@tangle-network/sandbox 1.0.108 → 1.0.109

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.
@@ -889,11 +889,6 @@ function outcomeToFinishReason(outcome, hasToolCall) {
889
889
  }
890
890
  //#endregion
891
891
  //#region src/openai/translate/chunks.ts
892
- /**
893
- * Read the text token from a `token` event. Tangle emits the delta as
894
- * either `delta`, `text`, or `token`; tolerate all three so the
895
- * translator stays decoupled from minor runtime variations.
896
- */
897
892
  function readTokenDelta(event) {
898
893
  if (typeof event.delta === "string") return event.delta;
899
894
  if (typeof event.text === "string") return event.text;
@@ -916,10 +911,6 @@ function readToolInvocation(event) {
916
911
  arguments: typeof args === "string" ? args : JSON.stringify(args)
917
912
  };
918
913
  }
919
- /**
920
- * Read a usage payload from a `done` event. The runtime emits usage
921
- * either at the top level or under a `usage` key; try both.
922
- */
923
914
  function readUsage(event) {
924
915
  const u = event.usage ?? event;
925
916
  const prompt = Number(u.prompt_tokens ?? u.input_tokens ?? u.inputTokens ?? 0);
@@ -937,36 +928,89 @@ function readOutcome(event) {
937
928
  if (event.success === false) return "failure";
938
929
  return "success";
939
930
  }
940
- function chatBaseChunk(ctx) {
931
+ function chatChunk(ctx, delta, finish, usage) {
941
932
  ctx.chunkIndex += 1;
942
- return {
933
+ const chunk = {
943
934
  id: ctx.runId,
944
935
  created: ctx.createdAt,
945
936
  model: ctx.modelId,
946
- object: "chat.completion.chunk"
937
+ object: "chat.completion.chunk",
938
+ choices: [{
939
+ index: 0,
940
+ delta,
941
+ finish_reason: finish
942
+ }]
947
943
  };
944
+ if (usage) chunk.usage = usage;
945
+ return chunk;
946
+ }
947
+ function textField(value) {
948
+ return typeof value === "string" && value.length > 0 ? value : void 0;
949
+ }
950
+ function recordField(value) {
951
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
952
+ const record = {};
953
+ for (const [key, entry] of Object.entries(value)) record[key] = entry;
954
+ return record;
955
+ }
956
+ /** Incremental part `delta` only. A tool part was already run, so it does not set `finish_reason` to `tool_calls`. */
957
+ function chatPartChunk(event, ctx) {
958
+ const part = recordField(event.part);
959
+ if (!part) return null;
960
+ const incremental = textField(event.delta);
961
+ if (part.type === "text") return incremental ? chatChunk(ctx, {
962
+ role: "assistant",
963
+ content: incremental
964
+ }, null) : null;
965
+ if (part.type === "reasoning") return incremental ? chatChunk(ctx, {
966
+ role: "assistant",
967
+ reasoning: incremental
968
+ }, null) : null;
969
+ if (part.type !== "tool") return null;
970
+ const state = recordField(part.state) ?? {};
971
+ const id = textField(part.callID) ?? textField(part.id) ?? textField(part.toolCallId);
972
+ const name = textField(part.tool) ?? textField(part.name);
973
+ if (!id || !name) return null;
974
+ const args = state.input ?? part.input ?? {};
975
+ const delta = {
976
+ role: "assistant",
977
+ tool_calls: [{
978
+ index: 0,
979
+ id,
980
+ type: "function",
981
+ function: {
982
+ name,
983
+ arguments: typeof args === "string" ? args : JSON.stringify(args)
984
+ }
985
+ }]
986
+ };
987
+ const status = state.status;
988
+ if (status === "completed" || status === "error" || status === "failed") {
989
+ const output = state.output;
990
+ const rendered = typeof output === "string" ? output : JSON.stringify(output ?? "");
991
+ delta.tool_results = [{
992
+ id,
993
+ name,
994
+ status: status === "completed" ? "completed" : "error",
995
+ ...status === "completed" ? { output: rendered } : { error: textField(state.error) ?? rendered }
996
+ }];
997
+ }
998
+ return chatChunk(ctx, delta, null);
948
999
  }
949
1000
  function sandboxEventToChatChunk(event, ctx) {
950
1001
  switch (event.type) {
951
- case "start": return null;
952
- case "execution.started": return null;
953
- case "status": return null;
1002
+ case "start":
1003
+ case "execution.started":
1004
+ case "status":
954
1005
  case "session.updated": return null;
955
- case "message.part.updated": return null;
1006
+ case "message.part.updated": return chatPartChunk(event, ctx);
956
1007
  case "token": {
957
1008
  const delta = readTokenDelta(event);
958
1009
  if (delta == null || delta.length === 0) return null;
959
- return {
960
- ...chatBaseChunk(ctx),
961
- choices: [{
962
- index: 0,
963
- delta: {
964
- role: "assistant",
965
- content: delta
966
- },
967
- finish_reason: null
968
- }]
969
- };
1010
+ return chatChunk(ctx, {
1011
+ role: "assistant",
1012
+ content: delta
1013
+ }, null);
970
1014
  }
971
1015
  case "raw": {
972
1016
  const tool = readToolInvocation(event);
@@ -979,52 +1023,21 @@ function sandboxEventToChatChunk(event, ctx) {
979
1023
  name: tool.name,
980
1024
  arguments: tool.arguments
981
1025
  });
982
- return {
983
- ...chatBaseChunk(ctx),
984
- choices: [{
985
- index: 0,
986
- delta: {
987
- role: "assistant",
988
- tool_calls: [{
989
- index,
990
- id: tool.id,
991
- type: "function",
992
- function: {
993
- name: tool.name,
994
- arguments: tool.arguments
995
- }
996
- }]
997
- },
998
- finish_reason: null
999
- }]
1000
- };
1001
- }
1002
- case "error": {
1003
- const hasToolCall = ctx.toolCallBuffer.size > 0;
1004
- return {
1005
- ...chatBaseChunk(ctx),
1006
- choices: [{
1007
- index: 0,
1008
- delta: {},
1009
- finish_reason: outcomeToFinishReason("error", hasToolCall)
1010
- }]
1011
- };
1012
- }
1013
- case "done": {
1014
- const hasToolCall = ctx.toolCallBuffer.size > 0;
1015
- const finish = outcomeToFinishReason(readOutcome(event), hasToolCall);
1016
- const usage = readUsage(event);
1017
- const chunk = {
1018
- ...chatBaseChunk(ctx),
1019
- choices: [{
1020
- index: 0,
1021
- delta: {},
1022
- finish_reason: finish
1026
+ return chatChunk(ctx, {
1027
+ role: "assistant",
1028
+ tool_calls: [{
1029
+ index,
1030
+ id: tool.id,
1031
+ type: "function",
1032
+ function: {
1033
+ name: tool.name,
1034
+ arguments: tool.arguments
1035
+ }
1023
1036
  }]
1024
- };
1025
- if (usage) chunk.usage = usage;
1026
- return chunk;
1037
+ }, null);
1027
1038
  }
1039
+ case "error":
1040
+ case "done": return chatChunk(ctx, {}, outcomeToFinishReason(event.type === "error" ? "error" : readOutcome(event), ctx.toolCallBuffer.size > 0), readUsage(event) ?? void 0);
1028
1041
  default: return null;
1029
1042
  }
1030
1043
  }
@@ -1168,10 +1181,10 @@ function terminalResponseEvent(event, ctx, extras) {
1168
1181
  function sandboxEventToResponsesEvent(event, ctx) {
1169
1182
  const extras = getResponsesExtras(ctx);
1170
1183
  switch (event.type) {
1171
- case "start": return null;
1172
- case "execution.started": return null;
1173
- case "status": return null;
1174
- case "session.updated": return null;
1184
+ case "start":
1185
+ case "execution.started":
1186
+ case "status":
1187
+ case "session.updated":
1175
1188
  case "message.part.updated": return null;
1176
1189
  case "token": {
1177
1190
  const delta = readTokenDelta(event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "description": "Client SDK for the Tangle Sandbox platform - build AI agent applications with dev containers",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -155,13 +155,13 @@
155
155
  "yjs": "13.6.33",
156
156
  "@products/sandbox-test-utils": "0.0.0",
157
157
  "@repo/shared": "0.0.0",
158
- "@tangle-network/cli-agent-registry": "0.14.0",
159
158
  "@tangle-network/runtime-contracts": "0.20.0",
160
- "@tangle-network/agent-profile-materialize": "0.27.1"
159
+ "@tangle-network/agent-profile-materialize": "0.27.1",
160
+ "@tangle-network/cli-agent-registry": "0.14.0"
161
161
  },
162
162
  "tangleRelease": {
163
- "sourceSha": "e984225adda184c2f01441ce7cc2538aab2cee4e",
164
- "mergedAt": "2026-10-29T20:23:54-06:00"
163
+ "sourceSha": "92b6e4434fdfc165d69bb28623b5ff056e3fa6d5",
164
+ "mergedAt": "2026-10-29T20:53:53-06:00"
165
165
  },
166
166
  "scripts": {
167
167
  "build": "node scripts/build-dist.mjs",