@band-ai/sdk 0.3.4 → 0.4.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.
Files changed (97) hide show
  1. package/README.md +54 -1
  2. package/dist/{ClaudeSDKAdapter-CXud2DBE.d.ts → CopilotACPAdapter-B_AVyAl6.d.ts} +249 -19
  3. package/dist/{ClaudeSDKAdapter-Cx6zhSaG.d.cts → CopilotACPAdapter-Clid9xGR.d.cts} +249 -19
  4. package/dist/{opencode-2YdscIc1.d.cts → acp-client-D-I_5lK-.d.cts} +23 -4
  5. package/dist/{opencode-Bld62x5t.d.ts → acp-client-DUXyczlF.d.ts} +23 -4
  6. package/dist/acp-server-BlcYMxKt.d.ts +17 -0
  7. package/dist/acp-server-CJhclo6P.d.cts +17 -0
  8. package/dist/adapters.cjs +2257 -969
  9. package/dist/adapters.d.cts +21 -132
  10. package/dist/adapters.d.ts +21 -132
  11. package/dist/adapters.js +26 -1922
  12. package/dist/{backends-D-dBdDm-.d.ts → backends-CgsPQa9B.d.ts} +2 -2
  13. package/dist/{backends-ZLxmQrTZ.d.cts → backends-Dh2WXcHQ.d.cts} +2 -2
  14. package/dist/{chunk-JY75VSQK.js → chunk-4OVNFDD7.js} +14 -1
  15. package/dist/chunk-6BE2EG5P.js +128 -0
  16. package/dist/{chunk-U6AFCLYZ.js → chunk-6TGXV5TE.js} +1824 -514
  17. package/dist/{chunk-OH6VVVKT.js → chunk-CBCHTTUY.js} +10 -0
  18. package/dist/{chunk-K5KAEYPF.js → chunk-HNWZZXAE.js} +288 -120
  19. package/dist/chunk-I34SXMTJ.js +6 -0
  20. package/dist/{chunk-XWHWJP4I.js → chunk-JDW5WSGF.js} +2 -2
  21. package/dist/{chunk-KXJ74J73.js → chunk-JIZE4EC6.js} +4 -10
  22. package/dist/chunk-OGOXY43L.js +119 -0
  23. package/dist/{chunk-W5IAI6Z4.js → chunk-OVXVZUPO.js} +5 -5
  24. package/dist/{chunk-YJ42AZO4.js → chunk-RJNJUISR.js} +5 -2
  25. package/dist/{chunk-MQY74R7D.js → chunk-SHZBLLDQ.js} +21 -9
  26. package/dist/{chunk-JADCAMZY.js → chunk-TGDDFBYS.js} +45 -0
  27. package/dist/{chunk-US226AS4.js → chunk-UENIC5FJ.js} +14 -11
  28. package/dist/{chunk-MQBBWYRP.js → chunk-UFO6XMCV.js} +3404 -572
  29. package/dist/{chunk-WA7CHXUS.js → chunk-UL3Y5C4J.js} +2 -2
  30. package/dist/{chunk-WL2HNJZ6.js → chunk-VOMJRQOM.js} +3 -3
  31. package/dist/{chunk-OD2G5LFQ.js → chunk-ZYOXI4JL.js} +41 -2
  32. package/dist/config.cjs +2 -12
  33. package/dist/config.js +2 -2
  34. package/dist/converters.cjs +36 -11
  35. package/dist/converters.d.cts +7 -5
  36. package/dist/converters.d.ts +7 -5
  37. package/dist/converters.js +11 -13
  38. package/dist/core.cjs +239 -5
  39. package/dist/core.d.cts +71 -6
  40. package/dist/core.d.ts +71 -6
  41. package/dist/core.js +31 -6
  42. package/dist/{customTools-BzF0IISO.d.cts → customTools-Bfecd0mJ.d.cts} +1 -1
  43. package/dist/{customTools-BzF0IISO.d.ts → customTools-Bfecd0mJ.d.ts} +1 -1
  44. package/dist/{disconnectReason-IuADl6TH.d.ts → disconnectReason-Cctmg1SN.d.cts} +1 -1
  45. package/dist/{disconnectReason-IuADl6TH.d.cts → disconnectReason-Cctmg1SN.d.ts} +1 -1
  46. package/dist/{dtos-B8KU_q4d.d.ts → dtos-CjQsN1_h.d.cts} +5 -12
  47. package/dist/{dtos-B8KU_q4d.d.cts → dtos-CjQsN1_h.d.ts} +5 -12
  48. package/dist/index.cjs +5289 -1474
  49. package/dist/index.d.cts +61 -22
  50. package/dist/index.d.ts +61 -22
  51. package/dist/index.js +151 -43
  52. package/dist/linear.cjs +45 -7
  53. package/dist/linear.d.cts +4 -3
  54. package/dist/linear.d.ts +4 -3
  55. package/dist/linear.js +10 -10
  56. package/dist/mcp-claude.cjs +11 -6
  57. package/dist/mcp-claude.d.cts +4 -3
  58. package/dist/mcp-claude.d.ts +4 -3
  59. package/dist/mcp-claude.js +4 -5
  60. package/dist/mcp.cjs +13 -7
  61. package/dist/mcp.d.cts +6 -5
  62. package/dist/mcp.d.ts +6 -5
  63. package/dist/mcp.js +5 -6
  64. package/dist/{pagination-DqdkQArT.d.cts → pagination-BZDhB_nO.d.cts} +2 -2
  65. package/dist/{pagination-BgEx-HeL.d.ts → pagination-CPz0J_vQ.d.ts} +2 -2
  66. package/dist/{protocols-Bz1rxcUg.d.cts → protocols-CabgO52c.d.cts} +38 -3
  67. package/dist/{protocols-Bwwcql0h.d.ts → protocols-Dpci6uae.d.ts} +38 -3
  68. package/dist/rest.cjs +43 -1
  69. package/dist/rest.d.cts +6 -5
  70. package/dist/rest.d.ts +6 -5
  71. package/dist/rest.js +6 -5
  72. package/dist/runtime.cjs +2113 -597
  73. package/dist/runtime.d.cts +44 -25
  74. package/dist/runtime.d.ts +44 -25
  75. package/dist/runtime.js +11 -11
  76. package/dist/{schemas-BgJhlqqO.d.cts → schemas-BKnh4fKR.d.cts} +209 -24
  77. package/dist/{schemas-C4mK1WSs.d.ts → schemas-CDa3V_I5.d.ts} +209 -24
  78. package/dist/{sdk-BTciSLRQ.d.cts → sdk-CXNqzoY1.d.cts} +1 -1
  79. package/dist/{sdk-qKJtMma_.d.ts → sdk-Cin80BTC.d.ts} +1 -1
  80. package/dist/{simpleAdapter-BpT4XbZC.d.cts → simpleAdapter-D75rcz9n.d.cts} +3 -1
  81. package/dist/{simpleAdapter--wznuoOw.d.ts → simpleAdapter-eLvsAQNo.d.ts} +3 -1
  82. package/dist/testing.cjs +25 -7
  83. package/dist/testing.d.cts +5 -3
  84. package/dist/testing.d.ts +5 -3
  85. package/dist/testing.js +9 -6
  86. package/dist/{types-BivGO7I9.d.ts → types-42-HWeX8.d.cts} +10 -4
  87. package/dist/types-CKU1N0SK.d.ts +137 -0
  88. package/dist/{types-BgYFd_Yw.d.cts → types-CjxZekMH.d.ts} +10 -4
  89. package/dist/types-DtcOLALn.d.cts +137 -0
  90. package/package.json +25 -26
  91. package/dist/acp-server-CiUqN3G3.d.ts +0 -24
  92. package/dist/acp-server-Dlj7D563.d.cts +0 -24
  93. package/dist/chunk-AVVDPXP4.js +0 -39
  94. package/dist/chunk-F63TPOI3.js +0 -29
  95. package/dist/chunk-V5TSWS7P.js +0 -62
  96. package/dist/types-BNNtOXu3.d.cts +0 -446
  97. package/dist/types-DFUtpxah.d.ts +0 -446
@@ -4,11 +4,11 @@ import {
4
4
  MEMORY_TOOL_NAMES,
5
5
  TOOL_MODELS,
6
6
  getToolDescription
7
- } from "./chunk-MQY74R7D.js";
7
+ } from "./chunk-SHZBLLDQ.js";
8
8
  import {
9
9
  isToolExecutorError,
10
10
  toLegacyToolExecutorErrorMessage
11
- } from "./chunk-JADCAMZY.js";
11
+ } from "./chunk-TGDDFBYS.js";
12
12
 
13
13
  // src/mcp/registrations.ts
14
14
  function buildRoomScopedRegistrations(resolver, options = {}) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toLegacyToolExecutorErrorMessage
3
- } from "./chunk-JADCAMZY.js";
3
+ } from "./chunk-TGDDFBYS.js";
4
4
 
5
5
  // src/adapters/shared/coercion.ts
6
6
  function asOptionalRecord(value) {
@@ -43,7 +43,8 @@ function toDisplayText(value) {
43
43
  return "";
44
44
  }
45
45
  try {
46
- return JSON.stringify(value);
46
+ const json = JSON.stringify(value);
47
+ return typeof json === "string" ? json : String(value);
47
48
  } catch {
48
49
  return String(value);
49
50
  }
@@ -63,12 +64,6 @@ function toWireString(value) {
63
64
  return String(value);
64
65
  }
65
66
  }
66
- function asErrorMessage(error) {
67
- if (error instanceof Error) {
68
- return error.message;
69
- }
70
- return String(error);
71
- }
72
67
 
73
68
  export {
74
69
  asOptionalRecord,
@@ -77,6 +72,5 @@ export {
77
72
  asString,
78
73
  asNullableString,
79
74
  toDisplayText,
80
- toWireString,
81
- asErrorMessage
75
+ toWireString
82
76
  };
@@ -0,0 +1,119 @@
1
+ import {
2
+ asErrorMessage
3
+ } from "./chunk-6BE2EG5P.js";
4
+ import {
5
+ RecoverableTurnError
6
+ } from "./chunk-4OVNFDD7.js";
7
+
8
+ // src/core/simpleAdapter.ts
9
+ var SimpleAdapter = class {
10
+ historyConverter;
11
+ agentName = "";
12
+ agentDescription = "";
13
+ constructor(options) {
14
+ this.historyConverter = options?.historyConverter;
15
+ }
16
+ async onCleanup(_roomId) {
17
+ }
18
+ async onStarted(agentName, agentDescription) {
19
+ this.agentName = agentName;
20
+ this.agentDescription = agentDescription;
21
+ }
22
+ async onEvent(input) {
23
+ const history = this.convertHistory(input.history);
24
+ await this.onMessage(
25
+ input.message,
26
+ input.tools,
27
+ history,
28
+ input.participantsMessage,
29
+ input.contactsMessage,
30
+ {
31
+ isSessionBootstrap: input.isSessionBootstrap,
32
+ roomId: input.roomId
33
+ }
34
+ );
35
+ }
36
+ convertHistory(provider) {
37
+ if (!this.historyConverter) {
38
+ return provider;
39
+ }
40
+ return provider.convert(this.historyConverter);
41
+ }
42
+ };
43
+
44
+ // src/core/deliveryFailedError.ts
45
+ var DeliveryFailedError = class extends RecoverableTurnError {
46
+ constructor(cause) {
47
+ super(asErrorMessage(cause), cause);
48
+ this.cause = cause;
49
+ this.name = "DeliveryFailedError";
50
+ }
51
+ };
52
+ async function deliverReply(tools, content, mentions = []) {
53
+ try {
54
+ return await tools.sendMessage(content, mentions);
55
+ } catch (error) {
56
+ throw new DeliveryFailedError(error);
57
+ }
58
+ }
59
+
60
+ // src/core/providerFailure.ts
61
+ import { AgentFailure } from "@band-ai/band-sdk-core";
62
+ var FAILURE_CODE_TIMEOUT = "timeout";
63
+ var ProviderTurnFailedError = class extends RecoverableTurnError {
64
+ constructor(failure) {
65
+ super(failure.message);
66
+ this.failure = failure;
67
+ this.name = "ProviderTurnFailedError";
68
+ }
69
+ };
70
+ async function trySendFailure(tools, failure, logger, logContext) {
71
+ logger?.warn("provider_failure.reported", {
72
+ provider: failure.provider,
73
+ code: failure.code,
74
+ ...logContext
75
+ });
76
+ try {
77
+ await tools.sendFailure(failure);
78
+ } catch (error) {
79
+ logger?.warn("provider_failure.report_failed", {
80
+ provider: failure.provider,
81
+ code: failure.code,
82
+ ...logContext,
83
+ error
84
+ });
85
+ }
86
+ }
87
+ async function reportTurnFailure(tools, failure, logger, logContext) {
88
+ await trySendFailure(tools, failure, logger, logContext);
89
+ throw new ProviderTurnFailedError(failure);
90
+ }
91
+ async function reportProviderTurnFailure(tools, logger, provider, logLabel, error, logContext) {
92
+ logger.error(logLabel, { ...logContext, error });
93
+ return reportTurnFailure(tools, agentFailure(provider, asErrorMessage(error)), logger, logContext);
94
+ }
95
+ async function safeSendFailure(tools, failure, logger, logContext) {
96
+ await trySendFailure(tools, failure, logger, logContext);
97
+ }
98
+ function agentFailure(provider, message, code, detail) {
99
+ if (detail === void 0) {
100
+ return new AgentFailure(provider, message, code);
101
+ }
102
+ try {
103
+ return new AgentFailure(provider, message, code, detail);
104
+ } catch {
105
+ return new AgentFailure(provider, message, code);
106
+ }
107
+ }
108
+
109
+ export {
110
+ SimpleAdapter,
111
+ DeliveryFailedError,
112
+ deliverReply,
113
+ FAILURE_CODE_TIMEOUT,
114
+ ProviderTurnFailedError,
115
+ reportTurnFailure,
116
+ reportProviderTurnFailure,
117
+ safeSendFailure,
118
+ agentFailure
119
+ };
@@ -2,14 +2,14 @@ import {
2
2
  asNullableString,
3
3
  asOptionalRecord,
4
4
  asString
5
- } from "./chunk-KXJ74J73.js";
5
+ } from "./chunk-JIZE4EC6.js";
6
6
  import {
7
- NoopLogger
8
- } from "./chunk-OD2G5LFQ.js";
7
+ resolveLogger
8
+ } from "./chunk-ZYOXI4JL.js";
9
9
  import {
10
10
  UnsupportedFeatureError,
11
11
  ValidationError
12
- } from "./chunk-JY75VSQK.js";
12
+ } from "./chunk-4OVNFDD7.js";
13
13
 
14
14
  // src/client/rest/pagination.ts
15
15
  var DEFAULT_PAGE_SIZE = 100;
@@ -802,7 +802,7 @@ var RestFacade = class {
802
802
  logger;
803
803
  constructor(options) {
804
804
  this.api = options.api;
805
- this.logger = options.logger ?? new NoopLogger();
805
+ this.logger = resolveLogger(options.logger);
806
806
  }
807
807
  async getAgentMe(options) {
808
808
  return this.forward("getAgentMe", () => this.api.getAgentMe(options));
@@ -5,7 +5,7 @@ import {
5
5
  MEMORY_SYSTEM_TYPES,
6
6
  MEMORY_TYPE,
7
7
  TOOL_MODELS
8
- } from "./chunk-MQY74R7D.js";
8
+ } from "./chunk-SHZBLLDQ.js";
9
9
 
10
10
  // src/runtime/prompts/base.ts
11
11
  var ENVIRONMENT_SECTION = `
@@ -105,6 +105,7 @@ function longTermPattern(label, type, segment, scope) {
105
105
  };
106
106
  }
107
107
  var COMMON_MEMORY_PATTERNS = [
108
+ longTermPattern("Private notes for this agent only", MEMORY_TYPE.semantic, MEMORY_SEGMENT.guideline, MEMORY_STORE_SCOPE.agent),
108
109
  longTermPattern("Facts learned about a specific agent/entity", MEMORY_TYPE.semantic, MEMORY_SEGMENT.agent, MEMORY_STORE_SCOPE.subject),
109
110
  longTermPattern("Events involving a specific person/agent", MEMORY_TYPE.episodic, MEMORY_SEGMENT.agent, MEMORY_STORE_SCOPE.subject),
110
111
  longTermPattern("A user's preferences or profile info", MEMORY_TYPE.semantic, MEMORY_SEGMENT.user, MEMORY_STORE_SCOPE.subject),
@@ -117,7 +118,9 @@ var MEMORY_COMMON_PATTERNS = [
117
118
  "Common patterns:",
118
119
  ...COMMON_MEMORY_PATTERNS.map(renderMemoryPattern)
119
120
  ].join("\n");
120
- var MEMORY_SCOPE_GUIDANCE = `Prefer \`scope="${MEMORY_STORE_SCOPE.subject}"\` whenever the memory is about a specific person or agent, so it
121
+ var MEMORY_SCOPE_GUIDANCE = `Use \`scope="${MEMORY_STORE_SCOPE.agent}"\` for information private to this agent that is not about an
122
+ identified subject. Omitting \`scope\` and \`subject_id\` on store defaults to agent scope on the platform.
123
+ Prefer \`scope="${MEMORY_STORE_SCOPE.subject}"\` whenever the memory is about a specific person or agent, so it
121
124
  stays attached to that subject rather than leaking org-wide. Storing with \`scope="${MEMORY_STORE_SCOPE.subject}"\` requires a
122
125
  real \`subject_id\` UUID, so resolve it first via \`band_lookup_peers\` or the participant list.
123
126
  Reserve \`scope="${MEMORY_STORE_SCOPE.organization}"\` for knowledge that is genuinely shared across the whole organization and
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  CHAT_EVENT_TYPES
3
- } from "./chunk-F63TPOI3.js";
3
+ } from "./chunk-TGDDFBYS.js";
4
4
 
5
5
  // src/contracts/memory.ts
6
+ import { validateMemoryTypeForSystem } from "@band-ai/band-sdk-core";
6
7
  var SENSORY_MEMORY_TYPES = [
7
8
  "iconic",
8
9
  // Visual input
@@ -46,18 +47,22 @@ var MEMORY_SEGMENTS = [
46
47
  // Behavioral rules or policies
47
48
  ];
48
49
  var MEMORY_STORE_SCOPES = [
50
+ "agent",
51
+ // Private to the storing agent; omit subject_id
49
52
  "subject",
50
53
  // About one person/agent; requires subject_id
51
54
  "organization"
52
55
  // Shared org-wide
53
56
  ];
54
57
  var MEMORY_LIST_SCOPES = [
58
+ "agent",
59
+ // Caller's private agent-scoped memories only
55
60
  "subject",
56
61
  // Subject-scoped memories only
57
62
  "organization",
58
63
  // Organization-scoped memories only
59
64
  "all"
60
- // Both scopes (no scope filter)
65
+ // All scopes (no scope filter)
61
66
  ];
62
67
  var MEMORY_STATUSES = [
63
68
  "active",
@@ -80,7 +85,15 @@ function isMemoryType(value) {
80
85
  return MEMORY_TYPES.includes(value);
81
86
  }
82
87
  function isMemoryTypeForSystem(system, type) {
83
- return MEMORY_SYSTEM_TYPES[system].includes(type);
88
+ try {
89
+ validateMemoryTypeForSystem(system, type);
90
+ return true;
91
+ } catch (err) {
92
+ if (err instanceof Error && "issues" in err) {
93
+ return false;
94
+ }
95
+ throw err;
96
+ }
84
97
  }
85
98
  function isMemorySegment(value) {
86
99
  return MEMORY_SEGMENTS.includes(value);
@@ -283,7 +296,7 @@ var TOOL_MODELS = {
283
296
  required: ["action"]
284
297
  },
285
298
  band_list_memories: {
286
- description: "List memories accessible to the agent. Returns memories about the specified subject (cross-agent sharing) and organization-wide shared memories.",
299
+ description: `List memories accessible to the agent. Use scope="agent" for the caller's private memories, scope="subject" for memories about a specific person or agent, and scope="organization" for org-wide shared memories. Omit scope or use scope="all" to search across scopes.`,
287
300
  properties: {
288
301
  subject_id: {
289
302
  type: "string",
@@ -292,7 +305,7 @@ var TOOL_MODELS = {
292
305
  scope: {
293
306
  type: "string",
294
307
  enum: [...MEMORY_LIST_SCOPES],
295
- description: "Filter by scope."
308
+ description: `Filter by scope. "agent" returns the caller's private memories; "subject" and "organization" filter to those audiences; "all" omits the filter.`
296
309
  },
297
310
  system: {
298
311
  type: "string",
@@ -328,7 +341,7 @@ var TOOL_MODELS = {
328
341
  required: []
329
342
  },
330
343
  band_store_memory: {
331
- description: "Store a new memory entry. The memory will be associated with the authenticated agent as the source. For subject-scoped memories, provide a subject_id. For organization-scoped memories, omit subject_id.",
344
+ description: 'Store a new memory entry. The memory will be associated with the authenticated agent as the source. Use scope="agent" for information private to this agent (no subject_id). Use scope="subject" with a subject_id for memories about a specific person or agent. Use scope="organization" for knowledge genuinely shared across the organization.',
332
345
  properties: {
333
346
  content: {
334
347
  type: "string",
@@ -356,11 +369,11 @@ var TOOL_MODELS = {
356
369
  scope: {
357
370
  type: "string",
358
371
  enum: [...MEMORY_STORE_SCOPES],
359
- description: "Visibility scope."
372
+ description: 'Visibility scope. "agent" is private to this agent; "subject" requires subject_id; "organization" is shared org-wide.'
360
373
  },
361
374
  subject_id: {
362
375
  type: "string",
363
- description: "UUID of the subject this memory is about (required for subject scope)."
376
+ description: "UUID of the subject this memory is about (required for subject scope; omit for agent scope)."
364
377
  },
365
378
  metadata: {
366
379
  type: "object",
@@ -453,7 +466,6 @@ export {
453
466
  isMemoryListScope,
454
467
  isMemoryStatus,
455
468
  expectedList,
456
- expectedMemoryTypesForSystem,
457
469
  memoryTypeForSystemError,
458
470
  TOOL_MODELS,
459
471
  ALL_TOOL_NAMES,
@@ -1,4 +1,40 @@
1
+ import {
2
+ ValidationError
3
+ } from "./chunk-4OVNFDD7.js";
4
+
5
+ // src/contracts/chatEvents.ts
6
+ var CHAT_EVENT_TYPES = ["tool_call", "tool_result", "thought", "error", "task"];
7
+ var CHAT_MESSAGE_TYPES = ["text", ...CHAT_EVENT_TYPES];
8
+ function isChatEventType(value) {
9
+ return CHAT_EVENT_TYPES.includes(value);
10
+ }
11
+ function assertChatEventType(value) {
12
+ if (!isChatEventType(value)) {
13
+ throw new ValidationError(
14
+ `Invalid event message_type '${value}'. Expected one of: ${CHAT_EVENT_TYPES.join(", ")}`
15
+ );
16
+ }
17
+ }
18
+ var VISIBLE_CONTENT_PATTERN = /[\p{L}\p{N}\p{P}\p{S}]/u;
19
+ function isBlankEventContent(content) {
20
+ return !VISIBLE_CONTENT_PATTERN.test(content);
21
+ }
22
+
1
23
  // src/contracts/protocols.ts
24
+ var FAILURE_EVENT_TYPE = "error";
25
+ var FAILURE_METADATA_KEY = "failure";
26
+ function sendFailureViaEvent(sendEvent, failure) {
27
+ const { content, messageType, metadata } = toFailureEvent(failure);
28
+ return sendEvent(content, messageType, metadata);
29
+ }
30
+ function toFailureEvent(failure) {
31
+ const content = isBlankEventContent(failure.message) ? `${failure.provider} failed without an error message.` : failure.message;
32
+ return {
33
+ content,
34
+ messageType: FAILURE_EVENT_TYPE,
35
+ metadata: { [FAILURE_METADATA_KEY]: failure.toObject() }
36
+ };
37
+ }
2
38
  var TOOL_EXECUTOR_ERROR_TYPES = [
3
39
  "ToolArgumentsValidationError",
4
40
  "ToolNotFoundError",
@@ -44,6 +80,15 @@ var DEFAULT_AGENT_TOOLS_CAPABILITIES = {
44
80
  };
45
81
 
46
82
  export {
83
+ CHAT_EVENT_TYPES,
84
+ CHAT_MESSAGE_TYPES,
85
+ isChatEventType,
86
+ assertChatEventType,
87
+ isBlankEventContent,
88
+ FAILURE_EVENT_TYPE,
89
+ FAILURE_METADATA_KEY,
90
+ sendFailureViaEvent,
91
+ toFailureEvent,
47
92
  createToolExecutorError,
48
93
  isToolExecutorError,
49
94
  isStructuredToolFailure,
@@ -1,5 +1,6 @@
1
1
  // src/platform/streaming/disconnectReason.ts
2
2
  import { z } from "zod";
3
+ import { validateEventPayload } from "@band-ai/band-sdk-core";
3
4
  var UPGRADE_CODES = [
4
5
  "invalid_on_conflict",
5
6
  "connection_conflict",
@@ -50,7 +51,7 @@ var upgradeErrorSchema = z.object({
50
51
  })
51
52
  })
52
53
  ),
53
- headers: z.record(z.unknown()).optional()
54
+ headers: z.record(z.string(), z.unknown()).optional()
54
55
  });
55
56
  var WebSocketDisconnectError = class extends Error {
56
57
  reason;
@@ -61,18 +62,20 @@ var WebSocketDisconnectError = class extends Error {
61
62
  }
62
63
  };
63
64
  function parseSupersedeDisconnectReason(payload) {
64
- if (typeof payload.reason !== "string" || typeof payload.message !== "string") {
65
+ try {
66
+ const normalized = validateEventPayload("supersede", payload);
67
+ return {
68
+ source: "agent_control",
69
+ code: normalized.reason,
70
+ message: normalized.message,
71
+ retryable: normalized.retryable,
72
+ retryAfter: normalized.retry_after ?? null,
73
+ targetSocketId: normalized.target_socket_id ?? null,
74
+ correlationId: normalized.correlation_id
75
+ };
76
+ } catch {
65
77
  return null;
66
78
  }
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
79
  }
77
80
  function parseUpgradeDisconnectReason(event) {
78
81
  const parsed = upgradeErrorSchema.safeParse(event);