@dudousxd/nestjs-agent-core 0.44.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -116,7 +116,7 @@ function observeTurnFrames(writer, now = Date.now) {
116
116
  return;
117
117
  }
118
118
  closeBurst();
119
- if (event.kind === "ui") {
119
+ if (event.kind === "ui" && event.partial !== true) {
120
120
  ui.set(event.id, {
121
121
  id: event.id,
122
122
  component: event.component,
@@ -186,6 +186,423 @@ function withTurnFrames(result2, frames) {
186
186
  }
187
187
  __name(withTurnFrames, "withTurnFrames");
188
188
 
189
+ // src/partial-json.ts
190
+ var Cut = class Cut2 extends Error {
191
+ static {
192
+ __name(this, "Cut");
193
+ }
194
+ };
195
+ function parsePartialJson(text) {
196
+ const open = /* @__PURE__ */ new WeakSet();
197
+ const pending = /* @__PURE__ */ new WeakMap();
198
+ let at = 0;
199
+ const skipSpace = /* @__PURE__ */ __name(() => {
200
+ while (at < text.length) {
201
+ const char = text.charCodeAt(at);
202
+ if (char === 32 || char === 9 || char === 10 || char === 13) at += 1;
203
+ else break;
204
+ }
205
+ }, "skipSpace");
206
+ const fail = /* @__PURE__ */ __name(() => {
207
+ throw new SyntaxError(`unexpected character at ${at}`);
208
+ }, "fail");
209
+ const readString = /* @__PURE__ */ __name(() => {
210
+ at += 1;
211
+ let out = "";
212
+ while (at < text.length) {
213
+ const char = text[at];
214
+ if (char === '"') {
215
+ at += 1;
216
+ return {
217
+ value: out,
218
+ cut: false
219
+ };
220
+ }
221
+ if (char === "\\") {
222
+ const next = text[at + 1];
223
+ if (next === void 0) {
224
+ at = text.length;
225
+ return {
226
+ value: out,
227
+ cut: true
228
+ };
229
+ }
230
+ if (next === "u") {
231
+ const hex = text.slice(at + 2, at + 6);
232
+ if (hex.length < 4) {
233
+ at = text.length;
234
+ return {
235
+ value: out,
236
+ cut: true
237
+ };
238
+ }
239
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) fail();
240
+ out += String.fromCharCode(Number.parseInt(hex, 16));
241
+ at += 6;
242
+ continue;
243
+ }
244
+ const escapes = {
245
+ '"': '"',
246
+ "\\": "\\",
247
+ "/": "/",
248
+ b: "\b",
249
+ f: "\f",
250
+ n: "\n",
251
+ r: "\r",
252
+ t: " "
253
+ };
254
+ const escaped = escapes[next];
255
+ if (escaped === void 0) fail();
256
+ out += escaped;
257
+ at += 2;
258
+ continue;
259
+ }
260
+ out += char;
261
+ at += 1;
262
+ }
263
+ return {
264
+ value: out,
265
+ cut: true
266
+ };
267
+ }, "readString");
268
+ const readValue = /* @__PURE__ */ __name(() => {
269
+ skipSpace();
270
+ if (at >= text.length) throw new Cut();
271
+ const char = text[at];
272
+ if (char === "{") return readObject();
273
+ if (char === "[") return readArray();
274
+ if (char === '"') return readString();
275
+ const rest = text.slice(at);
276
+ const number = /^-?\d*(?:\.\d*)?(?:[eE][+-]?\d*)?/.exec(rest)?.[0] ?? "";
277
+ if (number.length > 0) {
278
+ if (at + number.length >= text.length) throw new Cut();
279
+ if (!/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(number)) fail();
280
+ at += number.length;
281
+ return {
282
+ value: Number(number),
283
+ cut: false
284
+ };
285
+ }
286
+ for (const [word, value] of [
287
+ [
288
+ "true",
289
+ true
290
+ ],
291
+ [
292
+ "false",
293
+ false
294
+ ],
295
+ [
296
+ "null",
297
+ null
298
+ ]
299
+ ]) {
300
+ if (rest.startsWith(word)) {
301
+ at += word.length;
302
+ return {
303
+ value,
304
+ cut: false
305
+ };
306
+ }
307
+ if (word.startsWith(rest)) throw new Cut();
308
+ }
309
+ return fail();
310
+ }, "readValue");
311
+ const readObject = /* @__PURE__ */ __name(() => {
312
+ const object = {};
313
+ open.add(object);
314
+ at += 1;
315
+ skipSpace();
316
+ if (text[at] === "}") {
317
+ at += 1;
318
+ open.delete(object);
319
+ return {
320
+ value: object,
321
+ cut: false
322
+ };
323
+ }
324
+ for (; ; ) {
325
+ skipSpace();
326
+ if (at >= text.length) return {
327
+ value: object,
328
+ cut: true
329
+ };
330
+ if (text[at] !== '"') fail();
331
+ const key = readString();
332
+ if (key.cut) return {
333
+ value: object,
334
+ cut: true
335
+ };
336
+ skipSpace();
337
+ if (at >= text.length) {
338
+ pending.set(object, key.value);
339
+ return {
340
+ value: object,
341
+ cut: true
342
+ };
343
+ }
344
+ if (text[at] !== ":") fail();
345
+ at += 1;
346
+ let member;
347
+ try {
348
+ member = readValue();
349
+ } catch (error) {
350
+ if (!(error instanceof Cut)) throw error;
351
+ pending.set(object, key.value);
352
+ return {
353
+ value: object,
354
+ cut: true
355
+ };
356
+ }
357
+ object[key.value] = member.value;
358
+ if (member.cut) {
359
+ pending.set(object, key.value);
360
+ return {
361
+ value: object,
362
+ cut: true
363
+ };
364
+ }
365
+ skipSpace();
366
+ if (at >= text.length) return {
367
+ value: object,
368
+ cut: true
369
+ };
370
+ if (text[at] === ",") {
371
+ at += 1;
372
+ continue;
373
+ }
374
+ if (text[at] === "}") {
375
+ at += 1;
376
+ open.delete(object);
377
+ return {
378
+ value: object,
379
+ cut: false
380
+ };
381
+ }
382
+ fail();
383
+ }
384
+ }, "readObject");
385
+ const readArray = /* @__PURE__ */ __name(() => {
386
+ const array = [];
387
+ open.add(array);
388
+ at += 1;
389
+ skipSpace();
390
+ if (text[at] === "]") {
391
+ at += 1;
392
+ open.delete(array);
393
+ return {
394
+ value: array,
395
+ cut: false
396
+ };
397
+ }
398
+ for (; ; ) {
399
+ let item;
400
+ try {
401
+ item = readValue();
402
+ } catch (error) {
403
+ if (!(error instanceof Cut)) throw error;
404
+ pending.set(array, array.length);
405
+ return {
406
+ value: array,
407
+ cut: true
408
+ };
409
+ }
410
+ array.push(item.value);
411
+ if (item.cut) {
412
+ pending.set(array, array.length - 1);
413
+ return {
414
+ value: array,
415
+ cut: true
416
+ };
417
+ }
418
+ skipSpace();
419
+ if (at >= text.length) return {
420
+ value: array,
421
+ cut: true
422
+ };
423
+ if (text[at] === ",") {
424
+ at += 1;
425
+ continue;
426
+ }
427
+ if (text[at] === "]") {
428
+ at += 1;
429
+ open.delete(array);
430
+ return {
431
+ value: array,
432
+ cut: false
433
+ };
434
+ }
435
+ fail();
436
+ }
437
+ }, "readArray");
438
+ let root;
439
+ try {
440
+ root = readValue();
441
+ } catch (error) {
442
+ if (error instanceof Cut) root = {
443
+ value: void 0,
444
+ cut: true
445
+ };
446
+ else return void 0;
447
+ }
448
+ skipSpace();
449
+ return {
450
+ value: root.value,
451
+ complete: !root.cut && at >= text.length,
452
+ isOpen: /* @__PURE__ */ __name((container) => open.has(container), "isOpen"),
453
+ pendingMember: /* @__PURE__ */ __name((container) => pending.get(container), "pendingMember")
454
+ };
455
+ }
456
+ __name(parsePartialJson, "parsePartialJson");
457
+
458
+ // src/tool-input-preview.ts
459
+ var DEFAULT_PREVIEW_THROTTLE_MS = 100;
460
+ function previewUiId(toolCallId) {
461
+ return `${toolCallId}:ui:0`;
462
+ }
463
+ __name(previewUiId, "previewUiId");
464
+ function withdrawPreviewEvent(shown) {
465
+ return {
466
+ kind: "ui",
467
+ id: shown.id,
468
+ component: shown.component,
469
+ props: {},
470
+ toolCallId: shown.toolCallId,
471
+ partial: true
472
+ };
473
+ }
474
+ __name(withdrawPreviewEvent, "withdrawPreviewEvent");
475
+ function previewToolInputs(inner, resolve, now = Date.now) {
476
+ const calls = /* @__PURE__ */ new Map();
477
+ const shown = /* @__PURE__ */ new Map();
478
+ const decoder3 = new TextDecoder();
479
+ let pending = "";
480
+ async function emit2(id, state, input, done) {
481
+ let rendered;
482
+ try {
483
+ const parsed = done && input !== void 0 ? {
484
+ value: input,
485
+ complete: true,
486
+ isOpen: /* @__PURE__ */ __name(() => false, "isOpen"),
487
+ pendingMember: /* @__PURE__ */ __name(() => void 0, "pendingMember")
488
+ } : parsePartialJson(state.text);
489
+ if (parsed === void 0) return;
490
+ rendered = state.preview.render({
491
+ value: parsed.value,
492
+ done: done || parsed.complete,
493
+ isOpen: parsed.isOpen,
494
+ pendingMember: parsed.pendingMember
495
+ });
496
+ } catch {
497
+ rendered = null;
498
+ }
499
+ if (rendered === void 0) return;
500
+ const uiId = previewUiId(id);
501
+ if (rendered === null) {
502
+ state.stopped = true;
503
+ const standing = shown.get(uiId);
504
+ if (standing !== void 0) {
505
+ shown.delete(uiId);
506
+ await inner.write(encodeStreamEvent(withdrawPreviewEvent(standing)));
507
+ }
508
+ return;
509
+ }
510
+ const props = JSON.stringify(rendered.props);
511
+ if (props === state.lastProps && rendered.component === state.component) return;
512
+ state.lastProps = props;
513
+ state.component = rendered.component;
514
+ state.lastAt = now();
515
+ shown.set(uiId, {
516
+ id: uiId,
517
+ component: rendered.component,
518
+ toolCallId: id
519
+ });
520
+ await inner.write(encodeStreamEvent({
521
+ kind: "ui",
522
+ id: uiId,
523
+ component: rendered.component,
524
+ props: JSON.parse(props),
525
+ ...rendered.version !== void 0 ? {
526
+ version: rendered.version
527
+ } : {},
528
+ toolCallId: id,
529
+ partial: true
530
+ }));
531
+ }
532
+ __name(emit2, "emit");
533
+ async function observe(event) {
534
+ if (event.kind === "tool-input-start") {
535
+ if (calls.has(event.id)) return;
536
+ let preview;
537
+ try {
538
+ preview = await resolve(event.name, event.id);
539
+ } catch {
540
+ preview = void 0;
541
+ }
542
+ if (preview !== void 0) {
543
+ calls.set(event.id, {
544
+ preview,
545
+ text: "",
546
+ lastAt: void 0,
547
+ lastProps: void 0,
548
+ component: void 0,
549
+ stopped: false
550
+ });
551
+ }
552
+ return;
553
+ }
554
+ if (event.kind === "tool-input-delta") {
555
+ const state = calls.get(event.id);
556
+ if (state === void 0 || state.stopped) return;
557
+ state.text += event.delta;
558
+ const throttle = state.preview.throttleMs ?? DEFAULT_PREVIEW_THROTTLE_MS;
559
+ if (state.lastAt !== void 0 && now() - state.lastAt < throttle) return;
560
+ await emit2(event.id, state, void 0, false);
561
+ return;
562
+ }
563
+ if (event.kind === "tool-input-available") {
564
+ const state = calls.get(event.id);
565
+ if (state === void 0) return;
566
+ calls.delete(event.id);
567
+ if (state.stopped) return;
568
+ await emit2(event.id, state, event.input, true);
569
+ }
570
+ }
571
+ __name(observe, "observe");
572
+ return {
573
+ writer: {
574
+ async write(chunk) {
575
+ await inner.write(chunk);
576
+ pending += decoder3.decode(chunk, {
577
+ stream: true
578
+ });
579
+ let newline = pending.indexOf("\n");
580
+ while (newline !== -1) {
581
+ const line = pending.slice(0, newline);
582
+ pending = pending.slice(newline + 1);
583
+ const event = line.trim().length > 0 ? decodeStreamEvent(line) : null;
584
+ if (event !== null) await observe(event);
585
+ newline = pending.indexOf("\n");
586
+ }
587
+ },
588
+ end: /* @__PURE__ */ __name(() => inner.end(), "end"),
589
+ fail: /* @__PURE__ */ __name((error) => inner.fail(error), "fail")
590
+ },
591
+ shown: /* @__PURE__ */ __name(() => [
592
+ ...shown.values()
593
+ ], "shown")
594
+ };
595
+ }
596
+ __name(previewToolInputs, "previewToolInputs");
597
+ function registryInputPreviews(registry, offered, scope) {
598
+ const names = new Set(offered.map((tool) => tool.name));
599
+ return async (toolName, toolCallId) => names.has(toolName) ? registry.previewInput(toolName, {
600
+ ...scope,
601
+ toolCallId
602
+ }) : void 0;
603
+ }
604
+ __name(registryInputPreviews, "registryInputPreviews");
605
+
189
606
  // src/tool-ui.ts
190
607
  var TOOL_STEP_UI = "@@nestjs-agent/tool-step-ui";
191
608
  function wrapToolStepOutput(output, ui, text) {
@@ -2715,9 +3132,10 @@ function actionProposalOutcomeFenceValid(row2, command, now) {
2715
3132
  }
2716
3133
  __name(actionProposalOutcomeFenceValid, "actionProposalOutcomeFenceValid");
2717
3134
  function outcomeSummary(outcome) {
2718
- if (outcome.executionStatus === "succeeded") return `Action ${JSON.stringify(outcome.toolName)} completed (proposal ${JSON.stringify(outcome.proposalId)}).${Object.hasOwn(outcome, "result") ? ` Result: ${JSON.stringify(outcome.result)}` : ""}`;
2719
- if (outcome.executionStatus === "failed") return `Action ${JSON.stringify(outcome.toolName)} failed (proposal ${JSON.stringify(outcome.proposalId)}): ${JSON.stringify(outcome.error ?? "Execution failed")}`;
2720
- return `Action ${JSON.stringify(outcome.toolName)} was ${outcome.decision} (proposal ${JSON.stringify(outcome.proposalId)}) and was not executed.${outcome.error ? ` Reason: ${JSON.stringify(outcome.error)}` : ""}`;
3135
+ const tool = JSON.stringify(outcome.toolName);
3136
+ if (outcome.executionStatus === "succeeded") return `Action ${tool} completed.${Object.hasOwn(outcome, "result") ? ` Result: ${JSON.stringify(outcome.result)}` : ""}`;
3137
+ if (outcome.executionStatus === "failed") return `Action ${tool} failed: ${JSON.stringify(outcome.error ?? "Execution failed")}`;
3138
+ return `Action ${tool} was ${outcome.decision} and was not executed.${outcome.error ? ` Reason: ${JSON.stringify(outcome.error)}` : ""}`;
2721
3139
  }
2722
3140
  __name(outcomeSummary, "outcomeSummary");
2723
3141
  function actionProposalOutcomeScope(outcome) {
@@ -2728,8 +3146,15 @@ function actionProposalOutcomeScope(outcome) {
2728
3146
  };
2729
3147
  }
2730
3148
  __name(actionProposalOutcomeScope, "actionProposalOutcomeScope");
3149
+ function storableText(text) {
3150
+ return text.replaceAll(String.fromCharCode(0), "\\u0000").replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g, (char) => `\\u${char.charCodeAt(0).toString(16)}`);
3151
+ }
3152
+ __name(storableText, "storableText");
2731
3153
  function actionProposalOutcomeText(outcome) {
2732
- return outcomeSummary(outcome) + (outcome.text ? ` UI: ${JSON.stringify(outcome.text)}` : "");
3154
+ const text = outcome.text === void 0 ? void 0 : storableText(outcome.text).trim();
3155
+ return text ? `${text}
3156
+
3157
+ ${outcomeSummary(outcome)}` : outcomeSummary(outcome);
2733
3158
  }
2734
3159
  __name(actionProposalOutcomeText, "actionProposalOutcomeText");
2735
3160
 
@@ -3064,6 +3489,7 @@ function defineComponent(definition) {
3064
3489
  }
3065
3490
  if (definition.version !== void 0 && (!Number.isSafeInteger(definition.version) || definition.version <= 0)) throw new RangeError("genui: component version must be a positive safe integer");
3066
3491
  if (definition.fallbackText !== void 0 && typeof definition.fallbackText !== "function") throw new TypeError("genui: fallbackText must be a function");
3492
+ if (definition.streaming !== void 0 && definition.streaming !== "partial" && definition.streaming !== "complete") throw new TypeError("genui: streaming must be 'partial' or 'complete'");
3067
3493
  return definition;
3068
3494
  }
3069
3495
  __name(defineComponent, "defineComponent");
@@ -4422,6 +4848,19 @@ var ToolRegistry = class {
4422
4848
  unregister(name) {
4423
4849
  return this.entries.delete(name);
4424
4850
  }
4851
+ /**
4852
+ * How a streamed call of `name` is previewed while its input arrives (`ToolHandler.previewInput`),
4853
+ * or `undefined`. A preview that fails to build is no preview: it never fails the turn.
4854
+ */
4855
+ async previewInput(name, scope) {
4856
+ const handler = this.entries.get(name)?.handler;
4857
+ if (handler?.previewInput === void 0) return void 0;
4858
+ try {
4859
+ return await handler.previewInput(scope) ?? void 0;
4860
+ } catch {
4861
+ return void 0;
4862
+ }
4863
+ }
4425
4864
  spec(name) {
4426
4865
  return this.entries.get(name)?.spec;
4427
4866
  }
@@ -4480,6 +4919,9 @@ var ToolRegistry = class {
4480
4919
  * Run a tool. Re-checks that the tool is enabled and that the role allows it (defense-in-depth —
4481
4920
  * a call can reach here from a replayed durable step or an approval granted before the flag
4482
4921
  * moved, neither of which went through `definitionsFor` again) and re-parses the input via Zod.
4922
+ * A tool whose `describe()` answers `available: false` for the call's scope (actor, thread, agent,
4923
+ * `uiCapabilities`) is refused with {@link ToolNotFoundError}, as the unknown tool it was to the
4924
+ * model.
4483
4925
  */
4484
4926
  async invoke(name, input, ctx, policy, options = {}) {
4485
4927
  const { entry, value, ctx: withEmit } = await this.validated(name, input, ctx, policy, options);
@@ -4533,6 +4975,10 @@ var ToolRegistry = class {
4533
4975
  if (options.allowedTools !== void 0 && !options.allowedTools.includes(name)) {
4534
4976
  throw new ToolForbiddenError(name);
4535
4977
  }
4978
+ if (entry.handler.describe !== void 0) {
4979
+ const described = await entry.handler.describe(describeScopeOf(ctx));
4980
+ if (described?.available === false) throw new ToolNotFoundError(name);
4981
+ }
4536
4982
  const validation = await entry.spec.inputSchema["~standard"].validate(input);
4537
4983
  if (validation.issues !== void 0) {
4538
4984
  throw new ToolInputInvalidError(name, validation.issues);
@@ -4548,6 +4994,21 @@ var ToolRegistry = class {
4548
4994
  };
4549
4995
  }
4550
4996
  };
4997
+ function describeScopeOf(ctx) {
4998
+ return {
4999
+ actor: ctx.actor,
5000
+ ...ctx.threadId ? {
5001
+ threadId: ctx.threadId
5002
+ } : {},
5003
+ ...ctx.agentName !== void 0 ? {
5004
+ agentName: ctx.agentName
5005
+ } : {},
5006
+ ...ctx.uiCapabilities !== void 0 ? {
5007
+ uiCapabilities: ctx.uiCapabilities
5008
+ } : {}
5009
+ };
5010
+ }
5011
+ __name(describeScopeOf, "describeScopeOf");
4551
5012
  var DefaultRolesPolicy = class {
4552
5013
  static {
4553
5014
  __name(this, "DefaultRolesPolicy");
@@ -4931,6 +5392,21 @@ var RunCancelledError = class extends Error {
4931
5392
  this.name = "RunCancelledError";
4932
5393
  }
4933
5394
  };
5395
+ async function abortableModelCall(hooks, call) {
5396
+ const signal = hooks.abortSignal;
5397
+ let result2;
5398
+ try {
5399
+ result2 = await call(signal !== void 0 ? {
5400
+ abortSignal: signal
5401
+ } : {});
5402
+ } catch (error) {
5403
+ if (signal?.aborted === true) throw new RunCancelledError();
5404
+ throw error;
5405
+ }
5406
+ if (signal?.aborted === true) throw new RunCancelledError();
5407
+ return result2;
5408
+ }
5409
+ __name(abortableModelCall, "abortableModelCall");
4934
5410
  function agentFailureCode(error) {
4935
5411
  if (error instanceof RunCancelledError) {
4936
5412
  return "cancelled";
@@ -5388,13 +5864,14 @@ async function structureAnswer(schema, deps, input, hooks, messages, step) {
5388
5864
  fail: /* @__PURE__ */ __name(() => {
5389
5865
  }, "fail")
5390
5866
  };
5391
- const turn = await deps.model.runTurn({
5867
+ const turn = await abortableModelCall(hooks, (signal) => deps.model.runTurn({
5392
5868
  system,
5393
5869
  messages,
5394
5870
  tools: [],
5395
5871
  sink: discard,
5396
- outputSchema: schema
5397
- });
5872
+ outputSchema: schema,
5873
+ ...signal
5874
+ }));
5398
5875
  return {
5399
5876
  text: turn.text,
5400
5877
  usage: turn.usage,
@@ -5516,6 +5993,9 @@ function toolContext(deps, input, hooks) {
5516
5993
  ...deps.host !== void 0 ? {
5517
5994
  host: deps.host
5518
5995
  } : {},
5996
+ ...hooks.abortSignal !== void 0 ? {
5997
+ abortSignal: hooks.abortSignal
5998
+ } : {},
5519
5999
  // Replaced per tool call by the call's own collector (see the tool step); this one only serves
5520
6000
  // what runs outside a call — the elicitation wait.
5521
6001
  emitUi: createNoopEmitUi(hooks.runId)
@@ -6883,26 +7363,46 @@ ${block}`;
6883
7363
  writer
6884
7364
  }) : void 0;
6885
7365
  const buffer = gateMode === "whole" ? createFrameBuffer() : void 0;
6886
- const frames = observeTurnFrames(incremental?.writer ?? buffer?.writer ?? writer);
6887
- const result2 = stampToolKinds(withTurnFrames(await traceLlmTurn(hooks.runId, i, () => deps.model.runTurn({
7366
+ const previews = previewToolInputs(incremental?.writer ?? buffer?.writer ?? writer, registryInputPreviews(deps.registry, tools, {
7367
+ actor: input.actor,
7368
+ threadId: input.threadId,
7369
+ ...input.agentName !== void 0 ? {
7370
+ agentName: input.agentName
7371
+ } : {},
7372
+ ...input.uiCapabilities !== void 0 ? {
7373
+ uiCapabilities: input.uiCapabilities
7374
+ } : {}
7375
+ }));
7376
+ const frames = observeTurnFrames(previews.writer);
7377
+ const result2 = stampToolKinds(withTurnFrames(await traceLlmTurn(hooks.runId, i, () => abortableModelCall(hooks, (signal) => deps.model.runTurn({
6888
7378
  system: prompt.system,
6889
7379
  messages: prompt.messages,
6890
7380
  tools,
6891
- sink: frames.writer
6892
- })), frames.summary()), deps);
7381
+ sink: frames.writer,
7382
+ ...signal
7383
+ }))), frames.summary()), deps);
7384
+ const shownPreviews = previews.shown();
7385
+ const previewed = shownPreviews.length > 0 ? {
7386
+ previews: shownPreviews
7387
+ } : {};
6893
7388
  if (incremental !== void 0) {
6894
7389
  await incremental.settled();
6895
7390
  const refusal = incremental.rejection();
6896
7391
  return {
6897
7392
  ...result2,
7393
+ ...previewed,
6898
7394
  releasedText: incremental.released(),
6899
7395
  ...refusal !== void 0 ? {
6900
7396
  gateRejection: refusal
6901
7397
  } : {}
6902
7398
  };
6903
7399
  }
6904
- return buffer === void 0 ? result2 : {
7400
+ return buffer === void 0 ? {
7401
+ ...result2,
7402
+ ...previewed
7403
+ } : {
6905
7404
  ...result2,
7405
+ ...previewed,
6906
7406
  bufferedFrames: buffer.frames()
6907
7407
  };
6908
7408
  });
@@ -7221,6 +7721,12 @@ ${block}`;
7221
7721
  if (toolUi.length > 0) {
7222
7722
  await deps.store.setMessageUi?.(assistant.id, mergeUi(turn.ui, toolUi));
7223
7723
  }
7724
+ for (const preview of turn.previews ?? []) {
7725
+ const pushed = turnCalls.toolUi.get(preview.toolCallId) ?? [];
7726
+ if (!pushed.some((component) => component.id === preview.id)) {
7727
+ await writer.write(encodeStreamEvent(withdrawPreviewEvent(preview)));
7728
+ }
7729
+ }
7224
7730
  for (const result2 of results) {
7225
7731
  await writer.write(encodeStreamEvent(outputFrame(result2)));
7226
7732
  }
@@ -9159,9 +9665,9 @@ var ptBrActionProposalText = {
9159
9665
  ]
9160
9666
  },
9161
9667
  replies: {
9162
- approved: "Proposta aprovada e enfileirada para execu\xE7\xE3o.",
9163
- rejected: "Proposta rejeitada; nenhuma a\xE7\xE3o foi executada.",
9164
- expired: "A proposta expirou; nenhuma a\xE7\xE3o foi executada.",
9668
+ approved: "Confirmado! J\xE1 estou cuidando disso.",
9669
+ rejected: "Tudo bem, cancelado. Nada foi feito.",
9670
+ expired: "Esse pedido expirou; nada foi feito.",
9165
9671
  unchanged: "N\xE3o foi poss\xEDvel alterar esta proposta; atualize a lista para consultar seu estado.",
9166
9672
  ambiguous: /* @__PURE__ */ __name((ids) => `Qual proposta? Responda confirmar #ID ou cancelar #ID: ${ids.join(", ")}`, "ambiguous"),
9167
9673
  tooMany: "H\xE1 v\xE1rias propostas. Confirme ou rejeite usando #ID expl\xEDcito."
@@ -9505,6 +10011,7 @@ export {
9505
10011
  DEFAULT_MAX_FACT_CHARS,
9506
10012
  DEFAULT_MAX_MEMORIES,
9507
10013
  DEFAULT_MAX_SKILLS,
10014
+ DEFAULT_PREVIEW_THROTTLE_MS,
9508
10015
  DEFAULT_REFUSAL_REASON,
9509
10016
  DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION,
9510
10017
  DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES,
@@ -9623,9 +10130,12 @@ export {
9623
10130
  observeTurnFrames,
9624
10131
  offerMemories,
9625
10132
  offerSkills,
10133
+ parsePartialJson,
9626
10134
  parseTextActionProposalCommand,
9627
10135
  personaCatalogEntry,
9628
10136
  prepareActionProposal,
10137
+ previewToolInputs,
10138
+ previewUiId,
9629
10139
  ptBrActionProposalText,
9630
10140
  publishAgentDelegated,
9631
10141
  publishAgentMemoryResolved,
@@ -9646,6 +10156,7 @@ export {
9646
10156
  quotaWarning,
9647
10157
  readElicitationInput,
9648
10158
  readElicitationQuestions,
10159
+ registryInputPreviews,
9649
10160
  releaseGatedFrames,
9650
10161
  releaseThreadRun,
9651
10162
  rememberInputSchema,
@@ -9714,6 +10225,7 @@ export {
9714
10225
  withSkillTool,
9715
10226
  withToolTimeout,
9716
10227
  withTurnFrames,
10228
+ withdrawPreviewEvent,
9717
10229
  wrapToolPreflightDenied,
9718
10230
  wrapToolStepOutput,
9719
10231
  writeMemory