@irogane/kaji 0.2.0-beta.11 → 0.3.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 (137) hide show
  1. package/README.md +112 -551
  2. package/dist/index.d.mts +253 -0
  3. package/dist/index.mjs +440 -0
  4. package/package.json +28 -166
  5. package/contracts/README.md +0 -14
  6. package/contracts/beta-core-v1.json +0 -52
  7. package/contracts/cli/init-cases-v1.json +0 -27
  8. package/contracts/errors/error-codes.json +0 -48
  9. package/contracts/errors/integration-recovery-v1.json +0 -127
  10. package/contracts/errors/provider-normalization.json +0 -111
  11. package/contracts/events/conformance-invalid.json +0 -20
  12. package/contracts/events/conformance.json +0 -511
  13. package/contracts/events/new-kaji-event-v1.schema.json +0 -1021
  14. package/contracts/events/stored-kaji-event-v1.schema.json +0 -1025
  15. package/contracts/feature-tiers-v1.json +0 -488
  16. package/contracts/integrations/abi-index-v1.json +0 -8
  17. package/contracts/integrations/conformance-invalid.json +0 -443
  18. package/contracts/integrations/conformance-valid.json +0 -121
  19. package/contracts/integrations/copy-provenance-v1.schema.json +0 -61
  20. package/contracts/integrations/echo-tool-abi-v1.json +0 -37
  21. package/contracts/integrations/github-api-conformance-v1.json +0 -644
  22. package/contracts/integrations/github-tool-abi-typescript-v1.json +0 -369
  23. package/contracts/integrations/github-tool-abi-v1.json +0 -146
  24. package/contracts/integrations/gmail-api-conformance-v1.json +0 -750
  25. package/contracts/integrations/gmail-tool-abi-v1.json +0 -62
  26. package/contracts/integrations/index.schema.json +0 -37
  27. package/contracts/integrations/manifest.schema.json +0 -119
  28. package/contracts/parity/expected-normalized.json +0 -4906
  29. package/contracts/parity/scenarios.json +0 -100
  30. package/contracts/parity/scenarios.schema.json +0 -214
  31. package/contracts/providers/cost-conformance.json +0 -112
  32. package/contracts/release/github-proof-v1.schema.json +0 -138
  33. package/contracts/release/gmail-proof-v1.schema.json +0 -138
  34. package/contracts/release/kaji-ts-consumer-handoff-v1.schema.json +0 -1289
  35. package/contracts/release/publisher-identity-receipt-v1.schema.json +0 -319
  36. package/contracts/release/typescript-onboarding-evidence-v1.schema.json +0 -740
  37. package/contracts/tools/conformance-invalid.json +0 -271
  38. package/contracts/tools/conformance-valid.json +0 -78
  39. package/contracts/tools/tool-schema-v1.schema.json +0 -18
  40. package/dist/anthropic.cjs +0 -1231
  41. package/dist/anthropic.cjs.map +0 -1
  42. package/dist/anthropic.d.cts +0 -26
  43. package/dist/anthropic.d.ts +0 -26
  44. package/dist/anthropic.js +0 -270
  45. package/dist/anthropic.js.map +0 -1
  46. package/dist/auth.cjs +0 -1507
  47. package/dist/auth.cjs.map +0 -1
  48. package/dist/auth.d.cts +0 -129
  49. package/dist/auth.d.ts +0 -129
  50. package/dist/auth.js +0 -1039
  51. package/dist/auth.js.map +0 -1
  52. package/dist/base-B9FRMcP8.d.cts +0 -140
  53. package/dist/base-nHQd1VtS.d.ts +0 -140
  54. package/dist/chunk-AAM33KAO.js +0 -4367
  55. package/dist/chunk-AAM33KAO.js.map +0 -1
  56. package/dist/chunk-KAJ6BM64.js +0 -153
  57. package/dist/chunk-KAJ6BM64.js.map +0 -1
  58. package/dist/chunk-KCAXIOZS.js +0 -308
  59. package/dist/chunk-KCAXIOZS.js.map +0 -1
  60. package/dist/chunk-LSJ4AVO2.js +0 -243
  61. package/dist/chunk-LSJ4AVO2.js.map +0 -1
  62. package/dist/chunk-TM7ZGOJX.js +0 -716
  63. package/dist/chunk-TM7ZGOJX.js.map +0 -1
  64. package/dist/cli/bin.d.ts +0 -2
  65. package/dist/cli/bin.js +0 -13
  66. package/dist/cli/bin.js.map +0 -1
  67. package/dist/cli/chunk-2RCWPRVY.js +0 -6277
  68. package/dist/cli/chunk-2RCWPRVY.js.map +0 -1
  69. package/dist/cli/chunk-SEBX54TR.js +0 -681
  70. package/dist/cli/chunk-SEBX54TR.js.map +0 -1
  71. package/dist/cli/index.d.ts +0 -232
  72. package/dist/cli/index.js +0 -11
  73. package/dist/cli/index.js.map +0 -1
  74. package/dist/cli/init-worker.d.ts +0 -2
  75. package/dist/cli/init-worker.js +0 -18
  76. package/dist/cli/init-worker.js.map +0 -1
  77. package/dist/cli/integration-copy-worker.js +0 -48
  78. package/dist/cli/integration-copy-worker.js.map +0 -1
  79. package/dist/cli/package-entry-cjs.cjs +0 -21
  80. package/dist/cli/package-entry-cjs.cjs.map +0 -1
  81. package/dist/cli/package-entry-cjs.d.cts +0 -2
  82. package/dist/cli/package-entry.d.ts +0 -2
  83. package/dist/cli/package-entry.js +0 -13
  84. package/dist/cli/package-entry.js.map +0 -1
  85. package/dist/context-BaFHrQHv.d.cts +0 -21
  86. package/dist/context-BaFHrQHv.d.ts +0 -21
  87. package/dist/context-C-YPY-GS.d.cts +0 -1538
  88. package/dist/context-C-YPY-GS.d.ts +0 -1538
  89. package/dist/index.cjs +0 -12346
  90. package/dist/index.cjs.map +0 -1
  91. package/dist/index.d.cts +0 -1560
  92. package/dist/index.d.ts +0 -1560
  93. package/dist/index.js +0 -7852
  94. package/dist/index.js.map +0 -1
  95. package/dist/integrations/github.cjs +0 -2092
  96. package/dist/integrations/github.cjs.map +0 -1
  97. package/dist/integrations/github.d.cts +0 -21
  98. package/dist/integrations/github.d.ts +0 -21
  99. package/dist/integrations/github.js +0 -2088
  100. package/dist/integrations/github.js.map +0 -1
  101. package/dist/integrations.cjs +0 -3370
  102. package/dist/integrations.cjs.map +0 -1
  103. package/dist/integrations.d.cts +0 -202
  104. package/dist/integrations.d.ts +0 -202
  105. package/dist/integrations.js +0 -2650
  106. package/dist/integrations.js.map +0 -1
  107. package/dist/observability-Cj--OkME.d.cts +0 -96
  108. package/dist/observability-Cj--OkME.d.ts +0 -96
  109. package/dist/openai.cjs +0 -1235
  110. package/dist/openai.cjs.map +0 -1
  111. package/dist/openai.d.cts +0 -32
  112. package/dist/openai.d.ts +0 -32
  113. package/dist/openai.js +0 -272
  114. package/dist/openai.js.map +0 -1
  115. package/dist/testing.cjs +0 -554
  116. package/dist/testing.cjs.map +0 -1
  117. package/dist/testing.d.cts +0 -43
  118. package/dist/testing.d.ts +0 -43
  119. package/dist/testing.js +0 -118
  120. package/dist/testing.js.map +0 -1
  121. package/registry/echo/index.ts +0 -53
  122. package/registry/echo/manifest.json +0 -53
  123. package/registry/github/LICENSE +0 -105
  124. package/registry/github/client.ts +0 -1727
  125. package/registry/github/index.ts +0 -263
  126. package/registry/github/manifest.json +0 -227
  127. package/registry/github/owner-fixtures.json +0 -10
  128. package/registry/github/tests/github.test.ts +0 -32
  129. package/registry/gmail/LICENSE +0 -105
  130. package/registry/gmail/client.ts +0 -548
  131. package/registry/gmail/index.ts +0 -165
  132. package/registry/gmail/manifest.json +0 -102
  133. package/registry/gmail/owner-fixtures.json +0 -10
  134. package/registry/gmail/tests/gmail.test.ts +0 -32
  135. package/registry/index.json +0 -21
  136. package/registry/index.schema.json +0 -37
  137. package/registry/schema.json +0 -119
@@ -1,2650 +0,0 @@
1
- import { canonicalJsonValue, cloneAndFreezeJson, durableJsonSnapshot } from './chunk-KAJ6BM64.js';
2
- import { defaultUuid, isClosedRecoveryTuple, IntegrationTransportError, IntegrationPolicyError } from './chunk-KCAXIOZS.js';
3
- export { INTEGRATION_RECOVERY, IntegrationAuthRequiredError, IntegrationExecutionError, IntegrationPolicyError, IntegrationRateLimitedError, IntegrationTransientReadError, closedRecoveryFields } from './chunk-KCAXIOZS.js';
4
- import { NOOP_METRICS, NOOP_TRACE, startSpan, recordMetric } from './chunk-LSJ4AVO2.js';
5
- import * as z from 'zod';
6
- import Ajv2020 from 'ajv/dist/2020.js';
7
- import { Agent, request } from 'https';
8
-
9
- // src/events/types.ts
10
- var EventType = {
11
- SESSION_CREATED: "session.created",
12
- SESSION_CLOSED: "session.closed",
13
- USER_MESSAGE: "user.message",
14
- USER_AUDIO_CHUNK: "user.audio.chunk",
15
- TRANSCRIPT_PARTIAL: "transcript.partial",
16
- TRANSCRIPT_FINAL: "transcript.final",
17
- MEMORY_RETRIEVAL_STARTED: "memory.retrieval.started",
18
- MEMORY_RETRIEVAL_COMPLETED: "memory.retrieval.completed",
19
- AGENT_REASONING_STARTED: "agent.reasoning.started",
20
- AGENT_MESSAGE_DELTA: "agent.message.delta",
21
- AGENT_MESSAGE_COMPLETED: "agent.message.completed",
22
- AGENT_TURN_EXHAUSTED: "agent.turn.exhausted",
23
- AGENT_TURN_FAILED: "agent.turn.failed",
24
- TOOL_CALL_REQUESTED: "tool.call.requested",
25
- TOOL_CALL_STARTED: "tool.call.started",
26
- TOOL_CALL_COMPLETED: "tool.call.completed",
27
- TOOL_CALL_FAILED: "tool.call.failed",
28
- TOOL_APPROVAL_REQUESTED: "tool.approval.requested",
29
- TOOL_APPROVAL_APPROVED: "tool.approval.approved",
30
- TOOL_APPROVAL_REJECTED: "tool.approval.rejected",
31
- WORKFLOW_STARTED: "workflow.started",
32
- WORKFLOW_COMPLETED: "workflow.completed",
33
- WORKFLOW_FAILED: "workflow.failed",
34
- CANCELLATION_REQUESTED: "cancellation.requested",
35
- CANCELLATION_COMPLETED: "cancellation.completed"
36
- };
37
-
38
- // contracts/events/new-kaji-event-v1.schema.json
39
- var new_kaji_event_v1_schema_default = {
40
- $schema: "https://json-schema.org/draft/2020-12/schema",
41
- $id: "https://kaji.dev/contracts/events/new-kaji-event-v1.schema.json",
42
- title: "New Kaji event",
43
- "x-maxSerializedBytes": 1048576,
44
- $defs: {
45
- nonEmptyId: {
46
- type: "string",
47
- minLength: 1
48
- },
49
- integrationRecoveryFields: {
50
- oneOf: [
51
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "github_token_missing" }, recovery_code: { const: "CONFIGURE_GITHUB_TOKEN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#github-token" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
52
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "gmail_grant_missing" }, recovery_code: { const: "CONNECT_GMAIL" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-grant" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
53
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_missing" }, recovery_code: { const: "RESTORE_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-missing" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
54
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_locked" }, recovery_code: { const: "UNLOCK_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-locked" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
55
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_corrupt" }, recovery_code: { const: "RESET_GMAIL_GRANT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-corrupt" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
56
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_unsupported" }, recovery_code: { const: "USE_SUPPORTED_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-unsupported" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
57
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "gmail_scope_drift" }, recovery_code: { const: "RECONNECT_GMAIL" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-scope-drift" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
58
- { properties: { error_code: { const: "INTEGRATION_POLICY_REJECTED" }, reason_code: { const: "policy_rejected" }, recovery_code: { const: "REVIEW_INTEGRATION_POLICY" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#policy-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
59
- { properties: { error_code: { const: "INTEGRATION_API_ERROR" }, reason_code: { const: "api_rejected" }, recovery_code: { const: "REVIEW_PROVIDER_REJECTION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#api-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
60
- { properties: { error_code: { const: "INTEGRATION_API_ERROR" }, reason_code: { const: "transient_read_failed" }, recovery_code: { const: "RETRY_INTEGRATION_READ" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#transient-read" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
61
- { properties: { error_code: { const: "INTEGRATION_RATE_LIMITED" }, reason_code: { const: "rate_limited" }, recovery_code: { const: "RETRY_AFTER_RATE_LIMIT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#rate-limited" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
62
- { properties: { error_code: { const: "INTEGRATION_REDIRECT_REJECTED" }, reason_code: { const: "redirect_rejected" }, recovery_code: { const: "REJECT_PROVIDER_REDIRECT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#redirect-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
63
- { properties: { error_code: { const: "INTEGRATION_RESPONSE_LIMIT" }, reason_code: { const: "response_limit_exceeded" }, recovery_code: { const: "REDUCE_INTEGRATION_RESPONSE" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#response-limit" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
64
- { properties: { error_code: { const: "TOOL_EXECUTION_FAILED" }, reason_code: { const: "github_mutation_unknown" }, recovery_code: { const: "RECONCILE_GITHUB_MUTATION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#github-mutation-unknown" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
65
- { properties: { error_code: { const: "TOOL_EXECUTION_FAILED" }, reason_code: { const: "gmail_mutation_unknown" }, recovery_code: { const: "RECONCILE_GMAIL_MUTATION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-mutation-unknown" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] }
66
- ]
67
- },
68
- safeInteger: {
69
- type: "integer",
70
- minimum: -9007199254740991,
71
- maximum: 9007199254740991
72
- },
73
- positiveInteger: {
74
- allOf: [
75
- {
76
- $ref: "#/$defs/safeInteger"
77
- },
78
- {
79
- minimum: 1
80
- }
81
- ]
82
- },
83
- nonNegativeInteger: {
84
- allOf: [
85
- {
86
- $ref: "#/$defs/safeInteger"
87
- },
88
- {
89
- minimum: 0
90
- }
91
- ]
92
- },
93
- jsonNumber: {
94
- oneOf: [
95
- {
96
- $ref: "#/$defs/safeInteger"
97
- },
98
- {
99
- type: "number",
100
- not: {
101
- type: "integer"
102
- }
103
- }
104
- ]
105
- },
106
- nonNegativeNumber: {
107
- allOf: [
108
- {
109
- $ref: "#/$defs/jsonNumber"
110
- },
111
- {
112
- minimum: 0
113
- }
114
- ]
115
- },
116
- jsonValue: {
117
- oneOf: [
118
- {
119
- type: "null"
120
- },
121
- {
122
- type: "boolean"
123
- },
124
- {
125
- $ref: "#/$defs/jsonNumber"
126
- },
127
- {
128
- type: "string"
129
- },
130
- {
131
- type: "array",
132
- items: {
133
- $ref: "#/$defs/jsonValue"
134
- }
135
- },
136
- {
137
- type: "object",
138
- additionalProperties: {
139
- $ref: "#/$defs/jsonValue"
140
- }
141
- }
142
- ]
143
- },
144
- jsonObject: {
145
- type: "object",
146
- additionalProperties: {
147
- $ref: "#/$defs/jsonValue"
148
- }
149
- },
150
- tokenUsage: {
151
- type: "object",
152
- properties: {
153
- input: {
154
- $ref: "#/$defs/nonNegativeInteger"
155
- },
156
- output: {
157
- $ref: "#/$defs/nonNegativeInteger"
158
- }
159
- },
160
- required: [
161
- "input",
162
- "output"
163
- ],
164
- additionalProperties: false
165
- },
166
- base: {
167
- type: "object",
168
- properties: {
169
- id: {
170
- $ref: "#/$defs/nonEmptyId"
171
- },
172
- version: {
173
- const: "1.0"
174
- },
175
- timestamp: {
176
- $ref: "#/$defs/jsonNumber"
177
- },
178
- session_id: {
179
- $ref: "#/$defs/nonEmptyId"
180
- },
181
- turn_id: {
182
- $ref: "#/$defs/nonEmptyId"
183
- },
184
- metadata: {
185
- $ref: "#/$defs/jsonObject"
186
- }
187
- },
188
- required: [
189
- "id",
190
- "version",
191
- "timestamp",
192
- "session_id"
193
- ]
194
- },
195
- sessionCreated: {
196
- allOf: [
197
- {
198
- $ref: "#/$defs/base"
199
- },
200
- {
201
- type: "object",
202
- properties: {
203
- type: {
204
- const: "session.created"
205
- }
206
- },
207
- required: [
208
- "type"
209
- ]
210
- }
211
- ],
212
- unevaluatedProperties: false
213
- },
214
- sessionClosed: {
215
- allOf: [
216
- {
217
- $ref: "#/$defs/base"
218
- },
219
- {
220
- type: "object",
221
- properties: {
222
- type: {
223
- const: "session.closed"
224
- },
225
- reason: {
226
- type: [
227
- "string",
228
- "null"
229
- ]
230
- }
231
- },
232
- required: [
233
- "type"
234
- ]
235
- }
236
- ],
237
- unevaluatedProperties: false
238
- },
239
- userMessage: {
240
- allOf: [
241
- {
242
- $ref: "#/$defs/base"
243
- },
244
- {
245
- type: "object",
246
- properties: {
247
- type: {
248
- const: "user.message"
249
- },
250
- content: {
251
- type: "string"
252
- }
253
- },
254
- required: [
255
- "type",
256
- "content"
257
- ]
258
- }
259
- ],
260
- unevaluatedProperties: false
261
- },
262
- userAudioChunk: {
263
- allOf: [
264
- {
265
- $ref: "#/$defs/base"
266
- },
267
- {
268
- type: "object",
269
- properties: {
270
- type: {
271
- const: "user.audio.chunk"
272
- },
273
- chunk_size_bytes: {
274
- $ref: "#/$defs/safeInteger"
275
- }
276
- },
277
- required: [
278
- "type",
279
- "chunk_size_bytes"
280
- ]
281
- }
282
- ],
283
- unevaluatedProperties: false
284
- },
285
- transcriptPartial: {
286
- allOf: [
287
- {
288
- $ref: "#/$defs/base"
289
- },
290
- {
291
- type: "object",
292
- properties: {
293
- type: {
294
- const: "transcript.partial"
295
- },
296
- text: {
297
- type: "string"
298
- }
299
- },
300
- required: [
301
- "type",
302
- "text"
303
- ]
304
- }
305
- ],
306
- unevaluatedProperties: false
307
- },
308
- transcriptFinal: {
309
- allOf: [
310
- {
311
- $ref: "#/$defs/base"
312
- },
313
- {
314
- type: "object",
315
- properties: {
316
- type: {
317
- const: "transcript.final"
318
- },
319
- text: {
320
- type: "string"
321
- }
322
- },
323
- required: [
324
- "type",
325
- "text"
326
- ]
327
- }
328
- ],
329
- unevaluatedProperties: false
330
- },
331
- memoryRetrievalStarted: {
332
- allOf: [
333
- {
334
- $ref: "#/$defs/base"
335
- },
336
- {
337
- type: "object",
338
- properties: {
339
- type: {
340
- const: "memory.retrieval.started"
341
- },
342
- query: {
343
- type: "string"
344
- }
345
- },
346
- required: [
347
- "type",
348
- "query"
349
- ]
350
- }
351
- ],
352
- unevaluatedProperties: false
353
- },
354
- memoryRetrievalCompleted: {
355
- allOf: [
356
- {
357
- $ref: "#/$defs/base"
358
- },
359
- {
360
- type: "object",
361
- properties: {
362
- type: {
363
- const: "memory.retrieval.completed"
364
- },
365
- query: {
366
- type: "string"
367
- },
368
- documents: {
369
- type: "array",
370
- items: {
371
- $ref: "#/$defs/jsonObject"
372
- }
373
- }
374
- },
375
- required: [
376
- "type",
377
- "query",
378
- "documents"
379
- ]
380
- }
381
- ],
382
- unevaluatedProperties: false
383
- },
384
- agentReasoningStarted: {
385
- allOf: [
386
- {
387
- $ref: "#/$defs/base"
388
- },
389
- {
390
- type: "object",
391
- properties: {
392
- type: {
393
- const: "agent.reasoning.started"
394
- }
395
- },
396
- required: [
397
- "type"
398
- ]
399
- }
400
- ],
401
- unevaluatedProperties: false
402
- },
403
- agentMessageDelta: {
404
- allOf: [
405
- {
406
- $ref: "#/$defs/base"
407
- },
408
- {
409
- type: "object",
410
- properties: {
411
- type: {
412
- const: "agent.message.delta"
413
- },
414
- delta: {
415
- type: "string"
416
- }
417
- },
418
- required: [
419
- "type",
420
- "delta"
421
- ]
422
- }
423
- ],
424
- unevaluatedProperties: false
425
- },
426
- agentMessageCompleted: {
427
- allOf: [
428
- {
429
- $ref: "#/$defs/base"
430
- },
431
- {
432
- type: "object",
433
- properties: {
434
- type: {
435
- const: "agent.message.completed"
436
- },
437
- content: {
438
- type: "string"
439
- },
440
- tokens: {
441
- oneOf: [
442
- { $ref: "#/$defs/tokenUsage" },
443
- { type: "null" }
444
- ]
445
- },
446
- cost_usd: {
447
- oneOf: [
448
- { $ref: "#/$defs/nonNegativeNumber" },
449
- { type: "null" }
450
- ]
451
- }
452
- },
453
- required: [
454
- "type",
455
- "content"
456
- ]
457
- }
458
- ],
459
- unevaluatedProperties: false
460
- },
461
- agentTurnExhausted: {
462
- allOf: [
463
- {
464
- $ref: "#/$defs/base"
465
- },
466
- {
467
- type: "object",
468
- properties: {
469
- type: {
470
- const: "agent.turn.exhausted"
471
- },
472
- max_iterations: {
473
- $ref: "#/$defs/nonNegativeInteger"
474
- },
475
- pending_tool_calls: {
476
- type: "array",
477
- items: {
478
- $ref: "#/$defs/jsonObject"
479
- }
480
- },
481
- reason: {
482
- type: [
483
- "string",
484
- "null"
485
- ]
486
- }
487
- },
488
- required: [
489
- "type",
490
- "max_iterations",
491
- "pending_tool_calls"
492
- ]
493
- }
494
- ],
495
- unevaluatedProperties: false
496
- },
497
- agentTurnFailed: {
498
- allOf: [
499
- {
500
- $ref: "#/$defs/base"
501
- },
502
- {
503
- type: "object",
504
- properties: {
505
- type: {
506
- const: "agent.turn.failed"
507
- },
508
- turn_id: {
509
- $ref: "#/$defs/nonEmptyId"
510
- },
511
- error: {
512
- type: "string",
513
- minLength: 1,
514
- maxLength: 200
515
- },
516
- error_code: {
517
- type: "string"
518
- },
519
- phase: {
520
- enum: [
521
- "queue",
522
- "provider_open",
523
- "provider_stream",
524
- "approval",
525
- "tool"
526
- ]
527
- },
528
- retryable: {
529
- type: "boolean"
530
- },
531
- outcome: {
532
- enum: [
533
- "not_started",
534
- "failed",
535
- "unknown"
536
- ]
537
- }
538
- },
539
- required: [
540
- "type",
541
- "turn_id",
542
- "error"
543
- ]
544
- }
545
- ],
546
- unevaluatedProperties: false
547
- },
548
- toolCallRequested: {
549
- allOf: [
550
- {
551
- $ref: "#/$defs/base"
552
- },
553
- {
554
- type: "object",
555
- properties: {
556
- type: {
557
- const: "tool.call.requested"
558
- },
559
- turn_id: {
560
- $ref: "#/$defs/nonEmptyId"
561
- },
562
- tool_name: {
563
- $ref: "#/$defs/nonEmptyId"
564
- },
565
- tool_args: {
566
- $ref: "#/$defs/jsonObject",
567
- "x-maxSerializedBytes": 65536
568
- },
569
- tool_call_id: {
570
- $ref: "#/$defs/nonEmptyId"
571
- }
572
- },
573
- required: [
574
- "type",
575
- "turn_id",
576
- "tool_name",
577
- "tool_args",
578
- "tool_call_id"
579
- ]
580
- }
581
- ],
582
- unevaluatedProperties: false
583
- },
584
- toolCallStarted: {
585
- allOf: [
586
- {
587
- $ref: "#/$defs/base"
588
- },
589
- {
590
- type: "object",
591
- properties: {
592
- type: {
593
- const: "tool.call.started"
594
- },
595
- turn_id: {
596
- $ref: "#/$defs/nonEmptyId"
597
- },
598
- tool_name: {
599
- $ref: "#/$defs/nonEmptyId"
600
- },
601
- tool_call_id: {
602
- $ref: "#/$defs/nonEmptyId"
603
- }
604
- },
605
- required: [
606
- "type",
607
- "turn_id",
608
- "tool_name",
609
- "tool_call_id"
610
- ]
611
- }
612
- ],
613
- unevaluatedProperties: false
614
- },
615
- toolCallCompleted: {
616
- allOf: [
617
- {
618
- $ref: "#/$defs/base"
619
- },
620
- {
621
- type: "object",
622
- properties: {
623
- type: {
624
- const: "tool.call.completed"
625
- },
626
- turn_id: {
627
- $ref: "#/$defs/nonEmptyId"
628
- },
629
- tool_name: {
630
- $ref: "#/$defs/nonEmptyId"
631
- },
632
- tool_call_id: {
633
- $ref: "#/$defs/nonEmptyId"
634
- },
635
- result: {
636
- $ref: "#/$defs/jsonValue",
637
- "x-maxSerializedBytes": 65536
638
- },
639
- tokens: {
640
- oneOf: [
641
- { $ref: "#/$defs/tokenUsage" },
642
- { type: "null" }
643
- ]
644
- },
645
- cost_usd: {
646
- oneOf: [
647
- { $ref: "#/$defs/nonNegativeNumber" },
648
- { type: "null" }
649
- ]
650
- }
651
- },
652
- required: [
653
- "type",
654
- "turn_id",
655
- "tool_name",
656
- "tool_call_id",
657
- "result"
658
- ]
659
- }
660
- ],
661
- unevaluatedProperties: false
662
- },
663
- toolCallFailed: {
664
- allOf: [
665
- {
666
- $ref: "#/$defs/base"
667
- },
668
- {
669
- type: "object",
670
- properties: {
671
- type: {
672
- const: "tool.call.failed"
673
- },
674
- turn_id: {
675
- $ref: "#/$defs/nonEmptyId"
676
- },
677
- tool_name: {
678
- $ref: "#/$defs/nonEmptyId"
679
- },
680
- tool_call_id: {
681
- $ref: "#/$defs/nonEmptyId"
682
- },
683
- error: {
684
- type: "string",
685
- minLength: 1,
686
- maxLength: 200
687
- },
688
- error_code: {
689
- type: "string"
690
- },
691
- error_path: {
692
- type: "string"
693
- },
694
- retryable: {
695
- type: "boolean"
696
- },
697
- outcome: {
698
- enum: [
699
- "not_started",
700
- "failed",
701
- "unknown"
702
- ]
703
- },
704
- reason_code: {
705
- type: "string"
706
- },
707
- recovery_code: {
708
- type: "string"
709
- },
710
- doc_url: {
711
- type: "string"
712
- }
713
- },
714
- required: [
715
- "type",
716
- "turn_id",
717
- "tool_name",
718
- "tool_call_id",
719
- "error"
720
- ]
721
- },
722
- {
723
- if: {
724
- anyOf: [
725
- { required: ["reason_code"] },
726
- { required: ["recovery_code"] },
727
- { required: ["doc_url"] }
728
- ]
729
- },
730
- then: {
731
- $ref: "#/$defs/integrationRecoveryFields"
732
- }
733
- }
734
- ],
735
- unevaluatedProperties: false
736
- },
737
- toolApprovalRequested: {
738
- allOf: [
739
- {
740
- $ref: "#/$defs/base"
741
- },
742
- {
743
- type: "object",
744
- properties: {
745
- type: {
746
- const: "tool.approval.requested"
747
- },
748
- turn_id: {
749
- $ref: "#/$defs/nonEmptyId"
750
- },
751
- tool_name: {
752
- $ref: "#/$defs/nonEmptyId"
753
- },
754
- tool_call_id: {
755
- $ref: "#/$defs/nonEmptyId"
756
- },
757
- tool_args: {
758
- $ref: "#/$defs/jsonObject",
759
- "x-maxSerializedBytes": 65536
760
- },
761
- risk: {
762
- enum: [
763
- "read",
764
- "write",
765
- "external_effect",
766
- "destructive",
767
- "admin"
768
- ]
769
- }
770
- },
771
- required: [
772
- "type",
773
- "turn_id",
774
- "tool_name",
775
- "tool_call_id",
776
- "tool_args",
777
- "risk"
778
- ]
779
- }
780
- ],
781
- unevaluatedProperties: false
782
- },
783
- toolApprovalApproved: {
784
- allOf: [
785
- {
786
- $ref: "#/$defs/base"
787
- },
788
- {
789
- type: "object",
790
- properties: {
791
- type: {
792
- const: "tool.approval.approved"
793
- },
794
- turn_id: {
795
- $ref: "#/$defs/nonEmptyId"
796
- },
797
- tool_name: {
798
- $ref: "#/$defs/nonEmptyId"
799
- },
800
- tool_call_id: {
801
- $ref: "#/$defs/nonEmptyId"
802
- }
803
- },
804
- required: [
805
- "type",
806
- "turn_id",
807
- "tool_name",
808
- "tool_call_id"
809
- ]
810
- }
811
- ],
812
- unevaluatedProperties: false
813
- },
814
- toolApprovalRejected: {
815
- allOf: [
816
- {
817
- $ref: "#/$defs/base"
818
- },
819
- {
820
- type: "object",
821
- properties: {
822
- type: {
823
- const: "tool.approval.rejected"
824
- },
825
- turn_id: {
826
- $ref: "#/$defs/nonEmptyId"
827
- },
828
- tool_name: {
829
- $ref: "#/$defs/nonEmptyId"
830
- },
831
- tool_call_id: {
832
- $ref: "#/$defs/nonEmptyId"
833
- },
834
- error_code: {
835
- enum: [
836
- "APPROVAL_REJECTED",
837
- "APPROVAL_TIMEOUT",
838
- "TURN_TIMEOUT",
839
- "TOOL_CANCELLED",
840
- "APPROVAL_UNAVAILABLE"
841
- ]
842
- },
843
- reason: {
844
- type: "string",
845
- minLength: 1,
846
- maxLength: 200,
847
- pattern: "\\S"
848
- }
849
- },
850
- required: [
851
- "type",
852
- "turn_id",
853
- "tool_name",
854
- "tool_call_id",
855
- "error_code",
856
- "reason"
857
- ]
858
- }
859
- ],
860
- unevaluatedProperties: false
861
- },
862
- workflowStarted: {
863
- allOf: [
864
- {
865
- $ref: "#/$defs/base"
866
- },
867
- {
868
- type: "object",
869
- properties: {
870
- type: {
871
- const: "workflow.started"
872
- },
873
- workflow_name: {
874
- type: "string"
875
- }
876
- },
877
- required: [
878
- "type",
879
- "workflow_name"
880
- ]
881
- }
882
- ],
883
- unevaluatedProperties: false
884
- },
885
- workflowCompleted: {
886
- allOf: [
887
- {
888
- $ref: "#/$defs/base"
889
- },
890
- {
891
- type: "object",
892
- properties: {
893
- type: {
894
- const: "workflow.completed"
895
- },
896
- workflow_name: {
897
- type: "string"
898
- },
899
- result: {
900
- $ref: "#/$defs/jsonValue"
901
- }
902
- },
903
- required: [
904
- "type",
905
- "workflow_name",
906
- "result"
907
- ]
908
- }
909
- ],
910
- unevaluatedProperties: false
911
- },
912
- workflowFailed: {
913
- allOf: [
914
- {
915
- $ref: "#/$defs/base"
916
- },
917
- {
918
- type: "object",
919
- properties: {
920
- type: {
921
- const: "workflow.failed"
922
- },
923
- workflow_name: {
924
- type: "string"
925
- },
926
- error: {
927
- type: "string"
928
- }
929
- },
930
- required: [
931
- "type",
932
- "workflow_name",
933
- "error"
934
- ]
935
- }
936
- ],
937
- unevaluatedProperties: false
938
- },
939
- cancellationRequested: {
940
- allOf: [
941
- {
942
- $ref: "#/$defs/base"
943
- },
944
- {
945
- type: "object",
946
- properties: {
947
- type: {
948
- const: "cancellation.requested"
949
- },
950
- reason: {
951
- type: "string"
952
- }
953
- },
954
- required: [
955
- "type",
956
- "reason"
957
- ]
958
- }
959
- ],
960
- unevaluatedProperties: false
961
- },
962
- cancellationCompleted: {
963
- allOf: [
964
- {
965
- $ref: "#/$defs/base"
966
- },
967
- {
968
- type: "object",
969
- properties: {
970
- type: {
971
- const: "cancellation.completed"
972
- }
973
- },
974
- required: [
975
- "type"
976
- ]
977
- }
978
- ],
979
- unevaluatedProperties: false
980
- }
981
- },
982
- oneOf: [
983
- {
984
- $ref: "#/$defs/sessionCreated"
985
- },
986
- {
987
- $ref: "#/$defs/sessionClosed"
988
- },
989
- {
990
- $ref: "#/$defs/userMessage"
991
- },
992
- {
993
- $ref: "#/$defs/userAudioChunk"
994
- },
995
- {
996
- $ref: "#/$defs/transcriptPartial"
997
- },
998
- {
999
- $ref: "#/$defs/transcriptFinal"
1000
- },
1001
- {
1002
- $ref: "#/$defs/memoryRetrievalStarted"
1003
- },
1004
- {
1005
- $ref: "#/$defs/memoryRetrievalCompleted"
1006
- },
1007
- {
1008
- $ref: "#/$defs/agentReasoningStarted"
1009
- },
1010
- {
1011
- $ref: "#/$defs/agentMessageDelta"
1012
- },
1013
- {
1014
- $ref: "#/$defs/agentMessageCompleted"
1015
- },
1016
- {
1017
- $ref: "#/$defs/agentTurnExhausted"
1018
- },
1019
- {
1020
- $ref: "#/$defs/agentTurnFailed"
1021
- },
1022
- {
1023
- $ref: "#/$defs/toolCallRequested"
1024
- },
1025
- {
1026
- $ref: "#/$defs/toolCallStarted"
1027
- },
1028
- {
1029
- $ref: "#/$defs/toolCallCompleted"
1030
- },
1031
- {
1032
- $ref: "#/$defs/toolCallFailed"
1033
- },
1034
- {
1035
- $ref: "#/$defs/toolApprovalRequested"
1036
- },
1037
- {
1038
- $ref: "#/$defs/toolApprovalApproved"
1039
- },
1040
- {
1041
- $ref: "#/$defs/toolApprovalRejected"
1042
- },
1043
- {
1044
- $ref: "#/$defs/workflowStarted"
1045
- },
1046
- {
1047
- $ref: "#/$defs/workflowCompleted"
1048
- },
1049
- {
1050
- $ref: "#/$defs/workflowFailed"
1051
- },
1052
- {
1053
- $ref: "#/$defs/cancellationRequested"
1054
- },
1055
- {
1056
- $ref: "#/$defs/cancellationCompleted"
1057
- }
1058
- ]
1059
- };
1060
-
1061
- // contracts/events/stored-kaji-event-v1.schema.json
1062
- var stored_kaji_event_v1_schema_default = {
1063
- $schema: "https://json-schema.org/draft/2020-12/schema",
1064
- $id: "https://kaji.dev/contracts/events/stored-kaji-event-v1.schema.json",
1065
- title: "Stored Kaji event",
1066
- "x-maxSerializedBytes": 1048576,
1067
- $defs: {
1068
- nonEmptyId: {
1069
- type: "string",
1070
- minLength: 1
1071
- },
1072
- integrationRecoveryFields: {
1073
- oneOf: [
1074
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "github_token_missing" }, recovery_code: { const: "CONFIGURE_GITHUB_TOKEN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#github-token" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1075
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "gmail_grant_missing" }, recovery_code: { const: "CONNECT_GMAIL" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-grant" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1076
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_missing" }, recovery_code: { const: "RESTORE_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-missing" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1077
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_locked" }, recovery_code: { const: "UNLOCK_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-locked" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1078
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_corrupt" }, recovery_code: { const: "RESET_GMAIL_GRANT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-corrupt" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1079
- { properties: { error_code: { const: "INTEGRATION_AUTH_ERROR" }, reason_code: { const: "keychain_unsupported" }, recovery_code: { const: "USE_SUPPORTED_KEYCHAIN" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#keychain-unsupported" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1080
- { properties: { error_code: { const: "INTEGRATION_AUTH_REQUIRED" }, reason_code: { const: "gmail_scope_drift" }, recovery_code: { const: "RECONNECT_GMAIL" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-scope-drift" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1081
- { properties: { error_code: { const: "INTEGRATION_POLICY_REJECTED" }, reason_code: { const: "policy_rejected" }, recovery_code: { const: "REVIEW_INTEGRATION_POLICY" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#policy-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1082
- { properties: { error_code: { const: "INTEGRATION_API_ERROR" }, reason_code: { const: "api_rejected" }, recovery_code: { const: "REVIEW_PROVIDER_REJECTION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#api-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1083
- { properties: { error_code: { const: "INTEGRATION_API_ERROR" }, reason_code: { const: "transient_read_failed" }, recovery_code: { const: "RETRY_INTEGRATION_READ" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#transient-read" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1084
- { properties: { error_code: { const: "INTEGRATION_RATE_LIMITED" }, reason_code: { const: "rate_limited" }, recovery_code: { const: "RETRY_AFTER_RATE_LIMIT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#rate-limited" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1085
- { properties: { error_code: { const: "INTEGRATION_REDIRECT_REJECTED" }, reason_code: { const: "redirect_rejected" }, recovery_code: { const: "REJECT_PROVIDER_REDIRECT" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#redirect-rejected" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1086
- { properties: { error_code: { const: "INTEGRATION_RESPONSE_LIMIT" }, reason_code: { const: "response_limit_exceeded" }, recovery_code: { const: "REDUCE_INTEGRATION_RESPONSE" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#response-limit" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1087
- { properties: { error_code: { const: "TOOL_EXECUTION_FAILED" }, reason_code: { const: "github_mutation_unknown" }, recovery_code: { const: "RECONCILE_GITHUB_MUTATION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#github-mutation-unknown" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] },
1088
- { properties: { error_code: { const: "TOOL_EXECUTION_FAILED" }, reason_code: { const: "gmail_mutation_unknown" }, recovery_code: { const: "RECONCILE_GMAIL_MUTATION" }, doc_url: { const: "https://kaji.dev/docs/integrations/recovery-v1#gmail-mutation-unknown" } }, required: ["error_code", "reason_code", "recovery_code", "doc_url"] }
1089
- ]
1090
- },
1091
- safeInteger: {
1092
- type: "integer",
1093
- minimum: -9007199254740991,
1094
- maximum: 9007199254740991
1095
- },
1096
- positiveInteger: {
1097
- allOf: [
1098
- {
1099
- $ref: "#/$defs/safeInteger"
1100
- },
1101
- {
1102
- minimum: 1
1103
- }
1104
- ]
1105
- },
1106
- nonNegativeInteger: {
1107
- allOf: [
1108
- {
1109
- $ref: "#/$defs/safeInteger"
1110
- },
1111
- {
1112
- minimum: 0
1113
- }
1114
- ]
1115
- },
1116
- jsonNumber: {
1117
- oneOf: [
1118
- {
1119
- $ref: "#/$defs/safeInteger"
1120
- },
1121
- {
1122
- type: "number",
1123
- not: {
1124
- type: "integer"
1125
- }
1126
- }
1127
- ]
1128
- },
1129
- nonNegativeNumber: {
1130
- allOf: [
1131
- {
1132
- $ref: "#/$defs/jsonNumber"
1133
- },
1134
- {
1135
- minimum: 0
1136
- }
1137
- ]
1138
- },
1139
- jsonValue: {
1140
- oneOf: [
1141
- {
1142
- type: "null"
1143
- },
1144
- {
1145
- type: "boolean"
1146
- },
1147
- {
1148
- $ref: "#/$defs/jsonNumber"
1149
- },
1150
- {
1151
- type: "string"
1152
- },
1153
- {
1154
- type: "array",
1155
- items: {
1156
- $ref: "#/$defs/jsonValue"
1157
- }
1158
- },
1159
- {
1160
- type: "object",
1161
- additionalProperties: {
1162
- $ref: "#/$defs/jsonValue"
1163
- }
1164
- }
1165
- ]
1166
- },
1167
- jsonObject: {
1168
- type: "object",
1169
- additionalProperties: {
1170
- $ref: "#/$defs/jsonValue"
1171
- }
1172
- },
1173
- tokenUsage: {
1174
- type: "object",
1175
- properties: {
1176
- input: {
1177
- $ref: "#/$defs/nonNegativeInteger"
1178
- },
1179
- output: {
1180
- $ref: "#/$defs/nonNegativeInteger"
1181
- }
1182
- },
1183
- required: [
1184
- "input",
1185
- "output"
1186
- ],
1187
- additionalProperties: false
1188
- },
1189
- base: {
1190
- type: "object",
1191
- properties: {
1192
- id: {
1193
- $ref: "#/$defs/nonEmptyId"
1194
- },
1195
- version: {
1196
- const: "1.0"
1197
- },
1198
- timestamp: {
1199
- $ref: "#/$defs/jsonNumber"
1200
- },
1201
- session_id: {
1202
- $ref: "#/$defs/nonEmptyId"
1203
- },
1204
- turn_id: {
1205
- $ref: "#/$defs/nonEmptyId"
1206
- },
1207
- metadata: {
1208
- $ref: "#/$defs/jsonObject"
1209
- },
1210
- sequence: {
1211
- $ref: "#/$defs/positiveInteger"
1212
- }
1213
- },
1214
- required: [
1215
- "id",
1216
- "version",
1217
- "timestamp",
1218
- "session_id",
1219
- "sequence"
1220
- ]
1221
- },
1222
- sessionCreated: {
1223
- allOf: [
1224
- {
1225
- $ref: "#/$defs/base"
1226
- },
1227
- {
1228
- type: "object",
1229
- properties: {
1230
- type: {
1231
- const: "session.created"
1232
- }
1233
- },
1234
- required: [
1235
- "type"
1236
- ]
1237
- }
1238
- ],
1239
- unevaluatedProperties: false
1240
- },
1241
- sessionClosed: {
1242
- allOf: [
1243
- {
1244
- $ref: "#/$defs/base"
1245
- },
1246
- {
1247
- type: "object",
1248
- properties: {
1249
- type: {
1250
- const: "session.closed"
1251
- },
1252
- reason: {
1253
- type: [
1254
- "string",
1255
- "null"
1256
- ]
1257
- }
1258
- },
1259
- required: [
1260
- "type"
1261
- ]
1262
- }
1263
- ],
1264
- unevaluatedProperties: false
1265
- },
1266
- userMessage: {
1267
- allOf: [
1268
- {
1269
- $ref: "#/$defs/base"
1270
- },
1271
- {
1272
- type: "object",
1273
- properties: {
1274
- type: {
1275
- const: "user.message"
1276
- },
1277
- content: {
1278
- type: "string"
1279
- }
1280
- },
1281
- required: [
1282
- "type",
1283
- "content"
1284
- ]
1285
- }
1286
- ],
1287
- unevaluatedProperties: false
1288
- },
1289
- userAudioChunk: {
1290
- allOf: [
1291
- {
1292
- $ref: "#/$defs/base"
1293
- },
1294
- {
1295
- type: "object",
1296
- properties: {
1297
- type: {
1298
- const: "user.audio.chunk"
1299
- },
1300
- chunk_size_bytes: {
1301
- $ref: "#/$defs/safeInteger"
1302
- }
1303
- },
1304
- required: [
1305
- "type",
1306
- "chunk_size_bytes"
1307
- ]
1308
- }
1309
- ],
1310
- unevaluatedProperties: false
1311
- },
1312
- transcriptPartial: {
1313
- allOf: [
1314
- {
1315
- $ref: "#/$defs/base"
1316
- },
1317
- {
1318
- type: "object",
1319
- properties: {
1320
- type: {
1321
- const: "transcript.partial"
1322
- },
1323
- text: {
1324
- type: "string"
1325
- }
1326
- },
1327
- required: [
1328
- "type",
1329
- "text"
1330
- ]
1331
- }
1332
- ],
1333
- unevaluatedProperties: false
1334
- },
1335
- transcriptFinal: {
1336
- allOf: [
1337
- {
1338
- $ref: "#/$defs/base"
1339
- },
1340
- {
1341
- type: "object",
1342
- properties: {
1343
- type: {
1344
- const: "transcript.final"
1345
- },
1346
- text: {
1347
- type: "string"
1348
- }
1349
- },
1350
- required: [
1351
- "type",
1352
- "text"
1353
- ]
1354
- }
1355
- ],
1356
- unevaluatedProperties: false
1357
- },
1358
- memoryRetrievalStarted: {
1359
- allOf: [
1360
- {
1361
- $ref: "#/$defs/base"
1362
- },
1363
- {
1364
- type: "object",
1365
- properties: {
1366
- type: {
1367
- const: "memory.retrieval.started"
1368
- },
1369
- query: {
1370
- type: "string"
1371
- }
1372
- },
1373
- required: [
1374
- "type",
1375
- "query"
1376
- ]
1377
- }
1378
- ],
1379
- unevaluatedProperties: false
1380
- },
1381
- memoryRetrievalCompleted: {
1382
- allOf: [
1383
- {
1384
- $ref: "#/$defs/base"
1385
- },
1386
- {
1387
- type: "object",
1388
- properties: {
1389
- type: {
1390
- const: "memory.retrieval.completed"
1391
- },
1392
- query: {
1393
- type: "string"
1394
- },
1395
- documents: {
1396
- type: "array",
1397
- items: {
1398
- $ref: "#/$defs/jsonObject"
1399
- }
1400
- }
1401
- },
1402
- required: [
1403
- "type",
1404
- "query",
1405
- "documents"
1406
- ]
1407
- }
1408
- ],
1409
- unevaluatedProperties: false
1410
- },
1411
- agentReasoningStarted: {
1412
- allOf: [
1413
- {
1414
- $ref: "#/$defs/base"
1415
- },
1416
- {
1417
- type: "object",
1418
- properties: {
1419
- type: {
1420
- const: "agent.reasoning.started"
1421
- }
1422
- },
1423
- required: [
1424
- "type"
1425
- ]
1426
- }
1427
- ],
1428
- unevaluatedProperties: false
1429
- },
1430
- agentMessageDelta: {
1431
- allOf: [
1432
- {
1433
- $ref: "#/$defs/base"
1434
- },
1435
- {
1436
- type: "object",
1437
- properties: {
1438
- type: {
1439
- const: "agent.message.delta"
1440
- },
1441
- delta: {
1442
- type: "string"
1443
- }
1444
- },
1445
- required: [
1446
- "type",
1447
- "delta"
1448
- ]
1449
- }
1450
- ],
1451
- unevaluatedProperties: false
1452
- },
1453
- agentMessageCompleted: {
1454
- allOf: [
1455
- {
1456
- $ref: "#/$defs/base"
1457
- },
1458
- {
1459
- type: "object",
1460
- properties: {
1461
- type: {
1462
- const: "agent.message.completed"
1463
- },
1464
- content: {
1465
- type: "string"
1466
- },
1467
- tokens: {
1468
- oneOf: [
1469
- { $ref: "#/$defs/tokenUsage" },
1470
- { type: "null" }
1471
- ]
1472
- },
1473
- cost_usd: {
1474
- oneOf: [
1475
- { $ref: "#/$defs/nonNegativeNumber" },
1476
- { type: "null" }
1477
- ]
1478
- }
1479
- },
1480
- required: [
1481
- "type",
1482
- "content"
1483
- ]
1484
- }
1485
- ],
1486
- unevaluatedProperties: false
1487
- },
1488
- agentTurnExhausted: {
1489
- allOf: [
1490
- {
1491
- $ref: "#/$defs/base"
1492
- },
1493
- {
1494
- type: "object",
1495
- properties: {
1496
- type: {
1497
- const: "agent.turn.exhausted"
1498
- },
1499
- max_iterations: {
1500
- $ref: "#/$defs/nonNegativeInteger"
1501
- },
1502
- pending_tool_calls: {
1503
- type: "array",
1504
- items: {
1505
- $ref: "#/$defs/jsonObject"
1506
- }
1507
- },
1508
- reason: {
1509
- type: [
1510
- "string",
1511
- "null"
1512
- ]
1513
- }
1514
- },
1515
- required: [
1516
- "type",
1517
- "max_iterations",
1518
- "pending_tool_calls"
1519
- ]
1520
- }
1521
- ],
1522
- unevaluatedProperties: false
1523
- },
1524
- agentTurnFailed: {
1525
- allOf: [
1526
- {
1527
- $ref: "#/$defs/base"
1528
- },
1529
- {
1530
- type: "object",
1531
- properties: {
1532
- type: {
1533
- const: "agent.turn.failed"
1534
- },
1535
- turn_id: {
1536
- $ref: "#/$defs/nonEmptyId"
1537
- },
1538
- error: {
1539
- type: "string",
1540
- minLength: 1,
1541
- maxLength: 200
1542
- },
1543
- error_code: {
1544
- type: "string"
1545
- },
1546
- phase: {
1547
- enum: [
1548
- "queue",
1549
- "provider_open",
1550
- "provider_stream",
1551
- "approval",
1552
- "tool"
1553
- ]
1554
- },
1555
- retryable: {
1556
- type: "boolean"
1557
- },
1558
- outcome: {
1559
- enum: [
1560
- "not_started",
1561
- "failed",
1562
- "unknown"
1563
- ]
1564
- }
1565
- },
1566
- required: [
1567
- "type",
1568
- "turn_id",
1569
- "error"
1570
- ]
1571
- }
1572
- ],
1573
- unevaluatedProperties: false
1574
- },
1575
- toolCallRequested: {
1576
- allOf: [
1577
- {
1578
- $ref: "#/$defs/base"
1579
- },
1580
- {
1581
- type: "object",
1582
- properties: {
1583
- type: {
1584
- const: "tool.call.requested"
1585
- },
1586
- turn_id: {
1587
- $ref: "#/$defs/nonEmptyId"
1588
- },
1589
- tool_name: {
1590
- $ref: "#/$defs/nonEmptyId"
1591
- },
1592
- tool_args: {
1593
- $ref: "#/$defs/jsonObject",
1594
- "x-maxSerializedBytes": 65536
1595
- },
1596
- tool_call_id: {
1597
- $ref: "#/$defs/nonEmptyId"
1598
- }
1599
- },
1600
- required: [
1601
- "type",
1602
- "turn_id",
1603
- "tool_name",
1604
- "tool_args",
1605
- "tool_call_id"
1606
- ]
1607
- }
1608
- ],
1609
- unevaluatedProperties: false
1610
- },
1611
- toolCallStarted: {
1612
- allOf: [
1613
- {
1614
- $ref: "#/$defs/base"
1615
- },
1616
- {
1617
- type: "object",
1618
- properties: {
1619
- type: {
1620
- const: "tool.call.started"
1621
- },
1622
- turn_id: {
1623
- $ref: "#/$defs/nonEmptyId"
1624
- },
1625
- tool_name: {
1626
- $ref: "#/$defs/nonEmptyId"
1627
- },
1628
- tool_call_id: {
1629
- $ref: "#/$defs/nonEmptyId"
1630
- }
1631
- },
1632
- required: [
1633
- "type",
1634
- "turn_id",
1635
- "tool_name",
1636
- "tool_call_id"
1637
- ]
1638
- }
1639
- ],
1640
- unevaluatedProperties: false
1641
- },
1642
- toolCallCompleted: {
1643
- allOf: [
1644
- {
1645
- $ref: "#/$defs/base"
1646
- },
1647
- {
1648
- type: "object",
1649
- properties: {
1650
- type: {
1651
- const: "tool.call.completed"
1652
- },
1653
- turn_id: {
1654
- $ref: "#/$defs/nonEmptyId"
1655
- },
1656
- tool_name: {
1657
- $ref: "#/$defs/nonEmptyId"
1658
- },
1659
- tool_call_id: {
1660
- $ref: "#/$defs/nonEmptyId"
1661
- },
1662
- result: {
1663
- $ref: "#/$defs/jsonValue",
1664
- "x-maxSerializedBytes": 65536
1665
- },
1666
- tokens: {
1667
- oneOf: [
1668
- { $ref: "#/$defs/tokenUsage" },
1669
- { type: "null" }
1670
- ]
1671
- },
1672
- cost_usd: {
1673
- oneOf: [
1674
- { $ref: "#/$defs/nonNegativeNumber" },
1675
- { type: "null" }
1676
- ]
1677
- }
1678
- },
1679
- required: [
1680
- "type",
1681
- "turn_id",
1682
- "tool_name",
1683
- "tool_call_id",
1684
- "result"
1685
- ]
1686
- }
1687
- ],
1688
- unevaluatedProperties: false
1689
- },
1690
- toolCallFailed: {
1691
- allOf: [
1692
- {
1693
- $ref: "#/$defs/base"
1694
- },
1695
- {
1696
- type: "object",
1697
- properties: {
1698
- type: {
1699
- const: "tool.call.failed"
1700
- },
1701
- turn_id: {
1702
- $ref: "#/$defs/nonEmptyId"
1703
- },
1704
- tool_name: {
1705
- $ref: "#/$defs/nonEmptyId"
1706
- },
1707
- tool_call_id: {
1708
- $ref: "#/$defs/nonEmptyId"
1709
- },
1710
- error: {
1711
- type: "string",
1712
- minLength: 1,
1713
- maxLength: 200
1714
- },
1715
- error_code: {
1716
- type: "string"
1717
- },
1718
- error_path: {
1719
- type: "string"
1720
- },
1721
- retryable: {
1722
- type: "boolean"
1723
- },
1724
- outcome: {
1725
- enum: [
1726
- "not_started",
1727
- "failed",
1728
- "unknown"
1729
- ]
1730
- },
1731
- reason_code: {
1732
- type: "string"
1733
- },
1734
- recovery_code: {
1735
- type: "string"
1736
- },
1737
- doc_url: {
1738
- type: "string"
1739
- }
1740
- },
1741
- required: [
1742
- "type",
1743
- "turn_id",
1744
- "tool_name",
1745
- "tool_call_id",
1746
- "error"
1747
- ]
1748
- },
1749
- {
1750
- if: {
1751
- anyOf: [
1752
- { required: ["reason_code"] },
1753
- { required: ["recovery_code"] },
1754
- { required: ["doc_url"] }
1755
- ]
1756
- },
1757
- then: {
1758
- $ref: "#/$defs/integrationRecoveryFields"
1759
- }
1760
- }
1761
- ],
1762
- unevaluatedProperties: false
1763
- },
1764
- toolApprovalRequested: {
1765
- allOf: [
1766
- {
1767
- $ref: "#/$defs/base"
1768
- },
1769
- {
1770
- type: "object",
1771
- properties: {
1772
- type: {
1773
- const: "tool.approval.requested"
1774
- },
1775
- turn_id: {
1776
- $ref: "#/$defs/nonEmptyId"
1777
- },
1778
- tool_name: {
1779
- $ref: "#/$defs/nonEmptyId"
1780
- },
1781
- tool_call_id: {
1782
- $ref: "#/$defs/nonEmptyId"
1783
- },
1784
- tool_args: {
1785
- $ref: "#/$defs/jsonObject",
1786
- "x-maxSerializedBytes": 65536
1787
- },
1788
- risk: {
1789
- enum: [
1790
- "read",
1791
- "write",
1792
- "external_effect",
1793
- "destructive",
1794
- "admin"
1795
- ]
1796
- }
1797
- },
1798
- required: [
1799
- "type",
1800
- "turn_id",
1801
- "tool_name",
1802
- "tool_call_id",
1803
- "tool_args",
1804
- "risk"
1805
- ]
1806
- }
1807
- ],
1808
- unevaluatedProperties: false
1809
- },
1810
- toolApprovalApproved: {
1811
- allOf: [
1812
- {
1813
- $ref: "#/$defs/base"
1814
- },
1815
- {
1816
- type: "object",
1817
- properties: {
1818
- type: {
1819
- const: "tool.approval.approved"
1820
- },
1821
- turn_id: {
1822
- $ref: "#/$defs/nonEmptyId"
1823
- },
1824
- tool_name: {
1825
- $ref: "#/$defs/nonEmptyId"
1826
- },
1827
- tool_call_id: {
1828
- $ref: "#/$defs/nonEmptyId"
1829
- }
1830
- },
1831
- required: [
1832
- "type",
1833
- "turn_id",
1834
- "tool_name",
1835
- "tool_call_id"
1836
- ]
1837
- }
1838
- ],
1839
- unevaluatedProperties: false
1840
- },
1841
- toolApprovalRejected: {
1842
- allOf: [
1843
- {
1844
- $ref: "#/$defs/base"
1845
- },
1846
- {
1847
- type: "object",
1848
- properties: {
1849
- type: {
1850
- const: "tool.approval.rejected"
1851
- },
1852
- turn_id: {
1853
- $ref: "#/$defs/nonEmptyId"
1854
- },
1855
- tool_name: {
1856
- $ref: "#/$defs/nonEmptyId"
1857
- },
1858
- tool_call_id: {
1859
- $ref: "#/$defs/nonEmptyId"
1860
- },
1861
- error_code: {
1862
- enum: [
1863
- "APPROVAL_REJECTED",
1864
- "APPROVAL_TIMEOUT",
1865
- "TURN_TIMEOUT",
1866
- "TOOL_CANCELLED",
1867
- "APPROVAL_UNAVAILABLE"
1868
- ]
1869
- },
1870
- reason: {
1871
- type: "string",
1872
- minLength: 1,
1873
- maxLength: 200,
1874
- pattern: "\\S"
1875
- }
1876
- },
1877
- required: [
1878
- "type",
1879
- "turn_id",
1880
- "tool_name",
1881
- "tool_call_id",
1882
- "error_code",
1883
- "reason"
1884
- ]
1885
- }
1886
- ],
1887
- unevaluatedProperties: false
1888
- },
1889
- workflowStarted: {
1890
- allOf: [
1891
- {
1892
- $ref: "#/$defs/base"
1893
- },
1894
- {
1895
- type: "object",
1896
- properties: {
1897
- type: {
1898
- const: "workflow.started"
1899
- },
1900
- workflow_name: {
1901
- type: "string"
1902
- }
1903
- },
1904
- required: [
1905
- "type",
1906
- "workflow_name"
1907
- ]
1908
- }
1909
- ],
1910
- unevaluatedProperties: false
1911
- },
1912
- workflowCompleted: {
1913
- allOf: [
1914
- {
1915
- $ref: "#/$defs/base"
1916
- },
1917
- {
1918
- type: "object",
1919
- properties: {
1920
- type: {
1921
- const: "workflow.completed"
1922
- },
1923
- workflow_name: {
1924
- type: "string"
1925
- },
1926
- result: {
1927
- $ref: "#/$defs/jsonValue"
1928
- }
1929
- },
1930
- required: [
1931
- "type",
1932
- "workflow_name",
1933
- "result"
1934
- ]
1935
- }
1936
- ],
1937
- unevaluatedProperties: false
1938
- },
1939
- workflowFailed: {
1940
- allOf: [
1941
- {
1942
- $ref: "#/$defs/base"
1943
- },
1944
- {
1945
- type: "object",
1946
- properties: {
1947
- type: {
1948
- const: "workflow.failed"
1949
- },
1950
- workflow_name: {
1951
- type: "string"
1952
- },
1953
- error: {
1954
- type: "string"
1955
- }
1956
- },
1957
- required: [
1958
- "type",
1959
- "workflow_name",
1960
- "error"
1961
- ]
1962
- }
1963
- ],
1964
- unevaluatedProperties: false
1965
- },
1966
- cancellationRequested: {
1967
- allOf: [
1968
- {
1969
- $ref: "#/$defs/base"
1970
- },
1971
- {
1972
- type: "object",
1973
- properties: {
1974
- type: {
1975
- const: "cancellation.requested"
1976
- },
1977
- reason: {
1978
- type: "string"
1979
- }
1980
- },
1981
- required: [
1982
- "type",
1983
- "reason"
1984
- ]
1985
- }
1986
- ],
1987
- unevaluatedProperties: false
1988
- },
1989
- cancellationCompleted: {
1990
- allOf: [
1991
- {
1992
- $ref: "#/$defs/base"
1993
- },
1994
- {
1995
- type: "object",
1996
- properties: {
1997
- type: {
1998
- const: "cancellation.completed"
1999
- }
2000
- },
2001
- required: [
2002
- "type"
2003
- ]
2004
- }
2005
- ],
2006
- unevaluatedProperties: false
2007
- }
2008
- },
2009
- oneOf: [
2010
- {
2011
- $ref: "#/$defs/sessionCreated"
2012
- },
2013
- {
2014
- $ref: "#/$defs/sessionClosed"
2015
- },
2016
- {
2017
- $ref: "#/$defs/userMessage"
2018
- },
2019
- {
2020
- $ref: "#/$defs/userAudioChunk"
2021
- },
2022
- {
2023
- $ref: "#/$defs/transcriptPartial"
2024
- },
2025
- {
2026
- $ref: "#/$defs/transcriptFinal"
2027
- },
2028
- {
2029
- $ref: "#/$defs/memoryRetrievalStarted"
2030
- },
2031
- {
2032
- $ref: "#/$defs/memoryRetrievalCompleted"
2033
- },
2034
- {
2035
- $ref: "#/$defs/agentReasoningStarted"
2036
- },
2037
- {
2038
- $ref: "#/$defs/agentMessageDelta"
2039
- },
2040
- {
2041
- $ref: "#/$defs/agentMessageCompleted"
2042
- },
2043
- {
2044
- $ref: "#/$defs/agentTurnExhausted"
2045
- },
2046
- {
2047
- $ref: "#/$defs/agentTurnFailed"
2048
- },
2049
- {
2050
- $ref: "#/$defs/toolCallRequested"
2051
- },
2052
- {
2053
- $ref: "#/$defs/toolCallStarted"
2054
- },
2055
- {
2056
- $ref: "#/$defs/toolCallCompleted"
2057
- },
2058
- {
2059
- $ref: "#/$defs/toolCallFailed"
2060
- },
2061
- {
2062
- $ref: "#/$defs/toolApprovalRequested"
2063
- },
2064
- {
2065
- $ref: "#/$defs/toolApprovalApproved"
2066
- },
2067
- {
2068
- $ref: "#/$defs/toolApprovalRejected"
2069
- },
2070
- {
2071
- $ref: "#/$defs/workflowStarted"
2072
- },
2073
- {
2074
- $ref: "#/$defs/workflowCompleted"
2075
- },
2076
- {
2077
- $ref: "#/$defs/workflowFailed"
2078
- },
2079
- {
2080
- $ref: "#/$defs/cancellationRequested"
2081
- },
2082
- {
2083
- $ref: "#/$defs/cancellationCompleted"
2084
- }
2085
- ]
2086
- };
2087
-
2088
- // src/events/schemas.ts
2089
- var MAX_DURABLE_TOOL_ARGUMENT_BYTES = 64 * 1024;
2090
- var MAX_DURABLE_TOOL_RESULT_BYTES = 64 * 1024;
2091
- var MAX_DURABLE_EVENT_BYTES = 1024 * 1024;
2092
- function durableToolArgumentsSize(value) {
2093
- return new TextEncoder().encode(canonicalJsonValue(value, "tool arguments")).byteLength;
2094
- }
2095
- var durableJsonValue = z.unknown().superRefine((value, ctx) => {
2096
- try {
2097
- canonicalJsonValue(value, "event value");
2098
- } catch {
2099
- ctx.addIssue({ code: "custom", message: "event value must contain only JSON values" });
2100
- }
2101
- });
2102
- var durableJsonObject = z.record(z.string(), durableJsonValue).superRefine((value, ctx) => {
2103
- try {
2104
- canonicalJsonValue(value, "event value");
2105
- } catch {
2106
- ctx.addIssue({ code: "custom", message: "event value must contain only JSON values" });
2107
- }
2108
- });
2109
- function durableSubjectValue(subject, maxBytes) {
2110
- return z.unknown().superRefine((value, ctx) => {
2111
- try {
2112
- durableJsonSnapshot(value, subject, maxBytes);
2113
- } catch {
2114
- ctx.addIssue({ code: "custom", message: `${subject} must be bounded durable JSON` });
2115
- }
2116
- });
2117
- }
2118
- function durableSubjectObject(subject) {
2119
- return z.record(z.string(), z.unknown()).superRefine((value, ctx) => {
2120
- try {
2121
- durableJsonSnapshot(value, subject, MAX_DURABLE_EVENT_BYTES);
2122
- } catch {
2123
- ctx.addIssue({ code: "custom", message: `${subject} must be bounded durable JSON` });
2124
- }
2125
- });
2126
- }
2127
- var durableToolArguments = durableJsonObject.superRefine((value, ctx) => {
2128
- let size;
2129
- try {
2130
- size = durableToolArgumentsSize(value);
2131
- } catch {
2132
- ctx.addIssue({ code: "custom", message: "tool_args must contain only JSON values" });
2133
- return;
2134
- }
2135
- if (size > MAX_DURABLE_TOOL_ARGUMENT_BYTES) {
2136
- ctx.addIssue({
2137
- code: "custom",
2138
- message: "tool_args cannot exceed 65536 serialized bytes; payload redacted"
2139
- });
2140
- }
2141
- });
2142
- var nonEmptyId = z.string().min(1);
2143
- var baseShape = {
2144
- id: nonEmptyId.default(() => defaultUuid()),
2145
- version: z.literal("1.0").default("1.0"),
2146
- timestamp: z.number().default(() => Date.now() / 1e3),
2147
- session_id: nonEmptyId,
2148
- turn_id: nonEmptyId.optional(),
2149
- metadata: durableSubjectObject("event_metadata").default(() => ({}))
2150
- };
2151
- function maxUnicodeCodePoints(field) {
2152
- return (value, ctx) => {
2153
- if (Array.from(value).length > 200) {
2154
- ctx.addIssue({ code: "custom", message: `${field} must contain at most 200 characters` });
2155
- }
2156
- };
2157
- }
2158
- function event(shape) {
2159
- return z.object(baseShape).extend(shape).strict();
2160
- }
2161
- var SessionCreated = event({
2162
- type: z.literal(EventType.SESSION_CREATED)
2163
- });
2164
- var SessionClosed = event({
2165
- type: z.literal(EventType.SESSION_CLOSED),
2166
- reason: z.string().nullish()
2167
- });
2168
- var UserMessage = event({
2169
- type: z.literal(EventType.USER_MESSAGE),
2170
- content: z.string()
2171
- });
2172
- var UserAudioChunk = event({
2173
- type: z.literal(EventType.USER_AUDIO_CHUNK),
2174
- chunk_size_bytes: z.number().int()
2175
- });
2176
- var TranscriptPartial = event({
2177
- type: z.literal(EventType.TRANSCRIPT_PARTIAL),
2178
- text: z.string()
2179
- });
2180
- var TranscriptFinal = event({
2181
- type: z.literal(EventType.TRANSCRIPT_FINAL),
2182
- text: z.string()
2183
- });
2184
- var MemoryRetrievalStarted = event({
2185
- type: z.literal(EventType.MEMORY_RETRIEVAL_STARTED),
2186
- query: z.string()
2187
- });
2188
- var MemoryRetrievalCompleted = event({
2189
- type: z.literal(EventType.MEMORY_RETRIEVAL_COMPLETED),
2190
- query: z.string(),
2191
- documents: z.array(durableSubjectObject("memory_document"))
2192
- });
2193
- var AgentReasoningStarted = event({
2194
- type: z.literal(EventType.AGENT_REASONING_STARTED)
2195
- });
2196
- var AgentMessageDelta = event({
2197
- type: z.literal(EventType.AGENT_MESSAGE_DELTA),
2198
- delta: z.string()
2199
- });
2200
- var AgentMessageCompleted = event({
2201
- type: z.literal(EventType.AGENT_MESSAGE_COMPLETED),
2202
- content: z.string(),
2203
- tokens: z.object({ input: z.number().int().nonnegative(), output: z.number().int().nonnegative() }).strict().nullish(),
2204
- cost_usd: z.number().nonnegative().nullish()
2205
- });
2206
- var AgentTurnExhausted = event({
2207
- type: z.literal(EventType.AGENT_TURN_EXHAUSTED),
2208
- max_iterations: z.number().int().nonnegative(),
2209
- pending_tool_calls: z.array(durableSubjectObject("pending_tool_call")),
2210
- reason: z.string().nullish()
2211
- });
2212
- var AgentTurnFailed = event({
2213
- type: z.literal(EventType.AGENT_TURN_FAILED),
2214
- turn_id: z.string().min(1),
2215
- error: z.string().min(1).superRefine(maxUnicodeCodePoints("error")),
2216
- error_code: z.string().optional(),
2217
- phase: z.enum(["queue", "provider_open", "provider_stream", "approval", "tool"]).optional(),
2218
- retryable: z.boolean().optional(),
2219
- outcome: z.enum(["not_started", "failed", "unknown"]).optional()
2220
- });
2221
- var ToolCallRequested = event({
2222
- type: z.literal(EventType.TOOL_CALL_REQUESTED),
2223
- turn_id: z.string().min(1),
2224
- tool_name: z.string().min(1),
2225
- tool_args: durableToolArguments,
2226
- tool_call_id: z.string().min(1)
2227
- });
2228
- var ToolCallStarted = event({
2229
- type: z.literal(EventType.TOOL_CALL_STARTED),
2230
- turn_id: z.string().min(1),
2231
- tool_name: z.string().min(1),
2232
- tool_call_id: z.string().min(1)
2233
- });
2234
- var ToolCallCompleted = event({
2235
- type: z.literal(EventType.TOOL_CALL_COMPLETED),
2236
- turn_id: z.string().min(1),
2237
- tool_name: z.string().min(1),
2238
- tool_call_id: z.string().min(1),
2239
- result: durableSubjectValue("tool_result", MAX_DURABLE_TOOL_RESULT_BYTES),
2240
- tokens: z.object({ input: z.number().int().nonnegative(), output: z.number().int().nonnegative() }).strict().nullish(),
2241
- cost_usd: z.number().nonnegative().nullish()
2242
- });
2243
- var ToolCallFailed = event({
2244
- type: z.literal(EventType.TOOL_CALL_FAILED),
2245
- turn_id: z.string().min(1),
2246
- tool_name: z.string().min(1),
2247
- tool_call_id: z.string().min(1),
2248
- error: z.string().min(1).superRefine(maxUnicodeCodePoints("error")),
2249
- error_code: z.string().optional(),
2250
- error_path: z.string().optional(),
2251
- retryable: z.boolean().optional(),
2252
- outcome: z.enum(["not_started", "failed", "unknown"]).optional(),
2253
- reason_code: z.string().optional(),
2254
- recovery_code: z.string().optional(),
2255
- doc_url: z.string().optional()
2256
- }).superRefine((value, ctx) => {
2257
- if (!isClosedRecoveryTuple(value.reason_code, value.recovery_code, value.doc_url, value.error_code)) {
2258
- ctx.addIssue({
2259
- code: "custom",
2260
- path: ["reason_code"],
2261
- message: "integration recovery metadata must be a closed tuple"
2262
- });
2263
- }
2264
- });
2265
- var ToolApprovalRequested = event({
2266
- type: z.literal(EventType.TOOL_APPROVAL_REQUESTED),
2267
- turn_id: z.string().min(1),
2268
- tool_name: z.string().min(1),
2269
- tool_call_id: z.string().min(1),
2270
- tool_args: durableToolArguments,
2271
- risk: z.enum(["read", "write", "external_effect", "destructive", "admin"])
2272
- });
2273
- var ToolApprovalApproved = event({
2274
- type: z.literal(EventType.TOOL_APPROVAL_APPROVED),
2275
- turn_id: z.string().min(1),
2276
- tool_name: z.string().min(1),
2277
- tool_call_id: z.string().min(1)
2278
- });
2279
- var ToolApprovalRejected = event({
2280
- type: z.literal(EventType.TOOL_APPROVAL_REJECTED),
2281
- turn_id: z.string().min(1),
2282
- tool_name: z.string().min(1),
2283
- tool_call_id: z.string().min(1),
2284
- error_code: z.enum([
2285
- "APPROVAL_REJECTED",
2286
- "APPROVAL_TIMEOUT",
2287
- "TURN_TIMEOUT",
2288
- "TOOL_CANCELLED",
2289
- "APPROVAL_UNAVAILABLE"
2290
- ]),
2291
- reason: z.string().min(1).refine((value) => value.trim().length > 0, "reason must not be blank").superRefine(maxUnicodeCodePoints("reason"))
2292
- });
2293
- var WorkflowStarted = event({
2294
- type: z.literal(EventType.WORKFLOW_STARTED),
2295
- workflow_name: z.string()
2296
- });
2297
- var WorkflowCompleted = event({
2298
- type: z.literal(EventType.WORKFLOW_COMPLETED),
2299
- workflow_name: z.string(),
2300
- result: durableSubjectValue("workflow_result", MAX_DURABLE_EVENT_BYTES)
2301
- });
2302
- var WorkflowFailed = event({
2303
- type: z.literal(EventType.WORKFLOW_FAILED),
2304
- workflow_name: z.string(),
2305
- error: z.string()
2306
- });
2307
- var CancellationRequested = event({
2308
- type: z.literal(EventType.CANCELLATION_REQUESTED),
2309
- reason: z.string()
2310
- });
2311
- var CancellationCompleted = event({
2312
- type: z.literal(EventType.CANCELLATION_COMPLETED)
2313
- });
2314
- var KajiEvent = z.discriminatedUnion("type", [
2315
- SessionCreated,
2316
- SessionClosed,
2317
- UserMessage,
2318
- UserAudioChunk,
2319
- TranscriptPartial,
2320
- TranscriptFinal,
2321
- MemoryRetrievalStarted,
2322
- MemoryRetrievalCompleted,
2323
- AgentReasoningStarted,
2324
- AgentMessageDelta,
2325
- AgentMessageCompleted,
2326
- AgentTurnExhausted,
2327
- AgentTurnFailed,
2328
- ToolCallRequested,
2329
- ToolCallStarted,
2330
- ToolCallCompleted,
2331
- ToolCallFailed,
2332
- ToolApprovalRequested,
2333
- ToolApprovalApproved,
2334
- ToolApprovalRejected,
2335
- WorkflowStarted,
2336
- WorkflowCompleted,
2337
- WorkflowFailed,
2338
- CancellationRequested,
2339
- CancellationCompleted
2340
- ]);
2341
- z.object({ sequence: z.number().int().positive() }).loose().transform((value, ctx) => {
2342
- const { sequence, ...candidate } = value;
2343
- const parsed = KajiEvent.safeParse(candidate);
2344
- if (!parsed.success) {
2345
- for (const issue of parsed.error.issues) ctx.addIssue({ ...issue });
2346
- return z.NEVER;
2347
- }
2348
- return cloneAndFreezeJson({ ...parsed.data, sequence });
2349
- });
2350
- new Set(Object.values(EventType));
2351
- var wireAjv = new Ajv2020({ allErrors: true, strict: false });
2352
- wireAjv.compile(new_kaji_event_v1_schema_default);
2353
- wireAjv.compile(stored_kaji_event_v1_schema_default);
2354
- var DEFAULT_TIMEOUT_MS = 1e4;
2355
- var DEFAULT_MAX_RESPONSE_BYTES = 1048576;
2356
- var MAX_RESPONSE_HEADER_FIELDS = 64;
2357
- var MAX_RESPONSE_HEADER_BYTES = 64 * 1024;
2358
- var FORBIDDEN_REQUEST_HEADERS = /* @__PURE__ */ new Set([
2359
- "connection",
2360
- "content-length",
2361
- "host",
2362
- "keep-alive",
2363
- "proxy-authenticate",
2364
- "proxy-authorization",
2365
- "proxy-connection",
2366
- "te",
2367
- "trailer",
2368
- "transfer-encoding",
2369
- "upgrade"
2370
- ]);
2371
- function policyError() {
2372
- return new IntegrationPolicyError();
2373
- }
2374
- function responseLimit() {
2375
- return new IntegrationTransportError("INTEGRATION_RESPONSE_LIMIT", "response_limit_exceeded");
2376
- }
2377
- function positiveInteger(value, fallback) {
2378
- const resolved = value ?? fallback;
2379
- if (!Number.isSafeInteger(resolved) || resolved < 1) throw policyError();
2380
- return resolved;
2381
- }
2382
- function validatedOrigin(input) {
2383
- const origin = new URL(input.href);
2384
- if (origin.protocol !== "https:" || origin.username !== "" || origin.password !== "" || origin.pathname !== "/" || origin.search !== "" || origin.hash !== "") {
2385
- throw policyError();
2386
- }
2387
- return origin;
2388
- }
2389
- function validatedPath(origin, pathAndQuery) {
2390
- if (typeof pathAndQuery !== "string" || !pathAndQuery.startsWith("/") || pathAndQuery.startsWith("//") || pathAndQuery.includes("\\") || pathAndQuery.includes("#")) {
2391
- throw policyError();
2392
- }
2393
- const rawPath = pathAndQuery.split("?", 1)[0];
2394
- let decodedPath;
2395
- try {
2396
- decodedPath = decodeURIComponent(rawPath);
2397
- } catch {
2398
- throw policyError();
2399
- }
2400
- if (decodedPath.startsWith("//") || decodedPath.includes("\\")) throw policyError();
2401
- const target = new URL(pathAndQuery, origin);
2402
- if (target.origin !== origin.origin) throw policyError();
2403
- return target;
2404
- }
2405
- function validatedRequestHeaders(input) {
2406
- let headers;
2407
- try {
2408
- headers = new Headers(input);
2409
- } catch {
2410
- throw policyError();
2411
- }
2412
- const result = {};
2413
- for (const [name, value] of headers) {
2414
- const normalized = name.toLowerCase();
2415
- if (FORBIDDEN_REQUEST_HEADERS.has(normalized) || normalized.startsWith("proxy-")) {
2416
- throw policyError();
2417
- }
2418
- result[normalized] = value;
2419
- }
2420
- return Object.freeze(result);
2421
- }
2422
- function boundedResponseHeaders(input) {
2423
- if (input.length > MAX_RESPONSE_HEADER_FIELDS) throw responseLimit();
2424
- const encoder = new TextEncoder();
2425
- let size = 0;
2426
- const result = {};
2427
- const contentLengths = [];
2428
- for (const [name, value] of input) {
2429
- size += encoder.encode(name).byteLength + encoder.encode(value).byteLength;
2430
- if (size > MAX_RESPONSE_HEADER_BYTES) throw responseLimit();
2431
- const normalized = name.toLowerCase();
2432
- if (normalized === "content-length") contentLengths.push(value);
2433
- result[normalized] = value;
2434
- }
2435
- if (contentLengths.length > 1 || contentLengths.length === 1 && !/^\d+$/.test(contentLengths[0])) {
2436
- throw responseLimit();
2437
- }
2438
- return Object.freeze(result);
2439
- }
2440
- function safeAbort(name) {
2441
- return new DOMException(
2442
- name === "AbortError" ? "Integration request cancelled" : "Integration request timed out",
2443
- name
2444
- );
2445
- }
2446
- function requestSignal(context, timeoutMs) {
2447
- if (context.signal.aborted) throw safeAbort("AbortError");
2448
- const remaining = context.deadlineMonotonicMs === void 0 ? timeoutMs : Math.min(timeoutMs, context.deadlineMonotonicMs - performance.now());
2449
- if (remaining <= 0) throw safeAbort("TimeoutError");
2450
- const controller = new AbortController();
2451
- const onAbort = () => controller.abort(safeAbort("AbortError"));
2452
- context.signal.addEventListener("abort", onAbort, { once: true });
2453
- const timer = setTimeout(() => controller.abort(safeAbort("TimeoutError")), remaining);
2454
- return {
2455
- signal: controller.signal,
2456
- dispose() {
2457
- clearTimeout(timer);
2458
- context.signal.removeEventListener("abort", onAbort);
2459
- }
2460
- };
2461
- }
2462
- async function withAbort(operation, signal) {
2463
- if (signal.aborted) throw signal.reason;
2464
- return new Promise((resolve, reject) => {
2465
- const onAbort = () => {
2466
- cleanup();
2467
- reject(signal.reason);
2468
- };
2469
- const cleanup = () => signal.removeEventListener("abort", onAbort);
2470
- signal.addEventListener("abort", onAbort, { once: true });
2471
- void operation.then(
2472
- (value) => {
2473
- cleanup();
2474
- resolve(value);
2475
- },
2476
- (error) => {
2477
- cleanup();
2478
- reject(error);
2479
- }
2480
- );
2481
- });
2482
- }
2483
- var NodeHttpsTransport = class {
2484
- agent = new Agent({ keepAlive: true });
2485
- request(url, init) {
2486
- return new Promise((resolve, reject) => {
2487
- const request$1 = request(
2488
- url,
2489
- { method: init.method, headers: init.headers, agent: this.agent },
2490
- (response) => {
2491
- const headers = [];
2492
- for (let index = 0; index < response.rawHeaders.length; index += 2) {
2493
- headers.push([response.rawHeaders[index], response.rawHeaders[index + 1] ?? ""]);
2494
- }
2495
- resolve({
2496
- status: response.statusCode ?? 0,
2497
- headers,
2498
- body: response,
2499
- close: () => response.destroy()
2500
- });
2501
- }
2502
- );
2503
- const onAbort = () => request$1.destroy(init.signal.reason);
2504
- init.signal.addEventListener("abort", onAbort, { once: true });
2505
- request$1.once("error", reject);
2506
- request$1.once("close", () => init.signal.removeEventListener("abort", onAbort));
2507
- request$1.end(init.body);
2508
- });
2509
- }
2510
- close() {
2511
- this.agent.destroy();
2512
- }
2513
- };
2514
- var FixedOriginRequesterImpl = class {
2515
- constructor(policy, transport, observability = {}) {
2516
- this.transport = transport;
2517
- this.origin = validatedOrigin(policy.origin);
2518
- this.integration = policy.integration;
2519
- this.timeoutMs = positiveInteger(policy.timeoutMs, DEFAULT_TIMEOUT_MS);
2520
- this.maxResponseBytes = positiveInteger(policy.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES);
2521
- const allowedMethods = policy.allowedMethods ?? ["GET", "POST"];
2522
- if (allowedMethods.length === 0 || allowedMethods.some((method) => method !== "GET" && method !== "POST")) {
2523
- throw policyError();
2524
- }
2525
- this.allowedMethods = new Set(allowedMethods);
2526
- this.metrics = observability.metricsSink ?? NOOP_METRICS;
2527
- this.trace = observability.traceSink ?? NOOP_TRACE;
2528
- this.monotonicNow = observability.monotonicNow ?? (() => performance.now());
2529
- }
2530
- transport;
2531
- origin;
2532
- timeoutMs;
2533
- maxResponseBytes;
2534
- allowedMethods;
2535
- integration;
2536
- metrics;
2537
- trace;
2538
- monotonicNow;
2539
- closed = false;
2540
- async request(pathAndQuery, init, context) {
2541
- const started = this.monotonicNow();
2542
- const operation = init.method === "GET" ? "read" : "mutation";
2543
- const span = startSpan(this.trace, "kaji.integration.request", {
2544
- "session.id": context.sessionId,
2545
- "turn.id": context.turnId,
2546
- "request.id": context.requestId,
2547
- "trace.id": context.traceId,
2548
- "tool.call_id": context.toolCallId,
2549
- "integration.name": this.integration,
2550
- "integration.operation": operation,
2551
- "http.status_family": "none"
2552
- });
2553
- let outcome = "error";
2554
- let scope;
2555
- let response;
2556
- try {
2557
- if (this.closed) throw policyError();
2558
- if (!this.allowedMethods.has(init.method)) throw policyError();
2559
- if (init.body !== void 0 && !(init.body instanceof Uint8Array)) throw policyError();
2560
- const url = validatedPath(this.origin, pathAndQuery);
2561
- const headers = validatedRequestHeaders(init.headers);
2562
- scope = requestSignal(context, this.timeoutMs);
2563
- const signal = scope.signal;
2564
- const pendingResponse = this.transport.request(url, {
2565
- method: init.method,
2566
- headers,
2567
- ...init.body === void 0 ? {} : { body: init.body },
2568
- signal
2569
- });
2570
- void pendingResponse.then((lateResponse) => {
2571
- if (signal.aborted && response === void 0) lateResponse.close();
2572
- }).catch(() => void 0);
2573
- response = await withAbort(pendingResponse, signal);
2574
- const boundedHeaders = boundedResponseHeaders(response.headers);
2575
- if (response.status >= 300 && response.status < 400) {
2576
- throw new IntegrationTransportError("INTEGRATION_REDIRECT_REJECTED", "redirect_rejected");
2577
- }
2578
- const contentLength = boundedHeaders["content-length"];
2579
- if (contentLength !== void 0 && Number(contentLength) > this.maxResponseBytes) {
2580
- throw responseLimit();
2581
- }
2582
- const iterator = response.body[Symbol.asyncIterator]();
2583
- const chunks = [];
2584
- let size = 0;
2585
- while (true) {
2586
- const next = await withAbort(iterator.next(), scope.signal);
2587
- if (next.done) break;
2588
- if (!(next.value instanceof Uint8Array)) throw responseLimit();
2589
- size += next.value.byteLength;
2590
- if (size > this.maxResponseBytes) {
2591
- throw responseLimit();
2592
- }
2593
- chunks.push(next.value);
2594
- }
2595
- const bytes = new Uint8Array(size);
2596
- let offset = 0;
2597
- for (const chunk of chunks) {
2598
- bytes.set(chunk, offset);
2599
- offset += chunk.byteLength;
2600
- }
2601
- const family = Math.floor(response.status / 100);
2602
- span.setAttribute("http.status_family", family >= 1 && family <= 5 ? `${family}xx` : "none");
2603
- outcome = response.status >= 200 && response.status < 300 ? "success" : "error";
2604
- return { status: response.status, headers: boundedHeaders, bytes };
2605
- } catch (error) {
2606
- response?.close();
2607
- if (error instanceof DOMException && error.name === "AbortError") outcome = "cancelled";
2608
- span.recordError(error);
2609
- throw error;
2610
- } finally {
2611
- scope?.dispose();
2612
- recordMetric(
2613
- this.metrics,
2614
- "kaji.integration.request_ms",
2615
- Math.max(0, this.monotonicNow() - started),
2616
- { integration: this.integration, operation, outcome }
2617
- );
2618
- span.end();
2619
- }
2620
- }
2621
- close() {
2622
- if (this.closed) return;
2623
- this.transport.close?.();
2624
- this.closed = true;
2625
- }
2626
- };
2627
- var productionTransport = () => new NodeHttpsTransport();
2628
- function createGitHubRequester(observability = {}) {
2629
- return new FixedOriginRequesterImpl(
2630
- { origin: new URL("https://api.github.com/"), integration: "github" },
2631
- productionTransport(),
2632
- observability
2633
- );
2634
- }
2635
- function createGmailRequester(observability = {}) {
2636
- return new FixedOriginRequesterImpl(
2637
- { origin: new URL("https://gmail.googleapis.com/"), integration: "gmail" },
2638
- productionTransport(),
2639
- observability
2640
- );
2641
- }
2642
-
2643
- // src/integrations/public.ts
2644
- function snapshotIntegrationResult(value) {
2645
- return durableJsonSnapshot(value, "tool_result", MAX_DURABLE_TOOL_RESULT_BYTES);
2646
- }
2647
-
2648
- export { createGitHubRequester, createGmailRequester, snapshotIntegrationResult };
2649
- //# sourceMappingURL=integrations.js.map
2650
- //# sourceMappingURL=integrations.js.map