opsveritas-sdk 0.4.2 → 0.4.4
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +30 -6
- package/dist/index.mjs +29 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ declare function init(apiKey: string, options?: {
|
|
|
3
3
|
metadataOnly?: boolean;
|
|
4
4
|
}): void;
|
|
5
5
|
|
|
6
|
+
declare function reportAction(note: string, confirmed?: boolean): void;
|
|
6
7
|
declare function run<T>(agentName: string, fn: () => Promise<T>, opts?: {
|
|
7
8
|
userId?: string;
|
|
8
9
|
}): Promise<T>;
|
|
@@ -90,6 +91,7 @@ interface ExecutionPayload {
|
|
|
90
91
|
error_message?: string | null;
|
|
91
92
|
user_id?: string;
|
|
92
93
|
output_summary?: string;
|
|
94
|
+
action_confirmed?: boolean;
|
|
93
95
|
/** Set automatically by the SDK so the server can identify SDK vs raw-webhook ingestion. Not user-configurable. */
|
|
94
96
|
source?: 'sdk';
|
|
95
97
|
}
|
|
@@ -97,10 +99,11 @@ interface ExecutionPayload {
|
|
|
97
99
|
declare const OpsVeritas: {
|
|
98
100
|
init: typeof init;
|
|
99
101
|
run: typeof run;
|
|
102
|
+
reportAction: typeof reportAction;
|
|
100
103
|
trace: typeof trace;
|
|
101
104
|
wrap: typeof wrap;
|
|
102
105
|
langchain: typeof langchain;
|
|
103
106
|
wrapLangChain: typeof wrapLangChain;
|
|
104
107
|
};
|
|
105
108
|
|
|
106
|
-
export { type ExecutionPayload, type LangChainOptions, OpsVeritas, OpsVeritasKilledError, type TraceOptions, type WrapOptions, OpsVeritas as default, init, langchain, run, trace, wrap, wrapLangChain };
|
|
109
|
+
export { type ExecutionPayload, type LangChainOptions, OpsVeritas, OpsVeritasKilledError, type TraceOptions, type WrapOptions, OpsVeritas as default, init, langchain, reportAction, run, trace, wrap, wrapLangChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare function init(apiKey: string, options?: {
|
|
|
3
3
|
metadataOnly?: boolean;
|
|
4
4
|
}): void;
|
|
5
5
|
|
|
6
|
+
declare function reportAction(note: string, confirmed?: boolean): void;
|
|
6
7
|
declare function run<T>(agentName: string, fn: () => Promise<T>, opts?: {
|
|
7
8
|
userId?: string;
|
|
8
9
|
}): Promise<T>;
|
|
@@ -90,6 +91,7 @@ interface ExecutionPayload {
|
|
|
90
91
|
error_message?: string | null;
|
|
91
92
|
user_id?: string;
|
|
92
93
|
output_summary?: string;
|
|
94
|
+
action_confirmed?: boolean;
|
|
93
95
|
/** Set automatically by the SDK so the server can identify SDK vs raw-webhook ingestion. Not user-configurable. */
|
|
94
96
|
source?: 'sdk';
|
|
95
97
|
}
|
|
@@ -97,10 +99,11 @@ interface ExecutionPayload {
|
|
|
97
99
|
declare const OpsVeritas: {
|
|
98
100
|
init: typeof init;
|
|
99
101
|
run: typeof run;
|
|
102
|
+
reportAction: typeof reportAction;
|
|
100
103
|
trace: typeof trace;
|
|
101
104
|
wrap: typeof wrap;
|
|
102
105
|
langchain: typeof langchain;
|
|
103
106
|
wrapLangChain: typeof wrapLangChain;
|
|
104
107
|
};
|
|
105
108
|
|
|
106
|
-
export { type ExecutionPayload, type LangChainOptions, OpsVeritas, OpsVeritasKilledError, type TraceOptions, type WrapOptions, OpsVeritas as default, init, langchain, run, trace, wrap, wrapLangChain };
|
|
109
|
+
export { type ExecutionPayload, type LangChainOptions, OpsVeritas, OpsVeritasKilledError, type TraceOptions, type WrapOptions, OpsVeritas as default, init, langchain, reportAction, run, trace, wrap, wrapLangChain };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
default: () => index_default,
|
|
26
26
|
init: () => init,
|
|
27
27
|
langchain: () => langchain,
|
|
28
|
+
reportAction: () => reportAction,
|
|
28
29
|
run: () => run,
|
|
29
30
|
trace: () => trace,
|
|
30
31
|
wrap: () => wrap,
|
|
@@ -131,6 +132,13 @@ var storage = new import_async_hooks.AsyncLocalStorage();
|
|
|
131
132
|
function getActiveRun() {
|
|
132
133
|
return storage.getStore();
|
|
133
134
|
}
|
|
135
|
+
function reportAction(note, confirmed = true) {
|
|
136
|
+
const ctx = getActiveRun();
|
|
137
|
+
if (!ctx) return;
|
|
138
|
+
if (note) ctx.actionNotes.push(note);
|
|
139
|
+
if (confirmed === false) ctx.actionConfirmed = false;
|
|
140
|
+
else if (ctx.actionConfirmed === void 0) ctx.actionConfirmed = true;
|
|
141
|
+
}
|
|
134
142
|
async function run(agentName, fn, opts) {
|
|
135
143
|
const ctx = {
|
|
136
144
|
agentName,
|
|
@@ -138,7 +146,9 @@ async function run(agentName, fn, opts) {
|
|
|
138
146
|
startTime: Date.now(),
|
|
139
147
|
executedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
140
148
|
calls: [],
|
|
141
|
-
status: "success"
|
|
149
|
+
status: "success",
|
|
150
|
+
actionNotes: [],
|
|
151
|
+
actionConfirmed: void 0
|
|
142
152
|
};
|
|
143
153
|
return storage.run(ctx, async () => {
|
|
144
154
|
try {
|
|
@@ -154,6 +164,8 @@ async function run(agentName, fn, opts) {
|
|
|
154
164
|
const totalCost = ctx.calls.reduce((s, c) => s + (c.costUsd ?? 0), 0);
|
|
155
165
|
const models = [...new Set(ctx.calls.map((c) => c.model).filter((m) => !!m))];
|
|
156
166
|
const platform = ctx.calls[0]?.platform ?? "custom_webhook";
|
|
167
|
+
const callSummary = [...ctx.calls].reverse().find((c) => c.outputSummary)?.outputSummary;
|
|
168
|
+
const outputSummary = [callSummary, ...ctx.actionNotes].filter(Boolean).join("\n\n") || void 0;
|
|
157
169
|
const payload = {
|
|
158
170
|
platform,
|
|
159
171
|
agent_name: agentName,
|
|
@@ -167,6 +179,8 @@ async function run(agentName, fn, opts) {
|
|
|
167
179
|
if (totalCost) payload.cost_usd = Math.round(totalCost * 1e6) / 1e6;
|
|
168
180
|
if (models.length) payload.models = models;
|
|
169
181
|
if (ctx.userId) payload.user_id = ctx.userId;
|
|
182
|
+
if (outputSummary) payload.output_summary = outputSummary;
|
|
183
|
+
if (ctx.actionConfirmed !== void 0) payload.action_confirmed = ctx.actionConfirmed;
|
|
170
184
|
void sendExecution(payload);
|
|
171
185
|
}
|
|
172
186
|
});
|
|
@@ -471,7 +485,7 @@ function patchOpenAI(client, opts) {
|
|
|
471
485
|
const cost_usd = model && input_tokens != null && output_tokens != null ? calcCost(String(model), input_tokens, output_tokens) : void 0;
|
|
472
486
|
const activeRun = getActiveRun();
|
|
473
487
|
if (activeRun) {
|
|
474
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
488
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
475
489
|
} else {
|
|
476
490
|
void sendExecution({
|
|
477
491
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -523,7 +537,7 @@ function patchAnthropic(client, opts) {
|
|
|
523
537
|
const cost_usd = model && input_tokens != null && output_tokens != null ? calcCost(String(model), input_tokens, output_tokens) : void 0;
|
|
524
538
|
const activeRun = getActiveRun();
|
|
525
539
|
if (activeRun) {
|
|
526
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
540
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
527
541
|
} else {
|
|
528
542
|
void sendExecution({
|
|
529
543
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -573,7 +587,7 @@ function patchGemini(client, opts) {
|
|
|
573
587
|
const cost_usd = modelName && input_tokens != null && output_tokens != null ? calcCost(modelName, input_tokens, output_tokens) : void 0;
|
|
574
588
|
const activeRun = getActiveRun();
|
|
575
589
|
if (activeRun) {
|
|
576
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: modelName, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
590
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: modelName, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
577
591
|
} else {
|
|
578
592
|
void sendExecution({
|
|
579
593
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -677,7 +691,16 @@ function langchain(agentName, opts = {}) {
|
|
|
677
691
|
const cost_usd = model && inputTokens != null && outputTokens != null ? calcCost(model, inputTokens, outputTokens) : void 0;
|
|
678
692
|
const activeRun = getActiveRun();
|
|
679
693
|
if (activeRun) {
|
|
680
|
-
activeRun.calls.push({
|
|
694
|
+
activeRun.calls.push({
|
|
695
|
+
platform,
|
|
696
|
+
model,
|
|
697
|
+
inputTokens,
|
|
698
|
+
outputTokens,
|
|
699
|
+
costUsd: cost_usd,
|
|
700
|
+
status,
|
|
701
|
+
errorMessage,
|
|
702
|
+
outputSummary: output ? extractText(output) : void 0
|
|
703
|
+
});
|
|
681
704
|
} else {
|
|
682
705
|
void sendExecution({
|
|
683
706
|
platform,
|
|
@@ -765,7 +788,7 @@ function wrapLangChain(model, opts) {
|
|
|
765
788
|
}
|
|
766
789
|
|
|
767
790
|
// src/index.ts
|
|
768
|
-
var OpsVeritas = { init, run, trace, wrap, langchain, wrapLangChain };
|
|
791
|
+
var OpsVeritas = { init, run, reportAction, trace, wrap, langchain, wrapLangChain };
|
|
769
792
|
var index_default = OpsVeritas;
|
|
770
793
|
// Annotate the CommonJS export names for ESM import in node:
|
|
771
794
|
0 && (module.exports = {
|
|
@@ -773,6 +796,7 @@ var index_default = OpsVeritas;
|
|
|
773
796
|
OpsVeritasKilledError,
|
|
774
797
|
init,
|
|
775
798
|
langchain,
|
|
799
|
+
reportAction,
|
|
776
800
|
run,
|
|
777
801
|
trace,
|
|
778
802
|
wrap,
|
package/dist/index.mjs
CHANGED
|
@@ -97,6 +97,13 @@ var storage = new AsyncLocalStorage();
|
|
|
97
97
|
function getActiveRun() {
|
|
98
98
|
return storage.getStore();
|
|
99
99
|
}
|
|
100
|
+
function reportAction(note, confirmed = true) {
|
|
101
|
+
const ctx = getActiveRun();
|
|
102
|
+
if (!ctx) return;
|
|
103
|
+
if (note) ctx.actionNotes.push(note);
|
|
104
|
+
if (confirmed === false) ctx.actionConfirmed = false;
|
|
105
|
+
else if (ctx.actionConfirmed === void 0) ctx.actionConfirmed = true;
|
|
106
|
+
}
|
|
100
107
|
async function run(agentName, fn, opts) {
|
|
101
108
|
const ctx = {
|
|
102
109
|
agentName,
|
|
@@ -104,7 +111,9 @@ async function run(agentName, fn, opts) {
|
|
|
104
111
|
startTime: Date.now(),
|
|
105
112
|
executedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
106
113
|
calls: [],
|
|
107
|
-
status: "success"
|
|
114
|
+
status: "success",
|
|
115
|
+
actionNotes: [],
|
|
116
|
+
actionConfirmed: void 0
|
|
108
117
|
};
|
|
109
118
|
return storage.run(ctx, async () => {
|
|
110
119
|
try {
|
|
@@ -120,6 +129,8 @@ async function run(agentName, fn, opts) {
|
|
|
120
129
|
const totalCost = ctx.calls.reduce((s, c) => s + (c.costUsd ?? 0), 0);
|
|
121
130
|
const models = [...new Set(ctx.calls.map((c) => c.model).filter((m) => !!m))];
|
|
122
131
|
const platform = ctx.calls[0]?.platform ?? "custom_webhook";
|
|
132
|
+
const callSummary = [...ctx.calls].reverse().find((c) => c.outputSummary)?.outputSummary;
|
|
133
|
+
const outputSummary = [callSummary, ...ctx.actionNotes].filter(Boolean).join("\n\n") || void 0;
|
|
123
134
|
const payload = {
|
|
124
135
|
platform,
|
|
125
136
|
agent_name: agentName,
|
|
@@ -133,6 +144,8 @@ async function run(agentName, fn, opts) {
|
|
|
133
144
|
if (totalCost) payload.cost_usd = Math.round(totalCost * 1e6) / 1e6;
|
|
134
145
|
if (models.length) payload.models = models;
|
|
135
146
|
if (ctx.userId) payload.user_id = ctx.userId;
|
|
147
|
+
if (outputSummary) payload.output_summary = outputSummary;
|
|
148
|
+
if (ctx.actionConfirmed !== void 0) payload.action_confirmed = ctx.actionConfirmed;
|
|
136
149
|
void sendExecution(payload);
|
|
137
150
|
}
|
|
138
151
|
});
|
|
@@ -437,7 +450,7 @@ function patchOpenAI(client, opts) {
|
|
|
437
450
|
const cost_usd = model && input_tokens != null && output_tokens != null ? calcCost(String(model), input_tokens, output_tokens) : void 0;
|
|
438
451
|
const activeRun = getActiveRun();
|
|
439
452
|
if (activeRun) {
|
|
440
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
453
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
441
454
|
} else {
|
|
442
455
|
void sendExecution({
|
|
443
456
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -489,7 +502,7 @@ function patchAnthropic(client, opts) {
|
|
|
489
502
|
const cost_usd = model && input_tokens != null && output_tokens != null ? calcCost(String(model), input_tokens, output_tokens) : void 0;
|
|
490
503
|
const activeRun = getActiveRun();
|
|
491
504
|
if (activeRun) {
|
|
492
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
505
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: model ? String(model) : void 0, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
493
506
|
} else {
|
|
494
507
|
void sendExecution({
|
|
495
508
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -539,7 +552,7 @@ function patchGemini(client, opts) {
|
|
|
539
552
|
const cost_usd = modelName && input_tokens != null && output_tokens != null ? calcCost(modelName, input_tokens, output_tokens) : void 0;
|
|
540
553
|
const activeRun = getActiveRun();
|
|
541
554
|
if (activeRun) {
|
|
542
|
-
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: modelName, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage });
|
|
555
|
+
activeRun.calls.push({ platform: opts.platform ?? "custom_webhook", model: modelName, inputTokens: input_tokens, outputTokens: output_tokens, costUsd: cost_usd, status, errorMessage, outputSummary: extractOutput(resp) });
|
|
543
556
|
} else {
|
|
544
557
|
void sendExecution({
|
|
545
558
|
platform: opts.platform ?? "custom_webhook",
|
|
@@ -643,7 +656,16 @@ function langchain(agentName, opts = {}) {
|
|
|
643
656
|
const cost_usd = model && inputTokens != null && outputTokens != null ? calcCost(model, inputTokens, outputTokens) : void 0;
|
|
644
657
|
const activeRun = getActiveRun();
|
|
645
658
|
if (activeRun) {
|
|
646
|
-
activeRun.calls.push({
|
|
659
|
+
activeRun.calls.push({
|
|
660
|
+
platform,
|
|
661
|
+
model,
|
|
662
|
+
inputTokens,
|
|
663
|
+
outputTokens,
|
|
664
|
+
costUsd: cost_usd,
|
|
665
|
+
status,
|
|
666
|
+
errorMessage,
|
|
667
|
+
outputSummary: output ? extractText(output) : void 0
|
|
668
|
+
});
|
|
647
669
|
} else {
|
|
648
670
|
void sendExecution({
|
|
649
671
|
platform,
|
|
@@ -731,7 +753,7 @@ function wrapLangChain(model, opts) {
|
|
|
731
753
|
}
|
|
732
754
|
|
|
733
755
|
// src/index.ts
|
|
734
|
-
var OpsVeritas = { init, run, trace, wrap, langchain, wrapLangChain };
|
|
756
|
+
var OpsVeritas = { init, run, reportAction, trace, wrap, langchain, wrapLangChain };
|
|
735
757
|
var index_default = OpsVeritas;
|
|
736
758
|
export {
|
|
737
759
|
OpsVeritas,
|
|
@@ -739,6 +761,7 @@ export {
|
|
|
739
761
|
index_default as default,
|
|
740
762
|
init,
|
|
741
763
|
langchain,
|
|
764
|
+
reportAction,
|
|
742
765
|
run,
|
|
743
766
|
trace,
|
|
744
767
|
wrap,
|