@osfactory/otel-hook 0.11.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 +26 -1
- package/dist/{adapter-DiLknaTF.d.ts → adapter-DQiPu8xF.d.ts} +2 -2
- package/dist/cli.js +371 -65
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +16 -3
- package/dist/config.js.map +1 -1
- package/dist/{destinations-BIl3gGzx.d.ts → destinations-DvqsPulb.d.ts} +1 -1
- package/dist/{events-CSD_YiJ2.d.ts → events-fcomX6d5.d.ts} +22 -0
- package/dist/{export-destinations-QWKGGEjk.d.ts → export-destinations-CI7z4n3i.d.ts} +11 -6
- package/dist/{filesystem-store-D3SCNmbX.d.ts → filesystem-store-CmnUlj1O.d.ts} +1 -1
- package/dist/{hook-BOecWGSz.d.ts → hook-vM_cgqS2.d.ts} +11 -5
- package/dist/index.d.ts +14 -14
- package/dist/index.js +389 -100
- 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 +16 -10
- package/dist/integration.js +341 -71
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +10 -2
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-Cs51jyRk.d.ts → memory-DdU1U91y.d.ts} +2 -2
- package/dist/{metric-model-DDnWxL9d.d.ts → metric-model-C9lLqqpI.d.ts} +4 -1
- package/dist/model.d.ts +1 -1
- package/dist/model.js +9 -1
- package/dist/model.js.map +1 -1
- package/dist/{payload-ChtrEX6A.d.ts → payload-BT19hiVZ.d.ts} +1 -1
- package/dist/{ports-CeqLq31i.d.ts → ports-C3k_5eOQ.d.ts} +33 -2
- package/dist/providers.d.ts +10 -10
- package/dist/providers.js +10 -1
- package/dist/providers.js.map +1 -1
- package/dist/{registry-CcJNF3WY.d.ts → registry-gyJqaWmp.d.ts} +2 -2
- package/dist/runtime.d.ts +97 -9
- package/dist/runtime.js +257 -24
- package/dist/runtime.js.map +1 -1
- package/dist/{schema-DMnoU1V_.d.ts → schema-SpFM6YQY.d.ts} +24 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js +9 -1
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +77 -22
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.js +109 -24
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { O as OtelHookConfig, i as OtelHookConfigPatch } from './schema-
|
|
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';
|
|
@@ -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
|
|
@@ -416,13 +417,19 @@ var providersPolicySchema = z5.strictObject({
|
|
|
416
417
|
readTranscriptUsage: z5.boolean()
|
|
417
418
|
}).optional()
|
|
418
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
|
+
});
|
|
419
424
|
var otelHookConfigSchema = z5.strictObject({
|
|
420
425
|
exporter: exporterPolicySchema,
|
|
421
426
|
privacy: privacyPolicySchema,
|
|
422
427
|
detection: detectionPolicySchema,
|
|
423
428
|
diagnostics: diagnosticsPolicySchema,
|
|
424
429
|
/** Optional so a hand-built configuration from before it existed stays valid. */
|
|
425
|
-
providers: providersPolicySchema.optional()
|
|
430
|
+
providers: providersPolicySchema.optional(),
|
|
431
|
+
/** Optional: absent means no session context is read. */
|
|
432
|
+
sessionContext: sessionContextPolicySchema.optional()
|
|
426
433
|
});
|
|
427
434
|
var otelHookConfigPatchSchema = z5.strictObject({
|
|
428
435
|
// `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
|
|
@@ -438,7 +445,8 @@ var otelHookConfigPatchSchema = z5.strictObject({
|
|
|
438
445
|
diagnostics: diagnosticsPolicySchema.partial().optional(),
|
|
439
446
|
providers: z5.strictObject({
|
|
440
447
|
claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional()
|
|
441
|
-
}).partial().optional()
|
|
448
|
+
}).partial().optional(),
|
|
449
|
+
sessionContext: sessionContextPolicySchema.partial().optional()
|
|
442
450
|
});
|
|
443
451
|
var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
444
452
|
enabled: true,
|
|
@@ -915,11 +923,11 @@ var createPrivacyService = (policyInput) => {
|
|
|
915
923
|
};
|
|
916
924
|
const flattenToAttributes = (value, prefix) => {
|
|
917
925
|
const attributes = {};
|
|
918
|
-
const walk = (current,
|
|
926
|
+
const walk = (current, path4) => {
|
|
919
927
|
if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
920
928
|
const primitive = toAttributePrimitive(current);
|
|
921
929
|
if (primitive !== void 0) {
|
|
922
|
-
attributes[
|
|
930
|
+
attributes[path4] = primitive;
|
|
923
931
|
}
|
|
924
932
|
return;
|
|
925
933
|
}
|
|
@@ -938,16 +946,16 @@ var createPrivacyService = (policyInput) => {
|
|
|
938
946
|
primitives.push(entryPrimitive);
|
|
939
947
|
}
|
|
940
948
|
if (uniform) {
|
|
941
|
-
attributes[
|
|
949
|
+
attributes[path4] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
|
|
942
950
|
return;
|
|
943
951
|
}
|
|
944
952
|
for (const [index, entry] of current.entries()) {
|
|
945
|
-
walk(entry, `${
|
|
953
|
+
walk(entry, `${path4}.${index}`);
|
|
946
954
|
}
|
|
947
955
|
return;
|
|
948
956
|
}
|
|
949
957
|
for (const [key, entry] of Object.entries(current)) {
|
|
950
|
-
walk(entry,
|
|
958
|
+
walk(entry, path4 === "" ? key : `${path4}.${key}`);
|
|
951
959
|
}
|
|
952
960
|
};
|
|
953
961
|
walk(value, prefix);
|
|
@@ -1580,7 +1588,15 @@ var baseEventFields = {
|
|
|
1580
1588
|
* factory, never by hand.
|
|
1581
1589
|
*/
|
|
1582
1590
|
subagentId: subagentIdSchema.optional(),
|
|
1583
|
-
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()
|
|
1584
1600
|
};
|
|
1585
1601
|
var event = (shape) => z13.strictObject({ ...baseEventFields, ...shape });
|
|
1586
1602
|
var sessionStartEventSchema = event({
|
|
@@ -1931,6 +1947,7 @@ var createEventFactory = (input) => {
|
|
|
1931
1947
|
const rest = { ...drafted };
|
|
1932
1948
|
delete rest.target;
|
|
1933
1949
|
delete rest.subagentId;
|
|
1950
|
+
delete rest.contextAttributes;
|
|
1934
1951
|
const sanitized = extensions === void 0 ? { extensions: {}, droppedKeys: [] } : context.privacy.sanitizeExtensions(extensions);
|
|
1935
1952
|
dropped.push(...sanitized.droppedKeys);
|
|
1936
1953
|
const currentSequence = sequence;
|
|
@@ -5781,7 +5798,7 @@ var createFixedClock = (options = {}) => {
|
|
|
5781
5798
|
};
|
|
5782
5799
|
|
|
5783
5800
|
// src/runtime/hook.ts
|
|
5784
|
-
import { z as
|
|
5801
|
+
import { z as z23 } from "zod";
|
|
5785
5802
|
|
|
5786
5803
|
// src/runtime/delivery.ts
|
|
5787
5804
|
var PROVIDER_SCOPE_PREFIX = "provider-session";
|
|
@@ -6056,8 +6073,64 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
|
|
|
6056
6073
|
return fn();
|
|
6057
6074
|
};
|
|
6058
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
|
+
|
|
6059
6132
|
// src/runtime/hook.ts
|
|
6060
|
-
var usageScopeSchema =
|
|
6133
|
+
var usageScopeSchema = z23.enum(["session", "generation", "subagent"]);
|
|
6061
6134
|
var classifyDurability = (input) => {
|
|
6062
6135
|
if (!input.attempted) {
|
|
6063
6136
|
return "nothing-to-deliver";
|
|
@@ -6765,6 +6838,10 @@ var createOtelHook = (deps) => {
|
|
|
6765
6838
|
});
|
|
6766
6839
|
}
|
|
6767
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
|
+
);
|
|
6768
6845
|
let emitted = 0;
|
|
6769
6846
|
let exportRejected = 0;
|
|
6770
6847
|
if (!suppress && batch.length > 0) {
|
|
@@ -6880,6 +6957,13 @@ var createOtelHook = (deps) => {
|
|
|
6880
6957
|
};
|
|
6881
6958
|
return { resolveDelivery, ingest, flush, shutdown, config };
|
|
6882
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
|
+
};
|
|
6883
6967
|
var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
|
|
6884
6968
|
const events = [];
|
|
6885
6969
|
for (const [index, info] of diagnostics.slice(0, MAX_ERROR_EVENTS).entries()) {
|
|
@@ -7032,11 +7116,11 @@ var createRecordingLogger = (level = "debug") => {
|
|
|
7032
7116
|
};
|
|
7033
7117
|
|
|
7034
7118
|
// src/testing/fixture-adapter.ts
|
|
7035
|
-
import { z as
|
|
7036
|
-
var syntheticPayloadSchema =
|
|
7037
|
-
provider:
|
|
7038
|
-
sessionId:
|
|
7039
|
-
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([
|
|
7040
7124
|
"session.start",
|
|
7041
7125
|
"prompt",
|
|
7042
7126
|
"generation",
|
|
@@ -7046,15 +7130,15 @@ var syntheticPayloadSchema = z23.object({
|
|
|
7046
7130
|
"session.end",
|
|
7047
7131
|
"noop"
|
|
7048
7132
|
]),
|
|
7049
|
-
requestId:
|
|
7050
|
-
model:
|
|
7051
|
-
promptText:
|
|
7052
|
-
toolName:
|
|
7053
|
-
toolInput:
|
|
7054
|
-
workspaceKey:
|
|
7055
|
-
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(),
|
|
7056
7140
|
usage: usageReportSchema.optional(),
|
|
7057
|
-
agentVersion:
|
|
7141
|
+
agentVersion: z24.string().min(1).optional()
|
|
7058
7142
|
});
|
|
7059
7143
|
var SYNTHETIC_PROVIDER_ID = "fixture";
|
|
7060
7144
|
var DEFAULT_FIXTURE_CAPABILITIES = Object.freeze({
|
|
@@ -7459,7 +7543,8 @@ var createTestHook = (options = {}) => {
|
|
|
7459
7543
|
logger,
|
|
7460
7544
|
...options.worktreeLocator === void 0 ? {} : { worktreeLocator: options.worktreeLocator },
|
|
7461
7545
|
...options.targetResolutionBudgetMillis === void 0 ? {} : { targetResolutionBudgetMillis: options.targetResolutionBudgetMillis },
|
|
7462
|
-
...options.payloadEnrichers === void 0 ? {} : { payloadEnrichers: options.payloadEnrichers }
|
|
7546
|
+
...options.payloadEnrichers === void 0 ? {} : { payloadEnrichers: options.payloadEnrichers },
|
|
7547
|
+
...options.sessionContext === void 0 ? {} : { sessionContext: options.sessionContext }
|
|
7463
7548
|
});
|
|
7464
7549
|
return { hook, sink, stateStore, clock, ids, privacy, logger, registry, config };
|
|
7465
7550
|
};
|