refactor(schema): apply session review decisions (#35793)
This commit is contained in:
parent
d27746e5b3
commit
ed6ad272ec
142 changed files with 4239 additions and 3174 deletions
|
|
@ -5,49 +5,56 @@ import { optional } from "./schema.js"
|
|||
import { AbsolutePath } from "./schema.js"
|
||||
import { ephemeral, inventory } from "./event.js"
|
||||
|
||||
export const ID = Schema.String.pipe(Schema.brand("Skill.ID"))
|
||||
export type ID = typeof ID.Type
|
||||
|
||||
export const Name = Schema.String.pipe(Schema.brand("Skill.Name"))
|
||||
export type Name = typeof Name.Type
|
||||
|
||||
export interface DirectorySource extends Schema.Schema.Type<typeof DirectorySource> {}
|
||||
export const DirectorySource = Schema.Struct({
|
||||
type: Schema.Literal("directory"),
|
||||
type: Schema.tag("directory"),
|
||||
path: AbsolutePath,
|
||||
}).annotate({ identifier: "SkillV2.DirectorySource" })
|
||||
}).annotate({ identifier: "Skill.DirectorySource" })
|
||||
|
||||
export interface UrlSource extends Schema.Schema.Type<typeof UrlSource> {}
|
||||
export const UrlSource = Schema.Struct({
|
||||
type: Schema.Literal("url"),
|
||||
type: Schema.tag("url"),
|
||||
url: Schema.String,
|
||||
}).annotate({ identifier: "SkillV2.UrlSource" })
|
||||
}).annotate({ identifier: "Skill.UrlSource" })
|
||||
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
export const Info = Schema.Struct({
|
||||
name: Schema.String,
|
||||
id: ID,
|
||||
name: Name,
|
||||
description: Schema.String.pipe(optional),
|
||||
slash: Schema.Boolean.pipe(optional),
|
||||
autoinvoke: Schema.Boolean.pipe(optional),
|
||||
location: AbsolutePath,
|
||||
content: Schema.String,
|
||||
}).annotate({ identifier: "SkillV2.Info" })
|
||||
}).annotate({ identifier: "Skill.Info" })
|
||||
|
||||
const Updated = ephemeral({ type: "skill.updated", schema: {} })
|
||||
export const Event = { Updated, Definitions: inventory(Updated) }
|
||||
|
||||
export interface EmbeddedSource extends Schema.Schema.Type<typeof EmbeddedSource> {}
|
||||
export const EmbeddedSource = Schema.Struct({
|
||||
type: Schema.Literal("embedded"),
|
||||
type: Schema.tag("embedded"),
|
||||
skill: Schema.suspend(() => Info),
|
||||
}).annotate({ identifier: "SkillV2.EmbeddedSource" })
|
||||
}).annotate({ identifier: "Skill.EmbeddedSource" })
|
||||
|
||||
export type Source = DirectorySource | UrlSource | EmbeddedSource
|
||||
export const Source = Object.assign(
|
||||
Schema.Union([DirectorySource, UrlSource, EmbeddedSource]).pipe(
|
||||
Schema.toTaggedUnion("type"),
|
||||
Schema.annotate({ identifier: "SkillV2.Source" }),
|
||||
Schema.annotate({ identifier: "Skill.Source" }),
|
||||
),
|
||||
{
|
||||
equals: (a: Source, b: Source) => {
|
||||
if (a.type !== b.type) return false
|
||||
if (a.type === "directory" && b.type === "directory") return a.path === b.path
|
||||
if (a.type === "url" && b.type === "url") return a.url === b.url
|
||||
if (a.type === "embedded" && b.type === "embedded") return a.skill.name === b.skill.name
|
||||
if (a.type === "embedded" && b.type === "embedded") return a.skill.id === b.skill.id
|
||||
return false
|
||||
},
|
||||
key: (source: Source) =>
|
||||
|
|
@ -55,6 +62,6 @@ export const Source = Object.assign(
|
|||
? `directory:${source.path}`
|
||||
: source.type === "url"
|
||||
? `url:${source.url}`
|
||||
: `embedded:${source.skill.name}`,
|
||||
: `embedded:${source.skill.id}`,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue