@kortix/sdk 0.13.28 → 0.13.30

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 (164) hide show
  1. package/dist/core/client/kortix.d.ts +4 -0
  2. package/dist/core/client/kortix.d.ts.map +1 -1
  3. package/dist/core/client/kortix.js +32 -1
  4. package/dist/core/client/kortix.js.map +1 -1
  5. package/dist/core/http/api-client.js.map +1 -1
  6. package/dist/core/rest/projects-client/accounts.d.ts +5 -0
  7. package/dist/core/rest/projects-client/accounts.d.ts.map +1 -1
  8. package/dist/core/rest/projects-client/accounts.js.map +1 -1
  9. package/dist/core/rest/projects-client/agent-config.d.ts +8 -0
  10. package/dist/core/rest/projects-client/agent-config.d.ts.map +1 -1
  11. package/dist/core/rest/projects-client/agent-config.js.map +1 -1
  12. package/dist/core/rest/projects-client/apps.d.ts +14 -0
  13. package/dist/core/rest/projects-client/apps.d.ts.map +1 -1
  14. package/dist/core/rest/projects-client/apps.js +4 -0
  15. package/dist/core/rest/projects-client/apps.js.map +1 -1
  16. package/dist/core/rest/projects-client/audit.d.ts +4 -0
  17. package/dist/core/rest/projects-client/audit.d.ts.map +1 -1
  18. package/dist/core/rest/projects-client/audit.js.map +1 -1
  19. package/dist/core/rest/projects-client/gateway.d.ts +4 -8
  20. package/dist/core/rest/projects-client/gateway.d.ts.map +1 -1
  21. package/dist/core/rest/projects-client/gateway.js.map +1 -1
  22. package/dist/core/rest/projects-client/iam.d.ts +16 -0
  23. package/dist/core/rest/projects-client/iam.d.ts.map +1 -1
  24. package/dist/core/rest/projects-client/iam.js +7 -0
  25. package/dist/core/rest/projects-client/iam.js.map +1 -1
  26. package/dist/core/rest/projects-client/index.d.ts +1 -0
  27. package/dist/core/rest/projects-client/index.d.ts.map +1 -1
  28. package/dist/core/rest/projects-client/index.js +1 -0
  29. package/dist/core/rest/projects-client/index.js.map +1 -1
  30. package/dist/core/rest/projects-client/projects.d.ts +15 -1
  31. package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
  32. package/dist/core/rest/projects-client/projects.js +1 -0
  33. package/dist/core/rest/projects-client/projects.js.map +1 -1
  34. package/dist/core/rest/projects-client/review-items.d.ts +173 -0
  35. package/dist/core/rest/projects-client/review-items.d.ts.map +1 -0
  36. package/dist/core/rest/projects-client/review-items.js +260 -0
  37. package/dist/core/rest/projects-client/review-items.js.map +1 -0
  38. package/dist/core/rest/projects-client/session-costs.d.ts +7 -9
  39. package/dist/core/rest/projects-client/session-costs.d.ts.map +1 -1
  40. package/dist/core/rest/projects-client/session-costs.js.map +1 -1
  41. package/dist/core/turns/index.d.ts +3 -0
  42. package/dist/core/turns/index.d.ts.map +1 -1
  43. package/dist/core/turns/index.js +2 -0
  44. package/dist/core/turns/index.js.map +1 -1
  45. package/dist/core/turns/segments/burst-summary.d.ts +49 -0
  46. package/dist/core/turns/segments/burst-summary.d.ts.map +1 -0
  47. package/dist/core/turns/segments/burst-summary.js +64 -0
  48. package/dist/core/turns/segments/burst-summary.js.map +1 -0
  49. package/dist/core/turns/segments/compaction-state.d.ts +44 -0
  50. package/dist/core/turns/segments/compaction-state.d.ts.map +1 -0
  51. package/dist/core/turns/segments/compaction-state.js +79 -0
  52. package/dist/core/turns/segments/compaction-state.js.map +1 -0
  53. package/dist/core/turns/segments/group-steps.d.ts +22 -0
  54. package/dist/core/turns/segments/group-steps.d.ts.map +1 -0
  55. package/dist/core/turns/segments/group-steps.js +89 -0
  56. package/dist/core/turns/segments/group-steps.js.map +1 -0
  57. package/dist/core/turns/segments/index.d.ts +21 -0
  58. package/dist/core/turns/segments/index.d.ts.map +1 -0
  59. package/dist/core/turns/segments/index.js +21 -0
  60. package/dist/core/turns/segments/index.js.map +1 -0
  61. package/dist/core/turns/segments/merge-steps.d.ts +79 -0
  62. package/dist/core/turns/segments/merge-steps.d.ts.map +1 -0
  63. package/dist/core/turns/segments/merge-steps.js +190 -0
  64. package/dist/core/turns/segments/merge-steps.js.map +1 -0
  65. package/dist/core/turns/segments/message-time.d.ts +86 -0
  66. package/dist/core/turns/segments/message-time.d.ts.map +1 -0
  67. package/dist/core/turns/segments/message-time.js +196 -0
  68. package/dist/core/turns/segments/message-time.js.map +1 -0
  69. package/dist/core/turns/segments/narration.d.ts +71 -0
  70. package/dist/core/turns/segments/narration.d.ts.map +1 -0
  71. package/dist/core/turns/segments/narration.js +836 -0
  72. package/dist/core/turns/segments/narration.js.map +1 -0
  73. package/dist/core/turns/segments/segment-turn.d.ts +26 -0
  74. package/dist/core/turns/segments/segment-turn.d.ts.map +1 -0
  75. package/dist/core/turns/segments/segment-turn.js +36 -0
  76. package/dist/core/turns/segments/segment-turn.js.map +1 -0
  77. package/dist/core/turns/segments/session-activity-groups.d.ts +93 -0
  78. package/dist/core/turns/segments/session-activity-groups.d.ts.map +1 -0
  79. package/dist/core/turns/segments/session-activity-groups.js +127 -0
  80. package/dist/core/turns/segments/session-activity-groups.js.map +1 -0
  81. package/dist/core/turns/segments/step-label.d.ts +44 -0
  82. package/dist/core/turns/segments/step-label.d.ts.map +1 -0
  83. package/dist/core/turns/segments/step-label.js +129 -0
  84. package/dist/core/turns/segments/step-label.js.map +1 -0
  85. package/dist/core/turns/segments/turn-busy-visibility.d.ts +51 -0
  86. package/dist/core/turns/segments/turn-busy-visibility.d.ts.map +1 -0
  87. package/dist/core/turns/segments/turn-busy-visibility.js +47 -0
  88. package/dist/core/turns/segments/turn-busy-visibility.js.map +1 -0
  89. package/dist/core/turns/segments/working-turn.d.ts +165 -0
  90. package/dist/core/turns/segments/working-turn.d.ts.map +1 -0
  91. package/dist/core/turns/segments/working-turn.js +168 -0
  92. package/dist/core/turns/segments/working-turn.js.map +1 -0
  93. package/dist/core/turns/text-scan.d.ts +65 -0
  94. package/dist/core/turns/text-scan.d.ts.map +1 -0
  95. package/dist/core/turns/text-scan.js +344 -0
  96. package/dist/core/turns/text-scan.js.map +1 -0
  97. package/dist/core/turns/tools/agent-helpers.d.ts +10 -0
  98. package/dist/core/turns/tools/agent-helpers.d.ts.map +1 -0
  99. package/dist/core/turns/tools/agent-helpers.js +54 -0
  100. package/dist/core/turns/tools/agent-helpers.js.map +1 -0
  101. package/dist/core/turns/tools/file-verb.d.ts +81 -0
  102. package/dist/core/turns/tools/file-verb.d.ts.map +1 -0
  103. package/dist/core/turns/tools/file-verb.js +70 -0
  104. package/dist/core/turns/tools/file-verb.js.map +1 -0
  105. package/dist/core/turns/tools/index.d.ts +22 -0
  106. package/dist/core/turns/tools/index.d.ts.map +1 -0
  107. package/dist/core/turns/tools/index.js +22 -0
  108. package/dist/core/turns/tools/index.js.map +1 -0
  109. package/dist/core/turns/tools/memory-helpers.d.ts +16 -0
  110. package/dist/core/turns/tools/memory-helpers.d.ts.map +1 -0
  111. package/dist/core/turns/tools/memory-helpers.js +55 -0
  112. package/dist/core/turns/tools/memory-helpers.js.map +1 -0
  113. package/dist/core/turns/tools/patch-summary.d.ts +53 -0
  114. package/dist/core/turns/tools/patch-summary.d.ts.map +1 -0
  115. package/dist/core/turns/tools/patch-summary.js +71 -0
  116. package/dist/core/turns/tools/patch-summary.js.map +1 -0
  117. package/dist/core/turns/tools/presentation-helpers.d.ts +16 -0
  118. package/dist/core/turns/tools/presentation-helpers.d.ts.map +1 -0
  119. package/dist/core/turns/tools/presentation-helpers.js +18 -0
  120. package/dist/core/turns/tools/presentation-helpers.js.map +1 -0
  121. package/dist/core/turns/tools/question-helpers.d.ts +10 -0
  122. package/dist/core/turns/tools/question-helpers.d.ts.map +1 -0
  123. package/dist/core/turns/tools/question-helpers.js +13 -0
  124. package/dist/core/turns/tools/question-helpers.js.map +1 -0
  125. package/dist/core/turns/tools/read-helpers.d.ts +8 -0
  126. package/dist/core/turns/tools/read-helpers.d.ts.map +1 -0
  127. package/dist/core/turns/tools/read-helpers.js +25 -0
  128. package/dist/core/turns/tools/read-helpers.js.map +1 -0
  129. package/dist/core/turns/tools/search-query.d.ts +28 -0
  130. package/dist/core/turns/tools/search-query.d.ts.map +1 -0
  131. package/dist/core/turns/tools/search-query.js +137 -0
  132. package/dist/core/turns/tools/search-query.js.map +1 -0
  133. package/dist/core/turns/tools/show-availability.d.ts +53 -0
  134. package/dist/core/turns/tools/show-availability.d.ts.map +1 -0
  135. package/dist/core/turns/tools/show-availability.js +110 -0
  136. package/dist/core/turns/tools/show-availability.js.map +1 -0
  137. package/dist/core/turns/tools/skill-helpers.d.ts +35 -0
  138. package/dist/core/turns/tools/skill-helpers.d.ts.map +1 -0
  139. package/dist/core/turns/tools/skill-helpers.js +129 -0
  140. package/dist/core/turns/tools/skill-helpers.js.map +1 -0
  141. package/dist/core/turns/tools/tool-meta.d.ts +72 -0
  142. package/dist/core/turns/tools/tool-meta.d.ts.map +1 -0
  143. package/dist/core/turns/tools/tool-meta.js +174 -0
  144. package/dist/core/turns/tools/tool-meta.js.map +1 -0
  145. package/dist/core/turns/tools/tool-outcome.d.ts +78 -0
  146. package/dist/core/turns/tools/tool-outcome.d.ts.map +1 -0
  147. package/dist/core/turns/tools/tool-outcome.js +244 -0
  148. package/dist/core/turns/tools/tool-outcome.js.map +1 -0
  149. package/dist/core/turns/tools/tool-output-format.d.ts +63 -0
  150. package/dist/core/turns/tools/tool-output-format.d.ts.map +1 -0
  151. package/dist/core/turns/tools/tool-output-format.js +174 -0
  152. package/dist/core/turns/tools/tool-output-format.js.map +1 -0
  153. package/dist/core/turns/tools/web-helpers.d.ts +40 -0
  154. package/dist/core/turns/tools/web-helpers.d.ts.map +1 -0
  155. package/dist/core/turns/tools/web-helpers.js +297 -0
  156. package/dist/core/turns/tools/web-helpers.js.map +1 -0
  157. package/dist/kortix.esm.min.js +42 -26
  158. package/dist/kortix.global.js +42 -26
  159. package/dist/react/session-cache-write.d.ts +3 -3
  160. package/dist/react/session-cache-write.d.ts.map +1 -1
  161. package/dist/react/session-cache-write.js +31 -5
  162. package/dist/react/session-cache-write.js.map +1 -1
  163. package/dist/react/sign-in-with-kortix.d.ts +3 -3
  164. package/package.json +2 -2
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Burst parts → the rows a reader actually sees.
3
+ *
4
+ * Three rules, all about reducing the row count rather than the information:
5
+ *
6
+ * 1. Plumbing never appears. Memory reads/writes and context compaction are
7
+ * machinery the reader did not ask for and cannot act on.
8
+ * 2. A run of consecutive thinking collapses into ONE row. The model emits
9
+ * reasoning in fragments; rendering a row per fragment turns a single
10
+ * train of thought into a wall of near-identical lines.
11
+ * 3. A run of consecutive same-family tool calls collapses into ONE group
12
+ * row that opens to its members. Two reads and two commands are two pieces
13
+ * of work, not four; expanding a burst to seven flat siblings un-groups
14
+ * exactly what makes a 60-call run readable.
15
+ *
16
+ * A thought row also carries whether IT is the one still being written. That
17
+ * cannot be answered by the burst around it: a trailing burst reports "running"
18
+ * for the whole turn on purpose (so the disclosure does not blink shut between
19
+ * SSE tool calls), so a burst-wide flag makes every thought a turn ever emitted
20
+ * claim to be live — shimmering, and forcing its paragraph open, twenty steps
21
+ * after it closed. See `reasoningIsRunning` and the settle pass at the end of
22
+ * `mergeBurstSteps`.
23
+ *
24
+ * Rule 3 reuses `groupSteps` — the same model the Easy action panel renders
25
+ * from — rather than restating the family table here. There is one grouping
26
+ * implementation; two that must agree forever is the trap this avoids.
27
+ *
28
+ * No React import — every rule here is unit-tested.
29
+ */
30
+ import { isReasoningPart, isToolPart } from '../parts.js';
31
+ import { groupSteps } from './group-steps.js';
32
+ /**
33
+ * True while the model is still writing this reasoning fragment.
34
+ *
35
+ * A closed reasoning block carries `time.end`; an open one has a start and
36
+ * nothing else. Exported so `burstIsRunning` asks the same question in the same
37
+ * words — two copies of this predicate is exactly how a burst and the rows
38
+ * inside it end up disagreeing about who is still working.
39
+ */
40
+ export function reasoningIsRunning(part) {
41
+ const end = part.time?.end;
42
+ return !(typeof end === 'number' && end > 0);
43
+ }
44
+ /**
45
+ * `tierOf` is injected rather than imported so the merge rules can be tested
46
+ * without dragging the whole tool-name table in behind them.
47
+ */
48
+ export function mergeBurstSteps(parts, tierOf) {
49
+ const steps = [];
50
+ let pending = null;
51
+ let tools = [];
52
+ const flushThought = () => {
53
+ if (pending && pending.texts.length > 0) {
54
+ // FIRST start to LAST end: the fragments of one thought are one stretch
55
+ // of thinking, and the row that merges them reports the stretch. A sum of
56
+ // per-fragment durations would silently drop the gaps between them.
57
+ const { startedAt, endedAt } = pending;
58
+ const durationMs = typeof startedAt === 'number' && typeof endedAt === 'number' && endedAt > startedAt
59
+ ? endedAt - startedAt
60
+ : undefined;
61
+ steps.push({
62
+ kind: 'thought',
63
+ key: pending.key,
64
+ texts: pending.texts,
65
+ running: pending.running,
66
+ durationMs,
67
+ });
68
+ }
69
+ pending = null;
70
+ };
71
+ /**
72
+ * The buffered run → its group rows, in order.
73
+ *
74
+ * A group of one is NOT wrapped. An expandable row holding a single call
75
+ * hides that call behind a click and says nothing the call did not already
76
+ * say — strictly worse than the flat row it replaced.
77
+ */
78
+ const flushTools = () => {
79
+ if (tools.length === 0)
80
+ return;
81
+ for (const step of groupSteps(tools)) {
82
+ steps.push(step.parts.length === 1
83
+ ? { kind: 'part', key: step.parts[0].id, part: step.parts[0] }
84
+ : { kind: 'group', key: `group-${step.parts[0].id}`, step });
85
+ }
86
+ tools = [];
87
+ };
88
+ for (const part of parts) {
89
+ // Machinery is dropped outright, and — importantly — without breaking the
90
+ // run around it, thinking or tool. A memory write between two thoughts
91
+ // should not split them into two rows, and one between two shells should
92
+ // not split "Ran 2 commands" into two singles.
93
+ if (tierOf(part) === 'plumbing')
94
+ continue;
95
+ if (isReasoningPart(part)) {
96
+ // Read the text before flushing: an empty fragment renders nothing, so
97
+ // it must not break the tool run it happens to sit inside either.
98
+ const text = part.text?.trim();
99
+ if (!text)
100
+ continue;
101
+ flushTools();
102
+ if (!pending)
103
+ pending = { key: `thought-${part.id}`, texts: [], running: false };
104
+ pending.texts.push(text);
105
+ const time = part.time;
106
+ if (pending.startedAt === undefined && typeof time?.start === 'number') {
107
+ pending.startedAt = time.start;
108
+ }
109
+ // The LAST fragment's end is the run's end, for the same reason it
110
+ // decides `running` below: an earlier fragment closes as the next opens.
111
+ pending.endedAt = typeof time?.end === 'number' && time.end > 0 ? time.end : undefined;
112
+ // The LAST fragment decides. Fragments arrive one at a time and each
113
+ // closes as the next opens, so an early `time.end` says nothing about
114
+ // whether the run as a whole is still being written.
115
+ pending.running = reasoningIsRunning(part);
116
+ continue;
117
+ }
118
+ flushThought();
119
+ if (isToolPart(part)) {
120
+ tools.push(part);
121
+ continue;
122
+ }
123
+ // Neither tool nor reasoning. `groupSteps` has no family for it and
124
+ // `ActivityStep` renders it as a bare label row — but it is still a part,
125
+ // and this module never silently drops one.
126
+ flushTools();
127
+ steps.push({ kind: 'part', key: part.id, part });
128
+ }
129
+ flushThought();
130
+ flushTools();
131
+ /**
132
+ * Only the final row can still be live.
133
+ *
134
+ * `time.end` is the provider's answer and this is the structural one: the
135
+ * model cannot call a tool and then keep writing the same reasoning block —
136
+ * more reasoning after the tool arrives as a NEW row. So a thought with any
137
+ * later step is finished, whatever its own timestamps say, and the rule holds
138
+ * even against a provider that never writes `time.end` at all.
139
+ *
140
+ * Dropped plumbing is not a later step: it renders no row, so it is no
141
+ * evidence the model stopped thinking.
142
+ */
143
+ for (let i = 0; i < steps.length - 1; i++) {
144
+ const step = steps[i];
145
+ if (step.kind === 'thought')
146
+ step.running = false;
147
+ }
148
+ return steps;
149
+ }
150
+ /** Words that already announce a thought, so the prefix would double up. */
151
+ const ALREADY_THINKING = /^(thinking|thought|considering|planning|deciding|weighing|exploring|analy[sz]ing|reasoning|working out|figuring)/i;
152
+ /** Markdown that carries no meaning once the block becomes a single sentence. */
153
+ function stripMarkdown(text) {
154
+ return text
155
+ .replace(/```[\s\S]*?```/g, ' ')
156
+ .replace(/`([^`]*)`/g, '$1')
157
+ .replace(/^#{1,6}\s*/gm, '')
158
+ .replace(/\*\*([^*]*)\*\*/g, '$1')
159
+ .replace(/(^|\s)[*_]([^*_]+)[*_]/g, '$1$2')
160
+ .replace(/^\s*[-*+]\s+/gm, '')
161
+ .replace(/\s+/g, ' ')
162
+ .trim();
163
+ }
164
+ /**
165
+ * A run of thinking fragments → the one sentence the row shows.
166
+ *
167
+ * Fragments are joined, stripped of document markup, and given a "Thinking
168
+ * about" lead-in — unless they already open with a thinking verb, where the
169
+ * prefix would read as a stutter ("Thinking about thinking about…").
170
+ */
171
+ export function flattenThought(texts) {
172
+ const joined = texts
173
+ .flatMap((text) => {
174
+ const stripped = stripMarkdown(text);
175
+ return stripped ? [stripped] : [];
176
+ })
177
+ .join(' ')
178
+ .trim();
179
+ if (!joined)
180
+ return 'Thinking';
181
+ if (ALREADY_THINKING.test(joined))
182
+ return joined;
183
+ // Lower-case the lead-in so it reads as one sentence — but only when the
184
+ // opening word is ordinary sentence case. Lowering "API" to "aPI" would be
185
+ // worse than the capital it replaced.
186
+ const isSentenceCased = /^[A-Z][a-z]/.test(joined);
187
+ const body = isSentenceCased ? joined[0].toLowerCase() + joined.slice(1) : joined;
188
+ return `Thinking about ${body}`;
189
+ }
190
+ //# sourceMappingURL=merge-steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-steps.js","sourceRoot":"","sources":["../../../../src/core/turns/segments/merge-steps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AAuBtD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAU;IAC3C,MAAM,GAAG,GAAI,IAAoC,CAAC,IAAI,EAAE,GAAG,CAAC;IAC5D,OAAO,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,KAA0B,EAC1B,MAAgC;IAEhC,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,IAAI,OAAO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AAM,GAAG,KAAK;SACjB,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC;SACT,IAAI,EAAE,CAAC;IAEV,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC;IAC/B,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAEjD,yEAAyE;IACzE,2EAA2E;IAC3E,sCAAsC;IACtC,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAClF,OAAO,kBAAkB,IAAI,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * When a message was sent, in the two registers a reader actually wants.
3
+ *
4
+ * **The label says how long ago. The hint says exactly when.** Recent messages
5
+ * are easiest to place by distance — "5 days ago" lands immediately, where a
6
+ * date makes you do arithmetic. Past a week that inverts: nobody counts to
7
+ * "23 days ago", so the label becomes the date itself. The precise instant,
8
+ * down to the second, lives one hover away and never clutters the thread.
9
+ *
10
+ * `now` is injected, never read here. Same reason the sibling
11
+ * `session-turn-meta-rows` does it: the wording is a pure function of two
12
+ * instants, so it stays testable, and one render derives every label from a
13
+ * single clock read instead of each row racing its own.
14
+ */
15
+ import type { MessageWithParts } from '../../../transcript.js';
16
+ /**
17
+ * `Message` is a union whose user and assistant arms carry different `time`
18
+ * shapes, and neither is on the shared `info` type — so `info.time` does not
19
+ * typecheck against the union. This narrow accessor is the one place that cast
20
+ * lives; `session-turn-meta-rows` imports it rather than keeping a second copy.
21
+ */
22
+ export declare function messageTime(message: MessageWithParts | undefined): {
23
+ created?: number;
24
+ completed?: number;
25
+ };
26
+ /**
27
+ * When the message was created, in epoch **milliseconds**, or `null` when the
28
+ * backend never stamped one.
29
+ *
30
+ * Milliseconds is not an assumption: `packages/sdk/src/transcript.ts` feeds the
31
+ * same field straight to `new Date(...)` with no `* 1000`, and hands
32
+ * `time.completed - time.created` to a `formatDuration(ms)`.
33
+ *
34
+ * `0` is rejected along with `NaN`: the epoch is not a plausible message time,
35
+ * so a zeroed field is missing data, not midnight in 1970.
36
+ */
37
+ export declare function messageCreatedAt(message: MessageWithParts | undefined): number | null;
38
+ export interface MessageTimeOptions {
39
+ /**
40
+ * IANA zone to render in. Omit for the viewer's own zone — which is what the
41
+ * browser should use, and exactly what a server render must NOT, since the
42
+ * server's zone is its own and the resulting text would not survive
43
+ * hydration.
44
+ */
45
+ timeZone?: string;
46
+ /**
47
+ * BCP-47 locale. Omit for the viewer's own — it decides 12- vs 24-hour, which
48
+ * is the whole reason not to hardcode `en-US` on the client.
49
+ */
50
+ locale?: string;
51
+ }
52
+ /**
53
+ * The label on screen.
54
+ *
55
+ * | When | Reads as (`en-US`) |
56
+ * | --------------- | ------------------ |
57
+ * | under a minute | `just now` |
58
+ * | under a week | `5 days ago` |
59
+ * | this year | `June 9` |
60
+ * | any older | `June 9, 2025` |
61
+ *
62
+ * Strict distance (`relativePast`) rather than a loose one: it never rounds up
63
+ * into a vague "about 1 minute", and the point of the label is a real
64
+ * distance, not an impression.
65
+ *
66
+ * `now` is `null` for a server render, where distance is unknowable: the
67
+ * server cannot know the viewer's clock, and guessing produces text that
68
+ * changes on hydration. `null` returns the dated form instead, so the string
69
+ * shown before hydration is never *wrong* — only less immediate than it will be.
70
+ *
71
+ * Returns `''` for a timestamp that is absent or unparseable, so the caller can
72
+ * render nothing rather than an `Invalid Date` placeholder.
73
+ */
74
+ export declare function formatMessageDay(timestamp: number | null | undefined, now: number | null, opts?: MessageTimeOptions): string;
75
+ /**
76
+ * The hover label: the full date and the time of day. `June 9, 2026 2:32 PM`.
77
+ *
78
+ * This is where the specifics belong. The label on screen is deliberately
79
+ * loose so the thread stays readable; hovering answers "when exactly" without
80
+ * that answer ever taking up room in the transcript.
81
+ *
82
+ * Minutes, not seconds. A second-level reading looks like it is worth reading
83
+ * and never is — nobody hovers a chat message to learn it landed at :05.
84
+ */
85
+ export declare function formatMessageExact(timestamp: number | null | undefined, opts?: MessageTimeOptions): string;
86
+ //# sourceMappingURL=message-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-time.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/segments/message-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAIA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIrF;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAoHD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,IAAI,GAAE,kBAAuB,GAC5B,MAAM,CAoBR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,IAAI,GAAE,kBAAuB,GAC5B,MAAM,CAMR"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * When a message was sent, in the two registers a reader actually wants.
3
+ *
4
+ * **The label says how long ago. The hint says exactly when.** Recent messages
5
+ * are easiest to place by distance — "5 days ago" lands immediately, where a
6
+ * date makes you do arithmetic. Past a week that inverts: nobody counts to
7
+ * "23 days ago", so the label becomes the date itself. The precise instant,
8
+ * down to the second, lives one hover away and never clutters the thread.
9
+ *
10
+ * `now` is injected, never read here. Same reason the sibling
11
+ * `session-turn-meta-rows` does it: the wording is a pure function of two
12
+ * instants, so it stays testable, and one render derives every label from a
13
+ * single clock read instead of each row racing its own.
14
+ */
15
+ /**
16
+ * `Message` is a union whose user and assistant arms carry different `time`
17
+ * shapes, and neither is on the shared `info` type — so `info.time` does not
18
+ * typecheck against the union. This narrow accessor is the one place that cast
19
+ * lives; `session-turn-meta-rows` imports it rather than keeping a second copy.
20
+ */
21
+ export function messageTime(message) {
22
+ return (message?.info?.time ?? {});
23
+ }
24
+ /**
25
+ * When the message was created, in epoch **milliseconds**, or `null` when the
26
+ * backend never stamped one.
27
+ *
28
+ * Milliseconds is not an assumption: `packages/sdk/src/transcript.ts` feeds the
29
+ * same field straight to `new Date(...)` with no `* 1000`, and hands
30
+ * `time.completed - time.created` to a `formatDuration(ms)`.
31
+ *
32
+ * `0` is rejected along with `NaN`: the epoch is not a plausible message time,
33
+ * so a zeroed field is missing data, not midnight in 1970.
34
+ */
35
+ export function messageCreatedAt(message) {
36
+ const created = messageTime(message).created;
37
+ if (typeof created !== 'number' || !Number.isFinite(created) || created <= 0)
38
+ return null;
39
+ return created;
40
+ }
41
+ const MINUTE = 60_000;
42
+ const WEEK = 7 * 24 * 60 * MINUTE;
43
+ const MINUTES_IN_DAY = 24 * 60;
44
+ /**
45
+ * The runtime zone's UTC offset at an instant, in milliseconds, with second
46
+ * precision. A day that crosses a DST change is 23 or 25 wall-clock hours, and
47
+ * `relativePast` counts days in wall-clock terms so "1 day ago" still means
48
+ * "same time yesterday".
49
+ */
50
+ function zoneOffsetMs(date) {
51
+ const utc = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
52
+ utc.setUTCFullYear(date.getFullYear());
53
+ return date.getTime() - utc.getTime();
54
+ }
55
+ /**
56
+ * `date` → "N minutes ago" / "N hours ago" / "N days ago", for a `date` at
57
+ * least one minute and under one week before `now`.
58
+ *
59
+ * This is `date-fns`' `formatDistanceStrict(date, now, { addSuffix: true })`
60
+ * for the en-US locale, restricted to the range `formatMessageDay` calls it
61
+ * with: the same unit thresholds, the same `Math.round`, and the same DST
62
+ * normalisation for days. It lives here so the SDK carries no date library.
63
+ */
64
+ function relativePast(date, now) {
65
+ const milliseconds = now.getTime() - date.getTime();
66
+ const minutes = milliseconds / MINUTE;
67
+ const plural = (count, unit) => `${count} ${unit}${count === 1 ? '' : 's'} ago`;
68
+ if (minutes < 60)
69
+ return plural(Math.round(minutes), 'minute');
70
+ if (minutes < MINUTES_IN_DAY)
71
+ return plural(Math.round(minutes / 60), 'hour');
72
+ const dstNormalizedMinutes = (milliseconds - (zoneOffsetMs(now) - zoneOffsetMs(date))) / MINUTE;
73
+ return plural(Math.round(dstNormalizedMinutes / MINUTES_IN_DAY), 'day');
74
+ }
75
+ /** A usable instant, or `null`. One guard, used by both formatters. */
76
+ function instant(timestamp) {
77
+ if (typeof timestamp !== 'number' || !Number.isFinite(timestamp) || timestamp <= 0)
78
+ return null;
79
+ const date = new Date(timestamp);
80
+ return Number.isNaN(date.getTime()) ? null : date;
81
+ }
82
+ /**
83
+ * `Intl.DateTimeFormat` construction is the expensive half of formatting — it
84
+ * resolves locale data every time — while the instances themselves are
85
+ * immutable and safe to reuse. A transcript re-renders every label on each
86
+ * clock tick, so building a fresh formatter per label per tick is the one cost
87
+ * here that scales with conversation length. There are only a handful of
88
+ * distinct (locale, options) pairs in this module, so they are all cached.
89
+ */
90
+ const formatters = new Map();
91
+ function formatter(options, opts) {
92
+ const resolved = { ...options, ...(opts.timeZone ? { timeZone: opts.timeZone } : {}) };
93
+ const key = `${opts.locale ?? ''}|${JSON.stringify(resolved)}`;
94
+ let cached = formatters.get(key);
95
+ if (!cached) {
96
+ cached = new Intl.DateTimeFormat(opts.locale, resolved);
97
+ formatters.set(key, cached);
98
+ }
99
+ return cached;
100
+ }
101
+ /**
102
+ * Format, with the day period forced to upper case.
103
+ *
104
+ * `Intl` does not agree with itself here: CLDR gives `en-US` an uppercase
105
+ * "PM" but hands `en-AU` a lowercase "pm" — so the same code renders
106
+ * "2:32 PM" for one reader and "2:32 pm" for another, with nothing in this
107
+ * file to explain the difference. Uppercasing the one token settles it without
108
+ * touching month names, weekday names, or the 24-hour locales that have no day
109
+ * period at all.
110
+ *
111
+ * `formatToParts(...).join('')` reproduces `format()` exactly, so this is the
112
+ * same string with one token changed — not a reimplementation of formatting.
113
+ */
114
+ function part(date, options, opts) {
115
+ return formatter(options, opts)
116
+ .formatToParts(date)
117
+ .map((token) => (token.type === 'dayPeriod' ? dayPeriod(token.value, opts) : token.value))
118
+ .join('');
119
+ }
120
+ /**
121
+ * CLDR also drifts on punctuation, not just case: depending on the ICU
122
+ * version, `en-CA` hands out "p.m." where `en-US` gives "PM" — dots included.
123
+ * Every Latin a.m./p.m. variant collapses to the same two letters; day
124
+ * periods in other scripts keep their own convention, uppercased as before.
125
+ */
126
+ function dayPeriod(value, opts) {
127
+ const latin = /^([ap])\.?\s?m\.?$/i.exec(value.trim());
128
+ if (latin)
129
+ return `${latin[1].toUpperCase()}M`;
130
+ return value.toLocaleUpperCase(opts.locale);
131
+ }
132
+ /** The calendar year at an instant, in the render zone — so "same year" is
133
+ * asked in the zone the date is printed in, not the runtime's. */
134
+ function yearIn(date, opts) {
135
+ return part(date, { year: 'numeric' }, opts);
136
+ }
137
+ /**
138
+ * The label on screen.
139
+ *
140
+ * | When | Reads as (`en-US`) |
141
+ * | --------------- | ------------------ |
142
+ * | under a minute | `just now` |
143
+ * | under a week | `5 days ago` |
144
+ * | this year | `June 9` |
145
+ * | any older | `June 9, 2025` |
146
+ *
147
+ * Strict distance (`relativePast`) rather than a loose one: it never rounds up
148
+ * into a vague "about 1 minute", and the point of the label is a real
149
+ * distance, not an impression.
150
+ *
151
+ * `now` is `null` for a server render, where distance is unknowable: the
152
+ * server cannot know the viewer's clock, and guessing produces text that
153
+ * changes on hydration. `null` returns the dated form instead, so the string
154
+ * shown before hydration is never *wrong* — only less immediate than it will be.
155
+ *
156
+ * Returns `''` for a timestamp that is absent or unparseable, so the caller can
157
+ * render nothing rather than an `Invalid Date` placeholder.
158
+ */
159
+ export function formatMessageDay(timestamp, now, opts = {}) {
160
+ const date = instant(timestamp);
161
+ if (!date)
162
+ return '';
163
+ const dated = (withYear) => part(date, { month: 'long', day: 'numeric', ...(withYear ? { year: 'numeric' } : {}) }, opts);
164
+ if (now === null)
165
+ return dated(true);
166
+ // A negative gap means the stamp is ahead of this clock — a few seconds of
167
+ // skew between the sandbox and the browser, not a message from the future.
168
+ // Clamping keeps the skew invisible instead of printing "in 3 seconds".
169
+ const elapsed = Math.max(0, now - date.getTime());
170
+ // Under a minute, a strict distance says "8 seconds ago" and then
171
+ // "9 seconds ago" — motion that carries nothing. One word covers it.
172
+ if (elapsed < MINUTE)
173
+ return 'just now';
174
+ if (elapsed < WEEK)
175
+ return relativePast(date, new Date(now));
176
+ return dated(yearIn(date, opts) !== yearIn(new Date(now), opts));
177
+ }
178
+ /**
179
+ * The hover label: the full date and the time of day. `June 9, 2026 2:32 PM`.
180
+ *
181
+ * This is where the specifics belong. The label on screen is deliberately
182
+ * loose so the thread stays readable; hovering answers "when exactly" without
183
+ * that answer ever taking up room in the transcript.
184
+ *
185
+ * Minutes, not seconds. A second-level reading looks like it is worth reading
186
+ * and never is — nobody hovers a chat message to learn it landed at :05.
187
+ */
188
+ export function formatMessageExact(timestamp, opts = {}) {
189
+ const date = instant(timestamp);
190
+ if (!date)
191
+ return '';
192
+ const day = part(date, { month: 'long', day: 'numeric', year: 'numeric' }, opts);
193
+ const clock = part(date, { hour: 'numeric', minute: '2-digit' }, opts);
194
+ return `${day} ${clock}`;
195
+ }
196
+ //# sourceMappingURL=message-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-time.js","sourceRoot":"","sources":["../../../../src/core/turns/segments/message-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqC;IAI/D,OAAO,CACJ,OAAO,EAAE,IAAwE,EAAE,IAAI,IAAI,EAAE,CAC/F,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAqC;IACpE,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;IAC7C,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1F,OAAO,OAAO,CAAC;AACjB,CAAC;AAiBD,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AAClC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/B;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAU;IAC9B,MAAM,GAAG,GAAG,IAAI,IAAI,CAClB,IAAI,CAAC,GAAG,CACN,IAAI,CAAC,WAAW,EAAE,EAClB,IAAI,CAAC,QAAQ,EAAE,EACf,IAAI,CAAC,OAAO,EAAE,EACd,IAAI,CAAC,QAAQ,EAAE,EACf,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,eAAe,EAAE,CACvB,CAC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kE;IAClE,qEAAqE;IACrE,IAAI,OAAO,GAAG,MAAM;QAAE,OAAO,UAAU,CAAC;IACxC,IAAI,OAAO,GAAG,IAAI;QAAE,OAAO,YAAY,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7D,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAoC,EACpC,OAA2B,EAAE;IAE7B,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;IACjF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;IACvE,OAAO,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Plain-language narration for Easy mode.
3
+ *
4
+ * Turns the 104 registered tools into sentences a non-technical user can read.
5
+ * The registry holds ~200 keys because every tool registers snake_case,
6
+ * kebab-case and an `oc-` alias — `normalizeName` collapses those first.
7
+ *
8
+ * The `other` fallback is load-bearing: MCP tools have arbitrary `server/tool`
9
+ * names that cannot be enumerated, and tools added after this ships are unknown
10
+ * here. Neither may ever surface a raw identifier.
11
+ *
12
+ * GOVERNING RULE: narration must never mislead. A tool's family and sentence
13
+ * are decided by what its registered component actually renders/does (see
14
+ * apps/web/src/features/session/tool/tools/*.tsx), not by how its name reads.
15
+ * Several tools register the *same* component under multiple aliases (e.g.
16
+ * `task_create` and `agent_task_create` both render `AgentSpawnTool`) — those
17
+ * aliases must always resolve to the same family and the same sentence.
18
+ */
19
+ import type { ToolPart } from '../../runtime/client.js';
20
+ export type StepFamily = 'explore' | 'edit' | 'run' | 'web' | 'create' | 'plan' | 'delegate' | 'sessions' | 'memory' | 'connectors' | 'automations' | 'projects' | 'skills' | 'ask' | 'retired' | 'other';
21
+ export declare function familyForTool(toolName: string): StepFamily | 'hidden';
22
+ /**
23
+ * `linear/create_issue` → `Create Issue`. Never returns a raw identifier.
24
+ *
25
+ * Named `narrationToolName`, not `humanizeToolName`: the SDK already exports a
26
+ * `humanizeToolName` (tool-registry) that keeps the server segment
27
+ * (`linear/create_issue` → "Linear/create Issue"). This one names only the
28
+ * leaf, which is what a narrated sentence wants.
29
+ *
30
+ * MCP tool ids also arrive as `mcp__server__tool_name` — `__` is that
31
+ * format's hierarchy separator, the same role `/` plays elsewhere. Without
32
+ * normalizing it first, only the trailing `_` gets word-split, leaving the
33
+ * server segment glued onto the leaf ("Mcp Linear Create Issue", still
34
+ * effectively the raw identifier) — collapsing `__` to `/` first lets the
35
+ * existing leaf-splitting logic below do the same job it already does for
36
+ * `linear/create_issue`.
37
+ */
38
+ export declare function narrationToolName(toolName: string): string;
39
+ export declare function contextLabelForTool(toolName: string): string;
40
+ export type CreateArtifactKind = 'image' | 'video' | 'presentation';
41
+ /**
42
+ * The kind of artifact this call produced, or `null` if it did not make
43
+ * anything worth surfacing in Outputs (a delete, a listing, a preview, …).
44
+ *
45
+ * `image_gen` has no pure-read action — generate/edit/upscale/remove_bg (and
46
+ * a missing/unrecognized action) all leave behind a real image file the user
47
+ * asked for and will want to open (see ImageGenTool, which renders a
48
+ * resulting image for every one of these). Only the LABEL differs by action
49
+ * (see `imageGenSentence` — calling an edit "Made an image" would be a lie);
50
+ * the artifact itself must always surface here, or a user who asks to
51
+ * edit/upscale/remove a background gets an empty Outputs card despite the
52
+ * agent having actually produced something.
53
+ */
54
+ export declare function createArtifactKind(part: ToolPart): CreateArtifactKind | null;
55
+ /**
56
+ * One sentence for a group of same-family calls.
57
+ * `parts` is guaranteed non-empty and homogeneous by `group-steps` — homogeneous
58
+ * by *family*, not by tool, so a single call can still mix several distinct
59
+ * tools (e.g. `image_gen` + `video_gen`, or `connector_get` + `connector_setup`).
60
+ * Every branch below inspects every part, never just `parts[0]`.
61
+ */
62
+ export declare function narrateStep(family: StepFamily, parts: ToolPart[]): string;
63
+ /**
64
+ * The failure phrasing for a step whose status is 'error' (W7). Same rules as
65
+ * `narrateStep` — plain language, never a raw identifier, never an error code.
66
+ * Grouped steps can mix one failure among successes; the step-level status is
67
+ * already 'error' (see group-steps.statusOf), so the sentence owns the whole
68
+ * step: vague-but-true beats specific-but-false here exactly as everywhere else.
69
+ */
70
+ export declare function narrateFailedStep(family: StepFamily, parts: ToolPart[]): string;
71
+ //# sourceMappingURL=narration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"narration.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/segments/narration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAgBrD,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,MAAM,GACN,KAAK,GACL,KAAK,GACL,QAAQ,GACR,MAAM,GACN,UAAU,GACV,UAAU,GACV,QAAQ,GACR,YAAY,GACZ,aAAa,GACb,UAAU,GACV,QAAQ,GACR,KAAK,GACL,SAAS,GACT,OAAO,CAAC;AA+HZ,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,CAIrE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO1D;AAwBD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI5D;AAoWD,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC;AAQpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,GAAG,kBAAkB,GAAG,IAAI,CAa5E;AA8CD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CA2LzE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAmD/E"}