@sentry/junior 0.105.0 → 0.107.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 (133) hide show
  1. package/dist/{agent-hooks-EOFSY2PD.js → agent-hooks-ICPIJAFY.js} +9 -7
  2. package/dist/api/conversations/detail.d.ts +1 -1
  3. package/dist/api/conversations/events.d.ts +14 -0
  4. package/dist/api/conversations/schema.d.ts +196 -463
  5. package/dist/api/schema.d.ts +2 -7
  6. package/dist/api/schema.js +10 -8
  7. package/dist/api.js +377 -810
  8. package/dist/app.js +2284 -2288
  9. package/dist/{catalog-runtime-5CVM2DOF.js → catalog-runtime-FOFNPR3P.js} +3 -2
  10. package/dist/chat/agent/prompt.d.ts +1 -1
  11. package/dist/chat/agent/request.d.ts +28 -29
  12. package/dist/chat/agent/resume.d.ts +7 -7
  13. package/dist/chat/agent/session.d.ts +5 -6
  14. package/dist/chat/agent/tools.d.ts +3 -3
  15. package/dist/chat/agent-dispatch/runner.d.ts +2 -0
  16. package/dist/chat/config.d.ts +3 -2
  17. package/dist/chat/conversations/history.d.ts +582 -167
  18. package/dist/chat/conversations/message-projection.d.ts +6 -0
  19. package/dist/chat/conversations/message-summaries.d.ts +9 -0
  20. package/dist/chat/conversations/messages.d.ts +13 -27
  21. package/dist/chat/conversations/projection.d.ts +30 -53
  22. package/dist/chat/conversations/provenance.d.ts +42 -0
  23. package/dist/chat/conversations/search.d.ts +2 -2
  24. package/dist/chat/conversations/sql/conversation-row.d.ts +1 -1
  25. package/dist/chat/conversations/sql/event-lock.d.ts +3 -0
  26. package/dist/chat/conversations/sql/history.d.ts +3 -3
  27. package/dist/chat/conversations/sql/privacy.d.ts +27 -0
  28. package/dist/chat/conversations/sql/purge.d.ts +2 -10
  29. package/dist/chat/conversations/sql/store.d.ts +0 -5
  30. package/dist/chat/conversations/store.d.ts +8 -13
  31. package/dist/chat/conversations/turn-lifecycle.d.ts +41 -0
  32. package/dist/chat/db.d.ts +4 -10
  33. package/dist/chat/model-profile.d.ts +10 -0
  34. package/dist/chat/oauth-flow.d.ts +0 -5
  35. package/dist/chat/pi/conversation-events.d.ts +33 -0
  36. package/dist/chat/pi/sql-model-usage.d.ts +10 -0
  37. package/dist/chat/plugins/agent-hooks.d.ts +4 -2
  38. package/dist/chat/resource-events/ingest.d.ts +0 -13
  39. package/dist/chat/runtime/delivered-turn-state.d.ts +1 -1
  40. package/dist/chat/runtime/generated-artifacts.d.ts +1 -1
  41. package/dist/chat/runtime/reply-executor.d.ts +2 -0
  42. package/dist/chat/runtime/slack-resume.d.ts +23 -28
  43. package/dist/chat/runtime/slack-runtime.d.ts +2 -0
  44. package/dist/chat/runtime/turn.d.ts +14 -1
  45. package/dist/chat/services/context-compaction-marker.d.ts +0 -1
  46. package/dist/chat/services/context-compaction.d.ts +1 -0
  47. package/dist/chat/services/conversation-memory.d.ts +9 -0
  48. package/dist/chat/services/plugin-auth-orchestration.d.ts +1 -4
  49. package/dist/chat/services/subscribed-decision.d.ts +1 -1
  50. package/dist/chat/services/turn-failure-response.d.ts +10 -3
  51. package/dist/chat/services/turn-limit.d.ts +6 -0
  52. package/dist/chat/services/turn-result.d.ts +7 -12
  53. package/dist/chat/services/{turn-reasoning-level.d.ts → turn-router.d.ts} +12 -8
  54. package/dist/chat/services/turn-session-record.d.ts +15 -17
  55. package/dist/chat/slack/adapter.d.ts +2 -2
  56. package/dist/chat/slack/errors.d.ts +2 -0
  57. package/dist/chat/slack/outbound.d.ts +0 -1
  58. package/dist/chat/slack/reply.d.ts +2 -8
  59. package/dist/chat/slack/tools/channel-capabilities.d.ts +2 -2
  60. package/dist/chat/slack/tools/{send-message.d.ts → send-files.d.ts} +27 -19
  61. package/dist/chat/state/conversation.d.ts +4 -4
  62. package/dist/chat/state/turn-id.d.ts +2 -0
  63. package/dist/chat/state/turn-session-keys.d.ts +6 -0
  64. package/dist/chat/state/turn-session.d.ts +11 -9
  65. package/dist/chat/task-execution/state.d.ts +6 -1
  66. package/dist/chat/task-execution/store.d.ts +1 -1
  67. package/dist/chat/tool-support/pi-tool-adapter.d.ts +1 -1
  68. package/dist/chat/tool-support/tool-execution-report.d.ts +1 -0
  69. package/dist/chat/tools/handoff/tool.d.ts +2 -2
  70. package/dist/chat/tools/sandbox/file-uploads.d.ts +28 -6
  71. package/dist/chat/tools/types.d.ts +6 -9
  72. package/dist/chat/tools/web/image-generate.d.ts +4 -6
  73. package/dist/{chunk-QDKRE3LS.js → chunk-4YF7Z6IA.js} +390 -270
  74. package/dist/{chunk-4PDVOHXP.js → chunk-AUUOHQAT.js} +2 -2
  75. package/dist/chunk-B2Z2H66D.js +250 -0
  76. package/dist/{chunk-QVTVCJR4.js → chunk-CQ7KSO2B.js} +75 -45
  77. package/dist/{chunk-MJSJAHBW.js → chunk-DY7TRYB5.js} +1 -1
  78. package/dist/{chunk-NJJFU6CP.js → chunk-EDLNHZH3.js} +883 -898
  79. package/dist/{chunk-O7ILGCMJ.js → chunk-IGHMVDWI.js} +134 -18
  80. package/dist/chunk-MU6HHZEN.js +99 -0
  81. package/dist/{chunk-BCULHGZK.js → chunk-NVOTGWYX.js} +458 -684
  82. package/dist/{chunk-AEWZ7F65.js → chunk-O24R4DCK.js} +2 -179
  83. package/dist/{chunk-CCFROYAV.js → chunk-PUAMO4PI.js} +115 -125
  84. package/dist/{chunk-VDHMFCDY.js → chunk-RMVOAJRL.js} +30 -13
  85. package/dist/{chunk-7G4J3CR7.js → chunk-SPUAJVVH.js} +6 -4
  86. package/dist/{chunk-M3UAVLEN.js → chunk-SS67LUOK.js} +43 -290
  87. package/dist/{chunk-FXFQNHRU.js → chunk-VFUK3X5B.js} +4 -2
  88. package/dist/{chunk-CCTCIISK.js → chunk-VH6KWKG2.js} +2 -2
  89. package/dist/chunk-VIXFG2VC.js +182 -0
  90. package/dist/{chunk-RMZ65YAA.js → chunk-YFQ7CQDE.js} +687 -21
  91. package/dist/{chunk-77LHNQK4.js → chunk-YIPD3L6L.js} +4 -2
  92. package/dist/{chunk-U26ZWZCN.js → chunk-YNP2ATQX.js} +6 -4
  93. package/dist/{chunk-WR7H7VLJ.js → chunk-YT72TOEK.js} +2 -2
  94. package/dist/cli/chat.js +21 -20
  95. package/dist/cli/check.js +4 -3
  96. package/dist/cli/plugins.js +11 -9
  97. package/dist/cli/snapshot-warmup.js +7 -5
  98. package/dist/cli/upgrade.js +2046 -105
  99. package/dist/db/schema/{agent-steps.d.ts → conversation-events.d.ts} +37 -21
  100. package/dist/db/schema.d.ts +28 -159
  101. package/dist/{db-PDMC67T3.js → db-DIGO4TGW.js} +6 -8
  102. package/dist/{runner-6A7MQRUE.js → runner-ACR2HAIC.js} +209 -101
  103. package/dist/{skills-722AXRV5.js → skills-ITNHBARB.js} +4 -3
  104. package/dist/{validation-EUI2UFRM.js → validation-AGQ46ZGV.js} +4 -3
  105. package/migrations/0005_conversation_events.sql +122 -0
  106. package/migrations/README.md +23 -10
  107. package/migrations/meta/0005_snapshot.json +948 -0
  108. package/migrations/meta/_journal.json +7 -0
  109. package/package.json +6 -6
  110. package/dist/api/conversations/activity.d.ts +0 -40
  111. package/dist/api/conversations/detail-projection.d.ts +0 -11
  112. package/dist/api/conversations/detail.query.d.ts +0 -3
  113. package/dist/api/conversations/subagent.d.ts +0 -10
  114. package/dist/api/conversations/transcript.d.ts +0 -28
  115. package/dist/chat/conversations/legacy-advisor-session.d.ts +0 -7
  116. package/dist/chat/conversations/legacy-import.d.ts +0 -38
  117. package/dist/chat/conversations/sql/legacy-history-import.d.ts +0 -55
  118. package/dist/chat/conversations/sql/messages.d.ts +0 -4
  119. package/dist/chat/conversations/visible-compactions.d.ts +0 -11
  120. package/dist/chat/conversations/visible-messages.d.ts +0 -47
  121. package/dist/chat/services/reply-delivery-plan.d.ts +0 -5
  122. package/dist/chat/state/session-log.d.ts +0 -384
  123. package/dist/chunk-RYDF4GOX.js +0 -1072
  124. package/dist/chunk-XIMUQ4IU.js +0 -147
  125. package/dist/db/schema/conversation-messages.d.ts +0 -153
  126. package/dist/handlers/github-webhook/check-suite.d.ts +0 -3
  127. package/dist/handlers/github-webhook/issue-comment.d.ts +0 -3
  128. package/dist/handlers/github-webhook/pull-request-review-comment.d.ts +0 -3
  129. package/dist/handlers/github-webhook/pull-request-review.d.ts +0 -3
  130. package/dist/handlers/github-webhook/pull-request.d.ts +0 -3
  131. package/dist/handlers/github-webhook/resource.d.ts +0 -10
  132. package/dist/handlers/github-webhook.d.ts +0 -15
  133. package/dist/legacy-import-G333RHJZ.js +0 -18
@@ -1,23 +1,145 @@
1
1
  /**
2
- * Durable agent execution history port.
2
+ * Durable conversation event history port.
3
3
  *
4
- * Steps are appended one row at a time under the conversation lease; context
5
- * rebuilds (compaction, handoff, rollback) open a new context epoch instead of
6
- * rewriting history. Each new epoch binds the model profile that owns it and
7
- * records the exact resolved model id for audit.
8
- * The step envelope is strictly validated an unknown type or malformed shape
9
- * is corrupt state and fails loudly — while `pi_message` content stays
10
- * permissive because the Pi SDK owns the message shape.
4
+ * Events append under the conversation lease in stable sequence order.
5
+ * Compaction and handoff replace the active model history without rewriting
6
+ * prior events. Unsupported stored events remain readable as opaque facts,
7
+ * while malformed known events fail loudly. Provider-specific message fields
8
+ * are validated by the Pi adapter when it restores model context.
11
9
  */
12
10
  import { z } from "zod";
13
- declare const piMessageStepSchema: z.ZodObject<{
11
+ /** Store one opaque agent-step payload while Pi owns provider validation. */
12
+ export declare const conversationAgentStepPayloadSchema: z.ZodPipe<z.ZodObject<{
13
+ role: z.ZodString;
14
+ }, z.core.$loose>, z.ZodTransform<{
15
+ role: string;
16
+ }, {
17
+ [x: string]: unknown;
18
+ role: string;
19
+ }>>;
20
+ /** The opaque Pi history entry carried by an `agent_step` event. */
21
+ export type ConversationAgentStepPayload = z.output<typeof conversationAgentStepPayloadSchema>;
22
+ /** Validate an event that intentionally replaces active model history. */
23
+ export declare const historyReplacementSchema: z.ZodObject<{
24
+ data: z.ZodDiscriminatedUnion<[z.ZodObject<{
25
+ type: z.ZodLiteral<"handoff">;
26
+ modelProfile: z.ZodString;
27
+ modelId: z.ZodString;
28
+ triggeringToolCallId: z.ZodOptional<z.ZodString>;
29
+ replacementHistory: z.ZodArray<z.ZodObject<{
30
+ message: z.ZodPipe<z.ZodObject<{
31
+ role: z.ZodString;
32
+ }, z.core.$loose>, z.ZodTransform<{
33
+ role: string;
34
+ }, {
35
+ [x: string]: unknown;
36
+ role: string;
37
+ }>>;
38
+ provenance: z.ZodOptional<z.ZodObject<{
39
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
40
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
41
+ platform: z.ZodLiteral<"slack">;
42
+ teamId: z.ZodString;
43
+ email: z.ZodOptional<z.ZodString>;
44
+ fullName: z.ZodOptional<z.ZodString>;
45
+ userId: z.ZodString;
46
+ userName: z.ZodOptional<z.ZodString>;
47
+ }, z.core.$strict>, z.ZodObject<{
48
+ platform: z.ZodLiteral<"local">;
49
+ email: z.ZodOptional<z.ZodString>;
50
+ fullName: z.ZodOptional<z.ZodString>;
51
+ userId: z.ZodString;
52
+ userName: z.ZodOptional<z.ZodString>;
53
+ }, z.core.$strict>, z.ZodObject<{
54
+ platform: z.ZodLiteral<"system">;
55
+ name: z.ZodString;
56
+ }, z.core.$strict>], "platform">>;
57
+ }, z.core.$strict>>;
58
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
59
+ }, z.core.$strict>>;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ type: z.ZodLiteral<"compaction">;
62
+ modelProfile: z.ZodString;
63
+ modelId: z.ZodString;
64
+ replacementHistory: z.ZodArray<z.ZodObject<{
65
+ message: z.ZodPipe<z.ZodObject<{
66
+ role: z.ZodString;
67
+ }, z.core.$loose>, z.ZodTransform<{
68
+ role: string;
69
+ }, {
70
+ [x: string]: unknown;
71
+ role: string;
72
+ }>>;
73
+ provenance: z.ZodOptional<z.ZodObject<{
74
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
75
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
76
+ platform: z.ZodLiteral<"slack">;
77
+ teamId: z.ZodString;
78
+ email: z.ZodOptional<z.ZodString>;
79
+ fullName: z.ZodOptional<z.ZodString>;
80
+ userId: z.ZodString;
81
+ userName: z.ZodOptional<z.ZodString>;
82
+ }, z.core.$strict>, z.ZodObject<{
83
+ platform: z.ZodLiteral<"local">;
84
+ email: z.ZodOptional<z.ZodString>;
85
+ fullName: z.ZodOptional<z.ZodString>;
86
+ userId: z.ZodString;
87
+ userName: z.ZodOptional<z.ZodString>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ platform: z.ZodLiteral<"system">;
90
+ name: z.ZodString;
91
+ }, z.core.$strict>], "platform">>;
92
+ }, z.core.$strict>>;
93
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
94
+ }, z.core.$strict>>;
95
+ }, z.core.$strict>], "type">;
96
+ createdAtMs: z.ZodNumber;
97
+ }, z.core.$strict>;
98
+ /** One atomically persisted model-history replacement. */
99
+ export type HistoryReplacement = z.output<typeof historyReplacementSchema>;
100
+ export declare const authorizationKindSchema: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
101
+ /** Provider authorization family recorded by conversation events. */
102
+ export type AuthorizationKind = z.output<typeof authorizationKindSchema>;
103
+ /** Product surface that owns a durable conversation turn. */
104
+ export declare const conversationTurnSurfaceSchema: z.ZodEnum<{
105
+ slack: "slack";
106
+ api: "api";
107
+ internal: "internal";
108
+ scheduler: "scheduler";
109
+ }>;
110
+ /** Stable, privacy-safe classification for a failed turn. */
111
+ export declare const conversationTurnFailureCodeSchema: z.ZodEnum<{
112
+ agent_run_failed: "agent_run_failed";
113
+ delivery_failed: "delivery_failed";
114
+ model_execution_failed: "model_execution_failed";
115
+ persistence_failed: "persistence_failed";
116
+ }>;
117
+ /** Failure classification persisted without raw provider or exception data. */
118
+ export type ConversationTurnFailureCode = z.output<typeof conversationTurnFailureCodeSchema>;
119
+ /** Strict event-data contract reused by the SQL row codec. */
120
+ export declare const conversationEventDataSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
121
+ type: z.ZodLiteral<"message">;
122
+ messageId: z.ZodString;
123
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
124
+ text: z.ZodString;
125
+ authorIdentityId: z.ZodOptional<z.ZodString>;
126
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
127
+ }, z.core.$strict>, z.ZodObject<{
128
+ messageId: z.ZodString;
129
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
130
+ text: z.ZodString;
131
+ authorIdentityId: z.ZodOptional<z.ZodString>;
132
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
133
+ type: z.ZodLiteral<"message_updated">;
134
+ }, z.core.$strict>, z.ZodObject<{
14
135
  message: z.ZodPipe<z.ZodObject<{
15
136
  role: z.ZodString;
16
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
137
+ }, z.core.$loose>, z.ZodTransform<{
138
+ role: string;
139
+ }, {
17
140
  [x: string]: unknown;
18
141
  role: string;
19
142
  }>>;
20
- createdAtMs: z.ZodNumber;
21
143
  provenance: z.ZodOptional<z.ZodObject<{
22
144
  authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
23
145
  actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -38,20 +160,93 @@ declare const piMessageStepSchema: z.ZodObject<{
38
160
  name: z.ZodString;
39
161
  }, z.core.$strict>], "platform">>;
40
162
  }, z.core.$strict>>;
41
- }, z.core.$strict>;
42
- /** Validate one atomically persisted context epoch. */
43
- export declare const contextEpochStartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
44
- reason: z.ZodLiteral<"initial">;
45
- modelProfile: z.ZodLiteral<"standard">;
163
+ type: z.ZodLiteral<"agent_step">;
164
+ }, z.core.$strict>, z.ZodObject<{
165
+ type: z.ZodLiteral<"mcp_provider_connected">;
166
+ provider: z.ZodString;
167
+ }, z.core.$strict>, z.ZodObject<{
168
+ type: z.ZodLiteral<"authorization_requested">;
169
+ kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
170
+ provider: z.ZodString;
171
+ actorId: z.ZodString;
172
+ authorizationId: z.ZodString;
173
+ delivery: z.ZodUnion<readonly [z.ZodLiteral<"private_link_sent">, z.ZodLiteral<"private_link_reused">]>;
174
+ }, z.core.$strict>, z.ZodObject<{
175
+ type: z.ZodLiteral<"authorization_completed">;
176
+ kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
177
+ provider: z.ZodString;
178
+ actorId: z.ZodString;
179
+ authorizationId: z.ZodString;
180
+ }, z.core.$strict>, z.ZodObject<{
181
+ type: z.ZodLiteral<"tool_execution_started">;
182
+ toolCallId: z.ZodString;
183
+ toolName: z.ZodString;
184
+ }, z.core.$strict>, z.ZodObject<{
185
+ type: z.ZodLiteral<"message_handled">;
186
+ messageId: z.ZodString;
187
+ }, z.core.$strict>, z.ZodObject<{
188
+ type: z.ZodLiteral<"messages_summarized">;
189
+ historyFromSeq: z.ZodNumber;
190
+ compactions: z.ZodArray<z.ZodObject<{
191
+ coveredMessageCount: z.ZodNumber;
192
+ createdAtMs: z.ZodNumber;
193
+ id: z.ZodString;
194
+ summary: z.ZodString;
195
+ }, z.core.$strict>>;
196
+ }, z.core.$strict>, z.ZodObject<{
197
+ type: z.ZodLiteral<"turn_started">;
198
+ turnId: z.ZodString;
199
+ inputMessageIds: z.ZodArray<z.ZodString>;
200
+ surface: z.ZodEnum<{
201
+ slack: "slack";
202
+ api: "api";
203
+ internal: "internal";
204
+ scheduler: "scheduler";
205
+ }>;
206
+ }, z.core.$strict>, z.ZodObject<{
207
+ type: z.ZodLiteral<"turn_completed">;
208
+ turnId: z.ZodString;
209
+ outcome: z.ZodEnum<{
210
+ success: "success";
211
+ no_reply: "no_reply";
212
+ }>;
213
+ }, z.core.$strict>, z.ZodObject<{
214
+ type: z.ZodLiteral<"turn_failed">;
215
+ turnId: z.ZodString;
216
+ failureCode: z.ZodEnum<{
217
+ agent_run_failed: "agent_run_failed";
218
+ delivery_failed: "delivery_failed";
219
+ model_execution_failed: "model_execution_failed";
220
+ persistence_failed: "persistence_failed";
221
+ }>;
222
+ eventId: z.ZodOptional<z.ZodString>;
223
+ }, z.core.$strict>, z.ZodObject<{
224
+ type: z.ZodLiteral<"subagent_started">;
225
+ subagentInvocationId: z.ZodString;
226
+ subagentKind: z.ZodString;
227
+ modelId: z.ZodOptional<z.ZodString>;
228
+ parentToolCallId: z.ZodOptional<z.ZodString>;
229
+ reasoningLevel: z.ZodOptional<z.ZodString>;
230
+ childConversationId: z.ZodString;
231
+ }, z.core.$strict>, z.ZodObject<{
232
+ type: z.ZodLiteral<"subagent_ended">;
233
+ subagentInvocationId: z.ZodString;
234
+ outcome: z.ZodUnion<readonly [z.ZodLiteral<"success">, z.ZodLiteral<"error">, z.ZodLiteral<"aborted">]>;
235
+ errorCode: z.ZodOptional<z.ZodString>;
236
+ }, z.core.$strict>]>, z.ZodDiscriminatedUnion<[z.ZodObject<{
237
+ type: z.ZodLiteral<"handoff">;
238
+ modelProfile: z.ZodString;
46
239
  modelId: z.ZodString;
47
- messages: z.ZodArray<z.ZodObject<{
240
+ triggeringToolCallId: z.ZodOptional<z.ZodString>;
241
+ replacementHistory: z.ZodArray<z.ZodObject<{
48
242
  message: z.ZodPipe<z.ZodObject<{
49
243
  role: z.ZodString;
50
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
244
+ }, z.core.$loose>, z.ZodTransform<{
245
+ role: string;
246
+ }, {
51
247
  [x: string]: unknown;
52
248
  role: string;
53
249
  }>>;
54
- createdAtMs: z.ZodNumber;
55
250
  provenance: z.ZodOptional<z.ZodObject<{
56
251
  authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
57
252
  actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -72,19 +267,21 @@ export declare const contextEpochStartSchema: z.ZodDiscriminatedUnion<[z.ZodObje
72
267
  name: z.ZodString;
73
268
  }, z.core.$strict>], "platform">>;
74
269
  }, z.core.$strict>>;
270
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
75
271
  }, z.core.$strict>>;
76
272
  }, z.core.$strict>, z.ZodObject<{
77
- reason: z.ZodLiteral<"handoff">;
273
+ type: z.ZodLiteral<"compaction">;
78
274
  modelProfile: z.ZodString;
79
275
  modelId: z.ZodString;
80
- messages: z.ZodArray<z.ZodObject<{
276
+ replacementHistory: z.ZodArray<z.ZodObject<{
81
277
  message: z.ZodPipe<z.ZodObject<{
82
278
  role: z.ZodString;
83
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
279
+ }, z.core.$loose>, z.ZodTransform<{
280
+ role: string;
281
+ }, {
84
282
  [x: string]: unknown;
85
283
  role: string;
86
284
  }>>;
87
- createdAtMs: z.ZodNumber;
88
285
  provenance: z.ZodOptional<z.ZodObject<{
89
286
  authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
90
287
  actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -105,19 +302,21 @@ export declare const contextEpochStartSchema: z.ZodDiscriminatedUnion<[z.ZodObje
105
302
  name: z.ZodString;
106
303
  }, z.core.$strict>], "platform">>;
107
304
  }, z.core.$strict>>;
305
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
108
306
  }, z.core.$strict>>;
109
- }, z.core.$strict>, z.ZodObject<{
110
- reason: z.ZodUnion<readonly [z.ZodLiteral<"compaction">, z.ZodLiteral<"rollback">]>;
307
+ }, z.core.$strict>], "type">, z.ZodObject<{
308
+ type: z.ZodLiteral<"rollback">;
111
309
  modelProfile: z.ZodString;
112
310
  modelId: z.ZodString;
113
- messages: z.ZodArray<z.ZodObject<{
311
+ replacementHistory: z.ZodArray<z.ZodObject<{
114
312
  message: z.ZodPipe<z.ZodObject<{
115
313
  role: z.ZodString;
116
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
314
+ }, z.core.$loose>, z.ZodTransform<{
315
+ role: string;
316
+ }, {
117
317
  [x: string]: unknown;
118
318
  role: string;
119
319
  }>>;
120
- createdAtMs: z.ZodNumber;
121
320
  provenance: z.ZodOptional<z.ZodObject<{
122
321
  authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
123
322
  actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -138,121 +337,303 @@ export declare const contextEpochStartSchema: z.ZodDiscriminatedUnion<[z.ZodObje
138
337
  name: z.ZodString;
139
338
  }, z.core.$strict>], "platform">>;
140
339
  }, z.core.$strict>>;
340
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
141
341
  }, z.core.$strict>>;
142
- }, z.core.$strict>], "reason">;
143
- /** One atomically persisted context epoch and its model binding. */
144
- export type ContextEpochStart = z.output<typeof contextEpochStartSchema>;
145
- /** Strict step envelope reused by the SQL row codec; unknown types fail loudly. */
146
- export declare const agentStepEntrySchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
147
- type: z.ZodLiteral<"pi_message">;
148
- schemaVersion: z.ZodOptional<z.ZodNumber>;
149
- message: z.ZodPipe<z.ZodObject<{
150
- role: z.ZodString;
151
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
152
- [x: string]: unknown;
153
- role: string;
154
- }>>;
155
- provenance: z.ZodOptional<z.ZodObject<{
156
- authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
157
- actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
158
- platform: z.ZodLiteral<"slack">;
159
- teamId: z.ZodString;
160
- email: z.ZodOptional<z.ZodString>;
161
- fullName: z.ZodOptional<z.ZodString>;
162
- userId: z.ZodString;
163
- userName: z.ZodOptional<z.ZodString>;
164
- }, z.core.$strict>, z.ZodObject<{
165
- platform: z.ZodLiteral<"local">;
166
- email: z.ZodOptional<z.ZodString>;
167
- fullName: z.ZodOptional<z.ZodString>;
168
- userId: z.ZodString;
169
- userName: z.ZodOptional<z.ZodString>;
170
- }, z.core.$strict>, z.ZodObject<{
171
- platform: z.ZodLiteral<"system">;
172
- name: z.ZodString;
173
- }, z.core.$strict>], "platform">>;
174
- }, z.core.$strict>>;
175
- }, z.core.$strip>, z.ZodObject<{
176
- type: z.ZodLiteral<"mcp_provider_connected">;
177
- provider: z.ZodString;
178
- }, z.core.$strip>, z.ZodObject<{
179
- type: z.ZodLiteral<"authorization_requested">;
180
- kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
181
- provider: z.ZodString;
182
- actorId: z.ZodString;
183
- authorizationId: z.ZodString;
184
- delivery: z.ZodUnion<readonly [z.ZodLiteral<"private_link_sent">, z.ZodLiteral<"private_link_reused">]>;
185
- }, z.core.$strip>, z.ZodObject<{
186
- type: z.ZodLiteral<"authorization_completed">;
187
- kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
188
- provider: z.ZodString;
189
- actorId: z.ZodString;
190
- authorizationId: z.ZodString;
191
- }, z.core.$strip>, z.ZodObject<{
192
- type: z.ZodLiteral<"tool_execution_started">;
193
- toolCallId: z.ZodString;
194
- toolName: z.ZodString;
195
- args: z.ZodOptional<z.ZodUnknown>;
196
- }, z.core.$strip>, z.ZodObject<{
197
- type: z.ZodLiteral<"visible_context_compacted">;
198
- compactions: z.ZodArray<z.ZodObject<{
199
- coveredMessageIds: z.ZodArray<z.ZodString>;
200
- createdAtMs: z.ZodNumber;
201
- id: z.ZodString;
202
- summary: z.ZodString;
203
- }, z.core.$strip>>;
204
- }, z.core.$strip>, z.ZodObject<{
205
- type: z.ZodLiteral<"subagent_started">;
206
- subagentInvocationId: z.ZodString;
207
- subagentKind: z.ZodString;
208
- modelId: z.ZodOptional<z.ZodString>;
209
- parentToolCallId: z.ZodOptional<z.ZodString>;
210
- reasoningLevel: z.ZodOptional<z.ZodString>;
211
- childConversationId: z.ZodString;
212
- historyMode: z.ZodUnion<readonly [z.ZodLiteral<"isolated">, z.ZodLiteral<"shared">]>;
213
- }, z.core.$strict>, z.ZodObject<{
214
- type: z.ZodLiteral<"subagent_ended">;
215
- subagentInvocationId: z.ZodString;
216
- outcome: z.ZodUnion<readonly [z.ZodLiteral<"success">, z.ZodLiteral<"error">, z.ZodLiteral<"aborted">]>;
217
- errorCode: z.ZodOptional<z.ZodString>;
218
- }, z.core.$strip>]>, z.ZodUnion<readonly [z.ZodObject<{
219
- type: z.ZodLiteral<"context_epoch_started">;
220
- reason: z.ZodLiteral<"initial">;
221
- modelProfile: z.ZodLiteral<"standard">;
222
- modelId: z.ZodString;
223
- }, z.core.$strict>, z.ZodObject<{
224
- type: z.ZodLiteral<"context_epoch_started">;
225
- reason: z.ZodLiteral<"handoff">;
226
- modelProfile: z.ZodString;
227
- modelId: z.ZodString;
228
- }, z.core.$strict>, z.ZodObject<{
229
- type: z.ZodLiteral<"context_epoch_started">;
230
- reason: z.ZodUnion<readonly [z.ZodLiteral<"compaction">, z.ZodLiteral<"rollback">]>;
231
- modelProfile: z.ZodOptional<z.ZodUndefined>;
232
- modelId: z.ZodOptional<z.ZodUndefined>;
342
+ }, z.core.$strict>]>;
343
+ /** One durable conversation event's validated data. */
344
+ export type ConversationEventData = z.output<typeof conversationEventDataSchema>;
345
+ declare const unknownConversationEventDataSchema: z.ZodObject<{
346
+ type: z.ZodLiteral<"unknown">;
347
+ originalType: z.ZodString;
348
+ payload: z.ZodUnknown;
349
+ }, z.core.$strict>;
350
+ /** Opaque data from a stored event this Junior version cannot interpret. */
351
+ export type UnknownConversationEventData = z.output<typeof unknownConversationEventDataSchema>;
352
+ /**
353
+ * Canonical ordered envelope for the durable conversation log.
354
+ * `schemaVersion` is persisted with every physical event row.
355
+ */
356
+ export declare const conversationEventSchema: z.ZodUnion<readonly [z.ZodObject<{
357
+ seq: z.ZodNumber;
358
+ historyVersion: z.ZodNumber;
359
+ idempotencyKey: z.ZodOptional<z.ZodString>;
360
+ createdAtMs: z.ZodNumber;
361
+ schemaVersion: z.ZodLiteral<1>;
362
+ data: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
363
+ type: z.ZodLiteral<"message">;
364
+ messageId: z.ZodString;
365
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
366
+ text: z.ZodString;
367
+ authorIdentityId: z.ZodOptional<z.ZodString>;
368
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
369
+ }, z.core.$strict>, z.ZodObject<{
370
+ messageId: z.ZodString;
371
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
372
+ text: z.ZodString;
373
+ authorIdentityId: z.ZodOptional<z.ZodString>;
374
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
375
+ type: z.ZodLiteral<"message_updated">;
376
+ }, z.core.$strict>, z.ZodObject<{
377
+ message: z.ZodPipe<z.ZodObject<{
378
+ role: z.ZodString;
379
+ }, z.core.$loose>, z.ZodTransform<{
380
+ role: string;
381
+ }, {
382
+ [x: string]: unknown;
383
+ role: string;
384
+ }>>;
385
+ provenance: z.ZodOptional<z.ZodObject<{
386
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
387
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
388
+ platform: z.ZodLiteral<"slack">;
389
+ teamId: z.ZodString;
390
+ email: z.ZodOptional<z.ZodString>;
391
+ fullName: z.ZodOptional<z.ZodString>;
392
+ userId: z.ZodString;
393
+ userName: z.ZodOptional<z.ZodString>;
394
+ }, z.core.$strict>, z.ZodObject<{
395
+ platform: z.ZodLiteral<"local">;
396
+ email: z.ZodOptional<z.ZodString>;
397
+ fullName: z.ZodOptional<z.ZodString>;
398
+ userId: z.ZodString;
399
+ userName: z.ZodOptional<z.ZodString>;
400
+ }, z.core.$strict>, z.ZodObject<{
401
+ platform: z.ZodLiteral<"system">;
402
+ name: z.ZodString;
403
+ }, z.core.$strict>], "platform">>;
404
+ }, z.core.$strict>>;
405
+ type: z.ZodLiteral<"agent_step">;
406
+ }, z.core.$strict>, z.ZodObject<{
407
+ type: z.ZodLiteral<"mcp_provider_connected">;
408
+ provider: z.ZodString;
409
+ }, z.core.$strict>, z.ZodObject<{
410
+ type: z.ZodLiteral<"authorization_requested">;
411
+ kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
412
+ provider: z.ZodString;
413
+ actorId: z.ZodString;
414
+ authorizationId: z.ZodString;
415
+ delivery: z.ZodUnion<readonly [z.ZodLiteral<"private_link_sent">, z.ZodLiteral<"private_link_reused">]>;
416
+ }, z.core.$strict>, z.ZodObject<{
417
+ type: z.ZodLiteral<"authorization_completed">;
418
+ kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
419
+ provider: z.ZodString;
420
+ actorId: z.ZodString;
421
+ authorizationId: z.ZodString;
422
+ }, z.core.$strict>, z.ZodObject<{
423
+ type: z.ZodLiteral<"tool_execution_started">;
424
+ toolCallId: z.ZodString;
425
+ toolName: z.ZodString;
426
+ }, z.core.$strict>, z.ZodObject<{
427
+ type: z.ZodLiteral<"message_handled">;
428
+ messageId: z.ZodString;
429
+ }, z.core.$strict>, z.ZodObject<{
430
+ type: z.ZodLiteral<"messages_summarized">;
431
+ historyFromSeq: z.ZodNumber;
432
+ compactions: z.ZodArray<z.ZodObject<{
433
+ coveredMessageCount: z.ZodNumber;
434
+ createdAtMs: z.ZodNumber;
435
+ id: z.ZodString;
436
+ summary: z.ZodString;
437
+ }, z.core.$strict>>;
438
+ }, z.core.$strict>, z.ZodObject<{
439
+ type: z.ZodLiteral<"turn_started">;
440
+ turnId: z.ZodString;
441
+ inputMessageIds: z.ZodArray<z.ZodString>;
442
+ surface: z.ZodEnum<{
443
+ slack: "slack";
444
+ api: "api";
445
+ internal: "internal";
446
+ scheduler: "scheduler";
447
+ }>;
448
+ }, z.core.$strict>, z.ZodObject<{
449
+ type: z.ZodLiteral<"turn_completed">;
450
+ turnId: z.ZodString;
451
+ outcome: z.ZodEnum<{
452
+ success: "success";
453
+ no_reply: "no_reply";
454
+ }>;
455
+ }, z.core.$strict>, z.ZodObject<{
456
+ type: z.ZodLiteral<"turn_failed">;
457
+ turnId: z.ZodString;
458
+ failureCode: z.ZodEnum<{
459
+ agent_run_failed: "agent_run_failed";
460
+ delivery_failed: "delivery_failed";
461
+ model_execution_failed: "model_execution_failed";
462
+ persistence_failed: "persistence_failed";
463
+ }>;
464
+ eventId: z.ZodOptional<z.ZodString>;
465
+ }, z.core.$strict>, z.ZodObject<{
466
+ type: z.ZodLiteral<"subagent_started">;
467
+ subagentInvocationId: z.ZodString;
468
+ subagentKind: z.ZodString;
469
+ modelId: z.ZodOptional<z.ZodString>;
470
+ parentToolCallId: z.ZodOptional<z.ZodString>;
471
+ reasoningLevel: z.ZodOptional<z.ZodString>;
472
+ childConversationId: z.ZodString;
473
+ }, z.core.$strict>, z.ZodObject<{
474
+ type: z.ZodLiteral<"subagent_ended">;
475
+ subagentInvocationId: z.ZodString;
476
+ outcome: z.ZodUnion<readonly [z.ZodLiteral<"success">, z.ZodLiteral<"error">, z.ZodLiteral<"aborted">]>;
477
+ errorCode: z.ZodOptional<z.ZodString>;
478
+ }, z.core.$strict>]>, z.ZodDiscriminatedUnion<[z.ZodObject<{
479
+ type: z.ZodLiteral<"handoff">;
480
+ modelProfile: z.ZodString;
481
+ modelId: z.ZodString;
482
+ triggeringToolCallId: z.ZodOptional<z.ZodString>;
483
+ replacementHistory: z.ZodArray<z.ZodObject<{
484
+ message: z.ZodPipe<z.ZodObject<{
485
+ role: z.ZodString;
486
+ }, z.core.$loose>, z.ZodTransform<{
487
+ role: string;
488
+ }, {
489
+ [x: string]: unknown;
490
+ role: string;
491
+ }>>;
492
+ provenance: z.ZodOptional<z.ZodObject<{
493
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
494
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
495
+ platform: z.ZodLiteral<"slack">;
496
+ teamId: z.ZodString;
497
+ email: z.ZodOptional<z.ZodString>;
498
+ fullName: z.ZodOptional<z.ZodString>;
499
+ userId: z.ZodString;
500
+ userName: z.ZodOptional<z.ZodString>;
501
+ }, z.core.$strict>, z.ZodObject<{
502
+ platform: z.ZodLiteral<"local">;
503
+ email: z.ZodOptional<z.ZodString>;
504
+ fullName: z.ZodOptional<z.ZodString>;
505
+ userId: z.ZodString;
506
+ userName: z.ZodOptional<z.ZodString>;
507
+ }, z.core.$strict>, z.ZodObject<{
508
+ platform: z.ZodLiteral<"system">;
509
+ name: z.ZodString;
510
+ }, z.core.$strict>], "platform">>;
511
+ }, z.core.$strict>>;
512
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
513
+ }, z.core.$strict>>;
514
+ }, z.core.$strict>, z.ZodObject<{
515
+ type: z.ZodLiteral<"compaction">;
516
+ modelProfile: z.ZodString;
517
+ modelId: z.ZodString;
518
+ replacementHistory: z.ZodArray<z.ZodObject<{
519
+ message: z.ZodPipe<z.ZodObject<{
520
+ role: z.ZodString;
521
+ }, z.core.$loose>, z.ZodTransform<{
522
+ role: string;
523
+ }, {
524
+ [x: string]: unknown;
525
+ role: string;
526
+ }>>;
527
+ provenance: z.ZodOptional<z.ZodObject<{
528
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
529
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
530
+ platform: z.ZodLiteral<"slack">;
531
+ teamId: z.ZodString;
532
+ email: z.ZodOptional<z.ZodString>;
533
+ fullName: z.ZodOptional<z.ZodString>;
534
+ userId: z.ZodString;
535
+ userName: z.ZodOptional<z.ZodString>;
536
+ }, z.core.$strict>, z.ZodObject<{
537
+ platform: z.ZodLiteral<"local">;
538
+ email: z.ZodOptional<z.ZodString>;
539
+ fullName: z.ZodOptional<z.ZodString>;
540
+ userId: z.ZodString;
541
+ userName: z.ZodOptional<z.ZodString>;
542
+ }, z.core.$strict>, z.ZodObject<{
543
+ platform: z.ZodLiteral<"system">;
544
+ name: z.ZodString;
545
+ }, z.core.$strict>], "platform">>;
546
+ }, z.core.$strict>>;
547
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
548
+ }, z.core.$strict>>;
549
+ }, z.core.$strict>], "type">, z.ZodObject<{
550
+ type: z.ZodLiteral<"rollback">;
551
+ modelProfile: z.ZodString;
552
+ modelId: z.ZodString;
553
+ replacementHistory: z.ZodArray<z.ZodObject<{
554
+ message: z.ZodPipe<z.ZodObject<{
555
+ role: z.ZodString;
556
+ }, z.core.$loose>, z.ZodTransform<{
557
+ role: string;
558
+ }, {
559
+ [x: string]: unknown;
560
+ role: string;
561
+ }>>;
562
+ provenance: z.ZodOptional<z.ZodObject<{
563
+ authority: z.ZodUnion<readonly [z.ZodLiteral<"instruction">, z.ZodLiteral<"context">]>;
564
+ actor: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
565
+ platform: z.ZodLiteral<"slack">;
566
+ teamId: z.ZodString;
567
+ email: z.ZodOptional<z.ZodString>;
568
+ fullName: z.ZodOptional<z.ZodString>;
569
+ userId: z.ZodString;
570
+ userName: z.ZodOptional<z.ZodString>;
571
+ }, z.core.$strict>, z.ZodObject<{
572
+ platform: z.ZodLiteral<"local">;
573
+ email: z.ZodOptional<z.ZodString>;
574
+ fullName: z.ZodOptional<z.ZodString>;
575
+ userId: z.ZodString;
576
+ userName: z.ZodOptional<z.ZodString>;
577
+ }, z.core.$strict>, z.ZodObject<{
578
+ platform: z.ZodLiteral<"system">;
579
+ name: z.ZodString;
580
+ }, z.core.$strict>], "platform">>;
581
+ }, z.core.$strict>>;
582
+ sourceEventSeq: z.ZodOptional<z.ZodNumber>;
583
+ }, z.core.$strict>>;
584
+ }, z.core.$strict>]>;
233
585
  }, z.core.$strict>, z.ZodObject<{
234
- type: z.ZodLiteral<"context_epoch_started">;
235
- reason: z.ZodUnion<readonly [z.ZodLiteral<"compaction">, z.ZodLiteral<"rollback">]>;
236
- modelProfile: z.ZodString;
237
- modelId: z.ZodString;
238
- }, z.core.$strict>]>]>;
239
- /** One durable execution step's validated payload (sessionId lifted to epoch). */
240
- export type AgentStepEntry = z.infer<typeof agentStepEntrySchema>;
241
- /** A step read back from storage with its assigned order and epoch. */
242
- export interface StoredAgentStep {
243
- seq: number;
244
- contextEpoch: number;
245
- createdAtMs: number;
246
- entry: AgentStepEntry;
247
- }
248
- /** Validate a current-epoch append without permitting epoch markers. */
249
- export declare const newAgentStepSchema: z.ZodObject<{
250
- entry: z.ZodUnion<readonly [z.ZodObject<{
251
- type: z.ZodLiteral<"pi_message">;
252
- schemaVersion: z.ZodOptional<z.ZodNumber>;
586
+ schemaVersion: z.ZodNumber;
587
+ seq: z.ZodNumber;
588
+ historyVersion: z.ZodNumber;
589
+ idempotencyKey: z.ZodOptional<z.ZodString>;
590
+ createdAtMs: z.ZodNumber;
591
+ data: z.ZodObject<{
592
+ type: z.ZodLiteral<"unknown">;
593
+ originalType: z.ZodString;
594
+ payload: z.ZodUnknown;
595
+ }, z.core.$strict>;
596
+ }, z.core.$strict>]>;
597
+ /** One versioned event read from the durable conversation log. */
598
+ export type ConversationEvent = z.output<typeof conversationEventSchema>;
599
+ declare const storedConversationEventSchema: z.ZodObject<{
600
+ schemaVersion: z.ZodNumber;
601
+ seq: z.ZodNumber;
602
+ historyVersion: z.ZodNumber;
603
+ idempotencyKey: z.ZodOptional<z.ZodString>;
604
+ createdAtMs: z.ZodNumber;
605
+ type: z.ZodString;
606
+ payload: z.ZodUnknown;
607
+ }, z.core.$strict>;
608
+ /**
609
+ * Decode a physical event row without making old or future event types
610
+ * unreadable. Unsupported rows stay opaque until an upgrade migration defines
611
+ * their semantics; known version-one events remain strict so corrupt canonical
612
+ * data cannot be mistaken for compatibility data.
613
+ */
614
+ export declare function decodeStoredConversationEvent(value: z.input<typeof storedConversationEventSchema>): ConversationEvent;
615
+ /** Validate an append without permitting model-history replacement events. */
616
+ export declare const newConversationEventSchema: z.ZodObject<{
617
+ data: z.ZodUnion<readonly [z.ZodObject<{
618
+ type: z.ZodLiteral<"message">;
619
+ messageId: z.ZodString;
620
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
621
+ text: z.ZodString;
622
+ authorIdentityId: z.ZodOptional<z.ZodString>;
623
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
624
+ }, z.core.$strict>, z.ZodObject<{
625
+ messageId: z.ZodString;
626
+ role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"system">]>;
627
+ text: z.ZodString;
628
+ authorIdentityId: z.ZodOptional<z.ZodString>;
629
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
630
+ type: z.ZodLiteral<"message_updated">;
631
+ }, z.core.$strict>, z.ZodObject<{
253
632
  message: z.ZodPipe<z.ZodObject<{
254
633
  role: z.ZodString;
255
- }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
634
+ }, z.core.$loose>, z.ZodTransform<{
635
+ role: string;
636
+ }, {
256
637
  [x: string]: unknown;
257
638
  role: string;
258
639
  }>>;
@@ -276,36 +657,67 @@ export declare const newAgentStepSchema: z.ZodObject<{
276
657
  name: z.ZodString;
277
658
  }, z.core.$strict>], "platform">>;
278
659
  }, z.core.$strict>>;
279
- }, z.core.$strip>, z.ZodObject<{
660
+ type: z.ZodLiteral<"agent_step">;
661
+ }, z.core.$strict>, z.ZodObject<{
280
662
  type: z.ZodLiteral<"mcp_provider_connected">;
281
663
  provider: z.ZodString;
282
- }, z.core.$strip>, z.ZodObject<{
664
+ }, z.core.$strict>, z.ZodObject<{
283
665
  type: z.ZodLiteral<"authorization_requested">;
284
666
  kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
285
667
  provider: z.ZodString;
286
668
  actorId: z.ZodString;
287
669
  authorizationId: z.ZodString;
288
670
  delivery: z.ZodUnion<readonly [z.ZodLiteral<"private_link_sent">, z.ZodLiteral<"private_link_reused">]>;
289
- }, z.core.$strip>, z.ZodObject<{
671
+ }, z.core.$strict>, z.ZodObject<{
290
672
  type: z.ZodLiteral<"authorization_completed">;
291
673
  kind: z.ZodUnion<readonly [z.ZodLiteral<"plugin">, z.ZodLiteral<"mcp">]>;
292
674
  provider: z.ZodString;
293
675
  actorId: z.ZodString;
294
676
  authorizationId: z.ZodString;
295
- }, z.core.$strip>, z.ZodObject<{
677
+ }, z.core.$strict>, z.ZodObject<{
296
678
  type: z.ZodLiteral<"tool_execution_started">;
297
679
  toolCallId: z.ZodString;
298
680
  toolName: z.ZodString;
299
- args: z.ZodOptional<z.ZodUnknown>;
300
- }, z.core.$strip>, z.ZodObject<{
301
- type: z.ZodLiteral<"visible_context_compacted">;
681
+ }, z.core.$strict>, z.ZodObject<{
682
+ type: z.ZodLiteral<"message_handled">;
683
+ messageId: z.ZodString;
684
+ }, z.core.$strict>, z.ZodObject<{
685
+ type: z.ZodLiteral<"messages_summarized">;
686
+ historyFromSeq: z.ZodNumber;
302
687
  compactions: z.ZodArray<z.ZodObject<{
303
- coveredMessageIds: z.ZodArray<z.ZodString>;
688
+ coveredMessageCount: z.ZodNumber;
304
689
  createdAtMs: z.ZodNumber;
305
690
  id: z.ZodString;
306
691
  summary: z.ZodString;
307
- }, z.core.$strip>>;
308
- }, z.core.$strip>, z.ZodObject<{
692
+ }, z.core.$strict>>;
693
+ }, z.core.$strict>, z.ZodObject<{
694
+ type: z.ZodLiteral<"turn_started">;
695
+ turnId: z.ZodString;
696
+ inputMessageIds: z.ZodArray<z.ZodString>;
697
+ surface: z.ZodEnum<{
698
+ slack: "slack";
699
+ api: "api";
700
+ internal: "internal";
701
+ scheduler: "scheduler";
702
+ }>;
703
+ }, z.core.$strict>, z.ZodObject<{
704
+ type: z.ZodLiteral<"turn_completed">;
705
+ turnId: z.ZodString;
706
+ outcome: z.ZodEnum<{
707
+ success: "success";
708
+ no_reply: "no_reply";
709
+ }>;
710
+ }, z.core.$strict>, z.ZodObject<{
711
+ type: z.ZodLiteral<"turn_failed">;
712
+ turnId: z.ZodString;
713
+ failureCode: z.ZodEnum<{
714
+ agent_run_failed: "agent_run_failed";
715
+ delivery_failed: "delivery_failed";
716
+ model_execution_failed: "model_execution_failed";
717
+ persistence_failed: "persistence_failed";
718
+ }>;
719
+ eventId: z.ZodOptional<z.ZodString>;
720
+ }, z.core.$strict>, z.ZodObject<{
309
721
  type: z.ZodLiteral<"subagent_started">;
310
722
  subagentInvocationId: z.ZodString;
311
723
  subagentKind: z.ZodString;
@@ -313,30 +725,33 @@ export declare const newAgentStepSchema: z.ZodObject<{
313
725
  parentToolCallId: z.ZodOptional<z.ZodString>;
314
726
  reasoningLevel: z.ZodOptional<z.ZodString>;
315
727
  childConversationId: z.ZodString;
316
- historyMode: z.ZodUnion<readonly [z.ZodLiteral<"isolated">, z.ZodLiteral<"shared">]>;
317
728
  }, z.core.$strict>, z.ZodObject<{
318
729
  type: z.ZodLiteral<"subagent_ended">;
319
730
  subagentInvocationId: z.ZodString;
320
731
  outcome: z.ZodUnion<readonly [z.ZodLiteral<"success">, z.ZodLiteral<"error">, z.ZodLiteral<"aborted">]>;
321
732
  errorCode: z.ZodOptional<z.ZodString>;
322
- }, z.core.$strip>]>;
733
+ }, z.core.$strict>]>;
734
+ idempotencyKey: z.ZodOptional<z.ZodString>;
323
735
  createdAtMs: z.ZodNumber;
324
736
  }, z.core.$strict>;
325
- /** A step to append; the store assigns `seq` and the current `context_epoch`. */
326
- export type NewAgentStep = z.output<typeof newAgentStepSchema>;
327
- /** A replacement Pi message written into a freshly opened epoch. */
328
- export type PiMessageStep = z.output<typeof piMessageStepSchema>;
329
- /** Persist and read the durable per-conversation agent execution history. */
330
- export interface AgentStepStore {
331
- /** Append steps in one transaction, assigning `seq = max+1` under the lease. */
332
- append(conversationId: string, steps: NewAgentStep[]): Promise<void>;
333
- /**
334
- * Open initial epoch 0 or the next replacement epoch in one transaction.
335
- */
336
- startEpoch(conversationId: string, opts: ContextEpochStart): Promise<void>;
337
- /** Steps of the highest epoch in `seq` order (all types; caller filters). */
338
- loadCurrentEpoch(conversationId: string): Promise<StoredAgentStep[]>;
339
- /** All steps across all epochs in `seq` order, for audit and reporting. */
340
- loadHistory(conversationId: string): Promise<StoredAgentStep[]>;
737
+ /** An event to append; the store assigns `seq` and current history version. */
738
+ export type NewConversationEvent = z.output<typeof newConversationEventSchema>;
739
+ /** Persist and read the canonical per-conversation event log. */
740
+ export interface ConversationEventStore {
741
+ /** Append events atomically, assigning `seq = max+1` under the lease. */
742
+ append(conversationId: string, events: NewConversationEvent[]): Promise<void>;
743
+ /** Replace active model history with a compaction or handoff event. */
744
+ replaceHistory(conversationId: string, replacement: HistoryReplacement): Promise<void>;
745
+ /** Events of the current history version in `seq` order. */
746
+ loadCurrentHistory(conversationId: string): Promise<ConversationEvent[]>;
747
+ /** Events in the history version containing `seq`, when it exists. */
748
+ loadHistoryContaining(conversationId: string, seq: number, throughSeq?: number): Promise<ConversationEvent[] | undefined>;
749
+ /** Current source/destination messages and their latest summary snapshot. */
750
+ loadMessageHistory(conversationId: string): Promise<{
751
+ events: ConversationEvent[];
752
+ compaction: ConversationEvent | undefined;
753
+ }>;
754
+ /** All events across every history version in `seq` order. */
755
+ loadHistory(conversationId: string): Promise<ConversationEvent[]>;
341
756
  }
342
757
  export {};