@band-ai/sdk 0.1.6 → 0.2.0

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 (85) hide show
  1. package/README.md +372 -0
  2. package/dist/{ClaudeSDKAdapter-CRq4R-WB.d.cts → ClaudeSDKAdapter-BY4zEbCl.d.cts} +14 -10
  3. package/dist/{ClaudeSDKAdapter-BHOkjN3X.d.ts → ClaudeSDKAdapter-Cna5P1dR.d.ts} +14 -10
  4. package/dist/{acp-server-B1Da7L6u.d.ts → acp-server-CiUqN3G3.d.ts} +2 -2
  5. package/dist/{acp-server-BdRz9_UN.d.cts → acp-server-Dlj7D563.d.cts} +2 -2
  6. package/dist/adapters.cjs +734 -279
  7. package/dist/adapters.d.cts +21 -19
  8. package/dist/adapters.d.ts +21 -19
  9. package/dist/adapters.js +65 -44
  10. package/dist/backends-D-dBdDm-.d.ts +27 -0
  11. package/dist/backends-ZLxmQrTZ.d.cts +27 -0
  12. package/dist/{chunk-MSL6CWHY.js → chunk-4IAXZBXX.js} +77 -37
  13. package/dist/{chunk-SG4WLD2H.js → chunk-EAI2M3WM.js} +38 -94
  14. package/dist/{chunk-YR3BOQNW.js → chunk-JY75VSQK.js} +7 -7
  15. package/dist/{chunk-INA6YZTZ.js → chunk-LBWKISBS.js} +51 -31
  16. package/dist/{chunk-I5EZG52P.js → chunk-N2QTUMGO.js} +532 -327
  17. package/dist/{chunk-RHVH2GZR.js → chunk-NMZLX7TP.js} +110 -56
  18. package/dist/{chunk-EDPKUUJL.js → chunk-NT7TBFX2.js} +9 -1
  19. package/dist/{chunk-GVEQ3RAH.js → chunk-RV76SKFT.js} +169 -54
  20. package/dist/{chunk-W5NDZSYE.js → chunk-TLBCKDQO.js} +23 -23
  21. package/dist/chunk-US226AS4.js +130 -0
  22. package/dist/{chunk-IZPV6QS6.js → chunk-WL2HNJZ6.js} +38 -11
  23. package/dist/chunk-WLCM2OXG.js +181 -0
  24. package/dist/config.cjs +40 -13
  25. package/dist/config.d.cts +7 -1
  26. package/dist/config.d.ts +7 -1
  27. package/dist/config.js +2 -2
  28. package/dist/converters.cjs +491 -35
  29. package/dist/converters.d.cts +5 -5
  30. package/dist/converters.d.ts +5 -5
  31. package/dist/converters.js +4 -3
  32. package/dist/core.cjs +53 -10
  33. package/dist/core.d.cts +10 -9
  34. package/dist/core.d.ts +10 -9
  35. package/dist/core.js +8 -4
  36. package/dist/disconnectReason-IuADl6TH.d.cts +34 -0
  37. package/dist/disconnectReason-IuADl6TH.d.ts +34 -0
  38. package/dist/{dtos-DUpbIu8k.d.ts → dtos-B8KU_q4d.d.cts} +26 -6
  39. package/dist/{dtos-DUpbIu8k.d.cts → dtos-B8KU_q4d.d.ts} +26 -6
  40. package/dist/index.cjs +1510 -735
  41. package/dist/index.d.cts +18 -16
  42. package/dist/index.d.ts +18 -16
  43. package/dist/index.js +21 -13
  44. package/dist/linear.cjs +1044 -112
  45. package/dist/linear.d.cts +146 -16
  46. package/dist/linear.d.ts +146 -16
  47. package/dist/linear.js +1031 -110
  48. package/dist/mcp-claude.cjs +338 -66
  49. package/dist/mcp-claude.d.cts +3 -3
  50. package/dist/mcp-claude.d.ts +3 -3
  51. package/dist/mcp-claude.js +215 -16
  52. package/dist/mcp.cjs +414 -105
  53. package/dist/mcp.d.cts +29 -16
  54. package/dist/mcp.d.ts +29 -16
  55. package/dist/mcp.js +14 -14
  56. package/dist/{opencode-BBcDchcN.d.cts → opencode-2YdscIc1.d.cts} +5 -5
  57. package/dist/{opencode-DthQQUsZ.d.ts → opencode-Bld62x5t.d.ts} +5 -5
  58. package/dist/{pagination-CcDkVFxK.d.ts → pagination-BgEx-HeL.d.ts} +2 -2
  59. package/dist/{pagination-BPiys10t.d.cts → pagination-DqdkQArT.d.cts} +2 -2
  60. package/dist/{protocols-DrhzOH6K.d.ts → protocols-Bwwcql0h.d.ts} +1 -1
  61. package/dist/{protocols-CInhtFpA.d.cts → protocols-Bz1rxcUg.d.cts} +1 -1
  62. package/dist/rest.cjs +41 -97
  63. package/dist/rest.d.cts +7 -7
  64. package/dist/rest.d.ts +7 -7
  65. package/dist/rest.js +2 -2
  66. package/dist/runtime.cjs +998 -620
  67. package/dist/runtime.d.cts +22 -29
  68. package/dist/runtime.d.ts +22 -29
  69. package/dist/runtime.js +19 -67
  70. package/dist/{schemas-BpEBkq5V.d.cts → schemas-BotL3ZLH.d.cts} +51 -56
  71. package/dist/{schemas-vos1AaBc.d.ts → schemas-DBsC4J1g.d.ts} +51 -56
  72. package/dist/{sdk-CwTAxhwI.d.cts → sdk-BTciSLRQ.d.cts} +35 -5
  73. package/dist/{sdk-CcnQ5OUC.d.ts → sdk-qKJtMma_.d.ts} +35 -5
  74. package/dist/{simpleAdapter-9OE_p6QW.d.ts → simpleAdapter--wznuoOw.d.ts} +1 -1
  75. package/dist/{simpleAdapter-DqhvjsGr.d.cts → simpleAdapter-BpT4XbZC.d.cts} +1 -1
  76. package/dist/testing.d.cts +3 -3
  77. package/dist/testing.d.ts +3 -3
  78. package/dist/{types-7jVzOeOP.d.ts → types-BTN_ZETM.d.ts} +2 -2
  79. package/dist/{types-CxII3XkA.d.ts → types-BgYFd_Yw.d.cts} +5 -5
  80. package/dist/{types-CSHFipIc.d.cts → types-BivGO7I9.d.ts} +5 -5
  81. package/dist/{types-CovcHpYf.d.cts → types-D958TC71.d.cts} +2 -2
  82. package/package.json +25 -23
  83. package/dist/backends-CzDbiQar.d.ts +0 -20
  84. package/dist/backends-SVMT-7l4.d.cts +0 -20
  85. package/dist/chunk-SFVKOEQH.js +0 -103
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/mcp/sdk.ts
21
21
  var sdk_exports = {};
22
22
  __export(sdk_exports, {
23
- createThenvoiSdkMcpServer: () => createThenvoiSdkMcpServer
23
+ createBandSdkMcpServer: () => createBandSdkMcpServer
24
24
  });
25
25
  module.exports = __toCommonJS(sdk_exports);
26
26
  var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
@@ -30,9 +30,81 @@ var import_zod = require("zod");
30
30
  var CHAT_EVENT_TYPES = ["tool_call", "tool_result", "thought", "error", "task"];
31
31
  var CHAT_MESSAGE_TYPES = ["text", ...CHAT_EVENT_TYPES];
32
32
 
33
+ // src/contracts/memory.ts
34
+ var SENSORY_MEMORY_TYPES = [
35
+ "iconic",
36
+ // Visual input
37
+ "echoic",
38
+ // Auditory input
39
+ "haptic"
40
+ // Tactile input
41
+ ];
42
+ var COGNITIVE_MEMORY_TYPES = [
43
+ "episodic",
44
+ // Events that occurred
45
+ "semantic",
46
+ // Facts, preferences, learned knowledge
47
+ "procedural"
48
+ // How to perform tasks
49
+ ];
50
+ function namedValues(values) {
51
+ return Object.fromEntries(values.map((value) => [value, value]));
52
+ }
53
+ var MEMORY_SYSTEM_TYPES = {
54
+ sensory: SENSORY_MEMORY_TYPES,
55
+ // Brief sensory inputs
56
+ working: COGNITIVE_MEMORY_TYPES,
57
+ // Short-term session context
58
+ long_term: COGNITIVE_MEMORY_TYPES
59
+ // Persistent cross-conversation memory
60
+ };
61
+ var MEMORY_SYSTEMS = Object.keys(MEMORY_SYSTEM_TYPES);
62
+ var MEMORY_TYPES = [
63
+ ...SENSORY_MEMORY_TYPES,
64
+ ...COGNITIVE_MEMORY_TYPES
65
+ ];
66
+ var MEMORY_SEGMENTS = [
67
+ "user",
68
+ // User preferences or profile info
69
+ "agent",
70
+ // Facts or events about agents/entities
71
+ "tool",
72
+ // Tool usage or task procedures
73
+ "guideline"
74
+ // Behavioral rules or policies
75
+ ];
76
+ var MEMORY_STORE_SCOPES = [
77
+ "subject",
78
+ // About one person/agent; requires subject_id
79
+ "organization"
80
+ // Shared org-wide
81
+ ];
82
+ var MEMORY_LIST_SCOPES = [
83
+ "subject",
84
+ // Subject-scoped memories only
85
+ "organization",
86
+ // Organization-scoped memories only
87
+ "all"
88
+ // Both scopes (no scope filter)
89
+ ];
90
+ var MEMORY_STATUSES = [
91
+ "active",
92
+ // Normal, visible memories
93
+ "superseded",
94
+ // Outdated; soft-deleted via band_supersede_memory
95
+ "archived",
96
+ // Hidden but preserved via band_archive_memory
97
+ "all"
98
+ // Any status (no filter)
99
+ ];
100
+ var MEMORY_SYSTEM = namedValues(MEMORY_SYSTEMS);
101
+ var MEMORY_TYPE = namedValues(MEMORY_TYPES);
102
+ var MEMORY_SEGMENT = namedValues(MEMORY_SEGMENTS);
103
+ var MEMORY_STORE_SCOPE = namedValues(MEMORY_STORE_SCOPES);
104
+
33
105
  // src/runtime/tools/schemas.ts
34
106
  var TOOL_MODELS = {
35
- thenvoi_send_message: {
107
+ band_send_message: {
36
108
  description: "Send a message to the chat room. Use this to respond to users or other agents. Messages require at least one @mention in the mentions array. You MUST use this tool to communicate \u2014 plain text responses won't reach users. When delegating, send the full task context in this message instead of assuming hidden state.",
37
109
  properties: {
38
110
  content: {
@@ -48,7 +120,7 @@ var TOOL_MODELS = {
48
120
  },
49
121
  required: ["content", "mentions"]
50
122
  },
51
- thenvoi_send_event: {
123
+ band_send_event: {
52
124
  description: "Send an event to the chat room. No mentions required. 'thought': Share your reasoning or plan BEFORE taking actions. Explain what you're about to do and why. 'error': Report an error or problem that occurred. 'task': Report task progress or completion status. Always send a thought before complex actions to keep users informed.",
53
125
  properties: {
54
126
  content: {
@@ -67,12 +139,12 @@ var TOOL_MODELS = {
67
139
  },
68
140
  required: ["content", "message_type"]
69
141
  },
70
- thenvoi_add_participant: {
71
- description: "Add a participant (agent or user) to the chat room by name. IMPORTANT: Use thenvoi_lookup_peers() first to find available agents. Pass the exact peer name from thenvoi_lookup_peers, not the handle. For normal delegation, omit role or use 'member'.",
142
+ band_add_participant: {
143
+ description: "Add a participant (agent or user) to the chat room by name. IMPORTANT: Use band_lookup_peers() first to find available agents. Pass the exact peer name from band_lookup_peers, not the handle. For normal delegation, omit role or use 'member'.",
72
144
  properties: {
73
145
  name: {
74
146
  type: "string",
75
- description: "Name of participant to add (must match a name from thenvoi_lookup_peers)."
147
+ description: "Name of participant to add (must match a name from band_lookup_peers)."
76
148
  },
77
149
  role: {
78
150
  type: "string",
@@ -82,7 +154,7 @@ var TOOL_MODELS = {
82
154
  },
83
155
  required: ["name"]
84
156
  },
85
- thenvoi_remove_participant: {
157
+ band_remove_participant: {
86
158
  description: "Remove a participant from the chat room by name.",
87
159
  properties: {
88
160
  name: {
@@ -92,12 +164,12 @@ var TOOL_MODELS = {
92
164
  },
93
165
  required: ["name"]
94
166
  },
95
- thenvoi_get_participants: {
167
+ band_get_participants: {
96
168
  description: "Get a list of all participants in the current chat room.",
97
169
  properties: {},
98
170
  required: []
99
171
  },
100
- thenvoi_lookup_peers: {
172
+ band_lookup_peers: {
101
173
  description: "List available peers (agents and users) that can be added to this room. Automatically excludes peers already in the room. Returns dict with 'peers' list and 'metadata' (page, page_size, total_count, total_pages). Use this to find specialized agents (e.g., Weather Agent) when you cannot answer a question directly.",
102
174
  properties: {
103
175
  page: {
@@ -112,7 +184,7 @@ var TOOL_MODELS = {
112
184
  },
113
185
  required: []
114
186
  },
115
- thenvoi_create_chatroom: {
187
+ band_create_chatroom: {
116
188
  description: "Create a new chat room for a specific task or conversation.",
117
189
  properties: {
118
190
  task_id: {
@@ -122,7 +194,7 @@ var TOOL_MODELS = {
122
194
  },
123
195
  required: []
124
196
  },
125
- thenvoi_list_contacts: {
197
+ band_list_contacts: {
126
198
  description: "List agent's contacts with pagination.",
127
199
  properties: {
128
200
  page: {
@@ -139,7 +211,7 @@ var TOOL_MODELS = {
139
211
  },
140
212
  required: []
141
213
  },
142
- thenvoi_add_contact: {
214
+ band_add_contact: {
143
215
  description: "Send a contact request to add someone as a contact. Returns 'pending' when request is created. Returns 'approved' when inverse request existed and was auto-accepted.",
144
216
  properties: {
145
217
  handle: {
@@ -153,7 +225,7 @@ var TOOL_MODELS = {
153
225
  },
154
226
  required: ["handle"]
155
227
  },
156
- thenvoi_remove_contact: {
228
+ band_remove_contact: {
157
229
  description: "Remove an existing contact by handle or ID.",
158
230
  properties: {
159
231
  handle: {
@@ -167,7 +239,7 @@ var TOOL_MODELS = {
167
239
  },
168
240
  required: []
169
241
  },
170
- thenvoi_list_contact_requests: {
242
+ band_list_contact_requests: {
171
243
  description: "List both received and sent contact requests. Received requests are always filtered to pending status. Sent requests can be filtered by status.",
172
244
  properties: {
173
245
  page: {
@@ -189,7 +261,7 @@ var TOOL_MODELS = {
189
261
  },
190
262
  required: []
191
263
  },
192
- thenvoi_respond_contact_request: {
264
+ band_respond_contact_request: {
193
265
  description: "Respond to a contact request. 'approve'/'reject': For requests you RECEIVED (handle = requester's handle). 'cancel': For requests you SENT (handle = recipient's handle).",
194
266
  properties: {
195
267
  action: {
@@ -208,7 +280,7 @@ var TOOL_MODELS = {
208
280
  },
209
281
  required: ["action"]
210
282
  },
211
- thenvoi_list_memories: {
283
+ band_list_memories: {
212
284
  description: "List memories accessible to the agent. Returns memories about the specified subject (cross-agent sharing) and organization-wide shared memories.",
213
285
  properties: {
214
286
  subject_id: {
@@ -217,29 +289,22 @@ var TOOL_MODELS = {
217
289
  },
218
290
  scope: {
219
291
  type: "string",
220
- enum: ["subject", "organization", "all"],
292
+ enum: [...MEMORY_LIST_SCOPES],
221
293
  description: "Filter by scope."
222
294
  },
223
295
  system: {
224
296
  type: "string",
225
- enum: ["sensory", "working", "long_term"],
297
+ enum: [...MEMORY_SYSTEMS],
226
298
  description: "Filter by memory system."
227
299
  },
228
300
  type: {
229
301
  type: "string",
230
- enum: [
231
- "iconic",
232
- "echoic",
233
- "haptic",
234
- "episodic",
235
- "semantic",
236
- "procedural"
237
- ],
302
+ enum: [...MEMORY_TYPES],
238
303
  description: "Filter by memory type."
239
304
  },
240
305
  segment: {
241
306
  type: "string",
242
- enum: ["user", "agent", "tool", "guideline"],
307
+ enum: [...MEMORY_SEGMENTS],
243
308
  description: "Filter by segment."
244
309
  },
245
310
  content_query: {
@@ -254,13 +319,13 @@ var TOOL_MODELS = {
254
319
  },
255
320
  status: {
256
321
  type: "string",
257
- enum: ["active", "superseded", "archived", "all"],
322
+ enum: [...MEMORY_STATUSES],
258
323
  description: "Filter by status."
259
324
  }
260
325
  },
261
326
  required: []
262
327
  },
263
- thenvoi_store_memory: {
328
+ band_store_memory: {
264
329
  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.",
265
330
  properties: {
266
331
  content: {
@@ -269,24 +334,17 @@ var TOOL_MODELS = {
269
334
  },
270
335
  system: {
271
336
  type: "string",
272
- enum: ["sensory", "working", "long_term"],
337
+ enum: [...MEMORY_SYSTEMS],
273
338
  description: "Memory system tier."
274
339
  },
275
340
  type: {
276
341
  type: "string",
277
- enum: [
278
- "iconic",
279
- "echoic",
280
- "haptic",
281
- "episodic",
282
- "semantic",
283
- "procedural"
284
- ],
342
+ enum: [...MEMORY_TYPES],
285
343
  description: "Memory type (must be valid for selected system)."
286
344
  },
287
345
  segment: {
288
346
  type: "string",
289
- enum: ["user", "agent", "tool", "guideline"],
347
+ enum: [...MEMORY_SEGMENTS],
290
348
  description: "Logical segment."
291
349
  },
292
350
  thought: {
@@ -295,7 +353,7 @@ var TOOL_MODELS = {
295
353
  },
296
354
  scope: {
297
355
  type: "string",
298
- enum: ["subject", "organization"],
356
+ enum: [...MEMORY_STORE_SCOPES],
299
357
  description: "Visibility scope."
300
358
  },
301
359
  subject_id: {
@@ -309,7 +367,7 @@ var TOOL_MODELS = {
309
367
  },
310
368
  required: ["content", "system", "type", "segment", "thought"]
311
369
  },
312
- thenvoi_get_memory: {
370
+ band_get_memory: {
313
371
  description: "Retrieve a specific memory by ID.",
314
372
  properties: {
315
373
  memory_id: {
@@ -319,7 +377,7 @@ var TOOL_MODELS = {
319
377
  },
320
378
  required: ["memory_id"]
321
379
  },
322
- thenvoi_supersede_memory: {
380
+ band_supersede_memory: {
323
381
  description: "Mark a memory as superseded (soft delete). Use when information is outdated or incorrect. The memory remains for audit trail but won't appear in normal queries. Only the source agent can supersede.",
324
382
  properties: {
325
383
  memory_id: {
@@ -329,7 +387,7 @@ var TOOL_MODELS = {
329
387
  },
330
388
  required: ["memory_id"]
331
389
  },
332
- thenvoi_archive_memory: {
390
+ band_archive_memory: {
333
391
  description: "Archive a memory (hide but preserve). Use when memory is valid but not currently needed. Archived memories can be restored later by humans. Only the source agent can archive.",
334
392
  properties: {
335
393
  memory_id: {
@@ -342,18 +400,18 @@ var TOOL_MODELS = {
342
400
  };
343
401
  var ALL_TOOL_NAMES = new Set(Object.keys(TOOL_MODELS));
344
402
  var MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
345
- "thenvoi_list_memories",
346
- "thenvoi_store_memory",
347
- "thenvoi_get_memory",
348
- "thenvoi_supersede_memory",
349
- "thenvoi_archive_memory"
403
+ "band_list_memories",
404
+ "band_store_memory",
405
+ "band_get_memory",
406
+ "band_supersede_memory",
407
+ "band_archive_memory"
350
408
  ]);
351
409
  var CONTACT_TOOL_NAMES = /* @__PURE__ */ new Set([
352
- "thenvoi_list_contacts",
353
- "thenvoi_add_contact",
354
- "thenvoi_remove_contact",
355
- "thenvoi_list_contact_requests",
356
- "thenvoi_respond_contact_request"
410
+ "band_list_contacts",
411
+ "band_add_contact",
412
+ "band_remove_contact",
413
+ "band_list_contact_requests",
414
+ "band_respond_contact_request"
357
415
  ]);
358
416
  var BASE_TOOL_NAMES = new Set(
359
417
  [...ALL_TOOL_NAMES].filter((name) => !MEMORY_TOOL_NAMES.has(name))
@@ -361,7 +419,8 @@ var BASE_TOOL_NAMES = new Set(
361
419
  var CHAT_TOOL_NAMES = new Set(
362
420
  [...BASE_TOOL_NAMES].filter((name) => !CONTACT_TOOL_NAMES.has(name))
363
421
  );
364
- var MCP_TOOL_PREFIX = "mcp__thenvoi__";
422
+ var MCP_TOOL_PREFIX = "mcp__band__";
423
+ var MCP_SERVER_NAME = "band";
365
424
  function mcpToolNames(names) {
366
425
  return [...names].sort((a, b) => a.localeCompare(b)).map((name) => `${MCP_TOOL_PREFIX}${name}`);
367
426
  }
@@ -414,6 +473,16 @@ function buildRoomScopedRegistrations(resolver, options = {}) {
414
473
  }
415
474
  return registrations;
416
475
  }
476
+ function buildSingleContextRegistrations(tools, options = {}) {
477
+ const toolNames = resolveToolNames(options);
478
+ const registrations = buildRegistrations(toolNames, (_toolName, args) => {
479
+ return executeToolCall(tools, _toolName, args);
480
+ }, { injectRoomId: false });
481
+ if (options.additionalTools) {
482
+ registrations.push(...options.additionalTools);
483
+ }
484
+ return registrations;
485
+ }
417
486
  function resolveToolNames(options) {
418
487
  const names = /* @__PURE__ */ new Set();
419
488
  for (const name of BASE_TOOL_NAMES) {
@@ -501,6 +570,13 @@ function serializeValue(value) {
501
570
  return String(value);
502
571
  }
503
572
  }
573
+ function resolveSingleRoomTools(getToolsForRoom) {
574
+ const tools = getToolsForRoom("");
575
+ if (!tools) {
576
+ throw new Error('Single-room mode requires getToolsForRoom("") to return a tools instance');
577
+ }
578
+ return tools;
579
+ }
504
580
 
505
581
  // src/mcp/zod.ts
506
582
  function buildZodShape(z2, properties, required) {
@@ -542,27 +618,223 @@ function jsonSchemaToZod(z2, schema) {
542
618
  }
543
619
 
544
620
  // src/mcp/sdk.ts
545
- function createThenvoiSdkMcpServer(options) {
546
- const registrations = buildRoomScopedRegistrations(
547
- options.getToolsForRoom,
548
- {
549
- enableMemoryTools: options.enableMemoryTools,
550
- enableContactTools: true,
551
- additionalTools: options.additionalTools
552
- }
553
- );
621
+ function createBandSdkMcpServer(options) {
622
+ const registrationOptions = {
623
+ enableMemoryTools: options.enableMemoryTools,
624
+ enableContactTools: true,
625
+ additionalTools: options.additionalTools
626
+ };
627
+ const registrations = options.multiRoom === false ? buildSingleContextRegistrations(resolveSingleRoomTools(options.getToolsForRoom), registrationOptions) : buildRoomScopedRegistrations(options.getToolsForRoom, registrationOptions);
554
628
  const toolDefinitions = registrations.map(toSdkToolDefinition);
555
629
  const toolNames = new Set(registrations.map((r) => r.name));
630
+ const contextCache = /* @__PURE__ */ new Map();
631
+ const MAX_CONTEXT_CACHE_ENTRIES = 100;
556
632
  const serverConfig = (0, import_claude_agent_sdk.createSdkMcpServer)({
557
- name: "thenvoi",
633
+ name: MCP_SERVER_NAME,
558
634
  tools: toolDefinitions
559
635
  });
560
636
  return {
561
637
  serverConfig,
562
638
  allowedTools: mcpToolNames(toolNames),
563
- toolDefinitions
639
+ toolDefinitions,
640
+ getSystemPromptContext: async (roomId, contextOptions) => {
641
+ const context = await getOrBuildSystemPromptContext(
642
+ roomId,
643
+ contextOptions,
644
+ options.getToolsForRoom,
645
+ contextCache,
646
+ MAX_CONTEXT_CACHE_ENTRIES
647
+ );
648
+ return context.markdown;
649
+ },
650
+ getSystemPromptContextData: (roomId, contextOptions) => {
651
+ return getOrBuildSystemPromptContext(
652
+ roomId,
653
+ contextOptions,
654
+ options.getToolsForRoom,
655
+ contextCache,
656
+ MAX_CONTEXT_CACHE_ENTRIES
657
+ );
658
+ }
659
+ };
660
+ }
661
+ async function getOrBuildSystemPromptContext(roomId, contextOptions, getToolsForRoom, contextCache, maxEntries) {
662
+ const ttlMs = contextOptions?.ttlMs ?? 3e4;
663
+ const now = Date.now();
664
+ const cached = contextCache.get(roomId);
665
+ if (cached && cached.expiresAt > now) {
666
+ cached.lastAccessedAt = now;
667
+ return cached.value;
668
+ }
669
+ if (cached) {
670
+ contextCache.delete(roomId);
671
+ }
672
+ const tools = getToolsForRoom(roomId);
673
+ if (!tools) {
674
+ return buildUnavailableSystemPromptContext(roomId);
675
+ }
676
+ const context = await buildSystemPromptContext(roomId, tools);
677
+ contextCache.set(roomId, {
678
+ value: context,
679
+ expiresAt: now + ttlMs,
680
+ lastAccessedAt: now
681
+ });
682
+ evictLeastRecentlyUsedContext(contextCache, maxEntries);
683
+ return context;
684
+ }
685
+ async function buildSystemPromptContext(roomId, tools) {
686
+ const participants = await tools.getParticipants();
687
+ const warnings = [];
688
+ const agentResolution = await resolveAgentIdentity(tools);
689
+ if (agentResolution.warning) {
690
+ warnings.push(agentResolution.warning);
691
+ }
692
+ const roomResolution = await resolveRoomTitle(tools, roomId);
693
+ if (roomResolution.warning) {
694
+ warnings.push(roomResolution.warning);
695
+ }
696
+ const agentIdentity = agentResolution.value;
697
+ const roomTitle = roomResolution.value;
698
+ const normalizedParticipants = participants.map((participant) => ({
699
+ id: String(participant.id),
700
+ name: String(participant.name ?? "Unknown"),
701
+ type: String(participant.type ?? "Unknown"),
702
+ handle: normalizeHandle(participant.handle),
703
+ isSelf: participant.id === agentIdentity?.id
704
+ }));
705
+ const selfHandle = normalizeHandle(agentIdentity?.handle);
706
+ const selfName = agentIdentity?.name ?? "Agent";
707
+ const mentionHandles = normalizedParticipants.filter((participant) => !participant.isSelf).map((participant) => participant.handle).filter((handle) => Boolean(handle));
708
+ const mentionFormat = mentionHandles.length > 0 ? mentionHandles.join(", ") : "No participant handles available";
709
+ const roomLabel = roomTitle ? `"${roomTitle}"` : "this room";
710
+ const agentLabel = selfHandle ? `${selfName} (${selfHandle})` : selfName;
711
+ const participantLines = normalizedParticipants.length > 0 ? normalizedParticipants.map((participant) => {
712
+ const suffix = participant.isSelf ? " (you)" : "";
713
+ const handle = participant.handle ? ` (${participant.handle})` : "";
714
+ return `- **${participant.name}**${handle} -- ${participant.type}${suffix}`;
715
+ }).join("\n") : "- No participants found";
716
+ const markdown = [
717
+ "## Room Context",
718
+ "",
719
+ `You are **${agentLabel}** in room ${roomLabel} (id: ${roomId}).`,
720
+ "",
721
+ "### Participants",
722
+ participantLines,
723
+ "",
724
+ "### Mention Format",
725
+ `To address someone, use their exact handle: ${mentionFormat}`,
726
+ ...warnings.length > 0 ? ["", "### Warnings", ...warnings.map((warning) => `- ${warning}`)] : []
727
+ ].join("\n");
728
+ return {
729
+ roomId,
730
+ roomTitle,
731
+ agent: {
732
+ id: agentIdentity?.id ?? "unknown-agent",
733
+ name: selfName,
734
+ handle: selfHandle,
735
+ description: agentIdentity?.description ?? null
736
+ },
737
+ participants: normalizedParticipants,
738
+ mentionFormat,
739
+ warnings,
740
+ markdown
564
741
  };
565
742
  }
743
+ async function resolveAgentIdentity(tools) {
744
+ const maybeTools = tools;
745
+ try {
746
+ if (maybeTools.getAgentIdentity) {
747
+ return { value: await maybeTools.getAgentIdentity(), warning: null };
748
+ }
749
+ if (maybeTools.rest?.getAgentMe) {
750
+ return { value: await maybeTools.rest.getAgentMe(), warning: null };
751
+ }
752
+ } catch (error) {
753
+ return {
754
+ value: null,
755
+ warning: `Unable to resolve agent identity: ${error instanceof Error ? error.message : String(error)}`
756
+ };
757
+ }
758
+ return { value: null, warning: null };
759
+ }
760
+ async function resolveRoomTitle(tools, roomId) {
761
+ const maybeTools = tools;
762
+ const rest = maybeTools.rest;
763
+ if (!rest?.listChats) {
764
+ return { value: null, warning: null };
765
+ }
766
+ try {
767
+ let page = 1;
768
+ const pageSize = 100;
769
+ while (true) {
770
+ const response = await rest.listChats({ page, pageSize });
771
+ const room = response?.data?.find((entry) => entry.id === roomId);
772
+ if (typeof room?.title === "string" && room.title.length > 0) {
773
+ return { value: room.title, warning: null };
774
+ }
775
+ const totalPages = response?.metadata?.totalPages ?? page;
776
+ if (page >= totalPages) {
777
+ return { value: null, warning: null };
778
+ }
779
+ page += 1;
780
+ }
781
+ } catch (error) {
782
+ return {
783
+ value: null,
784
+ warning: `Unable to resolve room title: ${error instanceof Error ? error.message : String(error)}`
785
+ };
786
+ }
787
+ }
788
+ function buildUnavailableSystemPromptContext(roomId) {
789
+ const warnings = [`No tool context found for room_id ${roomId}`];
790
+ const markdown = [
791
+ "## Room Context",
792
+ "",
793
+ `You are **Agent** in this room (id: ${roomId}).`,
794
+ "",
795
+ "### Participants",
796
+ "- No participants found",
797
+ "",
798
+ "### Mention Format",
799
+ "No participant handles available",
800
+ "",
801
+ "### Warnings",
802
+ ...warnings.map((warning) => `- ${warning}`)
803
+ ].join("\n");
804
+ return {
805
+ roomId,
806
+ roomTitle: null,
807
+ agent: {
808
+ id: "unknown-agent",
809
+ name: "Agent",
810
+ handle: null,
811
+ description: null
812
+ },
813
+ participants: [],
814
+ mentionFormat: "No participant handles available",
815
+ warnings,
816
+ markdown
817
+ };
818
+ }
819
+ function evictLeastRecentlyUsedContext(contextCache, maxEntries) {
820
+ if (contextCache.size <= maxEntries) {
821
+ return;
822
+ }
823
+ let oldestKey = null;
824
+ let oldestAccessedAt = Number.POSITIVE_INFINITY;
825
+ for (const [key, entry] of contextCache.entries()) {
826
+ if (entry.lastAccessedAt < oldestAccessedAt) {
827
+ oldestAccessedAt = entry.lastAccessedAt;
828
+ oldestKey = key;
829
+ }
830
+ }
831
+ if (oldestKey) {
832
+ contextCache.delete(oldestKey);
833
+ }
834
+ }
835
+ function normalizeHandle(handle) {
836
+ return typeof handle === "string" && handle.trim().length > 0 ? handle.trim() : null;
837
+ }
566
838
  function toSdkToolDefinition(registration) {
567
839
  const shape = buildZodShape(
568
840
  import_zod.z,
@@ -578,5 +850,5 @@ function toSdkToolDefinition(registration) {
578
850
  }
579
851
  // Annotate the CommonJS export names for ESM import in node:
580
852
  0 && (module.exports = {
581
- createThenvoiSdkMcpServer
853
+ createBandSdkMcpServer
582
854
  });
@@ -1,4 +1,4 @@
1
1
  import '@anthropic-ai/claude-agent-sdk';
2
- import './protocols-CInhtFpA.cjs';
3
- export { C as CreateThenvoiSdkMcpServerOptions, T as ThenvoiSdkMcpServer, f as createThenvoiSdkMcpServer } from './sdk-CwTAxhwI.cjs';
4
- import './dtos-DUpbIu8k.cjs';
2
+ import './protocols-Bz1rxcUg.cjs';
3
+ export { B as BandSdkMcpServer, C as CreateBandSdkMcpServerOptions, G as GetSystemPromptContextOptions, g as GetSystemPromptContextResult, h as createBandSdkMcpServer } from './sdk-BTciSLRQ.cjs';
4
+ import './dtos-B8KU_q4d.cjs';
@@ -1,4 +1,4 @@
1
1
  import '@anthropic-ai/claude-agent-sdk';
2
- import './protocols-DrhzOH6K.js';
3
- export { C as CreateThenvoiSdkMcpServerOptions, T as ThenvoiSdkMcpServer, f as createThenvoiSdkMcpServer } from './sdk-CcnQ5OUC.js';
4
- import './dtos-DUpbIu8k.js';
2
+ import './protocols-Bwwcql0h.js';
3
+ export { B as BandSdkMcpServer, C as CreateBandSdkMcpServerOptions, G as GetSystemPromptContextOptions, g as GetSystemPromptContextResult, h as createBandSdkMcpServer } from './sdk-qKJtMma_.js';
4
+ import './dtos-B8KU_q4d.js';