@ycodium-ai/agent-grok 0.2.5634 → 0.2.5763
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +255 -617
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -8,108 +8,13 @@ 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 = 181;
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
import
|
|
15
|
-
import * as NodeOS from "node:os";
|
|
16
|
-
import * as NodePath from "node:path";
|
|
17
|
-
import {
|
|
18
|
-
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
19
|
-
executorHomeEffectiveValue,
|
|
20
|
-
readExecutorEffectiveRequest,
|
|
21
|
-
mergeLaunchEnv
|
|
22
|
-
} from "@ycodium-ai/plugin-api/executor";
|
|
23
|
-
function instanceAccountDirectory(pluginDataDir, instanceId) {
|
|
24
|
-
return NodePath.join(
|
|
25
|
-
pluginDataDir,
|
|
26
|
-
"profiles",
|
|
27
|
-
NodeCrypto.createHash("sha256").update(instanceId).digest("hex")
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function privateHomeFor(config2, env, variable, dataDir, id) {
|
|
31
|
-
if (config2.privateAccount !== true || typeof config2.homePath === "string" && config2.homePath.trim() || env[variable]?.trim() || !id)
|
|
32
|
-
return void 0;
|
|
33
|
-
if (!dataDir) throw new Error("Executor plugin data directory unavailable");
|
|
34
|
-
return instanceAccountDirectory(dataDir, id);
|
|
35
|
-
}
|
|
36
|
-
function expandHomePath(value) {
|
|
37
|
-
if (value === "~") return NodeOS.homedir();
|
|
38
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
39
|
-
return NodePath.join(NodeOS.homedir(), value.slice(2));
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
function registerEffectiveHomeCommand(ctx, homeEnvVar, resolve4, profileDataDir) {
|
|
44
|
-
ctx.command({
|
|
45
|
-
name: "effectiveConfig",
|
|
46
|
-
description: "Settings form: the account directory an empty path resolves to on this machine.",
|
|
47
|
-
scope: "read",
|
|
48
|
-
payloadSchema: EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
49
|
-
handle: async (payload) => {
|
|
50
|
-
const req = readExecutorEffectiveRequest(payload);
|
|
51
|
-
if (profileDataDir && req.config.privateAccount === true && !req.instanceId && !req.environment[homeEnvVar]?.trim() && !req.config.homePath)
|
|
52
|
-
return {};
|
|
53
|
-
const home = profileDataDir && privateHomeFor(req.config, req.environment, homeEnvVar, profileDataDir, req.instanceId);
|
|
54
|
-
return {
|
|
55
|
-
homePath: home ? { value: home, detailKey: "form.effective.default" } : executorHomeEffectiveValue(homeEnvVar, req, process.env, resolve4)
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ../../packages/ycodium-instance-config/src/programHomeSchema.ts
|
|
62
|
-
var executorEnvelopeFields = {
|
|
63
|
-
enabled: { type: "boolean" },
|
|
64
|
-
customModels: { type: "array" },
|
|
65
|
-
driver: { type: "string" },
|
|
66
|
-
config: { type: "object" },
|
|
67
|
-
environment: { type: "array" }
|
|
68
|
-
};
|
|
69
|
-
function executorProgramField(name, options = {}) {
|
|
70
|
-
return {
|
|
71
|
-
type: "string",
|
|
72
|
-
"x-ycodium-form": {
|
|
73
|
-
titleKey: `form.${name}.title`,
|
|
74
|
-
...options.description === false ? {} : { descriptionKey: `form.${name}.description` },
|
|
75
|
-
...options.placeholder === false ? {} : { placeholderKey: `form.${name}.placeholder` },
|
|
76
|
-
...name === "binaryPath" ? { control: options.control ?? "executable-path" } : {},
|
|
77
|
-
...name === "homePath" || options.machineLocal ? { machineLocal: true } : {}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function programAndHomeConfigSchema(binaryPath) {
|
|
82
|
-
return {
|
|
83
|
-
type: "object",
|
|
84
|
-
...binaryPath.privateAccountOption ? { "x-ycodium-new-instance-defaults": { privateAccount: true } } : {},
|
|
85
|
-
"x-ycodium-form-order": [
|
|
86
|
-
"binaryPath",
|
|
87
|
-
"homePath",
|
|
88
|
-
...binaryPath.privateAccountOption ? ["privateAccount"] : []
|
|
89
|
-
],
|
|
90
|
-
properties: {
|
|
91
|
-
...executorEnvelopeFields,
|
|
92
|
-
binaryPath: executorProgramField("binaryPath", {
|
|
93
|
-
control: binaryPath.control,
|
|
94
|
-
machineLocal: binaryPath.machineLocal === true
|
|
95
|
-
}),
|
|
96
|
-
homePath: executorProgramField("homePath"),
|
|
97
|
-
...binaryPath.privateAccountOption ? {
|
|
98
|
-
privateAccount: {
|
|
99
|
-
type: "boolean",
|
|
100
|
-
default: false,
|
|
101
|
-
"x-ycodium-form": {
|
|
102
|
-
titleKey: "form.privateAccount.title",
|
|
103
|
-
descriptionKey: "form.privateAccount.description"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} : {}
|
|
107
|
-
},
|
|
108
|
-
additionalProperties: true
|
|
109
|
-
};
|
|
110
|
-
}
|
|
13
|
+
// src/index.ts
|
|
14
|
+
import { registerEffectiveHomeCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
111
15
|
|
|
112
16
|
// src/card.ts
|
|
17
|
+
import { programAndHomeConfigSchema } from "@ycodium-ai/plugin-api/instance-config";
|
|
113
18
|
var GROK_DRIVER_KIND = "grok";
|
|
114
19
|
var GROK_CLIENT_INFO = { name: "ycodium-agent-grok", version: "0.1.0" };
|
|
115
20
|
var GROK_CARD = {
|
|
@@ -244,66 +149,33 @@ var GROK_CARD = {
|
|
|
244
149
|
};
|
|
245
150
|
|
|
246
151
|
// src/grokHome.ts
|
|
247
|
-
import * as
|
|
248
|
-
import * as
|
|
249
|
-
import * as NodePath3 from "node:path";
|
|
250
|
-
import { mergeLaunchEnv as mergeLaunchEnv2 } from "@ycodium-ai/plugin-api/executor";
|
|
251
|
-
|
|
252
|
-
// src/grokAccount.ts
|
|
152
|
+
import * as NodeCrypto from "node:crypto";
|
|
153
|
+
import * as NodeOS from "node:os";
|
|
253
154
|
import * as NodePath2 from "node:path";
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
import * as NodeFS from "node:fs";
|
|
257
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
258
|
-
var readTrimmedString = (record4, key) => {
|
|
259
|
-
const value = record4[key];
|
|
260
|
-
if (typeof value !== "string") return void 0;
|
|
261
|
-
const trimmed3 = value.trim();
|
|
262
|
-
return trimmed3.length > 0 ? trimmed3 : void 0;
|
|
263
|
-
};
|
|
264
|
-
var parseJsonRecord = (raw) => {
|
|
265
|
-
let parsed;
|
|
266
|
-
try {
|
|
267
|
-
parsed = JSON.parse(raw);
|
|
268
|
-
} catch {
|
|
269
|
-
return void 0;
|
|
270
|
-
}
|
|
271
|
-
return isRecord(parsed) ? parsed : void 0;
|
|
272
|
-
};
|
|
273
|
-
var directoryExists = (homePath) => {
|
|
274
|
-
try {
|
|
275
|
-
return NodeFS.statSync(homePath).isDirectory();
|
|
276
|
-
} catch {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
var readCredentialFile = (path) => {
|
|
281
|
-
try {
|
|
282
|
-
return NodeFS.readFileSync(path, "utf8");
|
|
283
|
-
} catch {
|
|
284
|
-
return void 0;
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
var accountWithoutIdentity = (state, exists) => ({
|
|
288
|
-
state,
|
|
289
|
-
directoryExists: exists,
|
|
290
|
-
email: void 0,
|
|
291
|
-
name: void 0,
|
|
292
|
-
expiresAt: void 0
|
|
293
|
-
});
|
|
155
|
+
import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
|
|
156
|
+
import { expandHomePath } from "@ycodium-ai/plugin-api/instance-config";
|
|
294
157
|
|
|
295
158
|
// src/grokAccount.ts
|
|
159
|
+
import * as NodePath from "node:path";
|
|
160
|
+
import {
|
|
161
|
+
accountWithoutIdentity,
|
|
162
|
+
directoryExists,
|
|
163
|
+
isRecord,
|
|
164
|
+
parseJsonRecord,
|
|
165
|
+
readCredentialFile,
|
|
166
|
+
readTrimmedString as readString
|
|
167
|
+
} from "@ycodium-ai/plugin-api/credential-account";
|
|
296
168
|
var AUTH_FILE_NAME = "auth.json";
|
|
297
169
|
var joinName = (record4) => {
|
|
298
|
-
const first =
|
|
299
|
-
const last =
|
|
170
|
+
const first = readString(record4, "first_name");
|
|
171
|
+
const last = readString(record4, "last_name");
|
|
300
172
|
const joined = [first, last].filter((part) => part !== void 0).join(" ");
|
|
301
173
|
return joined.length > 0 ? joined : void 0;
|
|
302
174
|
};
|
|
303
175
|
var findIdentityEntry = (parsed) => {
|
|
304
176
|
for (const value of Object.values(parsed)) {
|
|
305
177
|
if (!isRecord(value)) continue;
|
|
306
|
-
if (
|
|
178
|
+
if (readString(value, "email") !== void 0 || readString(value, "user_id") !== void 0) {
|
|
307
179
|
return value;
|
|
308
180
|
}
|
|
309
181
|
}
|
|
@@ -316,16 +188,16 @@ var isExpired = (expiresAt, nowMs) => {
|
|
|
316
188
|
};
|
|
317
189
|
var readGrokAccount = (homePath) => {
|
|
318
190
|
const exists = directoryExists(homePath);
|
|
319
|
-
const raw = readCredentialFile(
|
|
191
|
+
const raw = readCredentialFile(NodePath.join(homePath, AUTH_FILE_NAME));
|
|
320
192
|
if (raw === void 0) return accountWithoutIdentity("signed-out", exists);
|
|
321
193
|
const parsed = parseJsonRecord(raw);
|
|
322
194
|
const identity = parsed === void 0 ? void 0 : findIdentityEntry(parsed);
|
|
323
195
|
if (identity === void 0) return accountWithoutIdentity("unreadable", exists);
|
|
324
|
-
const expiresAt =
|
|
196
|
+
const expiresAt = readString(identity, "expires_at");
|
|
325
197
|
return {
|
|
326
198
|
state: isExpired(expiresAt, Date.now()) ? "expired" : "signed-in",
|
|
327
199
|
directoryExists: exists,
|
|
328
|
-
email:
|
|
200
|
+
email: readString(identity, "email"),
|
|
329
201
|
name: joinName(identity),
|
|
330
202
|
expiresAt
|
|
331
203
|
};
|
|
@@ -334,8 +206,8 @@ var readGrokAccount = (homePath) => {
|
|
|
334
206
|
// src/grokHome.ts
|
|
335
207
|
function resolveGrokHomePath(value) {
|
|
336
208
|
const trimmed3 = value.trim();
|
|
337
|
-
if (trimmed3.length === 0) return
|
|
338
|
-
return
|
|
209
|
+
if (trimmed3.length === 0) return NodePath2.join(NodeOS.homedir(), ".grok");
|
|
210
|
+
return NodePath2.resolve(expandHomePath(trimmed3));
|
|
339
211
|
}
|
|
340
212
|
function probeGrokAccount(accountPath) {
|
|
341
213
|
const resolved = resolveGrokHomePath(accountPath);
|
|
@@ -354,14 +226,14 @@ function grokContinuationKey(recipe) {
|
|
|
354
226
|
function resolveAccountHomePath(recipe, configuredHome) {
|
|
355
227
|
const fromEnvironment = recipe.environment["GROK_HOME"]?.trim();
|
|
356
228
|
if (fromEnvironment !== void 0 && fromEnvironment.length > 0) {
|
|
357
|
-
return
|
|
229
|
+
return NodePath2.resolve(expandHomePath(fromEnvironment));
|
|
358
230
|
}
|
|
359
231
|
return resolveGrokHomePath(configuredHome);
|
|
360
232
|
}
|
|
361
233
|
function absentPath() {
|
|
362
|
-
return
|
|
363
|
-
|
|
364
|
-
`ycodium-grok-no-auth-${
|
|
234
|
+
return NodePath2.join(
|
|
235
|
+
NodeOS.tmpdir(),
|
|
236
|
+
`ycodium-grok-no-auth-${NodeCrypto.randomUUID()}`,
|
|
365
237
|
"auth.json"
|
|
366
238
|
);
|
|
367
239
|
}
|
|
@@ -378,7 +250,7 @@ function ownEndpointAuthGuard(recipe) {
|
|
|
378
250
|
function buildSignInEnv(recipe) {
|
|
379
251
|
const configuredHome = recipe.homePath;
|
|
380
252
|
const homeInjection = configuredHome.trim().length > 0 ? { [GROK_CARD.homeEnvVar]: resolveGrokHomePath(configuredHome) } : {};
|
|
381
|
-
return
|
|
253
|
+
return mergeLaunchEnv({
|
|
382
254
|
accountHome: homeInjection,
|
|
383
255
|
instanceTable: recipe.environment,
|
|
384
256
|
handOverrides: { GROK_OAUTH2_REFERRER: "ycodium" }
|
|
@@ -386,58 +258,23 @@ function buildSignInEnv(recipe) {
|
|
|
386
258
|
}
|
|
387
259
|
function buildSpawnEnv(recipe, resolvedHomePath, homeConfigured) {
|
|
388
260
|
const homeInjection = homeConfigured ? { [GROK_CARD.homeEnvVar]: resolvedHomePath } : {};
|
|
389
|
-
return
|
|
261
|
+
return mergeLaunchEnv({
|
|
390
262
|
accountHome: { ...homeInjection, ...ownEndpointAuthGuard(recipe) },
|
|
391
263
|
instanceTable: recipe.environment,
|
|
392
264
|
handOverrides: { GROK_OAUTH2_REFERRER: "ycodium" }
|
|
393
265
|
});
|
|
394
266
|
}
|
|
395
267
|
|
|
396
|
-
// ../../packages/ycodium-jsonl-stream/src/sessionTranscript.ts
|
|
397
|
-
var SESSION_IMPORT_ACTIVITY_TEXT_LIMIT = 32e3;
|
|
398
|
-
function bounded(value, tail = false) {
|
|
399
|
-
if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
|
|
400
|
-
const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
|
|
401
|
-
const character = value.charCodeAt(offset);
|
|
402
|
-
const previous = value.charCodeAt(offset - 1);
|
|
403
|
-
const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
|
|
404
|
-
return {
|
|
405
|
-
text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
|
|
406
|
-
truncated: true
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
function inputPayload(input2) {
|
|
410
|
-
if (input2 === void 0) return {};
|
|
411
|
-
const result = bounded(input2);
|
|
412
|
-
return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
|
|
413
|
-
}
|
|
414
|
-
function outputPayload(output2) {
|
|
415
|
-
if (output2 === void 0) return {};
|
|
416
|
-
const result = bounded(output2, true);
|
|
417
|
-
return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
|
|
418
|
-
}
|
|
419
|
-
function sessionReadFromImport(nativeSessionId, imported) {
|
|
420
|
-
return {
|
|
421
|
-
nativeSessionId,
|
|
422
|
-
model: imported.model,
|
|
423
|
-
resumeCursor: imported.resumeCursor,
|
|
424
|
-
messages: imported.messages.map(({ role, text: text4, createdAt }) => ({
|
|
425
|
-
role,
|
|
426
|
-
text: text4,
|
|
427
|
-
createdAt: Date.parse(createdAt)
|
|
428
|
-
}))
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
|
|
432
268
|
// src/grokInstance.ts
|
|
433
|
-
import
|
|
269
|
+
import { sessionReadFromImport } from "@ycodium-ai/plugin-api/session-history";
|
|
270
|
+
import * as NodeCrypto3 from "node:crypto";
|
|
434
271
|
import {
|
|
435
272
|
raceAbort as raceAbort2
|
|
436
273
|
} from "@ycodium-ai/plugin-api/executor";
|
|
437
274
|
import { nodeStreamsFromHandle as nodeStreamsFromHandle2 } from "@ycodium-ai/plugin-api/process-stdin";
|
|
438
275
|
|
|
439
276
|
// ../../packages/ycodium-acp-executor/src/executor.ts
|
|
440
|
-
import * as
|
|
277
|
+
import * as NodeCrypto2 from "node:crypto";
|
|
441
278
|
|
|
442
279
|
// ../../packages/ycodium-acp-executor/src/approvals.ts
|
|
443
280
|
function createApprovalGate(input2) {
|
|
@@ -551,8 +388,8 @@ var UnboundedEventStream = class {
|
|
|
551
388
|
iterators.subscribers.delete(subscriber);
|
|
552
389
|
return { value: void 0, done: true };
|
|
553
390
|
}
|
|
554
|
-
await new Promise((
|
|
555
|
-
subscriber.wake =
|
|
391
|
+
await new Promise((resolve2) => {
|
|
392
|
+
subscriber.wake = resolve2;
|
|
556
393
|
});
|
|
557
394
|
}
|
|
558
395
|
},
|
|
@@ -778,8 +615,8 @@ var settledExitCode = async (exited) => {
|
|
|
778
615
|
try {
|
|
779
616
|
return await Promise.race([
|
|
780
617
|
exited.catch(() => void 0),
|
|
781
|
-
new Promise((
|
|
782
|
-
timer = setTimeout(() =>
|
|
618
|
+
new Promise((resolve2) => {
|
|
619
|
+
timer = setTimeout(() => resolve2(void 0), AGENT_EXIT_SETTLE_MS);
|
|
783
620
|
})
|
|
784
621
|
]);
|
|
785
622
|
} finally {
|
|
@@ -1119,15 +956,15 @@ function boundToolCallRawOutput(rawOutput) {
|
|
|
1119
956
|
return rawOutput;
|
|
1120
957
|
}
|
|
1121
958
|
let changed = false;
|
|
1122
|
-
const
|
|
959
|
+
const bounded = { ...rawOutput };
|
|
1123
960
|
for (const field of RAW_OUTPUT_TEXT_FIELDS) {
|
|
1124
961
|
const value = rawOutput[field];
|
|
1125
962
|
if (typeof value === "string" && value.length > TOOL_CALL_CONTENT_MAX_CHARS) {
|
|
1126
|
-
|
|
963
|
+
bounded[field] = boundToolCallOutputText(value);
|
|
1127
964
|
changed = true;
|
|
1128
965
|
}
|
|
1129
966
|
}
|
|
1130
|
-
return changed ?
|
|
967
|
+
return changed ? bounded : rawOutput;
|
|
1131
968
|
}
|
|
1132
969
|
function toolCallContentText(entry) {
|
|
1133
970
|
if (entry.type !== "content" || entry.content?.type !== "text") {
|
|
@@ -1154,7 +991,7 @@ function extractTextContentFromToolCallContent(content) {
|
|
|
1154
991
|
if (joined.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
|
|
1155
992
|
return { text: joined, content: typed };
|
|
1156
993
|
}
|
|
1157
|
-
const
|
|
994
|
+
const bounded = boundToolCallOutputText(joined);
|
|
1158
995
|
const lastContributingTextIndex = typed.reduce(
|
|
1159
996
|
(lastIndex, entry, index) => toolCallContentText(entry)?.trim() ? index : lastIndex,
|
|
1160
997
|
-1
|
|
@@ -1166,9 +1003,9 @@ function extractTextContentFromToolCallContent(content) {
|
|
|
1166
1003
|
if (index !== lastContributingTextIndex) {
|
|
1167
1004
|
return [];
|
|
1168
1005
|
}
|
|
1169
|
-
return [{ type: "content", content: { type: "text", text:
|
|
1006
|
+
return [{ type: "content", content: { type: "text", text: bounded } }];
|
|
1170
1007
|
});
|
|
1171
|
-
return { text:
|
|
1008
|
+
return { text: bounded, content: boundedContent };
|
|
1172
1009
|
}
|
|
1173
1010
|
function normalizeToolKind(kind) {
|
|
1174
1011
|
return typeof kind === "string" && kind.trim().length > 0 ? kind.trim() : void 0;
|
|
@@ -3745,18 +3582,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
3745
3582
|
return result.issues.length === 0;
|
|
3746
3583
|
};
|
|
3747
3584
|
var _encode = (_Err) => {
|
|
3748
|
-
const
|
|
3585
|
+
const parse3 = _parse(_Err);
|
|
3749
3586
|
const fn = (schema, value, _ctx, _params) => {
|
|
3750
3587
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
3751
|
-
return
|
|
3588
|
+
return parse3(schema, value, ctx, finalizeParams(fn, _params));
|
|
3752
3589
|
};
|
|
3753
3590
|
return fn;
|
|
3754
3591
|
};
|
|
3755
3592
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
3756
3593
|
var _decode = (_Err) => {
|
|
3757
|
-
const
|
|
3594
|
+
const parse3 = _parse(_Err);
|
|
3758
3595
|
const fn = (schema, value, _ctx, _params) => {
|
|
3759
|
-
return
|
|
3596
|
+
return parse3(schema, value, _ctx, finalizeParams(fn, _params));
|
|
3760
3597
|
};
|
|
3761
3598
|
return fn;
|
|
3762
3599
|
};
|
|
@@ -6926,7 +6763,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6926
6763
|
var NONE = 0;
|
|
6927
6764
|
var ASSUMED = 1;
|
|
6928
6765
|
var PROVEN = 2;
|
|
6929
|
-
function isRecursive(inst, stack,
|
|
6766
|
+
function isRecursive(inst, stack, resolve2) {
|
|
6930
6767
|
const cached2 = recursive.get(inst);
|
|
6931
6768
|
if (cached2 !== void 0)
|
|
6932
6769
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6936,7 +6773,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
6936
6773
|
let result = NONE;
|
|
6937
6774
|
const check2 = (child) => {
|
|
6938
6775
|
if (result !== PROVEN && child?._zod) {
|
|
6939
|
-
const answer = isRecursive(child, stack,
|
|
6776
|
+
const answer = isRecursive(child, stack, resolve2);
|
|
6940
6777
|
if (answer > result)
|
|
6941
6778
|
result = answer;
|
|
6942
6779
|
}
|
|
@@ -6947,7 +6784,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
6947
6784
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6948
6785
|
if (spread && !desc.enumerable)
|
|
6949
6786
|
continue;
|
|
6950
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6787
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve2) : NONE;
|
|
6951
6788
|
if (child > answer)
|
|
6952
6789
|
answer = child;
|
|
6953
6790
|
}
|
|
@@ -7011,7 +6848,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
7011
6848
|
break;
|
|
7012
6849
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
7013
6850
|
case "lazy": {
|
|
7014
|
-
const inner = def._cachedInner ?? (
|
|
6851
|
+
const inner = def._cachedInner ?? (resolve2 ? inst._zod.innerType : void 0);
|
|
7015
6852
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
7016
6853
|
break;
|
|
7017
6854
|
}
|
|
@@ -23675,11 +23512,11 @@ var Connection = class {
|
|
|
23675
23512
|
const id = this.nextRequestId++;
|
|
23676
23513
|
let cancel = () => {
|
|
23677
23514
|
};
|
|
23678
|
-
const response = new Promise((
|
|
23515
|
+
const response = new Promise((resolve2, reject) => {
|
|
23679
23516
|
const pendingResponse = {
|
|
23680
23517
|
resolve: (value) => {
|
|
23681
23518
|
try {
|
|
23682
|
-
|
|
23519
|
+
resolve2(mapResponse ? mapResponse(value) : value);
|
|
23683
23520
|
} catch (error62) {
|
|
23684
23521
|
reject(error62);
|
|
23685
23522
|
}
|
|
@@ -23736,8 +23573,8 @@ var Connection = class {
|
|
|
23736
23573
|
this.stream = stream;
|
|
23737
23574
|
this.staticHandlers = handlers;
|
|
23738
23575
|
this.allowBatches = options?.allowBatches ?? true;
|
|
23739
|
-
this.closedPromise = new Promise((
|
|
23740
|
-
this.abortController.signal.addEventListener("abort", () =>
|
|
23576
|
+
this.closedPromise = new Promise((resolve2) => {
|
|
23577
|
+
this.abortController.signal.addEventListener("abort", () => resolve2());
|
|
23741
23578
|
});
|
|
23742
23579
|
void this.receive();
|
|
23743
23580
|
}
|
|
@@ -24028,13 +23865,13 @@ var ConnectionBuilder = class {
|
|
|
24028
23865
|
/**
|
|
24029
23866
|
* Adds a typed request handler for one method.
|
|
24030
23867
|
*/
|
|
24031
|
-
onReceiveRequest(method,
|
|
23868
|
+
onReceiveRequest(method, parse3, handler) {
|
|
24032
23869
|
return this.withHandler({
|
|
24033
23870
|
handleMessage: async (message, cx) => {
|
|
24034
23871
|
if (message.kind !== "request" || message.method !== method) {
|
|
24035
23872
|
return Handled.no(message);
|
|
24036
23873
|
}
|
|
24037
|
-
const request =
|
|
23874
|
+
const request = parse3(message.params);
|
|
24038
23875
|
return await handler(request, message.responder, cx) ?? Handled.yes();
|
|
24039
23876
|
},
|
|
24040
23877
|
describe: () => `${this.connectionName ?? "request"}:${method}`
|
|
@@ -24043,13 +23880,13 @@ var ConnectionBuilder = class {
|
|
|
24043
23880
|
/**
|
|
24044
23881
|
* Adds a typed notification handler for one method.
|
|
24045
23882
|
*/
|
|
24046
|
-
onReceiveNotification(method,
|
|
23883
|
+
onReceiveNotification(method, parse3, handler) {
|
|
24047
23884
|
return this.withHandler({
|
|
24048
23885
|
handleMessage: async (message, cx) => {
|
|
24049
23886
|
if (message.kind !== "notification" || message.method !== method) {
|
|
24050
23887
|
return Handled.no(message);
|
|
24051
23888
|
}
|
|
24052
|
-
const notification =
|
|
23889
|
+
const notification = parse3(message.params);
|
|
24053
23890
|
return await handler(notification, cx) ?? Handled.yes();
|
|
24054
23891
|
},
|
|
24055
23892
|
describe: () => `${this.connectionName ?? "notification"}:${method}`
|
|
@@ -24631,8 +24468,8 @@ var AsyncQueue = class {
|
|
|
24631
24468
|
if (this.failed) {
|
|
24632
24469
|
return Promise.reject(this.failure);
|
|
24633
24470
|
}
|
|
24634
|
-
return new Promise((
|
|
24635
|
-
this.waiters.push({ resolve:
|
|
24471
|
+
return new Promise((resolve2, reject) => {
|
|
24472
|
+
this.waiters.push({ resolve: resolve2, reject });
|
|
24636
24473
|
});
|
|
24637
24474
|
}
|
|
24638
24475
|
};
|
|
@@ -25679,12 +25516,12 @@ function createAcpConnection(options) {
|
|
|
25679
25516
|
failIfClosed();
|
|
25680
25517
|
const id = nextRequestId;
|
|
25681
25518
|
nextRequestId += 1;
|
|
25682
|
-
const { promise: promise2, resolve:
|
|
25519
|
+
const { promise: promise2, resolve: resolve2, reject } = Promise.withResolvers();
|
|
25683
25520
|
pending.set(String(id), {
|
|
25684
25521
|
method,
|
|
25685
25522
|
...promptId === void 0 ? {} : { promptId },
|
|
25686
25523
|
...onArrival === void 0 ? {} : { onArrival },
|
|
25687
|
-
resolve:
|
|
25524
|
+
resolve: resolve2,
|
|
25688
25525
|
reject
|
|
25689
25526
|
});
|
|
25690
25527
|
const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
@@ -25713,8 +25550,8 @@ function createAcpConnection(options) {
|
|
|
25713
25550
|
if (inboundBatches === 0) {
|
|
25714
25551
|
return;
|
|
25715
25552
|
}
|
|
25716
|
-
await new Promise((
|
|
25717
|
-
idleWaiters.push(
|
|
25553
|
+
await new Promise((resolve2) => {
|
|
25554
|
+
idleWaiters.push(resolve2);
|
|
25718
25555
|
if (inboundBatches === 0) {
|
|
25719
25556
|
releaseIdleWaiters();
|
|
25720
25557
|
}
|
|
@@ -25800,8 +25637,8 @@ var Mutex = class {
|
|
|
25800
25637
|
this.locked = true;
|
|
25801
25638
|
return Promise.resolve();
|
|
25802
25639
|
}
|
|
25803
|
-
return new Promise((
|
|
25804
|
-
this.waiters.push(
|
|
25640
|
+
return new Promise((resolve2) => {
|
|
25641
|
+
this.waiters.push(resolve2);
|
|
25805
25642
|
});
|
|
25806
25643
|
}
|
|
25807
25644
|
tryAcquire() {
|
|
@@ -26002,9 +25839,9 @@ function createExecutorLifecycle({
|
|
|
26002
25839
|
let timer;
|
|
26003
25840
|
await Promise.race([
|
|
26004
25841
|
connection.closed.catch(() => void 0),
|
|
26005
|
-
new Promise((
|
|
25842
|
+
new Promise((resolve2) => {
|
|
26006
25843
|
timer = setTimeout(
|
|
26007
|
-
|
|
25844
|
+
resolve2,
|
|
26008
25845
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
26009
25846
|
);
|
|
26010
25847
|
})
|
|
@@ -26177,7 +26014,7 @@ function toolSubagentSettlementOfTurn(state, failureCategory) {
|
|
|
26177
26014
|
if (state === "cancelled") return "turn-interrupted";
|
|
26178
26015
|
return state === "failed" && failureCategory === "process-exit" ? "session-ended" : "turn-ended";
|
|
26179
26016
|
}
|
|
26180
|
-
var sameFacts = (a, b) => a.title === b.title && a.description === b.description && a.summary === b.summary && a.role === b.role && a.model === b.model && a.effort === b.effort && a.rosterKind === b.rosterKind;
|
|
26017
|
+
var sameFacts = (a, b) => a.title === b.title && a.description === b.description && a.summary === b.summary && a.role === b.role && a.model === b.model && a.effort === b.effort && a.nativeSessionId === b.nativeSessionId && a.rosterKind === b.rosterKind;
|
|
26181
26018
|
function linkage(taskId, toolCallId, facts) {
|
|
26182
26019
|
return {
|
|
26183
26020
|
taskId,
|
|
@@ -26187,6 +26024,7 @@ function linkage(taskId, toolCallId, facts) {
|
|
|
26187
26024
|
...facts.role === void 0 ? {} : { role: facts.role },
|
|
26188
26025
|
...facts.model === void 0 ? {} : { model: facts.model },
|
|
26189
26026
|
...facts.effort === void 0 ? {} : { effort: facts.effort },
|
|
26027
|
+
...facts.nativeSessionId === void 0 ? {} : { nativeSessionId: facts.nativeSessionId },
|
|
26190
26028
|
...facts.rosterKind === void 0 ? {} : { rosterKind: facts.rosterKind }
|
|
26191
26029
|
};
|
|
26192
26030
|
}
|
|
@@ -26881,12 +26719,12 @@ function createPromptResults({
|
|
|
26881
26719
|
}) {
|
|
26882
26720
|
const prompts = /* @__PURE__ */ new Map();
|
|
26883
26721
|
const add = (identity, finish) => {
|
|
26884
|
-
const { promise: done, resolve:
|
|
26722
|
+
const { promise: done, resolve: resolve2 } = Promise.withResolvers();
|
|
26885
26723
|
const record4 = {
|
|
26886
26724
|
...identity,
|
|
26887
26725
|
finish,
|
|
26888
26726
|
done,
|
|
26889
|
-
resolve:
|
|
26727
|
+
resolve: resolve2,
|
|
26890
26728
|
rejected: false,
|
|
26891
26729
|
interrupted: false,
|
|
26892
26730
|
finished: false
|
|
@@ -26934,9 +26772,9 @@ function createPromptResults({
|
|
|
26934
26772
|
try {
|
|
26935
26773
|
const drained = await Promise.race([
|
|
26936
26774
|
Promise.all(claimed.map((record4) => record4.done)).then(() => true),
|
|
26937
|
-
new Promise((
|
|
26775
|
+
new Promise((resolve2) => {
|
|
26938
26776
|
timer = setTimeout(
|
|
26939
|
-
() =>
|
|
26777
|
+
() => resolve2(false),
|
|
26940
26778
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
26941
26779
|
);
|
|
26942
26780
|
})
|
|
@@ -27135,14 +26973,14 @@ function createExecutorRequests({
|
|
|
27135
26973
|
const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
|
|
27136
26974
|
const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
|
|
27137
26975
|
const requestId = randomId();
|
|
27138
|
-
const outcome = await new Promise((
|
|
26976
|
+
const outcome = await new Promise((resolve2) => {
|
|
27139
26977
|
const pending = {
|
|
27140
26978
|
requestId,
|
|
27141
26979
|
request: params,
|
|
27142
26980
|
permissionRequest,
|
|
27143
26981
|
turnId: shared.activeTurnId,
|
|
27144
26982
|
settled: false,
|
|
27145
|
-
resolve:
|
|
26983
|
+
resolve: resolve2
|
|
27146
26984
|
};
|
|
27147
26985
|
approvals.add(pending);
|
|
27148
26986
|
emit(
|
|
@@ -27225,7 +27063,7 @@ function createExecutorRequests({
|
|
|
27225
27063
|
}
|
|
27226
27064
|
|
|
27227
27065
|
// ../../packages/ycodium-acp-executor/src/artifacts.ts
|
|
27228
|
-
import * as
|
|
27066
|
+
import * as NodePath3 from "node:path";
|
|
27229
27067
|
import * as NodeURL from "node:url";
|
|
27230
27068
|
function resourceLinkArtifacts(content) {
|
|
27231
27069
|
if (content["type"] !== "resource_link" || typeof content["uri"] !== "string") return [];
|
|
@@ -27236,7 +27074,7 @@ function resourceLinkArtifacts(content) {
|
|
|
27236
27074
|
} catch {
|
|
27237
27075
|
return [];
|
|
27238
27076
|
}
|
|
27239
|
-
if (!
|
|
27077
|
+
if (!NodePath3.isAbsolute(path)) return [];
|
|
27240
27078
|
const name = typeof content["name"] === "string" ? content["name"].trim() : "";
|
|
27241
27079
|
const mimeType = typeof content["mimeType"] === "string" ? content["mimeType"].trim() : "";
|
|
27242
27080
|
return [
|
|
@@ -27359,14 +27197,14 @@ function createExecutorRuntime({
|
|
|
27359
27197
|
if (!promptMutex.isLocked) {
|
|
27360
27198
|
return true;
|
|
27361
27199
|
}
|
|
27362
|
-
return await new Promise((
|
|
27200
|
+
return await new Promise((resolve2) => {
|
|
27363
27201
|
const timer = setTimeout(() => {
|
|
27364
27202
|
shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
|
|
27365
|
-
|
|
27203
|
+
resolve2(false);
|
|
27366
27204
|
}, timeoutMs);
|
|
27367
27205
|
const onSettle = () => {
|
|
27368
27206
|
clearTimeout(timer);
|
|
27369
|
-
|
|
27207
|
+
resolve2(true);
|
|
27370
27208
|
};
|
|
27371
27209
|
shared.promptWaiters.push(onSettle);
|
|
27372
27210
|
});
|
|
@@ -27717,10 +27555,27 @@ function createExecutorSession({
|
|
|
27717
27555
|
throw new AcpExecutorDisposedError();
|
|
27718
27556
|
}
|
|
27719
27557
|
}
|
|
27558
|
+
const mcpCapabilities = initialized.agentCapabilities?.mcpCapabilities ?? hooks.mcpCapabilities;
|
|
27559
|
+
const requestedMcpServers = options.mcpServers ?? [];
|
|
27720
27560
|
const mcpServers = filterMcpServersByAgentCapabilities(
|
|
27721
|
-
|
|
27722
|
-
initialized.agentCapabilities
|
|
27561
|
+
requestedMcpServers,
|
|
27562
|
+
mcpCapabilities === void 0 ? initialized.agentCapabilities : { mcpCapabilities }
|
|
27723
27563
|
);
|
|
27564
|
+
if (mcpServers.length < requestedMcpServers.length) {
|
|
27565
|
+
const kept = new Set(mcpServers);
|
|
27566
|
+
const dropped = requestedMcpServers.filter((server) => !kept.has(server)).map((server) => ({
|
|
27567
|
+
...typeof server["name"] === "string" ? { name: server["name"] } : {},
|
|
27568
|
+
...typeof server.type === "string" ? { type: server.type } : {}
|
|
27569
|
+
}));
|
|
27570
|
+
options.log?.warn?.(
|
|
27571
|
+
"acp session dropped MCP servers whose transport was not advertised in initialize.agentCapabilities.mcpCapabilities; set hooks.mcpCapabilities if the agent supports the transport without reporting it",
|
|
27572
|
+
{
|
|
27573
|
+
threadId: options.threadId,
|
|
27574
|
+
dropped,
|
|
27575
|
+
advertisedMcpCapabilities: initialized.agentCapabilities?.mcpCapabilities ?? null
|
|
27576
|
+
}
|
|
27577
|
+
);
|
|
27578
|
+
}
|
|
27724
27579
|
const additionalDirectories = options.additionalDirectories !== void 0 && options.additionalDirectories.length > 0 ? { additionalDirectories: options.additionalDirectories } : {};
|
|
27725
27580
|
let setup;
|
|
27726
27581
|
let nextSessionId;
|
|
@@ -28442,9 +28297,9 @@ function readOpenToolCalls(toolCalls, turnId) {
|
|
|
28442
28297
|
}
|
|
28443
28298
|
|
|
28444
28299
|
// ../../packages/ycodium-acp-executor/src/protocol-log.ts
|
|
28445
|
-
import * as
|
|
28446
|
-
import * as
|
|
28447
|
-
import * as
|
|
28300
|
+
import * as NodeFS from "node:fs";
|
|
28301
|
+
import * as NodeOS2 from "node:os";
|
|
28302
|
+
import * as NodePath4 from "node:path";
|
|
28448
28303
|
var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
|
|
28449
28304
|
var UNSAFE_FILE_CHARS = /[^A-Za-z0-9._-]+/gu;
|
|
28450
28305
|
function safeFileName(value) {
|
|
@@ -28452,12 +28307,12 @@ function safeFileName(value) {
|
|
|
28452
28307
|
}
|
|
28453
28308
|
function createAcpProtocolLogFile(input2) {
|
|
28454
28309
|
const maxBytes = input2.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
28455
|
-
|
|
28456
|
-
const filePath =
|
|
28310
|
+
NodeFS.mkdirSync(input2.directory, { recursive: true });
|
|
28311
|
+
const filePath = NodePath4.join(
|
|
28457
28312
|
input2.directory,
|
|
28458
28313
|
`${safeFileName(input2.provider)}-${safeFileName(input2.threadId)}-${Date.now().toString(36)}.ndjson`
|
|
28459
28314
|
);
|
|
28460
|
-
const stream = (input2.openStream ?? ((path) =>
|
|
28315
|
+
const stream = (input2.openStream ?? ((path) => NodeFS.createWriteStream(path, { flags: "a" })))(
|
|
28461
28316
|
filePath
|
|
28462
28317
|
);
|
|
28463
28318
|
let bytes = 0;
|
|
@@ -28509,7 +28364,7 @@ function createAcpProtocolLogFromEnv(input2) {
|
|
|
28509
28364
|
const flag = process.env.YCODIUM_ACP_PROTOCOL_LOG;
|
|
28510
28365
|
if (flag !== "1" && flag?.toLowerCase() !== "true") return void 0;
|
|
28511
28366
|
const configured = process.env.YCODIUM_ACP_PROTOCOL_LOG_DIR?.trim();
|
|
28512
|
-
const directory = configured && configured.length > 0 ? configured :
|
|
28367
|
+
const directory = configured && configured.length > 0 ? configured : NodePath4.join(NodeOS2.tmpdir(), "ycodium-acp-protocol");
|
|
28513
28368
|
try {
|
|
28514
28369
|
const sink = createAcpProtocolLogFile({
|
|
28515
28370
|
directory,
|
|
@@ -28533,7 +28388,7 @@ function defaultNowIso() {
|
|
|
28533
28388
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
28534
28389
|
}
|
|
28535
28390
|
function defaultRandomId() {
|
|
28536
|
-
return
|
|
28391
|
+
return NodeCrypto2.randomUUID();
|
|
28537
28392
|
}
|
|
28538
28393
|
function createAcpExecutor(options) {
|
|
28539
28394
|
const hooks = { ...defaultVendorHooks, ...options.hooks };
|
|
@@ -28951,13 +28806,13 @@ function acpNativeSessionProcessMatcher(program, args) {
|
|
|
28951
28806
|
|
|
28952
28807
|
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
28953
28808
|
var dispatchAcpPrompt = (executor, input2) => {
|
|
28954
|
-
const { promise: dispatched, resolve:
|
|
28809
|
+
const { promise: dispatched, resolve: resolve2 } = Promise.withResolvers();
|
|
28955
28810
|
let written = false;
|
|
28956
28811
|
const finished = executor.prompt({
|
|
28957
28812
|
...input2,
|
|
28958
28813
|
onDispatched: (turnId) => {
|
|
28959
28814
|
written = true;
|
|
28960
|
-
|
|
28815
|
+
resolve2(turnId);
|
|
28961
28816
|
}
|
|
28962
28817
|
});
|
|
28963
28818
|
return Promise.race([
|
|
@@ -28972,8 +28827,8 @@ var dispatchAcpPrompt = (executor, input2) => {
|
|
|
28972
28827
|
};
|
|
28973
28828
|
|
|
28974
28829
|
// ../../packages/ycodium-acp-executor/src/thread-operations.ts
|
|
28975
|
-
var yieldTick = () => new Promise((
|
|
28976
|
-
setImmediate(
|
|
28830
|
+
var yieldTick = () => new Promise((resolve2) => {
|
|
28831
|
+
setImmediate(resolve2);
|
|
28977
28832
|
});
|
|
28978
28833
|
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
28979
28834
|
function createAcpThreadOperations(options) {
|
|
@@ -29049,7 +28904,7 @@ function createAcpThreadOperations(options) {
|
|
|
29049
28904
|
}
|
|
29050
28905
|
|
|
29051
28906
|
// ../../packages/ycodium-executor-common/src/nodeStreams.ts
|
|
29052
|
-
import * as
|
|
28907
|
+
import * as NodeOS3 from "node:os";
|
|
29053
28908
|
import * as NodeStream2 from "node:stream";
|
|
29054
28909
|
var PEER_CLOSED_STDIN_CODES = /* @__PURE__ */ new Set([
|
|
29055
28910
|
"EPIPE",
|
|
@@ -29117,7 +28972,7 @@ var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
|
29117
28972
|
var SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
|
|
29118
28973
|
function redactStderrExcerpt(text4, environment = process.env) {
|
|
29119
28974
|
let result = text4.replaceAll("\0", "");
|
|
29120
|
-
const homes = [environment["HOME"], environment["USERPROFILE"],
|
|
28975
|
+
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
|
|
29121
28976
|
(value) => typeof value === "string" && value.length > 1
|
|
29122
28977
|
);
|
|
29123
28978
|
for (const home of new Set(homes)) {
|
|
@@ -29138,8 +28993,8 @@ function drainStderrTail(stderr) {
|
|
|
29138
28993
|
let timer;
|
|
29139
28994
|
await Promise.race([
|
|
29140
28995
|
drained,
|
|
29141
|
-
new Promise((
|
|
29142
|
-
timer = setTimeout(
|
|
28996
|
+
new Promise((resolve2) => {
|
|
28997
|
+
timer = setTimeout(resolve2, STDERR_SETTLE_MS);
|
|
29143
28998
|
})
|
|
29144
28999
|
]);
|
|
29145
29000
|
clearTimeout(timer);
|
|
@@ -29153,11 +29008,11 @@ function nodeStreamsFromHandle(handle, errors = ownErrors) {
|
|
|
29153
29008
|
for await (const chunk of handle.stdout) {
|
|
29154
29009
|
if (!readable.writable) return;
|
|
29155
29010
|
if (!readable.write(chunk)) {
|
|
29156
|
-
await new Promise((
|
|
29011
|
+
await new Promise((resolve2) => {
|
|
29157
29012
|
const onDone = () => {
|
|
29158
29013
|
readable.off("drain", onDone);
|
|
29159
29014
|
readable.off("close", onDone);
|
|
29160
|
-
|
|
29015
|
+
resolve2();
|
|
29161
29016
|
};
|
|
29162
29017
|
readable.once("drain", onDone);
|
|
29163
29018
|
readable.once("close", onDone);
|
|
@@ -29214,8 +29069,8 @@ async function raceStartAbort(promise2, signal) {
|
|
|
29214
29069
|
}
|
|
29215
29070
|
|
|
29216
29071
|
// ../../packages/ycodium-acp-executor/src/instance-kit.ts
|
|
29217
|
-
var yieldTick2 = () => new Promise((
|
|
29218
|
-
setImmediate(
|
|
29072
|
+
var yieldTick2 = () => new Promise((resolve2) => {
|
|
29073
|
+
setImmediate(resolve2);
|
|
29219
29074
|
});
|
|
29220
29075
|
var nowIso2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
29221
29076
|
function createAcpThreadTable(log, beforeStopAll) {
|
|
@@ -29333,7 +29188,7 @@ var acpProbeFailureDetail = (error62) => (error62 instanceof Error ? error62.mes
|
|
|
29333
29188
|
// ../../packages/ycodium-acp-executor/src/probe.ts
|
|
29334
29189
|
function withProbeTimeout(promise2, timeoutMs, what, signal) {
|
|
29335
29190
|
signal?.throwIfAborted();
|
|
29336
|
-
return new Promise((
|
|
29191
|
+
return new Promise((resolve2, reject) => {
|
|
29337
29192
|
const onAbort = () => {
|
|
29338
29193
|
clearTimeout(timer);
|
|
29339
29194
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -29348,7 +29203,7 @@ function withProbeTimeout(promise2, timeoutMs, what, signal) {
|
|
|
29348
29203
|
(value) => {
|
|
29349
29204
|
clearTimeout(timer);
|
|
29350
29205
|
signal?.removeEventListener("abort", onAbort);
|
|
29351
|
-
|
|
29206
|
+
resolve2(value);
|
|
29352
29207
|
},
|
|
29353
29208
|
(error62) => {
|
|
29354
29209
|
clearTimeout(timer);
|
|
@@ -29501,121 +29356,17 @@ async function runAcpProbeProcess(input2) {
|
|
|
29501
29356
|
}
|
|
29502
29357
|
}
|
|
29503
29358
|
|
|
29504
|
-
//
|
|
29505
|
-
|
|
29506
|
-
|
|
29507
|
-
|
|
29508
|
-
|
|
29509
|
-
|
|
29510
|
-
let quote;
|
|
29511
|
-
let quoted = false;
|
|
29512
|
-
for (let index = 0; index < input2.length; index++) {
|
|
29513
|
-
const char = input2[index];
|
|
29514
|
-
if (char === void 0) continue;
|
|
29515
|
-
if (quote) {
|
|
29516
|
-
if (char === quote) {
|
|
29517
|
-
quote = void 0;
|
|
29518
|
-
quoted = true;
|
|
29519
|
-
} else if (char === "\\" && quote === '"') {
|
|
29520
|
-
const next = input2[index + 1];
|
|
29521
|
-
if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
|
|
29522
|
-
current += next;
|
|
29523
|
-
index++;
|
|
29524
|
-
} else {
|
|
29525
|
-
current += char;
|
|
29526
|
-
}
|
|
29527
|
-
} else {
|
|
29528
|
-
current += char;
|
|
29529
|
-
}
|
|
29530
|
-
continue;
|
|
29531
|
-
}
|
|
29532
|
-
if (char === "'" || char === '"') {
|
|
29533
|
-
quote = char;
|
|
29534
|
-
quoted = true;
|
|
29535
|
-
} else if (/\s/.test(char)) {
|
|
29536
|
-
if (current || quoted) {
|
|
29537
|
-
tokens.push(current);
|
|
29538
|
-
current = "";
|
|
29539
|
-
quoted = false;
|
|
29540
|
-
}
|
|
29541
|
-
} else if (char === "\\") {
|
|
29542
|
-
const next = input2[index + 1];
|
|
29543
|
-
if (next !== void 0 && /\s/.test(next)) {
|
|
29544
|
-
current += next;
|
|
29545
|
-
index++;
|
|
29546
|
-
} else {
|
|
29547
|
-
current += char;
|
|
29548
|
-
}
|
|
29549
|
-
} else {
|
|
29550
|
-
current += char;
|
|
29551
|
-
}
|
|
29552
|
-
}
|
|
29553
|
-
if (current || quoted) tokens.push(current);
|
|
29554
|
-
return tokens;
|
|
29555
|
-
}
|
|
29556
|
-
|
|
29557
|
-
// ../../packages/ycodium-instance-config/src/instanceConfig.ts
|
|
29558
|
-
import { modelSelectionStringOption as modelSelectionStringOption2 } from "@ycodium-ai/plugin-api/executor";
|
|
29559
|
-
function isRecord8(value) {
|
|
29560
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29561
|
-
}
|
|
29562
|
-
function readString(value) {
|
|
29563
|
-
return typeof value === "string" ? value : "";
|
|
29564
|
-
}
|
|
29565
|
-
function readTrimmed(value) {
|
|
29566
|
-
return readString(value).trim();
|
|
29567
|
-
}
|
|
29568
|
-
function modelIdFromSelection(selection) {
|
|
29569
|
-
if (!isRecord8(selection)) return void 0;
|
|
29570
|
-
const model = selection["model"];
|
|
29571
|
-
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
29572
|
-
}
|
|
29573
|
-
function readTurnSelection(selection, effortOptionId) {
|
|
29574
|
-
const requestedModelId = modelIdFromSelection(selection);
|
|
29575
|
-
const requestedEffort = modelSelectionStringOption2(selection, effortOptionId);
|
|
29576
|
-
return {
|
|
29577
|
-
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
29578
|
-
...requestedEffort === void 0 ? {} : { requestedEffort }
|
|
29579
|
-
};
|
|
29580
|
-
}
|
|
29581
|
-
function readEnvironment(value) {
|
|
29582
|
-
if (!Array.isArray(value)) return {};
|
|
29583
|
-
const entries = [];
|
|
29584
|
-
for (const entry of value) {
|
|
29585
|
-
if (!isRecord8(entry)) continue;
|
|
29586
|
-
const name = readTrimmed(entry["name"]);
|
|
29587
|
-
if (name.length === 0) continue;
|
|
29588
|
-
entries.push([name, readString(entry["value"])]);
|
|
29589
|
-
}
|
|
29590
|
-
return Object.fromEntries(entries);
|
|
29591
|
-
}
|
|
29592
|
-
function instanceSettings(config2) {
|
|
29593
|
-
if (!isRecord8(config2)) return {};
|
|
29594
|
-
return isRecord8(config2["config"]) ? config2["config"] : config2;
|
|
29595
|
-
}
|
|
29596
|
-
function readInstanceEnvelope(config2) {
|
|
29597
|
-
const envelope = isRecord8(config2) ? config2 : {};
|
|
29598
|
-
const settings = instanceSettings(config2);
|
|
29599
|
-
return {
|
|
29600
|
-
settings,
|
|
29601
|
-
settingOrEnvelope: (key) => readTrimmed(settings[key]) || readTrimmed(envelope[key]),
|
|
29602
|
-
environment: readEnvironment(envelope["environment"]),
|
|
29603
|
-
envelopeDriver: readTrimmed(envelope["driver"]) || void 0
|
|
29604
|
-
};
|
|
29605
|
-
}
|
|
29606
|
-
function readLaunchInstanceRecipe(config2, defaultLaunchArgs = "") {
|
|
29607
|
-
const envelope = readInstanceEnvelope(config2);
|
|
29608
|
-
return {
|
|
29609
|
-
binaryPath: readTrimmed(envelope.settings["binaryPath"]),
|
|
29610
|
-
launchArgs: readString(envelope.settings["launchArgs"]) || defaultLaunchArgs,
|
|
29611
|
-
homePath: envelope.settingOrEnvelope("homePath"),
|
|
29612
|
-
homeEnvVar: envelope.settingOrEnvelope("homeEnvVar"),
|
|
29613
|
-
environment: envelope.environment,
|
|
29614
|
-
envelopeDriver: envelope.envelopeDriver
|
|
29615
|
-
};
|
|
29616
|
-
}
|
|
29359
|
+
// src/grokInstance.ts
|
|
29360
|
+
import {
|
|
29361
|
+
tokenizeShellWords as tokenizeShellWords2,
|
|
29362
|
+
modelIdFromSelection,
|
|
29363
|
+
readTurnSelection
|
|
29364
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
29617
29365
|
|
|
29618
29366
|
// src/config.ts
|
|
29367
|
+
import {
|
|
29368
|
+
readLaunchInstanceRecipe
|
|
29369
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
29619
29370
|
var GROK_DEFAULT_LAUNCH_ARGS = "agent stdio";
|
|
29620
29371
|
function parseGrokInstanceConfig(config2) {
|
|
29621
29372
|
return readLaunchInstanceRecipe(config2, GROK_DEFAULT_LAUNCH_ARGS);
|
|
@@ -29640,69 +29391,17 @@ function makeGrokSignIn(input2) {
|
|
|
29640
29391
|
}
|
|
29641
29392
|
|
|
29642
29393
|
// src/grokQuota.ts
|
|
29643
|
-
import * as
|
|
29644
|
-
import * as
|
|
29394
|
+
import * as NodeFS2 from "node:fs";
|
|
29395
|
+
import * as NodePath5 from "node:path";
|
|
29645
29396
|
import "@ycodium-ai/plugin-api/usage";
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29650
|
-
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
...input2.method === void 0 ? {} : { method: input2.method },
|
|
29655
|
-
...input2.body === void 0 ? {} : { body: input2.body },
|
|
29656
|
-
...input2.redirect === void 0 ? {} : { redirect: input2.redirect },
|
|
29657
|
-
signal: AbortSignal.any([
|
|
29658
|
-
...input2.signal === void 0 ? [] : [input2.signal],
|
|
29659
|
-
AbortSignal.timeout(input2.timeoutMs)
|
|
29660
|
-
])
|
|
29661
|
-
});
|
|
29662
|
-
} catch (cause) {
|
|
29663
|
-
if (input2.propagateCallerAbort && input2.signal?.aborted) throw cause;
|
|
29664
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
29665
|
-
}
|
|
29666
|
-
if (!response.ok) {
|
|
29667
|
-
void response.body?.cancel().catch(() => void 0);
|
|
29668
|
-
if (response.status === 429) {
|
|
29669
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"), input2.now());
|
|
29670
|
-
return {
|
|
29671
|
-
status: "unavailable",
|
|
29672
|
-
reason: "rateLimited",
|
|
29673
|
-
...retryAfterMs === null ? {} : { retryAfterMs }
|
|
29674
|
-
};
|
|
29675
|
-
}
|
|
29676
|
-
const reason = input2.statusReasons?.[response.status] ?? (response.status === 401 || response.status === 403 ? "authRejected" : "unreachable");
|
|
29677
|
-
return { status: "unavailable", reason };
|
|
29678
|
-
}
|
|
29679
|
-
try {
|
|
29680
|
-
return { body: JSON.parse(await response.text()) };
|
|
29681
|
-
} catch (cause) {
|
|
29682
|
-
if (input2.propagateCallerAbort && input2.signal?.aborted) throw cause;
|
|
29683
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
29684
|
-
}
|
|
29685
|
-
}
|
|
29686
|
-
async function requestQuotaJson(input2) {
|
|
29687
|
-
const answer = await requestQuotaJsonValue(input2);
|
|
29688
|
-
if (!("body" in answer)) return answer;
|
|
29689
|
-
return isRecord(answer.body) ? { body: answer.body } : { status: "unavailable", reason: "unreachable" };
|
|
29690
|
-
}
|
|
29691
|
-
|
|
29692
|
-
// ../../packages/ycodium-credential-account/src/quotaJson.ts
|
|
29693
|
-
var asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
29694
|
-
var asString3 = (value) => typeof value === "string" && value.length > 0 ? value : null;
|
|
29695
|
-
var asNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
29696
|
-
var parseJson = (raw) => {
|
|
29697
|
-
try {
|
|
29698
|
-
return JSON.parse(raw);
|
|
29699
|
-
} catch {
|
|
29700
|
-
return null;
|
|
29701
|
-
}
|
|
29702
|
-
};
|
|
29703
|
-
var clampPercent = (value) => Math.min(100, Math.max(0, value));
|
|
29704
|
-
|
|
29705
|
-
// src/grokQuota.ts
|
|
29397
|
+
import {
|
|
29398
|
+
requestQuotaJson,
|
|
29399
|
+
clampPercent,
|
|
29400
|
+
asNumber,
|
|
29401
|
+
asObject,
|
|
29402
|
+
asString as asString3,
|
|
29403
|
+
parseJson
|
|
29404
|
+
} from "@ycodium-ai/plugin-api/credential-account";
|
|
29706
29405
|
var GROK_USAGE_URL = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
29707
29406
|
var GROK_ISSUER_PREFIX = "https://auth.x.ai::";
|
|
29708
29407
|
var AUTH_FILE_NAME2 = "auth.json";
|
|
@@ -29735,7 +29434,7 @@ var grokQuotaWindows = (body) => {
|
|
|
29735
29434
|
};
|
|
29736
29435
|
var createGrokUsage = (input2) => {
|
|
29737
29436
|
const now = input2.now ?? Date.now;
|
|
29738
|
-
const authPath =
|
|
29437
|
+
const authPath = NodePath5.join(input2.homePath, AUTH_FILE_NAME2);
|
|
29739
29438
|
const readQuota = async (request) => {
|
|
29740
29439
|
const baseUrlKey = GROK_CARD.modelConnectivity.baseUrlEnvKey;
|
|
29741
29440
|
if (baseUrlKey !== void 0 && (input2.environment[baseUrlKey]?.trim() ?? "") !== "") {
|
|
@@ -29743,7 +29442,7 @@ var createGrokUsage = (input2) => {
|
|
|
29743
29442
|
}
|
|
29744
29443
|
let token = null;
|
|
29745
29444
|
try {
|
|
29746
|
-
token = extractGrokToken(parseJson(
|
|
29445
|
+
token = extractGrokToken(parseJson(NodeFS2.readFileSync(authPath, "utf8")));
|
|
29747
29446
|
} catch {
|
|
29748
29447
|
token = null;
|
|
29749
29448
|
}
|
|
@@ -29780,11 +29479,11 @@ var createGrokUsage = (input2) => {
|
|
|
29780
29479
|
|
|
29781
29480
|
// src/grokTurnUsage.ts
|
|
29782
29481
|
var USAGE_GRACE_MS = 300;
|
|
29783
|
-
var
|
|
29482
|
+
var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29784
29483
|
var count = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0;
|
|
29785
29484
|
var text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
29786
29485
|
var readModelTotals = (entry) => {
|
|
29787
|
-
if (!
|
|
29486
|
+
if (!isRecord8(entry)) return void 0;
|
|
29788
29487
|
const input2 = count(entry["inputTokens"]);
|
|
29789
29488
|
const cachedInputTokens = count(entry["cachedReadTokens"]);
|
|
29790
29489
|
const cacheCreationTokens = count(entry["cacheCreationTokens"]);
|
|
@@ -29799,12 +29498,12 @@ var readModelTotals = (entry) => {
|
|
|
29799
29498
|
};
|
|
29800
29499
|
var sumOf = (totals) => totals.uncachedInputTokens + totals.cachedInputTokens + totals.cacheCreationTokens + totals.outputTokens;
|
|
29801
29500
|
var grokTurnUsageReport = (promptResponse) => {
|
|
29802
|
-
const meta3 =
|
|
29803
|
-
const usage =
|
|
29804
|
-
if (!
|
|
29501
|
+
const meta3 = isRecord8(promptResponse) ? promptResponse["_meta"] : void 0;
|
|
29502
|
+
const usage = isRecord8(meta3) ? meta3["usage"] : void 0;
|
|
29503
|
+
if (!isRecord8(meta3) || !isRecord8(usage)) return void 0;
|
|
29805
29504
|
const perModel = /* @__PURE__ */ new Map();
|
|
29806
29505
|
const modelUsage = usage["modelUsage"];
|
|
29807
|
-
if (
|
|
29506
|
+
if (isRecord8(modelUsage)) {
|
|
29808
29507
|
for (const [model, entry] of Object.entries(modelUsage)) {
|
|
29809
29508
|
const totals = readModelTotals(entry);
|
|
29810
29509
|
if (totals !== void 0 && model.trim().length > 0) perModel.set(model.trim(), totals);
|
|
@@ -29882,13 +29581,13 @@ var createGrokTurnUsageCollector = (base) => {
|
|
|
29882
29581
|
}
|
|
29883
29582
|
};
|
|
29884
29583
|
const attach = async (event) => {
|
|
29885
|
-
if (event.type !== "turn.completed" || !
|
|
29584
|
+
if (event.type !== "turn.completed" || !isRecord8(event.payload)) return event;
|
|
29886
29585
|
if (event.payload["state"] === "completed" && !allAnswered()) {
|
|
29887
|
-
await new Promise((
|
|
29888
|
-
const timer = setTimeout(
|
|
29586
|
+
await new Promise((resolve2) => {
|
|
29587
|
+
const timer = setTimeout(resolve2, USAGE_GRACE_MS);
|
|
29889
29588
|
wake = () => {
|
|
29890
29589
|
clearTimeout(timer);
|
|
29891
|
-
|
|
29590
|
+
resolve2();
|
|
29892
29591
|
};
|
|
29893
29592
|
});
|
|
29894
29593
|
wake = void 0;
|
|
@@ -29912,16 +29611,16 @@ var XAI_EXIT_PLAN_MODE_METHODS = [
|
|
|
29912
29611
|
var GROK_PLAN_APPROVE_OPTION_ID = "approved";
|
|
29913
29612
|
var GROK_PLAN_ABANDON_OPTION_ID = "abandoned";
|
|
29914
29613
|
var GROK_EMPTY_PLAN_TEXT = "The agent exited plan mode without writing a plan.";
|
|
29915
|
-
var
|
|
29614
|
+
var isRecord9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29916
29615
|
var trimmed = (value) => {
|
|
29917
29616
|
if (typeof value !== "string") return void 0;
|
|
29918
29617
|
const text4 = value.trim();
|
|
29919
29618
|
return text4.length > 0 ? text4 : void 0;
|
|
29920
29619
|
};
|
|
29921
29620
|
function parseXAiExitPlanModeParams(params) {
|
|
29922
|
-
const candidates = [params, ...
|
|
29621
|
+
const candidates = [params, ...isRecord9(params) ? [params["params"]] : []];
|
|
29923
29622
|
for (const candidate of candidates) {
|
|
29924
|
-
if (!
|
|
29623
|
+
if (!isRecord9(candidate)) continue;
|
|
29925
29624
|
const toolCallId = trimmed(candidate["toolCallId"]);
|
|
29926
29625
|
if (toolCallId === void 0) continue;
|
|
29927
29626
|
return { toolCallId, planContent: trimmed(candidate["planContent"]) };
|
|
@@ -29973,7 +29672,7 @@ function makeXAiExitPlanModeResponse(params, resolution) {
|
|
|
29973
29672
|
import { REASONING_OPTION_LABEL, reasoningEffortShortLabel } from "@ycodium-ai/plugin-api/executor";
|
|
29974
29673
|
|
|
29975
29674
|
// src/grokJson.ts
|
|
29976
|
-
var
|
|
29675
|
+
var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29977
29676
|
var trimmed2 = (value) => {
|
|
29978
29677
|
if (typeof value !== "string") return void 0;
|
|
29979
29678
|
const text4 = value.trim();
|
|
@@ -29983,11 +29682,11 @@ var trimmed2 = (value) => {
|
|
|
29983
29682
|
// src/grokReasoningEffort.ts
|
|
29984
29683
|
var GROK_REASONING_OPTION_ID = "reasoningEffort";
|
|
29985
29684
|
function grokReasoningEffortDescriptor(modelMeta) {
|
|
29986
|
-
if (!
|
|
29685
|
+
if (!isRecord10(modelMeta) || modelMeta["supportsReasoningEffort"] !== true) return void 0;
|
|
29987
29686
|
const table = modelMeta["reasoningEfforts"];
|
|
29988
29687
|
if (!Array.isArray(table)) return void 0;
|
|
29989
29688
|
const options = table.flatMap((entry) => {
|
|
29990
|
-
if (!
|
|
29689
|
+
if (!isRecord10(entry)) return [];
|
|
29991
29690
|
const value = trimmed2(entry["value"]) ?? trimmed2(entry["id"]);
|
|
29992
29691
|
if (value === void 0) return [];
|
|
29993
29692
|
const description = trimmed2(entry["description"]);
|
|
@@ -30012,23 +29711,23 @@ function grokReasoningEffortDescriptor(modelMeta) {
|
|
|
30012
29711
|
};
|
|
30013
29712
|
}
|
|
30014
29713
|
function grokReasoningEffortKnown(modelMeta) {
|
|
30015
|
-
if (!
|
|
29714
|
+
if (!isRecord10(modelMeta)) return "unknown";
|
|
30016
29715
|
if (modelMeta["supportsReasoningEffort"] === false) return "none";
|
|
30017
29716
|
if (modelMeta["supportsReasoningEffort"] !== true) return "unknown";
|
|
30018
29717
|
const table = modelMeta["reasoningEfforts"];
|
|
30019
29718
|
if (!Array.isArray(table)) return "unknown";
|
|
30020
29719
|
const readable = table.every(
|
|
30021
|
-
(entry) =>
|
|
29720
|
+
(entry) => isRecord10(entry) && (trimmed2(entry["value"]) ?? trimmed2(entry["id"])) !== void 0
|
|
30022
29721
|
);
|
|
30023
29722
|
if (!readable) return "unknown";
|
|
30024
29723
|
return table.length === 0 ? "none" : "listed";
|
|
30025
29724
|
}
|
|
30026
29725
|
function grokModelDefaultEffort(input2) {
|
|
30027
|
-
const models =
|
|
30028
|
-
const available =
|
|
29726
|
+
const models = isRecord10(input2.setup) ? input2.setup["models"] : void 0;
|
|
29727
|
+
const available = isRecord10(models) ? models["availableModels"] : void 0;
|
|
30029
29728
|
if (!Array.isArray(available)) return void 0;
|
|
30030
|
-
const model = available.find((entry) =>
|
|
30031
|
-
const current =
|
|
29729
|
+
const model = available.find((entry) => isRecord10(entry) && entry["modelId"] === input2.modelId);
|
|
29730
|
+
const current = isRecord10(model) ? grokReasoningEffortDescriptor(model["_meta"])?.currentValue : void 0;
|
|
30032
29731
|
return typeof current === "string" ? current : void 0;
|
|
30033
29732
|
}
|
|
30034
29733
|
function grokReasoningEffortArgs(effort) {
|
|
@@ -30187,7 +29886,7 @@ var NOTIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
|
30187
29886
|
"x.ai/session/update"
|
|
30188
29887
|
]);
|
|
30189
29888
|
var isGrokSessionNotification = (method) => NOTIFICATION_METHODS.has(method.startsWith("_") ? method.slice(1) : method);
|
|
30190
|
-
var record3 = (value) =>
|
|
29889
|
+
var record3 = (value) => isRecord10(value) ? value : {};
|
|
30191
29890
|
var text3 = trimmed2;
|
|
30192
29891
|
var count2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
30193
29892
|
var replyText = (value) => {
|
|
@@ -30475,7 +30174,7 @@ function createGrokRetryNotices() {
|
|
|
30475
30174
|
let phase;
|
|
30476
30175
|
return {
|
|
30477
30176
|
observe: (envelope, ctx) => {
|
|
30478
|
-
if (!
|
|
30177
|
+
if (!isRecord10(envelope) || !isRecord10(envelope["update"])) return [];
|
|
30479
30178
|
if (ctx.sessionId === void 0 || envelope["sessionId"] !== ctx.sessionId) return [];
|
|
30480
30179
|
const update = envelope["update"];
|
|
30481
30180
|
if (update["sessionUpdate"] !== "retry_state") {
|
|
@@ -30486,7 +30185,7 @@ function createGrokRetryNotices() {
|
|
|
30486
30185
|
phase = void 0;
|
|
30487
30186
|
return [];
|
|
30488
30187
|
}
|
|
30489
|
-
const meta3 =
|
|
30188
|
+
const meta3 = isRecord10(envelope["_meta"]) ? envelope["_meta"] : {};
|
|
30490
30189
|
if (meta3["isReplay"] === true) return [];
|
|
30491
30190
|
const turnId = ctx.turnId;
|
|
30492
30191
|
if (turnId === void 0) return [];
|
|
@@ -30525,7 +30224,7 @@ function createGrokRetryNotices() {
|
|
|
30525
30224
|
}
|
|
30526
30225
|
|
|
30527
30226
|
// src/grokSupport.ts
|
|
30528
|
-
import { modelSelectionStringOption as
|
|
30227
|
+
import { modelSelectionStringOption as modelSelectionStringOption2 } from "@ycodium-ai/plugin-api/executor";
|
|
30529
30228
|
var GROK_NATIVE_MODE_BY_RUNTIME_MODE = {
|
|
30530
30229
|
"approval-required": "default",
|
|
30531
30230
|
"auto-accept-edits": "auto",
|
|
@@ -30630,28 +30329,28 @@ function grokRuntimeModeCaveat(nativeModeId) {
|
|
|
30630
30329
|
};
|
|
30631
30330
|
}
|
|
30632
30331
|
function resolveGrokAuthMethodId(initializeResult) {
|
|
30633
|
-
const authMethods =
|
|
30332
|
+
const authMethods = isRecord10(initializeResult) ? initializeResult["authMethods"] : void 0;
|
|
30634
30333
|
if (!Array.isArray(authMethods)) return void 0;
|
|
30635
30334
|
for (const method of authMethods) {
|
|
30636
|
-
if (
|
|
30335
|
+
if (isRecord10(method) && method["id"] === "cached_token") return "cached_token";
|
|
30637
30336
|
}
|
|
30638
30337
|
return void 0;
|
|
30639
30338
|
}
|
|
30640
30339
|
var positive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : void 0;
|
|
30641
30340
|
function grokPromptUsage(promptResponse) {
|
|
30642
|
-
if (!
|
|
30341
|
+
if (!isRecord10(promptResponse)) return void 0;
|
|
30643
30342
|
const meta3 = promptResponse["_meta"];
|
|
30644
|
-
if (!
|
|
30343
|
+
if (!isRecord10(meta3)) return void 0;
|
|
30645
30344
|
const usedTokens = positive(meta3["totalTokens"]);
|
|
30646
30345
|
if (usedTokens === void 0) return void 0;
|
|
30647
30346
|
return { usedTokens, modelId: trimmed2(meta3["modelId"]) };
|
|
30648
30347
|
}
|
|
30649
30348
|
function grokModelState(initializeResult) {
|
|
30650
|
-
if (!
|
|
30349
|
+
if (!isRecord10(initializeResult)) return void 0;
|
|
30651
30350
|
const meta3 = initializeResult["_meta"];
|
|
30652
|
-
if (!
|
|
30351
|
+
if (!isRecord10(meta3)) return void 0;
|
|
30653
30352
|
const modelState = meta3["modelState"];
|
|
30654
|
-
if (!
|
|
30353
|
+
if (!isRecord10(modelState)) return void 0;
|
|
30655
30354
|
const availableModels = modelState["availableModels"];
|
|
30656
30355
|
if (!Array.isArray(availableModels)) return void 0;
|
|
30657
30356
|
return { currentModelId: trimmed2(modelState["currentModelId"]), availableModels };
|
|
@@ -30661,11 +30360,11 @@ function grokAdvertisedModels(initializeResult) {
|
|
|
30661
30360
|
if (state === void 0) return [];
|
|
30662
30361
|
const models = [];
|
|
30663
30362
|
for (const entry of state.availableModels) {
|
|
30664
|
-
if (!
|
|
30363
|
+
if (!isRecord10(entry)) continue;
|
|
30665
30364
|
const modelId = trimmed2(entry["modelId"]);
|
|
30666
30365
|
if (modelId === void 0) continue;
|
|
30667
30366
|
const modelMeta = entry["_meta"];
|
|
30668
|
-
const contextWindow =
|
|
30367
|
+
const contextWindow = isRecord10(modelMeta) ? positive(modelMeta["totalContextTokens"]) : void 0;
|
|
30669
30368
|
models.push({
|
|
30670
30369
|
modelId,
|
|
30671
30370
|
name: trimmed2(entry["name"]),
|
|
@@ -30682,7 +30381,7 @@ var XAI_ASK_USER_QUESTION_METHODS = [
|
|
|
30682
30381
|
"x.ai/ask_user_question"
|
|
30683
30382
|
];
|
|
30684
30383
|
var readOption = (value) => {
|
|
30685
|
-
if (!
|
|
30384
|
+
if (!isRecord10(value)) return void 0;
|
|
30686
30385
|
const label = typeof value["label"] === "string" ? value["label"] : void 0;
|
|
30687
30386
|
if (label === void 0) return void 0;
|
|
30688
30387
|
return {
|
|
@@ -30693,7 +30392,7 @@ var readOption = (value) => {
|
|
|
30693
30392
|
};
|
|
30694
30393
|
};
|
|
30695
30394
|
var readQuestion = (value) => {
|
|
30696
|
-
if (!
|
|
30395
|
+
if (!isRecord10(value)) return void 0;
|
|
30697
30396
|
const question = typeof value["question"] === "string" ? value["question"] : void 0;
|
|
30698
30397
|
if (question === void 0) return void 0;
|
|
30699
30398
|
const optionsRaw = value["options"];
|
|
@@ -30709,9 +30408,9 @@ var readQuestion = (value) => {
|
|
|
30709
30408
|
};
|
|
30710
30409
|
};
|
|
30711
30410
|
function parseXAiAskUserQuestionParams(params) {
|
|
30712
|
-
const candidates = [params, ...
|
|
30411
|
+
const candidates = [params, ...isRecord10(params) ? [params["params"]] : []];
|
|
30713
30412
|
for (const candidate of candidates) {
|
|
30714
|
-
if (!
|
|
30413
|
+
if (!isRecord10(candidate)) continue;
|
|
30715
30414
|
const questionsRaw = candidate["questions"];
|
|
30716
30415
|
if (!Array.isArray(questionsRaw)) continue;
|
|
30717
30416
|
const questions = questionsRaw.flatMap((entry) => {
|
|
@@ -30786,21 +30485,21 @@ var XAI_PROMPT_COMPLETE_METHOD = "_x.ai/session/prompt_complete";
|
|
|
30786
30485
|
var GROK_RATE_LIMIT_MESSAGE = "Grok usage limit reached or rate limited. Try again later.";
|
|
30787
30486
|
var grokAgentResultMessage = (value) => {
|
|
30788
30487
|
if (typeof value === "string") return trimmed2(value);
|
|
30789
|
-
return
|
|
30488
|
+
return isRecord10(value) ? trimmed2(value["message"]) : void 0;
|
|
30790
30489
|
};
|
|
30791
30490
|
var grokPromptSettlement = {
|
|
30792
30491
|
// 关联 id 双写 promptId 与 requestId(宿主 XAiAcpExtension 同款):
|
|
30793
30492
|
// agent 认回哪个键是它的事,两个都给才不猜版本。
|
|
30794
30493
|
requestFields: (promptKey) => ({ _meta: { promptId: promptKey, requestId: promptKey } }),
|
|
30795
30494
|
responseKey: (response) => {
|
|
30796
|
-
if (!
|
|
30495
|
+
if (!isRecord10(response)) return void 0;
|
|
30797
30496
|
const meta3 = response["_meta"];
|
|
30798
|
-
if (!
|
|
30497
|
+
if (!isRecord10(meta3)) return void 0;
|
|
30799
30498
|
return trimmed2(meta3["promptId"]) ?? trimmed2(meta3["requestId"]);
|
|
30800
30499
|
},
|
|
30801
30500
|
fromNotification: (method, params) => {
|
|
30802
30501
|
if (method !== XAI_PROMPT_COMPLETE_METHOD) return void 0;
|
|
30803
|
-
if (!
|
|
30502
|
+
if (!isRecord10(params)) return void 0;
|
|
30804
30503
|
const sessionId = params["sessionId"];
|
|
30805
30504
|
if (typeof sessionId !== "string") return void 0;
|
|
30806
30505
|
const stopReason = trimmed2(params["stopReason"]);
|
|
@@ -30819,12 +30518,12 @@ var grokPromptSettlement = {
|
|
|
30819
30518
|
};
|
|
30820
30519
|
|
|
30821
30520
|
// src/grokSkills.ts
|
|
30822
|
-
import * as
|
|
30823
|
-
import * as
|
|
30521
|
+
import * as NodeOS4 from "node:os";
|
|
30522
|
+
import * as NodePath6 from "node:path";
|
|
30824
30523
|
var INSPECT_TIMEOUT_MS = 15e3;
|
|
30825
30524
|
var MAX_INSPECT_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
30826
30525
|
var GROK_INSPECT_ARGS = ["inspect", "--json"];
|
|
30827
|
-
var
|
|
30526
|
+
var isRecord11 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30828
30527
|
var trimmedString = (value) => typeof value === "string" ? value.trim() : "";
|
|
30829
30528
|
function parseGrokInspectSkills(stdout) {
|
|
30830
30529
|
let parsed;
|
|
@@ -30833,13 +30532,13 @@ function parseGrokInspectSkills(stdout) {
|
|
|
30833
30532
|
} catch {
|
|
30834
30533
|
return [];
|
|
30835
30534
|
}
|
|
30836
|
-
const entries =
|
|
30535
|
+
const entries = isRecord11(parsed) ? parsed["skills"] : void 0;
|
|
30837
30536
|
if (!Array.isArray(entries)) return [];
|
|
30838
30537
|
const byName = /* @__PURE__ */ new Map();
|
|
30839
30538
|
for (const entry of entries) {
|
|
30840
|
-
if (!
|
|
30539
|
+
if (!isRecord11(entry)) continue;
|
|
30841
30540
|
const name = trimmedString(entry["name"]);
|
|
30842
|
-
const source =
|
|
30541
|
+
const source = isRecord11(entry["source"]) ? entry["source"] : void 0;
|
|
30843
30542
|
const path = trimmedString(source?.["path"]);
|
|
30844
30543
|
if (name.length === 0 || path.length === 0) continue;
|
|
30845
30544
|
const scope = trimmedString(source?.["type"]);
|
|
@@ -30873,14 +30572,14 @@ var runGrokInspect = async (input2) => {
|
|
|
30873
30572
|
throw new Error(`grok inspect exited with ${String(run.exitCode)}`);
|
|
30874
30573
|
}
|
|
30875
30574
|
const parsed = JSON.parse(run.stdout);
|
|
30876
|
-
if (!
|
|
30575
|
+
if (!isRecord11(parsed) || !Array.isArray(parsed["skills"])) {
|
|
30877
30576
|
throw new Error("grok inspect output has no skills list");
|
|
30878
30577
|
}
|
|
30879
30578
|
return parseGrokInspectSkills(run.stdout);
|
|
30880
30579
|
};
|
|
30881
30580
|
async function probeGrokSkills(input2) {
|
|
30882
30581
|
try {
|
|
30883
|
-
return await runGrokInspect({ ...input2, cwd:
|
|
30582
|
+
return await runGrokInspect({ ...input2, cwd: NodeOS4.homedir() });
|
|
30884
30583
|
} catch {
|
|
30885
30584
|
return [];
|
|
30886
30585
|
}
|
|
@@ -30889,14 +30588,14 @@ async function inspectGrokWorkspace(input2) {
|
|
|
30889
30588
|
const skills = await runGrokInspect(input2);
|
|
30890
30589
|
const watched = /* @__PURE__ */ new Set([
|
|
30891
30590
|
// 项目技能目录的位置没有实测,这两处只是触发重查的提示,不影响答案本身。
|
|
30892
|
-
|
|
30893
|
-
|
|
30591
|
+
NodePath6.join(input2.cwd, ".grok", "skills"),
|
|
30592
|
+
NodePath6.join(input2.cwd, ".agents", "skills")
|
|
30894
30593
|
]);
|
|
30895
30594
|
for (const skill of skills) {
|
|
30896
30595
|
watched.add(skill.path);
|
|
30897
|
-
const skillDirectory =
|
|
30596
|
+
const skillDirectory = NodePath6.dirname(skill.path);
|
|
30898
30597
|
watched.add(skillDirectory);
|
|
30899
|
-
watched.add(
|
|
30598
|
+
watched.add(NodePath6.dirname(skillDirectory));
|
|
30900
30599
|
}
|
|
30901
30600
|
return { skills, watchPaths: [...watched] };
|
|
30902
30601
|
}
|
|
@@ -30950,65 +30649,23 @@ function grokOpenCommands(session) {
|
|
|
30950
30649
|
|
|
30951
30650
|
// src/modelCacheRefresh.ts
|
|
30952
30651
|
import {
|
|
30953
|
-
runProcessOperation
|
|
30954
|
-
isOperationCleanupError
|
|
30652
|
+
runProcessOperation,
|
|
30653
|
+
isOperationCleanupError
|
|
30955
30654
|
} from "@ycodium-ai/plugin-api/process-operation";
|
|
30956
|
-
import * as
|
|
30957
|
-
import * as
|
|
30958
|
-
import {
|
|
30959
|
-
ExecutorSpawnAbortedError as ExecutorSpawnAbortedError2,
|
|
30960
|
-
ExecutorSpawnRefusedError as ExecutorSpawnRefusedError2,
|
|
30961
|
-
throwIfExecutorSpawnAborted
|
|
30962
|
-
} from "@ycodium-ai/plugin-api/executor";
|
|
30963
|
-
|
|
30964
|
-
// ../../packages/ycodium-instance-config/src/probeProcess.ts
|
|
30655
|
+
import * as NodeFS3 from "node:fs";
|
|
30656
|
+
import * as NodePath7 from "node:path";
|
|
30965
30657
|
import {
|
|
30966
|
-
describeExecutorSpawnFailure,
|
|
30967
30658
|
ExecutorSpawnAbortedError,
|
|
30968
|
-
ExecutorSpawnRefusedError
|
|
30659
|
+
ExecutorSpawnRefusedError,
|
|
30660
|
+
throwIfExecutorSpawnAborted
|
|
30969
30661
|
} from "@ycodium-ai/plugin-api/executor";
|
|
30970
|
-
import {
|
|
30971
|
-
isOperationCleanupError,
|
|
30972
|
-
runProcessOperation
|
|
30973
|
-
} from "@ycodium-ai/plugin-api/process-operation";
|
|
30974
|
-
async function spawnProbeProcess(host, launch) {
|
|
30975
|
-
try {
|
|
30976
|
-
const handle = await host.process.spawn({
|
|
30977
|
-
program: launch.program,
|
|
30978
|
-
args: launch.args,
|
|
30979
|
-
cwd: launch.cwd,
|
|
30980
|
-
owner: { bindingId: host.bindingId },
|
|
30981
|
-
...Object.keys(launch.env).length > 0 ? { env: launch.env } : {},
|
|
30982
|
-
...launch.signal === void 0 ? {} : { signal: launch.signal }
|
|
30983
|
-
});
|
|
30984
|
-
return { kind: "spawned", handle };
|
|
30985
|
-
} catch (error62) {
|
|
30986
|
-
if (error62 instanceof ExecutorSpawnRefusedError || error62 instanceof ExecutorSpawnAbortedError) {
|
|
30987
|
-
throw error62;
|
|
30988
|
-
}
|
|
30989
|
-
return { kind: "not-started", ...describeExecutorSpawnFailure(error62) };
|
|
30990
|
-
}
|
|
30991
|
-
}
|
|
30992
|
-
async function readCliVersionCommand(host, input2) {
|
|
30993
|
-
try {
|
|
30994
|
-
const run = await runProcessOperation(host, {
|
|
30995
|
-
program: input2.program,
|
|
30996
|
-
args: ["--version"],
|
|
30997
|
-
owner: { bindingId: host.bindingId },
|
|
30998
|
-
...Object.keys(input2.env).length > 0 ? { env: input2.env } : {},
|
|
30999
|
-
signal: input2.signal,
|
|
31000
|
-
timeoutMs: input2.timeoutMs,
|
|
31001
|
-
maxOutputBytes: 64 * 1024
|
|
31002
|
-
});
|
|
31003
|
-
if (run.exitCode !== 0 && !input2.acceptNonzeroExit) return null;
|
|
31004
|
-
return input2.parse(run.stdout) ?? input2.parse(run.stderr);
|
|
31005
|
-
} catch (error62) {
|
|
31006
|
-
if (isOperationCleanupError(error62) || input2.signal?.aborted) throw error62;
|
|
31007
|
-
return null;
|
|
31008
|
-
}
|
|
31009
|
-
}
|
|
31010
30662
|
|
|
31011
30663
|
// src/probeModels.ts
|
|
30664
|
+
import {
|
|
30665
|
+
tokenizeShellWords,
|
|
30666
|
+
readCliVersionCommand,
|
|
30667
|
+
spawnProbeProcess
|
|
30668
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
31012
30669
|
var PROBE_REQUEST_TIMEOUT_MS = 2e4;
|
|
31013
30670
|
function grokProbeModels(initializeResult) {
|
|
31014
30671
|
if (grokModelState(initializeResult) === void 0) return void 0;
|
|
@@ -31061,11 +30718,11 @@ var GROK_MODEL_CACHE_FILE = "models_cache.json";
|
|
|
31061
30718
|
var GROK_MODEL_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
31062
30719
|
var GROK_MODELS_COMMAND_TIMEOUT_MS = 6e4;
|
|
31063
30720
|
function grokModelCachePath(accountHome) {
|
|
31064
|
-
return
|
|
30721
|
+
return NodePath7.join(accountHome, GROK_MODEL_CACHE_FILE);
|
|
31065
30722
|
}
|
|
31066
30723
|
function readGrokModelCacheMtimeMs(accountHome) {
|
|
31067
30724
|
try {
|
|
31068
|
-
return
|
|
30725
|
+
return NodeFS3.statSync(grokModelCachePath(accountHome)).mtimeMs;
|
|
31069
30726
|
} catch {
|
|
31070
30727
|
return null;
|
|
31071
30728
|
}
|
|
@@ -31080,7 +30737,7 @@ async function runGrokModelsCommand(input2) {
|
|
|
31080
30737
|
const { recipe, host, env } = input2;
|
|
31081
30738
|
throwIfExecutorSpawnAborted(input2.signal);
|
|
31082
30739
|
try {
|
|
31083
|
-
const run = await
|
|
30740
|
+
const run = await runProcessOperation(host, {
|
|
31084
30741
|
program: recipe.binaryPath,
|
|
31085
30742
|
args: ["models"],
|
|
31086
30743
|
cwd: process.cwd(),
|
|
@@ -31097,10 +30754,10 @@ async function runGrokModelsCommand(input2) {
|
|
|
31097
30754
|
}
|
|
31098
30755
|
return true;
|
|
31099
30756
|
} catch (error62) {
|
|
31100
|
-
if (error62 instanceof
|
|
30757
|
+
if (error62 instanceof ExecutorSpawnAbortedError || isOperationCleanupError(error62) || input2.signal?.aborted)
|
|
31101
30758
|
throw error62;
|
|
31102
30759
|
host.log.warn("grok models failed; keeping the previous model list", {
|
|
31103
|
-
detail: error62 instanceof
|
|
30760
|
+
detail: error62 instanceof ExecutorSpawnRefusedError ? "process limit" : String(error62)
|
|
31104
30761
|
});
|
|
31105
30762
|
return false;
|
|
31106
30763
|
}
|
|
@@ -31182,7 +30839,7 @@ function createGrokModelCatalog(input2) {
|
|
|
31182
30839
|
throw new Error("grok models failed");
|
|
31183
30840
|
}
|
|
31184
30841
|
} catch (error62) {
|
|
31185
|
-
if (error62 instanceof
|
|
30842
|
+
if (error62 instanceof ExecutorSpawnAbortedError || isOperationCleanupError(error62) || request.signal?.aborted)
|
|
31186
30843
|
throw error62;
|
|
31187
30844
|
if (request.surfaceErrors === true) throw error62;
|
|
31188
30845
|
input2.host.log.warn("grok model cache refresh failed; keeping the previous model list", {
|
|
@@ -31195,8 +30852,8 @@ function createGrokModelCatalog(input2) {
|
|
|
31195
30852
|
}
|
|
31196
30853
|
|
|
31197
30854
|
// src/grokFollowUpSteer.ts
|
|
31198
|
-
import * as
|
|
31199
|
-
import * as
|
|
30855
|
+
import * as NodeFS4 from "node:fs";
|
|
30856
|
+
import * as NodePath8 from "node:path";
|
|
31200
30857
|
var SETTING = 'follow_up_behavior = "steer"';
|
|
31201
30858
|
function grokFollowUpSteerIsOn(text4) {
|
|
31202
30859
|
const lines = text4.split(/\r?\n/).map((line) => line.trim());
|
|
@@ -31210,21 +30867,21 @@ function grokFollowUpSteerIsOn(text4) {
|
|
|
31210
30867
|
return false;
|
|
31211
30868
|
}
|
|
31212
30869
|
function ensureGrokFollowUpSteer(homePath) {
|
|
31213
|
-
const path =
|
|
30870
|
+
const path = NodePath8.join(homePath, "config.toml");
|
|
31214
30871
|
try {
|
|
31215
|
-
return grokFollowUpSteerIsOn(
|
|
30872
|
+
return grokFollowUpSteerIsOn(NodeFS4.readFileSync(path, "utf8")) ? "on" : "off";
|
|
31216
30873
|
} catch (error62) {
|
|
31217
30874
|
if (error62.code !== "ENOENT") throw error62;
|
|
31218
30875
|
}
|
|
31219
|
-
|
|
30876
|
+
NodeFS4.mkdirSync(homePath, { recursive: true });
|
|
31220
30877
|
try {
|
|
31221
|
-
|
|
30878
|
+
NodeFS4.writeFileSync(path, `[ui]
|
|
31222
30879
|
${SETTING}
|
|
31223
30880
|
`, { encoding: "utf8", flag: "wx" });
|
|
31224
30881
|
return "created";
|
|
31225
30882
|
} catch (error62) {
|
|
31226
30883
|
if (error62.code !== "EEXIST") throw error62;
|
|
31227
|
-
return grokFollowUpSteerIsOn(
|
|
30884
|
+
return grokFollowUpSteerIsOn(NodeFS4.readFileSync(path, "utf8")) ? "on" : "off";
|
|
31228
30885
|
}
|
|
31229
30886
|
}
|
|
31230
30887
|
function prepareGrokFollowUpSteer(homePath, log, threadId) {
|
|
@@ -31260,42 +30917,23 @@ var grokPermissionStatement = ({
|
|
|
31260
30917
|
};
|
|
31261
30918
|
|
|
31262
30919
|
// src/nativeSessions.ts
|
|
31263
|
-
import * as
|
|
30920
|
+
import * as NodeFS5 from "node:fs";
|
|
31264
30921
|
import * as NodeFSP from "node:fs/promises";
|
|
31265
|
-
import * as
|
|
30922
|
+
import * as NodePath9 from "node:path";
|
|
31266
30923
|
import * as NodeReadline from "node:readline";
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
|
|
31270
|
-
|
|
31271
|
-
|
|
31272
|
-
|
|
31273
|
-
|
|
31274
|
-
|
|
31275
|
-
return home;
|
|
31276
|
-
}
|
|
31277
|
-
}
|
|
31278
|
-
function isAbsoluteDirectory(path) {
|
|
31279
|
-
if (!NodePath10.isAbsolute(path)) return false;
|
|
31280
|
-
if (NodePath10.sep !== "\\") return true;
|
|
31281
|
-
const { root } = NodePath10.parse(path);
|
|
31282
|
-
return root.length > 1;
|
|
31283
|
-
}
|
|
31284
|
-
var directoryKey = (directory) => {
|
|
31285
|
-
const resolved = NodePath10.resolve(directory);
|
|
31286
|
-
return NodePath10.sep === "\\" ? resolved.toLowerCase() : resolved;
|
|
31287
|
-
};
|
|
31288
|
-
function matchesSessionDirectory(rootKey, cwd, mode) {
|
|
31289
|
-
const relative2 = NodePath10.relative(rootKey, directoryKey(cwd));
|
|
31290
|
-
return relative2 === "" || mode === "scan" && relative2 !== ".." && !relative2.startsWith(`..${NodePath10.sep}`) && !NodePath10.isAbsolute(relative2);
|
|
31291
|
-
}
|
|
31292
|
-
|
|
31293
|
-
// src/nativeSessions.ts
|
|
30924
|
+
import {
|
|
30925
|
+
directoryKey,
|
|
30926
|
+
isAbsoluteDirectory,
|
|
30927
|
+
matchesSessionDirectory,
|
|
30928
|
+
readableStoragePath,
|
|
30929
|
+
inputPayload as inputPayload2,
|
|
30930
|
+
outputPayload as outputPayload2
|
|
30931
|
+
} from "@ycodium-ai/plugin-api/session-history";
|
|
31294
30932
|
var sessionIdPattern = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/iu;
|
|
31295
30933
|
function parseRecord(raw) {
|
|
31296
30934
|
try {
|
|
31297
30935
|
const value = JSON.parse(raw);
|
|
31298
|
-
return
|
|
30936
|
+
return isRecord10(value) ? value : void 0;
|
|
31299
30937
|
} catch {
|
|
31300
30938
|
return void 0;
|
|
31301
30939
|
}
|
|
@@ -31315,22 +30953,22 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
|
31315
30953
|
signal?.throwIfAborted();
|
|
31316
30954
|
const expectedCwd = directoryKey(cwd);
|
|
31317
30955
|
const result = [];
|
|
31318
|
-
const root =
|
|
30956
|
+
const root = NodePath9.join(home, "sessions");
|
|
31319
30957
|
for (const workspace of await directories(root)) {
|
|
31320
|
-
const workspacePath =
|
|
30958
|
+
const workspacePath = NodePath9.join(root, workspace);
|
|
31321
30959
|
for (const id of await directories(workspacePath)) {
|
|
31322
30960
|
signal?.throwIfAborted();
|
|
31323
30961
|
if (!sessionIdPattern.test(id) || nativeSessionId !== void 0 && nativeSessionId !== id)
|
|
31324
30962
|
continue;
|
|
31325
|
-
const sessionPath =
|
|
31326
|
-
const summaryPath =
|
|
30963
|
+
const sessionPath = NodePath9.join(workspacePath, id);
|
|
30964
|
+
const summaryPath = NodePath9.join(sessionPath, "summary.json");
|
|
31327
30965
|
try {
|
|
31328
30966
|
if (!(await NodeFSP.lstat(summaryPath)).isFile()) continue;
|
|
31329
30967
|
const summary = parseRecord(
|
|
31330
30968
|
await NodeFSP.readFile(summaryPath, { encoding: "utf8", signal })
|
|
31331
30969
|
);
|
|
31332
30970
|
const info = summary?.info;
|
|
31333
|
-
if (!summary || !
|
|
30971
|
+
if (!summary || !isRecord10(info) || info.id !== id || typeof info.cwd !== "string" || !isAbsoluteDirectory(info.cwd))
|
|
31334
30972
|
continue;
|
|
31335
30973
|
if (!matchesSessionDirectory(
|
|
31336
30974
|
expectedCwd,
|
|
@@ -31338,7 +30976,7 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
|
31338
30976
|
nativeSessionId === void 0 ? "scan" : "read"
|
|
31339
30977
|
))
|
|
31340
30978
|
continue;
|
|
31341
|
-
const updates =
|
|
30979
|
+
const updates = NodePath9.join(sessionPath, "updates.jsonl");
|
|
31342
30980
|
if (!(await NodeFSP.lstat(updates)).isFile()) continue;
|
|
31343
30981
|
const updatedAt = Date.parse(trimmed2(summary.updated_at) ?? "");
|
|
31344
30982
|
result.push({
|
|
@@ -31361,12 +30999,12 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
|
31361
30999
|
function toolOutput(content) {
|
|
31362
31000
|
if (!Array.isArray(content)) return void 0;
|
|
31363
31001
|
const output2 = content.flatMap(
|
|
31364
|
-
(entry) =>
|
|
31002
|
+
(entry) => isRecord10(entry) && isRecord10(entry.content) && entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : []
|
|
31365
31003
|
).join("\n");
|
|
31366
31004
|
return output2.length === 0 ? void 0 : output2;
|
|
31367
31005
|
}
|
|
31368
31006
|
async function readTranscript(session, signal, summaryOnly = false) {
|
|
31369
|
-
const stream =
|
|
31007
|
+
const stream = NodeFS5.createReadStream(session.updates, { signal });
|
|
31370
31008
|
const lines = NodeReadline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
31371
31009
|
const messages = [];
|
|
31372
31010
|
const activities = [];
|
|
@@ -31384,11 +31022,11 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31384
31022
|
signal?.throwIfAborted();
|
|
31385
31023
|
sourceOrder += 1;
|
|
31386
31024
|
const row = parseRecord(line);
|
|
31387
|
-
if (!row || !
|
|
31025
|
+
if (!row || !isRecord10(row.params) || row.params.sessionId !== session.id) continue;
|
|
31388
31026
|
const { update, _meta: metadata } = row.params;
|
|
31389
|
-
if (!
|
|
31390
|
-
const updateMetadata =
|
|
31391
|
-
const eventId =
|
|
31027
|
+
if (!isRecord10(update)) continue;
|
|
31028
|
+
const updateMetadata = isRecord10(update._meta) ? update._meta : void 0;
|
|
31029
|
+
const eventId = isRecord10(metadata) ? trimmed2(metadata.eventId) : void 0;
|
|
31392
31030
|
const sourceId = eventId ?? `update:${sourceOrder}`;
|
|
31393
31031
|
const timestamp = typeof row.timestamp_us === "number" ? row.timestamp_us / 1e3 : typeof row.timestamp === "number" ? row.timestamp * 1e3 : session.updatedAt;
|
|
31394
31032
|
const createdAt = new Date(Math.abs(timestamp) <= 864e13 ? timestamp : 0).toISOString();
|
|
@@ -31410,7 +31048,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31410
31048
|
};
|
|
31411
31049
|
if (role !== void 0) {
|
|
31412
31050
|
const content = update.content;
|
|
31413
|
-
if (!
|
|
31051
|
+
if (!isRecord10(content) || content.type !== "text" || typeof content.text !== "string" || content.text.length === 0)
|
|
31414
31052
|
continue;
|
|
31415
31053
|
hasMessages = true;
|
|
31416
31054
|
const continuing = previous?.role === role && previous.nativeTurnId === nativeTurnId;
|
|
@@ -31434,8 +31072,8 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31434
31072
|
if (summaryOnly) continue;
|
|
31435
31073
|
if (type === "tool_call") {
|
|
31436
31074
|
const name = trimmed2(update.title) ?? "Tool";
|
|
31437
|
-
const tool =
|
|
31438
|
-
const input2 =
|
|
31075
|
+
const tool = isRecord10(updateMetadata?.["x.ai/tool"]) ? updateMetadata["x.ai/tool"] : void 0;
|
|
31076
|
+
const input2 = isRecord10(update.rawInput) && typeof update.rawInput.command === "string" ? update.rawInput.command : update.rawInput === void 0 ? void 0 : JSON.stringify(update.rawInput);
|
|
31439
31077
|
const activity = {
|
|
31440
31078
|
...identity,
|
|
31441
31079
|
kind: "tool.started",
|
|
@@ -31446,7 +31084,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31446
31084
|
toolName: name,
|
|
31447
31085
|
itemType: tool?.kind === "execute" ? "command_execution" : "dynamic_tool_call",
|
|
31448
31086
|
startedAt: createdAt,
|
|
31449
|
-
...
|
|
31087
|
+
...inputPayload2(input2)
|
|
31450
31088
|
}
|
|
31451
31089
|
};
|
|
31452
31090
|
activities.push(activity);
|
|
@@ -31463,7 +31101,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
|
|
|
31463
31101
|
payload: {
|
|
31464
31102
|
...start.payload,
|
|
31465
31103
|
status: update.status,
|
|
31466
|
-
...
|
|
31104
|
+
...outputPayload2(output2)
|
|
31467
31105
|
}
|
|
31468
31106
|
});
|
|
31469
31107
|
tools.delete(toolCallId);
|
|
@@ -31706,8 +31344,8 @@ var createGrokInstance = (config2, host) => {
|
|
|
31706
31344
|
input2.threadId
|
|
31707
31345
|
);
|
|
31708
31346
|
const env = spawnEnv();
|
|
31709
|
-
const effort =
|
|
31710
|
-
const baseArgs =
|
|
31347
|
+
const effort = modelSelectionStringOption2(input2.modelSelection, GROK_REASONING_OPTION_ID);
|
|
31348
|
+
const baseArgs = tokenizeShellWords2(recipe.launchArgs);
|
|
31711
31349
|
const insertAt = baseArgs.length <= 1 ? baseArgs.length : baseArgs.length - 1;
|
|
31712
31350
|
const permissionMode = grokPermissionModeFor(input2.runtimeMode, input2.nativeModeId);
|
|
31713
31351
|
const args = [
|
|
@@ -31841,7 +31479,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
31841
31479
|
if (caveat !== void 0) {
|
|
31842
31480
|
input2.events.emit({
|
|
31843
31481
|
type: "runtime.warning",
|
|
31844
|
-
eventId:
|
|
31482
|
+
eventId: NodeCrypto3.randomUUID(),
|
|
31845
31483
|
provider: GROK_DRIVER_KIND,
|
|
31846
31484
|
providerInstanceId: host.instanceId,
|
|
31847
31485
|
threadId: input2.threadId,
|