@bradygaster/squad-sdk 0.8.0 → 0.8.2
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/adapter/client.d.ts +19 -1
- package/dist/adapter/client.d.ts.map +1 -1
- package/dist/adapter/client.js +245 -75
- package/dist/adapter/client.js.map +1 -1
- package/dist/agents/index.d.ts +6 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +132 -23
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lifecycle.d.ts.map +1 -1
- package/dist/agents/lifecycle.js +28 -2
- package/dist/agents/lifecycle.js.map +1 -1
- package/dist/agents/model-selector.d.ts.map +1 -1
- package/dist/agents/model-selector.js +10 -37
- package/dist/agents/model-selector.js.map +1 -1
- package/dist/casting/index.d.ts.map +1 -1
- package/dist/casting/index.js +10 -2
- package/dist/casting/index.js.map +1 -1
- package/dist/client/event-bus.d.ts.map +1 -1
- package/dist/client/event-bus.js +0 -1
- package/dist/client/event-bus.js.map +1 -1
- package/dist/config/init.d.ts.map +1 -1
- package/dist/config/init.js +19 -12
- package/dist/config/init.js.map +1 -1
- package/dist/coordinator/coordinator.d.ts.map +1 -1
- package/dist/coordinator/coordinator.js +73 -55
- package/dist/coordinator/coordinator.js.map +1 -1
- package/dist/coordinator/index.d.ts +19 -4
- package/dist/coordinator/index.d.ts.map +1 -1
- package/dist/coordinator/index.js +138 -21
- package/dist/coordinator/index.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/ralph/index.d.ts +3 -1
- package/dist/ralph/index.d.ts.map +1 -1
- package/dist/ralph/index.js +83 -16
- package/dist/ralph/index.js.map +1 -1
- package/dist/runtime/config.d.ts +3 -2
- package/dist/runtime/config.d.ts.map +1 -1
- package/dist/runtime/config.js +7 -6
- package/dist/runtime/config.js.map +1 -1
- package/dist/runtime/constants.d.ts +35 -0
- package/dist/runtime/constants.d.ts.map +1 -0
- package/dist/runtime/constants.js +58 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/event-bus-otel-bridge.d.ts +19 -0
- package/dist/runtime/event-bus-otel-bridge.d.ts.map +1 -0
- package/dist/runtime/event-bus-otel-bridge.js +61 -0
- package/dist/runtime/event-bus-otel-bridge.js.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts +35 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.js +55 -0
- package/dist/runtime/event-bus-ws-bridge.js.map +1 -0
- package/dist/runtime/event-payloads.d.ts +108 -0
- package/dist/runtime/event-payloads.d.ts.map +1 -0
- package/dist/runtime/event-payloads.js +28 -0
- package/dist/runtime/event-payloads.js.map +1 -0
- package/dist/runtime/health.d.ts.map +1 -1
- package/dist/runtime/health.js +2 -1
- package/dist/runtime/health.js.map +1 -1
- package/dist/runtime/otel-bridge.d.ts +52 -0
- package/dist/runtime/otel-bridge.d.ts.map +1 -0
- package/dist/runtime/otel-bridge.js +132 -0
- package/dist/runtime/otel-bridge.js.map +1 -0
- package/dist/runtime/otel-init.d.ts +72 -0
- package/dist/runtime/otel-init.d.ts.map +1 -0
- package/dist/runtime/otel-init.js +68 -0
- package/dist/runtime/otel-init.js.map +1 -0
- package/dist/runtime/otel-metrics.d.ts +42 -0
- package/dist/runtime/otel-metrics.d.ts.map +1 -0
- package/dist/runtime/otel-metrics.js +196 -0
- package/dist/runtime/otel-metrics.js.map +1 -0
- package/dist/runtime/otel.d.ts +53 -0
- package/dist/runtime/otel.d.ts.map +1 -0
- package/dist/runtime/otel.js +127 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/squad-observer.d.ts +75 -0
- package/dist/runtime/squad-observer.d.ts.map +1 -0
- package/dist/runtime/squad-observer.js +190 -0
- package/dist/runtime/squad-observer.js.map +1 -0
- package/dist/runtime/streaming.d.ts +9 -0
- package/dist/runtime/streaming.d.ts.map +1 -1
- package/dist/runtime/streaming.js +37 -1
- package/dist/runtime/streaming.js.map +1 -1
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +57 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/upstream/index.d.ts +8 -0
- package/dist/upstream/index.d.ts.map +1 -0
- package/dist/upstream/index.js +7 -0
- package/dist/upstream/index.js.map +1 -0
- package/dist/upstream/resolver.d.ts +37 -0
- package/dist/upstream/resolver.d.ts.map +1 -0
- package/dist/upstream/resolver.js +234 -0
- package/dist/upstream/resolver.js.map +1 -0
- package/dist/upstream/types.d.ts +55 -0
- package/dist/upstream/types.d.ts.map +1 -0
- package/dist/upstream/types.js +11 -0
- package/dist/upstream/types.js.map +1 -0
- package/package.json +84 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Event Payloads for SquadEventType (Issue #304)
|
|
3
|
+
*
|
|
4
|
+
* Canonical payload types for every EventBus event type.
|
|
5
|
+
* These are the SDK-owned contracts that downstream consumers
|
|
6
|
+
* (e.g., SquadOffice visualization) depend on.
|
|
7
|
+
*
|
|
8
|
+
* @module runtime/event-payloads
|
|
9
|
+
*/
|
|
10
|
+
import type { SquadEventType, SquadEvent } from './event-bus.js';
|
|
11
|
+
export interface SessionCreatedPayload {
|
|
12
|
+
agentName: string;
|
|
13
|
+
priority: 'low' | 'normal' | 'high' | 'critical';
|
|
14
|
+
}
|
|
15
|
+
export interface SessionIdlePayload {
|
|
16
|
+
agentName: string;
|
|
17
|
+
idleSince?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SessionErrorPayload {
|
|
20
|
+
agentName: string;
|
|
21
|
+
error: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SessionDestroyedPayload {
|
|
24
|
+
agentName: string;
|
|
25
|
+
reason?: 'complete' | 'error' | 'abort' | 'timeout' | 'user_exit';
|
|
26
|
+
}
|
|
27
|
+
export interface SessionMessagePayload {
|
|
28
|
+
message: string;
|
|
29
|
+
role?: string;
|
|
30
|
+
content?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SessionToolCallPayload {
|
|
33
|
+
toolName: string;
|
|
34
|
+
toolArgs: Record<string, unknown>;
|
|
35
|
+
resultType?: 'success' | 'failure' | 'rejected' | 'denied';
|
|
36
|
+
}
|
|
37
|
+
/** Multi-phase coordinator routing - discriminated by `phase`. */
|
|
38
|
+
export type CoordinatorRoutingPayload = {
|
|
39
|
+
phase: 'start';
|
|
40
|
+
messageLength: number;
|
|
41
|
+
} | {
|
|
42
|
+
phase: 'routed';
|
|
43
|
+
agents: string[];
|
|
44
|
+
confidence: 'high' | 'medium' | 'low';
|
|
45
|
+
reason: string;
|
|
46
|
+
} | {
|
|
47
|
+
phase: 'spawning';
|
|
48
|
+
strategy: 'direct' | 'single' | 'multi' | 'fallback';
|
|
49
|
+
agentCount: number;
|
|
50
|
+
} | {
|
|
51
|
+
phase: 'complete';
|
|
52
|
+
strategy: string;
|
|
53
|
+
spawnCount: number;
|
|
54
|
+
successCount: number;
|
|
55
|
+
};
|
|
56
|
+
export type AgentMilestonePayload = {
|
|
57
|
+
event: 'model.fallback';
|
|
58
|
+
agentName: string;
|
|
59
|
+
failedModel: string;
|
|
60
|
+
failedTier: 'premium' | 'standard' | 'fast';
|
|
61
|
+
error: string;
|
|
62
|
+
attemptNumber: number;
|
|
63
|
+
} | {
|
|
64
|
+
event: 'model.exhausted';
|
|
65
|
+
agentName: string;
|
|
66
|
+
originalModel: string;
|
|
67
|
+
originalTier: string;
|
|
68
|
+
totalAttempts: number;
|
|
69
|
+
};
|
|
70
|
+
export interface PoolHealthPayload {
|
|
71
|
+
activeSessions: number;
|
|
72
|
+
availableSlots: number;
|
|
73
|
+
queuedRequests: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SquadEventPayloadMap {
|
|
76
|
+
'session:created': SessionCreatedPayload;
|
|
77
|
+
'session:idle': SessionIdlePayload;
|
|
78
|
+
'session:error': SessionErrorPayload;
|
|
79
|
+
'session:destroyed': SessionDestroyedPayload;
|
|
80
|
+
'session:message': SessionMessagePayload;
|
|
81
|
+
'session:tool_call': SessionToolCallPayload;
|
|
82
|
+
'agent:milestone': AgentMilestonePayload;
|
|
83
|
+
'coordinator:routing': CoordinatorRoutingPayload;
|
|
84
|
+
'pool:health': PoolHealthPayload;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A strongly-typed SquadEvent where the payload type is inferred from the
|
|
88
|
+
* event type discriminant. Use this for type-safe event construction.
|
|
89
|
+
*/
|
|
90
|
+
export interface TypedSquadEvent<T extends SquadEventType = SquadEventType> {
|
|
91
|
+
type: T;
|
|
92
|
+
sessionId?: string;
|
|
93
|
+
agentName?: string;
|
|
94
|
+
payload: T extends keyof SquadEventPayloadMap ? SquadEventPayloadMap[T] : unknown;
|
|
95
|
+
timestamp: Date;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Type guard: narrows a SquadEvent to a specific typed event.
|
|
99
|
+
*/
|
|
100
|
+
export declare function isSquadEventOfType<T extends SquadEventType>(event: SquadEvent, type: T): event is TypedSquadEvent<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Helper to construct a typed SquadEvent with payload validation at compile time.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createSquadEvent<T extends SquadEventType>(type: T, payload: T extends keyof SquadEventPayloadMap ? SquadEventPayloadMap[T] : unknown, options?: {
|
|
105
|
+
sessionId?: string;
|
|
106
|
+
agentName?: string;
|
|
107
|
+
}): TypedSquadEvent<T>;
|
|
108
|
+
//# sourceMappingURL=event-payloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-payloads.d.ts","sourceRoot":"","sources":["../../src/runtime/event-payloads.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjE,MAAM,WAAW,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,CAAC,GAAG,OAAO,CAAC;IAClF,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,cAAc,EACzD,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,CAAC,GACN,KAAK,IAAI,eAAe,CAAC,CAAC,CAAC,CAE7B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,cAAc,EACvD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,SAAS,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO,EACjF,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,eAAe,CAAC,CAAC,CAAC,CAQpB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Event Payloads for SquadEventType (Issue #304)
|
|
3
|
+
*
|
|
4
|
+
* Canonical payload types for every EventBus event type.
|
|
5
|
+
* These are the SDK-owned contracts that downstream consumers
|
|
6
|
+
* (e.g., SquadOffice visualization) depend on.
|
|
7
|
+
*
|
|
8
|
+
* @module runtime/event-payloads
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Type guard: narrows a SquadEvent to a specific typed event.
|
|
12
|
+
*/
|
|
13
|
+
export function isSquadEventOfType(event, type) {
|
|
14
|
+
return event.type === type;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Helper to construct a typed SquadEvent with payload validation at compile time.
|
|
18
|
+
*/
|
|
19
|
+
export function createSquadEvent(type, payload, options) {
|
|
20
|
+
return {
|
|
21
|
+
type,
|
|
22
|
+
sessionId: options?.sessionId,
|
|
23
|
+
agentName: options?.agentName,
|
|
24
|
+
payload,
|
|
25
|
+
timestamp: new Date(),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=event-payloads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-payloads.js","sourceRoot":"","sources":["../../src/runtime/event-payloads.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsHH;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAiB,EACjB,IAAO;IAEP,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAO,EACP,OAAiF,EACjF,OAAoD;IAEpD,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,OAAO,EAAE,SAAS;QAC7B,SAAS,EAAE,OAAO,EAAE,SAAS;QAC7B,OAAO;QACP,SAAS,EAAE,IAAI,IAAI,EAAE;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/runtime/health.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/runtime/health.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;IAE7C,uBAAuB;IACvB,eAAe,EAAE,MAAM,CAAC;IAExB,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IAEnB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,oCAAoC;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,6BAA6B;IAC7B,SAAS,EAAE,IAAI,CAAC;IAEhB,oCAAoC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,wBAAwB;IACxB,MAAM,EAAE,WAAW,CAAC;IAEpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,6CAA6C;IAC7C,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAU;gBAEpB,MAAM,EAAE,mBAAmB;IAMvC;;;;;;;;;;OAUG;IACG,KAAK,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAgDzC;;;;OAIG;IACH,SAAS,IAAI,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;IAqB9F;;OAEG;IACH,OAAO,CAAC,aAAa;CAQtB"}
|
package/dist/runtime/health.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Monitors the health of SquadClient connections and provides diagnostics.
|
|
5
5
|
* Exposes health status for external monitoring and startup validation.
|
|
6
6
|
*/
|
|
7
|
+
import { TIMEOUTS } from './constants.js';
|
|
7
8
|
/**
|
|
8
9
|
* Health Monitor for SquadClient connections.
|
|
9
10
|
*
|
|
@@ -16,7 +17,7 @@ export class HealthMonitor {
|
|
|
16
17
|
logDiagnostics;
|
|
17
18
|
constructor(config) {
|
|
18
19
|
this.client = config.client;
|
|
19
|
-
this.timeout = config.timeout ??
|
|
20
|
+
this.timeout = config.timeout ?? TIMEOUTS.HEALTH_CHECK_MS;
|
|
20
21
|
this.logDiagnostics = config.logDiagnostics ?? true;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/runtime/health.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../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AC5C,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAE/C,IAAI,MAA4C,CAAC;QACjD,IAAI,SAAS,IAAI,eAAe,KAAK,WAAW,EAAE,CAAC;YACjD,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;aAAM,IAAI,eAAe,KAAK,cAAc,EAAE,CAAC;YAC9C,MAAM,GAAG,UAAU,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC;QACvB,CAAC;QAED,OAAO;YACL,MAAM;YACN,eAAe;YACf,SAAS;YACT,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,OAAe,EAAE,OAAe,EAAE,KAAe;QACrE,IAAI,CAAC,IAAI,CAAC,cAAc;YAAE,OAAO;QAEjC,OAAO,CAAC,KAAK,CAAC,mBAAmB,OAAO,KAAK,OAAO,EAAE,CAAC,CAAC;QACxD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTel Bridge for TelemetryCollector (Issue #256)
|
|
3
|
+
*
|
|
4
|
+
* Converts TelemetryEvents into OpenTelemetry spans, providing a
|
|
5
|
+
* TelemetryTransport that can be registered via setTelemetryTransport().
|
|
6
|
+
* Additive — the existing transport pipeline is unaffected.
|
|
7
|
+
*
|
|
8
|
+
* @module runtime/otel-bridge
|
|
9
|
+
*/
|
|
10
|
+
import type { TelemetryTransport } from './telemetry.js';
|
|
11
|
+
import type { EventBus, UnsubscribeFn } from './event-bus.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create a TelemetryTransport that emits OTel spans for each event.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { setTelemetryTransport } from './telemetry.js';
|
|
18
|
+
* import { createOTelTransport } from './otel-bridge.js';
|
|
19
|
+
*
|
|
20
|
+
* setTelemetryTransport(createOTelTransport());
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The bridge ignores the `endpoint` parameter — OTel exporter config is
|
|
24
|
+
* managed by the OTel provider initialized via `initializeOTel()`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createOTelTransport(): TelemetryTransport;
|
|
27
|
+
/**
|
|
28
|
+
* Subscribe an {@link EventBus} to OpenTelemetry, creating a span for every
|
|
29
|
+
* event that flows through the bus.
|
|
30
|
+
*
|
|
31
|
+
* This is the **mid-level** OTel integration point — it wires the Squad
|
|
32
|
+
* event bus directly into the OTel trace pipeline. If no `TracerProvider`
|
|
33
|
+
* has been registered (e.g. via {@link initializeOTel}), all spans are
|
|
34
|
+
* automatically no-ops with zero overhead.
|
|
35
|
+
*
|
|
36
|
+
* @param bus - The EventBus instance to bridge.
|
|
37
|
+
* @returns An unsubscribe function. Call it to detach the bridge.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { EventBus, initializeOTel, bridgeEventBusToOTel } from 'squad-sdk';
|
|
42
|
+
*
|
|
43
|
+
* const bus = new EventBus();
|
|
44
|
+
* initializeOTel({ endpoint: 'http://localhost:4318' });
|
|
45
|
+
* const detach = bridgeEventBusToOTel(bus);
|
|
46
|
+
*
|
|
47
|
+
* // Later, to stop bridging:
|
|
48
|
+
* detach();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function bridgeEventBusToOTel(bus: EventBus): UnsubscribeFn;
|
|
52
|
+
//# sourceMappingURL=otel-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-bridge.d.ts","sourceRoot":"","sources":["../../src/runtime/otel-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAc,MAAM,gBAAgB,CAAC;AAsE1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,IAAI,kBAAkB,CAMxD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,QAAQ,GAAG,aAAa,CAejE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTel Bridge for TelemetryCollector (Issue #256)
|
|
3
|
+
*
|
|
4
|
+
* Converts TelemetryEvents into OpenTelemetry spans, providing a
|
|
5
|
+
* TelemetryTransport that can be registered via setTelemetryTransport().
|
|
6
|
+
* Additive — the existing transport pipeline is unaffected.
|
|
7
|
+
*
|
|
8
|
+
* @module runtime/otel-bridge
|
|
9
|
+
*/
|
|
10
|
+
import { SpanStatusCode } from '@opentelemetry/api';
|
|
11
|
+
import { getTracer } from './otel.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Span mapping
|
|
14
|
+
// ============================================================================
|
|
15
|
+
function recordSpan(event) {
|
|
16
|
+
const tracer = getTracer('squad-sdk');
|
|
17
|
+
const attrs = {};
|
|
18
|
+
if (event.properties) {
|
|
19
|
+
for (const [k, v] of Object.entries(event.properties)) {
|
|
20
|
+
attrs[k] = v;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (event.timestamp) {
|
|
24
|
+
attrs['event.timestamp'] = event.timestamp;
|
|
25
|
+
}
|
|
26
|
+
switch (event.name) {
|
|
27
|
+
case 'squad.init': {
|
|
28
|
+
const span = tracer.startSpan('squad.init', { attributes: attrs });
|
|
29
|
+
span.end();
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'squad.agent.spawn': {
|
|
33
|
+
const span = tracer.startSpan('squad.agent.spawn', { attributes: attrs });
|
|
34
|
+
span.end();
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'squad.error': {
|
|
38
|
+
const span = tracer.startSpan('squad.error', { attributes: attrs });
|
|
39
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: String(attrs['error'] ?? 'unknown') });
|
|
40
|
+
span.addEvent('exception', {
|
|
41
|
+
'exception.message': String(attrs['error'] ?? attrs['message'] ?? 'unknown error'),
|
|
42
|
+
...(attrs['stack'] ? { 'exception.stacktrace': String(attrs['stack']) } : {}),
|
|
43
|
+
});
|
|
44
|
+
span.end();
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'squad.run': {
|
|
48
|
+
// Root span for the entire session — start and immediately end
|
|
49
|
+
// (the real duration would be managed by the caller if needed)
|
|
50
|
+
const span = tracer.startSpan('squad.run', { attributes: attrs });
|
|
51
|
+
span.end();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'squad.upgrade': {
|
|
55
|
+
const span = tracer.startSpan('squad.upgrade', { attributes: attrs });
|
|
56
|
+
span.end();
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
// Forward unknown events as generic spans
|
|
61
|
+
const span = tracer.startSpan(event.name, { attributes: attrs });
|
|
62
|
+
span.end();
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Public API
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Create a TelemetryTransport that emits OTel spans for each event.
|
|
72
|
+
*
|
|
73
|
+
* Usage:
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { setTelemetryTransport } from './telemetry.js';
|
|
76
|
+
* import { createOTelTransport } from './otel-bridge.js';
|
|
77
|
+
*
|
|
78
|
+
* setTelemetryTransport(createOTelTransport());
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* The bridge ignores the `endpoint` parameter — OTel exporter config is
|
|
82
|
+
* managed by the OTel provider initialized via `initializeOTel()`.
|
|
83
|
+
*/
|
|
84
|
+
export function createOTelTransport() {
|
|
85
|
+
return async (events, _endpoint) => {
|
|
86
|
+
for (const event of events) {
|
|
87
|
+
recordSpan(event);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe an {@link EventBus} to OpenTelemetry, creating a span for every
|
|
93
|
+
* event that flows through the bus.
|
|
94
|
+
*
|
|
95
|
+
* This is the **mid-level** OTel integration point — it wires the Squad
|
|
96
|
+
* event bus directly into the OTel trace pipeline. If no `TracerProvider`
|
|
97
|
+
* has been registered (e.g. via {@link initializeOTel}), all spans are
|
|
98
|
+
* automatically no-ops with zero overhead.
|
|
99
|
+
*
|
|
100
|
+
* @param bus - The EventBus instance to bridge.
|
|
101
|
+
* @returns An unsubscribe function. Call it to detach the bridge.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { EventBus, initializeOTel, bridgeEventBusToOTel } from 'squad-sdk';
|
|
106
|
+
*
|
|
107
|
+
* const bus = new EventBus();
|
|
108
|
+
* initializeOTel({ endpoint: 'http://localhost:4318' });
|
|
109
|
+
* const detach = bridgeEventBusToOTel(bus);
|
|
110
|
+
*
|
|
111
|
+
* // Later, to stop bridging:
|
|
112
|
+
* detach();
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function bridgeEventBusToOTel(bus) {
|
|
116
|
+
return bus.subscribeAll((event) => {
|
|
117
|
+
const tracer = getTracer('squad-sdk');
|
|
118
|
+
const attrs = {
|
|
119
|
+
'event.type': event.type,
|
|
120
|
+
};
|
|
121
|
+
if (event.sessionId)
|
|
122
|
+
attrs['session.id'] = event.sessionId;
|
|
123
|
+
if (event.agentName)
|
|
124
|
+
attrs['agent.name'] = event.agentName;
|
|
125
|
+
const span = tracer.startSpan(`squad.${event.type}`, { attributes: attrs });
|
|
126
|
+
if (event.type === 'session:error') {
|
|
127
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
128
|
+
}
|
|
129
|
+
span.end();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=otel-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-bridge.js","sourceRoot":"","sources":["../../src/runtime/otel-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,SAAS,UAAU,CAAC,KAAqB;IACvC,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IACtC,MAAM,KAAK,GAA8C,EAAE,CAAC;IAE5D,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACpB,KAAK,CAAC,iBAAiB,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;IAC7C,CAAC;IAED,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,YAAY,CAAC,CAAC,CAAC;YAClB,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;YACnE,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,MAAM;QACR,CAAC;QAED,KAAK,mBAAmB,CAAC,CAAC,CAAC;YACzB,MAAM,IAAI,GAAG,MAAM,CAAC,S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AC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-Level OTel Initialization (Issue #266)
|
|
3
|
+
*
|
|
4
|
+
* One-call setup that wires OTel providers, the EventBus bridge, and
|
|
5
|
+
* the TelemetryCollector transport in a single invocation. Consumers
|
|
6
|
+
* who don't use OTel pay nothing — if no provider is registered all
|
|
7
|
+
* instrumentation is a no-op.
|
|
8
|
+
*
|
|
9
|
+
* @module runtime/otel-init
|
|
10
|
+
*/
|
|
11
|
+
import type { OTelConfig } from './otel.js';
|
|
12
|
+
import type { EventBus } from './event-bus.js';
|
|
13
|
+
/** Options for the high-level {@link initSquadTelemetry} helper. */
|
|
14
|
+
export interface SquadTelemetryOptions extends OTelConfig {
|
|
15
|
+
/**
|
|
16
|
+
* When provided, all EventBus events are automatically forwarded
|
|
17
|
+
* as OTel spans via {@link bridgeEventBusToOTel}.
|
|
18
|
+
*/
|
|
19
|
+
eventBus?: EventBus;
|
|
20
|
+
/**
|
|
21
|
+
* When `true`, the OTel-backed TelemetryTransport is registered
|
|
22
|
+
* as the active transport for {@link TelemetryCollector}.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
installTransport?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Handle returned by {@link initSquadTelemetry} for lifecycle control. */
|
|
28
|
+
export interface SquadTelemetryHandle {
|
|
29
|
+
/** Whether tracing was activated. */
|
|
30
|
+
tracing: boolean;
|
|
31
|
+
/** Whether metrics were activated. */
|
|
32
|
+
metrics: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Flush pending telemetry, detach the EventBus bridge (if any),
|
|
35
|
+
* and shut down OTel providers. Safe to call multiple times.
|
|
36
|
+
*/
|
|
37
|
+
shutdown: () => Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One-call OTel setup for Squad SDK consumers.
|
|
41
|
+
*
|
|
42
|
+
* This is the **high-level** entry point. It:
|
|
43
|
+
* 1. Initializes tracing and metrics via `initializeOTel()`.
|
|
44
|
+
* 2. Optionally bridges an {@link EventBus} so every Squad event
|
|
45
|
+
* becomes an OTel span.
|
|
46
|
+
* 3. Optionally installs an OTel-backed `TelemetryTransport` so
|
|
47
|
+
* the existing `TelemetryCollector` pipeline emits spans too.
|
|
48
|
+
*
|
|
49
|
+
* If no `OTEL_EXPORTER_OTLP_ENDPOINT` env var is set **and** no
|
|
50
|
+
* `endpoint` is provided in `options`, everything remains a no-op.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Configuration and optional EventBus.
|
|
53
|
+
* @returns A handle with `tracing`, `metrics` status booleans and a
|
|
54
|
+
* `shutdown()` method for graceful cleanup.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { initSquadTelemetry, EventBus } from 'squad-sdk';
|
|
59
|
+
*
|
|
60
|
+
* const bus = new EventBus();
|
|
61
|
+
* const telemetry = initSquadTelemetry({
|
|
62
|
+
* endpoint: 'http://localhost:4318',
|
|
63
|
+
* eventBus: bus,
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // … run your squad …
|
|
67
|
+
*
|
|
68
|
+
* await telemetry.shutdown();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function initSquadTelemetry(options?: SquadTelemetryOptions): SquadTelemetryHandle;
|
|
72
|
+
//# sourceMappingURL=otel-init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-init.d.ts","sourceRoot":"","sources":["../../src/runtime/otel-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAU/C,oEAAoE;AACpE,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,qBAA0B,GAAG,oBAAoB,CAsB5F"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-Level OTel Initialization (Issue #266)
|
|
3
|
+
*
|
|
4
|
+
* One-call setup that wires OTel providers, the EventBus bridge, and
|
|
5
|
+
* the TelemetryCollector transport in a single invocation. Consumers
|
|
6
|
+
* who don't use OTel pay nothing — if no provider is registered all
|
|
7
|
+
* instrumentation is a no-op.
|
|
8
|
+
*
|
|
9
|
+
* @module runtime/otel-init
|
|
10
|
+
*/
|
|
11
|
+
import { initializeOTel, shutdownOTel } from './otel.js';
|
|
12
|
+
import { bridgeEventBusToOTel, createOTelTransport } from './otel-bridge.js';
|
|
13
|
+
import { setTelemetryTransport } from './telemetry.js';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Public API
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* One-call OTel setup for Squad SDK consumers.
|
|
19
|
+
*
|
|
20
|
+
* This is the **high-level** entry point. It:
|
|
21
|
+
* 1. Initializes tracing and metrics via `initializeOTel()`.
|
|
22
|
+
* 2. Optionally bridges an {@link EventBus} so every Squad event
|
|
23
|
+
* becomes an OTel span.
|
|
24
|
+
* 3. Optionally installs an OTel-backed `TelemetryTransport` so
|
|
25
|
+
* the existing `TelemetryCollector` pipeline emits spans too.
|
|
26
|
+
*
|
|
27
|
+
* If no `OTEL_EXPORTER_OTLP_ENDPOINT` env var is set **and** no
|
|
28
|
+
* `endpoint` is provided in `options`, everything remains a no-op.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration and optional EventBus.
|
|
31
|
+
* @returns A handle with `tracing`, `metrics` status booleans and a
|
|
32
|
+
* `shutdown()` method for graceful cleanup.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { initSquadTelemetry, EventBus } from 'squad-sdk';
|
|
37
|
+
*
|
|
38
|
+
* const bus = new EventBus();
|
|
39
|
+
* const telemetry = initSquadTelemetry({
|
|
40
|
+
* endpoint: 'http://localhost:4318',
|
|
41
|
+
* eventBus: bus,
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // … run your squad …
|
|
45
|
+
*
|
|
46
|
+
* await telemetry.shutdown();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function initSquadTelemetry(options = {}) {
|
|
50
|
+
const { eventBus, installTransport = true, ...otelConfig } = options;
|
|
51
|
+
const result = initializeOTel(otelConfig);
|
|
52
|
+
let unsubscribeBridge;
|
|
53
|
+
if (eventBus) {
|
|
54
|
+
unsubscribeBridge = bridgeEventBusToOTel(eventBus);
|
|
55
|
+
}
|
|
56
|
+
if (installTransport) {
|
|
57
|
+
setTelemetryTransport(createOTelTransport());
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
tracing: result.tracing,
|
|
61
|
+
metrics: result.metrics,
|
|
62
|
+
shutdown: async () => {
|
|
63
|
+
unsubscribeBridge?.();
|
|
64
|
+
await shutdownOTel();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=otel-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-init.js","sourceRoot":"","sources":["../../src/runtime/otel-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAmCvD,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAiC,EAAE;IACpE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAErE,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE1C,IAAI,iBAA4C,CAAC;IACjD,IAAI,QAAQ,EAAE,CAAC;QACb,iBAAiB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,qBAAqB,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,KAAK,IAAI,EAAE;YACnB,iBAAiB,EAAE,EAAE,CAAC;YACtB,MAAM,YAAY,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTel Metrics (Issues #261, #262, #263, #264)
|
|
3
|
+
*
|
|
4
|
+
* Provides counters, histograms, and gauges for token usage,
|
|
5
|
+
* agent performance, session pool, and response latency.
|
|
6
|
+
* No-op when OTel is not configured (getMeter returns a no-op meter).
|
|
7
|
+
*
|
|
8
|
+
* @module runtime/otel-metrics
|
|
9
|
+
*/
|
|
10
|
+
import type { UsageEvent } from './streaming.js';
|
|
11
|
+
/**
|
|
12
|
+
* Record token usage from a UsageEvent.
|
|
13
|
+
* Safe to call when OTel is not configured — metrics are no-ops.
|
|
14
|
+
*/
|
|
15
|
+
export declare function recordTokenUsage(event: UsageEvent): void;
|
|
16
|
+
/** Record an agent spawn event. */
|
|
17
|
+
export declare function recordAgentSpawn(agentName: string, mode?: string): void;
|
|
18
|
+
/** Record agent task completion with duration. */
|
|
19
|
+
export declare function recordAgentDuration(agentName: string, durationMs: number, status?: 'success' | 'error'): void;
|
|
20
|
+
/** Record an agent error. */
|
|
21
|
+
export declare function recordAgentError(agentName: string, errorType: string): void;
|
|
22
|
+
/** Record agent session destruction (decrements active count). */
|
|
23
|
+
export declare function recordAgentDestroy(agentName: string): void;
|
|
24
|
+
/** Record a new session being created. */
|
|
25
|
+
export declare function recordSessionCreated(): void;
|
|
26
|
+
/** Record a session becoming idle. */
|
|
27
|
+
export declare function recordSessionIdle(): void;
|
|
28
|
+
/** Record an idle session becoming active again. */
|
|
29
|
+
export declare function recordSessionReactivated(): void;
|
|
30
|
+
/** Record a session being closed. */
|
|
31
|
+
export declare function recordSessionClosed(): void;
|
|
32
|
+
/** Record a session error. */
|
|
33
|
+
export declare function recordSessionError(): void;
|
|
34
|
+
/** Record time to first token. */
|
|
35
|
+
export declare function recordTimeToFirstToken(ttftMs: number): void;
|
|
36
|
+
/** Record total response duration. */
|
|
37
|
+
export declare function recordResponseDuration(durationMs: number): void;
|
|
38
|
+
/** Record streaming throughput. */
|
|
39
|
+
export declare function recordTokensPerSecond(tokensPerSec: number): void;
|
|
40
|
+
/** Reset all cached metric instances. Used in tests only. */
|
|
41
|
+
export declare function _resetMetrics(): void;
|
|
42
|
+
//# sourceMappingURL=otel-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-metrics.d.ts","sourceRoot":"","sources":["../../src/runtime/otel-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK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