@gea-ai/agent-sdk 0.1.261019-alpha.0 → 0.1.261019-alpha.1
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-worker.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { agentModelTerminationSchema, } from "@gea-ai/contract/agent-usage";
|
|
2
2
|
export { uploadChannelInput } from "./agent-channel-api.js";
|
|
3
3
|
import { createChannelSessionNamespace } from "./agent-channel-session-transport.js";
|
|
4
|
-
import { contextSystemInputSchema } from "@gea-ai/contract/agent-worker-tools";
|
|
4
|
+
import { agentHostToolFailureSchema, contextSystemInputSchema, } from "@gea-ai/contract/agent-worker-tools";
|
|
5
|
+
import { HostToolExecutionError } from "./host-tool-error.js";
|
|
5
6
|
import { getAgentProgrammaticToolCalling, isAgentConnectorConnectionHelperExposed, } from "@gea-ai/contract/agent-packages";
|
|
6
7
|
import { AGENT_WORKER_TOOL_METADATA_HEADER, AGENT_WORKER_TOOL_METADATA_VERSION, } from "@gea-ai/contract/agent-worker-tools";
|
|
7
8
|
import { isAgentConnectorExposed } from "@gea-ai/contract/agent-packages";
|
|
@@ -2407,6 +2408,14 @@ async function invokeHostTool(input) {
|
|
|
2407
2408
|
method: "POST",
|
|
2408
2409
|
signal: input.signal,
|
|
2409
2410
|
});
|
|
2411
|
+
const failure = agentHostToolFailureSchema.safeParse(result.output);
|
|
2412
|
+
if (failure.success) {
|
|
2413
|
+
trace.getActiveSpan()?.setAttributes({
|
|
2414
|
+
"gea.tool.error_id": failure.data.errorId,
|
|
2415
|
+
"gea.tool.error_code": failure.data.code,
|
|
2416
|
+
});
|
|
2417
|
+
throw new HostToolExecutionError(failure.data);
|
|
2418
|
+
}
|
|
2410
2419
|
return result.output;
|
|
2411
2420
|
}
|
|
2412
2421
|
function encodeBytesBase64(value) {
|
|
@@ -4146,10 +4155,17 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
|
|
|
4146
4155
|
data: event,
|
|
4147
4156
|
},
|
|
4148
4157
|
});
|
|
4149
|
-
|
|
4158
|
+
// UI assembly resumes the last assistant response. Its recorded calls belong
|
|
4159
|
+
// to the logical Run, while this invocation may finish without another model call.
|
|
4160
|
+
const previousResponse = payload.originalMessages.at(-1);
|
|
4161
|
+
const modelCalls = new Map((previousResponse?.role === "assistant"
|
|
4162
|
+
? (previousResponse.metadata?.modelCalls ?? [])
|
|
4163
|
+
: [])
|
|
4164
|
+
.filter((call) => call.runId === payload.runId)
|
|
4165
|
+
.map((call) => [call.callId, agentModelCallSchema.parse(call)]));
|
|
4150
4166
|
const recordModelCall = async (entry, checkpoint = false) => {
|
|
4151
4167
|
const call = agentModelCallSchema.parse(entry);
|
|
4152
|
-
modelCalls.
|
|
4168
|
+
modelCalls.set(call.callId, call);
|
|
4153
4169
|
if (managedSession) {
|
|
4154
4170
|
if (checkpoint)
|
|
4155
4171
|
checkpointModelCalls.push(call);
|
|
@@ -4406,10 +4422,10 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
|
|
|
4406
4422
|
: {}),
|
|
4407
4423
|
finishedAt: new Date(),
|
|
4408
4424
|
finishReason: failure ? "error" : (end?.finishReason ?? "error"),
|
|
4409
|
-
totalUsage: modelCalls.reduce((sum, call) => call.usage ? addAgentWorkerUsage(sum, call.usage) : sum, null),
|
|
4425
|
+
totalUsage: [...modelCalls.values()].reduce((sum, call) => call.usage ? addAgentWorkerUsage(sum, call.usage) : sum, null),
|
|
4410
4426
|
...(executionDiagnostics ? { executionDiagnostics } : {}),
|
|
4411
4427
|
contextUsage: structuredClone(contextRuntime.usage),
|
|
4412
|
-
modelCalls: structuredClone(modelCalls),
|
|
4428
|
+
modelCalls: structuredClone([...modelCalls.values()]),
|
|
4413
4429
|
});
|
|
4414
4430
|
})();
|
|
4415
4431
|
return settling;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAgentTracing } from "../tracing.js";
|
|
2
|
+
import { HostToolExecutionError } from "../host-tool-error.js";
|
|
2
3
|
import { asSchema, safeValidateTypes } from "@ai-sdk/provider-utils";
|
|
3
4
|
import { toCoreModelOutput } from "./agent-core-messages.js";
|
|
4
5
|
import { agentCoreToolSchema } from "@gea-ai/contract/agent-core";
|
|
@@ -138,6 +139,17 @@ export async function createCoreWorkerTools(options) {
|
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
141
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
142
|
+
if (error instanceof HostToolExecutionError) {
|
|
143
|
+
span.setAttribute("gen_ai.tool.call.result", JSON.stringify(error.output));
|
|
144
|
+
return {
|
|
145
|
+
output: error.output,
|
|
146
|
+
is_error: true,
|
|
147
|
+
model_output: {
|
|
148
|
+
type: "error-json",
|
|
149
|
+
value: error.output,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
141
153
|
span.recordException(error instanceof Error ? error : String(error));
|
|
142
154
|
throw error;
|
|
143
155
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentHostToolFailure } from "@gea-ai/contract/agent-worker-tools";
|
|
2
|
+
/** Only the Host adapter creates this error, after validating its reserved envelope. */
|
|
3
|
+
export declare class HostToolExecutionError extends Error {
|
|
4
|
+
readonly output: AgentHostToolFailure;
|
|
5
|
+
readonly name = "HostToolExecutionError";
|
|
6
|
+
constructor(output: AgentHostToolFailure);
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Only the Host adapter creates this error, after validating its reserved envelope. */
|
|
2
|
+
export class HostToolExecutionError extends Error {
|
|
3
|
+
output;
|
|
4
|
+
name = "HostToolExecutionError";
|
|
5
|
+
constructor(output) {
|
|
6
|
+
super(output.message);
|
|
7
|
+
this.output = output;
|
|
8
|
+
// Telemetry may record this Error. Retain only the masked protocol message.
|
|
9
|
+
this.stack = undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const agentSdkVersion = "0.1.261019-alpha.
|
|
1
|
+
export declare const agentSdkVersion = "0.1.261019-alpha.1";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/build-sdk-version.mjs from package.json.
|
|
2
|
-
export const agentSdkVersion = "0.1.261019-alpha.
|
|
2
|
+
export const agentSdkVersion = "0.1.261019-alpha.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gea-ai/agent-sdk",
|
|
3
|
-
"version": "0.1.261019-alpha.
|
|
3
|
+
"version": "0.1.261019-alpha.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"homepage": "https://musegea.com/developers",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@ai-sdk/otel": "1.0.119",
|
|
124
124
|
"@ai-sdk/provider": "4.0.19",
|
|
125
125
|
"@ai-sdk/provider-utils": "5.0.50",
|
|
126
|
-
"@gea-ai/contract": "0.1.261019-alpha.
|
|
126
|
+
"@gea-ai/contract": "0.1.261019-alpha.1",
|
|
127
127
|
"@opentelemetry/api": "1.9.1",
|
|
128
128
|
"@opentelemetry/context-async-hooks": "2.10.0",
|
|
129
129
|
"@opentelemetry/core": "2.10.0",
|