@sentry/junior 0.204.0 → 0.206.0

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 (66) hide show
  1. package/dist/{agent-CMyTD4DD.js → agent-C9yuiZUF.js} +277 -85
  2. package/dist/{agent-hooks-Bbcp9e33.js → agent-hooks-DNjlz2A-.js} +1084 -16
  3. package/dist/{agent-runner-DNb1A49M.js → agent-runner-E67lFrDG.js} +5 -5
  4. package/dist/api/schema.d.ts +85 -0
  5. package/dist/api/schema.js +2 -2
  6. package/dist/api.js +44 -511
  7. package/dist/{app-B1TOqBI8.d.ts → app-AxGmJHwK.d.ts} +8 -0
  8. package/dist/app.d.ts +1 -1
  9. package/dist/app.js +56 -84
  10. package/dist/{auth-pause-state-DosEalIG.js → auth-pause-state-MVZ6xvEK.js} +6 -6
  11. package/dist/briefs-CvJFQvhJ.js +398 -0
  12. package/dist/{catalog-runtime-BReos-D4.js → catalog-runtime-TBR8n4e1.js} +1 -1
  13. package/dist/{checkpoint-CNrPyRJN.js → checkpoint-BY47jJCB.js} +7 -6
  14. package/dist/cli/chat.js +14 -12
  15. package/dist/cli/check.js +3 -3
  16. package/dist/cli/init.js +1 -0
  17. package/dist/cli/main.js +5 -1
  18. package/dist/cli/plugins.js +3 -3
  19. package/dist/cli/run.d.ts +2 -1
  20. package/dist/cli/run.js +2 -1
  21. package/dist/cli/snapshot-create.js +3 -3
  22. package/dist/cli/upgrade.js +3 -3
  23. package/dist/{config-nGCW1OTG.js → client-ceE7NtvC.js} +4 -367
  24. package/dist/config-CIE83sR2.js +386 -0
  25. package/dist/{schema-Rn8-XEaN.js → conversation-AA4R1VUn.js} +580 -558
  26. package/dist/{conversation-privacy-B4voFRSm.js → conversation-privacy-Auyq26XQ.js} +1 -1
  27. package/dist/{credential-sync-kXr1hvO1.js → credential-sync-BO33aNQd.js} +22 -20
  28. package/dist/{execution-stats-DWfSihcH.js → execution-stats-SiS2FLcv.js} +4 -4
  29. package/dist/{executor-DcMSlI5c.js → executor-BfbYPW63.js} +31 -3
  30. package/dist/instrumentation.js +2 -2
  31. package/dist/{job-queue-Drn_LXlM.js → job-queue-CyTc24Es.js} +1 -1
  32. package/dist/{logging-BzAk1S_s.js → logging-D37bayDc.js} +1 -1
  33. package/dist/nitro.d.ts +1 -1
  34. package/dist/nitro.js +3 -3
  35. package/dist/{oauth-callback-server-JiftokvA.js → oauth-callback-server-BtfOeHTZ.js} +2 -2
  36. package/dist/{pending-auth-CWmSdZVg.js → pending-auth-BPUzcs7n.js} +2 -2
  37. package/dist/{profile-CrT5nXbw.js → profile-CSixooTi.js} +4 -3
  38. package/dist/prompt-3gqNY1Ka.js +552 -0
  39. package/dist/{registry-DH1xUo2N.js → registry-DiR0-xRg.js} +1 -1
  40. package/dist/{resolve-CZHnfxaS.js → resolve-Bn5q__9b.js} +2 -2
  41. package/dist/{runner-CZV2sC46.js → runner-DFx3dIJH.js} +9 -9
  42. package/dist/{sandbox-egress-signals-bHZfmhbd.js → sandbox-egress-signals-bwvjihxA.js} +1 -1
  43. package/dist/schema-8GXFfclK.js +559 -0
  44. package/dist/{skills-CIcDQSgM.js → skills-BhM5qyCF.js} +2 -2
  45. package/dist/{spawn-DdkUFRmq.js → spawn-Dk0PqdH6.js} +2 -2
  46. package/dist/{stats-DTUbAb88.js → stats-DKRP4rsY.js} +26 -12
  47. package/dist/{task-queue-CJIR4RF7.js → task-queue-CdpTvu4R.js} +3 -3
  48. package/dist/{task-runner-D-O3A-Cp.js → task-runner-alpjVSxQ.js} +10 -10
  49. package/dist/{thread-state-CRc9jTJS.js → thread-state-CRK7aA41.js} +5 -5
  50. package/dist/{turn-execution-BkinIdJF.js → turn-execution-XtyzIHog.js} +3 -3
  51. package/dist/{turn-lifecycle-DQV19VTW.js → turn-lifecycle-VbwZLfBv.js} +1 -1
  52. package/dist/{usage-D3EbSO7w.js → usage-D4A48Bdl.js} +4 -125
  53. package/dist/{validation-C2CR-OX3.js → validation-jn_46o4U.js} +1 -1
  54. package/dist/{version-DxcWdoKa.js → version-DcfJxB4z.js} +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/web-authorization-CsfLSfEs.js +38 -0
  57. package/dist/{web-input-3EPfpf55.js → web-input-BPp_sc7t.js} +6 -6
  58. package/dist/{work-fGofI7Op.js → work-Di-ubSGg.js} +9 -9
  59. package/dist/{worker-CsOLq-mR.js → worker-Cu_D5Mr8.js} +5 -4
  60. package/migrations/0040_conversation_briefs.sql +17 -0
  61. package/migrations/meta/0040_snapshot.json +3516 -0
  62. package/migrations/meta/_journal.json +7 -0
  63. package/package.json +4 -4
  64. package/dist/history-CqTuSAdI.js +0 -441
  65. package/dist/usage-schema-CKaDkH_j.js +0 -20
  66. package/dist/web-authorization-RMBxAR_t.js +0 -76
@@ -1,12 +1,578 @@
1
- import { t as juniorDestinationKindSchema } from "./destinations-BeBiJeEM.js";
2
- import { a as conversationTurnFailureReasonSchema, i as conversationTurnFailureCodeSchema } from "./history-CqTuSAdI.js";
3
- import { t as usageSchema } from "./usage-schema-CKaDkH_j.js";
4
- import "./reporting-schema-DosTN__Q.js";
1
+ import { c as TURN_REASONING_LEVELS, o as modelProfileSchema } from "./model-profile-CZmVoGdX.js";
5
2
  import { z } from "zod";
6
- import { codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, taskOutcomeSchema } from "@sentry/junior-plugin-api";
7
- //#region src/api/schema/common.ts
8
- /** Stable error body returned by Junior-owned REST endpoints. */
9
- const apiErrorSchema = z.object({ error: z.string().min(1) }).strict();
3
+ import { actorSchema, codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema } from "@sentry/junior-plugin-api";
4
+ //#region src/chat/conversations/provenance.ts
5
+ /**
6
+ * Durable message attribution shared by storage and projections.
7
+ * Attribution never grants credential authority.
8
+ */
9
+ const conversationMessageAuthoritySchema = z.union([z.literal("instruction"), z.literal("context")]);
10
+ /** Canonical authority and actor metadata for one durable message event. */
11
+ const conversationMessageProvenanceSchema = z.object({
12
+ authority: conversationMessageAuthoritySchema,
13
+ actor: actorSchema.optional()
14
+ }).strict();
15
+ /** Build instruction provenance for an optional actor. */
16
+ function instructionProvenanceFor(actor) {
17
+ return actor ? {
18
+ authority: "instruction",
19
+ actor
20
+ } : { authority: "instruction" };
21
+ }
22
+ /** Unattributed ambient-context provenance for non-instruction messages. */
23
+ const contextProvenance = { authority: "context" };
24
+ function actorIdentityKey(actor) {
25
+ if (actor.platform === "system") return `system ${actor.name}`;
26
+ return actor.platform === "slack" ? `slack\u0000${actor.teamId}\u0000${actor.userId}` : `${actor.platform}\u0000${actor.userId}`;
27
+ }
28
+ /** Compare two actors by runtime identity only, never by display metadata. */
29
+ function sameActorIdentity(left, right) {
30
+ return Boolean(left && right && actorIdentityKey(left) === actorIdentityKey(right));
31
+ }
32
+ /**
33
+ * Return distinct instruction actors in first-seen order for attribution only.
34
+ * Never use this list as credential authority.
35
+ */
36
+ function instructionActors(provenance) {
37
+ const seen = /* @__PURE__ */ new Set();
38
+ const actors = [];
39
+ for (const entry of provenance) {
40
+ if (entry.authority !== "instruction" || !entry.actor) continue;
41
+ const identity = actorIdentityKey(entry.actor);
42
+ if (seen.has(identity)) continue;
43
+ seen.add(identity);
44
+ actors.push(entry.actor);
45
+ }
46
+ return actors;
47
+ }
48
+ //#endregion
49
+ //#region src/chat/conversations/history.ts
50
+ /**
51
+ * Durable conversation event history port.
52
+ *
53
+ * Events append under the conversation lease in stable sequence order.
54
+ * Compaction and handoff replace the active model history without rewriting
55
+ * prior events. Unsupported stored events remain readable as opaque facts,
56
+ * while malformed known events fail loudly. Provider-specific message fields
57
+ * are validated by the Pi adapter when it restores model context.
58
+ */
59
+ const userMessageEventDataSchema = z.object({
60
+ type: z.literal("user_message"),
61
+ role: z.never().optional(),
62
+ provenance: conversationMessageProvenanceSchema
63
+ }).passthrough();
64
+ const assistantMessageEventDataSchema = z.object({
65
+ type: z.literal("assistant_message"),
66
+ role: z.never().optional()
67
+ }).passthrough();
68
+ const toolResultEventDataSchema = z.object({
69
+ type: z.literal("tool_result"),
70
+ role: z.never().optional()
71
+ }).passthrough();
72
+ /**
73
+ * One replayable agent-history item. Junior owns `type` and user provenance,
74
+ * forbids the provider `role` discriminator, and leaves preserved message
75
+ * fields for the Pi adapter to validate when restoring model context.
76
+ */
77
+ const agentHistoryItemSchema = z.discriminatedUnion("type", [
78
+ userMessageEventDataSchema,
79
+ assistantMessageEventDataSchema,
80
+ toolResultEventDataSchema
81
+ ]);
82
+ const nativeReplacementHistoryItemSchema = z.object({
83
+ item: agentHistoryItemSchema,
84
+ sourceEventSeq: z.number().int().nonnegative().optional()
85
+ }).strict();
86
+ /**
87
+ * The complete agent history used immediately after a replacement. Later
88
+ * native history events append to it. Replacement entries are replayed model
89
+ * history, not new conversation activity.
90
+ */
91
+ const replacementHistorySchema = z.array(nativeReplacementHistoryItemSchema);
92
+ const compactionDetailsSchema = z.object({
93
+ reason: z.literal("capacity"),
94
+ estimatedInputTokens: z.number().int().nonnegative(),
95
+ replacementInputTokens: z.number().int().nonnegative().optional(),
96
+ triggerTokens: z.number().int().nonnegative(),
97
+ inputLimitTokens: z.number().int().positive(),
98
+ inputMessageCount: z.number().int().nonnegative(),
99
+ retainedMessageCount: z.number().int().nonnegative(),
100
+ summaryChars: z.number().int().nonnegative()
101
+ }).strict();
102
+ const historyReplacementEventDataSchema = z.discriminatedUnion("type", [z.object({
103
+ type: z.literal("handoff"),
104
+ modelProfile: modelProfileSchema,
105
+ modelId: z.string().min(1),
106
+ reasoningLevel: z.string().min(1).optional(),
107
+ triggeringToolCallId: z.string().min(1).optional(),
108
+ summary: z.string().min(1).optional(),
109
+ replacementHistory: replacementHistorySchema
110
+ }).strict(), z.object({
111
+ type: z.literal("compaction"),
112
+ modelProfile: modelProfileSchema,
113
+ modelId: z.string().min(1),
114
+ details: compactionDetailsSchema.optional(),
115
+ summary: z.string().min(1).optional(),
116
+ replacementHistory: replacementHistorySchema
117
+ }).strict()]);
118
+ /** Validate an event that intentionally replaces active model history. */
119
+ const historyReplacementSchema = z.object({
120
+ data: historyReplacementEventDataSchema,
121
+ createdAtMs: z.number().finite()
122
+ }).strict();
123
+ const mcpProviderConnectedEventDataSchema = z.object({
124
+ type: z.literal("mcp_provider_connected"),
125
+ provider: z.string().min(1),
126
+ credentialSubjectId: z.string().min(1)
127
+ }).strict();
128
+ const unownedMcpProviderConnectedEventDataSchema = z.object({
129
+ type: z.literal("mcp_provider_connected_unowned"),
130
+ provider: z.string().min(1)
131
+ }).strict();
132
+ const authorizationKindSchema = z.union([z.literal("plugin"), z.literal("mcp")]);
133
+ const authorizationRequestedEventDataSchema = z.object({
134
+ type: z.literal("authorization_requested"),
135
+ kind: authorizationKindSchema,
136
+ provider: z.string().min(1),
137
+ actorId: z.string().min(1),
138
+ authorizationId: z.string().min(1),
139
+ delivery: z.union([z.literal("private_link_sent"), z.literal("private_link_reused")])
140
+ }).strict();
141
+ const authorizationCompletedEventDataSchema = z.object({
142
+ type: z.literal("authorization_completed"),
143
+ kind: authorizationKindSchema,
144
+ provider: z.string().min(1),
145
+ actorId: z.string().min(1),
146
+ authorizationId: z.string().min(1)
147
+ }).strict();
148
+ const toolExecutionStartedEventDataSchema = z.object({
149
+ type: z.literal("tool_execution_started"),
150
+ toolCallId: z.string().min(1),
151
+ toolName: z.string().min(1)
152
+ }).strict();
153
+ const guardianActionReviewedEventDataSchema = z.object({
154
+ type: z.literal("guardian_action_reviewed"),
155
+ turnId: z.string().min(1),
156
+ toolCallId: z.string().min(1),
157
+ toolName: z.string().min(1),
158
+ costUsd: z.number().finite().nonnegative().optional(),
159
+ decision: z.enum([
160
+ "allow",
161
+ "ask",
162
+ "deny"
163
+ ]),
164
+ riskLevel: z.enum([
165
+ "low",
166
+ "medium",
167
+ "high",
168
+ "critical"
169
+ ]),
170
+ userAuthorization: z.enum([
171
+ "high",
172
+ "medium",
173
+ "low",
174
+ "unknown"
175
+ ])
176
+ }).strict();
177
+ const conversationMessageRoleSchema = z.union([
178
+ z.literal("user"),
179
+ z.literal("assistant"),
180
+ z.literal("system")
181
+ ]);
182
+ const messageEventDataSchema = z.object({
183
+ type: z.literal("message"),
184
+ messageId: z.string().min(1),
185
+ role: conversationMessageRoleSchema,
186
+ text: z.string(),
187
+ authorIdentityId: z.string().min(1).optional(),
188
+ meta: z.record(z.string(), z.unknown()).optional()
189
+ }).strict();
190
+ const messageUpdatedEventDataSchema = messageEventDataSchema.extend({ type: z.literal("message_updated") });
191
+ const messageHandledEventDataSchema = z.object({
192
+ type: z.literal("message_handled"),
193
+ messageId: z.string().min(1)
194
+ }).strict();
195
+ const messagesSummarizedEventDataSchema = z.object({
196
+ type: z.literal("messages_summarized"),
197
+ historyFromSeq: z.number().int().nonnegative(),
198
+ compactions: z.array(z.object({
199
+ coveredMessageCount: z.number().int().nonnegative(),
200
+ createdAtMs: z.number(),
201
+ id: z.string().min(1),
202
+ summary: z.string()
203
+ }).strict())
204
+ }).strict();
205
+ /** Product surface that owns a durable conversation turn. */
206
+ const conversationTurnSurfaceSchema = z.enum([
207
+ "slack",
208
+ "api",
209
+ "scheduler",
210
+ "internal"
211
+ ]);
212
+ /** Where a failed turn stopped. */
213
+ const conversationTurnFailureCodeSchema = z.enum([
214
+ "agent_run_failed",
215
+ "delivery_failed",
216
+ "model_execution_failed",
217
+ "persistence_failed"
218
+ ]);
219
+ /**
220
+ * Why a failed turn stopped.
221
+ * Values are fixed labels only. Do not store raw exception text.
222
+ */
223
+ const conversationTurnFailureReasonSchema = z.enum([
224
+ "auth",
225
+ "permission",
226
+ "rate_limit",
227
+ "capacity",
228
+ "timeout",
229
+ "network",
230
+ "server",
231
+ "invalid_request",
232
+ "invalid_response",
233
+ "quota",
234
+ "content_policy",
235
+ "unknown",
236
+ "empty_output",
237
+ "tool_errors",
238
+ "suppressed_output"
239
+ ]);
240
+ const turnStartedEventDataSchema = z.object({
241
+ type: z.literal("turn_started"),
242
+ turnId: z.string().min(1),
243
+ inputMessageIds: z.array(z.string().min(1)).min(1),
244
+ surface: conversationTurnSurfaceSchema
245
+ }).strict().refine((data) => new Set(data.inputMessageIds).size === data.inputMessageIds.length, "turn input message ids must be unique");
246
+ const turnRoutedEventDataSchema = z.object({
247
+ type: z.literal("turn_routed"),
248
+ turnId: z.string().min(1),
249
+ modelProfile: modelProfileSchema,
250
+ modelId: z.string().min(1),
251
+ costUsd: z.number().finite().nonnegative().optional(),
252
+ reasoningLevel: z.enum(TURN_REASONING_LEVELS),
253
+ confidence: z.number().min(0).max(1).optional(),
254
+ source: z.enum([
255
+ "configured",
256
+ "inherited",
257
+ "router"
258
+ ])
259
+ }).strict();
260
+ const turnContextEventDataSchema = z.object({
261
+ type: z.literal("turn_context"),
262
+ turnId: z.string().min(1),
263
+ pluginName: z.string().min(1),
264
+ kind: z.string().min(1).max(64),
265
+ version: z.number().int().positive(),
266
+ content: z.record(z.string(), z.unknown())
267
+ }).strict();
268
+ const structuredConversationEventDataSchema = z.object({
269
+ type: z.literal("structured_event"),
270
+ namespace: z.string().regex(/^[a-z][a-z0-9-]*$/),
271
+ name: z.string().regex(/^[a-z][a-z0-9_]*$/),
272
+ version: z.number().int().positive(),
273
+ turnId: z.string().min(1).optional(),
274
+ content: z.record(z.string(), z.unknown())
275
+ }).strict();
276
+ /** Durable attachment metadata on host-owned delivery events. */
277
+ const deliveredAttachmentSchema = z.object({
278
+ id: z.string().min(1),
279
+ filename: z.string().min(1),
280
+ contentType: z.string().min(1),
281
+ bytes: z.number().int().nonnegative()
282
+ }).strict();
283
+ /** Host-owned transcript item for files delivered to humans this turn. */
284
+ const attachmentsDeliveredEventDataSchema = z.object({
285
+ type: z.literal("attachments_delivered"),
286
+ attachments: z.array(deliveredAttachmentSchema).min(1),
287
+ toolCallId: z.string().min(1).optional(),
288
+ turnId: z.string().min(1).optional()
289
+ }).strict();
290
+ const turnCompletedEventDataSchema = z.object({
291
+ type: z.literal("turn_completed"),
292
+ turnId: z.string().min(1),
293
+ outcome: z.enum([
294
+ "success",
295
+ "no_reply",
296
+ "cancelled"
297
+ ])
298
+ }).strict();
299
+ const turnFailedEventDataSchema = z.object({
300
+ type: z.literal("turn_failed"),
301
+ turnId: z.string().min(1),
302
+ failureCode: conversationTurnFailureCodeSchema,
303
+ failureReason: conversationTurnFailureReasonSchema.optional(),
304
+ eventId: z.string().regex(/^[a-f0-9]{32}$/i).optional()
305
+ }).strict();
306
+ const subagentStartedEventDataSchema = z.object({
307
+ type: z.literal("subagent_started"),
308
+ subagentInvocationId: z.string().min(1),
309
+ subagentKind: z.string().min(1),
310
+ modelId: z.string().min(1).optional(),
311
+ parentToolCallId: z.string().min(1).optional(),
312
+ reasoningLevel: z.string().min(1).optional(),
313
+ childConversationId: z.string().min(1)
314
+ }).strict();
315
+ const subagentEndedEventDataSchema = z.object({
316
+ type: z.literal("subagent_ended"),
317
+ subagentInvocationId: z.string().min(1),
318
+ outcome: z.union([
319
+ z.literal("success"),
320
+ z.literal("error"),
321
+ z.literal("aborted")
322
+ ]),
323
+ errorCode: z.string().min(1).optional()
324
+ }).strict();
325
+ /** Prevent ordinary appends from bypassing history-replacement validation. */
326
+ const appendableConversationEventDataSchema = z.union([
327
+ messageEventDataSchema,
328
+ messageUpdatedEventDataSchema,
329
+ agentHistoryItemSchema,
330
+ mcpProviderConnectedEventDataSchema,
331
+ authorizationRequestedEventDataSchema,
332
+ authorizationCompletedEventDataSchema,
333
+ toolExecutionStartedEventDataSchema,
334
+ guardianActionReviewedEventDataSchema,
335
+ messageHandledEventDataSchema,
336
+ messagesSummarizedEventDataSchema,
337
+ turnStartedEventDataSchema,
338
+ turnContextEventDataSchema,
339
+ structuredConversationEventDataSchema,
340
+ attachmentsDeliveredEventDataSchema,
341
+ turnRoutedEventDataSchema,
342
+ turnCompletedEventDataSchema,
343
+ turnFailedEventDataSchema,
344
+ subagentStartedEventDataSchema,
345
+ subagentEndedEventDataSchema
346
+ ]);
347
+ /** Strict event-data contract reused by the SQL row codec. */
348
+ const conversationEventDataSchema = z.union([
349
+ appendableConversationEventDataSchema,
350
+ historyReplacementEventDataSchema,
351
+ unownedMcpProviderConnectedEventDataSchema
352
+ ]);
353
+ /** Event type names recognized by current readers and observational queries. */
354
+ const KNOWN_CONVERSATION_EVENT_TYPES = [
355
+ "message",
356
+ "message_updated",
357
+ "user_message",
358
+ "assistant_message",
359
+ "tool_result",
360
+ "mcp_provider_connected",
361
+ "mcp_provider_connected_unowned",
362
+ "authorization_requested",
363
+ "authorization_completed",
364
+ "tool_execution_started",
365
+ "guardian_action_reviewed",
366
+ "message_handled",
367
+ "messages_summarized",
368
+ "turn_started",
369
+ "turn_context",
370
+ "structured_event",
371
+ "attachments_delivered",
372
+ "turn_routed",
373
+ "turn_completed",
374
+ "turn_failed",
375
+ "subagent_started",
376
+ "subagent_ended",
377
+ "handoff",
378
+ "compaction"
379
+ ];
380
+ const knownConversationEventTypeSchema = z.enum(KNOWN_CONVERSATION_EVENT_TYPES);
381
+ const unknownConversationEventDataSchema = z.object({
382
+ type: z.literal("unknown"),
383
+ originalType: z.string().min(1),
384
+ payload: z.unknown()
385
+ }).strict();
386
+ const conversationEventEnvelopeSchema = z.object({
387
+ schemaVersion: z.number().int().nonnegative(),
388
+ seq: z.number().int().nonnegative(),
389
+ historyVersion: z.number().int().nonnegative(),
390
+ idempotencyKey: z.string().min(1).optional(),
391
+ createdAtMs: z.number().finite()
392
+ }).strict();
393
+ /**
394
+ * Canonical ordered envelope for the durable conversation log.
395
+ * `schemaVersion` is persisted with every physical event row.
396
+ */
397
+ const conversationEventSchema = z.union([conversationEventEnvelopeSchema.extend({
398
+ schemaVersion: z.literal(1),
399
+ data: conversationEventDataSchema
400
+ }), conversationEventEnvelopeSchema.extend({ data: unknownConversationEventDataSchema })]);
401
+ const storedConversationEventSchema = conversationEventEnvelopeSchema.extend({
402
+ type: z.string().min(1),
403
+ payload: z.unknown()
404
+ });
405
+ /**
406
+ * Decode a physical event row without making old or future event types
407
+ * unreadable. Unsupported rows stay opaque until an upgrade migration defines
408
+ * their semantics; known version-one events remain strict so corrupt canonical
409
+ * data cannot be mistaken for compatibility data.
410
+ */
411
+ function decodeStoredConversationEvent(value) {
412
+ const stored = storedConversationEventSchema.parse(value);
413
+ const { type, payload, ...envelope } = stored;
414
+ const knownType = knownConversationEventTypeSchema.safeParse(type).success;
415
+ if (stored.schemaVersion === 1 && knownType) {
416
+ const data = typeof payload === "object" && payload !== null && !Array.isArray(payload) ? {
417
+ ...payload,
418
+ type
419
+ } : { type };
420
+ return conversationEventSchema.parse({
421
+ ...envelope,
422
+ data
423
+ });
424
+ }
425
+ return conversationEventSchema.parse({
426
+ ...envelope,
427
+ data: {
428
+ type: "unknown",
429
+ originalType: type,
430
+ payload
431
+ }
432
+ });
433
+ }
434
+ /** Validate an append without permitting model-history replacement events. */
435
+ const newConversationEventSchema = z.object({
436
+ data: appendableConversationEventDataSchema,
437
+ idempotencyKey: z.string().min(1).optional(),
438
+ createdAtMs: z.number().finite()
439
+ }).strict();
440
+ //#endregion
441
+ //#region src/usage-schema.ts
442
+ const usageCostSchema = z.object({
443
+ input: z.number().finite().nonnegative().optional(),
444
+ output: z.number().finite().nonnegative().optional(),
445
+ cacheRead: z.number().finite().nonnegative().optional(),
446
+ cacheWrite: z.number().finite().nonnegative().optional(),
447
+ total: z.number().finite().nonnegative().optional()
448
+ }).strict();
449
+ const usageSchema = z.object({
450
+ inputTokens: z.number().int().nonnegative().optional(),
451
+ outputTokens: z.number().int().nonnegative().optional(),
452
+ cachedInputTokens: z.number().int().nonnegative().optional(),
453
+ cacheCreationTokens: z.number().int().nonnegative().optional(),
454
+ reasoningTokens: z.number().int().nonnegative().optional(),
455
+ totalTokens: z.number().int().nonnegative().optional(),
456
+ cost: usageCostSchema.optional()
457
+ }).strict();
458
+ //#endregion
459
+ //#region src/chat/briefs/schema.ts
460
+ /**
461
+ * Runtime schemas for the Brief record and the generator input. Both cross a
462
+ * durable or CLI edge, so these schemas own the exported types.
463
+ */
464
+ const lineSchema = z.string().trim().min(1).max(400);
465
+ const urlSchema = z.string().url().max(2048);
466
+ const timestampSchema = z.string().datetime();
467
+ const briefLocationSchema = z.object({
468
+ provider: z.string().trim().min(1).max(100),
469
+ channelName: lineSchema.optional()
470
+ }).strict();
471
+ const briefOutcomeStatusSchema = z.enum([
472
+ "in_progress",
473
+ "answered",
474
+ "done",
475
+ "partial",
476
+ "blocked",
477
+ "abandoned"
478
+ ]);
479
+ const briefCodeChangeSchema = z.object({
480
+ repository: lineSchema,
481
+ number: z.number().int().positive(),
482
+ title: lineSchema.optional(),
483
+ url: urlSchema,
484
+ state: codeChangeStateSchema,
485
+ openedAt: timestampSchema.optional(),
486
+ mergedAt: timestampSchema.optional(),
487
+ closedAt: timestampSchema.optional()
488
+ }).strict();
489
+ const briefLinkSchema = z.object({
490
+ kind: z.enum([
491
+ "code_change",
492
+ "resource",
493
+ "url"
494
+ ]),
495
+ label: lineSchema,
496
+ url: urlSchema,
497
+ status: lineSchema.optional()
498
+ }).strict();
499
+ const briefRecordSchema = z.object({
500
+ startedAt: timestampSchema,
501
+ lastActivityAt: timestampSchema,
502
+ durationMs: z.number().int().nonnegative(),
503
+ participants: z.array(z.object({
504
+ name: lineSchema,
505
+ messages: z.number().int().positive()
506
+ }).strict()),
507
+ userMessages: z.number().int().nonnegative(),
508
+ assistantMessages: z.number().int().nonnegative(),
509
+ toolResults: z.number().int().nonnegative(),
510
+ events: z.number().int().nonnegative(),
511
+ turns: z.number().int().positive().optional(),
512
+ location: briefLocationSchema.optional(),
513
+ codeChanges: z.array(briefCodeChangeSchema)
514
+ }).strict();
515
+ const conversationBriefSchema = z.object({
516
+ schemaVersion: z.literal(1),
517
+ record: briefRecordSchema,
518
+ summary: z.string().trim().min(1).max(600),
519
+ intent: lineSchema,
520
+ outcome: z.object({
521
+ status: briefOutcomeStatusSchema,
522
+ text: z.string().trim().min(1).max(600)
523
+ }).strict(),
524
+ decisions: z.array(z.object({
525
+ text: lineSchema,
526
+ by: lineSchema.optional(),
527
+ kind: z.enum([
528
+ "stated",
529
+ "confirmed",
530
+ "assumed"
531
+ ])
532
+ }).strict()).max(20),
533
+ openDecisions: z.array(z.object({
534
+ text: lineSchema,
535
+ owner: lineSchema.optional()
536
+ }).strict()).max(20),
537
+ facts: z.array(lineSchema).max(30),
538
+ links: z.array(briefLinkSchema).max(40),
539
+ keywords: z.array(z.string().trim().toLowerCase().min(1).max(400)).max(12)
540
+ }).strict();
541
+ const briefEntrySchema = z.object({
542
+ index: z.number().int().nonnegative(),
543
+ role: z.enum([
544
+ "user",
545
+ "assistant",
546
+ "tool",
547
+ "event"
548
+ ]),
549
+ author: lineSchema.optional(),
550
+ text: z.string().min(1),
551
+ createdAtMs: z.number().int().nonnegative(),
552
+ turnId: z.string().min(1).optional()
553
+ }).strict();
554
+ const briefResourceSchema = z.object({
555
+ label: lineSchema,
556
+ url: urlSchema,
557
+ status: lineSchema.optional()
558
+ }).strict();
559
+ const briefInputSchema = z.object({
560
+ conversationId: z.string().min(1),
561
+ title: lineSchema.optional(),
562
+ visibility: z.enum(["private", "public"]),
563
+ location: briefLocationSchema.optional(),
564
+ entries: z.array(briefEntrySchema),
565
+ codeChanges: z.array(briefCodeChangeSchema),
566
+ resources: z.array(briefResourceSchema)
567
+ }).strict();
568
+ /** Parse the provider-neutral input used by every Brief generator adapter. */
569
+ function parseBriefInput(input) {
570
+ const parsed = briefInputSchema.parse(input);
571
+ return {
572
+ ...parsed,
573
+ entries: [...parsed.entries].sort((left, right) => left.index - right.index || left.createdAtMs - right.createdAtMs)
574
+ };
575
+ }
10
576
  //#endregion
11
577
  //#region src/api/schema/conversation.ts
12
578
  const conversationReportStatusSchema = z.enum([
@@ -510,6 +1076,11 @@ function validateConversationEvents(report, context) {
510
1076
  }
511
1077
  }
512
1078
  const conversationDetailReportSchema = conversationSummaryReportSchema.extend({
1079
+ brief: z.object({
1080
+ content: conversationBriefSchema,
1081
+ updatedAt: z.string().datetime(),
1082
+ version: z.number().int().positive()
1083
+ }).strict().optional(),
513
1084
  modelUsage: z.array(conversationModelUsageSchema).optional(),
514
1085
  events: z.array(conversationReportEventSchema),
515
1086
  eventHistory: conversationEventHistorySchema,
@@ -588,553 +1159,4 @@ const conversationStatsReportSchema = z.object({
588
1159
  windowStart: z.string()
589
1160
  }).strict();
590
1161
  //#endregion
591
- //#region src/api/reporting-window.ts
592
- /** Shared UTC day/hour/six-hour windows for dashboard activity series. */
593
- const HOUR_MS = 36e5;
594
- const SIX_HOUR_MS = 6 * HOUR_MS;
595
- const DAY_MS = 24 * HOUR_MS;
596
- /** Start of the UTC calendar day containing `valueMs`. */
597
- function startOfUtcDay(valueMs) {
598
- const date = new Date(valueMs);
599
- date.setUTCHours(0, 0, 0, 0);
600
- return date;
601
- }
602
- /** Start of the UTC hour containing `valueMs`. */
603
- function startOfUtcHour(valueMs) {
604
- const date = new Date(valueMs);
605
- date.setUTCMinutes(0, 0, 0);
606
- return date;
607
- }
608
- /** Start of the UTC 6-hour bucket containing `valueMs` (00/06/12/18). */
609
- function startOfUtcSixHour(valueMs) {
610
- const date = startOfUtcHour(valueMs);
611
- date.setUTCHours(Math.floor(date.getUTCHours() / 6) * 6, 0, 0, 0);
612
- return date;
613
- }
614
- /** UTC day key `YYYY-MM-DD`. */
615
- function utcDayKey(value) {
616
- return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 10);
617
- }
618
- /** UTC hour key `YYYY-MM-DDTHH`. */
619
- function utcHourKey(value) {
620
- return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 13);
621
- }
622
- /** UTC 6-hour bucket key `YYYY-MM-DDTHH` at 00/06/12/18. */
623
- function utcSixHourKey(value) {
624
- return utcHourKey(startOfUtcSixHour(typeof value === "number" ? value : value.getTime()));
625
- }
626
- /** Inclusive trailing UTC day window ending on today's UTC day. */
627
- function trailingUtcDayWindow(nowMs, dayCount) {
628
- const end = startOfUtcDay(nowMs);
629
- const start = new Date(end);
630
- start.setUTCDate(start.getUTCDate() - (dayCount - 1));
631
- return {
632
- end,
633
- start
634
- };
635
- }
636
- /** Inclusive trailing UTC hour window ending on the current UTC hour. */
637
- function trailingUtcHourWindow(nowMs, hourCount = 24) {
638
- const end = startOfUtcHour(nowMs);
639
- return {
640
- end,
641
- start: /* @__PURE__ */ new Date(end.getTime() - (hourCount - 1) * HOUR_MS)
642
- };
643
- }
644
- /** Inclusive trailing UTC 6-hour window ending on the current 6h bucket. */
645
- function trailingUtcSixHourWindow(nowMs, bucketCount = 28) {
646
- const end = startOfUtcSixHour(nowMs);
647
- return {
648
- end,
649
- start: /* @__PURE__ */ new Date(end.getTime() - (bucketCount - 1) * SIX_HOUR_MS)
650
- };
651
- }
652
- /** Fill a fixed UTC day window from a sparse map. */
653
- function fillUtcDays(args) {
654
- const { end, start } = trailingUtcDayWindow(args.nowMs, args.count);
655
- const items = [];
656
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setUTCDate(cursor.getUTCDate() + 1)) {
657
- const date = utcDayKey(cursor);
658
- items.push(args.rows.get(date) ?? args.empty(date));
659
- }
660
- return items;
661
- }
662
- /** Fill a fixed UTC hour window from a sparse map. */
663
- function fillUtcHours(args) {
664
- const hourCount = args.count ?? 24;
665
- const { end, start } = trailingUtcHourWindow(args.nowMs, hourCount);
666
- const items = [];
667
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + HOUR_MS)) {
668
- const date = utcHourKey(cursor);
669
- items.push(args.rows.get(date) ?? args.empty(date));
670
- }
671
- return items;
672
- }
673
- /** Fill a fixed UTC 6-hour window from a map of known rows. */
674
- function fillUtcSixHours(args) {
675
- const bucketCount = args.count ?? 28;
676
- const { end, start } = trailingUtcSixHourWindow(args.nowMs, bucketCount);
677
- const items = [];
678
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + SIX_HOUR_MS)) {
679
- const date = utcSixHourKey(cursor);
680
- items.push(args.rows.get(date) ?? args.empty(date));
681
- }
682
- return items;
683
- }
684
- /**
685
- * Sum hour rows into trailing 6-hour buckets.
686
- * Adds number fields. Keeps other fields from the first row in the bucket.
687
- * Sets `date` to the 6-hour bucket key.
688
- */
689
- function sumUtcHoursIntoSixHours(args) {
690
- const bucketCount = args.count ?? 28;
691
- const bySix = /* @__PURE__ */ new Map();
692
- for (const hour of args.hours) {
693
- const key = utcSixHourKey(Date.parse(`${hour.date}:00:00.000Z`));
694
- const next = {
695
- ...bySix.get(key) ?? args.empty(key),
696
- date: key
697
- };
698
- for (const [field, value] of Object.entries(hour)) {
699
- if (field === "date") continue;
700
- if (typeof value === "number") {
701
- const prior = next[field];
702
- next[field] = (typeof prior === "number" ? prior : 0) + value;
703
- }
704
- }
705
- bySix.set(key, next);
706
- }
707
- return fillUtcSixHours({
708
- count: bucketCount,
709
- empty: args.empty,
710
- nowMs: args.nowMs,
711
- rows: bySix
712
- });
713
- }
714
- //#endregion
715
- //#region src/api/schema/code.ts
716
- const codeChangeSummarySchema = z.object({
717
- closed: z.number().int().nonnegative(),
718
- costUsd: z.number().nonnegative().optional(),
719
- created: z.number().int().nonnegative(),
720
- medianCostUsd: z.number().nonnegative().optional(),
721
- medianMergeTimeMs: z.number().nonnegative().optional(),
722
- merged: z.number().int().nonnegative(),
723
- mergeRate: z.number().min(0).max(1).optional(),
724
- open: z.number().int().nonnegative()
725
- }).strict();
726
- /** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) activity bucket key. */
727
- const codeMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
728
- const codeActivityDaySchema = z.object({
729
- closed: z.number().int().nonnegative(),
730
- created: z.number().int().nonnegative(),
731
- date: codeMetricBucketSchema,
732
- merged: z.number().int().nonnegative()
733
- }).strict();
734
- const codeRepositorySummarySchema = z.object({
735
- closed: z.number().int().nonnegative(),
736
- created: z.number().int().nonnegative(),
737
- id: z.string().uuid(),
738
- medianCostUsd: z.number().nonnegative().optional(),
739
- merged: z.number().int().nonnegative(),
740
- mergeRate: z.number().min(0).max(1).optional(),
741
- name: z.string().min(1),
742
- open: z.number().int().nonnegative(),
743
- provider: z.string().min(1),
744
- url: z.string().url().optional()
745
- }).strict();
746
- const codeChangeSummaryReportSchema = z.object({
747
- closedAt: z.string().optional(),
748
- id: z.string().uuid(),
749
- mergedAt: z.string().optional(),
750
- number: z.number().int().positive(),
751
- openedAt: z.string(),
752
- provider: z.string().min(1),
753
- repository: z.string().min(1),
754
- state: codeChangeStateSchema,
755
- title: z.string().optional(),
756
- url: z.string().url().optional()
757
- }).strict();
758
- const codeOverviewReportSchema = z.object({
759
- activityDays: z.array(codeActivityDaySchema),
760
- activityHours: z.array(codeActivityDaySchema).optional(),
761
- activitySixHours: z.array(codeActivityDaySchema).optional(),
762
- changes: z.array(codeChangeSummaryReportSchema),
763
- generatedAt: z.string(),
764
- repositories: z.array(codeRepositorySummarySchema),
765
- summary: codeChangeSummarySchema,
766
- windowEnd: z.string(),
767
- windowStart: z.string()
768
- }).strict();
769
- /** Person-scoped code activity for one People profile. */
770
- const codePersonReportSchema = z.object({
771
- activityDays: z.array(codeActivityDaySchema),
772
- activityHours: z.array(codeActivityDaySchema).optional(),
773
- activitySixHours: z.array(codeActivityDaySchema).optional(),
774
- generatedAt: z.string(),
775
- summary: codeChangeSummarySchema,
776
- windowEnd: z.string(),
777
- windowStart: z.string()
778
- }).strict();
779
- //#endregion
780
- //#region src/api/activity.ts
781
- const dailyConversationActivitySchema = z.object({
782
- active: z.number(),
783
- conversations: z.number(),
784
- date: z.string(),
785
- durationMs: z.number(),
786
- failed: z.number(),
787
- tokens: z.number().optional()
788
- }).strict();
789
- /** Build a zeroed day for conversation activity projections. */
790
- function emptyActivityDay(date) {
791
- return {
792
- active: 0,
793
- conversations: 0,
794
- date,
795
- durationMs: 0,
796
- failed: 0
797
- };
798
- }
799
- /** Fill a fixed UTC day window from sparse conversation activity. */
800
- function activityDays(days, nowMs, count) {
801
- return fillUtcDays({
802
- count,
803
- empty: emptyActivityDay,
804
- nowMs,
805
- rows: days
806
- });
807
- }
808
- /**
809
- * Fill the trailing 7-day UTC hour window from known hour rows.
810
- * 24h charts use the last 24 points. 7d charts sum hours into 6-hour buckets.
811
- */
812
- function activityHours(hours, nowMs) {
813
- return fillUtcHours({
814
- count: 168,
815
- empty: emptyActivityDay,
816
- nowMs,
817
- rows: hours
818
- });
819
- }
820
- /**
821
- * Fill trailing 6-hour buckets from hour keys or hour rows.
822
- * Hour keys must be summed into 6-hour keys first.
823
- */
824
- function activitySixHours(hours, nowMs) {
825
- return sumUtcHoursIntoSixHours({
826
- empty: emptyActivityDay,
827
- hours: hours instanceof Map ? activityHours(hours, nowMs) : [...hours],
828
- nowMs
829
- });
830
- }
831
- //#endregion
832
- //#region src/api/schema/location.ts
833
- const locationParamsSchema = z.object({ locationId: z.string().min(1) }).strict();
834
- const locationSummaryReportSchema = conversationStatsItemSchema.extend({
835
- id: z.string(),
836
- firstSeenAt: z.string(),
837
- kind: juniorDestinationKindSchema,
838
- lastSeenAt: z.string(),
839
- provider: z.string(),
840
- providerDestinationId: z.string(),
841
- visibility: z.literal("public")
842
- }).strict();
843
- const locationActorSummaryReportSchema = conversationStatsItemSchema.extend({ actor: actorIdentitySchema }).strict();
844
- /** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) activity bucket key. */
845
- const locationMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
846
- const locationActivityDayReportSchema = z.object({
847
- date: locationMetricBucketSchema,
848
- privateConversations: z.number(),
849
- publicConversations: z.number()
850
- }).strict();
851
- const locationDirectoryReportSchema = z.object({
852
- activityDays: z.array(locationActivityDayReportSchema),
853
- activityHours: z.array(locationActivityDayReportSchema).optional(),
854
- activitySixHours: z.array(locationActivityDayReportSchema).optional(),
855
- generatedAt: z.string(),
856
- locations: z.array(locationSummaryReportSchema),
857
- privateActivity: conversationStatsItemSchema,
858
- source: z.literal("conversation_index"),
859
- windowEnd: z.string(),
860
- windowStart: z.string()
861
- }).strict();
862
- const locationDetailReportSchema = locationSummaryReportSchema.extend({
863
- activityDays: z.array(dailyConversationActivitySchema),
864
- activityHours: z.array(dailyConversationActivitySchema).optional(),
865
- activitySixHours: z.array(dailyConversationActivitySchema).optional(),
866
- actors: z.array(locationActorSummaryReportSchema),
867
- generatedAt: z.string(),
868
- recentConversations: z.array(conversationSummaryReportSchema),
869
- source: z.literal("conversation_index"),
870
- windowEnd: z.string(),
871
- windowStart: z.string()
872
- }).strict();
873
- //#endregion
874
- //#region src/api/schema/person.ts
875
- const personParamsSchema = z.object({ email: z.string().trim().min(1) }).strict();
876
- const peopleConversationStatsItemSchema = conversationStatsItemSchema.omit({ costUsd: true });
877
- /** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) activity bucket key. */
878
- const peopleMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
879
- const actorActivityDayReportSchema = z.object({
880
- active: z.number(),
881
- conversations: z.number(),
882
- costUsd: z.number().optional(),
883
- date: peopleMetricBucketSchema,
884
- durationMs: z.number(),
885
- failed: z.number(),
886
- tokens: z.number().optional()
887
- }).strict();
888
- const peopleActivityDayReportSchema = z.object({
889
- activePeople: z.number(),
890
- conversations: z.number(),
891
- date: peopleMetricBucketSchema
892
- }).strict();
893
- const actorTotalsReportSchema = z.object({
894
- active: z.number(),
895
- activeDays: z.number(),
896
- conversations: z.number(),
897
- durationMs: z.number(),
898
- failed: z.number(),
899
- tokens: z.number().optional()
900
- }).strict();
901
- /** Spend and activity for one people-directory range, plus the prior period's spend. */
902
- const actorWindowMetricsSchema = z.object({
903
- conversations: z.number().int().nonnegative(),
904
- costUsd: z.number().finite().nonnegative(),
905
- durationMs: z.number().finite().nonnegative(),
906
- priorCostUsd: z.number().finite().nonnegative()
907
- }).strict();
908
- /** People-directory ranges that match the dashboard range control. */
909
- const actorDirectoryWindowsSchema = z.object({
910
- 1: actorWindowMetricsSchema,
911
- 7: actorWindowMetricsSchema,
912
- 30: actorWindowMetricsSchema,
913
- 90: actorWindowMetricsSchema
914
- }).strict();
915
- const identifiedActorSchema = actorIdentitySchema.extend({ email: z.string().min(1) }).strict();
916
- const actorSummaryReportSchema = actorTotalsReportSchema.extend({
917
- firstSeenAt: z.string(),
918
- lastSeenAt: z.string(),
919
- actor: identifiedActorSchema,
920
- windows: actorDirectoryWindowsSchema
921
- }).strict();
922
- const actorDirectoryReportSchema = z.object({
923
- activityDays: z.array(peopleActivityDayReportSchema),
924
- activityHours: z.array(peopleActivityDayReportSchema).optional(),
925
- activitySixHours: z.array(peopleActivityDayReportSchema).optional(),
926
- generatedAt: z.string(),
927
- people: z.array(actorSummaryReportSchema),
928
- source: z.literal("conversation_index"),
929
- windowEnd: z.string(),
930
- windowStart: z.string()
931
- }).strict();
932
- const actorProfileReportSchema = z.object({
933
- activityDays: z.array(actorActivityDayReportSchema),
934
- activityHours: z.array(actorActivityDayReportSchema).optional(),
935
- activitySixHours: z.array(actorActivityDayReportSchema).optional(),
936
- generatedAt: z.string(),
937
- locations: z.array(peopleConversationStatsItemSchema),
938
- recentConversations: z.array(conversationSummaryReportSchema),
939
- actor: identifiedActorSchema,
940
- source: z.literal("conversation_index"),
941
- surfaces: z.array(peopleConversationStatsItemSchema),
942
- totals: actorTotalsReportSchema,
943
- windowEnd: z.string(),
944
- windowStart: z.string()
945
- }).strict();
946
- const personalSpendReportSchema = z.object({
947
- generatedAt: z.string(),
948
- sevenDaysUsd: z.number().finite().nonnegative(),
949
- source: z.literal("conversation_index"),
950
- thirtyDaysUsd: z.number().finite().nonnegative(),
951
- windowEnd: z.string(),
952
- windowStart: z.string()
953
- }).strict();
954
- //#endregion
955
- //#region src/api/schema/personal-token.ts
956
- const personalTokenMetadataSchema = z.object({
957
- id: z.string().uuid(),
958
- name: z.string(),
959
- tokenSuffix: z.string(),
960
- createdAt: z.string().datetime(),
961
- expiresAt: z.string().datetime(),
962
- lastUsedAt: z.string().datetime().nullable()
963
- }).strict();
964
- const personalTokenListSchema = z.object({ tokens: z.array(personalTokenMetadataSchema) }).strict();
965
- const createPersonalTokenBodySchema = z.object({ name: z.string().trim().min(1).max(80) }).strict();
966
- const createdPersonalTokenSchema = personalTokenMetadataSchema.extend({ token: z.string().startsWith("jr_pat_") }).strict();
967
- const personalTokenParamsSchema = z.object({ id: z.string().uuid() }).strict();
968
- const revokePersonalTokenResponseSchema = z.object({ revoked: z.literal(true) }).strict();
969
- //#endregion
970
- //#region src/api/schema/task.ts
971
- const taskDestinationSchema = z.object({
972
- channelId: z.string().min(1),
973
- label: z.string().min(1),
974
- teamId: z.string().min(1),
975
- visibility: z.enum(["private", "public"])
976
- }).strict();
977
- /** Task run counts for the dashboard range control (24h/7d/30d/90d). */
978
- const taskRunWindowsSchema = z.object({
979
- 1: z.number().int().nonnegative(),
980
- 7: z.number().int().nonnegative(),
981
- 30: z.number().int().nonnegative(),
982
- 90: z.number().int().nonnegative()
983
- }).strict();
984
- const taskSummaryBaseSchema = z.object({
985
- createdAt: z.string().datetime(),
986
- createdBy: z.string().min(1),
987
- createdByEmail: z.string().trim().email().optional(),
988
- destination: taskDestinationSchema,
989
- id: z.string().min(1),
990
- instruction: z.string().min(1),
991
- lastConversationId: z.string().min(1).optional(),
992
- lastRunAt: z.string().datetime().optional(),
993
- ownedByViewer: z.boolean(),
994
- runs: taskRunWindowsSchema,
995
- outcomes: z.array(taskOutcomeSchema).max(5),
996
- /** Short display title; falls back from instruction when unset. */
997
- title: z.string().min(1),
998
- totalRuns: z.number().int().nonnegative()
999
- });
1000
- const scheduledTaskSummarySchema = taskSummaryBaseSchema.extend({
1001
- kind: z.literal("scheduled"),
1002
- nextRunAt: z.string().datetime().optional(),
1003
- schedule: z.string().min(1),
1004
- status: z.enum([
1005
- "active",
1006
- "blocked",
1007
- "completed"
1008
- ])
1009
- }).strict();
1010
- const eventTaskSummarySchema = taskSummaryBaseSchema.extend({
1011
- events: z.array(z.string().min(1)).min(1),
1012
- kind: z.literal("event"),
1013
- resource: z.string().min(1),
1014
- source: z.string().min(1),
1015
- triggerAvailable: z.boolean()
1016
- }).strict();
1017
- const taskSummarySchema = z.discriminatedUnion("kind", [scheduledTaskSummarySchema, eventTaskSummarySchema]);
1018
- /** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) execution bucket key. */
1019
- const taskMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
1020
- /** One UTC day/hour of completed task executions stacked by task type. */
1021
- const taskExecutionDaySchema = z.object({
1022
- /** Linked conversation spend for executions in this bucket. */
1023
- costUsd: z.number().finite().nonnegative(),
1024
- date: taskMetricBucketSchema,
1025
- event: z.number().int().nonnegative(),
1026
- scheduled: z.number().int().nonnegative()
1027
- }).strict();
1028
- const taskListQuerySchema = z.object({ q: z.string().trim().max(200).optional() }).strict();
1029
- const taskListSchema = z.object({
1030
- executionDays: z.array(taskExecutionDaySchema),
1031
- executionHours: z.array(taskExecutionDaySchema).optional(),
1032
- executionSixHours: z.array(taskExecutionDaySchema).optional(),
1033
- tasks: z.array(taskSummarySchema),
1034
- truncated: z.boolean()
1035
- }).strict();
1036
- const taskParamsSchema = z.object({
1037
- id: z.string().min(1),
1038
- kind: z.enum(["scheduled", "event"])
1039
- }).strict();
1040
- const taskExecutionStatusSchema = z.enum([
1041
- "blocked",
1042
- "completed",
1043
- "failed"
1044
- ]);
1045
- const taskExecutionSchema = z.object({
1046
- conversationId: z.string().min(1).optional(),
1047
- /** Estimated model cost for the linked conversation, when known. */
1048
- costUsd: z.number().finite().nonnegative().optional(),
1049
- /** Cumulative conversation runtime in milliseconds, when known. */
1050
- durationMs: z.number().finite().nonnegative().optional(),
1051
- executedAt: z.string().datetime(),
1052
- executionId: z.string().min(1),
1053
- status: taskExecutionStatusSchema,
1054
- title: z.string().min(1).optional(),
1055
- /** Cumulative conversation token total, when known. */
1056
- totalTokens: z.number().int().nonnegative().optional()
1057
- }).strict();
1058
- /** One UTC day/hour of terminal executions for a single task, stacked by status. */
1059
- const taskExecutionStatusDaySchema = z.object({
1060
- blocked: z.number().int().nonnegative(),
1061
- completed: z.number().int().nonnegative(),
1062
- date: taskMetricBucketSchema,
1063
- failed: z.number().int().nonnegative()
1064
- }).strict();
1065
- const taskExecutionListSchema = z.object({
1066
- executionDays: z.array(taskExecutionStatusDaySchema),
1067
- executionHours: z.array(taskExecutionStatusDaySchema).optional(),
1068
- executionSixHours: z.array(taskExecutionStatusDaySchema).optional(),
1069
- executions: z.array(taskExecutionSchema),
1070
- task: taskSummarySchema,
1071
- truncated: z.boolean()
1072
- }).strict();
1073
- const taskRunSchema = taskExecutionSchema.extend({
1074
- kind: z.enum(["scheduled", "event"]),
1075
- taskId: z.string().min(1),
1076
- taskTitle: z.string().min(1)
1077
- }).strict();
1078
- const taskRunListSchema = z.object({
1079
- runs: z.array(taskRunSchema),
1080
- truncated: z.boolean()
1081
- }).strict();
1082
- //#endregion
1083
- //#region src/api/schema/workspace.ts
1084
- const workspaceRepoInputSchema = z.object({
1085
- provider: z.string(),
1086
- repo: z.string()
1087
- }).strict();
1088
- const workspaceRepoSchema = z.object({
1089
- provider: z.string(),
1090
- repo: z.string(),
1091
- checkoutPath: z.string()
1092
- }).strict();
1093
- const workspaceSnapshotSchema = z.object({
1094
- id: z.string(),
1095
- generatedAt: z.iso.datetime(),
1096
- buildDurationMs: z.number().int().nonnegative(),
1097
- sizeBytes: z.number().int().nonnegative().nullable()
1098
- }).strict();
1099
- /** Install-wide baseline Sandbox snapshot used when no Workspace recipe is selected. */
1100
- const baselineSnapshotSchema = z.object({
1101
- id: z.string(),
1102
- generatedAt: z.iso.datetime(),
1103
- buildDurationMs: z.number().int().nonnegative(),
1104
- dependencyCount: z.number().int().nonnegative()
1105
- }).strict();
1106
- const workspaceSchema = z.object({
1107
- id: z.string().uuid(),
1108
- name: z.string(),
1109
- setupScript: z.string(),
1110
- repos: z.array(workspaceRepoSchema),
1111
- snapshot: workspaceSnapshotSchema.nullable()
1112
- }).strict();
1113
- const workspaceListSchema = z.object({
1114
- baselineSnapshot: baselineSnapshotSchema.nullable(),
1115
- workspaces: z.array(workspaceSchema)
1116
- }).strict();
1117
- const workspaceBodySchema = z.object({
1118
- name: z.string(),
1119
- setupScript: z.string().optional(),
1120
- repos: z.array(workspaceRepoInputSchema)
1121
- }).strict();
1122
- const workspaceParamsSchema = z.object({ id: z.string().uuid() }).strict();
1123
- const deleteWorkspaceResponseSchema = z.object({ deleted: z.literal(true) }).strict();
1124
- //#endregion
1125
- //#region src/api/schema/stats.ts
1126
- const statSchema = z.object({
1127
- count: z.number().int().nonnegative(),
1128
- date: z.string(),
1129
- metric: z.string().min(1),
1130
- name: z.string().min(1),
1131
- namespace: z.string().min(1)
1132
- }).strict();
1133
- const statsReportSchema = z.object({
1134
- generatedAt: z.string().datetime(),
1135
- stats: z.array(statSchema),
1136
- windowEnd: z.string(),
1137
- windowStart: z.string()
1138
- }).strict();
1139
- //#endregion
1140
- export { sumUtcHoursIntoSixHours as $, actorProfileReportSchema as A, createConversationMessageBodySchema as At, dailyConversationActivitySchema as B, createPersonalTokenBodySchema as C, conversationPendingMessageSchema as Ct, personalTokenParamsSchema as D, conversationStatsReportSchema as Dt, personalTokenMetadataSchema as E, conversationReportEventSchema as Et, locationDirectoryReportSchema as F, codePersonReportSchema as G, codeChangeSummaryReportSchema as H, locationParamsSchema as I, HOUR_MS as J, codeRepositorySummarySchema as K, activityDays as L, personalSpendReportSchema as M, locationActivityDayReportSchema as N, revokePersonalTokenResponseSchema as O, conversationSummaryReportSchema as Ot, locationDetailReportSchema as P, startOfUtcHour as Q, activityHours as R, taskSummarySchema as S, conversationPendingMessageDeliverySchema as St, personalTokenListSchema as T, conversationReportEventDataSchema as Tt, codeChangeSummarySchema as U, codeActivityDaySchema as V, codeOverviewReportSchema as W, fillUtcHours as X, fillUtcDays as Y, fillUtcSixHours as Z, taskListSchema as _, conversationEventsQuerySchema as _t, workspaceBodySchema as a, acceptedConversationMessageSchema as at, taskRunSchema as b, conversationParamsSchema as bt, workspaceRepoSchema as c, cancelConversationPendingMessagesBodySchema as ct, scheduledTaskSummarySchema as d, conversationAttachmentParamsSchema as dt, trailingUtcDayWindow as et, taskExecutionListSchema as f, conversationAuxiliaryCostsSchema as ft, taskListQuerySchema as g, conversationEventPageSchema as gt, taskExecutionStatusSchema as h, conversationEventHistorySchema as ht, deleteWorkspaceResponseSchema as i, utcHourKey as it, personParamsSchema as j, apiErrorSchema as jt, actorDirectoryReportSchema as k, createConversationBodySchema as kt, workspaceSchema as l, cancelConversationPendingMessagesResponseSchema as lt, taskExecutionStatusDaySchema as m, conversationDetailReportSchema as mt, statsReportSchema as n, trailingUtcSixHourWindow as nt, workspaceListSchema as o, archiveConversationBodySchema as ot, taskExecutionSchema as p, conversationDetailQuerySchema as pt, DAY_MS as q, baselineSnapshotSchema as r, utcDayKey as rt, workspaceParamsSchema as s, archiveConversationResponseSchema as st, statSchema as t, trailingUtcHourWindow as tt, eventTaskSummarySchema as u, conversationActivityPreviewSchema as ut, taskParamsSchema as v, conversationFeedQuerySchema as vt, createdPersonalTokenSchema as w, conversationPendingMessagesReportSchema as wt, taskRunWindowsSchema as x, conversationPendingAuthorizationSchema as xt, taskRunListSchema as y, conversationFeedSchema as yt, activitySixHours as z };
1162
+ export { briefLinkSchema as A, decodeStoredConversationEvent as B, conversationReportEventSchema as C, createConversationBodySchema as D, conversationSummaryReportSchema as E, KNOWN_CONVERSATION_EVENT_TYPES as F, instructionProvenanceFor as G, newConversationEventSchema as H, agentHistoryItemSchema as I, sameActorIdentity as K, conversationEventDataSchema as L, conversationBriefSchema as M, parseBriefInput as N, createConversationMessageBodySchema as O, usageSchema as P, conversationTurnFailureCodeSchema as R, conversationReportEventDataSchema as S, conversationStatsReportSchema as T, contextProvenance as U, historyReplacementSchema as V, instructionActors as W, conversationParamsSchema as _, cancelConversationPendingMessagesBodySchema as a, conversationPendingMessageSchema as b, conversationAttachmentParamsSchema as c, conversationDetailReportSchema as d, conversationEventHistorySchema as f, conversationFeedSchema as g, conversationFeedQuerySchema as h, archiveConversationResponseSchema as i, briefOutcomeStatusSchema as j, briefCodeChangeSchema as k, conversationAuxiliaryCostsSchema as l, conversationEventsQuerySchema as m, actorIdentitySchema as n, cancelConversationPendingMessagesResponseSchema as o, conversationEventPageSchema as p, archiveConversationBodySchema as r, conversationActivityPreviewSchema as s, acceptedConversationMessageSchema as t, conversationDetailQuerySchema as u, conversationPendingAuthorizationSchema as v, conversationStatsItemSchema as w, conversationPendingMessagesReportSchema as x, conversationPendingMessageDeliverySchema as y, conversationTurnFailureReasonSchema as z };