acpx 0.9.0 → 0.11.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/README.md +23 -19
- package/dist/{cli-Bf3yjqzE.js → cli-CC2w0U-A.js} +4 -4
- package/dist/{cli-Bf3yjqzE.js.map → cli-CC2w0U-A.js.map} +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +685 -67
- package/dist/cli.js.map +1 -1
- package/dist/{client-BssohYqM.d.ts → client-j3sLnpcM.d.ts} +27 -4
- package/dist/client-j3sLnpcM.d.ts.map +1 -0
- package/dist/{flags-C-rwARqg.js → flags-BKjjl3tF.js} +4 -4
- package/dist/flags-BKjjl3tF.js.map +1 -0
- package/dist/{flows-WLs26_5Y.js → flows-BabqiU0u.js} +5 -4
- package/dist/flows-BabqiU0u.js.map +1 -0
- package/dist/flows.d.ts +1 -1
- package/dist/flows.d.ts.map +1 -1
- package/dist/flows.js +1 -1
- package/dist/{live-checkpoint-D5d-K9s1.js → live-checkpoint-BZrk9Mjz.js} +894 -384
- package/dist/live-checkpoint-BZrk9Mjz.js.map +1 -0
- package/dist/{output-DPg20dvn.js → output-D_BGt1YI.js} +180 -98
- package/dist/output-D_BGt1YI.js.map +1 -0
- package/dist/runtime.d.ts +71 -5
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +188 -32
- package/dist/runtime.js.map +1 -1
- package/dist/{session-options-CFudjdkU.d.ts → session-options-Co1oGEK8.d.ts} +22 -2
- package/dist/{session-options-CFudjdkU.d.ts.map → session-options-Co1oGEK8.d.ts.map} +1 -1
- package/package.json +23 -17
- package/skills/acpx/SKILL.md +66 -5
- package/dist/client-BssohYqM.d.ts.map +0 -1
- package/dist/flags-C-rwARqg.js.map +0 -1
- package/dist/flows-WLs26_5Y.js.map +0 -1
- package/dist/live-checkpoint-D5d-K9s1.js.map +0 -1
- package/dist/output-DPg20dvn.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as setPerfGauge, A as assertRequestedModelSupported, At as isRetryablePromptError, B as listSessions, C as mergeSessionOptions, Ct as withTimeout, D as applyLifecycleSnapshotToRecord, E as applyConversation, F as absolutePath, G as writeSessionRecord, H as normalizeName, I as findGitRepositoryRoot, J as getPerfMetricsSnapshot, Kt as QueueConnectionError, L as findSession, Pt as toAcpErrorPayload, Q as resetPerfMetrics, R as findSessionByDirectoryWalk, Rt as OUTPUT_ERROR_CODES, S as advertisedModelState, St as withInterrupt, T as sessionOptionsFromRecord, U as pruneSessions, V as listSessionsForAgent, W as resolveSessionRecord, X as measurePerf, Y as incrementPerfCounter, Z as recordPerfDuration, _ as createSessionConversation, a as applyRequestedModelIfAdvertised, at as defaultSessionEventLog, b as recordSessionUpdate, bt as InterruptedError, c as setCurrentModelId, ct as sessionEventLockPath, d as setDesiredModelId, dt as isAcpJsonRpcMessage, et as startPerfTimer, f as syncAdvertisedModelState, ft as parseJsonRpcErrorMessage, g as cloneSessionConversation, h as cloneSessionAcpxState, ht as isPromptInput, i as connectAndLoadSession, j as modelStateFromConfigOptions, jt as normalizeOutputError, k as AcpClient, kt as formatErrorMessage, l as setDesiredConfigOption, lt as sessionEventSegmentPath, m as applyConfigOptionsToState, n as runPromptTurn, o as currentModelIdFromSetModelResponse, ot as sessionBaseDir, p as applyConfigOptionsToRecord, pt as parsePromptStopReason, q as formatPerfMetric, qt as QueueProtocolError, r as withConnectedSession, rt as normalizeRuntimeSessionId, s as clearDesiredConfigOption, st as sessionEventActivePath, t as LiveSessionCheckpoint, u as setDesiredModeId, ut as extractSessionUpdateNotification, v as recordClientOperation, vt as promptToDisplayText, w as persistSessionOptions, x as trimConversationForRuntime, xt as TimeoutError, y as recordPromptSubmission, yt as textPrompt, z as isoNow, zt as OUTPUT_ERROR_ORIGINS } from "./live-checkpoint-BZrk9Mjz.js";
|
|
2
2
|
import fs, { realpathSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import fs$1 from "node:fs/promises";
|
|
5
5
|
import os from "node:os";
|
|
6
|
-
import { spawn } from "node:child_process";
|
|
7
6
|
import { createHash, randomInt, randomUUID } from "node:crypto";
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
8
|
import net from "node:net";
|
|
9
9
|
//#region \0rolldown/runtime.js
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
@@ -18,14 +18,6 @@ var __exportAll = (all, no_symbols) => {
|
|
|
18
18
|
return target;
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region src/cli/session/contracts.ts
|
|
22
|
-
const DEFAULT_QUEUE_OWNER_TTL_MS = 3e5;
|
|
23
|
-
function normalizeQueueOwnerTtlMs(ttlMs) {
|
|
24
|
-
if (ttlMs == null) return DEFAULT_QUEUE_OWNER_TTL_MS;
|
|
25
|
-
if (!Number.isFinite(ttlMs) || ttlMs < 0) return DEFAULT_QUEUE_OWNER_TTL_MS;
|
|
26
|
-
return Math.round(ttlMs);
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
21
|
//#region src/process-liveness.ts
|
|
30
22
|
function isProcessAlive(pid) {
|
|
31
23
|
if (!pid || !Number.isInteger(pid) || pid <= 0 || pid === process.pid) return false;
|
|
@@ -37,6 +29,14 @@ function isProcessAlive(pid) {
|
|
|
37
29
|
}
|
|
38
30
|
}
|
|
39
31
|
//#endregion
|
|
32
|
+
//#region src/cli/session/contracts.ts
|
|
33
|
+
const DEFAULT_QUEUE_OWNER_TTL_MS = 3e5;
|
|
34
|
+
function normalizeQueueOwnerTtlMs(ttlMs) {
|
|
35
|
+
if (ttlMs == null) return DEFAULT_QUEUE_OWNER_TTL_MS;
|
|
36
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) return DEFAULT_QUEUE_OWNER_TTL_MS;
|
|
37
|
+
return Math.round(ttlMs);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
40
|
//#region src/cli/queue/paths.ts
|
|
41
41
|
function shortHash(value, length) {
|
|
42
42
|
return createHash("sha256").update(value).digest("hex").slice(0, length);
|
|
@@ -617,7 +617,7 @@ const QUEUE_OWNER_MESSAGE_PARSERS = {
|
|
|
617
617
|
cancel_result: (message, context) => parseBooleanResultOwnerMessage(message, context, "cancel_result", "cancelled"),
|
|
618
618
|
close_session_result: (message, context) => parseBooleanResultOwnerMessage(message, context, "close_session_result", "closed"),
|
|
619
619
|
set_mode_result: (message, context) => parseStringResultOwnerMessage(message, context, "set_mode_result", "modeId"),
|
|
620
|
-
set_model_result:
|
|
620
|
+
set_model_result: parseSetModelOwnerMessage,
|
|
621
621
|
set_config_option_result: parseSetConfigOptionOwnerMessage,
|
|
622
622
|
error: parseErrorOwnerMessage
|
|
623
623
|
};
|
|
@@ -665,6 +665,17 @@ function parseStringResultOwnerMessage(message, context, type, field) {
|
|
|
665
665
|
[field]: message[field]
|
|
666
666
|
};
|
|
667
667
|
}
|
|
668
|
+
function parseSetModelOwnerMessage(message, context) {
|
|
669
|
+
if (typeof message.modelId !== "string") return null;
|
|
670
|
+
const response = asRecord$2(message.response);
|
|
671
|
+
if (message.response !== void 0 && (!response || !Array.isArray(response.configOptions))) return null;
|
|
672
|
+
return {
|
|
673
|
+
type: "set_model_result",
|
|
674
|
+
...context,
|
|
675
|
+
modelId: message.modelId,
|
|
676
|
+
...response ? { response } : {}
|
|
677
|
+
};
|
|
678
|
+
}
|
|
668
679
|
function parseSetConfigOptionOwnerMessage(message, context) {
|
|
669
680
|
const response = asRecord$2(message.response);
|
|
670
681
|
if (!response || !Array.isArray(response.configOptions)) return null;
|
|
@@ -919,11 +930,12 @@ var SessionQueueOwner = class SessionQueueOwner {
|
|
|
919
930
|
socket,
|
|
920
931
|
requestId: request.requestId,
|
|
921
932
|
run: async () => {
|
|
922
|
-
await this.controlHandlers.setSessionModel(request.modelId, request.timeoutMs);
|
|
933
|
+
const response = await this.controlHandlers.setSessionModel(request.modelId, request.timeoutMs);
|
|
923
934
|
return {
|
|
924
935
|
type: "set_model_result",
|
|
925
936
|
requestId: request.requestId,
|
|
926
|
-
modelId: request.modelId
|
|
937
|
+
modelId: request.modelId,
|
|
938
|
+
response
|
|
927
939
|
};
|
|
928
940
|
}
|
|
929
941
|
});
|
|
@@ -1344,7 +1356,7 @@ async function submitSetModelToQueueOwner(owner, modelId, timeoutMs) {
|
|
|
1344
1356
|
origin: "queue",
|
|
1345
1357
|
retryable: true
|
|
1346
1358
|
});
|
|
1347
|
-
return
|
|
1359
|
+
return response;
|
|
1348
1360
|
}
|
|
1349
1361
|
async function submitSetConfigOptionToQueueOwner(owner, configId, value, timeoutMs) {
|
|
1350
1362
|
const request = {
|
|
@@ -1453,9 +1465,10 @@ async function trySetModeOnRunningOwner(sessionId, modeId, timeoutMs, verbose) {
|
|
|
1453
1465
|
async function trySetModelOnRunningOwner(sessionId, modelId, timeoutMs, verbose) {
|
|
1454
1466
|
const owner = await readQueueOwnerRecord(sessionId);
|
|
1455
1467
|
if (!owner) return;
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1468
|
+
const submitted = await submitSetModelToQueueOwner(owner, modelId, timeoutMs);
|
|
1469
|
+
if (submitted) {
|
|
1470
|
+
if (verbose) process.stderr.write(`[acpx] requested a model config update on owner pid ${owner.pid} for session ${sessionId}\n`);
|
|
1471
|
+
return submitted;
|
|
1459
1472
|
}
|
|
1460
1473
|
if (!(await probeQueueOwnerHealth(sessionId)).hasLease) return;
|
|
1461
1474
|
throw new QueueConnectionError("Session queue owner is running but not accepting set_model requests", {
|
|
@@ -1514,16 +1527,28 @@ async function runSessionSetModeDirect(options) {
|
|
|
1514
1527
|
})));
|
|
1515
1528
|
}
|
|
1516
1529
|
async function runSessionSetModelDirect(options) {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1530
|
+
const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
|
|
1531
|
+
const models = advertisedModelState(record.acpx);
|
|
1532
|
+
const response = await withTimeout(client.setSessionModel(sessionId, options.modelId, models), options.timeoutMs);
|
|
1533
|
+
applyConfigOptionsToRecord(record, response);
|
|
1534
|
+
setDesiredModelId(record, options.modelId, models?.configId);
|
|
1535
|
+
setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.modelId));
|
|
1536
|
+
return response;
|
|
1537
|
+
}));
|
|
1538
|
+
return {
|
|
1539
|
+
...toSessionMutationResult(result),
|
|
1540
|
+
response: result.value
|
|
1541
|
+
};
|
|
1522
1542
|
}
|
|
1523
1543
|
async function runSessionSetConfigOptionDirect(options) {
|
|
1524
1544
|
const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
|
|
1545
|
+
const modelConfigId = advertisedModelState(record.acpx)?.configId;
|
|
1525
1546
|
const response = await withTimeout(client.setSessionConfigOption(sessionId, options.configId, options.value), options.timeoutMs);
|
|
1526
|
-
|
|
1547
|
+
applyConfigOptionsToRecord(record, response);
|
|
1548
|
+
if (options.configId === modelConfigId) {
|
|
1549
|
+
setDesiredModelId(record, options.value, options.configId);
|
|
1550
|
+
setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.value));
|
|
1551
|
+
} else if (options.configId === "mode") setDesiredModeId(record, options.value);
|
|
1527
1552
|
else setDesiredConfigOption(record, options.configId, options.value);
|
|
1528
1553
|
return response;
|
|
1529
1554
|
}));
|
|
@@ -1566,13 +1591,16 @@ async function setSessionMode(options) {
|
|
|
1566
1591
|
});
|
|
1567
1592
|
}
|
|
1568
1593
|
async function setSessionModel(options) {
|
|
1569
|
-
|
|
1594
|
+
const submittedToOwner = await trySetModelOnRunningOwner(options.sessionId, options.modelId, options.timeoutMs, options.verbose);
|
|
1595
|
+
if (submittedToOwner) {
|
|
1570
1596
|
const record = await resolveSessionRecord(options.sessionId);
|
|
1571
|
-
|
|
1572
|
-
|
|
1597
|
+
applyConfigOptionsToRecord(record, submittedToOwner.response);
|
|
1598
|
+
setDesiredModelId(record, options.modelId, advertisedModelState(record.acpx)?.configId);
|
|
1599
|
+
setCurrentModelId(record, currentModelIdFromSetModelResponse(submittedToOwner.response, options.modelId));
|
|
1573
1600
|
await writeSessionRecord(record);
|
|
1574
1601
|
return {
|
|
1575
1602
|
record,
|
|
1603
|
+
response: submittedToOwner.response,
|
|
1576
1604
|
resumed: false
|
|
1577
1605
|
};
|
|
1578
1606
|
}
|
|
@@ -1592,7 +1620,12 @@ async function setSessionConfigOption(options) {
|
|
|
1592
1620
|
const ownerResponse = await trySetConfigOptionOnRunningOwner(options.sessionId, options.configId, options.value, options.timeoutMs, options.verbose);
|
|
1593
1621
|
if (ownerResponse) {
|
|
1594
1622
|
const record = await resolveSessionRecord(options.sessionId);
|
|
1595
|
-
|
|
1623
|
+
const modelConfigId = advertisedModelState(record.acpx)?.configId;
|
|
1624
|
+
applyConfigOptionsToRecord(record, ownerResponse);
|
|
1625
|
+
if (options.configId === modelConfigId) {
|
|
1626
|
+
setDesiredModelId(record, options.value, options.configId);
|
|
1627
|
+
setCurrentModelId(record, currentModelIdFromSetModelResponse(ownerResponse, options.value));
|
|
1628
|
+
} else if (options.configId === "mode") setDesiredModeId(record, options.value);
|
|
1596
1629
|
else setDesiredConfigOption(record, options.configId, options.value);
|
|
1597
1630
|
await writeSessionRecord(record);
|
|
1598
1631
|
return {
|
|
@@ -1650,33 +1683,8 @@ async function closeSession(sessionId) {
|
|
|
1650
1683
|
async function createSessionRecordWithClient(client, options) {
|
|
1651
1684
|
const cwd = absolutePath(options.cwd);
|
|
1652
1685
|
await withTimeout(client.start(), options.timeoutMs);
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
let sessionResult;
|
|
1656
|
-
let sessionModels;
|
|
1657
|
-
let requestedModelApplied = false;
|
|
1658
|
-
if (options.resumeSessionId) {
|
|
1659
|
-
const resumed = await resumeSessionRecordWithClient(client, options, cwd);
|
|
1660
|
-
sessionId = resumed.sessionId;
|
|
1661
|
-
agentSessionId = resumed.agentSessionId;
|
|
1662
|
-
sessionResult = resumed.sessionResult;
|
|
1663
|
-
sessionModels = resumed.sessionModels;
|
|
1664
|
-
requestedModelApplied = resumed.requestedModelApplied;
|
|
1665
|
-
} else {
|
|
1666
|
-
const createdSession = await withTimeout(client.createSession(cwd), options.timeoutMs);
|
|
1667
|
-
sessionId = createdSession.sessionId;
|
|
1668
|
-
agentSessionId = normalizeRuntimeSessionId(createdSession.agentSessionId);
|
|
1669
|
-
sessionResult = createdSession;
|
|
1670
|
-
sessionModels = createdSession.models;
|
|
1671
|
-
requestedModelApplied = await applyRequestedModelIfAdvertised({
|
|
1672
|
-
client,
|
|
1673
|
-
sessionId,
|
|
1674
|
-
requestedModel: options.sessionOptions?.model,
|
|
1675
|
-
models: sessionModels,
|
|
1676
|
-
agentCommand: options.agentCommand,
|
|
1677
|
-
timeoutMs: options.timeoutMs
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1686
|
+
const createdState = options.resumeSessionId ? await resumeSessionRecordWithClient(client, options, cwd) : await createFreshSessionState(client, options, cwd);
|
|
1687
|
+
const { sessionId, agentSessionId } = createdState;
|
|
1680
1688
|
const lifecycle = client.getAgentLifecycleSnapshot();
|
|
1681
1689
|
const now = isoNow();
|
|
1682
1690
|
const record = {
|
|
@@ -1702,12 +1710,36 @@ async function createSessionRecordWithClient(client, options) {
|
|
|
1702
1710
|
acpx: {}
|
|
1703
1711
|
};
|
|
1704
1712
|
persistSessionOptions(record, options.sessionOptions);
|
|
1705
|
-
|
|
1706
|
-
syncAdvertisedModelState(record, sessionModels);
|
|
1707
|
-
if (requestedModelApplied) setCurrentModelId(record, options.sessionOptions?.model);
|
|
1713
|
+
applyCreatedSessionModelState(record, createdState, options.sessionOptions?.model);
|
|
1708
1714
|
await writeSessionRecord(record);
|
|
1709
1715
|
return record;
|
|
1710
1716
|
}
|
|
1717
|
+
function applyCreatedSessionModelState(record, state, requestedModel) {
|
|
1718
|
+
applyConfigOptionsToRecord(record, state.sessionResult);
|
|
1719
|
+
applyConfigOptionsToRecord(record, state.requestedModelResponse);
|
|
1720
|
+
syncAdvertisedModelState(record, state.requestedModelResponse ? modelStateFromConfigOptions(state.requestedModelResponse.configOptions) : state.sessionModels);
|
|
1721
|
+
if (state.requestedModelApplied) setCurrentModelId(record, currentModelIdFromSetModelResponse(state.requestedModelResponse, requestedModel));
|
|
1722
|
+
}
|
|
1723
|
+
async function createFreshSessionState(client, options, cwd) {
|
|
1724
|
+
const createdSession = await withTimeout(client.createSession(cwd), options.timeoutMs);
|
|
1725
|
+
const modelApplication = await applyRequestedModelIfAdvertised({
|
|
1726
|
+
client,
|
|
1727
|
+
sessionId: createdSession.sessionId,
|
|
1728
|
+
requestedModel: options.sessionOptions?.model,
|
|
1729
|
+
models: createdSession.models,
|
|
1730
|
+
agentCommand: options.agentCommand,
|
|
1731
|
+
timeoutMs: options.timeoutMs,
|
|
1732
|
+
onWarning: options.onModelWarning
|
|
1733
|
+
});
|
|
1734
|
+
return {
|
|
1735
|
+
sessionId: createdSession.sessionId,
|
|
1736
|
+
agentSessionId: normalizeRuntimeSessionId(createdSession.agentSessionId),
|
|
1737
|
+
sessionResult: createdSession,
|
|
1738
|
+
sessionModels: createdSession.models,
|
|
1739
|
+
requestedModelApplied: modelApplication.applied,
|
|
1740
|
+
requestedModelResponse: modelApplication.response
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1711
1743
|
async function resumeSessionRecordWithClient(client, options, cwd) {
|
|
1712
1744
|
if (!options.resumeSessionId) throw new Error("resumeSessionId is required");
|
|
1713
1745
|
const resumeMethod = client.supportsResumeSession() ? "session/resume" : client.supportsLoadSession() ? "session/load" : void 0;
|
|
@@ -1715,19 +1747,22 @@ async function resumeSessionRecordWithClient(client, options, cwd) {
|
|
|
1715
1747
|
try {
|
|
1716
1748
|
const resumedSession = await withTimeout(resumeMethod === "session/resume" ? client.resumeSession(options.resumeSessionId, cwd) : client.loadSession(options.resumeSessionId, cwd), options.timeoutMs);
|
|
1717
1749
|
const sessionModels = resumedSession.models;
|
|
1750
|
+
const modelApplication = await applyRequestedModelIfAdvertised({
|
|
1751
|
+
client,
|
|
1752
|
+
sessionId: options.resumeSessionId,
|
|
1753
|
+
requestedModel: options.sessionOptions?.model,
|
|
1754
|
+
models: sessionModels,
|
|
1755
|
+
agentCommand: options.agentCommand,
|
|
1756
|
+
timeoutMs: options.timeoutMs,
|
|
1757
|
+
onWarning: options.onModelWarning
|
|
1758
|
+
});
|
|
1718
1759
|
return {
|
|
1719
1760
|
sessionId: options.resumeSessionId,
|
|
1720
1761
|
agentSessionId: normalizeRuntimeSessionId(resumedSession.agentSessionId),
|
|
1721
1762
|
sessionResult: resumedSession,
|
|
1722
1763
|
sessionModels,
|
|
1723
|
-
requestedModelApplied:
|
|
1724
|
-
|
|
1725
|
-
sessionId: options.resumeSessionId,
|
|
1726
|
-
requestedModel: options.sessionOptions?.model,
|
|
1727
|
-
models: sessionModels,
|
|
1728
|
-
agentCommand: options.agentCommand,
|
|
1729
|
-
timeoutMs: options.timeoutMs
|
|
1730
|
-
})
|
|
1764
|
+
requestedModelApplied: modelApplication.applied,
|
|
1765
|
+
requestedModelResponse: modelApplication.response
|
|
1731
1766
|
};
|
|
1732
1767
|
} catch (error) {
|
|
1733
1768
|
throw new Error(`Failed to resume ACP session ${options.resumeSessionId}: ${formatErrorMessage(error)}`, { cause: error });
|
|
@@ -2015,11 +2050,8 @@ var QueueOwnerTurnController = class {
|
|
|
2015
2050
|
async setSessionModel(modelId, timeoutMs) {
|
|
2016
2051
|
this.assertCanHandleControlRequest();
|
|
2017
2052
|
const activeController = this.activeController;
|
|
2018
|
-
if (activeController)
|
|
2019
|
-
|
|
2020
|
-
return;
|
|
2021
|
-
}
|
|
2022
|
-
await this.options.setSessionModelFallback(modelId, timeoutMs);
|
|
2053
|
+
if (activeController) return await this.options.withTimeout(async () => await activeController.setSessionModel(modelId), timeoutMs);
|
|
2054
|
+
return await this.options.setSessionModelFallback(modelId, timeoutMs);
|
|
2023
2055
|
}
|
|
2024
2056
|
async setSessionConfigOption(configId, value, timeoutMs) {
|
|
2025
2057
|
this.assertCanHandleControlRequest();
|
|
@@ -2379,35 +2411,54 @@ function toPromptResult(stopReason, sessionId, client) {
|
|
|
2379
2411
|
function requestedModelId(value) {
|
|
2380
2412
|
return typeof value === "string" ? value.trim() : "";
|
|
2381
2413
|
}
|
|
2382
|
-
function
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2414
|
+
function applyConfigOptionResponseToState(state, response) {
|
|
2415
|
+
if (!response?.configOptions) return state;
|
|
2416
|
+
return applyConfigOptionsToState(state, response.configOptions);
|
|
2417
|
+
}
|
|
2418
|
+
function mergeConnectedModelState(state, connectedState) {
|
|
2419
|
+
if (!connectedState) return state;
|
|
2420
|
+
const nextState = cloneSessionAcpxState(state) ?? {};
|
|
2421
|
+
mergeConnectedAdvertisedModelState(nextState, connectedState);
|
|
2422
|
+
mergeConnectedModelPreferences(nextState, connectedState);
|
|
2423
|
+
return nextState;
|
|
2424
|
+
}
|
|
2425
|
+
function mergeConnectedAdvertisedModelState(nextState, connectedState) {
|
|
2426
|
+
if (connectedState.config_options !== void 0) nextState.config_options = structuredClone(connectedState.config_options);
|
|
2427
|
+
else delete nextState.config_options;
|
|
2428
|
+
if (connectedState.current_model_id !== void 0) nextState.current_model_id = connectedState.current_model_id;
|
|
2429
|
+
else delete nextState.current_model_id;
|
|
2430
|
+
if (connectedState.available_models) nextState.available_models = [...connectedState.available_models];
|
|
2431
|
+
else delete nextState.available_models;
|
|
2432
|
+
if (connectedState.model_control) nextState.model_control = connectedState.model_control;
|
|
2433
|
+
else delete nextState.model_control;
|
|
2434
|
+
}
|
|
2435
|
+
function mergeConnectedModelPreferences(nextState, connectedState) {
|
|
2436
|
+
if (connectedState.session_options) nextState.session_options = cloneSessionAcpxState(connectedState)?.session_options;
|
|
2437
|
+
if (connectedState.desired_mode_id !== void 0) nextState.desired_mode_id = connectedState.desired_mode_id;
|
|
2438
|
+
if (connectedState.desired_config_options) nextState.desired_config_options = { ...connectedState.desired_config_options };
|
|
2392
2439
|
}
|
|
2393
2440
|
async function applyPromptModelIfAdvertised(params) {
|
|
2394
2441
|
const requestedModel = requestedModelId(params.requestedModel);
|
|
2395
2442
|
if (!requestedModel) return;
|
|
2396
|
-
const models =
|
|
2397
|
-
assertRequestedModelSupported({
|
|
2443
|
+
const models = advertisedModelState(params.record.acpx);
|
|
2444
|
+
emitModelSupportWarning(assertRequestedModelSupported({
|
|
2398
2445
|
requestedModel,
|
|
2399
2446
|
models,
|
|
2400
2447
|
agentCommand: params.record.agentCommand,
|
|
2401
2448
|
context: "apply"
|
|
2402
|
-
});
|
|
2449
|
+
}), params.suppressWarnings);
|
|
2403
2450
|
if (!models) return;
|
|
2404
2451
|
if (params.record.acpx?.current_model_id === requestedModel) {
|
|
2405
|
-
setDesiredModelId(params.record, requestedModel);
|
|
2452
|
+
setDesiredModelId(params.record, requestedModel, models.configId);
|
|
2406
2453
|
return;
|
|
2407
2454
|
}
|
|
2408
|
-
await withTimeout(params.client.setSessionModel(params.sessionId, requestedModel), params.timeoutMs);
|
|
2409
|
-
|
|
2410
|
-
|
|
2455
|
+
const response = await withTimeout(params.client.setSessionModel(params.sessionId, requestedModel, models), params.timeoutMs);
|
|
2456
|
+
applyConfigOptionsToRecord(params.record, response);
|
|
2457
|
+
setDesiredModelId(params.record, requestedModel, models.configId);
|
|
2458
|
+
setCurrentModelId(params.record, currentModelIdFromSetModelResponse(response, requestedModel));
|
|
2459
|
+
}
|
|
2460
|
+
function emitModelSupportWarning(warning, suppressWarnings) {
|
|
2461
|
+
if (warning && !suppressWarnings) process.stderr.write(`[acpx] warning: ${warning}\n`);
|
|
2411
2462
|
}
|
|
2412
2463
|
function jsonRpcIdKey$1(value) {
|
|
2413
2464
|
if (typeof value === "string") return `s:${value}`;
|
|
@@ -2685,10 +2736,37 @@ async function runSessionPrompt(options) {
|
|
|
2685
2736
|
await client.setSessionMode(activeSessionIdForControl, modeId);
|
|
2686
2737
|
},
|
|
2687
2738
|
setSessionModel: async (modelId) => {
|
|
2688
|
-
|
|
2739
|
+
const models = advertisedModelState(acpxState);
|
|
2740
|
+
const response = await client.setSessionModel(activeSessionIdForControl, modelId, models);
|
|
2741
|
+
acpxState = applyConfigOptionResponseToState(acpxState, response);
|
|
2742
|
+
const nextState = cloneSessionAcpxState(acpxState) ?? {};
|
|
2743
|
+
nextState.session_options = {
|
|
2744
|
+
...nextState.session_options,
|
|
2745
|
+
model: modelId
|
|
2746
|
+
};
|
|
2747
|
+
nextState.current_model_id = currentModelIdFromSetModelResponse(response, modelId);
|
|
2748
|
+
clearDesiredConfigOption(nextState, models?.configId);
|
|
2749
|
+
acpxState = nextState;
|
|
2750
|
+
return response;
|
|
2689
2751
|
},
|
|
2690
2752
|
setSessionConfigOption: async (configId, value) => {
|
|
2691
|
-
|
|
2753
|
+
const response = await client.setSessionConfigOption(activeSessionIdForControl, configId, value);
|
|
2754
|
+
acpxState = applyConfigOptionResponseToState(acpxState, response);
|
|
2755
|
+
const nextState = cloneSessionAcpxState(acpxState) ?? {};
|
|
2756
|
+
if (configId === modelStateFromConfigOptions(nextState.config_options)?.configId) {
|
|
2757
|
+
nextState.session_options = {
|
|
2758
|
+
...nextState.session_options,
|
|
2759
|
+
model: value
|
|
2760
|
+
};
|
|
2761
|
+
nextState.current_model_id = currentModelIdFromSetModelResponse(response, value);
|
|
2762
|
+
clearDesiredConfigOption(nextState, configId);
|
|
2763
|
+
} else if (configId === "mode") nextState.desired_mode_id = value;
|
|
2764
|
+
else nextState.desired_config_options = {
|
|
2765
|
+
...nextState.desired_config_options,
|
|
2766
|
+
[configId]: value
|
|
2767
|
+
};
|
|
2768
|
+
acpxState = nextState;
|
|
2769
|
+
return response;
|
|
2692
2770
|
}
|
|
2693
2771
|
};
|
|
2694
2772
|
const flushConnectOutput = (loadError) => {
|
|
@@ -2707,6 +2785,7 @@ async function runSessionPrompt(options) {
|
|
|
2707
2785
|
resumePolicy: options.resumePolicy,
|
|
2708
2786
|
timeoutMs: options.timeoutMs,
|
|
2709
2787
|
verbose: options.verbose,
|
|
2788
|
+
suppressWarnings: options.suppressSdkConsoleErrors,
|
|
2710
2789
|
activeController,
|
|
2711
2790
|
onClientAvailable: (controller) => {
|
|
2712
2791
|
options.onClientAvailable?.(controller);
|
|
@@ -2720,6 +2799,7 @@ async function runSessionPrompt(options) {
|
|
|
2720
2799
|
}
|
|
2721
2800
|
});
|
|
2722
2801
|
});
|
|
2802
|
+
acpxState = mergeConnectedModelState(acpxState, record.acpx);
|
|
2723
2803
|
flushConnectOutput(connected.loadError);
|
|
2724
2804
|
emitConnectPerfMetric(connectStartedAt, options.verbose);
|
|
2725
2805
|
return connected;
|
|
@@ -2807,8 +2887,10 @@ async function runSessionPrompt(options) {
|
|
|
2807
2887
|
sessionId: activeSessionId,
|
|
2808
2888
|
requestedModel: sessionOptions?.model,
|
|
2809
2889
|
record,
|
|
2810
|
-
timeoutMs: options.timeoutMs
|
|
2890
|
+
timeoutMs: options.timeoutMs,
|
|
2891
|
+
suppressWarnings: options.suppressSdkConsoleErrors
|
|
2811
2892
|
});
|
|
2893
|
+
acpxState = cloneSessionAcpxState(record.acpx);
|
|
2812
2894
|
output.setContext({ sessionId: record.acpxRecordId });
|
|
2813
2895
|
await liveCheckpoint.checkpoint();
|
|
2814
2896
|
const response = await savePromptSuccess(await runPromptWithRetries(activeSessionId));
|
|
@@ -2909,7 +2991,8 @@ async function runOnce(options) {
|
|
|
2909
2991
|
requestedModel: options.sessionOptions?.model,
|
|
2910
2992
|
models: createdSession.models,
|
|
2911
2993
|
agentCommand: options.agentCommand,
|
|
2912
|
-
timeoutMs: options.timeoutMs
|
|
2994
|
+
timeoutMs: options.timeoutMs,
|
|
2995
|
+
onWarning: options.suppressSdkConsoleErrors ? void 0 : (message) => process.stderr.write(`[acpx] warning: ${message}\n`)
|
|
2913
2996
|
});
|
|
2914
2997
|
output.setContext({ sessionId });
|
|
2915
2998
|
const response = await runExecPromptWithRetries(sessionId);
|
|
@@ -3001,7 +3084,7 @@ function createQueueOwnerTurnController(options) {
|
|
|
3001
3084
|
});
|
|
3002
3085
|
},
|
|
3003
3086
|
setSessionModelFallback: async (modelId, timeoutMs) => {
|
|
3004
|
-
await runSessionSetModelDirect({
|
|
3087
|
+
return (await runSessionSetModelDirect({
|
|
3005
3088
|
sessionRecordId: options.sessionId,
|
|
3006
3089
|
modelId,
|
|
3007
3090
|
mcpServers: options.mcpServers,
|
|
@@ -3011,7 +3094,7 @@ function createQueueOwnerTurnController(options) {
|
|
|
3011
3094
|
terminal: options.terminal,
|
|
3012
3095
|
timeoutMs,
|
|
3013
3096
|
verbose: options.verbose
|
|
3014
|
-
});
|
|
3097
|
+
})).response;
|
|
3015
3098
|
},
|
|
3016
3099
|
setSessionConfigOptionFallback: async (configId, value, timeoutMs) => {
|
|
3017
3100
|
return (await runSessionSetConfigOptionDirect({
|
|
@@ -3105,9 +3188,7 @@ async function runSessionQueueOwner(options) {
|
|
|
3105
3188
|
setSessionMode: async (modeId, timeoutMs) => {
|
|
3106
3189
|
await turnController.setSessionMode(modeId, timeoutMs);
|
|
3107
3190
|
},
|
|
3108
|
-
setSessionModel: async (modelId, timeoutMs) =>
|
|
3109
|
-
await turnController.setSessionModel(modelId, timeoutMs);
|
|
3110
|
-
},
|
|
3191
|
+
setSessionModel: async (modelId, timeoutMs) => await turnController.setSessionModel(modelId, timeoutMs),
|
|
3111
3192
|
setSessionConfigOption: async (configId, value, timeoutMs) => {
|
|
3112
3193
|
return await turnController.setSessionConfigOption(configId, value, timeoutMs);
|
|
3113
3194
|
}
|
|
@@ -3201,6 +3282,7 @@ var session_exports = /* @__PURE__ */ __exportAll({
|
|
|
3201
3282
|
listAgentSessions: () => listAgentSessions,
|
|
3202
3283
|
listSessions: () => listSessions,
|
|
3203
3284
|
listSessionsForAgent: () => listSessionsForAgent,
|
|
3285
|
+
mergeConnectedModelState: () => mergeConnectedModelState,
|
|
3204
3286
|
normalizeQueueOwnerTtlMs: () => normalizeQueueOwnerTtlMs,
|
|
3205
3287
|
pruneSessions: () => pruneSessions,
|
|
3206
3288
|
runOnce: () => runOnce,
|
|
@@ -4141,6 +4223,6 @@ function createOutputFormatter(format, options = {}) {
|
|
|
4141
4223
|
}
|
|
4142
4224
|
}
|
|
4143
4225
|
//#endregion
|
|
4144
|
-
export { runSessionQueueOwner as a, buildQueueOwnerArgOverride as c, createSessionWithClient as d, cancelSessionPrompt as f, __exportAll as h, session_exports as i, flushPerfMetricsCapture as l, DEFAULT_QUEUE_OWNER_TTL_MS as m, getTextErrorRemediationHints as n, runOnce as o, probeQueueOwnerHealth as p, output_exports as r, sendSessionDirect as s, createOutputFormatter as t, installPerfMetricsCapture as u };
|
|
4226
|
+
export { runSessionQueueOwner as a, buildQueueOwnerArgOverride as c, createSessionWithClient as d, cancelSessionPrompt as f, __exportAll as g, isProcessAlive as h, session_exports as i, flushPerfMetricsCapture as l, DEFAULT_QUEUE_OWNER_TTL_MS as m, getTextErrorRemediationHints as n, runOnce as o, probeQueueOwnerHealth as p, output_exports as r, sendSessionDirect as s, createOutputFormatter as t, installPerfMetricsCapture as u };
|
|
4145
4227
|
|
|
4146
|
-
//# sourceMappingURL=output-
|
|
4228
|
+
//# sourceMappingURL=output-D_BGt1YI.js.map
|