@armoriq/sdk-dev 0.8.0 → 0.8.3
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/_build_env.d.ts +2 -1
- package/dist/_build_env.d.ts.map +1 -1
- package/dist/_build_env.js +4 -0
- package/dist/_build_env.js.map +1 -1
- package/dist/_version.d.ts +1 -1
- package/dist/_version.js +1 -1
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +68 -38
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/orgs.js +1 -1
- package/dist/cli/commands/orgs.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +4 -3
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/state.d.ts +3 -3
- package/dist/cli/state.d.ts.map +1 -1
- package/dist/cli/state.js +24 -12
- package/dist/cli/state.js.map +1 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +26 -6
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/token_usage.d.ts +23 -0
- package/dist/token_usage.d.ts.map +1 -1
- package/dist/token_usage.js +107 -26
- package/dist/token_usage.js.map +1 -1
- package/package.json +1 -1
- package/dist/observability/handle.d.ts +0 -41
- package/dist/observability/handle.d.ts.map +0 -1
- package/dist/observability/handle.js +0 -54
- package/dist/observability/handle.js.map +0 -1
- package/dist/observability/recorder.d.ts +0 -245
- package/dist/observability/recorder.d.ts.map +0 -1
- package/dist/observability/recorder.js +0 -475
- package/dist/observability/recorder.js.map +0 -1
- package/dist/observability/schema.d.ts +0 -163
- package/dist/observability/schema.d.ts.map +0 -1
- package/dist/observability/schema.js +0 -291
- package/dist/observability/schema.js.map +0 -1
- package/dist/observability/shipper.d.ts +0 -84
- package/dist/observability/shipper.d.ts.map +0 -1
- package/dist/observability/shipper.js +0 -206
- package/dist/observability/shipper.js.map +0 -1
- package/dist/observability/trace-summary.d.ts +0 -34
- package/dist/observability/trace-summary.d.ts.map +0 -1
- package/dist/observability/trace-summary.js +0 -108
- package/dist/observability/trace-summary.js.map +0 -1
package/dist/token_usage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.summarizeTranscriptUsage = summarizeTranscriptUsage;
|
|
4
|
+
exports.summarizeTranscriptUsageByDay = summarizeTranscriptUsageByDay;
|
|
4
5
|
/**
|
|
5
6
|
* Token-usage capture — shared across all ArmorIQ tool integrations
|
|
6
7
|
* (ArmorClaude / ArmorCodex / ArmorCopilot / future agents).
|
|
@@ -39,14 +40,51 @@ function safeEmit(fn) {
|
|
|
39
40
|
* failure never affects the returned entries.
|
|
40
41
|
*/
|
|
41
42
|
async function summarizeTranscriptUsage(transcriptPath, otel) {
|
|
43
|
+
const { days } = readTranscriptUsage(transcriptPath);
|
|
44
|
+
const entries = mergeEntries(days.flatMap((day) => day.entries));
|
|
45
|
+
await emitModelSpans(entries, otel ?? null);
|
|
46
|
+
return entries;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Same parse as `summarizeTranscriptUsage`, split by the UTC day each message
|
|
50
|
+
* was sent and carrying the transcript's working directory. Posting one row per
|
|
51
|
+
* day keeps a multi-day session's tokens on the days they were spent.
|
|
52
|
+
*/
|
|
53
|
+
function summarizeTranscriptUsageByDay(transcriptPath) {
|
|
54
|
+
return readTranscriptUsage(transcriptPath);
|
|
55
|
+
}
|
|
56
|
+
function emptyEntry(model) {
|
|
57
|
+
return { model, inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
58
|
+
}
|
|
59
|
+
function addInto(acc, e) {
|
|
60
|
+
acc.inputTokens += e.inputTokens;
|
|
61
|
+
acc.outputTokens += e.outputTokens;
|
|
62
|
+
acc.cacheReadTokens += e.cacheReadTokens;
|
|
63
|
+
acc.cacheWriteTokens += e.cacheWriteTokens;
|
|
64
|
+
}
|
|
65
|
+
function mergeEntries(entries) {
|
|
66
|
+
const byModel = new Map();
|
|
67
|
+
for (const e of entries) {
|
|
68
|
+
const acc = byModel.get(e.model) ?? emptyEntry(e.model);
|
|
69
|
+
addInto(acc, e);
|
|
70
|
+
byModel.set(e.model, acc);
|
|
71
|
+
}
|
|
72
|
+
return [...byModel.values()];
|
|
73
|
+
}
|
|
74
|
+
function readTranscriptUsage(transcriptPath) {
|
|
42
75
|
let raw;
|
|
43
76
|
try {
|
|
44
77
|
raw = (0, fs_1.readFileSync)(transcriptPath, 'utf8');
|
|
45
78
|
}
|
|
46
79
|
catch {
|
|
47
|
-
return [];
|
|
80
|
+
return { days: [] };
|
|
48
81
|
}
|
|
49
|
-
const
|
|
82
|
+
const byDay = new Map();
|
|
83
|
+
// Claude Code writes one line per content block of an assistant message, each
|
|
84
|
+
// repeating that message's full usage. Count each message once.
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
let repo;
|
|
87
|
+
let lastDay;
|
|
50
88
|
for (const line of raw.split('\n')) {
|
|
51
89
|
const trimmed = line.trim();
|
|
52
90
|
if (!trimmed)
|
|
@@ -58,37 +96,80 @@ async function summarizeTranscriptUsage(transcriptPath, otel) {
|
|
|
58
96
|
catch {
|
|
59
97
|
continue;
|
|
60
98
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
99
|
+
if (!repo && typeof obj?.cwd === 'string' && obj.cwd)
|
|
100
|
+
repo = obj.cwd;
|
|
101
|
+
const day = utcDay(obj?.timestamp) ?? lastDay;
|
|
102
|
+
if (day)
|
|
103
|
+
lastDay = day;
|
|
104
|
+
const msg = firstObject(obj?.message, obj?.payload) ?? obj;
|
|
64
105
|
const usage = msg?.usage ?? obj?.usage;
|
|
65
106
|
const model = typeof msg?.model === 'string' ? msg.model : typeof obj?.model === 'string' ? obj.model : '';
|
|
66
107
|
if (!usage || !model || model === '<synthetic>')
|
|
67
108
|
continue;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
109
|
+
const messageId = typeof msg?.id === 'string' ? msg.id : '';
|
|
110
|
+
if (messageId) {
|
|
111
|
+
const key = `${messageId}:${typeof obj?.requestId === 'string' ? obj.requestId : ''}`;
|
|
112
|
+
if (seen.has(key))
|
|
113
|
+
continue;
|
|
114
|
+
seen.add(key);
|
|
115
|
+
}
|
|
116
|
+
const inTok = tokenCount(usage.input_tokens ?? usage.prompt_tokens);
|
|
117
|
+
const outTok = tokenCount(usage.output_tokens ?? usage.completion_tokens);
|
|
118
|
+
const cacheRead = tokenCount(usage.cache_read_input_tokens ?? usage.prompt_tokens_details?.cached_tokens);
|
|
119
|
+
const cacheWrite = tokenCount(usage.cache_creation_input_tokens);
|
|
73
120
|
if (inTok + outTok + cacheRead + cacheWrite === 0)
|
|
74
121
|
continue;
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
122
|
+
const bucketKey = day ?? '';
|
|
123
|
+
let models = byDay.get(bucketKey);
|
|
124
|
+
if (!models) {
|
|
125
|
+
models = new Map();
|
|
126
|
+
byDay.set(bucketKey, models);
|
|
127
|
+
}
|
|
128
|
+
const acc = models.get(model) ?? emptyEntry(model);
|
|
129
|
+
addInto(acc, {
|
|
130
|
+
model,
|
|
131
|
+
inputTokens: inTok,
|
|
132
|
+
outputTokens: outTok,
|
|
133
|
+
cacheReadTokens: cacheRead,
|
|
134
|
+
cacheWriteTokens: cacheWrite,
|
|
135
|
+
});
|
|
136
|
+
models.set(model, acc);
|
|
88
137
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
138
|
+
// Lines before the first timestamp belong to the first dated day.
|
|
139
|
+
const undated = byDay.get('');
|
|
140
|
+
byDay.delete('');
|
|
141
|
+
const dates = [...byDay.keys()].sort();
|
|
142
|
+
if (undated) {
|
|
143
|
+
const target = dates[0] ?? new Date().toISOString().slice(0, 10);
|
|
144
|
+
const models = byDay.get(target) ?? new Map();
|
|
145
|
+
for (const e of undated.values()) {
|
|
146
|
+
const acc = models.get(e.model) ?? emptyEntry(e.model);
|
|
147
|
+
addInto(acc, e);
|
|
148
|
+
models.set(e.model, acc);
|
|
149
|
+
}
|
|
150
|
+
byDay.set(target, models);
|
|
151
|
+
}
|
|
152
|
+
const days = [...byDay.entries()]
|
|
153
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
154
|
+
.map(([usageDate, models]) => ({ usageDate, entries: [...models.values()] }));
|
|
155
|
+
return repo ? { days, repo } : { days };
|
|
156
|
+
}
|
|
157
|
+
// A timestamp with no offset is read as UTC, not the machine's zone, so every
|
|
158
|
+
// machine files the same message under the same day (matches the Python SDK).
|
|
159
|
+
function utcDay(timestamp) {
|
|
160
|
+
if (typeof timestamp !== 'string' || !timestamp)
|
|
161
|
+
return undefined;
|
|
162
|
+
const hasZone = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(timestamp.trim());
|
|
163
|
+
const d = new Date(hasZone || !timestamp.includes('T') ? timestamp : `${timestamp}Z`);
|
|
164
|
+
return Number.isNaN(d.getTime()) ? undefined : d.toISOString().slice(0, 10);
|
|
165
|
+
}
|
|
166
|
+
/** Whole, non-negative token count; anything unparseable counts as 0. */
|
|
167
|
+
function tokenCount(value) {
|
|
168
|
+
const n = Number(value);
|
|
169
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
|
170
|
+
}
|
|
171
|
+
function firstObject(...values) {
|
|
172
|
+
return values.find((v) => v !== null && typeof v === 'object' && Object.keys(v).length > 0);
|
|
92
173
|
}
|
|
93
174
|
/**
|
|
94
175
|
* Emit one native `gen_ai.chat` model span per per-model usage entry via
|
package/dist/token_usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token_usage.js","sourceRoot":"","sources":["../src/token_usage.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"token_usage.js","sourceRoot":"","sources":["../src/token_usage.ts"],"names":[],"mappings":";;AAwEA,4DAQC;AAOD,sEAEC;AAzFD;;;;;;;;GAQG;AACH,2BAAkC;AAClC,mDAAmE;AAoCnE,SAAS,QAAQ,CAAI,EAAW;IAC9B,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,qDAAqD,GAAG,EAAE,CAAC,CAAC;QACzE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,wBAAwB,CAC5C,cAAsB,EACtB,IAAyB;IAEzB,MAAM,EAAE,IAAI,EAAE,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,MAAM,cAAc,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CAAC,cAAsB;IAClE,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,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K,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,cAAc,CAAC,OAA0B,EAAE,IAAwB;IAChF,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC1C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,CAC5B,IAAA,8BAAc,EACZ,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,YAAY,EAClB,KAAK,CAAC,eAAe,EACrB,KAAK,CAAC,gBAAgB,CACvB,CACF,IAAI,CAAC,CAAC;QACP,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAC1B,2BAA2B,EAAE,UAAU;YACvC,yBAAyB,EAAE,WAAW;YACtC,2BAA2B,EAAE,KAAK,CAAC,WAAW;YAC9C,4BAA4B,EAAE,KAAK,CAAC,YAAY;YAChD,gCAAgC,EAAE,KAAK,CAAC,eAAe;YACvD,iCAAiC,EAAE,KAAK,CAAC,gBAAgB;YACzD,uBAAuB,EAAE,OAAO;SACjC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone helper API for the chokepoints.
|
|
3
|
-
*
|
|
4
|
-
* The session chokepoints (in `src/session.ts`, owned by the peer subagent)
|
|
5
|
-
* call these helpers instead of going through `ObservabilityRecorder` methods
|
|
6
|
-
* directly. The wrapper signature is uniform:
|
|
7
|
-
*
|
|
8
|
-
* const ctx = startTrace(obs, 'iap.enforce', { toolName });
|
|
9
|
-
* recordPolicyCall(obs, ctx, { ... });
|
|
10
|
-
* endTrace(obs, ctx, { status: 'ok' });
|
|
11
|
-
*
|
|
12
|
-
* All helpers are thin pass-throughs to the recorder — they're the
|
|
13
|
-
* stable interface the chokepoints can import without needing to know
|
|
14
|
-
* about the recorder's internal class shape.
|
|
15
|
-
*/
|
|
16
|
-
import { type ObservabilityRecorder } from './recorder';
|
|
17
|
-
import type { TraceContext, SpanRecord } from './schema';
|
|
18
|
-
export declare function startTrace(recorder: ObservabilityRecorder, name: string, attributes?: Record<string, unknown>, sessionId?: string | null): TraceContext;
|
|
19
|
-
export declare function recordSpan(recorder: ObservabilityRecorder, ctx: TraceContext, span: SpanRecord): void;
|
|
20
|
-
export declare function recordPolicyCall(recorder: ObservabilityRecorder, ctx: TraceContext, attrs: Parameters<ObservabilityRecorder['recordPolicyCall']>[1], parentSpanId?: string | null): SpanRecord;
|
|
21
|
-
export declare function recordGeneration(recorder: ObservabilityRecorder, ctx: TraceContext, attrs: Parameters<ObservabilityRecorder['recordGeneration']>[1], parentSpanId?: string | null): SpanRecord;
|
|
22
|
-
export declare function recordEvent(recorder: ObservabilityRecorder, ctx: TraceContext, attrs: {
|
|
23
|
-
message: string;
|
|
24
|
-
level?: 'info' | 'warn' | 'error';
|
|
25
|
-
}, parentSpanId?: string | null): SpanRecord;
|
|
26
|
-
export declare function openSpan(recorder: ObservabilityRecorder, ctx: TraceContext, opts: {
|
|
27
|
-
name: string;
|
|
28
|
-
attributes?: Record<string, unknown>;
|
|
29
|
-
parentSpanId?: string | null;
|
|
30
|
-
}): string;
|
|
31
|
-
export declare function closeSpan(recorder: ObservabilityRecorder, ctx: TraceContext, spanId: string, opts?: {
|
|
32
|
-
status?: 'ok' | 'error' | 'denied';
|
|
33
|
-
durationMs?: number;
|
|
34
|
-
errorMessage?: string;
|
|
35
|
-
}): void;
|
|
36
|
-
export declare function endTrace(recorder: ObservabilityRecorder, ctx: TraceContext, opts?: {
|
|
37
|
-
status?: 'ok' | 'error' | 'denied';
|
|
38
|
-
errorMessage?: string;
|
|
39
|
-
}): void;
|
|
40
|
-
export declare function flushObservability(recorder: ObservabilityRecorder): Promise<void>;
|
|
41
|
-
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/observability/handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,wBAAgB,UAAU,CACxB,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,YAAY,CAEd;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,UAAU,GACf,IAAI,CAEN;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,UAAU,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC/D,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,UAAU,CAEZ;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,UAAU,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC/D,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,UAAU,CAEZ;AAED,wBAAgB,WAAW,CACzB,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,EAC7D,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,UAAU,CAEZ;AAED,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACzF,MAAM,CAER;AAED,wBAAgB,SAAS,CACvB,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACxF,IAAI,CAEN;AAED,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,qBAAqB,EAC/B,GAAG,EAAE,YAAY,EACjB,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,IAAI,CAEN;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAEf"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Standalone helper API for the chokepoints.
|
|
4
|
-
*
|
|
5
|
-
* The session chokepoints (in `src/session.ts`, owned by the peer subagent)
|
|
6
|
-
* call these helpers instead of going through `ObservabilityRecorder` methods
|
|
7
|
-
* directly. The wrapper signature is uniform:
|
|
8
|
-
*
|
|
9
|
-
* const ctx = startTrace(obs, 'iap.enforce', { toolName });
|
|
10
|
-
* recordPolicyCall(obs, ctx, { ... });
|
|
11
|
-
* endTrace(obs, ctx, { status: 'ok' });
|
|
12
|
-
*
|
|
13
|
-
* All helpers are thin pass-throughs to the recorder — they're the
|
|
14
|
-
* stable interface the chokepoints can import without needing to know
|
|
15
|
-
* about the recorder's internal class shape.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.startTrace = startTrace;
|
|
19
|
-
exports.recordSpan = recordSpan;
|
|
20
|
-
exports.recordPolicyCall = recordPolicyCall;
|
|
21
|
-
exports.recordGeneration = recordGeneration;
|
|
22
|
-
exports.recordEvent = recordEvent;
|
|
23
|
-
exports.openSpan = openSpan;
|
|
24
|
-
exports.closeSpan = closeSpan;
|
|
25
|
-
exports.endTrace = endTrace;
|
|
26
|
-
exports.flushObservability = flushObservability;
|
|
27
|
-
function startTrace(recorder, name, attributes, sessionId) {
|
|
28
|
-
return recorder.startTrace(name, attributes, sessionId);
|
|
29
|
-
}
|
|
30
|
-
function recordSpan(recorder, ctx, span) {
|
|
31
|
-
recorder.recordSpan(ctx, span);
|
|
32
|
-
}
|
|
33
|
-
function recordPolicyCall(recorder, ctx, attrs, parentSpanId) {
|
|
34
|
-
return recorder.recordPolicyCall(ctx, attrs, parentSpanId);
|
|
35
|
-
}
|
|
36
|
-
function recordGeneration(recorder, ctx, attrs, parentSpanId) {
|
|
37
|
-
return recorder.recordGeneration(ctx, attrs, parentSpanId);
|
|
38
|
-
}
|
|
39
|
-
function recordEvent(recorder, ctx, attrs, parentSpanId) {
|
|
40
|
-
return recorder.recordEvent(ctx, attrs, parentSpanId);
|
|
41
|
-
}
|
|
42
|
-
function openSpan(recorder, ctx, opts) {
|
|
43
|
-
return recorder.openSpan(ctx, opts);
|
|
44
|
-
}
|
|
45
|
-
function closeSpan(recorder, ctx, spanId, opts) {
|
|
46
|
-
recorder.closeSpan(ctx, spanId, opts);
|
|
47
|
-
}
|
|
48
|
-
function endTrace(recorder, ctx, opts) {
|
|
49
|
-
recorder.endTrace(ctx, opts);
|
|
50
|
-
}
|
|
51
|
-
async function flushObservability(recorder) {
|
|
52
|
-
await recorder.flush();
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=handle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/observability/handle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAUH,gCAOC;AAED,gCAMC;AAED,4CAOC;AAED,4CAOC;AAED,kCAOC;AAED,4BAMC;AAED,8BAOC;AAED,4BAMC;AAED,gDAIC;AAzED,SAAgB,UAAU,CACxB,QAA+B,EAC/B,IAAY,EACZ,UAAoC,EACpC,SAAyB;IAEzB,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,UAAU,CACxB,QAA+B,EAC/B,GAAiB,EACjB,IAAgB;IAEhB,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,gBAAgB,CAC9B,QAA+B,EAC/B,GAAiB,EACjB,KAA+D,EAC/D,YAA4B;IAE5B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC;AAED,SAAgB,gBAAgB,CAC9B,QAA+B,EAC/B,GAAiB,EACjB,KAA+D,EAC/D,YAA4B;IAE5B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC;AAED,SAAgB,WAAW,CACzB,QAA+B,EAC/B,GAAiB,EACjB,KAA6D,EAC7D,YAA4B;IAE5B,OAAO,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;AACxD,CAAC;AAED,SAAgB,QAAQ,CACtB,QAA+B,EAC/B,GAAiB,EACjB,IAA0F;IAE1F,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,SAAgB,SAAS,CACvB,QAA+B,EAC/B,GAAiB,EACjB,MAAc,EACd,IAAyF;IAEzF,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,QAAQ,CACtB,QAA+B,EAC/B,GAAiB,EACjB,IAAoE;IAEpE,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,QAA+B;IAE/B,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObservabilityRecorder — in-memory ring buffer for traces + spans.
|
|
3
|
-
*
|
|
4
|
-
* The recorder is the only place in the SDK that mints trace/span IDs. The
|
|
5
|
-
* session chokepoints (peer subagent's wrap) call `startTrace` /
|
|
6
|
-
* `recordPolicyCall` / `endTrace` and the recorder takes care of:
|
|
7
|
-
* 1. Validating each emit (cheap shape checks; bad data is logged + dropped,
|
|
8
|
-
* never thrown into the SDK consumer).
|
|
9
|
-
* 2. Minting IDs and computing endTime/durationMs.
|
|
10
|
-
* 3. Holding the in-memory ring buffer (default 1000 traces). On overflow,
|
|
11
|
-
* the oldest trace AND all its spans are dropped (we never want a partial
|
|
12
|
-
* trace at the backend).
|
|
13
|
-
* 4. Pushing ended traces onto the shipper's queue.
|
|
14
|
-
* 5. Forwarding every emit to the test sink (if set) so tests can assert
|
|
15
|
-
* on the exact lifecycle.
|
|
16
|
-
*
|
|
17
|
-
* Per plan §9 Q3: in-memory only. `durable: true` is parsed and stored but
|
|
18
|
-
* does nothing in v1 — a one-time warning is logged the first time a
|
|
19
|
-
* consumer opts in.
|
|
20
|
-
*/
|
|
21
|
-
import { AxiosInstance } from 'axios';
|
|
22
|
-
import { ObservabilityShipper } from './shipper';
|
|
23
|
-
import { type SpanRecord, type SpanStatus, type TraceContext, type TraceRecord } from './schema';
|
|
24
|
-
export interface ObservabilityConfig {
|
|
25
|
-
/** Master kill switch. Default: true. */
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
/** Full URL of the ingest endpoint, e.g. https://api.armoriq.ai/observability/spans. */
|
|
28
|
-
endpoint: string;
|
|
29
|
-
/** API key used in the X-API-Key header. */
|
|
30
|
-
apiKey: string;
|
|
31
|
-
/** Product tag sent with every ingest payload (e.g. 'armorclaude' | 'armorcodex' | 'armorcopilot' | 'armorgemini'). */
|
|
32
|
-
product: string;
|
|
33
|
-
/**
|
|
34
|
-
* Default session id applied to every trace started on this recorder when
|
|
35
|
-
* the caller doesn't pass an explicit `sessionId` to `startTrace()`. This
|
|
36
|
-
* is how `ArmorIQSession` stamps ITS one stable (UUID) session id onto
|
|
37
|
-
* every trace uniformly, without every chokepoint having to pass it
|
|
38
|
-
* explicitly. Must be a valid UUID or `null` — the backend's
|
|
39
|
-
* `obs_sessions.id` column is a UUID column, so a non-UUID value can never
|
|
40
|
-
* form a session.
|
|
41
|
-
*/
|
|
42
|
-
sessionId?: string | null;
|
|
43
|
-
/** SDK user id (denormalized onto every trace). May be null for multi-user flows. */
|
|
44
|
-
userId?: string | null;
|
|
45
|
-
/** SDK agent id (denormalized onto every trace). May be null for multi-user flows. */
|
|
46
|
-
agentId?: string | null;
|
|
47
|
-
/** Override the SDK's HTTP client (axios instance). Used for tests. */
|
|
48
|
-
httpClient?: AxiosInstance;
|
|
49
|
-
/** Max traces in the in-memory ring buffer. Default 1000. */
|
|
50
|
-
maxBufferSize?: number;
|
|
51
|
-
/** Auto-flush interval (ms). Default 5000. */
|
|
52
|
-
flushIntervalMs?: number;
|
|
53
|
-
/**
|
|
54
|
-
* Max batches per ingest POST. Default 100. The shipper chunks the queue
|
|
55
|
-
* into groups of at most this size at flush time, so a burst of traces
|
|
56
|
-
* never sends a single unbounded giant POST.
|
|
57
|
-
*/
|
|
58
|
-
batchSize?: number;
|
|
59
|
-
/** Optional onSpan hook. Called for every span after it's validated. */
|
|
60
|
-
onSpan?: (span: SpanRecord) => void;
|
|
61
|
-
/** Disk-backed WAL opt-in. Parsed and stored; unused in v1. */
|
|
62
|
-
durable?: boolean;
|
|
63
|
-
/** Data dir for the future WAL. Stored; unused in v1. */
|
|
64
|
-
dataDir?: string;
|
|
65
|
-
}
|
|
66
|
-
export type SinkEvent = {
|
|
67
|
-
kind: 'trace_started';
|
|
68
|
-
trace: TraceRecord;
|
|
69
|
-
sessionId: string | null;
|
|
70
|
-
} | {
|
|
71
|
-
kind: 'span_recorded';
|
|
72
|
-
traceId: string;
|
|
73
|
-
traceSessionId: string | null;
|
|
74
|
-
span: SpanRecord;
|
|
75
|
-
} | {
|
|
76
|
-
kind: 'trace_ended';
|
|
77
|
-
trace: TraceRecord;
|
|
78
|
-
spans: SpanRecord[];
|
|
79
|
-
};
|
|
80
|
-
export type ObservabilitySink = (event: SinkEvent) => void;
|
|
81
|
-
export declare function __setObservabilitySinkForTests(sink: ObservabilitySink | null): void;
|
|
82
|
-
export declare class ObservabilityRecorder {
|
|
83
|
-
private readonly enabled;
|
|
84
|
-
private readonly product;
|
|
85
|
-
private readonly userId;
|
|
86
|
-
private readonly agentId;
|
|
87
|
-
private readonly defaultSessionId;
|
|
88
|
-
private readonly maxBufferSize;
|
|
89
|
-
private readonly onSpan?;
|
|
90
|
-
private readonly buffer;
|
|
91
|
-
private readonly bufferIndex;
|
|
92
|
-
private readonly shipper;
|
|
93
|
-
private warnedDurable;
|
|
94
|
-
constructor(config: ObservabilityConfig);
|
|
95
|
-
/** Internal accessor for tests; not part of the public API. */
|
|
96
|
-
get __shipper(): ObservabilityShipper;
|
|
97
|
-
/** True when the consumer passed `enabled: true` (the default). */
|
|
98
|
-
get isEnabled(): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Mint a new trace and return its context. The trace is added to the
|
|
101
|
-
* in-memory buffer (dropping the oldest if at capacity) and the context
|
|
102
|
-
* is passed to subsequent `recordSpan` / `endTrace` calls.
|
|
103
|
-
*/
|
|
104
|
-
startTrace(name: string, attributes?: Record<string, unknown>, sessionId?: string | null): TraceContext;
|
|
105
|
-
/**
|
|
106
|
-
* Append a span to an existing trace. The span is validated against the
|
|
107
|
-
* wire schema; an invalid span is logged and dropped (never thrown).
|
|
108
|
-
*/
|
|
109
|
-
recordSpan(ctx: TraceContext, span: SpanRecord): void;
|
|
110
|
-
/**
|
|
111
|
-
* Construct a `kind: 'policy_call'` span from the supplied fields and
|
|
112
|
-
* record it under the given trace. Returns the constructed span (useful
|
|
113
|
-
* for tests); otherwise the return value can be ignored.
|
|
114
|
-
*/
|
|
115
|
-
recordPolicyCall(ctx: TraceContext, attrs: {
|
|
116
|
-
policyId: string | null;
|
|
117
|
-
policyName: string | null;
|
|
118
|
-
decision: 'allow' | 'deny' | 'hold' | 'ask';
|
|
119
|
-
reason: string | null;
|
|
120
|
-
source: 'native' | 'sdk-local' | 'sdk' | 'proxy' | 'opa' | 'opa_fallback';
|
|
121
|
-
input: unknown;
|
|
122
|
-
output: unknown;
|
|
123
|
-
policyHash?: string | null;
|
|
124
|
-
policyVersion?: string | null;
|
|
125
|
-
matchedRuleId?: string | null;
|
|
126
|
-
dataClasses?: string[];
|
|
127
|
-
enforcementAction?: 'allow' | 'allow_log' | 'hold' | 'block' | null;
|
|
128
|
-
obligations?: unknown;
|
|
129
|
-
delegationId?: string | null;
|
|
130
|
-
durationMs?: number | null;
|
|
131
|
-
}, parentSpanId?: string | null): SpanRecord;
|
|
132
|
-
/**
|
|
133
|
-
* Construct a `kind: 'generation'` span from the supplied fields,
|
|
134
|
-
* compute `costUsd` from the static price table, and record it.
|
|
135
|
-
* Unknown models yield costUsd=0 (the span is still recorded).
|
|
136
|
-
* Pass `costUsd` to override the computed value (e.g. when the caller
|
|
137
|
-
* already has a precomputed cost from a third-party billing system).
|
|
138
|
-
*/
|
|
139
|
-
recordGeneration(ctx: TraceContext, attrs: {
|
|
140
|
-
model: string;
|
|
141
|
-
inputTokens: number;
|
|
142
|
-
outputTokens: number;
|
|
143
|
-
cacheReadTokens?: number | null;
|
|
144
|
-
cacheWriteTokens?: number | null;
|
|
145
|
-
prompt?: string | null;
|
|
146
|
-
completion?: string | null;
|
|
147
|
-
finishReason?: string | null;
|
|
148
|
-
costUsd?: number | null;
|
|
149
|
-
}, parentSpanId?: string | null): SpanRecord;
|
|
150
|
-
/**
|
|
151
|
-
* Record a `kind: 'event'` span — a point-in-time annotation (e.g.
|
|
152
|
-
* "plan growth", "approval polled"). Use sparingly; events are cheap
|
|
153
|
-
* but they still count toward the ring buffer.
|
|
154
|
-
*/
|
|
155
|
-
recordEvent(ctx: TraceContext, attrs: {
|
|
156
|
-
message: string;
|
|
157
|
-
level?: 'info' | 'warn' | 'error';
|
|
158
|
-
}, parentSpanId?: string | null): SpanRecord;
|
|
159
|
-
/**
|
|
160
|
-
* Mint + record a `kind: 'span'` CONTAINER span — a nesting point that
|
|
161
|
-
* groups the child spans emitted by one chokepoint (e.g. `iap.enforce.local`)
|
|
162
|
-
* under the session's single active plan trace (Model A: trace-per-plan).
|
|
163
|
-
*
|
|
164
|
-
* The container starts open (`status: 'ok'`, `endTime: null`,
|
|
165
|
-
* `durationMs: null`) and MUST be finalized with `closeSpan()` once the
|
|
166
|
-
* chokepoint's work completes (success or error). A container span with a
|
|
167
|
-
* null `endTime` is intentionally valid mid-flight — see
|
|
168
|
-
* `isValidGenericSpanAttributes`/`isValidSpanRecord`, which permit a
|
|
169
|
-
* null `endTime`/`durationMs` for exactly this reason (Task 1 risk #1).
|
|
170
|
-
*
|
|
171
|
-
* Returns the minted span id — even when the recorder is disabled, so
|
|
172
|
-
* call sites can pass it along unconditionally as a `parentSpanId` to
|
|
173
|
-
* `recordPolicyCall`/`recordGeneration`/`recordEvent` without special-casing
|
|
174
|
-
* the disabled path.
|
|
175
|
-
*/
|
|
176
|
-
openSpan(ctx: TraceContext, opts: {
|
|
177
|
-
name: string;
|
|
178
|
-
attributes?: Record<string, unknown>;
|
|
179
|
-
parentSpanId?: string | null;
|
|
180
|
-
}): string;
|
|
181
|
-
/**
|
|
182
|
-
* Finalize a container span previously opened with `openSpan()`: sets
|
|
183
|
-
* `endTime`, optionally `durationMs`/`status`/`attributes.errorMessage`.
|
|
184
|
-
* No-op (never throws) when the recorder is disabled, the trace is
|
|
185
|
-
* unknown, or the spanId doesn't match a buffered span (e.g. it already
|
|
186
|
-
* shipped) — mirrors `endTrace`'s defensive lookup.
|
|
187
|
-
*/
|
|
188
|
-
closeSpan(ctx: TraceContext, spanId: string, opts?: {
|
|
189
|
-
status?: SpanStatus;
|
|
190
|
-
durationMs?: number;
|
|
191
|
-
errorMessage?: string;
|
|
192
|
-
}): void;
|
|
193
|
-
/**
|
|
194
|
-
* Finalize a trace: set endTime, compute durationMs, apply optional
|
|
195
|
-
* status / errorMessage. Pushes the (trace, spans) batch to the
|
|
196
|
-
* shipper's queue, then REMOVES the entry from the in-memory ring buffer
|
|
197
|
-
* — once a trace has been handed to the shipper, the shipper's own queue
|
|
198
|
-
* is the durable record; keeping a second copy in the ring buffer would
|
|
199
|
-
* let ended/shipped traces occupy buffer slots until overflow/flush,
|
|
200
|
-
* needlessly evicting still-in-flight traces sooner. No-op when disabled
|
|
201
|
-
* or when the trace is unknown.
|
|
202
|
-
*/
|
|
203
|
-
endTrace(ctx: TraceContext, opts?: {
|
|
204
|
-
status?: 'ok' | 'error' | 'denied';
|
|
205
|
-
errorMessage?: string;
|
|
206
|
-
}): void;
|
|
207
|
-
/**
|
|
208
|
-
* Drain the in-memory buffer. Returns a readonly array of the current
|
|
209
|
-
* (trace, spans) pairs. The buffer is NOT cleared by this call — that
|
|
210
|
-
* is `flush()`'s job. `drain()` is for inspection (tests, debugging).
|
|
211
|
-
*
|
|
212
|
-
* Note: since `endTrace()` removes entries once they're handed to the
|
|
213
|
-
* shipper (see #8), `drain()` only ever reflects traces that are still
|
|
214
|
-
* in-flight (started but not yet ended).
|
|
215
|
-
*/
|
|
216
|
-
drain(): ReadonlyArray<{
|
|
217
|
-
trace: TraceRecord;
|
|
218
|
-
spans: SpanRecord[];
|
|
219
|
-
}>;
|
|
220
|
-
/**
|
|
221
|
-
* POST any queued (ended) batches via the shipper. Returns the shipper's
|
|
222
|
-
* accepted/rejected counts. NEVER throws — observability failures must
|
|
223
|
-
* not break the SDK consumer.
|
|
224
|
-
*
|
|
225
|
-
* Only ended traces (`trace.endTime !== null`) are ever handed to the
|
|
226
|
-
* shipper (see `endTrace()`); in-flight (un-ended) traces stay in the
|
|
227
|
-
* in-memory ring buffer untouched — flushing must never drop a trace
|
|
228
|
-
* that's still being built. As an extra safety net (in case some future
|
|
229
|
-
* caller enqueues directly), any buffer entries whose trace happens to
|
|
230
|
-
* already carry an `endTime` are also handed to the shipper and removed
|
|
231
|
-
* here; anything without an `endTime` is left alone and a warning is
|
|
232
|
-
* logged with the retained count.
|
|
233
|
-
*/
|
|
234
|
-
flush(): Promise<{
|
|
235
|
-
accepted: number;
|
|
236
|
-
rejected: number;
|
|
237
|
-
}>;
|
|
238
|
-
/**
|
|
239
|
-
* Stop the underlying shipper (clears the periodic interval + final
|
|
240
|
-
* flush). Call on session close. Safe to call multiple times.
|
|
241
|
-
*/
|
|
242
|
-
stop(): Promise<void>;
|
|
243
|
-
private appendToBuffer;
|
|
244
|
-
}
|
|
245
|
-
//# sourceMappingURL=recorder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../../src/observability/recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAA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