@osfactory/otel-hook 0.10.0 → 0.12.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 +108 -4
- package/dist/{adapter-B9RwW6TO.d.ts → adapter-DQiPu8xF.d.ts} +2 -2
- package/dist/cli.js +1495 -135
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +11 -4
- package/dist/config.js +116 -21
- package/dist/config.js.map +1 -1
- package/dist/{destinations-DWOkVxV1.d.ts → destinations-DvqsPulb.d.ts} +12 -2
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/{events-CSD_YiJ2.d.ts → events-fcomX6d5.d.ts} +22 -0
- package/dist/{export-destinations-lORbe25J.d.ts → export-destinations-CI7z4n3i.d.ts} +136 -6
- package/dist/{filesystem-store-DX3dGIgu.d.ts → filesystem-store-CmnUlj1O.d.ts} +1 -1
- package/dist/{hook-BAxXoKsp.d.ts → hook-vM_cgqS2.d.ts} +11 -5
- package/dist/index.d.ts +16 -16
- package/dist/index.js +1496 -183
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +9 -1
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +36 -12
- package/dist/integration.js +1464 -231
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +55 -4
- package/dist/lifecycle.js +279 -5
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-aJilVG4R.d.ts → memory-DdU1U91y.d.ts} +2 -2
- package/dist/{semconv-Dw7gcQcg.d.ts → metric-model-C9lLqqpI.d.ts} +157 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +9 -1
- package/dist/model.js.map +1 -1
- package/dist/{payload-D7gc0-WQ.d.ts → payload-BT19hiVZ.d.ts} +1 -1
- package/dist/{ports-plO5MKrY.d.ts → ports-C3k_5eOQ.d.ts} +57 -2
- package/dist/providers.d.ts +10 -10
- package/dist/providers.js +10 -1
- package/dist/providers.js.map +1 -1
- package/dist/{registry-C7XO4DzD.d.ts → registry-gyJqaWmp.d.ts} +2 -2
- package/dist/runtime.d.ts +97 -9
- package/dist/runtime.js +312 -33
- package/dist/runtime.js.map +1 -1
- package/dist/{schema-CHb3GU1r.d.ts → schema-SpFM6YQY.d.ts} +87 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js +32 -1
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +929 -31
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +11 -9
- package/dist/testing.js +164 -33
- package/dist/testing.js.map +1 -1
- package/package.json +3 -1
package/dist/testing.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { O as OtelHookConfig,
|
|
2
|
-
import { b as CanonicalEvent } from './events-
|
|
1
|
+
import { O as OtelHookConfig, i as OtelHookConfigPatch } from './schema-SpFM6YQY.js';
|
|
2
|
+
import { b as CanonicalEvent } from './events-fcomX6d5.js';
|
|
3
3
|
import { I as IdentityClaim, d as InvocationIdentity, S as SourceProvenance } from './identity-BrVBs901.js';
|
|
4
4
|
import { P as PrivacyService } from './service-CbI9CObT.js';
|
|
5
|
-
import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-
|
|
6
|
-
import { P as ProviderRegistry } from './registry-
|
|
7
|
-
import { I as IdGenerator, W as WorktreeLocator, P as PayloadEnricher } from './ports-
|
|
8
|
-
import { c as RecordingTelemetrySink, I as InMemoryStateStore, F as FixedClock, R as RecordingLogger } from './memory-
|
|
9
|
-
export { e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, j as createRecordingLogger, k as createRecordingTelemetrySink } from './memory-
|
|
10
|
-
import { O as OtelHook } from './hook-
|
|
5
|
+
import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-DQiPu8xF.js';
|
|
6
|
+
import { P as ProviderRegistry } from './registry-gyJqaWmp.js';
|
|
7
|
+
import { I as IdGenerator, W as WorktreeLocator, P as PayloadEnricher, S as SessionContextReader } from './ports-C3k_5eOQ.js';
|
|
8
|
+
import { c as RecordingTelemetrySink, I as InMemoryStateStore, F as FixedClock, R as RecordingLogger } from './memory-DdU1U91y.js';
|
|
9
|
+
export { e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, j as createRecordingLogger, k as createRecordingTelemetrySink } from './memory-DdU1U91y.js';
|
|
10
|
+
import { O as OtelHook } from './hook-vM_cgqS2.js';
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
import { a as ContentDisclosure, b as ContentFact } from './content-M9xIKG7h.js';
|
|
13
13
|
import './primitives-CJ8-rn-f.js';
|
|
@@ -43,8 +43,8 @@ declare const syntheticPayloadSchema: z.ZodObject<{
|
|
|
43
43
|
occurredAt: z.ZodOptional<z.ZodNumber>;
|
|
44
44
|
usage: z.ZodOptional<z.ZodObject<{
|
|
45
45
|
temporality: z.ZodEnum<{
|
|
46
|
-
delta: "delta";
|
|
47
46
|
cumulative: "cumulative";
|
|
47
|
+
delta: "delta";
|
|
48
48
|
}>;
|
|
49
49
|
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
50
50
|
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -146,6 +146,8 @@ type TestHarnessOptions = {
|
|
|
146
146
|
readonly targetResolutionBudgetMillis?: number;
|
|
147
147
|
/** Payload enrichers, as a host would configure them (none by default). */
|
|
148
148
|
readonly payloadEnrichers?: readonly PayloadEnricher[];
|
|
149
|
+
/** Session context reader (none by default), e.g. a fake or the directory reader. */
|
|
150
|
+
readonly sessionContext?: SessionContextReader;
|
|
149
151
|
};
|
|
150
152
|
type TestHarness = {
|
|
151
153
|
readonly hook: OtelHook;
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/config/schema.ts
|
|
2
|
+
import { isAbsolute } from "path";
|
|
2
3
|
import { z as z5 } from "zod";
|
|
3
4
|
|
|
4
5
|
// src/model/primitives.ts
|
|
@@ -161,7 +162,7 @@ var HEADER_ENV_REFERENCE_PREFIX = "env:";
|
|
|
161
162
|
var HEADER_NAME_PATTERN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
|
|
162
163
|
var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
163
164
|
var MAX_HEADER_VALUE_LENGTH = 8192;
|
|
164
|
-
var exportSignalSchema = z3.enum(["traces", "logs"]);
|
|
165
|
+
var exportSignalSchema = z3.enum(["traces", "logs", "metrics"]);
|
|
165
166
|
var headerValueSchema = z3.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
|
|
166
167
|
(value) => !isUnsafeHeaderValue(value),
|
|
167
168
|
"header values may not contain line breaks, control characters, or characters beyond Latin-1"
|
|
@@ -184,6 +185,8 @@ var exportDestinationSchema = z3.strictObject({
|
|
|
184
185
|
tracesEndpoint: endpointSchema.optional(),
|
|
185
186
|
/** Per-signal override of the derived logs URL. */
|
|
186
187
|
logsEndpoint: endpointSchema.optional(),
|
|
188
|
+
/** Per-signal override of the derived metrics URL (`/v1/traces` becomes `/v1/metrics`). */
|
|
189
|
+
metricsEndpoint: endpointSchema.optional(),
|
|
187
190
|
/** Defaults to `exporter.protocol`. */
|
|
188
191
|
protocol: z3.enum(["http/protobuf", "http/json", "none"]).optional(),
|
|
189
192
|
/**
|
|
@@ -196,15 +199,17 @@ var exportDestinationSchema = z3.strictObject({
|
|
|
196
199
|
`at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
|
|
197
200
|
).optional(),
|
|
198
201
|
/**
|
|
199
|
-
* Which signals this destination receives. Default:
|
|
200
|
-
* still governed by `exporter.logs.enabled`, which stays the one
|
|
201
|
-
*
|
|
202
|
+
* Which signals this destination receives. Default: traces and logs. The logs
|
|
203
|
+
* signal is still governed by `exporter.logs.enabled`, which stays the one
|
|
204
|
+
* opt-in for content-bearing records leaving the host. `metrics` is never on by
|
|
205
|
+
* default: a destination receives hook-derived metrics only when it lists them.
|
|
202
206
|
*/
|
|
203
|
-
signals: z3.array(exportSignalSchema).min(1).max(
|
|
207
|
+
signals: z3.array(exportSignalSchema).min(1).max(3).readonly().optional()
|
|
204
208
|
}).refine(
|
|
205
|
-
(destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0,
|
|
206
|
-
"a destination needs an endpoint, or a tracesEndpoint / logsEndpoint"
|
|
209
|
+
(destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
|
|
210
|
+
"a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
|
|
207
211
|
);
|
|
212
|
+
var DEFAULT_DESTINATION_SIGNALS = Object.freeze(["traces", "logs"]);
|
|
208
213
|
var exportDestinationsSchema = z3.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
|
|
209
214
|
const seen = /* @__PURE__ */ new Set();
|
|
210
215
|
destinations.forEach((destination, index) => {
|
|
@@ -329,6 +334,18 @@ var DEFAULT_LOGS_POLICY = Object.freeze({
|
|
|
329
334
|
includeContent: false,
|
|
330
335
|
maxBatchSize: 128
|
|
331
336
|
});
|
|
337
|
+
var metricsPolicySchema = z5.strictObject({
|
|
338
|
+
enabled: z5.boolean(),
|
|
339
|
+
/** Full URL. Absent, derived from `endpoint` (`/v1/traces` becomes `/v1/metrics`). */
|
|
340
|
+
endpoint: z5.string().url().max(2048).optional(),
|
|
341
|
+
temporality: z5.enum(["cumulative", "delta"]),
|
|
342
|
+
includeSessionId: z5.boolean()
|
|
343
|
+
});
|
|
344
|
+
var DEFAULT_METRICS_POLICY = Object.freeze({
|
|
345
|
+
enabled: false,
|
|
346
|
+
temporality: "cumulative",
|
|
347
|
+
includeSessionId: true
|
|
348
|
+
});
|
|
332
349
|
var exporterPolicySchema = z5.strictObject({
|
|
333
350
|
enabled: z5.boolean(),
|
|
334
351
|
protocol: z5.enum(["http/protobuf", "http/json", "none"]),
|
|
@@ -359,6 +376,11 @@ var exporterPolicySchema = z5.strictObject({
|
|
|
359
376
|
* a second top-level section would invite two of each to drift apart.
|
|
360
377
|
*/
|
|
361
378
|
logs: logsPolicySchema,
|
|
379
|
+
/**
|
|
380
|
+
* Hook-derived metrics. Optional so an `ExporterPolicy` built by hand before
|
|
381
|
+
* metrics existed stays valid; absent reads as {@link DEFAULT_METRICS_POLICY}.
|
|
382
|
+
*/
|
|
383
|
+
metrics: metricsPolicySchema.optional(),
|
|
362
384
|
/**
|
|
363
385
|
* Additional OTLP destinations, each sent every batch in parallel.
|
|
364
386
|
*
|
|
@@ -395,20 +417,27 @@ var providersPolicySchema = z5.strictObject({
|
|
|
395
417
|
readTranscriptUsage: z5.boolean()
|
|
396
418
|
}).optional()
|
|
397
419
|
});
|
|
420
|
+
var sessionContextPolicySchema = z5.strictObject({
|
|
421
|
+
/** Absolute path of the context directory. */
|
|
422
|
+
dir: z5.string().min(1).max(4096).refine((value) => isAbsolute(value), { message: "must be an absolute path" })
|
|
423
|
+
});
|
|
398
424
|
var otelHookConfigSchema = z5.strictObject({
|
|
399
425
|
exporter: exporterPolicySchema,
|
|
400
426
|
privacy: privacyPolicySchema,
|
|
401
427
|
detection: detectionPolicySchema,
|
|
402
428
|
diagnostics: diagnosticsPolicySchema,
|
|
403
429
|
/** Optional so a hand-built configuration from before it existed stays valid. */
|
|
404
|
-
providers: providersPolicySchema.optional()
|
|
430
|
+
providers: providersPolicySchema.optional(),
|
|
431
|
+
/** Optional: absent means no session context is read. */
|
|
432
|
+
sessionContext: sessionContextPolicySchema.optional()
|
|
405
433
|
});
|
|
406
434
|
var otelHookConfigPatchSchema = z5.strictObject({
|
|
407
435
|
// `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
|
|
408
436
|
// merging happens per leaf, so a layer must be able to set `logs.enabled` alone
|
|
409
437
|
// without also restating the endpoint and the batch size.
|
|
410
|
-
exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
|
|
438
|
+
exporter: exporterPolicySchema.omit({ logs: true, metrics: true, spool: true }).partial().extend({
|
|
411
439
|
logs: logsPolicySchema.partial().optional(),
|
|
440
|
+
metrics: metricsPolicySchema.partial().optional(),
|
|
412
441
|
spool: spoolPolicySchema.partial().optional()
|
|
413
442
|
}).optional(),
|
|
414
443
|
privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
|
|
@@ -416,7 +445,8 @@ var otelHookConfigPatchSchema = z5.strictObject({
|
|
|
416
445
|
diagnostics: diagnosticsPolicySchema.partial().optional(),
|
|
417
446
|
providers: z5.strictObject({
|
|
418
447
|
claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional()
|
|
419
|
-
}).partial().optional()
|
|
448
|
+
}).partial().optional(),
|
|
449
|
+
sessionContext: sessionContextPolicySchema.partial().optional()
|
|
420
450
|
});
|
|
421
451
|
var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
422
452
|
enabled: true,
|
|
@@ -428,7 +458,8 @@ var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
|
428
458
|
maxRetryAttempts: 2,
|
|
429
459
|
serviceName: "coding-agent",
|
|
430
460
|
resourceAttributes: EMPTY_RESOURCE_ATTRIBUTES,
|
|
431
|
-
logs: DEFAULT_LOGS_POLICY
|
|
461
|
+
logs: DEFAULT_LOGS_POLICY,
|
|
462
|
+
metrics: DEFAULT_METRICS_POLICY
|
|
432
463
|
});
|
|
433
464
|
var DEFAULT_DETECTION_POLICY = Object.freeze({
|
|
434
465
|
minimumConfidence: "strong",
|
|
@@ -892,11 +923,11 @@ var createPrivacyService = (policyInput) => {
|
|
|
892
923
|
};
|
|
893
924
|
const flattenToAttributes = (value, prefix) => {
|
|
894
925
|
const attributes = {};
|
|
895
|
-
const walk = (current,
|
|
926
|
+
const walk = (current, path4) => {
|
|
896
927
|
if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
897
928
|
const primitive = toAttributePrimitive(current);
|
|
898
929
|
if (primitive !== void 0) {
|
|
899
|
-
attributes[
|
|
930
|
+
attributes[path4] = primitive;
|
|
900
931
|
}
|
|
901
932
|
return;
|
|
902
933
|
}
|
|
@@ -915,16 +946,16 @@ var createPrivacyService = (policyInput) => {
|
|
|
915
946
|
primitives.push(entryPrimitive);
|
|
916
947
|
}
|
|
917
948
|
if (uniform) {
|
|
918
|
-
attributes[
|
|
949
|
+
attributes[path4] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
|
|
919
950
|
return;
|
|
920
951
|
}
|
|
921
952
|
for (const [index, entry] of current.entries()) {
|
|
922
|
-
walk(entry, `${
|
|
953
|
+
walk(entry, `${path4}.${index}`);
|
|
923
954
|
}
|
|
924
955
|
return;
|
|
925
956
|
}
|
|
926
957
|
for (const [key, entry] of Object.entries(current)) {
|
|
927
|
-
walk(entry,
|
|
958
|
+
walk(entry, path4 === "" ? key : `${path4}.${key}`);
|
|
928
959
|
}
|
|
929
960
|
};
|
|
930
961
|
walk(value, prefix);
|
|
@@ -1557,7 +1588,15 @@ var baseEventFields = {
|
|
|
1557
1588
|
* factory, never by hand.
|
|
1558
1589
|
*/
|
|
1559
1590
|
subagentId: subagentIdSchema.optional(),
|
|
1560
|
-
extensions: extensionsSchema.default(emptyExtensions)
|
|
1591
|
+
extensions: extensionsSchema.default(emptyExtensions),
|
|
1592
|
+
/**
|
|
1593
|
+
* Attributes of the session context segment in force when the event
|
|
1594
|
+
* occurred (`docs/session-context.md`), stamped by the core from a file a
|
|
1595
|
+
* harness wrote. Exported on every record of the event, over the same keys
|
|
1596
|
+
* from the Resource. Absent when no context applies. Set by the core only,
|
|
1597
|
+
* never by an adapter.
|
|
1598
|
+
*/
|
|
1599
|
+
contextAttributes: z13.record(z13.string().min(1).max(255), z13.union([z13.string(), z13.number(), z13.boolean()])).optional()
|
|
1561
1600
|
};
|
|
1562
1601
|
var event = (shape) => z13.strictObject({ ...baseEventFields, ...shape });
|
|
1563
1602
|
var sessionStartEventSchema = event({
|
|
@@ -1908,6 +1947,7 @@ var createEventFactory = (input) => {
|
|
|
1908
1947
|
const rest = { ...drafted };
|
|
1909
1948
|
delete rest.target;
|
|
1910
1949
|
delete rest.subagentId;
|
|
1950
|
+
delete rest.contextAttributes;
|
|
1911
1951
|
const sanitized = extensions === void 0 ? { extensions: {}, droppedKeys: [] } : context.privacy.sanitizeExtensions(extensions);
|
|
1912
1952
|
dropped.push(...sanitized.droppedKeys);
|
|
1913
1953
|
const currentSequence = sequence;
|
|
@@ -5758,7 +5798,7 @@ var createFixedClock = (options = {}) => {
|
|
|
5758
5798
|
};
|
|
5759
5799
|
|
|
5760
5800
|
// src/runtime/hook.ts
|
|
5761
|
-
import { z as
|
|
5801
|
+
import { z as z23 } from "zod";
|
|
5762
5802
|
|
|
5763
5803
|
// src/runtime/delivery.ts
|
|
5764
5804
|
var PROVIDER_SCOPE_PREFIX = "provider-session";
|
|
@@ -5865,6 +5905,29 @@ var stateValueSchema = z21.discriminatedUnion("kind", [
|
|
|
5865
5905
|
* (Claude Code's transcript), so the next read starts where the last ended.
|
|
5866
5906
|
* `source` is an opaque digest of what was read, never a path.
|
|
5867
5907
|
*/
|
|
5908
|
+
/**
|
|
5909
|
+
* Running state of one metric series (issue #69), so a cumulative data point
|
|
5910
|
+
* exported by a later hook process continues the same total. Holds numbers and
|
|
5911
|
+
* a series digest only; the series' attributes are re-supplied by the caller
|
|
5912
|
+
* and never read back from disk.
|
|
5913
|
+
*/
|
|
5914
|
+
z21.strictObject({
|
|
5915
|
+
kind: z21.literal("metric-series"),
|
|
5916
|
+
/** Start of the cumulative interval. */
|
|
5917
|
+
startTimeMillis: epochMillisSchema,
|
|
5918
|
+
/** Counters: the running total. */
|
|
5919
|
+
value: z21.number().finite().min(0).optional(),
|
|
5920
|
+
/** Histograms: the running aggregation. */
|
|
5921
|
+
histogram: z21.strictObject({
|
|
5922
|
+
count: z21.number().int().min(0),
|
|
5923
|
+
sum: z21.number().finite().min(0),
|
|
5924
|
+
min: z21.number().finite(),
|
|
5925
|
+
max: z21.number().finite(),
|
|
5926
|
+
bucketCounts: z21.array(z21.number().int().min(0)).max(64)
|
|
5927
|
+
}).optional(),
|
|
5928
|
+
/** Opaque digest of the last delivery folded in; makes a replay a no-op. */
|
|
5929
|
+
appliedDelivery: z21.string().regex(/^[A-Za-z0-9_-]{1,128}$/).optional()
|
|
5930
|
+
}),
|
|
5868
5931
|
z21.strictObject({
|
|
5869
5932
|
kind: z21.literal("read-cursor"),
|
|
5870
5933
|
source: z21.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
|
|
@@ -6010,8 +6073,64 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
|
|
|
6010
6073
|
return fn();
|
|
6011
6074
|
};
|
|
6012
6075
|
|
|
6076
|
+
// src/runtime/session-context.ts
|
|
6077
|
+
import { open as open2 } from "fs/promises";
|
|
6078
|
+
import * as path3 from "path";
|
|
6079
|
+
import { z as z22 } from "zod";
|
|
6080
|
+
var SESSION_CONTEXT_FILE_VERSION = 1;
|
|
6081
|
+
var DEFAULT_SESSION_CONTEXT_MAX_BYTES = 256 * 1024;
|
|
6082
|
+
var MAX_SESSION_CONTEXT_SEGMENTS = 1024;
|
|
6083
|
+
var SESSION_CONTEXT_AGENT_TOOLS = Object.freeze({
|
|
6084
|
+
"claude-code": "claude_code",
|
|
6085
|
+
codex: "codex",
|
|
6086
|
+
cursor: "cursor",
|
|
6087
|
+
"gemini-cli": "gemini_cli",
|
|
6088
|
+
antigravity: "antigravity"
|
|
6089
|
+
});
|
|
6090
|
+
var RESERVED_CONTEXT_PREFIXES = Object.freeze(["factory.local.", "otelhook."]);
|
|
6091
|
+
var ISO_INSTANT_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
6092
|
+
var isoInstantSchema = z22.string().max(64).regex(ISO_INSTANT_PATTERN).transform((value, ctx) => {
|
|
6093
|
+
const millis = Date.parse(value);
|
|
6094
|
+
if (!Number.isFinite(millis)) {
|
|
6095
|
+
ctx.issues.push({ code: "custom", input: value, message: "not a valid instant" });
|
|
6096
|
+
return z22.NEVER;
|
|
6097
|
+
}
|
|
6098
|
+
return millis;
|
|
6099
|
+
});
|
|
6100
|
+
var segmentSchema = z22.object({
|
|
6101
|
+
from: isoInstantSchema,
|
|
6102
|
+
to: isoInstantSchema.nullable(),
|
|
6103
|
+
reason: z22.string().max(256).optional(),
|
|
6104
|
+
attributes: z22.record(z22.string(), z22.unknown())
|
|
6105
|
+
});
|
|
6106
|
+
var sessionContextFileSchema = z22.object({
|
|
6107
|
+
version: z22.literal(SESSION_CONTEXT_FILE_VERSION),
|
|
6108
|
+
agentTool: z22.string().max(64).optional(),
|
|
6109
|
+
sessionId: z22.string().max(256).optional(),
|
|
6110
|
+
segments: z22.array(segmentSchema).max(MAX_SESSION_CONTEXT_SEGMENTS)
|
|
6111
|
+
});
|
|
6112
|
+
var segmentInForce = (segments, at) => {
|
|
6113
|
+
let best;
|
|
6114
|
+
for (const segment of segments) {
|
|
6115
|
+
if (segment.from <= at && (segment.to === null || at < segment.to)) {
|
|
6116
|
+
if (best === void 0 || segment.from >= best.from) {
|
|
6117
|
+
best = segment;
|
|
6118
|
+
}
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
6121
|
+
return best;
|
|
6122
|
+
};
|
|
6123
|
+
var stampSessionContext = (events, segments) => events.map((event3) => {
|
|
6124
|
+
const { contextAttributes: _discarded, ...rest } = event3;
|
|
6125
|
+
const segment = segments === void 0 ? void 0 : segmentInForce(segments, event3.occurredAt);
|
|
6126
|
+
if (segment === void 0 || Object.keys(segment.attributes).length === 0) {
|
|
6127
|
+
return _discarded === void 0 ? event3 : rest;
|
|
6128
|
+
}
|
|
6129
|
+
return { ...rest, contextAttributes: { ...segment.attributes } };
|
|
6130
|
+
});
|
|
6131
|
+
|
|
6013
6132
|
// src/runtime/hook.ts
|
|
6014
|
-
var usageScopeSchema =
|
|
6133
|
+
var usageScopeSchema = z23.enum(["session", "generation", "subagent"]);
|
|
6015
6134
|
var classifyDurability = (input) => {
|
|
6016
6135
|
if (!input.attempted) {
|
|
6017
6136
|
return "nothing-to-deliver";
|
|
@@ -6719,6 +6838,10 @@ var createOtelHook = (deps) => {
|
|
|
6719
6838
|
});
|
|
6720
6839
|
}
|
|
6721
6840
|
}
|
|
6841
|
+
batch = stampSessionContext(
|
|
6842
|
+
batch,
|
|
6843
|
+
!suppress && batch.length > 0 && deps.sessionContext !== void 0 ? await readSessionContext(deps.sessionContext, detection.providerId, identity.sessionId) : void 0
|
|
6844
|
+
);
|
|
6722
6845
|
let emitted = 0;
|
|
6723
6846
|
let exportRejected = 0;
|
|
6724
6847
|
if (!suppress && batch.length > 0) {
|
|
@@ -6834,6 +6957,13 @@ var createOtelHook = (deps) => {
|
|
|
6834
6957
|
};
|
|
6835
6958
|
return { resolveDelivery, ingest, flush, shutdown, config };
|
|
6836
6959
|
};
|
|
6960
|
+
var readSessionContext = async (reader, providerId, sessionId) => {
|
|
6961
|
+
try {
|
|
6962
|
+
return await reader.read({ providerId, sessionId });
|
|
6963
|
+
} catch {
|
|
6964
|
+
return void 0;
|
|
6965
|
+
}
|
|
6966
|
+
};
|
|
6837
6967
|
var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
|
|
6838
6968
|
const events = [];
|
|
6839
6969
|
for (const [index, info] of diagnostics.slice(0, MAX_ERROR_EVENTS).entries()) {
|
|
@@ -6986,11 +7116,11 @@ var createRecordingLogger = (level = "debug") => {
|
|
|
6986
7116
|
};
|
|
6987
7117
|
|
|
6988
7118
|
// src/testing/fixture-adapter.ts
|
|
6989
|
-
import { z as
|
|
6990
|
-
var syntheticPayloadSchema =
|
|
6991
|
-
provider:
|
|
6992
|
-
sessionId:
|
|
6993
|
-
event:
|
|
7119
|
+
import { z as z24 } from "zod";
|
|
7120
|
+
var syntheticPayloadSchema = z24.object({
|
|
7121
|
+
provider: z24.string().min(1),
|
|
7122
|
+
sessionId: z24.string().min(1),
|
|
7123
|
+
event: z24.enum([
|
|
6994
7124
|
"session.start",
|
|
6995
7125
|
"prompt",
|
|
6996
7126
|
"generation",
|
|
@@ -7000,15 +7130,15 @@ var syntheticPayloadSchema = z23.object({
|
|
|
7000
7130
|
"session.end",
|
|
7001
7131
|
"noop"
|
|
7002
7132
|
]),
|
|
7003
|
-
requestId:
|
|
7004
|
-
model:
|
|
7005
|
-
promptText:
|
|
7006
|
-
toolName:
|
|
7007
|
-
toolInput:
|
|
7008
|
-
workspaceKey:
|
|
7009
|
-
occurredAt:
|
|
7133
|
+
requestId: z24.string().min(1).optional(),
|
|
7134
|
+
model: z24.string().min(1).optional(),
|
|
7135
|
+
promptText: z24.string().optional(),
|
|
7136
|
+
toolName: z24.string().min(1).optional(),
|
|
7137
|
+
toolInput: z24.unknown().optional(),
|
|
7138
|
+
workspaceKey: z24.string().min(1).optional(),
|
|
7139
|
+
occurredAt: z24.number().int().min(0).optional(),
|
|
7010
7140
|
usage: usageReportSchema.optional(),
|
|
7011
|
-
agentVersion:
|
|
7141
|
+
agentVersion: z24.string().min(1).optional()
|
|
7012
7142
|
});
|
|
7013
7143
|
var SYNTHETIC_PROVIDER_ID = "fixture";
|
|
7014
7144
|
var DEFAULT_FIXTURE_CAPABILITIES = Object.freeze({
|
|
@@ -7413,7 +7543,8 @@ var createTestHook = (options = {}) => {
|
|
|
7413
7543
|
logger,
|
|
7414
7544
|
...options.worktreeLocator === void 0 ? {} : { worktreeLocator: options.worktreeLocator },
|
|
7415
7545
|
...options.targetResolutionBudgetMillis === void 0 ? {} : { targetResolutionBudgetMillis: options.targetResolutionBudgetMillis },
|
|
7416
|
-
...options.payloadEnrichers === void 0 ? {} : { payloadEnrichers: options.payloadEnrichers }
|
|
7546
|
+
...options.payloadEnrichers === void 0 ? {} : { payloadEnrichers: options.payloadEnrichers },
|
|
7547
|
+
...options.sessionContext === void 0 ? {} : { sessionContext: options.sessionContext }
|
|
7417
7548
|
});
|
|
7418
7549
|
return { hook, sink, stateStore, clock, ids, privacy, logger, registry, config };
|
|
7419
7550
|
};
|