@anvia/core 0.13.0 → 0.13.2
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/agent/index.d.ts +2 -2
- package/dist/agent/index.js +9 -10
- package/dist/{agent-CXvjoW0J.d.ts → agent-3qSfIKIj.d.ts} +1 -0
- package/dist/{chunk-NPZDYOE6.js → chunk-2ODTMRHP.js} +11 -10
- package/dist/chunk-2ODTMRHP.js.map +1 -0
- package/dist/{chunk-HF4KHHNM.js → chunk-77D7XBWL.js} +5 -5
- package/dist/chunk-77D7XBWL.js.map +1 -0
- package/dist/{chunk-7BV5JBJW.js → chunk-BCGCTBDN.js} +23 -20
- package/dist/chunk-BCGCTBDN.js.map +1 -0
- package/dist/{chunk-JT4U4FGG.js → chunk-BHQ5UPSK.js} +3 -3
- package/dist/{chunk-7H3TQN3I.js → chunk-CNTGKNZ3.js} +7 -7
- package/dist/chunk-CNTGKNZ3.js.map +1 -0
- package/dist/chunk-CQNNSZPG.js +9 -0
- package/dist/chunk-CQNNSZPG.js.map +1 -0
- package/dist/{chunk-IZM6FNCT.js → chunk-F3C5653H.js} +46 -40
- package/dist/chunk-F3C5653H.js.map +1 -0
- package/dist/{chunk-46IR5ZTN.js → chunk-JIUZWN45.js} +10 -11
- package/dist/chunk-JIUZWN45.js.map +1 -0
- package/dist/{chunk-MU3UPROJ.js → chunk-NS7W4G26.js} +21 -12
- package/dist/chunk-NS7W4G26.js.map +1 -0
- package/dist/{chunk-OCYL4AB6.js → chunk-VSGL6LBZ.js} +6 -6
- package/dist/{chunk-JS5MGVNM.js → chunk-YBBD4HZ3.js} +8 -7
- package/dist/{chunk-JS5MGVNM.js.map → chunk-YBBD4HZ3.js.map} +1 -1
- package/dist/{chunk-HLISYYCB.js → chunk-YOXG2K7N.js} +214 -131
- package/dist/chunk-YOXG2K7N.js.map +1 -0
- package/dist/{chunk-W53PLBOL.js → chunk-YTF65GYU.js} +2 -2
- package/dist/completion/index.js +2 -2
- package/dist/embeddings/index.js +1 -1
- package/dist/evals/index.d.ts +1 -1
- package/dist/evals/index.js +58 -35
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +1 -1
- package/dist/extractor/index.js +10 -11
- package/dist/hooks/index.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/internal/agent.d.ts +1 -1
- package/dist/internal/agent.js +8 -9
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.js +34 -19
- package/dist/pipeline/index.js.map +1 -1
- package/dist/request/index.d.ts +1 -1
- package/dist/request/index.js +7 -8
- package/dist/skills/index.js +6 -6
- package/dist/tool/index.js +4 -5
- package/dist/ui/index.js +2 -2
- package/dist/vector-store/index.js +2 -3
- package/package.json +1 -1
- package/dist/chunk-46IR5ZTN.js.map +0 -1
- package/dist/chunk-7BV5JBJW.js.map +0 -1
- package/dist/chunk-7H3TQN3I.js.map +0 -1
- package/dist/chunk-HF4KHHNM.js.map +0 -1
- package/dist/chunk-HLISYYCB.js.map +0 -1
- package/dist/chunk-IZM6FNCT.js.map +0 -1
- package/dist/chunk-MMHG7WAM.js +0 -19
- package/dist/chunk-MMHG7WAM.js.map +0 -1
- package/dist/chunk-MU3UPROJ.js.map +0 -1
- package/dist/chunk-NPZDYOE6.js.map +0 -1
- /package/dist/{chunk-JT4U4FGG.js.map → chunk-BHQ5UPSK.js.map} +0 -0
- /package/dist/{chunk-OCYL4AB6.js.map → chunk-VSGL6LBZ.js.map} +0 -0
- /package/dist/{chunk-W53PLBOL.js.map → chunk-YTF65GYU.js.map} +0 -0
|
@@ -4,21 +4,18 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
parseToolArgs,
|
|
6
6
|
toolResultContentToText
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JIUZWN45.js";
|
|
8
8
|
import {
|
|
9
9
|
runControl,
|
|
10
10
|
toolCallControl
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import {
|
|
13
|
-
compact
|
|
14
|
-
} from "./chunk-MMHG7WAM.js";
|
|
11
|
+
} from "./chunk-2ODTMRHP.js";
|
|
15
12
|
import {
|
|
16
13
|
mapWithConcurrency
|
|
17
14
|
} from "./chunk-OIMLU4SF.js";
|
|
18
15
|
import {
|
|
19
16
|
CompletionRequestBuilder,
|
|
20
17
|
isStreamingCompletionModel
|
|
21
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-YTF65GYU.js";
|
|
22
19
|
import {
|
|
23
20
|
AssistantContent,
|
|
24
21
|
Message,
|
|
@@ -26,7 +23,7 @@ import {
|
|
|
26
23
|
Usage,
|
|
27
24
|
assertCompletionRequestSupported,
|
|
28
25
|
textFromAssistantContent
|
|
29
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-CNTGKNZ3.js";
|
|
30
27
|
import {
|
|
31
28
|
appendGuardrailPolicies,
|
|
32
29
|
hasEnforcedOutputGuardrails,
|
|
@@ -245,13 +242,14 @@ async function fetchDynamicContext(agent, ragText) {
|
|
|
245
242
|
documents.push(formatted);
|
|
246
243
|
} else {
|
|
247
244
|
const metadata = formatMetadata(result.metadata);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
245
|
+
const document = {
|
|
246
|
+
id: result.id,
|
|
247
|
+
text: typeof result.document === "string" ? result.document : JSON.stringify(result.document, null, 2)
|
|
248
|
+
};
|
|
249
|
+
if (metadata !== void 0) {
|
|
250
|
+
document.additionalProps = metadata;
|
|
251
|
+
}
|
|
252
|
+
documents.push(document);
|
|
255
253
|
}
|
|
256
254
|
}
|
|
257
255
|
}
|
|
@@ -311,8 +309,8 @@ var CompletionStreamAccumulator = class {
|
|
|
311
309
|
}
|
|
312
310
|
if (event.type === "tool_call_delta") {
|
|
313
311
|
const toolCall = this.toolCallStateForId(event.id);
|
|
314
|
-
if (event.callId !== void 0) toolCall.callId = event.callId;
|
|
315
|
-
if (event.name !== void 0) toolCall.name = event.name;
|
|
312
|
+
if (event.callId !== void 0 && event.callId.length > 0) toolCall.callId = event.callId;
|
|
313
|
+
if (event.name !== void 0 && event.name.length > 0) toolCall.name = event.name;
|
|
316
314
|
if (event.signature !== void 0) toolCall.signature = event.signature;
|
|
317
315
|
if (event.argumentsDelta !== void 0) {
|
|
318
316
|
toolCall.argumentsText += event.argumentsDelta;
|
|
@@ -397,15 +395,15 @@ var CompletionStreamAccumulator = class {
|
|
|
397
395
|
}
|
|
398
396
|
mergeFinalResponse(accumulatedResponse, finalResponse) {
|
|
399
397
|
if (finalResponse.choice.length === 0) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
);
|
|
398
|
+
const mergedResponse = {
|
|
399
|
+
...accumulatedResponse,
|
|
400
|
+
usage: finalResponse.usage,
|
|
401
|
+
rawResponse: finalResponse.rawResponse
|
|
402
|
+
};
|
|
403
|
+
if (finalResponse.messageId !== void 0) {
|
|
404
|
+
mergedResponse.messageId = finalResponse.messageId;
|
|
405
|
+
}
|
|
406
|
+
return this.withMessageIdFallback(mergedResponse, accumulatedResponse);
|
|
409
407
|
}
|
|
410
408
|
const finalById = /* @__PURE__ */ new Map();
|
|
411
409
|
const finalByCallId = /* @__PURE__ */ new Map();
|
|
@@ -650,6 +648,13 @@ var ToolCallExecutor = class {
|
|
|
650
648
|
requestMiddlewares;
|
|
651
649
|
cancel;
|
|
652
650
|
async execute(toolCalls, onResult, onStreamEvent, observation) {
|
|
651
|
+
for (const toolCall of toolCalls) {
|
|
652
|
+
if (toolCall.function.name.length === 0) {
|
|
653
|
+
throw new Error(
|
|
654
|
+
`Completion returned tool call "${toolCall.id}" with an empty function name; this indicates invalid provider output or provider mapping.`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
653
658
|
return mapWithConcurrency(toolCalls, this.concurrency, async (toolCall) => {
|
|
654
659
|
const args = JSON.stringify(toolCall.function.arguments ?? {});
|
|
655
660
|
const internalCallId = globalThis.crypto.randomUUID();
|
|
@@ -666,18 +671,23 @@ var ToolCallExecutor = class {
|
|
|
666
671
|
(definition) => definition.name === toolCall.function.name
|
|
667
672
|
);
|
|
668
673
|
const toolMetadata = toolTraceMetadata(tool);
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
674
|
+
const toolStartArgs = {
|
|
675
|
+
turn: observation?.turn ?? 0,
|
|
676
|
+
toolCall,
|
|
677
|
+
toolName: toolCall.function.name,
|
|
678
|
+
internalCallId,
|
|
679
|
+
args
|
|
680
|
+
};
|
|
681
|
+
if (toolCall.callId !== void 0) {
|
|
682
|
+
toolStartArgs.toolCallId = toolCall.callId;
|
|
683
|
+
}
|
|
684
|
+
if (toolDefinition !== void 0) {
|
|
685
|
+
toolStartArgs.toolDefinition = toolDefinition;
|
|
686
|
+
}
|
|
687
|
+
if (toolMetadata !== void 0) {
|
|
688
|
+
toolStartArgs.toolMetadata = toolMetadata;
|
|
689
|
+
}
|
|
690
|
+
const toolObservers = await observation?.runObservers.startTool(toolStartArgs);
|
|
681
691
|
let output;
|
|
682
692
|
let skipped = false;
|
|
683
693
|
let effectiveArgs = args;
|
|
@@ -805,17 +815,18 @@ var ToolCallExecutor = class {
|
|
|
805
815
|
try {
|
|
806
816
|
return await this.agent.callTool(toolCall.function.name, middlewareArgs, {
|
|
807
817
|
emitStreamEvent: async (event) => {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
818
|
+
const streamEventArgs = {
|
|
819
|
+
turn: observation?.turn ?? 0,
|
|
820
|
+
toolCall,
|
|
821
|
+
toolName: toolCall.function.name,
|
|
822
|
+
internalCallId: hookArgs.internalCallId,
|
|
823
|
+
args: middlewareArgs,
|
|
824
|
+
event
|
|
825
|
+
};
|
|
826
|
+
if (toolCall.callId !== void 0) {
|
|
827
|
+
streamEventArgs.toolCallId = toolCall.callId;
|
|
828
|
+
}
|
|
829
|
+
await toolObservers?.streamEvent(streamEventArgs);
|
|
819
830
|
const payload = agentToolEventPayload(toolCall, hookArgs.internalCallId, event);
|
|
820
831
|
if (payload !== void 0) {
|
|
821
832
|
onStreamEvent?.(payload);
|
|
@@ -829,15 +840,15 @@ var ToolCallExecutor = class {
|
|
|
829
840
|
error,
|
|
830
841
|
run: runControl
|
|
831
842
|
});
|
|
832
|
-
await toolObservers?.error(
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
843
|
+
await toolObservers?.error(
|
|
844
|
+
toolErrorArgs(
|
|
845
|
+
observation?.turn ?? 0,
|
|
846
|
+
toolCall,
|
|
847
|
+
hookArgs.internalCallId,
|
|
848
|
+
middlewareArgs,
|
|
849
|
+
error
|
|
850
|
+
)
|
|
851
|
+
);
|
|
841
852
|
if (errorAction?.type === "terminate") {
|
|
842
853
|
throw this.cancel(errorAction.reason);
|
|
843
854
|
}
|
|
@@ -907,14 +918,28 @@ var ToolCallExecutor = class {
|
|
|
907
918
|
}
|
|
908
919
|
const reason = await resolveApprovalText(policy.reason, context);
|
|
909
920
|
const rejectMessage = await resolveApprovalText(policy.rejectMessage, context);
|
|
910
|
-
|
|
921
|
+
const options = {};
|
|
922
|
+
if (reason !== void 0) {
|
|
923
|
+
options.reason = reason;
|
|
924
|
+
}
|
|
925
|
+
if (rejectMessage !== void 0) {
|
|
926
|
+
options.rejectMessage = rejectMessage;
|
|
927
|
+
}
|
|
928
|
+
return this.requestApproval(tool, hookArgs, options);
|
|
911
929
|
}
|
|
912
930
|
async requestApproval(tool, hookArgs, options) {
|
|
913
|
-
const request =
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
931
|
+
const request = approvalContext(
|
|
932
|
+
tool,
|
|
933
|
+
hookArgs,
|
|
934
|
+
this.agent,
|
|
935
|
+
this.runContext
|
|
936
|
+
);
|
|
937
|
+
if (options.reason !== void 0) {
|
|
938
|
+
request.reason = options.reason;
|
|
939
|
+
}
|
|
940
|
+
if (options.rejectMessage !== void 0) {
|
|
941
|
+
request.rejectMessage = options.rejectMessage;
|
|
942
|
+
}
|
|
918
943
|
if (this.approvals === void 0) {
|
|
919
944
|
throw new ToolApprovalRequiredError(request);
|
|
920
945
|
}
|
|
@@ -931,19 +956,27 @@ var ToolCallExecutor = class {
|
|
|
931
956
|
function approvalContext(tool, hookArgs, agent, run) {
|
|
932
957
|
const rawParsedArgs = parseToolArgs(hookArgs.args);
|
|
933
958
|
const parsedArgs = tool?.parseApprovalArgs?.(rawParsedArgs) ?? rawParsedArgs;
|
|
934
|
-
|
|
959
|
+
const approvalRun = {
|
|
960
|
+
agentId: agent.id,
|
|
961
|
+
runId: run.runId
|
|
962
|
+
};
|
|
963
|
+
if (run.sessionId !== void 0) {
|
|
964
|
+
approvalRun.sessionId = run.sessionId;
|
|
965
|
+
}
|
|
966
|
+
if (run.metadata !== void 0) {
|
|
967
|
+
approvalRun.metadata = run.metadata;
|
|
968
|
+
}
|
|
969
|
+
const context = {
|
|
935
970
|
toolName: hookArgs.toolName,
|
|
936
971
|
args: parsedArgs,
|
|
937
972
|
rawArgs: hookArgs.args,
|
|
938
|
-
toolCallId: hookArgs.toolCallId,
|
|
939
973
|
internalCallId: hookArgs.internalCallId,
|
|
940
|
-
run:
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
});
|
|
974
|
+
run: approvalRun
|
|
975
|
+
};
|
|
976
|
+
if (hookArgs.toolCallId !== void 0) {
|
|
977
|
+
context.toolCallId = hookArgs.toolCallId;
|
|
978
|
+
}
|
|
979
|
+
return context;
|
|
947
980
|
}
|
|
948
981
|
function normalizeApprovalDecision(decision) {
|
|
949
982
|
if (typeof decision === "boolean") {
|
|
@@ -966,10 +999,27 @@ function toolTraceMetadata(tool) {
|
|
|
966
999
|
}
|
|
967
1000
|
const metadata = tool[MCP_TOOL_METADATA_KEY];
|
|
968
1001
|
const mcpMetadata = typeof metadata === "object" && metadata !== null ? metadata : void 0;
|
|
969
|
-
|
|
970
|
-
approvalRequired: tool.approval !== void 0
|
|
971
|
-
|
|
1002
|
+
const result = {
|
|
1003
|
+
approvalRequired: tool.approval !== void 0
|
|
1004
|
+
};
|
|
1005
|
+
if (typeof mcpMetadata?.serverName === "string" && mcpMetadata.serverName.length > 0) {
|
|
1006
|
+
result.mcpServerName = mcpMetadata.serverName;
|
|
1007
|
+
}
|
|
1008
|
+
return result;
|
|
1009
|
+
}
|
|
1010
|
+
function toolErrorArgs(turn, toolCall, internalCallId, args, error) {
|
|
1011
|
+
const observerArgs = {
|
|
1012
|
+
turn,
|
|
1013
|
+
toolCall,
|
|
1014
|
+
toolName: toolCall.function.name,
|
|
1015
|
+
internalCallId,
|
|
1016
|
+
args,
|
|
1017
|
+
error
|
|
972
1018
|
};
|
|
1019
|
+
if (toolCall.callId !== void 0) {
|
|
1020
|
+
observerArgs.toolCallId = toolCall.callId;
|
|
1021
|
+
}
|
|
1022
|
+
return observerArgs;
|
|
973
1023
|
}
|
|
974
1024
|
async function recordToolError(toolObservers, turn, toolCall, internalCallId, args, error) {
|
|
975
1025
|
await toolObservers?.error({
|
|
@@ -992,15 +1042,20 @@ function agentToolEventPayload(toolCall, internalCallId, event) {
|
|
|
992
1042
|
if (typeof event.agentId !== "string" || event.agentId.length === 0) {
|
|
993
1043
|
return void 0;
|
|
994
1044
|
}
|
|
995
|
-
|
|
1045
|
+
const payload = {
|
|
996
1046
|
type: "agent_tool_event",
|
|
997
1047
|
toolName: toolCall.function.name,
|
|
998
|
-
toolCallId: toolCall.callId,
|
|
999
1048
|
internalCallId,
|
|
1000
1049
|
agentId: event.agentId,
|
|
1001
|
-
agentName: event.agentName,
|
|
1002
1050
|
event: event.event
|
|
1003
|
-
}
|
|
1051
|
+
};
|
|
1052
|
+
if (toolCall.callId !== void 0) {
|
|
1053
|
+
payload.toolCallId = toolCall.callId;
|
|
1054
|
+
}
|
|
1055
|
+
if (event.agentName !== void 0) {
|
|
1056
|
+
payload.agentName = event.agentName;
|
|
1057
|
+
}
|
|
1058
|
+
return payload;
|
|
1004
1059
|
}
|
|
1005
1060
|
|
|
1006
1061
|
// src/internal/rag-text.ts
|
|
@@ -1528,16 +1583,7 @@ var PromptRequest = class _PromptRequest {
|
|
|
1528
1583
|
assertCompletionRequestSupported(this.agent.model, request, { streaming: true });
|
|
1529
1584
|
const providerRequest = this.providerTraceRequest(request, { stream: true });
|
|
1530
1585
|
const generationObservers = await runObservers.startGeneration(
|
|
1531
|
-
|
|
1532
|
-
turn: currentTurns,
|
|
1533
|
-
request,
|
|
1534
|
-
providerRequest,
|
|
1535
|
-
modelInfo: {
|
|
1536
|
-
provider: this.agent.model.provider,
|
|
1537
|
-
defaultModel: this.agent.model.defaultModel,
|
|
1538
|
-
capabilities: this.agent.model.capabilities
|
|
1539
|
-
}
|
|
1540
|
-
})
|
|
1586
|
+
this.generationStartArgs(currentTurns, request, providerRequest)
|
|
1541
1587
|
);
|
|
1542
1588
|
const accumulator = new CompletionStreamAccumulator();
|
|
1543
1589
|
const generationStartedAt = Date.now();
|
|
@@ -1570,13 +1616,14 @@ var PromptRequest = class _PromptRequest {
|
|
|
1570
1616
|
throw error;
|
|
1571
1617
|
}
|
|
1572
1618
|
let response = accumulator.response();
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1619
|
+
const generationEndArgs = {
|
|
1620
|
+
turn: currentTurns,
|
|
1621
|
+
response
|
|
1622
|
+
};
|
|
1623
|
+
if (firstDeltaMs !== void 0) {
|
|
1624
|
+
generationEndArgs.firstDeltaMs = firstDeltaMs;
|
|
1625
|
+
}
|
|
1626
|
+
await generationObservers.end(generationEndArgs);
|
|
1580
1627
|
response = await this.runCompletionResponseMiddlewares(request, response, currentTurns);
|
|
1581
1628
|
usage = Usage.add(usage, response.usage);
|
|
1582
1629
|
await this.runCompletionResponseHook(prompt, response, newMessages);
|
|
@@ -1734,16 +1781,7 @@ var PromptRequest = class _PromptRequest {
|
|
|
1734
1781
|
assertCompletionRequestSupported(this.agent.model, request);
|
|
1735
1782
|
const providerRequest = this.providerTraceRequest(request);
|
|
1736
1783
|
const generationObservers = await runObservers.startGeneration(
|
|
1737
|
-
|
|
1738
|
-
turn,
|
|
1739
|
-
request,
|
|
1740
|
-
providerRequest,
|
|
1741
|
-
modelInfo: {
|
|
1742
|
-
provider: this.agent.model.provider,
|
|
1743
|
-
defaultModel: this.agent.model.defaultModel,
|
|
1744
|
-
capabilities: this.agent.model.capabilities
|
|
1745
|
-
}
|
|
1746
|
-
})
|
|
1784
|
+
this.generationStartArgs(turn, request, providerRequest)
|
|
1747
1785
|
);
|
|
1748
1786
|
try {
|
|
1749
1787
|
const response = await this.agent.model.completion(request);
|
|
@@ -1763,6 +1801,21 @@ var PromptRequest = class _PromptRequest {
|
|
|
1763
1801
|
};
|
|
1764
1802
|
}
|
|
1765
1803
|
}
|
|
1804
|
+
generationStartArgs(turn, request, providerRequest) {
|
|
1805
|
+
const args = {
|
|
1806
|
+
turn,
|
|
1807
|
+
request,
|
|
1808
|
+
modelInfo: {
|
|
1809
|
+
provider: this.agent.model.provider,
|
|
1810
|
+
defaultModel: this.agent.model.defaultModel,
|
|
1811
|
+
capabilities: this.agent.model.capabilities
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
if (providerRequest !== void 0) {
|
|
1815
|
+
args.providerRequest = providerRequest;
|
|
1816
|
+
}
|
|
1817
|
+
return args;
|
|
1818
|
+
}
|
|
1766
1819
|
async executeToolCalls(runId, toolCalls, newMessages, onResult, onStreamEvent, observation) {
|
|
1767
1820
|
const executor = new ToolCallExecutor(
|
|
1768
1821
|
this.agent,
|
|
@@ -1812,12 +1865,17 @@ var PromptRequest = class _PromptRequest {
|
|
|
1812
1865
|
});
|
|
1813
1866
|
}
|
|
1814
1867
|
guardrailRunContext(runId) {
|
|
1815
|
-
|
|
1868
|
+
const context = {
|
|
1816
1869
|
agentId: this.agent.id,
|
|
1817
|
-
runId
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1870
|
+
runId
|
|
1871
|
+
};
|
|
1872
|
+
if (this.memoryContext !== void 0) {
|
|
1873
|
+
context.sessionId = this.memoryContext.sessionId;
|
|
1874
|
+
if (this.memoryContext.metadata !== void 0) {
|
|
1875
|
+
context.metadata = this.memoryContext.metadata;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return context;
|
|
1821
1879
|
}
|
|
1822
1880
|
async startRunObservers() {
|
|
1823
1881
|
const failOnObserverError = this.traceOptions?.failOnObserverError === true || this.agent.observers.some((registration) => registration.failOnObserverError === true);
|
|
@@ -1846,17 +1904,25 @@ var PromptRequest = class _PromptRequest {
|
|
|
1846
1904
|
const turn = "turn" in event ? event.turn : void 0;
|
|
1847
1905
|
const agentId = event.type === "agent_tool_event" ? event.agentId : this.agent.id;
|
|
1848
1906
|
const agentName = event.type === "agent_tool_event" ? event.agentName : this.agent.name;
|
|
1849
|
-
|
|
1907
|
+
const input = {
|
|
1850
1908
|
runId,
|
|
1851
1909
|
agentId,
|
|
1852
|
-
...compact({ agentName, turn }),
|
|
1853
|
-
...event.type === "agent_tool_event" ? compact({
|
|
1854
|
-
toolName: event.toolName,
|
|
1855
|
-
toolCallId: event.toolCallId,
|
|
1856
|
-
internalCallId: event.internalCallId
|
|
1857
|
-
}) : {},
|
|
1858
1910
|
event
|
|
1859
|
-
}
|
|
1911
|
+
};
|
|
1912
|
+
if (agentName !== void 0) {
|
|
1913
|
+
input.agentName = agentName;
|
|
1914
|
+
}
|
|
1915
|
+
if (turn !== void 0) {
|
|
1916
|
+
input.turn = turn;
|
|
1917
|
+
}
|
|
1918
|
+
if (event.type === "agent_tool_event") {
|
|
1919
|
+
input.toolName = event.toolName;
|
|
1920
|
+
input.internalCallId = event.internalCallId;
|
|
1921
|
+
if (event.toolCallId !== void 0) {
|
|
1922
|
+
input.toolCallId = event.toolCallId;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
await registration.store.append(input);
|
|
1860
1926
|
}
|
|
1861
1927
|
async runCompletionCallHook(prompt, history, newMessages) {
|
|
1862
1928
|
const action = await this.activeHook?.onCompletionCall?.({
|
|
@@ -2041,19 +2107,14 @@ function responseStreamEvents(turn, response) {
|
|
|
2041
2107
|
if (item.type === "reasoning") {
|
|
2042
2108
|
if (item.content === void 0) {
|
|
2043
2109
|
if (item.text.length > 0) {
|
|
2044
|
-
events.push(
|
|
2045
|
-
compact({ type: "reasoning_delta", turn, delta: item.text, id: item.id })
|
|
2046
|
-
);
|
|
2110
|
+
events.push(reasoningDeltaEvent2(turn, item.text, { id: item.id }));
|
|
2047
2111
|
}
|
|
2048
2112
|
continue;
|
|
2049
2113
|
}
|
|
2050
2114
|
for (const content of item.content) {
|
|
2051
2115
|
const delta = content.type === "encrypted" || content.type === "redacted" ? content.data : content.text;
|
|
2052
2116
|
events.push(
|
|
2053
|
-
|
|
2054
|
-
type: "reasoning_delta",
|
|
2055
|
-
turn,
|
|
2056
|
-
delta,
|
|
2117
|
+
reasoningDeltaEvent2(turn, delta, {
|
|
2057
2118
|
id: item.id,
|
|
2058
2119
|
contentType: content.type,
|
|
2059
2120
|
signature: content.type === "text" ? content.signature : void 0
|
|
@@ -2068,6 +2129,23 @@ function responseStreamEvents(turn, response) {
|
|
|
2068
2129
|
}
|
|
2069
2130
|
return events;
|
|
2070
2131
|
}
|
|
2132
|
+
function reasoningDeltaEvent2(turn, delta, details = {}) {
|
|
2133
|
+
const event = {
|
|
2134
|
+
type: "reasoning_delta",
|
|
2135
|
+
turn,
|
|
2136
|
+
delta
|
|
2137
|
+
};
|
|
2138
|
+
if (details.id !== void 0) {
|
|
2139
|
+
event.id = details.id;
|
|
2140
|
+
}
|
|
2141
|
+
if (details.contentType !== void 0) {
|
|
2142
|
+
event.contentType = details.contentType;
|
|
2143
|
+
}
|
|
2144
|
+
if (details.signature !== void 0) {
|
|
2145
|
+
event.signature = details.signature;
|
|
2146
|
+
}
|
|
2147
|
+
return event;
|
|
2148
|
+
}
|
|
2071
2149
|
function textFromMessage(message) {
|
|
2072
2150
|
if (message.role === "system") {
|
|
2073
2151
|
return message.content;
|
|
@@ -2083,17 +2161,22 @@ function textFromMessage(message) {
|
|
|
2083
2161
|
}).join("\n");
|
|
2084
2162
|
}
|
|
2085
2163
|
function guardrailDecisionAttributes(decision) {
|
|
2086
|
-
|
|
2164
|
+
const attributes = {
|
|
2087
2165
|
policyId: decision.policyId,
|
|
2088
2166
|
guardrailId: decision.guardrailId,
|
|
2089
2167
|
boundary: decision.boundary,
|
|
2090
2168
|
mode: decision.mode,
|
|
2091
2169
|
action: decision.action,
|
|
2092
2170
|
applied: decision.applied,
|
|
2093
|
-
reason: decision.reason,
|
|
2094
|
-
message: decision.message,
|
|
2095
2171
|
latencyMs: decision.latencyMs
|
|
2096
|
-
}
|
|
2172
|
+
};
|
|
2173
|
+
if (decision.reason !== void 0) {
|
|
2174
|
+
attributes.reason = decision.reason;
|
|
2175
|
+
}
|
|
2176
|
+
if (decision.message !== void 0) {
|
|
2177
|
+
attributes.message = decision.message;
|
|
2178
|
+
}
|
|
2179
|
+
return attributes;
|
|
2097
2180
|
}
|
|
2098
2181
|
|
|
2099
2182
|
export {
|
|
@@ -2103,4 +2186,4 @@ export {
|
|
|
2103
2186
|
extractRagText,
|
|
2104
2187
|
PromptRequest
|
|
2105
2188
|
};
|
|
2106
|
-
//# sourceMappingURL=chunk-
|
|
2189
|
+
//# sourceMappingURL=chunk-YOXG2K7N.js.map
|