@nimbus-dev/client 0.5.0 → 0.6.1
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 +25 -2
- package/dist/ask-stream.d.ts.map +1 -1
- package/dist/ask-stream.js +110 -72
- package/dist/ask-stream.js.map +1 -1
- package/dist/index.cjs +363 -94
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ipc-transport.d.ts +15 -1
- package/dist/ipc-transport.d.ts.map +1 -1
- package/dist/ipc-transport.js +50 -6
- package/dist/ipc-transport.js.map +1 -1
- package/dist/mock-client.d.ts +13 -15
- package/dist/mock-client.d.ts.map +1 -1
- package/dist/mock-client.js +4 -3
- package/dist/mock-client.js.map +1 -1
- package/dist/nimbus-client.d.ts +65 -2
- package/dist/nimbus-client.d.ts.map +1 -1
- package/dist/nimbus-client.js +25 -13
- package/dist/nimbus-client.js.map +1 -1
- package/dist/paths.js.map +1 -1
- package/dist/validate.d.ts +51 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +218 -0
- package/dist/validate.js.map +1 -0
- package/package.json +12 -8
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,7 @@ __export(exports_src, {
|
|
|
69
69
|
discoverSocketPath: () => discoverSocketPath,
|
|
70
70
|
NimbusClient: () => NimbusClient,
|
|
71
71
|
MockClient: () => MockClient,
|
|
72
|
+
IpcResponseError: () => IpcResponseError,
|
|
72
73
|
IPCClient: () => IPCClient
|
|
73
74
|
});
|
|
74
75
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -237,6 +238,7 @@ class NdjsonLineReader {
|
|
|
237
238
|
}
|
|
238
239
|
// src/ipc-transport.ts
|
|
239
240
|
var HAS_BUN = globalThis.Bun !== undefined;
|
|
241
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
240
242
|
function idKey(id) {
|
|
241
243
|
return typeof id === "number" ? `n:${id}` : `s:${id}`;
|
|
242
244
|
}
|
|
@@ -269,8 +271,10 @@ class IPCClient {
|
|
|
269
271
|
bunSocket = null;
|
|
270
272
|
netSocket = null;
|
|
271
273
|
connected = false;
|
|
272
|
-
|
|
274
|
+
requestTimeoutMs;
|
|
275
|
+
constructor(socketPath, opts) {
|
|
273
276
|
this.socketPath = socketPath;
|
|
277
|
+
this.requestTimeoutMs = opts?.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
274
278
|
}
|
|
275
279
|
async connect() {
|
|
276
280
|
if (this.connected) {
|
|
@@ -340,6 +344,9 @@ class IPCClient {
|
|
|
340
344
|
this.ingest(chunk);
|
|
341
345
|
} catch (e) {
|
|
342
346
|
this.failAll(e);
|
|
347
|
+
this.connected = false;
|
|
348
|
+
this.endWindowsTransport();
|
|
349
|
+
this.endUnixTransport();
|
|
343
350
|
}
|
|
344
351
|
}
|
|
345
352
|
onNetSocketClosed() {
|
|
@@ -367,12 +374,35 @@ class IPCClient {
|
|
|
367
374
|
}
|
|
368
375
|
const line = `${JSON.stringify(body)}
|
|
369
376
|
`;
|
|
377
|
+
const key = idKey(id);
|
|
370
378
|
return await new Promise((resolve, reject) => {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
379
|
+
let timer;
|
|
380
|
+
const clear = () => {
|
|
381
|
+
if (timer !== undefined)
|
|
382
|
+
clearTimeout(timer);
|
|
383
|
+
};
|
|
384
|
+
this.pending.set(key, {
|
|
385
|
+
resolve: (v) => {
|
|
386
|
+
clear();
|
|
387
|
+
resolve(v);
|
|
388
|
+
},
|
|
389
|
+
reject: (e) => {
|
|
390
|
+
clear();
|
|
391
|
+
reject(e);
|
|
392
|
+
}
|
|
374
393
|
});
|
|
375
|
-
this.
|
|
394
|
+
if (this.requestTimeoutMs > 0) {
|
|
395
|
+
timer = setTimeout(() => {
|
|
396
|
+
if (this.pending.delete(key)) {
|
|
397
|
+
reject(new Error(`IPC request timed out after ${this.requestTimeoutMs}ms: ${method}`));
|
|
398
|
+
}
|
|
399
|
+
}, this.requestTimeoutMs);
|
|
400
|
+
}
|
|
401
|
+
if (!this.rawWrite(line)) {
|
|
402
|
+
this.pending.delete(key);
|
|
403
|
+
clear();
|
|
404
|
+
reject(new Error(`IPC write failed: transport not connected (${method})`));
|
|
405
|
+
}
|
|
376
406
|
});
|
|
377
407
|
}
|
|
378
408
|
onNotification(method, handler) {
|
|
@@ -383,6 +413,14 @@ class IPCClient {
|
|
|
383
413
|
}
|
|
384
414
|
set.add(handler);
|
|
385
415
|
}
|
|
416
|
+
offNotification(method, handler) {
|
|
417
|
+
const set = this.notifHandlers.get(method);
|
|
418
|
+
if (set === undefined)
|
|
419
|
+
return;
|
|
420
|
+
set.delete(handler);
|
|
421
|
+
if (set.size === 0)
|
|
422
|
+
this.notifHandlers.delete(method);
|
|
423
|
+
}
|
|
386
424
|
async disconnect() {
|
|
387
425
|
this.connected = false;
|
|
388
426
|
this.failAll(new Error("IPC disconnected"));
|
|
@@ -406,11 +444,13 @@ class IPCClient {
|
|
|
406
444
|
rawWrite(s) {
|
|
407
445
|
if (this.netSocket !== null) {
|
|
408
446
|
this.netSocket.write(s);
|
|
409
|
-
return;
|
|
447
|
+
return true;
|
|
410
448
|
}
|
|
411
449
|
if (this.bunSocket !== null) {
|
|
412
450
|
this.bunSocket.write(s);
|
|
451
|
+
return true;
|
|
413
452
|
}
|
|
453
|
+
return false;
|
|
414
454
|
}
|
|
415
455
|
ingest(chunk) {
|
|
416
456
|
const lines = this.reader.push(chunk);
|
|
@@ -520,7 +560,7 @@ class MockClient {
|
|
|
520
560
|
return;
|
|
521
561
|
} };
|
|
522
562
|
}
|
|
523
|
-
async getSessionTranscript() {
|
|
563
|
+
async getSessionTranscript(_params) {
|
|
524
564
|
return { sessionId: "mock-session", turns: [], hasMore: false };
|
|
525
565
|
}
|
|
526
566
|
async cancelStream() {
|
|
@@ -534,9 +574,9 @@ class MockClient {
|
|
|
534
574
|
return this.fixtures.rankedItems ?? [];
|
|
535
575
|
}
|
|
536
576
|
async querySql(_sql) {
|
|
537
|
-
return { rows: [] };
|
|
577
|
+
return { rows: this.fixtures.sqlRows ?? [] };
|
|
538
578
|
}
|
|
539
|
-
async auditList() {
|
|
579
|
+
async auditList(_limit) {
|
|
540
580
|
return [];
|
|
541
581
|
}
|
|
542
582
|
async egressHead() {
|
|
@@ -565,6 +605,7 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
565
605
|
let streamIdResolved;
|
|
566
606
|
let cancelled = false;
|
|
567
607
|
let unsubscribers = [];
|
|
608
|
+
let early = [];
|
|
568
609
|
const push = (ev) => {
|
|
569
610
|
if (done)
|
|
570
611
|
return;
|
|
@@ -579,6 +620,7 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
579
620
|
if (done)
|
|
580
621
|
return;
|
|
581
622
|
done = true;
|
|
623
|
+
early = [];
|
|
582
624
|
for (const u of unsubscribers)
|
|
583
625
|
u();
|
|
584
626
|
unsubscribers = [];
|
|
@@ -587,62 +629,77 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
587
629
|
w.resolve({ value: undefined, done: true });
|
|
588
630
|
}
|
|
589
631
|
};
|
|
632
|
+
const cancelUpstream = async (sid) => {
|
|
633
|
+
await ipc.call("engine.cancelStream", { streamId: sid }).catch(() => {
|
|
634
|
+
return;
|
|
635
|
+
});
|
|
636
|
+
};
|
|
590
637
|
const matchesStream = (params) => {
|
|
591
638
|
return typeof params === "object" && params !== null && typeof params.streamId === "string";
|
|
592
639
|
};
|
|
593
|
-
const
|
|
594
|
-
const
|
|
595
|
-
if (
|
|
596
|
-
|
|
597
|
-
const text = params.text;
|
|
598
|
-
if (typeof text === "string")
|
|
599
|
-
push({ type: "token", text });
|
|
600
|
-
};
|
|
601
|
-
const onDone = (params) => {
|
|
602
|
-
if (!matchesStream(params) || params.streamId !== streamId)
|
|
603
|
-
return;
|
|
604
|
-
const meta = params.meta ?? {};
|
|
605
|
-
const reply = typeof meta.reply === "string" ? meta.reply : "";
|
|
606
|
-
const sessionId = typeof meta.sessionId === "string" ? meta.sessionId : "";
|
|
607
|
-
push({ type: "done", reply, sessionId });
|
|
608
|
-
finish();
|
|
609
|
-
};
|
|
610
|
-
const onError = (params) => {
|
|
611
|
-
if (!matchesStream(params) || params.streamId !== streamId)
|
|
612
|
-
return;
|
|
613
|
-
const code = typeof params.code === "string" ? params.code : "stream_error";
|
|
614
|
-
const message = typeof params.error === "string" ? params.error : "Stream error";
|
|
615
|
-
push({ type: "error", code, message });
|
|
616
|
-
finish();
|
|
617
|
-
};
|
|
618
|
-
const onSubTask = (params) => {
|
|
619
|
-
if (!matchesStream(params) || params.streamId !== streamId)
|
|
620
|
-
return;
|
|
621
|
-
const p = params;
|
|
622
|
-
if (typeof p.subTaskId !== "string" || typeof p.status !== "string")
|
|
623
|
-
return;
|
|
624
|
-
const ev = typeof p.progress === "number" ? {
|
|
625
|
-
type: "subTaskProgress",
|
|
626
|
-
subTaskId: p.subTaskId,
|
|
627
|
-
status: p.status,
|
|
628
|
-
progress: p.progress
|
|
629
|
-
} : { type: "subTaskProgress", subTaskId: p.subTaskId, status: p.status };
|
|
630
|
-
push(ev);
|
|
640
|
+
const whenMatched = (handler) => (params) => {
|
|
641
|
+
const run = () => {
|
|
642
|
+
if (matchesStream(params) && params.streamId === streamIdResolved)
|
|
643
|
+
handler(params);
|
|
631
644
|
};
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
645
|
+
if (streamIdResolved === undefined) {
|
|
646
|
+
early.push(run);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
run();
|
|
650
|
+
};
|
|
651
|
+
const onToken = whenMatched((params) => {
|
|
652
|
+
const text = params.text;
|
|
653
|
+
if (typeof text === "string")
|
|
654
|
+
push({ type: "token", text });
|
|
655
|
+
});
|
|
656
|
+
const onDone = whenMatched((params) => {
|
|
657
|
+
const meta = params.meta ?? {};
|
|
658
|
+
const reply = typeof meta.reply === "string" ? meta.reply : "";
|
|
659
|
+
const sessionId = typeof meta.sessionId === "string" ? meta.sessionId : "";
|
|
660
|
+
push({ type: "done", reply, sessionId });
|
|
661
|
+
finish();
|
|
662
|
+
});
|
|
663
|
+
const onError = whenMatched((params) => {
|
|
664
|
+
const p = params;
|
|
665
|
+
const code = typeof p.code === "string" ? p.code : "stream_error";
|
|
666
|
+
const message = typeof p.error === "string" ? p.error : "Stream error";
|
|
667
|
+
push({ type: "error", code, message });
|
|
668
|
+
finish();
|
|
669
|
+
});
|
|
670
|
+
const onSubTask = whenMatched((params) => {
|
|
671
|
+
const p = params;
|
|
672
|
+
if (typeof p.subTaskId !== "string" || typeof p.status !== "string")
|
|
673
|
+
return;
|
|
674
|
+
const ev = typeof p.progress === "number" ? {
|
|
675
|
+
type: "subTaskProgress",
|
|
676
|
+
subTaskId: p.subTaskId,
|
|
677
|
+
status: p.status,
|
|
678
|
+
progress: p.progress
|
|
679
|
+
} : { type: "subTaskProgress", subTaskId: p.subTaskId, status: p.status };
|
|
680
|
+
push(ev);
|
|
681
|
+
});
|
|
682
|
+
const onHitl = whenMatched((params) => {
|
|
683
|
+
const p = params;
|
|
684
|
+
if (typeof p.requestId !== "string" || typeof p.prompt !== "string")
|
|
685
|
+
return;
|
|
686
|
+
push({ type: "hitlBatch", requestId: p.requestId, prompt: p.prompt, details: p.details });
|
|
687
|
+
});
|
|
688
|
+
const register = (method, handler) => {
|
|
689
|
+
ipc.onNotification(method, handler);
|
|
690
|
+
unsubscribers.push(() => ipc.offNotification(method, handler));
|
|
691
|
+
};
|
|
692
|
+
register("engine.streamToken", onToken);
|
|
693
|
+
register("engine.streamDone", onDone);
|
|
694
|
+
register("engine.streamError", onError);
|
|
695
|
+
register("agent.subTaskProgress", onSubTask);
|
|
696
|
+
register("agent.hitlBatch", onHitl);
|
|
697
|
+
const onAbort = () => {
|
|
698
|
+
cancelled = true;
|
|
699
|
+
const sid = streamIdResolved;
|
|
700
|
+
if (sid !== undefined)
|
|
701
|
+
cancelUpstream(sid);
|
|
702
|
+
finish();
|
|
646
703
|
};
|
|
647
704
|
const startPromise = (async () => {
|
|
648
705
|
const params = { input };
|
|
@@ -658,32 +715,35 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
658
715
|
throw new Error("no_stream_id");
|
|
659
716
|
}
|
|
660
717
|
streamIdResolved = sid;
|
|
718
|
+
const buffered = early;
|
|
719
|
+
early = [];
|
|
720
|
+
for (const run of buffered)
|
|
721
|
+
run();
|
|
661
722
|
if (cancelled) {
|
|
662
|
-
await
|
|
663
|
-
return;
|
|
664
|
-
});
|
|
723
|
+
await cancelUpstream(sid);
|
|
665
724
|
finish();
|
|
666
725
|
return sid;
|
|
667
726
|
}
|
|
668
|
-
|
|
727
|
+
if (done)
|
|
728
|
+
return sid;
|
|
669
729
|
if (opts.signal !== undefined) {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
});
|
|
730
|
+
const signal = opts.signal;
|
|
731
|
+
if (signal.aborted) {
|
|
732
|
+
await cancelUpstream(sid);
|
|
674
733
|
finish();
|
|
675
734
|
} else {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
return;
|
|
679
|
-
});
|
|
680
|
-
finish();
|
|
681
|
-
});
|
|
735
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
736
|
+
unsubscribers.push(() => signal.removeEventListener("abort", onAbort));
|
|
682
737
|
}
|
|
683
738
|
}
|
|
684
739
|
return sid;
|
|
685
740
|
})();
|
|
686
|
-
startPromise.catch(() => {
|
|
741
|
+
startPromise.catch((err) => {
|
|
742
|
+
push({
|
|
743
|
+
type: "error",
|
|
744
|
+
code: "stream_start_failed",
|
|
745
|
+
message: err instanceof Error ? err.message : String(err)
|
|
746
|
+
});
|
|
687
747
|
finish();
|
|
688
748
|
});
|
|
689
749
|
const handle = {
|
|
@@ -693,11 +753,8 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
693
753
|
async cancel() {
|
|
694
754
|
cancelled = true;
|
|
695
755
|
const sid = streamIdResolved;
|
|
696
|
-
if (sid !== undefined)
|
|
697
|
-
await
|
|
698
|
-
return;
|
|
699
|
-
});
|
|
700
|
-
}
|
|
756
|
+
if (sid !== undefined)
|
|
757
|
+
await cancelUpstream(sid);
|
|
701
758
|
finish();
|
|
702
759
|
},
|
|
703
760
|
[Symbol.asyncIterator]() {
|
|
@@ -715,6 +772,10 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
715
772
|
});
|
|
716
773
|
},
|
|
717
774
|
return() {
|
|
775
|
+
cancelled = true;
|
|
776
|
+
const sid = streamIdResolved;
|
|
777
|
+
if (sid !== undefined)
|
|
778
|
+
cancelUpstream(sid);
|
|
718
779
|
finish();
|
|
719
780
|
return Promise.resolve({ value: undefined, done: true });
|
|
720
781
|
}
|
|
@@ -724,6 +785,201 @@ function createAskStream(ipc, input, opts = {}) {
|
|
|
724
785
|
return handle;
|
|
725
786
|
}
|
|
726
787
|
|
|
788
|
+
// src/validate.ts
|
|
789
|
+
class IpcResponseError extends Error {
|
|
790
|
+
constructor(method, detail) {
|
|
791
|
+
super(`Invalid ${method} response: ${detail}`);
|
|
792
|
+
this.name = "IpcResponseError";
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
function isRecord(v) {
|
|
796
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
797
|
+
}
|
|
798
|
+
function record(method, v) {
|
|
799
|
+
if (!isRecord(v))
|
|
800
|
+
throw new IpcResponseError(method, "expected an object");
|
|
801
|
+
return v;
|
|
802
|
+
}
|
|
803
|
+
function str(method, o, key) {
|
|
804
|
+
const v = o[key];
|
|
805
|
+
if (typeof v !== "string")
|
|
806
|
+
throw new IpcResponseError(method, `"${key}" must be a string`);
|
|
807
|
+
return v;
|
|
808
|
+
}
|
|
809
|
+
function num(method, o, key) {
|
|
810
|
+
const v = o[key];
|
|
811
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
812
|
+
throw new IpcResponseError(method, `"${key}" must be a finite number`);
|
|
813
|
+
}
|
|
814
|
+
return v;
|
|
815
|
+
}
|
|
816
|
+
function bool(method, o, key) {
|
|
817
|
+
const v = o[key];
|
|
818
|
+
if (typeof v !== "boolean")
|
|
819
|
+
throw new IpcResponseError(method, `"${key}" must be a boolean`);
|
|
820
|
+
return v;
|
|
821
|
+
}
|
|
822
|
+
function arr(method, v) {
|
|
823
|
+
if (!Array.isArray(v))
|
|
824
|
+
throw new IpcResponseError(method, "expected an array");
|
|
825
|
+
return v;
|
|
826
|
+
}
|
|
827
|
+
function optStr(o, key) {
|
|
828
|
+
const v = o[key];
|
|
829
|
+
return typeof v === "string" ? v : undefined;
|
|
830
|
+
}
|
|
831
|
+
function optNum(o, key) {
|
|
832
|
+
const v = o[key];
|
|
833
|
+
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
834
|
+
}
|
|
835
|
+
function validateAgentInvoke(method, v) {
|
|
836
|
+
const o = record(method, v);
|
|
837
|
+
if (o["reply"] !== undefined && typeof o["reply"] !== "string") {
|
|
838
|
+
throw new IpcResponseError(method, `"reply" must be a string when present`);
|
|
839
|
+
}
|
|
840
|
+
return o;
|
|
841
|
+
}
|
|
842
|
+
function validateOk(method, v) {
|
|
843
|
+
const o = record(method, v);
|
|
844
|
+
return { ok: bool(method, o, "ok") };
|
|
845
|
+
}
|
|
846
|
+
function validateSessionTranscript(method, v) {
|
|
847
|
+
const o = record(method, v);
|
|
848
|
+
const turns = arr(method, o["turns"]).map((t) => {
|
|
849
|
+
const to = record(method, t);
|
|
850
|
+
const role = str(method, to, "role");
|
|
851
|
+
if (role !== "user" && role !== "assistant") {
|
|
852
|
+
throw new IpcResponseError(method, `turn "role" must be "user" or "assistant"`);
|
|
853
|
+
}
|
|
854
|
+
const turn = {
|
|
855
|
+
role,
|
|
856
|
+
text: str(method, to, "text"),
|
|
857
|
+
timestamp: num(method, to, "timestamp")
|
|
858
|
+
};
|
|
859
|
+
if (to["auditLogId"] !== undefined)
|
|
860
|
+
turn.auditLogId = num(method, to, "auditLogId");
|
|
861
|
+
return turn;
|
|
862
|
+
});
|
|
863
|
+
return { sessionId: str(method, o, "sessionId"), turns, hasMore: bool(method, o, "hasMore") };
|
|
864
|
+
}
|
|
865
|
+
function validateQueryItems(method, v) {
|
|
866
|
+
const o = record(method, v);
|
|
867
|
+
const items = arr(method, o["items"]).map((raw) => {
|
|
868
|
+
const r = record(method, raw);
|
|
869
|
+
const item = {
|
|
870
|
+
id: str(method, r, "id"),
|
|
871
|
+
indexPrimaryKey: str(method, r, "indexPrimaryKey"),
|
|
872
|
+
service: str(method, r, "service"),
|
|
873
|
+
itemType: str(method, r, "itemType"),
|
|
874
|
+
name: str(method, r, "name")
|
|
875
|
+
};
|
|
876
|
+
const mimeType = optStr(r, "mimeType");
|
|
877
|
+
if (mimeType !== undefined)
|
|
878
|
+
item.mimeType = mimeType;
|
|
879
|
+
const sizeBytes = optNum(r, "sizeBytes");
|
|
880
|
+
if (sizeBytes !== undefined)
|
|
881
|
+
item.sizeBytes = sizeBytes;
|
|
882
|
+
const createdAt = optNum(r, "createdAt");
|
|
883
|
+
if (createdAt !== undefined)
|
|
884
|
+
item.createdAt = createdAt;
|
|
885
|
+
const modifiedAt = optNum(r, "modifiedAt");
|
|
886
|
+
if (modifiedAt !== undefined)
|
|
887
|
+
item.modifiedAt = modifiedAt;
|
|
888
|
+
const url = optStr(r, "url");
|
|
889
|
+
if (url !== undefined)
|
|
890
|
+
item.url = url;
|
|
891
|
+
const parentId = optStr(r, "parentId");
|
|
892
|
+
if (parentId !== undefined)
|
|
893
|
+
item.parentId = parentId;
|
|
894
|
+
return item;
|
|
895
|
+
});
|
|
896
|
+
const meta = record(method, o["meta"]);
|
|
897
|
+
return { items, meta: { limit: num(method, meta, "limit"), total: num(method, meta, "total") } };
|
|
898
|
+
}
|
|
899
|
+
function validateRankedItems(method, v) {
|
|
900
|
+
return arr(method, v).map((it) => {
|
|
901
|
+
const o = record(method, it);
|
|
902
|
+
num(method, o, "score");
|
|
903
|
+
str(method, o, "indexPrimaryKey");
|
|
904
|
+
str(method, o, "indexedType");
|
|
905
|
+
return o;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function validateQuerySql(method, v) {
|
|
909
|
+
const o = record(method, v);
|
|
910
|
+
return { rows: arr(method, o["rows"]).map((r) => record(method, r)) };
|
|
911
|
+
}
|
|
912
|
+
function validateAuditList(method, v) {
|
|
913
|
+
return arr(method, v);
|
|
914
|
+
}
|
|
915
|
+
function validateEgressHead(method, v) {
|
|
916
|
+
const o = record(method, v);
|
|
917
|
+
return { head: str(method, o, "head"), count: num(method, o, "count") };
|
|
918
|
+
}
|
|
919
|
+
function validateEgressRow(method, v) {
|
|
920
|
+
const o = record(method, v);
|
|
921
|
+
const sourceId = o["sourceId"];
|
|
922
|
+
if (sourceId !== null && typeof sourceId !== "string") {
|
|
923
|
+
throw new IpcResponseError(method, `row "sourceId" must be a string or null`);
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
id: num(method, o, "id"),
|
|
927
|
+
timestamp: num(method, o, "timestamp"),
|
|
928
|
+
sourceType: str(method, o, "sourceType"),
|
|
929
|
+
sourceId,
|
|
930
|
+
destination: str(method, o, "destination"),
|
|
931
|
+
method: str(method, o, "method"),
|
|
932
|
+
payloadSummary: str(method, o, "payloadSummary"),
|
|
933
|
+
hitlStatus: str(method, o, "hitlStatus"),
|
|
934
|
+
resultStatus: str(method, o, "resultStatus"),
|
|
935
|
+
rowHash: str(method, o, "rowHash"),
|
|
936
|
+
prevHash: str(method, o, "prevHash")
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
function validateEgressList(method, v) {
|
|
940
|
+
const o = record(method, v);
|
|
941
|
+
return { rows: arr(method, o["rows"]).map((r) => validateEgressRow(method, r)) };
|
|
942
|
+
}
|
|
943
|
+
function validateEgressVerify(method, v) {
|
|
944
|
+
const o = record(method, v);
|
|
945
|
+
const result = {
|
|
946
|
+
ok: bool(method, o, "ok"),
|
|
947
|
+
verifiedRows: num(method, o, "verifiedRows")
|
|
948
|
+
};
|
|
949
|
+
if (o["brokenAt"] !== undefined)
|
|
950
|
+
result.brokenAt = num(method, o, "brokenAt");
|
|
951
|
+
if (o["reason"] !== undefined)
|
|
952
|
+
result.reason = str(method, o, "reason");
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
function validateEgressCompleteness(method, v) {
|
|
956
|
+
const o = record(method, v);
|
|
957
|
+
const tier = str(method, o, "tier");
|
|
958
|
+
if (tier !== "authorized-actions") {
|
|
959
|
+
throw new IpcResponseError(method, `completeness "tier" must be "authorized-actions"`);
|
|
960
|
+
}
|
|
961
|
+
return { tier, outboundEgressEvents: num(method, o, "outboundEgressEvents") };
|
|
962
|
+
}
|
|
963
|
+
function validateEgressReceipt(method, v) {
|
|
964
|
+
const o = record(method, v);
|
|
965
|
+
return {
|
|
966
|
+
sigB64: str(method, o, "sigB64"),
|
|
967
|
+
pubkeyB64: str(method, o, "pubkeyB64"),
|
|
968
|
+
digest: str(method, o, "digest")
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
function validateEgressProveWindow(method, v) {
|
|
972
|
+
const o = record(method, v);
|
|
973
|
+
const result = {
|
|
974
|
+
rows: arr(method, o["rows"]).map((r) => validateEgressRow(method, r)),
|
|
975
|
+
completeness: validateEgressCompleteness(method, o["completeness"]),
|
|
976
|
+
verify: validateEgressVerify(method, o["verify"])
|
|
977
|
+
};
|
|
978
|
+
if (o["receipt"] !== undefined)
|
|
979
|
+
result.receipt = validateEgressReceipt(method, o["receipt"]);
|
|
980
|
+
return result;
|
|
981
|
+
}
|
|
982
|
+
|
|
727
983
|
// src/nimbus-client.ts
|
|
728
984
|
class NimbusClient {
|
|
729
985
|
ipc;
|
|
@@ -731,17 +987,20 @@ class NimbusClient {
|
|
|
731
987
|
this.ipc = ipc;
|
|
732
988
|
}
|
|
733
989
|
static async open(opts) {
|
|
734
|
-
const ipc = new IPCClient(opts.socketPath
|
|
990
|
+
const ipc = new IPCClient(opts.socketPath, {
|
|
991
|
+
...opts.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: opts.requestTimeoutMs }
|
|
992
|
+
});
|
|
735
993
|
await ipc.connect();
|
|
736
994
|
return new NimbusClient(ipc);
|
|
737
995
|
}
|
|
738
996
|
async agentInvoke(input, options) {
|
|
739
|
-
|
|
997
|
+
const raw = await this.ipc.call("agent.invoke", {
|
|
740
998
|
input,
|
|
741
999
|
stream: options?.stream ?? false,
|
|
742
1000
|
...options?.sessionId === undefined ? {} : { sessionId: options.sessionId },
|
|
743
1001
|
...options?.agent === undefined ? {} : { agent: options.agent }
|
|
744
1002
|
});
|
|
1003
|
+
return validateAgentInvoke("agent.invoke", raw);
|
|
745
1004
|
}
|
|
746
1005
|
askStream(input, opts) {
|
|
747
1006
|
return createAskStream(this.ipc, input, opts);
|
|
@@ -763,26 +1022,31 @@ class NimbusClient {
|
|
|
763
1022
|
};
|
|
764
1023
|
this.ipc.onNotification("agent.hitlBatch", onBatch);
|
|
765
1024
|
return {
|
|
766
|
-
dispose: () => {
|
|
1025
|
+
dispose: () => {
|
|
1026
|
+
this.ipc.offNotification("agent.hitlBatch", onBatch);
|
|
1027
|
+
}
|
|
767
1028
|
};
|
|
768
1029
|
}
|
|
769
1030
|
async getSessionTranscript(params) {
|
|
770
|
-
|
|
1031
|
+
const raw = await this.ipc.call("engine.getSessionTranscript", params);
|
|
1032
|
+
return validateSessionTranscript("engine.getSessionTranscript", raw);
|
|
771
1033
|
}
|
|
772
1034
|
async cancelStream(streamId) {
|
|
773
|
-
|
|
1035
|
+
const raw = await this.ipc.call("engine.cancelStream", { streamId });
|
|
1036
|
+
return validateOk("engine.cancelStream", raw);
|
|
774
1037
|
}
|
|
775
1038
|
async queryItems(params) {
|
|
776
|
-
|
|
1039
|
+
const raw = await this.ipc.call("index.queryItems", {
|
|
777
1040
|
services: params.services,
|
|
778
1041
|
types: params.types,
|
|
779
1042
|
sinceMs: params.sinceMs,
|
|
780
1043
|
untilMs: params.untilMs,
|
|
781
1044
|
limit: params.limit
|
|
782
1045
|
});
|
|
1046
|
+
return validateQueryItems("index.queryItems", raw);
|
|
783
1047
|
}
|
|
784
1048
|
async searchRanked(params = {}) {
|
|
785
|
-
|
|
1049
|
+
const raw = await this.ipc.call("index.searchRanked", {
|
|
786
1050
|
name: params.name,
|
|
787
1051
|
service: params.service,
|
|
788
1052
|
itemType: params.itemType,
|
|
@@ -790,32 +1054,37 @@ class NimbusClient {
|
|
|
790
1054
|
semantic: params.semantic,
|
|
791
1055
|
contextChunks: params.contextChunks
|
|
792
1056
|
});
|
|
1057
|
+
return validateRankedItems("index.searchRanked", raw);
|
|
793
1058
|
}
|
|
794
1059
|
async querySql(sql) {
|
|
795
|
-
|
|
1060
|
+
const raw = await this.ipc.call("index.querySql", { sql });
|
|
1061
|
+
return validateQuerySql("index.querySql", raw);
|
|
796
1062
|
}
|
|
797
1063
|
async auditList(limit) {
|
|
798
|
-
|
|
1064
|
+
const raw = await this.ipc.call("audit.list", { limit: limit ?? 50 });
|
|
1065
|
+
return validateAuditList("audit.list", raw);
|
|
799
1066
|
}
|
|
800
1067
|
async egressHead() {
|
|
801
|
-
return await this.ipc.call("egress.head");
|
|
1068
|
+
return validateEgressHead("egress.head", await this.ipc.call("egress.head"));
|
|
802
1069
|
}
|
|
803
1070
|
async egressList(params = {}) {
|
|
804
|
-
|
|
1071
|
+
const raw = await this.ipc.call("egress.list", {
|
|
805
1072
|
since: params.since,
|
|
806
1073
|
until: params.until,
|
|
807
1074
|
limit: params.limit
|
|
808
1075
|
});
|
|
1076
|
+
return validateEgressList("egress.list", raw);
|
|
809
1077
|
}
|
|
810
1078
|
async egressVerify() {
|
|
811
|
-
return await this.ipc.call("egress.verify");
|
|
1079
|
+
return validateEgressVerify("egress.verify", await this.ipc.call("egress.verify"));
|
|
812
1080
|
}
|
|
813
1081
|
async egressProveWindow(params = {}) {
|
|
814
|
-
|
|
1082
|
+
const raw = await this.ipc.call("egress.proveWindow", {
|
|
815
1083
|
since: params.since,
|
|
816
1084
|
until: params.until,
|
|
817
1085
|
sign: params.sign
|
|
818
1086
|
});
|
|
1087
|
+
return validateEgressProveWindow("egress.proveWindow", raw);
|
|
819
1088
|
}
|
|
820
1089
|
async close() {
|
|
821
1090
|
await this.ipc.disconnect();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @nimbus-dev/client — MIT local Gateway client (IPC).
|
|
3
3
|
*/
|
|
4
|
+
export type { NimbusItem } from "@nimbus-dev/sdk";
|
|
4
5
|
export { discoverSocketPath, type GatewayStateFile, gatewayStatePath, readGatewayState, type SocketDiscoveryResult, } from "./discovery.js";
|
|
5
|
-
export { IPCClient } from "./ipc-transport.js";
|
|
6
|
+
export { IPCClient, type IPCClientOptions } from "./ipc-transport.js";
|
|
6
7
|
export { MockClient, type MockClientFixtures } from "./mock-client.js";
|
|
7
|
-
export { type EgressCompleteness, type EgressHead, type EgressListParams, type EgressListResult, type EgressProveWindowParams, type EgressProveWindowResult, type EgressReceipt, type EgressRow, type EgressVerifyResult, NimbusClient, type NimbusClientOptions, type RankedSearchItem, type RankedSearchParams, type SessionTranscript, } from "./nimbus-client.js";
|
|
8
|
+
export { type EgressCompleteness, type EgressHead, type EgressListParams, type EgressListResult, type EgressProveWindowParams, type EgressProveWindowResult, type EgressReceipt, type EgressRow, type EgressVerifyResult, type IndexedItem, NimbusClient, type NimbusClientLike, type NimbusClientOptions, type RankedSearchItem, type RankedSearchParams, type SessionTranscript, } from "./nimbus-client.js";
|
|
8
9
|
export { getNimbusPaths, type NimbusPaths } from "./paths.js";
|
|
9
10
|
export type { AskStreamHandle, AskStreamOptions, HitlRequest, StreamEvent, } from "./stream-events.js";
|
|
11
|
+
export { IpcResponseError } from "./validate.js";
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9D,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export { IPCClient } from "./ipc-transport.js";
|
|
|
6
6
|
export { MockClient } from "./mock-client.js";
|
|
7
7
|
export { NimbusClient, } from "./nimbus-client.js";
|
|
8
8
|
export { getNimbusPaths } from "./paths.js";
|
|
9
|
+
export { IpcResponseError } from "./validate.js";
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EACL,kBAAkB,EAElB,gBAAgB,EAChB,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,UAAU,EAA2B,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAWL,YAAY,GAMb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAC;AAO9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|