@layernorm/overlay-agent-host 0.7.0 → 0.8.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 +10 -2
- 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/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-models.d.ts +9 -1
- package/dist/private-threads-models.d.ts.map +1 -1
- package/dist/private-threads-models.js +20 -0
- package/dist/private-threads-models.js.map +1 -1
- 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 +112 -3
- package/dist/private-threads-protocol.d.ts.map +1 -1
- package/dist/private-threads-protocol.js +60 -9
- package/dist/private-threads-protocol.js.map +1 -1
- package/dist/private-threads.d.ts +12 -5
- package/dist/private-threads.d.ts.map +1 -1
- package/dist/private-threads.js +59 -17
- package/dist/private-threads.js.map +1 -1
- package/package.json +9 -8
|
@@ -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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GAAG,EAAE,CAAA;IACf,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,UAAuE,EAAE,EAAE;QACrG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,OAAM;QACxB,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,CAAC,eAAe,CAA4B,IAAI,CAAC,CAAC,CAAA;QACtE,CAAC;QAAC,MAAM,CAAC;YACP,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,iBAAiB,CAAC,8CAA8C,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;QAC1H,CAAC;IACH,CAAC,CAAA;IACD,OAAO,IAAI,eAAe,CAAC;QACzB,SAAS,CAAC,KAAK,EAAE,UAAU;YACzB,MAAM,IAAI,KAAK,CAAA;YACf,IAAI,OAAe,CAAA;YACnB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAA;gBAC1C,MAAM,GAAG,MAAM,CAAC,KAAK,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,61 @@ 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
|
+
/** Plans the person signed in to on this computer, called through Overlay Desktop's local CLIProxyAPI. */
|
|
28
|
+
export declare const privatePlanProviders: readonly ["claude", "chatgpt"];
|
|
29
|
+
export type PrivatePlanProvider = (typeof privatePlanProviders)[number];
|
|
30
|
+
/** Every way a private thread can call a model: a key, a plan, or Overlay's metered models (`overlay`). */
|
|
31
|
+
export type PrivateModelSource = PrivateModelProvider | PrivatePlanProvider | 'overlay';
|
|
32
|
+
/** Model sources this host can run; Overlay Desktop reads them from the `ready` message. */
|
|
33
|
+
export declare const PRIVATE_MODEL_SOURCES: readonly ["key", "plan", "overlay"];
|
|
34
|
+
/**
|
|
35
|
+
* How this turn calls its model. Secrets are read by Overlay Desktop for this run only and never stored by the host:
|
|
36
|
+
* a key from the Keychain, the local plan proxy's secret, or a short-lived token for Overlay's metered relay.
|
|
37
|
+
*/
|
|
38
|
+
declare const turnModel: z.ZodUnion<readonly [z.ZodObject<{
|
|
39
|
+
provider: z.ZodEnum<{
|
|
40
|
+
anthropic: "anthropic";
|
|
41
|
+
openai: "openai";
|
|
42
|
+
google: "google";
|
|
43
|
+
openrouter: "openrouter";
|
|
44
|
+
}>;
|
|
45
|
+
modelId: z.ZodString;
|
|
46
|
+
apiKey: z.ZodString;
|
|
47
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
48
|
+
provider: z.ZodEnum<{
|
|
49
|
+
claude: "claude";
|
|
50
|
+
chatgpt: "chatgpt";
|
|
51
|
+
}>;
|
|
52
|
+
modelId: z.ZodString;
|
|
53
|
+
proxy: z.ZodObject<{
|
|
54
|
+
url: z.ZodString;
|
|
55
|
+
key: z.ZodString;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
58
|
+
provider: z.ZodLiteral<"overlay">;
|
|
59
|
+
modelId: z.ZodString;
|
|
60
|
+
relay: z.ZodObject<{
|
|
61
|
+
url: z.ZodString;
|
|
62
|
+
token: z.ZodString;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
}, z.core.$strict>]>;
|
|
65
|
+
export type PrivateTurnModel = z.output<typeof turnModel>;
|
|
66
|
+
/**
|
|
67
|
+
* An MCP server that runs on this computer (stdio). Overlay Desktop keeps the list and reads the environment values
|
|
68
|
+
* from the Keychain for each turn; the host holds them in memory only while the server runs.
|
|
69
|
+
*/
|
|
70
|
+
export declare const localMcpServerSchema: z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
name: z.ZodString;
|
|
73
|
+
command: z.ZodString;
|
|
74
|
+
args: z.ZodArray<z.ZodString>;
|
|
75
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
76
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type LocalMcpServer = z.output<typeof localMcpServerSchema>;
|
|
26
79
|
export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
80
|
method: z.ZodLiteral<"list">;
|
|
28
81
|
owner: z.ZodObject<{
|
|
@@ -56,7 +109,7 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
56
109
|
threadId: z.ZodString;
|
|
57
110
|
turnId: z.ZodString;
|
|
58
111
|
messages: z.ZodArray<z.ZodCustom<PrivateUIMessage, PrivateUIMessage>>;
|
|
59
|
-
model: z.ZodObject<{
|
|
112
|
+
model: z.ZodUnion<readonly [z.ZodObject<{
|
|
60
113
|
provider: z.ZodEnum<{
|
|
61
114
|
anthropic: "anthropic";
|
|
62
115
|
openai: "openai";
|
|
@@ -65,7 +118,24 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
65
118
|
}>;
|
|
66
119
|
modelId: z.ZodString;
|
|
67
120
|
apiKey: z.ZodString;
|
|
68
|
-
}, z.core.$strict
|
|
121
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
122
|
+
provider: z.ZodEnum<{
|
|
123
|
+
claude: "claude";
|
|
124
|
+
chatgpt: "chatgpt";
|
|
125
|
+
}>;
|
|
126
|
+
modelId: z.ZodString;
|
|
127
|
+
proxy: z.ZodObject<{
|
|
128
|
+
url: z.ZodString;
|
|
129
|
+
key: z.ZodString;
|
|
130
|
+
}, z.core.$strict>;
|
|
131
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
132
|
+
provider: z.ZodLiteral<"overlay">;
|
|
133
|
+
modelId: z.ZodString;
|
|
134
|
+
relay: z.ZodObject<{
|
|
135
|
+
url: z.ZodString;
|
|
136
|
+
token: z.ZodString;
|
|
137
|
+
}, z.core.$strict>;
|
|
138
|
+
}, z.core.$strict>]>;
|
|
69
139
|
agent: z.ZodObject<{
|
|
70
140
|
name: z.ZodString;
|
|
71
141
|
instructions: z.ZodOptional<z.ZodString>;
|
|
@@ -79,6 +149,14 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
79
149
|
url: z.ZodString;
|
|
80
150
|
token: z.ZodString;
|
|
81
151
|
}, z.core.$strict>>;
|
|
152
|
+
localMcp: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
153
|
+
id: z.ZodString;
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
command: z.ZodString;
|
|
156
|
+
args: z.ZodArray<z.ZodString>;
|
|
157
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
158
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strict>>>;
|
|
82
160
|
}, z.core.$strict>, z.ZodObject<{
|
|
83
161
|
method: z.ZodLiteral<"stop">;
|
|
84
162
|
owner: z.ZodObject<{
|
|
@@ -109,8 +187,27 @@ export declare const privateRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
109
187
|
openai: "openai";
|
|
110
188
|
google: "google";
|
|
111
189
|
openrouter: "openrouter";
|
|
190
|
+
claude: "claude";
|
|
191
|
+
chatgpt: "chatgpt";
|
|
112
192
|
}>;
|
|
113
|
-
apiKey: z.ZodString
|
|
193
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
194
|
+
proxy: z.ZodOptional<z.ZodObject<{
|
|
195
|
+
url: z.ZodString;
|
|
196
|
+
key: z.ZodString;
|
|
197
|
+
}, z.core.$strict>>;
|
|
198
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
199
|
+
method: z.ZodLiteral<"mcpCheck">;
|
|
200
|
+
server: z.ZodObject<{
|
|
201
|
+
id: z.ZodString;
|
|
202
|
+
name: z.ZodString;
|
|
203
|
+
command: z.ZodString;
|
|
204
|
+
args: z.ZodArray<z.ZodString>;
|
|
205
|
+
env: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
206
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
207
|
+
}, z.core.$strict>;
|
|
208
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
209
|
+
method: z.ZodLiteral<"mcpStop">;
|
|
210
|
+
serverId: z.ZodString;
|
|
114
211
|
}, z.core.$strict>], "method">;
|
|
115
212
|
export type PrivateRequest = z.input<typeof privateRequestSchema>;
|
|
116
213
|
export type ParsedPrivateRequest = z.output<typeof privateRequestSchema>;
|
|
@@ -145,6 +242,15 @@ export type PrivateResults = {
|
|
|
145
242
|
name: string;
|
|
146
243
|
}[];
|
|
147
244
|
};
|
|
245
|
+
mcpCheck: {
|
|
246
|
+
tools: {
|
|
247
|
+
name: string;
|
|
248
|
+
description: string;
|
|
249
|
+
}[];
|
|
250
|
+
};
|
|
251
|
+
mcpStop: {
|
|
252
|
+
stopped: boolean;
|
|
253
|
+
};
|
|
148
254
|
};
|
|
149
255
|
export type PrivateTurnState = 'running' | 'finished' | 'stopped' | 'error';
|
|
150
256
|
export type PrivateEvent = {
|
|
@@ -170,6 +276,8 @@ export type PrivateIpcInbound = {
|
|
|
170
276
|
export type PrivateIpcOutbound = {
|
|
171
277
|
type: 'ready';
|
|
172
278
|
protocolVersion: typeof PRIVATE_THREADS_PROTOCOL_VERSION;
|
|
279
|
+
modelSources: typeof PRIVATE_MODEL_SOURCES;
|
|
280
|
+
features?: string[];
|
|
173
281
|
} | {
|
|
174
282
|
type: 'response';
|
|
175
283
|
id: number;
|
|
@@ -184,4 +292,5 @@ export type PrivateIpcOutbound = {
|
|
|
184
292
|
type: 'event';
|
|
185
293
|
event: PrivateEvent;
|
|
186
294
|
};
|
|
295
|
+
export {};
|
|
187
296
|
//# 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,MAAM,gCAAgC,EAAG,CAAU,CAAA;AAE1D,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAA;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AACxE,MAAM,MAAM,aAAa,GAAG,kBAAkB,GAAG;IAC/C,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,mEAAmE;IACnE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,qBAAqB,0DAA2D,CAAA;AAC7F,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAA;
|
|
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,MA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K,EAAE,YAAY,CAAA;CAAE,CAAA"}
|
|
@@ -6,10 +6,50 @@ 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
|
+
/** Plans the person signed in to on this computer, called through Overlay Desktop's local CLIProxyAPI. */
|
|
12
|
+
export const privatePlanProviders = ['claude', 'chatgpt'];
|
|
13
|
+
/** Model sources this host can run; Overlay Desktop reads them from the `ready` message. */
|
|
14
|
+
export const PRIVATE_MODEL_SOURCES = ['key', 'plan', 'overlay'];
|
|
10
15
|
const id = z.string().trim().min(1).max(200);
|
|
11
16
|
const owner = z.object({ userId: id, workspaceId: id }).strict();
|
|
12
17
|
const folder = z.string().trim().min(1).max(4096).refine(isAbsolute, 'Folders must be absolute paths.');
|
|
18
|
+
const modelId = z.string().trim().min(1).max(200);
|
|
19
|
+
/** The desktop's own CLIProxyAPI: loopback only, with the secret it made at launch. */
|
|
20
|
+
const planProxy = z.object({
|
|
21
|
+
url: z.string().url().max(200).refine(value => /^http:\/\/127\.0\.0\.1:\d{1,5}$/.test(value), 'The plan proxy must be on this computer.'),
|
|
22
|
+
key: z.string().min(16).max(512),
|
|
23
|
+
}).strict();
|
|
24
|
+
const overlayOrigin = (message) => z.string().url().max(2_048)
|
|
25
|
+
.refine(value => /^https:\/\/|^http:\/\/(localhost|127\.0\.0\.1)(:|\/)/.test(value), message);
|
|
26
|
+
/**
|
|
27
|
+
* How this turn calls its model. Secrets are read by Overlay Desktop for this run only and never stored by the host:
|
|
28
|
+
* a key from the Keychain, the local plan proxy's secret, or a short-lived token for Overlay's metered relay.
|
|
29
|
+
*/
|
|
30
|
+
const turnModel = z.union([
|
|
31
|
+
z.object({ provider: z.enum(privateModelProviders), modelId, apiKey: z.string().min(1).max(4_096) }).strict(),
|
|
32
|
+
z.object({ provider: z.enum(privatePlanProviders), modelId, proxy: planProxy }).strict(),
|
|
33
|
+
z.object({
|
|
34
|
+
provider: z.literal('overlay'),
|
|
35
|
+
/** An Overlay catalog id, for example `anthropic/claude-sonnet-4.6`. */
|
|
36
|
+
modelId,
|
|
37
|
+
relay: z.object({ url: overlayOrigin('Overlay models need https.'), token: z.string().min(1).max(4_096) }).strict(),
|
|
38
|
+
}).strict(),
|
|
39
|
+
]);
|
|
40
|
+
/**
|
|
41
|
+
* An MCP server that runs on this computer (stdio). Overlay Desktop keeps the list and reads the environment values
|
|
42
|
+
* from the Keychain for each turn; the host holds them in memory only while the server runs.
|
|
43
|
+
*/
|
|
44
|
+
export const localMcpServerSchema = z.object({
|
|
45
|
+
id,
|
|
46
|
+
name: z.string().trim().min(1).max(100),
|
|
47
|
+
command: z.string().trim().min(1).max(4_096),
|
|
48
|
+
args: z.array(z.string().max(4_096)).max(100),
|
|
49
|
+
env: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).max(200), z.string().max(32_768))
|
|
50
|
+
.refine(value => Object.keys(value).length <= 100, 'Too many environment values.'),
|
|
51
|
+
cwd: folder.optional(),
|
|
52
|
+
}).strict();
|
|
13
53
|
export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
14
54
|
z.object({ method: z.literal('list'), owner }).strict(),
|
|
15
55
|
z.object({ method: z.literal('get'), owner, threadId: id }).strict(),
|
|
@@ -29,12 +69,7 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
29
69
|
turnId: id,
|
|
30
70
|
/** The whole transcript as the page holds it, ending with the new user message or approval answers. */
|
|
31
71
|
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(),
|
|
72
|
+
model: turnModel,
|
|
38
73
|
agent: z.object({
|
|
39
74
|
name: z.string().trim().min(1).max(200),
|
|
40
75
|
instructions: z.string().max(50_000).optional(),
|
|
@@ -48,9 +83,11 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
48
83
|
* computer's tools.
|
|
49
84
|
*/
|
|
50
85
|
overlay: z.object({
|
|
51
|
-
url:
|
|
86
|
+
url: overlayOrigin('Overlay tools need https.'),
|
|
52
87
|
token: z.string().min(1).max(4_096),
|
|
53
88
|
}).strict().optional(),
|
|
89
|
+
/** MCP servers on this computer whose tools join this turn, when the agent's grant includes MCP servers. */
|
|
90
|
+
localMcp: z.array(localMcpServerSchema).max(20).optional(),
|
|
54
91
|
}).strict(),
|
|
55
92
|
z.object({ method: z.literal('stop'), owner, threadId: id }).strict(),
|
|
56
93
|
z.object({
|
|
@@ -60,7 +97,21 @@ export const privateRequestSchema = z.discriminatedUnion('method', [
|
|
|
60
97
|
folder: folder.nullable().optional(),
|
|
61
98
|
}).strict(),
|
|
62
99
|
z.object({ method: z.literal('delete'), owner, threadId: id }).strict(),
|
|
63
|
-
/** Checks a key and lists the chat models it can use. */
|
|
64
|
-
z.object({
|
|
100
|
+
/** Checks a key, or a signed-in plan through the local proxy, and lists the chat models it can use. */
|
|
101
|
+
z.object({
|
|
102
|
+
method: z.literal('models'),
|
|
103
|
+
provider: z.enum([...privateModelProviders, ...privatePlanProviders]),
|
|
104
|
+
apiKey: z.string().min(1).max(4_096).optional(),
|
|
105
|
+
proxy: planProxy.optional(),
|
|
106
|
+
}).strict().superRefine((value, context) => {
|
|
107
|
+
const plan = privatePlanProviders.includes(value.provider);
|
|
108
|
+
if (plan ? !value.proxy || value.apiKey : !value.apiKey || value.proxy) {
|
|
109
|
+
context.addIssue({ code: 'custom', message: plan ? 'A plan is listed through the local proxy.' : 'A key is needed.' });
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
/** Starts a local MCP server (or reuses it) and lists its tools, so Settings can show that it works. */
|
|
113
|
+
z.object({ method: z.literal('mcpCheck'), server: localMcpServerSchema }).strict(),
|
|
114
|
+
/** Stops a local MCP server that was removed or changed. */
|
|
115
|
+
z.object({ method: z.literal('mcpStop'), serverId: id }).strict(),
|
|
65
116
|
]);
|
|
66
117
|
//# sourceMappingURL=private-threads-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-threads-protocol.js","sourceRoot":"","sources":["../src/private-threads-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAU,CAAA;AAe1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"private-threads-protocol.js","sourceRoot":"","sources":["../src/private-threads-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAU,CAAA;AAe1D,sDAAsD;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAU,CAAA;AAE7F,0GAA0G;AAC1G,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAU,CAAA;AAKlE,4FAA4F;AAC5F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAU,CAAA;AAExE,MAAM,EAAE,GAAG,CAAC,CAAC,MAA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C,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACjF,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACvE,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAA;QACxH,CAAC;IACH,CAAC,CAAC;IACF,wGAAwG;IACxG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE;IAClF,4DAA4D;IAC5D,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CAClE,CAAC,CAAA"}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { type LanguageModel } from 'ai';
|
|
2
|
-
import { listProviderModels } from './private-threads-models.js';
|
|
2
|
+
import { listPlanModels, listProviderModels } from './private-threads-models.js';
|
|
3
3
|
import { connectOverlayTools } from './private-threads-overlay-tools.js';
|
|
4
|
+
import { LocalMcpServers } from './private-threads-local-mcp.js';
|
|
4
5
|
import { PrivateThreadStore } from './private-threads-store.js';
|
|
5
|
-
import { type PrivateEvent, type
|
|
6
|
+
import { type PrivateEvent, type PrivateRequest, type PrivateTurnModel, type PrivateResults, type PrivateUIMessage } from './private-threads-protocol.js';
|
|
6
7
|
export type PrivateThreadServiceOptions = {
|
|
7
8
|
store: PrivateThreadStore;
|
|
8
9
|
/** Holds terminal sessions and the browser profile of private runs. */
|
|
9
10
|
stateDirectory: string;
|
|
10
11
|
emit: (event: PrivateEvent) => void;
|
|
11
|
-
/** Tests replace the model; production builds it from the person's key. */
|
|
12
|
-
createModel?: (
|
|
12
|
+
/** Tests replace the model; production builds it from the person's key, plan or Overlay's relay. */
|
|
13
|
+
createModel?: (model: PrivateTurnModel) => LanguageModel;
|
|
13
14
|
listModels?: typeof listProviderModels;
|
|
15
|
+
listPlanModels?: typeof listPlanModels;
|
|
14
16
|
/** Tests replace the connection to Overlay's MCP server. */
|
|
15
17
|
connectOverlayTools?: typeof connectOverlayTools;
|
|
16
18
|
/** Tests shrink the context window to exercise compaction. */
|
|
17
19
|
contextWindow?: number;
|
|
20
|
+
/** MCP servers on this computer; tests pass one with a fixture server or a fake connection. */
|
|
21
|
+
localMcp?: LocalMcpServers;
|
|
18
22
|
log?: (message: string) => void;
|
|
19
23
|
};
|
|
20
24
|
/**
|
|
@@ -25,10 +29,13 @@ export type PrivateThreadServiceOptions = {
|
|
|
25
29
|
export declare class PrivateThreadService {
|
|
26
30
|
private readonly options;
|
|
27
31
|
private readonly runs;
|
|
32
|
+
private readonly localMcp;
|
|
28
33
|
constructor(options: PrivateThreadServiceOptions);
|
|
29
34
|
handle<M extends PrivateRequest['method']>(input: PrivateRequest & {
|
|
30
35
|
method: M;
|
|
31
36
|
}): Promise<PrivateResults[M]>;
|
|
37
|
+
/** A signed-in plan is listed through the local proxy; a provider with the person's key. */
|
|
38
|
+
private listModels;
|
|
32
39
|
private dispatch;
|
|
33
40
|
private send;
|
|
34
41
|
private execute;
|
|
@@ -37,7 +44,7 @@ export declare class PrivateThreadService {
|
|
|
37
44
|
/** Stops every run; their transcripts are already saved up to the last step. */
|
|
38
45
|
shutdown(): Promise<void>;
|
|
39
46
|
}
|
|
40
|
-
export declare function createModel(
|
|
47
|
+
export declare function createModel(model: PrivateTurnModel): LanguageModel;
|
|
41
48
|
/**
|
|
42
49
|
* Drops screenshot images from finished turns; the tool row keeps its size and the model is told to take a new one.
|
|
43
50
|
* `keepLast` keeps the images of a turn that is continuing (an approval answered mid-turn).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-threads.d.ts","sourceRoot":"","sources":["../src/private-threads.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"private-threads.d.ts","sourceRoot":"","sources":["../src/private-threads.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,aAAa,EAGnB,MAAM,IAAI,CAAA;AAEX,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAShF,OAAO,EAAE,mBAAmB,EAAiD,MAAM,oCAAoC,CAAA;AACvH,OAAO,EAAE,eAAe,EAAqB,MAAM,gCAAgC,CAAA;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,+BAA+B,CAAA;AAQtC,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,kBAAkB,CAAA;IACzB,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACnC,oGAAoG;IACpG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,aAAa,CAAA;IACxD,UAAU,CAAC,EAAE,OAAO,kBAAkB,CAAA;IACtC,cAAc,CAAC,EAAE,OAAO,cAAc,CAAA;IACtC,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAA;IAChD,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAChC,CAAA;AAED;;;;GAIG;AACH,qBAAa,oBAAoB;IAInB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;gBAEb,OAAO,EAAE,2BAA2B;IAI3D,MAAM,CAAC,CAAC,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAKnH,4FAA4F;YAC9E,UAAU;YAOV,QAAQ;IAyDtB,OAAO,CAAC,IAAI;YAuBE,OAAO;IA+DrB,4EAA4E;YAC9D,OAAO;IAyBrB,gFAAgF;IAC1E,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAKhC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAYlE;AA2BD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,gBAAgB,EAAE,CAcxH;AA+BD,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEzE"}
|
package/dist/private-threads.js
CHANGED
|
@@ -6,9 +6,11 @@ import { createOpenAI } from '@ai-sdk/openai';
|
|
|
6
6
|
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
7
7
|
import { ToolLoopAgent, createAgentUIStream, isStepCount, readUIMessageStream, } from 'ai';
|
|
8
8
|
import { LocalToolExecutor } from './local-tools.js';
|
|
9
|
-
import { listProviderModels } from './private-threads-models.js';
|
|
9
|
+
import { listPlanModels, listProviderModels } from './private-threads-models.js';
|
|
10
|
+
import { createOverlayRelayModel } from './private-threads-overlay-model.js';
|
|
10
11
|
import { contextWindowFor, createContextCompaction, instructionsWithSummary, messagesAfterSummary, summaryBoundary, } from './private-threads-context.js';
|
|
11
12
|
import { connectOverlayTools, withOverlayTools } from './private-threads-overlay-tools.js';
|
|
13
|
+
import { LocalMcpServers } from './private-threads-local-mcp.js';
|
|
12
14
|
import { privateComputerTools, SCREENSHOT_NOT_KEPT } from './private-threads-tools.js';
|
|
13
15
|
import { privateRequestSchema, } from './private-threads-protocol.js';
|
|
14
16
|
const MAX_STEPS = 60;
|
|
@@ -21,13 +23,22 @@ const DEFAULT_TITLE = 'New thread';
|
|
|
21
23
|
export class PrivateThreadService {
|
|
22
24
|
options;
|
|
23
25
|
runs = new Map();
|
|
26
|
+
localMcp;
|
|
24
27
|
constructor(options) {
|
|
25
28
|
this.options = options;
|
|
29
|
+
this.localMcp = options.localMcp ?? new LocalMcpServers({ log: options.log });
|
|
26
30
|
}
|
|
27
31
|
async handle(input) {
|
|
28
32
|
const request = privateRequestSchema.parse(input);
|
|
29
33
|
return await this.dispatch(request);
|
|
30
34
|
}
|
|
35
|
+
/** A signed-in plan is listed through the local proxy; a provider with the person's key. */
|
|
36
|
+
async listModels(request) {
|
|
37
|
+
if (request.provider === 'claude' || request.provider === 'chatgpt') {
|
|
38
|
+
return await (this.options.listPlanModels ?? listPlanModels)(request.provider, request.proxy);
|
|
39
|
+
}
|
|
40
|
+
return await (this.options.listModels ?? listProviderModels)(request.provider, request.apiKey);
|
|
41
|
+
}
|
|
31
42
|
async dispatch(request) {
|
|
32
43
|
const { store } = this.options;
|
|
33
44
|
switch (request.method) {
|
|
@@ -85,7 +96,11 @@ export class PrivateThreadService {
|
|
|
85
96
|
return { deleted };
|
|
86
97
|
}
|
|
87
98
|
case 'models':
|
|
88
|
-
return { models: await
|
|
99
|
+
return { models: await this.listModels(request) };
|
|
100
|
+
case 'mcpCheck':
|
|
101
|
+
return await this.localMcp.check(request.server);
|
|
102
|
+
case 'mcpStop':
|
|
103
|
+
return { stopped: await this.localMcp.stop(request.serverId) };
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
send(request) {
|
|
@@ -122,14 +137,19 @@ export class PrivateThreadService {
|
|
|
122
137
|
});
|
|
123
138
|
let failure;
|
|
124
139
|
let overlay = null;
|
|
140
|
+
let localMcp = null;
|
|
125
141
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
;
|
|
143
|
+
[overlay, localMcp] = await Promise.all([
|
|
144
|
+
(this.options.connectOverlayTools ?? connectOverlayTools)(request.overlay, {
|
|
145
|
+
signal,
|
|
146
|
+
onUnavailable: (reason) => this.options.log?.(`Overlay tools unavailable for this turn: ${publicError(reason)}`),
|
|
147
|
+
}),
|
|
148
|
+
request.localMcp?.length ? this.localMcp.open(request.localMcp, { signal, approvalMode: request.approvalMode }) : null,
|
|
149
|
+
]);
|
|
150
|
+
const model = (this.options.createModel ?? createModel)(request.model);
|
|
151
|
+
const instructions = instructionsFor(request, overlay, localMcp);
|
|
152
|
+
const tools = withLocalMcpTools(withOverlayTools(privateComputerTools({ executor, approvalMode: request.approvalMode, abortSignal: signal }), overlay), localMcp);
|
|
133
153
|
const saved = this.options.store.summary(threadId);
|
|
134
154
|
const agent = new ToolLoopAgent({
|
|
135
155
|
model,
|
|
@@ -169,6 +189,7 @@ export class PrivateThreadService {
|
|
|
169
189
|
failure = publicError(error);
|
|
170
190
|
}
|
|
171
191
|
finally {
|
|
192
|
+
localMcp?.release();
|
|
172
193
|
await Promise.all([executor.shutdown().catch(() => undefined), overlay?.close()]);
|
|
173
194
|
}
|
|
174
195
|
emit({ kind: 'turn', threadId, turnId, state: signal.aborted ? 'stopped' : failure ? 'error' : 'finished', ...(failure ? { error: failure } : {}) });
|
|
@@ -210,17 +231,33 @@ export class PrivateThreadService {
|
|
|
210
231
|
for (const run of this.runs.values())
|
|
211
232
|
run.controller.abort();
|
|
212
233
|
await Promise.allSettled([...this.runs.values()].map(run => run.done));
|
|
234
|
+
await this.localMcp.shutdown();
|
|
213
235
|
}
|
|
214
236
|
}
|
|
215
|
-
export function createModel(
|
|
216
|
-
switch (provider) {
|
|
217
|
-
case 'anthropic': return createAnthropic({ apiKey })(modelId);
|
|
218
|
-
case 'openai': return createOpenAI({ apiKey })(modelId);
|
|
219
|
-
case 'google': return createGoogleGenerativeAI({ apiKey })(modelId);
|
|
220
|
-
case 'openrouter': return createOpenRouter({ apiKey })(modelId);
|
|
237
|
+
export function createModel(model) {
|
|
238
|
+
switch (model.provider) {
|
|
239
|
+
case 'anthropic': return createAnthropic({ apiKey: model.apiKey })(model.modelId);
|
|
240
|
+
case 'openai': return createOpenAI({ apiKey: model.apiKey })(model.modelId);
|
|
241
|
+
case 'google': return createGoogleGenerativeAI({ apiKey: model.apiKey })(model.modelId);
|
|
242
|
+
case 'openrouter': return createOpenRouter({ apiKey: model.apiKey })(model.modelId);
|
|
243
|
+
// A signed-in plan, through Overlay Desktop's CLIProxyAPI on this computer: Claude speaks Anthropic's Messages API
|
|
244
|
+
// and ChatGPT (Codex) OpenAI's Responses API there.
|
|
245
|
+
case 'claude': return createAnthropic({ baseURL: `${model.proxy.url}/v1`, apiKey: model.proxy.key })(model.modelId);
|
|
246
|
+
case 'chatgpt': return createOpenAI({ baseURL: `${model.proxy.url}/v1`, apiKey: model.proxy.key }).responses(model.modelId);
|
|
247
|
+
case 'overlay': return createOverlayRelayModel(model.modelId, model.relay);
|
|
221
248
|
}
|
|
222
249
|
}
|
|
223
|
-
|
|
250
|
+
/** Local MCP tools are named `server__tool`, so they never take the name of a computer or Overlay tool. */
|
|
251
|
+
function withLocalMcpTools(tools, localMcp) {
|
|
252
|
+
if (!localMcp)
|
|
253
|
+
return tools;
|
|
254
|
+
const merged = { ...tools };
|
|
255
|
+
for (const [name, definition] of Object.entries(localMcp.tools))
|
|
256
|
+
if (!(name in merged))
|
|
257
|
+
merged[name] = definition;
|
|
258
|
+
return merged;
|
|
259
|
+
}
|
|
260
|
+
function instructionsFor(request, overlay, localMcp) {
|
|
224
261
|
const os = platform() === 'darwin' ? 'macOS' : platform() === 'win32' ? 'Windows' : 'Linux';
|
|
225
262
|
return [
|
|
226
263
|
`You are ${request.agent.name}, an agent in Overlay.`,
|
|
@@ -233,6 +270,7 @@ function instructionsFor(request, overlay) {
|
|
|
233
270
|
'Work step by step, check your results, and finish with a short summary of what you did.',
|
|
234
271
|
].join('\n'),
|
|
235
272
|
overlay && Object.keys(overlay.tools).length > 0 ? overlay.instructions : '',
|
|
273
|
+
localMcp?.instructions ?? '',
|
|
236
274
|
].filter(Boolean).join('\n\n');
|
|
237
275
|
}
|
|
238
276
|
/**
|
|
@@ -266,7 +304,11 @@ function titleFrom(messages) {
|
|
|
266
304
|
/** Provider errors can echo request details; keep the message and drop anything that looks like a key. */
|
|
267
305
|
function publicError(error) {
|
|
268
306
|
const message = error instanceof Error ? error.message : String(error);
|
|
269
|
-
return message
|
|
307
|
+
return message
|
|
308
|
+
.replace(/(sk|key|pk|AIza)[-_A-Za-z0-9]{12,}/g, '[redacted]')
|
|
309
|
+
.replace(/ovmcu_[a-z]_[-_.A-Za-z0-9]+/g, '[redacted]')
|
|
310
|
+
.replace(/ovlp_[A-Za-z0-9]+/g, '[redacted]')
|
|
311
|
+
.slice(0, 1_000) || 'The model call failed.';
|
|
270
312
|
}
|
|
271
313
|
function toReadable(iterable) {
|
|
272
314
|
const iterator = iterable[Symbol.asyncIterator]();
|