@zyro-sec/schema 1.0.1 → 1.0.3

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 -95
  2. package/package.json +5 -1
  3. package/script/build.ts +9 -9
  4. package/script/config-schema.ts +86 -86
  5. package/script/config-v1.json +1311 -1311
  6. package/script/pack.ts +5 -5
  7. package/src/agent.ts +68 -68
  8. package/src/artifact.ts +81 -81
  9. package/src/automation.ts +224 -224
  10. package/src/blob-store.ts +25 -25
  11. package/src/command.ts +18 -18
  12. package/src/config/agent.ts +26 -26
  13. package/src/config/command.ts +14 -14
  14. package/src/config/compaction.ts +27 -27
  15. package/src/config/experimental.ts +72 -72
  16. package/src/config/flag.ts +39 -39
  17. package/src/config/formatter.ts +13 -13
  18. package/src/config/lsp.ts +19 -19
  19. package/src/config/mcp.ts +22 -22
  20. package/src/config/media.ts +15 -15
  21. package/src/config/model.ts +37 -37
  22. package/src/config/plugin.ts +14 -14
  23. package/src/config/policy.ts +57 -57
  24. package/src/config/provider.ts +122 -122
  25. package/src/config/reference.ts +23 -23
  26. package/src/config/shell.ts +10 -10
  27. package/src/config/tool-output.ts +9 -9
  28. package/src/config/warming.ts +21 -21
  29. package/src/config/watcher.ts +8 -8
  30. package/src/config/websearch.ts +17 -17
  31. package/src/config/worktree.ts +10 -10
  32. package/src/config.ts +149 -149
  33. package/src/connection.ts +38 -38
  34. package/src/credential-legacy.ts +29 -29
  35. package/src/credential.ts +78 -78
  36. package/src/durable-event-manifest.ts +7 -7
  37. package/src/event-log.ts +21 -21
  38. package/src/event-manifest.ts +108 -108
  39. package/src/event.ts +205 -205
  40. package/src/file-diff.ts +25 -25
  41. package/src/filesystem-v1.ts +1 -1
  42. package/src/filesystem.ts +48 -48
  43. package/src/form.ts +177 -177
  44. package/src/generate.ts +292 -292
  45. package/src/goal.ts +46 -46
  46. package/src/identifier.ts +32 -32
  47. package/src/index.ts +51 -51
  48. package/src/installation-event.ts +20 -20
  49. package/src/instruction-entry.ts +40 -40
  50. package/src/instruction.ts +25 -25
  51. package/src/integration-id.ts +13 -13
  52. package/src/integration.ts +129 -129
  53. package/src/job.ts +79 -79
  54. package/src/legacy-event.ts +1 -1
  55. package/src/llm.ts +6 -6
  56. package/src/location-event.ts +8 -8
  57. package/src/location.ts +36 -36
  58. package/src/lsp-event.ts +7 -7
  59. package/src/mcp-event.ts +63 -63
  60. package/src/mcp.ts +171 -171
  61. package/src/model-compatibility.ts +55 -55
  62. package/src/model.ts +176 -176
  63. package/src/models-dev.ts +9 -9
  64. package/src/money.ts +18 -18
  65. package/src/permission-saved.ts +25 -25
  66. package/src/permission-v1.ts +1 -1
  67. package/src/permission.ts +67 -67
  68. package/src/persistent-pty.ts +73 -73
  69. package/src/plugin.ts +62 -62
  70. package/src/project-id.ts +9 -9
  71. package/src/project.ts +62 -62
  72. package/src/prompt-input.ts +33 -33
  73. package/src/prompt.ts +117 -117
  74. package/src/provider.ts +136 -136
  75. package/src/pty-ticket.ts +10 -10
  76. package/src/pty.ts +61 -61
  77. package/src/push.ts +86 -86
  78. package/src/question.ts +22 -22
  79. package/src/reference.ts +40 -40
  80. package/src/rpc.ts +167 -167
  81. package/src/schema.ts +41 -41
  82. package/src/server-event.ts +8 -8
  83. package/src/session-error.ts +14 -14
  84. package/src/session-event.ts +739 -739
  85. package/src/session-fork.ts +10 -10
  86. package/src/session-id.ts +12 -12
  87. package/src/session-inbox.ts +102 -102
  88. package/src/session-legacy.ts +117 -117
  89. package/src/session-message.ts +352 -352
  90. package/src/session-metadata.ts +11 -11
  91. package/src/session-revert.ts +86 -86
  92. package/src/session-stats.ts +68 -68
  93. package/src/session-status-event.ts +53 -53
  94. package/src/session-transfer.ts +11 -11
  95. package/src/session-v1.ts +1 -1
  96. package/src/session.ts +147 -147
  97. package/src/shell.ts +90 -90
  98. package/src/skill.ts +68 -68
  99. package/src/snapshot.ts +6 -6
  100. package/src/token-usage.ts +18 -18
  101. package/src/tool.ts +143 -143
  102. package/src/tui-event.ts +59 -59
  103. package/src/usage-limits.ts +76 -76
  104. package/src/v1/filesystem.ts +11 -11
  105. package/src/v1/legacy-event.ts +18 -18
  106. package/src/v1/permission.ts +66 -66
  107. package/src/v1/session.ts +667 -667
  108. package/src/vcs-event.ts +14 -14
  109. package/src/vcs.ts +41 -41
  110. package/src/websearch.ts +44 -44
  111. package/src/workspace-event.ts +32 -32
  112. package/src/workspace-id.ts +19 -19
  113. package/src/workspace.ts +20 -20
  114. package/src/worktree-event.ts +22 -22
  115. package/src/worktree.ts +109 -109
  116. package/tsconfig.build.json +11 -11
  117. package/tsconfig.json +14 -14
  118. package/test/agent.test.ts +0 -10
  119. package/test/automation.test.ts +0 -48
  120. package/test/compatibility.test.ts +0 -10
  121. package/test/config.test.ts +0 -194
  122. package/test/contract-hygiene.test.ts +0 -352
  123. package/test/credential-legacy.test.ts +0 -55
  124. package/test/event-manifest.test.ts +0 -228
  125. package/test/event.test.ts +0 -52
  126. package/test/legacy-event.test.ts +0 -46
  127. package/test/mcp.test.ts +0 -37
  128. package/test/model.test.ts +0 -104
  129. package/test/session-cursor.test.ts +0 -16
  130. package/test/session-error.test.ts +0 -51
  131. package/test/session-legacy.test.ts +0 -178
  132. package/test/session-terminal.test.ts +0 -50
  133. package/test/token-usage.test.ts +0 -18
  134. package/test/v1-isolation.test.ts +0 -26
  135. package/test/vcs.test.ts +0 -23
  136. package/test/worktree.test.ts +0 -45
@@ -1,352 +1,352 @@
1
- export * as SessionMessage from "./session-message.js"
2
-
3
- import { Schema } from "effect"
4
- import { optional } from "./schema.js"
5
- import { Content } from "./tool.js"
6
- import { Location } from "./location.js"
7
- import { Model } from "./model.js"
8
- import { Project } from "./project.js"
9
- import { Attachment, Prompt } from "./prompt.js"
10
- import { DateTimeUtcFromMillis, PositiveInt, RelativePath, statics } from "./schema.js"
11
- import { ascending } from "./identifier.js"
12
- import { Shell as ShellSchema } from "./shell.js"
13
- import { FinishReason } from "./llm.js"
14
- import { SessionError } from "./session-error.js"
15
- import { Agent } from "./agent.js"
16
- import { Skill as SkillSchema } from "./skill.js"
17
- import { Money } from "./money.js"
18
- import { Snapshot } from "./snapshot.js"
19
- import { TokenUsage } from "./token-usage.js"
20
-
21
- export const ID = Schema.String.check(Schema.isStartingWith("msg_")).pipe(
22
- Schema.brand("Session.Message.ID"),
23
- Schema.annotate({ identifier: "Session.Message.ID" }),
24
- statics((schema) => ({
25
- create: () => schema.make("msg_" + ascending()),
26
- fromEvent: (eventID: string) => schema.make(eventID.replace(/^evt_/, "msg_")),
27
- })),
28
- )
29
- export type ID = typeof ID.Type
30
-
31
- const Base = {
32
- id: ID,
33
- metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
34
- time: Schema.Struct({ created: DateTimeUtcFromMillis }),
35
- }
36
-
37
- /**
38
- * Provider-owned replay data, keyed by the producing provider's metadata fields and echoed back verbatim. A tool's
39
- * result data is merged into its call data, so adapters must not reuse a key with a different value across the two.
40
- */
41
- export const Native = Schema.Record(Schema.String, Schema.Unknown).annotate({
42
- identifier: "Session.Message.Native",
43
- })
44
- export type Native = typeof Native.Type
45
-
46
- export interface AgentSelected extends Schema.Schema.Type<typeof AgentSelected> {}
47
- export const AgentSelected = Schema.Struct({
48
- ...Base,
49
- type: Schema.tag("agent-switched"),
50
- agent: Agent.ID,
51
- previous: Agent.ID.pipe(optional),
52
- }).annotate({ identifier: "Session.Message.AgentSelected" })
53
-
54
- export interface ModelSelected extends Schema.Schema.Type<typeof ModelSelected> {}
55
- export const ModelSelected = Schema.Struct({
56
- ...Base,
57
- type: Schema.tag("model-switched"),
58
- model: Model.Ref,
59
- previous: Model.Ref.pipe(optional),
60
- }).annotate({ identifier: "Session.Message.ModelSelected" })
61
-
62
- export interface LocationSwitched extends Schema.Schema.Type<typeof LocationSwitched> {}
63
- export const LocationSwitched = Schema.Struct({
64
- ...Base,
65
- type: Schema.tag("location-switched"),
66
- location: Location.Ref,
67
- projectID: Project.ID.pipe(optional),
68
- subpath: RelativePath.pipe(optional),
69
- previous: Schema.Struct({
70
- location: Location.Ref,
71
- projectID: Project.ID.pipe(optional),
72
- subpath: RelativePath.pipe(optional),
73
- }).pipe(optional),
74
- }).annotate({ identifier: "Session.Message.LocationSwitched" })
75
-
76
- export interface User extends Schema.Schema.Type<typeof User> {}
77
- export const User = Schema.Struct({
78
- ...Base,
79
- /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
80
- text: Prompt.fields.text,
81
- files: Prompt.fields.files,
82
- agents: Prompt.fields.agents,
83
- skills: Prompt.fields.skills,
84
- type: Schema.tag("user"),
85
- }).annotate({ identifier: "Session.Message.User" })
86
-
87
- /** A {@link User} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
88
- export interface MediaUser extends Schema.Schema.Type<typeof MediaUser> {}
89
- export const MediaUser = Schema.Struct({
90
- ...User.fields,
91
- files: Schema.Array(Attachment).pipe(optional),
92
- }).annotate({ identifier: "Session.Message.MediaUser" })
93
-
94
- export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
95
- export const Synthetic = Schema.Struct({
96
- ...Base,
97
- text: Schema.String,
98
- description: Schema.String.pipe(optional),
99
- type: Schema.tag("synthetic"),
100
- }).annotate({ identifier: "Session.Message.Synthetic" })
101
-
102
- export interface System extends Schema.Schema.Type<typeof System> {}
103
- export const System = Schema.Struct({
104
- ...Base,
105
- type: Schema.tag("system"),
106
- /** The model-facing update text, frozen at emit time. */
107
- text: Schema.String,
108
- /** A short human-readable summary for transcript display. */
109
- description: Schema.String.pipe(optional),
110
- }).annotate({ identifier: "Session.Message.System" })
111
-
112
- export interface Skill extends Schema.Schema.Type<typeof Skill> {}
113
- export const Skill = Schema.Struct({
114
- ...Base,
115
- type: Schema.tag("skill"),
116
- skill: SkillSchema.ID,
117
- name: SkillSchema.Name,
118
- text: Schema.String,
119
- }).annotate({ identifier: "Session.Message.Skill" })
120
-
121
- export interface Shell extends Schema.Schema.Type<typeof Shell> {}
122
- export const Shell = Schema.Struct({
123
- ...Base,
124
- type: Schema.tag("shell"),
125
- shellID: ShellSchema.ID,
126
- command: Schema.String,
127
- status: ShellSchema.Status,
128
- exit: Schema.Number.pipe(optional),
129
- output: ShellSchema.Output.pipe(optional),
130
- time: Schema.Struct({
131
- created: DateTimeUtcFromMillis,
132
- completed: DateTimeUtcFromMillis.pipe(optional),
133
- }),
134
- }).annotate({ identifier: "Session.Message.Shell" })
135
-
136
- export interface ToolStateStreaming extends Schema.Schema.Type<typeof ToolStateStreaming> {}
137
- export const ToolStateStreaming = Schema.Struct({
138
- status: Schema.tag("streaming"),
139
- input: Schema.String,
140
- }).annotate({ identifier: "Session.Message.ToolState.Streaming" })
141
-
142
- export interface ToolStateRunning extends Schema.Schema.Type<typeof ToolStateRunning> {}
143
- export const ToolStateRunning = Schema.Struct({
144
- status: Schema.tag("running"),
145
- input: Schema.Record(Schema.String, Schema.Unknown),
146
- metadata: Schema.Record(Schema.String, Schema.Json),
147
- }).annotate({ identifier: "Session.Message.ToolState.Running" })
148
-
149
- export interface ToolStateCompleted extends Schema.Schema.Type<typeof ToolStateCompleted> {}
150
- export const ToolStateCompleted = Schema.Struct({
151
- status: Schema.tag("completed"),
152
- input: Schema.Record(Schema.String, Schema.Unknown),
153
- content: Schema.NonEmptyArray(Content),
154
- metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
155
- }).annotate({ identifier: "Session.Message.ToolState.Completed" })
156
-
157
- export interface ToolStateError extends Schema.Schema.Type<typeof ToolStateError> {}
158
- export const ToolStateError = Schema.Struct({
159
- status: Schema.tag("error"),
160
- input: Schema.Record(Schema.String, Schema.Unknown),
161
- error: SessionError.Error,
162
- content: Schema.NonEmptyArray(Content).pipe(optional),
163
- metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
164
- }).annotate({ identifier: "Session.Message.ToolState.Error" })
165
-
166
- export const ToolState = Schema.Union([ToolStateStreaming, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(
167
- Schema.toTaggedUnion("status"),
168
- )
169
- export type ToolState = ToolStateStreaming | ToolStateRunning | ToolStateCompleted | ToolStateError
170
-
171
- export interface AssistantTool extends Schema.Schema.Type<typeof AssistantTool> {}
172
- export const AssistantTool = Schema.Struct({
173
- type: Schema.tag("tool"),
174
- id: Schema.String,
175
- name: Schema.String,
176
- executed: Schema.Boolean.pipe(optional),
177
- native: Native.pipe(optional),
178
- state: ToolState,
179
- time: Schema.Struct({
180
- created: DateTimeUtcFromMillis,
181
- ran: DateTimeUtcFromMillis.pipe(optional),
182
- completed: DateTimeUtcFromMillis.pipe(optional),
183
- }),
184
- }).annotate({ identifier: "Session.Message.Assistant.Tool" })
185
-
186
- export interface AssistantText extends Schema.Schema.Type<typeof AssistantText> {}
187
- export const AssistantText = Schema.Struct({
188
- type: Schema.tag("text"),
189
- /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
190
- text: Schema.String,
191
- native: Native.pipe(optional),
192
- }).annotate({ identifier: "Session.Message.Assistant.Text" })
193
-
194
- export interface AssistantReasoning extends Schema.Schema.Type<typeof AssistantReasoning> {}
195
- export const AssistantReasoning = Schema.Struct({
196
- type: Schema.tag("reasoning"),
197
- text: Schema.String,
198
- native: Native.pipe(optional),
199
- time: Schema.Struct({
200
- created: DateTimeUtcFromMillis,
201
- completed: DateTimeUtcFromMillis.pipe(optional),
202
- }).pipe(optional),
203
- }).annotate({ identifier: "Session.Message.Assistant.Reasoning" })
204
-
205
- export const AssistantContent = Schema.Union([AssistantText, AssistantReasoning, AssistantTool]).pipe(
206
- Schema.toTaggedUnion("type"),
207
- )
208
- export type AssistantContent = AssistantText | AssistantReasoning | AssistantTool
209
-
210
- export const AssistantContentEncoded = Schema.toEncoded(AssistantContent).annotate({
211
- identifier: "Session.Message.AssistantContent.Encoded",
212
- })
213
- export type AssistantContentEncoded = typeof AssistantContentEncoded.Type
214
-
215
- export interface AssistantRetry extends Schema.Schema.Type<typeof AssistantRetry> {}
216
- export const AssistantRetry = Schema.Struct({
217
- attempt: PositiveInt,
218
- at: DateTimeUtcFromMillis,
219
- error: SessionError.Error,
220
- }).annotate({ identifier: "Session.Message.Assistant.Retry" })
221
-
222
- export interface Assistant extends Schema.Schema.Type<typeof Assistant> {}
223
- export const Assistant = Schema.Struct({
224
- ...Base,
225
- type: Schema.tag("assistant"),
226
- agent: Agent.ID,
227
- model: Model.Ref,
228
- /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
229
- content: AssistantContent.pipe(Schema.Array),
230
- snapshot: Schema.Struct({
231
- start: Snapshot.ID.pipe(optional),
232
- end: Snapshot.ID.pipe(optional),
233
- files: Schema.Array(RelativePath).pipe(optional),
234
- }).pipe(optional),
235
- finish: FinishReason.pipe(optional),
236
- rawFinish: Schema.String.pipe(optional),
237
- /** Step-level native data, such as a provider's reason for blocking a response. */
238
- native: Native.pipe(optional),
239
- cost: Money.USD.pipe(optional),
240
- tokens: TokenUsage.Info.pipe(optional),
241
- error: SessionError.Error.pipe(optional),
242
- retry: AssistantRetry.pipe(optional),
243
- time: Schema.Struct({
244
- created: DateTimeUtcFromMillis,
245
- /** When the provider streamed the first output token, before the rest of the response. */
246
- firstToken: DateTimeUtcFromMillis.pipe(optional),
247
- /** When the provider response body ended, before tool settlement. */
248
- streamed: DateTimeUtcFromMillis.pipe(optional),
249
- /** The session search index waits for this before indexing the message (`search-index.ts`). */
250
- completed: DateTimeUtcFromMillis.pipe(optional),
251
- }),
252
- }).annotate({ identifier: "Session.Message.Assistant" })
253
-
254
- const CompactionBase = { type: Schema.tag("compaction"), ...Base }
255
-
256
- /** Usage of the compaction request itself, not the size of the resulting context. */
257
- const CompactionUsage = {
258
- cost: Money.USD.pipe(optional),
259
- tokens: TokenUsage.Info.pipe(optional),
260
- }
261
-
262
- export interface CompactionRunning extends Schema.Schema.Type<typeof CompactionRunning> {}
263
- export const CompactionRunning = Schema.Struct({
264
- ...CompactionBase,
265
- status: Schema.tag("running"),
266
- reason: Schema.Literals(["auto", "manual"]),
267
- summary: Schema.String,
268
- }).annotate({ identifier: "Session.Message.Compaction.Running" })
269
-
270
- export interface CompactionCompleted extends Schema.Schema.Type<typeof CompactionCompleted> {}
271
- export const CompactionCompleted = Schema.Struct({
272
- ...CompactionBase,
273
- status: Schema.tag("completed"),
274
- reason: Schema.Literals(["auto", "manual"]),
275
- model: Model.Ref.pipe(optional),
276
- /** A provider compaction stores its replacement window in `native.messages`, replayed instead of `summary`. */
277
- native: Native.pipe(optional),
278
- /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
279
- summary: Schema.String,
280
- ...CompactionUsage,
281
- }).annotate({ identifier: "Session.Message.Compaction.Completed" })
282
-
283
- export interface CompactionFailed extends Schema.Schema.Type<typeof CompactionFailed> {}
284
- export const CompactionFailed = Schema.Struct({
285
- ...CompactionBase,
286
- status: Schema.tag("failed"),
287
- reason: Schema.Literals(["auto", "manual"]),
288
- error: SessionError.Error,
289
- ...CompactionUsage,
290
- }).annotate({ identifier: "Session.Message.Compaction.Failed" })
291
-
292
- export const Compaction = Schema.Union([CompactionRunning, CompactionCompleted, CompactionFailed]).pipe(
293
- Schema.toTaggedUnion("status"),
294
- Schema.annotate({ identifier: "Session.Message.Compaction" }),
295
- )
296
- export type Compaction = CompactionRunning | CompactionCompleted | CompactionFailed
297
-
298
- /**
299
- * Marks the Session going idle: every step since the previous marker belongs to
300
- * one turn, including prompts steered in while it was busy. A shutdown does not
301
- * record one, since the resumed execution continues the same turn.
302
- */
303
- export interface Idle extends Schema.Schema.Type<typeof Idle> {}
304
- export const Idle = Schema.Struct({
305
- ...Base,
306
- type: Schema.tag("idle"),
307
- outcome: Schema.Literals(["succeeded", "failed", "interrupted"]),
308
- error: SessionError.Error.pipe(optional),
309
- }).annotate({ identifier: "Session.Message.Idle" })
310
-
311
- export const Info = Schema.Union([
312
- AgentSelected,
313
- ModelSelected,
314
- LocationSwitched,
315
- User,
316
- Synthetic,
317
- System,
318
- Skill,
319
- Shell,
320
- Assistant,
321
- Compaction,
322
- Idle,
323
- ]).annotate({ identifier: "Session.Message.Info" })
324
- export type Info =
325
- | AgentSelected
326
- | ModelSelected
327
- | LocationSwitched
328
- | User
329
- | Synthetic
330
- | System
331
- | Skill
332
- | Shell
333
- | Assistant
334
- | Compaction
335
- | Idle
336
- export type Type = Info["type"]
337
-
338
- /** {@link Info} with {@link MediaUser} for clients that opt into `experimental-media-uri`. */
339
- export const MediaInfo = Schema.Union([
340
- AgentSelected,
341
- ModelSelected,
342
- LocationSwitched,
343
- MediaUser,
344
- Synthetic,
345
- System,
346
- Skill,
347
- Shell,
348
- Assistant,
349
- Compaction,
350
- Idle,
351
- ]).annotate({ identifier: "Session.Message.MediaInfo" })
352
- export type MediaInfo = Exclude<Info, User> | MediaUser
1
+ export * as SessionMessage from "./session-message.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional } from "./schema.js"
5
+ import { Content } from "./tool.js"
6
+ import { Location } from "./location.js"
7
+ import { Model } from "./model.js"
8
+ import { Project } from "./project.js"
9
+ import { Attachment, Prompt } from "./prompt.js"
10
+ import { DateTimeUtcFromMillis, PositiveInt, RelativePath, statics } from "./schema.js"
11
+ import { ascending } from "./identifier.js"
12
+ import { Shell as ShellSchema } from "./shell.js"
13
+ import { FinishReason } from "./llm.js"
14
+ import { SessionError } from "./session-error.js"
15
+ import { Agent } from "./agent.js"
16
+ import { Skill as SkillSchema } from "./skill.js"
17
+ import { Money } from "./money.js"
18
+ import { Snapshot } from "./snapshot.js"
19
+ import { TokenUsage } from "./token-usage.js"
20
+
21
+ export const ID = Schema.String.check(Schema.isStartingWith("msg_")).pipe(
22
+ Schema.brand("Session.Message.ID"),
23
+ Schema.annotate({ identifier: "Session.Message.ID" }),
24
+ statics((schema) => ({
25
+ create: () => schema.make("msg_" + ascending()),
26
+ fromEvent: (eventID: string) => schema.make(eventID.replace(/^evt_/, "msg_")),
27
+ })),
28
+ )
29
+ export type ID = typeof ID.Type
30
+
31
+ const Base = {
32
+ id: ID,
33
+ metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
34
+ time: Schema.Struct({ created: DateTimeUtcFromMillis }),
35
+ }
36
+
37
+ /**
38
+ * Provider-owned replay data, keyed by the producing provider's metadata fields and echoed back verbatim. A tool's
39
+ * result data is merged into its call data, so adapters must not reuse a key with a different value across the two.
40
+ */
41
+ export const Native = Schema.Record(Schema.String, Schema.Unknown).annotate({
42
+ identifier: "Session.Message.Native",
43
+ })
44
+ export type Native = typeof Native.Type
45
+
46
+ export interface AgentSelected extends Schema.Schema.Type<typeof AgentSelected> {}
47
+ export const AgentSelected = Schema.Struct({
48
+ ...Base,
49
+ type: Schema.tag("agent-switched"),
50
+ agent: Agent.ID,
51
+ previous: Agent.ID.pipe(optional),
52
+ }).annotate({ identifier: "Session.Message.AgentSelected" })
53
+
54
+ export interface ModelSelected extends Schema.Schema.Type<typeof ModelSelected> {}
55
+ export const ModelSelected = Schema.Struct({
56
+ ...Base,
57
+ type: Schema.tag("model-switched"),
58
+ model: Model.Ref,
59
+ previous: Model.Ref.pipe(optional),
60
+ }).annotate({ identifier: "Session.Message.ModelSelected" })
61
+
62
+ export interface LocationSwitched extends Schema.Schema.Type<typeof LocationSwitched> {}
63
+ export const LocationSwitched = Schema.Struct({
64
+ ...Base,
65
+ type: Schema.tag("location-switched"),
66
+ location: Location.Ref,
67
+ projectID: Project.ID.pipe(optional),
68
+ subpath: RelativePath.pipe(optional),
69
+ previous: Schema.Struct({
70
+ location: Location.Ref,
71
+ projectID: Project.ID.pipe(optional),
72
+ subpath: RelativePath.pipe(optional),
73
+ }).pipe(optional),
74
+ }).annotate({ identifier: "Session.Message.LocationSwitched" })
75
+
76
+ export interface User extends Schema.Schema.Type<typeof User> {}
77
+ export const User = Schema.Struct({
78
+ ...Base,
79
+ /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
80
+ text: Prompt.fields.text,
81
+ files: Prompt.fields.files,
82
+ agents: Prompt.fields.agents,
83
+ skills: Prompt.fields.skills,
84
+ type: Schema.tag("user"),
85
+ }).annotate({ identifier: "Session.Message.User" })
86
+
87
+ /** A {@link User} whose files may stay on the server, for clients that opt into `experimental-media-uri`. */
88
+ export interface MediaUser extends Schema.Schema.Type<typeof MediaUser> {}
89
+ export const MediaUser = Schema.Struct({
90
+ ...User.fields,
91
+ files: Schema.Array(Attachment).pipe(optional),
92
+ }).annotate({ identifier: "Session.Message.MediaUser" })
93
+
94
+ export interface Synthetic extends Schema.Schema.Type<typeof Synthetic> {}
95
+ export const Synthetic = Schema.Struct({
96
+ ...Base,
97
+ text: Schema.String,
98
+ description: Schema.String.pipe(optional),
99
+ type: Schema.tag("synthetic"),
100
+ }).annotate({ identifier: "Session.Message.Synthetic" })
101
+
102
+ export interface System extends Schema.Schema.Type<typeof System> {}
103
+ export const System = Schema.Struct({
104
+ ...Base,
105
+ type: Schema.tag("system"),
106
+ /** The model-facing update text, frozen at emit time. */
107
+ text: Schema.String,
108
+ /** A short human-readable summary for transcript display. */
109
+ description: Schema.String.pipe(optional),
110
+ }).annotate({ identifier: "Session.Message.System" })
111
+
112
+ export interface Skill extends Schema.Schema.Type<typeof Skill> {}
113
+ export const Skill = Schema.Struct({
114
+ ...Base,
115
+ type: Schema.tag("skill"),
116
+ skill: SkillSchema.ID,
117
+ name: SkillSchema.Name,
118
+ text: Schema.String,
119
+ }).annotate({ identifier: "Session.Message.Skill" })
120
+
121
+ export interface Shell extends Schema.Schema.Type<typeof Shell> {}
122
+ export const Shell = Schema.Struct({
123
+ ...Base,
124
+ type: Schema.tag("shell"),
125
+ shellID: ShellSchema.ID,
126
+ command: Schema.String,
127
+ status: ShellSchema.Status,
128
+ exit: Schema.Number.pipe(optional),
129
+ output: ShellSchema.Output.pipe(optional),
130
+ time: Schema.Struct({
131
+ created: DateTimeUtcFromMillis,
132
+ completed: DateTimeUtcFromMillis.pipe(optional),
133
+ }),
134
+ }).annotate({ identifier: "Session.Message.Shell" })
135
+
136
+ export interface ToolStateStreaming extends Schema.Schema.Type<typeof ToolStateStreaming> {}
137
+ export const ToolStateStreaming = Schema.Struct({
138
+ status: Schema.tag("streaming"),
139
+ input: Schema.String,
140
+ }).annotate({ identifier: "Session.Message.ToolState.Streaming" })
141
+
142
+ export interface ToolStateRunning extends Schema.Schema.Type<typeof ToolStateRunning> {}
143
+ export const ToolStateRunning = Schema.Struct({
144
+ status: Schema.tag("running"),
145
+ input: Schema.Record(Schema.String, Schema.Unknown),
146
+ metadata: Schema.Record(Schema.String, Schema.Json),
147
+ }).annotate({ identifier: "Session.Message.ToolState.Running" })
148
+
149
+ export interface ToolStateCompleted extends Schema.Schema.Type<typeof ToolStateCompleted> {}
150
+ export const ToolStateCompleted = Schema.Struct({
151
+ status: Schema.tag("completed"),
152
+ input: Schema.Record(Schema.String, Schema.Unknown),
153
+ content: Schema.NonEmptyArray(Content),
154
+ metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
155
+ }).annotate({ identifier: "Session.Message.ToolState.Completed" })
156
+
157
+ export interface ToolStateError extends Schema.Schema.Type<typeof ToolStateError> {}
158
+ export const ToolStateError = Schema.Struct({
159
+ status: Schema.tag("error"),
160
+ input: Schema.Record(Schema.String, Schema.Unknown),
161
+ error: SessionError.Error,
162
+ content: Schema.NonEmptyArray(Content).pipe(optional),
163
+ metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
164
+ }).annotate({ identifier: "Session.Message.ToolState.Error" })
165
+
166
+ export const ToolState = Schema.Union([ToolStateStreaming, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(
167
+ Schema.toTaggedUnion("status"),
168
+ )
169
+ export type ToolState = ToolStateStreaming | ToolStateRunning | ToolStateCompleted | ToolStateError
170
+
171
+ export interface AssistantTool extends Schema.Schema.Type<typeof AssistantTool> {}
172
+ export const AssistantTool = Schema.Struct({
173
+ type: Schema.tag("tool"),
174
+ id: Schema.String,
175
+ name: Schema.String,
176
+ executed: Schema.Boolean.pipe(optional),
177
+ native: Native.pipe(optional),
178
+ state: ToolState,
179
+ time: Schema.Struct({
180
+ created: DateTimeUtcFromMillis,
181
+ ran: DateTimeUtcFromMillis.pipe(optional),
182
+ completed: DateTimeUtcFromMillis.pipe(optional),
183
+ }),
184
+ }).annotate({ identifier: "Session.Message.Assistant.Tool" })
185
+
186
+ export interface AssistantText extends Schema.Schema.Type<typeof AssistantText> {}
187
+ export const AssistantText = Schema.Struct({
188
+ type: Schema.tag("text"),
189
+ /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
190
+ text: Schema.String,
191
+ native: Native.pipe(optional),
192
+ }).annotate({ identifier: "Session.Message.Assistant.Text" })
193
+
194
+ export interface AssistantReasoning extends Schema.Schema.Type<typeof AssistantReasoning> {}
195
+ export const AssistantReasoning = Schema.Struct({
196
+ type: Schema.tag("reasoning"),
197
+ text: Schema.String,
198
+ native: Native.pipe(optional),
199
+ time: Schema.Struct({
200
+ created: DateTimeUtcFromMillis,
201
+ completed: DateTimeUtcFromMillis.pipe(optional),
202
+ }).pipe(optional),
203
+ }).annotate({ identifier: "Session.Message.Assistant.Reasoning" })
204
+
205
+ export const AssistantContent = Schema.Union([AssistantText, AssistantReasoning, AssistantTool]).pipe(
206
+ Schema.toTaggedUnion("type"),
207
+ )
208
+ export type AssistantContent = AssistantText | AssistantReasoning | AssistantTool
209
+
210
+ export const AssistantContentEncoded = Schema.toEncoded(AssistantContent).annotate({
211
+ identifier: "Session.Message.AssistantContent.Encoded",
212
+ })
213
+ export type AssistantContentEncoded = typeof AssistantContentEncoded.Type
214
+
215
+ export interface AssistantRetry extends Schema.Schema.Type<typeof AssistantRetry> {}
216
+ export const AssistantRetry = Schema.Struct({
217
+ attempt: PositiveInt,
218
+ at: DateTimeUtcFromMillis,
219
+ error: SessionError.Error,
220
+ }).annotate({ identifier: "Session.Message.Assistant.Retry" })
221
+
222
+ export interface Assistant extends Schema.Schema.Type<typeof Assistant> {}
223
+ export const Assistant = Schema.Struct({
224
+ ...Base,
225
+ type: Schema.tag("assistant"),
226
+ agent: Agent.ID,
227
+ model: Model.Ref,
228
+ /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
229
+ content: AssistantContent.pipe(Schema.Array),
230
+ snapshot: Schema.Struct({
231
+ start: Snapshot.ID.pipe(optional),
232
+ end: Snapshot.ID.pipe(optional),
233
+ files: Schema.Array(RelativePath).pipe(optional),
234
+ }).pipe(optional),
235
+ finish: FinishReason.pipe(optional),
236
+ rawFinish: Schema.String.pipe(optional),
237
+ /** Step-level native data, such as a provider's reason for blocking a response. */
238
+ native: Native.pipe(optional),
239
+ cost: Money.USD.pipe(optional),
240
+ tokens: TokenUsage.Info.pipe(optional),
241
+ error: SessionError.Error.pipe(optional),
242
+ retry: AssistantRetry.pipe(optional),
243
+ time: Schema.Struct({
244
+ created: DateTimeUtcFromMillis,
245
+ /** When the provider streamed the first output token, before the rest of the response. */
246
+ firstToken: DateTimeUtcFromMillis.pipe(optional),
247
+ /** When the provider response body ended, before tool settlement. */
248
+ streamed: DateTimeUtcFromMillis.pipe(optional),
249
+ /** The session search index waits for this before indexing the message (`search-index.ts`). */
250
+ completed: DateTimeUtcFromMillis.pipe(optional),
251
+ }),
252
+ }).annotate({ identifier: "Session.Message.Assistant" })
253
+
254
+ const CompactionBase = { type: Schema.tag("compaction"), ...Base }
255
+
256
+ /** Usage of the compaction request itself, not the size of the resulting context. */
257
+ const CompactionUsage = {
258
+ cost: Money.USD.pipe(optional),
259
+ tokens: TokenUsage.Info.pipe(optional),
260
+ }
261
+
262
+ export interface CompactionRunning extends Schema.Schema.Type<typeof CompactionRunning> {}
263
+ export const CompactionRunning = Schema.Struct({
264
+ ...CompactionBase,
265
+ status: Schema.tag("running"),
266
+ reason: Schema.Literals(["auto", "manual"]),
267
+ summary: Schema.String,
268
+ }).annotate({ identifier: "Session.Message.Compaction.Running" })
269
+
270
+ export interface CompactionCompleted extends Schema.Schema.Type<typeof CompactionCompleted> {}
271
+ export const CompactionCompleted = Schema.Struct({
272
+ ...CompactionBase,
273
+ status: Schema.tag("completed"),
274
+ reason: Schema.Literals(["auto", "manual"]),
275
+ model: Model.Ref.pipe(optional),
276
+ /** A provider compaction stores its replacement window in `native.messages`, replayed instead of `summary`. */
277
+ native: Native.pipe(optional),
278
+ /** Read by the session search index's SQL (`packages/core/src/session/search-index.ts`); a rename needs its `Version` bumped. */
279
+ summary: Schema.String,
280
+ ...CompactionUsage,
281
+ }).annotate({ identifier: "Session.Message.Compaction.Completed" })
282
+
283
+ export interface CompactionFailed extends Schema.Schema.Type<typeof CompactionFailed> {}
284
+ export const CompactionFailed = Schema.Struct({
285
+ ...CompactionBase,
286
+ status: Schema.tag("failed"),
287
+ reason: Schema.Literals(["auto", "manual"]),
288
+ error: SessionError.Error,
289
+ ...CompactionUsage,
290
+ }).annotate({ identifier: "Session.Message.Compaction.Failed" })
291
+
292
+ export const Compaction = Schema.Union([CompactionRunning, CompactionCompleted, CompactionFailed]).pipe(
293
+ Schema.toTaggedUnion("status"),
294
+ Schema.annotate({ identifier: "Session.Message.Compaction" }),
295
+ )
296
+ export type Compaction = CompactionRunning | CompactionCompleted | CompactionFailed
297
+
298
+ /**
299
+ * Marks the Session going idle: every step since the previous marker belongs to
300
+ * one turn, including prompts steered in while it was busy. A shutdown does not
301
+ * record one, since the resumed execution continues the same turn.
302
+ */
303
+ export interface Idle extends Schema.Schema.Type<typeof Idle> {}
304
+ export const Idle = Schema.Struct({
305
+ ...Base,
306
+ type: Schema.tag("idle"),
307
+ outcome: Schema.Literals(["succeeded", "failed", "interrupted"]),
308
+ error: SessionError.Error.pipe(optional),
309
+ }).annotate({ identifier: "Session.Message.Idle" })
310
+
311
+ export const Info = Schema.Union([
312
+ AgentSelected,
313
+ ModelSelected,
314
+ LocationSwitched,
315
+ User,
316
+ Synthetic,
317
+ System,
318
+ Skill,
319
+ Shell,
320
+ Assistant,
321
+ Compaction,
322
+ Idle,
323
+ ]).annotate({ identifier: "Session.Message.Info" })
324
+ export type Info =
325
+ | AgentSelected
326
+ | ModelSelected
327
+ | LocationSwitched
328
+ | User
329
+ | Synthetic
330
+ | System
331
+ | Skill
332
+ | Shell
333
+ | Assistant
334
+ | Compaction
335
+ | Idle
336
+ export type Type = Info["type"]
337
+
338
+ /** {@link Info} with {@link MediaUser} for clients that opt into `experimental-media-uri`. */
339
+ export const MediaInfo = Schema.Union([
340
+ AgentSelected,
341
+ ModelSelected,
342
+ LocationSwitched,
343
+ MediaUser,
344
+ Synthetic,
345
+ System,
346
+ Skill,
347
+ Shell,
348
+ Assistant,
349
+ Compaction,
350
+ Idle,
351
+ ]).annotate({ identifier: "Session.Message.MediaInfo" })
352
+ export type MediaInfo = Exclude<Info, User> | MediaUser