@graphorin/core 0.5.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 (134) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +70 -0
  4. package/dist/channels/channels.d.ts +156 -0
  5. package/dist/channels/channels.d.ts.map +1 -0
  6. package/dist/channels/channels.js +90 -0
  7. package/dist/channels/channels.js.map +1 -0
  8. package/dist/channels/directive.d.ts +34 -0
  9. package/dist/channels/directive.d.ts.map +1 -0
  10. package/dist/channels/directive.js +29 -0
  11. package/dist/channels/directive.js.map +1 -0
  12. package/dist/channels/dispatch.d.ts +26 -0
  13. package/dist/channels/dispatch.d.ts.map +1 -0
  14. package/dist/channels/dispatch.js +32 -0
  15. package/dist/channels/dispatch.js.map +1 -0
  16. package/dist/channels/index.d.ts +5 -0
  17. package/dist/channels/index.js +6 -0
  18. package/dist/channels/pause.d.ts +84 -0
  19. package/dist/channels/pause.d.ts.map +1 -0
  20. package/dist/channels/pause.js +90 -0
  21. package/dist/channels/pause.js.map +1 -0
  22. package/dist/contracts/auth-token-store.d.ts +45 -0
  23. package/dist/contracts/auth-token-store.d.ts.map +1 -0
  24. package/dist/contracts/checkpoint-store.d.ts +90 -0
  25. package/dist/contracts/checkpoint-store.d.ts.map +1 -0
  26. package/dist/contracts/embedder.d.ts +45 -0
  27. package/dist/contracts/embedder.d.ts.map +1 -0
  28. package/dist/contracts/eval-scorer.d.ts +46 -0
  29. package/dist/contracts/eval-scorer.d.ts.map +1 -0
  30. package/dist/contracts/index.d.ts +22 -0
  31. package/dist/contracts/index.js +6 -0
  32. package/dist/contracts/local-provider-trust.d.ts +36 -0
  33. package/dist/contracts/local-provider-trust.d.ts.map +1 -0
  34. package/dist/contracts/logger.d.ts +53 -0
  35. package/dist/contracts/logger.d.ts.map +1 -0
  36. package/dist/contracts/logger.js +21 -0
  37. package/dist/contracts/logger.js.map +1 -0
  38. package/dist/contracts/memory-store.d.ts +106 -0
  39. package/dist/contracts/memory-store.d.ts.map +1 -0
  40. package/dist/contracts/oauth-server-store.d.ts +81 -0
  41. package/dist/contracts/oauth-server-store.d.ts.map +1 -0
  42. package/dist/contracts/preferred-model.d.ts +60 -0
  43. package/dist/contracts/preferred-model.d.ts.map +1 -0
  44. package/dist/contracts/preferred-model.js +15 -0
  45. package/dist/contracts/preferred-model.js.map +1 -0
  46. package/dist/contracts/provider.d.ts +272 -0
  47. package/dist/contracts/provider.d.ts.map +1 -0
  48. package/dist/contracts/reasoning-retention.d.ts +53 -0
  49. package/dist/contracts/reasoning-retention.d.ts.map +1 -0
  50. package/dist/contracts/redaction-validator.d.ts +59 -0
  51. package/dist/contracts/redaction-validator.d.ts.map +1 -0
  52. package/dist/contracts/sandbox.d.ts +73 -0
  53. package/dist/contracts/sandbox.d.ts.map +1 -0
  54. package/dist/contracts/secret-ref.d.ts +26 -0
  55. package/dist/contracts/secret-ref.d.ts.map +1 -0
  56. package/dist/contracts/secret-value.d.ts +112 -0
  57. package/dist/contracts/secret-value.d.ts.map +1 -0
  58. package/dist/contracts/secret-value.js +24 -0
  59. package/dist/contracts/secret-value.js.map +1 -0
  60. package/dist/contracts/secrets-store.d.ts +87 -0
  61. package/dist/contracts/secrets-store.d.ts.map +1 -0
  62. package/dist/contracts/session-store.d.ts +142 -0
  63. package/dist/contracts/session-store.d.ts.map +1 -0
  64. package/dist/contracts/token-counter.d.ts +28 -0
  65. package/dist/contracts/token-counter.d.ts.map +1 -0
  66. package/dist/contracts/tool.d.ts +264 -0
  67. package/dist/contracts/tool.d.ts.map +1 -0
  68. package/dist/contracts/tracer.d.ts +84 -0
  69. package/dist/contracts/tracer.d.ts.map +1 -0
  70. package/dist/contracts/tracer.js +34 -0
  71. package/dist/contracts/tracer.js.map +1 -0
  72. package/dist/contracts/trigger-store.d.ts +43 -0
  73. package/dist/contracts/trigger-store.d.ts.map +1 -0
  74. package/dist/index.d.ts +59 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +38 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/types/agent-event.d.ts +449 -0
  79. package/dist/types/agent-event.d.ts.map +1 -0
  80. package/dist/types/handoff.d.ts +112 -0
  81. package/dist/types/handoff.d.ts.map +1 -0
  82. package/dist/types/index.d.ts +13 -0
  83. package/dist/types/index.js +6 -0
  84. package/dist/types/memory.d.ts +354 -0
  85. package/dist/types/memory.d.ts.map +1 -0
  86. package/dist/types/message.d.ts +162 -0
  87. package/dist/types/message.d.ts.map +1 -0
  88. package/dist/types/run.d.ts +155 -0
  89. package/dist/types/run.d.ts.map +1 -0
  90. package/dist/types/run.js +31 -0
  91. package/dist/types/run.js.map +1 -0
  92. package/dist/types/sensitivity.d.ts +35 -0
  93. package/dist/types/sensitivity.d.ts.map +1 -0
  94. package/dist/types/sensitivity.js +29 -0
  95. package/dist/types/sensitivity.js.map +1 -0
  96. package/dist/types/session-scope.d.ts +22 -0
  97. package/dist/types/session-scope.d.ts.map +1 -0
  98. package/dist/types/stop-condition.d.ts +62 -0
  99. package/dist/types/stop-condition.d.ts.map +1 -0
  100. package/dist/types/stop-condition.js +81 -0
  101. package/dist/types/stop-condition.js.map +1 -0
  102. package/dist/types/tool-call.d.ts +27 -0
  103. package/dist/types/tool-call.d.ts.map +1 -0
  104. package/dist/types/tool.d.ts +260 -0
  105. package/dist/types/tool.d.ts.map +1 -0
  106. package/dist/types/usage.d.ts +82 -0
  107. package/dist/types/usage.d.ts.map +1 -0
  108. package/dist/types/usage.js +17 -0
  109. package/dist/types/usage.js.map +1 -0
  110. package/dist/types/workflow-event.d.ts +108 -0
  111. package/dist/types/workflow-event.d.ts.map +1 -0
  112. package/dist/utils/assert-never.d.ts +26 -0
  113. package/dist/utils/assert-never.d.ts.map +1 -0
  114. package/dist/utils/assert-never.js +29 -0
  115. package/dist/utils/assert-never.js.map +1 -0
  116. package/dist/utils/async-context.d.ts +37 -0
  117. package/dist/utils/async-context.d.ts.map +1 -0
  118. package/dist/utils/async-context.js +33 -0
  119. package/dist/utils/async-context.js.map +1 -0
  120. package/dist/utils/hash.d.ts +30 -0
  121. package/dist/utils/hash.d.ts.map +1 -0
  122. package/dist/utils/hash.js +102 -0
  123. package/dist/utils/hash.js.map +1 -0
  124. package/dist/utils/index.d.ts +6 -0
  125. package/dist/utils/index.js +7 -0
  126. package/dist/utils/streams.d.ts +59 -0
  127. package/dist/utils/streams.d.ts.map +1 -0
  128. package/dist/utils/streams.js +169 -0
  129. package/dist/utils/streams.js.map +1 -0
  130. package/dist/utils/validation.d.ts +67 -0
  131. package/dist/utils/validation.d.ts.map +1 -0
  132. package/dist/utils/validation.js +36 -0
  133. package/dist/utils/validation.js.map +1 -0
  134. package/package.json +82 -0
@@ -0,0 +1,449 @@
1
+ import { Usage } from "./usage.js";
2
+ import { ContentChunk, ToolError } from "./tool.js";
3
+ import { RunError, RunState, RunStatus } from "./run.js";
4
+
5
+ //#region src/types/agent-event.d.ts
6
+
7
+ /**
8
+ * Discriminated union of every event produced by `Agent.stream(...)`.
9
+ *
10
+ * Each variant has a literal `type` field used as the discriminator. The
11
+ * union is exhaustive: `assertNever(...)` catches missed variants at
12
+ * compile time.
13
+ *
14
+ * The shape is wire-stable: the protocol package (`@graphorin/protocol`,
15
+ * created in a later phase) re-exports this union as its server-to-client
16
+ * payload schema. Adding a variant here therefore counts as a wire-format
17
+ * change; track it through changesets.
18
+ *
19
+ * @stable
20
+ */
21
+ type AgentEvent<TOutput = string> = AgentStartEvent | StepStartEvent | TextDeltaEvent | TextCompleteEvent | ReasoningDeltaEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolExecuteStartEvent | ToolExecuteProgressEvent | ToolExecutePartialEvent | ToolExecuteEndEvent | ToolExecuteErrorEvent | ToolApprovalRequestedEvent | ToolApprovalGrantedEvent | ToolApprovalDeniedEvent | ContextCompactedEvent | HandoffEvent | AgentSteeredEvent | AgentFollowUpQueuedEvent | AgentCancellingEvent | AgentModelFellbackEvent | AgentFanOutSpawnedEvent | AgentFanOutMergedEvent | AgentEvaluatorIterationEvent | AgentEvaluatorConvergedEvent | AgentProgressWrittenEvent | AgentProgressReadEvent | AgentLateralLeakDetectedEvent | FileGeneratedEvent | SourceCitedEvent | StepEndEvent | GuardrailTrippedEvent | AgentEndEvent<TOutput> | AgentErrorEvent;
22
+ /** @stable */
23
+ interface AgentStartEvent {
24
+ readonly type: 'agent.start';
25
+ readonly runId: string;
26
+ readonly agentId: string;
27
+ }
28
+ /** @stable */
29
+ interface StepStartEvent {
30
+ readonly type: 'step.start';
31
+ readonly stepNumber: number;
32
+ }
33
+ /** @stable */
34
+ interface TextDeltaEvent {
35
+ readonly type: 'text.delta';
36
+ readonly delta: string;
37
+ }
38
+ /** @stable */
39
+ interface TextCompleteEvent {
40
+ readonly type: 'text.complete';
41
+ readonly text: string;
42
+ }
43
+ /** @stable */
44
+ interface ReasoningDeltaEvent {
45
+ readonly type: 'reasoning.delta';
46
+ readonly delta: string;
47
+ }
48
+ /** @stable */
49
+ interface ToolCallStartEvent {
50
+ readonly type: 'tool.call.start';
51
+ readonly toolCallId: string;
52
+ readonly toolName: string;
53
+ readonly args: unknown;
54
+ }
55
+ /** @stable */
56
+ interface ToolCallDeltaEvent {
57
+ readonly type: 'tool.call.delta';
58
+ readonly toolCallId: string;
59
+ readonly argsDelta: string;
60
+ }
61
+ /** @stable */
62
+ interface ToolCallEndEvent {
63
+ readonly type: 'tool.call.end';
64
+ readonly toolCallId: string;
65
+ readonly finalArgs: unknown;
66
+ }
67
+ /** @stable */
68
+ interface ToolExecuteStartEvent {
69
+ readonly type: 'tool.execute.start';
70
+ readonly toolCallId: string;
71
+ }
72
+ /**
73
+ * Emitted by streaming-hint tools via `ctx.reportProgress(...)`. Counter
74
+ * pair `(current, total?)` is consumer-rendered as a percentage when both
75
+ * fields are present.
76
+ *
77
+ * @stable
78
+ */
79
+ interface ToolExecuteProgressEvent {
80
+ readonly type: 'tool.execute.progress';
81
+ readonly toolName: string;
82
+ readonly toolCallId: string;
83
+ readonly current: number;
84
+ readonly total?: number;
85
+ readonly message?: string;
86
+ readonly stepNumber: number;
87
+ readonly ts: number;
88
+ }
89
+ /**
90
+ * Emitted by streaming-hint tools via `ctx.streamContent(...)`. Each
91
+ * chunk is concatenated into the assembled `output` per the
92
+ * buffer-becomes-output discipline. `chunkIndex` is monotone per
93
+ * `(toolCallId)` so subscribers can detect drops.
94
+ *
95
+ * @stable
96
+ */
97
+ interface ToolExecutePartialEvent {
98
+ readonly type: 'tool.execute.partial';
99
+ readonly toolName: string;
100
+ readonly toolCallId: string;
101
+ readonly chunk: ContentChunk;
102
+ readonly chunkIndex: number;
103
+ readonly stepNumber: number;
104
+ readonly ts: number;
105
+ }
106
+ /** @stable */
107
+ interface ToolExecuteEndEvent {
108
+ readonly type: 'tool.execute.end';
109
+ readonly toolCallId: string;
110
+ readonly result: unknown;
111
+ readonly durationMs: number;
112
+ }
113
+ /** @stable */
114
+ interface ToolExecuteErrorEvent {
115
+ readonly type: 'tool.execute.error';
116
+ readonly toolCallId: string;
117
+ readonly error: ToolError;
118
+ }
119
+ /** @stable */
120
+ interface ToolApprovalRequestedEvent {
121
+ readonly type: 'tool.approval.requested';
122
+ readonly toolCallId: string;
123
+ readonly reason?: string;
124
+ }
125
+ /** @stable */
126
+ interface ToolApprovalGrantedEvent {
127
+ readonly type: 'tool.approval.granted';
128
+ readonly toolCallId: string;
129
+ }
130
+ /** @stable */
131
+ interface ToolApprovalDeniedEvent {
132
+ readonly type: 'tool.approval.denied';
133
+ readonly toolCallId: string;
134
+ readonly reason?: string;
135
+ }
136
+ /**
137
+ * Emitted when the runtime auto-compacts the in-flight session
138
+ * message-history to fit the context window.
139
+ *
140
+ * @stable
141
+ */
142
+ interface ContextCompactedEvent {
143
+ readonly type: 'context.compacted';
144
+ readonly runId: string;
145
+ readonly sessionId: string;
146
+ readonly agentId: string;
147
+ readonly beforeTokens: number;
148
+ readonly afterTokens: number;
149
+ readonly summaryTokens: number;
150
+ readonly durationMs: number;
151
+ readonly source: 'auto-trigger' | 'manual' | 'pre-step';
152
+ readonly hooksFiredCount: number;
153
+ }
154
+ /** @stable */
155
+ interface HandoffEvent {
156
+ readonly type: 'handoff';
157
+ readonly fromAgentId: string;
158
+ readonly toAgentId: string;
159
+ readonly reason?: string;
160
+ }
161
+ /**
162
+ * A provider-generated file surfaced from the model stream (AG-26) —
163
+ * previously these `'file'` provider events were silently dropped.
164
+ *
165
+ * @stable
166
+ */
167
+ interface FileGeneratedEvent {
168
+ readonly type: 'file.generated';
169
+ readonly mimeType: string;
170
+ readonly data: Uint8Array;
171
+ }
172
+ /**
173
+ * A provider citation surfaced from the model stream (AG-26) —
174
+ * previously these `'source'` provider events were silently dropped.
175
+ *
176
+ * @stable
177
+ */
178
+ interface SourceCitedEvent {
179
+ readonly type: 'source.cited';
180
+ readonly uri: string;
181
+ readonly title?: string;
182
+ }
183
+ /** @stable */
184
+ interface StepEndEvent {
185
+ readonly type: 'step.end';
186
+ readonly stepNumber: number;
187
+ readonly usage: Usage;
188
+ }
189
+ /** @stable */
190
+ interface GuardrailTrippedEvent {
191
+ readonly type: 'guardrail.tripped';
192
+ readonly guardrailName: string;
193
+ readonly phase: 'input' | 'output';
194
+ readonly reason?: string;
195
+ }
196
+ /** @stable */
197
+ interface AgentEndEvent<TOutput = string> {
198
+ readonly type: 'agent.end';
199
+ readonly runId: string;
200
+ readonly result: AgentResult<TOutput>;
201
+ }
202
+ /** @stable */
203
+ interface AgentErrorEvent {
204
+ readonly type: 'agent.error';
205
+ readonly error: {
206
+ readonly message: string;
207
+ readonly code: string;
208
+ };
209
+ }
210
+ /**
211
+ * Emitted when `agent.steer(...)` queues an intervention to flow into
212
+ * the next provider call within the current run.
213
+ *
214
+ * @stable
215
+ */
216
+ interface AgentSteeredEvent {
217
+ readonly type: 'agent.steered';
218
+ readonly runId: string;
219
+ }
220
+ /**
221
+ * Emitted when `agent.followUp(...)` queues a follow-up turn to fire
222
+ * after the current turn completes.
223
+ *
224
+ * @stable
225
+ */
226
+ interface AgentFollowUpQueuedEvent {
227
+ readonly type: 'agent.followup.queued';
228
+ readonly runId: string;
229
+ }
230
+ /**
231
+ * Emitted at the moment `agent.abort({ ... })` is called, before any
232
+ * pending tool / provider calls have terminated. Subscribers use this
233
+ * to render "cancelling..." UI before the run actually winds down.
234
+ *
235
+ * @stable
236
+ */
237
+ interface AgentCancellingEvent {
238
+ readonly type: 'agent.cancelling';
239
+ readonly runId: string;
240
+ readonly drain: boolean;
241
+ readonly onPendingApprovals: 'deny' | 'hold' | 'fail';
242
+ }
243
+ /**
244
+ * Emitted exactly once per agent-level model-fallback transition.
245
+ * Identifies the failed primary, the next model in
246
+ * `Agent.fallbackModels`, the eligible reason taxonomy, the
247
+ * 1-based step number and the 1-based attempt index within the step.
248
+ *
249
+ * The event fires BEFORE the new model's stream starts so that
250
+ * observers see the transition before any of the new model's
251
+ * subsequent events flow.
252
+ *
253
+ * @stable
254
+ */
255
+ interface AgentModelFellbackEvent {
256
+ readonly type: 'agent.model.fellback';
257
+ readonly runId: string;
258
+ readonly sessionId: string;
259
+ readonly agentId: string;
260
+ readonly from: string;
261
+ readonly to: string;
262
+ readonly reason: 'rate-limit' | 'capacity' | 'context-length' | 'transient';
263
+ readonly stepNumber: number;
264
+ readonly attempt: number;
265
+ }
266
+ /**
267
+ * Emitted when `Agent.fanOut(...)` begins to spawn its sub-agents.
268
+ *
269
+ * @stable
270
+ */
271
+ interface AgentFanOutSpawnedEvent {
272
+ readonly type: 'agent.fanout.spawned';
273
+ readonly runId: string;
274
+ readonly sessionId: string;
275
+ readonly agentId: string;
276
+ readonly fanOutId: string;
277
+ readonly childCount: number;
278
+ readonly mergeStrategyKind: 'concat' | 'first-success' | 'judge-merge' | 'custom';
279
+ readonly spawnedAtIso: string;
280
+ }
281
+ /**
282
+ * Per-child result entry surfaced on
283
+ * {@link AgentFanOutMergedEvent.childMetadata}.
284
+ *
285
+ * @stable
286
+ */
287
+ interface FanOutChildMetadata {
288
+ readonly agentId: string;
289
+ readonly status: 'completed' | 'failed' | 'budget-exceeded' | 'cancelled';
290
+ readonly tokensUsed: number;
291
+ readonly toolCallCount: number;
292
+ readonly durationMs: number;
293
+ }
294
+ /**
295
+ * Emitted when the fan-out merge step completes.
296
+ *
297
+ * @stable
298
+ */
299
+ interface AgentFanOutMergedEvent {
300
+ readonly type: 'agent.fanout.merged';
301
+ readonly runId: string;
302
+ readonly sessionId: string;
303
+ readonly agentId: string;
304
+ readonly fanOutId: string;
305
+ readonly childCount: number;
306
+ readonly successfulChildCount: number;
307
+ readonly mergeStrategyKind: 'concat' | 'first-success' | 'judge-merge' | 'custom';
308
+ readonly mergeDurationMs: number;
309
+ readonly childMetadata: ReadonlyArray<FanOutChildMetadata>;
310
+ }
311
+ /**
312
+ * Emitted per iteration of an `evaluatorOptimizer({...})` loop.
313
+ *
314
+ * @stable
315
+ */
316
+ interface AgentEvaluatorIterationEvent {
317
+ readonly type: 'agent.evaluator.iteration';
318
+ readonly runId: string;
319
+ readonly sessionId: string;
320
+ readonly agentId: string;
321
+ readonly iteration: number;
322
+ readonly score: number;
323
+ readonly pass: boolean;
324
+ readonly critique: string;
325
+ readonly durationMs: number;
326
+ }
327
+ /**
328
+ * Emitted at the termination of an `evaluatorOptimizer({...})` loop.
329
+ *
330
+ * @stable
331
+ */
332
+ interface AgentEvaluatorConvergedEvent {
333
+ readonly type: 'agent.evaluator.converged';
334
+ readonly runId: string;
335
+ readonly sessionId: string;
336
+ readonly agentId: string;
337
+ readonly totalIterations: number;
338
+ readonly finalScore: number;
339
+ readonly terminationReason: 'pass' | 'maxIterations' | 'generator-exhausted' | 'cancelled';
340
+ }
341
+ /**
342
+ * Reference to a persisted progress artifact returned by
343
+ * `agent.progress.write(...)` and `agent.progress.read(...)`.
344
+ *
345
+ * @stable
346
+ */
347
+ interface ProgressArtifactRef {
348
+ readonly path: string;
349
+ readonly role: string;
350
+ readonly seq: number;
351
+ readonly sizeBytes: number;
352
+ readonly sensitivity: 'public' | 'internal' | 'secret';
353
+ readonly tags?: ReadonlyArray<string>;
354
+ readonly writtenAtIso: string;
355
+ readonly sha256: string;
356
+ }
357
+ /**
358
+ * Emitted after `agent.progress.write(...)` completes.
359
+ *
360
+ * @stable
361
+ */
362
+ interface AgentProgressWrittenEvent {
363
+ readonly type: 'agent.progress.written';
364
+ readonly runId: string;
365
+ readonly sessionId: string;
366
+ readonly agentId: string;
367
+ readonly ref: ProgressArtifactRef;
368
+ }
369
+ /**
370
+ * Emitted after `agent.progress.read(...)` completes.
371
+ *
372
+ * @stable
373
+ */
374
+ interface AgentProgressReadEvent {
375
+ readonly type: 'agent.progress.read';
376
+ readonly runId: string;
377
+ readonly sessionId: string;
378
+ readonly agentId: string;
379
+ readonly refs: ReadonlyArray<ProgressArtifactRef>;
380
+ readonly queriedRunId: string;
381
+ readonly queriedRole: string | undefined;
382
+ }
383
+ /**
384
+ * Lateral-leak vector classification surfaced on
385
+ * {@link AgentLateralLeakDetectedEvent.vector}.
386
+ *
387
+ * - `'causality-laundering'` — the assistant message references
388
+ * information about a denied earlier action via an indirect chain.
389
+ * - `'commentary-phase'` — operator-only commentary content was
390
+ * about to escape the session-output boundary.
391
+ * - `'sideways-injection'` — a low-trust child of an
392
+ * `Agent.fanOut(...)` `'judge-merge'` strategy contributed
393
+ * disproportionately to the merged output.
394
+ * - `'protocol-header'` — control-character bytes or a
395
+ * protocol-frame separator was about to escape one of the
396
+ * internal-service delivery boundaries.
397
+ *
398
+ * @stable
399
+ */
400
+ type LateralLeakVector = 'causality-laundering' | 'commentary-phase' | 'sideways-injection' | 'protocol-header';
401
+ /**
402
+ * Emitted when the lateral-leak defense layer flags or blocks a
403
+ * suspected leak.
404
+ *
405
+ * @stable
406
+ */
407
+ interface AgentLateralLeakDetectedEvent {
408
+ readonly type: 'agent.lateral-leak.detected';
409
+ readonly runId: string;
410
+ readonly sessionId: string;
411
+ readonly agentId: string;
412
+ readonly vector: LateralLeakVector;
413
+ readonly severity: 'info' | 'warn' | 'block';
414
+ readonly causalityChain: ReadonlyArray<string>;
415
+ readonly messageContentSha256: string;
416
+ readonly matchedPattern?: string;
417
+ readonly decision: 'detect' | 'flag' | 'strip' | 'block';
418
+ readonly detectedAtIso: string;
419
+ }
420
+ /**
421
+ * Final result of an agent run-loop invocation, returned by
422
+ * `agent.run(...)` and carried by the `agent.end` event.
423
+ *
424
+ * A failed run **resolves** with `status: 'failed'` and the error in
425
+ * `error` — `agent.run(...)` does not reject on run failure (only on
426
+ * configuration/usage errors thrown before the loop starts). A suspended
427
+ * run resolves with `status: 'awaiting_approval'` and a resumable
428
+ * `state` (AG-9).
429
+ *
430
+ * @stable
431
+ */
432
+ interface AgentResult<TOutput = string> {
433
+ readonly output: TOutput;
434
+ readonly usage: Usage;
435
+ /** Terminal status of this run-loop invocation. */
436
+ readonly status: RunStatus;
437
+ /** Populated when the run failed; mirrors `RunState.error`. */
438
+ readonly error?: RunError;
439
+ /**
440
+ * The run's final state. Resumable when `status === 'awaiting_approval'`
441
+ * — pass it back to `agent.run(...)` / `agent.stream(...)` (optionally
442
+ * round-tripped through `runStateToJSON`/`runStateFromJSON` for
443
+ * durability). Treat as an immutable snapshot.
444
+ */
445
+ readonly state: RunState;
446
+ }
447
+ //#endregion
448
+ export { AgentCancellingEvent, AgentEndEvent, AgentErrorEvent, AgentEvaluatorConvergedEvent, AgentEvaluatorIterationEvent, AgentEvent, AgentFanOutMergedEvent, AgentFanOutSpawnedEvent, AgentFollowUpQueuedEvent, AgentLateralLeakDetectedEvent, AgentModelFellbackEvent, AgentProgressReadEvent, AgentProgressWrittenEvent, AgentResult, AgentStartEvent, AgentSteeredEvent, ContextCompactedEvent, FanOutChildMetadata, GuardrailTrippedEvent, HandoffEvent, LateralLeakVector, ProgressArtifactRef, ReasoningDeltaEvent, StepEndEvent, StepStartEvent, TextCompleteEvent, TextDeltaEvent, ToolApprovalDeniedEvent, ToolApprovalGrantedEvent, ToolApprovalRequestedEvent, ToolCallDeltaEvent, ToolCallEndEvent, ToolCallStartEvent, ToolExecuteEndEvent, ToolExecuteErrorEvent, ToolExecutePartialEvent, ToolExecuteProgressEvent, ToolExecuteStartEvent };
449
+ //# sourceMappingURL=agent-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-event.d.ts","names":[],"sources":["../../src/types/agent-event.ts"],"sourcesContent":[],"mappings":"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"}
@@ -0,0 +1,112 @@
1
+ import { Message } from "./message.js";
2
+
3
+ //#region src/types/handoff.d.ts
4
+
5
+ /**
6
+ * Filter applied to the parent's message history when handing off control
7
+ * to a target agent. Implementations live in `@graphorin/agent` (e.g.
8
+ * `filters.lastN(10)`); the contract type lives here so every package
9
+ * (server, sessions, observability, …) can type a parameter as
10
+ * `HandoffFilter` without an agent dependency.
11
+ *
12
+ * The default for the agent runtime is `lastN(10)` (per the security-first
13
+ * compose policy). Filters should be **pure** — they receive a frozen
14
+ * history and return a fresh array.
15
+ *
16
+ * @stable
17
+ */
18
+ type HandoffFilter = (history: readonly Message[]) => readonly Message[];
19
+ /**
20
+ * Declarative handoff target. The value carries a reference to the target
21
+ * agent (`agentId` — looked up at runtime via the `AgentRegistry`) plus
22
+ * optional metadata used by the runtime when constructing the
23
+ * `transfer_to_<agentName>` virtual tool.
24
+ *
25
+ * @stable
26
+ */
27
+ interface Handoff {
28
+ /** ID of the target agent (looked up via `AgentRegistry`). */
29
+ readonly targetAgentId: string;
30
+ /** Optional human-readable name, surfaced in the virtual tool name. */
31
+ readonly targetAgentName?: string;
32
+ /** Optional input filter applied to the parent's history. */
33
+ readonly inputFilter?: HandoffFilter;
34
+ /** Optional human-readable reason rendered in the audit log. */
35
+ readonly reason?: string;
36
+ }
37
+ /**
38
+ * Stable, serializable description of the input filter applied to a
39
+ * handoff. Persisted alongside `HandoffRecord` and round-tripped through
40
+ * the JSONL session export so a replay can re-construct the filter
41
+ * stack even after the runtime filter implementations evolve.
42
+ *
43
+ * The discriminator `kind` is an open string union — well-known kinds
44
+ * include `'full' | 'last-n' | 'last-user' | 'summary' |
45
+ * 'sensitivity-filter' | 'compose' | 'custom'`. The accompanying `meta`
46
+ * carries kind-specific data (for example `{ n: 10 }` for `'last-n'`,
47
+ * `{ summary: '...' }` for `'summary'`, or
48
+ * `{ messagesPassedCount, strippedReasoningCount, ... }` summary stats
49
+ * for `'compose'`). New kinds may be added freely; consumers must not
50
+ * assume an exhaustive switch.
51
+ *
52
+ * @stable
53
+ */
54
+ interface HandoffInputFilterDescriptor {
55
+ readonly kind: string;
56
+ readonly meta?: Readonly<Record<string, unknown>>;
57
+ }
58
+ /**
59
+ * How the parent's secrets surface is propagated to the sub-agent
60
+ * during a handoff. The default — `'inherit-allowlist'` with an empty
61
+ * inherited list — applies the principle of least authority: the sub-
62
+ * agent inherits only the keys the operator has explicitly named.
63
+ *
64
+ * - `'inherit-allowlist'` — inherit the keys named in
65
+ * `inheritedSecrets`. Empty list = no inheritance.
66
+ * - `'isolated'` — the sub-agent runs with an empty secrets surface.
67
+ * - `'forward-explicit'` — every secret access on the sub-agent's side
68
+ * must be explicitly broadened by the operator with a recorded
69
+ * `secretsOverrideReason`.
70
+ *
71
+ * @stable
72
+ */
73
+ type HandoffSecretsInheritance = 'inherit-allowlist' | 'isolated' | 'forward-explicit';
74
+ /**
75
+ * Recorded handoff event captured on `RunState.handoffs` and replayed by
76
+ * the JSONL session export. The shape is wire-stable.
77
+ *
78
+ * @stable
79
+ */
80
+ interface HandoffRecord {
81
+ readonly fromAgentId: string;
82
+ readonly toAgentId: string;
83
+ readonly stepNumber: number;
84
+ readonly at: string;
85
+ readonly reason?: string;
86
+ /**
87
+ * Serializable input-filter descriptor applied at handoff time. When
88
+ * undefined the runtime defaults applied (commonly
89
+ * `compose(lastN(10), stripReasoning, stripSensitiveOutputs)`); the
90
+ * concrete filter implementations live in `@graphorin/agent`.
91
+ */
92
+ readonly inputFilter?: HandoffInputFilterDescriptor;
93
+ /**
94
+ * Sub-agent secrets propagation policy. Defaults to
95
+ * `'inherit-allowlist'` with empty `inheritedSecrets`.
96
+ */
97
+ readonly secretsInheritance?: HandoffSecretsInheritance;
98
+ /**
99
+ * Keys inherited by the sub-agent under the
100
+ * `'inherit-allowlist'` / `'forward-explicit'` policies. Never the
101
+ * secret values themselves — only the public key names.
102
+ */
103
+ readonly inheritedSecrets?: ReadonlyArray<string>;
104
+ /**
105
+ * Operator-supplied justification for broadening or narrowing the
106
+ * default secrets surface. Surfaced in audit logs.
107
+ */
108
+ readonly secretsOverrideReason?: string;
109
+ }
110
+ //#endregion
111
+ export { Handoff, HandoffFilter, HandoffInputFilterDescriptor, HandoffRecord, HandoffSecretsInheritance };
112
+ //# sourceMappingURL=handoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff.d.ts","names":[],"sources":["../../src/types/handoff.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAUA;AA4BA;AAoBA;AAQA;;;;;;;KAlEY,aAAA,sBAAmC,uBAAuB;;;;;;;;;UAUrD,OAAA;;;;;;yBAMQ;;;;;;;;;;;;;;;;;;;;;UAsBR,4BAAA;;kBAEC,SAAS;;;;;;;;;;;;;;;;;KAkBf,yBAAA;;;;;;;UAQK,aAAA;;;;;;;;;;;;yBAYQ;;;;;gCAKO;;;;;;8BAMF"}
@@ -0,0 +1,13 @@
1
+ import { SENSITIVITY_ORDER, Sensitivity, acceptsSensitivity } from "./sensitivity.js";
2
+ import { Block, EntityRole, Episode, Fact, GraphEntity, Insight, MemoryHit, MemoryKind, MemoryMetadata, MemoryProvenance, MemoryRecord, MemorySearchOptions, MemoryStatus, Rule } from "./memory.js";
3
+ import { ToolCall } from "./tool-call.js";
4
+ import { AssistantMessage, AudioContent, FileContent, ImageContent, Message, MessageContent, MessageRole, ReasoningContent, ReasoningContentMeta, SystemMessage, TextContent, ToolMessage, UserMessage } from "./message.js";
5
+ import { SessionScope } from "./session-scope.js";
6
+ import { Cost, ModelUsage, Usage, UsageAccumulator, UsageSnapshot, zeroUsage } from "./usage.js";
7
+ import { Handoff, HandoffFilter, HandoffInputFilterDescriptor, HandoffRecord, HandoffSecretsInheritance } from "./handoff.js";
8
+ import { CompletedToolCall, ContentChunk, InboundSanitizationPolicy, MemoryGuardTier, ResultHandle, SandboxPolicy, SideEffectClass, ToolApproval, ToolError, ToolErrorKind, ToolOutcome, ToolResult, ToolSource, ToolTrustClass, TruncationStrategy } from "./tool.js";
9
+ import { RunContext, RunError, RunState, RunStateUsageByModel, RunStatus, RunStep, RunTaintSummary, flattenUsageByModel } from "./run.js";
10
+ import { AgentCancellingEvent, AgentEndEvent, AgentErrorEvent, AgentEvaluatorConvergedEvent, AgentEvaluatorIterationEvent, AgentEvent, AgentFanOutMergedEvent, AgentFanOutSpawnedEvent, AgentFollowUpQueuedEvent, AgentLateralLeakDetectedEvent, AgentModelFellbackEvent, AgentProgressReadEvent, AgentProgressWrittenEvent, AgentResult, AgentStartEvent, AgentSteeredEvent, ContextCompactedEvent, FanOutChildMetadata, GuardrailTrippedEvent, HandoffEvent, LateralLeakVector, ProgressArtifactRef, ReasoningDeltaEvent, StepEndEvent, StepStartEvent, TextCompleteEvent, TextDeltaEvent, ToolApprovalDeniedEvent, ToolApprovalGrantedEvent, ToolApprovalRequestedEvent, ToolCallDeltaEvent, ToolCallEndEvent, ToolCallStartEvent, ToolExecuteEndEvent, ToolExecuteErrorEvent, ToolExecutePartialEvent, ToolExecuteProgressEvent, ToolExecuteStartEvent } from "./agent-event.js";
11
+ import { StopCondition, and, hasToolCall, isStepCount, isTerminal, not, or } from "./stop-condition.js";
12
+ import { WorkflowChannelUpdateEvent, WorkflowCheckpointWrittenEvent, WorkflowCustomEvent, WorkflowEndEvent, WorkflowErrorEvent, WorkflowEvent, WorkflowResumedEvent, WorkflowStartEvent, WorkflowStepEndEvent, WorkflowStepStartEvent, WorkflowSuspendedEvent, WorkflowTaskEndEvent, WorkflowTaskStartEvent } from "./workflow-event.js";
13
+ export { type AgentCancellingEvent, type AgentEndEvent, type AgentErrorEvent, type AgentEvaluatorConvergedEvent, type AgentEvaluatorIterationEvent, type AgentEvent, type AgentFanOutMergedEvent, type AgentFanOutSpawnedEvent, type AgentFollowUpQueuedEvent, type AgentLateralLeakDetectedEvent, type AgentModelFellbackEvent, type AgentProgressReadEvent, type AgentProgressWrittenEvent, type AgentResult, type AgentStartEvent, type AgentSteeredEvent, type AssistantMessage, type AudioContent, type Block, type CompletedToolCall, type ContentChunk, type ContextCompactedEvent, type Cost, type EntityRole, type Episode, type Fact, type FanOutChildMetadata, type FileContent, type GraphEntity, type GuardrailTrippedEvent, type Handoff, type HandoffEvent, type HandoffFilter, type HandoffInputFilterDescriptor, type HandoffRecord, type HandoffSecretsInheritance, type ImageContent, type InboundSanitizationPolicy, type Insight, type LateralLeakVector, type MemoryGuardTier, type MemoryHit, type MemoryKind, type MemoryMetadata, type MemoryProvenance, type MemoryRecord, type MemorySearchOptions, type MemoryStatus, type Message, type MessageContent, type MessageRole, type ModelUsage, type ProgressArtifactRef, type ReasoningContent, type ReasoningContentMeta, type ReasoningDeltaEvent, type ResultHandle, type Rule, type RunContext, type RunError, type RunState, type RunStateUsageByModel, type RunStatus, type RunStep, type RunTaintSummary, SENSITIVITY_ORDER, type SandboxPolicy, type Sensitivity, type SessionScope, type SideEffectClass, type StepEndEvent, type StepStartEvent, type StopCondition, type SystemMessage, type TextCompleteEvent, type TextContent, type TextDeltaEvent, type ToolApproval, type ToolApprovalDeniedEvent, type ToolApprovalGrantedEvent, type ToolApprovalRequestedEvent, type ToolCall, type ToolCallDeltaEvent, type ToolCallEndEvent, type ToolCallStartEvent, type ToolError, type ToolErrorKind, type ToolExecuteEndEvent, type ToolExecuteErrorEvent, type ToolExecutePartialEvent, type ToolExecuteProgressEvent, type ToolExecuteStartEvent, type ToolMessage, type ToolOutcome, type ToolResult, type ToolSource, type ToolTrustClass, type TruncationStrategy, type Usage, type UsageAccumulator, type UsageSnapshot, type UserMessage, type WorkflowChannelUpdateEvent, type WorkflowCheckpointWrittenEvent, type WorkflowCustomEvent, type WorkflowEndEvent, type WorkflowErrorEvent, type WorkflowEvent, type WorkflowResumedEvent, type WorkflowStartEvent, type WorkflowStepEndEvent, type WorkflowStepStartEvent, type WorkflowSuspendedEvent, type WorkflowTaskEndEvent, type WorkflowTaskStartEvent, acceptsSensitivity, and, flattenUsageByModel, hasToolCall, isStepCount, isTerminal, not, or, zeroUsage };
@@ -0,0 +1,6 @@
1
+ import { flattenUsageByModel } from "./run.js";
2
+ import { SENSITIVITY_ORDER, acceptsSensitivity } from "./sensitivity.js";
3
+ import { and, hasToolCall, isStepCount, isTerminal, not, or } from "./stop-condition.js";
4
+ import { zeroUsage } from "./usage.js";
5
+
6
+ export { SENSITIVITY_ORDER, acceptsSensitivity, and, flattenUsageByModel, hasToolCall, isStepCount, isTerminal, not, or, zeroUsage };