refactor(core): consolidate tool architecture
This commit is contained in:
parent
0fd73a2976
commit
8db7487c89
466 changed files with 9405 additions and 11071 deletions
|
|
@ -12,18 +12,16 @@ import { FileSystemV1 } from "./filesystem-v1.js"
|
|||
import { Form } from "./form.js"
|
||||
import { InstallationEvent } from "./installation-event.js"
|
||||
import { Integration } from "./integration.js"
|
||||
import { LegacyEvent } from "./legacy-event.js"
|
||||
import { LegacyEventV1 } from "./legacy-event.js"
|
||||
import { LspEvent } from "./lsp-event.js"
|
||||
import { McpEvent } from "./mcp-event.js"
|
||||
import { ModelsDev } from "./models-dev.js"
|
||||
import { Permission } from "./permission.js"
|
||||
import { PermissionV1 } from "./permission-v1.js"
|
||||
import { Plugin } from "./plugin.js"
|
||||
import { Project } from "./project.js"
|
||||
import { ProjectDirectories } from "./project-directories.js"
|
||||
import { Pty } from "./pty.js"
|
||||
import { Question } from "./question.js"
|
||||
import { QuestionV1 } from "./question-v1.js"
|
||||
import { Reference } from "./reference.js"
|
||||
import { ServerEvent } from "./server-event.js"
|
||||
import { Shell } from "./shell.js"
|
||||
|
|
@ -81,11 +79,7 @@ export const ServerDefinitions = Event.inventory(
|
|||
...VcsEvent.Definitions,
|
||||
McpEvent.StatusChanged,
|
||||
McpEvent.ResourcesChanged,
|
||||
// Shared transitional: V1 contracts the current TUI still consumes during
|
||||
// the migration (permission.asked/replied, question.asked, session.error).
|
||||
// Remove when the TUI moves to the current permission/question surfaces.
|
||||
...PermissionV1.Event.Definitions,
|
||||
...QuestionV1.Event.Definitions,
|
||||
// Shared transitional event retained until the TUI moves to the current session error surface.
|
||||
SessionV1.Error,
|
||||
)
|
||||
export const Server = Event.latest(ServerDefinitions)
|
||||
|
|
@ -98,14 +92,12 @@ export const Definitions = Event.inventory(
|
|||
...InstallationEvent.Definitions,
|
||||
...featureDefinitions,
|
||||
...LspEvent.Definitions,
|
||||
...PermissionV1.Event.Definitions,
|
||||
...TuiEvent.Definitions,
|
||||
...McpEvent.Definitions,
|
||||
...LegacyEvent.Definitions,
|
||||
...LegacyEventV1.Definitions,
|
||||
...FileSystemV1.Event.Definitions,
|
||||
...Project.Event.Definitions,
|
||||
...SessionStatusEvent.Definitions,
|
||||
...QuestionV1.Event.Definitions,
|
||||
...SessionCompactionEvent.Definitions,
|
||||
...VcsEvent.Definitions,
|
||||
...WorkspaceEvent.Definitions,
|
||||
|
|
|
|||
|
|
@ -10,22 +10,3 @@ export type ProviderMetadata = Schema.Schema.Type<typeof ProviderMetadata>
|
|||
|
||||
export const FinishReason = Schema.Literals(["stop", "length", "tool-calls", "content-filter", "error", "unknown"])
|
||||
export type FinishReason = typeof FinishReason.Type
|
||||
|
||||
export interface ToolTextContent extends Schema.Schema.Type<typeof ToolTextContent> {}
|
||||
export const ToolTextContent = Schema.Struct({
|
||||
type: Schema.Literal("text"),
|
||||
text: Schema.String,
|
||||
}).annotate({ identifier: "Tool.TextContent" })
|
||||
|
||||
export interface ToolFileContent extends Schema.Schema.Type<typeof ToolFileContent> {}
|
||||
export const ToolFileContent = Schema.Struct({
|
||||
type: Schema.Literal("file"),
|
||||
uri: Schema.String,
|
||||
mime: Schema.String,
|
||||
name: optional(Schema.String),
|
||||
}).annotate({ identifier: "Tool.FileContent" })
|
||||
|
||||
export const ToolContent = Schema.Union([ToolTextContent, ToolFileContent])
|
||||
.pipe(Schema.toTaggedUnion("type"))
|
||||
.annotate({ identifier: "LLM.ToolContent" })
|
||||
export type ToolContent = Schema.Schema.Type<typeof ToolContent>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { SessionID } from "./session-id.js"
|
|||
import { statics } from "./schema.js"
|
||||
|
||||
export const ID = Schema.String.check(Schema.isStartsWith("per")).pipe(
|
||||
Schema.brand("PermissionV2.ID"),
|
||||
Schema.brand("Permission.ID"),
|
||||
statics((schema) => ({ create: (id?: string) => schema.make(id ?? "per_" + ascending()) })),
|
||||
)
|
||||
export type ID = typeof ID.Type
|
||||
|
|
@ -19,7 +19,7 @@ export const Source = Schema.Union([
|
|||
messageID: Schema.String,
|
||||
callID: Schema.String,
|
||||
}),
|
||||
]).annotate({ identifier: "PermissionV2.Source" })
|
||||
]).annotate({ identifier: "Permission.Source" })
|
||||
export type Source = typeof Source.Type
|
||||
|
||||
const RequestFields = {
|
||||
|
|
@ -34,15 +34,15 @@ const RequestFields = {
|
|||
export const Request = Schema.Struct({
|
||||
id: ID,
|
||||
...RequestFields,
|
||||
}).annotate({ identifier: "PermissionV2.Request" })
|
||||
}).annotate({ identifier: "Permission.Request" })
|
||||
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
||||
|
||||
export const Reply = Schema.Literals(["once", "always", "reject"]).annotate({ identifier: "PermissionV2.Reply" })
|
||||
export const Reply = Schema.Literals(["once", "always", "reject"]).annotate({ identifier: "Permission.Reply" })
|
||||
export type Reply = typeof Reply.Type
|
||||
|
||||
const Asked = ephemeral({ type: "permission.v2.asked", schema: Request.fields })
|
||||
const Asked = ephemeral({ type: "permission.asked", schema: Request.fields })
|
||||
const Replied = ephemeral({
|
||||
type: "permission.v2.replied",
|
||||
type: "permission.replied",
|
||||
schema: {
|
||||
sessionID: SessionID,
|
||||
requestID: ID,
|
||||
|
|
@ -51,7 +51,7 @@ const Replied = ephemeral({
|
|||
})
|
||||
export const Event = { Asked, Replied, Definitions: inventory(Asked, Replied) }
|
||||
|
||||
export const Effect = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "PermissionV2.Effect" })
|
||||
export const Effect = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "Permission.Effect" })
|
||||
export type Effect = typeof Effect.Type
|
||||
|
||||
export interface Rule extends Schema.Schema.Type<typeof Rule> {}
|
||||
|
|
@ -59,7 +59,7 @@ export const Rule = Schema.Struct({
|
|||
action: Schema.String,
|
||||
resource: Schema.String,
|
||||
effect: Effect,
|
||||
}).annotate({ identifier: "PermissionV2.Rule" })
|
||||
}).annotate({ identifier: "Permission.Rule" })
|
||||
|
||||
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "PermissionV2.Ruleset" })
|
||||
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "Permission.Ruleset" })
|
||||
export type Ruleset = typeof Ruleset.Type
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Integration } from "./integration.js"
|
|||
import { optional, statics } from "./schema.js"
|
||||
|
||||
export const ID = Schema.String.pipe(
|
||||
Schema.brand("ProviderV2.ID"),
|
||||
Schema.brand("Provider.ID"),
|
||||
statics((schema) => ({
|
||||
opencode: schema.make("opencode"),
|
||||
anthropic: schema.make("anthropic"),
|
||||
|
|
@ -26,19 +26,19 @@ export const Package = Schema.String
|
|||
export type Package = typeof Package.Type
|
||||
|
||||
export const Overlays = {
|
||||
settings: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
settings: Schema.Record(Schema.String, Schema.Any).pipe(optional),
|
||||
headers: Schema.Record(Schema.String, Schema.String).pipe(optional),
|
||||
body: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
body: Schema.Record(Schema.String, Schema.Any).pipe(optional),
|
||||
}
|
||||
|
||||
export const Settings = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "Provider.Settings" })
|
||||
export const Settings = Schema.Record(Schema.String, Schema.Any).annotate({ identifier: "Provider.Settings" })
|
||||
export type Settings = typeof Settings.Type
|
||||
|
||||
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
||||
export const Request = Schema.Struct({
|
||||
settings: Settings.pipe(Schema.withConstructorDefault(Effect.succeed({}))),
|
||||
headers: Schema.Record(Schema.String, Schema.String),
|
||||
body: Schema.Record(Schema.String, Schema.Json),
|
||||
body: Schema.Record(Schema.String, Schema.Any),
|
||||
}).annotate({ identifier: "Provider.Request" })
|
||||
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
|
|
@ -50,7 +50,7 @@ export const Info = Schema.Struct({
|
|||
package: Package,
|
||||
...Overlays,
|
||||
})
|
||||
.annotate({ identifier: "ProviderV2.Info" })
|
||||
.annotate({ identifier: "Provider.Info" })
|
||||
.pipe(
|
||||
statics(() => ({
|
||||
empty: (id: ID): Info => ({ id, name: id, package: "" }),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { SessionID } from "./session-id.js"
|
|||
import { statics } from "./schema.js"
|
||||
|
||||
export const ID = Schema.String.check(Schema.isStartsWith("que")).pipe(
|
||||
Schema.brand("QuestionV2.ID"),
|
||||
Schema.brand("Question.ID"),
|
||||
statics((schema) => {
|
||||
const create = () => schema.make("que_" + ascending())
|
||||
return {
|
||||
|
|
@ -22,7 +22,7 @@ export type ID = typeof ID.Type
|
|||
export const Option = Schema.Struct({
|
||||
label: Schema.String.annotate({ description: "Display text (1-5 words, concise)" }),
|
||||
description: Schema.String.annotate({ description: "Explanation of choice" }),
|
||||
}).annotate({ identifier: "QuestionV2.Option" })
|
||||
}).annotate({ identifier: "Question.Option" })
|
||||
export interface Option extends Schema.Schema.Type<typeof Option> {}
|
||||
|
||||
const base = {
|
||||
|
|
@ -37,16 +37,16 @@ export const Info = Schema.Struct({
|
|||
custom: Schema.Boolean.pipe(optional).annotate({
|
||||
description: "Allow typing a custom answer (default: true)",
|
||||
}),
|
||||
}).annotate({ identifier: "QuestionV2.Info" })
|
||||
}).annotate({ identifier: "Question.Info" })
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
|
||||
export const Prompt = Schema.Struct(base).annotate({ identifier: "QuestionV2.Prompt" })
|
||||
export const Prompt = Schema.Struct(base).annotate({ identifier: "Question.Prompt" })
|
||||
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
|
||||
|
||||
export const Tool = Schema.Struct({
|
||||
messageID: Schema.String,
|
||||
callID: Schema.String,
|
||||
}).annotate({ identifier: "QuestionV2.Tool" })
|
||||
}).annotate({ identifier: "Question.Tool" })
|
||||
export interface Tool extends Schema.Schema.Type<typeof Tool> {}
|
||||
|
||||
export const Request = Schema.Struct({
|
||||
|
|
@ -54,22 +54,22 @@ export const Request = Schema.Struct({
|
|||
sessionID: SessionID,
|
||||
questions: Schema.Array(Info).annotate({ description: "Questions to ask" }),
|
||||
tool: Tool.pipe(optional),
|
||||
}).annotate({ identifier: "QuestionV2.Request" })
|
||||
}).annotate({ identifier: "Question.Request" })
|
||||
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
||||
|
||||
export const Answer = Schema.Array(Schema.String).annotate({ identifier: "QuestionV2.Answer" })
|
||||
export const Answer = Schema.Array(Schema.String).annotate({ identifier: "Question.Answer" })
|
||||
export type Answer = typeof Answer.Type
|
||||
|
||||
export const Reply = Schema.Struct({
|
||||
answers: Schema.Array(Answer).annotate({
|
||||
description: "User answers in order of questions (each answer is an array of selected labels)",
|
||||
}),
|
||||
}).annotate({ identifier: "QuestionV2.Reply" })
|
||||
}).annotate({ identifier: "Question.Reply" })
|
||||
export interface Reply extends Schema.Schema.Type<typeof Reply> {}
|
||||
|
||||
const Asked = ephemeral({ type: "question.v2.asked", schema: Request.fields })
|
||||
const Asked = ephemeral({ type: "question.asked", schema: Request.fields })
|
||||
const Replied = ephemeral({
|
||||
type: "question.v2.replied",
|
||||
type: "question.replied",
|
||||
schema: {
|
||||
sessionID: SessionID,
|
||||
requestID: ID,
|
||||
|
|
@ -77,7 +77,7 @@ const Replied = ephemeral({
|
|||
},
|
||||
})
|
||||
const Rejected = ephemeral({
|
||||
type: "question.v2.rejected",
|
||||
type: "question.rejected",
|
||||
schema: {
|
||||
sessionID: SessionID,
|
||||
requestID: ID,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ export * as SessionEvent from "./session-event.js"
|
|||
import { Schema } from "effect"
|
||||
import { optional } from "./schema.js"
|
||||
import { Event } from "./event.js"
|
||||
import { FinishReason, ToolContent } from "./llm.js"
|
||||
import { FinishReason } from "./llm.js"
|
||||
import { Content } from "./tool.js"
|
||||
import { Model } from "./model.js"
|
||||
import { NonNegativeInt, PositiveInt, RelativePath } from "./schema.js"
|
||||
import { FileAttachment } from "./prompt.js"
|
||||
|
|
@ -429,7 +430,7 @@ export namespace Tool {
|
|||
},
|
||||
schema: {
|
||||
...ToolBase,
|
||||
content: Schema.NonEmptyArray(ToolContent),
|
||||
content: Schema.NonEmptyArray(Content),
|
||||
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
executed: Schema.Boolean,
|
||||
resultState: SessionMessage.ProviderState.pipe(optional),
|
||||
|
|
@ -451,7 +452,7 @@ export namespace Tool {
|
|||
schema: {
|
||||
...ToolBase,
|
||||
error: SessionError.Error,
|
||||
content: Schema.NonEmptyArray(ToolContent).pipe(optional),
|
||||
content: Schema.NonEmptyArray(Content).pipe(optional),
|
||||
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
executed: Schema.Boolean,
|
||||
resultState: SessionMessage.ProviderState.pipe(optional),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ export * as SessionMessage from "./session-message.js"
|
|||
|
||||
import { Schema } from "effect"
|
||||
import { optional } from "./schema.js"
|
||||
import { ToolContent } from "./llm.js"
|
||||
import { Content } from "./tool.js"
|
||||
import { Model } from "./model.js"
|
||||
import { Prompt } from "./prompt.js"
|
||||
import { DateTimeUtcFromMillis, PositiveInt, RelativePath, statics } from "./schema.js"
|
||||
|
|
@ -117,7 +117,7 @@ export interface ToolStateCompleted extends Schema.Schema.Type<typeof ToolStateC
|
|||
export const ToolStateCompleted = Schema.Struct({
|
||||
status: Schema.tag("completed"),
|
||||
input: Schema.Record(Schema.String, Schema.Unknown),
|
||||
content: Schema.NonEmptyArray(ToolContent),
|
||||
content: Schema.NonEmptyArray(Content),
|
||||
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
}).annotate({ identifier: "Session.Message.ToolState.Completed" })
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ export const ToolStateError = Schema.Struct({
|
|||
status: Schema.tag("error"),
|
||||
input: Schema.Record(Schema.String, Schema.Unknown),
|
||||
error: SessionError.Error,
|
||||
content: Schema.NonEmptyArray(ToolContent).pipe(optional),
|
||||
content: Schema.NonEmptyArray(Content).pipe(optional),
|
||||
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
|
||||
}).annotate({ identifier: "Session.Message.ToolState.Error" })
|
||||
|
||||
|
|
@ -248,8 +248,6 @@ export const Info = Schema.Union([
|
|||
Shell,
|
||||
Assistant,
|
||||
Compaction,
|
||||
])
|
||||
.pipe(Schema.toTaggedUnion("type"))
|
||||
.annotate({ identifier: "Session.Message.Info" })
|
||||
]).annotate({ identifier: "Session.Message.Info" })
|
||||
export type Info = AgentSelected | ModelSelected | User | Synthetic | System | Skill | Shell | Assistant | Compaction
|
||||
export type Type = Info["type"]
|
||||
|
|
|
|||
89
packages/schema/src/tool.ts
Normal file
89
packages/schema/src/tool.ts
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
export * as Tool from "./tool.js"
|
||||
|
||||
import { Effect, JsonSchema, Schema } from "effect"
|
||||
import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec"
|
||||
import type { Agent } from "./agent.js"
|
||||
import type { Session } from "./session.js"
|
||||
import type { SessionMessage } from "./session-message.js"
|
||||
|
||||
export type Metadata = Readonly<Record<string, any>>
|
||||
|
||||
export const CallID = Schema.String.pipe(Schema.brand("Tool.CallID"))
|
||||
export type CallID = typeof CallID.Type
|
||||
|
||||
export interface Context {
|
||||
readonly sessionID: Session.ID
|
||||
readonly agent: Agent.ID
|
||||
readonly messageID: SessionMessage.ID
|
||||
readonly callID: CallID
|
||||
readonly progress: (update: Metadata) => Effect.Effect<void>
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
readonly namespace?: string
|
||||
readonly codemode?: boolean
|
||||
readonly permission?: string
|
||||
}
|
||||
|
||||
export type ValueSchema<A = unknown> =
|
||||
| Schema.Codec<A, any>
|
||||
| (StandardSchemaV1<any, A> & StandardJSONSchemaV1<any, A>)
|
||||
| JsonSchema.JsonSchema
|
||||
|
||||
type InputValue<S> = 0 extends 1 & S
|
||||
? any
|
||||
: S extends Schema.Codec<infer A, any>
|
||||
? A
|
||||
: S extends StandardSchemaV1<any, infer A>
|
||||
? A
|
||||
: unknown
|
||||
type OutputValue<S> = S extends undefined
|
||||
? never
|
||||
: S extends Schema.Codec<infer A, any>
|
||||
? A
|
||||
: S extends StandardSchemaV1<infer A, any>
|
||||
? A
|
||||
: any
|
||||
|
||||
export class Error extends Schema.TaggedErrorClass<Error>()("Tool.Error", {
|
||||
message: Schema.String,
|
||||
error: Schema.optional(Schema.Defect()),
|
||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
||||
}) {}
|
||||
|
||||
export interface TextContent extends Schema.Schema.Type<typeof TextContent> {}
|
||||
export const TextContent = Schema.Struct({
|
||||
type: Schema.Literal("text"),
|
||||
text: Schema.String,
|
||||
}).annotate({ identifier: "Tool.TextContent" })
|
||||
|
||||
export interface FileContent extends Schema.Schema.Type<typeof FileContent> {}
|
||||
export const FileContent = Schema.Struct({
|
||||
type: Schema.Literal("file"),
|
||||
uri: Schema.String,
|
||||
mime: Schema.String,
|
||||
name: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "Tool.FileContent" })
|
||||
|
||||
export const Content = Schema.Union([TextContent, FileContent])
|
||||
.pipe(Schema.toTaggedUnion("type"))
|
||||
.annotate({ identifier: "Tool.Content" })
|
||||
export type Content = Schema.Schema.Type<typeof Content>
|
||||
|
||||
export interface Result<Output extends ValueSchema<any> | undefined = ValueSchema<any> | undefined> {
|
||||
readonly output?: OutputValue<Output>
|
||||
readonly content?: string | ReadonlyArray<Content>
|
||||
readonly metadata?: Metadata
|
||||
}
|
||||
|
||||
export type Info<
|
||||
Input extends ValueSchema<any> = ValueSchema<any>,
|
||||
Output extends ValueSchema<any> | undefined = ValueSchema<any> | undefined,
|
||||
> = {
|
||||
readonly name: string
|
||||
readonly input: Input
|
||||
readonly description: string
|
||||
readonly execute: (input: InputValue<Input>, context: Context) => Effect.Effect<Result<Output>, Error>
|
||||
readonly output?: Output
|
||||
readonly options?: Options
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
export * as LegacyEvent from "./legacy-event.js"
|
||||
export * as LegacyEventV1 from "./legacy-event.js"
|
||||
|
||||
import { Schema } from "effect"
|
||||
import { ephemeral, inventory } from "../event.js"
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@ import { statics } from "../schema.js"
|
|||
import { SessionID } from "../session-id.js"
|
||||
|
||||
export const ID = Schema.String.check(Schema.isStartsWith("per")).pipe(
|
||||
Schema.brand("PermissionID"),
|
||||
Schema.brand("PermissionV1.ID"),
|
||||
statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "per_" + ascending()) })),
|
||||
)
|
||||
export type ID = typeof ID.Type
|
||||
|
||||
export const Action = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "PermissionAction" })
|
||||
export const Action = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "PermissionV1.Action" })
|
||||
export type Action = typeof Action.Type
|
||||
|
||||
export const Rule = Schema.Struct({ permission: Schema.String, pattern: Schema.String, action: Action }).annotate({
|
||||
identifier: "PermissionRule",
|
||||
identifier: "PermissionV1.Rule",
|
||||
})
|
||||
export type Rule = typeof Rule.Type
|
||||
|
||||
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "PermissionRuleset" })
|
||||
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "PermissionV1.Ruleset" })
|
||||
export type Ruleset = typeof Ruleset.Type
|
||||
|
||||
export const Request = Schema.Struct({
|
||||
|
|
@ -32,29 +32,29 @@ export const Request = Schema.Struct({
|
|||
metadata: Schema.Record(Schema.String, Schema.Unknown),
|
||||
always: Schema.Array(Schema.String),
|
||||
tool: Schema.optional(Schema.Struct({ messageID: Schema.String, callID: Schema.String })),
|
||||
}).annotate({ identifier: "PermissionRequest" })
|
||||
}).annotate({ identifier: "PermissionV1.Request" })
|
||||
export type Request = typeof Request.Type
|
||||
|
||||
export const Reply = Schema.Literals(["once", "always", "reject"])
|
||||
export type Reply = typeof Reply.Type
|
||||
|
||||
export const ReplyBody = Schema.Struct({ reply: Reply, message: Schema.optional(Schema.String) }).annotate({
|
||||
identifier: "PermissionReplyBody",
|
||||
identifier: "PermissionV1.ReplyBody",
|
||||
})
|
||||
export type ReplyBody = typeof ReplyBody.Type
|
||||
|
||||
export const Approval = Schema.Struct({ projectID: Project.ID, patterns: Schema.Array(Schema.String) }).annotate({
|
||||
identifier: "PermissionApproval",
|
||||
identifier: "PermissionV1.Approval",
|
||||
})
|
||||
export type Approval = typeof Approval.Type
|
||||
|
||||
export const AskInput = Schema.Struct({ ...Request.fields, id: Schema.optional(ID), ruleset: Ruleset }).annotate({
|
||||
identifier: "PermissionAskInput",
|
||||
identifier: "PermissionV1.AskInput",
|
||||
})
|
||||
export type AskInput = typeof AskInput.Type
|
||||
|
||||
export const ReplyInput = Schema.Struct({ requestID: ID, ...ReplyBody.fields }).annotate({
|
||||
identifier: "PermissionReplyInput",
|
||||
identifier: "PermissionV1.ReplyInput",
|
||||
})
|
||||
export type ReplyInput = typeof ReplyInput.Type
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ import { SessionID } from "../session-id.js"
|
|||
import { SessionV1 } from "./session.js"
|
||||
|
||||
export const ID = Schema.String.check(Schema.isStartsWith("que")).pipe(
|
||||
Schema.brand("QuestionID"),
|
||||
Schema.brand("QuestionV1.ID"),
|
||||
statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "que_" + ascending()) })),
|
||||
)
|
||||
|
||||
export const Option = Schema.Struct({
|
||||
label: Schema.String.annotate({ description: "Display text (1-5 words, concise)" }),
|
||||
description: Schema.String.annotate({ description: "Explanation of choice" }),
|
||||
}).annotate({ identifier: "QuestionOption" })
|
||||
}).annotate({ identifier: "QuestionV1.Option" })
|
||||
|
||||
const base = {
|
||||
question: Schema.String.annotate({ description: "Complete question" }),
|
||||
|
|
@ -27,32 +27,32 @@ const base = {
|
|||
export const Info = Schema.Struct({
|
||||
...base,
|
||||
custom: Schema.optional(Schema.Boolean).annotate({ description: "Allow typing a custom answer (default: true)" }),
|
||||
}).annotate({ identifier: "QuestionInfo" })
|
||||
export const Prompt = Schema.Struct(base).annotate({ identifier: "QuestionPrompt" })
|
||||
}).annotate({ identifier: "QuestionV1.Info" })
|
||||
export const Prompt = Schema.Struct(base).annotate({ identifier: "QuestionV1.Prompt" })
|
||||
export const Tool = Schema.Struct({ messageID: SessionV1.MessageID, callID: Schema.String }).annotate({
|
||||
identifier: "QuestionTool",
|
||||
identifier: "QuestionV1.Tool",
|
||||
})
|
||||
export const Request = Schema.Struct({
|
||||
id: ID,
|
||||
sessionID: SessionID,
|
||||
questions: Schema.Array(Info).annotate({ description: "Questions to ask" }),
|
||||
tool: Schema.optional(Tool),
|
||||
}).annotate({ identifier: "QuestionRequest" })
|
||||
export const Answer = Schema.Array(Schema.String).annotate({ identifier: "QuestionAnswer" })
|
||||
}).annotate({ identifier: "QuestionV1.Request" })
|
||||
export const Answer = Schema.Array(Schema.String).annotate({ identifier: "QuestionV1.Answer" })
|
||||
export const Reply = Schema.Struct({
|
||||
answers: Schema.Array(Answer).annotate({
|
||||
description: "User answers in order of questions (each answer is an array of selected labels)",
|
||||
}),
|
||||
}).annotate({ identifier: "QuestionReply" })
|
||||
}).annotate({ identifier: "QuestionV1.Reply" })
|
||||
export const Replied = Schema.Struct({
|
||||
sessionID: SessionID,
|
||||
requestID: ID,
|
||||
answers: Schema.Array(Answer),
|
||||
}).annotate({
|
||||
identifier: "QuestionReplied",
|
||||
identifier: "QuestionV1.Replied",
|
||||
})
|
||||
export const Rejected = Schema.Struct({ sessionID: SessionID, requestID: ID }).annotate({
|
||||
identifier: "QuestionRejected",
|
||||
identifier: "QuestionV1.Rejected",
|
||||
})
|
||||
|
||||
const Asked = ephemeral({ type: "question.asked", schema: Request.fields })
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ import { FileDiff } from "../file-diff.js"
|
|||
const Timestamp = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0))
|
||||
|
||||
export const MessageID = Schema.String.check(Schema.isStartsWith("msg")).pipe(
|
||||
Schema.brand("MessageID"),
|
||||
Schema.brand("SessionV1.MessageID"),
|
||||
statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "msg_" + ascending()) })),
|
||||
)
|
||||
export type MessageID = typeof MessageID.Type
|
||||
|
||||
export const PartID = Schema.String.check(Schema.isStartsWith("prt")).pipe(
|
||||
Schema.brand("PartID"),
|
||||
Schema.brand("SessionV1.PartID"),
|
||||
statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "prt_" + ascending()) })),
|
||||
)
|
||||
export type PartID = typeof PartID.Type
|
||||
|
|
@ -68,13 +68,13 @@ export class OutputFormatText extends Schema.Class<OutputFormatText>("OutputForm
|
|||
|
||||
export class OutputFormatJsonSchema extends Schema.Class<OutputFormatJsonSchema>("OutputFormatJsonSchema")({
|
||||
type: Schema.Literal("json_schema"),
|
||||
schema: Schema.Record(Schema.String, Schema.Any).annotate({ identifier: "JSONSchema" }),
|
||||
schema: Schema.Record(Schema.String, Schema.Any).annotate({ identifier: "SessionV1.JSONSchema" }),
|
||||
retryCount: NonNegativeInt.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed(2))),
|
||||
}) {}
|
||||
|
||||
export const Format = Schema.Union([OutputFormatText, OutputFormatJsonSchema]).annotate({
|
||||
discriminator: "type",
|
||||
identifier: "OutputFormat",
|
||||
identifier: "SessionV1.OutputFormat",
|
||||
})
|
||||
export type OutputFormat = Schema.Schema.Type<typeof Format>
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ export const SnapshotPart = Schema.Struct({
|
|||
...partBase,
|
||||
type: Schema.Literal("snapshot"),
|
||||
snapshot: Schema.String,
|
||||
}).annotate({ identifier: "SnapshotPart" })
|
||||
}).annotate({ identifier: "SessionV1.SnapshotPart" })
|
||||
export type SnapshotPart = Types.DeepMutable<Schema.Schema.Type<typeof SnapshotPart>>
|
||||
|
||||
export const PatchPart = Schema.Struct({
|
||||
|
|
@ -96,7 +96,7 @@ export const PatchPart = Schema.Struct({
|
|||
type: Schema.Literal("patch"),
|
||||
hash: Schema.String,
|
||||
files: Schema.Array(Schema.String),
|
||||
}).annotate({ identifier: "PatchPart" })
|
||||
}).annotate({ identifier: "SessionV1.PatchPart" })
|
||||
export type PatchPart = Types.DeepMutable<Schema.Schema.Type<typeof PatchPart>>
|
||||
|
||||
export const TextPart = Schema.Struct({
|
||||
|
|
@ -112,7 +112,7 @@ export const TextPart = Schema.Struct({
|
|||
}),
|
||||
),
|
||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
|
||||
}).annotate({ identifier: "TextPart" })
|
||||
}).annotate({ identifier: "SessionV1.TextPart" })
|
||||
export type TextPart = Types.DeepMutable<Schema.Schema.Type<typeof TextPart>>
|
||||
|
||||
export const ReasoningPart = Schema.Struct({
|
||||
|
|
@ -124,7 +124,7 @@ export const ReasoningPart = Schema.Struct({
|
|||
start: NonNegativeInt,
|
||||
end: Schema.optional(NonNegativeInt),
|
||||
}),
|
||||
}).annotate({ identifier: "ReasoningPart" })
|
||||
}).annotate({ identifier: "SessionV1.ReasoningPart" })
|
||||
export type ReasoningPart = Types.DeepMutable<Schema.Schema.Type<typeof ReasoningPart>>
|
||||
|
||||
const filePartSourceBase = {
|
||||
|
|
@ -132,20 +132,20 @@ const filePartSourceBase = {
|
|||
value: Schema.String,
|
||||
start: Schema.Finite,
|
||||
end: Schema.Finite,
|
||||
}).annotate({ identifier: "FilePartSourceText" }),
|
||||
}).annotate({ identifier: "SessionV1.FilePartSourceText" }),
|
||||
}
|
||||
|
||||
export const Range = Schema.Struct({
|
||||
start: Schema.Struct({ line: NonNegativeInt, character: NonNegativeInt }),
|
||||
end: Schema.Struct({ line: NonNegativeInt, character: NonNegativeInt }),
|
||||
}).annotate({ identifier: "Range" })
|
||||
}).annotate({ identifier: "SessionV1.Range" })
|
||||
export type Range = typeof Range.Type
|
||||
|
||||
export const FileSource = Schema.Struct({
|
||||
...filePartSourceBase,
|
||||
type: Schema.Literal("file"),
|
||||
path: Schema.String,
|
||||
}).annotate({ identifier: "FileSource" })
|
||||
}).annotate({ identifier: "SessionV1.FileSource" })
|
||||
|
||||
export const SymbolSource = Schema.Struct({
|
||||
...filePartSourceBase,
|
||||
|
|
@ -154,18 +154,18 @@ export const SymbolSource = Schema.Struct({
|
|||
range: Range,
|
||||
name: Schema.String,
|
||||
kind: NonNegativeInt,
|
||||
}).annotate({ identifier: "SymbolSource" })
|
||||
}).annotate({ identifier: "SessionV1.SymbolSource" })
|
||||
|
||||
export const ResourceSource = Schema.Struct({
|
||||
...filePartSourceBase,
|
||||
type: Schema.Literal("resource"),
|
||||
clientName: Schema.String,
|
||||
uri: Schema.String,
|
||||
}).annotate({ identifier: "ResourceSource" })
|
||||
}).annotate({ identifier: "SessionV1.ResourceSource" })
|
||||
|
||||
export const FilePartSource = Schema.Union([FileSource, SymbolSource, ResourceSource]).annotate({
|
||||
discriminator: "type",
|
||||
identifier: "FilePartSource",
|
||||
identifier: "SessionV1.FilePartSource",
|
||||
})
|
||||
|
||||
export const FilePart = Schema.Struct({
|
||||
|
|
@ -175,7 +175,7 @@ export const FilePart = Schema.Struct({
|
|||
filename: Schema.optional(Schema.String),
|
||||
url: Schema.String,
|
||||
source: Schema.optional(FilePartSource),
|
||||
}).annotate({ identifier: "FilePart" })
|
||||
}).annotate({ identifier: "SessionV1.FilePart" })
|
||||
export type FilePart = Types.DeepMutable<Schema.Schema.Type<typeof FilePart>>
|
||||
|
||||
export const AgentPart = Schema.Struct({
|
||||
|
|
@ -189,7 +189,7 @@ export const AgentPart = Schema.Struct({
|
|||
end: NonNegativeInt,
|
||||
}),
|
||||
),
|
||||
}).annotate({ identifier: "AgentPart" })
|
||||
}).annotate({ identifier: "SessionV1.AgentPart" })
|
||||
export type AgentPart = Types.DeepMutable<Schema.Schema.Type<typeof AgentPart>>
|
||||
|
||||
export const CompactionPart = Schema.Struct({
|
||||
|
|
@ -198,7 +198,7 @@ export const CompactionPart = Schema.Struct({
|
|||
auto: Schema.Boolean,
|
||||
overflow: Schema.optional(Schema.Boolean),
|
||||
tail_start_id: Schema.optional(MessageID),
|
||||
}).annotate({ identifier: "CompactionPart" })
|
||||
}).annotate({ identifier: "SessionV1.CompactionPart" })
|
||||
export type CompactionPart = Types.DeepMutable<Schema.Schema.Type<typeof CompactionPart>>
|
||||
|
||||
export const SubtaskPart = Schema.Struct({
|
||||
|
|
@ -214,7 +214,7 @@ export const SubtaskPart = Schema.Struct({
|
|||
}),
|
||||
),
|
||||
command: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "SubtaskPart" })
|
||||
}).annotate({ identifier: "SessionV1.SubtaskPart" })
|
||||
export type SubtaskPart = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPart>>
|
||||
|
||||
export const RetryPart = Schema.Struct({
|
||||
|
|
@ -225,7 +225,7 @@ export const RetryPart = Schema.Struct({
|
|||
time: Schema.Struct({
|
||||
created: NonNegativeInt,
|
||||
}),
|
||||
}).annotate({ identifier: "RetryPart" })
|
||||
}).annotate({ identifier: "SessionV1.RetryPart" })
|
||||
export type RetryPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof RetryPart>>, "error"> & {
|
||||
error: APIError
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ export const StepStartPart = Schema.Struct({
|
|||
...partBase,
|
||||
type: Schema.Literal("step-start"),
|
||||
snapshot: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "StepStartPart" })
|
||||
}).annotate({ identifier: "SessionV1.StepStartPart" })
|
||||
export type StepStartPart = Types.DeepMutable<Schema.Schema.Type<typeof StepStartPart>>
|
||||
|
||||
export const StepFinishPart = Schema.Struct({
|
||||
|
|
@ -253,14 +253,14 @@ export const StepFinishPart = Schema.Struct({
|
|||
write: Schema.Finite,
|
||||
}),
|
||||
}),
|
||||
}).annotate({ identifier: "StepFinishPart" })
|
||||
}).annotate({ identifier: "SessionV1.StepFinishPart" })
|
||||
export type StepFinishPart = Types.DeepMutable<Schema.Schema.Type<typeof StepFinishPart>>
|
||||
|
||||
export const ToolStatePending = Schema.Struct({
|
||||
status: Schema.Literal("pending"),
|
||||
input: Schema.Record(Schema.String, Schema.Any),
|
||||
raw: Schema.String,
|
||||
}).annotate({ identifier: "ToolStatePending" })
|
||||
}).annotate({ identifier: "SessionV1.ToolStatePending" })
|
||||
export type ToolStatePending = Types.DeepMutable<Schema.Schema.Type<typeof ToolStatePending>>
|
||||
|
||||
export const ToolStateRunning = Schema.Struct({
|
||||
|
|
@ -271,7 +271,7 @@ export const ToolStateRunning = Schema.Struct({
|
|||
time: Schema.Struct({
|
||||
start: NonNegativeInt,
|
||||
}),
|
||||
}).annotate({ identifier: "ToolStateRunning" })
|
||||
}).annotate({ identifier: "SessionV1.ToolStateRunning" })
|
||||
export type ToolStateRunning = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateRunning>>
|
||||
|
||||
export const ToolStateCompleted = Schema.Struct({
|
||||
|
|
@ -286,7 +286,7 @@ export const ToolStateCompleted = Schema.Struct({
|
|||
compacted: Schema.optional(NonNegativeInt),
|
||||
}),
|
||||
attachments: Schema.optional(Schema.Array(FilePart)),
|
||||
}).annotate({ identifier: "ToolStateCompleted" })
|
||||
}).annotate({ identifier: "SessionV1.ToolStateCompleted" })
|
||||
export type ToolStateCompleted = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateCompleted>>
|
||||
|
||||
export const ToolStateError = Schema.Struct({
|
||||
|
|
@ -298,7 +298,7 @@ export const ToolStateError = Schema.Struct({
|
|||
start: NonNegativeInt,
|
||||
end: NonNegativeInt,
|
||||
}),
|
||||
}).annotate({ identifier: "ToolStateError" })
|
||||
}).annotate({ identifier: "SessionV1.ToolStateError" })
|
||||
export type ToolStateError = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateError>>
|
||||
|
||||
export const ToolState = Schema.Union([
|
||||
|
|
@ -308,7 +308,7 @@ export const ToolState = Schema.Union([
|
|||
ToolStateError,
|
||||
]).annotate({
|
||||
discriminator: "status",
|
||||
identifier: "ToolState",
|
||||
identifier: "SessionV1.ToolState",
|
||||
})
|
||||
export type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ export const ToolPart = Schema.Struct({
|
|||
tool: Schema.String,
|
||||
state: ToolState,
|
||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
|
||||
}).annotate({ identifier: "ToolPart" })
|
||||
}).annotate({ identifier: "SessionV1.ToolPart" })
|
||||
export type ToolPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof ToolPart>>, "state"> & {
|
||||
state: ToolState
|
||||
}
|
||||
|
|
@ -351,7 +351,7 @@ export const User = Schema.Struct({
|
|||
}),
|
||||
system: Schema.optional(Schema.String),
|
||||
tools: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
|
||||
}).annotate({ identifier: "UserMessage" })
|
||||
}).annotate({ identifier: "SessionV1.UserMessage" })
|
||||
export type User = Types.DeepMutable<Schema.Schema.Type<typeof User>>
|
||||
|
||||
export const Part = Schema.Union([
|
||||
|
|
@ -367,7 +367,7 @@ export const Part = Schema.Union([
|
|||
AgentPart,
|
||||
RetryPart,
|
||||
CompactionPart,
|
||||
]).annotate({ discriminator: "type", identifier: "Part" })
|
||||
]).annotate({ discriminator: "type", identifier: "SessionV1.Part" })
|
||||
export type Part =
|
||||
| TextPart
|
||||
| SubtaskPart
|
||||
|
|
@ -407,7 +407,7 @@ export const TextPartInput = Schema.Struct({
|
|||
}),
|
||||
),
|
||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
|
||||
}).annotate({ identifier: "TextPartInput" })
|
||||
}).annotate({ identifier: "SessionV1.TextPartInput" })
|
||||
export type TextPartInput = Types.DeepMutable<Schema.Schema.Type<typeof TextPartInput>>
|
||||
|
||||
export const FilePartInput = Schema.Struct({
|
||||
|
|
@ -417,7 +417,7 @@ export const FilePartInput = Schema.Struct({
|
|||
filename: Schema.optional(Schema.String),
|
||||
url: Schema.String,
|
||||
source: Schema.optional(FilePartSource),
|
||||
}).annotate({ identifier: "FilePartInput" })
|
||||
}).annotate({ identifier: "SessionV1.FilePartInput" })
|
||||
export type FilePartInput = Types.DeepMutable<Schema.Schema.Type<typeof FilePartInput>>
|
||||
|
||||
export const AgentPartInput = Schema.Struct({
|
||||
|
|
@ -431,7 +431,7 @@ export const AgentPartInput = Schema.Struct({
|
|||
end: NonNegativeInt,
|
||||
}),
|
||||
),
|
||||
}).annotate({ identifier: "AgentPartInput" })
|
||||
}).annotate({ identifier: "SessionV1.AgentPartInput" })
|
||||
export type AgentPartInput = Types.DeepMutable<Schema.Schema.Type<typeof AgentPartInput>>
|
||||
|
||||
export const SubtaskPartInput = Schema.Struct({
|
||||
|
|
@ -447,7 +447,7 @@ export const SubtaskPartInput = Schema.Struct({
|
|||
}),
|
||||
),
|
||||
command: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "SubtaskPartInput" })
|
||||
}).annotate({ identifier: "SessionV1.SubtaskPartInput" })
|
||||
export type SubtaskPartInput = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPartInput>>
|
||||
|
||||
export const Assistant = Schema.Struct({
|
||||
|
|
@ -482,12 +482,12 @@ export const Assistant = Schema.Struct({
|
|||
structured: Schema.optional(Schema.Any),
|
||||
variant: Schema.optional(Schema.String),
|
||||
finish: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "AssistantMessage" })
|
||||
}).annotate({ identifier: "SessionV1.AssistantMessage" })
|
||||
export type Assistant = Omit<Types.DeepMutable<Schema.Schema.Type<typeof Assistant>>, "error"> & {
|
||||
error?: AssistantError
|
||||
}
|
||||
|
||||
export const Info = Schema.Union([User, Assistant]).annotate({ discriminator: "role", identifier: "Message" })
|
||||
export const Info = Schema.Union([User, Assistant]).annotate({ discriminator: "role", identifier: "SessionV1.Message" })
|
||||
export type Info = User | Assistant
|
||||
|
||||
export const WithParts = Schema.Struct({
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { ascending } from "./identifier.js"
|
|||
import { statics } from "./schema.js"
|
||||
|
||||
export const WorkspaceID = Schema.String.check(Schema.isStartsWith("wrk")).pipe(
|
||||
Schema.brand("WorkspaceV2.ID"),
|
||||
Schema.brand("Workspace.ID"),
|
||||
statics((schema) => {
|
||||
const create = () => schema.make("wrk_" + ascending())
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue