@zyro-sec/schema 1.0.0 → 1.0.2

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.
Files changed (136) hide show
  1. package/AGENTS.md +95 -0
  2. package/package.json +9 -11
  3. package/script/build.ts +9 -0
  4. package/script/config-schema.ts +86 -0
  5. package/script/config-v1.json +1312 -0
  6. package/script/pack.ts +5 -0
  7. package/src/agent.ts +68 -0
  8. package/src/artifact.ts +81 -0
  9. package/src/automation.ts +224 -0
  10. package/src/blob-store.ts +25 -0
  11. package/src/command.ts +18 -0
  12. package/src/config/agent.ts +26 -0
  13. package/src/config/command.ts +14 -0
  14. package/src/config/compaction.ts +27 -0
  15. package/src/config/experimental.ts +72 -0
  16. package/src/config/flag.ts +39 -0
  17. package/src/config/formatter.ts +13 -0
  18. package/src/config/lsp.ts +19 -0
  19. package/src/config/mcp.ts +22 -0
  20. package/src/config/media.ts +15 -0
  21. package/src/config/model.ts +37 -0
  22. package/src/config/plugin.ts +14 -0
  23. package/src/config/policy.ts +57 -0
  24. package/src/config/provider.ts +122 -0
  25. package/src/config/reference.ts +23 -0
  26. package/src/config/shell.ts +10 -0
  27. package/src/config/tool-output.ts +9 -0
  28. package/src/config/warming.ts +21 -0
  29. package/src/config/watcher.ts +8 -0
  30. package/src/config/websearch.ts +17 -0
  31. package/src/config/worktree.ts +10 -0
  32. package/src/config.ts +149 -0
  33. package/src/connection.ts +38 -0
  34. package/src/credential-legacy.ts +29 -0
  35. package/src/credential.ts +78 -0
  36. package/src/durable-event-manifest.ts +7 -0
  37. package/src/event-log.ts +21 -0
  38. package/src/event-manifest.ts +108 -0
  39. package/src/event.ts +205 -0
  40. package/src/file-diff.ts +25 -0
  41. package/src/filesystem-v1.ts +1 -0
  42. package/src/filesystem.ts +48 -0
  43. package/src/form.ts +177 -0
  44. package/src/generate.ts +292 -0
  45. package/src/goal.ts +46 -0
  46. package/src/identifier.ts +32 -0
  47. package/src/index.ts +51 -0
  48. package/src/installation-event.ts +20 -0
  49. package/src/instruction-entry.ts +40 -0
  50. package/src/instruction.ts +25 -0
  51. package/src/integration-id.ts +13 -0
  52. package/src/integration.ts +129 -0
  53. package/src/job.ts +79 -0
  54. package/src/legacy-event.ts +1 -0
  55. package/src/llm.ts +6 -0
  56. package/src/location-event.ts +8 -0
  57. package/src/location.ts +36 -0
  58. package/src/lsp-event.ts +7 -0
  59. package/src/mcp-event.ts +63 -0
  60. package/src/mcp.ts +171 -0
  61. package/src/model-compatibility.ts +55 -0
  62. package/src/model.ts +176 -0
  63. package/src/models-dev.ts +9 -0
  64. package/src/money.ts +18 -0
  65. package/src/permission-saved.ts +25 -0
  66. package/src/permission-v1.ts +1 -0
  67. package/src/permission.ts +67 -0
  68. package/src/persistent-pty.ts +73 -0
  69. package/src/plugin.ts +62 -0
  70. package/src/project-id.ts +9 -0
  71. package/src/project.ts +62 -0
  72. package/src/prompt-input.ts +33 -0
  73. package/src/prompt.ts +117 -0
  74. package/src/provider.ts +136 -0
  75. package/src/pty-ticket.ts +10 -0
  76. package/src/pty.ts +61 -0
  77. package/src/push.ts +86 -0
  78. package/src/question.ts +22 -0
  79. package/src/reference.ts +40 -0
  80. package/src/rpc.ts +167 -0
  81. package/src/schema.ts +41 -0
  82. package/src/server-event.ts +8 -0
  83. package/src/session-error.ts +14 -0
  84. package/src/session-event.ts +739 -0
  85. package/src/session-fork.ts +10 -0
  86. package/src/session-id.ts +12 -0
  87. package/src/session-inbox.ts +102 -0
  88. package/src/session-legacy.ts +117 -0
  89. package/src/session-message.ts +352 -0
  90. package/src/session-metadata.ts +11 -0
  91. package/src/session-revert.ts +86 -0
  92. package/src/session-stats.ts +68 -0
  93. package/src/session-status-event.ts +53 -0
  94. package/src/session-transfer.ts +11 -0
  95. package/src/session-v1.ts +1 -0
  96. package/src/session.ts +147 -0
  97. package/src/shell.ts +90 -0
  98. package/src/skill.ts +68 -0
  99. package/src/snapshot.ts +6 -0
  100. package/src/token-usage.ts +18 -0
  101. package/src/tool.ts +143 -0
  102. package/src/tui-event.ts +59 -0
  103. package/src/usage-limits.ts +76 -0
  104. package/src/v1/filesystem.ts +11 -0
  105. package/src/v1/legacy-event.ts +18 -0
  106. package/src/v1/permission.ts +66 -0
  107. package/src/v1/session.ts +667 -0
  108. package/src/vcs-event.ts +14 -0
  109. package/src/vcs.ts +41 -0
  110. package/src/websearch.ts +44 -0
  111. package/src/workspace-event.ts +32 -0
  112. package/src/workspace-id.ts +19 -0
  113. package/src/workspace.ts +20 -0
  114. package/src/worktree-event.ts +22 -0
  115. package/src/worktree.ts +109 -0
  116. package/test/agent.test.ts +10 -0
  117. package/test/automation.test.ts +48 -0
  118. package/test/compatibility.test.ts +10 -0
  119. package/test/config.test.ts +194 -0
  120. package/test/contract-hygiene.test.ts +352 -0
  121. package/test/credential-legacy.test.ts +55 -0
  122. package/test/event-manifest.test.ts +228 -0
  123. package/test/event.test.ts +52 -0
  124. package/test/legacy-event.test.ts +46 -0
  125. package/test/mcp.test.ts +37 -0
  126. package/test/model.test.ts +104 -0
  127. package/test/session-cursor.test.ts +16 -0
  128. package/test/session-error.test.ts +51 -0
  129. package/test/session-legacy.test.ts +178 -0
  130. package/test/session-terminal.test.ts +50 -0
  131. package/test/token-usage.test.ts +18 -0
  132. package/test/v1-isolation.test.ts +26 -0
  133. package/test/vcs.test.ts +23 -0
  134. package/test/worktree.test.ts +45 -0
  135. package/tsconfig.build.json +11 -0
  136. package/tsconfig.json +14 -0
package/src/job.ts ADDED
@@ -0,0 +1,79 @@
1
+ export * as Job from "./job.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { ephemeral, inventory } from "./event.js"
5
+ import { optional } from "./schema.js"
6
+ import { SessionID } from "./session-id.js"
7
+
8
+ export const Kind = Schema.Literals(["shell", "subagent", "image", "video", "codemode"]).annotate({
9
+ identifier: "Job.Kind",
10
+ })
11
+ export type Kind = typeof Kind.Type
12
+
13
+ export const Status = Schema.Literals(["running", "completed", "error", "cancelled"]).annotate({
14
+ identifier: "Job.Status",
15
+ })
16
+ export type Status = typeof Status.Type
17
+
18
+ export interface Time extends Schema.Schema.Type<typeof Time> {}
19
+ export const Time = Schema.Struct({
20
+ started: Schema.Finite.annotate({ description: "Start time in milliseconds since the Unix epoch" }),
21
+ completed: optional(Schema.Finite).annotate({
22
+ description: "Completion time in milliseconds since the Unix epoch",
23
+ }),
24
+ }).annotate({ identifier: "Job.Time" })
25
+
26
+ const Base = {
27
+ id: Schema.String,
28
+ sessionID: SessionID,
29
+ status: Status,
30
+ title: optional(Schema.String),
31
+ time: Time,
32
+ }
33
+
34
+ export interface Shell extends Schema.Schema.Type<typeof Shell> {}
35
+ export const Shell = Schema.Struct({
36
+ kind: Schema.tag("shell"),
37
+ ...Base,
38
+ shellID: Schema.String,
39
+ command: Schema.String,
40
+ }).annotate({ identifier: "Job.Shell" })
41
+
42
+ export interface Subagent extends Schema.Schema.Type<typeof Subagent> {}
43
+ export const Subagent = Schema.Struct({
44
+ kind: Schema.tag("subagent"),
45
+ ...Base,
46
+ childSessionID: SessionID,
47
+ agent: Schema.String,
48
+ description: Schema.String,
49
+ }).annotate({ identifier: "Job.Subagent" })
50
+
51
+ export interface Image extends Schema.Schema.Type<typeof Image> {}
52
+ export const Image = Schema.Struct({
53
+ kind: Schema.tag("image"),
54
+ ...Base,
55
+ path: Schema.String,
56
+ model: Schema.String,
57
+ }).annotate({ identifier: "Job.Image" })
58
+
59
+ export interface Video extends Schema.Schema.Type<typeof Video> {}
60
+ export const Video = Schema.Struct({
61
+ kind: Schema.tag("video"),
62
+ ...Base,
63
+ path: Schema.String,
64
+ }).annotate({ identifier: "Job.Video" })
65
+
66
+ export interface CodeMode extends Schema.Schema.Type<typeof CodeMode> {}
67
+ export const CodeMode = Schema.Struct({ kind: Schema.tag("codemode"), ...Base }).annotate({
68
+ identifier: "Job.CodeMode",
69
+ })
70
+
71
+ export const Info = Schema.Union([Shell, Subagent, Image, Video, CodeMode]).pipe(
72
+ Schema.toTaggedUnion("kind"),
73
+ Schema.annotate({ identifier: "Job.Info" }),
74
+ )
75
+ export type Info = typeof Info.Type
76
+
77
+ /** A background job started, moved to the background, or ended. Experimental: may change without compatibility guarantees. */
78
+ const Updated = ephemeral({ type: "experimental.job.updated", schema: { info: Info } })
79
+ export const Event = { Updated, Definitions: inventory(Updated) }
@@ -0,0 +1 @@
1
+ export * from "./v1/legacy-event.js"
package/src/llm.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * as LLM from "./llm.js"
2
+
3
+ import { Schema } from "effect"
4
+
5
+ export const FinishReason = Schema.Literals(["stop", "length", "tool-calls", "content-filter", "error", "unknown"])
6
+ export type FinishReason = typeof FinishReason.Type
@@ -0,0 +1,8 @@
1
+ export * as LocationEvent from "./location-event.js"
2
+
3
+ import { ephemeral, inventory } from "./event.js"
4
+
5
+ /** The location's cached services were shut down; clients must revalidate its reads. */
6
+ export const Shutdown = ephemeral({ type: "location.shutdown", schema: {} })
7
+
8
+ export const Definitions = inventory(Shutdown)
@@ -0,0 +1,36 @@
1
+ export * as Location from "./location.js"
2
+
3
+ import { Schema, Struct } from "effect"
4
+ import { AbsolutePath, optional } from "./schema.js"
5
+ import { ProjectID } from "./project-id.js"
6
+ import { WorkspaceID } from "./workspace-id.js"
7
+
8
+ export interface Ref extends Schema.Schema.Type<typeof Ref> {}
9
+ export const Ref = Schema.Struct({
10
+ directory: AbsolutePath,
11
+ workspaceID: optional(WorkspaceID),
12
+ }).annotate({ identifier: "Location.Ref" })
13
+
14
+ export const PublicRef = Schema.Struct(Struct.omit(Ref.fields, ["workspaceID"])).annotate({
15
+ identifier: "Location.PublicRef",
16
+ })
17
+ export interface PublicRef extends Schema.Schema.Type<typeof PublicRef> {}
18
+
19
+ export class Info extends Schema.Class<Info>("Location.Info")({
20
+ directory: AbsolutePath,
21
+ workspaceID: optional(WorkspaceID),
22
+ project: Schema.Struct({
23
+ id: ProjectID,
24
+ directory: AbsolutePath,
25
+ canonical: AbsolutePath,
26
+ }),
27
+ }) {}
28
+
29
+ export const PublicInfo = Schema.Struct(Struct.omit(Info.fields, ["workspaceID"])).annotate({
30
+ identifier: "Location.PublicInfo",
31
+ })
32
+ export interface PublicInfo extends Schema.Schema.Type<typeof PublicInfo> {}
33
+
34
+ export function response<S extends Schema.Top>(data: S) {
35
+ return Schema.Struct({ location: PublicRef, data })
36
+ }
@@ -0,0 +1,7 @@
1
+ export * as LspEvent from "./lsp-event.js"
2
+
3
+ import { Event } from "./event.js"
4
+
5
+ export const Updated = Event.ephemeral({ type: "lsp.updated", schema: {} })
6
+
7
+ export const Definitions = Event.inventory(Updated)
@@ -0,0 +1,63 @@
1
+ export * as McpEvent from "./mcp-event.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { Event } from "./event.js"
5
+
6
+ export const ToolsChanged = Event.ephemeral({
7
+ type: "mcp.tools.changed",
8
+ schema: {
9
+ server: Schema.String,
10
+ },
11
+ })
12
+
13
+ export const ResourcesChanged = Event.ephemeral({
14
+ type: "mcp.resources.changed",
15
+ schema: {
16
+ server: Schema.String,
17
+ },
18
+ })
19
+
20
+ // Emitted whenever a server's connection status settles (connected, failed, needs_auth, closed) so
21
+ // observers can refresh status without polling.
22
+ export const StatusChanged = Event.ephemeral({
23
+ type: "mcp.status.changed",
24
+ schema: {
25
+ server: Schema.String,
26
+ },
27
+ })
28
+
29
+ // Experimental: MCP Events is a draft extension; may change without compatibility guarantees.
30
+
31
+ /** One event from an MCP Events subscription. Delivery is at least once: dedupe on `id` and `eventId`. */
32
+ export const ExperimentalEvent = Event.ephemeral({
33
+ type: "experimental.mcp.event",
34
+ schema: {
35
+ /** The subscription that received it. */
36
+ id: Schema.String,
37
+ server: Schema.String,
38
+ name: Schema.String,
39
+ eventId: Schema.String,
40
+ timestamp: Schema.String,
41
+ data: Schema.Json,
42
+ /** Where the subscription resumes from after this event; null when the event type has no replay. */
43
+ cursor: Schema.NullOr(Schema.String),
44
+ /** The server skipped events before this one, which it could not replay. */
45
+ truncated: Schema.optional(Schema.Boolean),
46
+ },
47
+ })
48
+
49
+ /** A subscription's status changed; read it with the MCP service's `subscriptions`. */
50
+ export const ExperimentalSubscriptionChanged = Event.ephemeral({
51
+ type: "experimental.mcp.subscription.changed",
52
+ schema: {
53
+ id: Schema.String,
54
+ },
55
+ })
56
+
57
+ export const Definitions = Event.inventory(
58
+ ToolsChanged,
59
+ ResourcesChanged,
60
+ StatusChanged,
61
+ ExperimentalEvent,
62
+ ExperimentalSubscriptionChanged,
63
+ )
package/src/mcp.ts ADDED
@@ -0,0 +1,171 @@
1
+ export * as Mcp from "./mcp.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional, PositiveInt } from "./schema.js"
5
+ import { IntegrationID } from "./integration-id.js"
6
+
7
+ export class TimeoutConfig extends Schema.Class<TimeoutConfig>("Mcp.TimeoutConfig")({
8
+ startup: PositiveInt.pipe(optional).annotate({
9
+ description: "Maximum time in milliseconds to establish and initialize the MCP server.",
10
+ }),
11
+ catalog: PositiveInt.pipe(optional).annotate({
12
+ description: "Maximum time in milliseconds to wait for MCP discovery requests such as tools/list and prompts/list.",
13
+ }),
14
+ execution: PositiveInt.pipe(optional).annotate({
15
+ description: "Maximum time in milliseconds to wait for MCP tool and prompt execution.",
16
+ }),
17
+ }) {}
18
+
19
+ export type Protocol = typeof Protocol.Type
20
+ export const Protocol = Schema.Literals(["legacy", "auto", "2026-07-28"]).annotate({
21
+ identifier: "Mcp.Protocol",
22
+ description:
23
+ 'MCP protocol negotiation. "auto" (default) probes for the 2026-07-28 revision and falls back to legacy when the server does not support it. "legacy" opens with the initialize handshake and speaks protocol revisions up to 2025-11-25. "2026-07-28" requires that revision and fails otherwise.',
24
+ })
25
+
26
+ export class LocalConfig extends Schema.Class<LocalConfig>("Mcp.LocalConfig")({
27
+ type: Schema.Literal("local"),
28
+ command: Schema.String.pipe(Schema.Array),
29
+ cwd: Schema.String.pipe(optional).annotate({
30
+ description: "Working directory for the MCP server process. Relative paths resolve from the workspace directory.",
31
+ }),
32
+ environment: Schema.Record(Schema.String, Schema.String).pipe(optional),
33
+ disabled: Schema.Boolean.pipe(optional),
34
+ codemode: Schema.Boolean.pipe(optional).annotate({
35
+ description: "Expose this server's tools through Code Mode. Defaults to true.",
36
+ }),
37
+ timeout: TimeoutConfig.pipe(optional),
38
+ protocol: Protocol.pipe(optional),
39
+ pool: Schema.Boolean.pipe(optional).annotate({
40
+ description:
41
+ 'Share one connection to this server across every directory that configures it identically, instead of one per directory. Only connections that negotiate the 2026-07-28 revision are shared; an unset "protocol" becomes "auto", and "legacy" never shares. Defaults to false.',
42
+ }),
43
+ }) {}
44
+
45
+ export class OAuthConfig extends Schema.Class<OAuthConfig>("Mcp.OAuthConfig")({
46
+ client_id: Schema.String.pipe(optional),
47
+ client_secret: Schema.String.pipe(optional),
48
+ scope: Schema.String.pipe(optional),
49
+ callback_port: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 })).pipe(optional),
50
+ redirect_uri: Schema.String.pipe(optional),
51
+ auth_server_metadata_url: Schema.String.pipe(optional).annotate({
52
+ description:
53
+ "URL of the OAuth or OpenID Connect authorization server metadata document. Set when the MCP server does not publish protected resource metadata that names its authorization server.",
54
+ }),
55
+ }) {}
56
+
57
+ export class RemoteConfig extends Schema.Class<RemoteConfig>("Mcp.RemoteConfig")({
58
+ type: Schema.Literal("remote"),
59
+ url: Schema.String,
60
+ headers: Schema.Record(Schema.String, Schema.String).pipe(optional),
61
+ oauth: Schema.Union([OAuthConfig, Schema.Literal(false)]).pipe(optional),
62
+ disabled: Schema.Boolean.pipe(optional),
63
+ codemode: Schema.Boolean.pipe(optional).annotate({
64
+ description: "Expose this server's tools through Code Mode. Defaults to true.",
65
+ }),
66
+ timeout: TimeoutConfig.pipe(optional),
67
+ protocol: Protocol.pipe(optional),
68
+ pool: Schema.Boolean.pipe(optional).annotate({
69
+ description:
70
+ 'Share one connection to this server across every directory that configures it identically, instead of one per directory. Only connections that negotiate the 2026-07-28 revision are shared; an unset "protocol" becomes "auto", and "legacy" never shares. Defaults to false.',
71
+ }),
72
+ }) {}
73
+
74
+ export const ServerConfig = Schema.Union([LocalConfig, RemoteConfig]).pipe(Schema.toTaggedUnion("type"))
75
+ export type ServerConfig = typeof ServerConfig.Type
76
+
77
+ const Connected = Schema.Struct({ status: Schema.Literal("connected") }).annotate({
78
+ identifier: "Mcp.Status.Connected",
79
+ })
80
+ const Pending = Schema.Struct({ status: Schema.Literal("pending") }).annotate({
81
+ identifier: "Mcp.Status.Pending",
82
+ })
83
+ const Disabled = Schema.Struct({ status: Schema.Literal("disabled") }).annotate({
84
+ identifier: "Mcp.Status.Disabled",
85
+ })
86
+ const Failed = Schema.Struct({ status: Schema.Literal("failed"), error: Schema.String }).annotate({
87
+ identifier: "Mcp.Status.Failed",
88
+ })
89
+ const NeedsAuth = Schema.Struct({ status: Schema.Literal("needs_auth"), error: Schema.String }).annotate({
90
+ identifier: "Mcp.Status.NeedsAuth",
91
+ })
92
+
93
+ export type Status = typeof Status.Type
94
+ export const Status = Schema.Union([Connected, Pending, Disabled, Failed, NeedsAuth]).pipe(
95
+ Schema.toTaggedUnion("status"),
96
+ )
97
+
98
+ /**
99
+ * An MCP Events subscription: `pending` until its server confirms the stream, `active` while it does, and `ended` when
100
+ * the server terminated or rejected it, or no longer offers events. Pending covers a server that is not connected.
101
+ * Experimental: MCP Events is a draft extension; may change without compatibility guarantees.
102
+ */
103
+ export const SubscriptionStatus = Schema.Union([
104
+ Schema.Struct({ status: Schema.Literal("pending") }),
105
+ Schema.Struct({ status: Schema.Literal("active") }),
106
+ Schema.Struct({ status: Schema.Literal("ended"), reason: Schema.Literal("unavailable") }),
107
+ Schema.Struct({
108
+ status: Schema.Literal("ended"),
109
+ reason: Schema.Literals(["terminated", "rejected"]),
110
+ error: Schema.Struct({ code: Schema.Number, message: Schema.String }),
111
+ }),
112
+ ]).annotate({ identifier: "Mcp.SubscriptionStatus" })
113
+ export type SubscriptionStatus = typeof SubscriptionStatus.Type
114
+
115
+ export interface Server extends Schema.Schema.Type<typeof Server> {}
116
+ export const Server = Schema.Struct({
117
+ name: Schema.String,
118
+ status: Status,
119
+ // Display title from the connected server's `serverInfo.title`; absent while disconnected or when not provided.
120
+ title: optional(Schema.String),
121
+ // Set for remote servers registered as OAuth integrations; lets clients act on the right integration
122
+ // without matching by name, which could collide with provider or plugin integrations.
123
+ integrationID: optional(IntegrationID),
124
+ }).annotate({ identifier: "Mcp.Server" })
125
+
126
+ export interface Resource extends Schema.Schema.Type<typeof Resource> {}
127
+ export const Resource = Schema.Struct({
128
+ server: Schema.String,
129
+ name: Schema.String,
130
+ uri: Schema.String,
131
+ description: optional(Schema.String),
132
+ mimeType: optional(Schema.String),
133
+ }).annotate({ identifier: "Mcp.Resource" })
134
+
135
+ export interface ResourceTemplate extends Schema.Schema.Type<typeof ResourceTemplate> {}
136
+ export const ResourceTemplate = Schema.Struct({
137
+ server: Schema.String,
138
+ name: Schema.String,
139
+ uriTemplate: Schema.String,
140
+ description: optional(Schema.String),
141
+ mimeType: optional(Schema.String),
142
+ }).annotate({ identifier: "Mcp.ResourceTemplate" })
143
+
144
+ export interface ResourceCatalog extends Schema.Schema.Type<typeof ResourceCatalog> {}
145
+ export const ResourceCatalog = Schema.Struct({
146
+ resources: Schema.Array(Resource),
147
+ templates: Schema.Array(ResourceTemplate),
148
+ }).annotate({ identifier: "Mcp.ResourceCatalog" })
149
+
150
+ export const ResourceContentPart = Schema.Union([
151
+ Schema.Struct({
152
+ type: Schema.Literal("text"),
153
+ uri: Schema.String,
154
+ text: Schema.String,
155
+ mimeType: optional(Schema.String),
156
+ }),
157
+ Schema.Struct({
158
+ type: Schema.Literal("blob"),
159
+ uri: Schema.String,
160
+ blob: Schema.String,
161
+ mimeType: optional(Schema.String),
162
+ }),
163
+ ]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Mcp.ResourceContentPart" }))
164
+ export type ResourceContentPart = typeof ResourceContentPart.Type
165
+
166
+ export interface ResourceContent extends Schema.Schema.Type<typeof ResourceContent> {}
167
+ export const ResourceContent = Schema.Struct({
168
+ server: Schema.String,
169
+ uri: Schema.String,
170
+ contents: Schema.Array(ResourceContentPart),
171
+ }).annotate({ identifier: "Mcp.ResourceContent" })
@@ -0,0 +1,55 @@
1
+ import { Schema, Struct } from "effect"
2
+ import { optional } from "./schema.js"
3
+
4
+ // Shared by model and provider schemas; kept separate because model.ts imports provider.ts.
5
+ export type ReasoningField = "reasoning" | "reasoning_content" | "reasoning_text" | (string & {})
6
+ export const ReasoningField: Schema.Codec<ReasoningField> = Schema.Union([
7
+ Schema.Literals(["reasoning", "reasoning_content", "reasoning_text"]),
8
+ Schema.String,
9
+ ]).annotate({ identifier: "Model.ReasoningField" })
10
+
11
+ export const MaxTokensField = Schema.Literals(["max_completion_tokens", "max_tokens"]).annotate({
12
+ identifier: "Model.MaxTokensField",
13
+ })
14
+ export type MaxTokensField = typeof MaxTokensField.Type
15
+
16
+ /** Where a System One decision host reads media, from models.dev `compatibility.media_input`. */
17
+ export const MediaInput = Schema.Literals(["assets", "state", "root"]).annotate({
18
+ identifier: "Model.MediaInput",
19
+ })
20
+ export type MediaInput = typeof MediaInput.Type
21
+
22
+ export const CacheFormat = Schema.Literals(["anthropic", "alibaba"]).annotate({ identifier: "Model.CacheFormat" })
23
+ export type CacheFormat = typeof CacheFormat.Type
24
+
25
+ export interface Compatibility extends Schema.Schema.Type<typeof Compatibility> {}
26
+ export const Compatibility = Schema.Struct({
27
+ /** OpenAI Chat: assistant-message field that carries reasoning. Unset uses the streamed field, else `reasoning_content`. */
28
+ reasoningField: ReasoningField.pipe(optional),
29
+ /** OpenAI Chat: send the reasoning field on every prior assistant message, even when empty. */
30
+ requireReasoning: Schema.Boolean.pipe(optional),
31
+ /** OpenAI Chat: body field for the output token limit. Unset detects it from the provider. */
32
+ maxTokensField: MaxTokensField.pipe(optional),
33
+ /** OpenAI Chat: fail a stream that ends without `finish_reason`. Defaults to true. */
34
+ requireFinishReason: Schema.Boolean.pipe(optional),
35
+ /** OpenAI Chat: insert an assistant message between a tool result and the next user message. */
36
+ requireAssistantAfterTool: Schema.Boolean.pipe(optional),
37
+ /** OpenAI Chat, OpenAI Responses and Mistral: whether the endpoint accepts `prompt_cache_key`. */
38
+ supportsPromptCacheKey: Schema.Boolean.pipe(optional),
39
+ /** OpenAI Chat: request usage in the stream with `stream_options.include_usage`. Defaults to true. */
40
+ streamUsage: Schema.Boolean.pipe(optional),
41
+ /** Prompt-cache marker syntax the endpoint accepts. Overrides the route default; both send `cache_control`, and `alibaba` skips tool definitions. */
42
+ cacheFormat: CacheFormat.pipe(optional),
43
+ /** Anthropic Messages and Bedrock Converse: supports Anthropic's thinking-prefix mismatch controls. Overrides model-ID detection. */
44
+ supportsThinkingBlockBinding: Schema.Boolean.pipe(optional),
45
+ /** Anthropic Messages and OpenAI Responses: supports per-message effort updates. Overrides model-ID detection. */
46
+ supportsEffortUpdates: Schema.Boolean.pipe(optional),
47
+ /** System One: where the decision host reads media. Unset keeps the route default. */
48
+ mediaInput: MediaInput.pipe(optional),
49
+ }).annotate({ identifier: "Model.Compatibility" })
50
+
51
+ // Provider defaults inherited by its models. Model-version features stay model-only.
52
+ export interface ProviderCompatibility extends Schema.Schema.Type<typeof ProviderCompatibility> {}
53
+ export const ProviderCompatibility = Schema.Struct(
54
+ Struct.omit(Compatibility.fields, ["supportsThinkingBlockBinding", "supportsEffortUpdates"]),
55
+ ).annotate({ identifier: "Provider.Compatibility" })
package/src/model.ts ADDED
@@ -0,0 +1,176 @@
1
+ export * as Model from "./model.js"
2
+
3
+ import { Schema, Struct } from "effect"
4
+ import { optional, statics } from "./schema.js"
5
+ import { Provider } from "./provider.js"
6
+ import { Compatibility, MaxTokensField, MediaInput, ReasoningField } from "./model-compatibility.js"
7
+ import { Money } from "./money.js"
8
+ import { FreeformFormat } from "./tool.js"
9
+ import { ephemeral, inventory } from "./event.js"
10
+
11
+ export const ID = Schema.String.pipe(Schema.brand("Model.ID"))
12
+ export type ID = typeof ID.Type
13
+
14
+ const Updated = ephemeral({ type: "model.updated", schema: {} })
15
+ export const Event = { Updated, Definitions: inventory(Updated) }
16
+
17
+ export const VariantID = Schema.String.pipe(Schema.brand("Model.VariantID"))
18
+ export type VariantID = typeof VariantID.Type
19
+
20
+ export const Ref = Schema.Struct({
21
+ id: ID,
22
+ providerID: Provider.ID,
23
+ variant: VariantID.pipe(optional),
24
+ })
25
+ .annotate({ identifier: "Model.Ref" })
26
+ .pipe(
27
+ statics((schema) => ({
28
+ parse: (input: string) => {
29
+ const providerEnd = input.indexOf("/")
30
+ if (providerEnd <= 0) throw new Error(`Invalid model reference: ${input}`)
31
+ const providerID = input.slice(0, providerEnd)
32
+ const variantStart = input.indexOf("#", providerEnd + 1)
33
+ const id = input.slice(providerEnd + 1, variantStart === -1 ? undefined : variantStart)
34
+ const variant = variantStart === -1 ? undefined : input.slice(variantStart + 1)
35
+ if (!id || providerID.includes("#") || (variant !== undefined && (!variant || variant.includes("#"))))
36
+ throw new Error(`Invalid model reference: ${input}`)
37
+ return schema.make({
38
+ providerID: Provider.ID.make(providerID),
39
+ id: ID.make(id),
40
+ ...(variant ? { variant: VariantID.make(variant) } : {}),
41
+ })
42
+ },
43
+ })),
44
+ )
45
+ export interface Ref extends Schema.Schema.Type<typeof Ref> {}
46
+
47
+ export { Compatibility, MaxTokensField, MediaInput, ReasoningField }
48
+
49
+ export const Family = Schema.String.pipe(Schema.brand("Model.Family"))
50
+ export type Family = typeof Family.Type
51
+
52
+ /** What a model produces, from models.dev. Open-ended: new types keep being added. Only chat models are offered for sessions; an unset type means chat. */
53
+ export type Type = "chat" | "decision" | "image" | "video" | (string & {})
54
+ export const Type: Schema.Codec<Type> = Schema.Union([
55
+ Schema.Literals(["chat", "decision", "image", "video"]),
56
+ Schema.String,
57
+ ]).annotate({ identifier: "Model.Type" })
58
+
59
+ export const Settings = Schema.StructWithRest(
60
+ Schema.Struct(Struct.pick(Provider.Settings.schema.fields, ["compaction", "cache", "encoding"])),
61
+ // Provider packages may define arbitrary model-level options beyond OpenCode's shared compaction policy.
62
+ [Schema.Record(Schema.String, Schema.Any)],
63
+ ).annotate({ identifier: "Model.Settings" })
64
+ export type Settings = typeof Settings.Type
65
+
66
+ // Variants switch request settings. The prompt cache belongs to the model, so a variant can't change it.
67
+ const VariantSettings = Schema.StructWithRest(
68
+ Schema.Struct(Struct.omit(Settings.schema.fields, ["cache"])),
69
+ Settings.records,
70
+ ).annotate({ identifier: "Model.VariantSettings" })
71
+
72
+ export const Overlays = {
73
+ settings: Settings.pipe(optional),
74
+ headers: Schema.Record(Schema.String, Schema.String).pipe(optional),
75
+ body: Schema.Record(Schema.String, Schema.Any).pipe(optional),
76
+ }
77
+
78
+ export interface Capabilities extends Schema.Schema.Type<typeof Capabilities> {}
79
+ export const Capabilities = Schema.Struct({
80
+ tools: Schema.Boolean,
81
+ /** Freeform tool input formats advertised by the selected API. Absent or empty means JSON tools only. */
82
+ freeform: Schema.Array(FreeformFormat).pipe(optional),
83
+ input: Schema.Array(Schema.String),
84
+ output: Schema.Array(Schema.String),
85
+ /** Whether the model accepts a sampling temperature. Unknown when unset. */
86
+ temperature: Schema.Boolean.pipe(optional),
87
+ })
88
+ .annotate({ identifier: "Model.Capabilities" })
89
+ .pipe(
90
+ statics(() => ({
91
+ default: () => ({ tools: true, input: ["text", "image"], output: ["text"] }) satisfies Capabilities,
92
+ })),
93
+ )
94
+
95
+ export interface Cost extends Schema.Schema.Type<typeof Cost> {}
96
+ export const Cost = Schema.Struct({
97
+ tier: Schema.Struct({
98
+ type: Schema.tag("context"),
99
+ size: Schema.Int,
100
+ }).pipe(optional),
101
+ input: Money.USDPerMillionTokens,
102
+ output: Money.USDPerMillionTokens,
103
+ cache: Schema.Struct({
104
+ read: Money.USDPerMillionTokens,
105
+ write: Money.USDPerMillionTokens,
106
+ }),
107
+ }).annotate({ identifier: "Model.Cost" })
108
+
109
+ export interface Variant extends Schema.Schema.Type<typeof Variant> {}
110
+ export const Variant = Schema.Struct({
111
+ id: VariantID,
112
+ ...Overlays,
113
+ settings: VariantSettings.pipe(optional),
114
+ }).annotate({ identifier: "Model.Variant" })
115
+
116
+ /**
117
+ * Set on a model that is another model served faster or slower, such as "gpt-5.5-fast" for "gpt-5.5". Clients offer
118
+ * it as a speed of that model instead of listing it.
119
+ */
120
+ export interface Speed extends Schema.Schema.Type<typeof Speed> {}
121
+ export const Speed = Schema.Struct({
122
+ /** The same provider's model at its standard speed. */
123
+ base: ID,
124
+ /** The speed's name, such as "fast" or "flex". */
125
+ id: Schema.String,
126
+ /** Whether it is faster than the standard speed. A slower speed trades latency for a lower price. */
127
+ faster: Schema.Boolean,
128
+ }).annotate({ identifier: "Model.Speed" })
129
+
130
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
131
+ export const Info = Schema.Struct({
132
+ id: ID,
133
+ modelID: ID,
134
+ providerID: Provider.ID,
135
+ canonical: Provider.ID.pipe(optional),
136
+ type: Type.pipe(optional),
137
+ family: Family.pipe(optional),
138
+ name: Schema.String,
139
+ compatibility: Compatibility.pipe(optional),
140
+ package: Provider.Package.pipe(optional),
141
+ ...Overlays,
142
+ capabilities: Capabilities,
143
+ variants: Schema.Array(Variant),
144
+ /** Experimental: may change without compatibility guarantees. */
145
+ experimental: Schema.Struct({ speed: Speed.pipe(optional) }).pipe(optional),
146
+ time: Schema.Struct({
147
+ released: Schema.Finite,
148
+ }),
149
+ cost: Schema.Array(Cost),
150
+ status: Schema.Literals(["alpha", "beta", "deprecated", "active"]),
151
+ enabled: Schema.Boolean,
152
+ limit: Schema.Struct({
153
+ context: Schema.Int,
154
+ input: Schema.Int.pipe(optional),
155
+ output: Schema.Int,
156
+ }),
157
+ })
158
+ .annotate({ identifier: "Model.Info" })
159
+ .pipe(
160
+ statics(() => ({
161
+ default: (providerID: Provider.ID, id: ID) =>
162
+ ({
163
+ id,
164
+ modelID: id,
165
+ providerID,
166
+ name: id,
167
+ capabilities: Capabilities.default(),
168
+ variants: [],
169
+ time: { released: 0 },
170
+ cost: [],
171
+ status: "active",
172
+ enabled: true,
173
+ limit: { context: 200_000, output: 32_000 },
174
+ }) satisfies Info,
175
+ })),
176
+ )
@@ -0,0 +1,9 @@
1
+ export * as ModelsDev from "./models-dev.js"
2
+
3
+ import { ephemeral, inventory } from "./event.js"
4
+
5
+ const Refreshed = ephemeral({
6
+ type: "models-dev.refreshed",
7
+ schema: {},
8
+ })
9
+ export const Event = { Refreshed, Definitions: inventory(Refreshed) }
package/src/money.ts ADDED
@@ -0,0 +1,18 @@
1
+ export * as Money from "./money.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { statics } from "./schema.js"
5
+
6
+ export const USD = Schema.Finite.pipe(
7
+ Schema.brand("Money.USD"),
8
+ Schema.annotate({ identifier: "Money.USD" }),
9
+ statics((schema) => ({ zero: schema.make(0) })),
10
+ )
11
+ export type USD = typeof USD.Type
12
+
13
+ export const USDPerMillionTokens = Schema.Finite.pipe(
14
+ Schema.brand("Money.USDPerMillionTokens"),
15
+ Schema.annotate({ identifier: "Money.USDPerMillionTokens" }),
16
+ statics((schema) => ({ zero: schema.make(0) })),
17
+ )
18
+ export type USDPerMillionTokens = typeof USDPerMillionTokens.Type
@@ -0,0 +1,25 @@
1
+ export * as PermissionSaved from "./permission-saved.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { ascending } from "./identifier.js"
5
+ import { ProjectID } from "./project-id.js"
6
+ import { DateTimeUtcFromMillis, statics } from "./schema.js"
7
+
8
+ export const ID = Schema.String.pipe(
9
+ Schema.brand("PermissionSaved.ID"),
10
+ Schema.annotate({ identifier: "PermissionSaved.ID" }),
11
+ statics((schema) => ({ create: () => schema.make("psv_" + ascending()) })),
12
+ )
13
+ export type ID = typeof ID.Type
14
+
15
+ export const Info = Schema.Struct({
16
+ id: ID,
17
+ projectID: ProjectID,
18
+ action: Schema.String,
19
+ resource: Schema.String,
20
+ time: Schema.Struct({
21
+ created: DateTimeUtcFromMillis,
22
+ updated: DateTimeUtcFromMillis,
23
+ }),
24
+ }).annotate({ identifier: "PermissionSaved.Info" })
25
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
@@ -0,0 +1 @@
1
+ export * from "./v1/permission.js"