@zyro-sec/schema 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +95 -0
- package/package.json +31 -4
- package/script/build.ts +9 -0
- package/script/config-schema.ts +86 -0
- package/script/config-v1.json +1312 -0
- package/script/pack.ts +5 -0
- package/src/agent.ts +68 -0
- package/src/artifact.ts +81 -0
- package/src/automation.ts +224 -0
- package/src/blob-store.ts +25 -0
- package/src/command.ts +18 -0
- package/src/config/agent.ts +26 -0
- package/src/config/command.ts +14 -0
- package/src/config/compaction.ts +27 -0
- package/src/config/experimental.ts +72 -0
- package/src/config/flag.ts +39 -0
- package/src/config/formatter.ts +13 -0
- package/src/config/lsp.ts +19 -0
- package/src/config/mcp.ts +22 -0
- package/src/config/media.ts +15 -0
- package/src/config/model.ts +37 -0
- package/src/config/plugin.ts +14 -0
- package/src/config/policy.ts +57 -0
- package/src/config/provider.ts +122 -0
- package/src/config/reference.ts +23 -0
- package/src/config/shell.ts +10 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/warming.ts +21 -0
- package/src/config/watcher.ts +8 -0
- package/src/config/websearch.ts +17 -0
- package/src/config/worktree.ts +10 -0
- package/src/config.ts +149 -0
- package/src/connection.ts +38 -0
- package/src/credential-legacy.ts +29 -0
- package/src/credential.ts +78 -0
- package/src/durable-event-manifest.ts +7 -0
- package/src/event-log.ts +21 -0
- package/src/event-manifest.ts +108 -0
- package/src/event.ts +205 -0
- package/src/file-diff.ts +25 -0
- package/src/filesystem-v1.ts +1 -0
- package/src/filesystem.ts +48 -0
- package/src/form.ts +177 -0
- package/src/generate.ts +292 -0
- package/src/goal.ts +46 -0
- package/src/identifier.ts +32 -0
- package/src/index.ts +51 -0
- package/src/installation-event.ts +20 -0
- package/src/instruction-entry.ts +40 -0
- package/src/instruction.ts +25 -0
- package/src/integration-id.ts +13 -0
- package/src/integration.ts +129 -0
- package/src/job.ts +79 -0
- package/src/legacy-event.ts +1 -0
- package/src/llm.ts +6 -0
- package/src/location-event.ts +8 -0
- package/src/location.ts +36 -0
- package/src/lsp-event.ts +7 -0
- package/src/mcp-event.ts +63 -0
- package/src/mcp.ts +171 -0
- package/src/model-compatibility.ts +55 -0
- package/src/model.ts +176 -0
- package/src/models-dev.ts +9 -0
- package/src/money.ts +18 -0
- package/src/permission-saved.ts +25 -0
- package/src/permission-v1.ts +1 -0
- package/src/permission.ts +67 -0
- package/src/persistent-pty.ts +73 -0
- package/src/plugin.ts +62 -0
- package/src/project-id.ts +9 -0
- package/src/project.ts +62 -0
- package/src/prompt-input.ts +33 -0
- package/src/prompt.ts +117 -0
- package/src/provider.ts +136 -0
- package/src/pty-ticket.ts +10 -0
- package/src/pty.ts +61 -0
- package/src/push.ts +86 -0
- package/src/question.ts +22 -0
- package/src/reference.ts +40 -0
- package/src/rpc.ts +167 -0
- package/src/schema.ts +41 -0
- package/src/server-event.ts +8 -0
- package/src/session-error.ts +14 -0
- package/src/session-event.ts +739 -0
- package/src/session-fork.ts +10 -0
- package/src/session-id.ts +12 -0
- package/src/session-inbox.ts +102 -0
- package/src/session-legacy.ts +117 -0
- package/src/session-message.ts +352 -0
- package/src/session-metadata.ts +11 -0
- package/src/session-revert.ts +86 -0
- package/src/session-stats.ts +68 -0
- package/src/session-status-event.ts +53 -0
- package/src/session-transfer.ts +11 -0
- package/src/session-v1.ts +1 -0
- package/src/session.ts +147 -0
- package/src/shell.ts +90 -0
- package/src/skill.ts +68 -0
- package/src/snapshot.ts +6 -0
- package/src/token-usage.ts +18 -0
- package/src/tool.ts +143 -0
- package/src/tui-event.ts +59 -0
- package/src/usage-limits.ts +76 -0
- package/src/v1/filesystem.ts +11 -0
- package/src/v1/legacy-event.ts +18 -0
- package/src/v1/permission.ts +66 -0
- package/src/v1/session.ts +667 -0
- package/src/vcs-event.ts +14 -0
- package/src/vcs.ts +41 -0
- package/src/websearch.ts +44 -0
- package/src/workspace-event.ts +32 -0
- package/src/workspace-id.ts +19 -0
- package/src/workspace.ts +20 -0
- package/src/worktree-event.ts +22 -0
- package/src/worktree.ts +109 -0
- package/test/agent.test.ts +10 -0
- package/test/automation.test.ts +48 -0
- package/test/compatibility.test.ts +10 -0
- package/test/config.test.ts +194 -0
- package/test/contract-hygiene.test.ts +352 -0
- package/test/credential-legacy.test.ts +55 -0
- package/test/event-manifest.test.ts +228 -0
- package/test/event.test.ts +52 -0
- package/test/legacy-event.test.ts +46 -0
- package/test/mcp.test.ts +37 -0
- package/test/model.test.ts +104 -0
- package/test/session-cursor.test.ts +16 -0
- package/test/session-error.test.ts +51 -0
- package/test/session-legacy.test.ts +178 -0
- package/test/session-terminal.test.ts +50 -0
- package/test/token-usage.test.ts +18 -0
- package/test/v1-isolation.test.ts +26 -0
- package/test/vcs.test.ts +23 -0
- package/test/worktree.test.ts +45 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
- package/README.md +0 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export * as Permission from "./permission.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { ascending } from "./identifier.js"
|
|
7
|
+
import { SessionID } from "./session-id.js"
|
|
8
|
+
import { statics } from "./schema.js"
|
|
9
|
+
|
|
10
|
+
export const ID = Schema.String.check(Schema.isStartingWith("per")).pipe(
|
|
11
|
+
Schema.brand("Permission.ID"),
|
|
12
|
+
Schema.annotate({ identifier: "Permission.ID" }),
|
|
13
|
+
statics((schema) => ({ create: (id?: string) => schema.make(id ?? "per_" + ascending()) })),
|
|
14
|
+
)
|
|
15
|
+
export type ID = typeof ID.Type
|
|
16
|
+
|
|
17
|
+
export const Source = Schema.Union([
|
|
18
|
+
Schema.Struct({
|
|
19
|
+
type: Schema.Literal("tool"),
|
|
20
|
+
messageID: Schema.String,
|
|
21
|
+
id: Schema.String,
|
|
22
|
+
}),
|
|
23
|
+
]).annotate({ identifier: "Permission.Source" })
|
|
24
|
+
export type Source = typeof Source.Type
|
|
25
|
+
|
|
26
|
+
const RequestFields = {
|
|
27
|
+
sessionID: SessionID,
|
|
28
|
+
action: Schema.String,
|
|
29
|
+
resources: Schema.Array(Schema.String),
|
|
30
|
+
save: Schema.Array(Schema.String).pipe(optional),
|
|
31
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
|
32
|
+
source: Source.pipe(optional),
|
|
33
|
+
message: Schema.String.pipe(optional),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const Request = Schema.Struct({
|
|
37
|
+
id: ID,
|
|
38
|
+
...RequestFields,
|
|
39
|
+
}).annotate({ identifier: "Permission.Request" })
|
|
40
|
+
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
|
41
|
+
|
|
42
|
+
export const Reply = Schema.Literals(["once", "always", "reject"]).annotate({ identifier: "Permission.Reply" })
|
|
43
|
+
export type Reply = typeof Reply.Type
|
|
44
|
+
|
|
45
|
+
const Asked = ephemeral({ type: "permission.asked", schema: Request.fields })
|
|
46
|
+
const Replied = ephemeral({
|
|
47
|
+
type: "permission.replied",
|
|
48
|
+
schema: {
|
|
49
|
+
sessionID: SessionID,
|
|
50
|
+
requestID: ID,
|
|
51
|
+
reply: Reply,
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
export const Event = { Asked, Replied, Definitions: inventory(Asked, Replied) }
|
|
55
|
+
|
|
56
|
+
export const Effect = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "Permission.Effect" })
|
|
57
|
+
export type Effect = typeof Effect.Type
|
|
58
|
+
|
|
59
|
+
export interface Rule extends Schema.Schema.Type<typeof Rule> {}
|
|
60
|
+
export const Rule = Schema.Struct({
|
|
61
|
+
action: Schema.String,
|
|
62
|
+
resource: Schema.String,
|
|
63
|
+
effect: Effect,
|
|
64
|
+
}).annotate({ identifier: "Permission.Rule" })
|
|
65
|
+
|
|
66
|
+
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "Permission.Ruleset" })
|
|
67
|
+
export type Ruleset = typeof Ruleset.Type
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export * as PersistentPty from "./persistent-pty.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { Pty } from "./pty.js"
|
|
6
|
+
import { NonNegativeInt, PositiveInt, optional } from "./schema.js"
|
|
7
|
+
import { Session } from "./session.js"
|
|
8
|
+
|
|
9
|
+
export const Info = Schema.Struct({
|
|
10
|
+
...Pty.Info.fields,
|
|
11
|
+
sessionID: Session.ID,
|
|
12
|
+
userTitle: Schema.NullOr(Schema.String),
|
|
13
|
+
foregroundProcess: Schema.NullOr(Schema.String),
|
|
14
|
+
size: Schema.Struct({ cols: PositiveInt, rows: PositiveInt }),
|
|
15
|
+
output: Schema.Struct({ head: NonNegativeInt, tail: NonNegativeInt }),
|
|
16
|
+
}).annotate({ identifier: "PersistentPty.Info" })
|
|
17
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
18
|
+
|
|
19
|
+
export const Handoff = Schema.Struct({
|
|
20
|
+
directory: Schema.String,
|
|
21
|
+
instanceID: Schema.String,
|
|
22
|
+
ticket: Schema.String,
|
|
23
|
+
expiresAt: Schema.Number,
|
|
24
|
+
}).annotate({ identifier: "PersistentPty.Handoff" })
|
|
25
|
+
export interface Handoff extends Schema.Schema.Type<typeof Handoff> {}
|
|
26
|
+
|
|
27
|
+
export const CreateInput = Schema.Struct({
|
|
28
|
+
command: optional(Schema.String),
|
|
29
|
+
args: Schema.Array(Schema.String),
|
|
30
|
+
cwd: optional(Schema.String),
|
|
31
|
+
title: Schema.String,
|
|
32
|
+
env: Schema.Record(Schema.String, Schema.String),
|
|
33
|
+
size: optional(Schema.Struct({ cols: PositiveInt, rows: PositiveInt })),
|
|
34
|
+
}).annotate({ identifier: "PersistentPty.CreateInput" })
|
|
35
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
36
|
+
|
|
37
|
+
export const UpdateInput = Schema.Struct({
|
|
38
|
+
attachmentID: optional(Schema.String),
|
|
39
|
+
size: optional(Schema.Struct({ cols: PositiveInt, rows: PositiveInt })),
|
|
40
|
+
title: optional(Schema.NullOr(Schema.String)),
|
|
41
|
+
}).annotate({ identifier: "PersistentPty.UpdateInput" })
|
|
42
|
+
export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {}
|
|
43
|
+
|
|
44
|
+
export const Snapshot = Schema.Struct({
|
|
45
|
+
info: Info,
|
|
46
|
+
text: Schema.String,
|
|
47
|
+
checkpoint: Schema.Uint8Array,
|
|
48
|
+
cursor: Schema.Struct({ x: NonNegativeInt, y: NonNegativeInt }),
|
|
49
|
+
}).annotate({ identifier: "PersistentPty.Snapshot" })
|
|
50
|
+
export interface Snapshot extends Schema.Schema.Type<typeof Snapshot> {}
|
|
51
|
+
|
|
52
|
+
export const ReadLines = PositiveInt.check(Schema.isLessThanOrEqualTo(65535)).annotate({
|
|
53
|
+
identifier: "PersistentPty.ReadLines",
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export const ReadResult = Schema.Struct({
|
|
57
|
+
ptyID: Pty.ID,
|
|
58
|
+
title: Schema.String,
|
|
59
|
+
cwd: Schema.String,
|
|
60
|
+
foregroundProcess: Schema.NullOr(Schema.String),
|
|
61
|
+
screen: Schema.Struct({
|
|
62
|
+
text: Schema.String,
|
|
63
|
+
cols: PositiveInt,
|
|
64
|
+
rows: PositiveInt,
|
|
65
|
+
cursor: Snapshot.fields.cursor,
|
|
66
|
+
}),
|
|
67
|
+
}).annotate({ identifier: "PersistentPty.ReadResult" })
|
|
68
|
+
export interface ReadResult extends Schema.Schema.Type<typeof ReadResult> {}
|
|
69
|
+
|
|
70
|
+
export const Added = ephemeral({ type: "persistent-pty.added", schema: { sessionID: Session.ID, terminal: Info } })
|
|
71
|
+
export const Removed = ephemeral({ type: "persistent-pty.removed", schema: { sessionID: Session.ID, ptyID: Pty.ID } })
|
|
72
|
+
export const Updated = ephemeral({ type: "persistent-pty.updated", schema: { sessionID: Session.ID, terminal: Info } })
|
|
73
|
+
export const Event = { Added, Removed, Updated, Definitions: inventory(Added, Removed, Updated) }
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export * as Plugin from "./plugin.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
export const ID = Schema.String.pipe(Schema.brand("Plugin.ID"), Schema.annotate({ identifier: "Plugin.ID" }))
|
|
8
|
+
export type ID = typeof ID.Type
|
|
9
|
+
|
|
10
|
+
export const Source = Schema.Union([
|
|
11
|
+
Schema.Struct({ type: Schema.Literal("builtin") }),
|
|
12
|
+
Schema.Struct({
|
|
13
|
+
type: Schema.Literal("package"),
|
|
14
|
+
target: Schema.String,
|
|
15
|
+
version: Schema.String.pipe(optional),
|
|
16
|
+
outdated: Schema.Literal(true).pipe(optional),
|
|
17
|
+
updating: Schema.Literal(true).pipe(optional),
|
|
18
|
+
}),
|
|
19
|
+
Schema.Struct({ type: Schema.Literal("local"), path: Schema.String }),
|
|
20
|
+
Schema.Struct({ type: Schema.Literal("sdk") }),
|
|
21
|
+
]).annotate({ identifier: "Plugin.Source" })
|
|
22
|
+
export type Source = typeof Source.Type
|
|
23
|
+
|
|
24
|
+
export const Features = Schema.Struct({
|
|
25
|
+
server: Schema.Literal(true).pipe(optional),
|
|
26
|
+
tui: Schema.Literal(true).pipe(optional),
|
|
27
|
+
rpc: Schema.Literal(true).pipe(optional),
|
|
28
|
+
/** The package exports `./gui-experimental`, the GUI bundle the desktop app loads. */
|
|
29
|
+
gui: Schema.Literal(true).pipe(optional),
|
|
30
|
+
}).annotate({ identifier: "Plugin.Features" })
|
|
31
|
+
export type Features = typeof Features.Type
|
|
32
|
+
|
|
33
|
+
/** A plugin's prebuilt CommonJS `./gui-experimental` bundle. */
|
|
34
|
+
export interface GuiBundle extends Schema.Schema.Type<typeof GuiBundle> {}
|
|
35
|
+
export const GuiBundle = Schema.Struct({
|
|
36
|
+
/** The bundle's CommonJS code. */
|
|
37
|
+
code: Schema.String,
|
|
38
|
+
/** An opaque value that changes whenever the plugin, its options or its bundle change. */
|
|
39
|
+
revision: Schema.String,
|
|
40
|
+
/** The plugin's options from its `opencode.json` entry, as its server entry receives them. */
|
|
41
|
+
options: Schema.Record(Schema.String, Schema.Json),
|
|
42
|
+
}).annotate({ identifier: "Plugin.GuiBundle" })
|
|
43
|
+
|
|
44
|
+
export const State = Schema.Union([
|
|
45
|
+
Schema.Struct({ status: Schema.Literal("active") }),
|
|
46
|
+
Schema.Struct({ status: Schema.Literal("failed"), error: Schema.String, ref: Schema.String.pipe(optional) }),
|
|
47
|
+
]).annotate({ identifier: "Plugin.State" })
|
|
48
|
+
export type State = typeof State.Type
|
|
49
|
+
|
|
50
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
51
|
+
export const Info = Schema.Struct({
|
|
52
|
+
id: ID.pipe(optional),
|
|
53
|
+
source: Source,
|
|
54
|
+
features: Features,
|
|
55
|
+
state: State,
|
|
56
|
+
}).annotate({ identifier: "Plugin.Info" })
|
|
57
|
+
|
|
58
|
+
const Updated = ephemeral({
|
|
59
|
+
type: "plugin.updated",
|
|
60
|
+
schema: {},
|
|
61
|
+
})
|
|
62
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { statics } from "./schema.js"
|
|
3
|
+
|
|
4
|
+
export const ProjectID = Schema.String.pipe(
|
|
5
|
+
Schema.brand("Project.ID"),
|
|
6
|
+
Schema.annotate({ identifier: "Project.ID" }),
|
|
7
|
+
statics((schema) => ({ global: schema.make("global") })),
|
|
8
|
+
)
|
|
9
|
+
export type ProjectID = typeof ProjectID.Type
|
package/src/project.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export * as Project from "./project.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { AbsolutePath, NonNegativeInt, optional } from "./schema.js"
|
|
6
|
+
import { ProjectID } from "./project-id.js"
|
|
7
|
+
|
|
8
|
+
export const ID = ProjectID
|
|
9
|
+
export type ID = typeof ID.Type
|
|
10
|
+
|
|
11
|
+
export const Vcs = Schema.String.check(Schema.isPattern(/^[a-z][a-z0-9._-]*$/u)).annotate({
|
|
12
|
+
identifier: "Project.Vcs",
|
|
13
|
+
})
|
|
14
|
+
export const Current = Schema.Struct({
|
|
15
|
+
id: ID,
|
|
16
|
+
directory: AbsolutePath,
|
|
17
|
+
canonical: AbsolutePath,
|
|
18
|
+
}).annotate({ identifier: "Project.Current" })
|
|
19
|
+
export interface Current extends Schema.Schema.Type<typeof Current> {}
|
|
20
|
+
export const Icon = Schema.Struct({
|
|
21
|
+
url: optional(Schema.String),
|
|
22
|
+
override: optional(Schema.String),
|
|
23
|
+
color: optional(Schema.String),
|
|
24
|
+
}).annotate({ identifier: "Project.Icon" })
|
|
25
|
+
export interface Icon extends Schema.Schema.Type<typeof Icon> {}
|
|
26
|
+
export const Commands = Schema.Struct({
|
|
27
|
+
start: optional(
|
|
28
|
+
Schema.String.annotate({ description: "Startup script to run when creating a new workspace (worktree)" }),
|
|
29
|
+
),
|
|
30
|
+
}).annotate({ identifier: "Project.Commands" })
|
|
31
|
+
export interface Commands extends Schema.Schema.Type<typeof Commands> {}
|
|
32
|
+
export const Time = Schema.Struct({
|
|
33
|
+
created: NonNegativeInt,
|
|
34
|
+
updated: NonNegativeInt,
|
|
35
|
+
active: NonNegativeInt,
|
|
36
|
+
archived: optional(NonNegativeInt),
|
|
37
|
+
}).annotate({ identifier: "Project.Time" })
|
|
38
|
+
export interface Time extends Schema.Schema.Type<typeof Time> {}
|
|
39
|
+
|
|
40
|
+
export const Info = Schema.Struct({
|
|
41
|
+
id: ID,
|
|
42
|
+
canonical: AbsolutePath,
|
|
43
|
+
vcs: optional(Vcs),
|
|
44
|
+
name: optional(Schema.String),
|
|
45
|
+
icon: optional(Icon),
|
|
46
|
+
commands: optional(Commands),
|
|
47
|
+
time: Time,
|
|
48
|
+
sandboxes: Schema.Array(Schema.String),
|
|
49
|
+
}).annotate({ identifier: "Project" })
|
|
50
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
51
|
+
|
|
52
|
+
export const UpdateInput = Schema.Struct({
|
|
53
|
+
projectID: ID,
|
|
54
|
+
canonical: optional(AbsolutePath),
|
|
55
|
+
name: optional(Schema.String),
|
|
56
|
+
icon: optional(Icon),
|
|
57
|
+
commands: optional(Commands),
|
|
58
|
+
}).annotate({ identifier: "Project.UpdateInput" })
|
|
59
|
+
export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {}
|
|
60
|
+
|
|
61
|
+
const Updated = ephemeral({ type: "project.updated", schema: Info.fields })
|
|
62
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * as PromptInput from "./prompt-input.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { AgentAttachment, FileSource, PromptMention } from "./prompt.js"
|
|
5
|
+
import { optional } from "./schema.js"
|
|
6
|
+
import { Skill } from "./skill.js"
|
|
7
|
+
|
|
8
|
+
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
|
|
9
|
+
export const FileAttachment = Schema.Struct({
|
|
10
|
+
uri: Schema.String.annotate({
|
|
11
|
+
description:
|
|
12
|
+
"A file: URL on the server (a file, a directory, or ?start=N&end=M for lines of a text file), a data: URL, or a media: ref from a message. Up to 20 MB.",
|
|
13
|
+
}),
|
|
14
|
+
// Source metadata does not require reopening the original file.
|
|
15
|
+
source: FileSource.pipe(optional),
|
|
16
|
+
name: Schema.String.pipe(optional),
|
|
17
|
+
description: Schema.String.pipe(optional),
|
|
18
|
+
mention: PromptMention.pipe(optional),
|
|
19
|
+
}).annotate({ identifier: "PromptInput.FileAttachment" })
|
|
20
|
+
|
|
21
|
+
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
|
|
22
|
+
export interface SkillAttachment extends Schema.Schema.Type<typeof SkillAttachment> {}
|
|
23
|
+
export const SkillAttachment = Schema.Struct({
|
|
24
|
+
id: Skill.ID,
|
|
25
|
+
mention: PromptMention.pipe(optional),
|
|
26
|
+
}).annotate({ identifier: "PromptInput.SkillAttachment" })
|
|
27
|
+
|
|
28
|
+
export const Prompt = Schema.Struct({
|
|
29
|
+
text: Schema.String,
|
|
30
|
+
files: Schema.Array(FileAttachment).pipe(optional),
|
|
31
|
+
agents: Schema.Array(AgentAttachment).pipe(optional),
|
|
32
|
+
skills: Schema.Array(SkillAttachment).pipe(optional),
|
|
33
|
+
}).annotate({ identifier: "PromptInput" })
|
package/src/prompt.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { optional } from "./schema.js"
|
|
3
|
+
import { statics } from "./schema.js"
|
|
4
|
+
import { Skill } from "./skill.js"
|
|
5
|
+
|
|
6
|
+
export interface PromptMention extends Schema.Schema.Type<typeof PromptMention> {}
|
|
7
|
+
export const PromptMention = Schema.Struct({
|
|
8
|
+
start: Schema.Finite,
|
|
9
|
+
end: Schema.Finite,
|
|
10
|
+
text: Schema.String,
|
|
11
|
+
}).annotate({ identifier: "Prompt.Mention" })
|
|
12
|
+
|
|
13
|
+
export const FileSource = Schema.Union([
|
|
14
|
+
Schema.Struct({ type: Schema.Literal("inline") }),
|
|
15
|
+
Schema.Struct({ type: Schema.Literal("uri"), uri: Schema.String }),
|
|
16
|
+
])
|
|
17
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
18
|
+
.annotate({ identifier: "Prompt.FileSource" })
|
|
19
|
+
export type FileSource = typeof FileSource.Type
|
|
20
|
+
|
|
21
|
+
// The canonical pattern backtracks on large inputs, so it only supplies metadata (OpenAPI, errors) while an equivalent linear check runs.
|
|
22
|
+
export const Base64 = Schema.String.check(
|
|
23
|
+
Schema.makeFilter(
|
|
24
|
+
(value: string) => value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/u.test(value),
|
|
25
|
+
Schema.isPattern(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u).annotations,
|
|
26
|
+
),
|
|
27
|
+
).annotate({ identifier: "Prompt.Base64" })
|
|
28
|
+
export type Base64 = typeof Base64.Type
|
|
29
|
+
|
|
30
|
+
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
|
|
31
|
+
export const FileAttachment = Schema.Struct({
|
|
32
|
+
data: Base64,
|
|
33
|
+
mime: Schema.String,
|
|
34
|
+
source: FileSource,
|
|
35
|
+
name: Schema.String.pipe(optional),
|
|
36
|
+
description: Schema.String.pipe(optional),
|
|
37
|
+
mention: PromptMention.pipe(optional),
|
|
38
|
+
})
|
|
39
|
+
.annotate({ identifier: "Prompt.FileAttachment" })
|
|
40
|
+
.pipe(
|
|
41
|
+
statics((schema) => ({
|
|
42
|
+
create: (input: FileAttachment) =>
|
|
43
|
+
schema.make({
|
|
44
|
+
data: input.data,
|
|
45
|
+
mime: input.mime,
|
|
46
|
+
source: input.source,
|
|
47
|
+
name: input.name,
|
|
48
|
+
description: input.description,
|
|
49
|
+
mention: input.mention,
|
|
50
|
+
}),
|
|
51
|
+
})),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
/** `media:` and the lowercase hex SHA-256 of a stored blob's bytes. Names no server route. */
|
|
55
|
+
export const MediaRef = Schema.String.check(Schema.isPattern(/^media:[0-9a-f]{64}$/)).annotate({
|
|
56
|
+
identifier: "Prompt.MediaRef",
|
|
57
|
+
})
|
|
58
|
+
export type MediaRef = typeof MediaRef.Type
|
|
59
|
+
|
|
60
|
+
const { data: _, ...fileAttachmentFields } = FileAttachment.fields
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An attachment whose bytes stay on the server, sent to clients that opt in with the experimental `experimental-media-uri`
|
|
64
|
+
* capability. Fetch the bytes from `GET /api/experimental/media/:hash`.
|
|
65
|
+
*/
|
|
66
|
+
export interface MediaFileAttachment extends Schema.Schema.Type<typeof MediaFileAttachment> {}
|
|
67
|
+
export const MediaFileAttachment = Schema.Struct({
|
|
68
|
+
...fileAttachmentFields,
|
|
69
|
+
uri: MediaRef,
|
|
70
|
+
bytes: Schema.Int.pipe(optional),
|
|
71
|
+
width: Schema.Int.pipe(optional),
|
|
72
|
+
height: Schema.Int.pipe(optional),
|
|
73
|
+
}).annotate({ identifier: "Prompt.MediaFileAttachment" })
|
|
74
|
+
|
|
75
|
+
export const Attachment = Schema.Union([FileAttachment, MediaFileAttachment]).annotate({
|
|
76
|
+
identifier: "Prompt.Attachment",
|
|
77
|
+
})
|
|
78
|
+
export type Attachment = typeof Attachment.Type
|
|
79
|
+
|
|
80
|
+
export interface AgentAttachment extends Schema.Schema.Type<typeof AgentAttachment> {}
|
|
81
|
+
export const AgentAttachment = Schema.Struct({
|
|
82
|
+
name: Schema.String,
|
|
83
|
+
mention: PromptMention.pipe(optional),
|
|
84
|
+
}).annotate({
|
|
85
|
+
identifier: "Prompt.AgentAttachment",
|
|
86
|
+
description:
|
|
87
|
+
"An agent @-mentioned in the prompt, such as @explore, to suggest the model use it. Only the @name in text reaches the model; this records which agent it names and doesn't change the session's own agent.",
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
export interface SkillAttachment extends Schema.Schema.Type<typeof SkillAttachment> {}
|
|
91
|
+
export const SkillAttachment = Schema.Struct({
|
|
92
|
+
id: Skill.ID,
|
|
93
|
+
name: Skill.Name,
|
|
94
|
+
text: Schema.String.pipe(optional),
|
|
95
|
+
mention: PromptMention.pipe(optional),
|
|
96
|
+
}).annotate({ identifier: "Prompt.SkillAttachment" })
|
|
97
|
+
|
|
98
|
+
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
|
|
99
|
+
export const Prompt = Schema.Struct({
|
|
100
|
+
text: Schema.String,
|
|
101
|
+
files: Schema.Array(FileAttachment).pipe(optional),
|
|
102
|
+
agents: Schema.Array(AgentAttachment).pipe(optional),
|
|
103
|
+
skills: Schema.Array(SkillAttachment).pipe(optional),
|
|
104
|
+
})
|
|
105
|
+
.annotate({ identifier: "Prompt" })
|
|
106
|
+
.pipe(
|
|
107
|
+
statics((schema) => ({
|
|
108
|
+
equivalence: Schema.toEquivalence(schema),
|
|
109
|
+
fromUserMessage: (input: Pick<Prompt, "text" | "files" | "agents" | "skills">) =>
|
|
110
|
+
schema.make({
|
|
111
|
+
text: input.text,
|
|
112
|
+
...(input.files === undefined ? {} : { files: input.files }),
|
|
113
|
+
...(input.agents === undefined ? {} : { agents: input.agents }),
|
|
114
|
+
...(input.skills === undefined ? {} : { skills: input.skills }),
|
|
115
|
+
}),
|
|
116
|
+
})),
|
|
117
|
+
)
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export * as Provider from "./provider.js"
|
|
2
|
+
|
|
3
|
+
import { Effect, Schema } from "effect"
|
|
4
|
+
import { Integration } from "./integration.js"
|
|
5
|
+
import { ProviderCompatibility } from "./model-compatibility.js"
|
|
6
|
+
import { optional, statics } from "./schema.js"
|
|
7
|
+
import { ephemeral, inventory } from "./event.js"
|
|
8
|
+
|
|
9
|
+
export const ID = Schema.String.pipe(
|
|
10
|
+
Schema.brand("Provider.ID"),
|
|
11
|
+
Schema.annotate({ identifier: "Provider.ID" }),
|
|
12
|
+
statics((schema) => ({
|
|
13
|
+
opencode: schema.make("opencode"),
|
|
14
|
+
anthropic: schema.make("anthropic"),
|
|
15
|
+
openai: schema.make("openai"),
|
|
16
|
+
google: schema.make("google"),
|
|
17
|
+
googleVertex: schema.make("google-vertex"),
|
|
18
|
+
githubCopilot: schema.make("github-copilot"),
|
|
19
|
+
claudeAgent: schema.make("claude-agent"),
|
|
20
|
+
amazonBedrock: schema.make("amazon-bedrock"),
|
|
21
|
+
azure: schema.make("azure"),
|
|
22
|
+
openrouter: schema.make("openrouter"),
|
|
23
|
+
mistral: schema.make("mistral"),
|
|
24
|
+
gitlab: schema.make("gitlab"),
|
|
25
|
+
})),
|
|
26
|
+
)
|
|
27
|
+
export type ID = typeof ID.Type
|
|
28
|
+
|
|
29
|
+
const Updated = ephemeral({ type: "provider.updated", schema: {} })
|
|
30
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
31
|
+
|
|
32
|
+
export const Package = Schema.String
|
|
33
|
+
export type Package = typeof Package.Type
|
|
34
|
+
|
|
35
|
+
export const Activation = Schema.Literals(["auto", "enabled", "disabled"])
|
|
36
|
+
export type Activation = typeof Activation.Type
|
|
37
|
+
|
|
38
|
+
export const Compaction = Schema.Union([
|
|
39
|
+
Schema.Struct({ type: Schema.Literal("summary") }),
|
|
40
|
+
Schema.Struct({ type: Schema.Literal("native") }),
|
|
41
|
+
])
|
|
42
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
43
|
+
.annotate({ identifier: "Provider.Compaction" })
|
|
44
|
+
export type Compaction = typeof Compaction.Type
|
|
45
|
+
|
|
46
|
+
/** "websocket" on a route without a WebSocket channel warns and falls back to HTTP. */
|
|
47
|
+
export const Transport = Schema.Literals(["http", "websocket"]).annotate({ identifier: "Provider.Transport" })
|
|
48
|
+
export type Transport = typeof Transport.Type
|
|
49
|
+
|
|
50
|
+
/** Prompt-cache lifetime such as "5m", "30m", "1h" or "24h", in models.dev's duration format. */
|
|
51
|
+
export const CacheTTL = Schema.TemplateLiteral([Schema.Number, Schema.Literals(["ms", "s", "m", "h", "d"])])
|
|
52
|
+
.check(Schema.isPattern(/^\d+(ms|s|m|h|d)$/))
|
|
53
|
+
.annotate({ identifier: "Provider.CacheTTL" })
|
|
54
|
+
export type CacheTTL = typeof CacheTTL.Type
|
|
55
|
+
|
|
56
|
+
/** Keep-alive requests for this provider's or model's sessions; overrides the top-level `warming`. */
|
|
57
|
+
export const CacheWarming = Schema.Union([
|
|
58
|
+
Schema.Boolean,
|
|
59
|
+
Schema.Struct({
|
|
60
|
+
// Settings hold JSON, so durations stay strings here; the warming plugin parses them.
|
|
61
|
+
interval: Schema.Union([Schema.Literal("auto"), Schema.String])
|
|
62
|
+
.pipe(optional)
|
|
63
|
+
.annotate({ description: 'Duration such as "4 minutes", or "auto" (default) for 90% of the model\'s cache.ttl' }),
|
|
64
|
+
duration: Schema.String.pipe(optional).annotate({ description: 'Duration such as "30 minutes"' }),
|
|
65
|
+
}),
|
|
66
|
+
]).annotate({ identifier: "Provider.CacheWarming" })
|
|
67
|
+
export type CacheWarming = typeof CacheWarming.Type
|
|
68
|
+
|
|
69
|
+
/** Prompt-cache settings. `ttl` is sent to the provider as given; each provider accepts its own set. */
|
|
70
|
+
export const Cache = Schema.Struct({
|
|
71
|
+
ttl: CacheTTL.pipe(optional),
|
|
72
|
+
warming: CacheWarming.pipe(optional),
|
|
73
|
+
}).annotate({ identifier: "Provider.Cache" })
|
|
74
|
+
export type Cache = typeof Cache.Type
|
|
75
|
+
|
|
76
|
+
/** HTTP request body compression; only endpoints known to decode it should enable it. */
|
|
77
|
+
export const Encoding = Schema.Literals(["zstd", "gzip", "none"]).annotate({ identifier: "Provider.Encoding" })
|
|
78
|
+
export type Encoding = typeof Encoding.Type
|
|
79
|
+
|
|
80
|
+
const Timeout = Schema.Union([Schema.Finite, Schema.Literal(false)]).pipe(optional)
|
|
81
|
+
|
|
82
|
+
/** Client certificate for gateways that require mutual TLS. Values are PEM text; use `{file:...}` to read a file. */
|
|
83
|
+
export const Tls = Schema.Struct({
|
|
84
|
+
cert: Schema.String.annotate({ description: "PEM client certificate, usually `{file:/path/to/client.pem}`" }),
|
|
85
|
+
key: Schema.String.annotate({ description: "PEM private key, usually `{file:/path/to/client.key}`" }),
|
|
86
|
+
passphrase: Schema.String.pipe(optional).annotate({ description: "Passphrase for an encrypted private key" }),
|
|
87
|
+
}).annotate({ identifier: "Provider.Tls" })
|
|
88
|
+
export type Tls = typeof Tls.Type
|
|
89
|
+
|
|
90
|
+
// The named fields are the settings OpenCode reads itself; every other key is a provider option for the provider package.
|
|
91
|
+
export const Settings = Schema.StructWithRest(
|
|
92
|
+
Schema.Struct({
|
|
93
|
+
timeout: Timeout,
|
|
94
|
+
headerTimeout: Timeout,
|
|
95
|
+
chunkTimeout: Timeout,
|
|
96
|
+
compaction: Compaction.pipe(optional),
|
|
97
|
+
cache: Cache.pipe(optional),
|
|
98
|
+
transport: Transport.pipe(optional),
|
|
99
|
+
encoding: Encoding.pipe(optional),
|
|
100
|
+
tls: Tls.pipe(optional),
|
|
101
|
+
}),
|
|
102
|
+
[Schema.Record(Schema.String, Schema.Any)],
|
|
103
|
+
).annotate({ identifier: "Provider.Settings" })
|
|
104
|
+
export type Settings = typeof Settings.Type
|
|
105
|
+
|
|
106
|
+
export const Overlays = {
|
|
107
|
+
settings: Settings.pipe(optional),
|
|
108
|
+
headers: Schema.Record(Schema.String, Schema.String).pipe(optional),
|
|
109
|
+
body: Schema.Record(Schema.String, Schema.Any).pipe(optional),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface Request extends Schema.Schema.Type<typeof Request> {}
|
|
113
|
+
export const Request = Schema.Struct({
|
|
114
|
+
settings: Settings.pipe(Schema.withConstructorDefault(Effect.succeed({}))),
|
|
115
|
+
headers: Schema.Record(Schema.String, Schema.String),
|
|
116
|
+
body: Schema.Record(Schema.String, Schema.Any),
|
|
117
|
+
}).annotate({ identifier: "Provider.Request" })
|
|
118
|
+
|
|
119
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
120
|
+
export const Info = Schema.Struct({
|
|
121
|
+
id: ID,
|
|
122
|
+
canonical: ID.pipe(optional),
|
|
123
|
+
integrationID: Integration.ID.pipe(optional),
|
|
124
|
+
name: Schema.String,
|
|
125
|
+
activation: Activation,
|
|
126
|
+
package: Package,
|
|
127
|
+
/** Inherited by every model of this provider; model compatibility overrides individual fields. */
|
|
128
|
+
compatibility: ProviderCompatibility.pipe(optional),
|
|
129
|
+
...Overlays,
|
|
130
|
+
})
|
|
131
|
+
.annotate({ identifier: "Provider.Info" })
|
|
132
|
+
.pipe(
|
|
133
|
+
statics(() => ({
|
|
134
|
+
empty: (id: ID): Info => ({ id, name: id, activation: "auto", package: "" }),
|
|
135
|
+
})),
|
|
136
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * as PtyTicket from "./pty-ticket.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { PositiveInt } from "./schema.js"
|
|
5
|
+
|
|
6
|
+
export const ConnectToken = Schema.Struct({
|
|
7
|
+
ticket: Schema.String,
|
|
8
|
+
expires_in: PositiveInt,
|
|
9
|
+
}).annotate({ identifier: "PtyTicket.ConnectToken" })
|
|
10
|
+
export interface ConnectToken extends Schema.Schema.Type<typeof ConnectToken> {}
|
package/src/pty.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export * as Pty from "./pty.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { ascending } from "./identifier.js"
|
|
7
|
+
import { NonNegativeInt, PositiveInt, statics } from "./schema.js"
|
|
8
|
+
|
|
9
|
+
const IDSchema = Schema.String.check(Schema.isStartingWith("pty")).pipe(
|
|
10
|
+
Schema.brand("PtyID"),
|
|
11
|
+
Schema.annotate({ identifier: "Pty.ID" }),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
export const ID = IDSchema.pipe(
|
|
15
|
+
statics((schema: typeof IDSchema) => {
|
|
16
|
+
const create = () => schema.make("pty_" + ascending())
|
|
17
|
+
return {
|
|
18
|
+
create,
|
|
19
|
+
ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
export type ID = typeof ID.Type
|
|
24
|
+
|
|
25
|
+
export const Info = Schema.Struct({
|
|
26
|
+
id: ID,
|
|
27
|
+
title: Schema.String,
|
|
28
|
+
command: Schema.String,
|
|
29
|
+
args: Schema.Array(Schema.String),
|
|
30
|
+
cwd: Schema.String,
|
|
31
|
+
status: Schema.Literals(["running", "exited"]),
|
|
32
|
+
pid: NonNegativeInt,
|
|
33
|
+
exitCode: optional(NonNegativeInt),
|
|
34
|
+
}).annotate({ identifier: "Pty" })
|
|
35
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
36
|
+
|
|
37
|
+
const Created = ephemeral({ type: "pty.created", schema: { info: Info } })
|
|
38
|
+
const Updated = ephemeral({ type: "pty.updated", schema: { info: Info } })
|
|
39
|
+
const Exited = ephemeral({ type: "pty.exited", schema: { id: ID, exitCode: NonNegativeInt } })
|
|
40
|
+
const Deleted = ephemeral({ type: "pty.deleted", schema: { id: ID } })
|
|
41
|
+
export const Event = { Created, Updated, Exited, Deleted, Definitions: inventory(Created, Updated, Exited, Deleted) }
|
|
42
|
+
|
|
43
|
+
export const CreateInput = Schema.Struct({
|
|
44
|
+
command: optional(Schema.String),
|
|
45
|
+
args: optional(Schema.Array(Schema.String)),
|
|
46
|
+
cwd: optional(Schema.String),
|
|
47
|
+
title: optional(Schema.String),
|
|
48
|
+
env: optional(Schema.Record(Schema.String, Schema.String)),
|
|
49
|
+
})
|
|
50
|
+
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
|
51
|
+
|
|
52
|
+
export const UpdateInput = Schema.Struct({
|
|
53
|
+
title: optional(Schema.String),
|
|
54
|
+
size: optional(
|
|
55
|
+
Schema.Struct({
|
|
56
|
+
rows: PositiveInt,
|
|
57
|
+
cols: PositiveInt,
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
})
|
|
61
|
+
export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {}
|