@framers/agentos 0.12.13 → 0.12.14
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.
- package/README.md +1 -1
- package/dist/api/agent.d.ts +35 -1
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +8 -0
- package/dist/api/agent.js.map +1 -1
- package/dist/api/gmi.d.ts +21 -0
- package/dist/api/gmi.d.ts.map +1 -0
- package/dist/api/gmi.js +527 -0
- package/dist/api/gmi.js.map +1 -0
- package/dist/api/runtime/agentCognitiveMemory.d.ts +82 -0
- package/dist/api/runtime/agentCognitiveMemory.d.ts.map +1 -0
- package/dist/api/runtime/agentCognitiveMemory.js +277 -0
- package/dist/api/runtime/agentCognitiveMemory.js.map +1 -0
- package/dist/api/runtime/capabilityContract.d.ts +21 -1
- package/dist/api/runtime/capabilityContract.d.ts.map +1 -1
- package/dist/api/runtime/capabilityContract.js +15 -15
- package/dist/api/runtime/capabilityContract.js.map +1 -1
- package/dist/api/runtime/gmiCognition.d.ts +66 -0
- package/dist/api/runtime/gmiCognition.d.ts.map +1 -0
- package/dist/api/runtime/gmiCognition.js +58 -0
- package/dist/api/runtime/gmiCognition.js.map +1 -0
- package/dist/api/runtime/gmiPersona.d.ts +16 -0
- package/dist/api/runtime/gmiPersona.d.ts.map +1 -0
- package/dist/api/runtime/gmiPersona.js +91 -0
- package/dist/api/runtime/gmiPersona.js.map +1 -0
- package/dist/api/runtime/gmiResults.d.ts +98 -0
- package/dist/api/runtime/gmiResults.d.ts.map +1 -0
- package/dist/api/runtime/gmiResults.js +333 -0
- package/dist/api/runtime/gmiResults.js.map +1 -0
- package/dist/api/runtime/gmiSession.d.ts +85 -0
- package/dist/api/runtime/gmiSession.d.ts.map +1 -0
- package/dist/api/runtime/gmiSession.js +285 -0
- package/dist/api/runtime/gmiSession.js.map +1 -0
- package/dist/api/runtime/gmiTranscript.d.ts +48 -0
- package/dist/api/runtime/gmiTranscript.d.ts.map +1 -0
- package/dist/api/runtime/gmiTranscript.js +110 -0
- package/dist/api/runtime/gmiTranscript.js.map +1 -0
- package/dist/api/runtime/lightweightAgentDiagnostics.d.ts +6 -1
- package/dist/api/runtime/lightweightAgentDiagnostics.d.ts.map +1 -1
- package/dist/api/runtime/lightweightAgentDiagnostics.js +9 -2
- package/dist/api/runtime/lightweightAgentDiagnostics.js.map +1 -1
- package/dist/api/sessionHistory.d.ts +43 -1
- package/dist/api/sessionHistory.d.ts.map +1 -1
- package/dist/api/sessionHistory.js +56 -1
- package/dist/api/sessionHistory.js.map +1 -1
- package/dist/api/sessionTranscript.d.ts +8 -0
- package/dist/api/sessionTranscript.d.ts.map +1 -1
- package/dist/api/sessionTranscript.js.map +1 -1
- package/dist/api/transferStyle.d.ts +8 -0
- package/dist/api/transferStyle.d.ts.map +1 -1
- package/dist/api/transferStyle.js +4 -1
- package/dist/api/transferStyle.js.map +1 -1
- package/dist/api/types.d.ts +11 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/cognition/substrate/GMI.d.ts.map +1 -1
- package/dist/cognition/substrate/GMI.js +54 -2
- package/dist/cognition/substrate/GMI.js.map +1 -1
- package/dist/cognition/substrate/IGMI.d.ts +23 -1
- package/dist/cognition/substrate/IGMI.d.ts.map +1 -1
- package/dist/cognition/substrate/IGMI.js.map +1 -1
- package/dist/io/vision/VisionPipeline.d.ts +5 -0
- package/dist/io/vision/VisionPipeline.d.ts.map +1 -1
- package/dist/io/vision/VisionPipeline.js +28 -13
- package/dist/io/vision/VisionPipeline.js.map +1 -1
- package/dist/io/vision/index.d.ts.map +1 -1
- package/dist/io/vision/index.js +2 -0
- package/dist/io/vision/index.js.map +1 -1
- package/dist/io/vision/types.d.ts +11 -0
- package/dist/io/vision/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file gmiSession.ts
|
|
3
|
+
* One agent session served by one GMI (`agent({ runtime: 'gmi' })`, spec D10).
|
|
4
|
+
*
|
|
5
|
+
* The session store is the source of truth: before every turn the GMI's history
|
|
6
|
+
* is replaced with the store's messages, and as the turn runs each finished
|
|
7
|
+
* model step is written to the store through a turn writer; a turn that fails
|
|
8
|
+
* after some steps keeps them, marked partial. One turn runs at a time per
|
|
9
|
+
* session. Each step's usage goes to the usage ledger with the provider and
|
|
10
|
+
* model that served it.
|
|
11
|
+
*/
|
|
12
|
+
import { randomUUID } from 'node:crypto';
|
|
13
|
+
import { GMIInteractionType, GMIOutputChunkType, } from '../../cognition/substrate/IGMI.js';
|
|
14
|
+
import { addModelUsage, extractTextFromContent } from '../generateText.js';
|
|
15
|
+
import { ObjectGenerationError } from '../generateObject.js';
|
|
16
|
+
import { DEFAULT_MEMORY_TOKEN_BUDGET, MEMORY_TIMEOUT_MS } from './memoryProviderHooks.js';
|
|
17
|
+
import { GmiTurnFolder, streamFromGmiTurn } from './gmiResults.js';
|
|
18
|
+
import { stepToTranscript, transcriptToConversation } from './gmiTranscript.js';
|
|
19
|
+
/** Serialises turns: `acquire()` resolves with a release function once every earlier holder released. */
|
|
20
|
+
export class TurnLock {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.tail = Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
acquire() {
|
|
25
|
+
let release;
|
|
26
|
+
const held = new Promise((resolve) => {
|
|
27
|
+
release = resolve;
|
|
28
|
+
});
|
|
29
|
+
const previous = this.tail;
|
|
30
|
+
this.tail = previous.then(() => held);
|
|
31
|
+
return previous.then(() => release);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** `memoryProvider.getContext` for the turn, within its timeout; undefined when there is none or it fails. */
|
|
35
|
+
async function memoryProviderContext(opts, userText) {
|
|
36
|
+
const provider = opts.memoryProvider;
|
|
37
|
+
if (!provider?.getContext)
|
|
38
|
+
return undefined;
|
|
39
|
+
const timeoutMs = opts.memoryProviderOptions?.timeoutMs ?? MEMORY_TIMEOUT_MS;
|
|
40
|
+
const tokenBudget = opts.memoryProviderOptions?.tokenBudget ?? DEFAULT_MEMORY_TOKEN_BUDGET;
|
|
41
|
+
let timer;
|
|
42
|
+
let timedOut = false;
|
|
43
|
+
try {
|
|
44
|
+
const result = await Promise.race([
|
|
45
|
+
provider.getContext(userText, { tokenBudget }),
|
|
46
|
+
new Promise((resolve) => {
|
|
47
|
+
timer = setTimeout(() => {
|
|
48
|
+
timedOut = true;
|
|
49
|
+
resolve(null);
|
|
50
|
+
}, timeoutMs);
|
|
51
|
+
}),
|
|
52
|
+
]);
|
|
53
|
+
if (timedOut)
|
|
54
|
+
console.warn(`[agentos] memoryProvider.getContext exceeded ${timeoutMs}ms; continuing without memory context.`);
|
|
55
|
+
return result?.contextText || undefined;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.warn('[agentos] memoryProvider.getContext failed; continuing without memory context.', error);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (timer)
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** One usage ledger event; a ledger failure is never the caller's error. */
|
|
67
|
+
function recordLedgerUsage(ledger, providerId, modelId, usage) {
|
|
68
|
+
if (!usage || typeof usage !== 'object')
|
|
69
|
+
return;
|
|
70
|
+
const total = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
71
|
+
addModelUsage(total, usage);
|
|
72
|
+
// Imported on use, as agent() imports it: the ledger reads and writes files.
|
|
73
|
+
void import('./usageLedger.js')
|
|
74
|
+
.then(({ recordAgentOSUsage }) => recordAgentOSUsage({ providerId, modelId, usage: total, options: ledger }))
|
|
75
|
+
.catch(() => undefined);
|
|
76
|
+
}
|
|
77
|
+
/** `onAfterGeneration` for one finished step: a returned text replaces the step's text in the result and in the store. */
|
|
78
|
+
async function afterGeneration(opts, folder, step, calls) {
|
|
79
|
+
if (!opts.onAfterGeneration)
|
|
80
|
+
return;
|
|
81
|
+
const usage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
82
|
+
addModelUsage(usage, step.usage);
|
|
83
|
+
try {
|
|
84
|
+
const modified = await opts.onAfterGeneration({
|
|
85
|
+
text: folder.stepText(step),
|
|
86
|
+
toolCalls: calls.map((call) => ({ name: call.name, args: call.arguments })),
|
|
87
|
+
usage,
|
|
88
|
+
step: step.stepIndex,
|
|
89
|
+
...(step.cacheDiagnostics !== undefined ? { cacheDiagnostics: step.cacheDiagnostics } : {}),
|
|
90
|
+
});
|
|
91
|
+
// A schema answer stays the JSON the schema validated.
|
|
92
|
+
if (modified && typeof modified.text === 'string' && step.structuredOutput === undefined) {
|
|
93
|
+
folder.overrideStepText(step.stepIndex, modified.text);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (hookError) {
|
|
97
|
+
console.warn('[agentos] onAfterGeneration hook error:', hookError);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Runs one GMI turn and yields its chunks, pushing each into `folder`, writing
|
|
102
|
+
* each finished step to the session store and each step's usage to the ledger.
|
|
103
|
+
* The caller folds the chunks (send) or streams them (stream).
|
|
104
|
+
*
|
|
105
|
+
* The turn reads the store's epoch and messages the moment it holds the lock,
|
|
106
|
+
* before it waits for its GMI or its memory context, so a clear or reseed during
|
|
107
|
+
* those waits makes the turn's writes no-ops, as an in-flight legacy send's are.
|
|
108
|
+
*
|
|
109
|
+
* @returns The messages the turn added to the store (or would have, with no history).
|
|
110
|
+
*/
|
|
111
|
+
export async function* runGmiTurn(deps, input, turn, folder) {
|
|
112
|
+
const release = await deps.lock.acquire();
|
|
113
|
+
const recorded = [];
|
|
114
|
+
let writer;
|
|
115
|
+
let ended = false;
|
|
116
|
+
let releaseGmi;
|
|
117
|
+
const userMessage = { role: 'user', content: input };
|
|
118
|
+
let pending;
|
|
119
|
+
// Writes the last finished step once its tool results are in.
|
|
120
|
+
const flush = () => {
|
|
121
|
+
if (!pending)
|
|
122
|
+
return;
|
|
123
|
+
const messages = stepToTranscript({
|
|
124
|
+
step: pending.step,
|
|
125
|
+
calls: pending.calls,
|
|
126
|
+
results: pending.results,
|
|
127
|
+
userMessage: pending.first ? userMessage : undefined,
|
|
128
|
+
textOverride: folder.stepText(pending.step),
|
|
129
|
+
});
|
|
130
|
+
if (!writer || writer.appendStep(messages))
|
|
131
|
+
recorded.push(...messages);
|
|
132
|
+
pending = undefined;
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
// What the turn starts from, read together before any wait.
|
|
136
|
+
const epochAtStart = deps.history?.epoch();
|
|
137
|
+
const priorMessages = deps.history ? deps.history.messages() : [];
|
|
138
|
+
const userText = typeof input === 'string' ? input : extractTextFromContent(input);
|
|
139
|
+
const served = await deps.gmiFor();
|
|
140
|
+
releaseGmi = served.release;
|
|
141
|
+
const gmi = served.gmi;
|
|
142
|
+
gmi.replaceHistory?.(transcriptToConversation(priorMessages));
|
|
143
|
+
const memoryContext = deps.useMemoryProviderContext ? await memoryProviderContext(deps.opts, userText) : undefined;
|
|
144
|
+
served.prepare?.({ prompt: typeof input === 'string' ? input : undefined, memoryContext });
|
|
145
|
+
writer = deps.history?.beginTurn(turn.blockLabel, epochAtStart);
|
|
146
|
+
const turnInput = {
|
|
147
|
+
interactionId: `turn-${randomUUID()}`,
|
|
148
|
+
userId: deps.userId,
|
|
149
|
+
sessionId: deps.sessionId,
|
|
150
|
+
type: typeof input === 'string' ? GMIInteractionType.TEXT : GMIInteractionType.MULTIMODAL_CONTENT,
|
|
151
|
+
content: input,
|
|
152
|
+
metadata: {
|
|
153
|
+
options: {
|
|
154
|
+
...(turn.options ?? {}),
|
|
155
|
+
...(turn.responseSchema ? { responseSchema: turn.responseSchema, schemaName: turn.schemaName ?? 'response' } : {}),
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
let stepCalls = [];
|
|
160
|
+
let firstStep = true;
|
|
161
|
+
for await (const chunk of gmi.processTurnStream(turnInput)) {
|
|
162
|
+
folder.push(chunk);
|
|
163
|
+
switch (chunk.type) {
|
|
164
|
+
case GMIOutputChunkType.TOOL_CALL_REQUEST:
|
|
165
|
+
stepCalls.push(...(chunk.content ?? []));
|
|
166
|
+
break;
|
|
167
|
+
case GMIOutputChunkType.STEP_FINISHED: {
|
|
168
|
+
flush();
|
|
169
|
+
const step = chunk.content;
|
|
170
|
+
await afterGeneration(deps.opts, folder, step, stepCalls);
|
|
171
|
+
pending = { step, calls: stepCalls, results: [], first: firstStep };
|
|
172
|
+
stepCalls = [];
|
|
173
|
+
firstStep = false;
|
|
174
|
+
recordLedgerUsage(deps.ledger, step.providerId, step.modelId, step.usage);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case GMIOutputChunkType.TOOL_RESULT:
|
|
178
|
+
pending?.results.push(chunk.content);
|
|
179
|
+
break;
|
|
180
|
+
case GMIOutputChunkType.USAGE_UPDATE: {
|
|
181
|
+
// An attempt that failed before any output and was billed: no step carries it.
|
|
182
|
+
const meta = chunk.metadata;
|
|
183
|
+
if (meta?.attemptFailed)
|
|
184
|
+
recordLedgerUsage(deps.ledger, meta.providerId, meta.modelId, chunk.content);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
yield chunk;
|
|
191
|
+
}
|
|
192
|
+
flush();
|
|
193
|
+
ended = true;
|
|
194
|
+
if (folder.error()) {
|
|
195
|
+
writer?.abort({ partial: true });
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
writer?.commit();
|
|
199
|
+
const observe = deps.opts.memoryProvider?.observe;
|
|
200
|
+
if (observe) {
|
|
201
|
+
void observe('user', userText).catch(() => undefined);
|
|
202
|
+
const reply = folder.text();
|
|
203
|
+
if (reply)
|
|
204
|
+
void observe('assistant', reply).catch(() => undefined);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return recorded;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
folder.fail(error);
|
|
211
|
+
flush();
|
|
212
|
+
ended = true;
|
|
213
|
+
writer?.abort({ partial: true });
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
// A turn its consumer stopped reading keeps the steps that finished, marked partial.
|
|
218
|
+
if (!ended) {
|
|
219
|
+
flush();
|
|
220
|
+
writer?.abort({ partial: true });
|
|
221
|
+
}
|
|
222
|
+
const usage = folder.usage();
|
|
223
|
+
if (usage.totalTokens > 0 || usage.promptTokens > 0 || usage.completionTokens > 0)
|
|
224
|
+
deps.onUsage(usage);
|
|
225
|
+
if (releaseGmi)
|
|
226
|
+
void releaseGmi().catch(() => undefined);
|
|
227
|
+
release();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Parses a structured send's answer: the schema tool's arguments when a step carried them, else the reply text. */
|
|
231
|
+
function parseStructured(folder, result, schema) {
|
|
232
|
+
const structured = folder.structuredOutput();
|
|
233
|
+
let raw = structured;
|
|
234
|
+
if (structured === undefined || typeof structured === 'string') {
|
|
235
|
+
const source = typeof structured === 'string' ? structured : result.text;
|
|
236
|
+
try {
|
|
237
|
+
raw = JSON.parse(source);
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
throw new ObjectGenerationError(`session.send: provider response is not valid JSON despite enforcement (${err instanceof Error ? err.message : String(err)})`, source);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const safe = schema.safeParse(raw);
|
|
244
|
+
if (!safe.success) {
|
|
245
|
+
throw new ObjectGenerationError('session.send: provider-enforced JSON failed Zod validation', result.text, safe.error);
|
|
246
|
+
}
|
|
247
|
+
return safe.data;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* `send()`: the whole turn, folded into a `GenerateTextResult` (with `object`
|
|
251
|
+
* when a schema was given). Rejects with the GMI's error, its code kept, when
|
|
252
|
+
* the turn failed; an error thrown before the turn ran (no provider or model
|
|
253
|
+
* resolves, the memory cannot be built) is rethrown as it was thrown.
|
|
254
|
+
*/
|
|
255
|
+
export async function sendGmiTurn(deps, input, turn) {
|
|
256
|
+
const folder = new GmiTurnFolder();
|
|
257
|
+
const run = runGmiTurn(deps, input, turn, folder);
|
|
258
|
+
let recorded = [];
|
|
259
|
+
for (;;) {
|
|
260
|
+
const next = await run.next();
|
|
261
|
+
if (next.done) {
|
|
262
|
+
recorded = next.value;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const error = folder.toError();
|
|
267
|
+
if (error)
|
|
268
|
+
throw error;
|
|
269
|
+
const result = folder.toGenerateTextResult(recorded);
|
|
270
|
+
if (!turn.responseSchema)
|
|
271
|
+
return result;
|
|
272
|
+
return { ...result, object: parseStructured(folder, result, turn.responseSchema) };
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* `stream()`: the turn's chunks as a `StreamTextResult`. The promises settle
|
|
276
|
+
* after the turn is written to the session store, so a caller that awaits
|
|
277
|
+
* `text` and sends again finds the turn in the history.
|
|
278
|
+
*/
|
|
279
|
+
export function streamGmiTurn(deps, input, turn) {
|
|
280
|
+
const folder = new GmiTurnFolder();
|
|
281
|
+
const run = runGmiTurn(deps, input, turn, folder);
|
|
282
|
+
// runGmiTurn pushes every chunk into `folder` (with the onAfterGeneration replacements); the stream reads that folder.
|
|
283
|
+
return streamFromGmiTurn({ [Symbol.asyncIterator]: () => run }, { folder });
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=gmiSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmiSession.js","sourceRoot":"","sources":["../../../src/api/runtime/gmiSession.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAOnB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,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U,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAClD,uHAAuH;IACvH,OAAO,iBAAiB,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file gmiTranscript.ts
|
|
3
|
+
* Conversions between the session store's transcript and a GMI's conversation
|
|
4
|
+
* history (`agent({ runtime: 'gmi' })`). Before every turn the GMI's history is
|
|
5
|
+
* replaced with the store's messages; as each model step finishes, the messages
|
|
6
|
+
* it adds are written to the store.
|
|
7
|
+
*
|
|
8
|
+
* A step is stored as the GMI put it in its own history (the assistant message
|
|
9
|
+
* with its tool calls and thinking blocks, then each tool result in the GMI's
|
|
10
|
+
* wording), so the next turn replays the bytes the provider already saw and a
|
|
11
|
+
* cached prompt prefix stays valid.
|
|
12
|
+
*/
|
|
13
|
+
import { type ConversationMessage } from '../../core/conversation/ConversationMessage.js';
|
|
14
|
+
import type { StepFinishedChunkPayload, ToolCallRequest, ToolResultChunkPayload } from '../../cognition/substrate/IGMI.js';
|
|
15
|
+
import { type SessionTranscriptMessage } from '../sessionTranscript.js';
|
|
16
|
+
/**
|
|
17
|
+
* The store's messages as GMI conversation history: roles, tool calls with
|
|
18
|
+
* parsed arguments and Gemini thought signatures, tool-result ids, and thinking
|
|
19
|
+
* blocks (a caller-built signed `thinking` entry becomes a block, as a replay to
|
|
20
|
+
* the provider makes it). The `partial` marker is left out.
|
|
21
|
+
*
|
|
22
|
+
* @param messages - The session store's messages, oldest first.
|
|
23
|
+
* @returns History for `IGMI.replaceHistory`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function transcriptToConversation(messages: readonly SessionTranscriptMessage[]): ConversationMessage[];
|
|
26
|
+
/** One finished model step and what the turn produced around it. */
|
|
27
|
+
export interface StepTranscriptInput {
|
|
28
|
+
step: StepFinishedChunkPayload;
|
|
29
|
+
/** The tool calls the step requested, in order. */
|
|
30
|
+
calls: ToolCallRequest[];
|
|
31
|
+
/** The step's tool results, in order. */
|
|
32
|
+
results: ToolResultChunkPayload[];
|
|
33
|
+
/** The turn's user message, given on the turn's first step. */
|
|
34
|
+
userMessage?: SessionTranscriptMessage;
|
|
35
|
+
/** `onAfterGeneration`'s replacement for the step text. */
|
|
36
|
+
textOverride?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The store messages one finished step adds: the turn's user message on the
|
|
40
|
+
* first step, the assistant message (left out when the step produced neither
|
|
41
|
+
* text nor tool calls), then one tool message per result. A step that answered
|
|
42
|
+
* a response schema is stored as the JSON string of its answer.
|
|
43
|
+
*
|
|
44
|
+
* @param input - The step, its calls and results, and the turn's user message on the first step.
|
|
45
|
+
* @returns The messages to append through the turn writer.
|
|
46
|
+
*/
|
|
47
|
+
export declare function stepToTranscript(input: StepTranscriptInput): SessionTranscriptMessage[];
|
|
48
|
+
//# sourceMappingURL=gmiTranscript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmiTranscript.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/gmiTranscript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA0C,KAAK,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAElI,OAAO,KAAK,EAAE,wBAAwB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3H,OAAO,EAA2B,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAsBjG;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,SAAS,wBAAwB,EAAE,GAAG,mBAAmB,EAAE,CAsB7G;AAED,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,mDAAmD;IACnD,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,yCAAyC;IACzC,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,+DAA+D;IAC/D,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC,2DAA2D;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAUD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,GAAG,wBAAwB,EAAE,CAuBvF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file gmiTranscript.ts
|
|
3
|
+
* Conversions between the session store's transcript and a GMI's conversation
|
|
4
|
+
* history (`agent({ runtime: 'gmi' })`). Before every turn the GMI's history is
|
|
5
|
+
* replaced with the store's messages; as each model step finishes, the messages
|
|
6
|
+
* it adds are written to the store.
|
|
7
|
+
*
|
|
8
|
+
* A step is stored as the GMI put it in its own history (the assistant message
|
|
9
|
+
* with its tool calls and thinking blocks, then each tool result in the GMI's
|
|
10
|
+
* wording), so the next turn replays the bytes the provider already saw and a
|
|
11
|
+
* cached prompt prefix stays valid.
|
|
12
|
+
*/
|
|
13
|
+
import { createConversationMessage, MessageRole } from '../../core/conversation/ConversationMessage.js';
|
|
14
|
+
import { toProviderReplayMessage } from '../sessionTranscript.js';
|
|
15
|
+
/** A tool call's JSON arguments as an object; a non-object or unparsable value is kept under `value` or `raw`. */
|
|
16
|
+
function parseArguments(raw) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(raw);
|
|
19
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
20
|
+
? parsed
|
|
21
|
+
: { value: parsed };
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return { raw };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Message content a GMI history entry can hold: text, parts, or null; anything else as its JSON. */
|
|
28
|
+
function conversationContent(content) {
|
|
29
|
+
if (content === null || content === undefined)
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof content === 'string')
|
|
32
|
+
return content;
|
|
33
|
+
if (Array.isArray(content))
|
|
34
|
+
return content;
|
|
35
|
+
return JSON.stringify(content);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The store's messages as GMI conversation history: roles, tool calls with
|
|
39
|
+
* parsed arguments and Gemini thought signatures, tool-result ids, and thinking
|
|
40
|
+
* blocks (a caller-built signed `thinking` entry becomes a block, as a replay to
|
|
41
|
+
* the provider makes it). The `partial` marker is left out.
|
|
42
|
+
*
|
|
43
|
+
* @param messages - The session store's messages, oldest first.
|
|
44
|
+
* @returns History for `IGMI.replaceHistory`.
|
|
45
|
+
*/
|
|
46
|
+
export function transcriptToConversation(messages) {
|
|
47
|
+
return messages.map((message) => {
|
|
48
|
+
if (message.role === 'user') {
|
|
49
|
+
return createConversationMessage(MessageRole.USER, conversationContent(message.content) ?? '');
|
|
50
|
+
}
|
|
51
|
+
if (message.role === 'tool') {
|
|
52
|
+
return createConversationMessage(MessageRole.TOOL, message.content, { tool_call_id: message.tool_call_id });
|
|
53
|
+
}
|
|
54
|
+
const replay = toProviderReplayMessage(message);
|
|
55
|
+
const toolCalls = message.tool_calls?.length
|
|
56
|
+
? message.tool_calls.map((tc) => ({
|
|
57
|
+
id: tc.id,
|
|
58
|
+
name: tc.function.name,
|
|
59
|
+
arguments: parseArguments(tc.function.arguments),
|
|
60
|
+
...(tc.thoughtSignature ? { thoughtSignature: tc.thoughtSignature } : {}),
|
|
61
|
+
}))
|
|
62
|
+
: undefined;
|
|
63
|
+
return createConversationMessage(MessageRole.ASSISTANT, conversationContent(message.content), {
|
|
64
|
+
...(toolCalls ? { tool_calls: toolCalls } : {}),
|
|
65
|
+
...(replay.thinkingBlocks?.length ? { thinkingBlocks: replay.thinkingBlocks } : {}),
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** A tool result's content, worded as the GMI words it in its own history (`ConversationHistoryManager.updateWithToolResult`). */
|
|
70
|
+
function toolContent(result) {
|
|
71
|
+
if (result.isError) {
|
|
72
|
+
return `Error from tool '${result.name}': ${JSON.stringify(result.errorDetails || result.result)}`;
|
|
73
|
+
}
|
|
74
|
+
return typeof result.result === 'string' ? result.result : (JSON.stringify(result.result) ?? '');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The store messages one finished step adds: the turn's user message on the
|
|
78
|
+
* first step, the assistant message (left out when the step produced neither
|
|
79
|
+
* text nor tool calls), then one tool message per result. A step that answered
|
|
80
|
+
* a response schema is stored as the JSON string of its answer.
|
|
81
|
+
*
|
|
82
|
+
* @param input - The step, its calls and results, and the turn's user message on the first step.
|
|
83
|
+
* @returns The messages to append through the turn writer.
|
|
84
|
+
*/
|
|
85
|
+
export function stepToTranscript(input) {
|
|
86
|
+
const { step, calls, results, userMessage, textOverride } = input;
|
|
87
|
+
const text = step.structuredOutput !== undefined ? JSON.stringify(step.structuredOutput) : (textOverride ?? step.text);
|
|
88
|
+
const out = userMessage ? [userMessage] : [];
|
|
89
|
+
if (calls.length > 0 || text) {
|
|
90
|
+
out.push({
|
|
91
|
+
role: 'assistant',
|
|
92
|
+
content: text || null,
|
|
93
|
+
...(calls.length > 0
|
|
94
|
+
? {
|
|
95
|
+
tool_calls: calls.map((tc) => ({
|
|
96
|
+
id: tc.id,
|
|
97
|
+
type: 'function',
|
|
98
|
+
function: { name: tc.name, arguments: JSON.stringify(tc.arguments ?? {}) },
|
|
99
|
+
...(tc.thoughtSignature ? { thoughtSignature: tc.thoughtSignature } : {}),
|
|
100
|
+
})),
|
|
101
|
+
}
|
|
102
|
+
: {}),
|
|
103
|
+
...(step.thinkingBlocks?.length ? { thinkingBlocks: step.thinkingBlocks } : {}),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
for (const result of results)
|
|
107
|
+
out.push({ role: 'tool', tool_call_id: result.toolCallId, content: toolContent(result) });
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=gmiTranscript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmiTranscript.js","sourceRoot":"","sources":["../../../src/api/runtime/gmiTranscript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAA4B,MAAM,gDAAgD,CAAC;AAGlI,OAAO,EAAE,uBAAuB,EAAiC,MAAM,yBAAyB,CAAC;AAEjG,kHAAkH;AAClH,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC5E,CAAC,CAAE,MAAkC;YACrC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;AACH,CAAC;AAED,qGAAqG;AACrG,SAAS,mBAAmB,CAAC,OAAgB;IAC3C,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAqC,CAAC;IACzE,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAA6C;IACpF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,yBAAyB,CAAC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AAQ,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE;wBAC1E,GAAG,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC1E,CAAC,CAAC;iBACJ;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChF,CAAC,CAAC;IACL,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACxH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { BaseAgentConfig } from '../types.js';
|
|
2
|
-
import { type CapabilityKey } from './capabilityContract.js';
|
|
2
|
+
import { type CapabilityKey, type CapabilitySurface } from './capabilityContract.js';
|
|
3
|
+
/**
|
|
4
|
+
* The config fields that are set but that `surface` accepts without enforcing
|
|
5
|
+
* (`accepted_but_deferred` in {@link BASE_AGENT_CONFIG_CAPABILITY_CONTRACT}).
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDeferredCapabilities(config: Partial<BaseAgentConfig>, surface: CapabilitySurface): CapabilityKey[];
|
|
3
8
|
export declare function getDeferredLightweightAgentCapabilities(config: Partial<BaseAgentConfig>): CapabilityKey[];
|
|
4
9
|
export declare function warnOnDeferredLightweightAgentCapabilities(config: Partial<BaseAgentConfig>, warn?: (message: string) => void): CapabilityKey[];
|
|
5
10
|
//# sourceMappingURL=lightweightAgentDiagnostics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightweightAgentDiagnostics.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/lightweightAgentDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAGL,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"lightweightAgentDiagnostics.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/lightweightAgentDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAiBjC;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAChC,OAAO,EAAE,iBAAiB,GACzB,aAAa,EAAE,CAKjB;AAED,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAC/B,aAAa,EAAE,CAEjB;AAED,wBAAgB,0CAA0C,CACxD,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAChC,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAmB,GAC7C,aAAa,EAAE,CAYjB"}
|
|
@@ -19,10 +19,17 @@ function isMeaningfullyConfigured(value) {
|
|
|
19
19
|
}
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The config fields that are set but that `surface` accepts without enforcing
|
|
24
|
+
* (`accepted_but_deferred` in {@link BASE_AGENT_CONFIG_CAPABILITY_CONTRACT}).
|
|
25
|
+
*/
|
|
26
|
+
export function getDeferredCapabilities(config, surface) {
|
|
27
|
+
return CAPABILITY_KEYS.filter((key) => BASE_AGENT_CONFIG_CAPABILITY_CONTRACT[key][surface] === 'accepted_but_deferred'
|
|
24
28
|
&& isMeaningfullyConfigured(config[key]));
|
|
25
29
|
}
|
|
30
|
+
export function getDeferredLightweightAgentCapabilities(config) {
|
|
31
|
+
return getDeferredCapabilities(config, 'agent');
|
|
32
|
+
}
|
|
26
33
|
export function warnOnDeferredLightweightAgentCapabilities(config, warn = console.warn) {
|
|
27
34
|
const deferredCapabilities = getDeferredLightweightAgentCapabilities(config);
|
|
28
35
|
if (deferredCapabilities.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightweightAgentDiagnostics.js","sourceRoot":"","sources":["../../../src/api/runtime/lightweightAgentDiagnostics.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qCAAqC,EACrC,eAAe,
|
|
1
|
+
{"version":3,"file":"lightweightAgentDiagnostics.js","sourceRoot":"","sources":["../../../src/api/runtime/lightweightAgentDiagnostics.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qCAAqC,EACrC,eAAe,GAGhB,MAAM,yBAAyB,CAAC;AAEjC,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxF,IAAI,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG;QAAE,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,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BAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;UACxH,qGAAqG,CAC1G,CAAC;IAEF,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
|
|
@@ -21,13 +21,42 @@ export type HistoryEvent = {
|
|
|
21
21
|
type: 'stale-append-discarded';
|
|
22
22
|
label?: string;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* One in-flight turn on the GMI path (`agent({ runtime: 'gmi' })`). The turn's
|
|
26
|
+
* model steps accumulate and land as ONE block, so eviction keeps or drops the
|
|
27
|
+
* whole turn and never separates a tool call from its result.
|
|
28
|
+
*/
|
|
29
|
+
export interface SessionTurnWriter {
|
|
30
|
+
/**
|
|
31
|
+
* Adds one model step's messages: the user message first on the turn's first
|
|
32
|
+
* step, then the assistant message and its tool results. Returns false, and
|
|
33
|
+
* adds nothing, when the step leaves a tool call unanswered or the writer is
|
|
34
|
+
* closed.
|
|
35
|
+
*/
|
|
36
|
+
appendStep(messages: SessionTranscriptMessage[]): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Stores the turn as one block and runs eviction. Returns false when no step
|
|
39
|
+
* was appended, the writer is already closed, or the history was reseeded
|
|
40
|
+
* (or cleared) after the turn began.
|
|
41
|
+
*/
|
|
42
|
+
commit(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Ends a failed turn. With `partial: true` the steps that completed are
|
|
45
|
+
* stored, the block's last message marked `partial`; otherwise nothing is
|
|
46
|
+
* stored. Returns whether a block was stored.
|
|
47
|
+
*/
|
|
48
|
+
abort(options?: {
|
|
49
|
+
partial?: boolean;
|
|
50
|
+
}): boolean;
|
|
51
|
+
}
|
|
24
52
|
/**
|
|
25
53
|
* Session conversation state: whole-send blocks, chunk-amortized eviction,
|
|
26
54
|
* epoch-guarded mutation (spec §1c/§1d). Pure state machine — no I/O, no
|
|
27
55
|
* provider coupling — so eviction semantics are testable byte-for-byte.
|
|
28
56
|
*
|
|
29
57
|
* Eviction shape: one contiguous OLDEST chunk per event, whole blocks only
|
|
30
|
-
* (a block is one send's complete delta,
|
|
58
|
+
* (a block is one send's complete delta, or one GMI turn written through
|
|
59
|
+
* {@link SessionHistoryBuffer.beginTurn}, so tool_use never separates from
|
|
31
60
|
* its tool_result), amortizing the cache re-pay to one write per event.
|
|
32
61
|
* Byte-stability is an invariant of THIS stored serialization; the final
|
|
33
62
|
* wire request may still diverge under dynamic memory-context injection
|
|
@@ -52,6 +81,19 @@ export declare class SessionHistoryBuffer {
|
|
|
52
81
|
* is dropped (spec §1d).
|
|
53
82
|
*/
|
|
54
83
|
appendSendDelta(delta: SessionTranscriptMessage[], label?: string, expectEpoch?: number): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Starts a turn whose steps land as one block (GMI path). The turn is tied
|
|
86
|
+
* to the current epoch: a reseed or clear while it runs discards it at
|
|
87
|
+
* commit, as {@link appendSendDelta} discards a stale send. Eviction runs
|
|
88
|
+
* at commit only, so a turn's earlier steps can never be evicted while its
|
|
89
|
+
* later steps are still being written.
|
|
90
|
+
*
|
|
91
|
+
* @param label - Telemetry and eviction-boundary label for the turn's block.
|
|
92
|
+
* @param expectEpoch - The epoch the turn started under, when it read the
|
|
93
|
+
* history before calling this (default: the current epoch). A reseed or
|
|
94
|
+
* clear between that read and this call makes the turn's commit a no-op.
|
|
95
|
+
*/
|
|
96
|
+
beginTurn(label?: string, expectEpoch?: number): SessionTurnWriter;
|
|
55
97
|
/** Atomic replace + epoch bump. Throws on pairing-invalid snapshots. */
|
|
56
98
|
reseed(snapshot: SessionTranscriptMessage[]): void;
|
|
57
99
|
/** Returns accumulated telemetry events and clears the queue. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionHistory.d.ts","sourceRoot":"","sources":["../../src/api/sessionHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC,yFAAyF;AACzF,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC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