@eddyskywalker/dsh-chatgpt-subscription 0.81.3 → 0.82.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/CHANGELOG.md +8 -0
- package/lib/client.js +735 -377
- package/lib/client.js.map +1 -1
- package/lib/index.js +700 -40
- package/lib/types/client/CodexComposerQuota.d.ts.map +1 -1
- package/lib/types/client/common/ComposerQuotaBadge.d.ts +25 -4
- package/lib/types/client/common/ComposerQuotaBadge.d.ts.map +1 -1
- package/lib/types/client/compact-after-turn/CompactAfterTurnToggle.d.ts +24 -0
- package/lib/types/client/compact-after-turn/CompactAfterTurnToggle.d.ts.map +1 -0
- package/lib/types/client/compact-after-turn/locales.d.ts +34 -0
- package/lib/types/client/compact-after-turn/locales.d.ts.map +1 -0
- package/lib/types/client/compact-after-turn/styles.d.ts +2 -0
- package/lib/types/client/compact-after-turn/styles.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/kimi-code/styles.d.ts.map +1 -1
- package/lib/types/client/locales-ru/compact-after-turn.d.ts +3 -0
- package/lib/types/client/locales-ru/compact-after-turn.d.ts.map +1 -0
- package/lib/types/client/locales-ru/index.d.ts.map +1 -1
- package/lib/types/client/opendesign/styles.d.ts.map +1 -1
- package/lib/types/client/styles.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/host/aws-quick/adapter.d.ts +5 -0
- package/lib/types/host/aws-quick/adapter.d.ts.map +1 -1
- package/lib/types/host/aws-quick/client.d.ts +9 -0
- package/lib/types/host/aws-quick/client.d.ts.map +1 -1
- package/lib/types/host/aws-quick/markup.d.ts +42 -0
- package/lib/types/host/aws-quick/markup.d.ts.map +1 -0
- package/lib/types/host/aws-quick/protocol.d.ts +19 -0
- package/lib/types/host/aws-quick/protocol.d.ts.map +1 -1
- package/lib/types/host/compact-after-turn/index.d.ts +126 -0
- package/lib/types/host/compact-after-turn/index.d.ts.map +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/compact-after-turn.d.ts +45 -0
- package/lib/types/shared/compact-after-turn.d.ts.map +1 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -840,7 +840,7 @@ const ROUTE_PREFIX$5 = "/api/dsh-chatgpt-subscription";
|
|
|
840
840
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
841
841
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
842
842
|
*/
|
|
843
|
-
const PLUGIN_VERSION = "0.
|
|
843
|
+
const PLUGIN_VERSION = "0.82.0";
|
|
844
844
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
845
845
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
846
846
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -5460,7 +5460,7 @@ var CodexAdoptedCredentialError = class extends Error {
|
|
|
5460
5460
|
function codexPoolPath() {
|
|
5461
5461
|
return path.join(dshHomeDir(), "storages", "codex-pool.json");
|
|
5462
5462
|
}
|
|
5463
|
-
function optionalString$
|
|
5463
|
+
function optionalString$19(record, key) {
|
|
5464
5464
|
const value = record[key];
|
|
5465
5465
|
if (value === void 0 || value === null) return void 0;
|
|
5466
5466
|
if (typeof value !== "string") throw new Error("ChatGPT pool account field is invalid");
|
|
@@ -5486,13 +5486,13 @@ function parseCodexPoolData(value) {
|
|
|
5486
5486
|
adopted,
|
|
5487
5487
|
source: adopted ? CODEX_CLI_CREDENTIAL_SOURCE : "managed"
|
|
5488
5488
|
};
|
|
5489
|
-
const sourcePath = optionalString$
|
|
5489
|
+
const sourcePath = optionalString$19(raw, "sourcePath") ?? credentials.sourcePath;
|
|
5490
5490
|
if (adopted && sourcePath !== void 0) account.sourcePath = sourcePath;
|
|
5491
|
-
const email = optionalString$
|
|
5491
|
+
const email = optionalString$19(raw, "email") ?? credentials.email;
|
|
5492
5492
|
if (email !== void 0) account.email = email;
|
|
5493
|
-
const planType = optionalString$
|
|
5493
|
+
const planType = optionalString$19(raw, "planType") ?? credentials.planType;
|
|
5494
5494
|
if (planType !== void 0) account.planType = planType;
|
|
5495
|
-
const accountId = optionalString$
|
|
5495
|
+
const accountId = optionalString$19(raw, "accountId") ?? credentials.accountId;
|
|
5496
5496
|
if (accountId !== void 0) account.accountId = accountId;
|
|
5497
5497
|
if (typeof raw.lastUsedAt === "number") account.lastUsedAt = raw.lastUsedAt;
|
|
5498
5498
|
if (typeof raw.cooldownUntil === "number") account.cooldownUntil = raw.cooldownUntil;
|
|
@@ -12767,7 +12767,7 @@ function identityKey(credentials) {
|
|
|
12767
12767
|
}
|
|
12768
12768
|
//#endregion
|
|
12769
12769
|
//#region src/host/routes.ts
|
|
12770
|
-
const MAX_BODY_BYTES$
|
|
12770
|
+
const MAX_BODY_BYTES$14 = 64 * 1024;
|
|
12771
12771
|
function registerRoutes(ctx, oauth, usage, preferences, proxyManager, searchSwitcher, routeAudit, accountPool, fetchConfiguration, adopt) {
|
|
12772
12772
|
const adoptPaths = adopt?.adoptPaths;
|
|
12773
12773
|
const handler = async (request, response) => {
|
|
@@ -12871,7 +12871,7 @@ function registerRoutes(ctx, oauth, usage, preferences, proxyManager, searchSwit
|
|
|
12871
12871
|
});
|
|
12872
12872
|
return;
|
|
12873
12873
|
}
|
|
12874
|
-
const body = await readJson$
|
|
12874
|
+
const body = await readJson$5(request);
|
|
12875
12875
|
if (body === null) {
|
|
12876
12876
|
jsonError(response, 400, {
|
|
12877
12877
|
code: "bad-request",
|
|
@@ -13140,13 +13140,13 @@ function registerRoutes(ctx, oauth, usage, preferences, proxyManager, searchSwit
|
|
|
13140
13140
|
for (const dispose of disposers) dispose();
|
|
13141
13141
|
};
|
|
13142
13142
|
}
|
|
13143
|
-
async function readJson$
|
|
13143
|
+
async function readJson$5(request) {
|
|
13144
13144
|
const chunks = [];
|
|
13145
13145
|
let total = 0;
|
|
13146
13146
|
for await (const chunk of request) {
|
|
13147
13147
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
13148
13148
|
total += buffer.length;
|
|
13149
|
-
if (total > MAX_BODY_BYTES$
|
|
13149
|
+
if (total > MAX_BODY_BYTES$14) return null;
|
|
13150
13150
|
chunks.push(buffer);
|
|
13151
13151
|
}
|
|
13152
13152
|
try {
|
|
@@ -13312,6 +13312,292 @@ function statusFor(error) {
|
|
|
13312
13312
|
return 502;
|
|
13313
13313
|
}
|
|
13314
13314
|
//#endregion
|
|
13315
|
+
//#region src/shared/compact-after-turn.ts
|
|
13316
|
+
/**
|
|
13317
|
+
* Wire contract of the one-shot "compact when this turn ends" switch.
|
|
13318
|
+
*
|
|
13319
|
+
* The browser half is a row in the composer's model menu; the Host half watches
|
|
13320
|
+
* the session's agent and runs one manual compaction once the turn that was
|
|
13321
|
+
* running (or the next one) ends. The two halves only share this file.
|
|
13322
|
+
*
|
|
13323
|
+
* @module dsh-chatgpt-subscription/shared/compact-after-turn
|
|
13324
|
+
*/
|
|
13325
|
+
/** Route of the state read (GET `?session=<id>`) and the switch write (POST). */
|
|
13326
|
+
const COMPACT_AFTER_TURN_PATH = "/api/dsh-compact-after-turn/state";
|
|
13327
|
+
//#endregion
|
|
13328
|
+
//#region src/host/compact-after-turn/index.ts
|
|
13329
|
+
/** Sessions remembered at once; the oldest settled ones are dropped first. */
|
|
13330
|
+
const MAX_TRACKED_SESSIONS$3 = 256;
|
|
13331
|
+
const MAX_BODY_BYTES$13 = 4 * 1024;
|
|
13332
|
+
/** Refusal raised by {@link CompactAfterTurnController.setArmed}. */
|
|
13333
|
+
var CompactAfterTurnError = class extends Error {
|
|
13334
|
+
code;
|
|
13335
|
+
constructor(code, message) {
|
|
13336
|
+
super(message);
|
|
13337
|
+
this.code = code;
|
|
13338
|
+
this.name = "CompactAfterTurnError";
|
|
13339
|
+
}
|
|
13340
|
+
};
|
|
13341
|
+
var CompactAfterTurnController = class {
|
|
13342
|
+
deps;
|
|
13343
|
+
sessions = /* @__PURE__ */ new Map();
|
|
13344
|
+
/** The latest agent seen per session; its scope is where the engine lives. */
|
|
13345
|
+
agents = /* @__PURE__ */ new Map();
|
|
13346
|
+
now;
|
|
13347
|
+
defer;
|
|
13348
|
+
disposed = false;
|
|
13349
|
+
constructor(deps) {
|
|
13350
|
+
this.deps = deps;
|
|
13351
|
+
this.now = deps.now ?? Date.now;
|
|
13352
|
+
this.defer = deps.defer ?? ((task) => {
|
|
13353
|
+
setTimeout(task, 0);
|
|
13354
|
+
});
|
|
13355
|
+
}
|
|
13356
|
+
/**
|
|
13357
|
+
* Whether the session can compact. A session whose agent was seen answers by
|
|
13358
|
+
* that agent's scope; one not seen yet (no turn since the Host started) is
|
|
13359
|
+
* taken as able, and an attempt without an engine is recorded as a failure.
|
|
13360
|
+
*/
|
|
13361
|
+
available(sessionId) {
|
|
13362
|
+
const agent = this.agents.get(sessionId);
|
|
13363
|
+
return agent === void 0 || this.deps.compactor(agent) !== void 0;
|
|
13364
|
+
}
|
|
13365
|
+
state(sessionId) {
|
|
13366
|
+
const state = this.sessions.get(sessionId);
|
|
13367
|
+
return {
|
|
13368
|
+
sessionId,
|
|
13369
|
+
phase: state?.phase ?? "off",
|
|
13370
|
+
available: this.available(sessionId),
|
|
13371
|
+
last: state?.last ?? null
|
|
13372
|
+
};
|
|
13373
|
+
}
|
|
13374
|
+
setArmed(sessionId, armed) {
|
|
13375
|
+
const current = this.sessions.get(sessionId);
|
|
13376
|
+
if (current?.phase === "compacting") throw new CompactAfterTurnError("busy", "A compaction is running for this session.");
|
|
13377
|
+
if (armed) {
|
|
13378
|
+
if (!this.available(sessionId)) throw new CompactAfterTurnError("unavailable", "This session has no compaction engine.");
|
|
13379
|
+
const state = this.ensure(sessionId);
|
|
13380
|
+
state.phase = "armed";
|
|
13381
|
+
state.lastTurnEnd = null;
|
|
13382
|
+
} else if (current !== void 0) {
|
|
13383
|
+
current.phase = "off";
|
|
13384
|
+
current.lastTurnEnd = null;
|
|
13385
|
+
}
|
|
13386
|
+
return this.state(sessionId);
|
|
13387
|
+
}
|
|
13388
|
+
/** `session/event` listener: remembers how an armed session's turn ended. */
|
|
13389
|
+
observe(session, event) {
|
|
13390
|
+
const id = sessionIdOf$1(session);
|
|
13391
|
+
if (id === void 0 || event?.type !== "turn/end") return;
|
|
13392
|
+
const state = this.sessions.get(id);
|
|
13393
|
+
if (state?.phase !== "armed") return;
|
|
13394
|
+
const reason = event.data?.reason?.kind;
|
|
13395
|
+
state.lastTurnEnd = typeof reason === "string" ? reason : "completed";
|
|
13396
|
+
}
|
|
13397
|
+
/** `agent/status` listener: an armed session that just went idle compacts once. */
|
|
13398
|
+
onStatus(agent, status) {
|
|
13399
|
+
if (this.disposed || agent === void 0) return;
|
|
13400
|
+
const id = sessionIdOf$1(agent.session);
|
|
13401
|
+
if (id === void 0) return;
|
|
13402
|
+
this.agents.set(id, agent);
|
|
13403
|
+
if (status !== "idle") return;
|
|
13404
|
+
const state = this.sessions.get(id);
|
|
13405
|
+
if (state?.phase !== "armed" || state.lastTurnEnd === null) return;
|
|
13406
|
+
if (state.lastTurnEnd === "aborted") {
|
|
13407
|
+
state.lastTurnEnd = null;
|
|
13408
|
+
return;
|
|
13409
|
+
}
|
|
13410
|
+
const compactNow = this.deps.compactor(agent);
|
|
13411
|
+
if (compactNow === void 0) {
|
|
13412
|
+
state.phase = "off";
|
|
13413
|
+
state.lastTurnEnd = null;
|
|
13414
|
+
state.last = {
|
|
13415
|
+
kind: "failed",
|
|
13416
|
+
detail: "This session has no compaction engine.",
|
|
13417
|
+
at: this.now()
|
|
13418
|
+
};
|
|
13419
|
+
return;
|
|
13420
|
+
}
|
|
13421
|
+
state.phase = "compacting";
|
|
13422
|
+
state.lastTurnEnd = null;
|
|
13423
|
+
const abort = new AbortController();
|
|
13424
|
+
state.abort = abort;
|
|
13425
|
+
this.defer(() => {
|
|
13426
|
+
this.run(id, state, agent, compactNow, abort);
|
|
13427
|
+
});
|
|
13428
|
+
}
|
|
13429
|
+
/** `agent/disposed` listener: a compaction must not outlive its agent. */
|
|
13430
|
+
onDisposed(agent) {
|
|
13431
|
+
const id = sessionIdOf$1(agent?.session);
|
|
13432
|
+
if (id === void 0) return;
|
|
13433
|
+
this.sessions.get(id)?.abort?.abort(/* @__PURE__ */ new Error("agent disposed"));
|
|
13434
|
+
if (this.agents.get(id) === agent) this.agents.delete(id);
|
|
13435
|
+
}
|
|
13436
|
+
dispose() {
|
|
13437
|
+
this.disposed = true;
|
|
13438
|
+
for (const state of this.sessions.values()) state.abort?.abort(/* @__PURE__ */ new Error("plugin unloaded"));
|
|
13439
|
+
this.sessions.clear();
|
|
13440
|
+
this.agents.clear();
|
|
13441
|
+
}
|
|
13442
|
+
async run(id, state, agent, compactNow, abort) {
|
|
13443
|
+
let rearm = false;
|
|
13444
|
+
try {
|
|
13445
|
+
if (abort.signal.aborted) throw abort.signal.reason;
|
|
13446
|
+
const result = await compactNow(agent, abort.signal);
|
|
13447
|
+
state.last = {
|
|
13448
|
+
kind: result === null || result === void 0 ? "nothing" : "compacted",
|
|
13449
|
+
at: this.now()
|
|
13450
|
+
};
|
|
13451
|
+
this.deps.logger?.info?.(`compact-after-turn: session ${id} ${state.last.kind}`);
|
|
13452
|
+
} catch (error) {
|
|
13453
|
+
if (errorCode(error) === "busy" && !abort.signal.aborted) rearm = true;
|
|
13454
|
+
else {
|
|
13455
|
+
state.last = {
|
|
13456
|
+
kind: "failed",
|
|
13457
|
+
detail: errorMessage$1(error),
|
|
13458
|
+
at: this.now()
|
|
13459
|
+
};
|
|
13460
|
+
this.deps.logger?.warn(`compact-after-turn: session ${id} failed: ${errorMessage$1(error)}`);
|
|
13461
|
+
}
|
|
13462
|
+
} finally {
|
|
13463
|
+
if (state.abort === abort) state.abort = null;
|
|
13464
|
+
if (this.sessions.get(id) === state) {
|
|
13465
|
+
state.phase = rearm ? "armed" : "off";
|
|
13466
|
+
state.lastTurnEnd = null;
|
|
13467
|
+
}
|
|
13468
|
+
}
|
|
13469
|
+
}
|
|
13470
|
+
ensure(sessionId) {
|
|
13471
|
+
let state = this.sessions.get(sessionId);
|
|
13472
|
+
if (state !== void 0) {
|
|
13473
|
+
this.sessions.delete(sessionId);
|
|
13474
|
+
this.sessions.set(sessionId, state);
|
|
13475
|
+
return state;
|
|
13476
|
+
}
|
|
13477
|
+
state = {
|
|
13478
|
+
phase: "off",
|
|
13479
|
+
last: null,
|
|
13480
|
+
lastTurnEnd: null,
|
|
13481
|
+
abort: null
|
|
13482
|
+
};
|
|
13483
|
+
this.sessions.set(sessionId, state);
|
|
13484
|
+
if (this.sessions.size > MAX_TRACKED_SESSIONS$3) for (const [key, value] of this.sessions) {
|
|
13485
|
+
if (this.sessions.size <= MAX_TRACKED_SESSIONS$3) break;
|
|
13486
|
+
if (value.phase === "off") this.sessions.delete(key);
|
|
13487
|
+
}
|
|
13488
|
+
return state;
|
|
13489
|
+
}
|
|
13490
|
+
};
|
|
13491
|
+
function sessionIdOf$1(session) {
|
|
13492
|
+
const id = session?.id;
|
|
13493
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
13494
|
+
}
|
|
13495
|
+
function errorCode(error) {
|
|
13496
|
+
return error !== null && typeof error === "object" ? error.code : void 0;
|
|
13497
|
+
}
|
|
13498
|
+
function errorMessage$1(error) {
|
|
13499
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
13500
|
+
return text.length > 300 ? text.slice(0, 300) + "…" : text;
|
|
13501
|
+
}
|
|
13502
|
+
/**
|
|
13503
|
+
* Resolve the Host compaction engine lazily: it may load after this plugin and
|
|
13504
|
+
* may be replaced on a profile reload.
|
|
13505
|
+
*/
|
|
13506
|
+
function compactorOf(host, options, agent) {
|
|
13507
|
+
let engine;
|
|
13508
|
+
try {
|
|
13509
|
+
engine = agent?.ctx?.get?.("compaction") ?? options.engine?.() ?? host.get?.("compaction");
|
|
13510
|
+
} catch {
|
|
13511
|
+
return;
|
|
13512
|
+
}
|
|
13513
|
+
const compactNow = engine?.compactNow;
|
|
13514
|
+
if (typeof compactNow !== "function") return void 0;
|
|
13515
|
+
return (agent, signal) => compactNow.call(engine, agent, signal);
|
|
13516
|
+
}
|
|
13517
|
+
/** Install the listeners and the route; returns the disposer (undefined on a Host without an event bus). */
|
|
13518
|
+
function installCompactAfterTurn(host, options = {}) {
|
|
13519
|
+
if (typeof host.on !== "function") return void 0;
|
|
13520
|
+
const controller = new CompactAfterTurnController({
|
|
13521
|
+
compactor: (agent) => compactorOf(host, options, agent),
|
|
13522
|
+
logger: host.logger
|
|
13523
|
+
});
|
|
13524
|
+
const handles = [
|
|
13525
|
+
host.on("session/event", (session, event) => controller.observe(session, event)),
|
|
13526
|
+
host.on("agent/status", (payload) => controller.onStatus(payload?.agent, payload?.status)),
|
|
13527
|
+
host.on("agent/disposed", (payload) => controller.onDisposed(payload?.agent))
|
|
13528
|
+
];
|
|
13529
|
+
const disposeRoute = host.webServer?.register({
|
|
13530
|
+
kind: "exact",
|
|
13531
|
+
path: COMPACT_AFTER_TURN_PATH,
|
|
13532
|
+
handler: createCompactAfterTurnHandler(controller)
|
|
13533
|
+
});
|
|
13534
|
+
return () => {
|
|
13535
|
+
controller.dispose();
|
|
13536
|
+
disposeRoute?.();
|
|
13537
|
+
for (const handle of handles) if (typeof handle === "function") handle();
|
|
13538
|
+
else handle?.dispose?.();
|
|
13539
|
+
};
|
|
13540
|
+
}
|
|
13541
|
+
/** `GET ?session=<id>` reads, `POST { sessionId, armed }` writes (same-origin only). */
|
|
13542
|
+
function createCompactAfterTurnHandler(controller) {
|
|
13543
|
+
return async (request, response) => {
|
|
13544
|
+
try {
|
|
13545
|
+
if (request.method === "GET") {
|
|
13546
|
+
const sessionId = new URL(request.url ?? "/", "http://dsh.local").searchParams.get("session") ?? "";
|
|
13547
|
+
if (sessionId === "") return refuse(response, 400, "bad-request", "A session query parameter is required.");
|
|
13548
|
+
return send(response, 200, {
|
|
13549
|
+
ok: true,
|
|
13550
|
+
value: controller.state(sessionId)
|
|
13551
|
+
});
|
|
13552
|
+
}
|
|
13553
|
+
if (request.method === "POST") {
|
|
13554
|
+
if (!isSameOriginMutation(request)) return refuse(response, 403, "forbidden", "Cross-origin request refused.");
|
|
13555
|
+
const body = await readJson$4(request);
|
|
13556
|
+
const sessionId = body?.sessionId;
|
|
13557
|
+
const armed = body?.armed;
|
|
13558
|
+
if (typeof sessionId !== "string" || sessionId === "" || typeof armed !== "boolean") return refuse(response, 400, "bad-request", "Expected { sessionId: string, armed: boolean }.");
|
|
13559
|
+
return send(response, 200, {
|
|
13560
|
+
ok: true,
|
|
13561
|
+
value: controller.setArmed(sessionId, armed)
|
|
13562
|
+
});
|
|
13563
|
+
}
|
|
13564
|
+
response.setHeader("allow", "GET, POST");
|
|
13565
|
+
return refuse(response, 405, "bad-request", "Method not allowed.");
|
|
13566
|
+
} catch (error) {
|
|
13567
|
+
if (error instanceof CompactAfterTurnError) return refuse(response, error.code === "busy" ? 409 : 503, error.code, error.message);
|
|
13568
|
+
return refuse(response, 400, "bad-request", errorMessage$1(error));
|
|
13569
|
+
}
|
|
13570
|
+
};
|
|
13571
|
+
}
|
|
13572
|
+
function send(response, status, body) {
|
|
13573
|
+
response.writeHead(status, {
|
|
13574
|
+
"content-type": "application/json; charset=utf-8",
|
|
13575
|
+
"cache-control": "no-store"
|
|
13576
|
+
});
|
|
13577
|
+
response.end(JSON.stringify(body));
|
|
13578
|
+
}
|
|
13579
|
+
function refuse(response, status, code, message) {
|
|
13580
|
+
send(response, status, {
|
|
13581
|
+
ok: false,
|
|
13582
|
+
error: {
|
|
13583
|
+
code,
|
|
13584
|
+
message
|
|
13585
|
+
}
|
|
13586
|
+
});
|
|
13587
|
+
}
|
|
13588
|
+
async function readJson$4(request) {
|
|
13589
|
+
const chunks = [];
|
|
13590
|
+
let size = 0;
|
|
13591
|
+
for await (const chunk of request) {
|
|
13592
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
13593
|
+
size += buffer.length;
|
|
13594
|
+
if (size > MAX_BODY_BYTES$13) throw new Error("Request body too large.");
|
|
13595
|
+
chunks.push(buffer);
|
|
13596
|
+
}
|
|
13597
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
13598
|
+
return text === "" ? null : JSON.parse(text);
|
|
13599
|
+
}
|
|
13600
|
+
//#endregion
|
|
13315
13601
|
//#region src/host/search-provider-switcher.ts
|
|
13316
13602
|
/**
|
|
13317
13603
|
* Cordis fiber states, mirrored from its `FiberState` const enum.
|
|
@@ -17568,7 +17854,7 @@ function credentialPath$2() {
|
|
|
17568
17854
|
function modelSettingsPath$2() {
|
|
17569
17855
|
return path.join(dshHomeDir(), "storages", "command-code-models.json");
|
|
17570
17856
|
}
|
|
17571
|
-
function optionalString$
|
|
17857
|
+
function optionalString$18(record, key) {
|
|
17572
17858
|
const value = record[key];
|
|
17573
17859
|
if (value === void 0 || value === null) return void 0;
|
|
17574
17860
|
if (typeof value !== "string") throw new Error("Command Code credential payload is invalid");
|
|
@@ -17589,7 +17875,7 @@ function parseCommandCodeCredentials(value) {
|
|
|
17589
17875
|
"planLabel",
|
|
17590
17876
|
"planId"
|
|
17591
17877
|
]) {
|
|
17592
|
-
const parsed = optionalString$
|
|
17878
|
+
const parsed = optionalString$18(record, key);
|
|
17593
17879
|
if (parsed !== void 0) credentials[key] = parsed;
|
|
17594
17880
|
}
|
|
17595
17881
|
const authenticatedAt = record.authenticatedAt;
|
|
@@ -21069,7 +21355,7 @@ function commandCodeAccountKey(credentials) {
|
|
|
21069
21355
|
if (credentials.userId !== void 0 && credentials.userId !== "") return `${credentials.userId}:${credentials.keyName ?? ""}`;
|
|
21070
21356
|
return createHash("sha256").update(credentials.apiKey).digest("hex");
|
|
21071
21357
|
}
|
|
21072
|
-
function optionalString$
|
|
21358
|
+
function optionalString$17(record, key) {
|
|
21073
21359
|
const value = record[key];
|
|
21074
21360
|
if (value === void 0 || value === null) return void 0;
|
|
21075
21361
|
if (typeof value !== "string") throw new Error("Command Code pool account field is invalid");
|
|
@@ -21101,7 +21387,7 @@ function parseCommandCodePoolData(value) {
|
|
|
21101
21387
|
"planId",
|
|
21102
21388
|
"userId"
|
|
21103
21389
|
]) {
|
|
21104
|
-
const parsed = optionalString$
|
|
21390
|
+
const parsed = optionalString$17(raw, key);
|
|
21105
21391
|
if (parsed !== void 0) account[key] = parsed;
|
|
21106
21392
|
}
|
|
21107
21393
|
if (account.email === void 0 && credentials.email !== void 0) account.email = credentials.email;
|
|
@@ -22477,7 +22763,7 @@ function modelSettingsPath$11() {
|
|
|
22477
22763
|
function credentialAccount$10(filePath) {
|
|
22478
22764
|
return createHash("sha256").update(path.resolve(filePath)).digest("hex");
|
|
22479
22765
|
}
|
|
22480
|
-
function optionalString$
|
|
22766
|
+
function optionalString$16(record, key) {
|
|
22481
22767
|
const value = record[key];
|
|
22482
22768
|
if (value === void 0 || value === null) return void 0;
|
|
22483
22769
|
if (typeof value !== "string") throw new Error("Ollama credential payload is invalid");
|
|
@@ -22489,7 +22775,7 @@ function parseOllamaCredentials(value) {
|
|
|
22489
22775
|
const apiKey = record.apiKey;
|
|
22490
22776
|
if (typeof apiKey !== "string" || apiKey.trim() === "") throw new Error("Ollama credential is missing its API key");
|
|
22491
22777
|
const credentials = { apiKey };
|
|
22492
|
-
const alias = optionalString$
|
|
22778
|
+
const alias = optionalString$16(record, "alias");
|
|
22493
22779
|
if (alias !== void 0) credentials.alias = alias;
|
|
22494
22780
|
const addedAt = record.addedAt;
|
|
22495
22781
|
if (typeof addedAt === "number" && Number.isFinite(addedAt)) credentials.addedAt = addedAt;
|
|
@@ -24269,7 +24555,7 @@ function ollamaPoolPath() {
|
|
|
24269
24555
|
function ollamaAccountKey(credentials) {
|
|
24270
24556
|
return createHash("sha256").update(credentials.apiKey).digest("hex");
|
|
24271
24557
|
}
|
|
24272
|
-
function optionalString$
|
|
24558
|
+
function optionalString$15(record, key) {
|
|
24273
24559
|
const value = record[key];
|
|
24274
24560
|
if (value === void 0 || value === null) return void 0;
|
|
24275
24561
|
if (typeof value !== "string") throw new Error("Ollama pool account field is invalid");
|
|
@@ -24313,7 +24599,7 @@ function parseOllamaPoolData(value) {
|
|
|
24313
24599
|
addedAt: typeof raw.addedAt === "number" ? raw.addedAt : Date.now(),
|
|
24314
24600
|
isPrimary: raw.isPrimary === true
|
|
24315
24601
|
};
|
|
24316
|
-
const lastModelId = optionalString$
|
|
24602
|
+
const lastModelId = optionalString$15(raw, "lastModelId");
|
|
24317
24603
|
if (lastModelId !== void 0) account.lastModelId = lastModelId;
|
|
24318
24604
|
const usage = readUsage$1(raw.usage);
|
|
24319
24605
|
if (usage !== void 0) account.usage = usage;
|
|
@@ -29431,6 +29717,66 @@ function normalizeQuickEffort(value) {
|
|
|
29431
29717
|
return value === "off" || value === "low" || value === "medium" || value === "high" ? value : void 0;
|
|
29432
29718
|
}
|
|
29433
29719
|
const QUICK_DESKTOP_SURFACE = process.platform === "win32" ? "QUICK_WORK_DESKTOP_WINDOWS" : "QUICK_WORK_DESKTOP_MAC";
|
|
29720
|
+
function optionalString$14(record, snake, camel) {
|
|
29721
|
+
const value = record[snake] ?? record[camel];
|
|
29722
|
+
return typeof value === "string" && value ? value : void 0;
|
|
29723
|
+
}
|
|
29724
|
+
/** Normalize a Quick `permission_request` payload the way the official renderer does. */
|
|
29725
|
+
function readQuickPermissionRequest(payload, threadId) {
|
|
29726
|
+
const bodyJson = payload.request_body_json ?? payload.requestBodyJson;
|
|
29727
|
+
const body = payload.request_body ?? payload.requestBody;
|
|
29728
|
+
const params = typeof bodyJson === "string" && bodyJson ? bodyJson : body !== void 0 && body !== null ? JSON.stringify(body) : void 0;
|
|
29729
|
+
const toolName = optionalString$14(payload, "tool_name", "toolName");
|
|
29730
|
+
const paramsHash = optionalString$14(payload, "params_hash", "paramsHash");
|
|
29731
|
+
const agentId = optionalString$14(payload, "agent_id", "agentId");
|
|
29732
|
+
const conversationId = optionalString$14(payload, "conversation_id", "conversationId");
|
|
29733
|
+
const toolUseId = optionalString$14(payload, "call_tool_use_id", "callToolUseId") ?? optionalString$14(payload, "tool_use_id", "toolUseId");
|
|
29734
|
+
return {
|
|
29735
|
+
connectorId: optionalString$14(payload, "connector_id", "connectorId") ?? "",
|
|
29736
|
+
actionId: optionalString$14(payload, "action_id", "actionId") ?? "",
|
|
29737
|
+
sessionId: optionalString$14(payload, "thread_id", "threadId") ?? threadId,
|
|
29738
|
+
...toolName ? { toolName } : {},
|
|
29739
|
+
...params && params.length <= 8192 ? { params } : {},
|
|
29740
|
+
...paramsHash ? { paramsHash } : {},
|
|
29741
|
+
...agentId ? { agentId } : {},
|
|
29742
|
+
...conversationId ? { conversationId } : {},
|
|
29743
|
+
...toolUseId ? { toolUseId } : {}
|
|
29744
|
+
};
|
|
29745
|
+
}
|
|
29746
|
+
/** Official reply to a permission request: `tool_approval` (scope ALLOW_ONCE) or `permission_denied`. */
|
|
29747
|
+
function quickPermissionReply(request, approved) {
|
|
29748
|
+
const common = {
|
|
29749
|
+
connectorId: request.connectorId,
|
|
29750
|
+
actionId: request.actionId,
|
|
29751
|
+
sessionId: request.sessionId,
|
|
29752
|
+
...request.params ? { params: request.params } : {},
|
|
29753
|
+
...request.paramsHash ? { paramsHash: request.paramsHash } : {},
|
|
29754
|
+
...request.agentId ? { agentId: request.agentId } : {},
|
|
29755
|
+
...request.conversationId ? { conversationId: request.conversationId } : {},
|
|
29756
|
+
...request.toolUseId ? { toolUseId: request.toolUseId } : {}
|
|
29757
|
+
};
|
|
29758
|
+
return approved ? {
|
|
29759
|
+
type: "tool_approval",
|
|
29760
|
+
...common,
|
|
29761
|
+
scope: "ALLOW_ONCE"
|
|
29762
|
+
} : {
|
|
29763
|
+
type: "permission_denied",
|
|
29764
|
+
...common
|
|
29765
|
+
};
|
|
29766
|
+
}
|
|
29767
|
+
/** Official reply to a generic `approval_requested` event. */
|
|
29768
|
+
function quickApprovalDecision(payload, threadId, approved) {
|
|
29769
|
+
const approvalId = optionalString$14(payload, "approval_id", "approvalId");
|
|
29770
|
+
if (!approvalId) return null;
|
|
29771
|
+
return {
|
|
29772
|
+
type: "approval_decision",
|
|
29773
|
+
payload: {
|
|
29774
|
+
approval_id: approvalId,
|
|
29775
|
+
decision: approved ? "approved_once" : "denied",
|
|
29776
|
+
session_id: optionalString$14(payload, "session_id", "sessionId") ?? threadId
|
|
29777
|
+
}
|
|
29778
|
+
};
|
|
29779
|
+
}
|
|
29434
29780
|
const encoder = new TextEncoder();
|
|
29435
29781
|
const decoder = new TextDecoder();
|
|
29436
29782
|
const eventCodec = new EventStreamCodec((value) => decoder.decode(value), (value) => encoder.encode(value));
|
|
@@ -29629,6 +29975,7 @@ var QuickConnection = class QuickConnection {
|
|
|
29629
29975
|
closed = false;
|
|
29630
29976
|
signal;
|
|
29631
29977
|
activity;
|
|
29978
|
+
approvalResolver;
|
|
29632
29979
|
connectedResolve = () => {};
|
|
29633
29980
|
connected = new Promise((resolve) => {
|
|
29634
29981
|
this.connectedResolve = resolve;
|
|
@@ -29722,6 +30069,16 @@ var QuickConnection = class QuickConnection {
|
|
|
29722
30069
|
setActivity(activity) {
|
|
29723
30070
|
this.activity = activity;
|
|
29724
30071
|
}
|
|
30072
|
+
setApprovalResolver(resolver) {
|
|
30073
|
+
this.approvalResolver = resolver;
|
|
30074
|
+
}
|
|
30075
|
+
approves(request) {
|
|
30076
|
+
try {
|
|
30077
|
+
return this.approvalResolver?.(request) === true;
|
|
30078
|
+
} catch {
|
|
30079
|
+
return false;
|
|
30080
|
+
}
|
|
30081
|
+
}
|
|
29725
30082
|
onAbort = () => {
|
|
29726
30083
|
if (this.assistantMessageId) this.send(quickStopGeneration(this.threadId, this.assistantMessageId));
|
|
29727
30084
|
this.finish("cancelled");
|
|
@@ -29783,6 +30140,22 @@ var QuickConnection = class QuickConnection {
|
|
|
29783
30140
|
const thread = textField(event, "thread_id") ?? event.thread_id;
|
|
29784
30141
|
if (thread && thread !== this.threadId) return;
|
|
29785
30142
|
const type = event.type;
|
|
30143
|
+
const body = payload(event);
|
|
30144
|
+
if (type === "status" && body.type === "permission_request" || type === "permission_request") {
|
|
30145
|
+
const request = readQuickPermissionRequest(body, this.threadId);
|
|
30146
|
+
this.send(quickPermissionReply(request, this.approves({
|
|
30147
|
+
...request.toolName ? { toolName: request.toolName } : {},
|
|
30148
|
+
actionId: request.actionId,
|
|
30149
|
+
connectorId: request.connectorId
|
|
30150
|
+
})));
|
|
30151
|
+
return;
|
|
30152
|
+
}
|
|
30153
|
+
if (type === "approval_requested") {
|
|
30154
|
+
const toolName = typeof body.tool_name === "string" ? body.tool_name : typeof body.toolName === "string" ? body.toolName : void 0;
|
|
30155
|
+
const reply = quickApprovalDecision(body, this.threadId, this.approves(toolName ? { toolName } : {}));
|
|
30156
|
+
if (reply) this.send(reply);
|
|
30157
|
+
return;
|
|
30158
|
+
}
|
|
29786
30159
|
if (type === "connected") {
|
|
29787
30160
|
const user = payload(event).user;
|
|
29788
30161
|
this.send({
|
|
@@ -29838,6 +30211,170 @@ var QuickConnection = class QuickConnection {
|
|
|
29838
30211
|
}
|
|
29839
30212
|
};
|
|
29840
30213
|
//#endregion
|
|
30214
|
+
//#region src/host/aws-quick/markup.ts
|
|
30215
|
+
const OPENERS$1 = [
|
|
30216
|
+
"<decisions>",
|
|
30217
|
+
"<decision ",
|
|
30218
|
+
"<decision\n",
|
|
30219
|
+
"<decision ",
|
|
30220
|
+
"<sources>"
|
|
30221
|
+
];
|
|
30222
|
+
/** Held text longer than this without a closing tag is released verbatim. */
|
|
30223
|
+
const MAX_HOLD = 64 * 1024;
|
|
30224
|
+
function unescapeXml(text) {
|
|
30225
|
+
return text.replace(/"/g, "\"").replace(/'|'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
30226
|
+
}
|
|
30227
|
+
function attributes(tag) {
|
|
30228
|
+
const out = {};
|
|
30229
|
+
for (const match of tag.matchAll(/([\w-]+)\s*=\s*"([^"]*)"/g)) out[match[1].toLowerCase()] = unescapeXml(match[2]);
|
|
30230
|
+
return out;
|
|
30231
|
+
}
|
|
30232
|
+
/** Parse one `<decision …>…</decision>` element; null when it carries no question. */
|
|
30233
|
+
function parseQuickDecision(block) {
|
|
30234
|
+
const open = /^<decision\b([^>]*)>/.exec(block);
|
|
30235
|
+
if (!open) return null;
|
|
30236
|
+
const attrs = attributes(open[1]);
|
|
30237
|
+
const question = (attrs.question ?? "").trim();
|
|
30238
|
+
if (!question) return null;
|
|
30239
|
+
const options = [];
|
|
30240
|
+
for (const match of block.matchAll(/<option\b([^>]*)>([\s\S]*?)<\/option>/g)) {
|
|
30241
|
+
const label = unescapeXml(match[2].replace(/<[^>]+>/g, "")).trim();
|
|
30242
|
+
if (!label) continue;
|
|
30243
|
+
const description = attributes(match[1]).description?.trim();
|
|
30244
|
+
options.push(description ? {
|
|
30245
|
+
label,
|
|
30246
|
+
description
|
|
30247
|
+
} : { label });
|
|
30248
|
+
}
|
|
30249
|
+
const header = attrs.header?.trim();
|
|
30250
|
+
return {
|
|
30251
|
+
question,
|
|
30252
|
+
...header ? { header } : {},
|
|
30253
|
+
multi: /^(true|1|yes)$/i.test(attrs.multi ?? attrs.multiple ?? ""),
|
|
30254
|
+
options
|
|
30255
|
+
};
|
|
30256
|
+
}
|
|
30257
|
+
function closingIndex(buffer, start) {
|
|
30258
|
+
const head = buffer.slice(start);
|
|
30259
|
+
if (head.startsWith("<decisions>")) {
|
|
30260
|
+
const close = head.indexOf("</decisions>");
|
|
30261
|
+
return close < 0 ? null : {
|
|
30262
|
+
end: start + close + 12,
|
|
30263
|
+
kind: "decisions"
|
|
30264
|
+
};
|
|
30265
|
+
}
|
|
30266
|
+
if (head.startsWith("<sources>")) {
|
|
30267
|
+
const close = head.indexOf("</sources>");
|
|
30268
|
+
return close < 0 ? null : {
|
|
30269
|
+
end: start + close + 10,
|
|
30270
|
+
kind: "sources"
|
|
30271
|
+
};
|
|
30272
|
+
}
|
|
30273
|
+
const match = /<\/decision>|<\/invoke>\s*<\/decision>/.exec(head);
|
|
30274
|
+
return match ? {
|
|
30275
|
+
end: start + match.index + match[0].length,
|
|
30276
|
+
kind: "decision"
|
|
30277
|
+
} : null;
|
|
30278
|
+
}
|
|
30279
|
+
function openerAt(buffer, from) {
|
|
30280
|
+
let best = -1;
|
|
30281
|
+
for (const opener of OPENERS$1) {
|
|
30282
|
+
const index = buffer.indexOf(opener, from);
|
|
30283
|
+
if (index >= 0 && (best < 0 || index < best)) best = index;
|
|
30284
|
+
}
|
|
30285
|
+
return best;
|
|
30286
|
+
}
|
|
30287
|
+
function partialOpenerTail(buffer) {
|
|
30288
|
+
const last = buffer.lastIndexOf("<");
|
|
30289
|
+
if (last < 0) return -1;
|
|
30290
|
+
const tail = buffer.slice(last);
|
|
30291
|
+
return OPENERS$1.some((opener) => opener.startsWith(tail) && tail.length < opener.length) ? last : -1;
|
|
30292
|
+
}
|
|
30293
|
+
/** Streaming filter: push text deltas, get back the text that is safe to show. */
|
|
30294
|
+
var QuickMarkupFilter = class {
|
|
30295
|
+
buffer = "";
|
|
30296
|
+
decisions = [];
|
|
30297
|
+
push(delta) {
|
|
30298
|
+
this.buffer += delta;
|
|
30299
|
+
return this.drain(false);
|
|
30300
|
+
}
|
|
30301
|
+
/** Release everything still held (an unterminated block is shown verbatim). */
|
|
30302
|
+
flush() {
|
|
30303
|
+
return this.drain(true);
|
|
30304
|
+
}
|
|
30305
|
+
drain(final) {
|
|
30306
|
+
let out = "";
|
|
30307
|
+
for (;;) {
|
|
30308
|
+
const start = openerAt(this.buffer, 0);
|
|
30309
|
+
if (start < 0) {
|
|
30310
|
+
const tail = final ? -1 : partialOpenerTail(this.buffer);
|
|
30311
|
+
if (tail < 0) {
|
|
30312
|
+
out += this.buffer;
|
|
30313
|
+
this.buffer = "";
|
|
30314
|
+
} else {
|
|
30315
|
+
out += this.buffer.slice(0, tail);
|
|
30316
|
+
this.buffer = this.buffer.slice(tail);
|
|
30317
|
+
}
|
|
30318
|
+
return out;
|
|
30319
|
+
}
|
|
30320
|
+
out += this.buffer.slice(0, start);
|
|
30321
|
+
this.buffer = this.buffer.slice(start);
|
|
30322
|
+
const close = closingIndex(this.buffer, 0);
|
|
30323
|
+
if (!close) {
|
|
30324
|
+
if (final || this.buffer.length > MAX_HOLD) {
|
|
30325
|
+
out += this.buffer;
|
|
30326
|
+
this.buffer = "";
|
|
30327
|
+
}
|
|
30328
|
+
return out;
|
|
30329
|
+
}
|
|
30330
|
+
const block = this.buffer.slice(0, close.end);
|
|
30331
|
+
this.buffer = this.buffer.slice(close.end);
|
|
30332
|
+
if (close.kind === "decision") {
|
|
30333
|
+
const decision = parseQuickDecision(block);
|
|
30334
|
+
if (decision) this.decisions.push(decision);
|
|
30335
|
+
else out += block;
|
|
30336
|
+
} else if (close.kind === "decisions") for (const match of block.matchAll(/<decision\b[^>]*>[\s\S]*?(?:<\/decision>|<\/invoke>)/g)) {
|
|
30337
|
+
const decision = parseQuickDecision(match[0]);
|
|
30338
|
+
if (decision) this.decisions.push(decision);
|
|
30339
|
+
}
|
|
30340
|
+
}
|
|
30341
|
+
}
|
|
30342
|
+
};
|
|
30343
|
+
/** Arguments for DSH `ask_user_question` built from Quick decisions. */
|
|
30344
|
+
function decisionsToAskArguments(decisions) {
|
|
30345
|
+
return { questions: decisions.map((decision, index) => ({
|
|
30346
|
+
id: "q" + (index + 1),
|
|
30347
|
+
question: decision.question,
|
|
30348
|
+
...decision.header ? { header: decision.header } : {},
|
|
30349
|
+
...decision.options.length ? { options: decision.options.map((option) => option.description ? {
|
|
30350
|
+
label: option.label,
|
|
30351
|
+
description: option.description
|
|
30352
|
+
} : { label: option.label }) } : {},
|
|
30353
|
+
...decision.multi ? { multi_select: true } : {}
|
|
30354
|
+
})) };
|
|
30355
|
+
}
|
|
30356
|
+
/** Plain-text fallback when the DSH session offers no question tool. */
|
|
30357
|
+
function renderDecisionsAsText(decisions) {
|
|
30358
|
+
return decisions.map((decision) => [`**${decision.question}**`, ...decision.options.map((option, index) => `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ""}`)].join("\n")).join("\n\n");
|
|
30359
|
+
}
|
|
30360
|
+
/** Quick's native answer form for a DSH `ask_user_question` result. */
|
|
30361
|
+
function decisionResponseText(decisions, resultText) {
|
|
30362
|
+
let answers;
|
|
30363
|
+
try {
|
|
30364
|
+
const parsed = JSON.parse(resultText);
|
|
30365
|
+
if (Array.isArray(parsed.answers)) answers = parsed.answers;
|
|
30366
|
+
} catch {
|
|
30367
|
+
answers = void 0;
|
|
30368
|
+
}
|
|
30369
|
+
return `<decision_response>${decisions.map((decision, index) => {
|
|
30370
|
+
const answer = answers?.find((item) => item.id === "q" + (index + 1));
|
|
30371
|
+
if (!answer) return `${decision.question}: ${answers ? "" : resultText.trim()}`.trimEnd();
|
|
30372
|
+
const selected = Array.isArray(answer.selected) ? answer.selected.filter((item) => typeof item === "string") : [];
|
|
30373
|
+
const custom = typeof answer.custom === "string" && answer.custom.trim() ? [answer.custom.trim()] : [];
|
|
30374
|
+
return `${decision.question}: ${[...selected, ...custom].join(", ")}`;
|
|
30375
|
+
}).join("\n")}</decision_response>`;
|
|
30376
|
+
}
|
|
30377
|
+
//#endregion
|
|
29841
30378
|
//#region src/host/aws-quick/adapter.ts
|
|
29842
30379
|
const QUICK_STREAM_IDLE_TIMEOUT_MS = 6e5;
|
|
29843
30380
|
const RETRY_POLICY$12 = resolveRetryPolicy({
|
|
@@ -29884,6 +30421,16 @@ function fingerprint$3(messages, covered) {
|
|
|
29884
30421
|
m.content.filter((block) => block.type === "image").map((block) => block.attachment)
|
|
29885
30422
|
]));
|
|
29886
30423
|
}
|
|
30424
|
+
/** DSH tool that renders a question card; Quick decisions are projected onto it. */
|
|
30425
|
+
const ASK_TOOL = "ask_user_question";
|
|
30426
|
+
const MAX_DECISION_CALLS = 64;
|
|
30427
|
+
function resultText(block) {
|
|
30428
|
+
return block.content.map((item) => item.type === "text" ? item.text : "").filter(Boolean).join("\n");
|
|
30429
|
+
}
|
|
30430
|
+
/** Text DSH appended after a tool round (plan-mode notices, reminders, steering) that is not itself a tool result. */
|
|
30431
|
+
function extraContext(messages) {
|
|
30432
|
+
return messages.filter((message) => message.role !== "assistant").map((message) => message.content.filter((block) => block.type !== "tool-result").map(blockText).filter(Boolean).join("\n")).filter((text) => text.trim()).join("\n\n");
|
|
30433
|
+
}
|
|
29887
30434
|
function assertSupported(options) {
|
|
29888
30435
|
const unsupported = [];
|
|
29889
30436
|
if (options.temperature !== void 0) unsupported.push("temperature");
|
|
@@ -29908,6 +30455,7 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
29908
30455
|
threads = /* @__PURE__ */ new Map();
|
|
29909
30456
|
live = /* @__PURE__ */ new Map();
|
|
29910
30457
|
active = /* @__PURE__ */ new Set();
|
|
30458
|
+
decisionCalls = /* @__PURE__ */ new Map();
|
|
29911
30459
|
constructor(options) {
|
|
29912
30460
|
super();
|
|
29913
30461
|
this.options = options;
|
|
@@ -29942,6 +30490,30 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
29942
30490
|
stream(options) {
|
|
29943
30491
|
return wrapStreamWithWatchdog((signal, activity) => this.run(options, signal, activity), options.signal, QUICK_STREAM_IDLE_TIMEOUT_MS, STREAM_IDLE_TIMEOUT_CODE$6, PROVIDER_NAME$12, QUICK_STREAM_IDLE_TIMEOUT_MS);
|
|
29944
30492
|
}
|
|
30493
|
+
approvalResolver(catalog) {
|
|
30494
|
+
return (request) => !!catalog && [request.toolName, request.actionId].some((name) => !!name && catalog.resolve(name) !== null);
|
|
30495
|
+
}
|
|
30496
|
+
rememberDecision(id, decisions) {
|
|
30497
|
+
this.decisionCalls.set(id, decisions);
|
|
30498
|
+
while (this.decisionCalls.size > MAX_DECISION_CALLS) {
|
|
30499
|
+
const oldest = this.decisionCalls.keys().next().value;
|
|
30500
|
+
if (oldest === void 0) break;
|
|
30501
|
+
this.decisionCalls.delete(oldest);
|
|
30502
|
+
}
|
|
30503
|
+
}
|
|
30504
|
+
/** Quick-native answer text when the message answers a projected decision; undefined otherwise. */
|
|
30505
|
+
decisionAnswer(message) {
|
|
30506
|
+
const parts = [];
|
|
30507
|
+
for (const block of message.content) {
|
|
30508
|
+
if (block.type !== "tool-result") continue;
|
|
30509
|
+
const result = block;
|
|
30510
|
+
const decisions = this.decisionCalls.get(result.toolCallId);
|
|
30511
|
+
if (!decisions) continue;
|
|
30512
|
+
this.decisionCalls.delete(result.toolCallId);
|
|
30513
|
+
parts.push(decisionResponseText(decisions, resultText(result)));
|
|
30514
|
+
}
|
|
30515
|
+
return parts.length ? parts.join("\n") : void 0;
|
|
30516
|
+
}
|
|
29945
30517
|
compatible(state, options, model, effort, toolFingerprint) {
|
|
29946
30518
|
return state.model === model && state.effort === effort && state.toolFingerprint === toolFingerprint && fingerprint$3(options.messages, state.covered) === state.fingerprint;
|
|
29947
30519
|
}
|
|
@@ -29969,12 +30541,19 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
29969
30541
|
turn.catalog = catalog;
|
|
29970
30542
|
turn.connection.setSignal(signal);
|
|
29971
30543
|
turn.connection.setActivity(activity);
|
|
30544
|
+
turn.connection.setApprovalResolver?.(this.approvalResolver(catalog));
|
|
29972
30545
|
const freshMessages = options.messages.slice(previous.state.covered);
|
|
29973
30546
|
const results = collectResults(freshMessages, await resolveRequestImages$1({
|
|
29974
30547
|
...options,
|
|
29975
30548
|
messages: freshMessages
|
|
29976
30549
|
}, this.options.attachments, signal));
|
|
29977
30550
|
if (results.length === 0 && previous.pending.size > 0) throw new LlmError$1("AWS Quick tool continuation requires the DSH tool result.", "INVALID_REQUEST");
|
|
30551
|
+
const extra = extraContext(freshMessages);
|
|
30552
|
+
const last = results.at(-1);
|
|
30553
|
+
if (extra && last) last.content = [...last.content, {
|
|
30554
|
+
type: "text",
|
|
30555
|
+
text: "[DSH context added after this tool call]\n" + extra
|
|
30556
|
+
}];
|
|
29978
30557
|
for (const result of results) {
|
|
29979
30558
|
const call = previous.pending.get(result.id);
|
|
29980
30559
|
if (!call) throw new LlmError$1(`Unknown Quick tool result id: ${result.id}`, "INVALID_REQUEST");
|
|
@@ -29996,7 +30575,7 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
29996
30575
|
const latest = options.messages.slice(dormant.covered).filter((m) => m.role === "user").at(-1);
|
|
29997
30576
|
if (latest && messageText$1(latest).trim()) {
|
|
29998
30577
|
threadId = dormant.threadId;
|
|
29999
|
-
text = messageText$1(latest);
|
|
30578
|
+
text = this.decisionAnswer(latest) ?? messageText$1(latest);
|
|
30000
30579
|
outboundMessages = [latest];
|
|
30001
30580
|
}
|
|
30002
30581
|
}
|
|
@@ -30016,6 +30595,7 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
30016
30595
|
signal,
|
|
30017
30596
|
activity
|
|
30018
30597
|
});
|
|
30598
|
+
connection.setApprovalResolver?.(this.approvalResolver(catalog));
|
|
30019
30599
|
turn = {
|
|
30020
30600
|
connection,
|
|
30021
30601
|
catalog,
|
|
@@ -30029,7 +30609,11 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
30029
30609
|
...catalog ? { toolFingerprint: catalog.fingerprint } : {}
|
|
30030
30610
|
}
|
|
30031
30611
|
};
|
|
30032
|
-
const customPrompt = [
|
|
30612
|
+
const customPrompt = [
|
|
30613
|
+
systemContext(options.messages),
|
|
30614
|
+
"To ask the user a question or offer choices, call the ask_user_question tool when it is available; otherwise ask in plain text with numbered options. For planning, follow the plan-mode instructions in this context and submit the plan with the exit_plan_mode tool when it is available.",
|
|
30615
|
+
tools.length > 0 ? "This turn uses DeepSeek Harness (DSH). Prefer tools exposed by the DeepSeek Harness connector for coding, shell, repository and filesystem work. Quick load_skill/load_tools may be used for discovery. Keep every tool call subject to the normal DSH and Quick permission rules. If a required DSH tool is unavailable, report that capability clearly." : ""
|
|
30616
|
+
].filter(Boolean).join("\n\n") || void 0;
|
|
30033
30617
|
connection.sendUser(text, modelState.mode, effort, attachments, customPrompt);
|
|
30034
30618
|
}
|
|
30035
30619
|
if (!turn) throw new LlmError$1("AWS Quick failed to initialize its connection.", "SERVER");
|
|
@@ -30052,8 +30636,39 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
30052
30636
|
}
|
|
30053
30637
|
};
|
|
30054
30638
|
};
|
|
30639
|
+
const filter = new QuickMarkupFilter();
|
|
30640
|
+
const emit = function* (kind, delta) {
|
|
30641
|
+
if (!delta) return;
|
|
30642
|
+
if (open?.kind !== kind) {
|
|
30643
|
+
const closing = close();
|
|
30644
|
+
if (closing) yield closing;
|
|
30645
|
+
open = {
|
|
30646
|
+
kind,
|
|
30647
|
+
index: index++,
|
|
30648
|
+
text: ""
|
|
30649
|
+
};
|
|
30650
|
+
yield {
|
|
30651
|
+
type: "block-start",
|
|
30652
|
+
index: open.index,
|
|
30653
|
+
blockType: kind
|
|
30654
|
+
};
|
|
30655
|
+
}
|
|
30656
|
+
open.text += delta;
|
|
30657
|
+
yield {
|
|
30658
|
+
type: kind === "text" ? "text-delta" : "reasoning-delta",
|
|
30659
|
+
index: open.index,
|
|
30660
|
+
text: delta
|
|
30661
|
+
};
|
|
30662
|
+
};
|
|
30663
|
+
const separator = () => {
|
|
30664
|
+
const current = open;
|
|
30665
|
+
return current?.kind === "text" && current.text.trim() ? "\n\n" : "";
|
|
30666
|
+
};
|
|
30055
30667
|
for await (const event of currentTurn.connection.events()) {
|
|
30056
30668
|
if (event.kind === "tool-call") {
|
|
30669
|
+
yield* emit("text", filter.flush());
|
|
30670
|
+
const early = filter.decisions.splice(0);
|
|
30671
|
+
if (early.length) yield* emit("text", separator() + renderDecisionsAsText(early));
|
|
30057
30672
|
const original = currentTurn.catalog?.resolve(event.call.name) ?? null;
|
|
30058
30673
|
if (!original) {
|
|
30059
30674
|
currentTurn.connection.answerTool(event.call, "This tool is not part of the active DSH catalog. Use an available DeepSeek Harness tool or report the missing capability.", true);
|
|
@@ -30108,6 +30723,55 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
30108
30723
|
return;
|
|
30109
30724
|
}
|
|
30110
30725
|
if (event.kind === "done") {
|
|
30726
|
+
yield* emit("text", filter.flush());
|
|
30727
|
+
const decisions = filter.decisions.splice(0);
|
|
30728
|
+
if (decisions.length && event.reason !== "cancelled") {
|
|
30729
|
+
if (tools.some((tool) => tool.name === ASK_TOOL)) {
|
|
30730
|
+
const closing = close();
|
|
30731
|
+
if (closing) yield closing;
|
|
30732
|
+
const id = "quick-decision-" + randomUUID();
|
|
30733
|
+
const args = JSON.stringify(decisionsToAskArguments(decisions));
|
|
30734
|
+
const toolIndex = index++;
|
|
30735
|
+
yield {
|
|
30736
|
+
type: "block-start",
|
|
30737
|
+
index: toolIndex,
|
|
30738
|
+
blockType: "tool-call"
|
|
30739
|
+
};
|
|
30740
|
+
yield {
|
|
30741
|
+
type: "tool-call-delta",
|
|
30742
|
+
index: toolIndex,
|
|
30743
|
+
id,
|
|
30744
|
+
name: ASK_TOOL,
|
|
30745
|
+
argumentsDelta: args
|
|
30746
|
+
};
|
|
30747
|
+
yield {
|
|
30748
|
+
type: "block-end",
|
|
30749
|
+
index: toolIndex,
|
|
30750
|
+
block: {
|
|
30751
|
+
type: "tool-call",
|
|
30752
|
+
id,
|
|
30753
|
+
name: ASK_TOOL,
|
|
30754
|
+
arguments: args
|
|
30755
|
+
}
|
|
30756
|
+
};
|
|
30757
|
+
this.rememberDecision(id, decisions);
|
|
30758
|
+
yield {
|
|
30759
|
+
type: "finish",
|
|
30760
|
+
reason: { kind: "tool-calls" }
|
|
30761
|
+
};
|
|
30762
|
+
if (options.purpose === void 0) {
|
|
30763
|
+
this.threads.set(sessionId, {
|
|
30764
|
+
...currentTurn.state,
|
|
30765
|
+
covered: options.messages.length,
|
|
30766
|
+
fingerprint: fingerprint$3(options.messages, options.messages.length)
|
|
30767
|
+
});
|
|
30768
|
+
this.live.delete(sessionId);
|
|
30769
|
+
}
|
|
30770
|
+
await this.options.settings.update({ lastTurnAt: Date.now() });
|
|
30771
|
+
return;
|
|
30772
|
+
}
|
|
30773
|
+
yield* emit("text", separator() + renderDecisionsAsText(decisions));
|
|
30774
|
+
}
|
|
30111
30775
|
const closing = close();
|
|
30112
30776
|
if (closing) yield closing;
|
|
30113
30777
|
if (event.reason === "cancelled") throw new LlmError$1("AWS Quick turn was cancelled.", "ABORTED");
|
|
@@ -30126,26 +30790,7 @@ var AwsQuickAdapter = class extends LlmAdapter {
|
|
|
30126
30790
|
await this.options.settings.update({ lastTurnAt: Date.now() });
|
|
30127
30791
|
return;
|
|
30128
30792
|
}
|
|
30129
|
-
|
|
30130
|
-
const closing = close();
|
|
30131
|
-
if (closing) yield closing;
|
|
30132
|
-
open = {
|
|
30133
|
-
kind: event.kind,
|
|
30134
|
-
index: index++,
|
|
30135
|
-
text: ""
|
|
30136
|
-
};
|
|
30137
|
-
yield {
|
|
30138
|
-
type: "block-start",
|
|
30139
|
-
index: open.index,
|
|
30140
|
-
blockType: event.kind
|
|
30141
|
-
};
|
|
30142
|
-
}
|
|
30143
|
-
open.text += event.delta;
|
|
30144
|
-
yield {
|
|
30145
|
-
type: event.kind === "text" ? "text-delta" : "reasoning-delta",
|
|
30146
|
-
index: open.index,
|
|
30147
|
-
text: event.delta
|
|
30148
|
-
};
|
|
30793
|
+
yield* emit(event.kind, event.kind === "text" ? filter.push(event.delta) : event.delta);
|
|
30149
30794
|
}
|
|
30150
30795
|
throw new LlmError$1("AWS Quick ended without a terminal event.", "INVALID_RESPONSE");
|
|
30151
30796
|
} finally {
|
|
@@ -117162,6 +117807,21 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
117162
117807
|
}
|
|
117163
117808
|
return dispose;
|
|
117164
117809
|
}, "dsh-chatgpt-subscription: Kimi cache wait");
|
|
117810
|
+
let compactionEngine;
|
|
117811
|
+
ctx.inject(["compaction"], (scoped) => {
|
|
117812
|
+
compactionEngine = scoped.get("compaction");
|
|
117813
|
+
scoped.effect(() => () => {
|
|
117814
|
+
compactionEngine = void 0;
|
|
117815
|
+
}, "dsh-chatgpt-subscription: compaction engine");
|
|
117816
|
+
});
|
|
117817
|
+
ctx.effect(() => {
|
|
117818
|
+
const dispose = installCompactAfterTurn(ctx, { engine: () => compactionEngine });
|
|
117819
|
+
if (dispose === void 0) {
|
|
117820
|
+
ctx.logger.warn("[dsh-chatgpt-subscription] compact-after-turn skipped: this harness exposes no event bus");
|
|
117821
|
+
return () => void 0;
|
|
117822
|
+
}
|
|
117823
|
+
return dispose;
|
|
117824
|
+
}, "dsh-chatgpt-subscription: compact after turn");
|
|
117165
117825
|
const probeEnvFile = relayProbeEnvFile();
|
|
117166
117826
|
if (relayProbeEnabled(process.env, { envFile: probeEnvFile })) {
|
|
117167
117827
|
const probePath = relayProbeLogPath(process.env, { envFile: probeEnvFile });
|