@letta-ai/letta-code 0.34.7 → 0.34.8
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/dist/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/tools/impl/apply-patch.d.ts.map +1 -1
- package/letta.js +344 -67
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/letta.js
CHANGED
|
@@ -5727,7 +5727,7 @@ var package_default;
|
|
|
5727
5727
|
var init_package = __esm(() => {
|
|
5728
5728
|
package_default = {
|
|
5729
5729
|
name: "@letta-ai/letta-code",
|
|
5730
|
-
version: "0.34.
|
|
5730
|
+
version: "0.34.8",
|
|
5731
5731
|
lettaStartupLogProtocol: 1,
|
|
5732
5732
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
5733
5733
|
type: "module",
|
|
@@ -120193,6 +120193,226 @@ var init_personality = __esm(() => {
|
|
|
120193
120193
|
execFile5 = promisify6(execFileCb3);
|
|
120194
120194
|
});
|
|
120195
120195
|
|
|
120196
|
+
// src/browser-discovery-server.ts
|
|
120197
|
+
import {
|
|
120198
|
+
createServer as createServer3
|
|
120199
|
+
} from "node:http";
|
|
120200
|
+
function startBrowserDiscoveryServer(options = {}) {
|
|
120201
|
+
const port = options.port ?? BROWSER_DISCOVERY_PORT;
|
|
120202
|
+
const retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
120203
|
+
let activeServer = null;
|
|
120204
|
+
let pendingServer = null;
|
|
120205
|
+
let retryTimer = null;
|
|
120206
|
+
let stopped = false;
|
|
120207
|
+
let readySettled = false;
|
|
120208
|
+
let resolveReady;
|
|
120209
|
+
let rejectReady;
|
|
120210
|
+
const ready = new Promise((resolve10, reject) => {
|
|
120211
|
+
resolveReady = resolve10;
|
|
120212
|
+
rejectReady = reject;
|
|
120213
|
+
});
|
|
120214
|
+
ready.catch(() => {
|
|
120215
|
+
return;
|
|
120216
|
+
});
|
|
120217
|
+
const scheduleRetry = () => {
|
|
120218
|
+
if (stopped || retryTimer)
|
|
120219
|
+
return;
|
|
120220
|
+
retryTimer = setTimeout(() => {
|
|
120221
|
+
retryTimer = null;
|
|
120222
|
+
attemptListen();
|
|
120223
|
+
}, retryDelayMs);
|
|
120224
|
+
retryTimer.unref();
|
|
120225
|
+
};
|
|
120226
|
+
const attemptListen = () => {
|
|
120227
|
+
if (stopped || activeServer || pendingServer)
|
|
120228
|
+
return;
|
|
120229
|
+
const candidate = createBrowserDiscoveryHttpServer();
|
|
120230
|
+
pendingServer = candidate;
|
|
120231
|
+
const onStartupError = (error4) => {
|
|
120232
|
+
pendingServer = null;
|
|
120233
|
+
candidate.close();
|
|
120234
|
+
if (error4.code === "EADDRINUSE") {
|
|
120235
|
+
scheduleRetry();
|
|
120236
|
+
return;
|
|
120237
|
+
}
|
|
120238
|
+
if (!readySettled) {
|
|
120239
|
+
readySettled = true;
|
|
120240
|
+
rejectReady(error4);
|
|
120241
|
+
}
|
|
120242
|
+
};
|
|
120243
|
+
candidate.once("error", onStartupError);
|
|
120244
|
+
candidate.listen(port, BROWSER_DISCOVERY_HOST, () => {
|
|
120245
|
+
candidate.off("error", onStartupError);
|
|
120246
|
+
if (stopped) {
|
|
120247
|
+
candidate.close();
|
|
120248
|
+
return;
|
|
120249
|
+
}
|
|
120250
|
+
pendingServer = null;
|
|
120251
|
+
activeServer = candidate;
|
|
120252
|
+
candidate.unref();
|
|
120253
|
+
const address = candidate.address();
|
|
120254
|
+
if (!address || typeof address === "string") {
|
|
120255
|
+
candidate.close();
|
|
120256
|
+
return;
|
|
120257
|
+
}
|
|
120258
|
+
if (!readySettled) {
|
|
120259
|
+
readySettled = true;
|
|
120260
|
+
resolveReady(formatDiscoveryAddress(address));
|
|
120261
|
+
}
|
|
120262
|
+
candidate.on("error", () => {
|
|
120263
|
+
if (activeServer !== candidate)
|
|
120264
|
+
return;
|
|
120265
|
+
activeServer = null;
|
|
120266
|
+
candidate.close();
|
|
120267
|
+
scheduleRetry();
|
|
120268
|
+
});
|
|
120269
|
+
candidate.once("close", () => {
|
|
120270
|
+
if (activeServer === candidate)
|
|
120271
|
+
activeServer = null;
|
|
120272
|
+
scheduleRetry();
|
|
120273
|
+
});
|
|
120274
|
+
});
|
|
120275
|
+
};
|
|
120276
|
+
attemptListen();
|
|
120277
|
+
return {
|
|
120278
|
+
ready,
|
|
120279
|
+
close: async () => {
|
|
120280
|
+
if (stopped)
|
|
120281
|
+
return;
|
|
120282
|
+
stopped = true;
|
|
120283
|
+
if (retryTimer) {
|
|
120284
|
+
clearTimeout(retryTimer);
|
|
120285
|
+
retryTimer = null;
|
|
120286
|
+
}
|
|
120287
|
+
if (!readySettled) {
|
|
120288
|
+
readySettled = true;
|
|
120289
|
+
rejectReady(new Error("Browser discovery server stopped before listening"));
|
|
120290
|
+
}
|
|
120291
|
+
const servers = [pendingServer, activeServer].filter((server2) => server2 !== null);
|
|
120292
|
+
pendingServer = null;
|
|
120293
|
+
activeServer = null;
|
|
120294
|
+
await Promise.all(servers.map(closeServer));
|
|
120295
|
+
}
|
|
120296
|
+
};
|
|
120297
|
+
}
|
|
120298
|
+
function createBrowserDiscoveryHttpServer() {
|
|
120299
|
+
let server2;
|
|
120300
|
+
server2 = createServer3((request, response) => {
|
|
120301
|
+
handleBrowserDiscoveryRequest(server2, request, response);
|
|
120302
|
+
});
|
|
120303
|
+
server2.headersTimeout = 5000;
|
|
120304
|
+
server2.requestTimeout = 5000;
|
|
120305
|
+
server2.keepAliveTimeout = 1000;
|
|
120306
|
+
server2.maxHeadersCount = 32;
|
|
120307
|
+
server2.on("connection", (socket) => socket.unref());
|
|
120308
|
+
server2.on("timeout", (socket) => socket.destroy());
|
|
120309
|
+
server2.on("clientError", (_error, socket) => {
|
|
120310
|
+
if (!socket.writable)
|
|
120311
|
+
return;
|
|
120312
|
+
socket.end(`HTTP/1.1 400 Bad Request\r
|
|
120313
|
+
Connection: close\r
|
|
120314
|
+
Content-Length: 0\r
|
|
120315
|
+
\r
|
|
120316
|
+
`);
|
|
120317
|
+
});
|
|
120318
|
+
return server2;
|
|
120319
|
+
}
|
|
120320
|
+
function handleBrowserDiscoveryRequest(server2, request, response) {
|
|
120321
|
+
if (!isLoopbackAddress(request.socket.remoteAddress)) {
|
|
120322
|
+
respond(response, 403, "Browser connection must use loopback");
|
|
120323
|
+
return;
|
|
120324
|
+
}
|
|
120325
|
+
const address = server2.address();
|
|
120326
|
+
const expectedHost = address && typeof address !== "string" ? `${BROWSER_DISCOVERY_HOST}:${address.port}` : null;
|
|
120327
|
+
if (!expectedHost || request.headers.host !== expectedHost) {
|
|
120328
|
+
respond(response, 400, "Invalid discovery host");
|
|
120329
|
+
return;
|
|
120330
|
+
}
|
|
120331
|
+
if (request.url !== BROWSER_DISCOVERY_PATH) {
|
|
120332
|
+
respond(response, 404, "Not found");
|
|
120333
|
+
return;
|
|
120334
|
+
}
|
|
120335
|
+
const requestOrigin = request.headers.origin;
|
|
120336
|
+
const origin = allowedBrowserOrigin(requestOrigin);
|
|
120337
|
+
if (requestOrigin && !origin) {
|
|
120338
|
+
respond(response, 403, "Browser origin is not allowed");
|
|
120339
|
+
return;
|
|
120340
|
+
}
|
|
120341
|
+
if (request.method === "OPTIONS") {
|
|
120342
|
+
if (!origin || request.headers["access-control-request-method"] !== "GET") {
|
|
120343
|
+
respond(response, 403, "Browser preflight is not allowed");
|
|
120344
|
+
return;
|
|
120345
|
+
}
|
|
120346
|
+
response.writeHead(204, {
|
|
120347
|
+
...browserAccessHeaders(origin),
|
|
120348
|
+
"Content-Length": "0"
|
|
120349
|
+
});
|
|
120350
|
+
response.end();
|
|
120351
|
+
return;
|
|
120352
|
+
}
|
|
120353
|
+
if (request.method !== "GET") {
|
|
120354
|
+
response.writeHead(405, {
|
|
120355
|
+
...browserAccessHeaders(origin),
|
|
120356
|
+
Allow: "GET, OPTIONS",
|
|
120357
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
120358
|
+
});
|
|
120359
|
+
response.end("Method not allowed");
|
|
120360
|
+
return;
|
|
120361
|
+
}
|
|
120362
|
+
response.writeHead(200, {
|
|
120363
|
+
...browserAccessHeaders(origin),
|
|
120364
|
+
"Content-Length": String(Buffer.byteLength(STATUS_BODY)),
|
|
120365
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
120366
|
+
});
|
|
120367
|
+
response.end(STATUS_BODY);
|
|
120368
|
+
}
|
|
120369
|
+
function allowedBrowserOrigin(value) {
|
|
120370
|
+
if (!value)
|
|
120371
|
+
return;
|
|
120372
|
+
return ALLOWED_BROWSER_ORIGINS.has(value) || LOCAL_BROWSER_ORIGIN.test(value) ? value : undefined;
|
|
120373
|
+
}
|
|
120374
|
+
function isLoopbackAddress(value) {
|
|
120375
|
+
return value === "127.0.0.1" || value === "::ffff:127.0.0.1";
|
|
120376
|
+
}
|
|
120377
|
+
function browserAccessHeaders(origin) {
|
|
120378
|
+
return {
|
|
120379
|
+
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
|
120380
|
+
...origin ? { "Access-Control-Allow-Origin": origin } : {},
|
|
120381
|
+
"Access-Control-Allow-Private-Network": "true",
|
|
120382
|
+
"Cache-Control": "no-store",
|
|
120383
|
+
Connection: "close",
|
|
120384
|
+
Vary: "Origin, Access-Control-Request-Method, Access-Control-Request-Private-Network"
|
|
120385
|
+
};
|
|
120386
|
+
}
|
|
120387
|
+
function respond(response, statusCode2, body) {
|
|
120388
|
+
response.writeHead(statusCode2, {
|
|
120389
|
+
"Content-Length": String(Buffer.byteLength(body)),
|
|
120390
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
120391
|
+
});
|
|
120392
|
+
response.end(body);
|
|
120393
|
+
}
|
|
120394
|
+
function formatDiscoveryAddress(address) {
|
|
120395
|
+
return {
|
|
120396
|
+
host: BROWSER_DISCOVERY_HOST,
|
|
120397
|
+
port: address.port,
|
|
120398
|
+
url: `http://${BROWSER_DISCOVERY_HOST}:${address.port}${BROWSER_DISCOVERY_PATH}`
|
|
120399
|
+
};
|
|
120400
|
+
}
|
|
120401
|
+
async function closeServer(server2) {
|
|
120402
|
+
server2.closeAllConnections();
|
|
120403
|
+
if (!server2.listening)
|
|
120404
|
+
return;
|
|
120405
|
+
await new Promise((resolve10) => {
|
|
120406
|
+
server2.close(() => resolve10());
|
|
120407
|
+
});
|
|
120408
|
+
}
|
|
120409
|
+
var BROWSER_DISCOVERY_HOST = "127.0.0.1", BROWSER_DISCOVERY_PORT = 32187, BROWSER_DISCOVERY_PATH = "/status", DEFAULT_RETRY_DELAY_MS = 1000, STATUS_BODY, LOCAL_BROWSER_ORIGIN, ALLOWED_BROWSER_ORIGINS;
|
|
120410
|
+
var init_browser_discovery_server = __esm(() => {
|
|
120411
|
+
STATUS_BODY = JSON.stringify({ status: "ok" });
|
|
120412
|
+
LOCAL_BROWSER_ORIGIN = /^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/;
|
|
120413
|
+
ALLOWED_BROWSER_ORIGINS = new Set(["https://chat.letta.com"]);
|
|
120414
|
+
});
|
|
120415
|
+
|
|
120196
120416
|
// src/cli/args.ts
|
|
120197
120417
|
import { parseArgs } from "node:util";
|
|
120198
120418
|
function formatHelpFlagLabel(flagName, definition) {
|
|
@@ -196794,8 +197014,14 @@ function parseUpdateChunk(lines, startIndex, endIndex, allowMissingContext) {
|
|
|
196794
197014
|
}
|
|
196795
197015
|
const oldLines = [];
|
|
196796
197016
|
const newLines = [];
|
|
197017
|
+
const contextLineIndices = [];
|
|
196797
197018
|
let isEndOfFile = false;
|
|
196798
197019
|
let parsedLineCount = 0;
|
|
197020
|
+
const pushContextLine = (text2) => {
|
|
197021
|
+
contextLineIndices.push([oldLines.length, newLines.length]);
|
|
197022
|
+
oldLines.push(text2);
|
|
197023
|
+
newLines.push(text2);
|
|
197024
|
+
};
|
|
196799
197025
|
while (index < endIndex) {
|
|
196800
197026
|
const line = lines[index] ?? "";
|
|
196801
197027
|
if (line === EOF_MARKER) {
|
|
@@ -196808,17 +197034,14 @@ function parseUpdateChunk(lines, startIndex, endIndex, allowMissingContext) {
|
|
|
196808
197034
|
break;
|
|
196809
197035
|
}
|
|
196810
197036
|
if (line.length === 0) {
|
|
196811
|
-
|
|
196812
|
-
newLines.push("");
|
|
197037
|
+
pushContextLine("");
|
|
196813
197038
|
parsedLineCount += 1;
|
|
196814
197039
|
index += 1;
|
|
196815
197040
|
continue;
|
|
196816
197041
|
}
|
|
196817
197042
|
const prefix = line[0];
|
|
196818
197043
|
if (prefix === " ") {
|
|
196819
|
-
|
|
196820
|
-
oldLines.push(text2);
|
|
196821
|
-
newLines.push(text2);
|
|
197044
|
+
pushContextLine(line.slice(1));
|
|
196822
197045
|
parsedLineCount += 1;
|
|
196823
197046
|
index += 1;
|
|
196824
197047
|
continue;
|
|
@@ -196845,6 +197068,7 @@ function parseUpdateChunk(lines, startIndex, endIndex, allowMissingContext) {
|
|
|
196845
197068
|
changeContext,
|
|
196846
197069
|
oldLines,
|
|
196847
197070
|
newLines,
|
|
197071
|
+
contextLineIndices,
|
|
196848
197072
|
isEndOfFile
|
|
196849
197073
|
},
|
|
196850
197074
|
nextIndex: index
|
|
@@ -196918,18 +197142,41 @@ async function deriveNewContentsFromChunks(absolutePath, filePathForErrors, chun
|
|
|
196918
197142
|
const message = error4 instanceof Error ? error4.message : String(error4);
|
|
196919
197143
|
throw new Error(`Failed to read file to update ${filePathForErrors}: ${message}`);
|
|
196920
197144
|
}
|
|
196921
|
-
const
|
|
196922
|
-
|
|
196923
|
-
if (originalLines[originalLines.length - 1] === "") {
|
|
196924
|
-
originalLines.pop();
|
|
196925
|
-
}
|
|
197145
|
+
const sourceFile = parseSourceFile(originalContents);
|
|
197146
|
+
const originalLines = sourceFile.lines.map((line) => line.text);
|
|
196926
197147
|
const replacements = computeReplacements(originalLines, filePathForErrors, chunks);
|
|
196927
|
-
|
|
196928
|
-
|
|
196929
|
-
|
|
197148
|
+
return applyReplacements(sourceFile, replacements).map((line) => `${line.text}${line.ending ?? ""}`).join("");
|
|
197149
|
+
}
|
|
197150
|
+
function parseSourceFile(contents) {
|
|
197151
|
+
const lines = [];
|
|
197152
|
+
let preferredEnding = null;
|
|
197153
|
+
let lineStart = 0;
|
|
197154
|
+
let cursor = 0;
|
|
197155
|
+
while (cursor < contents.length) {
|
|
197156
|
+
const char = contents[cursor];
|
|
197157
|
+
let ending;
|
|
197158
|
+
if (char === "\r") {
|
|
197159
|
+
ending = contents[cursor + 1] === `
|
|
197160
|
+
` ? `\r
|
|
197161
|
+
` : "\r";
|
|
197162
|
+
} else if (char === `
|
|
197163
|
+
`) {
|
|
197164
|
+
ending = `
|
|
197165
|
+
`;
|
|
197166
|
+
} else {
|
|
197167
|
+
cursor += 1;
|
|
197168
|
+
continue;
|
|
197169
|
+
}
|
|
197170
|
+
preferredEnding ??= ending;
|
|
197171
|
+
lines.push({ text: contents.slice(lineStart, cursor), ending });
|
|
197172
|
+
cursor += ending.length;
|
|
197173
|
+
lineStart = cursor;
|
|
196930
197174
|
}
|
|
196931
|
-
|
|
196932
|
-
|
|
197175
|
+
if (lineStart < contents.length) {
|
|
197176
|
+
lines.push({ text: contents.slice(lineStart), ending: null });
|
|
197177
|
+
}
|
|
197178
|
+
return { lines, preferredEnding: preferredEnding ?? `
|
|
197179
|
+
` };
|
|
196933
197180
|
}
|
|
196934
197181
|
function computeReplacements(originalLines, filePathForErrors, chunks) {
|
|
196935
197182
|
const replacements = [];
|
|
@@ -196943,8 +197190,7 @@ function computeReplacements(originalLines, filePathForErrors, chunks) {
|
|
|
196943
197190
|
lineIndex = contextIndex + 1;
|
|
196944
197191
|
}
|
|
196945
197192
|
if (chunk2.oldLines.length === 0) {
|
|
196946
|
-
|
|
196947
|
-
replacements.push([insertionIndex, 0, [...chunk2.newLines]]);
|
|
197193
|
+
replacements.push([originalLines.length, 0, [...chunk2.newLines]]);
|
|
196948
197194
|
continue;
|
|
196949
197195
|
}
|
|
196950
197196
|
let pattern4 = [...chunk2.oldLines];
|
|
@@ -196962,23 +197208,47 @@ function computeReplacements(originalLines, filePathForErrors, chunks) {
|
|
|
196962
197208
|
${chunk2.oldLines.join(`
|
|
196963
197209
|
`)}`);
|
|
196964
197210
|
}
|
|
196965
|
-
|
|
197211
|
+
let oldStart = 0;
|
|
197212
|
+
let newStart = 0;
|
|
197213
|
+
for (const [oldContext, newContext] of chunk2.contextLineIndices) {
|
|
197214
|
+
if (oldContext >= pattern4.length || newContext >= newSlice.length) {
|
|
197215
|
+
break;
|
|
197216
|
+
}
|
|
197217
|
+
if (oldStart !== oldContext || newStart !== newContext) {
|
|
197218
|
+
replacements.push([
|
|
197219
|
+
found + oldStart,
|
|
197220
|
+
oldContext - oldStart,
|
|
197221
|
+
newSlice.slice(newStart, newContext)
|
|
197222
|
+
]);
|
|
197223
|
+
}
|
|
197224
|
+
oldStart = oldContext + 1;
|
|
197225
|
+
newStart = newContext + 1;
|
|
197226
|
+
}
|
|
197227
|
+
if (oldStart !== pattern4.length || newStart !== newSlice.length) {
|
|
197228
|
+
replacements.push([
|
|
197229
|
+
found + oldStart,
|
|
197230
|
+
pattern4.length - oldStart,
|
|
197231
|
+
newSlice.slice(newStart)
|
|
197232
|
+
]);
|
|
197233
|
+
}
|
|
196966
197234
|
lineIndex = found + pattern4.length;
|
|
196967
197235
|
}
|
|
196968
197236
|
replacements.sort((left, right) => left[0] - right[0]);
|
|
196969
197237
|
return replacements;
|
|
196970
197238
|
}
|
|
196971
|
-
function applyReplacements(lines, replacements) {
|
|
196972
|
-
|
|
196973
|
-
|
|
196974
|
-
|
|
196975
|
-
|
|
196976
|
-
|
|
196977
|
-
|
|
196978
|
-
|
|
196979
|
-
|
|
196980
|
-
|
|
196981
|
-
|
|
197239
|
+
function applyReplacements({ lines, preferredEnding }, replacements) {
|
|
197240
|
+
const newLines = [];
|
|
197241
|
+
let sourceIndex = 0;
|
|
197242
|
+
for (const [startIndex, oldLength, newSegment] of replacements) {
|
|
197243
|
+
newLines.push(...lines.slice(sourceIndex, startIndex));
|
|
197244
|
+
newLines.push(...newSegment.map((text2) => ({ text: text2, ending: preferredEnding })));
|
|
197245
|
+
sourceIndex = startIndex + oldLength;
|
|
197246
|
+
}
|
|
197247
|
+
newLines.push(...lines.slice(sourceIndex));
|
|
197248
|
+
return newLines.map((line) => ({
|
|
197249
|
+
text: line.text,
|
|
197250
|
+
ending: line.ending ?? preferredEnding
|
|
197251
|
+
}));
|
|
196982
197252
|
}
|
|
196983
197253
|
function seekSequence(lines, pattern4, start, eof) {
|
|
196984
197254
|
if (pattern4.length === 0) {
|
|
@@ -196988,7 +197258,7 @@ function seekSequence(lines, pattern4, start, eof) {
|
|
|
196988
197258
|
return null;
|
|
196989
197259
|
}
|
|
196990
197260
|
const maxStart = lines.length - pattern4.length;
|
|
196991
|
-
const searchStart = eof && lines.length >= pattern4.length ? lines.length - pattern4.length : start;
|
|
197261
|
+
const searchStart = eof && lines.length >= pattern4.length ? Math.max(lines.length - pattern4.length, start) : start;
|
|
196992
197262
|
const tryMatch = (matches3) => {
|
|
196993
197263
|
for (let index = searchStart;index <= maxStart; index += 1) {
|
|
196994
197264
|
let ok = true;
|
|
@@ -220177,7 +220447,7 @@ class CodexAppServerClient {
|
|
|
220177
220447
|
await this.request("initialize", {
|
|
220178
220448
|
clientInfo: {
|
|
220179
220449
|
name: "letta-code",
|
|
220180
|
-
version: "0.34.
|
|
220450
|
+
version: "0.34.8"
|
|
220181
220451
|
},
|
|
220182
220452
|
capabilities: null
|
|
220183
220453
|
});
|
|
@@ -247072,12 +247342,12 @@ var init_mcp_client = __esm(() => {
|
|
|
247072
247342
|
init_streamableHttp();
|
|
247073
247343
|
DEFAULT_CLIENT_INFO = {
|
|
247074
247344
|
name: "letta-code",
|
|
247075
|
-
version: "0.34.
|
|
247345
|
+
version: "0.34.8"
|
|
247076
247346
|
};
|
|
247077
247347
|
});
|
|
247078
247348
|
|
|
247079
247349
|
// src/mcp-oauth-callback.ts
|
|
247080
|
-
import { createServer as
|
|
247350
|
+
import { createServer as createServer4 } from "node:http";
|
|
247081
247351
|
async function startOAuthCallbackServer2(preferredPort) {
|
|
247082
247352
|
try {
|
|
247083
247353
|
return await startOAuthCallbackServerOnPort(preferredPort ?? 0);
|
|
@@ -247116,7 +247386,7 @@ async function startOAuthCallbackServerOnPort(port) {
|
|
|
247116
247386
|
codePromise.catch(() => {
|
|
247117
247387
|
return;
|
|
247118
247388
|
});
|
|
247119
|
-
server2 =
|
|
247389
|
+
server2 = createServer4((request, response) => {
|
|
247120
247390
|
if (request.method !== "GET" || !request.url?.startsWith("/") || request.url.startsWith("//") || request.url.includes("\\")) {
|
|
247121
247391
|
response.writeHead(400, { "Content-Type": "text/plain" });
|
|
247122
247392
|
response.end("Invalid request target");
|
|
@@ -247153,7 +247423,7 @@ async function startOAuthCallbackServerOnPort(port) {
|
|
|
247153
247423
|
response.writeHead(400, { "Content-Type": "text/html" });
|
|
247154
247424
|
reject2?.(new Error(`MCP OAuth authorization failed: ${error5}`));
|
|
247155
247425
|
response.end(callbackPage("Authorization failed", error5), () => {
|
|
247156
|
-
|
|
247426
|
+
closeServer2(true);
|
|
247157
247427
|
});
|
|
247158
247428
|
return;
|
|
247159
247429
|
}
|
|
@@ -247165,7 +247435,7 @@ async function startOAuthCallbackServerOnPort(port) {
|
|
|
247165
247435
|
response.writeHead(200, { "Content-Type": "text/html" });
|
|
247166
247436
|
settle3?.(code2);
|
|
247167
247437
|
response.end(callbackPage("Authorization complete", "You can close this tab and return to Letta Code."), () => {
|
|
247168
|
-
|
|
247438
|
+
closeServer2(true);
|
|
247169
247439
|
});
|
|
247170
247440
|
});
|
|
247171
247441
|
server2.on("clientError", (_error, socket) => {
|
|
@@ -247178,7 +247448,7 @@ Content-Length: 0\r
|
|
|
247178
247448
|
`);
|
|
247179
247449
|
});
|
|
247180
247450
|
let serverClosing = false;
|
|
247181
|
-
const
|
|
247451
|
+
const closeServer2 = (force = false) => {
|
|
247182
247452
|
if (serverClosing)
|
|
247183
247453
|
return;
|
|
247184
247454
|
serverClosing = true;
|
|
@@ -247198,7 +247468,7 @@ Content-Length: 0\r
|
|
|
247198
247468
|
}
|
|
247199
247469
|
const timeout = setTimeout(() => {
|
|
247200
247470
|
reject2?.(new Error("Timed out waiting for MCP OAuth authorization"));
|
|
247201
|
-
|
|
247471
|
+
closeServer2(true);
|
|
247202
247472
|
}, CALLBACK_TIMEOUT_MS);
|
|
247203
247473
|
timeout.unref();
|
|
247204
247474
|
return {
|
|
@@ -247209,7 +247479,7 @@ Content-Length: 0\r
|
|
|
247209
247479
|
clearTimeout(timeout);
|
|
247210
247480
|
if (!completed)
|
|
247211
247481
|
reject2?.(new Error("MCP OAuth flow was cancelled"));
|
|
247212
|
-
|
|
247482
|
+
closeServer2(true);
|
|
247213
247483
|
}
|
|
247214
247484
|
};
|
|
247215
247485
|
}
|
|
@@ -259665,7 +259935,7 @@ function printListenUsage() {
|
|
|
259665
259935
|
}
|
|
259666
259936
|
|
|
259667
259937
|
// src/cli/subcommands/listener-readiness.ts
|
|
259668
|
-
async function completeListenerConnectionStartup(expectedConnection, readiness) {
|
|
259938
|
+
async function completeListenerConnectionStartup(expectedConnection, readiness, startGateway = async () => {}) {
|
|
259669
259939
|
const { getActiveRuntime: getActiveRuntime2 } = await init_runtime6().then(() => exports_runtime);
|
|
259670
259940
|
const runtime = getActiveRuntime2();
|
|
259671
259941
|
const connection = runtime?.connections.get(expectedConnection.id);
|
|
@@ -259675,8 +259945,11 @@ async function completeListenerConnectionStartup(expectedConnection, readiness)
|
|
|
259675
259945
|
const { isListenerTransportOpen: isListenerTransportOpen2 } = await Promise.resolve().then(() => (init_transport(), exports_transport));
|
|
259676
259946
|
if (!isListenerTransportOpen2(connection.writer))
|
|
259677
259947
|
return false;
|
|
259948
|
+
await startGateway();
|
|
259678
259949
|
if (getActiveRuntime2()?.connections.get(connection.id) !== connection)
|
|
259679
259950
|
return false;
|
|
259951
|
+
if (!connection.initialized || !connection.ingressReady || connection.cancellation.signal.aborted || !isListenerTransportOpen2(connection.writer))
|
|
259952
|
+
return false;
|
|
259680
259953
|
readiness.completeCloudStartup(epoch);
|
|
259681
259954
|
return true;
|
|
259682
259955
|
}
|
|
@@ -295532,7 +295805,7 @@ ${lanes.join(`
|
|
|
295532
295805
|
var contextFlags;
|
|
295533
295806
|
var topLevel = true;
|
|
295534
295807
|
var parseErrorBeforeNextFinishedNode = false;
|
|
295535
|
-
function
|
|
295808
|
+
function parseSourceFile2(fileName2, sourceText2, languageVersion2, syntaxCursor2, setParentNodes = false, scriptKind2, setExternalModuleIndicatorOverride, jsDocParsingMode = 0) {
|
|
295536
295809
|
var _a10;
|
|
295537
295810
|
scriptKind2 = ensureScriptKind(fileName2, scriptKind2);
|
|
295538
295811
|
if (scriptKind2 === 6) {
|
|
@@ -295551,7 +295824,7 @@ ${lanes.join(`
|
|
|
295551
295824
|
clearState();
|
|
295552
295825
|
return result3;
|
|
295553
295826
|
}
|
|
295554
|
-
Parser22.parseSourceFile =
|
|
295827
|
+
Parser22.parseSourceFile = parseSourceFile2;
|
|
295555
295828
|
function parseIsolatedEntityName2(content, languageVersion2) {
|
|
295556
295829
|
initializeState("", content, languageVersion2, undefined, 1, 0);
|
|
295557
295830
|
nextToken();
|
|
@@ -437140,7 +437413,8 @@ function finishClaimedTeleport(runtime, pending, commit, options = {}) {
|
|
|
437140
437413
|
agentId: pending.agentId,
|
|
437141
437414
|
conversationId: pending.conversationId,
|
|
437142
437415
|
persistTerminalWithoutConsumers: intentRevision !== undefined,
|
|
437143
|
-
expectedInterruptedRevision: intentRevision
|
|
437416
|
+
expectedInterruptedRevision: intentRevision,
|
|
437417
|
+
teleportHandoff: pending.activeTurn
|
|
437144
437418
|
});
|
|
437145
437419
|
} catch (error5) {
|
|
437146
437420
|
abandonTeleportIntent(runtime.listener, pending, intentRevision);
|
|
@@ -442254,7 +442528,7 @@ function finishListenerTurn(runtime, lease, options) {
|
|
|
442254
442528
|
type: "turn_finished",
|
|
442255
442529
|
turn_id: options.turnId,
|
|
442256
442530
|
stop_reason: options.stopReason,
|
|
442257
|
-
...options.terminalConsumerIds?.length ? {
|
|
442531
|
+
...options.terminalConsumerIds?.length && !options.teleportHandoff ? {
|
|
442258
442532
|
terminal_consumer_ids: [
|
|
442259
442533
|
...new Set(options.terminalConsumerIds)
|
|
442260
442534
|
]
|
|
@@ -442379,7 +442653,7 @@ function finishListenerTurn(runtime, lease, options) {
|
|
|
442379
442653
|
conversation_id: options.conversationId
|
|
442380
442654
|
});
|
|
442381
442655
|
}
|
|
442382
|
-
if (mayEmit && options.socket && turnFinishedMessage && preparedTurnFinished) {
|
|
442656
|
+
if (mayEmit && options.socket && turnFinishedMessage && preparedTurnFinished && !options.teleportHandoff) {
|
|
442383
442657
|
emitDurableTurnFinished(options.socket, runtime, turnFinishedMessage, TO_SUBSCRIBERS, options.turnFinishedStore, preparedTurnFinished);
|
|
442384
442658
|
}
|
|
442385
442659
|
if (options.stopReason === "end_turn" || options.stopReason === "cancelled" && transition2.interruptionCause !== "transport") {
|
|
@@ -448046,12 +448320,12 @@ function rowToolCalls(row, index, diagnostics2) {
|
|
|
448046
448320
|
}
|
|
448047
448321
|
return calls;
|
|
448048
448322
|
}
|
|
448049
|
-
function
|
|
448323
|
+
function contentText3(content) {
|
|
448050
448324
|
if (typeof content === "string") {
|
|
448051
448325
|
if (content.startsWith(CONTENT_JSON_PREFIX)) {
|
|
448052
448326
|
const encoded = content.slice(CONTENT_JSON_PREFIX.length);
|
|
448053
448327
|
try {
|
|
448054
|
-
return
|
|
448328
|
+
return contentText3(JSON.parse(encoded));
|
|
448055
448329
|
} catch {
|
|
448056
448330
|
return encoded;
|
|
448057
448331
|
}
|
|
@@ -448137,7 +448411,7 @@ var init_hermes = __esm(() => {
|
|
|
448137
448411
|
});
|
|
448138
448412
|
};
|
|
448139
448413
|
if (row.role === "user") {
|
|
448140
|
-
const content =
|
|
448414
|
+
const content = contentText3(row.content);
|
|
448141
448415
|
if (content) {
|
|
448142
448416
|
emit({
|
|
448143
448417
|
type: "message",
|
|
@@ -448157,7 +448431,7 @@ var init_hermes = __esm(() => {
|
|
|
448157
448431
|
...timestamp ? { timestamp } : {}
|
|
448158
448432
|
});
|
|
448159
448433
|
}
|
|
448160
|
-
const content =
|
|
448434
|
+
const content = contentText3(row.content);
|
|
448161
448435
|
if (content) {
|
|
448162
448436
|
emit({
|
|
448163
448437
|
type: "message",
|
|
@@ -448180,7 +448454,7 @@ var init_hermes = __esm(() => {
|
|
|
448180
448454
|
if (row.role === "tool") {
|
|
448181
448455
|
emit({
|
|
448182
448456
|
type: "tool_result",
|
|
448183
|
-
content:
|
|
448457
|
+
content: contentText3(row.content),
|
|
448184
448458
|
...typeof row.tool_call_id === "string" && row.tool_call_id ? { callId: row.tool_call_id } : {},
|
|
448185
448459
|
...timestamp ? { timestamp } : {}
|
|
448186
448460
|
});
|
|
@@ -458402,7 +458676,7 @@ function createListenerMessageHandler(params) {
|
|
|
458402
458676
|
return;
|
|
458403
458677
|
}
|
|
458404
458678
|
if (parsed.type === "runtime_external_tools_update") {
|
|
458405
|
-
const
|
|
458679
|
+
const respond2 = (success, error5) => {
|
|
458406
458680
|
safeSocketSend(socket, {
|
|
458407
458681
|
type: "runtime_external_tools_update_response",
|
|
458408
458682
|
request_id: parsed.request_id,
|
|
@@ -458411,11 +458685,11 @@ function createListenerMessageHandler(params) {
|
|
|
458411
458685
|
}, "runtime_external_tools_update_response", "runtime_external_tools_update");
|
|
458412
458686
|
};
|
|
458413
458687
|
if (runtime !== getActiveRuntime() || runtime.intentionallyClosed) {
|
|
458414
|
-
|
|
458688
|
+
respond2(false, "Runtime is no longer active");
|
|
458415
458689
|
return;
|
|
458416
458690
|
}
|
|
458417
458691
|
updateRuntimeExternalTools(runtime, connectionId, parsed.updates);
|
|
458418
|
-
|
|
458692
|
+
respond2(true);
|
|
458419
458693
|
return;
|
|
458420
458694
|
}
|
|
458421
458695
|
if (parsed.type === "sync") {
|
|
@@ -462893,7 +463167,7 @@ __export(exports_app_server, {
|
|
|
462893
463167
|
startAppServer: () => startAppServer,
|
|
462894
463168
|
parseAppServerListenUrl: () => parseAppServerListenUrl
|
|
462895
463169
|
});
|
|
462896
|
-
import { createServer as
|
|
463170
|
+
import { createServer as createServer5 } from "node:http";
|
|
462897
463171
|
import { hostname as hostname4 } from "node:os";
|
|
462898
463172
|
import WebSocket11, { WebSocketServer } from "ws";
|
|
462899
463173
|
function getRequiredAddressInfo(server2) {
|
|
@@ -463026,7 +463300,7 @@ async function startAppServer(options = {}) {
|
|
|
463026
463300
|
closeSocket(socket, 1011, "failed to start connection");
|
|
463027
463301
|
});
|
|
463028
463302
|
};
|
|
463029
|
-
const server2 =
|
|
463303
|
+
const server2 = createServer5((request, response) => {
|
|
463030
463304
|
const requestUrl = getRequestUrl(request, listen.host);
|
|
463031
463305
|
if (request.headers.origin) {
|
|
463032
463306
|
options.onLog?.(`Rejecting app-server request with Origin header: ${request.url ?? "/"}`);
|
|
@@ -463951,11 +464225,9 @@ async function runListenSubcommand(argv) {
|
|
|
463951
464225
|
console.log(`[${formatTimestamp3()}] status: ${status}`);
|
|
463952
464226
|
}
|
|
463953
464227
|
},
|
|
463954
|
-
onConnected:
|
|
463955
|
-
await startChannelGateway();
|
|
463956
|
-
},
|
|
464228
|
+
onConnected: () => {},
|
|
463957
464229
|
onConnectionReady: async (connectedId) => {
|
|
463958
|
-
const ready = await completeListenerConnectionStartup(connectedId, readiness);
|
|
464230
|
+
const ready = await completeListenerConnectionStartup(connectedId, readiness, startChannelGateway);
|
|
463959
464231
|
if (!ready)
|
|
463960
464232
|
return;
|
|
463961
464233
|
sessionLog.log("Local channel listener ready.");
|
|
@@ -464058,11 +464330,9 @@ async function runListenSubcommand(argv) {
|
|
|
464058
464330
|
}
|
|
464059
464331
|
},
|
|
464060
464332
|
onLog: logListenerMessage,
|
|
464061
|
-
onConnected:
|
|
464062
|
-
await startChannelGateway();
|
|
464063
|
-
},
|
|
464333
|
+
onConnected: () => {},
|
|
464064
464334
|
onConnectionReady: async (connectedId) => {
|
|
464065
|
-
const ready = await completeListenerConnectionStartup(connectedId, readiness);
|
|
464335
|
+
const ready = await completeListenerConnectionStartup(connectedId, readiness, startChannelGateway);
|
|
464066
464336
|
if (!ready)
|
|
464067
464337
|
return;
|
|
464068
464338
|
sessionLog.log("Connected. Awaiting instructions.");
|
|
@@ -464139,9 +464409,12 @@ async function runListenSubcommand(argv) {
|
|
|
464139
464409
|
updateStatusCallback?.(status);
|
|
464140
464410
|
},
|
|
464141
464411
|
onLog: logListenerMessage,
|
|
464142
|
-
onConnected:
|
|
464412
|
+
onConnected: () => {},
|
|
464413
|
+
onConnectionReady: async (connectedId) => {
|
|
464414
|
+
const ready = await completeListenerConnectionStartup(connectedId, readiness, startChannelGateway);
|
|
464415
|
+
if (!ready)
|
|
464416
|
+
return;
|
|
464143
464417
|
sessionLog.log("Connected. Awaiting instructions.");
|
|
464144
|
-
await startChannelGateway();
|
|
464145
464418
|
clearRetryStatusCallback?.();
|
|
464146
464419
|
updateStatusCallback?.("idle");
|
|
464147
464420
|
},
|
|
@@ -528479,6 +528752,7 @@ var init_src5 = __esm(async () => {
|
|
|
528479
528752
|
init_backend2();
|
|
528480
528753
|
init_metadata();
|
|
528481
528754
|
init_paths();
|
|
528755
|
+
init_browser_discovery_server();
|
|
528482
528756
|
init_args();
|
|
528483
528757
|
init_app_urls();
|
|
528484
528758
|
init_error_formatter();
|
|
@@ -528502,6 +528776,9 @@ var init_src5 = __esm(async () => {
|
|
|
528502
528776
|
EMPTY_APPROVAL_ARRAY = [];
|
|
528503
528777
|
EMPTY_MESSAGE_ARRAY = [];
|
|
528504
528778
|
assertSupportedBunRuntime();
|
|
528779
|
+
startBrowserDiscoveryServer().ready.catch(() => {
|
|
528780
|
+
return;
|
|
528781
|
+
});
|
|
528505
528782
|
main();
|
|
528506
528783
|
});
|
|
528507
528784
|
|
|
@@ -530866,4 +531143,4 @@ function registerBunOAuthFlows() {
|
|
|
530866
531143
|
registerBunOAuthFlows();
|
|
530867
531144
|
await init_src5().then(() => exports_src2);
|
|
530868
531145
|
|
|
530869
|
-
//# debugId=
|
|
531146
|
+
//# debugId=F46164B649518D8764756E2164756E21
|