@argosvix/sdk 0.4.22-alpha.0 → 0.5.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 +4 -9
- package/dist/aiSdkMiddleware.d.ts +36 -20
- package/dist/aiSdkMiddleware.d.ts.map +1 -1
- package/dist/aiSdkMiddleware.js +98 -31
- package/dist/aiSdkMiddleware.js.map +1 -1
- package/dist/approvals.d.ts +37 -29
- package/dist/approvals.d.ts.map +1 -1
- package/dist/approvals.js +24 -18
- package/dist/approvals.js.map +1 -1
- package/dist/budgetGate.d.ts +30 -24
- package/dist/budgetGate.d.ts.map +1 -1
- package/dist/budgetGate.js +118 -92
- package/dist/budgetGate.js.map +1 -1
- package/dist/client.d.ts +15 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +271 -222
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +59 -48
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +72 -58
- package/dist/context.js.map +1 -1
- package/dist/flush.d.ts +6 -4
- package/dist/flush.d.ts.map +1 -1
- package/dist/flush.js +6 -4
- package/dist/flush.js.map +1 -1
- package/dist/ids.d.ts +3 -2
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +6 -5
- package/dist/ids.js.map +1 -1
- package/dist/langchainCallback.d.ts +14 -13
- package/dist/langchainCallback.d.ts.map +1 -1
- package/dist/langchainCallback.js +22 -17
- package/dist/langchainCallback.js.map +1 -1
- package/dist/policyScan.d.ts +29 -22
- package/dist/policyScan.d.ts.map +1 -1
- package/dist/policyScan.js +47 -38
- package/dist/policyScan.js.map +1 -1
- package/dist/pricing.d.ts +5 -5
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +24 -22
- package/dist/pricing.js.map +1 -1
- package/dist/prompts.d.ts +20 -17
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +21 -17
- package/dist/prompts.js.map +1 -1
- package/dist/query.d.ts +21 -21
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +14 -14
- package/dist/recorder.d.ts +39 -19
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +120 -69
- package/dist/recorder.js.map +1 -1
- package/dist/redaction.d.ts +35 -33
- package/dist/redaction.d.ts.map +1 -1
- package/dist/redaction.js +73 -64
- package/dist/redaction.js.map +1 -1
- package/dist/types.d.ts +131 -114
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +9 -9
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -9
- package/dist/version.js.map +1 -1
- package/package.json +8 -2
package/dist/redaction.js
CHANGED
|
@@ -1,87 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plaintext PII redaction for the captureContent opt-in path.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Helper that automatically masks email addresses / credit card numbers /
|
|
5
|
+
* phone numbers / Japanese My Number / IP addresses before prompt and
|
|
6
|
+
* completion bodies are sent verbatim under the Pro+ plaintext storage
|
|
7
|
+
* feature's SDK-side opt-in.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
9
|
+
* Design policy:
|
|
10
|
+
* - False-positive tolerant, false negatives strictly avoided (over-masking
|
|
11
|
+
* is OK; missing PII is not). This function always runs unless the user
|
|
12
|
+
* explicitly disables it with disablePiiRedaction:true.
|
|
13
|
+
* - Pure function with no side effects. Same input always yields same output.
|
|
14
|
+
* - An empty string or null / undefined input is returned as-is.
|
|
15
|
+
* - Non-string input (objects etc.) is stringified with String() before
|
|
16
|
+
* replacement; the original type is not preserved — a string is returned.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* -
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
18
|
+
* Known limitations:
|
|
19
|
+
* - International phone number formats are too diverse to cover fully.
|
|
20
|
+
* Conservative patterns focus on the major Japanese forms
|
|
21
|
+
* (+81-XX-XXXX-XXXX / 090-XXXX-XXXX etc.) and the North American
|
|
22
|
+
* (123) 456-7890 form.
|
|
23
|
+
* - Credit card numbers are not Luhn-checked (false-positive tolerant).
|
|
24
|
+
* Any run of 13-19 digits (including space and hyphen separators) is
|
|
25
|
+
* replaced uniformly.
|
|
26
|
+
* - My Number is 12 digits. Where it collides with the credit card pattern,
|
|
27
|
+
* the 12-digit run may match the CC pattern first — either way both get
|
|
28
|
+
* replaced, so there is no PII-leak risk (only the masking category may
|
|
29
|
+
* be inaccurate).
|
|
27
30
|
*/
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
30
|
-
* redaction_metadata
|
|
31
|
-
*
|
|
32
|
+
* Each pattern carries a type tag so we can aggregate a counts JSON into the
|
|
33
|
+
* backend's redaction_metadata column — each regex declares which category it
|
|
34
|
+
* belongs to. metadata = { email: N, creditCard: N, ... }.
|
|
32
35
|
*/
|
|
33
36
|
const PATTERNS = [
|
|
34
|
-
// Email
|
|
35
|
-
// (
|
|
36
|
-
// local/domain/TLD
|
|
37
|
+
// Email, RFC 5322 based. An earlier ASCII-only pattern missed IDN domains
|
|
38
|
+
// (e.g. Japanese-script domains under .jp) and non-ASCII local parts.
|
|
39
|
+
// Following the false-positive-tolerant policy, local/domain/TLD are widened
|
|
40
|
+
// to any non-whitespace, non-@ characters so internationalized addresses are
|
|
41
|
+
// also captured.
|
|
37
42
|
{
|
|
38
43
|
regex: /[^\s@]+@[^\s@]+\.[^\s@]{2,}/g,
|
|
39
44
|
replacement: "[REDACTED_EMAIL]",
|
|
40
45
|
type: "email",
|
|
41
46
|
},
|
|
42
|
-
// Credit card (
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
+
// Credit card (also covers numbers spanning newlines and whitespace).
|
|
48
|
+
// A "\d sep \d sep ..." structure would make the trailing separator demand a
|
|
49
|
+
// following digit, breaking the match for newline-spanning cases like
|
|
50
|
+
// 4111-1111-\n1111-1111 (found in review). Using a leading \d followed by
|
|
51
|
+
// (sep* \d){12,18} allows multiple consecutive separators, so newlines and
|
|
52
|
+
// repeated spaces are swallowed too.
|
|
47
53
|
{
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
54
|
+
// '.' added to the separator set (found in review): the old pattern only
|
|
55
|
+
// allowed space/tab/newline/hyphen, so dot-separated numbers
|
|
56
|
+
// (4111.1111.1111.1111) did not match as CC, got partially consumed by the
|
|
57
|
+
// later phone pattern, and left the last 4 digits in plaintext. Since CC
|
|
58
|
+
// runs before phone, including dots as CC separators redacts all digits
|
|
59
|
+
// (false-positive-tolerant policy).
|
|
52
60
|
regex: /\b\d(?:[ \t\r\n.-]*\d){12,18}\b/g,
|
|
53
61
|
replacement: "[REDACTED_CC]",
|
|
54
62
|
type: "creditCard",
|
|
55
63
|
},
|
|
56
|
-
//
|
|
57
|
-
// (
|
|
64
|
+
// Japanese My Number = 12 digits, delimited by word boundaries
|
|
65
|
+
// (the CC pattern above runs first, so 12-13 digit overlaps are handled as CC)
|
|
58
66
|
{
|
|
59
67
|
regex: /\b\d{12}\b/g,
|
|
60
68
|
replacement: "[REDACTED_MYNUMBER]",
|
|
61
69
|
type: "myNumber",
|
|
62
70
|
},
|
|
63
|
-
//
|
|
64
|
-
// -
|
|
65
|
-
// -
|
|
66
|
-
// -
|
|
67
|
-
// -
|
|
71
|
+
// Phone numbers = representative patterns for major countries:
|
|
72
|
+
// - Japan mobile: 090-XXXX-XXXX / 080-XXXX-XXXX / 070-XXXX-XXXX
|
|
73
|
+
// - Japan landline: 03-XXXX-XXXX / 06-XXXX-XXXX etc.
|
|
74
|
+
// - International: +81 90 XXXX XXXX / +1 (123) 456-7890
|
|
75
|
+
// - Fullwidth hyphens and middle dots are out of scope (ASCII assumed)
|
|
68
76
|
{
|
|
69
77
|
regex: /\+?\d{1,3}[-.\s]?\(?\d{2,4}\)?[-.\s]?\d{2,4}[-.\s]?\d{3,4}/g,
|
|
70
78
|
replacement: "[REDACTED_PHONE]",
|
|
71
79
|
type: "phone",
|
|
72
80
|
},
|
|
73
|
-
// IPv4 = 4
|
|
81
|
+
// IPv4 = 4 octets; the 0-255 range is not strictly checked — kept conservative
|
|
74
82
|
{
|
|
75
83
|
regex: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g,
|
|
76
84
|
replacement: "[REDACTED_IPV4]",
|
|
77
85
|
type: "ipv4",
|
|
78
86
|
},
|
|
79
|
-
// IPv6 (
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// `(?:[0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{1,4}`
|
|
83
|
-
//
|
|
84
|
-
//
|
|
87
|
+
// IPv6 (full + shortened forms). To also catch shortened notations like
|
|
88
|
+
// `::1` (found in review), each hex group allows 0-4 digits (an empty group
|
|
89
|
+
// matches "::"), with lookbehind / lookahead providing the word boundaries.
|
|
90
|
+
// `(?:[0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{1,4}` bundles `::1` / `fe80::1234`
|
|
91
|
+
// and the ordinary 8-group form (false-positive tolerant, false negatives
|
|
92
|
+
// strictly avoided).
|
|
85
93
|
{
|
|
86
94
|
regex: /(?<![\w:.])(?:[0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{1,4}(?![\w:.])/g,
|
|
87
95
|
replacement: "[REDACTED_IPV6]",
|
|
@@ -95,11 +103,12 @@ const PATTERNS = [
|
|
|
95
103
|
* @returns The text with PII patterns replaced by [REDACTED_*] markers.
|
|
96
104
|
*/
|
|
97
105
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* \d (
|
|
101
|
-
*
|
|
102
|
-
*
|
|
106
|
+
* Normalize fullwidth digits (U+FF10..FF19) to ASCII. Fullwidth credit card
|
|
107
|
+
* numbers, My Number, phone numbers, and IPs typed via a Japanese IME slipped
|
|
108
|
+
* straight past the \d (ASCII [0-9]) based PII patterns — a false negative.
|
|
109
|
+
* Normalizing before matching reliably captures fullwidth PII too (the side
|
|
110
|
+
* effect that non-PII fullwidth digits become halfwidth is accepted under the
|
|
111
|
+
* false-positive-tolerant policy).
|
|
103
112
|
*/
|
|
104
113
|
function normalizeFullwidthDigits(s) {
|
|
105
114
|
return s.replace(/[0-9]/g, (c) => String.fromCharCode(c.charCodeAt(0) - 0xfee0));
|
|
@@ -120,12 +129,12 @@ export function redactPii(input) {
|
|
|
120
129
|
return result;
|
|
121
130
|
}
|
|
122
131
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* SDK
|
|
132
|
+
* Perform the same redaction while simultaneously counting how many
|
|
133
|
+
* replacements occurred per type. Feeds the backend redaction_metadata JSON
|
|
134
|
+
* and the SDK-side "did this contain PII" decision (the piiRedacted boolean).
|
|
126
135
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
136
|
+
* Counts are taken via match, then the replacement is applied. The regexes use
|
|
137
|
+
* the g flag, so running them twice has no side effects.
|
|
129
138
|
*/
|
|
130
139
|
export function redactPiiWithCounts(input) {
|
|
131
140
|
if (input == null)
|
|
@@ -146,8 +155,8 @@ export function redactPiiWithCounts(input) {
|
|
|
146
155
|
return { text: result, counts };
|
|
147
156
|
}
|
|
148
157
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
158
|
+
* Helper that sums the counts from multiple redaction results (prompt /
|
|
159
|
+
* completion / each tool call).
|
|
151
160
|
*/
|
|
152
161
|
export function mergeRedactionCounts(base, addition) {
|
|
153
162
|
const out = { ...base };
|
|
@@ -157,8 +166,8 @@ export function mergeRedactionCounts(base, addition) {
|
|
|
157
166
|
return out;
|
|
158
167
|
}
|
|
159
168
|
/**
|
|
160
|
-
*
|
|
161
|
-
* piiRedacted boolean field
|
|
169
|
+
* Whether the counts object contains at least one redaction.
|
|
170
|
+
* The basis for the piiRedacted boolean field.
|
|
162
171
|
*/
|
|
163
172
|
export function hasAnyRedaction(counts) {
|
|
164
173
|
for (const v of Object.values(counts)) {
|
package/dist/redaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;GAIG;AACH,MAAM,QAAQ,GAAuE;IACnF,0EAA0E;IAC1E,sEAAsE;IACtE,6EAA6E;IAC7E,6EAA6E;IAC7E,iBAAiB;IACjB;QACE,KAAK,EAAE,8BAA8B;QACrC,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,OAAO;KACd;IACD,sEAAsE;IACtE,6EAA6E;IAC7E,sEAAsE;IACtE,0EAA0E;IAC1E,2EAA2E;IAC3E,qCAAqC;IACrC;QACE,yEAAyE;QACzE,6DAA6D;QAC7D,2EAA2E;QAC3E,yEAAyE;QACzE,wEAAwE;QACxE,oCAAoC;QACpC,KAAK,EAAE,kCAAkC;QACzC,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,YAAY;KACnB;IACD,+DAA+D;IAC/D,+EAA+E;IAC/E;QACE,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,UAAU;KACjB;IACD,+DAA+D;IAC/D,kEAAkE;IAClE,uDAAuD;IACvD,0DAA0D;IAC1D,yEAAyE;IACzE;QACE,KAAK,EAAE,6DAA6D;QACpE,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,OAAO;KACd;IACD,+EAA+E;IAC/E;QACE,KAAK,EAAE,8BAA8B;QACrC,WAAW,EAAE,iBAAiB;QAC9B,IAAI,EAAE,MAAM;KACb;IACD,wEAA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AC,EAAE,CAAC;QACtC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAI9B;IACC,MAAM,GAAG,GAA0D;QACjE,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;IACF,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACjC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC9B,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,19 +7,23 @@ export interface ArgosvixConfig {
|
|
|
7
7
|
/** Tags attached to every record (e.g. service / env / userId). */
|
|
8
8
|
tags?: Record<string, string>;
|
|
9
9
|
/**
|
|
10
|
-
* provider
|
|
11
|
-
* Anthropic: metadata.user_id)
|
|
12
|
-
*
|
|
13
|
-
* (/users)
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
10
|
+
* Whether to automatically map the provider's opaque end-user identifier
|
|
11
|
+
* (OpenAI: safety_identifier, Anthropic: metadata.user_id) into the `userId`
|
|
12
|
+
* tag. Defaults to true. Apps already passing these to the provider get the
|
|
13
|
+
* dashboard's per-user aggregation (/users) with zero configuration. The
|
|
14
|
+
* legacy OpenAI `user` field is excluded because it tends to contain PII
|
|
15
|
+
* (pass an explicit `tags.userId` if needed). An explicit `tags.userId`
|
|
16
|
+
* takes precedence (it is never overwritten). Set false only to disable the
|
|
17
|
+
* automatic capture.
|
|
16
18
|
*/
|
|
17
19
|
captureUserId?: boolean;
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* Automatic trace-context propagation. On by default. LLM calls wrapped
|
|
22
|
+
* inside `withTrace(fn)` are automatically grouped into the same trace
|
|
23
|
+
* without an explicit traceId. Setting false ignores the ambient context and
|
|
24
|
+
* builds traces only from an explicit config.traceId, as before.
|
|
25
|
+
* Automatically disabled on runtimes without AsyncLocalStorage (e.g. Workers
|
|
26
|
+
* without the nodejs_als flag).
|
|
23
27
|
*/
|
|
24
28
|
autoContext?: boolean;
|
|
25
29
|
/** Disable record submission entirely (e.g. for local dev). Defaults to false. */
|
|
@@ -48,117 +52,127 @@ export interface ArgosvixConfig {
|
|
|
48
52
|
*/
|
|
49
53
|
provider?: Provider;
|
|
50
54
|
/**
|
|
51
|
-
* Trace ID =
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* trace
|
|
55
|
-
*
|
|
56
|
-
*
|
|
55
|
+
* Trace ID = the trace axis of the OTel subset (the group of related LLM
|
|
56
|
+
* calls within one user request / job). When passed to wrap(), it is
|
|
57
|
+
* automatically attached to every call record from this client (one wrap =
|
|
58
|
+
* one trace). To share a trace across a multi-call chain, wrap with the same
|
|
59
|
+
* traceId; for a different chain, use a separate wrap or the override
|
|
60
|
+
* option. The format is up to the user (OTel hex / UUID / ULID / arbitrary
|
|
61
|
+
* string), max 128 chars.
|
|
57
62
|
*/
|
|
58
63
|
traceId?: string;
|
|
59
64
|
/**
|
|
60
|
-
* Span ID =
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
+
* Span ID = the span identifier for the LLM calls issued by the wrapped
|
|
66
|
+
* client. Deriving it dynamically per call is usually cleaner than fixing it
|
|
67
|
+
* per wrap (a per-call option is planned for a later phase). The MVP allows
|
|
68
|
+
* one wrap = one span via the wrap option (sub-calls inherit automatically),
|
|
69
|
+
* though in practice a traceId alone is often sufficient.
|
|
65
70
|
*/
|
|
66
71
|
spanId?: string;
|
|
67
72
|
/**
|
|
68
|
-
* Parent span ID =
|
|
69
|
-
*
|
|
70
|
-
*
|
|
73
|
+
* Parent span ID = the span_id of this call's upstream / preceding call.
|
|
74
|
+
* Fixing it per wrap targets the simple case where all sub LLM calls of a
|
|
75
|
+
* given step share the same parent.
|
|
71
76
|
*/
|
|
72
77
|
parentSpanId?: string;
|
|
73
78
|
/**
|
|
74
|
-
* Session ID = user
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
79
|
+
* Session ID = an arbitrary user-defined grouping axis (a continuous
|
|
80
|
+
* conversation / the same daily session / the same job). A higher-level
|
|
81
|
+
* concept than a trace (the OTel-style call group within one request); one
|
|
82
|
+
* session may contain multiple traces. When passed to wrap(), it is
|
|
83
|
+
* automatically attached to every call record and flows through the backend
|
|
84
|
+
* /v1/query/session/:id into the dashboard's conversation thread view. The
|
|
85
|
+
* format is up to the user (UUID / ULID / arbitrary string), max 128 chars
|
|
86
|
+
* [A-Za-z0-9_-].
|
|
80
87
|
*
|
|
81
|
-
* 2026-06-02 v0.4.0
|
|
88
|
+
* Added 2026-06-02 in v0.4.0 (SDK side of session tracking).
|
|
82
89
|
*/
|
|
83
90
|
sessionId?: string;
|
|
84
91
|
/**
|
|
85
|
-
* Enable plaintext content capture (
|
|
86
|
-
* Default false
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
92
|
+
* Enable plaintext content capture (the SDK-side opt-in for the Pro+
|
|
93
|
+
* plaintext storage feature). Default false. When true, each wrapper
|
|
94
|
+
* extracts the prompt / completion bodies and tool call arguments/results,
|
|
95
|
+
* attaches them to the record, and sends them to the backend. They are
|
|
96
|
+
* stored encrypted only when account.plaintext_storage_optin = 1 on the
|
|
97
|
+
* backend (a global gate via the PLAINTEXT_STORAGE_ENABLED env is also applied).
|
|
90
98
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* https://argosvix.com/ja/docs/plaintext
|
|
99
|
+
* Before setting this flag to true, you must enable the plaintext storage
|
|
100
|
+
* feature in the dashboard settings and give explicit consent in the consent
|
|
101
|
+
* dialog. See https://argosvix.com/ja/docs/plaintext for details.
|
|
94
102
|
*/
|
|
95
103
|
captureContent?: boolean;
|
|
96
104
|
/**
|
|
97
105
|
* Disable the built-in PII redaction filter that masks email / credit card /
|
|
98
|
-
* phone /
|
|
99
|
-
* is ON)
|
|
100
|
-
*
|
|
106
|
+
* phone / Japanese My Number / IP address before send. Default false
|
|
107
|
+
* (redaction is ON). When true, content is sent unmodified — the user bears
|
|
108
|
+
* the risk of personal data exposure (Terms of Service, Article 4-2,
|
|
109
|
+
* Paragraph 7).
|
|
101
110
|
*
|
|
102
|
-
* captureContent
|
|
111
|
+
* When captureContent is false, no plaintext is sent at all, so this flag
|
|
112
|
+
* has no effect.
|
|
103
113
|
*/
|
|
104
114
|
disablePiiRedaction?: boolean;
|
|
105
115
|
/**
|
|
106
|
-
* Project ID
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* `X-Project-Id` header
|
|
110
|
-
*
|
|
116
|
+
* Project ID. Used when observing multiple products under one account,
|
|
117
|
+
* switching between them. Pro = up to 5 projects, Team = unlimited. When
|
|
118
|
+
* passed to wrap(), it is automatically attached to the backend ingest path
|
|
119
|
+
* as the `X-Project-Id` header (records get associated with that project).
|
|
120
|
+
* When unset, records attach to the account's default project.
|
|
111
121
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
122
|
+
* A project_id not belonging to the account or already archived returns 404
|
|
123
|
+
* from the backend; a malformed one (outside /^[A-Za-z0-9_-]{1,128}$/)
|
|
124
|
+
* returns 400 (fail-closed).
|
|
114
125
|
*
|
|
115
|
-
*
|
|
116
|
-
* dashboard
|
|
126
|
+
* Details: https://argosvix.com/ja/docs/projects, or get the project list
|
|
127
|
+
* and IDs from the dashboard under Settings → Projects.
|
|
117
128
|
*/
|
|
118
129
|
projectId?: string;
|
|
119
130
|
/**
|
|
120
|
-
*
|
|
121
|
-
* true
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
131
|
+
* Opt-in for the runtime budget gate (part of the runtime control plane).
|
|
132
|
+
* When true, before each LLM call on a wrapped client, the SDK locally
|
|
133
|
+
* evaluates the monthly budget settings plus current-month spend from the
|
|
134
|
+
* backend `/v1/gate/budget`, and if the limit is exceeded it throws
|
|
135
|
+
* ArgosvixBudgetExceededError to stop the call. Settings and spend use a TTL
|
|
136
|
+
* cache (default 60s) — no round trip per call. A no-op on accounts without
|
|
137
|
+
* a configured gate. Default false.
|
|
126
138
|
*
|
|
127
|
-
*
|
|
128
|
-
* `messages.stream()
|
|
129
|
-
*
|
|
130
|
-
*
|
|
139
|
+
* Known limitation: methods the SDK does not wrap (e.g. Anthropic
|
|
140
|
+
* `messages.stream()`, paths outside observation) are also outside
|
|
141
|
+
* enforcement. See the README for the list of wrapped methods. To enforce
|
|
142
|
+
* limits reliably, use only wrapped methods.
|
|
131
143
|
*/
|
|
132
144
|
budgetGate?: boolean;
|
|
133
145
|
/**
|
|
134
|
-
*
|
|
135
|
-
* true
|
|
136
|
-
* PII block / secret block)
|
|
137
|
-
* ArgosvixPolicyViolationError
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
146
|
+
* Opt-in for the runtime policy gate (part of the runtime control plane).
|
|
147
|
+
* When true, before each LLM call the SDK locally evaluates the backend's
|
|
148
|
+
* policy settings (model allowlist / PII block / secret block) and on a
|
|
149
|
+
* violation throws ArgosvixPolicyViolationError to stop the call. Evaluation
|
|
150
|
+
* runs inside the customer's process, not through a proxy. A no-op on
|
|
151
|
+
* accounts without a policy. Can be opted into independently of budgetGate;
|
|
152
|
+
* both share the same settings fetch (/v1/gate/config). Default false.
|
|
141
153
|
*/
|
|
142
154
|
policyGate?: boolean;
|
|
143
155
|
/**
|
|
144
|
-
* budgetGate / policyGate
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
156
|
+
* Behavior while budgetGate / policyGate is true but the gate settings have
|
|
157
|
+
* never been fetched from the backend. Default false (fail-open, calls pass).
|
|
158
|
+
* When true, all calls are stopped with ArgosvixBudgetGateUnavailableError
|
|
159
|
+
* until the fetch succeeds (a strict-operation opt-in). After the fetch, the
|
|
160
|
+
* backend-side gate's enforceMode applies.
|
|
148
161
|
*/
|
|
149
162
|
budgetGateFailClosed?: boolean;
|
|
150
163
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
164
|
+
* Strict cold-start opt-in for policyGate. The backend's enforceMode
|
|
165
|
+
* (fail_closed) can only be determined by the SDK after a snapshot has been
|
|
166
|
+
* fetched once, so failures before the first fetch default to fail-open.
|
|
167
|
+
* When true, all calls are stopped with ArgosvixBudgetGateUnavailableError
|
|
168
|
+
* until the fetch succeeds. Same semantics as budgetGateFailClosed, for
|
|
169
|
+
* setups using only the policy gate.
|
|
156
170
|
*/
|
|
157
171
|
policyGateFailClosed?: boolean;
|
|
158
172
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* https://ingest.argosvix.com/v1/gate/budget
|
|
173
|
+
* Override for where budget gate settings are fetched from (for self-hosting
|
|
174
|
+
* / tests). When unset, /v1/gate/budget on the same origin as `endpoint`;
|
|
175
|
+
* failing that, https://ingest.argosvix.com/v1/gate/budget.
|
|
162
176
|
*/
|
|
163
177
|
gateEndpoint?: string;
|
|
164
178
|
}
|
|
@@ -170,21 +184,21 @@ export interface LlmCallRecord {
|
|
|
170
184
|
promptTokens: number;
|
|
171
185
|
completionTokens: number;
|
|
172
186
|
totalTokens: number;
|
|
173
|
-
/**
|
|
187
|
+
/** Prompt-cache read tokens (a subset of promptTokens, billed at a discount). 0 if none. */
|
|
174
188
|
cachedReadTokens?: number;
|
|
175
|
-
/**
|
|
189
|
+
/** Prompt-cache write tokens (Anthropic only, billed at a premium). 0 if none. */
|
|
176
190
|
cachedWriteTokens?: number;
|
|
177
191
|
/** USD value with 6 decimal places (sufficient for GPT-4o input $5 / 1M tokens granularity). */
|
|
178
192
|
costUsd: number;
|
|
179
|
-
/**
|
|
193
|
+
/** USD saved by cache reads (the difference versus uncached input). 0 if none. */
|
|
180
194
|
cacheSavingsUsd?: number;
|
|
181
195
|
/** End-to-end call latency in milliseconds. */
|
|
182
196
|
latencyMs: number;
|
|
183
|
-
/**
|
|
197
|
+
/** Time to first token in ms (streaming only; unset for non-streaming). */
|
|
184
198
|
ttftMs?: number;
|
|
185
|
-
/**
|
|
199
|
+
/** Reasoning tokens (thinking models; e.g. OpenAI completion_tokens_details.reasoning_tokens). Unset if none. */
|
|
186
200
|
reasoningTokens?: number;
|
|
187
|
-
/**
|
|
201
|
+
/** Audio tokens (input + output combined). Unset if none. */
|
|
188
202
|
audioTokens?: number;
|
|
189
203
|
/** ISO 8601 UTC timestamp. */
|
|
190
204
|
timestamp: string;
|
|
@@ -209,33 +223,34 @@ export interface LlmCallRecord {
|
|
|
209
223
|
temperature?: number;
|
|
210
224
|
maxTokens?: number;
|
|
211
225
|
};
|
|
212
|
-
/** OTel
|
|
226
|
+
/** OTel-subset trace axis — aggregated on the backend and shown in the waterfall view. */
|
|
213
227
|
traceId?: string;
|
|
214
228
|
spanId?: string;
|
|
215
229
|
parentSpanId?: string;
|
|
216
230
|
/**
|
|
217
|
-
* Session
|
|
218
|
-
*
|
|
219
|
-
*
|
|
231
|
+
* Session axis = an arbitrary user-defined group above traces (a continuous
|
|
232
|
+
* conversation / the same daily session / the same job). The backend
|
|
233
|
+
* /v1/query/session/:id fetches the calls sharing a session_id, rendered
|
|
234
|
+
* chronologically in the dashboard's conversation thread view.
|
|
220
235
|
*/
|
|
221
236
|
sessionId?: string;
|
|
222
237
|
/**
|
|
223
|
-
* Plaintext prompt body (
|
|
224
|
-
*
|
|
225
|
-
*
|
|
238
|
+
* Plaintext prompt body (only set when ArgosvixConfig.captureContent is
|
|
239
|
+
* true). The text body the user sent to the LLM API. If PII redaction is
|
|
240
|
+
* enabled, email addresses, card numbers, etc. have been replaced with
|
|
241
|
+
* [REDACTED_*].
|
|
226
242
|
*/
|
|
227
243
|
promptBody?: string;
|
|
228
244
|
/**
|
|
229
|
-
* Plaintext completion body (
|
|
230
|
-
*
|
|
231
|
-
* 適用済み。
|
|
245
|
+
* Plaintext completion body (only set when ArgosvixConfig.captureContent is
|
|
246
|
+
* true). The response text body from the LLM API. PII redaction applied.
|
|
232
247
|
*/
|
|
233
248
|
completionBody?: string;
|
|
234
249
|
/**
|
|
235
|
-
* Tool call (
|
|
236
|
-
* captureContent
|
|
237
|
-
* tool_calls / function_call
|
|
238
|
-
* redaction
|
|
250
|
+
* Tool call (function calling) names, arguments, and results.
|
|
251
|
+
* Only set when captureContent is true. The SDK extracts these from the
|
|
252
|
+
* response's tool_calls / function_call fields. Arguments and results are
|
|
253
|
+
* strings after PII redaction (possibly JSON strings).
|
|
239
254
|
*/
|
|
240
255
|
toolCalls?: Array<{
|
|
241
256
|
name: string;
|
|
@@ -243,27 +258,29 @@ export interface LlmCallRecord {
|
|
|
243
258
|
result?: string;
|
|
244
259
|
}>;
|
|
245
260
|
/**
|
|
246
|
-
*
|
|
247
|
-
* SDK
|
|
248
|
-
* myNumber / phone / ipv4 / ipv6
|
|
249
|
-
* backend
|
|
250
|
-
* disablePiiRedaction = true (
|
|
261
|
+
* Flag set when at least one PII redaction was applied. True when the
|
|
262
|
+
* SDK-side primary redaction (redactPiiWithCounts) detected and replaced any
|
|
263
|
+
* of email / creditCard / myNumber / phone / ipv4 / ipv6. Stored in the
|
|
264
|
+
* backend's llm_calls.pii_redacted column. Naturally false / unset when
|
|
265
|
+
* disablePiiRedaction = true (content passed through unmodified).
|
|
251
266
|
*/
|
|
252
267
|
piiRedacted?: boolean;
|
|
253
268
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
269
|
+
* Per-category redaction counts plus the redactor identifier, as JSON.
|
|
270
|
+
* Stored as-is in the backend's llm_calls.redaction_metadata column and
|
|
271
|
+
* surfaced by the dashboard / MCP server for the audit display of which
|
|
272
|
+
* types were detected and how many times.
|
|
258
273
|
*
|
|
259
|
-
*
|
|
274
|
+
* Example: { email: 2, phone: 1, creditCard: 0, redactor: "argosvix-sdk" }
|
|
260
275
|
*/
|
|
261
276
|
redactionMetadata?: Record<string, unknown>;
|
|
262
277
|
}
|
|
263
278
|
/**
|
|
264
|
-
*
|
|
265
|
-
* span / event / retrieval / tool / agent / chain
|
|
266
|
-
*
|
|
279
|
+
* Typed / nested observation nodes (non-LLM steps). Beyond generations
|
|
280
|
+
* (LlmCallRecord), span / event / retrieval / tool / agent / chain nodes are
|
|
281
|
+
* emitted via `withSpan` and stored in the backend's observations table.
|
|
282
|
+
* Warning: metadata must contain only non-sensitive structured attributes
|
|
283
|
+
* (counts / sizes etc.).
|
|
267
284
|
*/
|
|
268
285
|
export type ObservationType = "span" | "event" | "retrieval" | "tool" | "agent" | "chain";
|
|
269
286
|
export interface ObservationRecord {
|