@openllmsh/sdk 0.0.0-stage → 2.10.12-alpha.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.
- package/ARCHITECTURE.md +43 -0
- package/LICENSE +202 -0
- package/README.md +142 -2
- package/assets/openllm-light.svg +18 -0
- package/assets/openllm.svg +18 -0
- package/client/chat.ts +140 -0
- package/client/devices.ts +269 -0
- package/client/http.ts +72 -0
- package/client/index.ts +129 -0
- package/client/relay-mux.ts +547 -0
- package/client/types.ts +51 -0
- package/client/vault.ts +239 -0
- package/connect/chat.ts +58 -0
- package/connect/client.ts +240 -0
- package/connect/config.ts +47 -0
- package/connect/errors.ts +121 -0
- package/connect/index.ts +23 -0
- package/connect/oauth.ts +265 -0
- package/connect/routes.ts +234 -0
- package/connect/store.ts +107 -0
- package/mcp/handle.ts +24 -0
- package/mcp/index.ts +76 -0
- package/mcp/server.ts +319 -0
- package/mcp/tools/marketplace.ts +439 -0
- package/mcp/tools/memory-client.ts +297 -0
- package/mcp/tools/memory-config.ts +32 -0
- package/mcp/tools/memory.ts +369 -0
- package/mcp/tools/model-priority.ts +88 -0
- package/mcp/tools/openllm.ts +883 -0
- package/mcp/types.ts +28 -0
- package/openapi/call.ts +90 -0
- package/openapi/index.ts +8 -0
- package/openapi/openapi.json +80213 -0
- package/openapi/operations.ts +2075 -0
- package/package.json +39 -4
- package/protocol/CONTRIBUTING.md +21 -0
- package/protocol/README.md +134 -0
- package/protocol/access.ts +186 -0
- package/protocol/agent-prompt-text.ts +32 -0
- package/protocol/agent.ts +991 -0
- package/protocol/api-key-syntax.ts +105 -0
- package/protocol/assets/openllm-light.svg +18 -0
- package/protocol/assets/openllm.svg +18 -0
- package/protocol/audio.ts +29 -0
- package/protocol/auth.ts +142 -0
- package/protocol/changelog.ts +155 -0
- package/protocol/chat.ts +458 -0
- package/protocol/client-registry.ts +356 -0
- package/protocol/config.ts +345 -0
- package/protocol/control-channel.ts +115 -0
- package/protocol/cooldown-reason.ts +78 -0
- package/protocol/cost.ts +10 -0
- package/protocol/daemon-port.ts +31 -0
- package/protocol/daemon.ts +1524 -0
- package/protocol/default-chains.ts +66 -0
- package/protocol/device-state.ts +85 -0
- package/protocol/doctor-report-local.ts +443 -0
- package/protocol/doctor-report-policy.ts +119 -0
- package/protocol/doctor-report.ts +947 -0
- package/protocol/errors.ts +14 -0
- package/protocol/execution-selection.ts +141 -0
- package/protocol/hop-grant.ts +33 -0
- package/protocol/image-edit-parse.ts +263 -0
- package/protocol/images.ts +298 -0
- package/protocol/index.ts +74 -0
- package/protocol/inference-headers.ts +3 -0
- package/protocol/keepalive.ts +69 -0
- package/protocol/local-auth.ts +300 -0
- package/protocol/local-device-control.ts +133 -0
- package/protocol/local-provider.ts +288 -0
- package/protocol/local-session.ts +118 -0
- package/protocol/marketplace.ts +187 -0
- package/protocol/media-attempt.ts +81 -0
- package/protocol/media-bytes.ts +28 -0
- package/protocol/media-default.ts +357 -0
- package/protocol/media-dimensions.ts +132 -0
- package/protocol/media-input.ts +61 -0
- package/protocol/media-model.ts +142 -0
- package/protocol/media-option-issue.ts +90 -0
- package/protocol/media-types.ts +70 -0
- package/protocol/model-match.ts +1051 -0
- package/protocol/model-settings.ts +327 -0
- package/protocol/models.ts +767 -0
- package/protocol/mux.ts +722 -0
- package/protocol/plan-surface.ts +59 -0
- package/protocol/provider-models.ts +16 -0
- package/protocol/provider-status.ts +206 -0
- package/protocol/provider-tier.ts +67 -0
- package/protocol/provider-usage.ts +263 -0
- package/protocol/providers.ts +901 -0
- package/protocol/public-usage-index.ts +354 -0
- package/protocol/realtime-generated.ts +31 -0
- package/protocol/realtime.ts +324 -0
- package/protocol/registry-pointer.ts +118 -0
- package/protocol/relay.ts +702 -0
- package/protocol/replay-session.ts +11 -0
- package/protocol/responses.ts +280 -0
- package/protocol/semver.ts +182 -0
- package/protocol/setup-mode.ts +22 -0
- package/protocol/sha256-hex.ts +98 -0
- package/protocol/stats.ts +406 -0
- package/protocol/streaming.ts +19 -0
- package/protocol/subscription-daemon-floors.ts +33 -0
- package/protocol/subscription-provider-compat.ts +104 -0
- package/protocol/subscription-provider.ts +32 -0
- package/protocol/team-grant.ts +17 -0
- package/protocol/team-shareable.ts +61 -0
- package/protocol/transcription-encoding.ts +76 -0
- package/protocol/url-locality-dns.ts +37 -0
- package/protocol/url-locality.ts +288 -0
- package/protocol/usage-snapshots.ts +9 -0
- package/protocol/vendor-cli-install.ts +29 -0
- package/protocol/video-job-plan.ts +50 -0
- package/protocol/videos.ts +227 -0
- package/tsconfig.json +14 -0
- package/tunnel/ARCHITECTURE.md +111 -0
- package/tunnel/LICENSE +33 -0
- package/tunnel/README.md +45 -0
- package/tunnel/assets/openllm-light.svg +18 -0
- package/tunnel/assets/openllm.svg +18 -0
- package/tunnel/channel-envelope.ts +139 -0
- package/tunnel/codec.ts +191 -0
- package/tunnel/device-anchor.ts +229 -0
- package/tunnel/device-control.ts +118 -0
- package/tunnel/device-grant.ts +173 -0
- package/tunnel/fleet.ts +77 -0
- package/tunnel/index.ts +22 -0
- package/tunnel/mux.ts +580 -0
- package/tunnel/peer-link.ts +390 -0
- package/tunnel/rtc-auth.ts +415 -0
- package/tunnel/rtc-duplex.ts +187 -0
- package/tunnel/rtc-ice.ts +136 -0
- package/tunnel/secure.ts +1298 -0
- package/tunnel/stream-reset-error.ts +14 -0
- package/tunnel/streams.ts +1430 -0
- package/tunnel/team-grant.ts +302 -0
- package/tunnel/wire-bytes.ts +102 -0
- package/vault/ARCHITECTURE.md +470 -0
- package/vault/LICENSE +33 -0
- package/vault/api-key.ts +190 -0
- package/vault/argon2.ts +106 -0
- package/vault/cli-auth-seal.ts +157 -0
- package/vault/cred-seal.ts +146 -0
- package/vault/credential.ts +55 -0
- package/vault/crypto.ts +210 -0
- package/vault/daemon-attest.ts +229 -0
- package/vault/derive.ts +113 -0
- package/vault/device-access.ts +87 -0
- package/vault/device-anchor.ts +185 -0
- package/vault/device-control.ts +174 -0
- package/vault/handoff.ts +396 -0
- package/vault/index.ts +21 -0
- package/vault/passkey.ts +243 -0
- package/vault/phrase.ts +65 -0
- package/vault/pin.ts +153 -0
- package/vault/public-key-seal.ts +131 -0
- package/vault/seed.ts +272 -0
- package/vault/team.ts +355 -0
- package/vault/vault-item.ts +131 -0
- package/vault/vault-migrate-digest.ts +29 -0
- package/vault/wrapped.ts +77 -0
- package/wire/ARCHITECTURE.md +90 -0
- package/wire/CONTRIBUTING.md +19 -0
- package/wire/LICENSE +33 -0
- package/wire/README.md +51 -0
- package/wire/adapters/messages/anthropic-map.ts +37 -0
- package/wire/adapters/messages/index.ts +7 -0
- package/wire/adapters/messages/reasoning-from-items.ts +38 -0
- package/wire/adapters/messages/reasoning-signature.ts +243 -0
- package/wire/adapters/messages/request.ts +574 -0
- package/wire/adapters/messages/response.ts +215 -0
- package/wire/adapters/messages/streaming.ts +1027 -0
- package/wire/adapters/messages/usage.ts +43 -0
- package/wire/adapters/responses/index.ts +3 -0
- package/wire/adapters/responses/request.ts +395 -0
- package/wire/adapters/responses/response.ts +88 -0
- package/wire/adapters/responses/streaming.ts +344 -0
- package/wire/assets/openllm-light.svg +18 -0
- package/wire/assets/openllm.svg +18 -0
- package/wire/features/account-rank.ts +166 -0
- package/wire/features/compaction/compact-request.ts +862 -0
- package/wire/features/compaction/compaction-text.ts +43 -0
- package/wire/features/context-demote.ts +47 -0
- package/wire/features/context-overflow-strategy.ts +26 -0
- package/wire/features/context-skip.ts +170 -0
- package/wire/features/conversation-affinity.ts +144 -0
- package/wire/features/max-tokens-backfill.ts +141 -0
- package/wire/features/model-caps.ts +53 -0
- package/wire/features/model-settings.ts +24 -0
- package/wire/features/output-limit-clamp.ts +64 -0
- package/wire/features/quota-gate.ts +85 -0
- package/wire/index.ts +44 -0
- package/wire/lib/attempt-outcome.ts +43 -0
- package/wire/lib/canonical/content-part.ts +38 -0
- package/wire/lib/canonical/count-tokens-capability.ts +138 -0
- package/wire/lib/canonical/encoding-select.ts +82 -0
- package/wire/lib/canonical/image-signature.ts +202 -0
- package/wire/lib/canonical/image-sse.ts +216 -0
- package/wire/lib/canonical/message.ts +43 -0
- package/wire/lib/canonical/token-estimate.ts +266 -0
- package/wire/lib/encrypted-content.ts +66 -0
- package/wire/lib/error-class.ts +154 -0
- package/wire/lib/error-envelope.ts +56 -0
- package/wire/lib/forwarded-headers.ts +180 -0
- package/wire/lib/provider-error-rules.ts +48 -0
- package/wire/lib/refusal.ts +38 -0
- package/wire/lib/responses-apply-patch.ts +104 -0
- package/wire/lib/responses-namespace.ts +53 -0
- package/wire/lib/secret-scrub.ts +101 -0
- package/wire/lib/streaming/accumulate.ts +221 -0
- package/wire/lib/streaming/finish-reason.ts +33 -0
- package/wire/lib/streaming/peek.ts +154 -0
- package/wire/lib/streaming/provider-decode.ts +259 -0
- package/wire/lib/streaming/response-stream.ts +71 -0
- package/wire/lib/streaming/sse.ts +699 -0
- package/wire/lib/streaming/strip-tool-calls.ts +95 -0
- package/wire/lib/streaming/upstream-error.ts +58 -0
- package/wire/lib/strip-subagent-isolation.ts +284 -0
- package/wire/lib/thinking-signature.ts +156 -0
- package/wire/lib/token-ruler/bpe-core.ts +426 -0
- package/wire/lib/token-ruler/index.ts +2 -0
- package/wire/lib/token-ruler/ruler.ts +79 -0
- package/wire/lib/token-ruler/vocab/claude-ranks.ts +16 -0
- package/wire/lib/token-ruler/vocab/claude.ts +22 -0
- package/wire/lib/token-ruler/vocab/o200k-ranks.ts +18 -0
- package/wire/lib/token-ruler/vocab/o200k.ts +19 -0
- package/wire/lib/tool-name-map.ts +271 -0
- package/wire/lib/tool-schema.ts +353 -0
- package/wire/lib/usage-observer.ts +125 -0
- package/wire/providers/anthropic/adaptive-thinking.ts +291 -0
- package/wire/providers/anthropic/beta-headers.ts +165 -0
- package/wire/providers/anthropic/index.ts +10 -0
- package/wire/providers/anthropic/request.ts +607 -0
- package/wire/providers/anthropic/response.ts +155 -0
- package/wire/providers/anthropic/streaming.ts +315 -0
- package/wire/providers/anthropic/web-search-domains.ts +49 -0
- package/wire/providers/chatgpt/common.ts +136 -0
- package/wire/providers/chatgpt/index.ts +9 -0
- package/wire/providers/chatgpt/request.ts +959 -0
- package/wire/providers/chatgpt/streaming.ts +1007 -0
- package/wire/providers/chatgpt/web-search.ts +63 -0
- package/wire/providers/grok/web-search.ts +87 -0
- package/wire/providers/kimi/web-search.ts +145 -0
- package/wire/providers/upstream-deny.ts +355 -0
- package/wire/providers/upstream-request.ts +619 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin client over the gateway's OpenLLM Memory endpoints
|
|
3
|
+
* (`/api/integrations/memory/*`). Embedding and scoping live
|
|
4
|
+
* server-side — this client just forwards save/forget/search/match
|
|
5
|
+
* with the caller's API key.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { THttpClientOptions } from "@openllmsh/sdk/openapi";
|
|
9
|
+
import type { MemoryConfig, TProjectRef } from "./memory-config";
|
|
10
|
+
|
|
11
|
+
// ── Domain types ──────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export interface Memory {
|
|
14
|
+
id: string;
|
|
15
|
+
memory: string;
|
|
16
|
+
similarity: number;
|
|
17
|
+
project?: string;
|
|
18
|
+
createdAt?: string;
|
|
19
|
+
team_id?: string | null;
|
|
20
|
+
team_name?: string | null;
|
|
21
|
+
author_user_id?: string | null;
|
|
22
|
+
source?: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SearchResult {
|
|
26
|
+
results: Memory[];
|
|
27
|
+
total: number;
|
|
28
|
+
timing: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface WhoamiResult {
|
|
32
|
+
email: string;
|
|
33
|
+
role: string;
|
|
34
|
+
teams: Array<{ id: string; name: string }>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MatchedTeam {
|
|
38
|
+
id: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SaveOptions {
|
|
44
|
+
/** Single project slug — merged with `projects` server-side. */
|
|
45
|
+
project?: string;
|
|
46
|
+
/** Multiple project slugs — chunk surfaces in every named bucket. */
|
|
47
|
+
projects?: string[];
|
|
48
|
+
/** Single team id — merged with `teams` server-side. Caller must be a member. */
|
|
49
|
+
team?: string;
|
|
50
|
+
/** Multiple team ids — chunk is shared with every listed team. */
|
|
51
|
+
teams?: string[];
|
|
52
|
+
/** Project identity for automatic team matching. */
|
|
53
|
+
project_ref?: TProjectRef;
|
|
54
|
+
/** Opaque metadata (e.g. `{ source: "hook" | "tool" }`). */
|
|
55
|
+
metadata?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SearchOptions {
|
|
59
|
+
project?: string;
|
|
60
|
+
projects?: string[];
|
|
61
|
+
/** Restricts team-row search to matcher hits for this project. */
|
|
62
|
+
project_ref?: TProjectRef;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── Client ────────────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
const MEMORY_ROOT = "/api/integrations/memory";
|
|
68
|
+
|
|
69
|
+
/** `diagnostic.status` of a hook-transport error, duck-typed so this module
|
|
70
|
+
* never imports the CLI transport class. */
|
|
71
|
+
const statusOf = (error: unknown): number | null => {
|
|
72
|
+
if (error === null || typeof error !== "object") return null;
|
|
73
|
+
const diagnostic = (error as { readonly diagnostic?: unknown }).diagnostic;
|
|
74
|
+
if (diagnostic === null || typeof diagnostic !== "object") return null;
|
|
75
|
+
const status = (diagnostic as { readonly status?: unknown }).status;
|
|
76
|
+
return typeof status === "number" ? status : null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export class MemoryClient {
|
|
80
|
+
private baseUrl: string;
|
|
81
|
+
private apiKey: string;
|
|
82
|
+
|
|
83
|
+
constructor(
|
|
84
|
+
config: MemoryConfig,
|
|
85
|
+
private readonly options: THttpClientOptions = {},
|
|
86
|
+
) {
|
|
87
|
+
this.baseUrl = config.gatewayUrl.replace(/\/$/, "");
|
|
88
|
+
this.apiKey = config.gatewayApiKey;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private async requestOnce(
|
|
92
|
+
method: string,
|
|
93
|
+
path: string,
|
|
94
|
+
body: unknown | undefined,
|
|
95
|
+
): Promise<Response> {
|
|
96
|
+
const headers: Record<string, string> = {
|
|
97
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
98
|
+
};
|
|
99
|
+
if (body !== undefined) headers["Content-Type"] = "application/json";
|
|
100
|
+
return (this.options.fetch ?? fetch)(`${this.baseUrl}${path}`, {
|
|
101
|
+
method,
|
|
102
|
+
headers,
|
|
103
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
104
|
+
signal: AbortSignal.timeout(this.options.timeoutMs ?? 60_000),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private async request<T>(
|
|
109
|
+
method: string,
|
|
110
|
+
action: string,
|
|
111
|
+
body?: unknown,
|
|
112
|
+
): Promise<T> {
|
|
113
|
+
const path = `${MEMORY_ROOT}/${action}`;
|
|
114
|
+
const res = await this.requestOnce(method, path, body);
|
|
115
|
+
if (res.ok) {
|
|
116
|
+
if (res.status === 204) return undefined as unknown as T;
|
|
117
|
+
return (await res.json()) as T;
|
|
118
|
+
}
|
|
119
|
+
const text = await res.text().catch(() => "");
|
|
120
|
+
throw new Error(`${method} ${path} → ${res.status}: ${text}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Cheap personal enablement probe. Hooks call this (cached) before any
|
|
125
|
+
* recall/extract network work.
|
|
126
|
+
*
|
|
127
|
+
* - `200` with `enabled` → that value
|
|
128
|
+
* - `404` → treat as enabled (older gateway without the probe)
|
|
129
|
+
* - other failures throw (caller fail-opens to skip)
|
|
130
|
+
*/
|
|
131
|
+
async isEnabled(): Promise<boolean> {
|
|
132
|
+
const path = `${MEMORY_ROOT}/enabled`;
|
|
133
|
+
let res: Response;
|
|
134
|
+
try {
|
|
135
|
+
res = await this.requestOnce("GET", path, undefined);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
// The hook transport throws on non-OK (with `diagnostic.status`)
|
|
138
|
+
// instead of returning the response; a 404 there still means enabled.
|
|
139
|
+
if (statusOf(error) === 404) return true;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
if (res.ok) {
|
|
143
|
+
const body = (await res.json()) as { enabled?: unknown };
|
|
144
|
+
// Only an explicit `false` disables. Missing/unknown fields (and
|
|
145
|
+
// older mocks that return an empty JSON body) stay enabled.
|
|
146
|
+
return body.enabled !== false;
|
|
147
|
+
}
|
|
148
|
+
if (res.status === 404) return true;
|
|
149
|
+
const text = await res.text().catch(() => "");
|
|
150
|
+
throw new Error(`GET ${path} → ${res.status}: ${text}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Save a memory. The chunk is keyed on (saver email, content) — so
|
|
155
|
+
* re-saving the same content unions the projects/teams server-side
|
|
156
|
+
* without re-embedding. One stored chunk; many destinations expressed as
|
|
157
|
+
* metadata.projects[] + ref overlays.
|
|
158
|
+
*/
|
|
159
|
+
async save(
|
|
160
|
+
content: string,
|
|
161
|
+
opts: SaveOptions = {},
|
|
162
|
+
): Promise<{
|
|
163
|
+
id: string;
|
|
164
|
+
projects: string[];
|
|
165
|
+
teams: string[];
|
|
166
|
+
reused: boolean;
|
|
167
|
+
status: "saved";
|
|
168
|
+
}> {
|
|
169
|
+
if (!content.trim()) throw new Error("content is required");
|
|
170
|
+
const body: Record<string, unknown> = { content };
|
|
171
|
+
if (opts.project) body.project = opts.project;
|
|
172
|
+
if (opts.projects && opts.projects.length > 0)
|
|
173
|
+
body.projects = opts.projects;
|
|
174
|
+
if (opts.team) body.team = opts.team;
|
|
175
|
+
if (opts.teams && opts.teams.length > 0) body.teams = opts.teams;
|
|
176
|
+
if (opts.project_ref) body.project_ref = opts.project_ref;
|
|
177
|
+
if (opts.metadata) body.metadata = opts.metadata;
|
|
178
|
+
return this.request("POST", "save", body);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** List the distinct project slugs the caller can read. */
|
|
182
|
+
async listProjects(): Promise<string[]> {
|
|
183
|
+
const res = await this.request<{ projects: string[] }>("GET", "projects");
|
|
184
|
+
return Array.isArray(res?.projects) ? res.projects : [];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Automatic extraction retries must never fuzzy-delete a replacement. */
|
|
188
|
+
async forgetExact(
|
|
189
|
+
content: string,
|
|
190
|
+
opts: SaveOptions = {},
|
|
191
|
+
): Promise<{ deleted: number }> {
|
|
192
|
+
if (!content.trim()) throw new Error("content is required");
|
|
193
|
+
return this.request("POST", "forget", {
|
|
194
|
+
content,
|
|
195
|
+
...(opts.project ? { project: opts.project } : {}),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Forget by exact-content hash first, then semantic fallback. Server scopes
|
|
201
|
+
* every delete to the caller's own chunks (team chunks stay put).
|
|
202
|
+
*/
|
|
203
|
+
async forget(
|
|
204
|
+
content: string,
|
|
205
|
+
opts: SaveOptions = {},
|
|
206
|
+
): Promise<{ success: boolean; message: string }> {
|
|
207
|
+
// Exact-content match first (server hashes saver email + content).
|
|
208
|
+
const exact = await this.forgetExact(content, opts);
|
|
209
|
+
if (exact.deleted > 0) {
|
|
210
|
+
return { success: true, message: "Forgot memory (exact match)" };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Semantic fallback — scoped to the same project(s).
|
|
214
|
+
const SIM_THRESHOLD = 0.85;
|
|
215
|
+
const search = await this.search(content, 5, {
|
|
216
|
+
project: opts.project,
|
|
217
|
+
});
|
|
218
|
+
const hit = search.results.find((m) => m.similarity >= SIM_THRESHOLD);
|
|
219
|
+
if (!hit) {
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
message: `No matching memory found (exact + semantic search at similarity >= ${SIM_THRESHOLD}).`,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const byId = await this.request<{ deleted: number }>("POST", "forget", {
|
|
226
|
+
id: hit.id,
|
|
227
|
+
});
|
|
228
|
+
if (byId.deleted === 0) {
|
|
229
|
+
return {
|
|
230
|
+
success: false,
|
|
231
|
+
message:
|
|
232
|
+
"Semantic match belonged to another user or team — cannot forget.",
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
success: true,
|
|
237
|
+
message: `Forgot similar memory (similarity ${hit.similarity.toFixed(2)}): "${hit.memory.slice(0, 100)}"`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Semantic search — server embeds the query and auto-scopes to the caller's refs. */
|
|
242
|
+
async search(
|
|
243
|
+
query: string,
|
|
244
|
+
limit = 10,
|
|
245
|
+
opts: SearchOptions = {},
|
|
246
|
+
): Promise<SearchResult> {
|
|
247
|
+
if (!query.trim()) throw new Error("query is required");
|
|
248
|
+
const start = Date.now();
|
|
249
|
+
const body: Record<string, unknown> = { query, limit };
|
|
250
|
+
if (opts.projects && opts.projects.length > 0) {
|
|
251
|
+
body.projects = opts.projects;
|
|
252
|
+
} else if (opts.project) {
|
|
253
|
+
body.project = opts.project;
|
|
254
|
+
}
|
|
255
|
+
if (opts.project_ref) body.project_ref = opts.project_ref;
|
|
256
|
+
const res = await this.request<{
|
|
257
|
+
results: Array<{
|
|
258
|
+
id: string;
|
|
259
|
+
content: string;
|
|
260
|
+
similarity: number;
|
|
261
|
+
project?: string;
|
|
262
|
+
createdAt: string | null;
|
|
263
|
+
team_id?: string | null;
|
|
264
|
+
team_name?: string | null;
|
|
265
|
+
author_user_id?: string | null;
|
|
266
|
+
source?: string | null;
|
|
267
|
+
}>;
|
|
268
|
+
}>("POST", "search", body);
|
|
269
|
+
const results: Memory[] = res.results.map((r) => ({
|
|
270
|
+
id: r.id,
|
|
271
|
+
memory: r.content,
|
|
272
|
+
similarity: r.similarity,
|
|
273
|
+
project: r.project,
|
|
274
|
+
createdAt: r.createdAt ?? undefined,
|
|
275
|
+
team_id: r.team_id,
|
|
276
|
+
team_name: r.team_name,
|
|
277
|
+
author_user_id: r.author_user_id,
|
|
278
|
+
source: r.source,
|
|
279
|
+
}));
|
|
280
|
+
return { results, total: results.length, timing: Date.now() - start };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Deterministic team ↔ project match for automatic bucketing. */
|
|
284
|
+
async match(project_ref: TProjectRef): Promise<{ teams: MatchedTeam[] }> {
|
|
285
|
+
const res = await this.request<{ teams: MatchedTeam[] }>("POST", "match", {
|
|
286
|
+
project_ref,
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
teams: Array.isArray(res?.teams) ? res.teams : [],
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Identity lookup — which email/role/teams is this MCP bound to? */
|
|
294
|
+
async whoami(): Promise<WhoamiResult> {
|
|
295
|
+
return this.request<WhoamiResult>("GET", "whoami");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory integration config.
|
|
3
|
+
*
|
|
4
|
+
* Embedding happens entirely on the gateway (host-paid Bedrock Titan v2
|
|
5
|
+
* at 1024-d, fixed). The bundle ships raw text to
|
|
6
|
+
* `/api/integrations/memory/{save,forget,search}` and never touches an
|
|
7
|
+
* embedding endpoint — keeps the host model off the public surface.
|
|
8
|
+
*
|
|
9
|
+
* Project identity is injected by the host (CLI/browser). This module never
|
|
10
|
+
* reads `process.cwd()` or shells out to git.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const COLLECTION_NAME = "memories";
|
|
14
|
+
|
|
15
|
+
export type TProjectRef = {
|
|
16
|
+
readonly slug: string;
|
|
17
|
+
readonly remote_owner?: string;
|
|
18
|
+
readonly remote_repo?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface MemoryConfig {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
gatewayUrl: string;
|
|
25
|
+
gatewayApiKey: string;
|
|
26
|
+
/** Working directory used only when `resolveProject` is not provided. */
|
|
27
|
+
cwd?: string;
|
|
28
|
+
/** Resolve a project slug (optional override → slug). */
|
|
29
|
+
resolveProject?: (override?: string) => string;
|
|
30
|
+
/** Build the project_ref sent with save/search. */
|
|
31
|
+
buildProjectRef?: (projectSlug: string) => TProjectRef;
|
|
32
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory tool group — defs + dispatcher, composed into the ONE
|
|
3
|
+
* MCP server by `../server.ts`. Project identity is injected via
|
|
4
|
+
* `MemoryConfig` — this module never reads `process.cwd()` or git.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { TToolResult } from "../types";
|
|
8
|
+
import { MemoryClient } from "./memory-client";
|
|
9
|
+
import type { MemoryConfig, TProjectRef } from "./memory-config";
|
|
10
|
+
|
|
11
|
+
const MAX_CONTENT_LENGTH = 200_000;
|
|
12
|
+
const MAX_QUERY_LENGTH = 1_000;
|
|
13
|
+
const MAX_PROJECT_LENGTH = 64;
|
|
14
|
+
|
|
15
|
+
const memoryDescription =
|
|
16
|
+
"Cross-session memory for this user. Personal is the default; team sharing is automatic for repos that match a team the user belongs to — do NOT try to target arbitrary teams. " +
|
|
17
|
+
"PROACTIVELY call with action='save' when the user reveals: a preference or working-style rule, a fact about themselves or their team, feedback that should shape future behavior (corrections AND confirmations of non-obvious choices), an external reference (Linear project, Slack channel, dashboard, runbook), or a project goal/deadline/constraint not derivable from code. Saving is cheap; missing a save means the next session starts blind. " +
|
|
18
|
+
"Use action='forget' when a memory is outdated or the user asks to remove it (exact `(project, content)` hash first, then semantic similarity >= 0.85 within the same project). " +
|
|
19
|
+
"Optional `project` slug scopes the memory to a named personal bucket (default: 'default'). " +
|
|
20
|
+
"For personal multi-project fan-out, pass `destinations: [{project}, ...]` — each entry writes the same content to one personal project slug. Call `whoAmI` for identity (email/role/teams); teams listed there are informational only.";
|
|
21
|
+
|
|
22
|
+
const recallDescription =
|
|
23
|
+
"Cross-session recall for this user. " +
|
|
24
|
+
"Call BEFORE answering questions about the user, their preferences, or their projects; when the user references past work ('like we did before', 'the usual way'); and at the start of any non-trivial task to pull in relevant prior context. " +
|
|
25
|
+
"Returns the top N relevant memories with similarity scores, formatted as markdown. Team-matched project memories are included automatically. " +
|
|
26
|
+
"Note: a `UserPromptSubmit` hook auto-injects relevant memories on every prompt — if you already see a '[memory] Relevant saved memories (auto-recalled):' block in context, only re-query with a different angle. " +
|
|
27
|
+
"Optional `project` narrows the search to one named bucket (default: 'default').";
|
|
28
|
+
|
|
29
|
+
const whoAmIDescription =
|
|
30
|
+
"Identify which gateway account this MCP server is bound to. Returns email, role, and team memberships (informational — do not try to target teams by id when saving; team sharing is automatic for matched project repos). Useful for debugging MCP configuration.";
|
|
31
|
+
|
|
32
|
+
export const memoryToolDefs = [
|
|
33
|
+
{
|
|
34
|
+
name: "memory",
|
|
35
|
+
description: memoryDescription,
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
content: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description:
|
|
42
|
+
"The memory content to save or forget (e.g. 'User prefers dark mode').",
|
|
43
|
+
maxLength: MAX_CONTENT_LENGTH,
|
|
44
|
+
},
|
|
45
|
+
action: {
|
|
46
|
+
type: "string",
|
|
47
|
+
enum: ["save", "forget"],
|
|
48
|
+
default: "save",
|
|
49
|
+
},
|
|
50
|
+
project: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description:
|
|
53
|
+
"Optional project slug (a-z, 0-9, ., _, -). Defaults to 'default'. Ignored when `destinations` is provided.",
|
|
54
|
+
maxLength: MAX_PROJECT_LENGTH,
|
|
55
|
+
},
|
|
56
|
+
destinations: {
|
|
57
|
+
type: "array",
|
|
58
|
+
description:
|
|
59
|
+
"Optional personal fan-out targets. Each entry picks a project slug (defaults to 'default' if omitted). The same content is written once per destination — use this for facts that span multiple personal projects. Team sharing is automatic via project matching; do not try to target teams here.",
|
|
60
|
+
items: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
project: {
|
|
64
|
+
type: "string",
|
|
65
|
+
maxLength: MAX_PROJECT_LENGTH,
|
|
66
|
+
description:
|
|
67
|
+
"Project slug for this destination. Optional; defaults to 'default'.",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ["content"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "recall",
|
|
78
|
+
description: recallDescription,
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: {
|
|
82
|
+
query: {
|
|
83
|
+
type: "string",
|
|
84
|
+
description: "Natural language query to search saved memories.",
|
|
85
|
+
maxLength: MAX_QUERY_LENGTH,
|
|
86
|
+
},
|
|
87
|
+
limit: {
|
|
88
|
+
type: "number",
|
|
89
|
+
default: 10,
|
|
90
|
+
maximum: 50,
|
|
91
|
+
minimum: 1,
|
|
92
|
+
},
|
|
93
|
+
project: {
|
|
94
|
+
type: "string",
|
|
95
|
+
description:
|
|
96
|
+
"Optional project slug to scope the search. Defaults to 'default'.",
|
|
97
|
+
maxLength: MAX_PROJECT_LENGTH,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
required: ["query"],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "whoAmI",
|
|
105
|
+
description: whoAmIDescription,
|
|
106
|
+
inputSchema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
const clientFor = (() => {
|
|
114
|
+
let cached: { key: string; client: MemoryClient } | null = null;
|
|
115
|
+
return (config: MemoryConfig): MemoryClient => {
|
|
116
|
+
const key = `${config.gatewayUrl}\0${config.gatewayApiKey}`;
|
|
117
|
+
if (cached === null || cached.key !== key) {
|
|
118
|
+
cached = { key, client: new MemoryClient(config) };
|
|
119
|
+
}
|
|
120
|
+
return cached.client;
|
|
121
|
+
};
|
|
122
|
+
})();
|
|
123
|
+
|
|
124
|
+
/** Tiny basename without `node:path`. */
|
|
125
|
+
const basenameOf = (path: string): string => {
|
|
126
|
+
const trimmed = path.replace(/[/\\]+$/, "");
|
|
127
|
+
const slash = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
128
|
+
return slash === -1 ? trimmed : trimmed.slice(slash + 1);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const slugify = (input: string): string =>
|
|
132
|
+
input
|
|
133
|
+
.trim()
|
|
134
|
+
.toLowerCase()
|
|
135
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
136
|
+
.replace(/-+/g, "-")
|
|
137
|
+
.replace(/^[-._]+|[-._]+$/g, "")
|
|
138
|
+
.slice(0, 64);
|
|
139
|
+
|
|
140
|
+
const defaultResolveProject = (
|
|
141
|
+
config: MemoryConfig,
|
|
142
|
+
override?: string,
|
|
143
|
+
): string => {
|
|
144
|
+
if (config.resolveProject) return config.resolveProject(override);
|
|
145
|
+
const explicit = override ? slugify(override) : "";
|
|
146
|
+
if (explicit) return explicit;
|
|
147
|
+
if (typeof config.cwd === "string" && config.cwd.length > 0) {
|
|
148
|
+
return slugify(basenameOf(config.cwd)) || "default";
|
|
149
|
+
}
|
|
150
|
+
return "default";
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const defaultBuildProjectRef = (
|
|
154
|
+
config: MemoryConfig,
|
|
155
|
+
projectSlug: string,
|
|
156
|
+
): TProjectRef => {
|
|
157
|
+
if (config.buildProjectRef) return config.buildProjectRef(projectSlug);
|
|
158
|
+
return { slug: projectSlug };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const handleMemory = async (
|
|
162
|
+
client: MemoryClient,
|
|
163
|
+
config: MemoryConfig,
|
|
164
|
+
args: {
|
|
165
|
+
content: string;
|
|
166
|
+
action?: "save" | "forget";
|
|
167
|
+
project?: string;
|
|
168
|
+
destinations?: Array<{ project?: string }>;
|
|
169
|
+
},
|
|
170
|
+
): Promise<TToolResult> => {
|
|
171
|
+
const action = args.action ?? "save";
|
|
172
|
+
if (!args?.content) {
|
|
173
|
+
return {
|
|
174
|
+
content: [{ type: "text" as const, text: "Error: content is required" }],
|
|
175
|
+
isError: true,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (args.content.length > MAX_CONTENT_LENGTH) {
|
|
179
|
+
return {
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: "text" as const,
|
|
183
|
+
text: `Error: content exceeds max length of ${MAX_CONTENT_LENGTH} chars`,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
isError: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (action === "save") {
|
|
191
|
+
// Collapse `destinations: [{project}, ...]` into projects[]. Team ids are
|
|
192
|
+
// never accepted from the agent — matching is automatic via project_ref.
|
|
193
|
+
const projectSet = new Set<string>();
|
|
194
|
+
const hasDestinations = Array.isArray(args.destinations);
|
|
195
|
+
// `project` is documented as ignored when `destinations` is provided.
|
|
196
|
+
if (
|
|
197
|
+
!hasDestinations &&
|
|
198
|
+
typeof args.project === "string" &&
|
|
199
|
+
args.project.trim()
|
|
200
|
+
) {
|
|
201
|
+
projectSet.add(args.project.trim());
|
|
202
|
+
}
|
|
203
|
+
if (Array.isArray(args.destinations)) {
|
|
204
|
+
for (const d of args.destinations) {
|
|
205
|
+
if (!d || typeof d !== "object") continue;
|
|
206
|
+
if (typeof d.project === "string" && d.project.trim()) {
|
|
207
|
+
projectSet.add(d.project.trim());
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const primarySlug =
|
|
212
|
+
projectSet.size > 0
|
|
213
|
+
? ([...projectSet][0] ?? defaultResolveProject(config))
|
|
214
|
+
: typeof args.project === "string" && args.project.trim()
|
|
215
|
+
? args.project.trim()
|
|
216
|
+
: defaultResolveProject(config);
|
|
217
|
+
const project_ref = defaultBuildProjectRef(config, primarySlug);
|
|
218
|
+
try {
|
|
219
|
+
// Personal save with project_ref so the server can record observations
|
|
220
|
+
// and gate any future explicit team targets. Automatic team fan-out for
|
|
221
|
+
// project facts is the extract hook's job (scope=project → matched teams).
|
|
222
|
+
const res = await client.save(args.content, {
|
|
223
|
+
projects: projectSet.size > 0 ? Array.from(projectSet) : undefined,
|
|
224
|
+
project_ref,
|
|
225
|
+
metadata: { source: "tool" },
|
|
226
|
+
});
|
|
227
|
+
const projTag = res.projects.join(",");
|
|
228
|
+
const teamTag = res.teams.length ? ` · teams=${res.teams.join(",")}` : "";
|
|
229
|
+
const reusedTag = res.reused ? " (merged into existing chunk)" : "";
|
|
230
|
+
return {
|
|
231
|
+
content: [
|
|
232
|
+
{
|
|
233
|
+
type: "text" as const,
|
|
234
|
+
text: `Saved memory ${res.id} (projects=${projTag}${teamTag})${reusedTag}`,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
} catch (err) {
|
|
239
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
240
|
+
return {
|
|
241
|
+
content: [
|
|
242
|
+
{ type: "text" as const, text: `Error saving memory: ${msg}` },
|
|
243
|
+
],
|
|
244
|
+
isError: true,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (action === "forget") {
|
|
249
|
+
const res = await client.forget(args.content, { project: args.project });
|
|
250
|
+
return {
|
|
251
|
+
content: [{ type: "text" as const, text: res.message }],
|
|
252
|
+
isError: !res.success,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
content: [{ type: "text" as const, text: `Unknown action: ${action}` }],
|
|
257
|
+
isError: true,
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const handleRecall = async (
|
|
262
|
+
client: MemoryClient,
|
|
263
|
+
config: MemoryConfig,
|
|
264
|
+
args: { query: string; limit?: number; project?: string },
|
|
265
|
+
): Promise<TToolResult> => {
|
|
266
|
+
if (!args?.query) {
|
|
267
|
+
return {
|
|
268
|
+
content: [{ type: "text" as const, text: "Error: query is required" }],
|
|
269
|
+
isError: true,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
if (args.query.length > MAX_QUERY_LENGTH) {
|
|
273
|
+
return {
|
|
274
|
+
content: [
|
|
275
|
+
{
|
|
276
|
+
type: "text" as const,
|
|
277
|
+
text: `Error: query exceeds max length of ${MAX_QUERY_LENGTH} chars`,
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
isError: true,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const limit = Math.max(1, Math.min(50, Math.floor(args.limit ?? 10)));
|
|
284
|
+
const projectSlug =
|
|
285
|
+
typeof args.project === "string" && args.project.trim()
|
|
286
|
+
? args.project.trim()
|
|
287
|
+
: defaultResolveProject(config);
|
|
288
|
+
const res = await client.search(args.query, limit, {
|
|
289
|
+
project: args.project,
|
|
290
|
+
project_ref: defaultBuildProjectRef(config, projectSlug),
|
|
291
|
+
});
|
|
292
|
+
if (res.results.length === 0) {
|
|
293
|
+
return {
|
|
294
|
+
content: [
|
|
295
|
+
{
|
|
296
|
+
type: "text" as const,
|
|
297
|
+
text: `No memories matched. (${res.timing}ms)`,
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const parts: string[] = [
|
|
303
|
+
`## Relevant memories (${res.results.length}, ${res.timing}ms)`,
|
|
304
|
+
];
|
|
305
|
+
res.results.forEach((m, i) => {
|
|
306
|
+
const pct = Math.round(m.similarity * 100);
|
|
307
|
+
const teamName =
|
|
308
|
+
typeof m.team_name === "string" && m.team_name.trim()
|
|
309
|
+
? m.team_name.trim()
|
|
310
|
+
: "";
|
|
311
|
+
const projectTag = m.project
|
|
312
|
+
? teamName
|
|
313
|
+
? ` · team ${teamName} · project=${m.project}`
|
|
314
|
+
: ` · project=${m.project}`
|
|
315
|
+
: teamName
|
|
316
|
+
? ` · team ${teamName}`
|
|
317
|
+
: "";
|
|
318
|
+
parts.push(`\n### ${i + 1}. ${pct}% match${projectTag}`);
|
|
319
|
+
parts.push(m.memory);
|
|
320
|
+
});
|
|
321
|
+
return { content: [{ type: "text" as const, text: parts.join("\n") }] };
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const handleWhoAmI = async (client: MemoryClient): Promise<TToolResult> => {
|
|
325
|
+
const who = await client.whoami();
|
|
326
|
+
const teamList = who.teams.length
|
|
327
|
+
? who.teams.map((t) => `${t.name} (${t.id})`).join(", ")
|
|
328
|
+
: "(none)";
|
|
329
|
+
const text = [
|
|
330
|
+
`email: ${who.email}`,
|
|
331
|
+
`role: ${who.role}`,
|
|
332
|
+
`teams: ${teamList}`,
|
|
333
|
+
].join("\n");
|
|
334
|
+
return { content: [{ type: "text" as const, text }] };
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export const handleMemoryTool = async (
|
|
338
|
+
name: string,
|
|
339
|
+
args: Record<string, unknown>,
|
|
340
|
+
config: MemoryConfig,
|
|
341
|
+
): Promise<TToolResult> => {
|
|
342
|
+
const client = clientFor(config);
|
|
343
|
+
try {
|
|
344
|
+
switch (name) {
|
|
345
|
+
case "memory":
|
|
346
|
+
return await handleMemory(
|
|
347
|
+
client,
|
|
348
|
+
config,
|
|
349
|
+
args as Parameters<typeof handleMemory>[2],
|
|
350
|
+
);
|
|
351
|
+
case "recall":
|
|
352
|
+
return await handleRecall(
|
|
353
|
+
client,
|
|
354
|
+
config,
|
|
355
|
+
args as Parameters<typeof handleRecall>[2],
|
|
356
|
+
);
|
|
357
|
+
case "whoAmI":
|
|
358
|
+
return await handleWhoAmI(client);
|
|
359
|
+
default:
|
|
360
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
363
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
364
|
+
return {
|
|
365
|
+
content: [{ type: "text" as const, text: `Error: ${message}` }],
|
|
366
|
+
isError: true,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|