@band-ai/sdk 0.1.4 → 0.1.10

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.
Files changed (73) hide show
  1. package/README.md +372 -0
  2. package/dist/{ClaudeSDKAdapter-CRq4R-WB.d.cts → ClaudeSDKAdapter-DfjaI5ke.d.cts} +9 -7
  3. package/dist/{ClaudeSDKAdapter-BHOkjN3X.d.ts → ClaudeSDKAdapter-DonPGJ43.d.ts} +9 -7
  4. package/dist/{acp-server-BdRz9_UN.d.cts → acp-server-CUBXIiG6.d.cts} +2 -2
  5. package/dist/{acp-server-B1Da7L6u.d.ts → acp-server-NZAeg-WO.d.ts} +2 -2
  6. package/dist/adapters.cjs +494 -106
  7. package/dist/adapters.d.cts +12 -12
  8. package/dist/adapters.d.ts +12 -12
  9. package/dist/adapters.js +7 -7
  10. package/dist/{backends-SVMT-7l4.d.cts → backends-DYtEhCZG.d.cts} +7 -2
  11. package/dist/{backends-CzDbiQar.d.ts → backends-oYAb7EU-.d.ts} +7 -2
  12. package/dist/{chunk-MSL6CWHY.js → chunk-2BHHR6YW.js} +17 -16
  13. package/dist/{chunk-EDPKUUJL.js → chunk-6RXWL6TC.js} +9 -1
  14. package/dist/{chunk-SFVKOEQH.js → chunk-DNPVCR3S.js} +92 -14
  15. package/dist/{chunk-I5EZG52P.js → chunk-FP237EAG.js} +424 -136
  16. package/dist/{chunk-RHVH2GZR.js → chunk-J3M3PFFY.js} +81 -31
  17. package/dist/{chunk-GVEQ3RAH.js → chunk-MLROFDKR.js} +132 -23
  18. package/dist/{chunk-INA6YZTZ.js → chunk-RDM4TE4B.js} +32 -30
  19. package/dist/chunk-US226AS4.js +130 -0
  20. package/dist/{chunk-W5NDZSYE.js → chunk-XA4N2JPH.js} +1 -1
  21. package/dist/converters.cjs +469 -13
  22. package/dist/converters.d.cts +5 -5
  23. package/dist/converters.d.ts +5 -5
  24. package/dist/converters.js +3 -2
  25. package/dist/core.cjs +45 -2
  26. package/dist/core.d.cts +4 -3
  27. package/dist/core.d.ts +4 -3
  28. package/dist/core.js +5 -1
  29. package/dist/disconnectReason-IuADl6TH.d.cts +34 -0
  30. package/dist/disconnectReason-IuADl6TH.d.ts +34 -0
  31. package/dist/{dtos-DUpbIu8k.d.cts → dtos-Dd_fTfLn.d.cts} +26 -6
  32. package/dist/{dtos-DUpbIu8k.d.ts → dtos-Dd_fTfLn.d.ts} +26 -6
  33. package/dist/index.cjs +1089 -269
  34. package/dist/index.d.cts +16 -15
  35. package/dist/index.d.ts +16 -15
  36. package/dist/index.js +14 -8
  37. package/dist/linear.cjs +985 -53
  38. package/dist/linear.d.cts +137 -7
  39. package/dist/linear.d.ts +137 -7
  40. package/dist/linear.js +974 -53
  41. package/dist/mcp-claude.cjs +303 -32
  42. package/dist/mcp-claude.d.cts +3 -3
  43. package/dist/mcp-claude.d.ts +3 -3
  44. package/dist/mcp-claude.js +210 -12
  45. package/dist/mcp.cjs +313 -45
  46. package/dist/mcp.d.cts +5 -5
  47. package/dist/mcp.d.ts +5 -5
  48. package/dist/mcp.js +3 -3
  49. package/dist/{opencode-BBcDchcN.d.cts → opencode--iA5-KYk.d.cts} +2 -2
  50. package/dist/{opencode-DthQQUsZ.d.ts → opencode-YNacv-eJ.d.ts} +2 -2
  51. package/dist/{pagination-CcDkVFxK.d.ts → pagination-BBLsYLhT.d.ts} +2 -2
  52. package/dist/{pagination-BPiys10t.d.cts → pagination-CqidD-L_.d.cts} +2 -2
  53. package/dist/{protocols-DrhzOH6K.d.ts → protocols-BF6jamIl.d.ts} +1 -1
  54. package/dist/{protocols-CInhtFpA.d.cts → protocols-D2bTrQ_t.d.cts} +1 -1
  55. package/dist/rest.d.cts +5 -5
  56. package/dist/rest.d.ts +5 -5
  57. package/dist/runtime.cjs +721 -172
  58. package/dist/runtime.d.cts +15 -10
  59. package/dist/runtime.d.ts +15 -10
  60. package/dist/runtime.js +11 -8
  61. package/dist/{schemas-vos1AaBc.d.ts → schemas-B1Fd3oUM.d.ts} +17 -8
  62. package/dist/{schemas-BpEBkq5V.d.cts → schemas-CI0qgcp_.d.cts} +17 -8
  63. package/dist/{sdk-CcnQ5OUC.d.ts → sdk-CyqN1W5g.d.ts} +32 -2
  64. package/dist/{sdk-CwTAxhwI.d.cts → sdk-D2rTDU_o.d.cts} +32 -2
  65. package/dist/{simpleAdapter-DqhvjsGr.d.cts → simpleAdapter-C_f-01Cu.d.cts} +1 -1
  66. package/dist/{simpleAdapter-9OE_p6QW.d.ts → simpleAdapter-qQt-tSz4.d.ts} +1 -1
  67. package/dist/testing.d.cts +3 -3
  68. package/dist/testing.d.ts +3 -3
  69. package/dist/{types-CovcHpYf.d.cts → types-CKqrhGB1.d.cts} +2 -2
  70. package/dist/{types-CxII3XkA.d.ts → types-D3AsUnd0.d.ts} +1 -1
  71. package/dist/{types-7jVzOeOP.d.ts → types-DNySTI_8.d.ts} +2 -2
  72. package/dist/{types-CSHFipIc.d.cts → types-DtMms5Fi.d.cts} +1 -1
  73. package/package.json +22 -21
@@ -1,32 +1,32 @@
1
1
  import {
2
2
  createThenvoiMcpBackend
3
- } from "./chunk-MSL6CWHY.js";
3
+ } from "./chunk-2BHHR6YW.js";
4
4
  import {
5
5
  buildRoomScopedRegistrations,
6
6
  buildZodShape,
7
7
  errorResult,
8
8
  successResult
9
- } from "./chunk-EDPKUUJL.js";
9
+ } from "./chunk-6RXWL6TC.js";
10
10
  import {
11
11
  GoogleADKHistoryConverter,
12
12
  LazyAsyncValue,
13
13
  OpencodeHistoryConverter,
14
14
  extractClaudeSessionId,
15
15
  findLatestTaskMetadata
16
- } from "./chunk-W5NDZSYE.js";
16
+ } from "./chunk-XA4N2JPH.js";
17
17
  import {
18
18
  SimpleAdapter
19
19
  } from "./chunk-AVVDPXP4.js";
20
20
  import {
21
21
  formatHistoryForLlm,
22
22
  formatMessageForLlm
23
- } from "./chunk-INA6YZTZ.js";
24
- import {
25
- mcpToolNames
26
- } from "./chunk-GVEQ3RAH.js";
23
+ } from "./chunk-RDM4TE4B.js";
27
24
  import {
28
25
  renderSystemPrompt
29
- } from "./chunk-SFVKOEQH.js";
26
+ } from "./chunk-DNPVCR3S.js";
27
+ import {
28
+ mcpToolNames
29
+ } from "./chunk-MLROFDKR.js";
30
30
  import {
31
31
  asErrorMessage,
32
32
  asNonEmptyString,
@@ -750,7 +750,8 @@ var CodexAdapter = class extends SimpleAdapter {
750
750
  agentName: this.agentName,
751
751
  agentDescription: this.agentDescription,
752
752
  customSection,
753
- includeBaseInstructions: this.baseConfig.includeBaseInstructions ?? true
753
+ includeBaseInstructions: this.baseConfig.includeBaseInstructions ?? true,
754
+ capabilities: { memory: this.includeMemoryTools }
754
755
  }).trim();
755
756
  this.systemPrompt = prompt.length > 0 ? prompt : null;
756
757
  }
@@ -2630,7 +2631,8 @@ var GoogleADKAdapter = class extends SimpleAdapter {
2630
2631
  this.systemPrompt = this.systemPromptOverride ?? renderSystemPrompt({
2631
2632
  agentName,
2632
2633
  agentDescription,
2633
- customSection: this.customSection
2634
+ customSection: this.customSection,
2635
+ capabilities: { memory: this.enableMemoryTools }
2634
2636
  });
2635
2637
  }
2636
2638
  async onMessage(message, tools, history, participantsMessage, contactsMessage, context) {
@@ -2869,7 +2871,8 @@ var LangGraphAdapter = class extends SimpleAdapter {
2869
2871
  this.renderedSystemPrompt = this.systemPromptOverride ?? renderSystemPrompt({
2870
2872
  agentName,
2871
2873
  agentDescription,
2872
- customSection: this.customSection
2874
+ customSection: this.customSection,
2875
+ capabilities: { memory: this.includeMemoryTools }
2873
2876
  });
2874
2877
  }
2875
2878
  async onMessage(message, tools, history, participantsMessage, contactsMessage, context) {
@@ -2888,14 +2891,17 @@ var LangGraphAdapter = class extends SimpleAdapter {
2888
2891
  ];
2889
2892
  }
2890
2893
  const graph = await this.resolveGraph(sdk, langGraphTools);
2891
- const messages = this.buildMessages(
2892
- history,
2893
- message,
2894
- participantsMessage,
2895
- contactsMessage,
2896
- context.isSessionBootstrap,
2897
- context.roomId
2898
- );
2894
+ const usesCheckpointer = Boolean(this.checkpointer);
2895
+ const isFirstBootstrap = context.isSessionBootstrap && !this.bootstrappedRooms.has(context.roomId);
2896
+ const replayHistory = !usesCheckpointer || isFirstBootstrap;
2897
+ const includeSystemPrompt = this.usesCustomGraph && (!usesCheckpointer || isFirstBootstrap);
2898
+ if (context.isSessionBootstrap) {
2899
+ this.bootstrappedRooms.add(context.roomId);
2900
+ }
2901
+ const messages = this.buildMessages(history, message, participantsMessage, contactsMessage, {
2902
+ replayHistory,
2903
+ includeSystemPrompt
2904
+ });
2899
2905
  const input = { messages };
2900
2906
  const graphConfig = {
2901
2907
  configurable: {
@@ -2922,6 +2928,10 @@ var LangGraphAdapter = class extends SimpleAdapter {
2922
2928
  async onCleanup(roomId) {
2923
2929
  this.bootstrappedRooms.delete(roomId);
2924
2930
  }
2931
+ /** A caller-supplied graph rather than the built-in createReactAgent. */
2932
+ get usesCustomGraph() {
2933
+ return Boolean(this.graph || this.graphFactory);
2934
+ }
2925
2935
  resolveGraph(sdk, langGraphTools) {
2926
2936
  if (this.graphFactory) {
2927
2937
  return Promise.resolve(this.graphFactory(langGraphTools));
@@ -2942,14 +2952,13 @@ var LangGraphAdapter = class extends SimpleAdapter {
2942
2952
  prompt: this.renderedSystemPrompt
2943
2953
  }));
2944
2954
  }
2945
- buildMessages(history, message, participantsMessage, contactsMessage, isSessionBootstrap, roomId) {
2955
+ buildMessages(history, message, participantsMessage, contactsMessage, options) {
2946
2956
  const messages = [];
2947
- if (isSessionBootstrap && !this.bootstrappedRooms.has(roomId)) {
2957
+ if (options.includeSystemPrompt) {
2948
2958
  messages.push(["system", this.renderedSystemPrompt]);
2949
- this.bootstrappedRooms.add(roomId);
2950
2959
  }
2951
- if (isSessionBootstrap && history.length > 0) {
2952
- const historical = history.raw.slice(-this.maxHistoryMessages);
2960
+ if (options.replayHistory && history.length > 0) {
2961
+ const historical = history.raw.filter((item) => item.id !== message.id).slice(-this.maxHistoryMessages);
2953
2962
  for (const item of historical) {
2954
2963
  const role = String(item.sender_type ?? "") === "Agent" ? "assistant" : "user";
2955
2964
  const content = String(item.content ?? "");
@@ -2968,7 +2977,7 @@ var LangGraphAdapter = class extends SimpleAdapter {
2968
2977
  return messages;
2969
2978
  }
2970
2979
  async forwardStreamEvents(graph, input, config, tools) {
2971
- const stream = graph.streamEvents?.(input, config, { version: "v2" });
2980
+ const stream = graph.streamEvents?.(input, { ...config, version: "v2" });
2972
2981
  if (!stream) {
2973
2982
  return null;
2974
2983
  }
@@ -2995,6 +3004,10 @@ var LangGraphAdapter = class extends SimpleAdapter {
2995
3004
  );
2996
3005
  }
2997
3006
  if (eventType === "on_chain_end") {
3007
+ const chainName = String(data.name ?? "");
3008
+ if (!this.usesCustomGraph && chainName !== "LangGraph" && chainName !== "agent") {
3009
+ continue;
3010
+ }
2998
3011
  const output = asOptionalRecord(data.data) ?? {};
2999
3012
  const text = extractAssistantText(output.output);
3000
3013
  if (text) {
@@ -3056,18 +3069,25 @@ function stringifyToolResult2(value, logger, toolName) {
3056
3069
  });
3057
3070
  }
3058
3071
  function extractAssistantText(result) {
3059
- if (typeof result === "string" && result.trim().length > 0) {
3060
- return result.trim();
3072
+ if (typeof result === "string") {
3073
+ const trimmed = result.trim();
3074
+ return trimmed.length > 0 && !isInternalLangGraphMarker(trimmed) ? trimmed : null;
3061
3075
  }
3062
3076
  const record = asOptionalRecord(result) ?? {};
3077
+ if (isLangChainAssistantMessage(record)) {
3078
+ const text = asLangChainMessageContent(record);
3079
+ if (text && !isInternalLangGraphMarker(text)) {
3080
+ return text;
3081
+ }
3082
+ }
3063
3083
  const directContent = asMessageContent(record.content);
3064
- if (directContent) {
3084
+ if (directContent && !isInternalLangGraphMarker(directContent)) {
3065
3085
  return directContent;
3066
3086
  }
3067
3087
  const messages = Array.isArray(record.messages) ? record.messages : [];
3068
3088
  for (let index = messages.length - 1; index >= 0; index -= 1) {
3069
3089
  const text = asMessageText(messages[index]);
3070
- if (text) {
3090
+ if (text && !isInternalLangGraphMarker(text)) {
3071
3091
  return text;
3072
3092
  }
3073
3093
  }
@@ -3084,12 +3104,40 @@ function asMessageText(value) {
3084
3104
  if (!record) {
3085
3105
  return null;
3086
3106
  }
3107
+ if (isLangChainAssistantMessage(record)) {
3108
+ return asLangChainMessageContent(record);
3109
+ }
3087
3110
  const role = String(record.role ?? "");
3088
3111
  if (role !== "assistant") {
3089
3112
  return null;
3090
3113
  }
3091
3114
  return asMessageContent(record.content);
3092
3115
  }
3116
+ function isLangChainAssistantMessage(record) {
3117
+ const id = record.id;
3118
+ if (Array.isArray(id)) {
3119
+ const typeName = String(id[id.length - 1] ?? "");
3120
+ if (typeName === "AIMessage" || typeName === "AIMessageChunk") {
3121
+ return true;
3122
+ }
3123
+ }
3124
+ const getType = record.getType;
3125
+ if (typeof getType === "function") {
3126
+ try {
3127
+ return getType.call(record) === "ai";
3128
+ } catch {
3129
+ return false;
3130
+ }
3131
+ }
3132
+ return false;
3133
+ }
3134
+ function asLangChainMessageContent(record) {
3135
+ const kwargs = asOptionalRecord(record.kwargs);
3136
+ return asMessageContent(kwargs?.content ?? record.content);
3137
+ }
3138
+ function isInternalLangGraphMarker(text) {
3139
+ return text === "__end__" || text === "__start__";
3140
+ }
3093
3141
  function asMessageContent(value) {
3094
3142
  if (typeof value === "string" && value.trim().length > 0) {
3095
3143
  return value.trim();
@@ -4244,7 +4292,8 @@ var OpencodeAdapter = class extends SimpleAdapter {
4244
4292
  agentName,
4245
4293
  agentDescription,
4246
4294
  customSection: this.config.customSection,
4247
- includeBaseInstructions: this.config.includeBaseInstructions
4295
+ includeBaseInstructions: this.config.includeBaseInstructions,
4296
+ capabilities: { memory: this.config.enableMemoryTools }
4248
4297
  }).trim();
4249
4298
  this.systemPrompt = `${systemPrompt}
4250
4299
 
@@ -5095,7 +5144,8 @@ var ClaudeSDKAdapter = class extends SimpleAdapter {
5095
5144
  agentName,
5096
5145
  agentDescription,
5097
5146
  customSection: this.customSection,
5098
- includeBaseInstructions: this.includeBaseInstructions
5147
+ includeBaseInstructions: this.includeBaseInstructions,
5148
+ capabilities: { memory: this.enableMemoryTools }
5099
5149
  });
5100
5150
  if (this.enableMcpTools) {
5101
5151
  const createThenvoiMcpBridge = await thenvoiMcpBridgeFactory.get();
@@ -16,6 +16,108 @@ function assertChatEventType(value) {
16
16
  }
17
17
  }
18
18
 
19
+ // src/contracts/memory.ts
20
+ var SENSORY_MEMORY_TYPES = [
21
+ "iconic",
22
+ // Visual input
23
+ "echoic",
24
+ // Auditory input
25
+ "haptic"
26
+ // Tactile input
27
+ ];
28
+ var COGNITIVE_MEMORY_TYPES = [
29
+ "episodic",
30
+ // Events that occurred
31
+ "semantic",
32
+ // Facts, preferences, learned knowledge
33
+ "procedural"
34
+ // How to perform tasks
35
+ ];
36
+ function namedValues(values) {
37
+ return Object.fromEntries(values.map((value) => [value, value]));
38
+ }
39
+ var MEMORY_SYSTEM_TYPES = {
40
+ sensory: SENSORY_MEMORY_TYPES,
41
+ // Brief sensory inputs
42
+ working: COGNITIVE_MEMORY_TYPES,
43
+ // Short-term session context
44
+ long_term: COGNITIVE_MEMORY_TYPES
45
+ // Persistent cross-conversation memory
46
+ };
47
+ var MEMORY_SYSTEMS = Object.keys(MEMORY_SYSTEM_TYPES);
48
+ var MEMORY_TYPES = [
49
+ ...SENSORY_MEMORY_TYPES,
50
+ ...COGNITIVE_MEMORY_TYPES
51
+ ];
52
+ var MEMORY_SEGMENTS = [
53
+ "user",
54
+ // User preferences or profile info
55
+ "agent",
56
+ // Facts or events about agents/entities
57
+ "tool",
58
+ // Tool usage or task procedures
59
+ "guideline"
60
+ // Behavioral rules or policies
61
+ ];
62
+ var MEMORY_STORE_SCOPES = [
63
+ "subject",
64
+ // About one person/agent; requires subject_id
65
+ "organization"
66
+ // Shared org-wide
67
+ ];
68
+ var MEMORY_LIST_SCOPES = [
69
+ "subject",
70
+ // Subject-scoped memories only
71
+ "organization",
72
+ // Organization-scoped memories only
73
+ "all"
74
+ // Both scopes (no scope filter)
75
+ ];
76
+ var MEMORY_STATUSES = [
77
+ "active",
78
+ // Normal, visible memories
79
+ "superseded",
80
+ // Outdated; soft-deleted via thenvoi_supersede_memory
81
+ "archived",
82
+ // Hidden but preserved via thenvoi_archive_memory
83
+ "all"
84
+ // Any status (no filter)
85
+ ];
86
+ var MEMORY_SYSTEM = namedValues(MEMORY_SYSTEMS);
87
+ var MEMORY_TYPE = namedValues(MEMORY_TYPES);
88
+ var MEMORY_SEGMENT = namedValues(MEMORY_SEGMENTS);
89
+ var MEMORY_STORE_SCOPE = namedValues(MEMORY_STORE_SCOPES);
90
+ function isMemorySystem(value) {
91
+ return MEMORY_SYSTEMS.includes(value);
92
+ }
93
+ function isMemoryType(value) {
94
+ return MEMORY_TYPES.includes(value);
95
+ }
96
+ function isMemoryTypeForSystem(system, type) {
97
+ return MEMORY_SYSTEM_TYPES[system].includes(type);
98
+ }
99
+ function isMemorySegment(value) {
100
+ return MEMORY_SEGMENTS.includes(value);
101
+ }
102
+ function isMemoryStoreScope(value) {
103
+ return MEMORY_STORE_SCOPES.includes(value);
104
+ }
105
+ function isMemoryListScope(value) {
106
+ return MEMORY_LIST_SCOPES.includes(value);
107
+ }
108
+ function isMemoryStatus(value) {
109
+ return MEMORY_STATUSES.includes(value);
110
+ }
111
+ function expectedList(values) {
112
+ return values.join(", ");
113
+ }
114
+ function expectedMemoryTypesForSystem(system) {
115
+ return expectedList(MEMORY_SYSTEM_TYPES[system]);
116
+ }
117
+ function memoryTypeForSystemError(system) {
118
+ return `type must be one of: ${expectedMemoryTypesForSystem(system)} for system "${system}"`;
119
+ }
120
+
19
121
  // src/runtime/tools/schemas.ts
20
122
  var TOOL_MODELS = {
21
123
  thenvoi_send_message: {
@@ -203,29 +305,22 @@ var TOOL_MODELS = {
203
305
  },
204
306
  scope: {
205
307
  type: "string",
206
- enum: ["subject", "organization", "all"],
308
+ enum: [...MEMORY_LIST_SCOPES],
207
309
  description: "Filter by scope."
208
310
  },
209
311
  system: {
210
312
  type: "string",
211
- enum: ["sensory", "working", "long_term"],
313
+ enum: [...MEMORY_SYSTEMS],
212
314
  description: "Filter by memory system."
213
315
  },
214
316
  type: {
215
317
  type: "string",
216
- enum: [
217
- "iconic",
218
- "echoic",
219
- "haptic",
220
- "episodic",
221
- "semantic",
222
- "procedural"
223
- ],
318
+ enum: [...MEMORY_TYPES],
224
319
  description: "Filter by memory type."
225
320
  },
226
321
  segment: {
227
322
  type: "string",
228
- enum: ["user", "agent", "tool", "guideline"],
323
+ enum: [...MEMORY_SEGMENTS],
229
324
  description: "Filter by segment."
230
325
  },
231
326
  content_query: {
@@ -240,7 +335,7 @@ var TOOL_MODELS = {
240
335
  },
241
336
  status: {
242
337
  type: "string",
243
- enum: ["active", "superseded", "archived", "all"],
338
+ enum: [...MEMORY_STATUSES],
244
339
  description: "Filter by status."
245
340
  }
246
341
  },
@@ -255,24 +350,17 @@ var TOOL_MODELS = {
255
350
  },
256
351
  system: {
257
352
  type: "string",
258
- enum: ["sensory", "working", "long_term"],
353
+ enum: [...MEMORY_SYSTEMS],
259
354
  description: "Memory system tier."
260
355
  },
261
356
  type: {
262
357
  type: "string",
263
- enum: [
264
- "iconic",
265
- "echoic",
266
- "haptic",
267
- "episodic",
268
- "semantic",
269
- "procedural"
270
- ],
358
+ enum: [...MEMORY_TYPES],
271
359
  description: "Memory type (must be valid for selected system)."
272
360
  },
273
361
  segment: {
274
362
  type: "string",
275
- enum: ["user", "agent", "tool", "guideline"],
363
+ enum: [...MEMORY_SEGMENTS],
276
364
  description: "Logical segment."
277
365
  },
278
366
  thought: {
@@ -281,7 +369,7 @@ var TOOL_MODELS = {
281
369
  },
282
370
  scope: {
283
371
  type: "string",
284
- enum: ["subject", "organization"],
372
+ enum: [...MEMORY_STORE_SCOPES],
285
373
  description: "Visibility scope."
286
374
  },
287
375
  subject_id: {
@@ -361,6 +449,27 @@ export {
361
449
  CHAT_MESSAGE_TYPES,
362
450
  isChatEventType,
363
451
  assertChatEventType,
452
+ MEMORY_SYSTEM_TYPES,
453
+ MEMORY_SYSTEMS,
454
+ MEMORY_TYPES,
455
+ MEMORY_SEGMENTS,
456
+ MEMORY_STORE_SCOPES,
457
+ MEMORY_LIST_SCOPES,
458
+ MEMORY_STATUSES,
459
+ MEMORY_SYSTEM,
460
+ MEMORY_TYPE,
461
+ MEMORY_SEGMENT,
462
+ MEMORY_STORE_SCOPE,
463
+ isMemorySystem,
464
+ isMemoryType,
465
+ isMemoryTypeForSystem,
466
+ isMemorySegment,
467
+ isMemoryStoreScope,
468
+ isMemoryListScope,
469
+ isMemoryStatus,
470
+ expectedList,
471
+ expectedMemoryTypesForSystem,
472
+ memoryTypeForSystemError,
364
473
  TOOL_MODELS,
365
474
  ALL_TOOL_NAMES,
366
475
  MEMORY_TOOL_NAMES,
@@ -1,3 +1,26 @@
1
+ // src/runtime/types.ts
2
+ var HistoryProvider = class {
3
+ raw;
4
+ constructor(raw) {
5
+ this.raw = raw;
6
+ }
7
+ convert(converter) {
8
+ return converter.convert(this.raw);
9
+ }
10
+ get length() {
11
+ return this.raw.length;
12
+ }
13
+ };
14
+ var SYNTHETIC_SENDER_TYPE = "System";
15
+ var SYNTHETIC_CONTACT_EVENTS_SENDER_ID = "contact-events";
16
+ var SYNTHETIC_CONTACT_EVENTS_SENDER_NAME = "Contact Events";
17
+ function ensureHandlePrefix(handle) {
18
+ if (!handle) {
19
+ return null;
20
+ }
21
+ return handle.startsWith("@") ? handle : `@${handle}`;
22
+ }
23
+
1
24
  // src/runtime/formatters.ts
2
25
  function isMetadataMap(value) {
3
26
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -11,7 +34,7 @@ function replaceUuidMentions(content, participants) {
11
34
  const participantId = participant.id;
12
35
  const handle = participant.handle;
13
36
  if (typeof participantId === "string" && typeof handle === "string") {
14
- next = next.replaceAll(`@[[${participantId}]]`, `@${handle}`);
37
+ next = next.replaceAll(`@[[${participantId}]]`, ensureHandlePrefix(handle) ?? "");
15
38
  }
16
39
  }
17
40
  return next;
@@ -43,7 +66,9 @@ function buildParticipantsMessage(participants) {
43
66
  const participantType = String(participant.type ?? "Unknown");
44
67
  const participantName = String(participant.name ?? "Unknown");
45
68
  const participantHandle = String(participant.handle ?? "Unknown");
46
- lines.push(`- @${participantHandle} \u2014 ${participantName} (${participantType})`);
69
+ lines.push(
70
+ `- ${ensureHandlePrefix(participantHandle) ?? ""} \u2014 ${participantName} (${participantType})`
71
+ );
47
72
  }
48
73
  lines.push("");
49
74
  lines.push(
@@ -52,37 +77,14 @@ function buildParticipantsMessage(participants) {
52
77
  return lines.join("\n");
53
78
  }
54
79
 
55
- // src/runtime/types.ts
56
- var HistoryProvider = class {
57
- raw;
58
- constructor(raw) {
59
- this.raw = raw;
60
- }
61
- convert(converter) {
62
- return converter.convert(this.raw);
63
- }
64
- get length() {
65
- return this.raw.length;
66
- }
67
- };
68
- var SYNTHETIC_SENDER_TYPE = "System";
69
- var SYNTHETIC_CONTACT_EVENTS_SENDER_ID = "contact-events";
70
- var SYNTHETIC_CONTACT_EVENTS_SENDER_NAME = "Contact Events";
71
- function ensureHandlePrefix(handle) {
72
- if (!handle) {
73
- return null;
74
- }
75
- return handle.startsWith("@") ? handle : `@${handle}`;
76
- }
77
-
78
80
  export {
79
- replaceUuidMentions,
80
- formatMessageForLlm,
81
- formatHistoryForLlm,
82
- buildParticipantsMessage,
83
81
  HistoryProvider,
84
82
  SYNTHETIC_SENDER_TYPE,
85
83
  SYNTHETIC_CONTACT_EVENTS_SENDER_ID,
86
84
  SYNTHETIC_CONTACT_EVENTS_SENDER_NAME,
87
- ensureHandlePrefix
85
+ ensureHandlePrefix,
86
+ replaceUuidMentions,
87
+ formatMessageForLlm,
88
+ formatHistoryForLlm,
89
+ buildParticipantsMessage
88
90
  };
@@ -0,0 +1,130 @@
1
+ // src/platform/streaming/disconnectReason.ts
2
+ import { z } from "zod";
3
+ var UPGRADE_CODES = [
4
+ "invalid_on_conflict",
5
+ "connection_conflict",
6
+ "too_many_requests",
7
+ "tracking_failed"
8
+ ];
9
+ var UPGRADE_REASONS = {
10
+ invalid_on_conflict: {
11
+ status: 400,
12
+ message: "Invalid websocket conflict policy.",
13
+ retryable: false
14
+ },
15
+ connection_conflict: {
16
+ status: 409,
17
+ message: "Websocket connection conflict.",
18
+ retryable: false
19
+ },
20
+ too_many_requests: {
21
+ status: 429,
22
+ message: "Too many websocket connection attempts.",
23
+ retryable: true
24
+ },
25
+ tracking_failed: {
26
+ status: 503,
27
+ message: "Websocket connection tracking failed.",
28
+ retryable: true
29
+ }
30
+ };
31
+ var upgradeErrorSchema = z.object({
32
+ status: z.number(),
33
+ body: z.preprocess(
34
+ (body) => {
35
+ if (typeof body !== "string") {
36
+ return body;
37
+ }
38
+ try {
39
+ return JSON.parse(body);
40
+ } catch {
41
+ return null;
42
+ }
43
+ },
44
+ z.object({
45
+ error: z.object({
46
+ code: z.enum(UPGRADE_CODES),
47
+ message: z.string().optional(),
48
+ retry_after: z.number().nullable().optional(),
49
+ request_id: z.string().nullable().optional()
50
+ })
51
+ })
52
+ ),
53
+ headers: z.record(z.unknown()).optional()
54
+ });
55
+ var WebSocketDisconnectError = class extends Error {
56
+ reason;
57
+ constructor(reason) {
58
+ super(reason.message);
59
+ this.name = "WebSocketDisconnectError";
60
+ this.reason = reason;
61
+ }
62
+ };
63
+ function parseSupersedeDisconnectReason(payload) {
64
+ if (typeof payload.reason !== "string" || typeof payload.message !== "string") {
65
+ return null;
66
+ }
67
+ return {
68
+ source: "agent_control",
69
+ code: payload.reason,
70
+ message: payload.message,
71
+ retryable: false,
72
+ retryAfter: typeof payload.retry_after === "number" ? payload.retry_after : null,
73
+ targetSocketId: typeof payload.target_socket_id === "string" ? payload.target_socket_id : null,
74
+ correlationId: typeof payload.correlation_id === "string" ? payload.correlation_id : null
75
+ };
76
+ }
77
+ function parseUpgradeDisconnectReason(event) {
78
+ const parsed = upgradeErrorSchema.safeParse(event);
79
+ if (!parsed.success) {
80
+ return null;
81
+ }
82
+ const { status, body, headers } = parsed.data;
83
+ const {
84
+ code,
85
+ message,
86
+ retry_after: retryAfter,
87
+ request_id: requestId
88
+ } = body.error;
89
+ const reason = UPGRADE_REASONS[code];
90
+ if (status !== reason.status) {
91
+ return null;
92
+ }
93
+ return {
94
+ source: "upgrade",
95
+ status: reason.status,
96
+ code,
97
+ message: message ?? reason.message,
98
+ retryable: reason.retryable,
99
+ retryAfter: retryAfter ?? retryAfterFromHeaders(headers),
100
+ requestId: requestId ?? null
101
+ };
102
+ }
103
+ function genericCloseReason(event) {
104
+ return {
105
+ source: "websocket_close",
106
+ code: "websocket.closed",
107
+ message: "Phoenix socket closed without a platform disconnect reason.",
108
+ retryable: true,
109
+ closeCode: typeof event?.code === "number" ? event.code : null,
110
+ closeReason: typeof event?.reason === "string" && event.reason.length > 0 ? event.reason : null
111
+ };
112
+ }
113
+ function retryAfterFromHeaders(headers) {
114
+ const value = headers?.["retry-after"] ?? headers?.["Retry-After"];
115
+ if (typeof value === "number") {
116
+ return value;
117
+ }
118
+ if (typeof value === "string" && value.trim() !== "") {
119
+ const seconds = Number(value);
120
+ return Number.isFinite(seconds) ? seconds : null;
121
+ }
122
+ return null;
123
+ }
124
+
125
+ export {
126
+ WebSocketDisconnectError,
127
+ parseSupersedeDisconnectReason,
128
+ parseUpgradeDisconnectReason,
129
+ genericCloseReason
130
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-AVVDPXP4.js";
4
4
  import {
5
5
  renderSystemPrompt
6
- } from "./chunk-SFVKOEQH.js";
6
+ } from "./chunk-DNPVCR3S.js";
7
7
  import {
8
8
  asErrorMessage,
9
9
  asNonEmptyString,