@voltagent/core 0.1.68 → 0.1.70
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.d.ts +89 -5
- package/dist/index.js +67 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -122
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2432,6 +2432,14 @@ type ProviderTextResponse<TOriginalResponse> = {
|
|
|
2432
2432
|
* Finish reason (if applicable)
|
|
2433
2433
|
*/
|
|
2434
2434
|
finishReason?: string;
|
|
2435
|
+
/**
|
|
2436
|
+
* Reasoning text from the model (if applicable)
|
|
2437
|
+
*/
|
|
2438
|
+
reasoning?: string;
|
|
2439
|
+
/**
|
|
2440
|
+
* Warnings from the model provider (if applicable)
|
|
2441
|
+
*/
|
|
2442
|
+
warnings?: any[];
|
|
2435
2443
|
};
|
|
2436
2444
|
type TextDeltaStreamPart = {
|
|
2437
2445
|
type: "text-delta";
|
|
@@ -2499,6 +2507,30 @@ type ProviderTextStreamResponse<TOriginalResponse> = {
|
|
|
2499
2507
|
* Optional - only available in providers that support it
|
|
2500
2508
|
*/
|
|
2501
2509
|
fullStream?: AsyncIterable<StreamPart>;
|
|
2510
|
+
/**
|
|
2511
|
+
* The full generated text.
|
|
2512
|
+
* Resolved when the response is finished.
|
|
2513
|
+
* Optional - only available in providers that support it.
|
|
2514
|
+
*/
|
|
2515
|
+
text?: Promise<string>;
|
|
2516
|
+
/**
|
|
2517
|
+
* The reason why generation stopped.
|
|
2518
|
+
* Resolved when the response is finished.
|
|
2519
|
+
* Optional - only available in providers that support it.
|
|
2520
|
+
*/
|
|
2521
|
+
finishReason?: Promise<string>;
|
|
2522
|
+
/**
|
|
2523
|
+
* Token usage information.
|
|
2524
|
+
* Resolved when the response is finished.
|
|
2525
|
+
* Optional - only available in providers that support it.
|
|
2526
|
+
*/
|
|
2527
|
+
usage?: Promise<UsageInfo>;
|
|
2528
|
+
/**
|
|
2529
|
+
* Model's reasoning text (if available).
|
|
2530
|
+
* Resolved when the response is finished.
|
|
2531
|
+
* Optional - only available in providers that support it.
|
|
2532
|
+
*/
|
|
2533
|
+
reasoning?: Promise<string | undefined>;
|
|
2502
2534
|
};
|
|
2503
2535
|
/**
|
|
2504
2536
|
* Response type for object generation operations
|
|
@@ -2520,6 +2552,10 @@ type ProviderObjectResponse<TOriginalResponse, TObject> = {
|
|
|
2520
2552
|
* Finish reason (if applicable)
|
|
2521
2553
|
*/
|
|
2522
2554
|
finishReason?: string;
|
|
2555
|
+
/**
|
|
2556
|
+
* Warnings from the model provider (if applicable)
|
|
2557
|
+
*/
|
|
2558
|
+
warnings?: any[];
|
|
2523
2559
|
};
|
|
2524
2560
|
/**
|
|
2525
2561
|
* Response type for object streaming operations
|
|
@@ -2533,6 +2569,24 @@ type ProviderObjectStreamResponse<TOriginalResponse, TObject> = {
|
|
|
2533
2569
|
* Object stream for consuming partial objects
|
|
2534
2570
|
*/
|
|
2535
2571
|
objectStream: AsyncIterableStream<Partial<TObject>>;
|
|
2572
|
+
/**
|
|
2573
|
+
* The generated object (typed according to the schema).
|
|
2574
|
+
* Resolved when the response is finished.
|
|
2575
|
+
* Optional - only available in providers that support it.
|
|
2576
|
+
*/
|
|
2577
|
+
object?: Promise<TObject>;
|
|
2578
|
+
/**
|
|
2579
|
+
* Token usage information.
|
|
2580
|
+
* Resolved when the response is finished.
|
|
2581
|
+
* Optional - only available in providers that support it.
|
|
2582
|
+
*/
|
|
2583
|
+
usage?: Promise<UsageInfo>;
|
|
2584
|
+
/**
|
|
2585
|
+
* Warnings from the model provider.
|
|
2586
|
+
* Resolved when the response is finished.
|
|
2587
|
+
* Optional - only available in providers that support it.
|
|
2588
|
+
*/
|
|
2589
|
+
warnings?: Promise<any[] | undefined>;
|
|
2536
2590
|
};
|
|
2537
2591
|
/**
|
|
2538
2592
|
* Data content type for binary data
|
|
@@ -4605,10 +4659,6 @@ declare class Agent<TProvider extends {
|
|
|
4605
4659
|
* Add step to history immediately and to conversation steps
|
|
4606
4660
|
*/
|
|
4607
4661
|
private addStepToHistory;
|
|
4608
|
-
/**
|
|
4609
|
-
* Handle tool execution errors by creating appropriate events and steps
|
|
4610
|
-
*/
|
|
4611
|
-
private handleToolError;
|
|
4612
4662
|
/**
|
|
4613
4663
|
* Update history entry
|
|
4614
4664
|
*/
|
|
@@ -4771,6 +4821,10 @@ type WorkflowStepFuncConfig<INPUT, DATA, RESULT, SUSPEND_DATA, RESUME_DATA = any
|
|
|
4771
4821
|
interface WorkflowStepFunc<INPUT, DATA, RESULT, SUSPEND_DATA, RESUME_DATA = any> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT, SUSPEND_DATA, RESUME_DATA> {
|
|
4772
4822
|
type: "func";
|
|
4773
4823
|
}
|
|
4824
|
+
interface WorkflowStepWorkflow<INPUT, DATA, RESULT, SUSPEND_DATA, RESUME_DATA = any> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT, SUSPEND_DATA, RESUME_DATA> {
|
|
4825
|
+
type: "workflow";
|
|
4826
|
+
workflow: InternalWorkflow<INPUT, DATA, RESULT>;
|
|
4827
|
+
}
|
|
4774
4828
|
type WorkflowStepTapConfig<INPUT, DATA, _RESULT, SUSPEND_DATA, RESUME_DATA = any> = InternalWorkflowStepConfig<{
|
|
4775
4829
|
execute: InternalWorkflowFunc<INPUT, DATA, DangerouslyAllowAny, SUSPEND_DATA, RESUME_DATA>;
|
|
4776
4830
|
inputSchema?: z.ZodTypeAny;
|
|
@@ -4806,7 +4860,21 @@ interface WorkflowStepParallelAll<INPUT, DATA, RESULT> extends InternalBaseWorkf
|
|
|
4806
4860
|
type: "parallel-all";
|
|
4807
4861
|
steps: ReadonlyArray<InternalAnyWorkflowStep<INPUT, DATA, RESULT>>;
|
|
4808
4862
|
}
|
|
4809
|
-
type WorkflowStep<INPUT, DATA, RESULT, SUSPEND_DATA = any> = WorkflowStepAgent<INPUT, DATA, RESULT> | WorkflowStepFunc<INPUT, DATA, RESULT, SUSPEND_DATA> | WorkflowStepConditionalWhen<INPUT, DATA, RESULT> | WorkflowStepParallelAll<INPUT, DATA, RESULT> | WorkflowStepTap<INPUT, DATA, RESULT, SUSPEND_DATA> | WorkflowStepParallelRace<INPUT, DATA, RESULT>;
|
|
4863
|
+
type WorkflowStep<INPUT, DATA, RESULT, SUSPEND_DATA = any> = WorkflowStepAgent<INPUT, DATA, RESULT> | WorkflowStepFunc<INPUT, DATA, RESULT, SUSPEND_DATA> | WorkflowStepConditionalWhen<INPUT, DATA, RESULT> | WorkflowStepParallelAll<INPUT, DATA, RESULT> | WorkflowStepTap<INPUT, DATA, RESULT, SUSPEND_DATA> | WorkflowStepParallelRace<INPUT, DATA, RESULT> | WorkflowStepWorkflow<INPUT, DATA, RESULT, SUSPEND_DATA>;
|
|
4864
|
+
/**
|
|
4865
|
+
* Internal type to allow overriding the run method for the workflow
|
|
4866
|
+
*/
|
|
4867
|
+
interface InternalWorkflow<_INPUT, DATA, RESULT> extends Omit<Workflow<DangerouslyAllowAny, DangerouslyAllowAny>, "run"> {
|
|
4868
|
+
run: (input: InternalExtractWorkflowInputData<DATA>, options?: InternalWorkflowRunOptions) => Promise<{
|
|
4869
|
+
executionId: string;
|
|
4870
|
+
startAt: Date;
|
|
4871
|
+
endAt: Date;
|
|
4872
|
+
status: "completed";
|
|
4873
|
+
result: RESULT;
|
|
4874
|
+
}>;
|
|
4875
|
+
}
|
|
4876
|
+
interface InternalWorkflowRunOptions extends WorkflowRunOptions {
|
|
4877
|
+
}
|
|
4810
4878
|
|
|
4811
4879
|
/**
|
|
4812
4880
|
* Creates an async function step for the workflow
|
|
@@ -5313,6 +5381,22 @@ declare class WorkflowChain<INPUT_SCHEMA extends InternalBaseWorkflowInputSchema
|
|
|
5313
5381
|
suspendSchema?: z.ZodTypeAny;
|
|
5314
5382
|
resumeSchema?: z.ZodTypeAny;
|
|
5315
5383
|
}): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, CURRENT_DATA, SUSPEND_SCHEMA, RESUME_SCHEMA>;
|
|
5384
|
+
/**
|
|
5385
|
+
* Add a workflow step to the workflow
|
|
5386
|
+
*
|
|
5387
|
+
* @example
|
|
5388
|
+
* ```ts
|
|
5389
|
+
* import { myWorkflow } from "./my-workflow";
|
|
5390
|
+
*
|
|
5391
|
+
* const workflow = createWorkflowChain(config)
|
|
5392
|
+
* .andThen(async (data) => {
|
|
5393
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
5394
|
+
* return { userInfo };
|
|
5395
|
+
* })
|
|
5396
|
+
* .andWorkflow(myWorkflow)
|
|
5397
|
+
* ```
|
|
5398
|
+
*/
|
|
5399
|
+
andWorkflow<NEW_DATA>(workflow: InternalWorkflow<INPUT_SCHEMA, CURRENT_DATA, NEW_DATA>): WorkflowChain<INPUT_SCHEMA, RESULT_SCHEMA, NEW_DATA>;
|
|
5316
5400
|
/**
|
|
5317
5401
|
* Add a parallel execution step that runs multiple steps simultaneously and waits for all to complete
|
|
5318
5402
|
*
|
package/dist/index.js
CHANGED
|
@@ -3366,6 +3366,28 @@ function andTap({
|
|
|
3366
3366
|
}
|
|
3367
3367
|
__name(andTap, "andTap");
|
|
3368
3368
|
|
|
3369
|
+
// src/workflow/steps/and-workflow.ts
|
|
3370
|
+
function andWorkflow(workflow) {
|
|
3371
|
+
return {
|
|
3372
|
+
type: "workflow",
|
|
3373
|
+
workflow,
|
|
3374
|
+
id: workflow.id,
|
|
3375
|
+
name: workflow.name,
|
|
3376
|
+
purpose: workflow.purpose,
|
|
3377
|
+
execute: async (context) => {
|
|
3378
|
+
const { result } = await workflow.run(context.data, {
|
|
3379
|
+
active: context.state.active,
|
|
3380
|
+
executionId: context.state.executionId,
|
|
3381
|
+
conversationId: context.state.conversationId,
|
|
3382
|
+
userId: context.state.userId,
|
|
3383
|
+
userContext: context.state.userContext
|
|
3384
|
+
});
|
|
3385
|
+
return result;
|
|
3386
|
+
}
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
__name(andWorkflow, "andWorkflow");
|
|
3390
|
+
|
|
3369
3391
|
// src/workflow/core.ts
|
|
3370
3392
|
var import_zod = require("zod");
|
|
3371
3393
|
|
|
@@ -7643,6 +7665,27 @@ var WorkflowChain = class {
|
|
|
7643
7665
|
this.steps.push(finalStep);
|
|
7644
7666
|
return this;
|
|
7645
7667
|
}
|
|
7668
|
+
/**
|
|
7669
|
+
* Add a workflow step to the workflow
|
|
7670
|
+
*
|
|
7671
|
+
* @example
|
|
7672
|
+
* ```ts
|
|
7673
|
+
* import { myWorkflow } from "./my-workflow";
|
|
7674
|
+
*
|
|
7675
|
+
* const workflow = createWorkflowChain(config)
|
|
7676
|
+
* .andThen(async (data) => {
|
|
7677
|
+
* const userInfo = await fetchUserInfo(data.userId);
|
|
7678
|
+
* return { userInfo };
|
|
7679
|
+
* })
|
|
7680
|
+
* .andWorkflow(myWorkflow)
|
|
7681
|
+
* ```
|
|
7682
|
+
*/
|
|
7683
|
+
andWorkflow(workflow) {
|
|
7684
|
+
this.steps.push(
|
|
7685
|
+
andWorkflow(workflow)
|
|
7686
|
+
);
|
|
7687
|
+
return this;
|
|
7688
|
+
}
|
|
7646
7689
|
/**
|
|
7647
7690
|
* Add a parallel execution step that runs multiple steps simultaneously and waits for all to complete
|
|
7648
7691
|
*
|
|
@@ -12248,10 +12291,15 @@ ${retrieverContext}`;
|
|
|
12248
12291
|
toolName: tool2.name,
|
|
12249
12292
|
agentId: this.id,
|
|
12250
12293
|
modelName: this.getModelName(),
|
|
12251
|
-
error
|
|
12294
|
+
error
|
|
12252
12295
|
}
|
|
12253
12296
|
);
|
|
12254
|
-
|
|
12297
|
+
const result = {
|
|
12298
|
+
error: true,
|
|
12299
|
+
message: error instanceof Error ? error.message : String(error),
|
|
12300
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
12301
|
+
};
|
|
12302
|
+
return result;
|
|
12255
12303
|
}
|
|
12256
12304
|
}
|
|
12257
12305
|
};
|
|
@@ -12452,107 +12500,6 @@ ${retrieverContext}`;
|
|
|
12452
12500
|
};
|
|
12453
12501
|
context.conversationSteps.push(finalStep);
|
|
12454
12502
|
}
|
|
12455
|
-
/**
|
|
12456
|
-
* Handle tool execution errors by creating appropriate events and steps
|
|
12457
|
-
*/
|
|
12458
|
-
async handleToolError(error, operationContext, options) {
|
|
12459
|
-
if (!error.toolError) {
|
|
12460
|
-
return;
|
|
12461
|
-
}
|
|
12462
|
-
const { userId, conversationId, internalOptions } = options;
|
|
12463
|
-
const { toolCallId, toolName } = error.toolError;
|
|
12464
|
-
try {
|
|
12465
|
-
const toolStartInfo = operationContext.userContext.get(`tool_${toolCallId}`) || { eventId: void 0, startTime: (/* @__PURE__ */ new Date()).toISOString() };
|
|
12466
|
-
const toolErrorEvent = {
|
|
12467
|
-
id: crypto.randomUUID(),
|
|
12468
|
-
name: "tool:error",
|
|
12469
|
-
type: "tool",
|
|
12470
|
-
startTime: toolStartInfo.startTime,
|
|
12471
|
-
endTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12472
|
-
status: "error",
|
|
12473
|
-
level: "ERROR",
|
|
12474
|
-
input: null,
|
|
12475
|
-
output: null,
|
|
12476
|
-
statusMessage: {
|
|
12477
|
-
message: error.message,
|
|
12478
|
-
code: error.code,
|
|
12479
|
-
...error.toolError && { toolError: error.toolError }
|
|
12480
|
-
},
|
|
12481
|
-
metadata: {
|
|
12482
|
-
displayName: toolName,
|
|
12483
|
-
id: toolName,
|
|
12484
|
-
agentId: this.id
|
|
12485
|
-
},
|
|
12486
|
-
traceId: operationContext.historyEntry.id,
|
|
12487
|
-
parentEventId: toolStartInfo.eventId
|
|
12488
|
-
};
|
|
12489
|
-
this.publishTimelineEvent(operationContext, toolErrorEvent);
|
|
12490
|
-
const toolErrorStep = {
|
|
12491
|
-
id: toolCallId,
|
|
12492
|
-
type: "tool_result",
|
|
12493
|
-
name: toolName,
|
|
12494
|
-
result: {
|
|
12495
|
-
error
|
|
12496
|
-
},
|
|
12497
|
-
content: JSON.stringify([
|
|
12498
|
-
{
|
|
12499
|
-
type: "tool-result",
|
|
12500
|
-
toolCallId,
|
|
12501
|
-
toolName,
|
|
12502
|
-
result: {
|
|
12503
|
-
error: {
|
|
12504
|
-
message: error.message,
|
|
12505
|
-
code: error.code
|
|
12506
|
-
}
|
|
12507
|
-
}
|
|
12508
|
-
}
|
|
12509
|
-
]),
|
|
12510
|
-
role: "assistant"
|
|
12511
|
-
};
|
|
12512
|
-
this.addStepToHistory(toolErrorStep, operationContext);
|
|
12513
|
-
if (userId) {
|
|
12514
|
-
const onStepFinish = this.memoryManager.createStepFinishHandler(
|
|
12515
|
-
operationContext,
|
|
12516
|
-
userId,
|
|
12517
|
-
conversationId
|
|
12518
|
-
);
|
|
12519
|
-
await onStepFinish(toolErrorStep);
|
|
12520
|
-
}
|
|
12521
|
-
const tool2 = this.toolManager.getToolByName(toolName);
|
|
12522
|
-
if (tool2 && internalOptions) {
|
|
12523
|
-
await this.getMergedHooks(internalOptions).onToolEnd?.({
|
|
12524
|
-
agent: this,
|
|
12525
|
-
tool: tool2,
|
|
12526
|
-
output: void 0,
|
|
12527
|
-
error,
|
|
12528
|
-
context: operationContext
|
|
12529
|
-
});
|
|
12530
|
-
}
|
|
12531
|
-
const methodLogger = operationContext.logger || this.logger;
|
|
12532
|
-
methodLogger.error(
|
|
12533
|
-
buildAgentLogMessage(this.name, "toolCall" /* TOOL_CALL */, `Tool ${toolName} failed`),
|
|
12534
|
-
{
|
|
12535
|
-
event: LogEvents.TOOL_EXECUTION_FAILED,
|
|
12536
|
-
toolName,
|
|
12537
|
-
toolCallId,
|
|
12538
|
-
error: {
|
|
12539
|
-
message: error.message,
|
|
12540
|
-
code: error.code
|
|
12541
|
-
}
|
|
12542
|
-
}
|
|
12543
|
-
);
|
|
12544
|
-
} catch (updateError) {
|
|
12545
|
-
const methodLogger = operationContext.logger || this.logger;
|
|
12546
|
-
methodLogger.error(
|
|
12547
|
-
`Failed to update tool event to error status for ${toolName} (${toolCallId})`,
|
|
12548
|
-
{
|
|
12549
|
-
toolName,
|
|
12550
|
-
toolCallId,
|
|
12551
|
-
error: updateError
|
|
12552
|
-
}
|
|
12553
|
-
);
|
|
12554
|
-
}
|
|
12555
|
-
}
|
|
12556
12503
|
/**
|
|
12557
12504
|
* Update history entry
|
|
12558
12505
|
*/
|
|
@@ -12845,7 +12792,8 @@ ${retrieverContext}`;
|
|
|
12845
12792
|
...internalOptions,
|
|
12846
12793
|
conversationId: finalConversationId,
|
|
12847
12794
|
historyEntryId: operationContext.historyEntry.id,
|
|
12848
|
-
operationContext
|
|
12795
|
+
operationContext,
|
|
12796
|
+
logger: methodLogger
|
|
12849
12797
|
});
|
|
12850
12798
|
const promptHelper = VoltOpsClient.createPromptHelperWithFallback(
|
|
12851
12799
|
this.id,
|
|
@@ -13011,8 +12959,12 @@ ${retrieverContext}`;
|
|
|
13011
12959
|
level: "ERROR",
|
|
13012
12960
|
input: null,
|
|
13013
12961
|
output: null,
|
|
13014
|
-
statusMessage:
|
|
13015
|
-
message: "Unknown tool error"
|
|
12962
|
+
statusMessage: {
|
|
12963
|
+
message: step.result?.message || "Unknown tool error",
|
|
12964
|
+
// Include stack trace if available (from tool wrapper)
|
|
12965
|
+
...step.result?.stack && {
|
|
12966
|
+
stack: step.result.stack
|
|
12967
|
+
}
|
|
13016
12968
|
},
|
|
13017
12969
|
metadata: {
|
|
13018
12970
|
displayName: toolName,
|
|
@@ -13160,13 +13112,6 @@ ${retrieverContext}`;
|
|
|
13160
13112
|
return extendedResponse;
|
|
13161
13113
|
} catch (error) {
|
|
13162
13114
|
const voltagentError = error;
|
|
13163
|
-
if (voltagentError.toolError) {
|
|
13164
|
-
await this.handleToolError(voltagentError, operationContext, {
|
|
13165
|
-
userId,
|
|
13166
|
-
conversationId: finalConversationId,
|
|
13167
|
-
internalOptions
|
|
13168
|
-
});
|
|
13169
|
-
}
|
|
13170
13115
|
const agentErrorStartInfo = {
|
|
13171
13116
|
startTime: operationContext.userContext.get("agent_start_time") || (/* @__PURE__ */ new Date()).toISOString(),
|
|
13172
13117
|
eventId: operationContext.userContext.get("agent_start_event_id")
|
|
@@ -13372,7 +13317,8 @@ ${retrieverContext}`;
|
|
|
13372
13317
|
historyEntryId: operationContext.historyEntry.id,
|
|
13373
13318
|
operationContext,
|
|
13374
13319
|
// Pass the internal forwarder to tools
|
|
13375
|
-
internalStreamForwarder: internalStreamEventForwarder
|
|
13320
|
+
internalStreamForwarder: internalStreamEventForwarder,
|
|
13321
|
+
logger: methodLogger
|
|
13376
13322
|
});
|
|
13377
13323
|
const promptHelper = VoltOpsClient.createPromptHelperWithFallback(
|
|
13378
13324
|
this.id,
|
|
@@ -13468,7 +13414,13 @@ ${retrieverContext}`;
|
|
|
13468
13414
|
level: "ERROR",
|
|
13469
13415
|
input: null,
|
|
13470
13416
|
output: null,
|
|
13471
|
-
statusMessage:
|
|
13417
|
+
statusMessage: {
|
|
13418
|
+
message: chunk.result?.message || "Unknown tool error",
|
|
13419
|
+
// Include stack trace if available (from tool wrapper)
|
|
13420
|
+
...chunk.result?.stack && {
|
|
13421
|
+
stack: chunk.result.stack
|
|
13422
|
+
}
|
|
13423
|
+
},
|
|
13472
13424
|
metadata: {
|
|
13473
13425
|
displayName: toolName,
|
|
13474
13426
|
id: toolName,
|
|
@@ -13671,13 +13623,6 @@ ${retrieverContext}`;
|
|
|
13671
13623
|
}
|
|
13672
13624
|
},
|
|
13673
13625
|
onError: async (error) => {
|
|
13674
|
-
if (error.toolError) {
|
|
13675
|
-
await this.handleToolError(error, operationContext, {
|
|
13676
|
-
userId,
|
|
13677
|
-
conversationId: finalConversationId,
|
|
13678
|
-
internalOptions
|
|
13679
|
-
});
|
|
13680
|
-
}
|
|
13681
13626
|
const agentErrorStartInfo = {
|
|
13682
13627
|
startTime: operationContext.userContext.get("agent_start_time") || (/* @__PURE__ */ new Date()).toISOString(),
|
|
13683
13628
|
eventId: operationContext.userContext.get("agent_start_event_id")
|