@gea-ai/agent-sdk 0.1.261009-alpha.0 → 0.1.261009-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.
@@ -4207,6 +4207,9 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
4207
4207
  };
4208
4208
  let terminalMessage;
4209
4209
  let terminalEvent;
4210
+ // Inbox suspension is a live protocol frame, not a journaled response end.
4211
+ // Hold it until the final context commit so a failed commit cannot publish waiting.
4212
+ let liveFinish;
4210
4213
  const saveResponseMessage = async ({ responseMessage, }) => {
4211
4214
  const saveStartedAt = performance.now();
4212
4215
  const metadata = await contextFinished;
@@ -4224,6 +4227,21 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
4224
4227
  }
4225
4228
  if (inboxRunner?.suspended)
4226
4229
  context.metadata.suspendedMessageId = responseMessage.id;
4230
+ const needsInput = !inboxRunner?.suspended &&
4231
+ responseMessage.parts.some((part) => "state" in part &&
4232
+ (part.state === "approval-requested" ||
4233
+ (part.state === "input-available" &&
4234
+ input.snapshot.tools.some((tool) => tool.type === "custom" &&
4235
+ tool.execution === "client" &&
4236
+ part.type === `tool-${tool.name}`))));
4237
+ // The same metadata object is held by the deferred finish frame. Do not
4238
+ // publish waiting until the final context commit succeeds; a failed commit
4239
+ // seals the call as failed and must not leave the message looking suspended.
4240
+ const markWaiting = !failure &&
4241
+ (needsInput ||
4242
+ Boolean(inboxRunner?.suspended && metadata.sessionStatus === "waiting"));
4243
+ if (markWaiting)
4244
+ delete metadata.sessionStatus;
4227
4245
  responseMessage.metadata = {
4228
4246
  ...responseMessage.metadata,
4229
4247
  ...metadata,
@@ -4276,19 +4294,39 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
4276
4294
  }
4277
4295
  throw error;
4278
4296
  }
4297
+ if (markWaiting) {
4298
+ metadata.sessionStatus = "waiting";
4299
+ responseMessage.metadata = {
4300
+ ...responseMessage.metadata,
4301
+ sessionStatus: "waiting",
4302
+ };
4303
+ if (terminalMessage) {
4304
+ terminalMessage = {
4305
+ ...terminalMessage,
4306
+ metadata: {
4307
+ ...terminalMessage.metadata,
4308
+ sessionStatus: "waiting",
4309
+ },
4310
+ };
4311
+ }
4312
+ else if (sessionExecution) {
4313
+ await mutateSession({ messages: [{ ...responseMessage }] });
4314
+ }
4315
+ else {
4316
+ await appendSessionValue({
4317
+ body: { message: responseMessage, runId: payload.runId },
4318
+ chatId: payload.chatId,
4319
+ namespace: input.sessionNamespace,
4320
+ path: "/v1/messages",
4321
+ });
4322
+ }
4323
+ }
4279
4324
  const contextPersistedAt = performance.now();
4280
4325
  persistenceSpan?.setAttributes({
4281
4326
  "gea.session.finish.context_wait_ms": Math.round(contextFinishedAt - saveStartedAt),
4282
4327
  "gea.session.finish.transcript_ms": Math.round(transcriptFinishedAt - transcriptStartedAt),
4283
4328
  "gea.session.finish.context_write_ms": Math.round(contextPersistedAt - transcriptFinishedAt),
4284
4329
  });
4285
- const needsInput = !inboxRunner?.suspended &&
4286
- responseMessage.parts.some((part) => "state" in part &&
4287
- (part.state === "approval-requested" ||
4288
- (part.state === "input-available" &&
4289
- input.snapshot.tools.some((tool) => tool.type === "custom" &&
4290
- tool.execution === "client" &&
4291
- part.type === `tool-${tool.name}`))));
4292
4330
  ownSessionOutcome({
4293
4331
  ...(needsInput
4294
4332
  ? {
@@ -4957,14 +4995,19 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
4957
4995
  finishReason: metadata.finishReason,
4958
4996
  messageMetadata: metadata,
4959
4997
  };
4960
- if (metadata.sessionStatus === "waiting") {
4961
- controller.enqueue(chunk);
4998
+ if (inboxRunner?.suspended && metadata.finishReason !== "error") {
4999
+ // onFinish commits context before this frame is published. The
5000
+ // journal keeps the resumed response's finish, not this boundary.
5001
+ liveFinish = chunk;
4962
5002
  continue;
4963
5003
  }
4964
- if (sessionExecution &&
4965
- !input.channelJournal &&
4966
- !inboxRunner?.suspended &&
4967
- metadata.finishReason === "stop") {
5004
+ if (metadata.finishReason === "tool-calls" ||
5005
+ (sessionExecution &&
5006
+ !input.channelJournal &&
5007
+ !inboxRunner?.suspended &&
5008
+ metadata.finishReason === "stop")) {
5009
+ // onFinish commits context before publishing waiting metadata.
5010
+ // Flush emits this frame only after that commit returns.
4968
5011
  terminalEvent = chunk;
4969
5012
  continue;
4970
5013
  }
@@ -4982,16 +5025,26 @@ async function executeAgentWorkerRequest(input, waitUntil, ownComputer, ownSessi
4982
5025
  controller.enqueue(event);
4983
5026
  },
4984
5027
  async flush(controller) {
4985
- if (!terminalMessage && !terminalEvent)
5028
+ if (!terminalMessage && !terminalEvent && !liveFinish)
4986
5029
  return;
4987
- const startedAt = performance.now();
4988
- await mutateSession({
4989
- ...(terminalMessage ? { messages: [{ ...terminalMessage }] } : {}),
4990
- ...(terminalEvent ? { events: [terminalEvent] } : {}),
4991
- });
4992
- persistenceSpan?.setAttribute("gea.session.finish.transcript_ms", Math.round(performance.now() - startedAt));
5030
+ if (terminalMessage || terminalEvent) {
5031
+ const startedAt = performance.now();
5032
+ if (sessionExecution) {
5033
+ await mutateSession({
5034
+ ...(terminalMessage
5035
+ ? { messages: [{ ...terminalMessage }] }
5036
+ : {}),
5037
+ ...(terminalEvent ? { events: [terminalEvent] } : {}),
5038
+ });
5039
+ }
5040
+ else if (terminalEvent)
5041
+ await appendStreamEvent(terminalEvent);
5042
+ persistenceSpan?.setAttribute("gea.session.finish.transcript_ms", Math.round(performance.now() - startedAt));
5043
+ }
4993
5044
  if (terminalEvent)
4994
5045
  controller.enqueue(terminalEvent);
5046
+ if (liveFinish)
5047
+ controller.enqueue(liveFinish);
4995
5048
  },
4996
5049
  }));
4997
5050
  if (engine || sessionExecution) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const agentSdkVersion = "0.1.261009-alpha.0";
1
+ export declare const agentSdkVersion = "0.1.261009-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.261009-alpha.0";
2
+ export const agentSdkVersion = "0.1.261009-alpha.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gea-ai/agent-sdk",
3
- "version": "0.1.261009-alpha.0",
3
+ "version": "0.1.261009-alpha.1",
4
4
  "private": false,
5
5
  "homepage": "https://musegea.com/developers",
6
6
  "license": "Apache-2.0",
@@ -119,7 +119,7 @@
119
119
  "@ai-sdk/otel": "1.0.119",
120
120
  "@ai-sdk/provider": "4.0.19",
121
121
  "@ai-sdk/provider-utils": "5.0.50",
122
- "@gea-ai/contract": "0.1.261009-alpha.0",
122
+ "@gea-ai/contract": "0.1.261009-alpha.1",
123
123
  "@opentelemetry/api": "1.9.1",
124
124
  "@opentelemetry/context-async-hooks": "2.10.0",
125
125
  "@opentelemetry/core": "2.10.0",