dsh-observe 0.1.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/CHANGELOG.md +25 -0
- package/LICENSE +201 -0
- package/README.es.md +198 -0
- package/README.hi.md +198 -0
- package/README.md +198 -0
- package/README.pt.md +198 -0
- package/README.zh.md +198 -0
- package/THIRD_PARTY_NOTICES.md +21 -0
- package/cordis.patch.yml +86 -0
- package/lib/index.js +1947 -0
- package/lib/typert.host.js +109 -0
- package/lib/types/backoff.d.ts +17 -0
- package/lib/types/backoff.d.ts.map +1 -0
- package/lib/types/backoff.js +17 -0
- package/lib/types/backoff.js.map +1 -0
- package/lib/types/collector.d.ts +83 -0
- package/lib/types/collector.d.ts.map +1 -0
- package/lib/types/collector.js +506 -0
- package/lib/types/collector.js.map +1 -0
- package/lib/types/config.d.ts +286 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +312 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/ids.d.ts +43 -0
- package/lib/types/ids.d.ts.map +1 -0
- package/lib/types/ids.js +63 -0
- package/lib/types/ids.js.map +1 -0
- package/lib/types/index.d.ts +35 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +162 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/model.d.ts +89 -0
- package/lib/types/model.d.ts.map +1 -0
- package/lib/types/model.js +25 -0
- package/lib/types/model.js.map +1 -0
- package/lib/types/pipeline.d.ts +71 -0
- package/lib/types/pipeline.d.ts.map +1 -0
- package/lib/types/pipeline.js +193 -0
- package/lib/types/pipeline.js.map +1 -0
- package/lib/types/pricing.d.ts +34 -0
- package/lib/types/pricing.d.ts.map +1 -0
- package/lib/types/pricing.js +45 -0
- package/lib/types/pricing.js.map +1 -0
- package/lib/types/project.d.ts +26 -0
- package/lib/types/project.d.ts.map +1 -0
- package/lib/types/project.js +52 -0
- package/lib/types/project.js.map +1 -0
- package/lib/types/remote.d.ts +28 -0
- package/lib/types/remote.d.ts.map +1 -0
- package/lib/types/remote.js +45 -0
- package/lib/types/remote.js.map +1 -0
- package/lib/types/sanitize.d.ts +78 -0
- package/lib/types/sanitize.d.ts.map +1 -0
- package/lib/types/sanitize.js +132 -0
- package/lib/types/sanitize.js.map +1 -0
- package/lib/types/sinks.d.ts +84 -0
- package/lib/types/sinks.d.ts.map +1 -0
- package/lib/types/sinks.js +434 -0
- package/lib/types/sinks.js.map +1 -0
- package/lib/types/spool.d.ts +113 -0
- package/lib/types/spool.d.ts.map +1 -0
- package/lib/types/spool.js +167 -0
- package/lib/types/spool.js.map +1 -0
- package/lib/types/typert.host.d.ts +93 -0
- package/lib/types/typert.host.d.ts.map +1 -0
- package/lib/types/typert.host.js +23 -0
- package/lib/types/typert.host.js.map +1 -0
- package/lib/types/version.d.ts +10 -0
- package/lib/types/version.d.ts.map +1 -0
- package/lib/types/version.js +10 -0
- package/lib/types/version.js.map +1 -0
- package/lib/types/wire.d.ts +206 -0
- package/lib/types/wire.d.ts.map +1 -0
- package/lib/types/wire.js +71 -0
- package/lib/types/wire.js.map +1 -0
- package/package.json +147 -0
- package/src/backoff.ts +20 -0
- package/src/collector.ts +561 -0
- package/src/config.ts +604 -0
- package/src/ids.ts +68 -0
- package/src/index.ts +186 -0
- package/src/model.ts +100 -0
- package/src/pipeline.ts +205 -0
- package/src/pricing.ts +55 -0
- package/src/project.ts +55 -0
- package/src/remote.ts +56 -0
- package/src/sanitize.ts +132 -0
- package/src/sinks.ts +471 -0
- package/src/spool.ts +196 -0
- package/src/typert.host.ts +24 -0
- package/src/version.ts +10 -0
- package/src/wire.ts +97 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-backend delivery pipeline: an in-memory queue, periodic and
|
|
3
|
+
* size-triggered flushes, retry with exponential backoff, and spill-over
|
|
4
|
+
* into the durable offline buffer (both when the queue bound is hit and
|
|
5
|
+
* when retries are exhausted). Spool draining runs on its own cycle.
|
|
6
|
+
* @module dsh-observe/pipeline
|
|
7
|
+
*/
|
|
8
|
+
import { backoffDelayMs } from "./backoff.js";
|
|
9
|
+
/**
|
|
10
|
+
* One backend's delivery pipeline. Push is synchronous (the session event
|
|
11
|
+
* hot path); all network work happens on timers or in the background.
|
|
12
|
+
*/
|
|
13
|
+
export class Pipeline {
|
|
14
|
+
options;
|
|
15
|
+
queue = [];
|
|
16
|
+
pending;
|
|
17
|
+
inFlight = false;
|
|
18
|
+
consecutiveFailures = 0;
|
|
19
|
+
retryTimer;
|
|
20
|
+
disposed = false;
|
|
21
|
+
/**
|
|
22
|
+
* @param options - the pipeline options (copied, never mutated).
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
/** Records currently queued or awaiting retry. */
|
|
28
|
+
get depth() {
|
|
29
|
+
return this.queue.length + (this.pending?.length ?? 0);
|
|
30
|
+
}
|
|
31
|
+
/** The backend this pipeline delivers to (`otlp` / `langfuse`). */
|
|
32
|
+
get name() {
|
|
33
|
+
return this.options.name;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Queue one record. A disabled runtime drops it (counted); a full queue
|
|
37
|
+
* spills it straight into the durable buffer (bounded; oldest records
|
|
38
|
+
* there are evicted first).
|
|
39
|
+
* @param record - the owned, sanitized record.
|
|
40
|
+
*/
|
|
41
|
+
push(record) {
|
|
42
|
+
if (this.disposed)
|
|
43
|
+
return;
|
|
44
|
+
if (!this.options.isEnabled()) {
|
|
45
|
+
this.options.onMetric({
|
|
46
|
+
name: 'observe.dropped',
|
|
47
|
+
kind: 'counter',
|
|
48
|
+
unit: 'records',
|
|
49
|
+
value: 1,
|
|
50
|
+
attributes: { reason: 'disabled', backend: this.options.name },
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.queue.length < this.options.batch.maxQueueRecords) {
|
|
55
|
+
this.queue.push(record);
|
|
56
|
+
if (this.queue.length >= this.options.batch.maxRecords)
|
|
57
|
+
this.kick();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
void this.options.spool.push(this.options.name, [record]).catch((error) => {
|
|
61
|
+
this.options.logger.warn(`${this.options.name}: buffer spill failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Start a flush immediately when no flush is already running or scheduled. */
|
|
65
|
+
kick() {
|
|
66
|
+
if (this.retryTimer !== undefined || this.inFlight)
|
|
67
|
+
return;
|
|
68
|
+
void this.flushOnce();
|
|
69
|
+
}
|
|
70
|
+
/** The periodic flush entry point. */
|
|
71
|
+
async tick() {
|
|
72
|
+
await this.flushOnce();
|
|
73
|
+
}
|
|
74
|
+
/** One flush attempt: pending retry batch first, otherwise the queue head. */
|
|
75
|
+
async flushOnce() {
|
|
76
|
+
if (this.inFlight || this.disposed)
|
|
77
|
+
return;
|
|
78
|
+
const batch = this.pending ?? this.queue.splice(0, this.options.batch.maxRecords);
|
|
79
|
+
if (batch.length === 0)
|
|
80
|
+
return;
|
|
81
|
+
this.inFlight = true;
|
|
82
|
+
try {
|
|
83
|
+
await this.options.sink.exportSpans(batch);
|
|
84
|
+
this.consecutiveFailures = 0;
|
|
85
|
+
this.pending = undefined;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.consecutiveFailures += 1;
|
|
89
|
+
this.pending = batch;
|
|
90
|
+
if (this.consecutiveFailures >= this.options.retry.maxAttempts) {
|
|
91
|
+
this.pending = undefined;
|
|
92
|
+
this.consecutiveFailures = 0;
|
|
93
|
+
await this.options.spool.push(this.options.name, batch);
|
|
94
|
+
this.options.onMetric({
|
|
95
|
+
name: 'observe.spooled',
|
|
96
|
+
kind: 'counter',
|
|
97
|
+
unit: 'records',
|
|
98
|
+
value: batch.length,
|
|
99
|
+
attributes: { backend: this.options.name },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.scheduleRetry();
|
|
104
|
+
}
|
|
105
|
+
this.options.onMetric({
|
|
106
|
+
name: 'observe.export_failures',
|
|
107
|
+
kind: 'counter',
|
|
108
|
+
unit: 'requests',
|
|
109
|
+
value: 1,
|
|
110
|
+
attributes: { backend: this.options.name },
|
|
111
|
+
});
|
|
112
|
+
this.options.logger.warn(`${this.options.name}: export attempt ${this.consecutiveFailures} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
this.inFlight = false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Schedule the backoff retry for the pending batch. */
|
|
119
|
+
scheduleRetry() {
|
|
120
|
+
if (this.disposed || this.retryTimer !== undefined)
|
|
121
|
+
return;
|
|
122
|
+
const delay = backoffDelayMs(this.consecutiveFailures, this.options.retry);
|
|
123
|
+
this.retryTimer = setTimeout(() => {
|
|
124
|
+
this.retryTimer = undefined;
|
|
125
|
+
void this.flushOnce();
|
|
126
|
+
}, delay);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Try the oldest buffered batches once. Batches that fail stay in the
|
|
130
|
+
* buffer for the next cycle; success deletes them.
|
|
131
|
+
*/
|
|
132
|
+
async drainSpool() {
|
|
133
|
+
if (this.inFlight || this.disposed)
|
|
134
|
+
return;
|
|
135
|
+
const { batches, records } = this.options.spool.peek(this.options.name, this.options.batch.maxRecords);
|
|
136
|
+
if (records.length === 0)
|
|
137
|
+
return;
|
|
138
|
+
this.inFlight = true;
|
|
139
|
+
try {
|
|
140
|
+
await this.options.sink.exportSpans(records);
|
|
141
|
+
await this.options.spool.remove(batches);
|
|
142
|
+
this.consecutiveFailures = 0;
|
|
143
|
+
this.options.onMetric({
|
|
144
|
+
name: 'observe.spool_flushed',
|
|
145
|
+
kind: 'counter',
|
|
146
|
+
unit: 'records',
|
|
147
|
+
value: records.length,
|
|
148
|
+
attributes: { backend: this.options.name },
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
this.options.onMetric({
|
|
153
|
+
name: 'observe.export_failures',
|
|
154
|
+
kind: 'counter',
|
|
155
|
+
unit: 'requests',
|
|
156
|
+
value: 1,
|
|
157
|
+
attributes: { backend: this.options.name, kind: 'buffer' },
|
|
158
|
+
});
|
|
159
|
+
this.options.logger.warn(`${this.options.name}: buffer drain failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
this.inFlight = false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Final flush on unload: one best-effort export of everything queued;
|
|
167
|
+
* whatever fails goes to the durable buffer for the next process run.
|
|
168
|
+
*/
|
|
169
|
+
async dispose() {
|
|
170
|
+
this.disposed = true;
|
|
171
|
+
if (this.retryTimer !== undefined) {
|
|
172
|
+
clearTimeout(this.retryTimer);
|
|
173
|
+
this.retryTimer = undefined;
|
|
174
|
+
}
|
|
175
|
+
const batch = [...(this.pending ?? []), ...this.queue];
|
|
176
|
+
this.queue = [];
|
|
177
|
+
this.pending = undefined;
|
|
178
|
+
if (batch.length === 0)
|
|
179
|
+
return;
|
|
180
|
+
try {
|
|
181
|
+
await this.options.sink.exportSpans(batch);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
try {
|
|
185
|
+
await this.options.spool.push(this.options.name, batch);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
this.options.logger.warn(`${this.options.name}: final buffer spill failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAkB7C;;;GA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C;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAC5C,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACzD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YACxI,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost pricing: match a model's token usage against the configured pricing
|
|
3
|
+
* table and compute the call cost. No prices are hardcoded — an empty table
|
|
4
|
+
* simply means the cost metric stays silent for that model.
|
|
5
|
+
* @module dsh-observe/pricing
|
|
6
|
+
*/
|
|
7
|
+
import type { PricingRule } from './config.ts';
|
|
8
|
+
import type { TokenCounts } from './model.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Compile a glob pattern (only `*` is special) to an anchored regular
|
|
11
|
+
* expression.
|
|
12
|
+
* @param pattern - the glob pattern over a model id.
|
|
13
|
+
* @returns the compiled matcher.
|
|
14
|
+
*/
|
|
15
|
+
export declare function globToRegExp(pattern: string): RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Find the first pricing rule matching the attribution: `provider` matches
|
|
18
|
+
* exactly when set, `model` matches as a glob.
|
|
19
|
+
* @param pricing - the configured pricing table, in priority order.
|
|
20
|
+
* @param provider - the provider route id.
|
|
21
|
+
* @param model - the model id.
|
|
22
|
+
* @returns the first matching rule, or undefined.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findPrice(pricing: readonly PricingRule[], provider: string, model: string): PricingRule | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Compute the USD cost of one call under a matched rule. Cache-read and
|
|
27
|
+
* cache-write traffic falls back to the input price when the rule does not
|
|
28
|
+
* price them separately.
|
|
29
|
+
* @param rule - the matched pricing rule.
|
|
30
|
+
* @param usage - the normalized token counts.
|
|
31
|
+
* @returns the cost in USD.
|
|
32
|
+
*/
|
|
33
|
+
export declare function costUsd(rule: PricingRule, usage: TokenCounts): number;
|
|
34
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/pricing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,WAAW,GAAG,SAAS,CAIzB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAOrE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost pricing: match a model's token usage against the configured pricing
|
|
3
|
+
* table and compute the call cost. No prices are hardcoded — an empty table
|
|
4
|
+
* simply means the cost metric stays silent for that model.
|
|
5
|
+
* @module dsh-observe/pricing
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Compile a glob pattern (only `*` is special) to an anchored regular
|
|
9
|
+
* expression.
|
|
10
|
+
* @param pattern - the glob pattern over a model id.
|
|
11
|
+
* @returns the compiled matcher.
|
|
12
|
+
*/
|
|
13
|
+
export function globToRegExp(pattern) {
|
|
14
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/gu, '\\$&').replaceAll('*', '.*');
|
|
15
|
+
return new RegExp(`^${escaped}$`, 'u');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Find the first pricing rule matching the attribution: `provider` matches
|
|
19
|
+
* exactly when set, `model` matches as a glob.
|
|
20
|
+
* @param pricing - the configured pricing table, in priority order.
|
|
21
|
+
* @param provider - the provider route id.
|
|
22
|
+
* @param model - the model id.
|
|
23
|
+
* @returns the first matching rule, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
export function findPrice(pricing, provider, model) {
|
|
26
|
+
return pricing.find(rule => (rule.provider === undefined || rule.provider === provider)
|
|
27
|
+
&& globToRegExp(rule.model).test(model));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compute the USD cost of one call under a matched rule. Cache-read and
|
|
31
|
+
* cache-write traffic falls back to the input price when the rule does not
|
|
32
|
+
* price them separately.
|
|
33
|
+
* @param rule - the matched pricing rule.
|
|
34
|
+
* @param usage - the normalized token counts.
|
|
35
|
+
* @returns the cost in USD.
|
|
36
|
+
*/
|
|
37
|
+
export function costUsd(rule, usage) {
|
|
38
|
+
const cacheRead = usage.cacheRead * (rule.cacheReadPerToken ?? rule.inputPerToken);
|
|
39
|
+
const cacheWrite = usage.cacheWrite * (rule.cacheWritePerToken ?? rule.inputPerToken);
|
|
40
|
+
return usage.input * rule.inputPerToken
|
|
41
|
+
+ usage.output * rule.outputPerToken
|
|
42
|
+
+ cacheRead
|
|
43
|
+
+ cacheWrite;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/pricing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpF,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,EAAE,GAAG,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,OAA+B,EAC/B,QAAgB,EAChB,KAAa;IAEb,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzB,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC;WACxD,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,IAAiB,EAAE,KAAkB;IAC3D,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,aAAa,CAAC,CAAA;IAClF,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,aAAa,CAAC,CAAA;IACrF,OAAO,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,aAAa;UACnC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc;UAClC,SAAS;UACT,UAAU,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text projection of model-visible messages and content blocks. Used to
|
|
3
|
+
* turn logged messages into the sanitized prompt/completion strings exported
|
|
4
|
+
* to observability backends; every projection stays reconstructable from the
|
|
5
|
+
* session log (the model-visible ⟺ logged invariant holds — no extra
|
|
6
|
+
* information enters the export).
|
|
7
|
+
* @module dsh-observe/project
|
|
8
|
+
*/
|
|
9
|
+
import type { ContentBlock, Message } from '@deepseek-ai/dsh-llm';
|
|
10
|
+
/**
|
|
11
|
+
* Project content blocks to one compact plain-text string. Text and
|
|
12
|
+
* reasoning deltas pass through verbatim; tool calls render as
|
|
13
|
+
* `<tool-call name(arguments)>`; images render as `[image]`; tool results
|
|
14
|
+
* recurse. Unknown block types (merge-extensible) are skipped — they carry
|
|
15
|
+
* no projectable text.
|
|
16
|
+
* @param blocks - the model-facing content blocks.
|
|
17
|
+
* @returns the joined projection.
|
|
18
|
+
*/
|
|
19
|
+
export declare function projectContent(blocks: readonly ContentBlock[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Project one message with its role prefix.
|
|
22
|
+
* @param message - the logged message.
|
|
23
|
+
* @returns `[role] content` on one logical line.
|
|
24
|
+
*/
|
|
25
|
+
export declare function projectMessage(message: Message): string;
|
|
26
|
+
//# sourceMappingURL=project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEjE;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAyBtE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEvD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text projection of model-visible messages and content blocks. Used to
|
|
3
|
+
* turn logged messages into the sanitized prompt/completion strings exported
|
|
4
|
+
* to observability backends; every projection stays reconstructable from the
|
|
5
|
+
* session log (the model-visible ⟺ logged invariant holds — no extra
|
|
6
|
+
* information enters the export).
|
|
7
|
+
* @module dsh-observe/project
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Project content blocks to one compact plain-text string. Text and
|
|
11
|
+
* reasoning deltas pass through verbatim; tool calls render as
|
|
12
|
+
* `<tool-call name(arguments)>`; images render as `[image]`; tool results
|
|
13
|
+
* recurse. Unknown block types (merge-extensible) are skipped — they carry
|
|
14
|
+
* no projectable text.
|
|
15
|
+
* @param blocks - the model-facing content blocks.
|
|
16
|
+
* @returns the joined projection.
|
|
17
|
+
*/
|
|
18
|
+
export function projectContent(blocks) {
|
|
19
|
+
const parts = [];
|
|
20
|
+
for (const block of blocks) {
|
|
21
|
+
switch (block.type) {
|
|
22
|
+
case 'text':
|
|
23
|
+
parts.push(block.text);
|
|
24
|
+
break;
|
|
25
|
+
case 'reasoning':
|
|
26
|
+
parts.push(block.text);
|
|
27
|
+
break;
|
|
28
|
+
case 'tool-call':
|
|
29
|
+
parts.push(`<tool-call ${block.name}(${block.arguments})>`);
|
|
30
|
+
break;
|
|
31
|
+
case 'image':
|
|
32
|
+
parts.push('[image]');
|
|
33
|
+
break;
|
|
34
|
+
case 'tool-result':
|
|
35
|
+
parts.push(projectContent(block.content) + (block.isError === true ? ' [error]' : ''));
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
// Unknown content block types carry no projectable text.
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return parts.join('\n');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Project one message with its role prefix.
|
|
46
|
+
* @param message - the logged message.
|
|
47
|
+
* @returns `[role] content` on one logical line.
|
|
48
|
+
*/
|
|
49
|
+
export function projectMessage(message) {
|
|
50
|
+
return `[${message.role}] ${projectContent(message.content)}`;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAA+B;IAC5D,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,MAAM;gBACT,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACtB,MAAK;YACP,KAAK,WAAW;gBACd,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACtB,MAAK;YACP,KAAK,WAAW;gBACd,KAAK,CAAC,IAAI,CAAC,cAAc,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,CAAA;gBAC3D,MAAK;YACP,KAAK,OAAO;gBACV,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBACrB,MAAK;YACP,KAAK,aAAa;gBAChB,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;gBACtF,MAAK;YACP;gBACE,yDAAyD;gBACzD,MAAK;QACT,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAA;AAC/D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The optional Typert remote surface: a small `observe` service exposing
|
|
3
|
+
* `observe/status` and `observe/setEnabled` to settings pages and other
|
|
4
|
+
* remote consumers. `setEnabled` is the runtime kill switch — it stops
|
|
5
|
+
* (or resumes) exporting without unmounting the plugin. Mounted only when
|
|
6
|
+
* `remote.enabled: true`; the service itself never exports data.
|
|
7
|
+
*
|
|
8
|
+
* **No `@Remote` method decorators**: the rc.6 typert loader binds the
|
|
9
|
+
* `./typert` manifest invocations (src/typert.host.ts) to same-named public
|
|
10
|
+
* methods, and decorator syntax breaks both the vitest transform pipeline
|
|
11
|
+
* and the plain-Node build output (the dsh-mcp-panel precedent).
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-observe/remote
|
|
14
|
+
*/
|
|
15
|
+
import type { Plugin } from '@deepseek-ai/cordis';
|
|
16
|
+
import type { ObserveStatus } from './wire.ts';
|
|
17
|
+
/** Bindings the remote service reads from the runtime. */
|
|
18
|
+
export interface ObserveRemoteOptions {
|
|
19
|
+
getStatus: () => ObserveStatus;
|
|
20
|
+
setEnabled: (enabled: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build the `observe` Typert remote service as a Cordis plugin class.
|
|
24
|
+
* @param options - the runtime bindings.
|
|
25
|
+
* @returns the service plugin (mount with `ctx.plugin`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function observeRemotePlugin(options: ObserveRemoteOptions): Plugin;
|
|
28
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,aAAa,CAAA;IAC9B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CACvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAyBzE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The optional Typert remote surface: a small `observe` service exposing
|
|
3
|
+
* `observe/status` and `observe/setEnabled` to settings pages and other
|
|
4
|
+
* remote consumers. `setEnabled` is the runtime kill switch — it stops
|
|
5
|
+
* (or resumes) exporting without unmounting the plugin. Mounted only when
|
|
6
|
+
* `remote.enabled: true`; the service itself never exports data.
|
|
7
|
+
*
|
|
8
|
+
* **No `@Remote` method decorators**: the rc.6 typert loader binds the
|
|
9
|
+
* `./typert` manifest invocations (src/typert.host.ts) to same-named public
|
|
10
|
+
* methods, and decorator syntax breaks both the vitest transform pipeline
|
|
11
|
+
* and the plain-Node build output (the dsh-mcp-panel precedent).
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-observe/remote
|
|
14
|
+
*/
|
|
15
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
16
|
+
/**
|
|
17
|
+
* Build the `observe` Typert remote service as a Cordis plugin class.
|
|
18
|
+
* @param options - the runtime bindings.
|
|
19
|
+
* @returns the service plugin (mount with `ctx.plugin`).
|
|
20
|
+
*/
|
|
21
|
+
export function observeRemotePlugin(options) {
|
|
22
|
+
class ObserveRemoteService extends TypertRemoteService {
|
|
23
|
+
/**
|
|
24
|
+
* @param ctx - the mounting context.
|
|
25
|
+
*/
|
|
26
|
+
constructor(ctx) {
|
|
27
|
+
super(ctx, 'observe');
|
|
28
|
+
}
|
|
29
|
+
/** The read-only status snapshot (bound as `observe/status`). */
|
|
30
|
+
status() {
|
|
31
|
+
return options.getStatus();
|
|
32
|
+
}
|
|
33
|
+
/** The runtime kill switch (bound as `observe/setEnabled`). */
|
|
34
|
+
setEnabled(request) {
|
|
35
|
+
const value = request?.enabled;
|
|
36
|
+
if (typeof value !== 'boolean') {
|
|
37
|
+
throw new TypeError('observe.setEnabled requires { enabled: boolean }');
|
|
38
|
+
}
|
|
39
|
+
options.setEnabled(value);
|
|
40
|
+
return { enabled: options.getStatus().enabled };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return ObserveRemoteService;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAStE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,oBAAqB,SAAQ,mBAAmB;QACpD;;WAEG;QACH,YAAY,GAAY;YACtB,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QACvB,CAAC;QAED,iEAAiE;QACjE,MAAM;YACJ,OAAO,OAAO,CAAC,SAAS,EAAE,CAAA;QAC5B,CAAC;QAED,+DAA+D;QAC/D,UAAU,CAAC,OAA6B;YACtC,MAAM,KAAK,GAAY,OAAO,EAAE,OAAO,CAAA;YACvC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAA;YACzE,CAAC;YACD,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YACzB,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,CAAA;QACjD,CAAC;KACF;IACD,OAAO,oBAAyC,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pre-send sanitization layer. Every string or JSON value that could
|
|
3
|
+
* reach an observability backend passes through these pure functions before
|
|
4
|
+
* it is queued, batched, or spooled: key-name redaction and pattern
|
|
5
|
+
* redaction remove secrets and credentials, and per-surface character
|
|
6
|
+
* budgets truncate bodies. Sanitization is pure and deterministic so a
|
|
7
|
+
* replayed session log produces byte-identical exports.
|
|
8
|
+
* @module dsh-observe/sanitize
|
|
9
|
+
*/
|
|
10
|
+
import type { ResolvedSanitize } from './config.ts';
|
|
11
|
+
/** The placeholder replacing any redacted value. */
|
|
12
|
+
export declare const REDACTED = "[REDACTED]";
|
|
13
|
+
/**
|
|
14
|
+
* Truncate text to a character budget, appending an ellipsis marker when
|
|
15
|
+
* content is cut. A budget of zero yields the empty string.
|
|
16
|
+
* @param text - the text to bound.
|
|
17
|
+
* @param budget - maximum character count (marker included).
|
|
18
|
+
* @returns the bounded text.
|
|
19
|
+
*/
|
|
20
|
+
export declare function truncate(text: string, budget: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Apply pattern redaction to one text value: every match of every
|
|
23
|
+
* configured pattern (built-in secret patterns plus the user patterns) is
|
|
24
|
+
* replaced with {@link REDACTED}.
|
|
25
|
+
* @param text - the text to scan.
|
|
26
|
+
* @param policy - the resolved sanitization policy.
|
|
27
|
+
* @returns the redacted text.
|
|
28
|
+
*/
|
|
29
|
+
export declare function redactText(text: string, policy: ResolvedSanitize): string;
|
|
30
|
+
/**
|
|
31
|
+
* Split a key name into its words (snake_case, kebab-case, and camelCase
|
|
32
|
+
* boundaries) for structural key redaction.
|
|
33
|
+
* @param key - the raw key name.
|
|
34
|
+
* @returns lowercase word tokens.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tokenizeKey(key: string): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Whether a structural key name is redacted under the policy: any word
|
|
39
|
+
* token matches one of the redaction key names.
|
|
40
|
+
* @param key - the raw key name.
|
|
41
|
+
* @param policy - the resolved sanitization policy.
|
|
42
|
+
* @returns true when the key's value must be replaced.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isRedactedKey(key: string, policy: ResolvedSanitize): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Deep-clone an arbitrary JSON value while redacting: object keys matching
|
|
47
|
+
* the policy are replaced with {@link REDACTED} (their children are not
|
|
48
|
+
* walked), and every string value is pattern-scanned. Non-JSON exotic
|
|
49
|
+
* values (functions, symbols, class instances) normalize to `null` — the
|
|
50
|
+
* session log guarantees JSON inputs, so that branch exists only as
|
|
51
|
+
* containment for data crossing an untrusted boundary.
|
|
52
|
+
* @param value - the value to sanitize.
|
|
53
|
+
* @param policy - the resolved sanitization policy.
|
|
54
|
+
* @returns a JSON-safe sanitized clone.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sanitizeJson(value: unknown, policy: ResolvedSanitize): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Sanitize and bound one text body: pattern redaction first, then the
|
|
59
|
+
* character budget.
|
|
60
|
+
* @param text - the text to sanitize.
|
|
61
|
+
* @param budget - character budget.
|
|
62
|
+
* @param policy - the resolved sanitization policy.
|
|
63
|
+
* @returns the sanitized, bounded text.
|
|
64
|
+
*/
|
|
65
|
+
export declare function sanitizeText(text: string, budget: number, policy: ResolvedSanitize): string;
|
|
66
|
+
/**
|
|
67
|
+
* Sanitize a value that is either JSON text (parsed for structural key
|
|
68
|
+
* redaction, then re-serialized) or free-form text: a valid JSON parse gets
|
|
69
|
+
* the structural walk, anything else is pattern-scanned as text. Both paths
|
|
70
|
+
* end inside the character budget.
|
|
71
|
+
* @param value - the raw value (typically a tool arguments string).
|
|
72
|
+
* @param budget - character budget.
|
|
73
|
+
* @param policy - the resolved sanitization policy.
|
|
74
|
+
* @returns the sanitized value: re-serialized JSON when the input parsed,
|
|
75
|
+
* plain text otherwise.
|
|
76
|
+
*/
|
|
77
|
+
export declare function sanitizeJsonText(value: string, budget: number, policy: ResolvedSanitize): string;
|
|
78
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD,oDAAoD;AACpD,eAAO,MAAM,QAAQ,eAAe,CAAA;AAEpC;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAOzE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAMjD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAK5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAY9E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAE3F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAShG"}
|