@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
@@ -0,0 +1,667 @@
1
+ export * as SessionV1 from "./session.js"
2
+
3
+ import { Effect, Schema, Types } from "effect"
4
+ import { durable, ephemeral, inventory } from "../event.js"
5
+ import { Project } from "../project.js"
6
+ import { Provider } from "../provider.js"
7
+ import { Model } from "../model.js"
8
+ import { NonNegativeInt, optional, statics } from "../schema.js"
9
+ import { ascending } from "../identifier.js"
10
+ import { SessionID } from "../session-id.js"
11
+ import { WorkspaceID } from "../workspace-id.js"
12
+ import { PermissionV1 } from "./permission.js"
13
+ import { FileDiff } from "../file-diff.js"
14
+
15
+ const Timestamp = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0))
16
+
17
+ export const MessageID = Schema.String.check(Schema.isStartingWith("msg")).pipe(
18
+ Schema.brand("SessionV1.MessageID"),
19
+ statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "msg_" + ascending()) })),
20
+ )
21
+ export type MessageID = typeof MessageID.Type
22
+
23
+ export const PartID = Schema.String.check(Schema.isStartingWith("prt")).pipe(
24
+ Schema.brand("SessionV1.PartID"),
25
+ statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "prt_" + ascending()) })),
26
+ )
27
+ export type PartID = typeof PartID.Type
28
+
29
+ const namedError = <Name extends string, Fields extends Schema.Struct.Fields>(name: Name, fields: Fields) => {
30
+ const schema = Schema.Struct({ name: Schema.Literal(name), data: Schema.Struct(fields) }).annotate({
31
+ identifier: name,
32
+ })
33
+ return { Schema: schema, EffectSchema: schema }
34
+ }
35
+
36
+ export const OutputLengthError = namedError("MessageOutputLengthError", {})
37
+
38
+ export const AuthError = namedError("ProviderAuthError", {
39
+ providerID: Schema.String,
40
+ message: Schema.String,
41
+ })
42
+
43
+ export const AbortedError = namedError("MessageAbortedError", { message: Schema.String })
44
+ export const StructuredOutputError = namedError("StructuredOutputError", {
45
+ message: Schema.String,
46
+ retries: NonNegativeInt,
47
+ })
48
+ export const APIError = namedError("APIError", {
49
+ message: Schema.String,
50
+ statusCode: Schema.optional(NonNegativeInt),
51
+ isRetryable: Schema.Boolean,
52
+ responseHeaders: Schema.optional(Schema.Record(Schema.String, Schema.String)),
53
+ responseBody: Schema.optional(Schema.String),
54
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
55
+ })
56
+ export type APIError = Schema.Schema.Type<typeof APIError.Schema>
57
+ export const ContextOverflowError = namedError("ContextOverflowError", {
58
+ message: Schema.String,
59
+ responseBody: Schema.optional(Schema.String),
60
+ })
61
+ export const ContentFilterError = namedError("ContentFilterError", {
62
+ message: Schema.String,
63
+ })
64
+
65
+ export class OutputFormatText extends Schema.Class<OutputFormatText>("OutputFormatText")({
66
+ type: Schema.Literal("text"),
67
+ }) {}
68
+
69
+ export class OutputFormatJsonSchema extends Schema.Class<OutputFormatJsonSchema>("OutputFormatJsonSchema")({
70
+ type: Schema.Literal("json_schema"),
71
+ schema: Schema.Record(Schema.String, Schema.Any).annotate({ identifier: "SessionV1.JSONSchema" }),
72
+ retryCount: NonNegativeInt.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed(2))),
73
+ }) {}
74
+
75
+ export const Format = Schema.Union([OutputFormatText, OutputFormatJsonSchema]).annotate({
76
+ discriminator: "type",
77
+ identifier: "SessionV1.OutputFormat",
78
+ })
79
+ export type OutputFormat = Schema.Schema.Type<typeof Format>
80
+
81
+ const partBase = {
82
+ id: PartID,
83
+ sessionID: SessionID,
84
+ messageID: MessageID,
85
+ }
86
+
87
+ export const SnapshotPart = Schema.Struct({
88
+ ...partBase,
89
+ type: Schema.Literal("snapshot"),
90
+ snapshot: Schema.String,
91
+ }).annotate({ identifier: "SessionV1.SnapshotPart" })
92
+ export type SnapshotPart = Types.DeepMutable<Schema.Schema.Type<typeof SnapshotPart>>
93
+
94
+ export const PatchPart = Schema.Struct({
95
+ ...partBase,
96
+ type: Schema.Literal("patch"),
97
+ hash: Schema.String,
98
+ files: Schema.Array(Schema.String),
99
+ }).annotate({ identifier: "SessionV1.PatchPart" })
100
+ export type PatchPart = Types.DeepMutable<Schema.Schema.Type<typeof PatchPart>>
101
+
102
+ export const TextPart = Schema.Struct({
103
+ ...partBase,
104
+ type: Schema.Literal("text"),
105
+ text: Schema.String,
106
+ synthetic: Schema.optional(Schema.Boolean),
107
+ ignored: Schema.optional(Schema.Boolean),
108
+ time: Schema.optional(
109
+ Schema.Struct({
110
+ start: NonNegativeInt,
111
+ end: Schema.optional(NonNegativeInt),
112
+ }),
113
+ ),
114
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
115
+ }).annotate({ identifier: "SessionV1.TextPart" })
116
+ export type TextPart = Types.DeepMutable<Schema.Schema.Type<typeof TextPart>>
117
+
118
+ export const ReasoningPart = Schema.Struct({
119
+ ...partBase,
120
+ type: Schema.Literal("reasoning"),
121
+ text: Schema.String,
122
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
123
+ time: Schema.Struct({
124
+ start: NonNegativeInt,
125
+ end: Schema.optional(NonNegativeInt),
126
+ }),
127
+ }).annotate({ identifier: "SessionV1.ReasoningPart" })
128
+ export type ReasoningPart = Types.DeepMutable<Schema.Schema.Type<typeof ReasoningPart>>
129
+
130
+ const filePartSourceBase = {
131
+ text: Schema.Struct({
132
+ value: Schema.String,
133
+ start: Schema.Finite,
134
+ end: Schema.Finite,
135
+ }).annotate({ identifier: "SessionV1.FilePartSourceText" }),
136
+ }
137
+
138
+ export const Range = Schema.Struct({
139
+ start: Schema.Struct({ line: NonNegativeInt, character: NonNegativeInt }),
140
+ end: Schema.Struct({ line: NonNegativeInt, character: NonNegativeInt }),
141
+ }).annotate({ identifier: "SessionV1.Range" })
142
+ export type Range = typeof Range.Type
143
+
144
+ export const FileSource = Schema.Struct({
145
+ ...filePartSourceBase,
146
+ type: Schema.Literal("file"),
147
+ path: Schema.String,
148
+ }).annotate({ identifier: "SessionV1.FileSource" })
149
+
150
+ export const SymbolSource = Schema.Struct({
151
+ ...filePartSourceBase,
152
+ type: Schema.Literal("symbol"),
153
+ path: Schema.String,
154
+ range: Range,
155
+ name: Schema.String,
156
+ kind: NonNegativeInt,
157
+ }).annotate({ identifier: "SessionV1.SymbolSource" })
158
+
159
+ export const ResourceSource = Schema.Struct({
160
+ ...filePartSourceBase,
161
+ type: Schema.Literal("resource"),
162
+ clientName: Schema.String,
163
+ uri: Schema.String,
164
+ }).annotate({ identifier: "SessionV1.ResourceSource" })
165
+
166
+ export const FilePartSource = Schema.Union([FileSource, SymbolSource, ResourceSource]).annotate({
167
+ discriminator: "type",
168
+ identifier: "SessionV1.FilePartSource",
169
+ })
170
+
171
+ export const FilePart = Schema.Struct({
172
+ ...partBase,
173
+ type: Schema.Literal("file"),
174
+ mime: Schema.String,
175
+ filename: Schema.optional(Schema.String),
176
+ url: Schema.String,
177
+ source: Schema.optional(FilePartSource),
178
+ }).annotate({ identifier: "SessionV1.FilePart" })
179
+ export type FilePart = Types.DeepMutable<Schema.Schema.Type<typeof FilePart>>
180
+
181
+ export const AgentPart = Schema.Struct({
182
+ ...partBase,
183
+ type: Schema.Literal("agent"),
184
+ name: Schema.String,
185
+ source: Schema.optional(
186
+ Schema.Struct({
187
+ value: Schema.String,
188
+ start: NonNegativeInt,
189
+ end: NonNegativeInt,
190
+ }),
191
+ ),
192
+ }).annotate({ identifier: "SessionV1.AgentPart" })
193
+ export type AgentPart = Types.DeepMutable<Schema.Schema.Type<typeof AgentPart>>
194
+
195
+ export const CompactionPart = Schema.Struct({
196
+ ...partBase,
197
+ type: Schema.Literal("compaction"),
198
+ auto: Schema.Boolean,
199
+ overflow: Schema.optional(Schema.Boolean),
200
+ tail_start_id: Schema.optional(MessageID),
201
+ }).annotate({ identifier: "SessionV1.CompactionPart" })
202
+ export type CompactionPart = Types.DeepMutable<Schema.Schema.Type<typeof CompactionPart>>
203
+
204
+ export const SubtaskPart = Schema.Struct({
205
+ ...partBase,
206
+ type: Schema.Literal("subtask"),
207
+ prompt: Schema.String,
208
+ description: Schema.String,
209
+ agent: Schema.String,
210
+ model: Schema.optional(
211
+ Schema.Struct({
212
+ providerID: Provider.ID,
213
+ modelID: Model.ID,
214
+ }),
215
+ ),
216
+ command: Schema.optional(Schema.String),
217
+ }).annotate({ identifier: "SessionV1.SubtaskPart" })
218
+ export type SubtaskPart = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPart>>
219
+
220
+ export const RetryPart = Schema.Struct({
221
+ ...partBase,
222
+ type: Schema.Literal("retry"),
223
+ attempt: NonNegativeInt,
224
+ error: APIError.EffectSchema,
225
+ time: Schema.Struct({
226
+ created: NonNegativeInt,
227
+ }),
228
+ }).annotate({ identifier: "SessionV1.RetryPart" })
229
+ export type RetryPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof RetryPart>>, "error"> & {
230
+ error: APIError
231
+ }
232
+
233
+ export const StepStartPart = Schema.Struct({
234
+ ...partBase,
235
+ type: Schema.Literal("step-start"),
236
+ snapshot: Schema.optional(Schema.String),
237
+ }).annotate({ identifier: "SessionV1.StepStartPart" })
238
+ export type StepStartPart = Types.DeepMutable<Schema.Schema.Type<typeof StepStartPart>>
239
+
240
+ export const StepFinishPart = Schema.Struct({
241
+ ...partBase,
242
+ type: Schema.Literal("step-finish"),
243
+ reason: Schema.String,
244
+ snapshot: Schema.optional(Schema.String),
245
+ cost: Schema.Finite,
246
+ tokens: Schema.Struct({
247
+ total: Schema.optional(Schema.Finite),
248
+ input: Schema.Finite,
249
+ output: Schema.Finite,
250
+ reasoning: Schema.Finite,
251
+ cache: Schema.Struct({
252
+ read: Schema.Finite,
253
+ write: Schema.Finite,
254
+ }),
255
+ }),
256
+ }).annotate({ identifier: "SessionV1.StepFinishPart" })
257
+ export type StepFinishPart = Types.DeepMutable<Schema.Schema.Type<typeof StepFinishPart>>
258
+
259
+ export const ToolStatePending = Schema.Struct({
260
+ status: Schema.Literal("pending"),
261
+ input: Schema.Record(Schema.String, Schema.Any),
262
+ raw: Schema.String,
263
+ }).annotate({ identifier: "SessionV1.ToolStatePending" })
264
+ export type ToolStatePending = Types.DeepMutable<Schema.Schema.Type<typeof ToolStatePending>>
265
+
266
+ export const ToolStateRunning = Schema.Struct({
267
+ status: Schema.Literal("running"),
268
+ input: Schema.Record(Schema.String, Schema.Any),
269
+ title: Schema.optional(Schema.String),
270
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
271
+ time: Schema.Struct({
272
+ start: NonNegativeInt,
273
+ }),
274
+ }).annotate({ identifier: "SessionV1.ToolStateRunning" })
275
+ export type ToolStateRunning = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateRunning>>
276
+
277
+ export const ToolStateCompleted = Schema.Struct({
278
+ status: Schema.Literal("completed"),
279
+ input: Schema.Record(Schema.String, Schema.Any),
280
+ output: Schema.String,
281
+ title: Schema.String,
282
+ metadata: Schema.Record(Schema.String, Schema.Any),
283
+ time: Schema.Struct({
284
+ start: NonNegativeInt,
285
+ end: NonNegativeInt,
286
+ compacted: Schema.optional(NonNegativeInt),
287
+ }),
288
+ attachments: Schema.optional(Schema.Array(FilePart)),
289
+ }).annotate({ identifier: "SessionV1.ToolStateCompleted" })
290
+ export type ToolStateCompleted = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateCompleted>>
291
+
292
+ export const ToolStateError = Schema.Struct({
293
+ status: Schema.Literal("error"),
294
+ input: Schema.Record(Schema.String, Schema.Any),
295
+ error: Schema.String,
296
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
297
+ time: Schema.Struct({
298
+ start: NonNegativeInt,
299
+ end: NonNegativeInt,
300
+ }),
301
+ }).annotate({ identifier: "SessionV1.ToolStateError" })
302
+ export type ToolStateError = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateError>>
303
+
304
+ export const ToolState = Schema.Union([
305
+ ToolStatePending,
306
+ ToolStateRunning,
307
+ ToolStateCompleted,
308
+ ToolStateError,
309
+ ]).annotate({
310
+ discriminator: "status",
311
+ identifier: "SessionV1.ToolState",
312
+ })
313
+ export type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError
314
+
315
+ export const ToolPart = Schema.Struct({
316
+ ...partBase,
317
+ type: Schema.Literal("tool"),
318
+ callID: Schema.String,
319
+ tool: Schema.String,
320
+ state: ToolState,
321
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
322
+ }).annotate({ identifier: "SessionV1.ToolPart" })
323
+ export type ToolPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof ToolPart>>, "state"> & {
324
+ state: ToolState
325
+ }
326
+
327
+ const messageBase = {
328
+ id: MessageID,
329
+ sessionID: partBase.sessionID,
330
+ }
331
+
332
+ export const User = Schema.Struct({
333
+ ...messageBase,
334
+ role: Schema.Literal("user"),
335
+ time: Schema.Struct({
336
+ created: Timestamp,
337
+ }),
338
+ format: Schema.optional(Format),
339
+ summary: Schema.optional(
340
+ Schema.Struct({
341
+ title: Schema.optional(Schema.String),
342
+ body: Schema.optional(Schema.String),
343
+ diffs: Schema.Array(FileDiff.LegacyInfo),
344
+ }),
345
+ ),
346
+ agent: Schema.String,
347
+ model: Schema.Struct({
348
+ providerID: Provider.ID,
349
+ modelID: Model.ID,
350
+ variant: Schema.optional(Schema.String),
351
+ }),
352
+ system: Schema.optional(Schema.String),
353
+ tools: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
354
+ }).annotate({ identifier: "SessionV1.UserMessage" })
355
+ export type User = Types.DeepMutable<Schema.Schema.Type<typeof User>>
356
+
357
+ export const Part = Schema.Union([
358
+ TextPart,
359
+ SubtaskPart,
360
+ ReasoningPart,
361
+ FilePart,
362
+ ToolPart,
363
+ StepStartPart,
364
+ StepFinishPart,
365
+ SnapshotPart,
366
+ PatchPart,
367
+ AgentPart,
368
+ RetryPart,
369
+ CompactionPart,
370
+ ]).annotate({ discriminator: "type", identifier: "SessionV1.Part" })
371
+ export type Part =
372
+ | TextPart
373
+ | SubtaskPart
374
+ | ReasoningPart
375
+ | FilePart
376
+ | ToolPart
377
+ | StepStartPart
378
+ | StepFinishPart
379
+ | SnapshotPart
380
+ | PatchPart
381
+ | AgentPart
382
+ | RetryPart
383
+ | CompactionPart
384
+
385
+ const AssistantErrorSchema = Schema.Union([
386
+ AuthError.EffectSchema,
387
+ namedError("UnknownError", { message: Schema.String, ref: Schema.optional(Schema.String) }).EffectSchema,
388
+ OutputLengthError.EffectSchema,
389
+ AbortedError.EffectSchema,
390
+ StructuredOutputError.EffectSchema,
391
+ ContextOverflowError.EffectSchema,
392
+ ContentFilterError.EffectSchema,
393
+ APIError.EffectSchema,
394
+ ]).annotate({ discriminator: "name" })
395
+ type AssistantError = Schema.Schema.Type<typeof AssistantErrorSchema>
396
+
397
+ export const TextPartInput = Schema.Struct({
398
+ id: Schema.optional(PartID),
399
+ type: Schema.Literal("text"),
400
+ text: Schema.String,
401
+ synthetic: Schema.optional(Schema.Boolean),
402
+ ignored: Schema.optional(Schema.Boolean),
403
+ time: Schema.optional(
404
+ Schema.Struct({
405
+ start: NonNegativeInt,
406
+ end: Schema.optional(NonNegativeInt),
407
+ }),
408
+ ),
409
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
410
+ }).annotate({ identifier: "SessionV1.TextPartInput" })
411
+ export type TextPartInput = Types.DeepMutable<Schema.Schema.Type<typeof TextPartInput>>
412
+
413
+ export const FilePartInput = Schema.Struct({
414
+ id: Schema.optional(PartID),
415
+ type: Schema.Literal("file"),
416
+ mime: Schema.String,
417
+ filename: Schema.optional(Schema.String),
418
+ url: Schema.String,
419
+ source: Schema.optional(FilePartSource),
420
+ }).annotate({ identifier: "SessionV1.FilePartInput" })
421
+ export type FilePartInput = Types.DeepMutable<Schema.Schema.Type<typeof FilePartInput>>
422
+
423
+ export const AgentPartInput = Schema.Struct({
424
+ id: Schema.optional(PartID),
425
+ type: Schema.Literal("agent"),
426
+ name: Schema.String,
427
+ source: Schema.optional(
428
+ Schema.Struct({
429
+ value: Schema.String,
430
+ start: NonNegativeInt,
431
+ end: NonNegativeInt,
432
+ }),
433
+ ),
434
+ }).annotate({ identifier: "SessionV1.AgentPartInput" })
435
+ export type AgentPartInput = Types.DeepMutable<Schema.Schema.Type<typeof AgentPartInput>>
436
+
437
+ export const SubtaskPartInput = Schema.Struct({
438
+ id: Schema.optional(PartID),
439
+ type: Schema.Literal("subtask"),
440
+ prompt: Schema.String,
441
+ description: Schema.String,
442
+ agent: Schema.String,
443
+ model: Schema.optional(
444
+ Schema.Struct({
445
+ providerID: Provider.ID,
446
+ modelID: Model.ID,
447
+ }),
448
+ ),
449
+ command: Schema.optional(Schema.String),
450
+ }).annotate({ identifier: "SessionV1.SubtaskPartInput" })
451
+ export type SubtaskPartInput = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPartInput>>
452
+
453
+ export const Assistant = Schema.Struct({
454
+ ...messageBase,
455
+ role: Schema.Literal("assistant"),
456
+ time: Schema.Struct({
457
+ created: NonNegativeInt,
458
+ completed: Schema.optional(NonNegativeInt),
459
+ }),
460
+ error: Schema.optional(AssistantErrorSchema),
461
+ parentID: MessageID,
462
+ modelID: Model.ID,
463
+ providerID: Provider.ID,
464
+ mode: Schema.String,
465
+ agent: Schema.String,
466
+ path: Schema.Struct({
467
+ cwd: Schema.String,
468
+ root: Schema.String,
469
+ }),
470
+ summary: Schema.optional(Schema.Boolean),
471
+ cost: Schema.Finite,
472
+ tokens: Schema.Struct({
473
+ total: Schema.optional(Schema.Finite),
474
+ input: Schema.Finite,
475
+ output: Schema.Finite,
476
+ reasoning: Schema.Finite,
477
+ cache: Schema.Struct({
478
+ read: Schema.Finite,
479
+ write: Schema.Finite,
480
+ }),
481
+ }),
482
+ structured: Schema.optional(Schema.Any),
483
+ variant: Schema.optional(Schema.String),
484
+ finish: Schema.optional(Schema.String),
485
+ }).annotate({ identifier: "SessionV1.AssistantMessage" })
486
+ export type Assistant = Omit<Types.DeepMutable<Schema.Schema.Type<typeof Assistant>>, "error"> & {
487
+ error?: AssistantError
488
+ }
489
+
490
+ export const Info = Schema.Union([User, Assistant]).annotate({ discriminator: "role", identifier: "SessionV1.Message" })
491
+ export type Info = User | Assistant
492
+
493
+ const options = {
494
+ durable: {
495
+ aggregate: "sessionID",
496
+ version: 1,
497
+ },
498
+ } as const
499
+
500
+ const SessionSummary = Schema.Struct({
501
+ additions: Schema.Finite,
502
+ deletions: Schema.Finite,
503
+ files: Schema.Finite,
504
+ diffs: optional(Schema.Array(FileDiff.LegacyInfo)),
505
+ })
506
+
507
+ const SessionTokens = Schema.Struct({
508
+ input: Schema.Finite,
509
+ output: Schema.Finite,
510
+ reasoning: Schema.Finite,
511
+ cache: Schema.Struct({
512
+ read: Schema.Finite,
513
+ write: Schema.Finite,
514
+ }),
515
+ })
516
+
517
+ const SessionShare = Schema.Struct({
518
+ url: Schema.String,
519
+ })
520
+
521
+ const SessionRevert = Schema.Struct({
522
+ messageID: MessageID,
523
+ partID: optional(PartID),
524
+ snapshot: optional(Schema.String),
525
+ diff: optional(Schema.String),
526
+ })
527
+
528
+ const SessionModel = Schema.Struct({
529
+ id: Model.ID,
530
+ providerID: Provider.ID,
531
+ variant: optional(Schema.String),
532
+ })
533
+
534
+ export const SessionInfo = Schema.Struct({
535
+ id: SessionID,
536
+ slug: Schema.String,
537
+ projectID: Project.ID,
538
+ workspaceID: optional(WorkspaceID),
539
+ directory: Schema.String,
540
+ path: optional(Schema.String),
541
+ parentID: optional(SessionID),
542
+ summary: optional(SessionSummary),
543
+ cost: optional(Schema.Finite),
544
+ tokens: optional(SessionTokens),
545
+ share: optional(SessionShare),
546
+ title: optional(Schema.String),
547
+ agent: optional(Schema.String),
548
+ model: optional(SessionModel),
549
+ version: Schema.String,
550
+ metadata: optional(Schema.Record(Schema.String, Schema.Any)),
551
+ time: Schema.Struct({
552
+ created: NonNegativeInt,
553
+ updated: NonNegativeInt,
554
+ compacting: optional(NonNegativeInt),
555
+ archived: optional(Schema.Finite),
556
+ }),
557
+ permission: optional(PermissionV1.Ruleset),
558
+ revert: optional(SessionRevert),
559
+ }).annotate({ identifier: "SessionV1.Info" })
560
+ export type SessionInfo = typeof SessionInfo.Type
561
+
562
+ const events = {
563
+ Created: durable({
564
+ type: "session.created",
565
+ ...options,
566
+ schema: {
567
+ sessionID: SessionID,
568
+ info: SessionInfo,
569
+ },
570
+ }),
571
+ Updated: durable({
572
+ type: "session.updated",
573
+ ...options,
574
+ schema: {
575
+ sessionID: SessionID,
576
+ info: SessionInfo,
577
+ },
578
+ }),
579
+ Deleted: durable({
580
+ type: "session.deleted",
581
+ ...options,
582
+ schema: {
583
+ sessionID: SessionID,
584
+ info: SessionInfo,
585
+ },
586
+ }),
587
+ MessageUpdated: durable({
588
+ type: "message.updated",
589
+ ...options,
590
+ schema: {
591
+ sessionID: SessionID,
592
+ info: Info,
593
+ },
594
+ }),
595
+ MessageRemoved: durable({
596
+ type: "message.removed",
597
+ ...options,
598
+ schema: {
599
+ sessionID: SessionID,
600
+ messageID: MessageID,
601
+ },
602
+ }),
603
+ PartUpdated: durable({
604
+ type: "message.part.updated",
605
+ ...options,
606
+ schema: {
607
+ sessionID: SessionID,
608
+ part: Part,
609
+ time: Schema.Finite,
610
+ },
611
+ }),
612
+ PartRemoved: durable({
613
+ type: "message.part.removed",
614
+ ...options,
615
+ schema: {
616
+ sessionID: SessionID,
617
+ messageID: MessageID,
618
+ partID: PartID,
619
+ },
620
+ }),
621
+ }
622
+
623
+ export const PartDelta = ephemeral({
624
+ type: "message.part.delta",
625
+ schema: {
626
+ sessionID: SessionID,
627
+ messageID: MessageID,
628
+ partID: PartID,
629
+ field: Schema.String,
630
+ delta: Schema.String,
631
+ },
632
+ })
633
+
634
+ export const Diff = ephemeral({
635
+ type: "session.diff",
636
+ schema: {
637
+ sessionID: SessionID,
638
+ diff: Schema.Array(FileDiff.LegacyInfo),
639
+ },
640
+ })
641
+
642
+ export const Error = ephemeral({
643
+ type: "session.error",
644
+ schema: {
645
+ sessionID: Schema.optional(SessionID),
646
+ error: Assistant.fields.error,
647
+ },
648
+ })
649
+
650
+ export const Event = {
651
+ ...events,
652
+ PartDelta,
653
+ Diff,
654
+ Error,
655
+ Definitions: inventory(
656
+ events.Created,
657
+ events.Updated,
658
+ events.Deleted,
659
+ events.MessageUpdated,
660
+ events.MessageRemoved,
661
+ events.PartUpdated,
662
+ events.PartRemoved,
663
+ PartDelta,
664
+ Diff,
665
+ Error,
666
+ ),
667
+ }
@@ -0,0 +1,14 @@
1
+ export * as VcsEvent from "./vcs-event.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional } from "./schema.js"
5
+ import { Event } from "./event.js"
6
+
7
+ export const BranchUpdated = Event.ephemeral({
8
+ type: "vcs.branch.updated",
9
+ schema: {
10
+ branch: optional(Schema.String),
11
+ },
12
+ })
13
+
14
+ export const Definitions = Event.inventory(BranchUpdated)