@ai-sdk/harness 1.0.124 → 1.0.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +9 -8
- package/agent/index.ts +2 -0
- package/dist/agent/index.d.ts +31 -19
- package/dist/agent/index.js +340 -248
- package/dist/agent/index.js.map +1 -1
- package/dist/index.d.ts +39 -17
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +7 -14
- package/dist/utils/index.js +63 -97
- package/dist/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/agent/create-harness-sandbox-template.ts +80 -0
- package/src/agent/harness-agent-settings.ts +1 -0
- package/src/agent/harness-agent-types.ts +2 -0
- package/src/agent/harness-agent.ts +23 -0
- package/src/agent/internal/on-bootstrap-marker.ts +70 -0
- package/src/agent/internal/prepared-sandbox-identity.ts +42 -0
- package/src/agent/internal/sandbox-bootstrap.ts +19 -0
- package/src/agent/prepare-harness-sandbox-template.ts +5 -2
- package/src/agent/prepare-sandbox-for-harness.ts +7 -51
- package/src/v1/harness-v1-network-sandbox-session.ts +7 -14
- package/src/v1/harness-v1-sandbox-provider.ts +3 -2
- package/src/v1/harness-v1-sandbox-session-create-options.ts +14 -0
- package/src/v1/harness-v1-sandbox-session-resume-options.ts +10 -0
- package/src/v1/harness-v1-sandbox-template.ts +9 -0
- package/src/v1/index.ts +3 -0
package/dist/utils/index.js
CHANGED
|
@@ -10,8 +10,7 @@ function sleep({
|
|
|
10
10
|
abortSignal
|
|
11
11
|
}) {
|
|
12
12
|
return new Promise((resolve) => {
|
|
13
|
-
|
|
14
|
-
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
13
|
+
if (abortSignal?.aborted) {
|
|
15
14
|
resolve();
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
@@ -21,16 +20,16 @@ function sleep({
|
|
|
21
20
|
const finish = () => {
|
|
22
21
|
if (settled) return;
|
|
23
22
|
settled = true;
|
|
24
|
-
abortSignal
|
|
23
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
25
24
|
resolve();
|
|
26
25
|
};
|
|
27
26
|
const timer = setTimeout(finish, ms);
|
|
28
|
-
|
|
27
|
+
timer.unref?.();
|
|
29
28
|
onAbort = () => {
|
|
30
29
|
clearTimeout(timer);
|
|
31
30
|
finish();
|
|
32
31
|
};
|
|
33
|
-
abortSignal
|
|
32
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
|
|
@@ -41,8 +40,7 @@ var sandboxChannelEventCheckpointSymbol = /* @__PURE__ */ Symbol.for(
|
|
|
41
40
|
function getAbortReason({
|
|
42
41
|
abortSignal
|
|
43
42
|
}) {
|
|
44
|
-
|
|
45
|
-
return (_a = abortSignal.reason) != null ? _a : new Error("SandboxChannel connection aborted");
|
|
43
|
+
return abortSignal.reason ?? new Error("SandboxChannel connection aborted");
|
|
46
44
|
}
|
|
47
45
|
function closeWebSocket({ ws }) {
|
|
48
46
|
try {
|
|
@@ -52,10 +50,10 @@ function closeWebSocket({ ws }) {
|
|
|
52
50
|
} else {
|
|
53
51
|
ws.close();
|
|
54
52
|
}
|
|
55
|
-
} catch
|
|
53
|
+
} catch {
|
|
56
54
|
try {
|
|
57
55
|
ws.close();
|
|
58
|
-
} catch
|
|
56
|
+
} catch {
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -118,16 +116,15 @@ var SandboxChannel = class {
|
|
|
118
116
|
this._lastSeenEventId = 0;
|
|
119
117
|
this.pendingSends = [];
|
|
120
118
|
this.dispatchChain = Promise.resolve();
|
|
121
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
122
119
|
this.connectThunk = options.connect;
|
|
123
120
|
this.outboundSchema = options.outboundSchema;
|
|
124
121
|
this.onDebug = options.onDebug;
|
|
125
122
|
this.onDiagnostic = options.onDiagnostic;
|
|
126
123
|
this.onBridgeError = options.onBridgeError;
|
|
127
|
-
this.maxElapsedMs =
|
|
128
|
-
this.initialDelayMs =
|
|
129
|
-
this.maxDelayMs =
|
|
130
|
-
this._lastSeenEventId =
|
|
124
|
+
this.maxElapsedMs = options.reconnect?.maxElapsedMs ?? 3e4;
|
|
125
|
+
this.initialDelayMs = options.reconnect?.initialDelayMs ?? 50;
|
|
126
|
+
this.maxDelayMs = options.reconnect?.maxDelayMs ?? 2e3;
|
|
127
|
+
this._lastSeenEventId = options.initialLastSeenEventId ?? 0;
|
|
131
128
|
}
|
|
132
129
|
/**
|
|
133
130
|
* Highest bridge event `seq` this channel has observed. Persist it (e.g. via
|
|
@@ -161,7 +158,7 @@ var SandboxChannel = class {
|
|
|
161
158
|
this.wire(ws);
|
|
162
159
|
this.ws = ws;
|
|
163
160
|
this.connected = true;
|
|
164
|
-
if (opts
|
|
161
|
+
if (opts?.resume) {
|
|
165
162
|
this.rawSend(
|
|
166
163
|
JSON.stringify({
|
|
167
164
|
type: "resume",
|
|
@@ -245,13 +242,12 @@ var SandboxChannel = class {
|
|
|
245
242
|
this.abortActiveConnect();
|
|
246
243
|
}
|
|
247
244
|
close() {
|
|
248
|
-
var _a;
|
|
249
245
|
if (this.terminal) return;
|
|
250
246
|
this.closing = true;
|
|
251
247
|
this.abortActiveConnect();
|
|
252
248
|
try {
|
|
253
|
-
|
|
254
|
-
} catch
|
|
249
|
+
this.ws?.close();
|
|
250
|
+
} catch {
|
|
255
251
|
}
|
|
256
252
|
this.enqueue(() => this.finalizeClose(1e3, "closed"));
|
|
257
253
|
}
|
|
@@ -271,23 +267,21 @@ var SandboxChannel = class {
|
|
|
271
267
|
*/
|
|
272
268
|
suspend() {
|
|
273
269
|
return new Promise((resolve) => {
|
|
274
|
-
|
|
275
|
-
const pinnedSuspensionCursor = (_a = this.pinnedSuspensionCursor) == null ? void 0 : _a.eventId;
|
|
270
|
+
const pinnedSuspensionCursor = this.pinnedSuspensionCursor?.eventId;
|
|
276
271
|
if (this.terminal) {
|
|
277
|
-
resolve(pinnedSuspensionCursor
|
|
272
|
+
resolve(pinnedSuspensionCursor ?? this._lastSeenEventId);
|
|
278
273
|
return;
|
|
279
274
|
}
|
|
280
275
|
this.suspended = true;
|
|
281
276
|
this.closing = true;
|
|
282
277
|
this.abortActiveConnect();
|
|
283
278
|
this.onClose(
|
|
284
|
-
() => resolve(pinnedSuspensionCursor
|
|
279
|
+
() => resolve(pinnedSuspensionCursor ?? this._lastSeenEventId)
|
|
285
280
|
);
|
|
286
281
|
this.enqueue(() => {
|
|
287
|
-
var _a2;
|
|
288
282
|
try {
|
|
289
|
-
|
|
290
|
-
} catch
|
|
283
|
+
this.ws?.close();
|
|
284
|
+
} catch {
|
|
291
285
|
}
|
|
292
286
|
this.finalizeClose(1e3, "suspended");
|
|
293
287
|
});
|
|
@@ -317,15 +311,11 @@ var SandboxChannel = class {
|
|
|
317
311
|
});
|
|
318
312
|
ws.on(
|
|
319
313
|
"close",
|
|
320
|
-
(code, reason) =>
|
|
321
|
-
var _a, _b;
|
|
322
|
-
return onDrop(code, (_b = (_a = reason == null ? void 0 : reason.toString) == null ? void 0 : _a.call(reason, "utf8")) != null ? _b : "");
|
|
323
|
-
}
|
|
314
|
+
(code, reason) => onDrop(code, reason?.toString?.("utf8") ?? "")
|
|
324
315
|
);
|
|
325
316
|
ws.on("error", () => onDrop(1006, "socket error"));
|
|
326
317
|
}
|
|
327
318
|
async reconnectLoop() {
|
|
328
|
-
var _a, _b, _c;
|
|
329
319
|
if (this.terminal || this.closing) return;
|
|
330
320
|
const deadline = Date.now() + this.maxElapsedMs;
|
|
331
321
|
let attempt = 0;
|
|
@@ -343,7 +333,7 @@ var SandboxChannel = class {
|
|
|
343
333
|
return;
|
|
344
334
|
}
|
|
345
335
|
attempt++;
|
|
346
|
-
|
|
336
|
+
this.onDebug?.({
|
|
347
337
|
event: "reconnect-attempt",
|
|
348
338
|
attempt,
|
|
349
339
|
lastSeenEventId: this._lastSeenEventId
|
|
@@ -361,7 +351,7 @@ var SandboxChannel = class {
|
|
|
361
351
|
const timeout = setTimeout(() => {
|
|
362
352
|
abortController.abort(new Error("Reconnect deadline expired"));
|
|
363
353
|
}, remaining);
|
|
364
|
-
|
|
354
|
+
timeout.unref?.();
|
|
365
355
|
try {
|
|
366
356
|
const ws = await this.connect({
|
|
367
357
|
abortSignal: abortController.signal
|
|
@@ -381,7 +371,7 @@ var SandboxChannel = class {
|
|
|
381
371
|
);
|
|
382
372
|
this.flushPending();
|
|
383
373
|
for (const handler of this.onReconnectHandlers) handler();
|
|
384
|
-
|
|
374
|
+
this.onDebug?.({
|
|
385
375
|
event: "reconnected",
|
|
386
376
|
attempt,
|
|
387
377
|
lastSeenEventId: this._lastSeenEventId
|
|
@@ -429,11 +419,10 @@ var SandboxChannel = class {
|
|
|
429
419
|
});
|
|
430
420
|
}
|
|
431
421
|
abortActiveConnect() {
|
|
432
|
-
var _a;
|
|
433
422
|
const controller = this.activeConnectAbortController;
|
|
434
423
|
this.activeConnectAbortController = void 0;
|
|
435
|
-
controller
|
|
436
|
-
|
|
424
|
+
controller?.abort(new Error("SandboxChannel connection aborted"));
|
|
425
|
+
this.reconnectAbortController?.abort(
|
|
437
426
|
new Error("SandboxChannel connection aborted")
|
|
438
427
|
);
|
|
439
428
|
}
|
|
@@ -441,9 +430,8 @@ var SandboxChannel = class {
|
|
|
441
430
|
attempts,
|
|
442
431
|
cause
|
|
443
432
|
}) {
|
|
444
|
-
var _a;
|
|
445
433
|
this.finalizeClose(1006, "reconnect failed");
|
|
446
|
-
|
|
434
|
+
this.onDebug?.({
|
|
447
435
|
event: "reconnect-failed",
|
|
448
436
|
attempts,
|
|
449
437
|
lastSeenEventId: this._lastSeenEventId,
|
|
@@ -491,16 +479,14 @@ var SandboxChannel = class {
|
|
|
491
479
|
}
|
|
492
480
|
}
|
|
493
481
|
dispatch(message) {
|
|
494
|
-
var _a, _b;
|
|
495
482
|
if (message.type === "sandbox-log" || message.type === "debug-event") {
|
|
496
|
-
|
|
497
|
-
this,
|
|
483
|
+
this.onDiagnostic?.(
|
|
498
484
|
message
|
|
499
485
|
);
|
|
500
486
|
return;
|
|
501
487
|
}
|
|
502
488
|
if (message.type === "error") {
|
|
503
|
-
|
|
489
|
+
this.onBridgeError?.(message);
|
|
504
490
|
}
|
|
505
491
|
const type = message.type;
|
|
506
492
|
const set = this.listeners.get(type);
|
|
@@ -520,7 +506,6 @@ var SandboxChannel = class {
|
|
|
520
506
|
flushBuffered({
|
|
521
507
|
selective = false
|
|
522
508
|
} = {}) {
|
|
523
|
-
var _a;
|
|
524
509
|
if (this.flushingBuffered || this.listenerAttachmentDepth > 0) return;
|
|
525
510
|
this.flushingBuffered = true;
|
|
526
511
|
try {
|
|
@@ -529,7 +514,7 @@ var SandboxChannel = class {
|
|
|
529
514
|
const message = bufferedEvent.message;
|
|
530
515
|
const type = message.type;
|
|
531
516
|
const set = this.listeners.get(type);
|
|
532
|
-
const listeners =
|
|
517
|
+
const listeners = bufferedEvent.listeners ?? (set != null && set.size > 0 ? Array.from(set) : void 0);
|
|
533
518
|
if (!listeners || listeners.length === 0) {
|
|
534
519
|
if (!selective) return;
|
|
535
520
|
this.bufferedOffset++;
|
|
@@ -610,8 +595,7 @@ var SandboxChannel = class {
|
|
|
610
595
|
const token = {};
|
|
611
596
|
this.pinnedSuspensionCursor = { eventId: options.eventId, token };
|
|
612
597
|
return () => {
|
|
613
|
-
|
|
614
|
-
if (((_a = this.pinnedSuspensionCursor) == null ? void 0 : _a.token) === token) {
|
|
598
|
+
if (this.pinnedSuspensionCursor?.token === token) {
|
|
615
599
|
this.pinnedSuspensionCursor = void 0;
|
|
616
600
|
}
|
|
617
601
|
};
|
|
@@ -643,7 +627,6 @@ function experimental_createBridgeUserMessageSubmitter(options) {
|
|
|
643
627
|
}
|
|
644
628
|
};
|
|
645
629
|
const unsubscribeResponse = options.onResponse((response) => {
|
|
646
|
-
var _a, _b;
|
|
647
630
|
const entry = pending.get(response.messageId);
|
|
648
631
|
if (entry == null) return;
|
|
649
632
|
pending.delete(response.messageId);
|
|
@@ -652,7 +635,7 @@ function experimental_createBridgeUserMessageSubmitter(options) {
|
|
|
652
635
|
} else {
|
|
653
636
|
entry.reject(
|
|
654
637
|
new Error(
|
|
655
|
-
|
|
638
|
+
response.error?.message ?? "The runtime rejected the user message."
|
|
656
639
|
)
|
|
657
640
|
);
|
|
658
641
|
}
|
|
@@ -684,7 +667,7 @@ function experimental_createBridgeUserMessageSubmitter(options) {
|
|
|
684
667
|
closed = true;
|
|
685
668
|
unsubscribeResponse();
|
|
686
669
|
unsubscribeReconnect();
|
|
687
|
-
const reason = error
|
|
670
|
+
const reason = error ?? new Error("The bridge turn ended before accepting the user message.");
|
|
688
671
|
for (const entry of pending.values()) entry.reject(reason);
|
|
689
672
|
pending.clear();
|
|
690
673
|
}
|
|
@@ -710,10 +693,9 @@ var DEFAULT_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh";
|
|
|
710
693
|
function getAiGatewayAuthFromEnv({
|
|
711
694
|
env
|
|
712
695
|
}) {
|
|
713
|
-
var _a;
|
|
714
696
|
return {
|
|
715
697
|
apiKey: env.AI_GATEWAY_API_KEY || env.VERCEL_OIDC_TOKEN || void 0,
|
|
716
|
-
baseUrl:
|
|
698
|
+
baseUrl: env.AI_GATEWAY_BASE_URL ?? DEFAULT_AI_GATEWAY_BASE_URL
|
|
717
699
|
};
|
|
718
700
|
}
|
|
719
701
|
|
|
@@ -742,7 +724,7 @@ async function parseJwtPayload({
|
|
|
742
724
|
text: Buffer.from(segments[1], "base64url").toString("utf8")
|
|
743
725
|
});
|
|
744
726
|
return parsed.success && isRecord(parsed.value) ? parsed.value : void 0;
|
|
745
|
-
} catch
|
|
727
|
+
} catch {
|
|
746
728
|
return void 0;
|
|
747
729
|
}
|
|
748
730
|
}
|
|
@@ -750,7 +732,7 @@ async function getJwtExpiresAt({
|
|
|
750
732
|
token
|
|
751
733
|
}) {
|
|
752
734
|
const payload = await parseJwtPayload({ token });
|
|
753
|
-
const expiresAt = payload
|
|
735
|
+
const expiresAt = payload?.exp;
|
|
754
736
|
return typeof expiresAt === "number" && Number.isFinite(expiresAt) ? expiresAt * 1e3 : void 0;
|
|
755
737
|
}
|
|
756
738
|
|
|
@@ -770,7 +752,7 @@ async function readLinuxSecretServicePassword({
|
|
|
770
752
|
])
|
|
771
753
|
]);
|
|
772
754
|
return result.stdout || void 0;
|
|
773
|
-
} catch
|
|
755
|
+
} catch {
|
|
774
756
|
return void 0;
|
|
775
757
|
}
|
|
776
758
|
}
|
|
@@ -793,7 +775,7 @@ async function readMacOSKeychainPassword({
|
|
|
793
775
|
"-w"
|
|
794
776
|
]);
|
|
795
777
|
return result.stdout.trim() || void 0;
|
|
796
|
-
} catch
|
|
778
|
+
} catch {
|
|
797
779
|
return void 0;
|
|
798
780
|
}
|
|
799
781
|
}
|
|
@@ -860,7 +842,7 @@ async function readWindowsCredentialManagerPassword({
|
|
|
860
842
|
}
|
|
861
843
|
);
|
|
862
844
|
return result.stdout || void 0;
|
|
863
|
-
} catch
|
|
845
|
+
} catch {
|
|
864
846
|
return void 0;
|
|
865
847
|
}
|
|
866
848
|
}
|
|
@@ -1168,7 +1150,6 @@ function deriveOriginalContent({
|
|
|
1168
1150
|
currentDiskContent,
|
|
1169
1151
|
existingMetadata
|
|
1170
1152
|
}) {
|
|
1171
|
-
var _a;
|
|
1172
1153
|
if (existingMetadata == null) {
|
|
1173
1154
|
return currentDiskContent;
|
|
1174
1155
|
}
|
|
@@ -1189,7 +1170,7 @@ ${existingMetadata.instructions}`;
|
|
|
1189
1170
|
if (trimmedDisk === existingMetadata.instructions) {
|
|
1190
1171
|
return null;
|
|
1191
1172
|
}
|
|
1192
|
-
return
|
|
1173
|
+
return existingMetadata.originalContent ?? currentDiskContent;
|
|
1193
1174
|
}
|
|
1194
1175
|
function deriveRestoredContent({
|
|
1195
1176
|
currentDiskContent,
|
|
@@ -1363,7 +1344,6 @@ async function writeSkills({
|
|
|
1363
1344
|
invalidSkillFilePathMessage = ({ skillName, filePath }) => `Invalid skill file path for ${skillName}: ${filePath}`,
|
|
1364
1345
|
trailingNewline = false
|
|
1365
1346
|
}) {
|
|
1366
|
-
var _a;
|
|
1367
1347
|
const rootDir = resolveSkillsRootDir({ homePath, skillsDir });
|
|
1368
1348
|
const projectedSkills = skills.map(
|
|
1369
1349
|
(skill) => projectSkill({
|
|
@@ -1384,7 +1364,7 @@ async function writeSkills({
|
|
|
1384
1364
|
});
|
|
1385
1365
|
const nextEntries = projectedSkills.map(({ name, hash }) => ({ name, hash }));
|
|
1386
1366
|
const nextByName = new Map(nextEntries.map((entry) => [entry.name, entry]));
|
|
1387
|
-
if (
|
|
1367
|
+
if (existingManifest?.state === "pending") {
|
|
1388
1368
|
await ensureSkillsDirectory({ sandbox, rootDir, abortSignal });
|
|
1389
1369
|
const recoveryNames = existingManifest.skills.map((skill) => skill.name);
|
|
1390
1370
|
await removeSkillDirectories({
|
|
@@ -1417,19 +1397,13 @@ async function writeSkills({
|
|
|
1417
1397
|
unchanged: []
|
|
1418
1398
|
};
|
|
1419
1399
|
}
|
|
1420
|
-
const previousEntries =
|
|
1400
|
+
const previousEntries = existingManifest?.skills ?? [];
|
|
1421
1401
|
const previousByName = new Map(
|
|
1422
1402
|
previousEntries.map((entry) => [entry.name, entry])
|
|
1423
1403
|
);
|
|
1424
1404
|
const removed = previousEntries.filter((entry) => !nextByName.has(entry.name)).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
1425
|
-
const written = projectedSkills.filter((skill) =>
|
|
1426
|
-
|
|
1427
|
-
return ((_a2 = previousByName.get(skill.name)) == null ? void 0 : _a2.hash) !== skill.hash;
|
|
1428
|
-
}).map((skill) => skill.name).sort((a, b) => a.localeCompare(b));
|
|
1429
|
-
const unchanged = projectedSkills.filter((skill) => {
|
|
1430
|
-
var _a2;
|
|
1431
|
-
return ((_a2 = previousByName.get(skill.name)) == null ? void 0 : _a2.hash) === skill.hash;
|
|
1432
|
-
}).map((skill) => skill.name).sort((a, b) => a.localeCompare(b));
|
|
1405
|
+
const written = projectedSkills.filter((skill) => previousByName.get(skill.name)?.hash !== skill.hash).map((skill) => skill.name).sort((a, b) => a.localeCompare(b));
|
|
1406
|
+
const unchanged = projectedSkills.filter((skill) => previousByName.get(skill.name)?.hash === skill.hash).map((skill) => skill.name).sort((a, b) => a.localeCompare(b));
|
|
1433
1407
|
const changed = removed.length > 0 || written.length > 0;
|
|
1434
1408
|
if (!changed && existingManifest != null) {
|
|
1435
1409
|
return { changed: false, written, removed, unchanged };
|
|
@@ -1457,13 +1431,10 @@ async function writeSkills({
|
|
|
1457
1431
|
manifest: {
|
|
1458
1432
|
version: SKILLS_MANIFEST_VERSION,
|
|
1459
1433
|
state: "pending",
|
|
1460
|
-
skills: pendingNames.map((name) => {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
hash: (_b = (_a2 = nextByName.get(name)) == null ? void 0 : _a2.hash) != null ? _b : previousByName.get(name).hash
|
|
1465
|
-
};
|
|
1466
|
-
})
|
|
1434
|
+
skills: pendingNames.map((name) => ({
|
|
1435
|
+
name,
|
|
1436
|
+
hash: nextByName.get(name)?.hash ?? previousByName.get(name).hash
|
|
1437
|
+
}))
|
|
1467
1438
|
},
|
|
1468
1439
|
abortSignal
|
|
1469
1440
|
});
|
|
@@ -1515,7 +1486,6 @@ function projectSkill({
|
|
|
1515
1486
|
invalidSkillFilePathMessage,
|
|
1516
1487
|
trailingNewline
|
|
1517
1488
|
}) {
|
|
1518
|
-
var _a;
|
|
1519
1489
|
const name = validateSkillName({
|
|
1520
1490
|
name: skill.name,
|
|
1521
1491
|
pattern: skillNamePattern,
|
|
@@ -1523,7 +1493,7 @@ function projectSkill({
|
|
|
1523
1493
|
});
|
|
1524
1494
|
const files = /* @__PURE__ */ new Map();
|
|
1525
1495
|
files.set("SKILL.md", renderSkillFile({ skill, trailingNewline }));
|
|
1526
|
-
for (const file of
|
|
1496
|
+
for (const file of skill.files ?? []) {
|
|
1527
1497
|
files.set(
|
|
1528
1498
|
normalizeSkillFilePath({
|
|
1529
1499
|
skillName: skill.name,
|
|
@@ -1686,12 +1656,11 @@ function validateSkillName({
|
|
|
1686
1656
|
pattern,
|
|
1687
1657
|
message
|
|
1688
1658
|
}) {
|
|
1689
|
-
var _a;
|
|
1690
1659
|
pattern.lastIndex = 0;
|
|
1691
1660
|
const matches = pattern.test(name);
|
|
1692
1661
|
pattern.lastIndex = 0;
|
|
1693
1662
|
if (!matches || name === "." || name === "..") {
|
|
1694
|
-
throw new Error(
|
|
1663
|
+
throw new Error(message?.({ name }) ?? `Invalid skill name: ${name}`);
|
|
1695
1664
|
}
|
|
1696
1665
|
return name;
|
|
1697
1666
|
}
|
|
@@ -1701,12 +1670,11 @@ function normalizeSkillFilePath({
|
|
|
1701
1670
|
mode,
|
|
1702
1671
|
message
|
|
1703
1672
|
}) {
|
|
1704
|
-
var _a;
|
|
1705
1673
|
const normalized = mode === "strip-leading-slashes" ? filePath.replace(/^\/+/, "") : path3.posix.normalize(filePath);
|
|
1706
1674
|
const invalid = normalized === "" || mode === "relative" && normalized === "." || normalized.startsWith("../") || normalized.includes("/../") || normalized.endsWith("/..") || mode === "relative" && path3.posix.isAbsolute(normalized);
|
|
1707
1675
|
if (invalid) {
|
|
1708
1676
|
throw new Error(
|
|
1709
|
-
|
|
1677
|
+
message?.({ skillName: skillName ?? "", filePath }) ?? `Invalid skill file path for ${skillName}: ${filePath}`
|
|
1710
1678
|
);
|
|
1711
1679
|
}
|
|
1712
1680
|
return normalized;
|
|
@@ -2157,7 +2125,7 @@ async function markBridgeStarting({
|
|
|
2157
2125
|
content: JSON.stringify({ type: bridgeType, state: "starting" }),
|
|
2158
2126
|
abortSignal
|
|
2159
2127
|
});
|
|
2160
|
-
} catch
|
|
2128
|
+
} catch {
|
|
2161
2129
|
}
|
|
2162
2130
|
}
|
|
2163
2131
|
async function waitForBridgeReady({
|
|
@@ -2171,7 +2139,6 @@ async function waitForBridgeReady({
|
|
|
2171
2139
|
createTimeoutError,
|
|
2172
2140
|
createExitError
|
|
2173
2141
|
}) {
|
|
2174
|
-
var _a;
|
|
2175
2142
|
const reader = proc.stdout.pipeThrough(new TextDecoderStream()).getReader();
|
|
2176
2143
|
const decoder = lineDecoder();
|
|
2177
2144
|
const stdoutTail = [];
|
|
@@ -2182,10 +2149,10 @@ async function waitForBridgeReady({
|
|
|
2182
2149
|
let cancelReader = false;
|
|
2183
2150
|
try {
|
|
2184
2151
|
while (true) {
|
|
2185
|
-
if (abortSignal
|
|
2152
|
+
if (abortSignal?.aborted) {
|
|
2186
2153
|
cancelReader = true;
|
|
2187
2154
|
await proc.kill();
|
|
2188
|
-
throw
|
|
2155
|
+
throw abortSignal.reason ?? new DOMException("Aborted", "AbortError");
|
|
2189
2156
|
}
|
|
2190
2157
|
const remaining = deadline - Date.now();
|
|
2191
2158
|
if (remaining <= 0) {
|
|
@@ -2198,7 +2165,7 @@ async function waitForBridgeReady({
|
|
|
2198
2165
|
stdoutTail
|
|
2199
2166
|
});
|
|
2200
2167
|
}
|
|
2201
|
-
pendingStdoutRead
|
|
2168
|
+
pendingStdoutRead ??= reader.read();
|
|
2202
2169
|
const metaReadDelayMs = Math.max(0, nextMetaReadAt - Date.now());
|
|
2203
2170
|
if (pendingMetaRead === void 0 && metaReadDelayMs === 0) {
|
|
2204
2171
|
pendingMetaRead = readBridgeMetaReady({
|
|
@@ -2273,7 +2240,7 @@ async function waitForBridgeReady({
|
|
|
2273
2240
|
}
|
|
2274
2241
|
try {
|
|
2275
2242
|
reader.releaseLock();
|
|
2276
|
-
} catch
|
|
2243
|
+
} catch {
|
|
2277
2244
|
}
|
|
2278
2245
|
}
|
|
2279
2246
|
}
|
|
@@ -2372,24 +2339,23 @@ function stringifyUnknown(value) {
|
|
|
2372
2339
|
if (typeof value === "string") return value;
|
|
2373
2340
|
try {
|
|
2374
2341
|
return JSON.stringify(value);
|
|
2375
|
-
} catch
|
|
2342
|
+
} catch {
|
|
2376
2343
|
return String(value);
|
|
2377
2344
|
}
|
|
2378
2345
|
}
|
|
2379
2346
|
function formatBridgeError(error) {
|
|
2380
|
-
var _a, _b;
|
|
2381
2347
|
if (error instanceof Error) {
|
|
2382
|
-
return
|
|
2348
|
+
return error.stack ?? `${error.name}: ${error.message}`;
|
|
2383
2349
|
}
|
|
2384
2350
|
if (isSerializedError(error)) {
|
|
2385
|
-
return
|
|
2351
|
+
return error.stack ?? `${error.name ? `${error.name}: ` : ""}${error.message}`;
|
|
2386
2352
|
}
|
|
2387
2353
|
return stringifyUnknown(error);
|
|
2388
2354
|
}
|
|
2389
2355
|
function writeToStderr(line) {
|
|
2390
2356
|
try {
|
|
2391
2357
|
process.stderr.write(line);
|
|
2392
|
-
} catch
|
|
2358
|
+
} catch {
|
|
2393
2359
|
}
|
|
2394
2360
|
}
|
|
2395
2361
|
function logBridgeError({
|
|
@@ -2438,10 +2404,10 @@ async function createBridgeStartupError({
|
|
|
2438
2404
|
proc.wait(),
|
|
2439
2405
|
sleep3(250).then(() => void 0)
|
|
2440
2406
|
]);
|
|
2441
|
-
if (
|
|
2407
|
+
if (result?.exitCode !== void 0) {
|
|
2442
2408
|
exitStatus = ` Exit code: ${result.exitCode}.`;
|
|
2443
2409
|
}
|
|
2444
|
-
} catch
|
|
2410
|
+
} catch {
|
|
2445
2411
|
}
|
|
2446
2412
|
const details = [];
|
|
2447
2413
|
if (stdoutTail.length > 0) {
|
|
@@ -2478,7 +2444,7 @@ async function forwardBridgeProcessStream({
|
|
|
2478
2444
|
}
|
|
2479
2445
|
if (done) return;
|
|
2480
2446
|
}
|
|
2481
|
-
} catch
|
|
2447
|
+
} catch {
|
|
2482
2448
|
}
|
|
2483
2449
|
}
|
|
2484
2450
|
async function drainBridgeProcessStream(stream) {
|
|
@@ -2488,7 +2454,7 @@ async function drainBridgeProcessStream(stream) {
|
|
|
2488
2454
|
const { done } = await reader.read();
|
|
2489
2455
|
if (done) return;
|
|
2490
2456
|
}
|
|
2491
|
-
} catch
|
|
2457
|
+
} catch {
|
|
2492
2458
|
}
|
|
2493
2459
|
}
|
|
2494
2460
|
function recordTail({
|