@meetsmore-oss/use-ai-server 1.9.4 → 1.9.5
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/agents/AISDKAgent.d.ts +16 -0
- package/dist/agents/AISDKAgent.d.ts.map +1 -1
- package/dist/agents/AISDKAgent.perStepEvents.test.d.ts +2 -0
- package/dist/agents/AISDKAgent.perStepEvents.test.d.ts.map +1 -0
- package/dist/index.js +112 -39
- package/dist/src/agents/AISDKAgent.d.ts +16 -0
- package/dist/src/agents/AISDKAgent.d.ts.map +1 -1
- package/dist/src/agents/AISDKAgent.perStepEvents.test.d.ts +2 -0
- package/dist/src/agents/AISDKAgent.perStepEvents.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -252,6 +252,16 @@ export declare class AISDKAgent implements Agent {
|
|
|
252
252
|
* Each step runs ONE model invocation, then checks for updated tools/state.
|
|
253
253
|
*/
|
|
254
254
|
private executeStepLoop;
|
|
255
|
+
/**
|
|
256
|
+
* Detects incomplete tool calls caused by maxOutputTokens truncation and injects
|
|
257
|
+
* synthetic error tool_results into ctx so the model can retry with shorter arguments.
|
|
258
|
+
*
|
|
259
|
+
* When the stream is cut mid-tool-input, tool-input-start fires but tool-call never fires.
|
|
260
|
+
*
|
|
261
|
+
* Mutates ctx.allResponseMessages and ctx.currentMessages as a side effect.
|
|
262
|
+
* @returns true if recovery messages were injected (caller should continue to next step)
|
|
263
|
+
*/
|
|
264
|
+
private handleIncompleteToolCalls;
|
|
255
265
|
/**
|
|
256
266
|
* Processes a single stream chunk, emitting the appropriate AG-UI events.
|
|
257
267
|
* Mutates stepCtx.stepHadToolCalls when a tool call is detected.
|
|
@@ -291,6 +301,12 @@ export declare class AISDKAgent implements Agent {
|
|
|
291
301
|
* @returns A SystemModelMessage with the state, or undefined if no state
|
|
292
302
|
*/
|
|
293
303
|
private buildStateMessage;
|
|
304
|
+
/**
|
|
305
|
+
* When maxSteps is exhausted mid-tool-call chain, overrides step config
|
|
306
|
+
* to strip tools and inject a summary prompt so the model can summarize progress.
|
|
307
|
+
* No-ops when isGracefulSummaryStep is false.
|
|
308
|
+
*/
|
|
309
|
+
private applyGracefulSummaryOverrides;
|
|
294
310
|
/**
|
|
295
311
|
* Filters tools using the configured filter function.
|
|
296
312
|
* If no filter is configured, returns all tools.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AISDKAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,aAAa,
|
|
1
|
+
{"version":3,"file":"AISDKAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,aAAa,EAA8G,MAAM,IAAI,CAAC;AAMvK,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AA0BpE,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAoGjF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC;IAE/C;;;;;;;;;;;;;;;;;;;;;;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;;;;;OAKG;YACW,mBAAmB;IAcjC;;;;;;;OAOG;IACH,OAAO,CAAC,yBAAyB;IAgBjC;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;OAIG;IACH,OAAO,CAAC,6BAA6B;IAUrC;;;OAGG;IACH,OAAO,CAAC,WAAW;IAsBnB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAyD7B,OAAO,CAAC,mBAAmB;IAyC3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAMpC;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAKlC;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAG9B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAG/B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAI9B;IAEX;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAWhD;IAEJ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAOtC;IAEH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAM1B;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAqC;IAEhF;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;CAgBzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AISDKAgent.perStepEvents.test.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.perStepEvents.test.ts"],"names":[],"mappings":""}
|
package/dist/index.js
CHANGED
|
@@ -114191,14 +114191,13 @@ class AISDKAgent {
|
|
|
114191
114191
|
originalInput,
|
|
114192
114192
|
staticSystemMessages,
|
|
114193
114193
|
streamTextStarted: false,
|
|
114194
|
-
messageId: null,
|
|
114195
|
-
hasEmittedTextStart: false,
|
|
114196
114194
|
finalText: "",
|
|
114197
114195
|
currentStepNumber: 0,
|
|
114198
114196
|
hasAnyContent: false,
|
|
114199
114197
|
currentMessages: [...sanitizedInputMessages],
|
|
114200
114198
|
allResponseMessages: [],
|
|
114201
|
-
response: null
|
|
114199
|
+
response: null,
|
|
114200
|
+
lastStepHadToolCalls: false
|
|
114202
114201
|
};
|
|
114203
114202
|
}
|
|
114204
114203
|
emitRunStartEvents(ctx, events) {
|
|
@@ -114245,46 +114244,51 @@ class AISDKAgent {
|
|
|
114245
114244
|
});
|
|
114246
114245
|
}
|
|
114247
114246
|
async executeStepLoop(ctx, events, span) {
|
|
114248
|
-
for (let stepIteration = 0;stepIteration
|
|
114247
|
+
for (let stepIteration = 0;stepIteration <= this.maxSteps; stepIteration++) {
|
|
114248
|
+
const isGracefulSummaryStep = stepIteration === this.maxSteps;
|
|
114249
|
+
if (isGracefulSummaryStep && !ctx.lastStepHadToolCalls)
|
|
114250
|
+
break;
|
|
114249
114251
|
const stepCtx = {
|
|
114250
114252
|
currentTools: ctx.session.tools,
|
|
114251
114253
|
activeToolCalls: new Map,
|
|
114252
|
-
|
|
114254
|
+
completedToolCalls: new Set,
|
|
114255
|
+
stepHadToolCalls: false,
|
|
114256
|
+
messageId: null,
|
|
114257
|
+
hasEmittedTextStart: false,
|
|
114258
|
+
stepFinishReason: undefined
|
|
114253
114259
|
};
|
|
114254
|
-
logger2.debug("Starting step iteration", {
|
|
114255
|
-
stepIteration,
|
|
114256
|
-
toolCount: stepCtx.currentTools.length,
|
|
114257
|
-
toolNames: stepCtx.currentTools.map((t) => t.name)
|
|
114258
|
-
});
|
|
114259
114260
|
const stateMessage = this.buildStateMessage(ctx.session.state);
|
|
114260
114261
|
const messagesForStep = [
|
|
114261
114262
|
...ctx.staticSystemMessages || [],
|
|
114262
114263
|
...stateMessage ? [stateMessage] : [],
|
|
114263
114264
|
...ctx.currentMessages
|
|
114264
114265
|
];
|
|
114265
|
-
const
|
|
114266
|
+
const stepConfig = {
|
|
114267
|
+
messages: messagesForStep,
|
|
114268
|
+
tools: stepCtx.currentTools.length > 0 ? this.sanitizeToolsForAPI(this.filterTools(stepCtx.currentTools), ctx.session, events) : undefined,
|
|
114269
|
+
metadata: {
|
|
114270
|
+
sessionId: ctx.session.clientId,
|
|
114271
|
+
threadId: ctx.session.threadId,
|
|
114272
|
+
runId: ctx.runId,
|
|
114273
|
+
ipAddress: ctx.session.ipAddress,
|
|
114274
|
+
toolCount: stepCtx.currentTools.length,
|
|
114275
|
+
stepIteration,
|
|
114276
|
+
...ctx.originalInput.forwardedProps?.telemetryMetadata || {}
|
|
114277
|
+
}
|
|
114278
|
+
};
|
|
114279
|
+
this.applyGracefulSummaryOverrides(isGracefulSummaryStep, stepConfig);
|
|
114280
|
+
logger2.debug("Starting step iteration", { stepIteration, ...stepConfig.metadata });
|
|
114281
|
+
const messagesWithCache = applyCacheBreakpoints(stepConfig.messages, this.cacheBreakpoint, this.model);
|
|
114266
114282
|
ctx.streamTextStarted = true;
|
|
114267
114283
|
const createStream = () => streamText({
|
|
114268
114284
|
model: this.model,
|
|
114269
114285
|
messages: messagesWithCache,
|
|
114270
|
-
tools:
|
|
114286
|
+
tools: stepConfig.tools,
|
|
114271
114287
|
stopWhen: stepCountIs(1),
|
|
114272
114288
|
maxOutputTokens: this.maxOutputTokens,
|
|
114273
114289
|
temperature: this.temperature,
|
|
114274
114290
|
abortSignal: ctx.session.abortController?.signal,
|
|
114275
|
-
experimental_telemetry: span.active ? {
|
|
114276
|
-
isEnabled: true,
|
|
114277
|
-
functionId: "use-ai",
|
|
114278
|
-
metadata: {
|
|
114279
|
-
sessionId: ctx.session.clientId,
|
|
114280
|
-
threadId: ctx.session.threadId,
|
|
114281
|
-
runId: ctx.runId,
|
|
114282
|
-
ipAddress: ctx.session.ipAddress,
|
|
114283
|
-
toolCount: stepCtx.currentTools.length,
|
|
114284
|
-
stepIteration,
|
|
114285
|
-
...ctx.originalInput.forwardedProps?.telemetryMetadata || {}
|
|
114286
|
-
}
|
|
114287
|
-
} : undefined,
|
|
114291
|
+
experimental_telemetry: span.active ? { isEnabled: true, functionId: "use-ai", metadata: stepConfig.metadata } : undefined,
|
|
114288
114292
|
onStepFinish: ({ usage, finishReason }) => {
|
|
114289
114293
|
logger2.debug("Step finished", { usage, finishReason, stepIteration });
|
|
114290
114294
|
}
|
|
@@ -114306,11 +114310,15 @@ class AISDKAgent {
|
|
|
114306
114310
|
ctx.response = response;
|
|
114307
114311
|
const stepMessages = this.sanitizeMessages(response.messages);
|
|
114308
114312
|
ctx.allResponseMessages.push(...stepMessages);
|
|
114313
|
+
ctx.currentMessages = [...ctx.currentMessages, ...stepMessages];
|
|
114314
|
+
if (this.handleIncompleteToolCalls(ctx, stepCtx)) {
|
|
114315
|
+
continue;
|
|
114316
|
+
}
|
|
114317
|
+
ctx.lastStepHadToolCalls = stepCtx.stepHadToolCalls;
|
|
114309
114318
|
if (!stepCtx.stepHadToolCalls) {
|
|
114310
114319
|
logger2.debug("Step had no tool calls, finishing run", { stepIteration });
|
|
114311
114320
|
break;
|
|
114312
114321
|
}
|
|
114313
|
-
ctx.currentMessages = [...ctx.currentMessages, ...stepMessages];
|
|
114314
114322
|
logger2.debug("Continuing to next step after tool calls", {
|
|
114315
114323
|
stepIteration,
|
|
114316
114324
|
newMessageCount: ctx.currentMessages.length,
|
|
@@ -114318,6 +114326,20 @@ class AISDKAgent {
|
|
|
114318
114326
|
});
|
|
114319
114327
|
}
|
|
114320
114328
|
}
|
|
114329
|
+
handleIncompleteToolCalls(ctx, stepCtx) {
|
|
114330
|
+
const incompleteToolCalls = [...stepCtx.activeToolCalls.entries()].filter(([id]) => !stepCtx.completedToolCalls.has(id)).map(([id, call]) => ({ id, ...call }));
|
|
114331
|
+
const recoveryMessages = buildRecoveryToolResults(incompleteToolCalls, stepCtx.stepFinishReason, this.maxOutputTokens);
|
|
114332
|
+
if (recoveryMessages.length === 0) {
|
|
114333
|
+
return false;
|
|
114334
|
+
}
|
|
114335
|
+
const sanitized = this.sanitizeMessages(recoveryMessages);
|
|
114336
|
+
ctx.allResponseMessages.push(...sanitized);
|
|
114337
|
+
ctx.currentMessages = [...ctx.currentMessages, ...sanitized];
|
|
114338
|
+
logger2.warn("Incomplete tool calls detected (likely maxOutputTokens exceeded)", {
|
|
114339
|
+
incompleteCount: incompleteToolCalls.length
|
|
114340
|
+
});
|
|
114341
|
+
return true;
|
|
114342
|
+
}
|
|
114321
114343
|
processStreamChunk(chunk, ctx, stepCtx, events) {
|
|
114322
114344
|
switch (chunk.type) {
|
|
114323
114345
|
case "start-step": {
|
|
@@ -114330,19 +114352,19 @@ class AISDKAgent {
|
|
|
114330
114352
|
}
|
|
114331
114353
|
case "text-delta": {
|
|
114332
114354
|
ctx.hasAnyContent = true;
|
|
114333
|
-
if (!
|
|
114334
|
-
|
|
114355
|
+
if (!stepCtx.hasEmittedTextStart) {
|
|
114356
|
+
stepCtx.messageId = v4_default();
|
|
114335
114357
|
events.emit({
|
|
114336
114358
|
type: export_EventType.TEXT_MESSAGE_START,
|
|
114337
|
-
messageId:
|
|
114359
|
+
messageId: stepCtx.messageId,
|
|
114338
114360
|
role: "assistant",
|
|
114339
114361
|
timestamp: Date.now()
|
|
114340
114362
|
});
|
|
114341
|
-
|
|
114363
|
+
stepCtx.hasEmittedTextStart = true;
|
|
114342
114364
|
}
|
|
114343
114365
|
events.emit({
|
|
114344
114366
|
type: export_EventType.TEXT_MESSAGE_CONTENT,
|
|
114345
|
-
messageId:
|
|
114367
|
+
messageId: stepCtx.messageId,
|
|
114346
114368
|
delta: chunk.text,
|
|
114347
114369
|
timestamp: Date.now()
|
|
114348
114370
|
});
|
|
@@ -114356,13 +114378,22 @@ class AISDKAgent {
|
|
|
114356
114378
|
case "tool-input-start": {
|
|
114357
114379
|
ctx.hasAnyContent = true;
|
|
114358
114380
|
stepCtx.stepHadToolCalls = true;
|
|
114381
|
+
if (stepCtx.messageId) {
|
|
114382
|
+
events.emit({
|
|
114383
|
+
type: export_EventType.TEXT_MESSAGE_END,
|
|
114384
|
+
messageId: stepCtx.messageId,
|
|
114385
|
+
timestamp: Date.now()
|
|
114386
|
+
});
|
|
114387
|
+
}
|
|
114359
114388
|
const toolDef = stepCtx.currentTools.find((t) => t.name === chunk.toolName);
|
|
114360
114389
|
const annotations = getToolAnnotations(toolDef);
|
|
114390
|
+
const parentId = stepCtx.messageId ?? v4_default();
|
|
114391
|
+
stepCtx.messageId = null;
|
|
114361
114392
|
const toolCallStartEvent = {
|
|
114362
114393
|
type: export_EventType.TOOL_CALL_START,
|
|
114363
114394
|
toolCallId: chunk.id,
|
|
114364
114395
|
toolCallName: chunk.toolName,
|
|
114365
|
-
parentMessageId:
|
|
114396
|
+
parentMessageId: parentId,
|
|
114366
114397
|
timestamp: Date.now()
|
|
114367
114398
|
};
|
|
114368
114399
|
if (annotations) {
|
|
@@ -114387,6 +114418,7 @@ class AISDKAgent {
|
|
|
114387
114418
|
}
|
|
114388
114419
|
case "tool-call": {
|
|
114389
114420
|
stepCtx.stepHadToolCalls = true;
|
|
114421
|
+
stepCtx.completedToolCalls.add(chunk.toolCallId);
|
|
114390
114422
|
const toolCall = stepCtx.activeToolCalls.get(chunk.toolCallId);
|
|
114391
114423
|
const finalArgs = JSON.stringify(chunk.input);
|
|
114392
114424
|
if (toolCall && toolCall.args.length === 0) {
|
|
@@ -114417,7 +114449,19 @@ class AISDKAgent {
|
|
|
114417
114449
|
});
|
|
114418
114450
|
return;
|
|
114419
114451
|
}
|
|
114452
|
+
case "finish": {
|
|
114453
|
+
stepCtx.stepFinishReason = chunk.finishReason;
|
|
114454
|
+
return;
|
|
114455
|
+
}
|
|
114420
114456
|
case "finish-step": {
|
|
114457
|
+
if (stepCtx.messageId) {
|
|
114458
|
+
events.emit({
|
|
114459
|
+
type: export_EventType.TEXT_MESSAGE_END,
|
|
114460
|
+
messageId: stepCtx.messageId,
|
|
114461
|
+
timestamp: Date.now()
|
|
114462
|
+
});
|
|
114463
|
+
stepCtx.messageId = null;
|
|
114464
|
+
}
|
|
114421
114465
|
events.emit({
|
|
114422
114466
|
type: export_EventType.STEP_FINISHED,
|
|
114423
114467
|
stepName: `step-${ctx.currentStepNumber - 1}`,
|
|
@@ -114444,13 +114488,6 @@ class AISDKAgent {
|
|
|
114444
114488
|
}
|
|
114445
114489
|
}
|
|
114446
114490
|
finalizeRun(ctx, events, span) {
|
|
114447
|
-
if (ctx.hasEmittedTextStart && ctx.messageId) {
|
|
114448
|
-
events.emit({
|
|
114449
|
-
type: export_EventType.TEXT_MESSAGE_END,
|
|
114450
|
-
messageId: ctx.messageId,
|
|
114451
|
-
timestamp: Date.now()
|
|
114452
|
-
});
|
|
114453
|
-
}
|
|
114454
114491
|
if (!ctx.hasAnyContent) {
|
|
114455
114492
|
span.endWithError("Empty response from AI");
|
|
114456
114493
|
events.emit({
|
|
@@ -114548,6 +114585,13 @@ class AISDKAgent {
|
|
|
114548
114585
|
${JSON.stringify(state, null, 2)}`
|
|
114549
114586
|
};
|
|
114550
114587
|
}
|
|
114588
|
+
applyGracefulSummaryOverrides(isGracefulSummaryStep, stepConfig) {
|
|
114589
|
+
if (!isGracefulSummaryStep)
|
|
114590
|
+
return;
|
|
114591
|
+
stepConfig.messages.push({ role: "user", content: "max steps reached, summarize progress" });
|
|
114592
|
+
stepConfig.tools = undefined;
|
|
114593
|
+
Object.assign(stepConfig.metadata, { toolCount: 0, gracefulSummary: true });
|
|
114594
|
+
}
|
|
114551
114595
|
filterTools(tools) {
|
|
114552
114596
|
if (!this.toolFilter) {
|
|
114553
114597
|
return tools;
|
|
@@ -114690,6 +114734,35 @@ ${val.text}`
|
|
|
114690
114734
|
}
|
|
114691
114735
|
}
|
|
114692
114736
|
}
|
|
114737
|
+
function buildRecoveryToolResults(incompleteToolCalls, stepFinishReason, maxOutputTokens) {
|
|
114738
|
+
if (incompleteToolCalls.length === 0 || stepFinishReason !== "length") {
|
|
114739
|
+
return [];
|
|
114740
|
+
}
|
|
114741
|
+
const recoveryAssistantMessage = {
|
|
114742
|
+
role: "assistant",
|
|
114743
|
+
content: incompleteToolCalls.map((toolCall) => ({
|
|
114744
|
+
type: "tool-call",
|
|
114745
|
+
toolCallId: toolCall.id,
|
|
114746
|
+
toolName: toolCall.name,
|
|
114747
|
+
input: {}
|
|
114748
|
+
}))
|
|
114749
|
+
};
|
|
114750
|
+
const recoveryToolResults = incompleteToolCalls.map((toolCall) => ({
|
|
114751
|
+
role: "tool",
|
|
114752
|
+
content: [
|
|
114753
|
+
{
|
|
114754
|
+
type: "tool-result",
|
|
114755
|
+
toolCallId: toolCall.id,
|
|
114756
|
+
toolName: toolCall.name,
|
|
114757
|
+
output: {
|
|
114758
|
+
type: "text",
|
|
114759
|
+
value: `Error: Tool call "${toolCall.name}" failed because its arguments were cut off mid-stream by the output token limit (maxOutputTokens: ${maxOutputTokens}). This call was recorded with args={} as a placeholder — retry with shorter arguments. Truncated args (first 200 chars): ${toolCall.args.substring(0, 200)}`
|
|
114760
|
+
}
|
|
114761
|
+
}
|
|
114762
|
+
]
|
|
114763
|
+
}));
|
|
114764
|
+
return [recoveryAssistantMessage, ...recoveryToolResults];
|
|
114765
|
+
}
|
|
114693
114766
|
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
114694
114767
|
var ignoreOverride2 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
114695
114768
|
var defaultOptions2 = {
|
|
@@ -252,6 +252,16 @@ export declare class AISDKAgent implements Agent {
|
|
|
252
252
|
* Each step runs ONE model invocation, then checks for updated tools/state.
|
|
253
253
|
*/
|
|
254
254
|
private executeStepLoop;
|
|
255
|
+
/**
|
|
256
|
+
* Detects incomplete tool calls caused by maxOutputTokens truncation and injects
|
|
257
|
+
* synthetic error tool_results into ctx so the model can retry with shorter arguments.
|
|
258
|
+
*
|
|
259
|
+
* When the stream is cut mid-tool-input, tool-input-start fires but tool-call never fires.
|
|
260
|
+
*
|
|
261
|
+
* Mutates ctx.allResponseMessages and ctx.currentMessages as a side effect.
|
|
262
|
+
* @returns true if recovery messages were injected (caller should continue to next step)
|
|
263
|
+
*/
|
|
264
|
+
private handleIncompleteToolCalls;
|
|
255
265
|
/**
|
|
256
266
|
* Processes a single stream chunk, emitting the appropriate AG-UI events.
|
|
257
267
|
* Mutates stepCtx.stepHadToolCalls when a tool call is detected.
|
|
@@ -291,6 +301,12 @@ export declare class AISDKAgent implements Agent {
|
|
|
291
301
|
* @returns A SystemModelMessage with the state, or undefined if no state
|
|
292
302
|
*/
|
|
293
303
|
private buildStateMessage;
|
|
304
|
+
/**
|
|
305
|
+
* When maxSteps is exhausted mid-tool-call chain, overrides step config
|
|
306
|
+
* to strip tools and inject a summary prompt so the model can summarize progress.
|
|
307
|
+
* No-ops when isGracefulSummaryStep is false.
|
|
308
|
+
*/
|
|
309
|
+
private applyGracefulSummaryOverrides;
|
|
294
310
|
/**
|
|
295
311
|
* Filters tools using the configured filter function.
|
|
296
312
|
* If no filter is configured, returns all tools.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AISDKAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,aAAa,
|
|
1
|
+
{"version":3,"file":"AISDKAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/AISDKAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,aAAa,EAA8G,MAAM,IAAI,CAAC;AAMvK,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AA0BpE,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAoGjF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;;OAGG;IAC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