@ycodium-ai/agent-grok 0.2.6274 → 0.2.6450
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 +10 -4
- package/dist/index.js +830 -448
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
9
9
|
|
|
10
10
|
// ../../packages/plugin-api/src/version.ts
|
|
11
|
-
var PLUGIN_API_VERSION =
|
|
11
|
+
var PLUGIN_API_VERSION = 214;
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
14
|
import { registerEffectiveHomeCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
@@ -79,6 +79,16 @@ var GROK_CARD = {
|
|
|
79
79
|
// 型号与思考档都在会话里切,不重开(重开会把进程里的子 agent 一起关掉):执行器发送前经
|
|
80
80
|
// `model` 与 `reasoning_effort` 两个配置项写进去(1.0.70 实测,同一进程,下一轮生效)。
|
|
81
81
|
sessionModelSwitch: "in-session",
|
|
82
|
+
// 单图 10 MiB 是产品自定的上限,不是 Grok 的限制:Grok 自带指南里没有单图上限
|
|
83
|
+
// (11-custom-models.md 的 max_request_bytes、26-config-reference.md),只有整次请求体的预算——
|
|
84
|
+
// `messages` 后端 30 MB、其余 50 MiB——超限时把对话里较早的图逐出而不是拒收,所以没有可探测的
|
|
85
|
+
// 拒收边界。预算量的是请求体(含 base64 膨胀),不抄进 maxBytes。沿用 Codex / OpenCode 同一条
|
|
86
|
+
// 例外(ADR-0018 第六节 2026-12-02 修订)。
|
|
87
|
+
// ACP 的 promptCapabilities 只有 image?: boolean,没有尺寸字段;握手报 true 才发块(1.0.70 起)。
|
|
88
|
+
// 读口由 index.ts 捕获 ctx.attachments.read 传给工厂,grokAttachmentReader.test.ts 钉着这根线。
|
|
89
|
+
inlineImages: { maxBytes: 10 * 1024 * 1024 },
|
|
90
|
+
// _x.ai/ask_user_question 与 exit_plan_mode 扩展请求:不回应答就一直卡在这一步。
|
|
91
|
+
questionTransport: "blocking",
|
|
82
92
|
sessionOptionSwitch: "in-session",
|
|
83
93
|
// 运行模式只在 spawn 时定得了(`--permission-mode` 是启动旗标,ACP 那一侧
|
|
84
94
|
// `modes: null`,`session/set_mode` 对它无效),所以不许声称能会话中途换。
|
|
@@ -95,6 +105,13 @@ var GROK_CARD = {
|
|
|
95
105
|
contextCompaction: "native",
|
|
96
106
|
// 子 agent 经父会话上的 subagent_* 通知报成 task.*(grokSubagents.ts)。
|
|
97
107
|
reportsSpawnedAgents: true,
|
|
108
|
+
// CLI 自己扫工作目录与逐级父目录下的 `.grok/`、`.agents/`、`.claude/`、`.cursor/` 的 `skills/`,
|
|
109
|
+
// 出处是它随包发的用户指南 `docs/user-guide/08-skills.md`「Skill Locations」表;
|
|
110
|
+
// 宿主不再把仓库技能交第二遍。
|
|
111
|
+
discoversRepoSkills: true,
|
|
112
|
+
// 会话技能经 --plugin-dir 加载后,正文里的 `/name` 由 CLI 原生展开(1.0.97 实测,零工具调用,
|
|
113
|
+
// 录像 test/grokSkillInvocation.wire.ndjson);插件把输入区的 $name 翻成它,漏掉的补指示行。
|
|
114
|
+
handlesSkillInvocations: true,
|
|
98
115
|
// 插话:起会话前在配置里打开 `follow_up_behavior = "steer"`(grokFollowUpSteer.ts),运行中再发的 prompt
|
|
99
116
|
// 由 grok 在下一个工具调用结束时并进这一轮(1.0.70 ACP 模式实测);执行器不等前一条应答就写出去。
|
|
100
117
|
turnSteering: true,
|
|
@@ -168,9 +185,9 @@ import {
|
|
|
168
185
|
readTrimmedString as readString
|
|
169
186
|
} from "@ycodium-ai/plugin-api/credential-account";
|
|
170
187
|
var AUTH_FILE_NAME = "auth.json";
|
|
171
|
-
var joinName = (
|
|
172
|
-
const first = readString(
|
|
173
|
-
const last = readString(
|
|
188
|
+
var joinName = (record5) => {
|
|
189
|
+
const first = readString(record5, "first_name");
|
|
190
|
+
const last = readString(record5, "last_name");
|
|
174
191
|
const joined = [first, last].filter((part) => part !== void 0).join(" ");
|
|
175
192
|
return joined.length > 0 ? joined : void 0;
|
|
176
193
|
};
|
|
@@ -269,7 +286,7 @@ function buildSpawnEnv(recipe, resolvedHomePath, homeConfigured) {
|
|
|
269
286
|
|
|
270
287
|
// src/grokInstance.ts
|
|
271
288
|
import { sessionReadFromImport } from "@ycodium-ai/plugin-api/session-history";
|
|
272
|
-
import * as
|
|
289
|
+
import * as NodeCrypto6 from "node:crypto";
|
|
273
290
|
import {
|
|
274
291
|
raceAbort as raceAbort2
|
|
275
292
|
} from "@ycodium-ai/plugin-api/executor";
|
|
@@ -1317,6 +1334,18 @@ function parseSessionModeState(sessionResponse) {
|
|
|
1317
1334
|
availableModes
|
|
1318
1335
|
};
|
|
1319
1336
|
}
|
|
1337
|
+
var ACP_COMPACT_COMMAND = "compact";
|
|
1338
|
+
function acpAdvertisesCommand(commands, commandName) {
|
|
1339
|
+
return commands.some((command) => command.name === commandName);
|
|
1340
|
+
}
|
|
1341
|
+
function acpCompactingSessionCommands(host, threadId) {
|
|
1342
|
+
host.reportSessionInventory?.({ threadId, supportsContextCompaction: false });
|
|
1343
|
+
return (commands) => host.reportSessionInventory?.({
|
|
1344
|
+
threadId,
|
|
1345
|
+
slashCommands: acpCommandsToSlashCommands(commands),
|
|
1346
|
+
supportsContextCompaction: acpAdvertisesCommand(commands, ACP_COMPACT_COMMAND)
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1320
1349
|
function acpCommandsToSlashCommands(commands) {
|
|
1321
1350
|
return commands.map((command) => ({
|
|
1322
1351
|
name: command.name,
|
|
@@ -1823,7 +1852,7 @@ function makeAcpToolCallEvent(input2) {
|
|
|
1823
1852
|
const rawData = input2.toolCall.data;
|
|
1824
1853
|
const data = readToolCallIdentityFields(input2.toolCall).negativeMcp ? { ...rawData, mcpServer: null, mcpTool: null } : rawData;
|
|
1825
1854
|
return {
|
|
1826
|
-
type: input2.toolCall.status === "completed" || input2.toolCall.status === "failed" ? "item.completed" : "item.updated",
|
|
1855
|
+
type: input2.toolCall.status === "completed" || input2.toolCall.status === "failed" ? "item.completed" : input2.lifecycle ?? "item.updated",
|
|
1827
1856
|
...input2.stamp,
|
|
1828
1857
|
provider: input2.provider,
|
|
1829
1858
|
threadId: input2.threadId,
|
|
@@ -1924,10 +1953,10 @@ function createChildSessionRegistry(limit = CHILD_LIMIT) {
|
|
|
1924
1953
|
const records = /* @__PURE__ */ new Map();
|
|
1925
1954
|
const evictOne = (keep) => {
|
|
1926
1955
|
const protectedIds = /* @__PURE__ */ new Set();
|
|
1927
|
-
for (const [id,
|
|
1928
|
-
if (!active(
|
|
1956
|
+
for (const [id, record5] of records) {
|
|
1957
|
+
if (!active(record5.observed)) continue;
|
|
1929
1958
|
protectedIds.add(id);
|
|
1930
|
-
let parent =
|
|
1959
|
+
let parent = record5.parentAgentId;
|
|
1931
1960
|
while (parent !== void 0 && !protectedIds.has(parent)) {
|
|
1932
1961
|
protectedIds.add(parent);
|
|
1933
1962
|
parent = records.get(parent)?.parentAgentId;
|
|
@@ -1939,8 +1968,8 @@ function createChildSessionRegistry(limit = CHILD_LIMIT) {
|
|
|
1939
1968
|
return;
|
|
1940
1969
|
}
|
|
1941
1970
|
};
|
|
1942
|
-
const add = (sessionId,
|
|
1943
|
-
records.set(sessionId,
|
|
1971
|
+
const add = (sessionId, record5) => {
|
|
1972
|
+
records.set(sessionId, record5);
|
|
1944
1973
|
if (records.size > limit) evictOne(sessionId);
|
|
1945
1974
|
};
|
|
1946
1975
|
return {
|
|
@@ -18624,8 +18653,8 @@ function rewriteKeyNames(ctx) {
|
|
|
18624
18653
|
bySchema.set(entry.schema, entry);
|
|
18625
18654
|
}
|
|
18626
18655
|
const rewrites = /* @__PURE__ */ new Map();
|
|
18627
|
-
for (const
|
|
18628
|
-
const seen = ctx.seen.get(
|
|
18656
|
+
for (const record5 of pendingRecords.get(ctx) ?? []) {
|
|
18657
|
+
const seen = ctx.seen.get(record5);
|
|
18629
18658
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
18630
18659
|
if (!names || names === true || rewrites.has(names))
|
|
18631
18660
|
continue;
|
|
@@ -25963,6 +25992,7 @@ var defaultVendorHooks = {
|
|
|
25963
25992
|
|
|
25964
25993
|
// ../../packages/ycodium-acp-executor/src/executor/support.ts
|
|
25965
25994
|
var DEFAULT_RESULT_DRAIN_TIMEOUT_MS = 2e3;
|
|
25995
|
+
var DEFAULT_COMPACTION_SIGNAL_TIMEOUT_MS = 12e4;
|
|
25966
25996
|
|
|
25967
25997
|
// ../../packages/ycodium-acp-executor/src/executor/lifecycle.ts
|
|
25968
25998
|
function createExecutorLifecycle({
|
|
@@ -25980,6 +26010,7 @@ function createExecutorLifecycle({
|
|
|
25980
26010
|
emit,
|
|
25981
26011
|
stamp,
|
|
25982
26012
|
options,
|
|
26013
|
+
hooks,
|
|
25983
26014
|
promptMutex,
|
|
25984
26015
|
randomId,
|
|
25985
26016
|
nowMs,
|
|
@@ -25987,6 +26018,7 @@ function createExecutorLifecycle({
|
|
|
25987
26018
|
sendPromptRpc,
|
|
25988
26019
|
compactions,
|
|
25989
26020
|
notifyPromptSettled,
|
|
26021
|
+
wakeManualCompactionWait,
|
|
25990
26022
|
eventStream,
|
|
25991
26023
|
onInputDead,
|
|
25992
26024
|
shared,
|
|
@@ -25997,6 +26029,7 @@ function createExecutorLifecycle({
|
|
|
25997
26029
|
const cancel = async (turnId) => {
|
|
25998
26030
|
failIfDisposed();
|
|
25999
26031
|
const started = requireStarted();
|
|
26032
|
+
wakeManualCompactionWait();
|
|
26000
26033
|
const targetTurnId = turnId ?? shared.activeTurnId;
|
|
26001
26034
|
promptResults.stop(targetTurnId);
|
|
26002
26035
|
if (targetTurnId !== void 0) {
|
|
@@ -26049,7 +26082,7 @@ function createExecutorLifecycle({
|
|
|
26049
26082
|
const started = requireStarted();
|
|
26050
26083
|
const trimmedName = input2.commandName.trim();
|
|
26051
26084
|
const commandName = trimmedName.startsWith("/") ? trimmedName.slice(1) : trimmedName;
|
|
26052
|
-
if (!shared.availableCommands
|
|
26085
|
+
if (!acpAdvertisesCommand(shared.availableCommands, commandName)) {
|
|
26053
26086
|
throw new AcpExecutorError(
|
|
26054
26087
|
"command-unavailable",
|
|
26055
26088
|
`The agent has not advertised the /${commandName} command`
|
|
@@ -26061,7 +26094,7 @@ function createExecutorLifecycle({
|
|
|
26061
26094
|
"Cannot compact while a turn or another compaction is running"
|
|
26062
26095
|
);
|
|
26063
26096
|
}
|
|
26064
|
-
const
|
|
26097
|
+
const record5 = {
|
|
26065
26098
|
snapshotId: randomId()?.trim() || NodeCrypto2.randomUUID(),
|
|
26066
26099
|
trigger: "manual",
|
|
26067
26100
|
startedAtMs: nowMs(),
|
|
@@ -26071,7 +26104,13 @@ function createExecutorLifecycle({
|
|
|
26071
26104
|
adopted: false
|
|
26072
26105
|
};
|
|
26073
26106
|
await promptMutex.acquire();
|
|
26074
|
-
shared.manualCompaction =
|
|
26107
|
+
shared.manualCompaction = record5;
|
|
26108
|
+
const completion = hooks.compactionCompleted === void 0 ? void 0 : (() => {
|
|
26109
|
+
const waiting = Promise.withResolvers();
|
|
26110
|
+
const state = { arrived: false, wake: waiting.resolve };
|
|
26111
|
+
shared.manualCompactionWait = state;
|
|
26112
|
+
return { state, promise: waiting.promise };
|
|
26113
|
+
})();
|
|
26075
26114
|
const emitSessionState = (state) => {
|
|
26076
26115
|
emit({
|
|
26077
26116
|
type: "session.state.changed",
|
|
@@ -26084,7 +26123,7 @@ function createExecutorLifecycle({
|
|
|
26084
26123
|
try {
|
|
26085
26124
|
failIfDisposed();
|
|
26086
26125
|
emitSessionState("compacting");
|
|
26087
|
-
emitCompactionState(
|
|
26126
|
+
emitCompactionState(record5, "compacting");
|
|
26088
26127
|
let response;
|
|
26089
26128
|
try {
|
|
26090
26129
|
response = await sendPromptRpc(started.sessionId, [
|
|
@@ -26098,15 +26137,45 @@ function createExecutorLifecycle({
|
|
|
26098
26137
|
if (response.stopReason === "cancelled") {
|
|
26099
26138
|
return;
|
|
26100
26139
|
}
|
|
26101
|
-
|
|
26102
|
-
|
|
26103
|
-
|
|
26140
|
+
let timedOut = false;
|
|
26141
|
+
if (completion !== void 0 && !record5.finished && !completion.state.arrived) {
|
|
26142
|
+
let timer;
|
|
26143
|
+
timedOut = await Promise.race([
|
|
26144
|
+
completion.promise.then(() => false),
|
|
26145
|
+
new Promise((resolve2) => {
|
|
26146
|
+
timer = setTimeout(
|
|
26147
|
+
resolve2,
|
|
26148
|
+
options.compactionSignalTimeoutMs ?? DEFAULT_COMPACTION_SIGNAL_TIMEOUT_MS,
|
|
26149
|
+
true
|
|
26150
|
+
);
|
|
26151
|
+
})
|
|
26152
|
+
]);
|
|
26153
|
+
clearTimeout(timer);
|
|
26154
|
+
}
|
|
26155
|
+
if (!record5.finished) {
|
|
26156
|
+
if (completion === void 0 || completion.state.arrived) {
|
|
26157
|
+
record5.finished = true;
|
|
26158
|
+
emitCompactionState(record5, "compacted");
|
|
26159
|
+
} else if (timedOut) {
|
|
26160
|
+
record5.finished = true;
|
|
26161
|
+
emit({
|
|
26162
|
+
type: "runtime.warning",
|
|
26163
|
+
...stamp(),
|
|
26164
|
+
provider: options.provider,
|
|
26165
|
+
threadId: options.threadId,
|
|
26166
|
+
payload: {
|
|
26167
|
+
message: "Ycodium stopped waiting for the agent to report that context compaction finished.",
|
|
26168
|
+
detail: { code: "context-compaction-signal-timeout" }
|
|
26169
|
+
}
|
|
26170
|
+
});
|
|
26171
|
+
}
|
|
26104
26172
|
}
|
|
26105
26173
|
} finally {
|
|
26106
26174
|
for (const [agentId, tracked] of compactions) {
|
|
26107
|
-
if (tracked ===
|
|
26175
|
+
if (tracked === record5) compactions.delete(agentId);
|
|
26108
26176
|
}
|
|
26109
26177
|
shared.manualCompaction = void 0;
|
|
26178
|
+
shared.manualCompactionWait = void 0;
|
|
26110
26179
|
promptMutex.release();
|
|
26111
26180
|
notifyPromptSettled();
|
|
26112
26181
|
if (!shared.disposed) emitSessionState("ready");
|
|
@@ -26118,6 +26187,7 @@ function createExecutorLifecycle({
|
|
|
26118
26187
|
shared.disposing = true;
|
|
26119
26188
|
disposing = (async () => {
|
|
26120
26189
|
shared.localPromptWait?.stop();
|
|
26190
|
+
wakeManualCompactionWait();
|
|
26121
26191
|
if (exitCode !== void 0) {
|
|
26122
26192
|
let timer;
|
|
26123
26193
|
await Promise.race([
|
|
@@ -26193,10 +26263,10 @@ function selectAutoApprovedAcpPermissionOption(request) {
|
|
|
26193
26263
|
}
|
|
26194
26264
|
function parseAcpResumeCursor(raw, schemaVersion) {
|
|
26195
26265
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
|
|
26196
|
-
const
|
|
26197
|
-
if (
|
|
26198
|
-
if (typeof
|
|
26199
|
-
return { sessionId:
|
|
26266
|
+
const record5 = raw;
|
|
26267
|
+
if (record5["schemaVersion"] !== schemaVersion) return void 0;
|
|
26268
|
+
if (typeof record5["sessionId"] !== "string" || !record5["sessionId"].trim()) return void 0;
|
|
26269
|
+
return { sessionId: record5["sessionId"].trim() };
|
|
26200
26270
|
}
|
|
26201
26271
|
function acpPromptSettlementBelongsToContext(input2) {
|
|
26202
26272
|
return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
|
|
@@ -26212,18 +26282,18 @@ function isAcpRequestPermissionParams(value) {
|
|
|
26212
26282
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
26213
26283
|
return false;
|
|
26214
26284
|
}
|
|
26215
|
-
const
|
|
26216
|
-
if (typeof
|
|
26285
|
+
const record5 = value;
|
|
26286
|
+
if (typeof record5["sessionId"] !== "string") {
|
|
26217
26287
|
return false;
|
|
26218
26288
|
}
|
|
26219
|
-
const toolCall =
|
|
26289
|
+
const toolCall = record5["toolCall"];
|
|
26220
26290
|
if (typeof toolCall !== "object" || toolCall === null || Array.isArray(toolCall)) {
|
|
26221
26291
|
return false;
|
|
26222
26292
|
}
|
|
26223
26293
|
if (typeof toolCall["toolCallId"] !== "string") {
|
|
26224
26294
|
return false;
|
|
26225
26295
|
}
|
|
26226
|
-
return Array.isArray(
|
|
26296
|
+
return Array.isArray(record5["options"]) && record5["options"].every(isAcpPermissionOption);
|
|
26227
26297
|
}
|
|
26228
26298
|
|
|
26229
26299
|
// ../../packages/ycodium-acp-executor/src/apply-effort.ts
|
|
@@ -26290,6 +26360,41 @@ var acpPromptFailureCategory = (error62, input2) => {
|
|
|
26290
26360
|
return error62 instanceof AcpConnectionClosedError ? acpClosedConnectionCategory(error62, input2.sessionEstablished, input2.disposed) : void 0;
|
|
26291
26361
|
};
|
|
26292
26362
|
|
|
26363
|
+
// ../../packages/ycodium-acp-executor/src/prompt-images.ts
|
|
26364
|
+
import * as NodeBuffer from "node:buffer";
|
|
26365
|
+
function acpAcceptsInlineImages(initializeResult) {
|
|
26366
|
+
return initializeResult?.agentCapabilities?.promptCapabilities?.image === true;
|
|
26367
|
+
}
|
|
26368
|
+
function isRecord7(value) {
|
|
26369
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26370
|
+
}
|
|
26371
|
+
function acpImageAttachmentCount(attachments) {
|
|
26372
|
+
return (attachments ?? []).filter((entry) => isRecord7(entry) && entry["type"] === "image").length;
|
|
26373
|
+
}
|
|
26374
|
+
async function acpPromptImagesFromAttachments(input2) {
|
|
26375
|
+
const { attachments, readAttachment: readAttachment2 } = input2;
|
|
26376
|
+
if (attachments === void 0 || attachments.length === 0 || readAttachment2 === void 0) {
|
|
26377
|
+
return [];
|
|
26378
|
+
}
|
|
26379
|
+
const images = [];
|
|
26380
|
+
for (const attachment of attachments) {
|
|
26381
|
+
if (!isRecord7(attachment) || attachment["type"] !== "image") continue;
|
|
26382
|
+
const id = typeof attachment["id"] === "string" ? attachment["id"] : "";
|
|
26383
|
+
const mimeType = typeof attachment["mimeType"] === "string" ? attachment["mimeType"] : "";
|
|
26384
|
+
if (id === "" || mimeType === "") continue;
|
|
26385
|
+
try {
|
|
26386
|
+
const bytes = await readAttachment2(id);
|
|
26387
|
+
images.push({
|
|
26388
|
+
data: NodeBuffer.Buffer.from(bytes).toString("base64"),
|
|
26389
|
+
mimeType
|
|
26390
|
+
});
|
|
26391
|
+
} catch {
|
|
26392
|
+
continue;
|
|
26393
|
+
}
|
|
26394
|
+
}
|
|
26395
|
+
return images;
|
|
26396
|
+
}
|
|
26397
|
+
|
|
26293
26398
|
// ../../packages/ycodium-acp-executor/src/tool-subagents.ts
|
|
26294
26399
|
var EXCLUDED = /* @__PURE__ */ Symbol("excluded");
|
|
26295
26400
|
var sealedHidden = (entry) => ({
|
|
@@ -26635,6 +26740,7 @@ function createExecutorPrompt({
|
|
|
26635
26740
|
return false;
|
|
26636
26741
|
}
|
|
26637
26742
|
const outcome = (input2.foldedIn === true ? ownOutcomes.get(input2.turnId) : void 0) ?? input2;
|
|
26743
|
+
const singlePrompt = promptResults.sentCount(input2.turnId) === 1;
|
|
26638
26744
|
ownOutcomes.delete(input2.turnId);
|
|
26639
26745
|
shared.activeTurnId = void 0;
|
|
26640
26746
|
if (shared.status !== "disposed") {
|
|
@@ -26658,14 +26764,16 @@ function createExecutorPrompt({
|
|
|
26658
26764
|
state: interrupted ? "cancelled" : outcome.state,
|
|
26659
26765
|
stopReason: interrupted ? "cancelled" : outcome.stopReason,
|
|
26660
26766
|
...outcome.errorMessage === void 0 ? {} : { errorMessage: outcome.errorMessage },
|
|
26661
|
-
...outcome.state === "failed" ? failureCategoryField(outcome.failureCategory) : {}
|
|
26767
|
+
...outcome.state === "failed" ? failureCategoryField(outcome.failureCategory) : {},
|
|
26768
|
+
// 一轮发出过多次 session/prompt(插话)时,单条应答不再可证为整轮总数,不报 tokenUsage。
|
|
26769
|
+
...singlePrompt && outcome.tokenUsage !== void 0 ? { tokenUsage: outcome.tokenUsage } : {}
|
|
26662
26770
|
}
|
|
26663
26771
|
});
|
|
26664
26772
|
interruptedTurnIds.delete(input2.turnId);
|
|
26665
26773
|
promptResults.forget(input2.turnId);
|
|
26666
26774
|
return true;
|
|
26667
26775
|
};
|
|
26668
|
-
const sendPromptRpc = async (sessionId, promptParts, onWritten,
|
|
26776
|
+
const sendPromptRpc = async (sessionId, promptParts, onWritten, record5) => {
|
|
26669
26777
|
const settlementHooks = hooks.promptSettlement;
|
|
26670
26778
|
const promptKey = settlementHooks === void 0 ? void 0 : randomId();
|
|
26671
26779
|
const pending = connection.begin(
|
|
@@ -26675,7 +26783,7 @@ function createExecutorPrompt({
|
|
|
26675
26783
|
prompt: promptParts,
|
|
26676
26784
|
...settlementHooks !== void 0 && promptKey !== void 0 ? settlementHooks.requestFields(promptKey) : {}
|
|
26677
26785
|
},
|
|
26678
|
-
|
|
26786
|
+
record5?.promptId
|
|
26679
26787
|
);
|
|
26680
26788
|
void pending.written.then(onWritten, () => void 0);
|
|
26681
26789
|
const promptRpc = pending.response;
|
|
@@ -26687,10 +26795,10 @@ function createExecutorPrompt({
|
|
|
26687
26795
|
promptKey,
|
|
26688
26796
|
sessionId,
|
|
26689
26797
|
settle: settleEarly,
|
|
26690
|
-
...
|
|
26691
|
-
onResponse: (response) => promptResults.receive(
|
|
26692
|
-
onError: () => promptResults.reject(
|
|
26693
|
-
hasResult: () =>
|
|
26798
|
+
...record5 === void 0 ? {} : {
|
|
26799
|
+
onResponse: (response) => promptResults.receive(record5.promptId, response),
|
|
26800
|
+
onError: () => promptResults.reject(record5.promptId),
|
|
26801
|
+
hasResult: () => record5.response !== void 0
|
|
26694
26802
|
}
|
|
26695
26803
|
});
|
|
26696
26804
|
try {
|
|
@@ -26784,11 +26892,11 @@ function createExecutorPrompt({
|
|
|
26784
26892
|
failIfPromptUnavailable();
|
|
26785
26893
|
const started = requireStarted();
|
|
26786
26894
|
const sessionId = started.sessionId;
|
|
26787
|
-
let
|
|
26895
|
+
let record5;
|
|
26788
26896
|
const settle2 = (rest) => settleTurn({
|
|
26789
26897
|
expectedGeneration: started.generation,
|
|
26790
26898
|
expectedSessionId: sessionId,
|
|
26791
|
-
record:
|
|
26899
|
+
record: record5,
|
|
26792
26900
|
...rest
|
|
26793
26901
|
});
|
|
26794
26902
|
let turnId;
|
|
@@ -26801,7 +26909,7 @@ function createExecutorPrompt({
|
|
|
26801
26909
|
randomId
|
|
26802
26910
|
);
|
|
26803
26911
|
shared.promptsInFlight += 1;
|
|
26804
|
-
|
|
26912
|
+
record5 = promptResults.add(
|
|
26805
26913
|
{
|
|
26806
26914
|
promptId: randomId(),
|
|
26807
26915
|
sessionId: started.sessionId,
|
|
@@ -26827,12 +26935,27 @@ function createExecutorPrompt({
|
|
|
26827
26935
|
} finally {
|
|
26828
26936
|
threadMutex.release();
|
|
26829
26937
|
}
|
|
26830
|
-
const
|
|
26938
|
+
const images = input2.images ?? [];
|
|
26939
|
+
const acceptsImages = acpAcceptsInlineImages(shared.initializeResult);
|
|
26940
|
+
if (images.length > 0 && !acceptsImages) {
|
|
26941
|
+
options.log?.info("acp agent does not accept image content; sending their path lines only", {
|
|
26942
|
+
threadId: options.threadId,
|
|
26943
|
+
droppedImages: images.length
|
|
26944
|
+
});
|
|
26945
|
+
}
|
|
26946
|
+
const promptParts = input2.prompt ?? [
|
|
26947
|
+
{ type: "text", text: input2.text ?? "" },
|
|
26948
|
+
...acceptsImages ? images.map((image) => ({
|
|
26949
|
+
type: "image",
|
|
26950
|
+
data: image.data,
|
|
26951
|
+
mimeType: image.mimeType
|
|
26952
|
+
})) : []
|
|
26953
|
+
];
|
|
26831
26954
|
let contextWindow;
|
|
26832
26955
|
const finishPrompt = () => {
|
|
26833
|
-
if (!isLive(started.generation) ||
|
|
26834
|
-
const response2 =
|
|
26835
|
-
if (
|
|
26956
|
+
if (!isLive(started.generation) || record5.finished) throw new AcpExecutorDisposedError();
|
|
26957
|
+
const response2 = record5.response;
|
|
26958
|
+
if (record5.interrupted || response2 === void 0) {
|
|
26836
26959
|
settle2({ turnId, stopReason: "cancelled", state: "cancelled" });
|
|
26837
26960
|
return { threadId: options.threadId, turnId, stopReason: "cancelled" };
|
|
26838
26961
|
}
|
|
@@ -26852,10 +26975,16 @@ function createExecutorPrompt({
|
|
|
26852
26975
|
}
|
|
26853
26976
|
});
|
|
26854
26977
|
}
|
|
26978
|
+
const tokenUsage = hooks.turnUsageFromPromptResponse?.({
|
|
26979
|
+
promptResponse: response2,
|
|
26980
|
+
modelId: shared.modelSelectionState.currentModelId,
|
|
26981
|
+
sessionId
|
|
26982
|
+
});
|
|
26855
26983
|
settle2({
|
|
26856
26984
|
turnId,
|
|
26857
26985
|
stopReason,
|
|
26858
26986
|
state: response2.stopReason === "cancelled" ? "cancelled" : "completed",
|
|
26987
|
+
...tokenUsage === void 0 ? {} : { tokenUsage },
|
|
26859
26988
|
// 立刻写出的插话没被打断却应答 cancelled:agent 把它并进了这一轮(grok 的 removedFromQueue)。
|
|
26860
26989
|
foldedIn: response2.stopReason === "cancelled" && input2.expectedActiveTurnId !== void 0 && hooks.queuesPromptsWhileRunning === true
|
|
26861
26990
|
});
|
|
@@ -26912,6 +27041,7 @@ function createExecutorPrompt({
|
|
|
26912
27041
|
let written = false;
|
|
26913
27042
|
try {
|
|
26914
27043
|
const readFailure = hooks.observePromptFailure?.(sessionId);
|
|
27044
|
+
promptResults.markSent(record5);
|
|
26915
27045
|
response = await sendPromptRpc(
|
|
26916
27046
|
sessionId,
|
|
26917
27047
|
promptParts,
|
|
@@ -26919,7 +27049,7 @@ function createExecutorPrompt({
|
|
|
26919
27049
|
written = true;
|
|
26920
27050
|
input2.onDispatched?.(turnId);
|
|
26921
27051
|
},
|
|
26922
|
-
|
|
27052
|
+
record5
|
|
26923
27053
|
);
|
|
26924
27054
|
if (readFailure && response.stopReason === "end_turn" && isLive(started.generation) && !isStale()) {
|
|
26925
27055
|
const controller = new AbortController();
|
|
@@ -26974,7 +27104,7 @@ function createExecutorPrompt({
|
|
|
26974
27104
|
if (turnId === void 0) {
|
|
26975
27105
|
throw new AcpExecutorError("internal", "ACP prompt settled without a turn id");
|
|
26976
27106
|
}
|
|
26977
|
-
if (
|
|
27107
|
+
if (record5.finished) throw new AcpExecutorDisposedError();
|
|
26978
27108
|
if (hooks.readContextWindow !== void 0) {
|
|
26979
27109
|
try {
|
|
26980
27110
|
contextWindow = await hooks.readContextWindow({
|
|
@@ -27010,58 +27140,63 @@ function createPromptResults({
|
|
|
27010
27140
|
const prompts = /* @__PURE__ */ new Map();
|
|
27011
27141
|
const add = (identity, finish) => {
|
|
27012
27142
|
const { promise: done, resolve: resolve2 } = Promise.withResolvers();
|
|
27013
|
-
const
|
|
27143
|
+
const record5 = {
|
|
27014
27144
|
...identity,
|
|
27015
27145
|
finish,
|
|
27016
27146
|
done,
|
|
27017
27147
|
resolve: resolve2,
|
|
27148
|
+
sent: false,
|
|
27018
27149
|
rejected: false,
|
|
27019
27150
|
interrupted: false,
|
|
27020
27151
|
finished: false
|
|
27021
27152
|
};
|
|
27022
|
-
prompts.set(
|
|
27023
|
-
return
|
|
27153
|
+
prompts.set(record5.promptId, record5);
|
|
27154
|
+
return record5;
|
|
27024
27155
|
};
|
|
27156
|
+
const markSent = (record5) => {
|
|
27157
|
+
record5.sent = true;
|
|
27158
|
+
};
|
|
27159
|
+
const sentCount = (turnId) => [...prompts.values()].filter((record5) => record5.turnId === turnId && record5.sent).length;
|
|
27025
27160
|
const receive = (promptId, response) => {
|
|
27026
|
-
const
|
|
27027
|
-
if (!
|
|
27028
|
-
if (shared.disposed || shared.generation !==
|
|
27161
|
+
const record5 = prompts.get(promptId);
|
|
27162
|
+
if (!record5 || record5.finished || record5.rejected || record5.response !== void 0) return;
|
|
27163
|
+
if (shared.disposed || shared.generation !== record5.generation || shared.sessionId !== record5.sessionId)
|
|
27029
27164
|
return;
|
|
27030
|
-
|
|
27165
|
+
record5.response = response;
|
|
27031
27166
|
};
|
|
27032
27167
|
const reject = (promptId) => {
|
|
27033
|
-
const
|
|
27034
|
-
if (
|
|
27168
|
+
const record5 = prompts.get(promptId);
|
|
27169
|
+
if (record5 && record5.response === void 0) record5.rejected = true;
|
|
27035
27170
|
};
|
|
27036
27171
|
const stop = (turnId) => {
|
|
27037
|
-
for (const
|
|
27038
|
-
if (!
|
|
27039
|
-
|
|
27172
|
+
for (const record5 of prompts.values()) {
|
|
27173
|
+
if (!record5.finished && (turnId === void 0 || record5.turnId === turnId) && record5.response === void 0) {
|
|
27174
|
+
record5.interrupted = true;
|
|
27040
27175
|
}
|
|
27041
27176
|
}
|
|
27042
27177
|
};
|
|
27043
|
-
const complete = (
|
|
27044
|
-
|
|
27045
|
-
|
|
27178
|
+
const complete = (record5) => {
|
|
27179
|
+
record5.finished = true;
|
|
27180
|
+
record5.resolve();
|
|
27046
27181
|
};
|
|
27047
|
-
const hasInterrupted = (turnId) => [...prompts.values()].some((
|
|
27182
|
+
const hasInterrupted = (turnId) => [...prompts.values()].some((record5) => record5.turnId === turnId && record5.interrupted);
|
|
27048
27183
|
const forget = (turnId) => {
|
|
27049
|
-
for (const [id,
|
|
27050
|
-
if (
|
|
27051
|
-
complete(
|
|
27184
|
+
for (const [id, record5] of prompts) {
|
|
27185
|
+
if (record5.turnId === turnId) {
|
|
27186
|
+
complete(record5);
|
|
27052
27187
|
prompts.delete(id);
|
|
27053
27188
|
}
|
|
27054
27189
|
}
|
|
27055
27190
|
};
|
|
27056
27191
|
const wait = async (turnId, includeUnreceived = false) => {
|
|
27057
27192
|
const claimed = [...prompts.values()].filter(
|
|
27058
|
-
(
|
|
27193
|
+
(record5) => !record5.finished && (includeUnreceived || record5.response !== void 0) && (turnId === void 0 || record5.turnId === turnId)
|
|
27059
27194
|
);
|
|
27060
27195
|
if (claimed.length === 0) return;
|
|
27061
27196
|
let timer;
|
|
27062
27197
|
try {
|
|
27063
27198
|
const drained = await Promise.race([
|
|
27064
|
-
Promise.all(claimed.map((
|
|
27199
|
+
Promise.all(claimed.map((record5) => record5.done)).then(() => true),
|
|
27065
27200
|
new Promise((resolve2) => {
|
|
27066
27201
|
timer = setTimeout(
|
|
27067
27202
|
() => resolve2(false),
|
|
@@ -27071,23 +27206,35 @@ function createPromptResults({
|
|
|
27071
27206
|
]);
|
|
27072
27207
|
if (drained) return;
|
|
27073
27208
|
options.log?.warn?.("ACP result settlement timed out", { threadId: options.threadId });
|
|
27074
|
-
for (const
|
|
27209
|
+
for (const record5 of claimed) if (!record5.finished) record5.finish();
|
|
27075
27210
|
} finally {
|
|
27076
27211
|
clearTimeout(timer);
|
|
27077
27212
|
}
|
|
27078
27213
|
};
|
|
27079
27214
|
const finishUnreceived = () => {
|
|
27080
27215
|
const claimedTurns = new Set(
|
|
27081
|
-
[...prompts.values()].filter((
|
|
27216
|
+
[...prompts.values()].filter((record5) => !record5.finished && record5.response !== void 0).map((record5) => record5.turnId)
|
|
27082
27217
|
);
|
|
27083
|
-
for (const
|
|
27084
|
-
if (!
|
|
27085
|
-
if (claimedTurns.has(
|
|
27086
|
-
else complete(
|
|
27218
|
+
for (const record5 of prompts.values()) {
|
|
27219
|
+
if (!record5.finished && record5.response === void 0) {
|
|
27220
|
+
if (claimedTurns.has(record5.turnId)) record5.finish();
|
|
27221
|
+
else complete(record5);
|
|
27087
27222
|
}
|
|
27088
27223
|
}
|
|
27089
27224
|
};
|
|
27090
|
-
return {
|
|
27225
|
+
return {
|
|
27226
|
+
add,
|
|
27227
|
+
markSent,
|
|
27228
|
+
sentCount,
|
|
27229
|
+
receive,
|
|
27230
|
+
reject,
|
|
27231
|
+
stop,
|
|
27232
|
+
complete,
|
|
27233
|
+
hasInterrupted,
|
|
27234
|
+
forget,
|
|
27235
|
+
wait,
|
|
27236
|
+
finishUnreceived
|
|
27237
|
+
};
|
|
27091
27238
|
}
|
|
27092
27239
|
|
|
27093
27240
|
// ../../packages/ycodium-acp-executor/src/permission-statement.ts
|
|
@@ -27366,7 +27513,7 @@ function createExecutorRequests({
|
|
|
27366
27513
|
const immediateHadPrevious = toolCalls.has(trackingKey);
|
|
27367
27514
|
const immediatePrevious = toolCalls.get(trackingKey);
|
|
27368
27515
|
let mutatedToolCall = false;
|
|
27369
|
-
const hasTextField = (
|
|
27516
|
+
const hasTextField = (record5, key) => typeof record5[key] === "string" && record5[key].trim().length > 0;
|
|
27370
27517
|
const rawToolCallRecord = rawParams.toolCall;
|
|
27371
27518
|
const rawReqMeta = rawToolCallRecord["_meta"];
|
|
27372
27519
|
const rawParentMeta = rawParams["_meta"];
|
|
@@ -27720,6 +27867,9 @@ function createExecutorRuntime({
|
|
|
27720
27867
|
waiter();
|
|
27721
27868
|
}
|
|
27722
27869
|
};
|
|
27870
|
+
const wakeManualCompactionWait = () => {
|
|
27871
|
+
shared.manualCompactionWait?.wake();
|
|
27872
|
+
};
|
|
27723
27873
|
const waitForPromptIdle = async (timeoutMs) => {
|
|
27724
27874
|
if (!promptMutex.isLocked) {
|
|
27725
27875
|
return true;
|
|
@@ -27745,6 +27895,7 @@ function createExecutorRuntime({
|
|
|
27745
27895
|
closeActiveAssistantSegment,
|
|
27746
27896
|
ensureActiveAssistantSegment,
|
|
27747
27897
|
notifyPromptSettled,
|
|
27898
|
+
wakeManualCompactionWait,
|
|
27748
27899
|
waitForPromptIdle
|
|
27749
27900
|
};
|
|
27750
27901
|
}
|
|
@@ -27873,18 +28024,18 @@ function modelRefreshFailedError(requestedModelId, error62) {
|
|
|
27873
28024
|
}
|
|
27874
28025
|
|
|
27875
28026
|
// ../../packages/ycodium-acp-executor/src/runtime-mode.ts
|
|
27876
|
-
function
|
|
28027
|
+
function isRecord8(value) {
|
|
27877
28028
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27878
28029
|
}
|
|
27879
28030
|
function asString2(value) {
|
|
27880
28031
|
return typeof value === "string" ? value : void 0;
|
|
27881
28032
|
}
|
|
27882
28033
|
function acpModeConfigId(setup) {
|
|
27883
|
-
if (!
|
|
28034
|
+
if (!isRecord8(setup)) return void 0;
|
|
27884
28035
|
const configOptions = setup["configOptions"];
|
|
27885
28036
|
if (!Array.isArray(configOptions)) return void 0;
|
|
27886
28037
|
for (const option of configOptions) {
|
|
27887
|
-
if (!
|
|
28038
|
+
if (!isRecord8(option)) continue;
|
|
27888
28039
|
if (asString2(option["category"])?.trim().toLowerCase() !== "mode") continue;
|
|
27889
28040
|
const id = asString2(option["id"])?.trim();
|
|
27890
28041
|
if (id) return id;
|
|
@@ -28215,10 +28366,7 @@ function createExecutorSession({
|
|
|
28215
28366
|
provider: options.provider,
|
|
28216
28367
|
...options.providerInstanceId ? { providerInstanceId: options.providerInstanceId } : {},
|
|
28217
28368
|
threadId: options.threadId,
|
|
28218
|
-
payload: {
|
|
28219
|
-
sessionId: nextSessionId,
|
|
28220
|
-
cwd: options.cwd
|
|
28221
|
-
}
|
|
28369
|
+
payload: options.resumeSessionId ? { resume: { sessionId: nextSessionId } } : {}
|
|
28222
28370
|
});
|
|
28223
28371
|
return result;
|
|
28224
28372
|
};
|
|
@@ -28363,13 +28511,13 @@ function parseState(raw) {
|
|
|
28363
28511
|
if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
|
|
28364
28512
|
return { status: "idle", error: void 0 };
|
|
28365
28513
|
}
|
|
28366
|
-
function childLinkage(childId,
|
|
28514
|
+
function childLinkage(childId, record5) {
|
|
28367
28515
|
return {
|
|
28368
28516
|
taskType: "subagent",
|
|
28369
28517
|
rosterKind: "subagent",
|
|
28370
28518
|
nativeSessionId: childId,
|
|
28371
28519
|
timelineBypass: true,
|
|
28372
|
-
...
|
|
28520
|
+
...record5.title === void 0 ? {} : { title: record5.title }
|
|
28373
28521
|
};
|
|
28374
28522
|
}
|
|
28375
28523
|
function createSubagentSessionTracker(registry2) {
|
|
@@ -28385,9 +28533,9 @@ function createSubagentSessionTracker(registry2) {
|
|
|
28385
28533
|
const title = asTrimmedString(update["title"]);
|
|
28386
28534
|
const description = asTrimmedString(update["description"]);
|
|
28387
28535
|
const state = parseState(update["state"]);
|
|
28388
|
-
let
|
|
28389
|
-
if (
|
|
28390
|
-
|
|
28536
|
+
let record5 = registry2.get(childId);
|
|
28537
|
+
if (record5 === void 0) {
|
|
28538
|
+
record5 = {
|
|
28391
28539
|
turnId: ctx.turnId,
|
|
28392
28540
|
title,
|
|
28393
28541
|
description,
|
|
@@ -28399,40 +28547,40 @@ function createSubagentSessionTracker(registry2) {
|
|
|
28399
28547
|
announced: ctx.silent,
|
|
28400
28548
|
pendingMetadata: false
|
|
28401
28549
|
};
|
|
28402
|
-
registry2.add(childId,
|
|
28550
|
+
registry2.add(childId, record5);
|
|
28403
28551
|
}
|
|
28404
|
-
|
|
28552
|
+
record5.turnId ??= ctx.turnId;
|
|
28405
28553
|
if (!ctx.silent) {
|
|
28406
|
-
if (title !== void 0 && title !==
|
|
28407
|
-
|
|
28554
|
+
if (title !== void 0 && title !== record5.title || description !== void 0 && description !== record5.description) {
|
|
28555
|
+
record5.pendingMetadata = true;
|
|
28408
28556
|
}
|
|
28409
28557
|
}
|
|
28410
|
-
if (title !== void 0)
|
|
28411
|
-
if (description !== void 0)
|
|
28412
|
-
if (state.status !== void 0)
|
|
28558
|
+
if (title !== void 0) record5.title = title;
|
|
28559
|
+
if (description !== void 0) record5.description = description;
|
|
28560
|
+
if (state.status !== void 0) record5.observed = state.status;
|
|
28413
28561
|
if (ctx.silent) return [];
|
|
28414
|
-
const linkage2 = childLinkage(childId,
|
|
28415
|
-
const turn =
|
|
28562
|
+
const linkage2 = childLinkage(childId, record5);
|
|
28563
|
+
const turn = record5.turnId === void 0 ? {} : { turnId: record5.turnId };
|
|
28416
28564
|
const events = [];
|
|
28417
|
-
if (!
|
|
28418
|
-
if (!
|
|
28419
|
-
|
|
28420
|
-
|
|
28565
|
+
if (!record5.announced && state.status === void 0) return events;
|
|
28566
|
+
if (!record5.announced) {
|
|
28567
|
+
record5.announced = true;
|
|
28568
|
+
record5.pendingMetadata = false;
|
|
28421
28569
|
events.push({
|
|
28422
28570
|
type: "task.started",
|
|
28423
28571
|
...turn,
|
|
28424
28572
|
payload: {
|
|
28425
28573
|
taskId: childId,
|
|
28426
28574
|
...linkage2,
|
|
28427
|
-
...
|
|
28575
|
+
...record5.description === void 0 ? {} : { description: record5.description }
|
|
28428
28576
|
}
|
|
28429
28577
|
});
|
|
28430
28578
|
}
|
|
28431
|
-
const statusChanged = state.status !== void 0 && (state.status !==
|
|
28579
|
+
const statusChanged = state.status !== void 0 && (state.status !== record5.reported || record5.pendingMetadata || state.error !== void 0 && state.error !== record5.reportedError);
|
|
28432
28580
|
if (statusChanged) {
|
|
28433
|
-
|
|
28434
|
-
|
|
28435
|
-
|
|
28581
|
+
record5.pendingMetadata = false;
|
|
28582
|
+
record5.reported = state.status;
|
|
28583
|
+
record5.reportedError = state.status === "failed" ? state.error ?? record5.reportedError : void 0;
|
|
28436
28584
|
events.push({
|
|
28437
28585
|
type: "task.updated",
|
|
28438
28586
|
...turn,
|
|
@@ -28440,7 +28588,7 @@ function createSubagentSessionTracker(registry2) {
|
|
|
28440
28588
|
taskId: childId,
|
|
28441
28589
|
status: state.status,
|
|
28442
28590
|
...state.error === void 0 ? {} : { error: state.error },
|
|
28443
|
-
...
|
|
28591
|
+
...record5.description === void 0 ? {} : { description: record5.description },
|
|
28444
28592
|
...linkage2
|
|
28445
28593
|
}
|
|
28446
28594
|
});
|
|
@@ -28449,20 +28597,20 @@ function createSubagentSessionTracker(registry2) {
|
|
|
28449
28597
|
};
|
|
28450
28598
|
const settleSessionEnded = () => {
|
|
28451
28599
|
const events = [];
|
|
28452
|
-
for (const [childId,
|
|
28453
|
-
const last =
|
|
28454
|
-
if (!
|
|
28455
|
-
|
|
28456
|
-
|
|
28600
|
+
for (const [childId, record5] of registry2.entries()) {
|
|
28601
|
+
const last = record5.reported ?? record5.observed;
|
|
28602
|
+
if (!record5.announced || last !== "running" && last !== "waiting") continue;
|
|
28603
|
+
record5.reported = "idle";
|
|
28604
|
+
record5.observed = "idle";
|
|
28457
28605
|
events.push({
|
|
28458
28606
|
type: "task.updated",
|
|
28459
|
-
...
|
|
28607
|
+
...record5.turnId === void 0 ? {} : { turnId: record5.turnId },
|
|
28460
28608
|
payload: {
|
|
28461
28609
|
taskId: childId,
|
|
28462
28610
|
status: "idle",
|
|
28463
28611
|
outcomeUnknown: true,
|
|
28464
|
-
...
|
|
28465
|
-
...childLinkage(childId,
|
|
28612
|
+
...record5.description === void 0 ? {} : { description: record5.description },
|
|
28613
|
+
...childLinkage(childId, record5)
|
|
28466
28614
|
}
|
|
28467
28615
|
});
|
|
28468
28616
|
}
|
|
@@ -28492,6 +28640,7 @@ function createExecutorUpdates({
|
|
|
28492
28640
|
runWithCommittedPermissionBaseline
|
|
28493
28641
|
}) {
|
|
28494
28642
|
const shownToolCallIds = /* @__PURE__ */ new Set();
|
|
28643
|
+
const suppressedNewToolCallIds = /* @__PURE__ */ new Set();
|
|
28495
28644
|
const markChildSession = shared.childSessions.mark;
|
|
28496
28645
|
const subagentSessions = options.subagentSessions === true ? createSubagentSessionTracker(shared.childSessions) : void 0;
|
|
28497
28646
|
const resolveCompactionSnapshotId = (candidate) => {
|
|
@@ -28500,9 +28649,9 @@ function createExecutorUpdates({
|
|
|
28500
28649
|
const generated = randomId()?.trim();
|
|
28501
28650
|
return generated || NodeCrypto3.randomUUID();
|
|
28502
28651
|
};
|
|
28503
|
-
const emitCompactionState = (
|
|
28504
|
-
|
|
28505
|
-
const summary =
|
|
28652
|
+
const emitCompactionState = (record5, state) => {
|
|
28653
|
+
record5.snapshotId = resolveCompactionSnapshotId(record5.snapshotId);
|
|
28654
|
+
const summary = record5.summary?.trim() ?? "";
|
|
28506
28655
|
const truncated = summary.length > COMPACTION_SUMMARY_MAX_CHARS;
|
|
28507
28656
|
emit({
|
|
28508
28657
|
type: "thread.state.changed",
|
|
@@ -28513,9 +28662,9 @@ function createExecutorUpdates({
|
|
|
28513
28662
|
payload: {
|
|
28514
28663
|
state,
|
|
28515
28664
|
compaction: {
|
|
28516
|
-
compactionId:
|
|
28517
|
-
trigger:
|
|
28518
|
-
...state === "compacted" ? { durationMs: Math.max(0, nowMs() -
|
|
28665
|
+
compactionId: record5.snapshotId,
|
|
28666
|
+
trigger: record5.trigger,
|
|
28667
|
+
...state === "compacted" ? { durationMs: Math.max(0, nowMs() - record5.startedAtMs) } : {},
|
|
28519
28668
|
...summary.length > 0 ? {
|
|
28520
28669
|
summary: truncated ? summary.slice(0, COMPACTION_SUMMARY_MAX_CHARS) : summary,
|
|
28521
28670
|
...truncated ? { summaryTruncated: true } : {}
|
|
@@ -28524,18 +28673,21 @@ function createExecutorUpdates({
|
|
|
28524
28673
|
}
|
|
28525
28674
|
});
|
|
28526
28675
|
};
|
|
28676
|
+
const settleManualCompactionWait = (record5) => {
|
|
28677
|
+
if (record5 === shared.manualCompaction) shared.manualCompactionWait?.wake();
|
|
28678
|
+
};
|
|
28527
28679
|
const applyCompactionUpdate = (event) => {
|
|
28528
28680
|
const mapKey = event.compactionId ?? ANONYMOUS_COMPACTION_KEY;
|
|
28529
|
-
let
|
|
28530
|
-
if (
|
|
28681
|
+
let record5 = compactions.get(mapKey);
|
|
28682
|
+
if (record5 === void 0) {
|
|
28531
28683
|
if (shared.manualCompaction !== void 0 && !shared.manualCompaction.adopted) {
|
|
28532
28684
|
shared.manualCompaction.adopted = true;
|
|
28533
28685
|
shared.manualCompaction.snapshotId = resolveCompactionSnapshotId(
|
|
28534
28686
|
shared.manualCompaction.snapshotId
|
|
28535
28687
|
);
|
|
28536
|
-
|
|
28688
|
+
record5 = shared.manualCompaction;
|
|
28537
28689
|
} else {
|
|
28538
|
-
|
|
28690
|
+
record5 = {
|
|
28539
28691
|
snapshotId: resolveCompactionSnapshotId(),
|
|
28540
28692
|
trigger: "automatic",
|
|
28541
28693
|
startedAtMs: nowMs(),
|
|
@@ -28545,25 +28697,26 @@ function createExecutorUpdates({
|
|
|
28545
28697
|
adopted: false
|
|
28546
28698
|
};
|
|
28547
28699
|
}
|
|
28548
|
-
compactions.set(mapKey,
|
|
28700
|
+
compactions.set(mapKey, record5);
|
|
28549
28701
|
}
|
|
28550
|
-
if (event.summary !== void 0)
|
|
28702
|
+
if (event.summary !== void 0) record5.summary = event.summary ?? void 0;
|
|
28551
28703
|
switch (event.status) {
|
|
28552
28704
|
case "in_progress":
|
|
28553
|
-
if (!
|
|
28554
|
-
|
|
28555
|
-
emitCompactionState(
|
|
28705
|
+
if (!record5.announced) {
|
|
28706
|
+
record5.announced = true;
|
|
28707
|
+
emitCompactionState(record5, "compacting");
|
|
28556
28708
|
}
|
|
28557
28709
|
return;
|
|
28558
28710
|
case "completed":
|
|
28559
|
-
|
|
28560
|
-
|
|
28711
|
+
record5.announced = true;
|
|
28712
|
+
record5.finished = true;
|
|
28561
28713
|
compactions.delete(mapKey);
|
|
28562
|
-
emitCompactionState(
|
|
28714
|
+
emitCompactionState(record5, "compacted");
|
|
28715
|
+
settleManualCompactionWait(record5);
|
|
28563
28716
|
return;
|
|
28564
28717
|
case "failed":
|
|
28565
28718
|
case "cancelled":
|
|
28566
|
-
|
|
28719
|
+
record5.finished = true;
|
|
28567
28720
|
compactions.delete(mapKey);
|
|
28568
28721
|
emit({
|
|
28569
28722
|
type: "runtime.warning",
|
|
@@ -28576,6 +28729,7 @@ function createExecutorUpdates({
|
|
|
28576
28729
|
detail: { code: `context-compaction-${event.status}` }
|
|
28577
28730
|
}
|
|
28578
28731
|
});
|
|
28732
|
+
settleManualCompactionWait(record5);
|
|
28579
28733
|
return;
|
|
28580
28734
|
default:
|
|
28581
28735
|
return;
|
|
@@ -28618,6 +28772,38 @@ function createExecutorUpdates({
|
|
|
28618
28772
|
});
|
|
28619
28773
|
}
|
|
28620
28774
|
};
|
|
28775
|
+
const askedToolCallIds = /* @__PURE__ */ new Set();
|
|
28776
|
+
const askToolQuestion = (call) => {
|
|
28777
|
+
if (hooks.toolUserInput === void 0 || askedToolCallIds.has(call.toolCallId)) return;
|
|
28778
|
+
let questions;
|
|
28779
|
+
try {
|
|
28780
|
+
questions = hooks.toolUserInput(call);
|
|
28781
|
+
} catch (error62) {
|
|
28782
|
+
if (call.status !== "completed" && call.status !== "failed") return;
|
|
28783
|
+
askedToolCallIds.add(call.toolCallId);
|
|
28784
|
+
emitHookEvents([
|
|
28785
|
+
{
|
|
28786
|
+
type: "runtime.warning",
|
|
28787
|
+
payload: {
|
|
28788
|
+
message: "The agent asked a question Ycodium could not read.",
|
|
28789
|
+
detail: error62 instanceof Error ? error62.message : String(error62)
|
|
28790
|
+
}
|
|
28791
|
+
}
|
|
28792
|
+
]);
|
|
28793
|
+
return;
|
|
28794
|
+
}
|
|
28795
|
+
if (questions === void 0 || questions.length === 0) return;
|
|
28796
|
+
askedToolCallIds.add(call.toolCallId);
|
|
28797
|
+
emit({
|
|
28798
|
+
type: "user-input.requested",
|
|
28799
|
+
...stamp(),
|
|
28800
|
+
provider: options.provider,
|
|
28801
|
+
threadId: options.threadId,
|
|
28802
|
+
...call.turnId !== void 0 ? { turnId: call.turnId } : {},
|
|
28803
|
+
requestId: `tool-question:${call.toolCallId}`,
|
|
28804
|
+
payload: { questions, responseMode: "message" }
|
|
28805
|
+
});
|
|
28806
|
+
};
|
|
28621
28807
|
const toolSubagents = hooks.toolSubagents === void 0 ? void 0 : createToolSubagentTracker(hooks.toolSubagents);
|
|
28622
28808
|
const settleToolSubagents = (settlement, turnId) => emitHookEvents(toolSubagents?.settle(settlement, turnId));
|
|
28623
28809
|
const settleSessionEnded = () => {
|
|
@@ -28704,8 +28890,9 @@ function createExecutorUpdates({
|
|
|
28704
28890
|
if (reset) {
|
|
28705
28891
|
supersedePermissionTrackedState?.(shownKey);
|
|
28706
28892
|
shownToolCallIds.delete(shownKey);
|
|
28893
|
+
suppressedNewToolCallIds.delete(shownKey);
|
|
28707
28894
|
}
|
|
28708
|
-
const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0;
|
|
28895
|
+
const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0 || hooks.toolUserInput !== void 0;
|
|
28709
28896
|
const toolName = typeof nextToolCall.data["name"] === "string" ? nextToolCall.data["name"] : void 0;
|
|
28710
28897
|
const call = !hasToolHooks ? void 0 : {
|
|
28711
28898
|
toolCallId: nextToolCall.toolCallId,
|
|
@@ -28719,6 +28906,7 @@ function createExecutorUpdates({
|
|
|
28719
28906
|
meta: params.update._meta,
|
|
28720
28907
|
turnId: shared.activeTurnId
|
|
28721
28908
|
};
|
|
28909
|
+
if (call !== void 0) askToolQuestion(call);
|
|
28722
28910
|
const hookResult = call === void 0 ? void 0 : toolSubagents?.onToolCallUpdated(call) ?? hooks.onToolCallUpdated?.(call);
|
|
28723
28911
|
const handledByHook = hookResult !== void 0 && "events" in hookResult && hookResult.handled === true;
|
|
28724
28912
|
emitHookEvents(
|
|
@@ -28727,9 +28915,17 @@ function createExecutorUpdates({
|
|
|
28727
28915
|
if (nextToolCall.status === "completed" && hookResult && "artifacts" in hookResult)
|
|
28728
28916
|
emitArtifacts(hookResult.artifacts ?? [], nextToolCall.toolCallId);
|
|
28729
28917
|
if (handledByHook || !decision.emit) {
|
|
28918
|
+
if (!handledByHook && isNewCall) {
|
|
28919
|
+
suppressedNewToolCallIds.add(shownKey);
|
|
28920
|
+
if (suppressedNewToolCallIds.size > 512) {
|
|
28921
|
+
const first = suppressedNewToolCallIds.values().next().value;
|
|
28922
|
+
if (first !== void 0) suppressedNewToolCallIds.delete(first);
|
|
28923
|
+
}
|
|
28924
|
+
}
|
|
28730
28925
|
continue;
|
|
28731
28926
|
}
|
|
28732
28927
|
const toolTurnId = (hookResult !== void 0 && "events" in hookResult ? hookResult.turnId : void 0) ?? shared.activeTurnId;
|
|
28928
|
+
const wasSuppressedStart = suppressedNewToolCallIds.delete(shownKey);
|
|
28733
28929
|
if (isNewCall || !shownToolCallIds.has(shownKey)) {
|
|
28734
28930
|
rememberShownToolCall(shownKey);
|
|
28735
28931
|
if (toolTurnId === shared.activeTurnId) closeActiveAssistantSegment(shared.activeTurnId);
|
|
@@ -28741,6 +28937,7 @@ function createExecutorUpdates({
|
|
|
28741
28937
|
threadId: options.threadId,
|
|
28742
28938
|
turnId: toolTurnId,
|
|
28743
28939
|
toolCall: nextToolCall,
|
|
28940
|
+
lifecycle: isNewCall || wasSuppressedStart ? "item.started" : "item.updated",
|
|
28744
28941
|
rawPayload: event.rawPayload
|
|
28745
28942
|
})
|
|
28746
28943
|
);
|
|
@@ -28766,9 +28963,9 @@ function createExecutorUpdates({
|
|
|
28766
28963
|
continue;
|
|
28767
28964
|
}
|
|
28768
28965
|
if (event._tag === "CompactionSummaryChunk") {
|
|
28769
|
-
const
|
|
28770
|
-
if (
|
|
28771
|
-
|
|
28966
|
+
const record5 = compactions.get(event.compactionId ?? ANONYMOUS_COMPACTION_KEY) ?? shared.manualCompaction;
|
|
28967
|
+
if (record5 !== void 0 && !record5.finished) {
|
|
28968
|
+
record5.summary = (record5.summary ?? "") + event.text;
|
|
28772
28969
|
}
|
|
28773
28970
|
continue;
|
|
28774
28971
|
}
|
|
@@ -28998,6 +29195,7 @@ function createAcpExecutor(options) {
|
|
|
28998
29195
|
promptsInFlight: 0,
|
|
28999
29196
|
pendingSettlements: /* @__PURE__ */ new Map(),
|
|
29000
29197
|
manualCompaction: void 0,
|
|
29198
|
+
manualCompactionWait: void 0,
|
|
29001
29199
|
assistantSegment: { nextSegmentIndex: 0 },
|
|
29002
29200
|
modeState: void 0,
|
|
29003
29201
|
availableCommands: [],
|
|
@@ -29031,6 +29229,7 @@ function createAcpExecutor(options) {
|
|
|
29031
29229
|
closeActiveAssistantSegment,
|
|
29032
29230
|
ensureActiveAssistantSegment,
|
|
29033
29231
|
notifyPromptSettled,
|
|
29232
|
+
wakeManualCompactionWait,
|
|
29034
29233
|
waitForPromptIdle
|
|
29035
29234
|
} = createExecutorRuntime({
|
|
29036
29235
|
randomId,
|
|
@@ -29114,6 +29313,11 @@ function createAcpExecutor(options) {
|
|
|
29114
29313
|
onNotification: (notification) => {
|
|
29115
29314
|
if (notification.method === "session/update") {
|
|
29116
29315
|
const params = notification.params;
|
|
29316
|
+
const compactionWait = shared.manualCompactionWait;
|
|
29317
|
+
if (compactionWait !== void 0 && params.sessionId === shared.sessionId && hooks.compactionCompleted?.(params) === true) {
|
|
29318
|
+
compactionWait.arrived = true;
|
|
29319
|
+
compactionWait.wake();
|
|
29320
|
+
}
|
|
29117
29321
|
const rawUpdate = params.update;
|
|
29118
29322
|
const transformed = hooks.transformSessionUpdate ? hooks.transformSessionUpdate(params) : params;
|
|
29119
29323
|
if (transformed !== void 0) receiveSessionUpdate(transformed, rawUpdate);
|
|
@@ -29145,6 +29349,7 @@ function createAcpExecutor(options) {
|
|
|
29145
29349
|
}
|
|
29146
29350
|
settleAllApprovals("cancel");
|
|
29147
29351
|
settleAllUserInputs();
|
|
29352
|
+
wakeManualCompactionWait();
|
|
29148
29353
|
abortPendingSettlement(
|
|
29149
29354
|
"connection closed",
|
|
29150
29355
|
acpClosedConnectionCategory(
|
|
@@ -29165,6 +29370,7 @@ function createAcpExecutor(options) {
|
|
|
29165
29370
|
}
|
|
29166
29371
|
settleAllApprovals("cancel");
|
|
29167
29372
|
settleAllUserInputs();
|
|
29373
|
+
wakeManualCompactionWait();
|
|
29168
29374
|
shared.promptWaiters.splice(0).forEach((wake) => wake());
|
|
29169
29375
|
};
|
|
29170
29376
|
options.readable.once("end", onInputDead);
|
|
@@ -29231,6 +29437,7 @@ function createAcpExecutor(options) {
|
|
|
29231
29437
|
emit,
|
|
29232
29438
|
stamp,
|
|
29233
29439
|
options,
|
|
29440
|
+
hooks,
|
|
29234
29441
|
promptMutex,
|
|
29235
29442
|
randomId,
|
|
29236
29443
|
nowMs,
|
|
@@ -29238,6 +29445,7 @@ function createAcpExecutor(options) {
|
|
|
29238
29445
|
sendPromptRpc,
|
|
29239
29446
|
compactions,
|
|
29240
29447
|
notifyPromptSettled,
|
|
29448
|
+
wakeManualCompactionWait,
|
|
29241
29449
|
eventStream,
|
|
29242
29450
|
onInputDead,
|
|
29243
29451
|
shared
|
|
@@ -29259,6 +29467,9 @@ function createAcpExecutor(options) {
|
|
|
29259
29467
|
get status() {
|
|
29260
29468
|
return shared.status;
|
|
29261
29469
|
},
|
|
29470
|
+
get acceptsInlineImages() {
|
|
29471
|
+
return acpAcceptsInlineImages(shared.initializeResult);
|
|
29472
|
+
},
|
|
29262
29473
|
events: eventStream.subscribe(),
|
|
29263
29474
|
start,
|
|
29264
29475
|
prompt,
|
|
@@ -29418,46 +29629,73 @@ var yieldTick = () => new Promise((resolve2) => {
|
|
|
29418
29629
|
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
29419
29630
|
function createAcpThreadOperations(options) {
|
|
29420
29631
|
const { threads, requireThread } = options;
|
|
29632
|
+
const pendingSends = /* @__PURE__ */ new Map();
|
|
29421
29633
|
return {
|
|
29422
29634
|
sendTurn: async (input2, signal) => {
|
|
29423
29635
|
if (options.isDisposed()) throw new Error("instance disposed");
|
|
29424
29636
|
const booked = requireThread(input2.threadId);
|
|
29425
29637
|
if (signal?.aborted) throw new Error("aborted");
|
|
29426
29638
|
options.beforeSendTurn?.(booked);
|
|
29427
|
-
const
|
|
29428
|
-
|
|
29429
|
-
|
|
29430
|
-
|
|
29639
|
+
const pending = { cancelled: false };
|
|
29640
|
+
const waiting = pendingSends.get(input2.threadId) ?? /* @__PURE__ */ new Set();
|
|
29641
|
+
waiting.add(pending);
|
|
29642
|
+
pendingSends.set(input2.threadId, waiting);
|
|
29431
29643
|
try {
|
|
29432
|
-
const
|
|
29433
|
-
const
|
|
29434
|
-
|
|
29435
|
-
|
|
29436
|
-
|
|
29437
|
-
|
|
29438
|
-
|
|
29439
|
-
|
|
29440
|
-
|
|
29441
|
-
|
|
29442
|
-
|
|
29443
|
-
|
|
29644
|
+
const acceptsImages = booked.executor.acceptsInlineImages;
|
|
29645
|
+
const images = acceptsImages ? await acpPromptImagesFromAttachments({
|
|
29646
|
+
attachments: input2.attachments,
|
|
29647
|
+
readAttachment: options.readAttachment
|
|
29648
|
+
}) : [];
|
|
29649
|
+
if (!acceptsImages) {
|
|
29650
|
+
const droppedImages = acpImageAttachmentCount(input2.attachments);
|
|
29651
|
+
if (droppedImages > 0) {
|
|
29652
|
+
options.log.info(
|
|
29653
|
+
"acp agent does not accept image content; sending their path lines only",
|
|
29654
|
+
{ threadId: input2.threadId, droppedImages }
|
|
29655
|
+
);
|
|
29656
|
+
}
|
|
29657
|
+
}
|
|
29658
|
+
if (signal?.aborted || pending.cancelled) throw new Error("aborted");
|
|
29659
|
+
const onAbort = () => {
|
|
29660
|
+
void booked.executor.cancel(input2.expectedTurnId).catch(() => void 0);
|
|
29444
29661
|
};
|
|
29662
|
+
signal?.addEventListener("abort", onAbort);
|
|
29663
|
+
try {
|
|
29664
|
+
const { requestedModelId, requestedEffort } = options.turnSelection?.(input2.modelSelection) ?? {};
|
|
29665
|
+
const turn = await dispatchAcpPrompt(booked.executor, {
|
|
29666
|
+
text: input2.input ?? "",
|
|
29667
|
+
...images.length === 0 ? {} : { images },
|
|
29668
|
+
expectedActiveTurnId: input2.expectedTurnId,
|
|
29669
|
+
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
29670
|
+
...requestedEffort === void 0 ? {} : { requestedEffort }
|
|
29671
|
+
});
|
|
29672
|
+
booked.turns.push({ id: turn.turnId, items: [] });
|
|
29673
|
+
return {
|
|
29674
|
+
threadId: input2.threadId,
|
|
29675
|
+
turnId: turn.turnId,
|
|
29676
|
+
...booked.session.resumeCursor === void 0 ? {} : { resumeCursor: booked.session.resumeCursor }
|
|
29677
|
+
};
|
|
29678
|
+
} finally {
|
|
29679
|
+
signal?.removeEventListener("abort", onAbort);
|
|
29680
|
+
}
|
|
29445
29681
|
} finally {
|
|
29446
|
-
|
|
29682
|
+
waiting.delete(pending);
|
|
29683
|
+
if (waiting.size === 0) pendingSends.delete(input2.threadId);
|
|
29447
29684
|
}
|
|
29448
29685
|
},
|
|
29449
29686
|
interruptTurn: async (threadId, turnId) => {
|
|
29687
|
+
for (const pending of pendingSends.get(threadId) ?? []) pending.cancelled = true;
|
|
29450
29688
|
const booked = threads.get(threadId);
|
|
29451
29689
|
if (booked === void 0 || booked.closing) return;
|
|
29452
29690
|
options.log.info("interrupt turn", { threadId, turnId });
|
|
29453
29691
|
await booked.executor.cancel(turnId);
|
|
29454
29692
|
await yieldTick();
|
|
29455
29693
|
},
|
|
29456
|
-
respondToRequest: async (threadId, requestId, decision, reason) => {
|
|
29694
|
+
respondToRequest: async (threadId, requestId, decision, reason, detailedDecision) => {
|
|
29457
29695
|
const booked = requireThread(threadId);
|
|
29458
29696
|
await booked.executor.respondToRequest(
|
|
29459
29697
|
requestId,
|
|
29460
|
-
decision === "allow" ? "accept" : "decline",
|
|
29698
|
+
detailedDecision ?? (decision === "allow" ? "accept" : "decline"),
|
|
29461
29699
|
reason
|
|
29462
29700
|
);
|
|
29463
29701
|
},
|
|
@@ -29997,9 +30235,9 @@ var GROK_ISSUER_PREFIX = "https://auth.x.ai::";
|
|
|
29997
30235
|
var AUTH_FILE_NAME2 = "auth.json";
|
|
29998
30236
|
var QUOTA_TIMEOUT_MS = 1e4;
|
|
29999
30237
|
var extractGrokToken = (auth) => {
|
|
30000
|
-
const
|
|
30001
|
-
if (
|
|
30002
|
-
for (const [key, value] of Object.entries(
|
|
30238
|
+
const record5 = asObject(auth);
|
|
30239
|
+
if (record5 === null) return null;
|
|
30240
|
+
for (const [key, value] of Object.entries(record5)) {
|
|
30003
30241
|
if (!key.startsWith(GROK_ISSUER_PREFIX)) continue;
|
|
30004
30242
|
const nestedKey = asString3(asObject(value)?.["key"]);
|
|
30005
30243
|
if (nestedKey !== null) return nestedKey;
|
|
@@ -30067,13 +30305,23 @@ var createGrokUsage = (input2) => {
|
|
|
30067
30305
|
return { readQuota };
|
|
30068
30306
|
};
|
|
30069
30307
|
|
|
30308
|
+
// src/grokTurnUsage.ts
|
|
30309
|
+
import * as NodeCrypto5 from "node:crypto";
|
|
30310
|
+
|
|
30311
|
+
// src/grokJson.ts
|
|
30312
|
+
var isRecord9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30313
|
+
var trimmed = (value) => {
|
|
30314
|
+
if (typeof value !== "string") return void 0;
|
|
30315
|
+
const text4 = value.trim();
|
|
30316
|
+
return text4.length > 0 ? text4 : void 0;
|
|
30317
|
+
};
|
|
30318
|
+
|
|
30070
30319
|
// src/grokTurnUsage.ts
|
|
30071
30320
|
var USAGE_GRACE_MS = 300;
|
|
30072
|
-
var
|
|
30321
|
+
var PAST_KEY_LIMIT = 16;
|
|
30073
30322
|
var count = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0;
|
|
30074
|
-
var text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
30075
30323
|
var readModelTotals = (entry) => {
|
|
30076
|
-
if (!
|
|
30324
|
+
if (!isRecord9(entry)) return void 0;
|
|
30077
30325
|
const input2 = count(entry["inputTokens"]);
|
|
30078
30326
|
const cachedInputTokens = count(entry["cachedReadTokens"]);
|
|
30079
30327
|
const cacheCreationTokens = count(entry["cacheCreationTokens"]);
|
|
@@ -30087,25 +30335,19 @@ var readModelTotals = (entry) => {
|
|
|
30087
30335
|
};
|
|
30088
30336
|
};
|
|
30089
30337
|
var sumOf = (totals) => totals.uncachedInputTokens + totals.cachedInputTokens + totals.cacheCreationTokens + totals.outputTokens;
|
|
30090
|
-
var
|
|
30091
|
-
const meta3 = isRecord8(promptResponse) ? promptResponse["_meta"] : void 0;
|
|
30092
|
-
const usage = isRecord8(meta3) ? meta3["usage"] : void 0;
|
|
30093
|
-
if (!isRecord8(meta3) || !isRecord8(usage)) return void 0;
|
|
30338
|
+
var grokTurnUsageFromUsageRecord = (usage) => {
|
|
30094
30339
|
const perModel = /* @__PURE__ */ new Map();
|
|
30095
30340
|
const modelUsage = usage["modelUsage"];
|
|
30096
|
-
if (
|
|
30341
|
+
if (isRecord9(modelUsage)) {
|
|
30097
30342
|
for (const [model, entry] of Object.entries(modelUsage)) {
|
|
30098
30343
|
const totals = readModelTotals(entry);
|
|
30099
30344
|
if (totals !== void 0 && model.trim().length > 0) perModel.set(model.trim(), totals);
|
|
30100
30345
|
}
|
|
30101
30346
|
}
|
|
30102
30347
|
if (perModel.size === 0) {
|
|
30103
|
-
const fallbackModel = text(meta3["modelId"]);
|
|
30104
30348
|
const totals = readModelTotals(usage);
|
|
30105
|
-
|
|
30106
|
-
perModel.set(fallbackModel, totals);
|
|
30349
|
+
return totals !== void 0 && sumOf(totals) > 0 ? totals : void 0;
|
|
30107
30350
|
}
|
|
30108
|
-
let dominant;
|
|
30109
30351
|
const sum = {
|
|
30110
30352
|
uncachedInputTokens: 0,
|
|
30111
30353
|
cachedInputTokens: 0,
|
|
@@ -30113,56 +30355,129 @@ var grokTurnUsageReport = (promptResponse) => {
|
|
|
30113
30355
|
outputTokens: 0,
|
|
30114
30356
|
reasoningTokens: 0
|
|
30115
30357
|
};
|
|
30116
|
-
for (const
|
|
30358
|
+
for (const totals of perModel.values()) {
|
|
30117
30359
|
sum.uncachedInputTokens += totals.uncachedInputTokens;
|
|
30118
30360
|
sum.cachedInputTokens += totals.cachedInputTokens;
|
|
30119
30361
|
sum.cacheCreationTokens += totals.cacheCreationTokens;
|
|
30120
30362
|
sum.outputTokens += totals.outputTokens;
|
|
30121
30363
|
sum.reasoningTokens += totals.reasoningTokens;
|
|
30122
|
-
const size = sumOf(totals);
|
|
30123
|
-
if (dominant === void 0 || size > dominant.size) dominant = { model, size };
|
|
30124
30364
|
}
|
|
30125
|
-
|
|
30126
|
-
|
|
30365
|
+
return sumOf(sum) > 0 ? sum : void 0;
|
|
30366
|
+
};
|
|
30367
|
+
var grokPromptUsageTotals = (promptResponse) => {
|
|
30368
|
+
const meta3 = isRecord9(promptResponse) ? promptResponse["_meta"] : void 0;
|
|
30369
|
+
const usage = isRecord9(meta3) ? meta3["usage"] : void 0;
|
|
30370
|
+
if (!isRecord9(usage)) return void 0;
|
|
30371
|
+
return grokTurnUsageFromUsageRecord(usage);
|
|
30372
|
+
};
|
|
30373
|
+
var grokTurnCompletedNotificationUsage = (envelope, expectedSessionId) => {
|
|
30374
|
+
if (!isRecord9(envelope) || !isRecord9(envelope["update"])) return void 0;
|
|
30375
|
+
const envelopeSessionId = trimmed(envelope["sessionId"]);
|
|
30376
|
+
if (expectedSessionId !== void 0 && envelopeSessionId !== expectedSessionId) return void 0;
|
|
30377
|
+
const meta3 = isRecord9(envelope["_meta"]) ? envelope["_meta"] : void 0;
|
|
30378
|
+
if (meta3?.["isReplay"] === true) return void 0;
|
|
30379
|
+
const update = envelope["update"];
|
|
30380
|
+
if (update["sessionUpdate"] !== "turn_completed" || !isRecord9(update["usage"])) {
|
|
30381
|
+
return void 0;
|
|
30382
|
+
}
|
|
30383
|
+
const totals = grokTurnUsageFromUsageRecord(update["usage"]);
|
|
30384
|
+
if (totals === void 0) return void 0;
|
|
30127
30385
|
return {
|
|
30128
|
-
|
|
30129
|
-
|
|
30130
|
-
totals: sum,
|
|
30131
|
-
...sessionId === void 0 ? {} : { sessionId }
|
|
30386
|
+
promptKey: trimmed(update["prompt_id"]) ?? trimmed(update["promptId"]),
|
|
30387
|
+
totals
|
|
30132
30388
|
};
|
|
30133
30389
|
};
|
|
30134
|
-
var
|
|
30135
|
-
if (
|
|
30136
|
-
const
|
|
30137
|
-
|
|
30138
|
-
|
|
30139
|
-
|
|
30140
|
-
|
|
30141
|
-
|
|
30142
|
-
};
|
|
30143
|
-
const larger = sumOf(left.totals) >= sumOf(right.totals) ? left : right;
|
|
30144
|
-
return { ...larger, totals };
|
|
30390
|
+
var readEventContextWindow = (event) => {
|
|
30391
|
+
if (event.type !== "thread.token-usage.updated" || !isRecord9(event.payload)) return void 0;
|
|
30392
|
+
const usage = event.payload["usage"];
|
|
30393
|
+
if (!isRecord9(usage)) return void 0;
|
|
30394
|
+
const usedTokens = count(usage["usedTokens"]);
|
|
30395
|
+
if (usedTokens === 0) return void 0;
|
|
30396
|
+
const maxTokens = count(usage["maxTokens"]);
|
|
30397
|
+
return maxTokens > 0 ? { usedTokens, maxTokens } : { usedTokens };
|
|
30145
30398
|
};
|
|
30146
|
-
var
|
|
30399
|
+
var makeUsageEvent = (turnCompleted, usage) => ({
|
|
30400
|
+
type: "thread.token-usage.updated",
|
|
30401
|
+
eventId: NodeCrypto5.randomUUID(),
|
|
30402
|
+
provider: turnCompleted.provider,
|
|
30403
|
+
...turnCompleted.providerInstanceId === void 0 ? {} : { providerInstanceId: turnCompleted.providerInstanceId },
|
|
30404
|
+
threadId: turnCompleted.threadId,
|
|
30405
|
+
createdAt: turnCompleted.createdAt,
|
|
30406
|
+
...turnCompleted.turnId === void 0 ? {} : { turnId: turnCompleted.turnId },
|
|
30407
|
+
payload: { usage }
|
|
30408
|
+
});
|
|
30409
|
+
var createGrokTurnUsageCollector = (base, readContextWindow) => {
|
|
30147
30410
|
const pastKeys = [];
|
|
30148
30411
|
const turn = /* @__PURE__ */ new Map();
|
|
30149
30412
|
const answered = /* @__PURE__ */ new Set();
|
|
30150
|
-
|
|
30413
|
+
const nonTurnClaims = /* @__PURE__ */ new Set();
|
|
30414
|
+
let unattributed = false;
|
|
30415
|
+
let latestContextWindow;
|
|
30151
30416
|
let wake;
|
|
30417
|
+
const rememberPastKey = (key) => {
|
|
30418
|
+
if (pastKeys.includes(key)) return;
|
|
30419
|
+
pastKeys.push(key);
|
|
30420
|
+
while (pastKeys.length > PAST_KEY_LIMIT) pastKeys.shift();
|
|
30421
|
+
};
|
|
30152
30422
|
const allAnswered = () => [...turn.keys()].every((key) => answered.has(key));
|
|
30423
|
+
const resolveTurnKey = (explicitKey) => {
|
|
30424
|
+
if (turn.size === 0) return { kind: "drop" };
|
|
30425
|
+
if (explicitKey !== void 0) {
|
|
30426
|
+
if (!turn.has(explicitKey) && pastKeys.includes(explicitKey)) return { kind: "drop" };
|
|
30427
|
+
return { kind: "key", key: explicitKey };
|
|
30428
|
+
}
|
|
30429
|
+
let unique;
|
|
30430
|
+
for (const key of turn.keys()) {
|
|
30431
|
+
if (answered.has(key)) continue;
|
|
30432
|
+
if (unique !== void 0) return { kind: "ambiguous" };
|
|
30433
|
+
unique = key;
|
|
30434
|
+
}
|
|
30435
|
+
return unique === void 0 ? { kind: "ambiguous" } : { kind: "key", key: unique };
|
|
30436
|
+
};
|
|
30153
30437
|
const observe = (response) => {
|
|
30154
|
-
const
|
|
30155
|
-
if (
|
|
30156
|
-
|
|
30157
|
-
|
|
30158
|
-
|
|
30438
|
+
const resolved = resolveTurnKey(base.responseKey?.(response));
|
|
30439
|
+
if (resolved.kind === "drop") return;
|
|
30440
|
+
const totals = grokPromptUsageTotals(response);
|
|
30441
|
+
const contextWindow = readContextWindow(response);
|
|
30442
|
+
if (contextWindow !== void 0) latestContextWindow = contextWindow;
|
|
30443
|
+
if (resolved.kind === "ambiguous") {
|
|
30444
|
+
if (totals !== void 0) unattributed = true;
|
|
30445
|
+
return;
|
|
30446
|
+
}
|
|
30447
|
+
const previous = turn.get(resolved.key);
|
|
30448
|
+
turn.set(resolved.key, {
|
|
30449
|
+
totals: totals ?? previous?.totals,
|
|
30450
|
+
contextWindow: contextWindow ?? previous?.contextWindow
|
|
30451
|
+
});
|
|
30452
|
+
answered.add(resolved.key);
|
|
30159
30453
|
if (allAnswered()) wake?.();
|
|
30160
30454
|
};
|
|
30455
|
+
const observeEnvelope = (envelope, expectedSessionId) => {
|
|
30456
|
+
if (expectedSessionId === void 0) return;
|
|
30457
|
+
const parsed = grokTurnCompletedNotificationUsage(envelope, expectedSessionId);
|
|
30458
|
+
if (parsed === void 0) return;
|
|
30459
|
+
const resolved = resolveTurnKey(parsed.promptKey);
|
|
30460
|
+
if (resolved.kind === "drop") return;
|
|
30461
|
+
if (resolved.kind === "ambiguous") {
|
|
30462
|
+
unattributed = true;
|
|
30463
|
+
return;
|
|
30464
|
+
}
|
|
30465
|
+
const previous = turn.get(resolved.key);
|
|
30466
|
+
turn.set(resolved.key, {
|
|
30467
|
+
totals: previous?.totals ?? parsed.totals,
|
|
30468
|
+
contextWindow: previous?.contextWindow
|
|
30469
|
+
});
|
|
30470
|
+
};
|
|
30161
30471
|
const settlement = {
|
|
30162
30472
|
...base,
|
|
30163
30473
|
requestFields: (key) => {
|
|
30164
|
-
|
|
30165
|
-
|
|
30474
|
+
const claim2 = nonTurnClaims.values().next().value;
|
|
30475
|
+
if (claim2 !== void 0) {
|
|
30476
|
+
nonTurnClaims.delete(claim2);
|
|
30477
|
+
rememberPastKey(key);
|
|
30478
|
+
} else {
|
|
30479
|
+
turn.set(key, {});
|
|
30480
|
+
}
|
|
30166
30481
|
return base.requestFields(key);
|
|
30167
30482
|
},
|
|
30168
30483
|
responseKey: (response) => {
|
|
@@ -30170,8 +30485,22 @@ var createGrokTurnUsageCollector = (base) => {
|
|
|
30170
30485
|
return base.responseKey?.(response);
|
|
30171
30486
|
}
|
|
30172
30487
|
};
|
|
30488
|
+
const runNonTurnPrompt = async (run) => {
|
|
30489
|
+
const claim2 = /* @__PURE__ */ Symbol();
|
|
30490
|
+
nonTurnClaims.add(claim2);
|
|
30491
|
+
try {
|
|
30492
|
+
return await run();
|
|
30493
|
+
} finally {
|
|
30494
|
+
nonTurnClaims.delete(claim2);
|
|
30495
|
+
}
|
|
30496
|
+
};
|
|
30173
30497
|
const attach = async (event) => {
|
|
30174
|
-
if (event.type
|
|
30498
|
+
if (event.type === "thread.token-usage.updated") {
|
|
30499
|
+
const contextWindow = readEventContextWindow(event);
|
|
30500
|
+
if (contextWindow !== void 0) latestContextWindow = contextWindow;
|
|
30501
|
+
return [event];
|
|
30502
|
+
}
|
|
30503
|
+
if (event.type !== "turn.completed" || !isRecord9(event.payload)) return [event];
|
|
30175
30504
|
if (event.payload["state"] === "completed" && !allAnswered()) {
|
|
30176
30505
|
await new Promise((resolve2) => {
|
|
30177
30506
|
const timer = setTimeout(resolve2, USAGE_GRACE_MS);
|
|
@@ -30182,15 +30511,40 @@ var createGrokTurnUsageCollector = (base) => {
|
|
|
30182
30511
|
});
|
|
30183
30512
|
wake = void 0;
|
|
30184
30513
|
}
|
|
30185
|
-
|
|
30186
|
-
|
|
30187
|
-
for (const
|
|
30188
|
-
|
|
30514
|
+
const usageEvents = [];
|
|
30515
|
+
let carriedWindow;
|
|
30516
|
+
for (const [promptKey, entry] of turn) {
|
|
30517
|
+
if (entry.contextWindow !== void 0) carriedWindow = entry.contextWindow;
|
|
30518
|
+
if (entry.totals === void 0) continue;
|
|
30519
|
+
const contextWindow = entry.contextWindow ?? carriedWindow ?? latestContextWindow;
|
|
30520
|
+
if (contextWindow === void 0) continue;
|
|
30521
|
+
usageEvents.push(
|
|
30522
|
+
makeUsageEvent(event, {
|
|
30523
|
+
usedTokens: contextWindow.usedTokens,
|
|
30524
|
+
...contextWindow.maxTokens === void 0 ? {} : { maxTokens: contextWindow.maxTokens },
|
|
30525
|
+
request: {
|
|
30526
|
+
id: promptKey,
|
|
30527
|
+
totals: entry.totals
|
|
30528
|
+
}
|
|
30529
|
+
})
|
|
30530
|
+
);
|
|
30531
|
+
}
|
|
30532
|
+
if (unattributed && latestContextWindow !== void 0) {
|
|
30533
|
+
usageEvents.push(
|
|
30534
|
+
makeUsageEvent(event, {
|
|
30535
|
+
usedTokens: latestContextWindow.usedTokens,
|
|
30536
|
+
...latestContextWindow.maxTokens === void 0 ? {} : { maxTokens: latestContextWindow.maxTokens },
|
|
30537
|
+
lastUsedTokens: latestContextWindow.usedTokens
|
|
30538
|
+
})
|
|
30539
|
+
);
|
|
30540
|
+
}
|
|
30541
|
+
for (const key of turn.keys()) rememberPastKey(key);
|
|
30189
30542
|
turn.clear();
|
|
30190
30543
|
answered.clear();
|
|
30191
|
-
|
|
30544
|
+
unattributed = false;
|
|
30545
|
+
return [...usageEvents, event];
|
|
30192
30546
|
};
|
|
30193
|
-
return { settlement, attach };
|
|
30547
|
+
return { settlement, observeEnvelope, attach, runNonTurnPrompt };
|
|
30194
30548
|
};
|
|
30195
30549
|
|
|
30196
30550
|
// src/grokPlanGate.ts
|
|
@@ -30201,19 +30555,19 @@ var XAI_EXIT_PLAN_MODE_METHODS = [
|
|
|
30201
30555
|
var GROK_PLAN_APPROVE_OPTION_ID = "approved";
|
|
30202
30556
|
var GROK_PLAN_ABANDON_OPTION_ID = "abandoned";
|
|
30203
30557
|
var GROK_EMPTY_PLAN_TEXT = "The agent exited plan mode without writing a plan.";
|
|
30204
|
-
var
|
|
30205
|
-
var
|
|
30558
|
+
var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30559
|
+
var trimmed2 = (value) => {
|
|
30206
30560
|
if (typeof value !== "string") return void 0;
|
|
30207
30561
|
const text4 = value.trim();
|
|
30208
30562
|
return text4.length > 0 ? text4 : void 0;
|
|
30209
30563
|
};
|
|
30210
30564
|
function parseXAiExitPlanModeParams(params) {
|
|
30211
|
-
const candidates = [params, ...
|
|
30565
|
+
const candidates = [params, ...isRecord10(params) ? [params["params"]] : []];
|
|
30212
30566
|
for (const candidate of candidates) {
|
|
30213
|
-
if (!
|
|
30214
|
-
const toolCallId =
|
|
30567
|
+
if (!isRecord10(candidate)) continue;
|
|
30568
|
+
const toolCallId = trimmed2(candidate["toolCallId"]);
|
|
30215
30569
|
if (toolCallId === void 0) continue;
|
|
30216
|
-
return { toolCallId, planContent:
|
|
30570
|
+
return { toolCallId, planContent: trimmed2(candidate["planContent"]) };
|
|
30217
30571
|
}
|
|
30218
30572
|
return void 0;
|
|
30219
30573
|
}
|
|
@@ -30251,7 +30605,7 @@ function makeXAiExitPlanModeResponse(params, resolution) {
|
|
|
30251
30605
|
if (resolution.kind === "cancelled") return abandoned();
|
|
30252
30606
|
const answer = resolution.answers[params.toolCallId];
|
|
30253
30607
|
const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
|
|
30254
|
-
const text4 =
|
|
30608
|
+
const text4 = trimmed2(selected);
|
|
30255
30609
|
if (text4 === void 0) return abandoned();
|
|
30256
30610
|
if (text4 === GROK_PLAN_APPROVE_OPTION_ID) return { outcome: "approved" };
|
|
30257
30611
|
if (text4 === GROK_PLAN_ABANDON_OPTION_ID) return abandoned();
|
|
@@ -30260,31 +30614,21 @@ function makeXAiExitPlanModeResponse(params, resolution) {
|
|
|
30260
30614
|
|
|
30261
30615
|
// src/grokReasoningEffort.ts
|
|
30262
30616
|
import { REASONING_OPTION_LABEL, reasoningEffortShortLabel } from "@ycodium-ai/plugin-api/executor";
|
|
30263
|
-
|
|
30264
|
-
// src/grokJson.ts
|
|
30265
|
-
var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30266
|
-
var trimmed2 = (value) => {
|
|
30267
|
-
if (typeof value !== "string") return void 0;
|
|
30268
|
-
const text4 = value.trim();
|
|
30269
|
-
return text4.length > 0 ? text4 : void 0;
|
|
30270
|
-
};
|
|
30271
|
-
|
|
30272
|
-
// src/grokReasoningEffort.ts
|
|
30273
30617
|
var GROK_REASONING_OPTION_ID = "reasoningEffort";
|
|
30274
30618
|
function grokReasoningEffortDescriptor(modelMeta) {
|
|
30275
|
-
if (!
|
|
30619
|
+
if (!isRecord9(modelMeta) || modelMeta["supportsReasoningEffort"] !== true) return void 0;
|
|
30276
30620
|
const table = modelMeta["reasoningEfforts"];
|
|
30277
30621
|
if (!Array.isArray(table)) return void 0;
|
|
30278
30622
|
const options = table.flatMap((entry) => {
|
|
30279
|
-
if (!
|
|
30280
|
-
const value =
|
|
30623
|
+
if (!isRecord9(entry)) return [];
|
|
30624
|
+
const value = trimmed(entry["value"]) ?? trimmed(entry["id"]);
|
|
30281
30625
|
if (value === void 0) return [];
|
|
30282
|
-
const description =
|
|
30626
|
+
const description = trimmed(entry["description"]);
|
|
30283
30627
|
return [
|
|
30284
30628
|
{
|
|
30285
30629
|
id: value,
|
|
30286
30630
|
// CLI 自带的标签是「High Effort」这种,放在档位那一格里重复;认不出的档才用它。
|
|
30287
|
-
label: reasoningEffortShortLabel(value) ??
|
|
30631
|
+
label: reasoningEffortShortLabel(value) ?? trimmed(entry["label"]) ?? value,
|
|
30288
30632
|
...description === void 0 ? {} : { description },
|
|
30289
30633
|
...entry["default"] === true ? { isDefault: true } : {}
|
|
30290
30634
|
}
|
|
@@ -30301,23 +30645,23 @@ function grokReasoningEffortDescriptor(modelMeta) {
|
|
|
30301
30645
|
};
|
|
30302
30646
|
}
|
|
30303
30647
|
function grokReasoningEffortKnown(modelMeta) {
|
|
30304
|
-
if (!
|
|
30648
|
+
if (!isRecord9(modelMeta)) return "unknown";
|
|
30305
30649
|
if (modelMeta["supportsReasoningEffort"] === false) return "none";
|
|
30306
30650
|
if (modelMeta["supportsReasoningEffort"] !== true) return "unknown";
|
|
30307
30651
|
const table = modelMeta["reasoningEfforts"];
|
|
30308
30652
|
if (!Array.isArray(table)) return "unknown";
|
|
30309
30653
|
const readable = table.every(
|
|
30310
|
-
(entry) =>
|
|
30654
|
+
(entry) => isRecord9(entry) && (trimmed(entry["value"]) ?? trimmed(entry["id"])) !== void 0
|
|
30311
30655
|
);
|
|
30312
30656
|
if (!readable) return "unknown";
|
|
30313
30657
|
return table.length === 0 ? "none" : "listed";
|
|
30314
30658
|
}
|
|
30315
30659
|
function grokModelDefaultEffort(input2) {
|
|
30316
|
-
const models =
|
|
30317
|
-
const available =
|
|
30660
|
+
const models = isRecord9(input2.setup) ? input2.setup["models"] : void 0;
|
|
30661
|
+
const available = isRecord9(models) ? models["availableModels"] : void 0;
|
|
30318
30662
|
if (!Array.isArray(available)) return void 0;
|
|
30319
|
-
const model = available.find((entry) =>
|
|
30320
|
-
const current =
|
|
30663
|
+
const model = available.find((entry) => isRecord9(entry) && entry["modelId"] === input2.modelId);
|
|
30664
|
+
const current = isRecord9(model) ? grokReasoningEffortDescriptor(model["_meta"])?.currentValue : void 0;
|
|
30321
30665
|
return typeof current === "string" ? current : void 0;
|
|
30322
30666
|
}
|
|
30323
30667
|
function grokReasoningEffortArgs(effort) {
|
|
@@ -30327,14 +30671,14 @@ function grokReasoningEffortArgs(effort) {
|
|
|
30327
30671
|
|
|
30328
30672
|
// src/grokBackgroundTasks.ts
|
|
30329
30673
|
var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
30330
|
-
var
|
|
30674
|
+
var text = (value) => typeof value === "string" ? value.trim() || void 0 : void 0;
|
|
30331
30675
|
var isSubagentCommand = (command) => command !== void 0 && /^\[subagent[:\]]/.test(command);
|
|
30332
30676
|
var taskResults = (output2) => {
|
|
30333
30677
|
const results = record2(output2["MultiResult"])["results"];
|
|
30334
30678
|
return (Array.isArray(results) ? results : [output2["Result"]]).map(record2);
|
|
30335
30679
|
};
|
|
30336
30680
|
var lifecycle = (status, exitCode) => {
|
|
30337
|
-
switch (
|
|
30681
|
+
switch (text(status)?.toLowerCase()) {
|
|
30338
30682
|
case "pending":
|
|
30339
30683
|
case "running":
|
|
30340
30684
|
return "running";
|
|
@@ -30388,17 +30732,32 @@ function buildGrokBackgroundTaskEvents(input2) {
|
|
|
30388
30732
|
});
|
|
30389
30733
|
};
|
|
30390
30734
|
if (output2["type"] === "Monitor" && toolCallStatus === "completed") {
|
|
30391
|
-
const id =
|
|
30735
|
+
const id = text(output2["taskId"]);
|
|
30392
30736
|
if (id) {
|
|
30393
|
-
start(id, "monitor",
|
|
30737
|
+
start(id, "monitor", text(record2(input2.rawInput)["description"]) ?? "Monitor", toolCallId);
|
|
30394
30738
|
}
|
|
30395
30739
|
} else if (output2["type"] === "BackgroundTaskStarted") {
|
|
30396
|
-
const id =
|
|
30397
|
-
const command =
|
|
30740
|
+
const id = text(output2["task_id"]) ?? text(output2["taskId"]);
|
|
30741
|
+
const command = text(output2["command"]);
|
|
30398
30742
|
if (id && command) start(id, "shell", command.split("\n")[0].slice(0, 200), toolCallId);
|
|
30743
|
+
} else if (output2["type"] === "SchedulerCreate" && toolCallStatus === "completed") {
|
|
30744
|
+
const id = text(output2["id"]);
|
|
30745
|
+
const args = record2(input2.rawInput);
|
|
30746
|
+
if (id && args["recurring"] !== false && args["durable"] !== true) {
|
|
30747
|
+
start(
|
|
30748
|
+
id,
|
|
30749
|
+
"monitor",
|
|
30750
|
+
text(output2["humanSchedule"]) ?? text(args["prompt"]) ?? "Scheduled task",
|
|
30751
|
+
toolCallId
|
|
30752
|
+
);
|
|
30753
|
+
}
|
|
30754
|
+
} else if (output2["type"] === "SchedulerDelete" && toolCallStatus === "completed" && output2["success"] === true) {
|
|
30755
|
+
const id = text(record2(input2.rawInput)["task_id"]);
|
|
30756
|
+
const task = id === void 0 ? void 0 : tasks.get(id);
|
|
30757
|
+
if (task) complete(task, "stopped");
|
|
30399
30758
|
} else if (output2["type"] === "TaskOutput" || output2["type"] === "KillTask") {
|
|
30400
30759
|
for (const result of taskResults(output2)) {
|
|
30401
|
-
const id =
|
|
30760
|
+
const id = text(result["task_id"]);
|
|
30402
30761
|
if (!id) continue;
|
|
30403
30762
|
if (output2["type"] === "KillTask") {
|
|
30404
30763
|
const task2 = tasks.get(id);
|
|
@@ -30407,11 +30766,11 @@ function buildGrokBackgroundTaskEvents(input2) {
|
|
|
30407
30766
|
}
|
|
30408
30767
|
continue;
|
|
30409
30768
|
}
|
|
30410
|
-
const command =
|
|
30769
|
+
const command = text(result["command"]);
|
|
30411
30770
|
const status = lifecycle(result["status"], result["exit_code"]);
|
|
30412
30771
|
if (!command || !status || isSubagentCommand(command)) continue;
|
|
30413
30772
|
const task = start(id, /^\[monitor[:\]]/.test(command) ? "monitor" : "shell", command);
|
|
30414
|
-
const summary =
|
|
30773
|
+
const summary = text(result["output"])?.split("\n").find((line) => line.trim())?.trim();
|
|
30415
30774
|
if (status === "running") {
|
|
30416
30775
|
events.push({
|
|
30417
30776
|
type: "task.progress",
|
|
@@ -30471,6 +30830,62 @@ function grokImageArtifacts(rawOutput) {
|
|
|
30471
30830
|
return [{ path, name: filename, ...linkBase !== void 0 ? { linkBase } : {} }];
|
|
30472
30831
|
}
|
|
30473
30832
|
|
|
30833
|
+
// src/grokTodoPlan.ts
|
|
30834
|
+
import { planFromTodos } from "@ycodium-ai/plugin-api/executor";
|
|
30835
|
+
var TODO_TOOL = "todo_write";
|
|
30836
|
+
var record3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
30837
|
+
var text2 = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
30838
|
+
var isTodoWrite = (input2) => record3(record3(input2.meta)["x.ai/tool"])["name"] === TODO_TOOL || input2.name === TODO_TOOL || input2.title === TODO_TOOL;
|
|
30839
|
+
function createGrokTodoPlan(publish) {
|
|
30840
|
+
const items = /* @__PURE__ */ new Map();
|
|
30841
|
+
const calls = /* @__PURE__ */ new Set();
|
|
30842
|
+
return {
|
|
30843
|
+
observe(input2) {
|
|
30844
|
+
if (isTodoWrite(input2)) calls.add(input2.toolCallId);
|
|
30845
|
+
if (!calls.has(input2.toolCallId)) return;
|
|
30846
|
+
if (input2.status !== "completed") return;
|
|
30847
|
+
const args = record3(input2.rawInput);
|
|
30848
|
+
const todos = args["todos"];
|
|
30849
|
+
if (!Array.isArray(todos)) return;
|
|
30850
|
+
if (args["merge"] === false) items.clear();
|
|
30851
|
+
for (const entry of todos) {
|
|
30852
|
+
const todo = record3(entry);
|
|
30853
|
+
const id = text2(todo["id"]);
|
|
30854
|
+
if (id === void 0) continue;
|
|
30855
|
+
const known = items.get(id);
|
|
30856
|
+
const content = text2(todo["content"]) ?? known?.content;
|
|
30857
|
+
if (content === void 0) continue;
|
|
30858
|
+
items.set(id, { content, status: text2(todo["status"]) ?? known?.status ?? "pending" });
|
|
30859
|
+
}
|
|
30860
|
+
const plan = planFromTodos([...items.values()]);
|
|
30861
|
+
if (plan !== void 0) publish(plan, input2.turnId);
|
|
30862
|
+
}
|
|
30863
|
+
};
|
|
30864
|
+
}
|
|
30865
|
+
|
|
30866
|
+
// src/grokSkillDispatch.ts
|
|
30867
|
+
import { matchSkillTokens, skillInvocationNotice } from "@ycodium-ai/plugin-api/composer";
|
|
30868
|
+
var paragraphs = (parts) => parts.filter((part) => part !== void 0 && part.length > 0).join("\n\n");
|
|
30869
|
+
function dispatchGrokSkills(prompt, names, preamble) {
|
|
30870
|
+
const mentions = names.length === 0 ? [] : matchSkillTokens(prompt, new Map(names.map((name) => [name, { name }])));
|
|
30871
|
+
if (mentions.length === 0) return paragraphs([preamble, prompt]);
|
|
30872
|
+
const leading = prompt.slice(0, mentions[0].start).trim();
|
|
30873
|
+
if (leading !== "") {
|
|
30874
|
+
return paragraphs([preamble, prompt, skillInvocationNotice(mentions.map((m) => m.skill.name))]);
|
|
30875
|
+
}
|
|
30876
|
+
const first = mentions[0];
|
|
30877
|
+
const rest = prompt.slice(first.end);
|
|
30878
|
+
const later = mentions.slice(1).map((m) => m.skill.name);
|
|
30879
|
+
const trailing = paragraphs([
|
|
30880
|
+
preamble,
|
|
30881
|
+
later.length === 0 ? void 0 : skillInvocationNotice(later)
|
|
30882
|
+
]);
|
|
30883
|
+
const rewritten = `/${first.skill.name}${rest}`;
|
|
30884
|
+
return trailing === "" ? rewritten : `${rewritten}
|
|
30885
|
+
|
|
30886
|
+
${trailing}`;
|
|
30887
|
+
}
|
|
30888
|
+
|
|
30474
30889
|
// src/grokSubagents.ts
|
|
30475
30890
|
var SPAWN_TOOL = "spawn_subagent";
|
|
30476
30891
|
var SPAWN_ACK_ID = /^subagent_id:\s*(\S+)\s*$/m;
|
|
@@ -30487,8 +30902,8 @@ var NOTIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
|
30487
30902
|
"x.ai/session/update"
|
|
30488
30903
|
]);
|
|
30489
30904
|
var isGrokSessionNotification = (method) => NOTIFICATION_METHODS.has(method.startsWith("_") ? method.slice(1) : method);
|
|
30490
|
-
var
|
|
30491
|
-
var text3 =
|
|
30905
|
+
var record4 = (value) => isRecord9(value) ? value : {};
|
|
30906
|
+
var text3 = trimmed;
|
|
30492
30907
|
var count2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
30493
30908
|
var replyText = (value) => {
|
|
30494
30909
|
const reply = typeof value === "string" ? value.replace(MACHINE_BLOCKS, "").trim() : "";
|
|
@@ -30705,11 +31120,11 @@ function createGrokSubagents() {
|
|
|
30705
31120
|
return changed ? [completed(agent, merged, turnId)] : [];
|
|
30706
31121
|
};
|
|
30707
31122
|
const fromEnvelope = (params, ctx) => {
|
|
30708
|
-
const envelope =
|
|
30709
|
-
if (
|
|
31123
|
+
const envelope = record4(params);
|
|
31124
|
+
if (record4(envelope["_meta"])["isReplay"] === true) return void 0;
|
|
30710
31125
|
const sessionId = text3(envelope["sessionId"]);
|
|
30711
31126
|
if (ctx.sessionId !== void 0 && sessionId !== ctx.sessionId) return void 0;
|
|
30712
|
-
const update =
|
|
31127
|
+
const update = record4(envelope["update"]);
|
|
30713
31128
|
switch (update["sessionUpdate"]) {
|
|
30714
31129
|
case "subagent_spawned":
|
|
30715
31130
|
return onSpawned(update, ctx);
|
|
@@ -30725,13 +31140,13 @@ function createGrokSubagents() {
|
|
|
30725
31140
|
onExtensionNotification: (method, params, ctx) => isGrokSessionNotification(method) ? fromEnvelope(params, ctx) : void 0,
|
|
30726
31141
|
onSessionUpdate: (notification, ctx) => ctx.foreign ? void 0 : fromEnvelope(notification, ctx),
|
|
30727
31142
|
handlesToolCall: (input2) => {
|
|
30728
|
-
if (!spawnCalls.has(input2.toolCallId) && (
|
|
31143
|
+
if (!spawnCalls.has(input2.toolCallId) && (record4(record4(input2.meta)["x.ai/tool"])["name"] === SPAWN_TOOL || record4(input2.rawInput)["variant"] === "Task")) {
|
|
30729
31144
|
spawnCalls.add(input2.toolCallId);
|
|
30730
31145
|
}
|
|
30731
31146
|
if (!spawnCalls.has(input2.toolCallId)) return false;
|
|
30732
31147
|
if (input2.status !== "completed" && input2.status !== "failed") return true;
|
|
30733
31148
|
if (input2.status === "failed") return false;
|
|
30734
|
-
const output2 =
|
|
31149
|
+
const output2 = record4(input2.rawOutput);
|
|
30735
31150
|
const ack = typeof output2["text"] === "string" ? SPAWN_ACK_ID.exec(output2["text"]) : null;
|
|
30736
31151
|
return output2["type"] === "SubagentCompleted" && text3(output2["subagent_id"]) !== void 0 || output2["type"] === "Text" && ack !== null;
|
|
30737
31152
|
},
|
|
@@ -30757,17 +31172,27 @@ var retryMessage = (errorType, attempt, maxRetries) => {
|
|
|
30757
31172
|
const cause = errorType === "rate_limited" ? "Grok is rate limited." : "Grok request failed temporarily.";
|
|
30758
31173
|
return `${cause} Retrying (attempt ${attempt} of ${maxRetries})`;
|
|
30759
31174
|
};
|
|
30760
|
-
function grokObservationHooks(subagents) {
|
|
31175
|
+
function grokObservationHooks(subagents, onEnvelope) {
|
|
30761
31176
|
const retryNotices = createGrokRetryNotices();
|
|
30762
31177
|
return {
|
|
30763
|
-
onExtensionNotification: (method, params, ctx) =>
|
|
30764
|
-
|
|
30765
|
-
|
|
30766
|
-
|
|
30767
|
-
|
|
30768
|
-
|
|
30769
|
-
|
|
30770
|
-
|
|
31178
|
+
onExtensionNotification: (method, params, ctx) => {
|
|
31179
|
+
if (isGrokSessionNotification(method)) {
|
|
31180
|
+
onEnvelope?.(params, ctx.sessionId);
|
|
31181
|
+
}
|
|
31182
|
+
return [
|
|
31183
|
+
...subagents.onExtensionNotification(method, params, ctx) ?? [],
|
|
31184
|
+
...isGrokSessionNotification(method) ? retryNotices.observe(params, ctx) : []
|
|
31185
|
+
];
|
|
31186
|
+
},
|
|
31187
|
+
onSessionUpdate: (notification, ctx) => {
|
|
31188
|
+
if (!ctx.foreign) {
|
|
31189
|
+
onEnvelope?.(notification, ctx.sessionId);
|
|
31190
|
+
}
|
|
31191
|
+
return [
|
|
31192
|
+
...subagents.onSessionUpdate(notification, ctx) ?? [],
|
|
31193
|
+
...retryNotices.observe(notification, ctx)
|
|
31194
|
+
];
|
|
31195
|
+
}
|
|
30771
31196
|
};
|
|
30772
31197
|
}
|
|
30773
31198
|
function createGrokRetryNotices() {
|
|
@@ -30775,7 +31200,7 @@ function createGrokRetryNotices() {
|
|
|
30775
31200
|
let phase;
|
|
30776
31201
|
return {
|
|
30777
31202
|
observe: (envelope, ctx) => {
|
|
30778
|
-
if (!
|
|
31203
|
+
if (!isRecord9(envelope) || !isRecord9(envelope["update"])) return [];
|
|
30779
31204
|
if (ctx.sessionId === void 0 || envelope["sessionId"] !== ctx.sessionId) return [];
|
|
30780
31205
|
const update = envelope["update"];
|
|
30781
31206
|
if (update["sessionUpdate"] !== "retry_state") {
|
|
@@ -30786,7 +31211,7 @@ function createGrokRetryNotices() {
|
|
|
30786
31211
|
phase = void 0;
|
|
30787
31212
|
return [];
|
|
30788
31213
|
}
|
|
30789
|
-
const meta3 =
|
|
31214
|
+
const meta3 = isRecord9(envelope["_meta"]) ? envelope["_meta"] : {};
|
|
30790
31215
|
if (meta3["isReplay"] === true) return [];
|
|
30791
31216
|
const turnId = ctx.turnId;
|
|
30792
31217
|
if (turnId === void 0) return [];
|
|
@@ -30930,45 +31355,50 @@ function grokRuntimeModeCaveat(nativeModeId) {
|
|
|
30930
31355
|
};
|
|
30931
31356
|
}
|
|
30932
31357
|
function resolveGrokAuthMethodId(initializeResult) {
|
|
30933
|
-
const authMethods =
|
|
31358
|
+
const authMethods = isRecord9(initializeResult) ? initializeResult["authMethods"] : void 0;
|
|
30934
31359
|
if (!Array.isArray(authMethods)) return void 0;
|
|
30935
31360
|
for (const method of authMethods) {
|
|
30936
|
-
if (
|
|
31361
|
+
if (isRecord9(method) && method["id"] === "cached_token") return "cached_token";
|
|
30937
31362
|
}
|
|
30938
31363
|
return void 0;
|
|
30939
31364
|
}
|
|
30940
31365
|
var positive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : void 0;
|
|
30941
|
-
function
|
|
30942
|
-
if (!
|
|
31366
|
+
function grokContextWindow(promptResponse, initializeResult) {
|
|
31367
|
+
if (!isRecord9(promptResponse)) return void 0;
|
|
30943
31368
|
const meta3 = promptResponse["_meta"];
|
|
30944
|
-
if (!
|
|
31369
|
+
if (!isRecord9(meta3)) return void 0;
|
|
30945
31370
|
const usedTokens = positive(meta3["totalTokens"]);
|
|
30946
31371
|
if (usedTokens === void 0) return void 0;
|
|
30947
|
-
|
|
31372
|
+
const modelId = trimmed(meta3["modelId"]);
|
|
31373
|
+
const matched = grokAdvertisedModels(initializeResult).find((model) => model.modelId === modelId);
|
|
31374
|
+
return {
|
|
31375
|
+
usedTokens,
|
|
31376
|
+
...matched?.contextWindow === void 0 ? {} : { maxTokens: matched.contextWindow }
|
|
31377
|
+
};
|
|
30948
31378
|
}
|
|
30949
31379
|
function grokModelState(initializeResult) {
|
|
30950
|
-
if (!
|
|
31380
|
+
if (!isRecord9(initializeResult)) return void 0;
|
|
30951
31381
|
const meta3 = initializeResult["_meta"];
|
|
30952
|
-
if (!
|
|
31382
|
+
if (!isRecord9(meta3)) return void 0;
|
|
30953
31383
|
const modelState = meta3["modelState"];
|
|
30954
|
-
if (!
|
|
31384
|
+
if (!isRecord9(modelState)) return void 0;
|
|
30955
31385
|
const availableModels = modelState["availableModels"];
|
|
30956
31386
|
if (!Array.isArray(availableModels)) return void 0;
|
|
30957
|
-
return { currentModelId:
|
|
31387
|
+
return { currentModelId: trimmed(modelState["currentModelId"]), availableModels };
|
|
30958
31388
|
}
|
|
30959
31389
|
function grokAdvertisedModels(initializeResult) {
|
|
30960
31390
|
const state = grokModelState(initializeResult);
|
|
30961
31391
|
if (state === void 0) return [];
|
|
30962
31392
|
const models = [];
|
|
30963
31393
|
for (const entry of state.availableModels) {
|
|
30964
|
-
if (!
|
|
30965
|
-
const modelId =
|
|
31394
|
+
if (!isRecord9(entry)) continue;
|
|
31395
|
+
const modelId = trimmed(entry["modelId"]);
|
|
30966
31396
|
if (modelId === void 0) continue;
|
|
30967
31397
|
const modelMeta = entry["_meta"];
|
|
30968
|
-
const contextWindow =
|
|
31398
|
+
const contextWindow = isRecord9(modelMeta) ? positive(modelMeta["totalContextTokens"]) : void 0;
|
|
30969
31399
|
models.push({
|
|
30970
31400
|
modelId,
|
|
30971
|
-
name:
|
|
31401
|
+
name: trimmed(entry["name"]),
|
|
30972
31402
|
isDefault: state.currentModelId !== void 0 && modelId === state.currentModelId,
|
|
30973
31403
|
contextWindow,
|
|
30974
31404
|
reasoningEffort: grokReasoningEffortDescriptor(modelMeta),
|
|
@@ -30982,7 +31412,7 @@ var XAI_ASK_USER_QUESTION_METHODS = [
|
|
|
30982
31412
|
"x.ai/ask_user_question"
|
|
30983
31413
|
];
|
|
30984
31414
|
var readOption = (value) => {
|
|
30985
|
-
if (!
|
|
31415
|
+
if (!isRecord9(value)) return void 0;
|
|
30986
31416
|
const label = typeof value["label"] === "string" ? value["label"] : void 0;
|
|
30987
31417
|
if (label === void 0) return void 0;
|
|
30988
31418
|
return {
|
|
@@ -30993,7 +31423,7 @@ var readOption = (value) => {
|
|
|
30993
31423
|
};
|
|
30994
31424
|
};
|
|
30995
31425
|
var readQuestion = (value) => {
|
|
30996
|
-
if (!
|
|
31426
|
+
if (!isRecord9(value)) return void 0;
|
|
30997
31427
|
const question = typeof value["question"] === "string" ? value["question"] : void 0;
|
|
30998
31428
|
if (question === void 0) return void 0;
|
|
30999
31429
|
const optionsRaw = value["options"];
|
|
@@ -31009,9 +31439,9 @@ var readQuestion = (value) => {
|
|
|
31009
31439
|
};
|
|
31010
31440
|
};
|
|
31011
31441
|
function parseXAiAskUserQuestionParams(params) {
|
|
31012
|
-
const candidates = [params, ...
|
|
31442
|
+
const candidates = [params, ...isRecord9(params) ? [params["params"]] : []];
|
|
31013
31443
|
for (const candidate of candidates) {
|
|
31014
|
-
if (!
|
|
31444
|
+
if (!isRecord9(candidate)) continue;
|
|
31015
31445
|
const questionsRaw = candidate["questions"];
|
|
31016
31446
|
if (!Array.isArray(questionsRaw)) continue;
|
|
31017
31447
|
const questions = questionsRaw.flatMap((entry) => {
|
|
@@ -31037,11 +31467,11 @@ function extractXAiAskUserQuestions(params) {
|
|
|
31037
31467
|
var answerValues = (answer) => {
|
|
31038
31468
|
if (Array.isArray(answer)) {
|
|
31039
31469
|
return answer.flatMap((entry) => {
|
|
31040
|
-
const text5 =
|
|
31470
|
+
const text5 = trimmed(entry);
|
|
31041
31471
|
return text5 === void 0 ? [] : [text5];
|
|
31042
31472
|
});
|
|
31043
31473
|
}
|
|
31044
|
-
const text4 =
|
|
31474
|
+
const text4 = trimmed(answer);
|
|
31045
31475
|
return text4 === void 0 ? [] : [text4];
|
|
31046
31476
|
};
|
|
31047
31477
|
function makeXAiAskUserQuestionResponse(params, answers) {
|
|
@@ -31053,7 +31483,7 @@ function makeXAiAskUserQuestionResponse(params, answers) {
|
|
|
31053
31483
|
const resolved = values.map((value) => ({ value, option: optionByLabel.get(value) }));
|
|
31054
31484
|
const selectedLabels = resolved.flatMap(({ option }) => option ? [option.label] : []);
|
|
31055
31485
|
const notes = resolved.flatMap(({ option, value }) => option ? [] : [value]);
|
|
31056
|
-
const preview = question.multiSelect ? void 0 : resolved.map(({ option }) =>
|
|
31486
|
+
const preview = question.multiSelect ? void 0 : resolved.map(({ option }) => trimmed(option?.preview)).find((value) => value);
|
|
31057
31487
|
const annotation = preview !== void 0 || notes.length > 0 ? {
|
|
31058
31488
|
...preview !== void 0 ? { preview } : {},
|
|
31059
31489
|
...notes.length > 0 ? { notes: notes.join("\n") } : {}
|
|
@@ -31085,25 +31515,25 @@ function makeXAiAskUserQuestionCancelledResponse() {
|
|
|
31085
31515
|
var XAI_PROMPT_COMPLETE_METHOD = "_x.ai/session/prompt_complete";
|
|
31086
31516
|
var GROK_RATE_LIMIT_MESSAGE = "Grok usage limit reached or rate limited. Try again later.";
|
|
31087
31517
|
var grokAgentResultMessage = (value) => {
|
|
31088
|
-
if (typeof value === "string") return
|
|
31089
|
-
return
|
|
31518
|
+
if (typeof value === "string") return trimmed(value);
|
|
31519
|
+
return isRecord9(value) ? trimmed(value["message"]) : void 0;
|
|
31090
31520
|
};
|
|
31091
31521
|
var grokPromptSettlement = {
|
|
31092
31522
|
// 关联 id 双写 promptId 与 requestId(宿主 XAiAcpExtension 同款):
|
|
31093
31523
|
// agent 认回哪个键是它的事,两个都给才不猜版本。
|
|
31094
31524
|
requestFields: (promptKey) => ({ _meta: { promptId: promptKey, requestId: promptKey } }),
|
|
31095
31525
|
responseKey: (response) => {
|
|
31096
|
-
if (!
|
|
31526
|
+
if (!isRecord9(response)) return void 0;
|
|
31097
31527
|
const meta3 = response["_meta"];
|
|
31098
|
-
if (!
|
|
31099
|
-
return
|
|
31528
|
+
if (!isRecord9(meta3)) return void 0;
|
|
31529
|
+
return trimmed(meta3["promptId"]) ?? trimmed(meta3["requestId"]);
|
|
31100
31530
|
},
|
|
31101
31531
|
fromNotification: (method, params) => {
|
|
31102
31532
|
if (method !== XAI_PROMPT_COMPLETE_METHOD) return void 0;
|
|
31103
|
-
if (!
|
|
31533
|
+
if (!isRecord9(params)) return void 0;
|
|
31104
31534
|
const sessionId = params["sessionId"];
|
|
31105
31535
|
if (typeof sessionId !== "string") return void 0;
|
|
31106
|
-
const stopReason =
|
|
31536
|
+
const stopReason = trimmed(params["stopReason"]);
|
|
31107
31537
|
const rateLimited = stopReason === "rate_limit";
|
|
31108
31538
|
const failed = stopReason === "error" || rateLimited;
|
|
31109
31539
|
const detail = rateLimited ? GROK_RATE_LIMIT_MESSAGE : grokAgentResultMessage(params["agentResult"]);
|
|
@@ -31188,9 +31618,13 @@ async function probeGrokSkills(input2) {
|
|
|
31188
31618
|
async function inspectGrokWorkspace(input2) {
|
|
31189
31619
|
const skills = await runGrokInspect(input2);
|
|
31190
31620
|
const watched = /* @__PURE__ */ new Set([
|
|
31191
|
-
//
|
|
31621
|
+
// CLI 自己扫工作目录(及逐级父目录到仓库根)下这四个 vendor 目录的 `skills/`,
|
|
31622
|
+
// 出处是它随包发的用户指南 `docs/user-guide/08-skills.md` 的「Skill Locations」表。
|
|
31623
|
+
// 这里只是触发重查的提示,不影响答案本身。
|
|
31192
31624
|
NodePath6.join(input2.cwd, ".grok", "skills"),
|
|
31193
|
-
NodePath6.join(input2.cwd, ".agents", "skills")
|
|
31625
|
+
NodePath6.join(input2.cwd, ".agents", "skills"),
|
|
31626
|
+
NodePath6.join(input2.cwd, ".claude", "skills"),
|
|
31627
|
+
NodePath6.join(input2.cwd, ".cursor", "skills")
|
|
31194
31628
|
]);
|
|
31195
31629
|
for (const skill of skills) {
|
|
31196
31630
|
watched.add(skill.path);
|
|
@@ -31691,75 +32125,49 @@ import * as NodeFS5 from "node:fs";
|
|
|
31691
32125
|
import * as NodeFSP from "node:fs/promises";
|
|
31692
32126
|
import * as NodePath9 from "node:path";
|
|
31693
32127
|
import * as NodeReadline from "node:readline";
|
|
32128
|
+
import { parseJsonRecord as parseJsonRecord2 } from "@ycodium-ai/plugin-api/credential-account";
|
|
31694
32129
|
import {
|
|
31695
|
-
|
|
32130
|
+
createDirectoryNativeSessions,
|
|
31696
32131
|
isAbsoluteDirectory,
|
|
31697
|
-
|
|
31698
|
-
|
|
32132
|
+
isMissingFileError,
|
|
32133
|
+
listSubdirectories,
|
|
31699
32134
|
inputPayload as inputPayload2,
|
|
31700
32135
|
outputPayload as outputPayload2
|
|
31701
32136
|
} from "@ycodium-ai/plugin-api/session-history";
|
|
31702
32137
|
var sessionIdPattern = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/iu;
|
|
31703
|
-
function
|
|
31704
|
-
try {
|
|
31705
|
-
const value = JSON.parse(raw);
|
|
31706
|
-
return isRecord10(value) ? value : void 0;
|
|
31707
|
-
} catch {
|
|
31708
|
-
return void 0;
|
|
31709
|
-
}
|
|
31710
|
-
}
|
|
31711
|
-
function missingFile(error62) {
|
|
31712
|
-
return error62.code === "ENOENT";
|
|
31713
|
-
}
|
|
31714
|
-
async function directories(path) {
|
|
31715
|
-
try {
|
|
31716
|
-
return (await NodeFSP.readdir(path, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
31717
|
-
} catch (error62) {
|
|
31718
|
-
if (missingFile(error62)) return [];
|
|
31719
|
-
throw error62;
|
|
31720
|
-
}
|
|
31721
|
-
}
|
|
31722
|
-
async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
32138
|
+
async function findSessions(home, signal) {
|
|
31723
32139
|
signal?.throwIfAborted();
|
|
31724
|
-
const expectedCwd = directoryKey(cwd);
|
|
31725
32140
|
const result = [];
|
|
31726
32141
|
const root = NodePath9.join(home, "sessions");
|
|
31727
|
-
for (const workspace of await
|
|
32142
|
+
for (const workspace of await listSubdirectories(root)) {
|
|
31728
32143
|
const workspacePath = NodePath9.join(root, workspace);
|
|
31729
|
-
for (const id of await
|
|
32144
|
+
for (const id of await listSubdirectories(workspacePath)) {
|
|
31730
32145
|
signal?.throwIfAborted();
|
|
31731
|
-
if (!sessionIdPattern.test(id)
|
|
31732
|
-
continue;
|
|
32146
|
+
if (!sessionIdPattern.test(id)) continue;
|
|
31733
32147
|
const sessionPath = NodePath9.join(workspacePath, id);
|
|
31734
32148
|
const summaryPath = NodePath9.join(sessionPath, "summary.json");
|
|
31735
32149
|
try {
|
|
31736
32150
|
if (!(await NodeFSP.lstat(summaryPath)).isFile()) continue;
|
|
31737
|
-
const summary =
|
|
32151
|
+
const summary = parseJsonRecord2(
|
|
31738
32152
|
await NodeFSP.readFile(summaryPath, { encoding: "utf8", signal })
|
|
31739
32153
|
);
|
|
31740
32154
|
const info = summary?.info;
|
|
31741
|
-
if (!summary || !
|
|
31742
|
-
continue;
|
|
31743
|
-
if (!matchesSessionDirectory(
|
|
31744
|
-
expectedCwd,
|
|
31745
|
-
info.cwd,
|
|
31746
|
-
nativeSessionId === void 0 ? "scan" : "read"
|
|
31747
|
-
))
|
|
32155
|
+
if (!summary || !isRecord9(info) || info.id !== id || typeof info.cwd !== "string" || !isAbsoluteDirectory(info.cwd))
|
|
31748
32156
|
continue;
|
|
31749
32157
|
const updates = NodePath9.join(sessionPath, "updates.jsonl");
|
|
31750
32158
|
if (!(await NodeFSP.lstat(updates)).isFile()) continue;
|
|
31751
|
-
const updatedAt = Date.parse(
|
|
32159
|
+
const updatedAt = Date.parse(trimmed(summary.updated_at) ?? "");
|
|
31752
32160
|
result.push({
|
|
31753
32161
|
id,
|
|
31754
32162
|
cwd: info.cwd,
|
|
31755
|
-
title:
|
|
31756
|
-
preview:
|
|
31757
|
-
model:
|
|
32163
|
+
title: trimmed(summary.title) ?? trimmed(summary.generated_title) ?? null,
|
|
32164
|
+
preview: trimmed(summary.session_summary) ?? null,
|
|
32165
|
+
model: trimmed(summary.current_model_id) ?? null,
|
|
31758
32166
|
updatedAt: Number.isFinite(updatedAt) ? updatedAt : 0,
|
|
31759
32167
|
updates
|
|
31760
32168
|
});
|
|
31761
32169
|
} catch (error62) {
|
|
31762
|
-
if (!
|
|
32170
|
+
if (!isMissingFileError(error62)) throw error62;
|
|
31763
32171
|
}
|
|
31764
32172
|
}
|
|
31765
32173
|
}
|
|
@@ -31769,7 +32177,7 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
|
31769
32177
|
function toolOutput(content) {
|
|
31770
32178
|
if (!Array.isArray(content)) return void 0;
|
|
31771
32179
|
const output2 = content.flatMap(
|
|
31772
|
-
(entry) =>
|
|
32180
|
+
(entry) => isRecord9(entry) && isRecord9(entry.content) && entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : []
|
|
31773
32181
|
).join("\n");
|
|
31774
32182
|
return output2.length === 0 ? void 0 : output2;
|
|
31775
32183
|
}
|
|
@@ -31791,12 +32199,12 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31791
32199
|
for await (const line of lines) {
|
|
31792
32200
|
signal?.throwIfAborted();
|
|
31793
32201
|
sourceOrder += 1;
|
|
31794
|
-
const row =
|
|
31795
|
-
if (!row || !
|
|
32202
|
+
const row = parseJsonRecord2(line);
|
|
32203
|
+
if (!row || !isRecord9(row.params) || row.params.sessionId !== session.id) continue;
|
|
31796
32204
|
const { update, _meta: metadata } = row.params;
|
|
31797
|
-
if (!
|
|
31798
|
-
const updateMetadata =
|
|
31799
|
-
const eventId =
|
|
32205
|
+
if (!isRecord9(update)) continue;
|
|
32206
|
+
const updateMetadata = isRecord9(update._meta) ? update._meta : void 0;
|
|
32207
|
+
const eventId = isRecord9(metadata) ? trimmed(metadata.eventId) : void 0;
|
|
31800
32208
|
const sourceId = eventId ?? `update:${sourceOrder}`;
|
|
31801
32209
|
const timestamp = typeof row.timestamp_us === "number" ? row.timestamp_us / 1e3 : typeof row.timestamp === "number" ? row.timestamp * 1e3 : session.updatedAt;
|
|
31802
32210
|
const createdAt = new Date(Math.abs(timestamp) <= 864e13 ? timestamp : 0).toISOString();
|
|
@@ -31807,7 +32215,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31807
32215
|
const turnId = typeof promptIndex === "number" ? String(promptIndex) : previous?.role === "user" ? nativeTurnId : sourceId;
|
|
31808
32216
|
if (turnId !== nativeTurnId) turnCount += 1;
|
|
31809
32217
|
nativeTurnId = turnId;
|
|
31810
|
-
model =
|
|
32218
|
+
model = trimmed(updateMetadata?.modelId) ?? model;
|
|
31811
32219
|
}
|
|
31812
32220
|
const identity = {
|
|
31813
32221
|
sourceId,
|
|
@@ -31818,7 +32226,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31818
32226
|
};
|
|
31819
32227
|
if (role !== void 0) {
|
|
31820
32228
|
const content = update.content;
|
|
31821
|
-
if (!
|
|
32229
|
+
if (!isRecord9(content) || content.type !== "text" || typeof content.text !== "string" || content.text.length === 0)
|
|
31822
32230
|
continue;
|
|
31823
32231
|
hasMessages = true;
|
|
31824
32232
|
const continuing = previous?.role === role && previous.nativeTurnId === nativeTurnId;
|
|
@@ -31836,14 +32244,14 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31836
32244
|
continue;
|
|
31837
32245
|
}
|
|
31838
32246
|
if (type === "turn_completed") previous = void 0;
|
|
31839
|
-
const toolCallId =
|
|
32247
|
+
const toolCallId = trimmed(update.toolCallId);
|
|
31840
32248
|
if (toolCallId === void 0) continue;
|
|
31841
32249
|
if (type === "tool_call") previous = void 0;
|
|
31842
32250
|
if (summaryOnly) continue;
|
|
31843
32251
|
if (type === "tool_call") {
|
|
31844
|
-
const name =
|
|
31845
|
-
const tool =
|
|
31846
|
-
const input2 =
|
|
32252
|
+
const name = trimmed(update.title) ?? "Tool";
|
|
32253
|
+
const tool = isRecord9(updateMetadata?.["x.ai/tool"]) ? updateMetadata["x.ai/tool"] : void 0;
|
|
32254
|
+
const input2 = isRecord9(update.rawInput) && typeof update.rawInput.command === "string" ? update.rawInput.command : update.rawInput === void 0 ? void 0 : JSON.stringify(update.rawInput);
|
|
31847
32255
|
const activity = {
|
|
31848
32256
|
...identity,
|
|
31849
32257
|
kind: "tool.started",
|
|
@@ -31885,72 +32293,14 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31885
32293
|
return { messages, activities, turnCount, hasMessages, preview };
|
|
31886
32294
|
}
|
|
31887
32295
|
function createGrokNativeSessions(home, resumeSchemaVersion) {
|
|
31888
|
-
|
|
31889
|
-
|
|
31890
|
-
|
|
31891
|
-
|
|
31892
|
-
|
|
31893
|
-
|
|
31894
|
-
|
|
31895
|
-
|
|
31896
|
-
scan: async ({
|
|
31897
|
-
directory,
|
|
31898
|
-
signal
|
|
31899
|
-
}) => {
|
|
31900
|
-
const sessions = (await findSessions(importHome(), directory, signal)).sort(
|
|
31901
|
-
(left, right) => right.updatedAt - left.updatedAt
|
|
31902
|
-
);
|
|
31903
|
-
const candidates = [];
|
|
31904
|
-
for (const session of sessions) {
|
|
31905
|
-
try {
|
|
31906
|
-
const {
|
|
31907
|
-
hasMessages,
|
|
31908
|
-
preview: prompt,
|
|
31909
|
-
turnCount
|
|
31910
|
-
} = await readTranscript(session, signal, true);
|
|
31911
|
-
if (!hasMessages) continue;
|
|
31912
|
-
candidates.push({
|
|
31913
|
-
nativeSessionId: session.id,
|
|
31914
|
-
cwd: session.cwd,
|
|
31915
|
-
title: session.title ?? prompt?.slice(0, 160) ?? null,
|
|
31916
|
-
preview: session.preview ?? prompt?.slice(0, 240) ?? null,
|
|
31917
|
-
model: session.model,
|
|
31918
|
-
turnCount,
|
|
31919
|
-
updatedAt: session.updatedAt,
|
|
31920
|
-
availability: "importable",
|
|
31921
|
-
openElsewhere: false
|
|
31922
|
-
});
|
|
31923
|
-
} catch (error62) {
|
|
31924
|
-
if (!missingFile(error62)) throw error62;
|
|
31925
|
-
}
|
|
31926
|
-
}
|
|
31927
|
-
return { candidates };
|
|
31928
|
-
},
|
|
31929
|
-
readImport: async ({
|
|
31930
|
-
nativeSessionId,
|
|
31931
|
-
cwd,
|
|
31932
|
-
signal
|
|
31933
|
-
}) => {
|
|
31934
|
-
signal?.throwIfAborted();
|
|
31935
|
-
if (cwd === void 0 || !isAbsoluteDirectory(cwd)) {
|
|
31936
|
-
throw new Error("Grok session import requires an absolute working directory.");
|
|
31937
|
-
}
|
|
31938
|
-
const matches = await findSessions(importHome(), cwd, signal, nativeSessionId);
|
|
31939
|
-
const session = matches[0];
|
|
31940
|
-
if (matches.length !== 1 || session === void 0)
|
|
31941
|
-
throw new Error("Grok session was not found uniquely in the requested working directory.");
|
|
31942
|
-
const { messages, activities } = await readTranscript(session, signal);
|
|
31943
|
-
return {
|
|
31944
|
-
resumeCursor: { schemaVersion: resumeSchemaVersion, sessionId: session.id },
|
|
31945
|
-
title: session.title ?? messages.find((message) => message.role === "user")?.text.slice(0, 160) ?? null,
|
|
31946
|
-
model: session.model,
|
|
31947
|
-
messages,
|
|
31948
|
-
activities,
|
|
31949
|
-
availableMessages: messages.length,
|
|
31950
|
-
availableActivities: activities.length
|
|
31951
|
-
};
|
|
31952
|
-
}
|
|
31953
|
-
};
|
|
32296
|
+
return createDirectoryNativeSessions({
|
|
32297
|
+
providerName: "Grok",
|
|
32298
|
+
storageKeyPrefix: "grok",
|
|
32299
|
+
home,
|
|
32300
|
+
resumeSchemaVersion,
|
|
32301
|
+
findSessions: (sessionHome, _cwd, signal) => findSessions(sessionHome, signal),
|
|
32302
|
+
readTranscript
|
|
32303
|
+
});
|
|
31954
32304
|
}
|
|
31955
32305
|
|
|
31956
32306
|
// src/grokInstance.ts
|
|
@@ -31958,7 +32308,7 @@ var RESUME_SCHEMA_VERSION = 1;
|
|
|
31958
32308
|
function nowIso3() {
|
|
31959
32309
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
31960
32310
|
}
|
|
31961
|
-
var createGrokInstance = (config2, host) => {
|
|
32311
|
+
var createGrokInstance = (config2, host, deps) => {
|
|
31962
32312
|
const recipe = parseGrokInstanceConfig(config2);
|
|
31963
32313
|
let disposed = false;
|
|
31964
32314
|
const table = createAcpThreadTable(host.log, () => signIn.close());
|
|
@@ -32065,8 +32415,10 @@ var createGrokInstance = (config2, host) => {
|
|
|
32065
32415
|
requireThread,
|
|
32066
32416
|
isDisposed: () => disposed,
|
|
32067
32417
|
turnSelection: (selection) => readTurnSelection(selection, GROK_REASONING_OPTION_ID),
|
|
32068
|
-
log: host.log
|
|
32418
|
+
log: host.log,
|
|
32419
|
+
...deps?.readAttachment === void 0 ? {} : { readAttachment: deps.readAttachment }
|
|
32069
32420
|
});
|
|
32421
|
+
const sessionSkillNames = /* @__PURE__ */ new Map();
|
|
32070
32422
|
const sessionHome = (spawnEnv().GROK_HOME ?? process.env.GROK_HOME)?.trim();
|
|
32071
32423
|
const sessions = createGrokNativeSessions(
|
|
32072
32424
|
sessionHome || resolveGrokHomePath(""),
|
|
@@ -32113,6 +32465,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
32113
32465
|
host.log,
|
|
32114
32466
|
input2.threadId
|
|
32115
32467
|
);
|
|
32468
|
+
sessionSkillNames.set(input2.threadId, input2.skills?.names ?? []);
|
|
32116
32469
|
const env = spawnEnv();
|
|
32117
32470
|
const effort = modelSelectionStringOption2(input2.modelSelection, GROK_REASONING_OPTION_ID);
|
|
32118
32471
|
const baseArgs = tokenizeShellWords2(recipe.launchArgs);
|
|
@@ -32138,7 +32491,20 @@ var createGrokInstance = (config2, host) => {
|
|
|
32138
32491
|
let initializeResult;
|
|
32139
32492
|
const backgroundTasks = /* @__PURE__ */ new Map();
|
|
32140
32493
|
const subagents = createGrokSubagents();
|
|
32141
|
-
const
|
|
32494
|
+
const todoPlan = createGrokTodoPlan(
|
|
32495
|
+
(plan, turnId) => input2.events.emit({
|
|
32496
|
+
type: "turn.plan.updated",
|
|
32497
|
+
eventId: NodeCrypto6.randomUUID(),
|
|
32498
|
+
provider: GROK_DRIVER_KIND,
|
|
32499
|
+
providerInstanceId: host.instanceId,
|
|
32500
|
+
threadId: input2.threadId,
|
|
32501
|
+
createdAt: nowIso3(),
|
|
32502
|
+
...turnId === void 0 ? {} : { turnId },
|
|
32503
|
+
payload: { plan }
|
|
32504
|
+
})
|
|
32505
|
+
);
|
|
32506
|
+
const readContextWindow = (promptResponse) => grokContextWindow(promptResponse, initializeResult);
|
|
32507
|
+
const turnUsage = createGrokTurnUsageCollector(grokPromptSettlement, readContextWindow);
|
|
32142
32508
|
const mcpToolHooks = createGrokMcpToolHooks(input2.mcpServers);
|
|
32143
32509
|
const executor = createAcpExecutor({
|
|
32144
32510
|
readable,
|
|
@@ -32152,10 +32518,8 @@ var createGrokInstance = (config2, host) => {
|
|
|
32152
32518
|
clientInfo: GROK_CLIENT_INFO,
|
|
32153
32519
|
log: host.log,
|
|
32154
32520
|
// agent 自己宣告的斜杠命令按会话报给宿主,输入区的 / 菜单才有它们。
|
|
32155
|
-
|
|
32156
|
-
|
|
32157
|
-
slashCommands: acpCommandsToSlashCommands(commands)
|
|
32158
|
-
}),
|
|
32521
|
+
// 压缩也走宣告的命令:起会话前先报压不了,宣告了 compact 再放开。
|
|
32522
|
+
onAvailableCommands: acpCompactingSessionCommands(host, input2.threadId),
|
|
32159
32523
|
// 等 `initialize` 回来再挑认证方式:能不能用 `cached_token`,只有 agent
|
|
32160
32524
|
// 播报的 `authMethods` 说了算(见 resolveGrokAuthMethodId)。
|
|
32161
32525
|
authMethodId: resolveGrokAuthMethodId,
|
|
@@ -32167,20 +32531,23 @@ var createGrokInstance = (config2, host) => {
|
|
|
32167
32531
|
queuesPromptsWhileRunning: true,
|
|
32168
32532
|
modelDefaultEffort: grokModelDefaultEffort,
|
|
32169
32533
|
// 派发子 agent 的调用由子 agent 名单接管,不再画成普通工具。
|
|
32170
|
-
onToolCallUpdated: (update) =>
|
|
32171
|
-
|
|
32172
|
-
|
|
32173
|
-
|
|
32174
|
-
|
|
32175
|
-
|
|
32176
|
-
|
|
32177
|
-
|
|
32178
|
-
|
|
32179
|
-
|
|
32180
|
-
|
|
32181
|
-
|
|
32182
|
-
|
|
32183
|
-
|
|
32534
|
+
onToolCallUpdated: (update) => {
|
|
32535
|
+
todoPlan.observe(update);
|
|
32536
|
+
return {
|
|
32537
|
+
events: buildGrokBackgroundTaskEvents({
|
|
32538
|
+
tasks: backgroundTasks,
|
|
32539
|
+
toolCallId: update.toolCallId,
|
|
32540
|
+
rawInput: update.rawInput,
|
|
32541
|
+
rawOutput: update.rawOutput,
|
|
32542
|
+
toolCallStatus: update.status,
|
|
32543
|
+
turnId: update.turnId
|
|
32544
|
+
}),
|
|
32545
|
+
artifacts: grokImageArtifacts(update.rawOutput),
|
|
32546
|
+
...subagents.handlesToolCall(update) ? { handled: true } : {}
|
|
32547
|
+
};
|
|
32548
|
+
},
|
|
32549
|
+
// 子 agent 名单、CLI 自己重试提示与 `turn_completed.usage` 幂等备份。
|
|
32550
|
+
...grokObservationHooks(subagents, turnUsage.observeEnvelope),
|
|
32184
32551
|
onSessionEnded: () => [
|
|
32185
32552
|
...subagents.onSessionEnded(),
|
|
32186
32553
|
...settleGrokBackgroundTasks(backgroundTasks)
|
|
@@ -32207,16 +32574,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
32207
32574
|
}
|
|
32208
32575
|
return makeXAiAskUserQuestionResponse(parsed, resolution.answers);
|
|
32209
32576
|
},
|
|
32210
|
-
readContextWindow: ({ promptResponse }) =>
|
|
32211
|
-
const usage = grokPromptUsage(promptResponse);
|
|
32212
|
-
if (usage === void 0) return void 0;
|
|
32213
|
-
const models = grokAdvertisedModels(initializeResult);
|
|
32214
|
-
const matched = models.find((model) => model.modelId === usage.modelId);
|
|
32215
|
-
return {
|
|
32216
|
-
usedTokens: usage.usedTokens,
|
|
32217
|
-
...matched?.contextWindow === void 0 ? {} : { maxTokens: matched.contextWindow }
|
|
32218
|
-
};
|
|
32219
|
-
}
|
|
32577
|
+
readContextWindow: ({ promptResponse }) => readContextWindow(promptResponse)
|
|
32220
32578
|
},
|
|
32221
32579
|
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
32222
32580
|
refreshCatalogForSend: () => modelCatalog.refreshForSend(),
|
|
@@ -32235,7 +32593,11 @@ var createGrokInstance = (config2, host) => {
|
|
|
32235
32593
|
handle,
|
|
32236
32594
|
signal,
|
|
32237
32595
|
log: host.log,
|
|
32238
|
-
emit: async (event) =>
|
|
32596
|
+
emit: async (event) => {
|
|
32597
|
+
for (const out of await turnUsage.attach(event)) {
|
|
32598
|
+
input2.events.emit(out);
|
|
32599
|
+
}
|
|
32600
|
+
},
|
|
32239
32601
|
afterStart: (started) => {
|
|
32240
32602
|
initializeResult = started.initializeResult;
|
|
32241
32603
|
},
|
|
@@ -32248,13 +32610,13 @@ var createGrokInstance = (config2, host) => {
|
|
|
32248
32610
|
bindingGeneration: input2.bindingGeneration,
|
|
32249
32611
|
resumeSchemaVersion: RESUME_SCHEMA_VERSION
|
|
32250
32612
|
},
|
|
32251
|
-
booked: (base) => ({ ...base, spawned }),
|
|
32613
|
+
booked: (base) => ({ ...base, spawned, turnUsage }),
|
|
32252
32614
|
afterRegister: () => {
|
|
32253
32615
|
const caveat = grokRuntimeModeCaveat(permissionMode);
|
|
32254
32616
|
if (caveat !== void 0) {
|
|
32255
32617
|
input2.events.emit({
|
|
32256
32618
|
type: "runtime.warning",
|
|
32257
|
-
eventId:
|
|
32619
|
+
eventId: NodeCrypto6.randomUUID(),
|
|
32258
32620
|
provider: GROK_DRIVER_KIND,
|
|
32259
32621
|
providerInstanceId: host.instanceId,
|
|
32260
32622
|
threadId: input2.threadId,
|
|
@@ -32274,7 +32636,19 @@ var createGrokInstance = (config2, host) => {
|
|
|
32274
32636
|
}
|
|
32275
32637
|
});
|
|
32276
32638
|
},
|
|
32277
|
-
|
|
32639
|
+
// 用户点名的技能翻成 CLI 原生 `/name`(实测见 grokSkillDispatch);其余提及补回指示行。
|
|
32640
|
+
// 名片声明了 handlesSkillInvocations,宿主的 inputPreamble 只在这里拼回正文,漏了就整段丢。
|
|
32641
|
+
sendTurn: (input2, signal) => threadOps.sendTurn(
|
|
32642
|
+
{
|
|
32643
|
+
...input2,
|
|
32644
|
+
input: dispatchGrokSkills(
|
|
32645
|
+
input2.input ?? "",
|
|
32646
|
+
sessionSkillNames.get(input2.threadId) ?? [],
|
|
32647
|
+
input2.inputPreamble
|
|
32648
|
+
)
|
|
32649
|
+
},
|
|
32650
|
+
signal
|
|
32651
|
+
),
|
|
32278
32652
|
interruptTurn: threadOps.interruptTurn,
|
|
32279
32653
|
openCommandProcesses: async (threadId) => {
|
|
32280
32654
|
const booked = threads.get(threadId);
|
|
@@ -32288,13 +32662,15 @@ var createGrokInstance = (config2, host) => {
|
|
|
32288
32662
|
respondToRequest: threadOps.respondToRequest,
|
|
32289
32663
|
respondToUserInput: threadOps.respondToUserInput,
|
|
32290
32664
|
// 原生压缩:让 CLI 执行它自己宣告的 `/compact`。这不是用户消息——执行器不开轮次、
|
|
32291
|
-
//
|
|
32665
|
+
// 不把命令吐的文本放进时间线,进度与结果只走压缩生命周期事件;其 prompt 用量不归入下一轮。
|
|
32292
32666
|
compactContext: async (threadId) => {
|
|
32293
32667
|
const booked = requireThread(threadId);
|
|
32294
32668
|
if (booked.executor.status === "running") {
|
|
32295
32669
|
throw new Error("Cannot compact context while a turn is running");
|
|
32296
32670
|
}
|
|
32297
|
-
await booked.
|
|
32671
|
+
await booked.turnUsage.runNonTurnPrompt(
|
|
32672
|
+
() => booked.executor.compact({ commandName: ACP_COMPACT_COMMAND })
|
|
32673
|
+
);
|
|
32298
32674
|
},
|
|
32299
32675
|
stopSession: (threadId) => stopSession(threadId),
|
|
32300
32676
|
readThread: threadOps.readThread,
|
|
@@ -32315,6 +32691,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
32315
32691
|
};
|
|
32316
32692
|
|
|
32317
32693
|
// src/index.ts
|
|
32694
|
+
var readAttachment;
|
|
32318
32695
|
var executors = [
|
|
32319
32696
|
{
|
|
32320
32697
|
card: GROK_CARD,
|
|
@@ -32326,7 +32703,11 @@ var executors = [
|
|
|
32326
32703
|
],
|
|
32327
32704
|
createInstance: async (config2, host) => {
|
|
32328
32705
|
host.log.info("createInstance");
|
|
32329
|
-
return createGrokInstance(
|
|
32706
|
+
return createGrokInstance(
|
|
32707
|
+
config2,
|
|
32708
|
+
host,
|
|
32709
|
+
readAttachment === void 0 ? {} : { readAttachment }
|
|
32710
|
+
);
|
|
32330
32711
|
},
|
|
32331
32712
|
probeAccount: async ({ accountPath }) => probeGrokAccount(accountPath)
|
|
32332
32713
|
}
|
|
@@ -32336,6 +32717,7 @@ var index_default = definePlugin({
|
|
|
32336
32717
|
apiVersion: PLUGIN_API_VERSION,
|
|
32337
32718
|
executors,
|
|
32338
32719
|
activate(ctx) {
|
|
32720
|
+
readAttachment = ctx.attachments?.read;
|
|
32339
32721
|
registerEffectiveHomeCommand(
|
|
32340
32722
|
ctx,
|
|
32341
32723
|
GROK_CARD.homeEnvVar,
|