@layernorm/overlay-agent-host 0.7.0 → 0.9.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/Dockerfile +9 -2
- package/LICENSE +176 -0
- package/README.md +10 -7
- package/dist/cli.js +1 -1
- package/dist/host-capabilities.d.ts +1 -1
- package/dist/host-capabilities.js +1 -1
- package/dist/keyed-lock.d.ts +2 -0
- package/dist/keyed-lock.d.ts.map +1 -0
- package/dist/keyed-lock.js +18 -0
- package/dist/keyed-lock.js.map +1 -0
- package/dist/local-tools-exec.d.ts +14 -1
- package/dist/local-tools-exec.d.ts.map +1 -1
- package/dist/local-tools-exec.js +68 -12
- package/dist/local-tools-exec.js.map +1 -1
- package/dist/local-tools-paths.d.ts +8 -0
- package/dist/local-tools-paths.d.ts.map +1 -1
- package/dist/local-tools-paths.js +6 -2
- package/dist/local-tools-paths.js.map +1 -1
- package/dist/local-tools-terminal.d.ts +12 -3
- package/dist/local-tools-terminal.d.ts.map +1 -1
- package/dist/local-tools-terminal.js +113 -8
- package/dist/local-tools-terminal.js.map +1 -1
- package/dist/local-tools.d.ts.map +1 -1
- package/dist/local-tools.js +10 -4
- package/dist/local-tools.js.map +1 -1
- package/dist/private-threads-context.d.ts +2 -2
- package/dist/private-threads-context.d.ts.map +1 -1
- package/dist/private-threads-context.js +3 -1
- package/dist/private-threads-context.js.map +1 -1
- package/dist/private-threads-ipc.d.ts.map +1 -1
- package/dist/private-threads-ipc.js +3 -2
- package/dist/private-threads-ipc.js.map +1 -1
- package/dist/private-threads-local-mcp.d.ts +58 -0
- package/dist/private-threads-local-mcp.d.ts.map +1 -0
- package/dist/private-threads-local-mcp.js +252 -0
- package/dist/private-threads-local-mcp.js.map +1 -0
- package/dist/private-threads-overlay-model.d.ts +17 -0
- package/dist/private-threads-overlay-model.d.ts.map +1 -0
- package/dist/private-threads-overlay-model.js +89 -0
- package/dist/private-threads-overlay-model.js.map +1 -0
- package/dist/private-threads-protocol.d.ts +82 -2
- package/dist/private-threads-protocol.d.ts.map +1 -1
- package/dist/private-threads-protocol.js +45 -8
- package/dist/private-threads-protocol.js.map +1 -1
- package/dist/private-threads-title.d.ts +12 -0
- package/dist/private-threads-title.d.ts.map +1 -0
- package/dist/private-threads-title.js +47 -0
- package/dist/private-threads-title.js.map +1 -0
- package/dist/private-threads-tools.d.ts +3 -0
- package/dist/private-threads-tools.d.ts.map +1 -1
- package/dist/private-threads-tools.js +73 -8
- package/dist/private-threads-tools.js.map +1 -1
- package/dist/private-threads.d.ts +22 -6
- package/dist/private-threads.d.ts.map +1 -1
- package/dist/private-threads.js +125 -30
- package/dist/private-threads.js.map +1 -1
- package/package.json +10 -9
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { createMCPClient } from '@ai-sdk/mcp';
|
|
4
|
+
import { getDefaultEnvironment, StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
+
/**
|
|
6
|
+
* MCP servers that run on this computer (stdio), for private threads. Overlay Desktop keeps the person's list and
|
|
7
|
+
* their environment values in the Keychain and passes them with each turn; this pool starts a server the first time a
|
|
8
|
+
* turn needs it, shares it between turns, stops it after it has been idle for a while, and stops every server when the
|
|
9
|
+
* host quits. Their tools ask for approval in Ask mode, like the computer tools that run commands.
|
|
10
|
+
*/
|
|
11
|
+
/** Marks a host that runs local MCP servers; Overlay Desktop looks for it in the bundled host before offering them. */
|
|
12
|
+
export const LOCAL_MCP_FEATURE = 'overlay-private-local-mcp-servers';
|
|
13
|
+
const IDLE_MS = 10 * 60_000;
|
|
14
|
+
const START_TIMEOUT_MS = 60_000;
|
|
15
|
+
const MAX_TOOL_NAME = 64;
|
|
16
|
+
const STDERR_TAIL = 2_000;
|
|
17
|
+
export class LocalMcpServers {
|
|
18
|
+
options;
|
|
19
|
+
entries = new Map();
|
|
20
|
+
closed = false;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
/** Ids of the servers running now. */
|
|
25
|
+
running() {
|
|
26
|
+
return [...this.entries.values()].map(entry => entry.server.id);
|
|
27
|
+
}
|
|
28
|
+
/** The tools of these servers for one turn. A server that fails to start is left out and named in the instructions. */
|
|
29
|
+
async open(servers, options) {
|
|
30
|
+
const tools = {};
|
|
31
|
+
const used = [];
|
|
32
|
+
const failed = [];
|
|
33
|
+
const names = new Set();
|
|
34
|
+
const results = await Promise.all(servers.map(async (server) => {
|
|
35
|
+
const entry = this.acquire(server);
|
|
36
|
+
used.push(entry);
|
|
37
|
+
try {
|
|
38
|
+
return { server, connection: await untilAborted(entry.connection, options.signal) };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (!options.signal.aborted)
|
|
42
|
+
failed.push(`${server.name} (${errorText(error, entry)})`);
|
|
43
|
+
return { server, connection: null };
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
for (const { server, connection } of results) {
|
|
47
|
+
if (!connection)
|
|
48
|
+
continue;
|
|
49
|
+
for (const [name, definition] of Object.entries(connection.tools)) {
|
|
50
|
+
const toolName = uniqueName(localMcpToolName(server.name, name), names);
|
|
51
|
+
names.add(toolName);
|
|
52
|
+
tools[toolName] = asApprovedTool(definition, server.name, name, options.approvalMode);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let released = false;
|
|
56
|
+
const release = () => {
|
|
57
|
+
if (released)
|
|
58
|
+
return;
|
|
59
|
+
released = true;
|
|
60
|
+
for (const entry of used)
|
|
61
|
+
this.release(entry);
|
|
62
|
+
};
|
|
63
|
+
const prefixes = results.filter(result => result.connection).map(result => `${localMcpToolName(result.server.name, '')}*`);
|
|
64
|
+
const instructions = [
|
|
65
|
+
prefixes.length
|
|
66
|
+
? `Tools named ${prefixes.join(', ')} come from MCP servers the person runs on this computer. The person approves each call unless they chose Auto.`
|
|
67
|
+
: '',
|
|
68
|
+
failed.length ? `These MCP servers on this computer could not start for this turn: ${failed.join('; ')}.` : '',
|
|
69
|
+
].filter(Boolean).join('\n');
|
|
70
|
+
return { tools, instructions, release };
|
|
71
|
+
}
|
|
72
|
+
/** Starts a server (or reuses it) and lists its tools, for Settings. */
|
|
73
|
+
async check(server) {
|
|
74
|
+
const entry = this.acquire(server);
|
|
75
|
+
try {
|
|
76
|
+
const connection = await entry.connection.catch((error) => { throw new Error(errorText(error, entry)); });
|
|
77
|
+
return {
|
|
78
|
+
tools: Object.entries(connection.tools).map(([name, definition]) => ({ name, description: describe(definition).slice(0, 300) })),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
this.release(entry);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Stops a server now (it was removed or changed in Settings). Turns using it keep their tools until they end. */
|
|
86
|
+
async stop(serverId) {
|
|
87
|
+
const entry = this.entries.get(serverId);
|
|
88
|
+
if (!entry)
|
|
89
|
+
return false;
|
|
90
|
+
await this.close(entry);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
/** Stops every server: the host is quitting. */
|
|
94
|
+
async shutdown() {
|
|
95
|
+
this.closed = true;
|
|
96
|
+
await Promise.allSettled([...this.entries.values()].map(entry => this.close(entry)));
|
|
97
|
+
}
|
|
98
|
+
acquire(server) {
|
|
99
|
+
if (this.closed)
|
|
100
|
+
throw new Error('Private threads are stopping.');
|
|
101
|
+
const key = configKey(server);
|
|
102
|
+
let entry = this.entries.get(server.id);
|
|
103
|
+
if (entry && entry.key !== key) {
|
|
104
|
+
// Changed in Settings: the old process goes, the new one starts.
|
|
105
|
+
void this.close(entry);
|
|
106
|
+
entry = undefined;
|
|
107
|
+
}
|
|
108
|
+
if (!entry) {
|
|
109
|
+
const stderr = [];
|
|
110
|
+
const created = { key, server, users: 0, stderr, connection: Promise.resolve(null) };
|
|
111
|
+
created.connection = this.start(server, stderr);
|
|
112
|
+
// A server that fails to start is forgotten, so the next turn tries again.
|
|
113
|
+
created.connection.catch(() => { if (this.entries.get(server.id) === created)
|
|
114
|
+
this.entries.delete(server.id); });
|
|
115
|
+
this.entries.set(server.id, created);
|
|
116
|
+
entry = created;
|
|
117
|
+
}
|
|
118
|
+
if (entry.idle) {
|
|
119
|
+
clearTimeout(entry.idle);
|
|
120
|
+
entry.idle = undefined;
|
|
121
|
+
}
|
|
122
|
+
entry.users++;
|
|
123
|
+
return entry;
|
|
124
|
+
}
|
|
125
|
+
release(entry) {
|
|
126
|
+
entry.users = Math.max(0, entry.users - 1);
|
|
127
|
+
if (entry.users > 0 || this.entries.get(entry.server.id) !== entry)
|
|
128
|
+
return;
|
|
129
|
+
entry.idle = setTimeout(() => void this.close(entry), this.options.idleMs ?? IDLE_MS);
|
|
130
|
+
entry.idle.unref?.();
|
|
131
|
+
}
|
|
132
|
+
async close(entry) {
|
|
133
|
+
if (entry.idle)
|
|
134
|
+
clearTimeout(entry.idle);
|
|
135
|
+
if (this.entries.get(entry.server.id) === entry)
|
|
136
|
+
this.entries.delete(entry.server.id);
|
|
137
|
+
const connection = await entry.connection.catch(() => null);
|
|
138
|
+
await connection?.close().catch(() => undefined);
|
|
139
|
+
}
|
|
140
|
+
async start(server, stderr) {
|
|
141
|
+
const signal = AbortSignal.timeout(this.options.startTimeoutMs ?? START_TIMEOUT_MS);
|
|
142
|
+
const connect = this.options.connect ?? ((value, abort) => connectStdio(value, abort, (text) => {
|
|
143
|
+
stderr.push(text);
|
|
144
|
+
while (stderr.join('').length > STDERR_TAIL)
|
|
145
|
+
stderr.shift();
|
|
146
|
+
}));
|
|
147
|
+
const attempt = connect(server, signal);
|
|
148
|
+
const connection = await untilAborted(attempt, signal).catch((error) => {
|
|
149
|
+
if (!signal.aborted)
|
|
150
|
+
throw error;
|
|
151
|
+
// A connection that finishes after the deadline belongs to no entry, so nothing else would ever stop it.
|
|
152
|
+
attempt.then(late => late.close().catch(() => undefined), () => undefined);
|
|
153
|
+
throw new Error('it did not answer within a minute');
|
|
154
|
+
});
|
|
155
|
+
this.options.log?.(`Local MCP server ${server.name} started with ${Object.keys(connection.tools).length} tools.`);
|
|
156
|
+
return connection;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function connectStdio(server, signal, onStderr) {
|
|
160
|
+
const transport = new StdioClientTransport({
|
|
161
|
+
command: server.command,
|
|
162
|
+
args: server.args,
|
|
163
|
+
// Only the basics of this process's environment (home, user, PATH…), then what the person set for this server.
|
|
164
|
+
env: { ...getDefaultEnvironment(), ...server.env },
|
|
165
|
+
cwd: server.cwd ?? homedir(),
|
|
166
|
+
stderr: 'pipe',
|
|
167
|
+
});
|
|
168
|
+
transport.stderr?.on('data', (chunk) => onStderr(chunk.toString()));
|
|
169
|
+
// Past the deadline the process is stopped, so a slow tool listing fails instead of finishing unseen.
|
|
170
|
+
const stopAtDeadline = () => void transport.close().catch(() => undefined);
|
|
171
|
+
signal.addEventListener('abort', stopAtDeadline, { once: true });
|
|
172
|
+
let client = null;
|
|
173
|
+
try {
|
|
174
|
+
client = await createMCPClient({
|
|
175
|
+
transport: transport,
|
|
176
|
+
clientName: 'overlay-private-thread',
|
|
177
|
+
initializationOptions: { signal },
|
|
178
|
+
});
|
|
179
|
+
const connected = client;
|
|
180
|
+
const tools = await connected.tools();
|
|
181
|
+
signal.throwIfAborted();
|
|
182
|
+
signal.removeEventListener('abort', stopAtDeadline);
|
|
183
|
+
return {
|
|
184
|
+
tools,
|
|
185
|
+
...(connected.instructions?.trim() ? { instructions: connected.instructions.trim() } : {}),
|
|
186
|
+
close: async () => { await connected.close().catch(() => undefined); await transport.close().catch(() => undefined); },
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
signal.removeEventListener('abort', stopAtDeadline);
|
|
191
|
+
await client?.close().catch(() => undefined);
|
|
192
|
+
await transport.close().catch(() => undefined);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** `server__tool`, in the characters and length every model provider accepts for tool names. */
|
|
197
|
+
export function localMcpToolName(serverName, toolName) {
|
|
198
|
+
const clean = (value) => value.replace(/[^A-Za-z0-9_-]+/g, '_').replace(/^_+|_+$/g, '');
|
|
199
|
+
const server = (clean(serverName) || 'mcp').slice(0, 24);
|
|
200
|
+
return `${server}__${clean(toolName)}`.slice(0, MAX_TOOL_NAME);
|
|
201
|
+
}
|
|
202
|
+
function uniqueName(name, taken) {
|
|
203
|
+
if (!taken.has(name))
|
|
204
|
+
return name;
|
|
205
|
+
for (let index = 2;; index++) {
|
|
206
|
+
const candidate = `${name.slice(0, MAX_TOOL_NAME - 3)}_${index}`;
|
|
207
|
+
if (!taken.has(candidate))
|
|
208
|
+
return candidate;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A static tool (so the page shows its row and approval card like any other tool) that runs the server's tool. In Ask
|
|
213
|
+
* mode every call waits for the person: a local server can do anything its command can.
|
|
214
|
+
*/
|
|
215
|
+
function asApprovedTool(definition, serverName, toolName, approvalMode) {
|
|
216
|
+
const description = describe(definition) || toolName;
|
|
217
|
+
return {
|
|
218
|
+
...definition,
|
|
219
|
+
type: 'function',
|
|
220
|
+
description: `${description}\n(From the MCP server “${serverName}” on this computer.)`,
|
|
221
|
+
needsApproval: approvalMode === 'ask',
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function describe(definition) {
|
|
225
|
+
return typeof definition.description === 'string' ? definition.description.trim() : '';
|
|
226
|
+
}
|
|
227
|
+
function configKey(server) {
|
|
228
|
+
return createHash('sha256').update(JSON.stringify([server.command, server.args, server.cwd ?? null, Object.entries(server.env).sort()])).digest('hex');
|
|
229
|
+
}
|
|
230
|
+
/** What went wrong, without environment values, and with the end of the server's own error output. */
|
|
231
|
+
function errorText(error, entry) {
|
|
232
|
+
let message = error instanceof Error ? error.message : String(error);
|
|
233
|
+
if (/ENOENT/.test(message))
|
|
234
|
+
message = `${entry.server.command} was not found on this computer`;
|
|
235
|
+
const tail = entry.stderr.join('').trim().split(/\r?\n/).slice(-3).join(' ').trim();
|
|
236
|
+
let text = tail && !message.includes(tail) ? `${message}: ${tail}` : message;
|
|
237
|
+
for (const value of Object.values(entry.server.env)) {
|
|
238
|
+
if (value.length >= 4)
|
|
239
|
+
text = text.split(value).join('[hidden]');
|
|
240
|
+
}
|
|
241
|
+
return text.slice(0, 500);
|
|
242
|
+
}
|
|
243
|
+
function untilAborted(work, signal) {
|
|
244
|
+
if (signal.aborted)
|
|
245
|
+
return Promise.reject(signal.reason);
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
247
|
+
const abort = () => reject(signal.reason);
|
|
248
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
249
|
+
work.then(resolve, reject).finally(() => signal.removeEventListener('abort', abort));
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=private-threads-local-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-threads-local-mcp.js","sourceRoot":"","sources":["../src/private-threads-local-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,eAAe,EAAqC,MAAM,aAAa,CAAA;AAChF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAIvG;;;;;GAKG;AAEH,uHAAuH;AACvH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mCAAmC,CAAA;AAEpE,MAAM,OAAO,GAAG,EAAE,GAAG,MAAM,CAAA;AAC3B,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAC/B,MAAM,aAAa,GAAG,EAAE,CAAA;AACxB,MAAM,WAAW,GAAG,KAAK,CAAA;AAqBzB,MAAM,OAAO,eAAe;IAIG;IAHZ,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAA;IAC3C,MAAM,GAAG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EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACvD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IACtF,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
|
+
/**
|
|
3
|
+
* An Overlay-billed model in a private thread (internal/develop/private-threads.md). The loop stays on this computer;
|
|
4
|
+
* each call is sent to Overlay's metered relay with a short-lived token Overlay Desktop got for this person, workspace
|
|
5
|
+
* and agent. Overlay runs the call, charges the workspace, and keeps nothing of it.
|
|
6
|
+
*/
|
|
7
|
+
export type OverlayRelayAccess = {
|
|
8
|
+
url: string;
|
|
9
|
+
token: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class OverlayRelayError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly code?: string | undefined;
|
|
14
|
+
constructor(message: string, status: number, code?: string | undefined);
|
|
15
|
+
}
|
|
16
|
+
export declare function createOverlayRelayModel(modelId: string, access: OverlayRelayAccess, fetchImpl?: typeof fetch): LanguageModelV4;
|
|
17
|
+
//# sourceMappingURL=private-threads-overlay-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-threads-overlay-model.d.ts","sourceRoot":"","sources":["../src/private-threads-overlay-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,kBAAkB,CAAA;AAQzB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE/D,qBAAa,iBAAkB,SAAQ,KAAK;IACb,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;gBAAhE,OAAO,EAAE,MAAM,EAAW,MAAM,EAAE,MAAM,EAAW,IAAI,CAAC,EAAE,MAAM,YAAA;CAI7E;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,kBAAkB,EAC1B,SAAS,GAAE,OAAO,KAAa,GAC9B,eAAe,CAgCjB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { decodeRelayJson, encodeRelayJson, PRIVATE_MODEL_RELAY_VERSION, } from '@layernorm/overlay-agent-bridge-protocol';
|
|
2
|
+
export class OverlayRelayError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
constructor(message, status, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = 'OverlayRelayError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function createOverlayRelayModel(modelId, access, fetchImpl = fetch) {
|
|
13
|
+
const call = async (mode, options) => {
|
|
14
|
+
const { abortSignal, headers: _headers, ...rest } = options;
|
|
15
|
+
void _headers;
|
|
16
|
+
const request = { version: PRIVATE_MODEL_RELAY_VERSION, modelId, mode, options: rest };
|
|
17
|
+
const response = await fetchImpl(access.url, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: { authorization: `Bearer ${access.token}`, 'content-type': 'application/json' },
|
|
20
|
+
body: encodeRelayJson(request),
|
|
21
|
+
// The token goes only to the server the desktop named.
|
|
22
|
+
redirect: 'error',
|
|
23
|
+
...(abortSignal ? { signal: abortSignal } : {}),
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
throw await relayError(response);
|
|
27
|
+
return response;
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
specificationVersion: 'v4',
|
|
31
|
+
provider: 'overlay',
|
|
32
|
+
modelId,
|
|
33
|
+
// Overlay's server fetches nothing on the computer's behalf: the AI SDK downloads URLs here first.
|
|
34
|
+
supportedUrls: {},
|
|
35
|
+
async doGenerate(options) {
|
|
36
|
+
const response = await call('generate', options);
|
|
37
|
+
return decodeRelayJson(await response.text());
|
|
38
|
+
},
|
|
39
|
+
async doStream(options) {
|
|
40
|
+
const response = await call('stream', options);
|
|
41
|
+
if (!response.body)
|
|
42
|
+
throw new OverlayRelayError('Overlay sent no reply.', 502);
|
|
43
|
+
return { stream: response.body.pipeThrough(new TextDecoderStream()).pipeThrough(ndjsonParts()) };
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function relayError(response) {
|
|
48
|
+
let message = `Overlay's models answered ${response.status}.`;
|
|
49
|
+
let code;
|
|
50
|
+
try {
|
|
51
|
+
const body = await response.json();
|
|
52
|
+
if (typeof body.error === 'string' && body.error.trim())
|
|
53
|
+
message = body.error.trim().slice(0, 500);
|
|
54
|
+
if (typeof body.code === 'string')
|
|
55
|
+
code = body.code;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
/* Not JSON; keep the status. */
|
|
59
|
+
}
|
|
60
|
+
return new OverlayRelayError(message, response.status, code);
|
|
61
|
+
}
|
|
62
|
+
/** One JSON stream part per line; a line the relay could not finish becomes an error part. */
|
|
63
|
+
function ndjsonParts() {
|
|
64
|
+
let buffer = '';
|
|
65
|
+
const emit = (line, controller) => {
|
|
66
|
+
if (!line.trim())
|
|
67
|
+
return;
|
|
68
|
+
try {
|
|
69
|
+
controller.enqueue(decodeRelayJson(line));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
controller.enqueue({ type: 'error', error: new OverlayRelayError('Overlay sent a reply that could not be read.', 502) });
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return new TransformStream({
|
|
76
|
+
transform(chunk, controller) {
|
|
77
|
+
buffer += chunk;
|
|
78
|
+
let newline;
|
|
79
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
80
|
+
emit(buffer.slice(0, newline), controller);
|
|
81
|
+
buffer = buffer.slice(newline + 1);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
flush(controller) {
|
|
85
|
+
emit(buffer, controller);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=private-threads-overlay-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-threads-overlay-model.js","sourceRoot":"","sources":["../src/private-threads-overlay-model.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EACf,eAAe,EACf,2BAA2B,GAE5B,MAAM,0CAA0C,CAAA;AASjD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACJ;IAAyB;IAA/D,YAAY,OAAe,EAAW,MAAc,EAAW,IAAa;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAA;QADsB,WAAM,GAAN,MAAM,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAAS;QAE1E,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED,MAAM,UAAU,uBAAuB,CACrC,OAAe,EACf,MAA0B,EAC1B,YAA0B,KAAK;IAE/B,MAAM,IAAI,GAAG,KAAK,EAAE,IAAsC,EAAE,OAAmC,EAAqB,EAAE;QACpH,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;QAC3D,KAAK,QAAQ,CAAA;QACb,MAAM,OAAO,GAA6B,EAAE,OAAO,EAAE,2BAA2B,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAA+B,EAAE,CAAA;QAC3I,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE;YAC3C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YACxF,IAAI,EAAE,eA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CAAC,OAAO,GAAG,CAAC,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;QACD,KAAK,CAAC,UAAU;YACd,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QAC1B,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -21,8 +21,48 @@ export type PrivateThread = PrivateThreadOwner & {
|
|
|
21
21
|
createdAt: number;
|
|
22
22
|
updatedAt: number;
|
|
23
23
|
};
|
|
24
|
+
/** Providers called with the person's own API key. */
|
|
24
25
|
export declare const privateModelProviders: readonly ["anthropic", "openai", "google", "openrouter"];
|
|
25
26
|
export type PrivateModelProvider = (typeof privateModelProviders)[number];
|
|
27
|
+
/** How a private thread calls a model: a key, or Overlay's relay (`overlay`): its models or the agent's connection. */
|
|
28
|
+
export type PrivateModelSource = PrivateModelProvider | 'overlay';
|
|
29
|
+
/** Model sources this host can run; Overlay Desktop reads them from the `ready` message. */
|
|
30
|
+
export declare const PRIVATE_MODEL_SOURCES: readonly ["key", "overlay"];
|
|
31
|
+
/**
|
|
32
|
+
* How this turn calls its model. Secrets are read by Overlay Desktop for this run only and never stored by the host:
|
|
33
|
+
* a key from the Keychain, or a short-lived token for Overlay's model relay.
|
|
34
|
+
*/
|
|
35
|
+
declare const turnModel: z.ZodUnion<readonly [z.ZodObject<{
|
|
36
|
+
provider: z.ZodEnum<{
|
|
37
|
+
anthropic: "anthropic";
|
|
38
|
+
openai: "openai";
|
|
39
|
+
google: "google";
|
|
40
|
+
openrouter: "openrouter";
|
|
41
|
+
}>;
|
|
42
|
+
modelId: z.ZodString;
|
|
43
|
+
apiKey: z.ZodString;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
provider: z.ZodLiteral<"overlay">;
|
|
46
|
+
modelId: z.ZodString;
|
|
47
|
+
relay: z.ZodObject<{
|
|
48
|
+
url: z.ZodString;
|
|
49
|
+
token: z.ZodString;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
}, z.core.$strict>]>;
|
|
52
|
+
export type PrivateTurnModel = z.output<typeof turnModel>;
|
|
53
|
+
/**
|
|
54
|
+
* An MCP server that runs on this computer (stdio). Overlay Desktop keeps the list and reads the environment values
|
|
55
|
+
* from the Keychain for each turn; the host holds them in memory only while the server runs.
|
|
56
|
+
*/
|
|
57
|
+
export declare const localMcpServerSchema: z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
command: z.ZodString;
|
|
61
|
+
args: z.ZodArray<z.ZodString>;
|
|
62
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
63
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strict>;
|
|
65
|
+
export type LocalMcpServer = z.output<typeof localMcpServerSchema>;
|
|
26
66
|
export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
67
|
method: z.ZodLiteral<"list">;
|
|
28
68
|
owner: z.ZodObject<{
|
|
@@ -56,7 +96,7 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
56
96
|
threadId: z.ZodString;
|
|
57
97
|
turnId: z.ZodString;
|
|
58
98
|
messages: z.ZodArray<z.ZodCustom<PrivateUIMessage, PrivateUIMessage>>;
|
|
59
|
-
model: z.ZodObject<{
|
|
99
|
+
model: z.ZodUnion<readonly [z.ZodObject<{
|
|
60
100
|
provider: z.ZodEnum<{
|
|
61
101
|
anthropic: "anthropic";
|
|
62
102
|
openai: "openai";
|
|
@@ -65,7 +105,14 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
65
105
|
}>;
|
|
66
106
|
modelId: z.ZodString;
|
|
67
107
|
apiKey: z.ZodString;
|
|
68
|
-
}, z.core.$strict
|
|
108
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
109
|
+
provider: z.ZodLiteral<"overlay">;
|
|
110
|
+
modelId: z.ZodString;
|
|
111
|
+
relay: z.ZodObject<{
|
|
112
|
+
url: z.ZodString;
|
|
113
|
+
token: z.ZodString;
|
|
114
|
+
}, z.core.$strict>;
|
|
115
|
+
}, z.core.$strict>]>;
|
|
69
116
|
agent: z.ZodObject<{
|
|
70
117
|
name: z.ZodString;
|
|
71
118
|
instructions: z.ZodOptional<z.ZodString>;
|
|
@@ -79,6 +126,14 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
79
126
|
url: z.ZodString;
|
|
80
127
|
token: z.ZodString;
|
|
81
128
|
}, z.core.$strict>>;
|
|
129
|
+
localMcp: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
130
|
+
id: z.ZodString;
|
|
131
|
+
name: z.ZodString;
|
|
132
|
+
command: z.ZodString;
|
|
133
|
+
args: z.ZodArray<z.ZodString>;
|
|
134
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
135
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>>>;
|
|
82
137
|
}, z.core.$strict>, z.ZodObject<{
|
|
83
138
|
method: z.ZodLiteral<"stop">;
|
|
84
139
|
owner: z.ZodObject<{
|
|
@@ -111,6 +166,19 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
111
166
|
openrouter: "openrouter";
|
|
112
167
|
}>;
|
|
113
168
|
apiKey: z.ZodString;
|
|
169
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
170
|
+
method: z.ZodLiteral<"mcpCheck">;
|
|
171
|
+
server: z.ZodObject<{
|
|
172
|
+
id: z.ZodString;
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
command: z.ZodString;
|
|
175
|
+
args: z.ZodArray<z.ZodString>;
|
|
176
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
177
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
178
|
+
}, z.core.$strict>;
|
|
179
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
180
|
+
method: z.ZodLiteral<"mcpStop">;
|
|
181
|
+
serverId: z.ZodString;
|
|
114
182
|
}, z.core.$strict>], "method">;
|
|
115
183
|
export type PrivateRequest = z.input<typeof privateRequestSchema>;
|
|
116
184
|
export type ParsedPrivateRequest = z.output<typeof privateRequestSchema>;
|
|
@@ -145,6 +213,15 @@ export type PrivateResults = {
|
|
|
145
213
|
name: string;
|
|
146
214
|
}[];
|
|
147
215
|
};
|
|
216
|
+
mcpCheck: {
|
|
217
|
+
tools: {
|
|
218
|
+
name: string;
|
|
219
|
+
description: string;
|
|
220
|
+
}[];
|
|
221
|
+
};
|
|
222
|
+
mcpStop: {
|
|
223
|
+
stopped: boolean;
|
|
224
|
+
};
|
|
148
225
|
};
|
|
149
226
|
export type PrivateTurnState = 'running' | 'finished' | 'stopped' | 'error';
|
|
150
227
|
export type PrivateEvent = {
|
|
@@ -170,6 +247,8 @@ export type PrivateIpcInbound = {
|
|
|
170
247
|
export type PrivateIpcOutbound = {
|
|
171
248
|
type: 'ready';
|
|
172
249
|
protocolVersion: typeof PRIVATE_THREADS_PROTOCOL_VERSION;
|
|
250
|
+
modelSources: typeof PRIVATE_MODEL_SOURCES;
|
|
251
|
+
features?: string[];
|
|
173
252
|
} | {
|
|
174
253
|
type: 'response';
|
|
175
254
|
id: number;
|
|
@@ -184,4 +263,5 @@ export type PrivateIpcOutbound = {
|
|
|
184
263
|
type: 'event';
|
|
185
264
|
event: PrivateEvent;
|
|
186
265
|
};
|
|
266
|
+
export {};
|
|
187
267
|
//# sourceMappingURL=private-threads-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-threads-protocol.d.ts","sourceRoot":"","sources":["../src/private-threads-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AAEnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,eAAO,MA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AAE,MAAM,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAA;AACxF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,eAAe,EAAE,OAAO,gCAAgC,CAAC;IAAC,YAAY,EAAE,OAAO,qBAAqB,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5I;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,CAAA"}
|
|
@@ -6,10 +6,42 @@ import { z } from 'zod';
|
|
|
6
6
|
* the only outbound calls are to the model provider the person chose.
|
|
7
7
|
*/
|
|
8
8
|
export const PRIVATE_THREADS_PROTOCOL_VERSION = 1;
|
|
9
|
+
/** Providers called with the person's own API key. */
|
|
9
10
|
export const privateModelProviders = ['anthropic', 'openai', 'google', 'openrouter'];
|
|
11
|
+
/** Model sources this host can run; Overlay Desktop reads them from the `ready` message. */
|
|
12
|
+
export const PRIVATE_MODEL_SOURCES = ['key', 'overlay'];
|
|
10
13
|
const id = z.string().trim().min(1).max(200);
|
|
11
14
|
const owner = z.object({ userId: id, workspaceId: id }).strict();
|
|
12
15
|
const folder = z.string().trim().min(1).max(4096).refine(isAbsolute, 'Folders must be absolute paths.');
|
|
16
|
+
const modelId = z.string().trim().min(1).max(200);
|
|
17
|
+
const overlayOrigin = (message) => z.string().url().max(2_048)
|
|
18
|
+
.refine(value => /^https:\/\/|^http:\/\/(localhost|127\.0\.0\.1)(:|\/)/.test(value), message);
|
|
19
|
+
/**
|
|
20
|
+
* How this turn calls its model. Secrets are read by Overlay Desktop for this run only and never stored by the host:
|
|
21
|
+
* a key from the Keychain, or a short-lived token for Overlay's model relay.
|
|
22
|
+
*/
|
|
23
|
+
const turnModel = z.union([
|
|
24
|
+
z.object({ provider: z.enum(privateModelProviders), modelId, apiKey: z.string().min(1).max(4_096) }).strict(),
|
|
25
|
+
z.object({
|
|
26
|
+
provider: z.literal('overlay'),
|
|
27
|
+
/** An Overlay catalog id (`anthropic/claude-sonnet-4.6`) or the agent's connection (`byok/<connection>/<model>`). */
|
|
28
|
+
modelId,
|
|
29
|
+
relay: z.object({ url: overlayOrigin('Overlay models need https.'), token: z.string().min(1).max(4_096) }).strict(),
|
|
30
|
+
}).strict(),
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* An MCP server that runs on this computer (stdio). Overlay Desktop keeps the list and reads the environment values
|
|
34
|
+
* from the Keychain for each turn; the host holds them in memory only while the server runs.
|
|
35
|
+
*/
|
|
36
|
+
export const localMcpServerSchema = z.object({
|
|
37
|
+
id,
|
|
38
|
+
name: z.string().trim().min(1).max(100),
|
|
39
|
+
command: z.string().trim().min(1).max(4_096),
|
|
40
|
+
args: z.array(z.string().max(4_096)).max(100),
|
|
41
|
+
env: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).max(200), z.string().max(32_768))
|
|
42
|
+
.refine(value => Object.keys(value).length <= 100, 'Too many environment values.'),
|
|
43
|
+
cwd: folder.optional(),
|
|
44
|
+
}).strict();
|
|
13
45
|
export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
14
46
|
z.object({ method: z.literal('list'), owner }).strict(),
|
|
15
47
|
z.object({ method: z.literal('get'), owner, threadId: id }).strict(),
|
|
@@ -29,12 +61,7 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
29
61
|
turnId: id,
|
|
30
62
|
/** The whole transcript as the page holds it, ending with the new user message or approval answers. */
|
|
31
63
|
messages: z.array(z.custom(value => Boolean(value && typeof value === 'object'))).min(1).max(2_000),
|
|
32
|
-
model:
|
|
33
|
-
provider: z.enum(privateModelProviders),
|
|
34
|
-
modelId: z.string().trim().min(1).max(200),
|
|
35
|
-
/** Read from the Keychain by Overlay Desktop for this run; never stored by the host. */
|
|
36
|
-
apiKey: z.string().min(1).max(4_096),
|
|
37
|
-
}).strict(),
|
|
64
|
+
model: turnModel,
|
|
38
65
|
agent: z.object({
|
|
39
66
|
name: z.string().trim().min(1).max(200),
|
|
40
67
|
instructions: z.string().max(50_000).optional(),
|
|
@@ -48,9 +75,11 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
48
75
|
* computer's tools.
|
|
49
76
|
*/
|
|
50
77
|
overlay: z.object({
|
|
51
|
-
url:
|
|
78
|
+
url: overlayOrigin('Overlay tools need https.'),
|
|
52
79
|
token: z.string().min(1).max(4_096),
|
|
53
80
|
}).strict().optional(),
|
|
81
|
+
/** MCP servers on this computer whose tools join this turn, when the agent's grant includes MCP servers. */
|
|
82
|
+
localMcp: z.array(localMcpServerSchema).max(20).optional(),
|
|
54
83
|
}).strict(),
|
|
55
84
|
z.object({ method: z.literal('stop'), owner, threadId: id }).strict(),
|
|
56
85
|
z.object({
|
|
@@ -61,6 +90,14 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
61
90
|
}).strict(),
|
|
62
91
|
z.object({ method: z.literal('delete'), owner, threadId: id }).strict(),
|
|
63
92
|
/** Checks a key and lists the chat models it can use. */
|
|
64
|
-
z.object({
|
|
93
|
+
z.object({
|
|
94
|
+
method: z.literal('models'),
|
|
95
|
+
provider: z.enum(privateModelProviders),
|
|
96
|
+
apiKey: z.string().min(1).max(4_096),
|
|
97
|
+
}).strict(),
|
|
98
|
+
/** Starts a local MCP server (or reuses it) and lists its tools, so Settings can show that it works. */
|
|
99
|
+
z.object({ method: z.literal('mcpCheck'), server: localMcpServerSchema }).strict(),
|
|
100
|
+
/** Stops a local MCP server that was removed or changed. */
|
|
101
|
+
z.object({ method: z.literal('mcpStop'), serverId: id }).strict(),
|
|
65
102
|
]);
|
|
66
103
|
//# sourceMappingURL=private-threads-protocol.js.map
|