poe-code 3.0.102 → 3.0.103
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/cli/container.js +2 -0
- package/dist/cli/container.js.map +1 -1
- package/dist/cli/options.d.ts +1 -2
- package/dist/cli/options.js +6 -44
- package/dist/cli/options.js.map +1 -1
- package/dist/index.js +273 -277
- package/dist/index.js.map +4 -4
- package/dist/sdk/container.js +3 -1
- package/dist/sdk/container.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5210,33 +5210,251 @@ var init_prompts2 = __esm({
|
|
|
5210
5210
|
}
|
|
5211
5211
|
});
|
|
5212
5212
|
|
|
5213
|
-
// src/
|
|
5214
|
-
function
|
|
5215
|
-
|
|
5213
|
+
// packages/poe-oauth/src/check-auth.ts
|
|
5214
|
+
async function checkAuth(options) {
|
|
5215
|
+
try {
|
|
5216
|
+
const fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
5217
|
+
const response = await fetchImplementation(
|
|
5218
|
+
createCurrentBalanceUrl(options.baseUrl ?? DEFAULT_BASE_URL),
|
|
5219
|
+
{
|
|
5220
|
+
method: "GET",
|
|
5221
|
+
headers: {
|
|
5222
|
+
Authorization: `Bearer ${options.apiKey}`
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
);
|
|
5226
|
+
if (!response.ok) {
|
|
5227
|
+
return null;
|
|
5228
|
+
}
|
|
5229
|
+
const data = await response.json();
|
|
5230
|
+
if (typeof data.email !== "string" || data.email.length === 0) {
|
|
5231
|
+
return null;
|
|
5232
|
+
}
|
|
5233
|
+
return {
|
|
5234
|
+
email: data.email,
|
|
5235
|
+
balance: typeof data.current_point_balance === "number" ? data.current_point_balance : null
|
|
5236
|
+
};
|
|
5237
|
+
} catch {
|
|
5238
|
+
return null;
|
|
5239
|
+
}
|
|
5216
5240
|
}
|
|
5217
|
-
function
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5241
|
+
function createCurrentBalanceUrl(baseUrl) {
|
|
5242
|
+
const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
5243
|
+
return `${normalizedBaseUrl}/usage/current_balance`;
|
|
5244
|
+
}
|
|
5245
|
+
var DEFAULT_BASE_URL;
|
|
5246
|
+
var init_check_auth = __esm({
|
|
5247
|
+
"packages/poe-oauth/src/check-auth.ts"() {
|
|
5248
|
+
"use strict";
|
|
5249
|
+
DEFAULT_BASE_URL = "https://poe.com";
|
|
5250
|
+
}
|
|
5251
|
+
});
|
|
5252
|
+
|
|
5253
|
+
// packages/poe-oauth/src/oauth-client.ts
|
|
5254
|
+
import http from "node:http";
|
|
5255
|
+
import crypto from "node:crypto";
|
|
5256
|
+
function createOAuthClient(config2) {
|
|
5257
|
+
const fetchFn = config2.fetch ?? globalThis.fetch;
|
|
5258
|
+
return {
|
|
5259
|
+
authorize: () => startAuthorization(config2, fetchFn)
|
|
5260
|
+
};
|
|
5261
|
+
}
|
|
5262
|
+
function generateCodeVerifier() {
|
|
5263
|
+
return crypto.randomBytes(32).toString("base64url");
|
|
5264
|
+
}
|
|
5265
|
+
function generateCodeChallenge(verifier) {
|
|
5266
|
+
return crypto.createHash("sha256").update(verifier).digest("base64url");
|
|
5267
|
+
}
|
|
5268
|
+
async function startAuthorization(config2, fetchFn) {
|
|
5269
|
+
const authorizationEndpoint = config2.authorizationEndpoint ?? DEFAULT_AUTHORIZATION_ENDPOINT;
|
|
5270
|
+
const tokenEndpoint = config2.tokenEndpoint ?? DEFAULT_TOKEN_ENDPOINT;
|
|
5271
|
+
const codeVerifier = generateCodeVerifier();
|
|
5272
|
+
const codeChallenge = generateCodeChallenge(codeVerifier);
|
|
5273
|
+
const server = config2.createServer ? config2.createServer() : http.createServer();
|
|
5274
|
+
const port = await startServer(server);
|
|
5275
|
+
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
5276
|
+
const authorizationUrl = buildAuthorizationUrl({
|
|
5277
|
+
endpoint: authorizationEndpoint,
|
|
5278
|
+
clientId: config2.clientId,
|
|
5279
|
+
redirectUri,
|
|
5280
|
+
codeChallenge
|
|
5281
|
+
});
|
|
5282
|
+
const waitForResult = async () => {
|
|
5283
|
+
try {
|
|
5284
|
+
const code = await waitForAuthorizationCode(server, config2, authorizationUrl);
|
|
5285
|
+
return await exchangeCodeForApiKey({
|
|
5286
|
+
tokenEndpoint,
|
|
5287
|
+
code,
|
|
5288
|
+
codeVerifier,
|
|
5289
|
+
clientId: config2.clientId,
|
|
5290
|
+
redirectUri,
|
|
5291
|
+
fetchFn
|
|
5292
|
+
});
|
|
5293
|
+
} finally {
|
|
5294
|
+
server.closeAllConnections?.();
|
|
5295
|
+
server.close();
|
|
5296
|
+
}
|
|
5297
|
+
};
|
|
5298
|
+
return { authorizationUrl, waitForResult };
|
|
5299
|
+
}
|
|
5300
|
+
function startServer(server) {
|
|
5301
|
+
return new Promise((resolve) => {
|
|
5302
|
+
server.listen(0, "127.0.0.1", () => {
|
|
5303
|
+
const address = server.address();
|
|
5304
|
+
resolve(address.port);
|
|
5305
|
+
});
|
|
5306
|
+
});
|
|
5307
|
+
}
|
|
5308
|
+
function buildAuthorizationUrl(params) {
|
|
5309
|
+
const url2 = new URL(params.endpoint);
|
|
5310
|
+
url2.searchParams.set("response_type", "code");
|
|
5311
|
+
url2.searchParams.set("client_id", params.clientId);
|
|
5312
|
+
url2.searchParams.set("scope", "apikey:create");
|
|
5313
|
+
url2.searchParams.set("code_challenge", params.codeChallenge);
|
|
5314
|
+
url2.searchParams.set("code_challenge_method", "S256");
|
|
5315
|
+
url2.searchParams.set("redirect_uri", params.redirectUri);
|
|
5316
|
+
return url2.toString();
|
|
5317
|
+
}
|
|
5318
|
+
function waitForAuthorizationCode(server, config2, authorizationUrl) {
|
|
5319
|
+
return new Promise((resolve, reject) => {
|
|
5320
|
+
let settled = false;
|
|
5321
|
+
const settle = (fn) => {
|
|
5322
|
+
if (!settled) {
|
|
5323
|
+
settled = true;
|
|
5324
|
+
fn();
|
|
5325
|
+
}
|
|
5326
|
+
};
|
|
5327
|
+
server.on("request", (req, res) => {
|
|
5328
|
+
const url2 = new URL(req.url, `http://127.0.0.1`);
|
|
5329
|
+
if (url2.pathname !== "/callback") {
|
|
5330
|
+
res.writeHead(404);
|
|
5331
|
+
res.end("Not found");
|
|
5332
|
+
return;
|
|
5333
|
+
}
|
|
5334
|
+
const error2 = url2.searchParams.get("error");
|
|
5335
|
+
if (error2) {
|
|
5336
|
+
const description = url2.searchParams.get("error_description") ?? error2;
|
|
5337
|
+
res.writeHead(400);
|
|
5338
|
+
res.end(`Authorization failed: ${description}`);
|
|
5339
|
+
settle(() => reject(new Error(`OAuth authorization failed: ${error2} \u2014 ${description}`)));
|
|
5340
|
+
return;
|
|
5341
|
+
}
|
|
5342
|
+
const code = url2.searchParams.get("code");
|
|
5343
|
+
if (!code) {
|
|
5344
|
+
res.writeHead(400);
|
|
5345
|
+
res.end("Missing authorization code");
|
|
5346
|
+
settle(() => reject(new Error("OAuth callback missing authorization code")));
|
|
5347
|
+
return;
|
|
5348
|
+
}
|
|
5349
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
5350
|
+
res.end(buildSuccessPage(config2.landingPage));
|
|
5351
|
+
settle(() => resolve(code));
|
|
5352
|
+
});
|
|
5353
|
+
if (config2.readLine) {
|
|
5354
|
+
config2.readLine().then((input) => {
|
|
5355
|
+
const code = extractCodeFromInput(input);
|
|
5356
|
+
if (code) {
|
|
5357
|
+
settle(() => resolve(code));
|
|
5358
|
+
}
|
|
5359
|
+
}).catch(() => {
|
|
5360
|
+
});
|
|
5361
|
+
}
|
|
5362
|
+
if (config2.openBrowser) {
|
|
5363
|
+
config2.openBrowser(authorizationUrl).catch(
|
|
5364
|
+
(err) => settle(() => reject(err))
|
|
5365
|
+
);
|
|
5366
|
+
}
|
|
5367
|
+
});
|
|
5368
|
+
}
|
|
5369
|
+
function extractCodeFromInput(input) {
|
|
5370
|
+
const trimmed = input.replace(/[\r\n]/g, "").trim();
|
|
5371
|
+
if (trimmed.length === 0) {
|
|
5372
|
+
return null;
|
|
5373
|
+
}
|
|
5374
|
+
try {
|
|
5375
|
+
const url2 = new URL(trimmed);
|
|
5376
|
+
return url2.searchParams.get("code");
|
|
5377
|
+
} catch {
|
|
5378
|
+
return trimmed;
|
|
5379
|
+
}
|
|
5380
|
+
}
|
|
5381
|
+
async function exchangeCodeForApiKey(params) {
|
|
5382
|
+
const body = new URLSearchParams({
|
|
5383
|
+
grant_type: "authorization_code",
|
|
5384
|
+
code: params.code,
|
|
5385
|
+
code_verifier: params.codeVerifier,
|
|
5386
|
+
client_id: params.clientId,
|
|
5387
|
+
redirect_uri: params.redirectUri
|
|
5388
|
+
});
|
|
5389
|
+
const response = await params.fetchFn(params.tokenEndpoint, {
|
|
5390
|
+
method: "POST",
|
|
5391
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
5392
|
+
body: body.toString()
|
|
5393
|
+
});
|
|
5394
|
+
if (!response.ok) {
|
|
5395
|
+
const text4 = await response.text();
|
|
5396
|
+
const description = parseErrorDescription(text4);
|
|
5397
|
+
throw new Error(description ?? `Token exchange failed (${response.status}): ${text4}`);
|
|
5227
5398
|
}
|
|
5228
|
-
|
|
5399
|
+
const data = await response.json();
|
|
5400
|
+
if (typeof data.api_key !== "string" || data.api_key.length === 0) {
|
|
5401
|
+
throw new Error("Token response missing api_key field");
|
|
5402
|
+
}
|
|
5403
|
+
return {
|
|
5404
|
+
apiKey: data.api_key,
|
|
5405
|
+
expiresIn: typeof data.api_key_expires_in === "number" ? data.api_key_expires_in : null
|
|
5406
|
+
};
|
|
5229
5407
|
}
|
|
5230
|
-
function
|
|
5231
|
-
|
|
5408
|
+
function parseErrorDescription(text4) {
|
|
5409
|
+
try {
|
|
5410
|
+
const data = JSON.parse(text4);
|
|
5411
|
+
if (typeof data.error_description === "string") {
|
|
5412
|
+
return data.error_description;
|
|
5413
|
+
}
|
|
5414
|
+
if (typeof data.error === "string") {
|
|
5415
|
+
return data.error;
|
|
5416
|
+
}
|
|
5417
|
+
} catch {
|
|
5418
|
+
}
|
|
5419
|
+
return null;
|
|
5232
5420
|
}
|
|
5233
|
-
function
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5421
|
+
function escapeHtml(text4) {
|
|
5422
|
+
return text4.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5423
|
+
}
|
|
5424
|
+
function buildSuccessPage(landingPage) {
|
|
5425
|
+
const title = landingPage?.title ?? "Connected to Poe";
|
|
5426
|
+
const body = landingPage?.body ?? "You can close this tab and return to your terminal.";
|
|
5427
|
+
return [
|
|
5428
|
+
"<!DOCTYPE html>",
|
|
5429
|
+
`<html><head><meta charset=utf-8><title>${escapeHtml(title)}</title></head>`,
|
|
5430
|
+
'<body style="font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0">',
|
|
5431
|
+
'<div style="text-align:center">',
|
|
5432
|
+
`<h1>${escapeHtml(title)}</h1>`,
|
|
5433
|
+
`<p style="color:#666">${escapeHtml(body)}</p>`,
|
|
5434
|
+
"</div></body></html>"
|
|
5435
|
+
].join("");
|
|
5436
|
+
}
|
|
5437
|
+
var DEFAULT_AUTHORIZATION_ENDPOINT, DEFAULT_TOKEN_ENDPOINT;
|
|
5438
|
+
var init_oauth_client = __esm({
|
|
5439
|
+
"packages/poe-oauth/src/oauth-client.ts"() {
|
|
5440
|
+
"use strict";
|
|
5441
|
+
DEFAULT_AUTHORIZATION_ENDPOINT = "https://poe.com/oauth/authorize";
|
|
5442
|
+
DEFAULT_TOKEN_ENDPOINT = "https://api.poe.com/token";
|
|
5443
|
+
}
|
|
5444
|
+
});
|
|
5445
|
+
|
|
5446
|
+
// packages/poe-oauth/src/index.ts
|
|
5447
|
+
var init_src7 = __esm({
|
|
5448
|
+
"packages/poe-oauth/src/index.ts"() {
|
|
5449
|
+
"use strict";
|
|
5450
|
+
init_check_auth();
|
|
5451
|
+
init_oauth_client();
|
|
5238
5452
|
}
|
|
5239
|
-
|
|
5453
|
+
});
|
|
5454
|
+
|
|
5455
|
+
// src/cli/options.ts
|
|
5456
|
+
function stripBracketedPaste(value) {
|
|
5457
|
+
return value.replace(/\x1b\[200~/g, "").replace(/\x1b\[201~/g, "").replace(/undefinedndefined$/, "").replace(/undefined$/, "").replace(/ndefined$/, "");
|
|
5240
5458
|
}
|
|
5241
5459
|
function createOptionResolvers(init) {
|
|
5242
5460
|
const ensure = async (input) => {
|
|
@@ -5253,7 +5471,7 @@ function createOptionResolvers(init) {
|
|
|
5253
5471
|
}
|
|
5254
5472
|
return result;
|
|
5255
5473
|
};
|
|
5256
|
-
const
|
|
5474
|
+
const normalizeApiKey = (value) => {
|
|
5257
5475
|
const sanitized = stripBracketedPaste(value);
|
|
5258
5476
|
const trimmed = sanitized.trim();
|
|
5259
5477
|
if (trimmed.length === 0) {
|
|
@@ -5261,20 +5479,15 @@ function createOptionResolvers(init) {
|
|
|
5261
5479
|
}
|
|
5262
5480
|
return trimmed;
|
|
5263
5481
|
};
|
|
5264
|
-
const
|
|
5265
|
-
|
|
5266
|
-
if (assumeYes) return false;
|
|
5267
|
-
return await init.confirm(
|
|
5268
|
-
"Key doesn't match expected API key format. Use it anyway?"
|
|
5269
|
-
);
|
|
5482
|
+
const validateApiKey = async (apiKey) => {
|
|
5483
|
+
return await init.checkAuth(apiKey);
|
|
5270
5484
|
};
|
|
5271
5485
|
const resolveApiKey2 = async (input) => {
|
|
5272
5486
|
const assumeYes = input.assumeYes ?? false;
|
|
5273
5487
|
const allowStored = input.allowStored ?? true;
|
|
5274
5488
|
if (input.value != null) {
|
|
5275
|
-
const apiKey =
|
|
5276
|
-
|
|
5277
|
-
if (!accepted) {
|
|
5489
|
+
const apiKey = normalizeApiKey(input.value);
|
|
5490
|
+
if (!await validateApiKey(apiKey)) {
|
|
5278
5491
|
throw new Error("API key rejected.");
|
|
5279
5492
|
}
|
|
5280
5493
|
if (!input.dryRun) {
|
|
@@ -5288,9 +5501,8 @@ function createOptionResolvers(init) {
|
|
|
5288
5501
|
"Use API key from POE_API_KEY environment variable?"
|
|
5289
5502
|
);
|
|
5290
5503
|
if (useEnv) {
|
|
5291
|
-
const apiKey =
|
|
5292
|
-
|
|
5293
|
-
if (accepted) {
|
|
5504
|
+
const apiKey = normalizeApiKey(envValue);
|
|
5505
|
+
if (await validateApiKey(apiKey)) {
|
|
5294
5506
|
if (!input.dryRun) {
|
|
5295
5507
|
await init.apiKeyStore.write(apiKey);
|
|
5296
5508
|
}
|
|
@@ -5304,12 +5516,12 @@ function createOptionResolvers(init) {
|
|
|
5304
5516
|
if (allowStored) {
|
|
5305
5517
|
const stored = await init.apiKeyStore.read();
|
|
5306
5518
|
if (stored) {
|
|
5307
|
-
return
|
|
5519
|
+
return normalizeApiKey(stored);
|
|
5308
5520
|
}
|
|
5309
5521
|
}
|
|
5310
5522
|
if (init.loginViaOAuth) {
|
|
5311
5523
|
const apiKey = await init.loginViaOAuth();
|
|
5312
|
-
const normalized =
|
|
5524
|
+
const normalized = normalizeApiKey(apiKey);
|
|
5313
5525
|
if (!input.dryRun) {
|
|
5314
5526
|
await init.apiKeyStore.write(normalized);
|
|
5315
5527
|
}
|
|
@@ -5324,15 +5536,14 @@ function createOptionResolvers(init) {
|
|
|
5324
5536
|
}
|
|
5325
5537
|
let apiKey;
|
|
5326
5538
|
try {
|
|
5327
|
-
apiKey =
|
|
5539
|
+
apiKey = normalizeApiKey(result);
|
|
5328
5540
|
} catch (error2) {
|
|
5329
5541
|
if (error2 instanceof Error && error2.message === "POE API key cannot be empty.") {
|
|
5330
5542
|
continue;
|
|
5331
5543
|
}
|
|
5332
5544
|
throw error2;
|
|
5333
5545
|
}
|
|
5334
|
-
|
|
5335
|
-
if (!accepted) {
|
|
5546
|
+
if (!await validateApiKey(apiKey)) {
|
|
5336
5547
|
continue;
|
|
5337
5548
|
}
|
|
5338
5549
|
if (!input.dryRun) {
|
|
@@ -5395,19 +5606,12 @@ function createOptionResolvers(init) {
|
|
|
5395
5606
|
resolveModel: resolveModel2,
|
|
5396
5607
|
resolveReasoning,
|
|
5397
5608
|
resolveConfigName,
|
|
5398
|
-
resolveApiKey: resolveApiKey2
|
|
5399
|
-
normalizeApiKey: normalizeApiKey2
|
|
5609
|
+
resolveApiKey: resolveApiKey2
|
|
5400
5610
|
};
|
|
5401
5611
|
}
|
|
5402
|
-
var API_KEY_REFERENCE_LENGTH, API_KEY_MIN_LENGTH_RATIO, MIN_API_KEY_LENGTH;
|
|
5403
5612
|
var init_options = __esm({
|
|
5404
5613
|
"src/cli/options.ts"() {
|
|
5405
5614
|
"use strict";
|
|
5406
|
-
API_KEY_REFERENCE_LENGTH = 43;
|
|
5407
|
-
API_KEY_MIN_LENGTH_RATIO = 0.8;
|
|
5408
|
-
MIN_API_KEY_LENGTH = Math.ceil(
|
|
5409
|
-
API_KEY_REFERENCE_LENGTH * API_KEY_MIN_LENGTH_RATIO
|
|
5410
|
-
);
|
|
5411
5615
|
}
|
|
5412
5616
|
});
|
|
5413
5617
|
|
|
@@ -6270,7 +6474,8 @@ function createSdkContainer(options) {
|
|
|
6270
6474
|
read: readApiKey,
|
|
6271
6475
|
write: writeApiKey
|
|
6272
6476
|
},
|
|
6273
|
-
confirm: async () => true
|
|
6477
|
+
confirm: async () => true,
|
|
6478
|
+
checkAuth: async (apiKey) => await checkAuth({ apiKey }) !== null
|
|
6274
6479
|
});
|
|
6275
6480
|
const registry2 = createServiceRegistry();
|
|
6276
6481
|
const providers = getDefaultProviders().filter((adapter) => !adapter.disabled);
|
|
@@ -6327,6 +6532,7 @@ var init_container = __esm({
|
|
|
6327
6532
|
init_service_registry();
|
|
6328
6533
|
init_context();
|
|
6329
6534
|
init_prompts2();
|
|
6535
|
+
init_src7();
|
|
6330
6536
|
init_options();
|
|
6331
6537
|
init_logger2();
|
|
6332
6538
|
init_error_logger();
|
|
@@ -7671,7 +7877,7 @@ var init_run_report = __esm({
|
|
|
7671
7877
|
});
|
|
7672
7878
|
|
|
7673
7879
|
// packages/poe-acp-client/src/index.ts
|
|
7674
|
-
var
|
|
7880
|
+
var init_src8 = __esm({
|
|
7675
7881
|
"packages/poe-acp-client/src/index.ts"() {
|
|
7676
7882
|
"use strict";
|
|
7677
7883
|
init_acp_client();
|
|
@@ -9710,7 +9916,7 @@ var AgentHost;
|
|
|
9710
9916
|
var init_agent_host = __esm({
|
|
9711
9917
|
"packages/poe-agent/src/runtime/agent-host.ts"() {
|
|
9712
9918
|
"use strict";
|
|
9713
|
-
|
|
9919
|
+
init_src8();
|
|
9714
9920
|
init_agent_session();
|
|
9715
9921
|
init_acp_core();
|
|
9716
9922
|
init_run_context();
|
|
@@ -10997,7 +11203,7 @@ var init_internal = __esm({
|
|
|
10997
11203
|
});
|
|
10998
11204
|
|
|
10999
11205
|
// packages/tiny-mcp-client/src/index.ts
|
|
11000
|
-
var
|
|
11206
|
+
var init_src9 = __esm({
|
|
11001
11207
|
"packages/tiny-mcp-client/src/index.ts"() {
|
|
11002
11208
|
"use strict";
|
|
11003
11209
|
init_internal();
|
|
@@ -11046,7 +11252,7 @@ var DEFAULT_MCP_CLIENT_INFO, PluginApiImpl;
|
|
|
11046
11252
|
var init_plugin_api_impl = __esm({
|
|
11047
11253
|
"packages/poe-agent/src/runtime/plugin-api-impl.ts"() {
|
|
11048
11254
|
"use strict";
|
|
11049
|
-
|
|
11255
|
+
init_src9();
|
|
11050
11256
|
init_hooks();
|
|
11051
11257
|
DEFAULT_MCP_CLIENT_INFO = {
|
|
11052
11258
|
name: "poe-agent",
|
|
@@ -11613,7 +11819,7 @@ __export(src_exports, {
|
|
|
11613
11819
|
agent: () => agent,
|
|
11614
11820
|
createAgentSession: () => createAgentSession
|
|
11615
11821
|
});
|
|
11616
|
-
var
|
|
11822
|
+
var init_src10 = __esm({
|
|
11617
11823
|
"packages/poe-agent/src/index.ts"() {
|
|
11618
11824
|
"use strict";
|
|
11619
11825
|
init_agent();
|
|
@@ -11951,7 +12157,7 @@ function createInMemoryAcpTransport2(options) {
|
|
|
11951
12157
|
}
|
|
11952
12158
|
if (method === "session/new") {
|
|
11953
12159
|
const request = params;
|
|
11954
|
-
const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (
|
|
12160
|
+
const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (init_src10(), src_exports));
|
|
11955
12161
|
const session = await createAgentSession2({
|
|
11956
12162
|
model: options.model,
|
|
11957
12163
|
cwd: request.cwd || options.cwd,
|
|
@@ -12101,7 +12307,7 @@ var init_poe_agent = __esm({
|
|
|
12101
12307
|
"src/providers/poe-agent.ts"() {
|
|
12102
12308
|
"use strict";
|
|
12103
12309
|
init_constants();
|
|
12104
|
-
|
|
12310
|
+
init_src8();
|
|
12105
12311
|
init_create_provider();
|
|
12106
12312
|
poeAgentService = createProvider({
|
|
12107
12313
|
id: "poe-agent",
|
|
@@ -13100,7 +13306,7 @@ var init_pipeline = __esm({
|
|
|
13100
13306
|
});
|
|
13101
13307
|
|
|
13102
13308
|
// packages/pipeline/src/index.ts
|
|
13103
|
-
var
|
|
13309
|
+
var init_src11 = __esm({
|
|
13104
13310
|
"packages/pipeline/src/index.ts"() {
|
|
13105
13311
|
"use strict";
|
|
13106
13312
|
init_loader();
|
|
@@ -13132,7 +13338,7 @@ async function runPipeline2(options) {
|
|
|
13132
13338
|
var init_pipeline2 = __esm({
|
|
13133
13339
|
async "src/sdk/pipeline.ts"() {
|
|
13134
13340
|
"use strict";
|
|
13135
|
-
|
|
13341
|
+
init_src11();
|
|
13136
13342
|
init_src5();
|
|
13137
13343
|
await init_spawn3();
|
|
13138
13344
|
}
|
|
@@ -13382,7 +13588,7 @@ var init_ralph = __esm({
|
|
|
13382
13588
|
});
|
|
13383
13589
|
|
|
13384
13590
|
// packages/ralph/src/index.ts
|
|
13385
|
-
var
|
|
13591
|
+
var init_src12 = __esm({
|
|
13386
13592
|
"packages/ralph/src/index.ts"() {
|
|
13387
13593
|
"use strict";
|
|
13388
13594
|
init_discovery2();
|
|
@@ -13411,7 +13617,7 @@ async function runRalph2(options) {
|
|
|
13411
13617
|
var init_ralph2 = __esm({
|
|
13412
13618
|
async "src/sdk/ralph.ts"() {
|
|
13413
13619
|
"use strict";
|
|
13414
|
-
|
|
13620
|
+
init_src12();
|
|
13415
13621
|
init_src5();
|
|
13416
13622
|
await init_spawn3();
|
|
13417
13623
|
}
|
|
@@ -13576,218 +13782,6 @@ var init_client_instance = __esm({
|
|
|
13576
13782
|
}
|
|
13577
13783
|
});
|
|
13578
13784
|
|
|
13579
|
-
// packages/poe-oauth/src/check-auth.ts
|
|
13580
|
-
var init_check_auth = __esm({
|
|
13581
|
-
"packages/poe-oauth/src/check-auth.ts"() {
|
|
13582
|
-
"use strict";
|
|
13583
|
-
}
|
|
13584
|
-
});
|
|
13585
|
-
|
|
13586
|
-
// packages/poe-oauth/src/api-key-validation.ts
|
|
13587
|
-
var init_api_key_validation = __esm({
|
|
13588
|
-
"packages/poe-oauth/src/api-key-validation.ts"() {
|
|
13589
|
-
"use strict";
|
|
13590
|
-
}
|
|
13591
|
-
});
|
|
13592
|
-
|
|
13593
|
-
// packages/poe-oauth/src/oauth-client.ts
|
|
13594
|
-
import http from "node:http";
|
|
13595
|
-
import crypto from "node:crypto";
|
|
13596
|
-
function createOAuthClient(config2) {
|
|
13597
|
-
const fetchFn = config2.fetch ?? globalThis.fetch;
|
|
13598
|
-
return {
|
|
13599
|
-
authorize: () => startAuthorization(config2, fetchFn)
|
|
13600
|
-
};
|
|
13601
|
-
}
|
|
13602
|
-
function generateCodeVerifier() {
|
|
13603
|
-
return crypto.randomBytes(32).toString("base64url");
|
|
13604
|
-
}
|
|
13605
|
-
function generateCodeChallenge(verifier) {
|
|
13606
|
-
return crypto.createHash("sha256").update(verifier).digest("base64url");
|
|
13607
|
-
}
|
|
13608
|
-
async function startAuthorization(config2, fetchFn) {
|
|
13609
|
-
const authorizationEndpoint = config2.authorizationEndpoint ?? DEFAULT_AUTHORIZATION_ENDPOINT;
|
|
13610
|
-
const tokenEndpoint = config2.tokenEndpoint ?? DEFAULT_TOKEN_ENDPOINT;
|
|
13611
|
-
const codeVerifier = generateCodeVerifier();
|
|
13612
|
-
const codeChallenge = generateCodeChallenge(codeVerifier);
|
|
13613
|
-
const server = config2.createServer ? config2.createServer() : http.createServer();
|
|
13614
|
-
const port = await startServer(server);
|
|
13615
|
-
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
13616
|
-
const authorizationUrl = buildAuthorizationUrl({
|
|
13617
|
-
endpoint: authorizationEndpoint,
|
|
13618
|
-
clientId: config2.clientId,
|
|
13619
|
-
redirectUri,
|
|
13620
|
-
codeChallenge
|
|
13621
|
-
});
|
|
13622
|
-
const waitForResult = async () => {
|
|
13623
|
-
try {
|
|
13624
|
-
const code = await waitForAuthorizationCode(server, config2, authorizationUrl);
|
|
13625
|
-
return await exchangeCodeForApiKey({
|
|
13626
|
-
tokenEndpoint,
|
|
13627
|
-
code,
|
|
13628
|
-
codeVerifier,
|
|
13629
|
-
clientId: config2.clientId,
|
|
13630
|
-
redirectUri,
|
|
13631
|
-
fetchFn
|
|
13632
|
-
});
|
|
13633
|
-
} finally {
|
|
13634
|
-
server.closeAllConnections?.();
|
|
13635
|
-
server.close();
|
|
13636
|
-
}
|
|
13637
|
-
};
|
|
13638
|
-
return { authorizationUrl, waitForResult };
|
|
13639
|
-
}
|
|
13640
|
-
function startServer(server) {
|
|
13641
|
-
return new Promise((resolve) => {
|
|
13642
|
-
server.listen(0, "127.0.0.1", () => {
|
|
13643
|
-
const address = server.address();
|
|
13644
|
-
resolve(address.port);
|
|
13645
|
-
});
|
|
13646
|
-
});
|
|
13647
|
-
}
|
|
13648
|
-
function buildAuthorizationUrl(params) {
|
|
13649
|
-
const url2 = new URL(params.endpoint);
|
|
13650
|
-
url2.searchParams.set("response_type", "code");
|
|
13651
|
-
url2.searchParams.set("client_id", params.clientId);
|
|
13652
|
-
url2.searchParams.set("scope", "apikey:create");
|
|
13653
|
-
url2.searchParams.set("code_challenge", params.codeChallenge);
|
|
13654
|
-
url2.searchParams.set("code_challenge_method", "S256");
|
|
13655
|
-
url2.searchParams.set("redirect_uri", params.redirectUri);
|
|
13656
|
-
return url2.toString();
|
|
13657
|
-
}
|
|
13658
|
-
function waitForAuthorizationCode(server, config2, authorizationUrl) {
|
|
13659
|
-
return new Promise((resolve, reject) => {
|
|
13660
|
-
let settled = false;
|
|
13661
|
-
const settle = (fn) => {
|
|
13662
|
-
if (!settled) {
|
|
13663
|
-
settled = true;
|
|
13664
|
-
fn();
|
|
13665
|
-
}
|
|
13666
|
-
};
|
|
13667
|
-
server.on("request", (req, res) => {
|
|
13668
|
-
const url2 = new URL(req.url, `http://127.0.0.1`);
|
|
13669
|
-
if (url2.pathname !== "/callback") {
|
|
13670
|
-
res.writeHead(404);
|
|
13671
|
-
res.end("Not found");
|
|
13672
|
-
return;
|
|
13673
|
-
}
|
|
13674
|
-
const error2 = url2.searchParams.get("error");
|
|
13675
|
-
if (error2) {
|
|
13676
|
-
const description = url2.searchParams.get("error_description") ?? error2;
|
|
13677
|
-
res.writeHead(400);
|
|
13678
|
-
res.end(`Authorization failed: ${description}`);
|
|
13679
|
-
settle(() => reject(new Error(`OAuth authorization failed: ${error2} \u2014 ${description}`)));
|
|
13680
|
-
return;
|
|
13681
|
-
}
|
|
13682
|
-
const code = url2.searchParams.get("code");
|
|
13683
|
-
if (!code) {
|
|
13684
|
-
res.writeHead(400);
|
|
13685
|
-
res.end("Missing authorization code");
|
|
13686
|
-
settle(() => reject(new Error("OAuth callback missing authorization code")));
|
|
13687
|
-
return;
|
|
13688
|
-
}
|
|
13689
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
13690
|
-
res.end(buildSuccessPage());
|
|
13691
|
-
settle(() => resolve(code));
|
|
13692
|
-
});
|
|
13693
|
-
if (config2.readLine) {
|
|
13694
|
-
config2.readLine().then((input) => {
|
|
13695
|
-
const code = extractCodeFromInput(input);
|
|
13696
|
-
if (code) {
|
|
13697
|
-
settle(() => resolve(code));
|
|
13698
|
-
}
|
|
13699
|
-
}).catch(() => {
|
|
13700
|
-
});
|
|
13701
|
-
}
|
|
13702
|
-
if (config2.openBrowser) {
|
|
13703
|
-
config2.openBrowser(authorizationUrl).catch(
|
|
13704
|
-
(err) => settle(() => reject(err))
|
|
13705
|
-
);
|
|
13706
|
-
}
|
|
13707
|
-
});
|
|
13708
|
-
}
|
|
13709
|
-
function extractCodeFromInput(input) {
|
|
13710
|
-
const trimmed = input.replace(/[\r\n]/g, "").trim();
|
|
13711
|
-
if (trimmed.length === 0) {
|
|
13712
|
-
return null;
|
|
13713
|
-
}
|
|
13714
|
-
try {
|
|
13715
|
-
const url2 = new URL(trimmed);
|
|
13716
|
-
return url2.searchParams.get("code");
|
|
13717
|
-
} catch {
|
|
13718
|
-
return trimmed;
|
|
13719
|
-
}
|
|
13720
|
-
}
|
|
13721
|
-
async function exchangeCodeForApiKey(params) {
|
|
13722
|
-
const body = new URLSearchParams({
|
|
13723
|
-
grant_type: "authorization_code",
|
|
13724
|
-
code: params.code,
|
|
13725
|
-
code_verifier: params.codeVerifier,
|
|
13726
|
-
client_id: params.clientId,
|
|
13727
|
-
redirect_uri: params.redirectUri
|
|
13728
|
-
});
|
|
13729
|
-
const response = await params.fetchFn(params.tokenEndpoint, {
|
|
13730
|
-
method: "POST",
|
|
13731
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
13732
|
-
body: body.toString()
|
|
13733
|
-
});
|
|
13734
|
-
if (!response.ok) {
|
|
13735
|
-
const text4 = await response.text();
|
|
13736
|
-
const description = parseErrorDescription(text4);
|
|
13737
|
-
throw new Error(description ?? `Token exchange failed (${response.status}): ${text4}`);
|
|
13738
|
-
}
|
|
13739
|
-
const data = await response.json();
|
|
13740
|
-
if (typeof data.api_key !== "string" || data.api_key.length === 0) {
|
|
13741
|
-
throw new Error("Token response missing api_key field");
|
|
13742
|
-
}
|
|
13743
|
-
return {
|
|
13744
|
-
apiKey: data.api_key,
|
|
13745
|
-
expiresIn: typeof data.api_key_expires_in === "number" ? data.api_key_expires_in : null
|
|
13746
|
-
};
|
|
13747
|
-
}
|
|
13748
|
-
function parseErrorDescription(text4) {
|
|
13749
|
-
try {
|
|
13750
|
-
const data = JSON.parse(text4);
|
|
13751
|
-
if (typeof data.error_description === "string") {
|
|
13752
|
-
return data.error_description;
|
|
13753
|
-
}
|
|
13754
|
-
if (typeof data.error === "string") {
|
|
13755
|
-
return data.error;
|
|
13756
|
-
}
|
|
13757
|
-
} catch {
|
|
13758
|
-
}
|
|
13759
|
-
return null;
|
|
13760
|
-
}
|
|
13761
|
-
function buildSuccessPage() {
|
|
13762
|
-
return [
|
|
13763
|
-
"<!DOCTYPE html>",
|
|
13764
|
-
"<html><head><meta charset=utf-8><title>Connected to Poe</title></head>",
|
|
13765
|
-
'<body style="font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0">',
|
|
13766
|
-
'<div style="text-align:center">',
|
|
13767
|
-
"<h1>Connected to Poe</h1>",
|
|
13768
|
-
'<p style="color:#666">You can close this tab and return to your terminal.</p>',
|
|
13769
|
-
"</div></body></html>"
|
|
13770
|
-
].join("");
|
|
13771
|
-
}
|
|
13772
|
-
var DEFAULT_AUTHORIZATION_ENDPOINT, DEFAULT_TOKEN_ENDPOINT;
|
|
13773
|
-
var init_oauth_client = __esm({
|
|
13774
|
-
"packages/poe-oauth/src/oauth-client.ts"() {
|
|
13775
|
-
"use strict";
|
|
13776
|
-
DEFAULT_AUTHORIZATION_ENDPOINT = "https://poe.com/oauth/authorize";
|
|
13777
|
-
DEFAULT_TOKEN_ENDPOINT = "https://api.poe.com/token";
|
|
13778
|
-
}
|
|
13779
|
-
});
|
|
13780
|
-
|
|
13781
|
-
// packages/poe-oauth/src/index.ts
|
|
13782
|
-
var init_src12 = __esm({
|
|
13783
|
-
"packages/poe-oauth/src/index.ts"() {
|
|
13784
|
-
"use strict";
|
|
13785
|
-
init_check_auth();
|
|
13786
|
-
init_api_key_validation();
|
|
13787
|
-
init_oauth_client();
|
|
13788
|
-
}
|
|
13789
|
-
});
|
|
13790
|
-
|
|
13791
13785
|
// src/cli/oauth-login.ts
|
|
13792
13786
|
import { exec as exec2 } from "node:child_process";
|
|
13793
13787
|
import readline from "node:readline";
|
|
@@ -13830,7 +13824,7 @@ function openInBrowser(url2) {
|
|
|
13830
13824
|
var init_oauth_login = __esm({
|
|
13831
13825
|
"src/cli/oauth-login.ts"() {
|
|
13832
13826
|
"use strict";
|
|
13833
|
-
|
|
13827
|
+
init_src7();
|
|
13834
13828
|
init_src4();
|
|
13835
13829
|
}
|
|
13836
13830
|
});
|
|
@@ -13900,6 +13894,7 @@ function createCliContainer(dependencies) {
|
|
|
13900
13894
|
read: readApiKey,
|
|
13901
13895
|
write: writeApiKey
|
|
13902
13896
|
},
|
|
13897
|
+
checkAuth: async (apiKey) => await checkAuth({ apiKey }) !== null,
|
|
13903
13898
|
confirm: async (message) => {
|
|
13904
13899
|
const result = await confirm2({ message });
|
|
13905
13900
|
if (isCancel2(result)) {
|
|
@@ -13948,6 +13943,7 @@ var init_container2 = __esm({
|
|
|
13948
13943
|
init_service_registry();
|
|
13949
13944
|
init_context();
|
|
13950
13945
|
init_prompts2();
|
|
13946
|
+
init_src7();
|
|
13951
13947
|
init_options();
|
|
13952
13948
|
init_logger2();
|
|
13953
13949
|
init_error_logger();
|
|
@@ -14329,7 +14325,7 @@ function registerAgentCommand(program, container) {
|
|
|
14329
14325
|
}
|
|
14330
14326
|
let session;
|
|
14331
14327
|
try {
|
|
14332
|
-
const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (
|
|
14328
|
+
const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (init_src10(), src_exports));
|
|
14333
14329
|
session = await createAgentSession2({
|
|
14334
14330
|
model: options.model,
|
|
14335
14331
|
apiKey: options.apiKey,
|
|
@@ -39408,7 +39404,7 @@ var init_pipeline4 = __esm({
|
|
|
39408
39404
|
init_errors();
|
|
39409
39405
|
init_shared();
|
|
39410
39406
|
await init_pipeline2();
|
|
39411
|
-
|
|
39407
|
+
init_src11();
|
|
39412
39408
|
DEFAULT_PIPELINE_AGENT = "claude-code";
|
|
39413
39409
|
DEFAULT_PIPELINE_SCOPE = "local";
|
|
39414
39410
|
pipelineTemplatesCache = null;
|
|
@@ -39627,7 +39623,7 @@ var init_ralph3 = __esm({
|
|
|
39627
39623
|
init_src4();
|
|
39628
39624
|
init_src3();
|
|
39629
39625
|
init_src5();
|
|
39630
|
-
|
|
39626
|
+
init_src12();
|
|
39631
39627
|
init_errors();
|
|
39632
39628
|
init_shared();
|
|
39633
39629
|
await init_ralph2();
|
|
@@ -39641,7 +39637,7 @@ var init_package = __esm({
|
|
|
39641
39637
|
"package.json"() {
|
|
39642
39638
|
package_default = {
|
|
39643
39639
|
name: "poe-code",
|
|
39644
|
-
version: "3.0.
|
|
39640
|
+
version: "3.0.103",
|
|
39645
39641
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
39646
39642
|
type: "module",
|
|
39647
39643
|
main: "./dist/index.js",
|