@nimbus-dev/client 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +1907 -1857
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ipc-transport.d.ts +2 -1
- package/dist/ipc-transport.d.ts.map +1 -1
- package/dist/ipc-transport.js +3 -2
- package/dist/ipc-transport.js.map +1 -1
- package/dist/mock-client.d.ts.map +1 -1
- package/dist/mock-client.js +10 -1
- package/dist/mock-client.js.map +1 -1
- package/dist/nimbus-client.d.ts +46 -3
- package/dist/nimbus-client.d.ts.map +1 -1
- package/dist/nimbus-client.js +37 -1
- package/dist/nimbus-client.js.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +42 -5
- package/dist/validate.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -71,10 +71,13 @@ __export(exports_src, {
|
|
|
71
71
|
gatewayStatePath: () => gatewayStatePath,
|
|
72
72
|
discoverSocketPath: () => discoverSocketPath,
|
|
73
73
|
NimbusClient: () => NimbusClient,
|
|
74
|
+
NO_EGRESS_COVERAGE: () => NO_EGRESS_COVERAGE,
|
|
74
75
|
MockClient: () => MockClient,
|
|
75
76
|
JsonRpcError: () => JsonRpcError,
|
|
76
77
|
IpcResponseError: () => IpcResponseError,
|
|
77
78
|
IPCClient: () => IPCClient,
|
|
79
|
+
EGRESS_GRANULARITIES: () => EGRESS_GRANULARITIES,
|
|
80
|
+
EGRESS_COVERAGE_CLASSES: () => EGRESS_COVERAGE_CLASSES,
|
|
78
81
|
DEFAULT_AGENT_TIMEOUT_MS: () => DEFAULT_AGENT_TIMEOUT_MS,
|
|
79
82
|
AgentTimeoutError: () => AgentTimeoutError,
|
|
80
83
|
AgentBriefError: () => AgentBriefError
|
|
@@ -197,11 +200,11 @@ function arrayEntryRule(field, allowed) {
|
|
|
197
200
|
var RUNTIME_ENUM = {
|
|
198
201
|
id: "manifest.runtime.enum",
|
|
199
202
|
field: "runtime",
|
|
200
|
-
check: (manifest) => manifest["runtime"] === "bun" || manifest["runtime"] === "node" ? [] : [
|
|
203
|
+
check: (manifest) => manifest["runtime"] === "bun" || manifest["runtime"] === "node" || manifest["runtime"] === "python" ? [] : [
|
|
201
204
|
{
|
|
202
205
|
rule: "manifest.runtime.enum",
|
|
203
206
|
path: "/runtime",
|
|
204
|
-
message: 'manifest.runtime must be "bun" or "
|
|
207
|
+
message: 'manifest.runtime must be "bun", "node", or "python"'
|
|
205
208
|
}
|
|
206
209
|
]
|
|
207
210
|
};
|
|
@@ -416,6 +419,86 @@ var KNOWN_ITEM_TYPES = [
|
|
|
416
419
|
"worker"
|
|
417
420
|
];
|
|
418
421
|
var KNOWN = new Set(KNOWN_ITEM_TYPES);
|
|
422
|
+
// node_modules/@nimbus-dev/sdk/src/ipc/ndjson-line-reader.ts
|
|
423
|
+
var IPC_MAX_LINE_BYTES = 1024 * 1024;
|
|
424
|
+
function byteLengthUtf8(s) {
|
|
425
|
+
return new TextEncoder().encode(s).length;
|
|
426
|
+
}
|
|
427
|
+
var LINE_LIMIT_MESSAGE = "Message exceeds 1MB line limit";
|
|
428
|
+
var BYTE_ORDER_MARK = "\uFEFF";
|
|
429
|
+
|
|
430
|
+
class NdjsonLineReader {
|
|
431
|
+
lineLimitCtor;
|
|
432
|
+
decoder = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
|
|
433
|
+
pending = "";
|
|
434
|
+
latched = false;
|
|
435
|
+
streamStarted = false;
|
|
436
|
+
constructor(opts = {}) {
|
|
437
|
+
this.lineLimitCtor = opts.lineLimitError ?? Error;
|
|
438
|
+
}
|
|
439
|
+
throwLineTooLong(message) {
|
|
440
|
+
this.latched = true;
|
|
441
|
+
this.pending = "";
|
|
442
|
+
throw new this.lineLimitCtor(message);
|
|
443
|
+
}
|
|
444
|
+
failIfLatched() {
|
|
445
|
+
if (this.latched) {
|
|
446
|
+
throw new this.lineLimitCtor(LINE_LIMIT_MESSAGE);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
decode(chunk, stream) {
|
|
450
|
+
let text = this.decoder.decode(chunk, { stream });
|
|
451
|
+
if (text.length > 0 && !this.streamStarted) {
|
|
452
|
+
this.streamStarted = true;
|
|
453
|
+
if (text.startsWith(BYTE_ORDER_MARK)) {
|
|
454
|
+
text = text.slice(1);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return text;
|
|
458
|
+
}
|
|
459
|
+
push(chunk) {
|
|
460
|
+
this.failIfLatched();
|
|
461
|
+
this.pending += this.decode(chunk, true);
|
|
462
|
+
const out = [];
|
|
463
|
+
while (true) {
|
|
464
|
+
const nl = this.pending.indexOf(`
|
|
465
|
+
`);
|
|
466
|
+
if (nl < 0) {
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
const line = this.pending.slice(0, nl);
|
|
470
|
+
this.pending = this.pending.slice(nl + 1);
|
|
471
|
+
const trimmed = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
472
|
+
if (trimmed.length === 0) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (byteLengthUtf8(trimmed) > IPC_MAX_LINE_BYTES) {
|
|
476
|
+
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
477
|
+
}
|
|
478
|
+
out.push(trimmed);
|
|
479
|
+
}
|
|
480
|
+
if (byteLengthUtf8(this.pending) > IPC_MAX_LINE_BYTES) {
|
|
481
|
+
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
482
|
+
}
|
|
483
|
+
return out;
|
|
484
|
+
}
|
|
485
|
+
flushFrames() {
|
|
486
|
+
this.failIfLatched();
|
|
487
|
+
const rest = this.pending + this.decode(new Uint8Array(0), false);
|
|
488
|
+
this.pending = "";
|
|
489
|
+
if (byteLengthUtf8(rest) > IPC_MAX_LINE_BYTES) {
|
|
490
|
+
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
491
|
+
}
|
|
492
|
+
const frame = rest.endsWith("\r") ? rest.slice(0, -1) : rest;
|
|
493
|
+
if (frame.length === 0) {
|
|
494
|
+
return { frames: [], truncated: false };
|
|
495
|
+
}
|
|
496
|
+
return { frames: [frame], truncated: true };
|
|
497
|
+
}
|
|
498
|
+
flush() {
|
|
499
|
+
return this.flushFrames().frames;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
419
502
|
// node_modules/@nimbus-dev/sdk/src/testing/sandbox-protocol.ts
|
|
420
503
|
var NETWORK_BLOCKED_CODES = new Set([
|
|
421
504
|
"ECONNREFUSED",
|
|
@@ -577,75 +660,6 @@ async function discoverSocketPath(opts) {
|
|
|
577
660
|
var import_node_crypto = require("node:crypto");
|
|
578
661
|
var import_node_net = __toESM(require("node:net"));
|
|
579
662
|
var import_node_os2 = require("node:os");
|
|
580
|
-
// node_modules/@nimbus-dev/sdk/src/ipc/ndjson-line-reader.ts
|
|
581
|
-
var IPC_MAX_LINE_BYTES = 1024 * 1024;
|
|
582
|
-
function byteLengthUtf8(s) {
|
|
583
|
-
return new TextEncoder().encode(s).length;
|
|
584
|
-
}
|
|
585
|
-
var LINE_LIMIT_MESSAGE = "Message exceeds 1MB line limit";
|
|
586
|
-
|
|
587
|
-
class NdjsonLineReader {
|
|
588
|
-
lineLimitCtor;
|
|
589
|
-
decoder = new TextDecoder("utf-8", { fatal: false });
|
|
590
|
-
pending = "";
|
|
591
|
-
latched = false;
|
|
592
|
-
constructor(opts = {}) {
|
|
593
|
-
this.lineLimitCtor = opts.lineLimitError ?? Error;
|
|
594
|
-
}
|
|
595
|
-
throwLineTooLong(message) {
|
|
596
|
-
this.latched = true;
|
|
597
|
-
this.pending = "";
|
|
598
|
-
throw new this.lineLimitCtor(message);
|
|
599
|
-
}
|
|
600
|
-
failIfLatched() {
|
|
601
|
-
if (this.latched) {
|
|
602
|
-
throw new this.lineLimitCtor(LINE_LIMIT_MESSAGE);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
push(chunk) {
|
|
606
|
-
this.failIfLatched();
|
|
607
|
-
this.pending += this.decoder.decode(chunk, { stream: true });
|
|
608
|
-
const out = [];
|
|
609
|
-
while (true) {
|
|
610
|
-
const nl = this.pending.indexOf(`
|
|
611
|
-
`);
|
|
612
|
-
if (nl < 0) {
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
const line = this.pending.slice(0, nl);
|
|
616
|
-
this.pending = this.pending.slice(nl + 1);
|
|
617
|
-
const trimmed = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
618
|
-
if (trimmed.length === 0) {
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
if (byteLengthUtf8(trimmed) > IPC_MAX_LINE_BYTES) {
|
|
622
|
-
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
623
|
-
}
|
|
624
|
-
out.push(trimmed);
|
|
625
|
-
}
|
|
626
|
-
if (byteLengthUtf8(this.pending) > IPC_MAX_LINE_BYTES) {
|
|
627
|
-
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
628
|
-
}
|
|
629
|
-
return out;
|
|
630
|
-
}
|
|
631
|
-
flushFrames() {
|
|
632
|
-
this.failIfLatched();
|
|
633
|
-
const rest = this.pending + this.decoder.decode();
|
|
634
|
-
this.pending = "";
|
|
635
|
-
if (byteLengthUtf8(rest) > IPC_MAX_LINE_BYTES) {
|
|
636
|
-
this.throwLineTooLong(LINE_LIMIT_MESSAGE);
|
|
637
|
-
}
|
|
638
|
-
const frame = rest.endsWith("\r") ? rest.slice(0, -1) : rest;
|
|
639
|
-
if (frame.length === 0) {
|
|
640
|
-
return { frames: [], truncated: false };
|
|
641
|
-
}
|
|
642
|
-
return { frames: [frame], truncated: true };
|
|
643
|
-
}
|
|
644
|
-
flush() {
|
|
645
|
-
return this.flushFrames().frames;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
// src/ipc-transport.ts
|
|
649
663
|
var HAS_BUN = globalThis.Bun !== undefined;
|
|
650
664
|
var DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
651
665
|
function idKey(id) {
|
|
@@ -814,7 +828,7 @@ class IPCClient {
|
|
|
814
828
|
return;
|
|
815
829
|
}
|
|
816
830
|
this.closeNotified = true;
|
|
817
|
-
for (const handler of
|
|
831
|
+
for (const handler of new Set(this.closeHandlers)) {
|
|
818
832
|
try {
|
|
819
833
|
handler(err);
|
|
820
834
|
} catch {}
|
|
@@ -981,2002 +995,2038 @@ class IPCClient {
|
|
|
981
995
|
this.pending.clear();
|
|
982
996
|
}
|
|
983
997
|
}
|
|
984
|
-
// src/
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
const reply = this.fixtures.reply ?? tokens.join("");
|
|
996
|
-
let i = 0;
|
|
997
|
-
let cancelled = false;
|
|
998
|
-
const handle = {
|
|
999
|
-
streamId: "mock-stream",
|
|
1000
|
-
async cancel() {
|
|
1001
|
-
cancelled = true;
|
|
1002
|
-
},
|
|
1003
|
-
[Symbol.asyncIterator]() {
|
|
1004
|
-
return {
|
|
1005
|
-
async next() {
|
|
1006
|
-
if (cancelled)
|
|
1007
|
-
return { value: undefined, done: true };
|
|
1008
|
-
if (i < tokens.length) {
|
|
1009
|
-
const text = tokens[i];
|
|
1010
|
-
i += 1;
|
|
1011
|
-
return { value: { type: "token", text }, done: false };
|
|
1012
|
-
}
|
|
1013
|
-
if (i === tokens.length) {
|
|
1014
|
-
i += 1;
|
|
1015
|
-
return {
|
|
1016
|
-
value: { type: "done", reply, sessionId: "mock-session" },
|
|
1017
|
-
done: false
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
return { value: undefined, done: true };
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
return handle;
|
|
1026
|
-
}
|
|
1027
|
-
subscribeHitl(_handler) {
|
|
1028
|
-
return { dispose: () => {
|
|
998
|
+
// src/ask-stream.ts
|
|
999
|
+
function createAskStream(ipc, input, opts = {}) {
|
|
1000
|
+
const queue = [];
|
|
1001
|
+
const waiters = [];
|
|
1002
|
+
let done = false;
|
|
1003
|
+
let streamIdResolved;
|
|
1004
|
+
let cancelled = false;
|
|
1005
|
+
let unsubscribers = [];
|
|
1006
|
+
let early = [];
|
|
1007
|
+
const push = (ev) => {
|
|
1008
|
+
if (done)
|
|
1029
1009
|
return;
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
return { dispose: () => {
|
|
1010
|
+
if (waiters.length > 0) {
|
|
1011
|
+
const w = waiters.shift();
|
|
1012
|
+
w.resolve({ value: ev, done: false });
|
|
1034
1013
|
return;
|
|
1035
|
-
} };
|
|
1036
|
-
}
|
|
1037
|
-
subscribeAgentBrief(_agent, _handler) {
|
|
1038
|
-
return { dispose: () => {} };
|
|
1039
|
-
}
|
|
1040
|
-
brief(agent) {
|
|
1041
|
-
const fixture = this.fixtures.agentBriefs?.[agent];
|
|
1042
|
-
if (fixture === undefined) {
|
|
1043
|
-
return Promise.reject(new Error(`MockClient: no agentBriefs.${agent} fixture configured`));
|
|
1044
1014
|
}
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
async agentsConflicts(_p) {
|
|
1060
|
-
return this.brief("conflicts");
|
|
1061
|
-
}
|
|
1062
|
-
async agentsHuddle(_p) {
|
|
1063
|
-
return this.brief("huddle");
|
|
1064
|
-
}
|
|
1065
|
-
async agentsJanitor(_p) {
|
|
1066
|
-
return this.brief("janitor");
|
|
1067
|
-
}
|
|
1068
|
-
async agentsPreflight(_p) {
|
|
1069
|
-
return this.brief("preflight");
|
|
1070
|
-
}
|
|
1071
|
-
async agentsWhy(_p) {
|
|
1072
|
-
return this.brief("why");
|
|
1073
|
-
}
|
|
1074
|
-
async agentsWhyPeek(_p) {
|
|
1075
|
-
if (this.fixtures.whyPeek === undefined) {
|
|
1076
|
-
throw new Error("MockClient: no whyPeek fixture configured");
|
|
1015
|
+
queue.push(ev);
|
|
1016
|
+
};
|
|
1017
|
+
const finish = () => {
|
|
1018
|
+
if (done)
|
|
1019
|
+
return;
|
|
1020
|
+
done = true;
|
|
1021
|
+
early = [];
|
|
1022
|
+
for (const u of unsubscribers)
|
|
1023
|
+
u();
|
|
1024
|
+
unsubscribers = [];
|
|
1025
|
+
while (waiters.length > 0) {
|
|
1026
|
+
const w = waiters.shift();
|
|
1027
|
+
w.resolve({ value: undefined, done: true });
|
|
1077
1028
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1029
|
+
};
|
|
1030
|
+
const cancelUpstream = async (sid) => {
|
|
1031
|
+
await ipc.call("engine.cancelStream", { streamId: sid }).catch(() => {
|
|
1032
|
+
return;
|
|
1033
|
+
});
|
|
1034
|
+
};
|
|
1035
|
+
const matchesStream = (params) => {
|
|
1036
|
+
return typeof params === "object" && params !== null && typeof params.streamId === "string";
|
|
1037
|
+
};
|
|
1038
|
+
const whenMatched = (handler) => (params) => {
|
|
1039
|
+
const run = () => {
|
|
1040
|
+
if (matchesStream(params) && params.streamId === streamIdResolved)
|
|
1041
|
+
handler(params);
|
|
1042
|
+
};
|
|
1043
|
+
if (streamIdResolved === undefined) {
|
|
1044
|
+
early.push(run);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
run();
|
|
1048
|
+
};
|
|
1049
|
+
const onToken = whenMatched((params) => {
|
|
1050
|
+
const text = params.text;
|
|
1051
|
+
if (typeof text === "string")
|
|
1052
|
+
push({ type: "token", text });
|
|
1053
|
+
});
|
|
1054
|
+
const onDone = whenMatched((params) => {
|
|
1055
|
+
const meta = params.meta ?? {};
|
|
1056
|
+
const reply = typeof meta.reply === "string" ? meta.reply : "";
|
|
1057
|
+
const sessionId = typeof meta.sessionId === "string" ? meta.sessionId : "";
|
|
1058
|
+
push({ type: "done", reply, sessionId });
|
|
1059
|
+
finish();
|
|
1060
|
+
});
|
|
1061
|
+
const onError = whenMatched((params) => {
|
|
1062
|
+
const p = params;
|
|
1063
|
+
const code = typeof p.code === "string" ? p.code : "stream_error";
|
|
1064
|
+
const message = typeof p.error === "string" ? p.error : "Stream error";
|
|
1065
|
+
push({ type: "error", code, message });
|
|
1066
|
+
finish();
|
|
1067
|
+
});
|
|
1068
|
+
const onSubTask = whenMatched((params) => {
|
|
1069
|
+
const p = params;
|
|
1070
|
+
if (typeof p.subTaskId !== "string" || typeof p.status !== "string")
|
|
1071
|
+
return;
|
|
1072
|
+
const ev = typeof p.progress === "number" ? {
|
|
1073
|
+
type: "subTaskProgress",
|
|
1074
|
+
subTaskId: p.subTaskId,
|
|
1075
|
+
status: p.status,
|
|
1076
|
+
progress: p.progress
|
|
1077
|
+
} : { type: "subTaskProgress", subTaskId: p.subTaskId, status: p.status };
|
|
1078
|
+
push(ev);
|
|
1079
|
+
});
|
|
1080
|
+
const onHitl = whenMatched((params) => {
|
|
1081
|
+
const p = params;
|
|
1082
|
+
if (typeof p.requestId !== "string" || typeof p.prompt !== "string")
|
|
1083
|
+
return;
|
|
1084
|
+
push({ type: "hitlBatch", requestId: p.requestId, prompt: p.prompt, details: p.details });
|
|
1085
|
+
});
|
|
1086
|
+
const register = (method, handler) => {
|
|
1087
|
+
ipc.onNotification(method, handler);
|
|
1088
|
+
unsubscribers.push(() => ipc.offNotification(method, handler));
|
|
1089
|
+
};
|
|
1090
|
+
register("engine.streamToken", onToken);
|
|
1091
|
+
register("engine.streamDone", onDone);
|
|
1092
|
+
register("engine.streamError", onError);
|
|
1093
|
+
register("agent.subTaskProgress", onSubTask);
|
|
1094
|
+
register("agent.hitlBatch", onHitl);
|
|
1095
|
+
const onAbort = () => {
|
|
1096
|
+
cancelled = true;
|
|
1097
|
+
const sid = streamIdResolved;
|
|
1098
|
+
if (sid !== undefined)
|
|
1099
|
+
cancelUpstream(sid);
|
|
1100
|
+
finish();
|
|
1101
|
+
};
|
|
1102
|
+
const startPromise = (async () => {
|
|
1103
|
+
const params = { input };
|
|
1104
|
+
if (opts.sessionId !== undefined)
|
|
1105
|
+
params["sessionId"] = opts.sessionId;
|
|
1106
|
+
if (opts.agent !== undefined)
|
|
1107
|
+
params["agent"] = opts.agent;
|
|
1108
|
+
const result = await ipc.call("engine.askStream", params);
|
|
1109
|
+
const sid = result?.streamId;
|
|
1110
|
+
if (typeof sid !== "string") {
|
|
1111
|
+
push({ type: "error", code: "no_stream_id", message: "Gateway returned no streamId" });
|
|
1112
|
+
finish();
|
|
1113
|
+
throw new Error("no_stream_id");
|
|
1114
|
+
}
|
|
1115
|
+
streamIdResolved = sid;
|
|
1116
|
+
const buffered = early;
|
|
1117
|
+
early = [];
|
|
1118
|
+
for (const run of buffered)
|
|
1119
|
+
run();
|
|
1120
|
+
if (cancelled) {
|
|
1121
|
+
await cancelUpstream(sid);
|
|
1122
|
+
finish();
|
|
1123
|
+
return sid;
|
|
1124
|
+
}
|
|
1125
|
+
if (done)
|
|
1126
|
+
return sid;
|
|
1127
|
+
if (opts.signal !== undefined) {
|
|
1128
|
+
const signal = opts.signal;
|
|
1129
|
+
if (signal.aborted) {
|
|
1130
|
+
await cancelUpstream(sid);
|
|
1131
|
+
finish();
|
|
1132
|
+
} else {
|
|
1133
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1134
|
+
unsubscribers.push(() => signal.removeEventListener("abort", onAbort));
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return sid;
|
|
1138
|
+
})();
|
|
1139
|
+
startPromise.catch((err) => {
|
|
1140
|
+
push({
|
|
1141
|
+
type: "error",
|
|
1142
|
+
code: "stream_start_failed",
|
|
1143
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1144
|
+
});
|
|
1145
|
+
finish();
|
|
1146
|
+
});
|
|
1147
|
+
const handle = {
|
|
1148
|
+
get streamId() {
|
|
1149
|
+
return streamIdResolved ?? "";
|
|
1150
|
+
},
|
|
1151
|
+
async cancel() {
|
|
1152
|
+
cancelled = true;
|
|
1153
|
+
const sid = streamIdResolved;
|
|
1154
|
+
if (sid !== undefined)
|
|
1155
|
+
await cancelUpstream(sid);
|
|
1156
|
+
finish();
|
|
1157
|
+
},
|
|
1158
|
+
[Symbol.asyncIterator]() {
|
|
1159
|
+
return {
|
|
1160
|
+
next() {
|
|
1161
|
+
if (queue.length > 0) {
|
|
1162
|
+
const ev = queue.shift();
|
|
1163
|
+
return Promise.resolve({ value: ev, done: false });
|
|
1164
|
+
}
|
|
1165
|
+
if (done) {
|
|
1166
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
1167
|
+
}
|
|
1168
|
+
return new Promise((resolve, reject) => {
|
|
1169
|
+
waiters.push({ resolve, reject });
|
|
1170
|
+
});
|
|
1171
|
+
},
|
|
1172
|
+
return() {
|
|
1173
|
+
cancelled = true;
|
|
1174
|
+
const sid = streamIdResolved;
|
|
1175
|
+
if (sid !== undefined)
|
|
1176
|
+
cancelUpstream(sid);
|
|
1177
|
+
finish();
|
|
1178
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
return handle;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// src/validate.ts
|
|
1187
|
+
class IpcResponseError extends Error {
|
|
1188
|
+
constructor(method, detail) {
|
|
1189
|
+
super(`Invalid ${method} response: ${detail}`);
|
|
1190
|
+
this.name = "IpcResponseError";
|
|
1097
1191
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1192
|
+
}
|
|
1193
|
+
function isRecord2(v) {
|
|
1194
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1195
|
+
}
|
|
1196
|
+
function record(method, v) {
|
|
1197
|
+
if (!isRecord2(v))
|
|
1198
|
+
throw new IpcResponseError(method, "expected an object");
|
|
1199
|
+
return v;
|
|
1200
|
+
}
|
|
1201
|
+
function str(method, o, key) {
|
|
1202
|
+
const v = o[key];
|
|
1203
|
+
if (typeof v !== "string")
|
|
1204
|
+
throw new IpcResponseError(method, `"${key}" must be a string`);
|
|
1205
|
+
return v;
|
|
1206
|
+
}
|
|
1207
|
+
function num(method, o, key) {
|
|
1208
|
+
const v = o[key];
|
|
1209
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
1210
|
+
throw new IpcResponseError(method, `"${key}" must be a finite number`);
|
|
1101
1211
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1212
|
+
return v;
|
|
1213
|
+
}
|
|
1214
|
+
function bool(method, o, key) {
|
|
1215
|
+
const v = o[key];
|
|
1216
|
+
if (typeof v !== "boolean")
|
|
1217
|
+
throw new IpcResponseError(method, `"${key}" must be a boolean`);
|
|
1218
|
+
return v;
|
|
1219
|
+
}
|
|
1220
|
+
function arr(method, v) {
|
|
1221
|
+
if (!Array.isArray(v))
|
|
1222
|
+
throw new IpcResponseError(method, "expected an array");
|
|
1223
|
+
return v;
|
|
1224
|
+
}
|
|
1225
|
+
function optStr(o, key) {
|
|
1226
|
+
const v = o[key];
|
|
1227
|
+
return typeof v === "string" ? v : undefined;
|
|
1228
|
+
}
|
|
1229
|
+
function optNum(o, key) {
|
|
1230
|
+
const v = o[key];
|
|
1231
|
+
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
1232
|
+
}
|
|
1233
|
+
function nullableNum(method, o, key) {
|
|
1234
|
+
const v = o[key];
|
|
1235
|
+
if (v === null)
|
|
1236
|
+
return null;
|
|
1237
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
1238
|
+
throw new IpcResponseError(method, `"${key}" must be a number or null`);
|
|
1104
1239
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1240
|
+
return v;
|
|
1241
|
+
}
|
|
1242
|
+
function nullableStr(method, o, key) {
|
|
1243
|
+
const v = o[key];
|
|
1244
|
+
if (v === null)
|
|
1245
|
+
return null;
|
|
1246
|
+
if (typeof v !== "string") {
|
|
1247
|
+
throw new IpcResponseError(method, `"${key}" must be a string or null`);
|
|
1107
1248
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1249
|
+
return v;
|
|
1250
|
+
}
|
|
1251
|
+
function nullableBool(method, o, key) {
|
|
1252
|
+
const v = o[key];
|
|
1253
|
+
if (v === null)
|
|
1254
|
+
return null;
|
|
1255
|
+
if (typeof v !== "boolean") {
|
|
1256
|
+
throw new IpcResponseError(method, `"${key}" must be a boolean or null`);
|
|
1110
1257
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1258
|
+
return v;
|
|
1259
|
+
}
|
|
1260
|
+
function validateAgentInvoke(method, v) {
|
|
1261
|
+
const o = record(method, v);
|
|
1262
|
+
if (o["reply"] !== undefined && typeof o["reply"] !== "string") {
|
|
1263
|
+
throw new IpcResponseError(method, `"reply" must be a string when present`);
|
|
1113
1264
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
completeness: { tier: "authorized-actions", outboundEgressEvents: 0 },
|
|
1133
|
-
verify: { ok: true, verifiedRows: 0 }
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
async consentRespond(_params) {
|
|
1137
|
-
return { ok: true };
|
|
1138
|
-
}
|
|
1139
|
-
async gatewayPing(_params) {
|
|
1140
|
-
return this.fixtures.gatewayPing ?? {
|
|
1141
|
-
version: "mock",
|
|
1142
|
-
uptime: 0,
|
|
1143
|
-
agentLimits: { maxAgentDepth: 5, maxToolCallsPerSession: 50 }
|
|
1265
|
+
return o;
|
|
1266
|
+
}
|
|
1267
|
+
function validateOk(method, v) {
|
|
1268
|
+
const o = record(method, v);
|
|
1269
|
+
return { ok: bool(method, o, "ok") };
|
|
1270
|
+
}
|
|
1271
|
+
function validateSessionTranscript(method, v) {
|
|
1272
|
+
const o = record(method, v);
|
|
1273
|
+
const turns = arr(method, o["turns"]).map((t) => {
|
|
1274
|
+
const to = record(method, t);
|
|
1275
|
+
const role = str(method, to, "role");
|
|
1276
|
+
if (role !== "user" && role !== "assistant") {
|
|
1277
|
+
throw new IpcResponseError(method, `turn "role" must be "user" or "assistant"`);
|
|
1278
|
+
}
|
|
1279
|
+
const turn = {
|
|
1280
|
+
role,
|
|
1281
|
+
text: str(method, to, "text"),
|
|
1282
|
+
timestamp: num(method, to, "timestamp")
|
|
1144
1283
|
};
|
|
1284
|
+
if (to["auditLogId"] !== undefined)
|
|
1285
|
+
turn.auditLogId = num(method, to, "auditLogId");
|
|
1286
|
+
return turn;
|
|
1287
|
+
});
|
|
1288
|
+
return { sessionId: str(method, o, "sessionId"), turns, hasMore: bool(method, o, "hasMore") };
|
|
1289
|
+
}
|
|
1290
|
+
function validateSessionMemoryRole(method, o, key) {
|
|
1291
|
+
const v = o[key];
|
|
1292
|
+
if (v !== "user" && v !== "assistant" && v !== "tool") {
|
|
1293
|
+
throw new IpcResponseError(method, `"${key}" must be "user", "assistant", or "tool"`);
|
|
1145
1294
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1295
|
+
return v;
|
|
1296
|
+
}
|
|
1297
|
+
function validateSessionRecallHit(method, v) {
|
|
1298
|
+
const o = record(method, v);
|
|
1299
|
+
return {
|
|
1300
|
+
chunkText: str(method, o, "chunkText"),
|
|
1301
|
+
role: validateSessionMemoryRole(method, o, "role"),
|
|
1302
|
+
createdAt: num(method, o, "createdAt"),
|
|
1303
|
+
distance: num(method, o, "distance")
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function validateSessionRecall(method, v) {
|
|
1307
|
+
const o = record(method, v);
|
|
1308
|
+
return { chunks: arr(method, o["chunks"]).map((c) => validateSessionRecallHit(method, c)) };
|
|
1309
|
+
}
|
|
1310
|
+
function validateSessionListEntry(method, v) {
|
|
1311
|
+
const o = record(method, v);
|
|
1312
|
+
return {
|
|
1313
|
+
sessionId: str(method, o, "sessionId"),
|
|
1314
|
+
lastWriteAt: num(method, o, "lastWriteAt"),
|
|
1315
|
+
chunkCount: num(method, o, "chunkCount")
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function validateSessionList(method, v) {
|
|
1319
|
+
const o = record(method, v);
|
|
1320
|
+
return {
|
|
1321
|
+
sessions: arr(method, o["sessions"]).map((s) => validateSessionListEntry(method, s))
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function validateSessionClear(method, v) {
|
|
1325
|
+
const o = record(method, v);
|
|
1326
|
+
return { ok: bool(method, o, "ok"), cleared: str(method, o, "cleared") };
|
|
1327
|
+
}
|
|
1328
|
+
function validateQueryItems(method, v) {
|
|
1329
|
+
const o = record(method, v);
|
|
1330
|
+
const items = arr(method, o["items"]).map((raw) => {
|
|
1331
|
+
const r = record(method, raw);
|
|
1332
|
+
const item = {
|
|
1333
|
+
id: str(method, r, "id"),
|
|
1334
|
+
indexPrimaryKey: str(method, r, "indexPrimaryKey"),
|
|
1335
|
+
service: str(method, r, "service"),
|
|
1336
|
+
itemType: str(method, r, "itemType"),
|
|
1337
|
+
name: str(method, r, "name")
|
|
1159
1338
|
};
|
|
1339
|
+
const mimeType = optStr(r, "mimeType");
|
|
1340
|
+
if (mimeType !== undefined)
|
|
1341
|
+
item.mimeType = mimeType;
|
|
1342
|
+
const sizeBytes = optNum(r, "sizeBytes");
|
|
1343
|
+
if (sizeBytes !== undefined)
|
|
1344
|
+
item.sizeBytes = sizeBytes;
|
|
1345
|
+
const createdAt = optNum(r, "createdAt");
|
|
1346
|
+
if (createdAt !== undefined)
|
|
1347
|
+
item.createdAt = createdAt;
|
|
1348
|
+
const modifiedAt = optNum(r, "modifiedAt");
|
|
1349
|
+
if (modifiedAt !== undefined)
|
|
1350
|
+
item.modifiedAt = modifiedAt;
|
|
1351
|
+
const url = optStr(r, "url");
|
|
1352
|
+
if (url !== undefined)
|
|
1353
|
+
item.url = url;
|
|
1354
|
+
const parentId = optStr(r, "parentId");
|
|
1355
|
+
if (parentId !== undefined)
|
|
1356
|
+
item.parentId = parentId;
|
|
1357
|
+
return item;
|
|
1358
|
+
});
|
|
1359
|
+
const meta = record(method, o["meta"]);
|
|
1360
|
+
return { items, meta: { limit: num(method, meta, "limit"), total: num(method, meta, "total") } };
|
|
1361
|
+
}
|
|
1362
|
+
function validateRankedItems(method, v) {
|
|
1363
|
+
return arr(method, v).map((it) => {
|
|
1364
|
+
const o = record(method, it);
|
|
1365
|
+
num(method, o, "score");
|
|
1366
|
+
str(method, o, "indexPrimaryKey");
|
|
1367
|
+
str(method, o, "indexedType");
|
|
1368
|
+
return o;
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function validateQuerySql(method, v) {
|
|
1372
|
+
const o = record(method, v);
|
|
1373
|
+
return { rows: arr(method, o["rows"]).map((r) => record(method, r)) };
|
|
1374
|
+
}
|
|
1375
|
+
function validateAuditList(method, v) {
|
|
1376
|
+
return arr(method, v);
|
|
1377
|
+
}
|
|
1378
|
+
function validateAuditVerify(method, v) {
|
|
1379
|
+
const o = record(method, v);
|
|
1380
|
+
const result = {
|
|
1381
|
+
ok: bool(method, o, "ok"),
|
|
1382
|
+
verifiedRows: num(method, o, "verifiedRows"),
|
|
1383
|
+
lastVerifiedId: num(method, o, "lastVerifiedId")
|
|
1384
|
+
};
|
|
1385
|
+
if (o["firstBreakAtId"] !== undefined)
|
|
1386
|
+
result.firstBreakAtId = num(method, o, "firstBreakAtId");
|
|
1387
|
+
if (o["reason"] !== undefined)
|
|
1388
|
+
result.reason = str(method, o, "reason");
|
|
1389
|
+
return result;
|
|
1390
|
+
}
|
|
1391
|
+
function validateNumberRecord(method, v, field) {
|
|
1392
|
+
const o = record(method, v);
|
|
1393
|
+
for (const val of Object.values(o)) {
|
|
1394
|
+
if (typeof val !== "number" || !Number.isFinite(val)) {
|
|
1395
|
+
throw new IpcResponseError(method, `"${field}" values must be numbers`);
|
|
1396
|
+
}
|
|
1160
1397
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1398
|
+
return o;
|
|
1399
|
+
}
|
|
1400
|
+
function validateAuditSummary(method, v) {
|
|
1401
|
+
const o = record(method, v);
|
|
1402
|
+
return {
|
|
1403
|
+
byOutcome: validateNumberRecord(method, o["byOutcome"], "byOutcome"),
|
|
1404
|
+
byService: validateNumberRecord(method, o["byService"], "byService"),
|
|
1405
|
+
total: num(method, o, "total")
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function validateToolCallLogEntry(method, v) {
|
|
1409
|
+
const o = record(method, v);
|
|
1410
|
+
const sessionId = o["sessionId"];
|
|
1411
|
+
if (sessionId !== null && typeof sessionId !== "string") {
|
|
1412
|
+
throw new IpcResponseError(method, `tool call "sessionId" must be a string or null`);
|
|
1163
1413
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
connectorHealth: [],
|
|
1168
|
-
index: this.defaultIndexMetrics(),
|
|
1169
|
-
hitl: { pendingConsentRequests: 0 },
|
|
1170
|
-
watchers: [],
|
|
1171
|
-
auditLogTail: [],
|
|
1172
|
-
extensions: { disabled_pre_t2: 0, signature_disabled_count: 0 },
|
|
1173
|
-
sandbox: {
|
|
1174
|
-
platform_capabilities: { network: "all_or_nothing", reason: null },
|
|
1175
|
-
linux_helper: null,
|
|
1176
|
-
stale_rules_count: 0
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1414
|
+
const status = o["status"];
|
|
1415
|
+
if (status !== "ok" && status !== "error") {
|
|
1416
|
+
throw new IpcResponseError(method, `tool call "status" must be "ok" or "error"`);
|
|
1179
1417
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1418
|
+
return {
|
|
1419
|
+
id: num(method, o, "id"),
|
|
1420
|
+
sessionId,
|
|
1421
|
+
toolId: str(method, o, "toolId"),
|
|
1422
|
+
service: str(method, o, "service"),
|
|
1423
|
+
calledAt: num(method, o, "calledAt"),
|
|
1424
|
+
durationMs: num(method, o, "durationMs"),
|
|
1425
|
+
resultEnvelope: str(method, o, "resultEnvelope"),
|
|
1426
|
+
status,
|
|
1427
|
+
params: o["params"]
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function validateToolCallsCursor(method, v) {
|
|
1431
|
+
if (v === null)
|
|
1432
|
+
return null;
|
|
1433
|
+
const o = record(method, v);
|
|
1434
|
+
return { calledAt: num(method, o, "calledAt"), id: num(method, o, "id") };
|
|
1435
|
+
}
|
|
1436
|
+
function validateAuditToolCalls(method, v) {
|
|
1437
|
+
const o = record(method, v);
|
|
1438
|
+
return {
|
|
1439
|
+
toolCalls: arr(method, o["toolCalls"]).map((t) => validateToolCallLogEntry(method, t)),
|
|
1440
|
+
hasMore: bool(method, o, "hasMore"),
|
|
1441
|
+
nextCursor: validateToolCallsCursor(method, o["nextCursor"])
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
function validateEgressHead(method, v) {
|
|
1445
|
+
const o = record(method, v);
|
|
1446
|
+
return { head: str(method, o, "head"), count: num(method, o, "count") };
|
|
1447
|
+
}
|
|
1448
|
+
function validateEgressRow(method, v) {
|
|
1449
|
+
const o = record(method, v);
|
|
1450
|
+
const sourceId = o["sourceId"];
|
|
1451
|
+
if (sourceId !== null && typeof sourceId !== "string") {
|
|
1452
|
+
throw new IpcResponseError(method, `row "sourceId" must be a string or null`);
|
|
1191
1453
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1454
|
+
return {
|
|
1455
|
+
id: num(method, o, "id"),
|
|
1456
|
+
timestamp: num(method, o, "timestamp"),
|
|
1457
|
+
sourceType: str(method, o, "sourceType"),
|
|
1458
|
+
sourceId,
|
|
1459
|
+
destination: str(method, o, "destination"),
|
|
1460
|
+
method: str(method, o, "method"),
|
|
1461
|
+
payloadSummary: str(method, o, "payloadSummary"),
|
|
1462
|
+
hitlStatus: str(method, o, "hitlStatus"),
|
|
1463
|
+
resultStatus: str(method, o, "resultStatus"),
|
|
1464
|
+
rowHash: str(method, o, "rowHash"),
|
|
1465
|
+
prevHash: str(method, o, "prevHash")
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function validateEgressList(method, v) {
|
|
1469
|
+
const o = record(method, v);
|
|
1470
|
+
return { rows: arr(method, o["rows"]).map((r) => validateEgressRow(method, r)) };
|
|
1471
|
+
}
|
|
1472
|
+
function validateEgressVerify(method, v) {
|
|
1473
|
+
const o = record(method, v);
|
|
1474
|
+
const result = {
|
|
1475
|
+
ok: bool(method, o, "ok"),
|
|
1476
|
+
verifiedRows: num(method, o, "verifiedRows")
|
|
1477
|
+
};
|
|
1478
|
+
if (o["brokenAt"] !== undefined)
|
|
1479
|
+
result.brokenAt = num(method, o, "brokenAt");
|
|
1480
|
+
if (o["reason"] !== undefined)
|
|
1481
|
+
result.reason = str(method, o, "reason");
|
|
1482
|
+
return result;
|
|
1483
|
+
}
|
|
1484
|
+
function readCoverageVector(v) {
|
|
1485
|
+
const src = v !== null && typeof v === "object" ? v : {};
|
|
1486
|
+
const out = {};
|
|
1487
|
+
for (const cls of EGRESS_COVERAGE_CLASSES) {
|
|
1488
|
+
const raw = src[cls];
|
|
1489
|
+
out[cls] = EGRESS_GRANULARITIES.includes(raw) ? raw : "none";
|
|
1214
1490
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1491
|
+
return out;
|
|
1492
|
+
}
|
|
1493
|
+
function validateEgressCompleteness(method, v) {
|
|
1494
|
+
const o = record(method, v);
|
|
1495
|
+
const coverage = readCoverageVector(o["coverage"]);
|
|
1496
|
+
const indeterminate = typeof o["indeterminate"] === "boolean" ? o["indeterminate"] : true;
|
|
1497
|
+
return {
|
|
1498
|
+
coverage,
|
|
1499
|
+
outboundEgressEvents: num(method, o, "outboundEgressEvents"),
|
|
1500
|
+
indeterminate
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function validateEgressReceipt(method, v) {
|
|
1504
|
+
const o = record(method, v);
|
|
1505
|
+
return {
|
|
1506
|
+
sigB64: str(method, o, "sigB64"),
|
|
1507
|
+
pubkeyB64: str(method, o, "pubkeyB64"),
|
|
1508
|
+
digest: str(method, o, "digest")
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
function validateEgressProveWindow(method, v) {
|
|
1512
|
+
const o = record(method, v);
|
|
1513
|
+
const result = {
|
|
1514
|
+
rows: arr(method, o["rows"]).map((r) => validateEgressRow(method, r)),
|
|
1515
|
+
completeness: validateEgressCompleteness(method, o["completeness"]),
|
|
1516
|
+
verify: validateEgressVerify(method, o["verify"])
|
|
1517
|
+
};
|
|
1518
|
+
if (o["receipt"] !== undefined)
|
|
1519
|
+
result.receipt = validateEgressReceipt(method, o["receipt"]);
|
|
1520
|
+
return result;
|
|
1521
|
+
}
|
|
1522
|
+
function validateAgentSession(method, v) {
|
|
1523
|
+
const o = record(method, v);
|
|
1524
|
+
return { sessionId: str(method, o, "sessionId") };
|
|
1525
|
+
}
|
|
1526
|
+
function validateGatewayPing(method, v) {
|
|
1527
|
+
const o = record(method, v);
|
|
1528
|
+
str(method, o, "version");
|
|
1529
|
+
num(method, o, "uptime");
|
|
1530
|
+
const limits = record(method, o["agentLimits"]);
|
|
1531
|
+
num(method, limits, "maxAgentDepth");
|
|
1532
|
+
num(method, limits, "maxToolCallsPerSession");
|
|
1533
|
+
if (o["drift"] !== undefined) {
|
|
1534
|
+
const drift = record(method, o["drift"]);
|
|
1535
|
+
for (const line of arr(method, drift["lines"])) {
|
|
1536
|
+
if (typeof line !== "string") {
|
|
1537
|
+
throw new IpcResponseError(method, `drift "lines" must be strings`);
|
|
1225
1538
|
}
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
async connectorListStatus(_params) {
|
|
1229
|
-
return this.fixtures.connectorSyncStatuses ?? [];
|
|
1230
|
-
}
|
|
1231
|
-
defaultConnectorStatus(serviceId) {
|
|
1232
|
-
return {
|
|
1233
|
-
serviceId,
|
|
1234
|
-
status: "ok",
|
|
1235
|
-
lastSyncAt: null,
|
|
1236
|
-
nextSyncAt: null,
|
|
1237
|
-
intervalMs: 0,
|
|
1238
|
-
itemCount: 0,
|
|
1239
|
-
lastError: null,
|
|
1240
|
-
consecutiveFailures: 0,
|
|
1241
|
-
depth: "metadata_only",
|
|
1242
|
-
enabled: true
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
1245
|
-
async connectorStatus(params) {
|
|
1246
|
-
return this.fixtures.connectorStatus ?? this.defaultConnectorStatus(params.serviceId);
|
|
1539
|
+
}
|
|
1247
1540
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1541
|
+
return o;
|
|
1542
|
+
}
|
|
1543
|
+
function validateDiagVersion(method, v) {
|
|
1544
|
+
const o = record(method, v);
|
|
1545
|
+
const version = str(method, o, "version");
|
|
1546
|
+
const commit = o["commit"];
|
|
1547
|
+
if (commit !== null && typeof commit !== "string") {
|
|
1548
|
+
throw new IpcResponseError(method, `"commit" must be a string or null`);
|
|
1250
1549
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1550
|
+
const buildId = o["buildId"];
|
|
1551
|
+
if (buildId !== null && typeof buildId !== "string") {
|
|
1552
|
+
throw new IpcResponseError(method, `"buildId" must be a string or null`);
|
|
1253
1553
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1554
|
+
return { version, commit, buildId, uptimeMs: num(method, o, "uptimeMs") };
|
|
1555
|
+
}
|
|
1556
|
+
function validateIndexMetrics(method, v) {
|
|
1557
|
+
const o = record(method, v);
|
|
1558
|
+
const itemCountByService = record(method, o["itemCountByService"]);
|
|
1559
|
+
for (const val of Object.values(itemCountByService)) {
|
|
1560
|
+
if (typeof val !== "number" || !Number.isFinite(val)) {
|
|
1561
|
+
throw new IpcResponseError(method, `"itemCountByService" values must be numbers`);
|
|
1562
|
+
}
|
|
1256
1563
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1564
|
+
const lastSuccessfulSyncByConnector = record(method, o["lastSuccessfulSyncByConnector"]);
|
|
1565
|
+
for (const val of Object.values(lastSuccessfulSyncByConnector)) {
|
|
1566
|
+
if (val !== null && (typeof val !== "number" || !Number.isFinite(val))) {
|
|
1567
|
+
throw new IpcResponseError(method, `"lastSuccessfulSyncByConnector" values must be a number or null`);
|
|
1568
|
+
}
|
|
1259
1569
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1570
|
+
return {
|
|
1571
|
+
itemCountByService,
|
|
1572
|
+
totalItems: num(method, o, "totalItems"),
|
|
1573
|
+
indexSizeBytes: num(method, o, "indexSizeBytes"),
|
|
1574
|
+
embeddingCoveragePercent: num(method, o, "embeddingCoveragePercent"),
|
|
1575
|
+
lastSuccessfulSyncByConnector,
|
|
1576
|
+
queryLatencyP50Ms: num(method, o, "queryLatencyP50Ms"),
|
|
1577
|
+
queryLatencyP95Ms: num(method, o, "queryLatencyP95Ms"),
|
|
1578
|
+
queryLatencyP99Ms: num(method, o, "queryLatencyP99Ms")
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
function validateConnectorHealthEntry(method, v) {
|
|
1582
|
+
const o = record(method, v);
|
|
1583
|
+
const entry = {
|
|
1584
|
+
connectorId: str(method, o, "connectorId"),
|
|
1585
|
+
state: str(method, o, "state"),
|
|
1586
|
+
backoffAttempt: num(method, o, "backoffAttempt")
|
|
1587
|
+
};
|
|
1588
|
+
const retryAfterMs = optNum(o, "retryAfterMs");
|
|
1589
|
+
if (retryAfterMs !== undefined)
|
|
1590
|
+
entry.retryAfterMs = retryAfterMs;
|
|
1591
|
+
const backoffUntilMs = optNum(o, "backoffUntilMs");
|
|
1592
|
+
if (backoffUntilMs !== undefined)
|
|
1593
|
+
entry.backoffUntilMs = backoffUntilMs;
|
|
1594
|
+
const lastError = optStr(o, "lastError");
|
|
1595
|
+
if (lastError !== undefined)
|
|
1596
|
+
entry.lastError = lastError;
|
|
1597
|
+
const lastSuccessfulSyncMs = optNum(o, "lastSuccessfulSyncMs");
|
|
1598
|
+
if (lastSuccessfulSyncMs !== undefined)
|
|
1599
|
+
entry.lastSuccessfulSyncMs = lastSuccessfulSyncMs;
|
|
1600
|
+
const lastSyncAttemptMs = optNum(o, "lastSyncAttemptMs");
|
|
1601
|
+
if (lastSyncAttemptMs !== undefined)
|
|
1602
|
+
entry.lastSyncAttemptMs = lastSyncAttemptMs;
|
|
1603
|
+
return entry;
|
|
1604
|
+
}
|
|
1605
|
+
function validateWatcherSummary(method, v) {
|
|
1606
|
+
const o = record(method, v);
|
|
1607
|
+
const lastFiredAtMs = o["lastFiredAtMs"];
|
|
1608
|
+
if (lastFiredAtMs !== null && (typeof lastFiredAtMs !== "number" || !Number.isFinite(lastFiredAtMs))) {
|
|
1609
|
+
throw new IpcResponseError(method, `"lastFiredAtMs" must be a number or null`);
|
|
1267
1610
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1611
|
+
return {
|
|
1612
|
+
id: str(method, o, "id"),
|
|
1613
|
+
name: str(method, o, "name"),
|
|
1614
|
+
enabled: bool(method, o, "enabled"),
|
|
1615
|
+
lastFiredAtMs
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
function validateSandboxDiag(method, v) {
|
|
1619
|
+
const o = record(method, v);
|
|
1620
|
+
const caps = record(method, o["platform_capabilities"]);
|
|
1621
|
+
const network = caps["network"];
|
|
1622
|
+
if (network !== "per_host" && network !== "all_or_nothing") {
|
|
1623
|
+
throw new IpcResponseError(method, `platform_capabilities "network" must be "per_host" or "all_or_nothing"`);
|
|
1270
1624
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1625
|
+
const capsReason = caps["reason"];
|
|
1626
|
+
if (capsReason !== null && typeof capsReason !== "string") {
|
|
1627
|
+
throw new IpcResponseError(method, `platform_capabilities "reason" must be a string or null`);
|
|
1273
1628
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1629
|
+
const linuxHelperRaw = o["linux_helper"];
|
|
1630
|
+
let linuxHelper = null;
|
|
1631
|
+
if (linuxHelperRaw !== null) {
|
|
1632
|
+
const lh = record(method, linuxHelperRaw);
|
|
1633
|
+
const lhReason = lh["reason"];
|
|
1634
|
+
if (lhReason !== null && typeof lhReason !== "string") {
|
|
1635
|
+
throw new IpcResponseError(method, `linux_helper "reason" must be a string or null`);
|
|
1636
|
+
}
|
|
1637
|
+
linuxHelper = { available: bool(method, lh, "available"), reason: lhReason };
|
|
1276
1638
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1639
|
+
return {
|
|
1640
|
+
platform_capabilities: { network, reason: capsReason },
|
|
1641
|
+
linux_helper: linuxHelper,
|
|
1642
|
+
stale_rules_count: num(method, o, "stale_rules_count")
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
function validateDiagSnapshot(method, v) {
|
|
1646
|
+
const o = record(method, v);
|
|
1647
|
+
const gateway = record(method, o["gateway"]);
|
|
1648
|
+
const hitl = record(method, o["hitl"]);
|
|
1649
|
+
const extensionsRaw = record(method, o["extensions"]);
|
|
1650
|
+
const extensions = {
|
|
1651
|
+
disabled_pre_t2: num(method, extensionsRaw, "disabled_pre_t2"),
|
|
1652
|
+
signature_disabled_count: num(method, extensionsRaw, "signature_disabled_count")
|
|
1653
|
+
};
|
|
1654
|
+
if (extensionsRaw["auto_update"] !== undefined) {
|
|
1655
|
+
const au = record(method, extensionsRaw["auto_update"]);
|
|
1656
|
+
extensions.auto_update = {
|
|
1657
|
+
cached_updates_count: num(method, au, "cached_updates_count"),
|
|
1658
|
+
interval_hours: num(method, au, "interval_hours"),
|
|
1659
|
+
air_gap_blocked: bool(method, au, "air_gap_blocked")
|
|
1660
|
+
};
|
|
1279
1661
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
async workflowRun(params) {
|
|
1300
|
-
return this.fixtures.workflowRun ?? {
|
|
1301
|
-
runId: "mock-run",
|
|
1302
|
-
dryRun: params.dryRun ?? false,
|
|
1303
|
-
stepResults: []
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
workflowRunStream(params) {
|
|
1307
|
-
const chunks = this.fixtures.workflowRunChunks ?? ["mock ", "workflow"];
|
|
1308
|
-
const value = this.fixtures.workflowRun ?? {
|
|
1309
|
-
runId: "mock-run",
|
|
1310
|
-
dryRun: params.dryRun ?? false,
|
|
1311
|
-
stepResults: []
|
|
1312
|
-
};
|
|
1313
|
-
let i = 0;
|
|
1314
|
-
return {
|
|
1315
|
-
result: Promise.resolve(value),
|
|
1316
|
-
[Symbol.asyncIterator]() {
|
|
1317
|
-
return {
|
|
1318
|
-
async next() {
|
|
1319
|
-
if (i < chunks.length) {
|
|
1320
|
-
const text = chunks[i];
|
|
1321
|
-
i += 1;
|
|
1322
|
-
return { value: { type: "chunk", text }, done: false };
|
|
1323
|
-
}
|
|
1324
|
-
if (i === chunks.length) {
|
|
1325
|
-
i += 1;
|
|
1326
|
-
return { value: { type: "done", result: value }, done: false };
|
|
1327
|
-
}
|
|
1328
|
-
return { value: undefined, done: true };
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
};
|
|
1662
|
+
return {
|
|
1663
|
+
gateway: {
|
|
1664
|
+
version: str(method, gateway, "version"),
|
|
1665
|
+
uptimeMs: num(method, gateway, "uptimeMs")
|
|
1666
|
+
},
|
|
1667
|
+
connectorHealth: arr(method, o["connectorHealth"]).map((h) => validateConnectorHealthEntry(method, h)),
|
|
1668
|
+
index: validateIndexMetrics(method, o["index"]),
|
|
1669
|
+
hitl: { pendingConsentRequests: num(method, hitl, "pendingConsentRequests") },
|
|
1670
|
+
watchers: arr(method, o["watchers"]).map((w) => validateWatcherSummary(method, w)),
|
|
1671
|
+
auditLogTail: arr(method, o["auditLogTail"]),
|
|
1672
|
+
extensions,
|
|
1673
|
+
sandbox: validateSandboxDiag(method, o["sandbox"])
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
function validatePolicyState(method, v) {
|
|
1677
|
+
const o = record(method, v);
|
|
1678
|
+
const source = o["source"];
|
|
1679
|
+
if (source !== "anchor" && source !== "peer" && source !== "none") {
|
|
1680
|
+
throw new IpcResponseError(method, `policy "source" must be "anchor", "peer", or "none"`);
|
|
1333
1681
|
}
|
|
1334
|
-
|
|
1682
|
+
const state = {
|
|
1683
|
+
signatureValid: bool(method, o, "signatureValid"),
|
|
1684
|
+
pendingRestart: bool(method, o, "pendingRestart"),
|
|
1685
|
+
source
|
|
1686
|
+
};
|
|
1687
|
+
const org = optStr(o, "org");
|
|
1688
|
+
if (org !== undefined)
|
|
1689
|
+
state.org = org;
|
|
1690
|
+
const version = optNum(o, "version");
|
|
1691
|
+
if (version !== undefined)
|
|
1692
|
+
state.version = version;
|
|
1693
|
+
const lastFetchedMs = optNum(o, "lastFetchedMs");
|
|
1694
|
+
if (lastFetchedMs !== undefined)
|
|
1695
|
+
state.lastFetchedMs = lastFetchedMs;
|
|
1696
|
+
return state;
|
|
1335
1697
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
kind: "why",
|
|
1342
|
-
query: { ref: "src/retry.ts", line: 42 },
|
|
1343
|
-
subject: { repoRoot: "/repo", filePath: "src/retry.ts", lineNo: 42, symbol: "retryBackoff" },
|
|
1344
|
-
findings: ["authorship", "pull_request", "ticket", "discussion", "driver", "downstream"].map((lane, i) => ({
|
|
1345
|
-
lane,
|
|
1346
|
-
title: `${lane} finding`,
|
|
1347
|
-
detail: `${lane} detail`,
|
|
1348
|
-
url: `https://x/${lane}`,
|
|
1349
|
-
occurredAt: 1700000000000 + i,
|
|
1350
|
-
entityId: `e${i}`
|
|
1351
|
-
}))
|
|
1352
|
-
};
|
|
1353
|
-
// src/ask-stream.ts
|
|
1354
|
-
function createAskStream(ipc, input, opts = {}) {
|
|
1355
|
-
const queue = [];
|
|
1356
|
-
const waiters = [];
|
|
1357
|
-
let done = false;
|
|
1358
|
-
let streamIdResolved;
|
|
1359
|
-
let cancelled = false;
|
|
1360
|
-
let unsubscribers = [];
|
|
1361
|
-
let early = [];
|
|
1362
|
-
const push = (ev) => {
|
|
1363
|
-
if (done)
|
|
1364
|
-
return;
|
|
1365
|
-
if (waiters.length > 0) {
|
|
1366
|
-
const w = waiters.shift();
|
|
1367
|
-
w.resolve({ value: ev, done: false });
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
queue.push(ev);
|
|
1698
|
+
function validatePeerStatus(method, v) {
|
|
1699
|
+
const o = record(method, v);
|
|
1700
|
+
const status = {
|
|
1701
|
+
peerId: str(method, o, "peerId"),
|
|
1702
|
+
reachable: bool(method, o, "reachable")
|
|
1371
1703
|
};
|
|
1372
|
-
const
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1704
|
+
const lastSeenMs = optNum(o, "lastSeenMs");
|
|
1705
|
+
if (lastSeenMs !== undefined)
|
|
1706
|
+
status.lastSeenMs = lastSeenMs;
|
|
1707
|
+
return status;
|
|
1708
|
+
}
|
|
1709
|
+
function validateConnectorStatus(method, v) {
|
|
1710
|
+
const o = record(method, v);
|
|
1711
|
+
const status = {
|
|
1712
|
+
id: str(method, o, "id"),
|
|
1713
|
+
enabled: bool(method, o, "enabled"),
|
|
1714
|
+
blockedByPolicy: bool(method, o, "blockedByPolicy"),
|
|
1715
|
+
health: str(method, o, "health")
|
|
1384
1716
|
};
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1717
|
+
const lastSyncMs = optNum(o, "lastSyncMs");
|
|
1718
|
+
if (lastSyncMs !== undefined)
|
|
1719
|
+
status.lastSyncMs = lastSyncMs;
|
|
1720
|
+
return status;
|
|
1721
|
+
}
|
|
1722
|
+
function validateNamespaceStatus(method, v) {
|
|
1723
|
+
const o = record(method, v);
|
|
1724
|
+
const status = {
|
|
1725
|
+
name: str(method, o, "name"),
|
|
1726
|
+
subscribers: num(method, o, "subscribers")
|
|
1389
1727
|
};
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1728
|
+
const lastPropagateMs = optNum(o, "lastPropagateMs");
|
|
1729
|
+
if (lastPropagateMs !== undefined)
|
|
1730
|
+
status.lastPropagateMs = lastPropagateMs;
|
|
1731
|
+
return status;
|
|
1732
|
+
}
|
|
1733
|
+
function validateGatewayStatus(method, v) {
|
|
1734
|
+
const o = record(method, v);
|
|
1735
|
+
const audit = record(method, o["audit"]);
|
|
1736
|
+
const hitl = record(method, o["hitl"]);
|
|
1737
|
+
const identity = record(method, o["identity"]);
|
|
1738
|
+
const identityStatus = { operatorValid: bool(method, identity, "operatorValid") };
|
|
1739
|
+
const externalId = optStr(identity, "externalId");
|
|
1740
|
+
if (externalId !== undefined)
|
|
1741
|
+
identityStatus.externalId = externalId;
|
|
1742
|
+
return {
|
|
1743
|
+
policy: validatePolicyState(method, o["policy"]),
|
|
1744
|
+
peers: arr(method, o["peers"]).map((p) => validatePeerStatus(method, p)),
|
|
1745
|
+
connectors: arr(method, o["connectors"]).map((c) => validateConnectorStatus(method, c)),
|
|
1746
|
+
namespaces: arr(method, o["namespaces"]).map((n) => validateNamespaceStatus(method, n)),
|
|
1747
|
+
audit: {
|
|
1748
|
+
chainLength: num(method, audit, "chainLength"),
|
|
1749
|
+
lastHash: str(method, audit, "lastHash"),
|
|
1750
|
+
appendRate1h: num(method, audit, "appendRate1h")
|
|
1751
|
+
},
|
|
1752
|
+
hitl: {
|
|
1753
|
+
pendingApprovals: num(method, hitl, "pendingApprovals"),
|
|
1754
|
+
pendingQuorum: num(method, hitl, "pendingQuorum")
|
|
1755
|
+
},
|
|
1756
|
+
identity: identityStatus,
|
|
1757
|
+
syncFreshnessMs: num(method, o, "syncFreshnessMs")
|
|
1392
1758
|
};
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1759
|
+
}
|
|
1760
|
+
var DORA_GAP_VALUES = new Set([
|
|
1761
|
+
"no_pagerduty_mapping",
|
|
1762
|
+
"no_repos",
|
|
1763
|
+
"no_deployment_data",
|
|
1764
|
+
"low_sample",
|
|
1765
|
+
"approximate_lead_time",
|
|
1766
|
+
"mixed_source"
|
|
1767
|
+
]);
|
|
1768
|
+
function validateDoraGap(method, v, field) {
|
|
1769
|
+
if (v === null)
|
|
1770
|
+
return null;
|
|
1771
|
+
if (typeof v === "string" && DORA_GAP_VALUES.has(v))
|
|
1772
|
+
return v;
|
|
1773
|
+
throw new IpcResponseError(method, `"${field}" must be a recognised DORA gap code or null`);
|
|
1774
|
+
}
|
|
1775
|
+
function validateDoraMetricValue(method, v, field) {
|
|
1776
|
+
const o = record(method, v);
|
|
1777
|
+
const value = o["value"];
|
|
1778
|
+
if (value !== null && (typeof value !== "number" || !Number.isFinite(value))) {
|
|
1779
|
+
throw new IpcResponseError(method, `"${field}.value" must be a number or null`);
|
|
1780
|
+
}
|
|
1781
|
+
return {
|
|
1782
|
+
value,
|
|
1783
|
+
unit: str(method, o, "unit"),
|
|
1784
|
+
sample: num(method, o, "sample"),
|
|
1785
|
+
gap: validateDoraGap(method, o["gap"], `${field}.gap`)
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
function validateDoraMetrics(method, v) {
|
|
1789
|
+
const o = record(method, v);
|
|
1790
|
+
const metrics = record(method, o["metrics"]);
|
|
1791
|
+
return {
|
|
1792
|
+
service: str(method, o, "service"),
|
|
1793
|
+
since_ms: num(method, o, "since_ms"),
|
|
1794
|
+
computed_at: str(method, o, "computed_at"),
|
|
1795
|
+
metrics: {
|
|
1796
|
+
deployment_frequency: validateDoraMetricValue(method, metrics["deployment_frequency"], "deployment_frequency"),
|
|
1797
|
+
lead_time_for_changes: validateDoraMetricValue(method, metrics["lead_time_for_changes"], "lead_time_for_changes"),
|
|
1798
|
+
change_failure_rate: validateDoraMetricValue(method, metrics["change_failure_rate"], "change_failure_rate"),
|
|
1799
|
+
mttr: validateDoraMetricValue(method, metrics["mttr"], "mttr")
|
|
1401
1800
|
}
|
|
1402
|
-
run();
|
|
1403
1801
|
};
|
|
1404
|
-
const onToken = whenMatched((params) => {
|
|
1405
|
-
const text = params.text;
|
|
1406
|
-
if (typeof text === "string")
|
|
1407
|
-
push({ type: "token", text });
|
|
1408
|
-
});
|
|
1409
|
-
const onDone = whenMatched((params) => {
|
|
1410
|
-
const meta = params.meta ?? {};
|
|
1411
|
-
const reply = typeof meta.reply === "string" ? meta.reply : "";
|
|
1412
|
-
const sessionId = typeof meta.sessionId === "string" ? meta.sessionId : "";
|
|
1413
|
-
push({ type: "done", reply, sessionId });
|
|
1414
|
-
finish();
|
|
1415
|
-
});
|
|
1416
|
-
const onError = whenMatched((params) => {
|
|
1417
|
-
const p = params;
|
|
1418
|
-
const code = typeof p.code === "string" ? p.code : "stream_error";
|
|
1419
|
-
const message = typeof p.error === "string" ? p.error : "Stream error";
|
|
1420
|
-
push({ type: "error", code, message });
|
|
1421
|
-
finish();
|
|
1422
|
-
});
|
|
1423
|
-
const onSubTask = whenMatched((params) => {
|
|
1424
|
-
const p = params;
|
|
1425
|
-
if (typeof p.subTaskId !== "string" || typeof p.status !== "string")
|
|
1426
|
-
return;
|
|
1427
|
-
const ev = typeof p.progress === "number" ? {
|
|
1428
|
-
type: "subTaskProgress",
|
|
1429
|
-
subTaskId: p.subTaskId,
|
|
1430
|
-
status: p.status,
|
|
1431
|
-
progress: p.progress
|
|
1432
|
-
} : { type: "subTaskProgress", subTaskId: p.subTaskId, status: p.status };
|
|
1433
|
-
push(ev);
|
|
1434
|
-
});
|
|
1435
|
-
const onHitl = whenMatched((params) => {
|
|
1436
|
-
const p = params;
|
|
1437
|
-
if (typeof p.requestId !== "string" || typeof p.prompt !== "string")
|
|
1438
|
-
return;
|
|
1439
|
-
push({ type: "hitlBatch", requestId: p.requestId, prompt: p.prompt, details: p.details });
|
|
1440
|
-
});
|
|
1441
|
-
const register = (method, handler) => {
|
|
1442
|
-
ipc.onNotification(method, handler);
|
|
1443
|
-
unsubscribers.push(() => ipc.offNotification(method, handler));
|
|
1444
|
-
};
|
|
1445
|
-
register("engine.streamToken", onToken);
|
|
1446
|
-
register("engine.streamDone", onDone);
|
|
1447
|
-
register("engine.streamError", onError);
|
|
1448
|
-
register("agent.subTaskProgress", onSubTask);
|
|
1449
|
-
register("agent.hitlBatch", onHitl);
|
|
1450
|
-
const onAbort = () => {
|
|
1451
|
-
cancelled = true;
|
|
1452
|
-
const sid = streamIdResolved;
|
|
1453
|
-
if (sid !== undefined)
|
|
1454
|
-
cancelUpstream(sid);
|
|
1455
|
-
finish();
|
|
1456
|
-
};
|
|
1457
|
-
const startPromise = (async () => {
|
|
1458
|
-
const params = { input };
|
|
1459
|
-
if (opts.sessionId !== undefined)
|
|
1460
|
-
params["sessionId"] = opts.sessionId;
|
|
1461
|
-
if (opts.agent !== undefined)
|
|
1462
|
-
params["agent"] = opts.agent;
|
|
1463
|
-
const result = await ipc.call("engine.askStream", params);
|
|
1464
|
-
const sid = result?.streamId;
|
|
1465
|
-
if (typeof sid !== "string") {
|
|
1466
|
-
push({ type: "error", code: "no_stream_id", message: "Gateway returned no streamId" });
|
|
1467
|
-
finish();
|
|
1468
|
-
throw new Error("no_stream_id");
|
|
1469
|
-
}
|
|
1470
|
-
streamIdResolved = sid;
|
|
1471
|
-
const buffered = early;
|
|
1472
|
-
early = [];
|
|
1473
|
-
for (const run of buffered)
|
|
1474
|
-
run();
|
|
1475
|
-
if (cancelled) {
|
|
1476
|
-
await cancelUpstream(sid);
|
|
1477
|
-
finish();
|
|
1478
|
-
return sid;
|
|
1479
|
-
}
|
|
1480
|
-
if (done)
|
|
1481
|
-
return sid;
|
|
1482
|
-
if (opts.signal !== undefined) {
|
|
1483
|
-
const signal = opts.signal;
|
|
1484
|
-
if (signal.aborted) {
|
|
1485
|
-
await cancelUpstream(sid);
|
|
1486
|
-
finish();
|
|
1487
|
-
} else {
|
|
1488
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1489
|
-
unsubscribers.push(() => signal.removeEventListener("abort", onAbort));
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
return sid;
|
|
1493
|
-
})();
|
|
1494
|
-
startPromise.catch((err) => {
|
|
1495
|
-
push({
|
|
1496
|
-
type: "error",
|
|
1497
|
-
code: "stream_start_failed",
|
|
1498
|
-
message: err instanceof Error ? err.message : String(err)
|
|
1499
|
-
});
|
|
1500
|
-
finish();
|
|
1501
|
-
});
|
|
1502
|
-
const handle = {
|
|
1503
|
-
get streamId() {
|
|
1504
|
-
return streamIdResolved ?? "";
|
|
1505
|
-
},
|
|
1506
|
-
async cancel() {
|
|
1507
|
-
cancelled = true;
|
|
1508
|
-
const sid = streamIdResolved;
|
|
1509
|
-
if (sid !== undefined)
|
|
1510
|
-
await cancelUpstream(sid);
|
|
1511
|
-
finish();
|
|
1512
|
-
},
|
|
1513
|
-
[Symbol.asyncIterator]() {
|
|
1514
|
-
return {
|
|
1515
|
-
next() {
|
|
1516
|
-
if (queue.length > 0) {
|
|
1517
|
-
const ev = queue.shift();
|
|
1518
|
-
return Promise.resolve({ value: ev, done: false });
|
|
1519
|
-
}
|
|
1520
|
-
if (done) {
|
|
1521
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
1522
|
-
}
|
|
1523
|
-
return new Promise((resolve, reject) => {
|
|
1524
|
-
waiters.push({ resolve, reject });
|
|
1525
|
-
});
|
|
1526
|
-
},
|
|
1527
|
-
return() {
|
|
1528
|
-
cancelled = true;
|
|
1529
|
-
const sid = streamIdResolved;
|
|
1530
|
-
if (sid !== undefined)
|
|
1531
|
-
cancelUpstream(sid);
|
|
1532
|
-
finish();
|
|
1533
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
1534
|
-
}
|
|
1535
|
-
};
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
return handle;
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
// src/validate.ts
|
|
1542
|
-
class IpcResponseError extends Error {
|
|
1543
|
-
constructor(method, detail) {
|
|
1544
|
-
super(`Invalid ${method} response: ${detail}`);
|
|
1545
|
-
this.name = "IpcResponseError";
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
function isRecord2(v) {
|
|
1549
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1550
|
-
}
|
|
1551
|
-
function record(method, v) {
|
|
1552
|
-
if (!isRecord2(v))
|
|
1553
|
-
throw new IpcResponseError(method, "expected an object");
|
|
1554
|
-
return v;
|
|
1555
|
-
}
|
|
1556
|
-
function str(method, o, key) {
|
|
1557
|
-
const v = o[key];
|
|
1558
|
-
if (typeof v !== "string")
|
|
1559
|
-
throw new IpcResponseError(method, `"${key}" must be a string`);
|
|
1560
|
-
return v;
|
|
1561
|
-
}
|
|
1562
|
-
function num(method, o, key) {
|
|
1563
|
-
const v = o[key];
|
|
1564
|
-
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
1565
|
-
throw new IpcResponseError(method, `"${key}" must be a finite number`);
|
|
1566
|
-
}
|
|
1567
|
-
return v;
|
|
1568
|
-
}
|
|
1569
|
-
function bool(method, o, key) {
|
|
1570
|
-
const v = o[key];
|
|
1571
|
-
if (typeof v !== "boolean")
|
|
1572
|
-
throw new IpcResponseError(method, `"${key}" must be a boolean`);
|
|
1573
|
-
return v;
|
|
1574
|
-
}
|
|
1575
|
-
function arr(method, v) {
|
|
1576
|
-
if (!Array.isArray(v))
|
|
1577
|
-
throw new IpcResponseError(method, "expected an array");
|
|
1578
|
-
return v;
|
|
1579
|
-
}
|
|
1580
|
-
function optStr(o, key) {
|
|
1581
|
-
const v = o[key];
|
|
1582
|
-
return typeof v === "string" ? v : undefined;
|
|
1583
|
-
}
|
|
1584
|
-
function optNum(o, key) {
|
|
1585
|
-
const v = o[key];
|
|
1586
|
-
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
1587
1802
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1803
|
+
var PREFLIGHT_GAP_VALUES = new Set([
|
|
1804
|
+
"no_pagerduty_mapping",
|
|
1805
|
+
"no_repos",
|
|
1806
|
+
"unknown_mergeable_state",
|
|
1807
|
+
"pagerduty_urgency_without_priority"
|
|
1808
|
+
]);
|
|
1809
|
+
function validatePreflightGap(method, v, field) {
|
|
1590
1810
|
if (v === null)
|
|
1591
1811
|
return null;
|
|
1592
|
-
if (typeof v
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
return v;
|
|
1812
|
+
if (typeof v === "string" && PREFLIGHT_GAP_VALUES.has(v))
|
|
1813
|
+
return v;
|
|
1814
|
+
throw new IpcResponseError(method, `"${field}" must be a recognised preflight gap code or null`);
|
|
1596
1815
|
}
|
|
1597
|
-
function
|
|
1598
|
-
const
|
|
1599
|
-
if (
|
|
1600
|
-
|
|
1601
|
-
if (typeof v !== "string") {
|
|
1602
|
-
throw new IpcResponseError(method, `"${key}" must be a string or null`);
|
|
1816
|
+
function optUrl(method, o, field) {
|
|
1817
|
+
const url = o["url"];
|
|
1818
|
+
if (url !== null && typeof url !== "string") {
|
|
1819
|
+
throw new IpcResponseError(method, `${field} "url" must be a string or null`);
|
|
1603
1820
|
}
|
|
1604
|
-
return
|
|
1821
|
+
return url;
|
|
1605
1822
|
}
|
|
1606
|
-
function
|
|
1607
|
-
const
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
throw new IpcResponseError(method, `"${key}" must be a boolean or null`);
|
|
1823
|
+
function validateIncidentFinding(method, v) {
|
|
1824
|
+
const o = record(method, v);
|
|
1825
|
+
const status = o["status"];
|
|
1826
|
+
if (status !== "triggered" && status !== "acknowledged") {
|
|
1827
|
+
throw new IpcResponseError(method, `incident finding "status" must be "triggered" or "acknowledged"`);
|
|
1612
1828
|
}
|
|
1613
|
-
return
|
|
1829
|
+
return {
|
|
1830
|
+
id: str(method, o, "id"),
|
|
1831
|
+
title: str(method, o, "title"),
|
|
1832
|
+
status,
|
|
1833
|
+
severity: str(method, o, "severity"),
|
|
1834
|
+
opened_at_ms: num(method, o, "opened_at_ms"),
|
|
1835
|
+
pagerduty_service_id: str(method, o, "pagerduty_service_id"),
|
|
1836
|
+
url: optUrl(method, o, "incident finding")
|
|
1837
|
+
};
|
|
1614
1838
|
}
|
|
1615
|
-
function
|
|
1839
|
+
function validateCiFinding(method, v) {
|
|
1616
1840
|
const o = record(method, v);
|
|
1617
|
-
|
|
1618
|
-
|
|
1841
|
+
const conclusion = o["conclusion"];
|
|
1842
|
+
if (conclusion !== "failure" && conclusion !== "cancelled" && conclusion !== "timed_out") {
|
|
1843
|
+
throw new IpcResponseError(method, `ci finding "conclusion" must be "failure", "cancelled", or "timed_out"`);
|
|
1619
1844
|
}
|
|
1620
|
-
|
|
1845
|
+
const headSha = o["head_sha"];
|
|
1846
|
+
if (headSha !== null && typeof headSha !== "string") {
|
|
1847
|
+
throw new IpcResponseError(method, `ci finding "head_sha" must be a string or null`);
|
|
1848
|
+
}
|
|
1849
|
+
return {
|
|
1850
|
+
id: str(method, o, "id"),
|
|
1851
|
+
title: str(method, o, "title"),
|
|
1852
|
+
conclusion,
|
|
1853
|
+
modified_at_ms: num(method, o, "modified_at_ms"),
|
|
1854
|
+
branch: str(method, o, "branch"),
|
|
1855
|
+
head_sha: headSha,
|
|
1856
|
+
url: optUrl(method, o, "ci finding")
|
|
1857
|
+
};
|
|
1621
1858
|
}
|
|
1622
|
-
function
|
|
1859
|
+
function validatePrFinding(method, v) {
|
|
1623
1860
|
const o = record(method, v);
|
|
1624
|
-
return {
|
|
1861
|
+
return {
|
|
1862
|
+
id: str(method, o, "id"),
|
|
1863
|
+
title: str(method, o, "title"),
|
|
1864
|
+
number: num(method, o, "number"),
|
|
1865
|
+
mergeable_state: str(method, o, "mergeable_state"),
|
|
1866
|
+
modified_at_ms: num(method, o, "modified_at_ms"),
|
|
1867
|
+
url: optUrl(method, o, "pr finding")
|
|
1868
|
+
};
|
|
1625
1869
|
}
|
|
1626
|
-
function
|
|
1627
|
-
const o = record(method, v);
|
|
1628
|
-
const turns = arr(method, o["turns"]).map((t) => {
|
|
1629
|
-
const to = record(method, t);
|
|
1630
|
-
const role = str(method, to, "role");
|
|
1631
|
-
if (role !== "user" && role !== "assistant") {
|
|
1632
|
-
throw new IpcResponseError(method, `turn "role" must be "user" or "assistant"`);
|
|
1633
|
-
}
|
|
1634
|
-
const turn = {
|
|
1635
|
-
role,
|
|
1636
|
-
text: str(method, to, "text"),
|
|
1637
|
-
timestamp: num(method, to, "timestamp")
|
|
1638
|
-
};
|
|
1639
|
-
if (to["auditLogId"] !== undefined)
|
|
1640
|
-
turn.auditLogId = num(method, to, "auditLogId");
|
|
1641
|
-
return turn;
|
|
1642
|
-
});
|
|
1643
|
-
return { sessionId: str(method, o, "sessionId"), turns, hasMore: bool(method, o, "hasMore") };
|
|
1644
|
-
}
|
|
1645
|
-
function validateSessionMemoryRole(method, o, key) {
|
|
1646
|
-
const v = o[key];
|
|
1647
|
-
if (v !== "user" && v !== "assistant" && v !== "tool") {
|
|
1648
|
-
throw new IpcResponseError(method, `"${key}" must be "user", "assistant", or "tool"`);
|
|
1649
|
-
}
|
|
1650
|
-
return v;
|
|
1651
|
-
}
|
|
1652
|
-
function validateSessionRecallHit(method, v) {
|
|
1653
|
-
const o = record(method, v);
|
|
1654
|
-
return {
|
|
1655
|
-
chunkText: str(method, o, "chunkText"),
|
|
1656
|
-
role: validateSessionMemoryRole(method, o, "role"),
|
|
1657
|
-
createdAt: num(method, o, "createdAt"),
|
|
1658
|
-
distance: num(method, o, "distance")
|
|
1659
|
-
};
|
|
1660
|
-
}
|
|
1661
|
-
function validateSessionRecall(method, v) {
|
|
1662
|
-
const o = record(method, v);
|
|
1663
|
-
return { chunks: arr(method, o["chunks"]).map((c) => validateSessionRecallHit(method, c)) };
|
|
1664
|
-
}
|
|
1665
|
-
function validateSessionListEntry(method, v) {
|
|
1870
|
+
function validatePreflightCheck(method, v, field, validateFinding) {
|
|
1666
1871
|
const o = record(method, v);
|
|
1667
1872
|
return {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1873
|
+
count: num(method, o, "count"),
|
|
1874
|
+
findings: arr(method, o["findings"]).map((f) => validateFinding(method, f)),
|
|
1875
|
+
gap: validatePreflightGap(method, o["gap"], `${field}.gap`)
|
|
1671
1876
|
};
|
|
1672
1877
|
}
|
|
1673
|
-
function
|
|
1878
|
+
function validateDeployPreflight(method, v) {
|
|
1674
1879
|
const o = record(method, v);
|
|
1880
|
+
const verdict = o["verdict"];
|
|
1881
|
+
if (verdict !== "ok" && verdict !== "warn") {
|
|
1882
|
+
throw new IpcResponseError(method, `"verdict" must be "ok" or "warn"`);
|
|
1883
|
+
}
|
|
1884
|
+
const checks = record(method, o["checks"]);
|
|
1675
1885
|
return {
|
|
1676
|
-
|
|
1886
|
+
service: str(method, o, "service"),
|
|
1887
|
+
target_ref: str(method, o, "target_ref"),
|
|
1888
|
+
computed_at: str(method, o, "computed_at"),
|
|
1889
|
+
verdict,
|
|
1890
|
+
checks: {
|
|
1891
|
+
active_p1_incidents: validatePreflightCheck(method, checks["active_p1_incidents"], "active_p1_incidents", validateIncidentFinding),
|
|
1892
|
+
failing_ci_runs: validatePreflightCheck(method, checks["failing_ci_runs"], "failing_ci_runs", validateCiFinding),
|
|
1893
|
+
merge_conflicts: validatePreflightCheck(method, checks["merge_conflicts"], "merge_conflicts", validatePrFinding)
|
|
1894
|
+
}
|
|
1677
1895
|
};
|
|
1678
1896
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
function validateQueryItems(method, v) {
|
|
1684
|
-
const o = record(method, v);
|
|
1685
|
-
const items = arr(method, o["items"]).map((raw) => {
|
|
1686
|
-
const r = record(method, raw);
|
|
1687
|
-
const item = {
|
|
1688
|
-
id: str(method, r, "id"),
|
|
1689
|
-
indexPrimaryKey: str(method, r, "indexPrimaryKey"),
|
|
1690
|
-
service: str(method, r, "service"),
|
|
1691
|
-
itemType: str(method, r, "itemType"),
|
|
1692
|
-
name: str(method, r, "name")
|
|
1693
|
-
};
|
|
1694
|
-
const mimeType = optStr(r, "mimeType");
|
|
1695
|
-
if (mimeType !== undefined)
|
|
1696
|
-
item.mimeType = mimeType;
|
|
1697
|
-
const sizeBytes = optNum(r, "sizeBytes");
|
|
1698
|
-
if (sizeBytes !== undefined)
|
|
1699
|
-
item.sizeBytes = sizeBytes;
|
|
1700
|
-
const createdAt = optNum(r, "createdAt");
|
|
1701
|
-
if (createdAt !== undefined)
|
|
1702
|
-
item.createdAt = createdAt;
|
|
1703
|
-
const modifiedAt = optNum(r, "modifiedAt");
|
|
1704
|
-
if (modifiedAt !== undefined)
|
|
1705
|
-
item.modifiedAt = modifiedAt;
|
|
1706
|
-
const url = optStr(r, "url");
|
|
1707
|
-
if (url !== undefined)
|
|
1708
|
-
item.url = url;
|
|
1709
|
-
const parentId = optStr(r, "parentId");
|
|
1710
|
-
if (parentId !== undefined)
|
|
1711
|
-
item.parentId = parentId;
|
|
1712
|
-
return item;
|
|
1713
|
-
});
|
|
1714
|
-
const meta = record(method, o["meta"]);
|
|
1715
|
-
return { items, meta: { limit: num(method, meta, "limit"), total: num(method, meta, "total") } };
|
|
1716
|
-
}
|
|
1717
|
-
function validateRankedItems(method, v) {
|
|
1718
|
-
return arr(method, v).map((it) => {
|
|
1719
|
-
const o = record(method, it);
|
|
1720
|
-
num(method, o, "score");
|
|
1721
|
-
str(method, o, "indexPrimaryKey");
|
|
1722
|
-
str(method, o, "indexedType");
|
|
1723
|
-
return o;
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
function validateQuerySql(method, v) {
|
|
1727
|
-
const o = record(method, v);
|
|
1728
|
-
return { rows: arr(method, o["rows"]).map((r) => record(method, r)) };
|
|
1729
|
-
}
|
|
1730
|
-
function validateAuditList(method, v) {
|
|
1731
|
-
return arr(method, v);
|
|
1732
|
-
}
|
|
1733
|
-
function validateAuditVerify(method, v) {
|
|
1897
|
+
var CONNECTOR_STATUS_VALUES = new Set(["ok", "syncing", "paused", "backoff", "error"]);
|
|
1898
|
+
var CONNECTOR_DEPTH_VALUES = new Set(["metadata_only", "summary", "full"]);
|
|
1899
|
+
function validateConnectorSyncStatus(method, v) {
|
|
1734
1900
|
const o = record(method, v);
|
|
1901
|
+
const status = o["status"];
|
|
1902
|
+
if (typeof status !== "string" || !CONNECTOR_STATUS_VALUES.has(status)) {
|
|
1903
|
+
throw new IpcResponseError(method, `"status" must be a recognised connector status`);
|
|
1904
|
+
}
|
|
1905
|
+
const depth = o["depth"];
|
|
1906
|
+
if (typeof depth !== "string" || !CONNECTOR_DEPTH_VALUES.has(depth)) {
|
|
1907
|
+
throw new IpcResponseError(method, `"depth" must be "metadata_only", "summary", or "full"`);
|
|
1908
|
+
}
|
|
1735
1909
|
const result = {
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1910
|
+
serviceId: str(method, o, "serviceId"),
|
|
1911
|
+
status,
|
|
1912
|
+
lastSyncAt: nullableNum(method, o, "lastSyncAt"),
|
|
1913
|
+
nextSyncAt: nullableNum(method, o, "nextSyncAt"),
|
|
1914
|
+
intervalMs: num(method, o, "intervalMs"),
|
|
1915
|
+
itemCount: num(method, o, "itemCount"),
|
|
1916
|
+
lastError: nullableStr(method, o, "lastError"),
|
|
1917
|
+
consecutiveFailures: num(method, o, "consecutiveFailures"),
|
|
1918
|
+
depth,
|
|
1919
|
+
enabled: bool(method, o, "enabled")
|
|
1739
1920
|
};
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1921
|
+
const healthState = optStr(o, "healthState");
|
|
1922
|
+
if (healthState !== undefined)
|
|
1923
|
+
result.healthState = healthState;
|
|
1924
|
+
if (o["healthRetryAfterMs"] !== undefined) {
|
|
1925
|
+
result.healthRetryAfterMs = nullableNum(method, o, "healthRetryAfterMs");
|
|
1926
|
+
}
|
|
1744
1927
|
return result;
|
|
1745
1928
|
}
|
|
1746
|
-
function
|
|
1929
|
+
function validateConnectorSyncStatusList(method, v) {
|
|
1930
|
+
return arr(method, v).map((r) => validateConnectorSyncStatus(method, r));
|
|
1931
|
+
}
|
|
1932
|
+
function validateConnectorSyncTelemetry(method, v) {
|
|
1747
1933
|
const o = record(method, v);
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1934
|
+
return {
|
|
1935
|
+
startedAt: num(method, o, "startedAt"),
|
|
1936
|
+
durationMs: num(method, o, "durationMs"),
|
|
1937
|
+
itemsUpserted: num(method, o, "itemsUpserted"),
|
|
1938
|
+
itemsDeleted: num(method, o, "itemsDeleted"),
|
|
1939
|
+
bytesTransferred: nullableNum(method, o, "bytesTransferred"),
|
|
1940
|
+
hadMore: bool(method, o, "hadMore"),
|
|
1941
|
+
errorMsg: nullableStr(method, o, "errorMsg")
|
|
1942
|
+
};
|
|
1754
1943
|
}
|
|
1755
|
-
function
|
|
1944
|
+
function validateConnectorStatusResult(method, v) {
|
|
1945
|
+
const base = validateConnectorSyncStatus(method, v);
|
|
1756
1946
|
const o = record(method, v);
|
|
1947
|
+
if (o["telemetry"] === undefined)
|
|
1948
|
+
return base;
|
|
1757
1949
|
return {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
total: num(method, o, "total")
|
|
1950
|
+
...base,
|
|
1951
|
+
telemetry: arr(method, o["telemetry"]).map((t) => validateConnectorSyncTelemetry(method, t))
|
|
1761
1952
|
};
|
|
1762
1953
|
}
|
|
1763
|
-
function
|
|
1954
|
+
function validateConnectorHealthHistoryEntry(method, v) {
|
|
1764
1955
|
const o = record(method, v);
|
|
1765
|
-
const sessionId = o["sessionId"];
|
|
1766
|
-
if (sessionId !== null && typeof sessionId !== "string") {
|
|
1767
|
-
throw new IpcResponseError(method, `tool call "sessionId" must be a string or null`);
|
|
1768
|
-
}
|
|
1769
|
-
const status = o["status"];
|
|
1770
|
-
if (status !== "ok" && status !== "error") {
|
|
1771
|
-
throw new IpcResponseError(method, `tool call "status" must be "ok" or "error"`);
|
|
1772
|
-
}
|
|
1773
1956
|
return {
|
|
1774
1957
|
id: num(method, o, "id"),
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
resultEnvelope: str(method, o, "resultEnvelope"),
|
|
1781
|
-
status,
|
|
1782
|
-
params: o["params"]
|
|
1958
|
+
connectorId: str(method, o, "connectorId"),
|
|
1959
|
+
fromState: nullableStr(method, o, "fromState"),
|
|
1960
|
+
toState: str(method, o, "toState"),
|
|
1961
|
+
reason: nullableStr(method, o, "reason"),
|
|
1962
|
+
occurredAtMs: num(method, o, "occurredAtMs")
|
|
1783
1963
|
};
|
|
1784
1964
|
}
|
|
1785
|
-
function
|
|
1786
|
-
|
|
1787
|
-
return null;
|
|
1788
|
-
const o = record(method, v);
|
|
1789
|
-
return { calledAt: num(method, o, "calledAt"), id: num(method, o, "id") };
|
|
1965
|
+
function validateConnectorHealthHistory(method, v) {
|
|
1966
|
+
return arr(method, v).map((r) => validateConnectorHealthHistoryEntry(method, r));
|
|
1790
1967
|
}
|
|
1791
|
-
function
|
|
1968
|
+
function validateConnectorSetConfig(method, v) {
|
|
1792
1969
|
const o = record(method, v);
|
|
1793
1970
|
return {
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1971
|
+
service: str(method, o, "service"),
|
|
1972
|
+
intervalMs: nullableNum(method, o, "intervalMs"),
|
|
1973
|
+
depth: nullableStr(method, o, "depth"),
|
|
1974
|
+
enabled: nullableBool(method, o, "enabled")
|
|
1797
1975
|
};
|
|
1798
1976
|
}
|
|
1799
|
-
function
|
|
1800
|
-
const o = record(method, v);
|
|
1801
|
-
return { head: str(method, o, "head"), count: num(method, o, "count") };
|
|
1802
|
-
}
|
|
1803
|
-
function validateEgressRow(method, v) {
|
|
1977
|
+
function validateConnectorReindex(method, v) {
|
|
1804
1978
|
const o = record(method, v);
|
|
1805
|
-
const
|
|
1806
|
-
if (
|
|
1807
|
-
throw new IpcResponseError(method, `
|
|
1979
|
+
const depth = o["depth"];
|
|
1980
|
+
if (typeof depth !== "string" || !CONNECTOR_DEPTH_VALUES.has(depth)) {
|
|
1981
|
+
throw new IpcResponseError(method, `"depth" must be "metadata_only", "summary", or "full"`);
|
|
1982
|
+
}
|
|
1983
|
+
const mode = o["mode"];
|
|
1984
|
+
if (mode !== "shallow" && mode !== "deepen" && mode !== "same") {
|
|
1985
|
+
throw new IpcResponseError(method, `"mode" must be "shallow", "deepen", or "same"`);
|
|
1808
1986
|
}
|
|
1809
1987
|
return {
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
sourceId,
|
|
1814
|
-
destination: str(method, o, "destination"),
|
|
1815
|
-
method: str(method, o, "method"),
|
|
1816
|
-
payloadSummary: str(method, o, "payloadSummary"),
|
|
1817
|
-
hitlStatus: str(method, o, "hitlStatus"),
|
|
1818
|
-
resultStatus: str(method, o, "resultStatus"),
|
|
1819
|
-
rowHash: str(method, o, "rowHash"),
|
|
1820
|
-
prevHash: str(method, o, "prevHash")
|
|
1988
|
+
itemsAffected: num(method, o, "itemsAffected"),
|
|
1989
|
+
depth,
|
|
1990
|
+
mode
|
|
1821
1991
|
};
|
|
1822
1992
|
}
|
|
1823
|
-
function
|
|
1993
|
+
function validateConnectorAuth(method, v) {
|
|
1824
1994
|
const o = record(method, v);
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
const
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
if (o["reason"] !== undefined)
|
|
1836
|
-
result.reason = str(method, o, "reason");
|
|
1837
|
-
return result;
|
|
1995
|
+
if (!bool(method, o, "ok")) {
|
|
1996
|
+
throw new IpcResponseError(method, `"ok" must be true`);
|
|
1997
|
+
}
|
|
1998
|
+
const scopesGranted = arr(method, o["scopesGranted"]).map((s) => {
|
|
1999
|
+
if (typeof s !== "string") {
|
|
2000
|
+
throw new IpcResponseError(method, `"scopesGranted" must contain only strings`);
|
|
2001
|
+
}
|
|
2002
|
+
return s;
|
|
2003
|
+
});
|
|
2004
|
+
return { ok: true, serviceId: str(method, o, "serviceId"), scopesGranted };
|
|
1838
2005
|
}
|
|
1839
|
-
function
|
|
2006
|
+
function validateGatedOrElse(method, v, validateSuccess) {
|
|
1840
2007
|
const o = record(method, v);
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
throw new IpcResponseError(method, `completeness "tier" must be "authorized-actions"`);
|
|
2008
|
+
if (o["status"] === "rejected") {
|
|
2009
|
+
return { status: "rejected", reason: str(method, o, "reason") };
|
|
1844
2010
|
}
|
|
1845
|
-
return
|
|
2011
|
+
return validateSuccess(method, o);
|
|
1846
2012
|
}
|
|
1847
|
-
function
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
};
|
|
2013
|
+
function validateConnectorAddMcp(method, v) {
|
|
2014
|
+
return validateGatedOrElse(method, v, (m, o) => {
|
|
2015
|
+
if (!bool(m, o, "ok")) {
|
|
2016
|
+
throw new IpcResponseError(m, `"ok" must be true`);
|
|
2017
|
+
}
|
|
2018
|
+
return { ok: true, serviceId: str(m, o, "serviceId") };
|
|
2019
|
+
});
|
|
1854
2020
|
}
|
|
1855
|
-
function
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2021
|
+
function validateConnectorRemove(method, v) {
|
|
2022
|
+
return validateGatedOrElse(method, v, (m, o) => {
|
|
2023
|
+
if (!bool(m, o, "ok")) {
|
|
2024
|
+
throw new IpcResponseError(m, `"ok" must be true`);
|
|
2025
|
+
}
|
|
2026
|
+
const vaultKeysRemoved = arr(m, o["vaultKeysRemoved"]).map((k) => {
|
|
2027
|
+
if (typeof k !== "string") {
|
|
2028
|
+
throw new IpcResponseError(m, `"vaultKeysRemoved" must contain only strings`);
|
|
2029
|
+
}
|
|
2030
|
+
return k;
|
|
2031
|
+
});
|
|
2032
|
+
return { ok: true, itemsDeleted: num(m, o, "itemsDeleted"), vaultKeysRemoved };
|
|
2033
|
+
});
|
|
1865
2034
|
}
|
|
1866
|
-
function
|
|
2035
|
+
function validateWorkflowRow(method, v) {
|
|
1867
2036
|
const o = record(method, v);
|
|
1868
|
-
return {
|
|
2037
|
+
return {
|
|
2038
|
+
id: str(method, o, "id"),
|
|
2039
|
+
name: str(method, o, "name"),
|
|
2040
|
+
description: nullableStr(method, o, "description"),
|
|
2041
|
+
steps_json: str(method, o, "steps_json"),
|
|
2042
|
+
created_at: num(method, o, "created_at"),
|
|
2043
|
+
updated_at: num(method, o, "updated_at")
|
|
2044
|
+
};
|
|
1869
2045
|
}
|
|
1870
|
-
function
|
|
2046
|
+
function validateWorkflowList(method, v) {
|
|
1871
2047
|
const o = record(method, v);
|
|
1872
|
-
|
|
1873
|
-
num(method, o, "uptime");
|
|
1874
|
-
const limits = record(method, o["agentLimits"]);
|
|
1875
|
-
num(method, limits, "maxAgentDepth");
|
|
1876
|
-
num(method, limits, "maxToolCallsPerSession");
|
|
1877
|
-
if (o["drift"] !== undefined) {
|
|
1878
|
-
const drift = record(method, o["drift"]);
|
|
1879
|
-
for (const line of arr(method, drift["lines"])) {
|
|
1880
|
-
if (typeof line !== "string") {
|
|
1881
|
-
throw new IpcResponseError(method, `drift "lines" must be strings`);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
return o;
|
|
2048
|
+
return { workflows: arr(method, o["workflows"]).map((w) => validateWorkflowRow(method, w)) };
|
|
1886
2049
|
}
|
|
1887
|
-
function
|
|
2050
|
+
function validateWorkflowSave(method, v) {
|
|
1888
2051
|
const o = record(method, v);
|
|
1889
|
-
|
|
1890
|
-
const commit = o["commit"];
|
|
1891
|
-
if (commit !== null && typeof commit !== "string") {
|
|
1892
|
-
throw new IpcResponseError(method, `"commit" must be a string or null`);
|
|
1893
|
-
}
|
|
1894
|
-
const buildId = o["buildId"];
|
|
1895
|
-
if (buildId !== null && typeof buildId !== "string") {
|
|
1896
|
-
throw new IpcResponseError(method, `"buildId" must be a string or null`);
|
|
1897
|
-
}
|
|
1898
|
-
return { version, commit, buildId, uptimeMs: num(method, o, "uptimeMs") };
|
|
2052
|
+
return { id: str(method, o, "id") };
|
|
1899
2053
|
}
|
|
1900
|
-
function
|
|
2054
|
+
function validateWorkflowRunHistoryRow(method, v) {
|
|
1901
2055
|
const o = record(method, v);
|
|
1902
|
-
const itemCountByService = record(method, o["itemCountByService"]);
|
|
1903
|
-
for (const val of Object.values(itemCountByService)) {
|
|
1904
|
-
if (typeof val !== "number" || !Number.isFinite(val)) {
|
|
1905
|
-
throw new IpcResponseError(method, `"itemCountByService" values must be numbers`);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
const lastSuccessfulSyncByConnector = record(method, o["lastSuccessfulSyncByConnector"]);
|
|
1909
|
-
for (const val of Object.values(lastSuccessfulSyncByConnector)) {
|
|
1910
|
-
if (val !== null && (typeof val !== "number" || !Number.isFinite(val))) {
|
|
1911
|
-
throw new IpcResponseError(method, `"lastSuccessfulSyncByConnector" values must be a number or null`);
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
2056
|
return {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
2057
|
+
id: str(method, o, "id"),
|
|
2058
|
+
startedAt: num(method, o, "startedAt"),
|
|
2059
|
+
finishedAt: nullableNum(method, o, "finishedAt"),
|
|
2060
|
+
durationMs: nullableNum(method, o, "durationMs"),
|
|
2061
|
+
status: str(method, o, "status"),
|
|
2062
|
+
errorMsg: nullableStr(method, o, "errorMsg"),
|
|
2063
|
+
dryRun: bool(method, o, "dryRun"),
|
|
2064
|
+
paramsOverrideJson: nullableStr(method, o, "paramsOverrideJson"),
|
|
2065
|
+
triggeredBy: str(method, o, "triggeredBy")
|
|
1923
2066
|
};
|
|
1924
2067
|
}
|
|
1925
|
-
function
|
|
2068
|
+
function validateWorkflowListRuns(method, v) {
|
|
1926
2069
|
const o = record(method, v);
|
|
1927
|
-
|
|
1928
|
-
connectorId: str(method, o, "connectorId"),
|
|
1929
|
-
state: str(method, o, "state"),
|
|
1930
|
-
backoffAttempt: num(method, o, "backoffAttempt")
|
|
1931
|
-
};
|
|
1932
|
-
const retryAfterMs = optNum(o, "retryAfterMs");
|
|
1933
|
-
if (retryAfterMs !== undefined)
|
|
1934
|
-
entry.retryAfterMs = retryAfterMs;
|
|
1935
|
-
const backoffUntilMs = optNum(o, "backoffUntilMs");
|
|
1936
|
-
if (backoffUntilMs !== undefined)
|
|
1937
|
-
entry.backoffUntilMs = backoffUntilMs;
|
|
1938
|
-
const lastError = optStr(o, "lastError");
|
|
1939
|
-
if (lastError !== undefined)
|
|
1940
|
-
entry.lastError = lastError;
|
|
1941
|
-
const lastSuccessfulSyncMs = optNum(o, "lastSuccessfulSyncMs");
|
|
1942
|
-
if (lastSuccessfulSyncMs !== undefined)
|
|
1943
|
-
entry.lastSuccessfulSyncMs = lastSuccessfulSyncMs;
|
|
1944
|
-
const lastSyncAttemptMs = optNum(o, "lastSyncAttemptMs");
|
|
1945
|
-
if (lastSyncAttemptMs !== undefined)
|
|
1946
|
-
entry.lastSyncAttemptMs = lastSyncAttemptMs;
|
|
1947
|
-
return entry;
|
|
2070
|
+
return { runs: arr(method, o["runs"]).map((r) => validateWorkflowRunHistoryRow(method, r)) };
|
|
1948
2071
|
}
|
|
1949
|
-
function
|
|
2072
|
+
function validateWorkflowStepResult(method, v) {
|
|
1950
2073
|
const o = record(method, v);
|
|
1951
|
-
const
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2074
|
+
const result = { status: str(method, o, "status") };
|
|
2075
|
+
const label = optStr(o, "label");
|
|
2076
|
+
if (label !== undefined)
|
|
2077
|
+
result.label = label;
|
|
2078
|
+
const output = optStr(o, "output");
|
|
2079
|
+
if (output !== undefined)
|
|
2080
|
+
result.output = output;
|
|
2081
|
+
const error = optStr(o, "error");
|
|
2082
|
+
if (error !== undefined)
|
|
2083
|
+
result.error = error;
|
|
2084
|
+
return result;
|
|
1961
2085
|
}
|
|
1962
|
-
function
|
|
2086
|
+
function validateWorkflowRun(method, v) {
|
|
1963
2087
|
const o = record(method, v);
|
|
1964
|
-
const caps = record(method, o["platform_capabilities"]);
|
|
1965
|
-
const network = caps["network"];
|
|
1966
|
-
if (network !== "per_host" && network !== "all_or_nothing") {
|
|
1967
|
-
throw new IpcResponseError(method, `platform_capabilities "network" must be "per_host" or "all_or_nothing"`);
|
|
1968
|
-
}
|
|
1969
|
-
const capsReason = caps["reason"];
|
|
1970
|
-
if (capsReason !== null && typeof capsReason !== "string") {
|
|
1971
|
-
throw new IpcResponseError(method, `platform_capabilities "reason" must be a string or null`);
|
|
1972
|
-
}
|
|
1973
|
-
const linuxHelperRaw = o["linux_helper"];
|
|
1974
|
-
let linuxHelper = null;
|
|
1975
|
-
if (linuxHelperRaw !== null) {
|
|
1976
|
-
const lh = record(method, linuxHelperRaw);
|
|
1977
|
-
const lhReason = lh["reason"];
|
|
1978
|
-
if (lhReason !== null && typeof lhReason !== "string") {
|
|
1979
|
-
throw new IpcResponseError(method, `linux_helper "reason" must be a string or null`);
|
|
1980
|
-
}
|
|
1981
|
-
linuxHelper = { available: bool(method, lh, "available"), reason: lhReason };
|
|
1982
|
-
}
|
|
1983
2088
|
return {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2089
|
+
runId: str(method, o, "runId"),
|
|
2090
|
+
dryRun: bool(method, o, "dryRun"),
|
|
2091
|
+
stepResults: arr(method, o["stepResults"]).map((s) => validateWorkflowStepResult(method, s))
|
|
1987
2092
|
};
|
|
1988
2093
|
}
|
|
1989
|
-
function
|
|
2094
|
+
function validateWhyPeek(method, v) {
|
|
1990
2095
|
const o = record(method, v);
|
|
1991
|
-
const
|
|
1992
|
-
const
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
if (extensionsRaw["auto_update"] !== undefined) {
|
|
1999
|
-
const au = record(method, extensionsRaw["auto_update"]);
|
|
2000
|
-
extensions.auto_update = {
|
|
2001
|
-
cached_updates_count: num(method, au, "cached_updates_count"),
|
|
2002
|
-
interval_hours: num(method, au, "interval_hours"),
|
|
2003
|
-
air_gap_blocked: bool(method, au, "air_gap_blocked")
|
|
2096
|
+
const subjRaw = o["subject"];
|
|
2097
|
+
const subject = subjRaw === null || subjRaw === undefined ? null : (() => {
|
|
2098
|
+
const s = record(method, subjRaw);
|
|
2099
|
+
return {
|
|
2100
|
+
repoRoot: str(method, s, "repoRoot"),
|
|
2101
|
+
filePath: str(method, s, "filePath"),
|
|
2102
|
+
lineNo: num(method, s, "lineNo")
|
|
2004
2103
|
};
|
|
2005
|
-
}
|
|
2104
|
+
})();
|
|
2105
|
+
const prRaw = o["pr"];
|
|
2106
|
+
const pr = prRaw === null || prRaw === undefined ? null : (() => {
|
|
2107
|
+
const p = record(method, prRaw);
|
|
2108
|
+
return {
|
|
2109
|
+
number: nullableNum(method, p, "number"),
|
|
2110
|
+
title: str(method, p, "title"),
|
|
2111
|
+
url: nullableStr(method, p, "url")
|
|
2112
|
+
};
|
|
2113
|
+
})();
|
|
2114
|
+
const tRaw = o["ticket"];
|
|
2115
|
+
const ticket = tRaw === null || tRaw === undefined ? null : (() => {
|
|
2116
|
+
const t = record(method, tRaw);
|
|
2117
|
+
return {
|
|
2118
|
+
key: str(method, t, "key"),
|
|
2119
|
+
title: str(method, t, "title"),
|
|
2120
|
+
url: nullableStr(method, t, "url")
|
|
2121
|
+
};
|
|
2122
|
+
})();
|
|
2006
2123
|
return {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
extensions,
|
|
2017
|
-
sandbox: validateSandboxDiag(method, o["sandbox"])
|
|
2018
|
-
};
|
|
2019
|
-
}
|
|
2020
|
-
function validatePolicyState(method, v) {
|
|
2021
|
-
const o = record(method, v);
|
|
2022
|
-
const source = o["source"];
|
|
2023
|
-
if (source !== "anchor" && source !== "peer" && source !== "none") {
|
|
2024
|
-
throw new IpcResponseError(method, `policy "source" must be "anchor", "peer", or "none"`);
|
|
2025
|
-
}
|
|
2026
|
-
const state = {
|
|
2027
|
-
signatureValid: bool(method, o, "signatureValid"),
|
|
2028
|
-
pendingRestart: bool(method, o, "pendingRestart"),
|
|
2029
|
-
source
|
|
2030
|
-
};
|
|
2031
|
-
const org = optStr(o, "org");
|
|
2032
|
-
if (org !== undefined)
|
|
2033
|
-
state.org = org;
|
|
2034
|
-
const version = optNum(o, "version");
|
|
2035
|
-
if (version !== undefined)
|
|
2036
|
-
state.version = version;
|
|
2037
|
-
const lastFetchedMs = optNum(o, "lastFetchedMs");
|
|
2038
|
-
if (lastFetchedMs !== undefined)
|
|
2039
|
-
state.lastFetchedMs = lastFetchedMs;
|
|
2040
|
-
return state;
|
|
2041
|
-
}
|
|
2042
|
-
function validatePeerStatus(method, v) {
|
|
2043
|
-
const o = record(method, v);
|
|
2044
|
-
const status = {
|
|
2045
|
-
peerId: str(method, o, "peerId"),
|
|
2046
|
-
reachable: bool(method, o, "reachable")
|
|
2047
|
-
};
|
|
2048
|
-
const lastSeenMs = optNum(o, "lastSeenMs");
|
|
2049
|
-
if (lastSeenMs !== undefined)
|
|
2050
|
-
status.lastSeenMs = lastSeenMs;
|
|
2051
|
-
return status;
|
|
2052
|
-
}
|
|
2053
|
-
function validateConnectorStatus(method, v) {
|
|
2054
|
-
const o = record(method, v);
|
|
2055
|
-
const status = {
|
|
2056
|
-
id: str(method, o, "id"),
|
|
2057
|
-
enabled: bool(method, o, "enabled"),
|
|
2058
|
-
blockedByPolicy: bool(method, o, "blockedByPolicy"),
|
|
2059
|
-
health: str(method, o, "health")
|
|
2124
|
+
subject,
|
|
2125
|
+
author: nullableStr(method, o, "author"),
|
|
2126
|
+
authorEmail: nullableStr(method, o, "authorEmail"),
|
|
2127
|
+
commitSha: nullableStr(method, o, "commitSha"),
|
|
2128
|
+
committedAt: nullableNum(method, o, "committedAt"),
|
|
2129
|
+
commitSubject: nullableStr(method, o, "commitSubject"),
|
|
2130
|
+
pr,
|
|
2131
|
+
ticket,
|
|
2132
|
+
hasMore: bool(method, o, "hasMore")
|
|
2060
2133
|
};
|
|
2061
|
-
const lastSyncMs = optNum(o, "lastSyncMs");
|
|
2062
|
-
if (lastSyncMs !== undefined)
|
|
2063
|
-
status.lastSyncMs = lastSyncMs;
|
|
2064
|
-
return status;
|
|
2065
2134
|
}
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2135
|
+
|
|
2136
|
+
// src/workflow-stream.ts
|
|
2137
|
+
function createWorkflowRunStream(ipc, params, validate) {
|
|
2138
|
+
const queue = [];
|
|
2139
|
+
const waiters = [];
|
|
2140
|
+
let done = false;
|
|
2141
|
+
let detach;
|
|
2142
|
+
const push = (ev) => {
|
|
2143
|
+
if (done)
|
|
2144
|
+
return;
|
|
2145
|
+
const w = waiters.shift();
|
|
2146
|
+
if (w !== undefined) {
|
|
2147
|
+
w.resolve({ value: ev, done: false });
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
queue.push(ev);
|
|
2071
2151
|
};
|
|
2072
|
-
const
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
const externalId = optStr(identity, "externalId");
|
|
2084
|
-
if (externalId !== undefined)
|
|
2085
|
-
identityStatus.externalId = externalId;
|
|
2086
|
-
return {
|
|
2087
|
-
policy: validatePolicyState(method, o["policy"]),
|
|
2088
|
-
peers: arr(method, o["peers"]).map((p) => validatePeerStatus(method, p)),
|
|
2089
|
-
connectors: arr(method, o["connectors"]).map((c) => validateConnectorStatus(method, c)),
|
|
2090
|
-
namespaces: arr(method, o["namespaces"]).map((n) => validateNamespaceStatus(method, n)),
|
|
2091
|
-
audit: {
|
|
2092
|
-
chainLength: num(method, audit, "chainLength"),
|
|
2093
|
-
lastHash: str(method, audit, "lastHash"),
|
|
2094
|
-
appendRate1h: num(method, audit, "appendRate1h")
|
|
2095
|
-
},
|
|
2096
|
-
hitl: {
|
|
2097
|
-
pendingApprovals: num(method, hitl, "pendingApprovals"),
|
|
2098
|
-
pendingQuorum: num(method, hitl, "pendingQuorum")
|
|
2099
|
-
},
|
|
2100
|
-
identity: identityStatus,
|
|
2101
|
-
syncFreshnessMs: num(method, o, "syncFreshnessMs")
|
|
2152
|
+
const finish = () => {
|
|
2153
|
+
if (done)
|
|
2154
|
+
return;
|
|
2155
|
+
done = true;
|
|
2156
|
+
detach?.();
|
|
2157
|
+
detach = undefined;
|
|
2158
|
+
let w = waiters.shift();
|
|
2159
|
+
while (w !== undefined) {
|
|
2160
|
+
w.resolve({ value: undefined, done: true });
|
|
2161
|
+
w = waiters.shift();
|
|
2162
|
+
}
|
|
2102
2163
|
};
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
"approximate_lead_time",
|
|
2110
|
-
"mixed_source"
|
|
2111
|
-
]);
|
|
2112
|
-
function validateDoraGap(method, v, field) {
|
|
2113
|
-
if (v === null)
|
|
2114
|
-
return null;
|
|
2115
|
-
if (typeof v === "string" && DORA_GAP_VALUES.has(v))
|
|
2116
|
-
return v;
|
|
2117
|
-
throw new IpcResponseError(method, `"${field}" must be a recognised DORA gap code or null`);
|
|
2118
|
-
}
|
|
2119
|
-
function validateDoraMetricValue(method, v, field) {
|
|
2120
|
-
const o = record(method, v);
|
|
2121
|
-
const value = o["value"];
|
|
2122
|
-
if (value !== null && (typeof value !== "number" || !Number.isFinite(value))) {
|
|
2123
|
-
throw new IpcResponseError(method, `"${field}.value" must be a number or null`);
|
|
2124
|
-
}
|
|
2125
|
-
return {
|
|
2126
|
-
value,
|
|
2127
|
-
unit: str(method, o, "unit"),
|
|
2128
|
-
sample: num(method, o, "sample"),
|
|
2129
|
-
gap: validateDoraGap(method, o["gap"], `${field}.gap`)
|
|
2164
|
+
const onChunk = (p) => {
|
|
2165
|
+
if (typeof p !== "object" || p === null)
|
|
2166
|
+
return;
|
|
2167
|
+
const text = p.text;
|
|
2168
|
+
if (typeof text === "string")
|
|
2169
|
+
push({ type: "chunk", text });
|
|
2130
2170
|
};
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
const
|
|
2134
|
-
|
|
2171
|
+
ipc.onNotification("agent.chunk", onChunk);
|
|
2172
|
+
detach = () => ipc.offNotification("agent.chunk", onChunk);
|
|
2173
|
+
const result = (async () => {
|
|
2174
|
+
try {
|
|
2175
|
+
const raw = await ipc.call("workflow.run", {
|
|
2176
|
+
name: params.name,
|
|
2177
|
+
triggeredBy: params.triggeredBy,
|
|
2178
|
+
dryRun: params.dryRun,
|
|
2179
|
+
stream: true,
|
|
2180
|
+
sessionId: params.sessionId,
|
|
2181
|
+
agent: params.agent,
|
|
2182
|
+
paramsOverride: params.paramsOverride
|
|
2183
|
+
});
|
|
2184
|
+
return validate("workflow.run", raw);
|
|
2185
|
+
} finally {
|
|
2186
|
+
detach?.();
|
|
2187
|
+
detach = undefined;
|
|
2188
|
+
}
|
|
2189
|
+
})();
|
|
2190
|
+
result.then((value) => {
|
|
2191
|
+
push({ type: "done", result: value });
|
|
2192
|
+
finish();
|
|
2193
|
+
}, (err) => {
|
|
2194
|
+
push({ type: "error", message: err instanceof Error ? err.message : String(err) });
|
|
2195
|
+
finish();
|
|
2196
|
+
});
|
|
2135
2197
|
return {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2198
|
+
result,
|
|
2199
|
+
[Symbol.asyncIterator]() {
|
|
2200
|
+
return {
|
|
2201
|
+
next() {
|
|
2202
|
+
const ev = queue.shift();
|
|
2203
|
+
if (ev !== undefined)
|
|
2204
|
+
return Promise.resolve({ value: ev, done: false });
|
|
2205
|
+
if (done) {
|
|
2206
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
2207
|
+
}
|
|
2208
|
+
return new Promise((resolve, reject) => {
|
|
2209
|
+
waiters.push({ resolve, reject });
|
|
2210
|
+
});
|
|
2211
|
+
},
|
|
2212
|
+
return() {
|
|
2213
|
+
finish();
|
|
2214
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2144
2217
|
}
|
|
2145
2218
|
};
|
|
2146
2219
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
"
|
|
2151
|
-
"
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2220
|
+
|
|
2221
|
+
// src/nimbus-client.ts
|
|
2222
|
+
var EGRESS_COVERAGE_CLASSES = [
|
|
2223
|
+
"http",
|
|
2224
|
+
"mcp",
|
|
2225
|
+
"model",
|
|
2226
|
+
"peer",
|
|
2227
|
+
"session",
|
|
2228
|
+
"sync",
|
|
2229
|
+
"task"
|
|
2230
|
+
];
|
|
2231
|
+
var EGRESS_GRANULARITIES = ["none", "per-run", "per-call"];
|
|
2232
|
+
var NO_EGRESS_COVERAGE = Object.freeze({
|
|
2233
|
+
http: "none",
|
|
2234
|
+
mcp: "none",
|
|
2235
|
+
model: "none",
|
|
2236
|
+
peer: "none",
|
|
2237
|
+
session: "none",
|
|
2238
|
+
sync: "none",
|
|
2239
|
+
task: "none"
|
|
2240
|
+
});
|
|
2241
|
+
|
|
2242
|
+
class NimbusClient {
|
|
2243
|
+
ipc;
|
|
2244
|
+
constructor(ipc) {
|
|
2245
|
+
this.ipc = ipc;
|
|
2164
2246
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
throw new IpcResponseError(method, `incident finding "status" must be "triggered" or "acknowledged"`);
|
|
2247
|
+
static async open(opts) {
|
|
2248
|
+
const ipc = new IPCClient(opts.socketPath, {
|
|
2249
|
+
...opts.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: opts.requestTimeoutMs }
|
|
2250
|
+
});
|
|
2251
|
+
await ipc.connect();
|
|
2252
|
+
return new NimbusClient(ipc);
|
|
2172
2253
|
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2183
|
-
function validateCiFinding(method, v) {
|
|
2184
|
-
const o = record(method, v);
|
|
2185
|
-
const conclusion = o["conclusion"];
|
|
2186
|
-
if (conclusion !== "failure" && conclusion !== "cancelled" && conclusion !== "timed_out") {
|
|
2187
|
-
throw new IpcResponseError(method, `ci finding "conclusion" must be "failure", "cancelled", or "timed_out"`);
|
|
2254
|
+
async agentInvoke(input, options) {
|
|
2255
|
+
const raw = await this.ipc.call("agent.invoke", {
|
|
2256
|
+
input,
|
|
2257
|
+
stream: options?.stream ?? false,
|
|
2258
|
+
...options?.sessionId === undefined ? {} : { sessionId: options.sessionId },
|
|
2259
|
+
...options?.agent === undefined ? {} : { agent: options.agent }
|
|
2260
|
+
});
|
|
2261
|
+
return validateAgentInvoke("agent.invoke", raw);
|
|
2188
2262
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
throw new IpcResponseError(method, `ci finding "head_sha" must be a string or null`);
|
|
2263
|
+
askStream(input, opts) {
|
|
2264
|
+
return createAskStream(this.ipc, input, opts);
|
|
2192
2265
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
}
|
|
2214
|
-
function validatePreflightCheck(method, v, field, validateFinding) {
|
|
2215
|
-
const o = record(method, v);
|
|
2216
|
-
return {
|
|
2217
|
-
count: num(method, o, "count"),
|
|
2218
|
-
findings: arr(method, o["findings"]).map((f) => validateFinding(method, f)),
|
|
2219
|
-
gap: validatePreflightGap(method, o["gap"], `${field}.gap`)
|
|
2220
|
-
};
|
|
2221
|
-
}
|
|
2222
|
-
function validateDeployPreflight(method, v) {
|
|
2223
|
-
const o = record(method, v);
|
|
2224
|
-
const verdict = o["verdict"];
|
|
2225
|
-
if (verdict !== "ok" && verdict !== "warn") {
|
|
2226
|
-
throw new IpcResponseError(method, `"verdict" must be "ok" or "warn"`);
|
|
2266
|
+
subscribeHitl(handler) {
|
|
2267
|
+
const onBatch = (params) => {
|
|
2268
|
+
if (typeof params !== "object" || params === null)
|
|
2269
|
+
return;
|
|
2270
|
+
const p = params;
|
|
2271
|
+
if (typeof p["requestId"] !== "string" || typeof p["prompt"] !== "string")
|
|
2272
|
+
return;
|
|
2273
|
+
const req = typeof p["streamId"] === "string" ? {
|
|
2274
|
+
requestId: p["requestId"],
|
|
2275
|
+
prompt: p["prompt"],
|
|
2276
|
+
details: p["details"],
|
|
2277
|
+
streamId: p["streamId"]
|
|
2278
|
+
} : { requestId: p["requestId"], prompt: p["prompt"], details: p["details"] };
|
|
2279
|
+
handler(req);
|
|
2280
|
+
};
|
|
2281
|
+
this.ipc.onNotification("agent.hitlBatch", onBatch);
|
|
2282
|
+
return {
|
|
2283
|
+
dispose: () => {
|
|
2284
|
+
this.ipc.offNotification("agent.hitlBatch", onBatch);
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2227
2287
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2288
|
+
subscribeConnectorConfigChanged(handler) {
|
|
2289
|
+
const onChanged = (params) => {
|
|
2290
|
+
if (typeof params !== "object" || params === null)
|
|
2291
|
+
return;
|
|
2292
|
+
const p = params;
|
|
2293
|
+
if (typeof p["service"] !== "string" || typeof p["intervalMs"] !== "number" || typeof p["depth"] !== "string" || typeof p["enabled"] !== "boolean") {
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
handler({
|
|
2297
|
+
service: p["service"],
|
|
2298
|
+
intervalMs: p["intervalMs"],
|
|
2299
|
+
depth: p["depth"],
|
|
2300
|
+
enabled: p["enabled"]
|
|
2301
|
+
});
|
|
2302
|
+
};
|
|
2303
|
+
this.ipc.onNotification("connector.configChanged", onChanged);
|
|
2304
|
+
return {
|
|
2305
|
+
dispose: () => {
|
|
2306
|
+
this.ipc.offNotification("connector.configChanged", onChanged);
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2248
2309
|
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2310
|
+
subscribeAgentBrief(agent, handler) {
|
|
2311
|
+
const readyMethod = `${agent}.briefReady`;
|
|
2312
|
+
const errorMethod = `${agent}.briefError`;
|
|
2313
|
+
const onReady = (params) => {
|
|
2314
|
+
const ev = parseBriefReady(agent, params);
|
|
2315
|
+
if (ev !== null)
|
|
2316
|
+
handler(ev);
|
|
2317
|
+
};
|
|
2318
|
+
const onError = (params) => {
|
|
2319
|
+
const ev = parseBriefError(params);
|
|
2320
|
+
if (ev !== null)
|
|
2321
|
+
handler(ev);
|
|
2322
|
+
};
|
|
2323
|
+
this.ipc.onNotification(readyMethod, onReady);
|
|
2324
|
+
this.ipc.onNotification(errorMethod, onError);
|
|
2325
|
+
return {
|
|
2326
|
+
dispose: () => {
|
|
2327
|
+
this.ipc.offNotification(readyMethod, onReady);
|
|
2328
|
+
this.ipc.offNotification(errorMethod, onError);
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2252
2331
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2332
|
+
async runAgent(agent, params, opts) {
|
|
2333
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_AGENT_TIMEOUT_MS;
|
|
2334
|
+
const buffered = [];
|
|
2335
|
+
let sessionId = null;
|
|
2336
|
+
let deliver = null;
|
|
2337
|
+
const sub = this.subscribeAgentBrief(agent, (ev) => {
|
|
2338
|
+
if (sessionId === null) {
|
|
2339
|
+
buffered.push(ev);
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
if (ev.sessionId === sessionId)
|
|
2343
|
+
deliver?.(ev);
|
|
2344
|
+
});
|
|
2345
|
+
let timer;
|
|
2346
|
+
try {
|
|
2347
|
+
const method = `agents.${agent}`;
|
|
2348
|
+
const raw = await this.ipc.call(method, params);
|
|
2349
|
+
const sid = validateAgentSession(method, raw).sessionId;
|
|
2350
|
+
sessionId = sid;
|
|
2351
|
+
const ev = await new Promise((resolve, reject) => {
|
|
2352
|
+
deliver = resolve;
|
|
2353
|
+
const early = buffered.find((b) => b.sessionId === sid);
|
|
2354
|
+
if (early !== undefined) {
|
|
2355
|
+
resolve(early);
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
timer = setTimeout(() => {
|
|
2359
|
+
reject(new AgentTimeoutError(agent, sid, timeoutMs));
|
|
2360
|
+
}, timeoutMs);
|
|
2361
|
+
});
|
|
2362
|
+
if (!ev.ok)
|
|
2363
|
+
throw new AgentBriefError(agent, ev.sessionId, ev.error);
|
|
2364
|
+
return ev.findings;
|
|
2365
|
+
} finally {
|
|
2366
|
+
if (timer !== undefined)
|
|
2367
|
+
clearTimeout(timer);
|
|
2368
|
+
sub.dispose();
|
|
2369
|
+
}
|
|
2270
2370
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
function validateConnectorSyncStatusList(method, v) {
|
|
2274
|
-
return arr(method, v).map((r) => validateConnectorSyncStatus(method, r));
|
|
2275
|
-
}
|
|
2276
|
-
function validateConnectorSyncTelemetry(method, v) {
|
|
2277
|
-
const o = record(method, v);
|
|
2278
|
-
return {
|
|
2279
|
-
startedAt: num(method, o, "startedAt"),
|
|
2280
|
-
durationMs: num(method, o, "durationMs"),
|
|
2281
|
-
itemsUpserted: num(method, o, "itemsUpserted"),
|
|
2282
|
-
itemsDeleted: num(method, o, "itemsDeleted"),
|
|
2283
|
-
bytesTransferred: nullableNum(method, o, "bytesTransferred"),
|
|
2284
|
-
hadMore: bool(method, o, "hadMore"),
|
|
2285
|
-
errorMsg: nullableStr(method, o, "errorMsg")
|
|
2286
|
-
};
|
|
2287
|
-
}
|
|
2288
|
-
function validateConnectorStatusResult(method, v) {
|
|
2289
|
-
const base = validateConnectorSyncStatus(method, v);
|
|
2290
|
-
const o = record(method, v);
|
|
2291
|
-
if (o["telemetry"] === undefined)
|
|
2292
|
-
return base;
|
|
2293
|
-
return {
|
|
2294
|
-
...base,
|
|
2295
|
-
telemetry: arr(method, o["telemetry"]).map((t) => validateConnectorSyncTelemetry(method, t))
|
|
2296
|
-
};
|
|
2297
|
-
}
|
|
2298
|
-
function validateConnectorHealthHistoryEntry(method, v) {
|
|
2299
|
-
const o = record(method, v);
|
|
2300
|
-
return {
|
|
2301
|
-
id: num(method, o, "id"),
|
|
2302
|
-
connectorId: str(method, o, "connectorId"),
|
|
2303
|
-
fromState: nullableStr(method, o, "fromState"),
|
|
2304
|
-
toState: str(method, o, "toState"),
|
|
2305
|
-
reason: nullableStr(method, o, "reason"),
|
|
2306
|
-
occurredAtMs: num(method, o, "occurredAtMs")
|
|
2307
|
-
};
|
|
2308
|
-
}
|
|
2309
|
-
function validateConnectorHealthHistory(method, v) {
|
|
2310
|
-
return arr(method, v).map((r) => validateConnectorHealthHistoryEntry(method, r));
|
|
2311
|
-
}
|
|
2312
|
-
function validateConnectorSetConfig(method, v) {
|
|
2313
|
-
const o = record(method, v);
|
|
2314
|
-
return {
|
|
2315
|
-
service: str(method, o, "service"),
|
|
2316
|
-
intervalMs: nullableNum(method, o, "intervalMs"),
|
|
2317
|
-
depth: nullableStr(method, o, "depth"),
|
|
2318
|
-
enabled: nullableBool(method, o, "enabled")
|
|
2319
|
-
};
|
|
2320
|
-
}
|
|
2321
|
-
function validateConnectorReindex(method, v) {
|
|
2322
|
-
const o = record(method, v);
|
|
2323
|
-
const depth = o["depth"];
|
|
2324
|
-
if (typeof depth !== "string" || !CONNECTOR_DEPTH_VALUES.has(depth)) {
|
|
2325
|
-
throw new IpcResponseError(method, `"depth" must be "metadata_only", "summary", or "full"`);
|
|
2371
|
+
agentsExpert(p, o) {
|
|
2372
|
+
return this.runAgent("expert", p, o);
|
|
2326
2373
|
}
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
throw new IpcResponseError(method, `"mode" must be "shallow", "deepen", or "same"`);
|
|
2374
|
+
agentsImpact(p, o) {
|
|
2375
|
+
return this.runAgent("impact", p, o);
|
|
2330
2376
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
depth,
|
|
2334
|
-
mode
|
|
2335
|
-
};
|
|
2336
|
-
}
|
|
2337
|
-
function validateConnectorAuth(method, v) {
|
|
2338
|
-
const o = record(method, v);
|
|
2339
|
-
if (!bool(method, o, "ok")) {
|
|
2340
|
-
throw new IpcResponseError(method, `"ok" must be true`);
|
|
2377
|
+
agentsCatchup(p, o) {
|
|
2378
|
+
return this.runAgent("catchup", p ?? {}, o);
|
|
2341
2379
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
throw new IpcResponseError(method, `"scopesGranted" must contain only strings`);
|
|
2345
|
-
}
|
|
2346
|
-
return s;
|
|
2347
|
-
});
|
|
2348
|
-
return { ok: true, serviceId: str(method, o, "serviceId"), scopesGranted };
|
|
2349
|
-
}
|
|
2350
|
-
function validateGatedOrElse(method, v, validateSuccess) {
|
|
2351
|
-
const o = record(method, v);
|
|
2352
|
-
if (o["status"] === "rejected") {
|
|
2353
|
-
return { status: "rejected", reason: str(method, o, "reason") };
|
|
2380
|
+
agentsGhost(p, o) {
|
|
2381
|
+
return this.runAgent("ghost", p, o);
|
|
2354
2382
|
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
return
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
}
|
|
2374
|
-
return k;
|
|
2383
|
+
agentsConflicts(p, o) {
|
|
2384
|
+
return this.runAgent("conflicts", p, o);
|
|
2385
|
+
}
|
|
2386
|
+
agentsHuddle(p, o) {
|
|
2387
|
+
return this.runAgent("huddle", p ?? {}, o);
|
|
2388
|
+
}
|
|
2389
|
+
agentsJanitor(p, o) {
|
|
2390
|
+
return this.runAgent("janitor", p, o);
|
|
2391
|
+
}
|
|
2392
|
+
agentsPreflight(p, o) {
|
|
2393
|
+
return this.runAgent("preflight", p, o);
|
|
2394
|
+
}
|
|
2395
|
+
agentsWhy(p, o) {
|
|
2396
|
+
return this.runAgent("why", p, o);
|
|
2397
|
+
}
|
|
2398
|
+
async agentsWhyPeek(p) {
|
|
2399
|
+
const raw = await this.ipc.call("agents.whyPeek", {
|
|
2400
|
+
ref: p.ref,
|
|
2401
|
+
...p.line === undefined ? {} : { line: p.line }
|
|
2375
2402
|
});
|
|
2376
|
-
return
|
|
2377
|
-
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
return
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
}
|
|
2494
|
-
queue.push(ev);
|
|
2495
|
-
};
|
|
2496
|
-
const finish = () => {
|
|
2497
|
-
if (done)
|
|
2498
|
-
return;
|
|
2499
|
-
done = true;
|
|
2500
|
-
detach?.();
|
|
2501
|
-
detach = undefined;
|
|
2502
|
-
let w = waiters.shift();
|
|
2503
|
-
while (w !== undefined) {
|
|
2504
|
-
w.resolve({ value: undefined, done: true });
|
|
2505
|
-
w = waiters.shift();
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2508
|
-
const onChunk = (p) => {
|
|
2509
|
-
if (typeof p !== "object" || p === null)
|
|
2510
|
-
return;
|
|
2511
|
-
const text = p.text;
|
|
2512
|
-
if (typeof text === "string")
|
|
2513
|
-
push({ type: "chunk", text });
|
|
2514
|
-
};
|
|
2515
|
-
ipc.onNotification("agent.chunk", onChunk);
|
|
2516
|
-
detach = () => ipc.offNotification("agent.chunk", onChunk);
|
|
2517
|
-
const result = (async () => {
|
|
2518
|
-
try {
|
|
2519
|
-
const raw = await ipc.call("workflow.run", {
|
|
2520
|
-
name: params.name,
|
|
2521
|
-
triggeredBy: params.triggeredBy,
|
|
2522
|
-
dryRun: params.dryRun,
|
|
2523
|
-
stream: true,
|
|
2524
|
-
sessionId: params.sessionId,
|
|
2525
|
-
agent: params.agent,
|
|
2526
|
-
paramsOverride: params.paramsOverride
|
|
2527
|
-
});
|
|
2528
|
-
return validate("workflow.run", raw);
|
|
2529
|
-
} finally {
|
|
2530
|
-
detach?.();
|
|
2531
|
-
detach = undefined;
|
|
2532
|
-
}
|
|
2533
|
-
})();
|
|
2534
|
-
result.then((value) => {
|
|
2535
|
-
push({ type: "done", result: value });
|
|
2536
|
-
finish();
|
|
2537
|
-
}, (err) => {
|
|
2538
|
-
push({ type: "error", message: err instanceof Error ? err.message : String(err) });
|
|
2539
|
-
finish();
|
|
2540
|
-
});
|
|
2541
|
-
return {
|
|
2542
|
-
result,
|
|
2543
|
-
[Symbol.asyncIterator]() {
|
|
2544
|
-
return {
|
|
2545
|
-
next() {
|
|
2546
|
-
const ev = queue.shift();
|
|
2547
|
-
if (ev !== undefined)
|
|
2548
|
-
return Promise.resolve({ value: ev, done: false });
|
|
2549
|
-
if (done) {
|
|
2550
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
2551
|
-
}
|
|
2552
|
-
return new Promise((resolve, reject) => {
|
|
2553
|
-
waiters.push({ resolve, reject });
|
|
2554
|
-
});
|
|
2555
|
-
},
|
|
2556
|
-
return() {
|
|
2557
|
-
finish();
|
|
2558
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
2559
|
-
}
|
|
2560
|
-
};
|
|
2561
|
-
}
|
|
2562
|
-
};
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
// src/nimbus-client.ts
|
|
2566
|
-
class NimbusClient {
|
|
2567
|
-
ipc;
|
|
2568
|
-
constructor(ipc) {
|
|
2569
|
-
this.ipc = ipc;
|
|
2403
|
+
return validateWhyPeek("agents.whyPeek", raw);
|
|
2404
|
+
}
|
|
2405
|
+
async getSessionTranscript(params) {
|
|
2406
|
+
const raw = await this.ipc.call("engine.getSessionTranscript", params);
|
|
2407
|
+
return validateSessionTranscript("engine.getSessionTranscript", raw);
|
|
2408
|
+
}
|
|
2409
|
+
async cancelStream(streamId) {
|
|
2410
|
+
const raw = await this.ipc.call("engine.cancelStream", { streamId });
|
|
2411
|
+
return validateOk("engine.cancelStream", raw);
|
|
2412
|
+
}
|
|
2413
|
+
async sessionAppend(params) {
|
|
2414
|
+
const raw = await this.ipc.call("session.append", {
|
|
2415
|
+
sessionId: params.sessionId,
|
|
2416
|
+
chunkText: params.chunkText,
|
|
2417
|
+
role: params.role
|
|
2418
|
+
});
|
|
2419
|
+
return validateOk("session.append", raw);
|
|
2420
|
+
}
|
|
2421
|
+
async sessionRecall(params) {
|
|
2422
|
+
const raw = await this.ipc.call("session.recall", {
|
|
2423
|
+
sessionId: params.sessionId,
|
|
2424
|
+
query: params.query,
|
|
2425
|
+
topK: params.topK
|
|
2426
|
+
});
|
|
2427
|
+
return validateSessionRecall("session.recall", raw);
|
|
2428
|
+
}
|
|
2429
|
+
async sessionList() {
|
|
2430
|
+
return validateSessionList("session.list", await this.ipc.call("session.list"));
|
|
2431
|
+
}
|
|
2432
|
+
async sessionClear(params = {}) {
|
|
2433
|
+
const raw = await this.ipc.call("session.clear", { sessionId: params.sessionId });
|
|
2434
|
+
return validateSessionClear("session.clear", raw);
|
|
2435
|
+
}
|
|
2436
|
+
async metricsDora(params) {
|
|
2437
|
+
const raw = await this.ipc.call("metrics.dora", {
|
|
2438
|
+
service: params.service,
|
|
2439
|
+
since: params.since
|
|
2440
|
+
});
|
|
2441
|
+
return validateDoraMetrics("metrics.dora", raw);
|
|
2442
|
+
}
|
|
2443
|
+
async deployPreflight(params) {
|
|
2444
|
+
const raw = await this.ipc.call("deploy.preflight", {
|
|
2445
|
+
service: params.service,
|
|
2446
|
+
target_ref: params.targetRef,
|
|
2447
|
+
max_findings: params.maxFindings
|
|
2448
|
+
});
|
|
2449
|
+
return validateDeployPreflight("deploy.preflight", raw);
|
|
2450
|
+
}
|
|
2451
|
+
async queryItems(params) {
|
|
2452
|
+
const raw = await this.ipc.call("index.queryItems", {
|
|
2453
|
+
services: params.services,
|
|
2454
|
+
types: params.types,
|
|
2455
|
+
sinceMs: params.sinceMs,
|
|
2456
|
+
untilMs: params.untilMs,
|
|
2457
|
+
limit: params.limit
|
|
2458
|
+
});
|
|
2459
|
+
return validateQueryItems("index.queryItems", raw);
|
|
2460
|
+
}
|
|
2461
|
+
async searchRanked(params = {}) {
|
|
2462
|
+
const raw = await this.ipc.call("index.searchRanked", {
|
|
2463
|
+
name: params.name,
|
|
2464
|
+
service: params.service,
|
|
2465
|
+
itemType: params.itemType,
|
|
2466
|
+
limit: params.limit,
|
|
2467
|
+
semantic: params.semantic,
|
|
2468
|
+
contextChunks: params.contextChunks
|
|
2469
|
+
});
|
|
2470
|
+
return validateRankedItems("index.searchRanked", raw);
|
|
2471
|
+
}
|
|
2472
|
+
async querySql(sql) {
|
|
2473
|
+
const raw = await this.ipc.call("index.querySql", { sql });
|
|
2474
|
+
return validateQuerySql("index.querySql", raw);
|
|
2475
|
+
}
|
|
2476
|
+
async auditList(limit) {
|
|
2477
|
+
const raw = await this.ipc.call("audit.list", { limit: limit ?? 50 });
|
|
2478
|
+
return validateAuditList("audit.list", raw);
|
|
2479
|
+
}
|
|
2480
|
+
async auditVerify(params = {}) {
|
|
2481
|
+
const raw = await this.ipc.call("audit.verify", { full: params.full });
|
|
2482
|
+
return validateAuditVerify("audit.verify", raw);
|
|
2483
|
+
}
|
|
2484
|
+
async auditGetSummary() {
|
|
2485
|
+
return validateAuditSummary("audit.getSummary", await this.ipc.call("audit.getSummary"));
|
|
2486
|
+
}
|
|
2487
|
+
async auditToolCalls(params = {}) {
|
|
2488
|
+
const raw = await this.ipc.call("audit.toolCalls", {
|
|
2489
|
+
since: params.since,
|
|
2490
|
+
until: params.until,
|
|
2491
|
+
limit: params.limit,
|
|
2492
|
+
sessionId: params.sessionId,
|
|
2493
|
+
toolId: params.toolId,
|
|
2494
|
+
status: params.status,
|
|
2495
|
+
cursor: params.cursor
|
|
2496
|
+
});
|
|
2497
|
+
return validateAuditToolCalls("audit.toolCalls", raw);
|
|
2498
|
+
}
|
|
2499
|
+
async egressHead() {
|
|
2500
|
+
return validateEgressHead("egress.head", await this.ipc.call("egress.head"));
|
|
2501
|
+
}
|
|
2502
|
+
async egressList(params = {}) {
|
|
2503
|
+
const raw = await this.ipc.call("egress.list", {
|
|
2504
|
+
since: params.since,
|
|
2505
|
+
until: params.until,
|
|
2506
|
+
limit: params.limit
|
|
2507
|
+
});
|
|
2508
|
+
return validateEgressList("egress.list", raw);
|
|
2509
|
+
}
|
|
2510
|
+
async egressVerify() {
|
|
2511
|
+
return validateEgressVerify("egress.verify", await this.ipc.call("egress.verify"));
|
|
2512
|
+
}
|
|
2513
|
+
async egressProveWindow(params = {}) {
|
|
2514
|
+
const raw = await this.ipc.call("egress.proveWindow", {
|
|
2515
|
+
since: params.since,
|
|
2516
|
+
until: params.until,
|
|
2517
|
+
sign: params.sign
|
|
2518
|
+
});
|
|
2519
|
+
return validateEgressProveWindow("egress.proveWindow", raw);
|
|
2570
2520
|
}
|
|
2571
|
-
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2521
|
+
async consentRespond(params) {
|
|
2522
|
+
const raw = await this.ipc.call("consent.respond", {
|
|
2523
|
+
requestId: params.requestId,
|
|
2524
|
+
approved: params.approved
|
|
2574
2525
|
});
|
|
2575
|
-
|
|
2576
|
-
return new NimbusClient(ipc);
|
|
2526
|
+
return validateOk("consent.respond", raw);
|
|
2577
2527
|
}
|
|
2578
|
-
async
|
|
2579
|
-
const raw = await this.ipc.call("
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2528
|
+
async gatewayPing(params = {}) {
|
|
2529
|
+
const raw = await this.ipc.call("gateway.ping", { includeDrift: params.includeDrift });
|
|
2530
|
+
return validateGatewayPing("gateway.ping", raw);
|
|
2531
|
+
}
|
|
2532
|
+
async diagGetVersion() {
|
|
2533
|
+
return validateDiagVersion("diag.getVersion", await this.ipc.call("diag.getVersion"));
|
|
2534
|
+
}
|
|
2535
|
+
async indexMetrics() {
|
|
2536
|
+
return validateIndexMetrics("index.metrics", await this.ipc.call("index.metrics"));
|
|
2537
|
+
}
|
|
2538
|
+
async diagSnapshot() {
|
|
2539
|
+
return validateDiagSnapshot("diag.snapshot", await this.ipc.call("diag.snapshot"));
|
|
2540
|
+
}
|
|
2541
|
+
async adminStatus() {
|
|
2542
|
+
return validateGatewayStatus("admin.status", await this.ipc.call("admin.status"));
|
|
2543
|
+
}
|
|
2544
|
+
async connectorListStatus(params = {}) {
|
|
2545
|
+
const raw = await this.ipc.call("connector.listStatus", { serviceId: params.serviceId });
|
|
2546
|
+
return validateConnectorSyncStatusList("connector.listStatus", raw);
|
|
2547
|
+
}
|
|
2548
|
+
async connectorStatus(params) {
|
|
2549
|
+
const raw = await this.ipc.call("connector.status", {
|
|
2550
|
+
serviceId: params.serviceId,
|
|
2551
|
+
includeStats: params.includeStats
|
|
2584
2552
|
});
|
|
2585
|
-
return
|
|
2553
|
+
return validateConnectorStatusResult("connector.status", raw);
|
|
2586
2554
|
}
|
|
2587
|
-
|
|
2588
|
-
|
|
2555
|
+
async connectorHealthHistory(params) {
|
|
2556
|
+
const raw = await this.ipc.call("connector.healthHistory", {
|
|
2557
|
+
service: params.service,
|
|
2558
|
+
limit: params.limit
|
|
2559
|
+
});
|
|
2560
|
+
return validateConnectorHealthHistory("connector.healthHistory", raw);
|
|
2589
2561
|
}
|
|
2590
|
-
|
|
2591
|
-
const
|
|
2592
|
-
|
|
2593
|
-
return;
|
|
2594
|
-
const p = params;
|
|
2595
|
-
if (typeof p["requestId"] !== "string" || typeof p["prompt"] !== "string")
|
|
2596
|
-
return;
|
|
2597
|
-
const req = typeof p["streamId"] === "string" ? {
|
|
2598
|
-
requestId: p["requestId"],
|
|
2599
|
-
prompt: p["prompt"],
|
|
2600
|
-
details: p["details"],
|
|
2601
|
-
streamId: p["streamId"]
|
|
2602
|
-
} : { requestId: p["requestId"], prompt: p["prompt"], details: p["details"] };
|
|
2603
|
-
handler(req);
|
|
2604
|
-
};
|
|
2605
|
-
this.ipc.onNotification("agent.hitlBatch", onBatch);
|
|
2606
|
-
return {
|
|
2607
|
-
dispose: () => {
|
|
2608
|
-
this.ipc.offNotification("agent.hitlBatch", onBatch);
|
|
2609
|
-
}
|
|
2610
|
-
};
|
|
2562
|
+
async connectorPause(params) {
|
|
2563
|
+
const raw = await this.ipc.call("connector.pause", { serviceId: params.serviceId });
|
|
2564
|
+
return validateOk("connector.pause", raw);
|
|
2611
2565
|
}
|
|
2612
|
-
|
|
2613
|
-
const
|
|
2614
|
-
|
|
2615
|
-
return;
|
|
2616
|
-
const p = params;
|
|
2617
|
-
if (typeof p["service"] !== "string" || typeof p["intervalMs"] !== "number" || typeof p["depth"] !== "string" || typeof p["enabled"] !== "boolean") {
|
|
2618
|
-
return;
|
|
2619
|
-
}
|
|
2620
|
-
handler({
|
|
2621
|
-
service: p["service"],
|
|
2622
|
-
intervalMs: p["intervalMs"],
|
|
2623
|
-
depth: p["depth"],
|
|
2624
|
-
enabled: p["enabled"]
|
|
2625
|
-
});
|
|
2626
|
-
};
|
|
2627
|
-
this.ipc.onNotification("connector.configChanged", onChanged);
|
|
2628
|
-
return {
|
|
2629
|
-
dispose: () => {
|
|
2630
|
-
this.ipc.offNotification("connector.configChanged", onChanged);
|
|
2631
|
-
}
|
|
2632
|
-
};
|
|
2566
|
+
async connectorResume(params) {
|
|
2567
|
+
const raw = await this.ipc.call("connector.resume", { serviceId: params.serviceId });
|
|
2568
|
+
return validateOk("connector.resume", raw);
|
|
2633
2569
|
}
|
|
2634
|
-
|
|
2635
|
-
const
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
handler(ev);
|
|
2641
|
-
};
|
|
2642
|
-
const onError = (params) => {
|
|
2643
|
-
const ev = parseBriefError(params);
|
|
2644
|
-
if (ev !== null)
|
|
2645
|
-
handler(ev);
|
|
2646
|
-
};
|
|
2647
|
-
this.ipc.onNotification(readyMethod, onReady);
|
|
2648
|
-
this.ipc.onNotification(errorMethod, onError);
|
|
2649
|
-
return {
|
|
2650
|
-
dispose: () => {
|
|
2651
|
-
this.ipc.offNotification(readyMethod, onReady);
|
|
2652
|
-
this.ipc.offNotification(errorMethod, onError);
|
|
2653
|
-
}
|
|
2654
|
-
};
|
|
2570
|
+
async connectorSetInterval(params) {
|
|
2571
|
+
const raw = await this.ipc.call("connector.setInterval", {
|
|
2572
|
+
serviceId: params.serviceId,
|
|
2573
|
+
intervalMs: params.intervalMs
|
|
2574
|
+
});
|
|
2575
|
+
return validateOk("connector.setInterval", raw);
|
|
2655
2576
|
}
|
|
2656
|
-
async
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2577
|
+
async connectorSetConfig(params) {
|
|
2578
|
+
const raw = await this.ipc.call("connector.setConfig", {
|
|
2579
|
+
serviceId: params.serviceId,
|
|
2580
|
+
intervalMs: params.intervalMs,
|
|
2581
|
+
depth: params.depth,
|
|
2582
|
+
enabled: params.enabled
|
|
2583
|
+
});
|
|
2584
|
+
return validateConnectorSetConfig("connector.setConfig", raw);
|
|
2585
|
+
}
|
|
2586
|
+
async connectorSync(params) {
|
|
2587
|
+
const raw = await this.ipc.call("connector.sync", {
|
|
2588
|
+
serviceId: params.serviceId,
|
|
2589
|
+
full: params.full
|
|
2590
|
+
});
|
|
2591
|
+
return validateOk("connector.sync", raw);
|
|
2592
|
+
}
|
|
2593
|
+
async connectorAuth(params) {
|
|
2594
|
+
const raw = await this.ipc.call("connector.auth", params);
|
|
2595
|
+
return validateConnectorAuth("connector.auth", raw);
|
|
2596
|
+
}
|
|
2597
|
+
async connectorAddMcp(params) {
|
|
2598
|
+
const raw = await this.ipc.call("connector.addMcp", {
|
|
2599
|
+
serviceId: params.serviceId,
|
|
2600
|
+
commandLine: params.commandLine
|
|
2601
|
+
});
|
|
2602
|
+
return validateConnectorAddMcp("connector.addMcp", raw);
|
|
2603
|
+
}
|
|
2604
|
+
async connectorRemove(params) {
|
|
2605
|
+
const raw = await this.ipc.call("connector.remove", {
|
|
2606
|
+
serviceId: params.serviceId,
|
|
2607
|
+
service: params.serviceId
|
|
2608
|
+
});
|
|
2609
|
+
return validateConnectorRemove("connector.remove", raw);
|
|
2610
|
+
}
|
|
2611
|
+
async connectorReindex(params) {
|
|
2612
|
+
const raw = await this.ipc.call("connector.reindex", {
|
|
2613
|
+
service: params.service,
|
|
2614
|
+
depth: params.depth
|
|
2615
|
+
});
|
|
2616
|
+
return validateConnectorReindex("connector.reindex", raw);
|
|
2617
|
+
}
|
|
2618
|
+
async workflowList() {
|
|
2619
|
+
return validateWorkflowList("workflow.list", await this.ipc.call("workflow.list"));
|
|
2620
|
+
}
|
|
2621
|
+
async workflowSave(params) {
|
|
2622
|
+
const raw = await this.ipc.call("workflow.save", {
|
|
2623
|
+
name: params.name,
|
|
2624
|
+
description: params.description,
|
|
2625
|
+
stepsJson: params.stepsJson
|
|
2626
|
+
});
|
|
2627
|
+
return validateWorkflowSave("workflow.save", raw);
|
|
2628
|
+
}
|
|
2629
|
+
async workflowDelete(params) {
|
|
2630
|
+
const raw = await this.ipc.call("workflow.delete", { name: params.name });
|
|
2631
|
+
return validateOk("workflow.delete", raw);
|
|
2632
|
+
}
|
|
2633
|
+
async workflowListRuns(params) {
|
|
2634
|
+
const raw = await this.ipc.call("workflow.listRuns", {
|
|
2635
|
+
workflowName: params.workflowName,
|
|
2636
|
+
limit: params.limit
|
|
2637
|
+
});
|
|
2638
|
+
return validateWorkflowListRuns("workflow.listRuns", raw);
|
|
2639
|
+
}
|
|
2640
|
+
async workflowRun(params) {
|
|
2641
|
+
const raw = await this.ipc.call("workflow.run", {
|
|
2642
|
+
name: params.name,
|
|
2643
|
+
triggeredBy: params.triggeredBy,
|
|
2644
|
+
dryRun: params.dryRun,
|
|
2645
|
+
stream: params.stream,
|
|
2646
|
+
sessionId: params.sessionId,
|
|
2647
|
+
agent: params.agent,
|
|
2648
|
+
paramsOverride: params.paramsOverride
|
|
2649
|
+
});
|
|
2650
|
+
return validateWorkflowRun("workflow.run", raw);
|
|
2651
|
+
}
|
|
2652
|
+
workflowRunStream(params) {
|
|
2653
|
+
return createWorkflowRunStream(this.ipc, params, validateWorkflowRun);
|
|
2654
|
+
}
|
|
2655
|
+
async close() {
|
|
2656
|
+
await this.ipc.disconnect();
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
// src/mock-client.ts
|
|
2661
|
+
class MockClient {
|
|
2662
|
+
fixtures;
|
|
2663
|
+
constructor(fixtures = {}) {
|
|
2664
|
+
this.fixtures = fixtures;
|
|
2665
|
+
}
|
|
2666
|
+
async agentInvoke(_input, _options) {
|
|
2667
|
+
return { reply: this.fixtures.reply ?? "[MockClient] agent.invoke" };
|
|
2668
|
+
}
|
|
2669
|
+
askStream(_input, _opts) {
|
|
2670
|
+
const tokens = this.fixtures.streamTokens ?? ["mock", " token"];
|
|
2671
|
+
const reply = this.fixtures.reply ?? tokens.join("");
|
|
2672
|
+
let i = 0;
|
|
2673
|
+
let cancelled = false;
|
|
2674
|
+
const handle = {
|
|
2675
|
+
streamId: "mock-stream",
|
|
2676
|
+
async cancel() {
|
|
2677
|
+
cancelled = true;
|
|
2678
|
+
},
|
|
2679
|
+
[Symbol.asyncIterator]() {
|
|
2680
|
+
return {
|
|
2681
|
+
async next() {
|
|
2682
|
+
if (cancelled)
|
|
2683
|
+
return { value: undefined, done: true };
|
|
2684
|
+
if (i < tokens.length) {
|
|
2685
|
+
const text = tokens[i];
|
|
2686
|
+
i += 1;
|
|
2687
|
+
return { value: { type: "token", text }, done: false };
|
|
2688
|
+
}
|
|
2689
|
+
if (i === tokens.length) {
|
|
2690
|
+
i += 1;
|
|
2691
|
+
return {
|
|
2692
|
+
value: { type: "done", reply, sessionId: "mock-session" },
|
|
2693
|
+
done: false
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
return { value: undefined, done: true };
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2665
2699
|
}
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
});
|
|
2669
|
-
let timer;
|
|
2670
|
-
try {
|
|
2671
|
-
const method = `agents.${agent}`;
|
|
2672
|
-
const raw = await this.ipc.call(method, params);
|
|
2673
|
-
const sid = validateAgentSession(method, raw).sessionId;
|
|
2674
|
-
sessionId = sid;
|
|
2675
|
-
const ev = await new Promise((resolve, reject) => {
|
|
2676
|
-
deliver = resolve;
|
|
2677
|
-
const early = buffered.find((b) => b.sessionId === sid);
|
|
2678
|
-
if (early !== undefined) {
|
|
2679
|
-
resolve(early);
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
timer = setTimeout(() => {
|
|
2683
|
-
reject(new AgentTimeoutError(agent, sid, timeoutMs));
|
|
2684
|
-
}, timeoutMs);
|
|
2685
|
-
});
|
|
2686
|
-
if (!ev.ok)
|
|
2687
|
-
throw new AgentBriefError(agent, ev.sessionId, ev.error);
|
|
2688
|
-
return ev.findings;
|
|
2689
|
-
} finally {
|
|
2690
|
-
if (timer !== undefined)
|
|
2691
|
-
clearTimeout(timer);
|
|
2692
|
-
sub.dispose();
|
|
2693
|
-
}
|
|
2700
|
+
};
|
|
2701
|
+
return handle;
|
|
2694
2702
|
}
|
|
2695
|
-
|
|
2696
|
-
return
|
|
2703
|
+
subscribeHitl(_handler) {
|
|
2704
|
+
return { dispose: () => {
|
|
2705
|
+
return;
|
|
2706
|
+
} };
|
|
2697
2707
|
}
|
|
2698
|
-
|
|
2699
|
-
return
|
|
2708
|
+
subscribeConnectorConfigChanged(_handler) {
|
|
2709
|
+
return { dispose: () => {
|
|
2710
|
+
return;
|
|
2711
|
+
} };
|
|
2700
2712
|
}
|
|
2701
|
-
|
|
2702
|
-
return
|
|
2713
|
+
subscribeAgentBrief(_agent, _handler) {
|
|
2714
|
+
return { dispose: () => {} };
|
|
2703
2715
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2716
|
+
brief(agent) {
|
|
2717
|
+
const fixture = this.fixtures.agentBriefs?.[agent];
|
|
2718
|
+
if (fixture === undefined) {
|
|
2719
|
+
return Promise.reject(new Error(`MockClient: no agentBriefs.${agent} fixture configured`));
|
|
2720
|
+
}
|
|
2721
|
+
return Promise.resolve(fixture);
|
|
2706
2722
|
}
|
|
2707
|
-
|
|
2708
|
-
return this.
|
|
2723
|
+
async agentsExpert(_p) {
|
|
2724
|
+
return this.brief("expert");
|
|
2709
2725
|
}
|
|
2710
|
-
|
|
2711
|
-
return this.
|
|
2726
|
+
async agentsImpact(_p) {
|
|
2727
|
+
return this.brief("impact");
|
|
2712
2728
|
}
|
|
2713
|
-
|
|
2714
|
-
return this.
|
|
2729
|
+
async agentsCatchup(_p) {
|
|
2730
|
+
return this.brief("catchup");
|
|
2715
2731
|
}
|
|
2716
|
-
|
|
2717
|
-
return this.
|
|
2732
|
+
async agentsGhost(_p) {
|
|
2733
|
+
return this.brief("ghost");
|
|
2718
2734
|
}
|
|
2719
|
-
|
|
2720
|
-
return this.
|
|
2735
|
+
async agentsConflicts(_p) {
|
|
2736
|
+
return this.brief("conflicts");
|
|
2721
2737
|
}
|
|
2722
|
-
async
|
|
2723
|
-
|
|
2724
|
-
ref: p.ref,
|
|
2725
|
-
...p.line === undefined ? {} : { line: p.line }
|
|
2726
|
-
});
|
|
2727
|
-
return validateWhyPeek("agents.whyPeek", raw);
|
|
2738
|
+
async agentsHuddle(_p) {
|
|
2739
|
+
return this.brief("huddle");
|
|
2728
2740
|
}
|
|
2729
|
-
async
|
|
2730
|
-
|
|
2731
|
-
return validateSessionTranscript("engine.getSessionTranscript", raw);
|
|
2741
|
+
async agentsJanitor(_p) {
|
|
2742
|
+
return this.brief("janitor");
|
|
2732
2743
|
}
|
|
2733
|
-
async
|
|
2734
|
-
|
|
2735
|
-
return validateOk("engine.cancelStream", raw);
|
|
2744
|
+
async agentsPreflight(_p) {
|
|
2745
|
+
return this.brief("preflight");
|
|
2736
2746
|
}
|
|
2737
|
-
async
|
|
2738
|
-
|
|
2739
|
-
sessionId: params.sessionId,
|
|
2740
|
-
chunkText: params.chunkText,
|
|
2741
|
-
role: params.role
|
|
2742
|
-
});
|
|
2743
|
-
return validateOk("session.append", raw);
|
|
2747
|
+
async agentsWhy(_p) {
|
|
2748
|
+
return this.brief("why");
|
|
2744
2749
|
}
|
|
2745
|
-
async
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
});
|
|
2751
|
-
return validateSessionRecall("session.recall", raw);
|
|
2750
|
+
async agentsWhyPeek(_p) {
|
|
2751
|
+
if (this.fixtures.whyPeek === undefined) {
|
|
2752
|
+
throw new Error("MockClient: no whyPeek fixture configured");
|
|
2753
|
+
}
|
|
2754
|
+
return this.fixtures.whyPeek;
|
|
2752
2755
|
}
|
|
2753
|
-
async
|
|
2754
|
-
return
|
|
2756
|
+
async getSessionTranscript(_params) {
|
|
2757
|
+
return { sessionId: "mock-session", turns: [], hasMore: false };
|
|
2755
2758
|
}
|
|
2756
|
-
async
|
|
2757
|
-
|
|
2758
|
-
return validateSessionClear("session.clear", raw);
|
|
2759
|
+
async cancelStream() {
|
|
2760
|
+
return { ok: true };
|
|
2759
2761
|
}
|
|
2760
|
-
async
|
|
2761
|
-
|
|
2762
|
-
service: params.service,
|
|
2763
|
-
since: params.since
|
|
2764
|
-
});
|
|
2765
|
-
return validateDoraMetrics("metrics.dora", raw);
|
|
2762
|
+
async sessionAppend(_params) {
|
|
2763
|
+
return { ok: true };
|
|
2766
2764
|
}
|
|
2767
|
-
async
|
|
2768
|
-
|
|
2769
|
-
service: params.service,
|
|
2770
|
-
target_ref: params.targetRef,
|
|
2771
|
-
max_findings: params.maxFindings
|
|
2772
|
-
});
|
|
2773
|
-
return validateDeployPreflight("deploy.preflight", raw);
|
|
2765
|
+
async sessionRecall(_params) {
|
|
2766
|
+
return this.fixtures.sessionRecall ?? { chunks: [] };
|
|
2774
2767
|
}
|
|
2775
|
-
async
|
|
2776
|
-
|
|
2777
|
-
services: params.services,
|
|
2778
|
-
types: params.types,
|
|
2779
|
-
sinceMs: params.sinceMs,
|
|
2780
|
-
untilMs: params.untilMs,
|
|
2781
|
-
limit: params.limit
|
|
2782
|
-
});
|
|
2783
|
-
return validateQueryItems("index.queryItems", raw);
|
|
2768
|
+
async sessionList() {
|
|
2769
|
+
return this.fixtures.sessionList ?? { sessions: [] };
|
|
2784
2770
|
}
|
|
2785
|
-
async
|
|
2786
|
-
|
|
2787
|
-
name: params.name,
|
|
2788
|
-
service: params.service,
|
|
2789
|
-
itemType: params.itemType,
|
|
2790
|
-
limit: params.limit,
|
|
2791
|
-
semantic: params.semantic,
|
|
2792
|
-
contextChunks: params.contextChunks
|
|
2793
|
-
});
|
|
2794
|
-
return validateRankedItems("index.searchRanked", raw);
|
|
2771
|
+
async sessionClear(_params) {
|
|
2772
|
+
return { ok: true, cleared: "all" };
|
|
2795
2773
|
}
|
|
2796
|
-
async
|
|
2797
|
-
const
|
|
2798
|
-
return
|
|
2774
|
+
async queryItems(_params) {
|
|
2775
|
+
const items = this.fixtures.items ?? [];
|
|
2776
|
+
return { items, meta: { limit: items.length, total: items.length } };
|
|
2799
2777
|
}
|
|
2800
|
-
async
|
|
2801
|
-
|
|
2802
|
-
return validateAuditList("audit.list", raw);
|
|
2778
|
+
async searchRanked(_params) {
|
|
2779
|
+
return this.fixtures.rankedItems ?? [];
|
|
2803
2780
|
}
|
|
2804
|
-
async
|
|
2805
|
-
|
|
2806
|
-
|
|
2781
|
+
async querySql(_sql) {
|
|
2782
|
+
return { rows: this.fixtures.sqlRows ?? [] };
|
|
2783
|
+
}
|
|
2784
|
+
async auditList(_limit) {
|
|
2785
|
+
return [];
|
|
2786
|
+
}
|
|
2787
|
+
async auditVerify(_params) {
|
|
2788
|
+
return this.fixtures.auditVerify ?? { ok: true, verifiedRows: 0, lastVerifiedId: 0 };
|
|
2807
2789
|
}
|
|
2808
2790
|
async auditGetSummary() {
|
|
2809
|
-
return
|
|
2791
|
+
return this.fixtures.auditSummary ?? { byOutcome: {}, byService: {}, total: 0 };
|
|
2810
2792
|
}
|
|
2811
|
-
async auditToolCalls(
|
|
2812
|
-
|
|
2813
|
-
since: params.since,
|
|
2814
|
-
until: params.until,
|
|
2815
|
-
limit: params.limit,
|
|
2816
|
-
sessionId: params.sessionId,
|
|
2817
|
-
toolId: params.toolId,
|
|
2818
|
-
status: params.status,
|
|
2819
|
-
cursor: params.cursor
|
|
2820
|
-
});
|
|
2821
|
-
return validateAuditToolCalls("audit.toolCalls", raw);
|
|
2793
|
+
async auditToolCalls(_params) {
|
|
2794
|
+
return this.fixtures.auditToolCalls ?? { toolCalls: [], hasMore: false, nextCursor: null };
|
|
2822
2795
|
}
|
|
2823
2796
|
async egressHead() {
|
|
2824
|
-
return
|
|
2797
|
+
return this.fixtures.egressHead ?? { head: "", count: 0 };
|
|
2825
2798
|
}
|
|
2826
|
-
async egressList(
|
|
2827
|
-
|
|
2828
|
-
since: params.since,
|
|
2829
|
-
until: params.until,
|
|
2830
|
-
limit: params.limit
|
|
2831
|
-
});
|
|
2832
|
-
return validateEgressList("egress.list", raw);
|
|
2799
|
+
async egressList(_params) {
|
|
2800
|
+
return { rows: this.fixtures.egressRows ?? [] };
|
|
2833
2801
|
}
|
|
2834
2802
|
async egressVerify() {
|
|
2835
|
-
return
|
|
2803
|
+
return this.fixtures.egressVerify ?? { ok: true, verifiedRows: 0 };
|
|
2836
2804
|
}
|
|
2837
|
-
async egressProveWindow(
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2805
|
+
async egressProveWindow(_params) {
|
|
2806
|
+
return this.fixtures.egressProveWindow ?? {
|
|
2807
|
+
rows: [],
|
|
2808
|
+
completeness: {
|
|
2809
|
+
coverage: NO_EGRESS_COVERAGE,
|
|
2810
|
+
outboundEgressEvents: 0,
|
|
2811
|
+
indeterminate: true
|
|
2812
|
+
},
|
|
2813
|
+
verify: { ok: true, verifiedRows: 0 }
|
|
2814
|
+
};
|
|
2844
2815
|
}
|
|
2845
|
-
async consentRespond(
|
|
2846
|
-
|
|
2847
|
-
requestId: params.requestId,
|
|
2848
|
-
approved: params.approved
|
|
2849
|
-
});
|
|
2850
|
-
return validateOk("consent.respond", raw);
|
|
2816
|
+
async consentRespond(_params) {
|
|
2817
|
+
return { ok: true };
|
|
2851
2818
|
}
|
|
2852
|
-
async gatewayPing(
|
|
2853
|
-
|
|
2854
|
-
|
|
2819
|
+
async gatewayPing(_params) {
|
|
2820
|
+
return this.fixtures.gatewayPing ?? {
|
|
2821
|
+
version: "mock",
|
|
2822
|
+
uptime: 0,
|
|
2823
|
+
agentLimits: { maxAgentDepth: 5, maxToolCallsPerSession: 50 }
|
|
2824
|
+
};
|
|
2855
2825
|
}
|
|
2856
2826
|
async diagGetVersion() {
|
|
2857
|
-
return
|
|
2827
|
+
return this.fixtures.diagVersion ?? { version: "mock", commit: null, buildId: null, uptimeMs: 0 };
|
|
2828
|
+
}
|
|
2829
|
+
defaultIndexMetrics() {
|
|
2830
|
+
return {
|
|
2831
|
+
itemCountByService: {},
|
|
2832
|
+
totalItems: 0,
|
|
2833
|
+
indexSizeBytes: 0,
|
|
2834
|
+
embeddingCoveragePercent: 0,
|
|
2835
|
+
lastSuccessfulSyncByConnector: {},
|
|
2836
|
+
queryLatencyP50Ms: 0,
|
|
2837
|
+
queryLatencyP95Ms: 0,
|
|
2838
|
+
queryLatencyP99Ms: 0
|
|
2839
|
+
};
|
|
2858
2840
|
}
|
|
2859
2841
|
async indexMetrics() {
|
|
2860
|
-
return
|
|
2842
|
+
return this.fixtures.indexMetrics ?? this.defaultIndexMetrics();
|
|
2861
2843
|
}
|
|
2862
2844
|
async diagSnapshot() {
|
|
2863
|
-
return
|
|
2845
|
+
return this.fixtures.diagSnapshot ?? {
|
|
2846
|
+
gateway: { version: "mock", uptimeMs: 0 },
|
|
2847
|
+
connectorHealth: [],
|
|
2848
|
+
index: this.defaultIndexMetrics(),
|
|
2849
|
+
hitl: { pendingConsentRequests: 0 },
|
|
2850
|
+
watchers: [],
|
|
2851
|
+
auditLogTail: [],
|
|
2852
|
+
extensions: { disabled_pre_t2: 0, signature_disabled_count: 0 },
|
|
2853
|
+
sandbox: {
|
|
2854
|
+
platform_capabilities: { network: "all_or_nothing", reason: null },
|
|
2855
|
+
linux_helper: null,
|
|
2856
|
+
stale_rules_count: 0
|
|
2857
|
+
}
|
|
2858
|
+
};
|
|
2864
2859
|
}
|
|
2865
2860
|
async adminStatus() {
|
|
2866
|
-
return
|
|
2861
|
+
return this.fixtures.adminStatus ?? {
|
|
2862
|
+
policy: { signatureValid: true, pendingRestart: false, source: "none" },
|
|
2863
|
+
peers: [],
|
|
2864
|
+
connectors: [],
|
|
2865
|
+
namespaces: [],
|
|
2866
|
+
audit: { chainLength: 0, lastHash: "", appendRate1h: 0 },
|
|
2867
|
+
hitl: { pendingApprovals: 0, pendingQuorum: 0 },
|
|
2868
|
+
identity: { operatorValid: true },
|
|
2869
|
+
syncFreshnessMs: 0
|
|
2870
|
+
};
|
|
2867
2871
|
}
|
|
2868
|
-
async
|
|
2869
|
-
|
|
2870
|
-
|
|
2872
|
+
async metricsDora(_params) {
|
|
2873
|
+
return this.fixtures.metricsDora ?? {
|
|
2874
|
+
service: "mock",
|
|
2875
|
+
since_ms: 0,
|
|
2876
|
+
computed_at: new Date(0).toISOString(),
|
|
2877
|
+
metrics: {
|
|
2878
|
+
deployment_frequency: {
|
|
2879
|
+
value: null,
|
|
2880
|
+
unit: "deploys_per_day",
|
|
2881
|
+
sample: 0,
|
|
2882
|
+
gap: "no_repos"
|
|
2883
|
+
},
|
|
2884
|
+
lead_time_for_changes: {
|
|
2885
|
+
value: null,
|
|
2886
|
+
unit: "seconds_median",
|
|
2887
|
+
sample: 0,
|
|
2888
|
+
gap: "no_repos"
|
|
2889
|
+
},
|
|
2890
|
+
change_failure_rate: { value: null, unit: "ratio", sample: 0, gap: "no_repos" },
|
|
2891
|
+
mttr: { value: null, unit: "seconds_median", sample: 0, gap: "no_repos" }
|
|
2892
|
+
}
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
async deployPreflight(_params) {
|
|
2896
|
+
return this.fixtures.deployPreflight ?? {
|
|
2897
|
+
service: "mock",
|
|
2898
|
+
target_ref: "main",
|
|
2899
|
+
computed_at: new Date(0).toISOString(),
|
|
2900
|
+
verdict: "ok",
|
|
2901
|
+
checks: {
|
|
2902
|
+
active_p1_incidents: { count: 0, findings: [], gap: "no_pagerduty_mapping" },
|
|
2903
|
+
failing_ci_runs: { count: 0, findings: [], gap: "no_repos" },
|
|
2904
|
+
merge_conflicts: { count: 0, findings: [], gap: "no_repos" }
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
async connectorListStatus(_params) {
|
|
2909
|
+
return this.fixtures.connectorSyncStatuses ?? [];
|
|
2910
|
+
}
|
|
2911
|
+
defaultConnectorStatus(serviceId) {
|
|
2912
|
+
return {
|
|
2913
|
+
serviceId,
|
|
2914
|
+
status: "ok",
|
|
2915
|
+
lastSyncAt: null,
|
|
2916
|
+
nextSyncAt: null,
|
|
2917
|
+
intervalMs: 0,
|
|
2918
|
+
itemCount: 0,
|
|
2919
|
+
lastError: null,
|
|
2920
|
+
consecutiveFailures: 0,
|
|
2921
|
+
depth: "metadata_only",
|
|
2922
|
+
enabled: true
|
|
2923
|
+
};
|
|
2871
2924
|
}
|
|
2872
2925
|
async connectorStatus(params) {
|
|
2873
|
-
|
|
2874
|
-
serviceId: params.serviceId,
|
|
2875
|
-
includeStats: params.includeStats
|
|
2876
|
-
});
|
|
2877
|
-
return validateConnectorStatusResult("connector.status", raw);
|
|
2926
|
+
return this.fixtures.connectorStatus ?? this.defaultConnectorStatus(params.serviceId);
|
|
2878
2927
|
}
|
|
2879
|
-
async connectorHealthHistory(
|
|
2880
|
-
|
|
2881
|
-
service: params.service,
|
|
2882
|
-
limit: params.limit
|
|
2883
|
-
});
|
|
2884
|
-
return validateConnectorHealthHistory("connector.healthHistory", raw);
|
|
2928
|
+
async connectorHealthHistory(_params) {
|
|
2929
|
+
return this.fixtures.connectorHealthHistory ?? [];
|
|
2885
2930
|
}
|
|
2886
|
-
async connectorPause(
|
|
2887
|
-
|
|
2888
|
-
return validateOk("connector.pause", raw);
|
|
2931
|
+
async connectorPause(_params) {
|
|
2932
|
+
return { ok: true };
|
|
2889
2933
|
}
|
|
2890
|
-
async connectorResume(
|
|
2891
|
-
|
|
2892
|
-
return validateOk("connector.resume", raw);
|
|
2934
|
+
async connectorResume(_params) {
|
|
2935
|
+
return { ok: true };
|
|
2893
2936
|
}
|
|
2894
|
-
async connectorSetInterval(
|
|
2895
|
-
|
|
2896
|
-
serviceId: params.serviceId,
|
|
2897
|
-
intervalMs: params.intervalMs
|
|
2898
|
-
});
|
|
2899
|
-
return validateOk("connector.setInterval", raw);
|
|
2937
|
+
async connectorSetInterval(_params) {
|
|
2938
|
+
return { ok: true };
|
|
2900
2939
|
}
|
|
2901
2940
|
async connectorSetConfig(params) {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
intervalMs: params.intervalMs,
|
|
2905
|
-
depth: params.depth,
|
|
2906
|
-
enabled: params.enabled
|
|
2907
|
-
}
|
|
2908
|
-
return validateConnectorSetConfig("connector.setConfig", raw);
|
|
2941
|
+
return this.fixtures.connectorSetConfig ?? {
|
|
2942
|
+
service: params.serviceId,
|
|
2943
|
+
intervalMs: params.intervalMs ?? null,
|
|
2944
|
+
depth: params.depth ?? null,
|
|
2945
|
+
enabled: params.enabled ?? null
|
|
2946
|
+
};
|
|
2909
2947
|
}
|
|
2910
|
-
async connectorSync(
|
|
2911
|
-
|
|
2912
|
-
serviceId: params.serviceId,
|
|
2913
|
-
full: params.full
|
|
2914
|
-
});
|
|
2915
|
-
return validateOk("connector.sync", raw);
|
|
2948
|
+
async connectorSync(_params) {
|
|
2949
|
+
return { ok: true };
|
|
2916
2950
|
}
|
|
2917
2951
|
async connectorAuth(params) {
|
|
2918
|
-
|
|
2919
|
-
return validateConnectorAuth("connector.auth", raw);
|
|
2952
|
+
return this.fixtures.connectorAuth ?? { ok: true, serviceId: params.serviceId, scopesGranted: [] };
|
|
2920
2953
|
}
|
|
2921
2954
|
async connectorAddMcp(params) {
|
|
2922
|
-
|
|
2923
|
-
serviceId: params.serviceId,
|
|
2924
|
-
commandLine: params.commandLine
|
|
2925
|
-
});
|
|
2926
|
-
return validateConnectorAddMcp("connector.addMcp", raw);
|
|
2955
|
+
return this.fixtures.connectorAddMcp ?? { ok: true, serviceId: params.serviceId };
|
|
2927
2956
|
}
|
|
2928
|
-
async connectorRemove(
|
|
2929
|
-
|
|
2930
|
-
serviceId: params.serviceId,
|
|
2931
|
-
service: params.serviceId
|
|
2932
|
-
});
|
|
2933
|
-
return validateConnectorRemove("connector.remove", raw);
|
|
2957
|
+
async connectorRemove(_params) {
|
|
2958
|
+
return this.fixtures.connectorRemove ?? { ok: true, itemsDeleted: 0, vaultKeysRemoved: [] };
|
|
2934
2959
|
}
|
|
2935
2960
|
async connectorReindex(params) {
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
depth: params.depth
|
|
2939
|
-
|
|
2940
|
-
|
|
2961
|
+
return this.fixtures.connectorReindex ?? {
|
|
2962
|
+
itemsAffected: 0,
|
|
2963
|
+
depth: params.depth ?? "metadata_only",
|
|
2964
|
+
mode: "shallow"
|
|
2965
|
+
};
|
|
2941
2966
|
}
|
|
2942
2967
|
async workflowList() {
|
|
2943
|
-
return
|
|
2968
|
+
return this.fixtures.workflowList ?? { workflows: [] };
|
|
2944
2969
|
}
|
|
2945
|
-
async workflowSave(
|
|
2946
|
-
|
|
2947
|
-
name: params.name,
|
|
2948
|
-
description: params.description,
|
|
2949
|
-
stepsJson: params.stepsJson
|
|
2950
|
-
});
|
|
2951
|
-
return validateWorkflowSave("workflow.save", raw);
|
|
2970
|
+
async workflowSave(_params) {
|
|
2971
|
+
return { id: "mock-workflow" };
|
|
2952
2972
|
}
|
|
2953
|
-
async workflowDelete(
|
|
2954
|
-
|
|
2955
|
-
return validateOk("workflow.delete", raw);
|
|
2973
|
+
async workflowDelete(_params) {
|
|
2974
|
+
return { ok: true };
|
|
2956
2975
|
}
|
|
2957
|
-
async workflowListRuns(
|
|
2958
|
-
|
|
2959
|
-
workflowName: params.workflowName,
|
|
2960
|
-
limit: params.limit
|
|
2961
|
-
});
|
|
2962
|
-
return validateWorkflowListRuns("workflow.listRuns", raw);
|
|
2976
|
+
async workflowListRuns(_params) {
|
|
2977
|
+
return this.fixtures.workflowListRuns ?? { runs: [] };
|
|
2963
2978
|
}
|
|
2964
2979
|
async workflowRun(params) {
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
sessionId: params.sessionId,
|
|
2971
|
-
agent: params.agent,
|
|
2972
|
-
paramsOverride: params.paramsOverride
|
|
2973
|
-
});
|
|
2974
|
-
return validateWorkflowRun("workflow.run", raw);
|
|
2980
|
+
return this.fixtures.workflowRun ?? {
|
|
2981
|
+
runId: "mock-run",
|
|
2982
|
+
dryRun: params.dryRun ?? false,
|
|
2983
|
+
stepResults: []
|
|
2984
|
+
};
|
|
2975
2985
|
}
|
|
2976
2986
|
workflowRunStream(params) {
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2987
|
+
const chunks = this.fixtures.workflowRunChunks ?? ["mock ", "workflow"];
|
|
2988
|
+
const value = this.fixtures.workflowRun ?? {
|
|
2989
|
+
runId: "mock-run",
|
|
2990
|
+
dryRun: params.dryRun ?? false,
|
|
2991
|
+
stepResults: []
|
|
2992
|
+
};
|
|
2993
|
+
let i = 0;
|
|
2994
|
+
return {
|
|
2995
|
+
result: Promise.resolve(value),
|
|
2996
|
+
[Symbol.asyncIterator]() {
|
|
2997
|
+
return {
|
|
2998
|
+
async next() {
|
|
2999
|
+
if (i < chunks.length) {
|
|
3000
|
+
const text = chunks[i];
|
|
3001
|
+
i += 1;
|
|
3002
|
+
return { value: { type: "chunk", text }, done: false };
|
|
3003
|
+
}
|
|
3004
|
+
if (i === chunks.length) {
|
|
3005
|
+
i += 1;
|
|
3006
|
+
return { value: { type: "done", result: value }, done: false };
|
|
3007
|
+
}
|
|
3008
|
+
return { value: undefined, done: true };
|
|
3009
|
+
}
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
};
|
|
2981
3013
|
}
|
|
3014
|
+
async close() {}
|
|
2982
3015
|
}
|
|
3016
|
+
var WHY_BRIEF_FIXTURE = {
|
|
3017
|
+
agentVersion: 1,
|
|
3018
|
+
generatedAt: 1,
|
|
3019
|
+
latencyMs: 5,
|
|
3020
|
+
gaps: [],
|
|
3021
|
+
kind: "why",
|
|
3022
|
+
query: { ref: "src/retry.ts", line: 42 },
|
|
3023
|
+
subject: { repoRoot: "/repo", filePath: "src/retry.ts", lineNo: 42, symbol: "retryBackoff" },
|
|
3024
|
+
findings: ["authorship", "pull_request", "ticket", "discussion", "driver", "downstream"].map((lane, i) => ({
|
|
3025
|
+
lane,
|
|
3026
|
+
title: `${lane} finding`,
|
|
3027
|
+
detail: `${lane} detail`,
|
|
3028
|
+
url: `https://x/${lane}`,
|
|
3029
|
+
occurredAt: 1700000000000 + i,
|
|
3030
|
+
entityId: `e${i}`
|
|
3031
|
+
}))
|
|
3032
|
+
};
|