opsveritas-sdk 0.4.0 → 0.4.2
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/dist/index.d.mts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +29 -6
- package/dist/index.mjs +29 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -48,6 +48,9 @@ declare function langchain(agentName: string, opts?: LangChainOptions): Record<s
|
|
|
48
48
|
interface LangChainModel {
|
|
49
49
|
invoke?: (...args: unknown[]) => unknown;
|
|
50
50
|
ainvoke?: (...args: unknown[]) => Promise<unknown>;
|
|
51
|
+
stream?: (...args: unknown[]) => unknown;
|
|
52
|
+
astream?: (...args: unknown[]) => unknown;
|
|
53
|
+
batch?: (...args: unknown[]) => unknown;
|
|
51
54
|
[key: string]: unknown;
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
@@ -55,16 +58,19 @@ interface LangChainModel {
|
|
|
55
58
|
* `langchain()` above. `langchain()` is telemetry-only (a callback handler;
|
|
56
59
|
* LangChain's callback manager swallows exceptions raised inside callbacks by
|
|
57
60
|
* default, so it can never actually block a call). This patches the model's
|
|
58
|
-
* own `invoke`/`ainvoke` directly — the same
|
|
59
|
-
* provider clients — so a kill-switch check
|
|
60
|
-
* API call happens.
|
|
61
|
+
* own `invoke`/`ainvoke`/`stream`/`astream`/`batch` directly — the same
|
|
62
|
+
* technique wrap() uses on raw provider clients — so a kill-switch check
|
|
63
|
+
* genuinely runs before the real API call happens.
|
|
61
64
|
*
|
|
62
65
|
* const model = new ChatOpenAI({ callbacks: [opsveritas.langchain('My Agent')] }); // telemetry
|
|
63
66
|
* opsveritas.wrapLangChain(model, { agentName: 'My Agent' }); // enforcement
|
|
64
67
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
+
* `stream`/`astream` are gated at call-start only (check-then-call, same as
|
|
69
|
+
* invoke/ainvoke) — NOT mid-stream cancellation. If the kill switch fires
|
|
70
|
+
* after a stream has already started, that in-flight stream still completes;
|
|
71
|
+
* only the *next* call is blocked. This is a deliberate, simpler scope than
|
|
72
|
+
* killing a stream already in progress, and matches the same bounded-delay
|
|
73
|
+
* philosophy as the kill switch's poll interval.
|
|
68
74
|
*/
|
|
69
75
|
declare function wrapLangChain<T extends LangChainModel>(model: T, opts: WrapOptions): T;
|
|
70
76
|
|
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,9 @@ declare function langchain(agentName: string, opts?: LangChainOptions): Record<s
|
|
|
48
48
|
interface LangChainModel {
|
|
49
49
|
invoke?: (...args: unknown[]) => unknown;
|
|
50
50
|
ainvoke?: (...args: unknown[]) => Promise<unknown>;
|
|
51
|
+
stream?: (...args: unknown[]) => unknown;
|
|
52
|
+
astream?: (...args: unknown[]) => unknown;
|
|
53
|
+
batch?: (...args: unknown[]) => unknown;
|
|
51
54
|
[key: string]: unknown;
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
@@ -55,16 +58,19 @@ interface LangChainModel {
|
|
|
55
58
|
* `langchain()` above. `langchain()` is telemetry-only (a callback handler;
|
|
56
59
|
* LangChain's callback manager swallows exceptions raised inside callbacks by
|
|
57
60
|
* default, so it can never actually block a call). This patches the model's
|
|
58
|
-
* own `invoke`/`ainvoke` directly — the same
|
|
59
|
-
* provider clients — so a kill-switch check
|
|
60
|
-
* API call happens.
|
|
61
|
+
* own `invoke`/`ainvoke`/`stream`/`astream`/`batch` directly — the same
|
|
62
|
+
* technique wrap() uses on raw provider clients — so a kill-switch check
|
|
63
|
+
* genuinely runs before the real API call happens.
|
|
61
64
|
*
|
|
62
65
|
* const model = new ChatOpenAI({ callbacks: [opsveritas.langchain('My Agent')] }); // telemetry
|
|
63
66
|
* opsveritas.wrapLangChain(model, { agentName: 'My Agent' }); // enforcement
|
|
64
67
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
+
* `stream`/`astream` are gated at call-start only (check-then-call, same as
|
|
69
|
+
* invoke/ainvoke) — NOT mid-stream cancellation. If the kill switch fires
|
|
70
|
+
* after a stream has already started, that in-flight stream still completes;
|
|
71
|
+
* only the *next* call is blocked. This is a deliberate, simpler scope than
|
|
72
|
+
* killing a stream already in progress, and matches the same bounded-delay
|
|
73
|
+
* philosophy as the kill switch's poll interval.
|
|
68
74
|
*/
|
|
69
75
|
declare function wrapLangChain<T extends LangChainModel>(model: T, opts: WrapOptions): T;
|
|
70
76
|
|
package/dist/index.js
CHANGED
|
@@ -406,7 +406,7 @@ function isKilled(agentName) {
|
|
|
406
406
|
|
|
407
407
|
// src/wrap.ts
|
|
408
408
|
var PATCHED = /* @__PURE__ */ Symbol("opsveritas.patched");
|
|
409
|
-
var OUTPUT_SUMMARY_MAX =
|
|
409
|
+
var OUTPUT_SUMMARY_MAX = 24e3;
|
|
410
410
|
var TOOL_INPUT_TEXT_FIELDS = ["body", "content", "text", "summary", "message", "output"];
|
|
411
411
|
function extractToolInputText(input) {
|
|
412
412
|
if (!input || typeof input !== "object") return void 0;
|
|
@@ -655,7 +655,7 @@ function extractText(output) {
|
|
|
655
655
|
const c = gen?.message?.content;
|
|
656
656
|
if (typeof c === "string") t = c;
|
|
657
657
|
}
|
|
658
|
-
if (typeof t === "string" && t.trim()) return t.slice(0,
|
|
658
|
+
if (typeof t === "string" && t.trim()) return t.slice(0, 24e3);
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
661
|
} catch {
|
|
@@ -721,22 +721,45 @@ function wrapLangChain(model, opts) {
|
|
|
721
721
|
const m = model;
|
|
722
722
|
if (m[LC_PATCHED]) return model;
|
|
723
723
|
startPolling(opts.agentName, "sdk");
|
|
724
|
+
const guard = () => {
|
|
725
|
+
const killState = isKilled(opts.agentName);
|
|
726
|
+
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
727
|
+
};
|
|
724
728
|
if (typeof m.invoke === "function") {
|
|
725
729
|
const origInvoke = m.invoke.bind(model);
|
|
726
730
|
m.invoke = function(...args) {
|
|
727
|
-
|
|
728
|
-
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
731
|
+
guard();
|
|
729
732
|
return origInvoke(...args);
|
|
730
733
|
};
|
|
731
734
|
}
|
|
732
735
|
if (typeof m.ainvoke === "function") {
|
|
733
736
|
const origAinvoke = m.ainvoke.bind(model);
|
|
734
737
|
m.ainvoke = async function(...args) {
|
|
735
|
-
|
|
736
|
-
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
738
|
+
guard();
|
|
737
739
|
return origAinvoke(...args);
|
|
738
740
|
};
|
|
739
741
|
}
|
|
742
|
+
if (typeof m.stream === "function") {
|
|
743
|
+
const origStream = m.stream.bind(model);
|
|
744
|
+
m.stream = function(...args) {
|
|
745
|
+
guard();
|
|
746
|
+
return origStream(...args);
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
if (typeof m.astream === "function") {
|
|
750
|
+
const origAstream = m.astream.bind(model);
|
|
751
|
+
m.astream = function(...args) {
|
|
752
|
+
guard();
|
|
753
|
+
return origAstream(...args);
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
if (typeof m.batch === "function") {
|
|
757
|
+
const origBatch = m.batch.bind(model);
|
|
758
|
+
m.batch = async function(...args) {
|
|
759
|
+
guard();
|
|
760
|
+
return origBatch(...args);
|
|
761
|
+
};
|
|
762
|
+
}
|
|
740
763
|
m[LC_PATCHED] = true;
|
|
741
764
|
return model;
|
|
742
765
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -372,7 +372,7 @@ function isKilled(agentName) {
|
|
|
372
372
|
|
|
373
373
|
// src/wrap.ts
|
|
374
374
|
var PATCHED = /* @__PURE__ */ Symbol("opsveritas.patched");
|
|
375
|
-
var OUTPUT_SUMMARY_MAX =
|
|
375
|
+
var OUTPUT_SUMMARY_MAX = 24e3;
|
|
376
376
|
var TOOL_INPUT_TEXT_FIELDS = ["body", "content", "text", "summary", "message", "output"];
|
|
377
377
|
function extractToolInputText(input) {
|
|
378
378
|
if (!input || typeof input !== "object") return void 0;
|
|
@@ -621,7 +621,7 @@ function extractText(output) {
|
|
|
621
621
|
const c = gen?.message?.content;
|
|
622
622
|
if (typeof c === "string") t = c;
|
|
623
623
|
}
|
|
624
|
-
if (typeof t === "string" && t.trim()) return t.slice(0,
|
|
624
|
+
if (typeof t === "string" && t.trim()) return t.slice(0, 24e3);
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
} catch {
|
|
@@ -687,22 +687,45 @@ function wrapLangChain(model, opts) {
|
|
|
687
687
|
const m = model;
|
|
688
688
|
if (m[LC_PATCHED]) return model;
|
|
689
689
|
startPolling(opts.agentName, "sdk");
|
|
690
|
+
const guard = () => {
|
|
691
|
+
const killState = isKilled(opts.agentName);
|
|
692
|
+
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
693
|
+
};
|
|
690
694
|
if (typeof m.invoke === "function") {
|
|
691
695
|
const origInvoke = m.invoke.bind(model);
|
|
692
696
|
m.invoke = function(...args) {
|
|
693
|
-
|
|
694
|
-
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
697
|
+
guard();
|
|
695
698
|
return origInvoke(...args);
|
|
696
699
|
};
|
|
697
700
|
}
|
|
698
701
|
if (typeof m.ainvoke === "function") {
|
|
699
702
|
const origAinvoke = m.ainvoke.bind(model);
|
|
700
703
|
m.ainvoke = async function(...args) {
|
|
701
|
-
|
|
702
|
-
if (killState.killed) throw new OpsVeritasKilledError(opts.agentName, killState.reason);
|
|
704
|
+
guard();
|
|
703
705
|
return origAinvoke(...args);
|
|
704
706
|
};
|
|
705
707
|
}
|
|
708
|
+
if (typeof m.stream === "function") {
|
|
709
|
+
const origStream = m.stream.bind(model);
|
|
710
|
+
m.stream = function(...args) {
|
|
711
|
+
guard();
|
|
712
|
+
return origStream(...args);
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
if (typeof m.astream === "function") {
|
|
716
|
+
const origAstream = m.astream.bind(model);
|
|
717
|
+
m.astream = function(...args) {
|
|
718
|
+
guard();
|
|
719
|
+
return origAstream(...args);
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
if (typeof m.batch === "function") {
|
|
723
|
+
const origBatch = m.batch.bind(model);
|
|
724
|
+
m.batch = async function(...args) {
|
|
725
|
+
guard();
|
|
726
|
+
return origBatch(...args);
|
|
727
|
+
};
|
|
728
|
+
}
|
|
706
729
|
m[LC_PATCHED] = true;
|
|
707
730
|
return model;
|
|
708
731
|
}
|