@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,107 @@
1
+ /**
2
+ * `fromV1` and `toV1`: the session log and `kortix.transcript.v1` as the v1 mirror stores it
3
+ * (`session_transcript_mirrors` + `session_transcript_messages`). Pure: no database, no fetch.
4
+ *
5
+ * EXACT BY CONSTRUCTION. `fromV1` maps each v1 message and part onto v2 fields. Then it runs
6
+ * `toV1`'s own builder on the result and stores the difference to the stored v1 value (a
7
+ * `V1Change`) in `ext[harness].data`, under the version `kortix.transcript.v1`. `toV1` runs the
8
+ * builder and applies the change. So every field the mapping does not use (OpenCode metadata,
9
+ * step tokens, snapshots, a stripped call's missing input) is kept, and `toV1(fromV1(x))`
10
+ * deep-equals `x` for any JSON `x`, well-formed or not. A native v2 record has no such ext and
11
+ * gets the builder's output alone.
12
+ *
13
+ * Decisions beyond the plain mapping:
14
+ * - Threads. `thread_id` is the runtime session id (`opencode_session_id`), as the OpenCode
15
+ * adapter exports it. A runtime session other than the root is a child thread when a tool
16
+ * call names it (`state.metadata.sessionId`, else any mention in the call's state: the
17
+ * capture's `childSessionIdOf` rules all put the id there). `spawned_by` is that call.
18
+ * - Multiple roots. A runtime session that is not the root and that no call names is an old
19
+ * root kept after a re-pin. Its messages go into the root thread, before the current root's,
20
+ * with `in_context: false, hidden_reason: 'superseded'`: the model of the current root never
21
+ * saw them, and a separate thread would claim a parent link that does not exist. A child of an
22
+ * old root becomes a child of the root thread.
23
+ * - No usable root. `root_id` is null (both mirror columns are nullable; the v1 read then serves
24
+ * every row), or it names no row: a stale root, as after a re-pin to a fresh runtime session
25
+ * whose first capture has not run. Then the group of the latest row that no call names (the
26
+ * null group included) is the root thread, so the conversation stays in context. The stored
27
+ * `root_id` is kept in the session `ext`.
28
+ * - At rest. The mirror holds only finished turns, so an assistant message with no
29
+ * `time.completed` and no error is `interrupted`, and every pending or running call is closed
30
+ * by the closure rule with the text the harness shows. An errored assistant row is out of
31
+ * context (`failed_attempt`), except an aborted one with a model-visible block (`aborted`,
32
+ * in context, as OpenCode sends it).
33
+ * - Errors. `error.code` is the daemon's `TurnErrorCode` (`info.error.code`) when the row has
34
+ * one, else the v1 error class name. `finish` takes the v2 values only; another v1 finish
35
+ * ('content-filter', 'other') maps to null and stays in ext.
36
+ * - Attachments (F13). A resolved attachment gets `ref` and `bytes`. An unresolved one has
37
+ * neither, keeps `mime`, `name` and the v1 `url`, and counts in `grade_counts.attachment`.
38
+ * - Tool kinds come from a name table (OpenCode and pi names); another name with `_` is `mcp`
39
+ * (OpenCode names MCP tools `<server>_<tool>`), the rest `other`.
40
+ * - Model-invisible parts become harness blocks (`model_visible: false`, data = the v1 part):
41
+ * ignored text, text/plain and directory file parts (OpenCode sends their content as
42
+ * synthetic text instead), patch, snapshot, agent, retry, unknown types and malformed parts.
43
+ * A subtask part is model-visible with OpenCode's fallback text.
44
+ * - Block ids are the part ids (F2). A part without an id gets `#<index>`. A repeated id keeps
45
+ * its first occurrence; each later one gets `<id>#<n>`, the smallest n >= 2 that no part of
46
+ * the message uses.
47
+ * - `grade_counts` counts what an in-context message lost: `tool_input`, a tool call whose
48
+ * `state.input` is not an object (the legacy stripped rows); `cut_point`, a completed
49
+ * compaction without `tail_start_id`; `attachment`, a file part or tool attachment the
50
+ * resolver did not resolve. `restore_grade` is `partial` when any count is non-zero, else
51
+ * `converted`. `grade_counts` is always set.
52
+ * - `toV1` returns rows in the mirror's order reversed to ascending (the read is
53
+ * `message_created_at DESC NULLS LAST, message_id DESC`, so a missing time comes first), then
54
+ * message id. Compare rows keyed by message id: Postgres orders ids by its collation.
55
+ * - `toV1` applies the stored residuals whatever the producer: a daemon adapter that runs
56
+ * `fromV1` (OpenCode, P2.6) journals records under producer `opencode`, and they are exact
57
+ * too. A thread `fromV1` built always carries a `kortix.transcript.v1` ext, so that ext (or
58
+ * producer `kortix-v1-import`) marks a v1-derived message. On one, an `opencode` or `pi`
59
+ * harness block's `data` is the v1 part and passes through. On a native v2 record (no such
60
+ * ext, as the pi adapter writes), `toV1` skips `system` and `context` messages (an old
61
+ * client would draw them as user bubbles) and never passes a harness block's `data` through.
62
+ * - Output never aliases input: `fromV1` and `toV1` clone their input.
63
+ */
64
+ import type { KortixFilePart, KortixMessageInfo, KortixPart } from '../runtime/transcript-types.js';
65
+ import { type SessionLog } from './types.js';
66
+ /** One `session_transcript_messages` row. The other columns are derived from `info` by the capture. */
67
+ export type V1Row = {
68
+ runtime_session_id: string | null;
69
+ info: KortixMessageInfo;
70
+ parts: KortixPart[];
71
+ };
72
+ /** One session's v1 mirror. `root_id` is `session_transcript_mirrors.opencode_session_id`. */
73
+ export type V1Transcript = {
74
+ session_id: string;
75
+ root_id: string | null;
76
+ rows: V1Row[];
77
+ };
78
+ /** A stored attachment object: `ref` names it, `bytes` is its size. */
79
+ export type V1Attachment = {
80
+ ref: string;
81
+ bytes: number;
82
+ sha256?: string;
83
+ };
84
+ export type FromV1Options = {
85
+ /** The harness that wrote the rows; it keys `ext`. Default `opencode`. */
86
+ harness?: 'opencode' | 'pi';
87
+ /**
88
+ * Finds the stored object for a file part or tool attachment, usually by its
89
+ * `kortix-attachment://` url. The mirror drops every other url, so a part may have none.
90
+ * api-contract has no storage access, so the default resolves nothing: the block gets no
91
+ * `ref` and no `bytes` (F13), keeps the url, and counts in `grade_counts.attachment`.
92
+ */
93
+ resolveAttachment?: (part: KortixFilePart) => V1Attachment | null;
94
+ };
95
+ /** What turns a value `toV1` builds into the stored one: replace it, delete it, or change some keys. */
96
+ export type V1Change = {
97
+ set: unknown;
98
+ } | {
99
+ del: true;
100
+ } | {
101
+ sub: Record<string, V1Change>;
102
+ };
103
+ /** v2 -> v1. Exact for a record `fromV1` built; for a native record, the v1 rows an old client renders. */
104
+ export declare function toV1(input: SessionLog): V1Transcript;
105
+ /** v1 mirror -> session log. See the module header for every mapping decision. */
106
+ export declare function fromV1(v1: V1Transcript, options?: FromV1Options): SessionLog;
107
+ //# sourceMappingURL=v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../../src/core/session-log/v1.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEjG,OAAO,EASL,KAAK,UAAU,EAOhB,MAAM,SAAS,CAAC;AAEjB,uGAAuG;AACvG,MAAM,MAAM,KAAK,GAAG;IAAE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AACxG,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,KAAK,EAAE,CAAA;CAAE,CAAC;AACzF,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3E,MAAM,MAAM,aAAa,GAAG;IAC1B,0EAA0E;IAC1E,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,GAAG,IAAI,CAAC;CACnE,CAAC;AACF,wGAAwG;AACxG,MAAM,MAAM,QAAQ,GAAG;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAAE,CAAC;AAwM5F,2GAA2G;AAC3G,wBAAgB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAOpD;AAuMD,kFAAkF;AAClF,wBAAgB,MAAM,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,GAAE,aAAkB,GAAG,UAAU,CA8EhF"}
@@ -0,0 +1,495 @@
1
+ import { KORTIX_TRANSCRIPT_SCHEMA, isTurnErrorCode } from '../runtime/transcript-types.js';
2
+ import { SESSION_LOG_MINOR, SESSION_LOG_SCHEMA, } from './types.js';
3
+ const IMPORT = 'kortix-v1-import';
4
+ const PRODUCER = { harness: IMPORT, harness_version: KORTIX_TRANSCRIPT_SCHEMA, adapter_version: '1' };
5
+ const V = { schema: SESSION_LOG_SCHEMA, v: SESSION_LOG_MINOR };
6
+ /** What the harness shows the model for a call that never ended. */
7
+ const INTERRUPTED = { opencode: '[Tool execution was interrupted]', pi: 'No result provided' };
8
+ /** What OpenCode shows the model for a pruned tool output (`time.compacted`). */
9
+ const CLEARED = '[Old tool result content cleared]';
10
+ const SUBTASK_TEXT = 'The following tool was executed by the user';
11
+ /** OpenCode 1.18 and pi 1.0.3 tool names (pi: bash, edit, find, grep, ls, powershell, read, write). */
12
+ const KIND = new Map(Object.entries({
13
+ bash: 'shell', powershell: 'shell', read: 'read', write: 'write', edit: 'edit', multiedit: 'edit', patch: 'patch', apply_patch: 'patch',
14
+ list: 'list', ls: 'list', glob: 'glob', find: 'glob', grep: 'grep', webfetch: 'web_fetch', websearch: 'web_search', codesearch: 'web_search',
15
+ todowrite: 'todo', todoread: 'todo', task: 'task', question: 'question', plan_enter: 'plan', plan_exit: 'plan',
16
+ }));
17
+ const kindOf = (name) => KIND.get(name) ?? (name.includes('_') ? 'mcp' : 'other');
18
+ const FINISH_V2 = new Map([['stop', 'stop'], ['tool-calls', 'tool_calls'], ['length', 'length'], ['error', 'error']]);
19
+ const FINISH_V1 = new Map([['stop', 'stop'], ['tool_calls', 'tool-calls'], ['length', 'length'], ['error', 'error']]);
20
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
21
+ const str = (v) => (typeof v === 'string' ? v : undefined);
22
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
23
+ const own = (o, k) => (Object.hasOwn(o, k) ? o[k] : undefined);
24
+ const define = (o, k, v) => Object.defineProperty(o, k, { value: v, enumerable: true, writable: true, configurable: true });
25
+ const iso = (ms) => (num(ms) !== undefined && Math.abs(ms) <= 8.64e15 ? new Date(ms).toISOString() : null);
26
+ const msOf = (s) => {
27
+ const t = s ? Date.parse(s) : NaN;
28
+ return Number.isNaN(t) ? undefined : t;
29
+ };
30
+ // ─── V1Change ────────────────────────────────────────────────────────────────
31
+ /** Deep equality of JSON values; key order and `undefined` members do not count. */
32
+ function same(a, b) {
33
+ if (a === b)
34
+ return true;
35
+ if (Array.isArray(a) || Array.isArray(b))
36
+ return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((x, i) => same(x, b[i]));
37
+ if (!isObj(a) || !isObj(b))
38
+ return false;
39
+ const ka = Object.keys(a).filter((k) => a[k] !== undefined);
40
+ return ka.length === Object.keys(b).filter((k) => b[k] !== undefined).length && ka.every((k) => same(a[k], own(b, k)));
41
+ }
42
+ /** The change that turns `built` into `stored`; undefined when they are equal. Arrays change whole. */
43
+ function diff(stored, built) {
44
+ if (same(stored, built))
45
+ return undefined;
46
+ if (stored === undefined)
47
+ return { del: true };
48
+ if (!isObj(stored) || !isObj(built))
49
+ return { set: stored };
50
+ const sub = {};
51
+ for (const k of new Set([...Object.keys(stored), ...Object.keys(built)])) {
52
+ const change = diff(own(stored, k), own(built, k));
53
+ if (change)
54
+ define(sub, k, change);
55
+ }
56
+ return { sub };
57
+ }
58
+ function apply(built, change) {
59
+ if (!change)
60
+ return built;
61
+ if ('set' in change)
62
+ return change.set;
63
+ if ('del' in change)
64
+ return undefined;
65
+ const out = isObj(built) ? { ...built } : {};
66
+ for (const [k, c] of Object.entries(change.sub)) {
67
+ const v = apply(own(out, k), c);
68
+ if (v === undefined)
69
+ delete out[k];
70
+ else
71
+ define(out, k, v);
72
+ }
73
+ return out;
74
+ }
75
+ /** The ext entry `fromV1` writes, whatever harness keys it. */
76
+ const v1Ext = (ext) => Object.values(ext ?? {}).find((e) => e.version === KORTIX_TRANSCRIPT_SCHEMA);
77
+ const extOf = (h, entry) => ({ [h]: { version: KORTIX_TRANSCRIPT_SCHEMA, ...entry } });
78
+ // ─── v2 -> v1 builders (shared by toV1 and by fromV1's residual) ─────────────
79
+ /**
80
+ * The v1 url of an attachment: the one it came with, else (native records only) its object ref.
81
+ * A v1-derived block keeps exactly the url its part had: an adapter sets `ref` after `fromV1`
82
+ * (P2.6), and the stored part has no url for it.
83
+ */
84
+ const urlOf = (a, c) => a.url !== undefined ? { url: a.url } : a.ref !== undefined && !c.fromV1 ? { url: a.ref } : {};
85
+ const textOf = (content) => (content ?? []).flatMap((c) => (c.type === 'text' ? [c.text] : [])).join('');
86
+ const head = (b, c) => ({ id: b.id, ...(c.sessionID !== null && { sessionID: c.sessionID }), messageID: c.messageID });
87
+ function toolState(b, c, base) {
88
+ const r = b.result;
89
+ const input = b.input === null || b.input === undefined ? {} : { input: b.input };
90
+ const start = msOf(b.started_at) ?? c.created;
91
+ const end = msOf(b.ended_at) ?? start;
92
+ const meta = r?.exit_code !== undefined ? { exit: r.exit_code } : {};
93
+ if (b.status === 'pending')
94
+ return { status: 'pending', input: b.input ?? {}, raw: '' };
95
+ if (b.status === 'running')
96
+ return { status: 'running', input: b.input ?? {}, ...(b.title && { title: b.title }), time: { start } };
97
+ if (b.status === 'error')
98
+ return { status: 'error', ...input, error: textOf(r?.content), ...(r?.exit_code !== undefined && { metadata: meta }), time: { start, end } };
99
+ const atts = (r?.content ?? []).flatMap((x, i) => x.type === 'attachment' ? [{ ...base, id: `${b.id}-a${i}`, type: 'file', mime: x.mime, ...urlOf(x, c) }] : []);
100
+ const compacted = msOf(r?.cleared_at);
101
+ return {
102
+ status: 'completed', ...input, output: textOf(r?.content), title: b.title ?? '', metadata: meta,
103
+ time: { start, end, ...(compacted !== undefined && { compacted }) },
104
+ ...(atts.length && { attachments: atts }),
105
+ };
106
+ }
107
+ /** A v1 part for one block; undefined for a block v1 cannot hold. */
108
+ function partOf(b, c) {
109
+ const base = head(b, c);
110
+ switch (b.type) {
111
+ case 'text': return { ...base, type: 'text', text: b.text, ...(b.synthetic !== undefined && { synthetic: b.synthetic }) };
112
+ case 'reasoning': return { ...base, type: 'reasoning', text: b.text, time: { start: c.created } };
113
+ case 'attachment': return { ...base, type: 'file', mime: b.mime, ...(b.name !== undefined && { filename: b.name }), ...urlOf(b, c) };
114
+ case 'tool_call': return { ...base, type: 'tool', callID: b.call_id, tool: b.name, state: toolState(b, c, { ...(c.sessionID !== null && { sessionID: c.sessionID }), messageID: c.messageID }) };
115
+ case 'step': return b.phase === 'start'
116
+ ? { ...base, type: 'step-start' }
117
+ : { ...base, type: 'step-finish', reason: 'stop', cost: 0, tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } } };
118
+ case 'compaction': return {
119
+ ...base, type: 'compaction', auto: b.trigger === 'auto' || b.trigger === 'overflow',
120
+ ...(b.trigger === 'overflow' && { overflow: true }), ...(b.first_kept_message_id !== null && { tail_start_id: b.first_kept_message_id }),
121
+ };
122
+ case 'harness':
123
+ if (c.fromV1 && (b.harness === 'opencode' || b.harness === 'pi'))
124
+ return b.data;
125
+ return b.model_visible && b.fallback_text !== undefined ? { ...base, type: 'text', text: b.fallback_text, synthetic: true } : undefined;
126
+ case 'subtask': return undefined;
127
+ }
128
+ }
129
+ /** A v1 error from a v2 one: a `TurnErrorCode` goes to `code` (the class name to `name`), any other code is the class name. */
130
+ function errorV1(e) {
131
+ if (!isTurnErrorCode(e.code))
132
+ return { name: e.code, data: { message: e.message } };
133
+ return { name: e.code === 'aborted' ? 'MessageAbortedError' : 'UnknownError', code: e.code, data: { message: e.message } };
134
+ }
135
+ function assistantInfo(m, c, over = {}) {
136
+ const u = m.usage;
137
+ const finish = m.finish === null ? undefined : FINISH_V1.get(m.finish);
138
+ return {
139
+ id: m.message_id, ...(c.sessionID !== null && { sessionID: c.sessionID }), role: 'assistant',
140
+ time: { created: c.created, ...(m.completed_at !== null && { completed: msOf(m.completed_at) }) },
141
+ ...(m.reply_to && { parentID: m.reply_to }),
142
+ modelID: m.model?.model ?? '', providerID: m.model?.provider ?? '', ...(m.model?.variant !== undefined && { variant: m.model.variant }),
143
+ mode: m.agent ?? '', agent: m.agent ?? '', path: { cwd: '', root: '' },
144
+ cost: u?.cost ?? 0, tokens: { input: u?.input ?? 0, output: u?.output ?? 0, reasoning: u?.reasoning ?? 0, cache: { read: u?.cache_read ?? 0, write: u?.cache_write ?? 0 } },
145
+ ...(finish && { finish }), ...(m.error && { error: errorV1(m.error) }),
146
+ ...over,
147
+ };
148
+ }
149
+ function infoOf(m, c) {
150
+ if (m.role === 'assistant')
151
+ return assistantInfo(m, c);
152
+ return {
153
+ id: m.message_id, ...(c.sessionID !== null && { sessionID: c.sessionID }), role: 'user', time: { created: c.created },
154
+ agent: m.agent ?? '', model: { providerID: m.model?.provider ?? '', modelID: m.model?.model ?? '', ...(m.model?.variant !== undefined && { variant: m.model.variant }) },
155
+ };
156
+ }
157
+ /** The assistant message OpenCode and pi store after a compaction marker. */
158
+ function summaryOf(m, cb, c) {
159
+ const id = `${m.message_id}-summary`;
160
+ const info = assistantInfo({ ...m, reply_to: m.message_id, agent: 'compaction', finish: m.status === 'complete' ? 'stop' : null }, c, { id, summary: true });
161
+ return { info, parts: [{ id: `${id}-p0`, ...(c.sessionID !== null && { sessionID: c.sessionID }), messageID: id, type: 'text', text: cb.summary }] };
162
+ }
163
+ /** `v1Thread`: the thread carries the `kortix.transcript.v1` ext every `fromV1` thread gets. */
164
+ function rowsOf(m, threadNative, v1Thread) {
165
+ const v1 = v1Thread || m.producer.harness === IMPORT;
166
+ if (!v1 && (m.role === 'system' || m.kind === 'context'))
167
+ return [];
168
+ const d = v1Ext(m.ext)?.data;
169
+ const sessionID = d && 'runtime_session_id' in d ? d.runtime_session_id ?? null : threadNative;
170
+ const c = { sessionID, messageID: m.message_id, created: msOf(m.created_at), fromV1: v1 };
171
+ const parts = d && 'parts' in d
172
+ ? d.parts
173
+ : m.blocks.flatMap((b) => {
174
+ const p = partOf(b, c);
175
+ return p === undefined ? [] : [apply(p, v1Ext(b.ext)?.data)];
176
+ });
177
+ const rows = [{ runtime_session_id: sessionID, info: apply(infoOf(m, c), d?.info), parts }];
178
+ const cb = m.blocks.find((b) => b.type === 'compaction');
179
+ if (m.kind === 'compaction' && cb && cb.summary !== null) {
180
+ const s = apply(summaryOf(m, cb, c), d?.summary);
181
+ rows.push({ runtime_session_id: sessionID, info: s.info, parts: s.parts });
182
+ }
183
+ return rows;
184
+ }
185
+ const created = (r) => num(isObj(r.info) && isObj(r.info.time) ? r.info.time.created : undefined) ?? -Infinity;
186
+ const idOf = (r) => String(isObj(r.info) ? r.info.id : '');
187
+ /** The mirror's order, ascending: `(message_created_at NULLS FIRST, message_id)`. */
188
+ const rowOrder = (a, b) => created(a) - created(b) || (idOf(a) < idOf(b) ? -1 : idOf(a) > idOf(b) ? 1 : 0);
189
+ const threadNativeOf = (t) => {
190
+ const e = v1Ext(t.ext);
191
+ return e ? e.native_id ?? null : t.thread_id;
192
+ };
193
+ /** v2 -> v1. Exact for a record `fromV1` built; for a native record, the v1 rows an old client renders. */
194
+ export function toV1(input) {
195
+ const log = structuredClone(input);
196
+ const root = log.threads.find((t) => t.parent_thread_id === null) ?? log.threads[0];
197
+ const rows = log.threads.flatMap((t) => t.messages.flatMap((m) => rowsOf(m, threadNativeOf(t), v1Ext(t.ext) !== undefined)));
198
+ const stated = v1Ext(log.ext)?.data;
199
+ const rootId = stated && 'root_id' in stated ? stated.root_id ?? null : root ? threadNativeOf(root) : null;
200
+ return { session_id: log.session_id, root_id: rootId, rows: rows.sort(rowOrder) };
201
+ }
202
+ function modelOf(info) {
203
+ const src = info.role === 'assistant' ? { p: info.providerID, m: info.modelID, v: info.variant } : isObj(info.model) ? { p: info.model.providerID, m: info.model.modelID, v: info.model.variant } : {};
204
+ const provider = str(src.p);
205
+ const model = str(src.m);
206
+ return provider === undefined || model === undefined ? null : { provider, model, ...(str(src.v) !== undefined && { variant: src.v }) };
207
+ }
208
+ function usageOf(info) {
209
+ if (!isObj(info.tokens))
210
+ return null;
211
+ const t = info.tokens;
212
+ const cache = isObj(t.cache) ? t.cache : {};
213
+ return {
214
+ input: num(t.input) ?? 0, output: num(t.output) ?? 0, cache_read: num(cache.read) ?? 0, cache_write: num(cache.write) ?? 0,
215
+ ...(num(t.reasoning) !== undefined && { reasoning: t.reasoning }), ...(num(info.cost) !== undefined && { cost: info.cost }),
216
+ };
217
+ }
218
+ const errorOf = (e) => ({ code: str(e.code) || str(e.name) || 'UnknownError', message: str(isObj(e.data) ? e.data.message : undefined) ?? '' });
219
+ /** F13: a resolved attachment has `ref` and `bytes`; an unresolved one has neither and counts as lost. Both keep the v1 url. */
220
+ function attachment(p, c, lost) {
221
+ const r = c.resolve(p);
222
+ if (!r)
223
+ lost.attachment++;
224
+ return {
225
+ mime: str(p.mime) ?? 'application/octet-stream',
226
+ ...(r && { ref: r.ref, bytes: r.bytes, ...(r.sha256 !== undefined && { sha256: r.sha256 }) }),
227
+ ...(str(p.url) !== undefined && { url: p.url }),
228
+ };
229
+ }
230
+ function toolBlock(p, id, c, lost) {
231
+ const st = p.state;
232
+ const time = isObj(st.time) ? st.time : {};
233
+ if (!isObj(st.input))
234
+ lost.tool_input++;
235
+ const exit = isObj(st.metadata) && num(st.metadata.exit) !== undefined ? { exit_code: st.metadata.exit } : {};
236
+ let status;
237
+ let result;
238
+ if (st.status === 'completed') {
239
+ const atts = (Array.isArray(st.attachments) ? st.attachments : []).filter(isObj).map((a) => {
240
+ const { bytes: _bytes, ...content } = attachment(a, c, lost);
241
+ return { type: 'attachment', ...content };
242
+ });
243
+ const cleared = iso(time.compacted);
244
+ status = 'complete';
245
+ result = {
246
+ content: [...(str(st.output) !== undefined ? [{ type: 'text', text: st.output }] : []), ...atts], is_error: false, ...exit,
247
+ ...(cleared && { model_content: [{ type: 'text', text: CLEARED }], cleared_at: cleared }),
248
+ };
249
+ }
250
+ else if (st.status === 'error') {
251
+ const error = str(st.error);
252
+ status = 'error';
253
+ result = { content: error !== undefined ? [{ type: 'text', text: error }] : [], is_error: true, ...(error !== undefined && { error: { message: error } }), ...exit };
254
+ }
255
+ else {
256
+ // C2 closure rule: a call that never ended, at rest.
257
+ const text = INTERRUPTED[c.h];
258
+ status = 'error';
259
+ result = { content: [{ type: 'text', text }], is_error: true, synthetic: true, error: { code: 'interrupted', message: text } };
260
+ }
261
+ const started = iso(time.start);
262
+ const ended = iso(time.end);
263
+ return {
264
+ type: 'tool_call', id, call_id: p.callID, name: p.tool, kind: kindOf(p.tool), input: st.input ?? null, status, result,
265
+ ...(str(st.title) && { title: st.title }), ...(started && { started_at: started }), ...(ended && { ended_at: ended }),
266
+ };
267
+ }
268
+ function blockOf(p, id, marker, summary, c, lost) {
269
+ const harness = (kind, model_visible = false) => ({
270
+ type: 'harness', id, harness: c.h, kind, data: p, model_visible, ...(model_visible && { fallback_text: SUBTASK_TEXT }),
271
+ });
272
+ if (!isObj(p))
273
+ return harness('unknown');
274
+ switch (p.type) {
275
+ case 'text':
276
+ return typeof p.text !== 'string' || p.ignored === true ? harness('text') : { type: 'text', id, text: p.text, ...(typeof p.synthetic === 'boolean' && { synthetic: p.synthetic }) };
277
+ case 'reasoning':
278
+ return typeof p.text !== 'string' ? harness('reasoning') : { type: 'reasoning', id, text: p.text };
279
+ case 'file': {
280
+ if (p.mime === 'text/plain' || p.mime === 'application/x-directory')
281
+ return harness('file');
282
+ return { type: 'attachment', id, ...attachment(p, c, lost), ...(str(p.filename) !== undefined && { name: p.filename }) };
283
+ }
284
+ case 'tool':
285
+ return typeof p.callID === 'string' && typeof p.tool === 'string' && isObj(p.state) ? toolBlock(p, id, c, lost) : harness('tool');
286
+ case 'step-start':
287
+ case 'step-finish':
288
+ return { type: 'step', id, phase: p.type === 'step-start' ? 'start' : 'finish' };
289
+ case 'compaction': {
290
+ if (p !== marker)
291
+ return harness('compaction');
292
+ const trigger = p.overflow === true ? 'overflow' : p.auto === true ? 'auto' : 'manual';
293
+ return { type: 'compaction', id, summary, first_kept_message_id: str(p.tail_start_id) ?? null, trigger };
294
+ }
295
+ case 'subtask':
296
+ return harness('subtask', true);
297
+ default:
298
+ return harness(str(p.type) || 'unknown');
299
+ }
300
+ }
301
+ /** F2 block ids: the part id; `#<index>` without one; `<id>#<n>` for a repeat (see the module header). */
302
+ function blockIds(parts) {
303
+ const given = parts.map((p, i) => (isObj(p) && typeof p.id === 'string' && p.id ? p.id : `#${i}`));
304
+ const taken = new Set(given);
305
+ const seen = new Set();
306
+ return given.map((id) => {
307
+ if (!seen.has(id)) {
308
+ seen.add(id);
309
+ return id;
310
+ }
311
+ let n = 2;
312
+ while (taken.has(`${id}#${n}`))
313
+ n++;
314
+ taken.add(`${id}#${n}`);
315
+ return `${id}#${n}`;
316
+ });
317
+ }
318
+ function toMessage(row, sum, threadId, seq, superseded, c) {
319
+ const info = isObj(row.info) ? row.info : {};
320
+ const parts = Array.isArray(row.parts) ? row.parts : [];
321
+ const marker = info.role === 'user' ? parts.find((p) => isObj(p) && p.type === 'compaction') : undefined;
322
+ const sInfo = sum && isObj(sum.info) ? sum.info : undefined;
323
+ const role = info.role === 'assistant' || info.role === 'user' ? info.role : 'system';
324
+ const src = marker ? sInfo : role === 'assistant' ? info : undefined; // whose error, completion and usage
325
+ const err = src && isObj(src.error) ? src.error : undefined;
326
+ const aborted = err?.name === 'MessageAbortedError';
327
+ const completedAt = src && isObj(src.time) ? iso(src.time.completed) : null;
328
+ const status = !src ? (marker ? 'interrupted' : 'complete') : err ? (aborted ? 'aborted' : 'error') : completedAt ? 'complete' : 'interrupted';
329
+ const createdAt = iso(isObj(info.time) ? info.time.created : undefined) ?? '';
330
+ const summary = sum ? (Array.isArray(sum.parts) ? sum.parts : []).flatMap((p) => (isObj(p) && p.type === 'text' && typeof p.text === 'string' ? [p.text] : [])).join('') : null;
331
+ const lost = { tool_input: 0, cut_point: 0, attachment: 0 };
332
+ const ids = blockIds(parts);
333
+ // blockIds returns one id per part.
334
+ const blocks = parts.map((p, i) => blockOf(p, ids[i], marker, summary, c, lost));
335
+ // An aborted reply stays in context only with something the model sees: an empty one would replay as an empty turn.
336
+ const visible = blocks.some((b) => b.type === 'text' || b.type === 'attachment' || b.type === 'tool_call' || (b.type === 'harness' && b.model_visible));
337
+ const inContext = !superseded && role !== 'system' && (marker ? status === 'complete' : !err || (aborted && visible));
338
+ // A compaction whose summary never arrived (or never finished) has no reason: nobody stopped it, nothing failed.
339
+ const hidden = superseded ? 'superseded' : inContext || !err ? undefined : aborted ? 'aborted' : 'failed_attempt';
340
+ if (marker && isObj(marker) && str(marker.tail_start_id) === undefined)
341
+ lost.cut_point++;
342
+ const m = {
343
+ ...V, message_id: str(info.id) ?? '', thread_id: threadId, seq, role, kind: marker ? 'compaction' : 'turn', status, in_context: inContext,
344
+ ...(hidden && { hidden_reason: hidden }),
345
+ agent: str(info.agent) ?? null,
346
+ ...(role === 'assistant' && { reply_to: str(info.parentID) ?? null }),
347
+ model: modelOf(info), usage: src ? usageOf(src) : null,
348
+ finish: !src || marker ? null : aborted ? 'aborted' : err ? 'error' : FINISH_V2.get(info.finish) ?? null,
349
+ error: err ? errorOf(err) : null,
350
+ created_at: createdAt, completed_at: src || marker ? completedAt : createdAt || null,
351
+ producer: PRODUCER, blocks,
352
+ };
353
+ return { m, lost };
354
+ }
355
+ /** Stores, on the message and its blocks, what `rowsOf` needs to rebuild the stored rows exactly. */
356
+ function keepResidual(m, row, sum, threadNative, h) {
357
+ const data = {};
358
+ if (row.runtime_session_id !== threadNative)
359
+ data.runtime_session_id = row.runtime_session_id;
360
+ const c = { sessionID: row.runtime_session_id, messageID: m.message_id, created: msOf(m.created_at), fromV1: true };
361
+ if (Array.isArray(row.parts)) {
362
+ m.blocks.forEach((b, i) => {
363
+ if (b.type === 'harness' || b.type === 'subtask')
364
+ return;
365
+ const change = diff(row.parts[i], partOf(b, c));
366
+ if (change)
367
+ b.ext = extOf(h, { data: change });
368
+ });
369
+ }
370
+ else
371
+ data.parts = row.parts;
372
+ const info = diff(row.info, infoOf(m, c));
373
+ if (info)
374
+ data.info = info;
375
+ const cb = m.blocks.find((b) => b.type === 'compaction');
376
+ if (sum && cb) {
377
+ const change = diff({ info: sum.info, parts: sum.parts }, summaryOf(m, cb, c));
378
+ if (change)
379
+ data.summary = change;
380
+ }
381
+ if (Object.keys(data).length)
382
+ m.ext = extOf(h, { data });
383
+ }
384
+ /**
385
+ * The first tool call that names runtime session `id`: by `state.metadata.sessionId`, else anywhere in its state.
386
+ * ponytail: the fallback is a substring match, so a call whose output merely lists an old root's id makes it a
387
+ * child thread (still out of the root's context). The precise rule is `childSessionIdOf` in
388
+ * `apps/api/src/projects/lib/session-transcript-mirror.ts`: hoist it here when a prod row shows a false positive.
389
+ */
390
+ function spawnerOf(rows, id, text) {
391
+ if (!id)
392
+ return undefined; // null or '': a substring match on '' would name every call
393
+ for (const exact of [true, false]) {
394
+ for (const row of rows) {
395
+ if (row.runtime_session_id === id || !Array.isArray(row.parts))
396
+ continue;
397
+ for (const p of row.parts) {
398
+ if (!isObj(p) || p.type !== 'tool' || !isObj(p.state))
399
+ continue;
400
+ if (exact ? isObj(p.state.metadata) && p.state.metadata.sessionId === id : text(p.state).includes(id))
401
+ return { row, part: p };
402
+ }
403
+ }
404
+ }
405
+ return undefined;
406
+ }
407
+ /** v1 mirror -> session log. See the module header for every mapping decision. */
408
+ export function fromV1(v1, options = {}) {
409
+ const c = { h: options.harness ?? 'opencode', resolve: options.resolveAttachment ?? (() => null), counts: { tool_input: 0, cut_point: 0, attachment: 0 } };
410
+ const rows = structuredClone(v1.rows).sort(rowOrder);
411
+ const groups = new Map();
412
+ for (const r of rows) {
413
+ const list = groups.get(r.runtime_session_id);
414
+ if (list)
415
+ list.push(r);
416
+ else
417
+ groups.set(r.runtime_session_id, [r]);
418
+ }
419
+ // A null root, or one that names no row, falls back to the latest row's group (see the module header).
420
+ const stated = v1.root_id;
421
+ const usable = groups.has(stated);
422
+ const texts = new Map();
423
+ const text = (state) => texts.get(state) ?? (texts.set(state, JSON.stringify(state)), texts.get(state));
424
+ const spawners = new Map();
425
+ for (const id of groups.keys()) {
426
+ const s = usable && id === stated ? undefined : spawnerOf(rows, id, text);
427
+ if (s)
428
+ spawners.set(id, s);
429
+ }
430
+ const latest = [...rows].reverse().find((r) => r.runtime_session_id === null || !spawners.has(r.runtime_session_id));
431
+ const root = usable || !latest ? stated : latest.runtime_session_id;
432
+ if (!groups.has(root))
433
+ groups.set(root, []);
434
+ const rootThread = root || v1.session_id;
435
+ const threadOf = (id) => (id !== null && spawners.has(id) ? id : rootThread);
436
+ const sessionCreated = iso(rows.map(created).find(Number.isFinite)) ?? '';
437
+ const threads = [];
438
+ for (const [id, own] of groups) {
439
+ if (id !== root && (id === null || !spawners.has(id)))
440
+ continue; // an old root: merged into the root thread
441
+ const isRoot = id === root;
442
+ const superseded = isRoot ? rows.filter((r) => r.runtime_session_id !== root && threadOf(r.runtime_session_id) === rootThread) : [];
443
+ const list = [...superseded, ...own];
444
+ const old = new Set(superseded);
445
+ // A compaction marker and its summary row, paired before the walk: the summary may sort first.
446
+ const summaries = new Map();
447
+ const paired = new Set();
448
+ for (const row of list) {
449
+ const info = isObj(row.info) ? row.info : {};
450
+ if (info.role !== 'user' || !Array.isArray(row.parts) || !row.parts.some((p) => isObj(p) && p.type === 'compaction'))
451
+ continue;
452
+ const sum = list.find((r) => !paired.has(r) && r.runtime_session_id === row.runtime_session_id && isObj(r.info) && r.info.role === 'assistant' && r.info.summary === true && r.info.parentID === info.id);
453
+ if (!sum)
454
+ continue;
455
+ summaries.set(row, sum);
456
+ paired.add(sum);
457
+ }
458
+ const messages = [];
459
+ for (const row of list) {
460
+ if (paired.has(row))
461
+ continue;
462
+ const sum = summaries.get(row);
463
+ const { m, lost } = toMessage(row, sum, isRoot ? rootThread : id, messages.length + 1, old.has(row), c);
464
+ keepResidual(m, row, sum, id, c.h);
465
+ if (m.in_context)
466
+ for (const k of ['tool_input', 'cut_point', 'attachment'])
467
+ c.counts[k] += lost[k];
468
+ messages.push(m);
469
+ }
470
+ const spawn = id === null ? undefined : spawners.get(id);
471
+ const firstUser = messages.find((m) => m.role === 'user' && m.kind === 'turn');
472
+ threads.push({
473
+ ...V, thread_id: isRoot ? rootThread : id,
474
+ parent_thread_id: spawn ? threadOf(spawn.row.runtime_session_id) : null,
475
+ spawned_by: spawn && typeof spawn.part.callID === 'string' ? { message_id: str(spawn.row.info?.id) ?? '', call_id: spawn.part.callID } : null,
476
+ agent: firstUser?.agent ?? null, title: null, created_at: messages[0]?.created_at || sessionCreated, messages,
477
+ ext: extOf(c.h, id === null ? {} : { native_id: id }),
478
+ });
479
+ }
480
+ threads.sort((a, b) => (a.parent_thread_id === null ? -1 : b.parent_thread_id === null ? 1 : rowsIndex(a) - rowsIndex(b)));
481
+ const lastUser = threads[0]?.messages.filter((m) => m.role === 'user' && m.kind === 'turn').at(-1);
482
+ const partial = c.counts.tool_input + c.counts.cut_point + c.counts.attachment > 0;
483
+ return {
484
+ ...V, session_id: v1.session_id, title: null, created_at: sessionCreated,
485
+ restore_grade: partial ? 'partial' : 'converted', grade_counts: c.counts,
486
+ harness: { current: c.h, history: [] },
487
+ selection: { agent: lastUser?.agent ?? null, model: lastUser?.model ?? null },
488
+ todos: [], pending: { questions: [], permissions: [] }, threads,
489
+ ...(root !== stated && { ext: extOf(c.h, { data: { root_id: stated } }) }),
490
+ };
491
+ function rowsIndex(t) {
492
+ return rows.findIndex((r) => r.runtime_session_id === t.thread_id);
493
+ }
494
+ }
495
+ //# sourceMappingURL=v1.js.map