@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
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  buildRoomScopedRegistrations,
3
- buildZodShape
4
- } from "./chunk-EDPKUUJL.js";
3
+ buildSingleContextRegistrations,
4
+ buildZodShape,
5
+ resolveSingleRoomTools
6
+ } from "./chunk-NT7TBFX2.js";
5
7
  import {
8
+ MCP_SERVER_NAME,
6
9
  mcpToolNames
7
- } from "./chunk-GVEQ3RAH.js";
10
+ } from "./chunk-RV76SKFT.js";
8
11
  import "./chunk-3BKAC4OZ.js";
9
- import "./chunk-YR3BOQNW.js";
12
+ import "./chunk-JY75VSQK.js";
10
13
 
11
14
  // src/mcp/sdk.ts
12
15
  import {
@@ -14,27 +17,223 @@ import {
14
17
  tool
15
18
  } from "@anthropic-ai/claude-agent-sdk";
16
19
  import { z } from "zod";
17
- function createThenvoiSdkMcpServer(options) {
18
- const registrations = buildRoomScopedRegistrations(
19
- options.getToolsForRoom,
20
- {
21
- enableMemoryTools: options.enableMemoryTools,
22
- enableContactTools: true,
23
- additionalTools: options.additionalTools
24
- }
25
- );
20
+ function createBandSdkMcpServer(options) {
21
+ const registrationOptions = {
22
+ enableMemoryTools: options.enableMemoryTools,
23
+ enableContactTools: true,
24
+ additionalTools: options.additionalTools
25
+ };
26
+ const registrations = options.multiRoom === false ? buildSingleContextRegistrations(resolveSingleRoomTools(options.getToolsForRoom), registrationOptions) : buildRoomScopedRegistrations(options.getToolsForRoom, registrationOptions);
26
27
  const toolDefinitions = registrations.map(toSdkToolDefinition);
27
28
  const toolNames = new Set(registrations.map((r) => r.name));
29
+ const contextCache = /* @__PURE__ */ new Map();
30
+ const MAX_CONTEXT_CACHE_ENTRIES = 100;
28
31
  const serverConfig = createSdkMcpServer({
29
- name: "thenvoi",
32
+ name: MCP_SERVER_NAME,
30
33
  tools: toolDefinitions
31
34
  });
32
35
  return {
33
36
  serverConfig,
34
37
  allowedTools: mcpToolNames(toolNames),
35
- toolDefinitions
38
+ toolDefinitions,
39
+ getSystemPromptContext: async (roomId, contextOptions) => {
40
+ const context = await getOrBuildSystemPromptContext(
41
+ roomId,
42
+ contextOptions,
43
+ options.getToolsForRoom,
44
+ contextCache,
45
+ MAX_CONTEXT_CACHE_ENTRIES
46
+ );
47
+ return context.markdown;
48
+ },
49
+ getSystemPromptContextData: (roomId, contextOptions) => {
50
+ return getOrBuildSystemPromptContext(
51
+ roomId,
52
+ contextOptions,
53
+ options.getToolsForRoom,
54
+ contextCache,
55
+ MAX_CONTEXT_CACHE_ENTRIES
56
+ );
57
+ }
58
+ };
59
+ }
60
+ async function getOrBuildSystemPromptContext(roomId, contextOptions, getToolsForRoom, contextCache, maxEntries) {
61
+ const ttlMs = contextOptions?.ttlMs ?? 3e4;
62
+ const now = Date.now();
63
+ const cached = contextCache.get(roomId);
64
+ if (cached && cached.expiresAt > now) {
65
+ cached.lastAccessedAt = now;
66
+ return cached.value;
67
+ }
68
+ if (cached) {
69
+ contextCache.delete(roomId);
70
+ }
71
+ const tools = getToolsForRoom(roomId);
72
+ if (!tools) {
73
+ return buildUnavailableSystemPromptContext(roomId);
74
+ }
75
+ const context = await buildSystemPromptContext(roomId, tools);
76
+ contextCache.set(roomId, {
77
+ value: context,
78
+ expiresAt: now + ttlMs,
79
+ lastAccessedAt: now
80
+ });
81
+ evictLeastRecentlyUsedContext(contextCache, maxEntries);
82
+ return context;
83
+ }
84
+ async function buildSystemPromptContext(roomId, tools) {
85
+ const participants = await tools.getParticipants();
86
+ const warnings = [];
87
+ const agentResolution = await resolveAgentIdentity(tools);
88
+ if (agentResolution.warning) {
89
+ warnings.push(agentResolution.warning);
90
+ }
91
+ const roomResolution = await resolveRoomTitle(tools, roomId);
92
+ if (roomResolution.warning) {
93
+ warnings.push(roomResolution.warning);
94
+ }
95
+ const agentIdentity = agentResolution.value;
96
+ const roomTitle = roomResolution.value;
97
+ const normalizedParticipants = participants.map((participant) => ({
98
+ id: String(participant.id),
99
+ name: String(participant.name ?? "Unknown"),
100
+ type: String(participant.type ?? "Unknown"),
101
+ handle: normalizeHandle(participant.handle),
102
+ isSelf: participant.id === agentIdentity?.id
103
+ }));
104
+ const selfHandle = normalizeHandle(agentIdentity?.handle);
105
+ const selfName = agentIdentity?.name ?? "Agent";
106
+ const mentionHandles = normalizedParticipants.filter((participant) => !participant.isSelf).map((participant) => participant.handle).filter((handle) => Boolean(handle));
107
+ const mentionFormat = mentionHandles.length > 0 ? mentionHandles.join(", ") : "No participant handles available";
108
+ const roomLabel = roomTitle ? `"${roomTitle}"` : "this room";
109
+ const agentLabel = selfHandle ? `${selfName} (${selfHandle})` : selfName;
110
+ const participantLines = normalizedParticipants.length > 0 ? normalizedParticipants.map((participant) => {
111
+ const suffix = participant.isSelf ? " (you)" : "";
112
+ const handle = participant.handle ? ` (${participant.handle})` : "";
113
+ return `- **${participant.name}**${handle} -- ${participant.type}${suffix}`;
114
+ }).join("\n") : "- No participants found";
115
+ const markdown = [
116
+ "## Room Context",
117
+ "",
118
+ `You are **${agentLabel}** in room ${roomLabel} (id: ${roomId}).`,
119
+ "",
120
+ "### Participants",
121
+ participantLines,
122
+ "",
123
+ "### Mention Format",
124
+ `To address someone, use their exact handle: ${mentionFormat}`,
125
+ ...warnings.length > 0 ? ["", "### Warnings", ...warnings.map((warning) => `- ${warning}`)] : []
126
+ ].join("\n");
127
+ return {
128
+ roomId,
129
+ roomTitle,
130
+ agent: {
131
+ id: agentIdentity?.id ?? "unknown-agent",
132
+ name: selfName,
133
+ handle: selfHandle,
134
+ description: agentIdentity?.description ?? null
135
+ },
136
+ participants: normalizedParticipants,
137
+ mentionFormat,
138
+ warnings,
139
+ markdown
140
+ };
141
+ }
142
+ async function resolveAgentIdentity(tools) {
143
+ const maybeTools = tools;
144
+ try {
145
+ if (maybeTools.getAgentIdentity) {
146
+ return { value: await maybeTools.getAgentIdentity(), warning: null };
147
+ }
148
+ if (maybeTools.rest?.getAgentMe) {
149
+ return { value: await maybeTools.rest.getAgentMe(), warning: null };
150
+ }
151
+ } catch (error) {
152
+ return {
153
+ value: null,
154
+ warning: `Unable to resolve agent identity: ${error instanceof Error ? error.message : String(error)}`
155
+ };
156
+ }
157
+ return { value: null, warning: null };
158
+ }
159
+ async function resolveRoomTitle(tools, roomId) {
160
+ const maybeTools = tools;
161
+ const rest = maybeTools.rest;
162
+ if (!rest?.listChats) {
163
+ return { value: null, warning: null };
164
+ }
165
+ try {
166
+ let page = 1;
167
+ const pageSize = 100;
168
+ while (true) {
169
+ const response = await rest.listChats({ page, pageSize });
170
+ const room = response?.data?.find((entry) => entry.id === roomId);
171
+ if (typeof room?.title === "string" && room.title.length > 0) {
172
+ return { value: room.title, warning: null };
173
+ }
174
+ const totalPages = response?.metadata?.totalPages ?? page;
175
+ if (page >= totalPages) {
176
+ return { value: null, warning: null };
177
+ }
178
+ page += 1;
179
+ }
180
+ } catch (error) {
181
+ return {
182
+ value: null,
183
+ warning: `Unable to resolve room title: ${error instanceof Error ? error.message : String(error)}`
184
+ };
185
+ }
186
+ }
187
+ function buildUnavailableSystemPromptContext(roomId) {
188
+ const warnings = [`No tool context found for room_id ${roomId}`];
189
+ const markdown = [
190
+ "## Room Context",
191
+ "",
192
+ `You are **Agent** in this room (id: ${roomId}).`,
193
+ "",
194
+ "### Participants",
195
+ "- No participants found",
196
+ "",
197
+ "### Mention Format",
198
+ "No participant handles available",
199
+ "",
200
+ "### Warnings",
201
+ ...warnings.map((warning) => `- ${warning}`)
202
+ ].join("\n");
203
+ return {
204
+ roomId,
205
+ roomTitle: null,
206
+ agent: {
207
+ id: "unknown-agent",
208
+ name: "Agent",
209
+ handle: null,
210
+ description: null
211
+ },
212
+ participants: [],
213
+ mentionFormat: "No participant handles available",
214
+ warnings,
215
+ markdown
36
216
  };
37
217
  }
218
+ function evictLeastRecentlyUsedContext(contextCache, maxEntries) {
219
+ if (contextCache.size <= maxEntries) {
220
+ return;
221
+ }
222
+ let oldestKey = null;
223
+ let oldestAccessedAt = Number.POSITIVE_INFINITY;
224
+ for (const [key, entry] of contextCache.entries()) {
225
+ if (entry.lastAccessedAt < oldestAccessedAt) {
226
+ oldestAccessedAt = entry.lastAccessedAt;
227
+ oldestKey = key;
228
+ }
229
+ }
230
+ if (oldestKey) {
231
+ contextCache.delete(oldestKey);
232
+ }
233
+ }
234
+ function normalizeHandle(handle) {
235
+ return typeof handle === "string" && handle.trim().length > 0 ? handle.trim() : null;
236
+ }
38
237
  function toSdkToolDefinition(registration) {
39
238
  const shape = buildZodShape(
40
239
  z,
@@ -49,5 +248,5 @@ function toSdkToolDefinition(registration) {
49
248
  );
50
249
  }
51
250
  export {
52
- createThenvoiSdkMcpServer
251
+ createBandSdkMcpServer
53
252
  };