@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.
- package/AGENTS.md +95 -95
- package/package.json +5 -1
- package/script/build.ts +9 -9
- package/script/config-schema.ts +86 -86
- package/script/config-v1.json +1311 -1311
- package/script/pack.ts +5 -5
- package/src/agent.ts +68 -68
- package/src/artifact.ts +81 -81
- package/src/automation.ts +224 -224
- package/src/blob-store.ts +25 -25
- package/src/command.ts +18 -18
- package/src/config/agent.ts +26 -26
- package/src/config/command.ts +14 -14
- package/src/config/compaction.ts +27 -27
- package/src/config/experimental.ts +72 -72
- package/src/config/flag.ts +39 -39
- package/src/config/formatter.ts +13 -13
- package/src/config/lsp.ts +19 -19
- package/src/config/mcp.ts +22 -22
- package/src/config/media.ts +15 -15
- package/src/config/model.ts +37 -37
- package/src/config/plugin.ts +14 -14
- package/src/config/policy.ts +57 -57
- package/src/config/provider.ts +122 -122
- package/src/config/reference.ts +23 -23
- package/src/config/shell.ts +10 -10
- package/src/config/tool-output.ts +9 -9
- package/src/config/warming.ts +21 -21
- package/src/config/watcher.ts +8 -8
- package/src/config/websearch.ts +17 -17
- package/src/config/worktree.ts +10 -10
- package/src/config.ts +149 -149
- package/src/connection.ts +38 -38
- package/src/credential-legacy.ts +29 -29
- package/src/credential.ts +78 -78
- package/src/durable-event-manifest.ts +7 -7
- package/src/event-log.ts +21 -21
- package/src/event-manifest.ts +108 -108
- package/src/event.ts +205 -205
- package/src/file-diff.ts +25 -25
- package/src/filesystem-v1.ts +1 -1
- package/src/filesystem.ts +48 -48
- package/src/form.ts +177 -177
- package/src/generate.ts +292 -292
- package/src/goal.ts +46 -46
- package/src/identifier.ts +32 -32
- package/src/index.ts +51 -51
- package/src/installation-event.ts +20 -20
- package/src/instruction-entry.ts +40 -40
- package/src/instruction.ts +25 -25
- package/src/integration-id.ts +13 -13
- package/src/integration.ts +129 -129
- package/src/job.ts +79 -79
- package/src/legacy-event.ts +1 -1
- package/src/llm.ts +6 -6
- package/src/location-event.ts +8 -8
- package/src/location.ts +36 -36
- package/src/lsp-event.ts +7 -7
- package/src/mcp-event.ts +63 -63
- package/src/mcp.ts +171 -171
- package/src/model-compatibility.ts +55 -55
- package/src/model.ts +176 -176
- package/src/models-dev.ts +9 -9
- package/src/money.ts +18 -18
- package/src/permission-saved.ts +25 -25
- package/src/permission-v1.ts +1 -1
- package/src/permission.ts +67 -67
- package/src/persistent-pty.ts +73 -73
- package/src/plugin.ts +62 -62
- package/src/project-id.ts +9 -9
- package/src/project.ts +62 -62
- package/src/prompt-input.ts +33 -33
- package/src/prompt.ts +117 -117
- package/src/provider.ts +136 -136
- package/src/pty-ticket.ts +10 -10
- package/src/pty.ts +61 -61
- package/src/push.ts +86 -86
- package/src/question.ts +22 -22
- package/src/reference.ts +40 -40
- package/src/rpc.ts +167 -167
- package/src/schema.ts +41 -41
- package/src/server-event.ts +8 -8
- package/src/session-error.ts +14 -14
- package/src/session-event.ts +739 -739
- package/src/session-fork.ts +10 -10
- package/src/session-id.ts +12 -12
- package/src/session-inbox.ts +102 -102
- package/src/session-legacy.ts +117 -117
- package/src/session-message.ts +352 -352
- package/src/session-metadata.ts +11 -11
- package/src/session-revert.ts +86 -86
- package/src/session-stats.ts +68 -68
- package/src/session-status-event.ts +53 -53
- package/src/session-transfer.ts +11 -11
- package/src/session-v1.ts +1 -1
- package/src/session.ts +147 -147
- package/src/shell.ts +90 -90
- package/src/skill.ts +68 -68
- package/src/snapshot.ts +6 -6
- package/src/token-usage.ts +18 -18
- package/src/tool.ts +143 -143
- package/src/tui-event.ts +59 -59
- package/src/usage-limits.ts +76 -76
- package/src/v1/filesystem.ts +11 -11
- package/src/v1/legacy-event.ts +18 -18
- package/src/v1/permission.ts +66 -66
- package/src/v1/session.ts +667 -667
- package/src/vcs-event.ts +14 -14
- package/src/vcs.ts +41 -41
- package/src/websearch.ts +44 -44
- package/src/workspace-event.ts +32 -32
- package/src/workspace-id.ts +19 -19
- package/src/workspace.ts +20 -20
- package/src/worktree-event.ts +22 -22
- package/src/worktree.ts +109 -109
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +14 -14
- package/test/agent.test.ts +0 -10
- package/test/automation.test.ts +0 -48
- package/test/compatibility.test.ts +0 -10
- package/test/config.test.ts +0 -194
- package/test/contract-hygiene.test.ts +0 -352
- package/test/credential-legacy.test.ts +0 -55
- package/test/event-manifest.test.ts +0 -228
- package/test/event.test.ts +0 -52
- package/test/legacy-event.test.ts +0 -46
- package/test/mcp.test.ts +0 -37
- package/test/model.test.ts +0 -104
- package/test/session-cursor.test.ts +0 -16
- package/test/session-error.test.ts +0 -51
- package/test/session-legacy.test.ts +0 -178
- package/test/session-terminal.test.ts +0 -50
- package/test/token-usage.test.ts +0 -18
- package/test/v1-isolation.test.ts +0 -26
- package/test/vcs.test.ts +0 -23
- package/test/worktree.test.ts +0 -45
package/src/v1/session.ts
CHANGED
|
@@ -1,667 +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
|
-
}
|
|
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
|
+
}
|