@nimbus-dev/client 0.15.1 → 0.17.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 +1948 -1855
- 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/mock-client.d.ts +4 -1
- package/dist/mock-client.d.ts.map +1 -1
- package/dist/mock-client.js +20 -1
- package/dist/mock-client.js.map +1 -1
- package/dist/nimbus-client.d.ts +113 -7
- package/dist/nimbus-client.d.ts.map +1 -1
- package/dist/nimbus-client.js +61 -6
- package/dist/nimbus-client.js.map +1 -1
- package/dist/stream-events.d.ts +25 -4
- package/dist/stream-events.d.ts.map +1 -1
- package/dist/validate.d.ts +4 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +61 -6
- package/dist/validate.js.map +1 -1
- package/dist/workflow-stream.d.ts +11 -14
- package/dist/workflow-stream.d.ts.map +1 -1
- package/dist/workflow-stream.js +38 -14
- package/dist/workflow-stream.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) {
|
|
@@ -981,2002 +995,2081 @@ 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
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
}
|
|
1969
|
-
const
|
|
1970
|
-
if (
|
|
1971
|
-
|
|
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`);
|
|
2088
|
+
const result = {
|
|
2089
|
+
runId: str(method, o, "runId"),
|
|
2090
|
+
dryRun: bool(method, o, "dryRun"),
|
|
2091
|
+
stepResults: arr(method, o["stepResults"]).map((s) => validateWorkflowStepResult(method, s))
|
|
2092
|
+
};
|
|
2093
|
+
const status = o["status"];
|
|
2094
|
+
if (status !== undefined) {
|
|
2095
|
+
if (typeof status !== "string") {
|
|
2096
|
+
throw new IpcResponseError(method, `"status" must be a string when present`);
|
|
1980
2097
|
}
|
|
1981
|
-
|
|
2098
|
+
result.status = status;
|
|
1982
2099
|
}
|
|
1983
|
-
return
|
|
1984
|
-
platform_capabilities: { network, reason: capsReason },
|
|
1985
|
-
linux_helper: linuxHelper,
|
|
1986
|
-
stale_rules_count: num(method, o, "stale_rules_count")
|
|
1987
|
-
};
|
|
2100
|
+
return result;
|
|
1988
2101
|
}
|
|
1989
|
-
function
|
|
2102
|
+
function validateWorkflowCancel(method, v) {
|
|
1990
2103
|
const o = record(method, v);
|
|
1991
|
-
|
|
1992
|
-
const hitl = record(method, o["hitl"]);
|
|
1993
|
-
const extensionsRaw = record(method, o["extensions"]);
|
|
1994
|
-
const extensions = {
|
|
1995
|
-
disabled_pre_t2: num(method, extensionsRaw, "disabled_pre_t2"),
|
|
1996
|
-
signature_disabled_count: num(method, extensionsRaw, "signature_disabled_count")
|
|
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")
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
2006
|
-
return {
|
|
2007
|
-
gateway: {
|
|
2008
|
-
version: str(method, gateway, "version"),
|
|
2009
|
-
uptimeMs: num(method, gateway, "uptimeMs")
|
|
2010
|
-
},
|
|
2011
|
-
connectorHealth: arr(method, o["connectorHealth"]).map((h) => validateConnectorHealthEntry(method, h)),
|
|
2012
|
-
index: validateIndexMetrics(method, o["index"]),
|
|
2013
|
-
hitl: { pendingConsentRequests: num(method, hitl, "pendingConsentRequests") },
|
|
2014
|
-
watchers: arr(method, o["watchers"]).map((w) => validateWatcherSummary(method, w)),
|
|
2015
|
-
auditLogTail: arr(method, o["auditLogTail"]),
|
|
2016
|
-
extensions,
|
|
2017
|
-
sandbox: validateSandboxDiag(method, o["sandbox"])
|
|
2018
|
-
};
|
|
2104
|
+
return { cancelled: bool(method, o, "cancelled") };
|
|
2019
2105
|
}
|
|
2020
|
-
function
|
|
2106
|
+
function validateWhyPeek(method, v) {
|
|
2021
2107
|
const o = record(method, v);
|
|
2022
|
-
const
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
};
|
|
2031
|
-
const
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
health: str(method, o, "health")
|
|
2108
|
+
const subjRaw = o["subject"];
|
|
2109
|
+
const subject = subjRaw === null || subjRaw === undefined ? null : (() => {
|
|
2110
|
+
const s = record(method, subjRaw);
|
|
2111
|
+
return {
|
|
2112
|
+
repoRoot: str(method, s, "repoRoot"),
|
|
2113
|
+
filePath: str(method, s, "filePath"),
|
|
2114
|
+
lineNo: num(method, s, "lineNo")
|
|
2115
|
+
};
|
|
2116
|
+
})();
|
|
2117
|
+
const prRaw = o["pr"];
|
|
2118
|
+
const pr = prRaw === null || prRaw === undefined ? null : (() => {
|
|
2119
|
+
const p = record(method, prRaw);
|
|
2120
|
+
return {
|
|
2121
|
+
number: nullableNum(method, p, "number"),
|
|
2122
|
+
title: str(method, p, "title"),
|
|
2123
|
+
url: nullableStr(method, p, "url")
|
|
2124
|
+
};
|
|
2125
|
+
})();
|
|
2126
|
+
const tRaw = o["ticket"];
|
|
2127
|
+
const ticket = tRaw === null || tRaw === undefined ? null : (() => {
|
|
2128
|
+
const t = record(method, tRaw);
|
|
2129
|
+
return {
|
|
2130
|
+
key: str(method, t, "key"),
|
|
2131
|
+
title: str(method, t, "title"),
|
|
2132
|
+
url: nullableStr(method, t, "url")
|
|
2133
|
+
};
|
|
2134
|
+
})();
|
|
2135
|
+
return {
|
|
2136
|
+
subject,
|
|
2137
|
+
author: nullableStr(method, o, "author"),
|
|
2138
|
+
authorEmail: nullableStr(method, o, "authorEmail"),
|
|
2139
|
+
commitSha: nullableStr(method, o, "commitSha"),
|
|
2140
|
+
committedAt: nullableNum(method, o, "committedAt"),
|
|
2141
|
+
commitSubject: nullableStr(method, o, "commitSubject"),
|
|
2142
|
+
pr,
|
|
2143
|
+
ticket,
|
|
2144
|
+
hasMore: bool(method, o, "hasMore")
|
|
2060
2145
|
};
|
|
2061
|
-
const lastSyncMs = optNum(o, "lastSyncMs");
|
|
2062
|
-
if (lastSyncMs !== undefined)
|
|
2063
|
-
status.lastSyncMs = lastSyncMs;
|
|
2064
|
-
return status;
|
|
2065
2146
|
}
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2147
|
+
|
|
2148
|
+
// src/workflow-stream.ts
|
|
2149
|
+
var import_node_crypto2 = require("node:crypto");
|
|
2150
|
+
function createWorkflowRunStream(ipc, params, validate) {
|
|
2151
|
+
const queue = [];
|
|
2152
|
+
const waiters = [];
|
|
2153
|
+
let done = false;
|
|
2154
|
+
let detach;
|
|
2155
|
+
const streamId = params.streamId ?? import_node_crypto2.randomUUID();
|
|
2156
|
+
const push = (ev) => {
|
|
2157
|
+
if (done)
|
|
2158
|
+
return;
|
|
2159
|
+
const w = waiters.shift();
|
|
2160
|
+
if (w !== undefined) {
|
|
2161
|
+
w.resolve({ value: ev, done: false });
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
queue.push(ev);
|
|
2071
2165
|
};
|
|
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")
|
|
2166
|
+
const finish = () => {
|
|
2167
|
+
if (done)
|
|
2168
|
+
return;
|
|
2169
|
+
done = true;
|
|
2170
|
+
detach?.();
|
|
2171
|
+
detach = undefined;
|
|
2172
|
+
let w = waiters.shift();
|
|
2173
|
+
while (w !== undefined) {
|
|
2174
|
+
w.resolve({ value: undefined, done: true });
|
|
2175
|
+
w = waiters.shift();
|
|
2176
|
+
}
|
|
2102
2177
|
};
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
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`)
|
|
2178
|
+
const onChunk = (p) => {
|
|
2179
|
+
if (typeof p !== "object" || p === null)
|
|
2180
|
+
return;
|
|
2181
|
+
const tag = p.streamId;
|
|
2182
|
+
if (typeof tag === "string" && tag !== streamId)
|
|
2183
|
+
return;
|
|
2184
|
+
const text = p.text;
|
|
2185
|
+
if (typeof text === "string")
|
|
2186
|
+
push({ type: "chunk", text });
|
|
2130
2187
|
};
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
const
|
|
2134
|
-
|
|
2188
|
+
ipc.onNotification("agent.chunk", onChunk);
|
|
2189
|
+
detach = () => ipc.offNotification("agent.chunk", onChunk);
|
|
2190
|
+
const result = (async () => {
|
|
2191
|
+
try {
|
|
2192
|
+
const raw = await ipc.call("workflow.run", {
|
|
2193
|
+
name: params.name,
|
|
2194
|
+
triggeredBy: params.triggeredBy,
|
|
2195
|
+
dryRun: params.dryRun,
|
|
2196
|
+
stream: true,
|
|
2197
|
+
sessionId: params.sessionId,
|
|
2198
|
+
agent: params.agent,
|
|
2199
|
+
paramsOverride: params.paramsOverride,
|
|
2200
|
+
streamId
|
|
2201
|
+
});
|
|
2202
|
+
return validate("workflow.run", raw);
|
|
2203
|
+
} finally {
|
|
2204
|
+
detach?.();
|
|
2205
|
+
detach = undefined;
|
|
2206
|
+
}
|
|
2207
|
+
})();
|
|
2208
|
+
result.then((value) => {
|
|
2209
|
+
push({ type: "done", result: value });
|
|
2210
|
+
finish();
|
|
2211
|
+
}, (err) => {
|
|
2212
|
+
push({ type: "error", message: err instanceof Error ? err.message : String(err) });
|
|
2213
|
+
finish();
|
|
2214
|
+
});
|
|
2135
2215
|
return {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2216
|
+
result,
|
|
2217
|
+
streamId,
|
|
2218
|
+
async cancel() {
|
|
2219
|
+
try {
|
|
2220
|
+
const raw = await ipc.call("workflow.cancel", { streamId });
|
|
2221
|
+
const flag = raw?.cancelled;
|
|
2222
|
+
return { cancelled: flag === true };
|
|
2223
|
+
} catch {
|
|
2224
|
+
return { cancelled: false };
|
|
2225
|
+
}
|
|
2226
|
+
},
|
|
2227
|
+
[Symbol.asyncIterator]() {
|
|
2228
|
+
return {
|
|
2229
|
+
next() {
|
|
2230
|
+
const ev = queue.shift();
|
|
2231
|
+
if (ev !== undefined)
|
|
2232
|
+
return Promise.resolve({ value: ev, done: false });
|
|
2233
|
+
if (done) {
|
|
2234
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
2235
|
+
}
|
|
2236
|
+
return new Promise((resolve, reject) => {
|
|
2237
|
+
waiters.push({ resolve, reject });
|
|
2238
|
+
});
|
|
2239
|
+
},
|
|
2240
|
+
return() {
|
|
2241
|
+
finish();
|
|
2242
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2144
2245
|
}
|
|
2145
2246
|
};
|
|
2146
2247
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
"
|
|
2151
|
-
"
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2248
|
+
|
|
2249
|
+
// src/nimbus-client.ts
|
|
2250
|
+
var EGRESS_COVERAGE_CLASSES = [
|
|
2251
|
+
"http",
|
|
2252
|
+
"mcp",
|
|
2253
|
+
"model",
|
|
2254
|
+
"peer",
|
|
2255
|
+
"session",
|
|
2256
|
+
"sync",
|
|
2257
|
+
"task"
|
|
2258
|
+
];
|
|
2259
|
+
var EGRESS_GRANULARITIES = ["none", "per-run", "per-call"];
|
|
2260
|
+
var NO_EGRESS_COVERAGE = Object.freeze({
|
|
2261
|
+
http: "none",
|
|
2262
|
+
mcp: "none",
|
|
2263
|
+
model: "none",
|
|
2264
|
+
peer: "none",
|
|
2265
|
+
session: "none",
|
|
2266
|
+
sync: "none",
|
|
2267
|
+
task: "none"
|
|
2268
|
+
});
|
|
2269
|
+
|
|
2270
|
+
class NimbusClient {
|
|
2271
|
+
ipc;
|
|
2272
|
+
constructor(ipc) {
|
|
2273
|
+
this.ipc = ipc;
|
|
2164
2274
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
throw new IpcResponseError(method, `incident finding "status" must be "triggered" or "acknowledged"`);
|
|
2275
|
+
static async open(opts) {
|
|
2276
|
+
const ipc = new IPCClient(opts.socketPath, {
|
|
2277
|
+
...opts.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: opts.requestTimeoutMs }
|
|
2278
|
+
});
|
|
2279
|
+
await ipc.connect();
|
|
2280
|
+
return new NimbusClient(ipc);
|
|
2172
2281
|
}
|
|
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"`);
|
|
2282
|
+
async agentInvoke(input, options) {
|
|
2283
|
+
const raw = await this.ipc.call("agent.invoke", {
|
|
2284
|
+
input,
|
|
2285
|
+
stream: options?.stream ?? false,
|
|
2286
|
+
...options?.sessionId === undefined ? {} : { sessionId: options.sessionId },
|
|
2287
|
+
...options?.agent === undefined ? {} : { agent: options.agent }
|
|
2288
|
+
});
|
|
2289
|
+
return validateAgentInvoke("agent.invoke", raw);
|
|
2188
2290
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
throw new IpcResponseError(method, `ci finding "head_sha" must be a string or null`);
|
|
2291
|
+
askStream(input, opts) {
|
|
2292
|
+
return createAskStream(this.ipc, input, opts);
|
|
2192
2293
|
}
|
|
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"`);
|
|
2294
|
+
subscribeHitl(handler) {
|
|
2295
|
+
const onBatch = (params) => {
|
|
2296
|
+
if (typeof params !== "object" || params === null)
|
|
2297
|
+
return;
|
|
2298
|
+
const p = params;
|
|
2299
|
+
if (typeof p["requestId"] !== "string" || typeof p["prompt"] !== "string")
|
|
2300
|
+
return;
|
|
2301
|
+
const req = typeof p["streamId"] === "string" ? {
|
|
2302
|
+
requestId: p["requestId"],
|
|
2303
|
+
prompt: p["prompt"],
|
|
2304
|
+
details: p["details"],
|
|
2305
|
+
streamId: p["streamId"]
|
|
2306
|
+
} : { requestId: p["requestId"], prompt: p["prompt"], details: p["details"] };
|
|
2307
|
+
handler(req);
|
|
2308
|
+
};
|
|
2309
|
+
this.ipc.onNotification("agent.hitlBatch", onBatch);
|
|
2310
|
+
return {
|
|
2311
|
+
dispose: () => {
|
|
2312
|
+
this.ipc.offNotification("agent.hitlBatch", onBatch);
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2227
2315
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2316
|
+
subscribeConnectorConfigChanged(handler) {
|
|
2317
|
+
const onChanged = (params) => {
|
|
2318
|
+
if (typeof params !== "object" || params === null)
|
|
2319
|
+
return;
|
|
2320
|
+
const p = params;
|
|
2321
|
+
if (typeof p["service"] !== "string" || typeof p["intervalMs"] !== "number" || typeof p["depth"] !== "string" || typeof p["enabled"] !== "boolean") {
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2324
|
+
handler({
|
|
2325
|
+
service: p["service"],
|
|
2326
|
+
intervalMs: p["intervalMs"],
|
|
2327
|
+
depth: p["depth"],
|
|
2328
|
+
enabled: p["enabled"]
|
|
2329
|
+
});
|
|
2330
|
+
};
|
|
2331
|
+
this.ipc.onNotification("connector.configChanged", onChanged);
|
|
2332
|
+
return {
|
|
2333
|
+
dispose: () => {
|
|
2334
|
+
this.ipc.offNotification("connector.configChanged", onChanged);
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
}
|
|
2338
|
+
subscribeAgentBrief(agent, handler) {
|
|
2339
|
+
const readyMethod = `${agent}.briefReady`;
|
|
2340
|
+
const errorMethod = `${agent}.briefError`;
|
|
2341
|
+
const onReady = (params) => {
|
|
2342
|
+
const ev = parseBriefReady(agent, params);
|
|
2343
|
+
if (ev !== null)
|
|
2344
|
+
handler(ev);
|
|
2345
|
+
};
|
|
2346
|
+
const onError = (params) => {
|
|
2347
|
+
const ev = parseBriefError(params);
|
|
2348
|
+
if (ev !== null)
|
|
2349
|
+
handler(ev);
|
|
2350
|
+
};
|
|
2351
|
+
this.ipc.onNotification(readyMethod, onReady);
|
|
2352
|
+
this.ipc.onNotification(errorMethod, onError);
|
|
2353
|
+
return {
|
|
2354
|
+
dispose: () => {
|
|
2355
|
+
this.ipc.offNotification(readyMethod, onReady);
|
|
2356
|
+
this.ipc.offNotification(errorMethod, onError);
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
async runAgent(agent, params, opts) {
|
|
2361
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_AGENT_TIMEOUT_MS;
|
|
2362
|
+
const buffered = [];
|
|
2363
|
+
let sessionId = null;
|
|
2364
|
+
let deliver = null;
|
|
2365
|
+
const sub = this.subscribeAgentBrief(agent, (ev) => {
|
|
2366
|
+
if (sessionId === null) {
|
|
2367
|
+
buffered.push(ev);
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
if (ev.sessionId === sessionId)
|
|
2371
|
+
deliver?.(ev);
|
|
2372
|
+
});
|
|
2373
|
+
let timer;
|
|
2374
|
+
try {
|
|
2375
|
+
const method = `agents.${agent}`;
|
|
2376
|
+
const raw = await this.ipc.call(method, params);
|
|
2377
|
+
const sid = validateAgentSession(method, raw).sessionId;
|
|
2378
|
+
sessionId = sid;
|
|
2379
|
+
const ev = await new Promise((resolve, reject) => {
|
|
2380
|
+
deliver = resolve;
|
|
2381
|
+
const early = buffered.find((b) => b.sessionId === sid);
|
|
2382
|
+
if (early !== undefined) {
|
|
2383
|
+
resolve(early);
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
timer = setTimeout(() => {
|
|
2387
|
+
reject(new AgentTimeoutError(agent, sid, timeoutMs));
|
|
2388
|
+
}, timeoutMs);
|
|
2389
|
+
});
|
|
2390
|
+
if (!ev.ok)
|
|
2391
|
+
throw new AgentBriefError(agent, ev.sessionId, ev.error);
|
|
2392
|
+
return ev.findings;
|
|
2393
|
+
} finally {
|
|
2394
|
+
if (timer !== undefined)
|
|
2395
|
+
clearTimeout(timer);
|
|
2396
|
+
sub.dispose();
|
|
2238
2397
|
}
|
|
2239
|
-
};
|
|
2240
|
-
}
|
|
2241
|
-
var CONNECTOR_STATUS_VALUES = new Set(["ok", "syncing", "paused", "backoff", "error"]);
|
|
2242
|
-
var CONNECTOR_DEPTH_VALUES = new Set(["metadata_only", "summary", "full"]);
|
|
2243
|
-
function validateConnectorSyncStatus(method, v) {
|
|
2244
|
-
const o = record(method, v);
|
|
2245
|
-
const status = o["status"];
|
|
2246
|
-
if (typeof status !== "string" || !CONNECTOR_STATUS_VALUES.has(status)) {
|
|
2247
|
-
throw new IpcResponseError(method, `"status" must be a recognised connector status`);
|
|
2248
2398
|
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
throw new IpcResponseError(method, `"depth" must be "metadata_only", "summary", or "full"`);
|
|
2399
|
+
agentsExpert(p, o) {
|
|
2400
|
+
return this.runAgent("expert", p, o);
|
|
2252
2401
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
status,
|
|
2256
|
-
lastSyncAt: nullableNum(method, o, "lastSyncAt"),
|
|
2257
|
-
nextSyncAt: nullableNum(method, o, "nextSyncAt"),
|
|
2258
|
-
intervalMs: num(method, o, "intervalMs"),
|
|
2259
|
-
itemCount: num(method, o, "itemCount"),
|
|
2260
|
-
lastError: nullableStr(method, o, "lastError"),
|
|
2261
|
-
consecutiveFailures: num(method, o, "consecutiveFailures"),
|
|
2262
|
-
depth,
|
|
2263
|
-
enabled: bool(method, o, "enabled")
|
|
2264
|
-
};
|
|
2265
|
-
const healthState = optStr(o, "healthState");
|
|
2266
|
-
if (healthState !== undefined)
|
|
2267
|
-
result.healthState = healthState;
|
|
2268
|
-
if (o["healthRetryAfterMs"] !== undefined) {
|
|
2269
|
-
result.healthRetryAfterMs = nullableNum(method, o, "healthRetryAfterMs");
|
|
2402
|
+
agentsImpact(p, o) {
|
|
2403
|
+
return this.runAgent("impact", p, o);
|
|
2270
2404
|
}
|
|
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"`);
|
|
2405
|
+
agentsCatchup(p, o) {
|
|
2406
|
+
return this.runAgent("catchup", p ?? {}, o);
|
|
2326
2407
|
}
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
throw new IpcResponseError(method, `"mode" must be "shallow", "deepen", or "same"`);
|
|
2408
|
+
agentsGhost(p, o) {
|
|
2409
|
+
return this.runAgent("ghost", p, o);
|
|
2330
2410
|
}
|
|
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`);
|
|
2411
|
+
agentsConflicts(p, o) {
|
|
2412
|
+
return this.runAgent("conflicts", p, o);
|
|
2341
2413
|
}
|
|
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") };
|
|
2414
|
+
agentsHuddle(p, o) {
|
|
2415
|
+
return this.runAgent("huddle", p ?? {}, o);
|
|
2354
2416
|
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
return
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
throw new IpcResponseError(m, `"ok" must be true`);
|
|
2369
|
-
}
|
|
2370
|
-
const vaultKeysRemoved = arr(m, o["vaultKeysRemoved"]).map((k) => {
|
|
2371
|
-
if (typeof k !== "string") {
|
|
2372
|
-
throw new IpcResponseError(m, `"vaultKeysRemoved" must contain only strings`);
|
|
2373
|
-
}
|
|
2374
|
-
return k;
|
|
2417
|
+
agentsJanitor(p, o) {
|
|
2418
|
+
return this.runAgent("janitor", p, o);
|
|
2419
|
+
}
|
|
2420
|
+
agentsPreflight(p, o) {
|
|
2421
|
+
return this.runAgent("preflight", p, o);
|
|
2422
|
+
}
|
|
2423
|
+
agentsWhy(p, o) {
|
|
2424
|
+
return this.runAgent("why", p, o);
|
|
2425
|
+
}
|
|
2426
|
+
async agentsWhyPeek(p) {
|
|
2427
|
+
const raw = await this.ipc.call("agents.whyPeek", {
|
|
2428
|
+
ref: p.ref,
|
|
2429
|
+
...p.line === undefined ? {} : { line: p.line }
|
|
2375
2430
|
});
|
|
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;
|
|
2431
|
+
return validateWhyPeek("agents.whyPeek", raw);
|
|
2432
|
+
}
|
|
2433
|
+
async getSessionTranscript(params) {
|
|
2434
|
+
const raw = await this.ipc.call("engine.getSessionTranscript", params);
|
|
2435
|
+
return validateSessionTranscript("engine.getSessionTranscript", raw);
|
|
2436
|
+
}
|
|
2437
|
+
async cancelStream(streamId) {
|
|
2438
|
+
const raw = await this.ipc.call("engine.cancelStream", { streamId });
|
|
2439
|
+
return validateOk("engine.cancelStream", raw);
|
|
2440
|
+
}
|
|
2441
|
+
async sessionAppend(params) {
|
|
2442
|
+
const raw = await this.ipc.call("session.append", {
|
|
2443
|
+
sessionId: params.sessionId,
|
|
2444
|
+
chunkText: params.chunkText,
|
|
2445
|
+
role: params.role
|
|
2446
|
+
});
|
|
2447
|
+
return validateOk("session.append", raw);
|
|
2448
|
+
}
|
|
2449
|
+
async sessionRecall(params) {
|
|
2450
|
+
const raw = await this.ipc.call("session.recall", {
|
|
2451
|
+
sessionId: params.sessionId,
|
|
2452
|
+
query: params.query,
|
|
2453
|
+
topK: params.topK
|
|
2454
|
+
});
|
|
2455
|
+
return validateSessionRecall("session.recall", raw);
|
|
2456
|
+
}
|
|
2457
|
+
async sessionList() {
|
|
2458
|
+
return validateSessionList("session.list", await this.ipc.call("session.list"));
|
|
2459
|
+
}
|
|
2460
|
+
async sessionClear(params = {}) {
|
|
2461
|
+
const raw = await this.ipc.call("session.clear", { sessionId: params.sessionId });
|
|
2462
|
+
return validateSessionClear("session.clear", raw);
|
|
2463
|
+
}
|
|
2464
|
+
async metricsDora(params) {
|
|
2465
|
+
const raw = await this.ipc.call("metrics.dora", {
|
|
2466
|
+
service: params.service,
|
|
2467
|
+
since: params.since
|
|
2468
|
+
});
|
|
2469
|
+
return validateDoraMetrics("metrics.dora", raw);
|
|
2470
|
+
}
|
|
2471
|
+
async deployPreflight(params) {
|
|
2472
|
+
const raw = await this.ipc.call("deploy.preflight", {
|
|
2473
|
+
service: params.service,
|
|
2474
|
+
target_ref: params.targetRef,
|
|
2475
|
+
max_findings: params.maxFindings
|
|
2476
|
+
});
|
|
2477
|
+
return validateDeployPreflight("deploy.preflight", raw);
|
|
2478
|
+
}
|
|
2479
|
+
async queryItems(params) {
|
|
2480
|
+
const raw = await this.ipc.call("index.queryItems", {
|
|
2481
|
+
services: params.services,
|
|
2482
|
+
types: params.types,
|
|
2483
|
+
sinceMs: params.sinceMs,
|
|
2484
|
+
untilMs: params.untilMs,
|
|
2485
|
+
limit: params.limit
|
|
2486
|
+
});
|
|
2487
|
+
return validateQueryItems("index.queryItems", raw);
|
|
2488
|
+
}
|
|
2489
|
+
async searchRanked(params = {}) {
|
|
2490
|
+
const raw = await this.ipc.call("index.searchRanked", {
|
|
2491
|
+
name: params.name,
|
|
2492
|
+
service: params.service,
|
|
2493
|
+
itemType: params.itemType,
|
|
2494
|
+
limit: params.limit,
|
|
2495
|
+
semantic: params.semantic,
|
|
2496
|
+
contextChunks: params.contextChunks
|
|
2497
|
+
});
|
|
2498
|
+
return validateRankedItems("index.searchRanked", raw);
|
|
2499
|
+
}
|
|
2500
|
+
async querySql(sql) {
|
|
2501
|
+
const raw = await this.ipc.call("index.querySql", { sql });
|
|
2502
|
+
return validateQuerySql("index.querySql", raw);
|
|
2503
|
+
}
|
|
2504
|
+
async auditList(limit) {
|
|
2505
|
+
const raw = await this.ipc.call("audit.list", { limit: limit ?? 50 });
|
|
2506
|
+
return validateAuditList("audit.list", raw);
|
|
2507
|
+
}
|
|
2508
|
+
async auditVerify(params = {}) {
|
|
2509
|
+
const raw = await this.ipc.call("audit.verify", { full: params.full });
|
|
2510
|
+
return validateAuditVerify("audit.verify", raw);
|
|
2511
|
+
}
|
|
2512
|
+
async auditGetSummary() {
|
|
2513
|
+
return validateAuditSummary("audit.getSummary", await this.ipc.call("audit.getSummary"));
|
|
2514
|
+
}
|
|
2515
|
+
async auditToolCalls(params = {}) {
|
|
2516
|
+
const raw = await this.ipc.call("audit.toolCalls", {
|
|
2517
|
+
since: params.since,
|
|
2518
|
+
until: params.until,
|
|
2519
|
+
limit: params.limit,
|
|
2520
|
+
sessionId: params.sessionId,
|
|
2521
|
+
toolId: params.toolId,
|
|
2522
|
+
status: params.status,
|
|
2523
|
+
cursor: params.cursor
|
|
2524
|
+
});
|
|
2525
|
+
return validateAuditToolCalls("audit.toolCalls", raw);
|
|
2526
|
+
}
|
|
2527
|
+
async egressHead() {
|
|
2528
|
+
return validateEgressHead("egress.head", await this.ipc.call("egress.head"));
|
|
2529
|
+
}
|
|
2530
|
+
async egressList(params = {}) {
|
|
2531
|
+
const raw = await this.ipc.call("egress.list", {
|
|
2532
|
+
since: params.since,
|
|
2533
|
+
until: params.until,
|
|
2534
|
+
limit: params.limit
|
|
2535
|
+
});
|
|
2536
|
+
return validateEgressList("egress.list", raw);
|
|
2537
|
+
}
|
|
2538
|
+
async egressVerify() {
|
|
2539
|
+
return validateEgressVerify("egress.verify", await this.ipc.call("egress.verify"));
|
|
2540
|
+
}
|
|
2541
|
+
async egressProveWindow(params = {}) {
|
|
2542
|
+
const raw = await this.ipc.call("egress.proveWindow", {
|
|
2543
|
+
since: params.since,
|
|
2544
|
+
until: params.until,
|
|
2545
|
+
sign: params.sign
|
|
2546
|
+
});
|
|
2547
|
+
return validateEgressProveWindow("egress.proveWindow", raw);
|
|
2570
2548
|
}
|
|
2571
|
-
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2549
|
+
async consentRespond(params) {
|
|
2550
|
+
const raw = await this.ipc.call("consent.respond", {
|
|
2551
|
+
requestId: params.requestId,
|
|
2552
|
+
approved: params.approved
|
|
2574
2553
|
});
|
|
2575
|
-
|
|
2576
|
-
return new NimbusClient(ipc);
|
|
2554
|
+
return validateOk("consent.respond", raw);
|
|
2577
2555
|
}
|
|
2578
|
-
async
|
|
2579
|
-
const raw = await this.ipc.call("
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2556
|
+
async gatewayPing(params = {}) {
|
|
2557
|
+
const raw = await this.ipc.call("gateway.ping", { includeDrift: params.includeDrift });
|
|
2558
|
+
return validateGatewayPing("gateway.ping", raw);
|
|
2559
|
+
}
|
|
2560
|
+
async diagGetVersion() {
|
|
2561
|
+
return validateDiagVersion("diag.getVersion", await this.ipc.call("diag.getVersion"));
|
|
2562
|
+
}
|
|
2563
|
+
async indexMetrics() {
|
|
2564
|
+
return validateIndexMetrics("index.metrics", await this.ipc.call("index.metrics"));
|
|
2565
|
+
}
|
|
2566
|
+
async diagSnapshot() {
|
|
2567
|
+
return validateDiagSnapshot("diag.snapshot", await this.ipc.call("diag.snapshot"));
|
|
2568
|
+
}
|
|
2569
|
+
async adminStatus() {
|
|
2570
|
+
return validateGatewayStatus("admin.status", await this.ipc.call("admin.status"));
|
|
2571
|
+
}
|
|
2572
|
+
async connectorListStatus(params = {}) {
|
|
2573
|
+
const raw = await this.ipc.call("connector.listStatus", { serviceId: params.serviceId });
|
|
2574
|
+
return validateConnectorSyncStatusList("connector.listStatus", raw);
|
|
2575
|
+
}
|
|
2576
|
+
async connectorStatus(params) {
|
|
2577
|
+
const raw = await this.ipc.call("connector.status", {
|
|
2578
|
+
serviceId: params.serviceId,
|
|
2579
|
+
includeStats: params.includeStats
|
|
2584
2580
|
});
|
|
2585
|
-
return
|
|
2581
|
+
return validateConnectorStatusResult("connector.status", raw);
|
|
2586
2582
|
}
|
|
2587
|
-
|
|
2588
|
-
|
|
2583
|
+
async connectorHealthHistory(params) {
|
|
2584
|
+
const raw = await this.ipc.call("connector.healthHistory", {
|
|
2585
|
+
service: params.service,
|
|
2586
|
+
limit: params.limit
|
|
2587
|
+
});
|
|
2588
|
+
return validateConnectorHealthHistory("connector.healthHistory", raw);
|
|
2589
2589
|
}
|
|
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
|
-
};
|
|
2590
|
+
async connectorPause(params) {
|
|
2591
|
+
const raw = await this.ipc.call("connector.pause", { serviceId: params.serviceId });
|
|
2592
|
+
return validateOk("connector.pause", raw);
|
|
2611
2593
|
}
|
|
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
|
-
};
|
|
2594
|
+
async connectorResume(params) {
|
|
2595
|
+
const raw = await this.ipc.call("connector.resume", { serviceId: params.serviceId });
|
|
2596
|
+
return validateOk("connector.resume", raw);
|
|
2633
2597
|
}
|
|
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
|
-
};
|
|
2598
|
+
async connectorSetInterval(params) {
|
|
2599
|
+
const raw = await this.ipc.call("connector.setInterval", {
|
|
2600
|
+
serviceId: params.serviceId,
|
|
2601
|
+
intervalMs: params.intervalMs
|
|
2602
|
+
});
|
|
2603
|
+
return validateOk("connector.setInterval", raw);
|
|
2655
2604
|
}
|
|
2656
|
-
async
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2605
|
+
async connectorSetConfig(params) {
|
|
2606
|
+
const raw = await this.ipc.call("connector.setConfig", {
|
|
2607
|
+
serviceId: params.serviceId,
|
|
2608
|
+
intervalMs: params.intervalMs,
|
|
2609
|
+
depth: params.depth,
|
|
2610
|
+
enabled: params.enabled
|
|
2611
|
+
});
|
|
2612
|
+
return validateConnectorSetConfig("connector.setConfig", raw);
|
|
2613
|
+
}
|
|
2614
|
+
async connectorSync(params) {
|
|
2615
|
+
const raw = await this.ipc.call("connector.sync", {
|
|
2616
|
+
serviceId: params.serviceId,
|
|
2617
|
+
full: params.full
|
|
2618
|
+
});
|
|
2619
|
+
return validateOk("connector.sync", raw);
|
|
2620
|
+
}
|
|
2621
|
+
async connectorAuth(params) {
|
|
2622
|
+
const raw = await this.ipc.call("connector.auth", params);
|
|
2623
|
+
return validateConnectorAuth("connector.auth", raw);
|
|
2624
|
+
}
|
|
2625
|
+
async connectorAddMcp(params) {
|
|
2626
|
+
const raw = await this.ipc.call("connector.addMcp", {
|
|
2627
|
+
serviceId: params.serviceId,
|
|
2628
|
+
commandLine: params.commandLine
|
|
2629
|
+
});
|
|
2630
|
+
return validateConnectorAddMcp("connector.addMcp", raw);
|
|
2631
|
+
}
|
|
2632
|
+
async connectorRemove(params) {
|
|
2633
|
+
const raw = await this.ipc.call("connector.remove", {
|
|
2634
|
+
serviceId: params.serviceId,
|
|
2635
|
+
service: params.serviceId
|
|
2636
|
+
});
|
|
2637
|
+
return validateConnectorRemove("connector.remove", raw);
|
|
2638
|
+
}
|
|
2639
|
+
async connectorReindex(params) {
|
|
2640
|
+
const raw = await this.ipc.call("connector.reindex", {
|
|
2641
|
+
service: params.service,
|
|
2642
|
+
depth: params.depth
|
|
2643
|
+
});
|
|
2644
|
+
return validateConnectorReindex("connector.reindex", raw);
|
|
2645
|
+
}
|
|
2646
|
+
async workflowList() {
|
|
2647
|
+
return validateWorkflowList("workflow.list", await this.ipc.call("workflow.list"));
|
|
2648
|
+
}
|
|
2649
|
+
async workflowSave(params) {
|
|
2650
|
+
const raw = await this.ipc.call("workflow.save", {
|
|
2651
|
+
name: params.name,
|
|
2652
|
+
description: params.description,
|
|
2653
|
+
stepsJson: params.stepsJson
|
|
2654
|
+
});
|
|
2655
|
+
return validateWorkflowSave("workflow.save", raw);
|
|
2656
|
+
}
|
|
2657
|
+
async workflowDelete(params) {
|
|
2658
|
+
const raw = await this.ipc.call("workflow.delete", { name: params.name });
|
|
2659
|
+
return validateOk("workflow.delete", raw);
|
|
2660
|
+
}
|
|
2661
|
+
async workflowListRuns(params) {
|
|
2662
|
+
const raw = await this.ipc.call("workflow.listRuns", {
|
|
2663
|
+
workflowName: params.workflowName,
|
|
2664
|
+
limit: params.limit
|
|
2665
|
+
});
|
|
2666
|
+
return validateWorkflowListRuns("workflow.listRuns", raw);
|
|
2667
|
+
}
|
|
2668
|
+
async workflowRun(params) {
|
|
2669
|
+
const raw = await this.ipc.call("workflow.run", {
|
|
2670
|
+
name: params.name,
|
|
2671
|
+
triggeredBy: params.triggeredBy,
|
|
2672
|
+
dryRun: params.dryRun,
|
|
2673
|
+
stream: params.stream,
|
|
2674
|
+
sessionId: params.sessionId,
|
|
2675
|
+
agent: params.agent,
|
|
2676
|
+
paramsOverride: params.paramsOverride,
|
|
2677
|
+
streamId: params.streamId
|
|
2678
|
+
});
|
|
2679
|
+
return validateWorkflowRun("workflow.run", raw);
|
|
2680
|
+
}
|
|
2681
|
+
workflowRunStream(params) {
|
|
2682
|
+
return createWorkflowRunStream(this.ipc, params, validateWorkflowRun);
|
|
2683
|
+
}
|
|
2684
|
+
async workflowCancel(params) {
|
|
2685
|
+
const raw = await this.ipc.call("workflow.cancel", { streamId: params.streamId });
|
|
2686
|
+
return validateWorkflowCancel("workflow.cancel", raw);
|
|
2687
|
+
}
|
|
2688
|
+
async close() {
|
|
2689
|
+
await this.ipc.disconnect();
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
// src/mock-client.ts
|
|
2694
|
+
class MockClient {
|
|
2695
|
+
fixtures;
|
|
2696
|
+
constructor(fixtures = {}) {
|
|
2697
|
+
this.fixtures = fixtures;
|
|
2698
|
+
}
|
|
2699
|
+
async agentInvoke(_input, _options) {
|
|
2700
|
+
return { reply: this.fixtures.reply ?? "[MockClient] agent.invoke" };
|
|
2701
|
+
}
|
|
2702
|
+
askStream(_input, _opts) {
|
|
2703
|
+
const tokens = this.fixtures.streamTokens ?? ["mock", " token"];
|
|
2704
|
+
const reply = this.fixtures.reply ?? tokens.join("");
|
|
2705
|
+
let i = 0;
|
|
2706
|
+
let cancelled = false;
|
|
2707
|
+
const handle = {
|
|
2708
|
+
streamId: "mock-stream",
|
|
2709
|
+
async cancel() {
|
|
2710
|
+
cancelled = true;
|
|
2711
|
+
},
|
|
2712
|
+
[Symbol.asyncIterator]() {
|
|
2713
|
+
return {
|
|
2714
|
+
async next() {
|
|
2715
|
+
if (cancelled)
|
|
2716
|
+
return { value: undefined, done: true };
|
|
2717
|
+
if (i < tokens.length) {
|
|
2718
|
+
const text = tokens[i];
|
|
2719
|
+
i += 1;
|
|
2720
|
+
return { value: { type: "token", text }, done: false };
|
|
2721
|
+
}
|
|
2722
|
+
if (i === tokens.length) {
|
|
2723
|
+
i += 1;
|
|
2724
|
+
return {
|
|
2725
|
+
value: { type: "done", reply, sessionId: "mock-session" },
|
|
2726
|
+
done: false
|
|
2727
|
+
};
|
|
2728
|
+
}
|
|
2729
|
+
return { value: undefined, done: true };
|
|
2730
|
+
}
|
|
2731
|
+
};
|
|
2665
2732
|
}
|
|
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
|
-
}
|
|
2733
|
+
};
|
|
2734
|
+
return handle;
|
|
2694
2735
|
}
|
|
2695
|
-
|
|
2696
|
-
return
|
|
2736
|
+
subscribeHitl(_handler) {
|
|
2737
|
+
return { dispose: () => {
|
|
2738
|
+
return;
|
|
2739
|
+
} };
|
|
2697
2740
|
}
|
|
2698
|
-
|
|
2699
|
-
return
|
|
2741
|
+
subscribeConnectorConfigChanged(_handler) {
|
|
2742
|
+
return { dispose: () => {
|
|
2743
|
+
return;
|
|
2744
|
+
} };
|
|
2700
2745
|
}
|
|
2701
|
-
|
|
2702
|
-
return
|
|
2746
|
+
subscribeAgentBrief(_agent, _handler) {
|
|
2747
|
+
return { dispose: () => {} };
|
|
2703
2748
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2749
|
+
brief(agent) {
|
|
2750
|
+
const fixture = this.fixtures.agentBriefs?.[agent];
|
|
2751
|
+
if (fixture === undefined) {
|
|
2752
|
+
return Promise.reject(new Error(`MockClient: no agentBriefs.${agent} fixture configured`));
|
|
2753
|
+
}
|
|
2754
|
+
return Promise.resolve(fixture);
|
|
2706
2755
|
}
|
|
2707
|
-
|
|
2708
|
-
return this.
|
|
2756
|
+
async agentsExpert(_p) {
|
|
2757
|
+
return this.brief("expert");
|
|
2709
2758
|
}
|
|
2710
|
-
|
|
2711
|
-
return this.
|
|
2759
|
+
async agentsImpact(_p) {
|
|
2760
|
+
return this.brief("impact");
|
|
2712
2761
|
}
|
|
2713
|
-
|
|
2714
|
-
return this.
|
|
2762
|
+
async agentsCatchup(_p) {
|
|
2763
|
+
return this.brief("catchup");
|
|
2715
2764
|
}
|
|
2716
|
-
|
|
2717
|
-
return this.
|
|
2765
|
+
async agentsGhost(_p) {
|
|
2766
|
+
return this.brief("ghost");
|
|
2718
2767
|
}
|
|
2719
|
-
|
|
2720
|
-
return this.
|
|
2768
|
+
async agentsConflicts(_p) {
|
|
2769
|
+
return this.brief("conflicts");
|
|
2721
2770
|
}
|
|
2722
|
-
async
|
|
2723
|
-
|
|
2724
|
-
ref: p.ref,
|
|
2725
|
-
...p.line === undefined ? {} : { line: p.line }
|
|
2726
|
-
});
|
|
2727
|
-
return validateWhyPeek("agents.whyPeek", raw);
|
|
2771
|
+
async agentsHuddle(_p) {
|
|
2772
|
+
return this.brief("huddle");
|
|
2728
2773
|
}
|
|
2729
|
-
async
|
|
2730
|
-
|
|
2731
|
-
return validateSessionTranscript("engine.getSessionTranscript", raw);
|
|
2774
|
+
async agentsJanitor(_p) {
|
|
2775
|
+
return this.brief("janitor");
|
|
2732
2776
|
}
|
|
2733
|
-
async
|
|
2734
|
-
|
|
2735
|
-
return validateOk("engine.cancelStream", raw);
|
|
2777
|
+
async agentsPreflight(_p) {
|
|
2778
|
+
return this.brief("preflight");
|
|
2736
2779
|
}
|
|
2737
|
-
async
|
|
2738
|
-
|
|
2739
|
-
sessionId: params.sessionId,
|
|
2740
|
-
chunkText: params.chunkText,
|
|
2741
|
-
role: params.role
|
|
2742
|
-
});
|
|
2743
|
-
return validateOk("session.append", raw);
|
|
2780
|
+
async agentsWhy(_p) {
|
|
2781
|
+
return this.brief("why");
|
|
2744
2782
|
}
|
|
2745
|
-
async
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
});
|
|
2751
|
-
return validateSessionRecall("session.recall", raw);
|
|
2783
|
+
async agentsWhyPeek(_p) {
|
|
2784
|
+
if (this.fixtures.whyPeek === undefined) {
|
|
2785
|
+
throw new Error("MockClient: no whyPeek fixture configured");
|
|
2786
|
+
}
|
|
2787
|
+
return this.fixtures.whyPeek;
|
|
2752
2788
|
}
|
|
2753
|
-
async
|
|
2754
|
-
return
|
|
2789
|
+
async getSessionTranscript(_params) {
|
|
2790
|
+
return { sessionId: "mock-session", turns: [], hasMore: false };
|
|
2755
2791
|
}
|
|
2756
|
-
async
|
|
2757
|
-
|
|
2758
|
-
return validateSessionClear("session.clear", raw);
|
|
2792
|
+
async cancelStream() {
|
|
2793
|
+
return { ok: true };
|
|
2759
2794
|
}
|
|
2760
|
-
async
|
|
2761
|
-
|
|
2762
|
-
service: params.service,
|
|
2763
|
-
since: params.since
|
|
2764
|
-
});
|
|
2765
|
-
return validateDoraMetrics("metrics.dora", raw);
|
|
2795
|
+
async sessionAppend(_params) {
|
|
2796
|
+
return { ok: true };
|
|
2766
2797
|
}
|
|
2767
|
-
async
|
|
2768
|
-
|
|
2769
|
-
service: params.service,
|
|
2770
|
-
target_ref: params.targetRef,
|
|
2771
|
-
max_findings: params.maxFindings
|
|
2772
|
-
});
|
|
2773
|
-
return validateDeployPreflight("deploy.preflight", raw);
|
|
2798
|
+
async sessionRecall(_params) {
|
|
2799
|
+
return this.fixtures.sessionRecall ?? { chunks: [] };
|
|
2774
2800
|
}
|
|
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);
|
|
2801
|
+
async sessionList() {
|
|
2802
|
+
return this.fixtures.sessionList ?? { sessions: [] };
|
|
2784
2803
|
}
|
|
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);
|
|
2804
|
+
async sessionClear(_params) {
|
|
2805
|
+
return { ok: true, cleared: "all" };
|
|
2795
2806
|
}
|
|
2796
|
-
async
|
|
2797
|
-
const
|
|
2798
|
-
return
|
|
2807
|
+
async queryItems(_params) {
|
|
2808
|
+
const items = this.fixtures.items ?? [];
|
|
2809
|
+
return { items, meta: { limit: items.length, total: items.length } };
|
|
2799
2810
|
}
|
|
2800
|
-
async
|
|
2801
|
-
|
|
2802
|
-
return validateAuditList("audit.list", raw);
|
|
2811
|
+
async searchRanked(_params) {
|
|
2812
|
+
return this.fixtures.rankedItems ?? [];
|
|
2803
2813
|
}
|
|
2804
|
-
async
|
|
2805
|
-
|
|
2806
|
-
|
|
2814
|
+
async querySql(_sql) {
|
|
2815
|
+
return { rows: this.fixtures.sqlRows ?? [] };
|
|
2816
|
+
}
|
|
2817
|
+
async auditList(_limit) {
|
|
2818
|
+
return [];
|
|
2819
|
+
}
|
|
2820
|
+
async auditVerify(_params) {
|
|
2821
|
+
return this.fixtures.auditVerify ?? { ok: true, verifiedRows: 0, lastVerifiedId: 0 };
|
|
2807
2822
|
}
|
|
2808
2823
|
async auditGetSummary() {
|
|
2809
|
-
return
|
|
2824
|
+
return this.fixtures.auditSummary ?? { byOutcome: {}, byService: {}, total: 0 };
|
|
2810
2825
|
}
|
|
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);
|
|
2826
|
+
async auditToolCalls(_params) {
|
|
2827
|
+
return this.fixtures.auditToolCalls ?? { toolCalls: [], hasMore: false, nextCursor: null };
|
|
2822
2828
|
}
|
|
2823
2829
|
async egressHead() {
|
|
2824
|
-
return
|
|
2830
|
+
return this.fixtures.egressHead ?? { head: "", count: 0 };
|
|
2825
2831
|
}
|
|
2826
|
-
async egressList(
|
|
2827
|
-
|
|
2828
|
-
since: params.since,
|
|
2829
|
-
until: params.until,
|
|
2830
|
-
limit: params.limit
|
|
2831
|
-
});
|
|
2832
|
-
return validateEgressList("egress.list", raw);
|
|
2832
|
+
async egressList(_params) {
|
|
2833
|
+
return { rows: this.fixtures.egressRows ?? [] };
|
|
2833
2834
|
}
|
|
2834
2835
|
async egressVerify() {
|
|
2835
|
-
return
|
|
2836
|
+
return this.fixtures.egressVerify ?? { ok: true, verifiedRows: 0 };
|
|
2836
2837
|
}
|
|
2837
|
-
async egressProveWindow(
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2838
|
+
async egressProveWindow(_params) {
|
|
2839
|
+
return this.fixtures.egressProveWindow ?? {
|
|
2840
|
+
rows: [],
|
|
2841
|
+
completeness: {
|
|
2842
|
+
coverage: NO_EGRESS_COVERAGE,
|
|
2843
|
+
outboundEgressEvents: 0,
|
|
2844
|
+
indeterminate: true
|
|
2845
|
+
},
|
|
2846
|
+
verify: { ok: true, verifiedRows: 0 }
|
|
2847
|
+
};
|
|
2844
2848
|
}
|
|
2845
|
-
async consentRespond(
|
|
2846
|
-
|
|
2847
|
-
requestId: params.requestId,
|
|
2848
|
-
approved: params.approved
|
|
2849
|
-
});
|
|
2850
|
-
return validateOk("consent.respond", raw);
|
|
2849
|
+
async consentRespond(_params) {
|
|
2850
|
+
return { ok: true };
|
|
2851
2851
|
}
|
|
2852
|
-
async gatewayPing(
|
|
2853
|
-
|
|
2854
|
-
|
|
2852
|
+
async gatewayPing(_params) {
|
|
2853
|
+
return this.fixtures.gatewayPing ?? {
|
|
2854
|
+
version: "mock",
|
|
2855
|
+
uptime: 0,
|
|
2856
|
+
agentLimits: { maxAgentDepth: 5, maxToolCallsPerSession: 50 }
|
|
2857
|
+
};
|
|
2855
2858
|
}
|
|
2856
2859
|
async diagGetVersion() {
|
|
2857
|
-
return
|
|
2860
|
+
return this.fixtures.diagVersion ?? { version: "mock", commit: null, buildId: null, uptimeMs: 0 };
|
|
2861
|
+
}
|
|
2862
|
+
defaultIndexMetrics() {
|
|
2863
|
+
return {
|
|
2864
|
+
itemCountByService: {},
|
|
2865
|
+
totalItems: 0,
|
|
2866
|
+
indexSizeBytes: 0,
|
|
2867
|
+
embeddingCoveragePercent: 0,
|
|
2868
|
+
lastSuccessfulSyncByConnector: {},
|
|
2869
|
+
queryLatencyP50Ms: 0,
|
|
2870
|
+
queryLatencyP95Ms: 0,
|
|
2871
|
+
queryLatencyP99Ms: 0
|
|
2872
|
+
};
|
|
2858
2873
|
}
|
|
2859
2874
|
async indexMetrics() {
|
|
2860
|
-
return
|
|
2875
|
+
return this.fixtures.indexMetrics ?? this.defaultIndexMetrics();
|
|
2861
2876
|
}
|
|
2862
2877
|
async diagSnapshot() {
|
|
2863
|
-
return
|
|
2878
|
+
return this.fixtures.diagSnapshot ?? {
|
|
2879
|
+
gateway: { version: "mock", uptimeMs: 0 },
|
|
2880
|
+
connectorHealth: [],
|
|
2881
|
+
index: this.defaultIndexMetrics(),
|
|
2882
|
+
hitl: { pendingConsentRequests: 0 },
|
|
2883
|
+
watchers: [],
|
|
2884
|
+
auditLogTail: [],
|
|
2885
|
+
extensions: { disabled_pre_t2: 0, signature_disabled_count: 0 },
|
|
2886
|
+
sandbox: {
|
|
2887
|
+
platform_capabilities: { network: "all_or_nothing", reason: null },
|
|
2888
|
+
linux_helper: null,
|
|
2889
|
+
stale_rules_count: 0
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2864
2892
|
}
|
|
2865
2893
|
async adminStatus() {
|
|
2866
|
-
return
|
|
2894
|
+
return this.fixtures.adminStatus ?? {
|
|
2895
|
+
policy: { signatureValid: true, pendingRestart: false, source: "none" },
|
|
2896
|
+
peers: [],
|
|
2897
|
+
connectors: [],
|
|
2898
|
+
namespaces: [],
|
|
2899
|
+
audit: { chainLength: 0, lastHash: "", appendRate1h: 0 },
|
|
2900
|
+
hitl: { pendingApprovals: 0, pendingQuorum: 0 },
|
|
2901
|
+
identity: { operatorValid: true },
|
|
2902
|
+
syncFreshnessMs: 0
|
|
2903
|
+
};
|
|
2867
2904
|
}
|
|
2868
|
-
async
|
|
2869
|
-
|
|
2870
|
-
|
|
2905
|
+
async metricsDora(_params) {
|
|
2906
|
+
return this.fixtures.metricsDora ?? {
|
|
2907
|
+
service: "mock",
|
|
2908
|
+
since_ms: 0,
|
|
2909
|
+
computed_at: new Date(0).toISOString(),
|
|
2910
|
+
metrics: {
|
|
2911
|
+
deployment_frequency: {
|
|
2912
|
+
value: null,
|
|
2913
|
+
unit: "deploys_per_day",
|
|
2914
|
+
sample: 0,
|
|
2915
|
+
gap: "no_repos"
|
|
2916
|
+
},
|
|
2917
|
+
lead_time_for_changes: {
|
|
2918
|
+
value: null,
|
|
2919
|
+
unit: "seconds_median",
|
|
2920
|
+
sample: 0,
|
|
2921
|
+
gap: "no_repos"
|
|
2922
|
+
},
|
|
2923
|
+
change_failure_rate: { value: null, unit: "ratio", sample: 0, gap: "no_repos" },
|
|
2924
|
+
mttr: { value: null, unit: "seconds_median", sample: 0, gap: "no_repos" }
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
}
|
|
2928
|
+
async deployPreflight(_params) {
|
|
2929
|
+
return this.fixtures.deployPreflight ?? {
|
|
2930
|
+
service: "mock",
|
|
2931
|
+
target_ref: "main",
|
|
2932
|
+
computed_at: new Date(0).toISOString(),
|
|
2933
|
+
verdict: "ok",
|
|
2934
|
+
checks: {
|
|
2935
|
+
active_p1_incidents: { count: 0, findings: [], gap: "no_pagerduty_mapping" },
|
|
2936
|
+
failing_ci_runs: { count: 0, findings: [], gap: "no_repos" },
|
|
2937
|
+
merge_conflicts: { count: 0, findings: [], gap: "no_repos" }
|
|
2938
|
+
}
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
async connectorListStatus(_params) {
|
|
2942
|
+
return this.fixtures.connectorSyncStatuses ?? [];
|
|
2943
|
+
}
|
|
2944
|
+
defaultConnectorStatus(serviceId) {
|
|
2945
|
+
return {
|
|
2946
|
+
serviceId,
|
|
2947
|
+
status: "ok",
|
|
2948
|
+
lastSyncAt: null,
|
|
2949
|
+
nextSyncAt: null,
|
|
2950
|
+
intervalMs: 0,
|
|
2951
|
+
itemCount: 0,
|
|
2952
|
+
lastError: null,
|
|
2953
|
+
consecutiveFailures: 0,
|
|
2954
|
+
depth: "metadata_only",
|
|
2955
|
+
enabled: true
|
|
2956
|
+
};
|
|
2871
2957
|
}
|
|
2872
2958
|
async connectorStatus(params) {
|
|
2873
|
-
|
|
2874
|
-
serviceId: params.serviceId,
|
|
2875
|
-
includeStats: params.includeStats
|
|
2876
|
-
});
|
|
2877
|
-
return validateConnectorStatusResult("connector.status", raw);
|
|
2959
|
+
return this.fixtures.connectorStatus ?? this.defaultConnectorStatus(params.serviceId);
|
|
2878
2960
|
}
|
|
2879
|
-
async connectorHealthHistory(
|
|
2880
|
-
|
|
2881
|
-
service: params.service,
|
|
2882
|
-
limit: params.limit
|
|
2883
|
-
});
|
|
2884
|
-
return validateConnectorHealthHistory("connector.healthHistory", raw);
|
|
2961
|
+
async connectorHealthHistory(_params) {
|
|
2962
|
+
return this.fixtures.connectorHealthHistory ?? [];
|
|
2885
2963
|
}
|
|
2886
|
-
async connectorPause(
|
|
2887
|
-
|
|
2888
|
-
return validateOk("connector.pause", raw);
|
|
2964
|
+
async connectorPause(_params) {
|
|
2965
|
+
return { ok: true };
|
|
2889
2966
|
}
|
|
2890
|
-
async connectorResume(
|
|
2891
|
-
|
|
2892
|
-
return validateOk("connector.resume", raw);
|
|
2967
|
+
async connectorResume(_params) {
|
|
2968
|
+
return { ok: true };
|
|
2893
2969
|
}
|
|
2894
|
-
async connectorSetInterval(
|
|
2895
|
-
|
|
2896
|
-
serviceId: params.serviceId,
|
|
2897
|
-
intervalMs: params.intervalMs
|
|
2898
|
-
});
|
|
2899
|
-
return validateOk("connector.setInterval", raw);
|
|
2970
|
+
async connectorSetInterval(_params) {
|
|
2971
|
+
return { ok: true };
|
|
2900
2972
|
}
|
|
2901
2973
|
async connectorSetConfig(params) {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
intervalMs: params.intervalMs,
|
|
2905
|
-
depth: params.depth,
|
|
2906
|
-
enabled: params.enabled
|
|
2907
|
-
}
|
|
2908
|
-
return validateConnectorSetConfig("connector.setConfig", raw);
|
|
2974
|
+
return this.fixtures.connectorSetConfig ?? {
|
|
2975
|
+
service: params.serviceId,
|
|
2976
|
+
intervalMs: params.intervalMs ?? null,
|
|
2977
|
+
depth: params.depth ?? null,
|
|
2978
|
+
enabled: params.enabled ?? null
|
|
2979
|
+
};
|
|
2909
2980
|
}
|
|
2910
|
-
async connectorSync(
|
|
2911
|
-
|
|
2912
|
-
serviceId: params.serviceId,
|
|
2913
|
-
full: params.full
|
|
2914
|
-
});
|
|
2915
|
-
return validateOk("connector.sync", raw);
|
|
2981
|
+
async connectorSync(_params) {
|
|
2982
|
+
return { ok: true };
|
|
2916
2983
|
}
|
|
2917
2984
|
async connectorAuth(params) {
|
|
2918
|
-
|
|
2919
|
-
return validateConnectorAuth("connector.auth", raw);
|
|
2985
|
+
return this.fixtures.connectorAuth ?? { ok: true, serviceId: params.serviceId, scopesGranted: [] };
|
|
2920
2986
|
}
|
|
2921
2987
|
async connectorAddMcp(params) {
|
|
2922
|
-
|
|
2923
|
-
serviceId: params.serviceId,
|
|
2924
|
-
commandLine: params.commandLine
|
|
2925
|
-
});
|
|
2926
|
-
return validateConnectorAddMcp("connector.addMcp", raw);
|
|
2988
|
+
return this.fixtures.connectorAddMcp ?? { ok: true, serviceId: params.serviceId };
|
|
2927
2989
|
}
|
|
2928
|
-
async connectorRemove(
|
|
2929
|
-
|
|
2930
|
-
serviceId: params.serviceId,
|
|
2931
|
-
service: params.serviceId
|
|
2932
|
-
});
|
|
2933
|
-
return validateConnectorRemove("connector.remove", raw);
|
|
2990
|
+
async connectorRemove(_params) {
|
|
2991
|
+
return this.fixtures.connectorRemove ?? { ok: true, itemsDeleted: 0, vaultKeysRemoved: [] };
|
|
2934
2992
|
}
|
|
2935
2993
|
async connectorReindex(params) {
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
depth: params.depth
|
|
2939
|
-
|
|
2940
|
-
|
|
2994
|
+
return this.fixtures.connectorReindex ?? {
|
|
2995
|
+
itemsAffected: 0,
|
|
2996
|
+
depth: params.depth ?? "metadata_only",
|
|
2997
|
+
mode: "shallow"
|
|
2998
|
+
};
|
|
2941
2999
|
}
|
|
2942
3000
|
async workflowList() {
|
|
2943
|
-
return
|
|
3001
|
+
return this.fixtures.workflowList ?? { workflows: [] };
|
|
2944
3002
|
}
|
|
2945
|
-
async workflowSave(
|
|
2946
|
-
|
|
2947
|
-
name: params.name,
|
|
2948
|
-
description: params.description,
|
|
2949
|
-
stepsJson: params.stepsJson
|
|
2950
|
-
});
|
|
2951
|
-
return validateWorkflowSave("workflow.save", raw);
|
|
3003
|
+
async workflowSave(_params) {
|
|
3004
|
+
return { id: "mock-workflow" };
|
|
2952
3005
|
}
|
|
2953
|
-
async workflowDelete(
|
|
2954
|
-
|
|
2955
|
-
return validateOk("workflow.delete", raw);
|
|
3006
|
+
async workflowDelete(_params) {
|
|
3007
|
+
return { ok: true };
|
|
2956
3008
|
}
|
|
2957
|
-
async workflowListRuns(
|
|
2958
|
-
|
|
2959
|
-
workflowName: params.workflowName,
|
|
2960
|
-
limit: params.limit
|
|
2961
|
-
});
|
|
2962
|
-
return validateWorkflowListRuns("workflow.listRuns", raw);
|
|
3009
|
+
async workflowListRuns(_params) {
|
|
3010
|
+
return this.fixtures.workflowListRuns ?? { runs: [] };
|
|
2963
3011
|
}
|
|
2964
3012
|
async workflowRun(params) {
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
dryRun: params.dryRun,
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
agent: params.agent,
|
|
2972
|
-
paramsOverride: params.paramsOverride
|
|
2973
|
-
});
|
|
2974
|
-
return validateWorkflowRun("workflow.run", raw);
|
|
3013
|
+
return this.fixtures.workflowRun ?? {
|
|
3014
|
+
runId: "mock-run",
|
|
3015
|
+
status: params.dryRun === true ? "preview" : "done",
|
|
3016
|
+
dryRun: params.dryRun ?? false,
|
|
3017
|
+
stepResults: []
|
|
3018
|
+
};
|
|
2975
3019
|
}
|
|
2976
|
-
|
|
2977
|
-
return
|
|
3020
|
+
async workflowCancel(_params) {
|
|
3021
|
+
return this.fixtures.workflowCancel ?? { cancelled: true };
|
|
2978
3022
|
}
|
|
2979
|
-
|
|
2980
|
-
|
|
3023
|
+
workflowRunStream(params) {
|
|
3024
|
+
const chunks = this.fixtures.workflowRunChunks ?? ["mock ", "workflow"];
|
|
3025
|
+
const value = this.fixtures.workflowRun ?? {
|
|
3026
|
+
runId: "mock-run",
|
|
3027
|
+
status: params.dryRun === true ? "preview" : "done",
|
|
3028
|
+
dryRun: params.dryRun ?? false,
|
|
3029
|
+
stepResults: []
|
|
3030
|
+
};
|
|
3031
|
+
const cancelResult = this.fixtures.workflowCancel ?? { cancelled: true };
|
|
3032
|
+
let i = 0;
|
|
3033
|
+
return {
|
|
3034
|
+
result: Promise.resolve(value),
|
|
3035
|
+
streamId: params.streamId ?? "mock-stream",
|
|
3036
|
+
async cancel() {
|
|
3037
|
+
return cancelResult;
|
|
3038
|
+
},
|
|
3039
|
+
[Symbol.asyncIterator]() {
|
|
3040
|
+
return {
|
|
3041
|
+
async next() {
|
|
3042
|
+
if (i < chunks.length) {
|
|
3043
|
+
const text = chunks[i];
|
|
3044
|
+
i += 1;
|
|
3045
|
+
return { value: { type: "chunk", text }, done: false };
|
|
3046
|
+
}
|
|
3047
|
+
if (i === chunks.length) {
|
|
3048
|
+
i += 1;
|
|
3049
|
+
return { value: { type: "done", result: value }, done: false };
|
|
3050
|
+
}
|
|
3051
|
+
return { value: undefined, done: true };
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
2981
3056
|
}
|
|
3057
|
+
async close() {}
|
|
2982
3058
|
}
|
|
3059
|
+
var WHY_BRIEF_FIXTURE = {
|
|
3060
|
+
agentVersion: 1,
|
|
3061
|
+
generatedAt: 1,
|
|
3062
|
+
latencyMs: 5,
|
|
3063
|
+
gaps: [],
|
|
3064
|
+
kind: "why",
|
|
3065
|
+
query: { ref: "src/retry.ts", line: 42 },
|
|
3066
|
+
subject: { repoRoot: "/repo", filePath: "src/retry.ts", lineNo: 42, symbol: "retryBackoff" },
|
|
3067
|
+
findings: ["authorship", "pull_request", "ticket", "discussion", "driver", "downstream"].map((lane, i) => ({
|
|
3068
|
+
lane,
|
|
3069
|
+
title: `${lane} finding`,
|
|
3070
|
+
detail: `${lane} detail`,
|
|
3071
|
+
url: `https://x/${lane}`,
|
|
3072
|
+
occurredAt: 1700000000000 + i,
|
|
3073
|
+
entityId: `e${i}`
|
|
3074
|
+
}))
|
|
3075
|
+
};
|