@linnlabs/linnkit 0.37.4 → 0.38.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 (68) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/cli.cjs +347 -179
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +347 -179
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs +55 -11
  7. package/dist/context-manager.cjs.map +1 -1
  8. package/dist/context-manager.js +55 -11
  9. package/dist/context-manager.js.map +1 -1
  10. package/dist/contracts/audit.d.cts +6 -6
  11. package/dist/contracts/audit.d.ts +6 -6
  12. package/dist/contracts/events.d.cts +532 -50
  13. package/dist/contracts/events.d.ts +532 -50
  14. package/dist/contracts/llm-retry.d.cts +47 -0
  15. package/dist/contracts/llm-retry.d.ts +47 -0
  16. package/dist/contracts/messages.d.cts +2 -2
  17. package/dist/contracts/messages.d.ts +2 -2
  18. package/dist/contracts/runtime-error.d.cts +26 -0
  19. package/dist/contracts/runtime-error.d.ts +26 -0
  20. package/dist/contracts/sse.d.cts +571 -55
  21. package/dist/contracts/sse.d.ts +571 -55
  22. package/dist/contracts/sub-run-trace-payload.d.cts +102 -6
  23. package/dist/contracts/sub-run-trace-payload.d.ts +102 -6
  24. package/dist/contracts/token-accounting.d.cts +18 -18
  25. package/dist/contracts/token-accounting.d.ts +18 -18
  26. package/dist/contracts.cjs +65 -10
  27. package/dist/contracts.cjs.map +1 -1
  28. package/dist/contracts.d.cts +4 -2
  29. package/dist/contracts.d.ts +4 -2
  30. package/dist/contracts.js +62 -11
  31. package/dist/contracts.js.map +1 -1
  32. package/dist/index.cjs +506 -286
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.js +506 -286
  35. package/dist/index.js.map +1 -1
  36. package/dist/ports/canonical-inference.d.cts +3 -0
  37. package/dist/ports/canonical-inference.d.ts +3 -0
  38. package/dist/ports/llm-call.d.cts +4 -0
  39. package/dist/ports/llm-call.d.ts +4 -0
  40. package/dist/quickstart.cjs +347 -179
  41. package/dist/quickstart.cjs.map +1 -1
  42. package/dist/quickstart.js +347 -179
  43. package/dist/quickstart.js.map +1 -1
  44. package/dist/runtime-kernel/child-run-trace/subrunTrace.types.d.cts +8 -0
  45. package/dist/runtime-kernel/child-run-trace/subrunTrace.types.d.ts +8 -0
  46. package/dist/runtime-kernel/events/agentEvents.d.cts +85 -4
  47. package/dist/runtime-kernel/events/agentEvents.d.ts +85 -4
  48. package/dist/runtime-kernel/events/eventGovernance.d.cts +1 -1
  49. package/dist/runtime-kernel/events/eventGovernance.d.ts +1 -1
  50. package/dist/runtime-kernel/events.cjs +55 -11
  51. package/dist/runtime-kernel/events.cjs.map +1 -1
  52. package/dist/runtime-kernel/events.js +55 -11
  53. package/dist/runtime-kernel/events.js.map +1 -1
  54. package/dist/runtime-kernel/llm/request-builder.d.cts +2 -0
  55. package/dist/runtime-kernel/llm/request-builder.d.ts +2 -0
  56. package/dist/runtime-kernel.cjs +468 -271
  57. package/dist/runtime-kernel.cjs.map +1 -1
  58. package/dist/runtime-kernel.js +468 -271
  59. package/dist/runtime-kernel.js.map +1 -1
  60. package/dist/shared/errorClassifier.d.cts +5 -0
  61. package/dist/shared/errorClassifier.d.ts +5 -0
  62. package/dist/testkit.cjs +466 -269
  63. package/dist/testkit.cjs.map +1 -1
  64. package/dist/testkit.js +466 -269
  65. package/dist/testkit.js.map +1 -1
  66. package/docs/integration/llm-provider.md +24 -0
  67. package/docs/integration/realtime.md +29 -0
  68. package/package.json +2 -2
@@ -4,6 +4,8 @@ import { SerializableJsonRecord } from '../../contracts/json.cjs';
4
4
  import { SubRunTraceEvent } from '../../contracts/events.cjs';
5
5
  import { SubRunTraceToolCallDecision } from '../../contracts/sub-run-trace-payload.cjs';
6
6
  import { FinalAnswerCompletionReason } from '../../contracts/final-answer.cjs';
7
+ import { LlmRetryState } from '../../contracts/llm-retry.cjs';
8
+ import { RuntimeErrorState } from '../../contracts/runtime-error.cjs';
7
9
 
8
10
  /**
9
11
  * 子 run trace 的“业务无关”发布载荷。
@@ -19,6 +21,12 @@ interface SubRunTraceEnvelopeBase {
19
21
  meta?: SerializableJsonRecord;
20
22
  }
21
23
  type SubRunTraceEnvelope = SubRunTraceEnvelopeBase & ({
24
+ kind: 'llm_retry';
25
+ retry: LlmRetryState;
26
+ } | {
27
+ kind: 'error';
28
+ failure: RuntimeErrorState;
29
+ } | {
22
30
  kind: 'thought_delta';
23
31
  delta: string;
24
32
  } | {
@@ -4,6 +4,8 @@ import { SerializableJsonRecord } from '../../contracts/json.js';
4
4
  import { SubRunTraceEvent } from '../../contracts/events.js';
5
5
  import { SubRunTraceToolCallDecision } from '../../contracts/sub-run-trace-payload.js';
6
6
  import { FinalAnswerCompletionReason } from '../../contracts/final-answer.js';
7
+ import { LlmRetryState } from '../../contracts/llm-retry.js';
8
+ import { RuntimeErrorState } from '../../contracts/runtime-error.js';
7
9
 
8
10
  /**
9
11
  * 子 run trace 的“业务无关”发布载荷。
@@ -19,6 +21,12 @@ interface SubRunTraceEnvelopeBase {
19
21
  meta?: SerializableJsonRecord;
20
22
  }
21
23
  type SubRunTraceEnvelope = SubRunTraceEnvelopeBase & ({
24
+ kind: 'llm_retry';
25
+ retry: LlmRetryState;
26
+ } | {
27
+ kind: 'error';
28
+ failure: RuntimeErrorState;
29
+ } | {
22
30
  kind: 'thought_delta';
23
31
  delta: string;
24
32
  } | {
@@ -1157,8 +1157,55 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1157
1157
  }>, z.ZodObject<{
1158
1158
  timestamp: z.ZodNumber;
1159
1159
  id: z.ZodEffects<z.ZodString, string, string>;
1160
+ } & {
1161
+ retry_id: z.ZodEffects<z.ZodString, string, string>;
1162
+ status: z.ZodEnum<["waiting", "retrying", "succeeded", "exhausted", "failed", "cancelled"]>;
1163
+ category: z.ZodEnum<["transport", "output", "rate_limit", "other"]>;
1164
+ attempt: z.ZodNumber;
1165
+ max_retries: z.ZodNumber;
1166
+ total_attempts: z.ZodNumber;
1167
+ started_at: z.ZodNumber;
1168
+ delay_ms: z.ZodNumber;
1169
+ next_retry_at: z.ZodOptional<z.ZodNumber>;
1170
+ error: z.ZodString;
1171
+ error_code: z.ZodString;
1172
+ type: z.ZodLiteral<"llm_retry">;
1173
+ }, "strict", z.ZodTypeAny, {
1174
+ type: "llm_retry";
1175
+ id: string;
1176
+ timestamp: number;
1177
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1178
+ error: string;
1179
+ error_code: string;
1180
+ retry_id: string;
1181
+ category: "transport" | "output" | "rate_limit" | "other";
1182
+ attempt: number;
1183
+ max_retries: number;
1184
+ total_attempts: number;
1185
+ started_at: number;
1186
+ delay_ms: number;
1187
+ next_retry_at?: number | undefined;
1188
+ }, {
1189
+ type: "llm_retry";
1190
+ id: string;
1191
+ timestamp: number;
1192
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1193
+ error: string;
1194
+ error_code: string;
1195
+ retry_id: string;
1196
+ category: "transport" | "output" | "rate_limit" | "other";
1197
+ attempt: number;
1198
+ max_retries: number;
1199
+ total_attempts: number;
1200
+ started_at: number;
1201
+ delay_ms: number;
1202
+ next_retry_at?: number | undefined;
1203
+ }>, z.ZodObject<{
1204
+ timestamp: z.ZodNumber;
1205
+ id: z.ZodEffects<z.ZodString, string, string>;
1160
1206
  } & {
1161
1207
  type: z.ZodLiteral<"error">;
1208
+ retry_id: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
1162
1209
  error: z.ZodString;
1163
1210
  error_code: z.ZodOptional<z.ZodString>;
1164
1211
  retryable: z.ZodOptional<z.ZodBoolean>;
@@ -1169,16 +1216,18 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1169
1216
  timestamp: number;
1170
1217
  error: string;
1171
1218
  error_code?: string | undefined;
1172
- details?: Record<string, unknown> | undefined;
1219
+ retry_id?: string | undefined;
1173
1220
  retryable?: boolean | undefined;
1221
+ details?: Record<string, unknown> | undefined;
1174
1222
  }, {
1175
1223
  type: "error";
1176
1224
  id: string;
1177
1225
  timestamp: number;
1178
1226
  error: string;
1179
1227
  error_code?: string | undefined;
1180
- details?: Record<string, unknown> | undefined;
1228
+ retry_id?: string | undefined;
1181
1229
  retryable?: boolean | undefined;
1230
+ details?: Record<string, unknown> | undefined;
1182
1231
  }>, z.ZodObject<{
1183
1232
  timestamp: z.ZodNumber;
1184
1233
  id: z.ZodEffects<z.ZodString, string, string>;
@@ -1490,14 +1539,30 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1490
1539
  }[] | undefined;
1491
1540
  })[] | undefined;
1492
1541
  meta?: Record<string, unknown> | undefined;
1542
+ } | {
1543
+ type: "llm_retry";
1544
+ id: string;
1545
+ timestamp: number;
1546
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1547
+ error: string;
1548
+ error_code: string;
1549
+ retry_id: string;
1550
+ category: "transport" | "output" | "rate_limit" | "other";
1551
+ attempt: number;
1552
+ max_retries: number;
1553
+ total_attempts: number;
1554
+ started_at: number;
1555
+ delay_ms: number;
1556
+ next_retry_at?: number | undefined;
1493
1557
  } | {
1494
1558
  type: "error";
1495
1559
  id: string;
1496
1560
  timestamp: number;
1497
1561
  error: string;
1498
1562
  error_code?: string | undefined;
1499
- details?: Record<string, unknown> | undefined;
1563
+ retry_id?: string | undefined;
1500
1564
  retryable?: boolean | undefined;
1565
+ details?: Record<string, unknown> | undefined;
1501
1566
  } | {
1502
1567
  type: "stream_chunk";
1503
1568
  id: string;
@@ -1712,14 +1777,30 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1712
1777
  }[] | undefined;
1713
1778
  })[] | undefined;
1714
1779
  meta?: Record<string, unknown> | undefined;
1780
+ } | {
1781
+ type: "llm_retry";
1782
+ id: string;
1783
+ timestamp: number;
1784
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1785
+ error: string;
1786
+ error_code: string;
1787
+ retry_id: string;
1788
+ category: "transport" | "output" | "rate_limit" | "other";
1789
+ attempt: number;
1790
+ max_retries: number;
1791
+ total_attempts: number;
1792
+ started_at: number;
1793
+ delay_ms: number;
1794
+ next_retry_at?: number | undefined;
1715
1795
  } | {
1716
1796
  type: "error";
1717
1797
  id: string;
1718
1798
  timestamp: number;
1719
1799
  error: string;
1720
1800
  error_code?: string | undefined;
1721
- details?: Record<string, unknown> | undefined;
1801
+ retry_id?: string | undefined;
1722
1802
  retryable?: boolean | undefined;
1803
+ details?: Record<string, unknown> | undefined;
1723
1804
  } | {
1724
1805
  type: "stream_chunk";
1725
1806
  id: string;
@@ -1157,8 +1157,55 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1157
1157
  }>, z.ZodObject<{
1158
1158
  timestamp: z.ZodNumber;
1159
1159
  id: z.ZodEffects<z.ZodString, string, string>;
1160
+ } & {
1161
+ retry_id: z.ZodEffects<z.ZodString, string, string>;
1162
+ status: z.ZodEnum<["waiting", "retrying", "succeeded", "exhausted", "failed", "cancelled"]>;
1163
+ category: z.ZodEnum<["transport", "output", "rate_limit", "other"]>;
1164
+ attempt: z.ZodNumber;
1165
+ max_retries: z.ZodNumber;
1166
+ total_attempts: z.ZodNumber;
1167
+ started_at: z.ZodNumber;
1168
+ delay_ms: z.ZodNumber;
1169
+ next_retry_at: z.ZodOptional<z.ZodNumber>;
1170
+ error: z.ZodString;
1171
+ error_code: z.ZodString;
1172
+ type: z.ZodLiteral<"llm_retry">;
1173
+ }, "strict", z.ZodTypeAny, {
1174
+ type: "llm_retry";
1175
+ id: string;
1176
+ timestamp: number;
1177
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1178
+ error: string;
1179
+ error_code: string;
1180
+ retry_id: string;
1181
+ category: "transport" | "output" | "rate_limit" | "other";
1182
+ attempt: number;
1183
+ max_retries: number;
1184
+ total_attempts: number;
1185
+ started_at: number;
1186
+ delay_ms: number;
1187
+ next_retry_at?: number | undefined;
1188
+ }, {
1189
+ type: "llm_retry";
1190
+ id: string;
1191
+ timestamp: number;
1192
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1193
+ error: string;
1194
+ error_code: string;
1195
+ retry_id: string;
1196
+ category: "transport" | "output" | "rate_limit" | "other";
1197
+ attempt: number;
1198
+ max_retries: number;
1199
+ total_attempts: number;
1200
+ started_at: number;
1201
+ delay_ms: number;
1202
+ next_retry_at?: number | undefined;
1203
+ }>, z.ZodObject<{
1204
+ timestamp: z.ZodNumber;
1205
+ id: z.ZodEffects<z.ZodString, string, string>;
1160
1206
  } & {
1161
1207
  type: z.ZodLiteral<"error">;
1208
+ retry_id: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
1162
1209
  error: z.ZodString;
1163
1210
  error_code: z.ZodOptional<z.ZodString>;
1164
1211
  retryable: z.ZodOptional<z.ZodBoolean>;
@@ -1169,16 +1216,18 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1169
1216
  timestamp: number;
1170
1217
  error: string;
1171
1218
  error_code?: string | undefined;
1172
- details?: Record<string, unknown> | undefined;
1219
+ retry_id?: string | undefined;
1173
1220
  retryable?: boolean | undefined;
1221
+ details?: Record<string, unknown> | undefined;
1174
1222
  }, {
1175
1223
  type: "error";
1176
1224
  id: string;
1177
1225
  timestamp: number;
1178
1226
  error: string;
1179
1227
  error_code?: string | undefined;
1180
- details?: Record<string, unknown> | undefined;
1228
+ retry_id?: string | undefined;
1181
1229
  retryable?: boolean | undefined;
1230
+ details?: Record<string, unknown> | undefined;
1182
1231
  }>, z.ZodObject<{
1183
1232
  timestamp: z.ZodNumber;
1184
1233
  id: z.ZodEffects<z.ZodString, string, string>;
@@ -1490,14 +1539,30 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1490
1539
  }[] | undefined;
1491
1540
  })[] | undefined;
1492
1541
  meta?: Record<string, unknown> | undefined;
1542
+ } | {
1543
+ type: "llm_retry";
1544
+ id: string;
1545
+ timestamp: number;
1546
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1547
+ error: string;
1548
+ error_code: string;
1549
+ retry_id: string;
1550
+ category: "transport" | "output" | "rate_limit" | "other";
1551
+ attempt: number;
1552
+ max_retries: number;
1553
+ total_attempts: number;
1554
+ started_at: number;
1555
+ delay_ms: number;
1556
+ next_retry_at?: number | undefined;
1493
1557
  } | {
1494
1558
  type: "error";
1495
1559
  id: string;
1496
1560
  timestamp: number;
1497
1561
  error: string;
1498
1562
  error_code?: string | undefined;
1499
- details?: Record<string, unknown> | undefined;
1563
+ retry_id?: string | undefined;
1500
1564
  retryable?: boolean | undefined;
1565
+ details?: Record<string, unknown> | undefined;
1501
1566
  } | {
1502
1567
  type: "stream_chunk";
1503
1568
  id: string;
@@ -1712,14 +1777,30 @@ declare const AgentEventSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.
1712
1777
  }[] | undefined;
1713
1778
  })[] | undefined;
1714
1779
  meta?: Record<string, unknown> | undefined;
1780
+ } | {
1781
+ type: "llm_retry";
1782
+ id: string;
1783
+ timestamp: number;
1784
+ status: "waiting" | "retrying" | "succeeded" | "exhausted" | "failed" | "cancelled";
1785
+ error: string;
1786
+ error_code: string;
1787
+ retry_id: string;
1788
+ category: "transport" | "output" | "rate_limit" | "other";
1789
+ attempt: number;
1790
+ max_retries: number;
1791
+ total_attempts: number;
1792
+ started_at: number;
1793
+ delay_ms: number;
1794
+ next_retry_at?: number | undefined;
1715
1795
  } | {
1716
1796
  type: "error";
1717
1797
  id: string;
1718
1798
  timestamp: number;
1719
1799
  error: string;
1720
1800
  error_code?: string | undefined;
1721
- details?: Record<string, unknown> | undefined;
1801
+ retry_id?: string | undefined;
1722
1802
  retryable?: boolean | undefined;
1803
+ details?: Record<string, unknown> | undefined;
1723
1804
  } | {
1724
1805
  type: "stream_chunk";
1725
1806
  id: string;
@@ -1,6 +1,6 @@
1
1
  import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.cjs';
2
2
 
3
- type RuntimeEventUiProjectionKind = 'hidden' | 'user_input' | 'thought' | 'final_answer' | 'final_answer_chunk' | 'final_answer_reset' | 'tool_call_decision' | 'tool_process' | 'tool_output' | 'requires_user_interaction' | 'audit_envelope' | 'subrun_trace' | 'error' | 'context_usage_snapshot' | 'run_execution_metrics' | 'history_summary' | 'unsupported';
3
+ type RuntimeEventUiProjectionKind = 'hidden' | 'user_input' | 'thought' | 'final_answer' | 'final_answer_chunk' | 'final_answer_reset' | 'tool_call_decision' | 'tool_process' | 'tool_output' | 'requires_user_interaction' | 'audit_envelope' | 'subrun_trace' | 'llm_retry' | 'error' | 'context_usage_snapshot' | 'run_execution_metrics' | 'history_summary' | 'unsupported';
4
4
  type RuntimeEventRealtimeChannel = 'event_bus_sse' | 'none';
5
5
  interface RuntimeEventLifecycleDecision {
6
6
  uiProjectionKind: RuntimeEventUiProjectionKind;
@@ -1,6 +1,6 @@
1
1
  import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.js';
2
2
 
3
- type RuntimeEventUiProjectionKind = 'hidden' | 'user_input' | 'thought' | 'final_answer' | 'final_answer_chunk' | 'final_answer_reset' | 'tool_call_decision' | 'tool_process' | 'tool_output' | 'requires_user_interaction' | 'audit_envelope' | 'subrun_trace' | 'error' | 'context_usage_snapshot' | 'run_execution_metrics' | 'history_summary' | 'unsupported';
3
+ type RuntimeEventUiProjectionKind = 'hidden' | 'user_input' | 'thought' | 'final_answer' | 'final_answer_chunk' | 'final_answer_reset' | 'tool_call_decision' | 'tool_process' | 'tool_output' | 'requires_user_interaction' | 'audit_envelope' | 'subrun_trace' | 'llm_retry' | 'error' | 'context_usage_snapshot' | 'run_execution_metrics' | 'history_summary' | 'unsupported';
4
4
  type RuntimeEventRealtimeChannel = 'event_bus_sse' | 'none';
5
5
  interface RuntimeEventLifecycleDecision {
6
6
  uiProjectionKind: RuntimeEventUiProjectionKind;
@@ -533,6 +533,28 @@ var AuditEnvelope = zod.z.object({
533
533
  costDelta: AuditCostDelta.optional(),
534
534
  scope: AuditScope.optional()
535
535
  });
536
+ var LlmRetryCategory = zod.z.enum(["transport", "output", "rate_limit", "other"]);
537
+ var LlmRetryState = zod.z.object({
538
+ retry_id: TraceIdSchema,
539
+ status: zod.z.enum(["waiting", "retrying", "succeeded", "exhausted", "failed", "cancelled"]),
540
+ category: LlmRetryCategory,
541
+ attempt: zod.z.number().int().nonnegative(),
542
+ max_retries: zod.z.number().int().nonnegative(),
543
+ total_attempts: zod.z.number().int().positive(),
544
+ started_at: zod.z.number().finite(),
545
+ delay_ms: zod.z.number().finite().nonnegative(),
546
+ next_retry_at: zod.z.number().finite().optional(),
547
+ /** 安全分类说明;不得放入供应商响应正文。 */
548
+ error: zod.z.string(),
549
+ error_code: zod.z.string().min(1)
550
+ }).strict();
551
+ var RuntimeErrorState = zod.z.object({
552
+ error: zod.z.string(),
553
+ error_code: zod.z.string().optional(),
554
+ retryable: zod.z.boolean().optional(),
555
+ retry_id: TraceIdSchema.optional(),
556
+ details: SerializableJsonValue.optional()
557
+ }).strict();
536
558
  var ToolCallPhase = zod.z.enum(["start", "update", "complete", "error"]);
537
559
  var Status = zod.z.enum(["loading", "success", "error"]);
538
560
  var SubRunTraceKind = zod.z.enum([
@@ -543,7 +565,9 @@ var SubRunTraceKind = zod.z.enum([
543
565
  "tool_output",
544
566
  "final_answer_chunk",
545
567
  "final_answer",
546
- "history_summary"
568
+ "history_summary",
569
+ "llm_retry",
570
+ "error"
547
571
  ]);
548
572
  var SubRunTraceToolCallDecision = zod.z.object({
549
573
  tool_call_id: ToolCallIdSchema,
@@ -556,6 +580,8 @@ var SubRunTracePayload = zod.z.object({
556
580
  subrun_parent_id: SubrunIdSchema.optional(),
557
581
  source_event_id: SourceEventIdSchema,
558
582
  kind: SubRunTraceKind,
583
+ retry: LlmRetryState.optional(),
584
+ failure: RuntimeErrorState.optional(),
559
585
  delta: zod.z.string().optional(),
560
586
  content: zod.z.string().optional(),
561
587
  answer_id: AnswerSegmentIdSchema.optional(),
@@ -578,6 +604,12 @@ var SubRunTracePayload = zod.z.object({
578
604
  meta: SerializableJsonRecord.optional()
579
605
  });
580
606
  function validateSubRunTracePayloadSemantics(payload, ctx) {
607
+ if (payload.kind === "llm_retry" !== (payload.retry !== void 0)) {
608
+ ctx.addIssue({ code: zod.z.ZodIssueCode.custom, path: ["retry"], message: "retry is required only for llm_retry trace" });
609
+ }
610
+ if (payload.kind === "error" !== (payload.failure !== void 0)) {
611
+ ctx.addIssue({ code: zod.z.ZodIssueCode.custom, path: ["failure"], message: "failure is required only for error trace" });
612
+ }
581
613
  if (payload.kind === "thought_delta" && payload.delta === void 0) {
582
614
  ctx.addIssue({ code: zod.z.ZodIssueCode.custom, path: ["delta"], message: "thought_delta requires delta" });
583
615
  }
@@ -931,12 +963,10 @@ var RuntimeEventShape = zod.z.discriminatedUnion("type", [
931
963
  compression_ratio: zod.z.number().min(0).max(1).optional(),
932
964
  included_old_summary: zod.z.boolean().optional()
933
965
  }),
966
+ BaseEvent.extend({ type: zod.z.literal("llm_retry"), ...LlmRetryState.shape }),
934
967
  BaseEvent.extend({
935
968
  type: zod.z.literal("error"),
936
- error: zod.z.string(),
937
- details: SerializableJsonValue.optional(),
938
- error_code: zod.z.string().optional(),
939
- retryable: zod.z.boolean().optional()
969
+ ...RuntimeErrorState.shape
940
970
  }),
941
971
  BaseEvent.extend({
942
972
  type: zod.z.literal("control"),
@@ -1299,12 +1329,13 @@ var SSERequiresUserInteractionEvent = BaseSSEEvent.extend({
1299
1329
  resume_token: ResumeTokenSchema,
1300
1330
  interaction_status: zod.z.literal("pending")
1301
1331
  });
1332
+ var SSELlmRetryEvent = BaseSSEEvent.extend({
1333
+ type: zod.z.literal("llm_retry"),
1334
+ ...LlmRetryState.shape
1335
+ });
1302
1336
  var SSEErrorEvent = BaseSSEEvent.extend({
1303
1337
  type: zod.z.literal("error"),
1304
- error: zod.z.string(),
1305
- details: SerializableJsonValue.optional(),
1306
- error_code: zod.z.string().optional(),
1307
- retryable: zod.z.boolean().optional()
1338
+ ...RuntimeErrorState.shape
1308
1339
  });
1309
1340
  var SSETransportErrorEvent = BaseSSEEvent.extend({
1310
1341
  type: zod.z.literal("transport_error"),
@@ -1387,6 +1418,7 @@ zod.z.discriminatedUnion("type", [
1387
1418
  SSEToolOutputEvent,
1388
1419
  SSESubRunTraceEvent,
1389
1420
  SSERequiresUserInteractionEvent,
1421
+ SSELlmRetryEvent,
1390
1422
  SSEErrorEvent,
1391
1423
  SSETransportErrorEvent,
1392
1424
  SSEContextUsageSnapshotEvent,
@@ -1680,8 +1712,13 @@ var FinalAnswerEventSchema = BaseAgentEvent.extend({
1680
1712
  assistant_replay_parts: AssistantReplayParts.optional(),
1681
1713
  meta: UnknownRecord.optional()
1682
1714
  }).strict();
1715
+ var LlmRetryEventSchema = BaseAgentEvent.extend({
1716
+ type: zod.z.literal("llm_retry"),
1717
+ ...LlmRetryState.shape
1718
+ }).strict();
1683
1719
  var ErrorEventSchema = BaseAgentEvent.extend({
1684
1720
  type: zod.z.literal("error"),
1721
+ retry_id: LlmRetryState.shape.retry_id.optional(),
1685
1722
  error: zod.z.string(),
1686
1723
  error_code: zod.z.string().optional(),
1687
1724
  retryable: zod.z.boolean().optional(),
@@ -1711,6 +1748,7 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
1711
1748
  ToolProcessEventSchema,
1712
1749
  ObservationEventSchema,
1713
1750
  FinalAnswerEventSchema,
1751
+ LlmRetryEventSchema,
1714
1752
  ErrorEventSchema,
1715
1753
  StreamChunkEventSchema,
1716
1754
  StreamResetEventSchema,
@@ -1811,13 +1849,16 @@ function mapAgentEventToRuntime(agentEvent, context, options) {
1811
1849
  if (contextMeta) event.metadata = { ...event.metadata ?? {}, ...contextMeta };
1812
1850
  return event;
1813
1851
  }
1852
+ case "llm_retry":
1853
+ return { ...typed, conversation_id: conversationId, turn_id: turnId, version: 1, ephemeral: false, ...contextMeta ? { metadata: contextMeta } : {} };
1814
1854
  case "error": {
1815
1855
  const errorEvent = typed;
1816
1856
  const event = createErrorEvent(id, conversationId, turnId, errorEvent.error, {
1817
1857
  timestamp,
1818
1858
  details: toSerializableJsonValue(errorEvent.details),
1819
1859
  error_code: errorEvent.error_code,
1820
- retryable: errorEvent.retryable
1860
+ retryable: errorEvent.retryable,
1861
+ retry_id: errorEvent.retry_id
1821
1862
  });
1822
1863
  if (contextMeta) event.metadata = { ...event.metadata ?? {}, ...contextMeta };
1823
1864
  return event;
@@ -2178,6 +2219,8 @@ function getRuntimeEventUiProjectionKind(event) {
2178
2219
  return "audit_envelope";
2179
2220
  case "subrun_trace":
2180
2221
  return "subrun_trace";
2222
+ case "llm_retry":
2223
+ return "llm_retry";
2181
2224
  case "error":
2182
2225
  return "error";
2183
2226
  case "context_usage_snapshot":
@@ -2207,7 +2250,7 @@ function describeRuntimeEventLifecycle(event) {
2207
2250
  if (isContextUsageSnapshotRuntimeEvent(event)) {
2208
2251
  return false;
2209
2252
  }
2210
- if (event.type === "error") {
2253
+ if (event.type === "error" || event.type === "llm_retry") {
2211
2254
  return false;
2212
2255
  }
2213
2256
  if (isRequiresUserInteractionRuntimeEvent(event)) {
@@ -2250,6 +2293,7 @@ function describeRuntimeEventLifecycle(event) {
2250
2293
  case "tool_output":
2251
2294
  case "requires_user_interaction":
2252
2295
  case "subrun_trace":
2296
+ case "llm_retry":
2253
2297
  case "error":
2254
2298
  case "context_usage_snapshot":
2255
2299
  case "run_execution_metrics":