whisper-id 0.5.0 → 0.5.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/index.js +34 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -618,7 +618,7 @@ async function graphQuery(cypher, params, opts = {}) {
|
|
|
618
618
|
|
|
619
619
|
// ── Flow runner (gallery/run, Server-Sent Events) ───────────────────────────────────
|
|
620
620
|
// A flow entry is a multi-step read workflow orchestrated by the Whisper workflow runner:
|
|
621
|
-
// POST {slug,
|
|
621
|
+
// POST {slug, value, paramValues} to the gallery/run endpoint (keyed, X-API-Key) and consume
|
|
622
622
|
// the SSE stream. Each `step` event carries a step's bound Cypher + rows; the terminal
|
|
623
623
|
// `complete` event carries the aggregate context. callFlow() collects the whole stream and
|
|
624
624
|
// resolves to { slug, steps, complete, events } - one call, the full flow.
|
|
@@ -652,6 +652,36 @@ function flowBody(m, input) {
|
|
|
652
652
|
return { inputs, params };
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
+
// Map the routed { inputs, params } onto the runner's wire contract {slug, value, paramValues}:
|
|
656
|
+
// `value` is the ONE primary entity (a host / IP / ASN), or `values` for a bulk list; the FIRST
|
|
657
|
+
// input becomes the anchor `value`, and every other input plus every tuning knob rides in
|
|
658
|
+
// `paramValues`. We send ONLY the keys the runner reads - an `inputs`/`params` map is silently
|
|
659
|
+
// ignored, so the flow would fall back to its default anchor. A nullish input is skipped so the
|
|
660
|
+
// flow's own default applies (Postel: sensible defaults, liberal in what we accept).
|
|
661
|
+
function flowWireBody(m, input) {
|
|
662
|
+
const { inputs, params } = flowBody(m, input);
|
|
663
|
+
const paramValues = {};
|
|
664
|
+
let value;
|
|
665
|
+
let values;
|
|
666
|
+
let first = true;
|
|
667
|
+
for (const [name, val] of Object.entries(inputs)) {
|
|
668
|
+
if (val === undefined || val === null) continue;
|
|
669
|
+
if (first) {
|
|
670
|
+
if (Array.isArray(val)) values = val.map((x) => String(x));
|
|
671
|
+
else value = String(val);
|
|
672
|
+
first = false;
|
|
673
|
+
} else {
|
|
674
|
+
paramValues[name] = val;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
for (const [k, v] of Object.entries(params)) paramValues[k] = v;
|
|
678
|
+
const body = { slug: m.slug };
|
|
679
|
+
if (value !== undefined) body.value = value;
|
|
680
|
+
if (values !== undefined) body.values = values;
|
|
681
|
+
if (Object.keys(paramValues).length > 0) body.paramValues = paramValues;
|
|
682
|
+
return body;
|
|
683
|
+
}
|
|
684
|
+
|
|
655
685
|
// Parse one SSE record ("event: x\ndata: {...}") into { event, data }; data is JSON-decoded
|
|
656
686
|
// when possible, else kept as the raw string. Never throws on shape.
|
|
657
687
|
function parseSseRecord(record) {
|
|
@@ -671,7 +701,7 @@ function parseSseRecord(record) {
|
|
|
671
701
|
}
|
|
672
702
|
|
|
673
703
|
// The one place that talks to the workflow runner. Requires a key (shared resolveKey),
|
|
674
|
-
// POSTs {slug,
|
|
704
|
+
// POSTs {slug, value, paramValues}, consumes the SSE stream, and resolves to the collected
|
|
675
705
|
// { slug, steps, complete, events }. Flows are multi-step, so the default timeout is 5
|
|
676
706
|
// minutes (override with opts.timeout). On an HTTP error, an `error` event, or a stream
|
|
677
707
|
// that ends with no result at all, throws a WhisperError with the server's clear detail.
|
|
@@ -683,7 +713,7 @@ async function callFlow(m, input, opts = {}) {
|
|
|
683
713
|
"(verify/verifyDetails/rdap are keyless and need no key; flows run keyed on the workflow runner.)"
|
|
684
714
|
);
|
|
685
715
|
}
|
|
686
|
-
const
|
|
716
|
+
const body = flowWireBody(m, input);
|
|
687
717
|
const url = flowRunUrl();
|
|
688
718
|
const timeout = opts.timeout || 300000;
|
|
689
719
|
const ctrl = new AbortController();
|
|
@@ -699,7 +729,7 @@ async function callFlow(m, input, opts = {}) {
|
|
|
699
729
|
"X-API-Key": key,
|
|
700
730
|
"User-Agent": UA,
|
|
701
731
|
},
|
|
702
|
-
body: JSON.stringify(
|
|
732
|
+
body: JSON.stringify(body),
|
|
703
733
|
signal: ctrl.signal,
|
|
704
734
|
});
|
|
705
735
|
} catch (err) {
|