@kortix/sdk 0.13.54 → 0.13.55

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 (114) hide show
  1. package/README.md +34 -9
  2. package/dist/browser/stores/sync-store.d.ts +20 -0
  3. package/dist/browser/stores/sync-store.d.ts.map +1 -1
  4. package/dist/browser/stores/sync-store.js +65 -23
  5. package/dist/browser/stores/sync-store.js.map +1 -1
  6. package/dist/core/auth/app-viewer.d.ts +1 -1
  7. package/dist/core/auth/app-viewer.js +1 -1
  8. package/dist/core/client/kortix.d.ts +3 -0
  9. package/dist/core/client/kortix.d.ts.map +1 -1
  10. package/dist/core/client/kortix.js +3 -0
  11. package/dist/core/client/kortix.js.map +1 -1
  12. package/dist/core/client/project-access-resources.d.ts +1 -1
  13. package/dist/core/client/project-access-resources.d.ts.map +1 -1
  14. package/dist/core/client/project-access-resources.js +1 -1
  15. package/dist/core/client/project-access-resources.js.map +1 -1
  16. package/dist/core/client/project-core.d.ts.map +1 -1
  17. package/dist/core/rest/platform-client/client-policy.d.ts +21 -0
  18. package/dist/core/rest/platform-client/client-policy.d.ts.map +1 -0
  19. package/dist/core/rest/platform-client/client-policy.js +49 -0
  20. package/dist/core/rest/platform-client/client-policy.js.map +1 -0
  21. package/dist/core/rest/platform-client/index.d.ts +1 -0
  22. package/dist/core/rest/platform-client/index.d.ts.map +1 -1
  23. package/dist/core/rest/platform-client/index.js +1 -0
  24. package/dist/core/rest/platform-client/index.js.map +1 -1
  25. package/dist/core/rest/projects-client/apps-fleet.js +1 -1
  26. package/dist/core/rest/projects-client/apps.d.ts +18 -2
  27. package/dist/core/rest/projects-client/apps.d.ts.map +1 -1
  28. package/dist/core/rest/projects-client/apps.js.map +1 -1
  29. package/dist/core/rest/projects-client/projects.d.ts +6 -1
  30. package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
  31. package/dist/core/rest/projects-client/projects.js +3 -0
  32. package/dist/core/rest/projects-client/projects.js.map +1 -1
  33. package/dist/core/session/control-stream.d.ts +12 -0
  34. package/dist/core/session/control-stream.d.ts.map +1 -1
  35. package/dist/core/session/control-stream.js +22 -1
  36. package/dist/core/session/control-stream.js.map +1 -1
  37. package/dist/core/session-log/guard.d.ts +18 -0
  38. package/dist/core/session-log/guard.d.ts.map +1 -0
  39. package/dist/core/session-log/guard.js +114 -0
  40. package/dist/core/session-log/guard.js.map +1 -0
  41. package/dist/core/session-log/index.d.ts +16 -0
  42. package/dist/core/session-log/index.d.ts.map +1 -0
  43. package/dist/core/session-log/index.js +15 -0
  44. package/dist/core/session-log/index.js.map +1 -0
  45. package/dist/core/session-log/saved-log.d.ts +23 -0
  46. package/dist/core/session-log/saved-log.d.ts.map +1 -0
  47. package/dist/core/session-log/saved-log.js +34 -0
  48. package/dist/core/session-log/saved-log.js.map +1 -0
  49. package/dist/core/session-log/source.d.ts +36 -0
  50. package/dist/core/session-log/source.d.ts.map +1 -0
  51. package/dist/core/session-log/source.js +52 -0
  52. package/dist/core/session-log/source.js.map +1 -0
  53. package/dist/core/session-log/store.d.ts +25 -0
  54. package/dist/core/session-log/store.d.ts.map +1 -0
  55. package/dist/core/session-log/store.js +170 -0
  56. package/dist/core/session-log/store.js.map +1 -0
  57. package/dist/core/session-log/types.d.ts +371 -0
  58. package/dist/core/session-log/types.d.ts.map +1 -0
  59. package/dist/core/session-log/types.js +24 -0
  60. package/dist/core/session-log/types.js.map +1 -0
  61. package/dist/core/session-log/v1-view.d.ts +30 -0
  62. package/dist/core/session-log/v1-view.d.ts.map +1 -0
  63. package/dist/core/session-log/v1-view.js +106 -0
  64. package/dist/core/session-log/v1-view.js.map +1 -0
  65. package/dist/core/session-log/v1.d.ts +107 -0
  66. package/dist/core/session-log/v1.d.ts.map +1 -0
  67. package/dist/core/session-log/v1.js +495 -0
  68. package/dist/core/session-log/v1.js.map +1 -0
  69. package/dist/core/session-sync/copy-store-types.d.ts +29 -0
  70. package/dist/core/session-sync/copy-store-types.d.ts.map +1 -0
  71. package/dist/core/session-sync/copy-store-types.js +2 -0
  72. package/dist/core/session-sync/copy-store-types.js.map +1 -0
  73. package/dist/core/session-sync/saved-copy-store.d.ts +5 -0
  74. package/dist/core/session-sync/saved-copy-store.d.ts.map +1 -1
  75. package/dist/core/session-sync/saved-copy-store.js +30 -4
  76. package/dist/core/session-sync/saved-copy-store.js.map +1 -1
  77. package/dist/core/turns/segments/index.d.ts +1 -0
  78. package/dist/core/turns/segments/index.d.ts.map +1 -1
  79. package/dist/core/turns/segments/index.js +1 -0
  80. package/dist/core/turns/segments/index.js.map +1 -1
  81. package/dist/core/turns/segments/work-split.d.ts +16 -0
  82. package/dist/core/turns/segments/work-split.d.ts.map +1 -0
  83. package/dist/core/turns/segments/work-split.js +59 -0
  84. package/dist/core/turns/segments/work-split.js.map +1 -0
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +1 -0
  88. package/dist/index.js.map +1 -1
  89. package/dist/kortix.esm.min.js +33 -33
  90. package/dist/kortix.global.js +34 -34
  91. package/dist/react/opencode.d.ts +1 -0
  92. package/dist/react/opencode.d.ts.map +1 -1
  93. package/dist/react/opencode.js +2 -0
  94. package/dist/react/opencode.js.map +1 -1
  95. package/dist/react/session-transcript-subscription.d.ts +5 -1
  96. package/dist/react/session-transcript-subscription.d.ts.map +1 -1
  97. package/dist/react/session-transcript-subscription.js +8 -2
  98. package/dist/react/session-transcript-subscription.js.map +1 -1
  99. package/dist/react/sign-in-with-kortix.d.ts +1 -1
  100. package/dist/react/use-opencode-events/handle-event.d.ts +6 -0
  101. package/dist/react/use-opencode-events/handle-event.d.ts.map +1 -1
  102. package/dist/react/use-opencode-events/handle-event.js +5 -0
  103. package/dist/react/use-opencode-events/handle-event.js.map +1 -1
  104. package/dist/react/use-opencode-events/index.d.ts.map +1 -1
  105. package/dist/react/use-opencode-events/index.js +1 -0
  106. package/dist/react/use-opencode-events/index.js.map +1 -1
  107. package/dist/react/use-session-log.d.ts +52 -0
  108. package/dist/react/use-session-log.d.ts.map +1 -0
  109. package/dist/react/use-session-log.js +166 -0
  110. package/dist/react/use-session-log.js.map +1 -0
  111. package/dist/react/use-session.d.ts.map +1 -1
  112. package/dist/react/use-session.js +4 -0
  113. package/dist/react/use-session.js.map +1 -1
  114. package/package.json +2 -2
@@ -0,0 +1,371 @@
1
+ /**
2
+ * The Kortix session log, `kortix.session/2` minor 1: the harness-neutral record
3
+ * of a session (threads, messages, blocks).
4
+ *
5
+ * A copy of `packages/api-contract/src/session-log/types.ts`, which kortixd and
6
+ * apps/api import. This package is published and cannot depend on that private
7
+ * one; `types.test.ts` fails when the two copies differ below this header. The
8
+ * copy has no imports, so it needs no edit.
9
+ *
10
+ * This package has no `zod` dependency and gets none: only the types and the
11
+ * constants are vendored. The validators (`SessionLogSchema` and the rest of
12
+ * `schema.ts`) stay in `@kortix/api-contract/session-log`. The source's change
13
+ * log (C1 to C13, F1 to F13) is in the header of the api-contract file.
14
+ *
15
+ * Public names: `./index.ts` in this directory lists what the package exports.
16
+ */
17
+ export declare const SESSION_LOG_SCHEMA: "kortix.session/2";
18
+ export declare const SESSION_LOG_MINOR = 1;
19
+ export type SchemaRef = {
20
+ schema: typeof SESSION_LOG_SCHEMA;
21
+ v: number;
22
+ };
23
+ /** Harness-unique data, keyed by harness id. `native_id` (C7) maps this record to the harness's own id. */
24
+ export type Ext = Record<string, {
25
+ version: string;
26
+ native_id?: string;
27
+ data?: unknown;
28
+ }>;
29
+ /**
30
+ * F6: `harness` names the exporting harness ('pi', 'opencode', 'claude-code', 'codex', ...).
31
+ * Rows converted from the Kortix v1 store carry 'kortix-v1-import', so a targeted upcaster
32
+ * can find and repair them later.
33
+ */
34
+ export type Producer = {
35
+ harness: string;
36
+ harness_version: string;
37
+ adapter_version: string;
38
+ };
39
+ /** C6: provider = who serves the model; api = the wire dialect the harness spoke. */
40
+ export type ModelRef = {
41
+ provider: string;
42
+ model: string;
43
+ api?: 'anthropic-messages' | 'openai-chat' | 'openai-responses' | (string & {});
44
+ variant?: string;
45
+ reasoning_effort?: string;
46
+ };
47
+ export type Todo = {
48
+ id?: string;
49
+ content: string;
50
+ status: 'pending' | 'in_progress' | 'completed' | 'cancelled';
51
+ priority?: 'high' | 'medium' | 'low';
52
+ };
53
+ /** C9: best-effort — a target harness may be unable to re-arm a pending question/permission. Shape unchanged from 2.0 (a minor must not change a shape). */
54
+ export type Pending = {
55
+ id: string;
56
+ thread_id: string;
57
+ call_id?: string;
58
+ payload: unknown;
59
+ asked_at: string;
60
+ };
61
+ /**
62
+ * F4. How faithfully the record restores into a harness. 'native' = exported by a harness
63
+ * adapter, nothing missing. 'converted' = built from the Kortix v1 store, every model-visible
64
+ * part present. 'partial' = something the model saw is missing; `grade_counts` says what.
65
+ */
66
+ export type RestoreGrade = 'native' | 'converted' | 'partial';
67
+ /** F4: tool inputs missing, compaction cut points missing, attachments missing. */
68
+ export type GradeCounts = {
69
+ tool_input: number;
70
+ cut_point: number;
71
+ attachment: number;
72
+ };
73
+ export type SessionLog = SchemaRef & {
74
+ session_id: string;
75
+ title: string | null;
76
+ created_at: string;
77
+ restore_grade: RestoreGrade;
78
+ grade_counts?: GradeCounts;
79
+ harness: {
80
+ current: string;
81
+ history: Array<{
82
+ harness: string;
83
+ version: string;
84
+ from_seq: number;
85
+ at: string;
86
+ }>;
87
+ };
88
+ selection: {
89
+ agent: string | null;
90
+ model: ModelRef | null;
91
+ };
92
+ todos: Todo[];
93
+ pending: {
94
+ questions: Pending[];
95
+ permissions: Pending[];
96
+ };
97
+ threads: SessionLogThread[];
98
+ ext?: Ext;
99
+ };
100
+ /** C8: async sub-agents (Codex spawn/wait/send/close/resume) as well as synchronous task calls. */
101
+ export type ThreadInteraction = {
102
+ message_id: string;
103
+ call_id: string;
104
+ op: 'spawn' | 'send' | 'wait' | 'close' | 'resume' | 'result';
105
+ };
106
+ export type SessionLogThread = SchemaRef & {
107
+ thread_id: string;
108
+ parent_thread_id: string | null;
109
+ spawned_by: {
110
+ message_id: string;
111
+ call_id: string;
112
+ } | null;
113
+ interactions?: ThreadInteraction[];
114
+ agent: string | null;
115
+ native_agent_id?: string;
116
+ nickname?: string | null;
117
+ title: string | null;
118
+ created_at: string;
119
+ messages: SessionLogMessage[];
120
+ ext?: Ext;
121
+ };
122
+ export type Role = 'user' | 'assistant' | 'system';
123
+ export type SessionLogMessage = SchemaRef & {
124
+ message_id: string;
125
+ thread_id: string;
126
+ seq: number;
127
+ role: Role;
128
+ kind: 'turn' | 'compaction' | 'context';
129
+ status: 'streaming' | 'complete' | 'error' | 'aborted' | 'interrupted';
130
+ in_context: boolean;
131
+ hidden_reason?: 'failed_attempt' | 'aborted' | 'retracted' | 'reverted' | 'superseded';
132
+ origin?: 'prompt' | 'steer' | 'command' | 'automation' | 'subagent' | 'notification';
133
+ agent?: string | null;
134
+ native_agent_id?: string;
135
+ reply_to?: string | null;
136
+ parent_message_id?: string | null;
137
+ model: ModelRef | null;
138
+ usage: Usage | null;
139
+ finish: 'stop' | 'tool_calls' | 'length' | 'error' | 'aborted' | null;
140
+ error: {
141
+ code: string;
142
+ message: string;
143
+ } | null;
144
+ created_at: string;
145
+ completed_at: string | null;
146
+ producer: Producer;
147
+ blocks: SessionLogBlock[];
148
+ /** C11: a context message may store its body as a deduplicated blob instead of blocks. */
149
+ context_ref?: string;
150
+ ext?: Ext;
151
+ };
152
+ export type Usage = {
153
+ input: number;
154
+ output: number;
155
+ cache_read: number;
156
+ cache_write: number;
157
+ reasoning?: number;
158
+ cost?: number;
159
+ };
160
+ /**
161
+ * F1/F2. Every block has `id`: a non-empty string, unique within its message and stable across
162
+ * reads, so UI list keys and `log.block.delta` targets can name a block. A block converted from
163
+ * a Kortix v1 part uses the v1 part id as its `id`; a block an adapter exports uses the native
164
+ * part id when the harness has one, else a position-derived id.
165
+ */
166
+ export type BlockBase = {
167
+ id: string;
168
+ };
169
+ export type SessionLogBlock = TextBlock | ReasoningBlock | AttachmentBlock | ToolCallBlock | CompactionBlock | SubtaskBlock | StepBlock | HarnessBlock;
170
+ /**
171
+ * model: `model_text ?? text`. Several text blocks in one message are seen by the
172
+ * model as their concatenation (harnesses join with "" or "\n").
173
+ * C10: synthetic = generated by the harness (reminders, image source lines,
174
+ * command caveats); model-visible in that harness; a foreign restore may drop it.
175
+ */
176
+ /**
177
+ * F3: a text over 256 kB keeps a 16 kB preview in `text` and the full text in the object `ref`
178
+ * names; `bytes` is the UTF-8 length of the full text. Without `ref`, `text` is the whole text.
179
+ */
180
+ export type TextBlock = BlockBase & {
181
+ type: 'text';
182
+ text: string;
183
+ model_text?: string;
184
+ synthetic?: boolean;
185
+ ref?: string;
186
+ bytes?: number;
187
+ ext?: Ext;
188
+ };
189
+ /**
190
+ * Display only. C3: a restore MUST NOT hand a reasoning block to a target whose
191
+ * (provider, model) differs from the block's message model — pi, OpenCode v1 and
192
+ * OpenCode v2 would replay it as visible text. Same-provider continuation data
193
+ * (signatures, encrypted_content) lives in ext[harness].
194
+ */
195
+ export type ReasoningBlock = BlockBase & {
196
+ type: 'reasoning';
197
+ text: string;
198
+ summary?: string[];
199
+ redacted?: boolean;
200
+ ext?: Ext;
201
+ };
202
+ /**
203
+ * model: the bytes behind `ref`. C4: label/source_path are display (Codex "[Image #1]", Claude "[Image: source: …]").
204
+ * F13: `ref` and `bytes` are both set or both absent. Both absent = the bytes are missing: a row
205
+ * converted from the Kortix v1 store whose object was not found. Such a block keeps `mime`, `name`
206
+ * and the v1 `url`, counts in `SessionLog.grade_counts.attachment`, and the model sees nothing for it.
207
+ * (Before P1.3 both were required and an unresolved converted attachment would have needed a
208
+ * sentinel `ref: ''`; no record was stored with that shape.)
209
+ */
210
+ export type AttachmentBlock = BlockBase & {
211
+ type: 'attachment';
212
+ ref?: string;
213
+ mime: string;
214
+ name?: string;
215
+ label?: string;
216
+ source_path?: string;
217
+ bytes?: number;
218
+ sha256?: string;
219
+ url?: string;
220
+ ext?: Ext;
221
+ };
222
+ /** Kinds every reader renders. */
223
+ export declare const KNOWN_TOOL_KINDS: readonly ["shell", "read", "write", "edit", "patch", "list", "glob", "grep", "web_fetch", "web_search", "todo", "task", "question", "plan", "mcp", "other"];
224
+ export type KnownToolKind = (typeof KNOWN_TOOL_KINDS)[number];
225
+ /** F12: a harness may define its own kind. A reader renders a kind it does not know as 'other'. */
226
+ export type ToolKind = KnownToolKind | (string & {});
227
+ /** F13: a tool-result attachment follows the AttachmentBlock rule: no `ref` = the bytes are missing, `url` = the v1 url. */
228
+ export type ToolResultContent = {
229
+ type: 'text';
230
+ text: string;
231
+ } | {
232
+ type: 'attachment';
233
+ ref?: string;
234
+ mime: string;
235
+ sha256?: string;
236
+ url?: string;
237
+ };
238
+ /**
239
+ * C2. model: call_id, name, input, and `result.model_content ?? result.content`.
240
+ * Rule: a thread AT REST has no in-context call without a result — an exporter
241
+ * closes an interrupted call with `{ is_error: true, synthetic: true }` and the
242
+ * text the harness showed (pi "No result provided", OpenCode "[Tool execution was
243
+ * interrupted]"), or "[interrupted]" if the harness showed nothing.
244
+ * F11: the closing result carries `error: { code: 'interrupted', message }`. 'interrupted' is
245
+ * the one code for this rule; validators accept any code.
246
+ */
247
+ export type ToolCallBlock = BlockBase & {
248
+ type: 'tool_call';
249
+ call_id: string;
250
+ name: string;
251
+ kind: ToolKind;
252
+ input: unknown;
253
+ input_format?: 'json' | 'text';
254
+ status: 'pending' | 'running' | 'complete' | 'error';
255
+ result?: {
256
+ content: ToolResultContent[];
257
+ model_content?: ToolResultContent[];
258
+ is_error: boolean;
259
+ error?: {
260
+ code?: string;
261
+ message: string;
262
+ };
263
+ exit_code?: number;
264
+ synthetic?: boolean;
265
+ cleared_at?: string;
266
+ details?: unknown;
267
+ };
268
+ title?: string;
269
+ started_at?: string;
270
+ ended_at?: string;
271
+ ext?: Ext;
272
+ };
273
+ /**
274
+ * C1. The model sees, in place of every in-context message before this marker:
275
+ * - with `layout`: exactly the listed entries, in order;
276
+ * - without `layout`: [summary, …messages from first_kept_message_id up to the marker].
277
+ * `summary: null` + `opaque: true` = a provider-encrypted compaction (OpenAI remote
278
+ * compaction); only the same provider can replay it (ext), another harness
279
+ * restores the layout's kept messages without a summary.
280
+ */
281
+ export type CompactionLayoutEntry = {
282
+ summary: true;
283
+ } | {
284
+ message_id: string;
285
+ text_only?: boolean;
286
+ } | {
287
+ text: string;
288
+ };
289
+ export type CompactionBlock = BlockBase & {
290
+ type: 'compaction';
291
+ summary: string | null;
292
+ opaque?: boolean;
293
+ first_kept_message_id: string | null;
294
+ layout?: CompactionLayoutEntry[];
295
+ tokens_before?: number;
296
+ trigger?: 'auto' | 'manual' | 'overflow' | 'unknown';
297
+ ext?: Ext;
298
+ };
299
+ export type SubtaskBlock = BlockBase & {
300
+ type: 'subtask';
301
+ thread_id: string;
302
+ agent: string;
303
+ description: string;
304
+ call_id?: string;
305
+ call_ids?: string[];
306
+ };
307
+ export type StepBlock = BlockBase & {
308
+ type: 'step';
309
+ phase: 'start' | 'finish';
310
+ ext?: Ext;
311
+ };
312
+ /**
313
+ * A block only this harness understands. F10: a tool result whose call is gone is kept as
314
+ * `{ harness, kind: 'orphan_output', data: <native payload>, model_visible: false, fallback_text: <its output> }`
315
+ * in its own assistant message (Codex adapter). No dedicated field exists for it.
316
+ */
317
+ export type HarnessBlock = BlockBase & {
318
+ type: 'harness';
319
+ harness: string;
320
+ kind: string;
321
+ data: unknown;
322
+ model_visible: boolean;
323
+ fallback_text?: string;
324
+ };
325
+ /**
326
+ * C12. What an adapter can render natively. A mid-session switch runs a preflight:
327
+ * every feature the session uses that the target lacks becomes a line in the
328
+ * loss report shown before the switch.
329
+ */
330
+ export type CapabilityFeatures = {
331
+ tool_error_channel: boolean;
332
+ attachments: {
333
+ user: string[];
334
+ tool_result: boolean;
335
+ };
336
+ compaction: Array<'summary_first_tail' | 'layout' | 'text_tail' | 'opaque'>;
337
+ subagents: 'none' | 'sync' | 'async';
338
+ todos: boolean;
339
+ reasoning_replay: 'none' | 'same_model' | 'lowers_to_text';
340
+ freeform_tool_input: boolean;
341
+ };
342
+ /**
343
+ * F9. `native` = what the harness handles without changing the model-visible shape.
344
+ * `rendered` = what the adapter can write, including by lowering or emulating (OpenCode v2 emulates
345
+ * a layout with synthetic user rows; openai-chat harnesses lower a tool-result attachment into a
346
+ * follow-up user turn; an object-only harness wraps freeform input as `{ input }`).
347
+ * Every native feature is also rendered. A feature in `rendered` and not in `native` is a
348
+ * degraded line in the switch loss report; a feature in neither is a lost line.
349
+ */
350
+ export type AdapterCapabilities = {
351
+ harness: string;
352
+ harness_versions: string;
353
+ schema_minors: number[];
354
+ dialects: Array<NonNullable<ModelRef['api']>>;
355
+ native: CapabilityFeatures;
356
+ rendered: CapabilityFeatures;
357
+ };
358
+ /**
359
+ * C13. Export is incremental and hash-guarded: after a restore, an adapter
360
+ * emits only messages that are new, or whose model-visible content changed
361
+ * (hash of the native rendering). A restored record is never re-derived from a
362
+ * lossy native store. (In the prototype every adapter needed a "sidecar" in its
363
+ * native store to pass round trips; with the database as source of truth the
364
+ * sidecar disappears and this rule replaces it.)
365
+ */
366
+ export type ExportCursor = {
367
+ thread_id: string;
368
+ last_seq: number;
369
+ native_hashes: Record<string, string>;
370
+ };
371
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/session-log/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,kBAAkB,EAAG,kBAA2B,CAAA;AAC7D,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,MAAM,MAAM,SAAS,GAAG;IAAE,MAAM,EAAE,OAAO,kBAAkB,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAExE,2GAA2G;AAC3G,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAA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AChC,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7C,MAAM,EAAE,kBAAkB,CAAA;IAC1B,QAAQ,EAAE,kBAAkB,CAAA;CAC7B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Kortix session log, `kortix.session/2` minor 1: the harness-neutral record
3
+ * of a session (threads, messages, blocks).
4
+ *
5
+ * A copy of `packages/api-contract/src/session-log/types.ts`, which kortixd and
6
+ * apps/api import. This package is published and cannot depend on that private
7
+ * one; `types.test.ts` fails when the two copies differ below this header. The
8
+ * copy has no imports, so it needs no edit.
9
+ *
10
+ * This package has no `zod` dependency and gets none: only the types and the
11
+ * constants are vendored. The validators (`SessionLogSchema` and the rest of
12
+ * `schema.ts`) stay in `@kortix/api-contract/session-log`. The source's change
13
+ * log (C1 to C13, F1 to F13) is in the header of the api-contract file.
14
+ *
15
+ * Public names: `./index.ts` in this directory lists what the package exports.
16
+ */
17
+ export const SESSION_LOG_SCHEMA = 'kortix.session/2';
18
+ export const SESSION_LOG_MINOR = 1;
19
+ /** Kinds every reader renders. */
20
+ export const KNOWN_TOOL_KINDS = [
21
+ 'shell', 'read', 'write', 'edit', 'patch', 'list', 'glob', 'grep',
22
+ 'web_fetch', 'web_search', 'todo', 'task', 'question', 'plan', 'mcp', 'other',
23
+ ];
24
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/session-log/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAA2B,CAAA;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAmJlC,kCAAkC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACjE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CACrE,CAAA"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The v1 rows (`{ info, parts }`, `kortix.transcript.v1`) of a `fromV1` session-log thread
3
+ * (the OpenCode adapter's records; see `findThread` for the others), for the hooks that render v1 (`useSessionMessages`, `useSession().messages`, `classifyTurn`).
4
+ * Each message converts with `toV1`, the same conversion the API's v1 projection uses, and
5
+ * its rows are cached on the message object: a row keeps its identity while its message is
6
+ * unchanged, so a memoized row component re-renders only for the message that changed.
7
+ *
8
+ * Rows come in v1 order (`time.created`, then id), as `toV1` returns a thread.
9
+ *
10
+ * The v1 store still holds what the session log does not carry yet: an optimistic send, and,
11
+ * until the API relays `schema=v2` (P4.4, the remaining prerequisite; the v1 frames keep
12
+ * arriving until then), the turn that is streaming. Those rows
13
+ * are merged in, by message id: a session-log message replaces the v1 row of the same id,
14
+ * a tombstoned id stays out, and every other v1 row goes where the v1 store orders it
15
+ * (`time.created`, then id; a row with no time goes last).
16
+ */
17
+ import type { Message, Part } from '../runtime/runtime-types.js';
18
+ import type { SessionLogState, SessionLogThreadHead } from './store.js';
19
+ export interface V1MessageRow {
20
+ info: Message;
21
+ parts: Part[];
22
+ }
23
+ /** A thread `fromV1` built (the OpenCode adapter's records): the only kind the v1 hooks read through `toV1`. */
24
+ export declare const isV1Thread: (head: SessionLogThreadHead | undefined) => boolean;
25
+ /**
26
+ * The rows the v1 hooks show for runtime session `runtimeSessionId`. `v1Rows` (the v1
27
+ * store's rows) come back as the same array when no session log holds that thread.
28
+ */
29
+ export declare function sessionLogRowsFor<R extends V1MessageRow>(logs: Record<string, SessionLogState>, runtimeSessionId: string, v1Rows: R[]): R[];
30
+ //# sourceMappingURL=v1-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1-view.d.ts","sourceRoot":"","sources":["../../../src/core/session-log/v1-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAKrE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAoBD,gHAAgH;AAChH,eAAO,MAAM,UAAU,GAAI,MAAM,oBAAoB,GAAG,SAAS,KAAG,OAA8C,CAAC;AA0EnH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,YAAY,EACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACrC,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,CAAC,EAAE,GACV,CAAC,EAAE,CAgBL"}
@@ -0,0 +1,106 @@
1
+ import { SESSION_LOG_MINOR, SESSION_LOG_SCHEMA } from './types.js';
2
+ import { KORTIX_TRANSCRIPT_SCHEMA } from '../runtime/transcript-types.js';
3
+ import { toV1 } from './v1.js';
4
+ const SHELL = {
5
+ schema: SESSION_LOG_SCHEMA,
6
+ v: SESSION_LOG_MINOR,
7
+ session_id: '',
8
+ title: null,
9
+ created_at: '',
10
+ restore_grade: 'native',
11
+ harness: { current: '', history: [] },
12
+ selection: { agent: null, model: null },
13
+ todos: [],
14
+ pending: { questions: [], permissions: [] },
15
+ };
16
+ /** One array for every thread with no messages, so the merge cache below can hold it. */
17
+ const NO_MESSAGES = [];
18
+ /** The `fromV1` mark: the thread carries an ext entry of version `kortix.transcript.v1`. */
19
+ const v1Ext = (head) => Object.values(head.ext ?? {}).find((e) => e.version === KORTIX_TRANSCRIPT_SCHEMA);
20
+ /** A thread `fromV1` built (the OpenCode adapter's records): the only kind the v1 hooks read through `toV1`. */
21
+ export const isV1Thread = (head) => !!head && v1Ext(head) !== undefined;
22
+ /** The runtime session id `toV1` gives the thread's rows: the v1 ext's native id, else the thread id. */
23
+ const nativeOf = (head) => {
24
+ const e = v1Ext(head);
25
+ return e ? (e.native_id ?? null) : head.thread_id;
26
+ };
27
+ /** Rows per message, valid for one runtime session id: a `log.thread` upsert keeps them. */
28
+ const messageRows = new WeakMap();
29
+ function rowsOf(head, message) {
30
+ const native = nativeOf(head);
31
+ const cached = messageRows.get(message);
32
+ if (cached && cached.native === native)
33
+ return cached.rows;
34
+ const { rows } = toV1({ ...SHELL, threads: [{ ...head, messages: [message] }] });
35
+ const out = rows.map((r) => ({ info: r.info, parts: r.parts }));
36
+ messageRows.set(message, { native, rows: out });
37
+ return out;
38
+ }
39
+ /** Runtime session id -> thread id of each `fromV1` thread, built once per state. */
40
+ const indexes = new WeakMap();
41
+ function indexOf(state) {
42
+ let index = indexes.get(state);
43
+ if (!index) {
44
+ index = new Map();
45
+ for (const head of Object.values(state.threads)) {
46
+ const native = v1Ext(head) ? nativeOf(head) : null;
47
+ if (native !== null && !index.has(native))
48
+ index.set(native, head.thread_id);
49
+ }
50
+ indexes.set(state, index);
51
+ }
52
+ return index;
53
+ }
54
+ /**
55
+ * The `fromV1` thread whose runtime session id is `runtimeSessionId`. Only such a thread
56
+ * reads through `toV1`, as the API's v1 reads do: a native record (the pi adapter writes
57
+ * its records without the v1 residuals) renders lossy through `toV1`, so its v1 hooks keep
58
+ * the v1 store rows.
59
+ */
60
+ function findThread(logs, runtimeSessionId) {
61
+ for (const state of Object.values(logs)) {
62
+ const threadId = indexOf(state).get(runtimeSessionId);
63
+ if (threadId !== undefined)
64
+ return { state, head: state.threads[threadId], list: state.messages[threadId] ?? NO_MESSAGES };
65
+ }
66
+ return null;
67
+ }
68
+ const createdOf = (row) => row.info.time?.created;
69
+ /** Where the v1 store would put `row` among `rows`: before the first strictly newer one. */
70
+ function insertAt(rows, row) {
71
+ const created = createdOf(row);
72
+ if (created === undefined)
73
+ return rows.length;
74
+ const at = rows.findIndex((other) => {
75
+ const t = createdOf(other);
76
+ return t !== undefined && (t > created || (t === created && other.info.id > row.info.id));
77
+ });
78
+ return at < 0 ? rows.length : at;
79
+ }
80
+ const v1Order = (a, b) => (createdOf(a) ?? -Infinity) - (createdOf(b) ?? -Infinity) || (a.info.id < b.info.id ? -1 : a.info.id > b.info.id ? 1 : 0);
81
+ const merged = new WeakMap();
82
+ /**
83
+ * The rows the v1 hooks show for runtime session `runtimeSessionId`. `v1Rows` (the v1
84
+ * store's rows) come back as the same array when no session log holds that thread.
85
+ */
86
+ export function sessionLogRowsFor(logs, runtimeSessionId, v1Rows) {
87
+ const found = findThread(logs, runtimeSessionId);
88
+ if (!found)
89
+ return v1Rows;
90
+ const { state, head, list } = found;
91
+ const cached = merged.get(list);
92
+ const native = nativeOf(head);
93
+ if (cached && cached.v1Rows === v1Rows && cached.native === native && cached.revs === state.revs)
94
+ return cached.result;
95
+ // v1 order, as `toV1` sorts a whole thread: `time.created` (none first), then id. `seq` can disagree (pi stamps coarse times).
96
+ const result = list.flatMap((m) => rowsOf(head, m)).sort(v1Order);
97
+ const shown = new Set(result.map((r) => r.info.id));
98
+ for (const row of v1Rows) {
99
+ if (shown.has(row.info.id) || state.revs[row.info.id] !== undefined)
100
+ continue;
101
+ result.splice(insertAt(result, row), 0, row);
102
+ }
103
+ merged.set(list, { v1Rows, native, revs: state.revs, result });
104
+ return result;
105
+ }
106
+ //# sourceMappingURL=v1-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1-view.js","sourceRoot":"","sources":["../../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