refactor(schema): extract shared public schemas (#33571)
This commit is contained in:
parent
60aba622ab
commit
516cfe4e09
130 changed files with 2014 additions and 1593 deletions
54
packages/schema/src/skill.ts
Normal file
54
packages/schema/src/skill.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
export * as Skill from "./skill"
|
||||
|
||||
import { Schema } from "effect"
|
||||
import { AbsolutePath } from "./schema"
|
||||
|
||||
export interface DirectorySource extends Schema.Schema.Type<typeof DirectorySource> {}
|
||||
export const DirectorySource = Schema.Struct({
|
||||
type: Schema.Literal("directory"),
|
||||
path: AbsolutePath,
|
||||
}).annotate({ identifier: "SkillV2.DirectorySource" })
|
||||
|
||||
export interface UrlSource extends Schema.Schema.Type<typeof UrlSource> {}
|
||||
export const UrlSource = Schema.Struct({
|
||||
type: Schema.Literal("url"),
|
||||
url: Schema.String,
|
||||
}).annotate({ identifier: "SkillV2.UrlSource" })
|
||||
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
export const Info = Schema.Struct({
|
||||
name: Schema.String,
|
||||
description: Schema.String.pipe(Schema.optional),
|
||||
slash: Schema.Boolean.pipe(Schema.optional),
|
||||
location: AbsolutePath,
|
||||
content: Schema.String,
|
||||
}).annotate({ identifier: "SkillV2.Info" })
|
||||
|
||||
export interface EmbeddedSource extends Schema.Schema.Type<typeof EmbeddedSource> {}
|
||||
export const EmbeddedSource = Schema.Struct({
|
||||
type: Schema.Literal("embedded"),
|
||||
skill: Schema.suspend(() => Info),
|
||||
}).annotate({ identifier: "SkillV2.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" }),
|
||||
),
|
||||
{
|
||||
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
|
||||
return false
|
||||
},
|
||||
key: (source: Source) =>
|
||||
source.type === "directory"
|
||||
? `directory:${source.path}`
|
||||
: source.type === "url"
|
||||
? `url:${source.url}`
|
||||
: `embedded:${source.skill.name}`,
|
||||
},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue