@a5c-ai/genty-runtime 5.1.1-staging.00ceebd28cf2

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.
Files changed (221) hide show
  1. package/README.md +69 -0
  2. package/dist/apiResult.d.ts +19 -0
  3. package/dist/apiResult.d.ts.map +1 -0
  4. package/dist/apiResult.js +16 -0
  5. package/dist/background/state.d.ts +20 -0
  6. package/dist/background/state.d.ts.map +1 -0
  7. package/dist/background/state.js +52 -0
  8. package/dist/backgroundProcessRegistry.d.ts +124 -0
  9. package/dist/backgroundProcessRegistry.d.ts.map +1 -0
  10. package/dist/backgroundProcessRegistry.js +427 -0
  11. package/dist/cost/claudeCodeParser.d.ts +81 -0
  12. package/dist/cost/claudeCodeParser.d.ts.map +1 -0
  13. package/dist/cost/claudeCodeParser.js +232 -0
  14. package/dist/cost/collector.d.ts +42 -0
  15. package/dist/cost/collector.d.ts.map +1 -0
  16. package/dist/cost/collector.js +105 -0
  17. package/dist/cost/effectCost.d.ts +23 -0
  18. package/dist/cost/effectCost.d.ts.map +1 -0
  19. package/dist/cost/effectCost.js +26 -0
  20. package/dist/cost/index.d.ts +19 -0
  21. package/dist/cost/index.d.ts.map +1 -0
  22. package/dist/cost/index.js +39 -0
  23. package/dist/cost/journal.d.ts +40 -0
  24. package/dist/cost/journal.d.ts.map +1 -0
  25. package/dist/cost/journal.js +137 -0
  26. package/dist/cost/types.d.ts +164 -0
  27. package/dist/cost/types.d.ts.map +1 -0
  28. package/dist/cost/types.js +228 -0
  29. package/dist/daemon/automationExecutor.d.ts +16 -0
  30. package/dist/daemon/automationExecutor.d.ts.map +1 -0
  31. package/dist/daemon/automationExecutor.js +222 -0
  32. package/dist/daemon/config.d.ts +8 -0
  33. package/dist/daemon/config.d.ts.map +1 -0
  34. package/dist/daemon/config.js +245 -0
  35. package/dist/daemon/daemonLog.d.ts +30 -0
  36. package/dist/daemon/daemonLog.d.ts.map +1 -0
  37. package/dist/daemon/daemonLog.js +140 -0
  38. package/dist/daemon/durableQueue.d.ts +41 -0
  39. package/dist/daemon/durableQueue.d.ts.map +1 -0
  40. package/dist/daemon/durableQueue.js +183 -0
  41. package/dist/daemon/fileWatcher.d.ts +9 -0
  42. package/dist/daemon/fileWatcher.d.ts.map +1 -0
  43. package/dist/daemon/fileWatcher.js +144 -0
  44. package/dist/daemon/index.d.ts +15 -0
  45. package/dist/daemon/index.d.ts.map +1 -0
  46. package/dist/daemon/index.js +25 -0
  47. package/dist/daemon/lifecycle.d.ts +13 -0
  48. package/dist/daemon/lifecycle.d.ts.map +1 -0
  49. package/dist/daemon/lifecycle.js +320 -0
  50. package/dist/daemon/loop.d.ts +27 -0
  51. package/dist/daemon/loop.d.ts.map +1 -0
  52. package/dist/daemon/loop.js +387 -0
  53. package/dist/daemon/timerScheduler.d.ts +13 -0
  54. package/dist/daemon/timerScheduler.d.ts.map +1 -0
  55. package/dist/daemon/timerScheduler.js +212 -0
  56. package/dist/daemon/types.d.ts +122 -0
  57. package/dist/daemon/types.d.ts.map +1 -0
  58. package/dist/daemon/types.js +25 -0
  59. package/dist/daemon/webhookListener.d.ts +6 -0
  60. package/dist/daemon/webhookListener.d.ts.map +1 -0
  61. package/dist/daemon/webhookListener.js +132 -0
  62. package/dist/execution/index.d.ts +10 -0
  63. package/dist/execution/index.d.ts.map +1 -0
  64. package/dist/execution/index.js +20 -0
  65. package/dist/execution/modes/docker.d.ts +26 -0
  66. package/dist/execution/modes/docker.d.ts.map +1 -0
  67. package/dist/execution/modes/docker.js +183 -0
  68. package/dist/execution/modes/index.d.ts +10 -0
  69. package/dist/execution/modes/index.d.ts.map +1 -0
  70. package/dist/execution/modes/index.js +14 -0
  71. package/dist/execution/modes/kubernetes.d.ts +46 -0
  72. package/dist/execution/modes/kubernetes.d.ts.map +1 -0
  73. package/dist/execution/modes/kubernetes.js +334 -0
  74. package/dist/execution/modes/local.d.ts +23 -0
  75. package/dist/execution/modes/local.d.ts.map +1 -0
  76. package/dist/execution/modes/local.js +117 -0
  77. package/dist/execution/modes/ssh.d.ts +23 -0
  78. package/dist/execution/modes/ssh.d.ts.map +1 -0
  79. package/dist/execution/modes/ssh.js +144 -0
  80. package/dist/execution/policy.d.ts +15 -0
  81. package/dist/execution/policy.d.ts.map +1 -0
  82. package/dist/execution/policy.js +121 -0
  83. package/dist/execution/provider.d.ts +32 -0
  84. package/dist/execution/provider.d.ts.map +1 -0
  85. package/dist/execution/provider.js +90 -0
  86. package/dist/execution/types.d.ts +189 -0
  87. package/dist/execution/types.d.ts.map +1 -0
  88. package/dist/execution/types.js +9 -0
  89. package/dist/index.d.ts +12 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +44 -0
  92. package/dist/observability/diagnostics.d.ts +25 -0
  93. package/dist/observability/diagnostics.d.ts.map +1 -0
  94. package/dist/observability/diagnostics.js +98 -0
  95. package/dist/observability/health.d.ts +19 -0
  96. package/dist/observability/health.d.ts.map +1 -0
  97. package/dist/observability/health.js +145 -0
  98. package/dist/observability/index.d.ts +7 -0
  99. package/dist/observability/index.d.ts.map +1 -0
  100. package/dist/observability/index.js +25 -0
  101. package/dist/observability/runStatus.d.ts +44 -0
  102. package/dist/observability/runStatus.d.ts.map +1 -0
  103. package/dist/observability/runStatus.js +169 -0
  104. package/dist/observability/timeline.d.ts +11 -0
  105. package/dist/observability/timeline.d.ts.map +1 -0
  106. package/dist/observability/timeline.js +176 -0
  107. package/dist/observability/types.d.ts +65 -0
  108. package/dist/observability/types.d.ts.map +1 -0
  109. package/dist/observability/types.js +8 -0
  110. package/dist/observability/webhooks.d.ts +68 -0
  111. package/dist/observability/webhooks.d.ts.map +1 -0
  112. package/dist/observability/webhooks.js +132 -0
  113. package/dist/resources/budget-tracker.d.ts +56 -0
  114. package/dist/resources/budget-tracker.d.ts.map +1 -0
  115. package/dist/resources/budget-tracker.js +131 -0
  116. package/dist/resources/concurrency-guard.d.ts +55 -0
  117. package/dist/resources/concurrency-guard.d.ts.map +1 -0
  118. package/dist/resources/concurrency-guard.js +132 -0
  119. package/dist/resources/index.d.ts +12 -0
  120. package/dist/resources/index.d.ts.map +1 -0
  121. package/dist/resources/index.js +20 -0
  122. package/dist/resources/manager.d.ts +52 -0
  123. package/dist/resources/manager.d.ts.map +1 -0
  124. package/dist/resources/manager.js +150 -0
  125. package/dist/resources/timeout-cascade.d.ts +56 -0
  126. package/dist/resources/timeout-cascade.d.ts.map +1 -0
  127. package/dist/resources/timeout-cascade.js +145 -0
  128. package/dist/resources/types.d.ts +130 -0
  129. package/dist/resources/types.d.ts.map +1 -0
  130. package/dist/resources/types.js +9 -0
  131. package/dist/rpc/index.d.ts +5 -0
  132. package/dist/rpc/index.d.ts.map +1 -0
  133. package/dist/rpc/index.js +7 -0
  134. package/dist/rpc/server.d.ts +13 -0
  135. package/dist/rpc/server.d.ts.map +1 -0
  136. package/dist/rpc/server.js +64 -0
  137. package/dist/rpc/server.test.d.ts +2 -0
  138. package/dist/rpc/server.test.d.ts.map +1 -0
  139. package/dist/rpc/server.test.js +35 -0
  140. package/dist/rpc/types.d.ts +23 -0
  141. package/dist/rpc/types.d.ts.map +1 -0
  142. package/dist/rpc/types.js +20 -0
  143. package/dist/session/context.d.ts +22 -0
  144. package/dist/session/context.d.ts.map +1 -0
  145. package/dist/session/context.js +113 -0
  146. package/dist/session/continuityState.d.ts +39 -0
  147. package/dist/session/continuityState.d.ts.map +1 -0
  148. package/dist/session/continuityState.js +164 -0
  149. package/dist/session/cost.d.ts +63 -0
  150. package/dist/session/cost.d.ts.map +1 -0
  151. package/dist/session/cost.js +194 -0
  152. package/dist/session/discovery.d.ts +22 -0
  153. package/dist/session/discovery.d.ts.map +1 -0
  154. package/dist/session/discovery.js +35 -0
  155. package/dist/session/export.d.ts +4 -0
  156. package/dist/session/export.d.ts.map +1 -0
  157. package/dist/session/export.js +56 -0
  158. package/dist/session/export.test.d.ts +2 -0
  159. package/dist/session/export.test.d.ts.map +1 -0
  160. package/dist/session/export.test.js +42 -0
  161. package/dist/session/history.d.ts +30 -0
  162. package/dist/session/history.d.ts.map +1 -0
  163. package/dist/session/history.js +143 -0
  164. package/dist/session/index.d.ts +20 -0
  165. package/dist/session/index.d.ts.map +1 -0
  166. package/dist/session/index.js +78 -0
  167. package/dist/session/memoryExtraction.d.ts +65 -0
  168. package/dist/session/memoryExtraction.d.ts.map +1 -0
  169. package/dist/session/memoryExtraction.js +201 -0
  170. package/dist/session/parse.d.ts +45 -0
  171. package/dist/session/parse.d.ts.map +1 -0
  172. package/dist/session/parse.js +170 -0
  173. package/dist/session/persistence.d.ts +46 -0
  174. package/dist/session/persistence.d.ts.map +1 -0
  175. package/dist/session/persistence.js +180 -0
  176. package/dist/session/rewind.d.ts +45 -0
  177. package/dist/session/rewind.d.ts.map +1 -0
  178. package/dist/session/rewind.js +68 -0
  179. package/dist/session/rewind.test.d.ts +2 -0
  180. package/dist/session/rewind.test.d.ts.map +1 -0
  181. package/dist/session/rewind.test.js +96 -0
  182. package/dist/session/tree.d.ts +29 -0
  183. package/dist/session/tree.d.ts.map +1 -0
  184. package/dist/session/tree.js +115 -0
  185. package/dist/session/tree.test.d.ts +2 -0
  186. package/dist/session/tree.test.d.ts.map +1 -0
  187. package/dist/session/tree.test.js +75 -0
  188. package/dist/session/types.d.ts +267 -0
  189. package/dist/session/types.d.ts.map +1 -0
  190. package/dist/session/types.js +45 -0
  191. package/dist/session/write.d.ts +61 -0
  192. package/dist/session/write.d.ts.map +1 -0
  193. package/dist/session/write.js +213 -0
  194. package/dist/shellInvocation.d.ts +6 -0
  195. package/dist/shellInvocation.d.ts.map +1 -0
  196. package/dist/shellInvocation.js +8 -0
  197. package/dist/shellInvocation.test.d.ts +2 -0
  198. package/dist/shellInvocation.test.d.ts.map +1 -0
  199. package/dist/shellInvocation.test.js +18 -0
  200. package/dist/telemetry/audit-log.d.ts +56 -0
  201. package/dist/telemetry/audit-log.d.ts.map +1 -0
  202. package/dist/telemetry/audit-log.js +59 -0
  203. package/dist/telemetry/exporters.d.ts +35 -0
  204. package/dist/telemetry/exporters.d.ts.map +1 -0
  205. package/dist/telemetry/exporters.js +141 -0
  206. package/dist/telemetry/index.d.ts +12 -0
  207. package/dist/telemetry/index.d.ts.map +1 -0
  208. package/dist/telemetry/index.js +25 -0
  209. package/dist/telemetry/provider.d.ts +57 -0
  210. package/dist/telemetry/provider.d.ts.map +1 -0
  211. package/dist/telemetry/provider.js +261 -0
  212. package/dist/telemetry/span-tree.d.ts +46 -0
  213. package/dist/telemetry/span-tree.d.ts.map +1 -0
  214. package/dist/telemetry/span-tree.js +93 -0
  215. package/dist/telemetry/traceContext.d.ts +10 -0
  216. package/dist/telemetry/traceContext.d.ts.map +1 -0
  217. package/dist/telemetry/traceContext.js +43 -0
  218. package/dist/telemetry/types.d.ts +109 -0
  219. package/dist/telemetry/types.d.ts.map +1 -0
  220. package/dist/telemetry/types.js +21 -0
  221. package/package.json +137 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * AuditLog — append-only structured log for security-relevant and
3
+ * compliance-relevant actions within a babysitter agent runtime session.
4
+ *
5
+ * Each entry captures *who* did *what* to *which target*, with an optional
6
+ * telemetry span correlation. Entries are queryable by actor, action, and
7
+ * time range.
8
+ */
9
+ /** A single audit log entry. */
10
+ export interface AuditEntry {
11
+ /** Who performed the action (user id, agent name, system, etc.). */
12
+ readonly actor: string;
13
+ /** What action was performed. */
14
+ readonly action: string;
15
+ /** What the action was performed on (resource, span, task, etc.). */
16
+ readonly target: string;
17
+ /** Optional human-readable detail or serialized context. */
18
+ readonly detail?: string;
19
+ /** Optional telemetry span ID to correlate with the span tree. */
20
+ readonly spanId?: string;
21
+ /** ISO-8601 timestamp of when the entry was recorded. */
22
+ readonly timestamp: string;
23
+ }
24
+ /** Filter criteria for querying the audit log. */
25
+ export interface AuditFilter {
26
+ /** Match entries from this actor. */
27
+ actor?: string;
28
+ /** Match entries with this action. */
29
+ action?: string;
30
+ /** Match entries recorded at or after this ISO-8601 timestamp. */
31
+ from?: string;
32
+ /** Match entries recorded at or before this ISO-8601 timestamp. */
33
+ to?: string;
34
+ }
35
+ /** Append-only in-memory audit log. */
36
+ export declare class AuditLog {
37
+ private readonly entries;
38
+ /**
39
+ * Record a new audit entry.
40
+ *
41
+ * The timestamp is auto-populated to the current time.
42
+ */
43
+ record(entry: Omit<AuditEntry, "timestamp">): AuditEntry;
44
+ /**
45
+ * Query log entries with optional filters.
46
+ *
47
+ * All supplied filter fields are AND-ed together. Omitted fields match
48
+ * everything.
49
+ */
50
+ getEntries(filter?: AuditFilter): AuditEntry[];
51
+ /** Total number of entries in the log. */
52
+ get size(): number;
53
+ /** Clear all entries (useful in tests or session resets). */
54
+ clear(): void;
55
+ }
56
+ //# sourceMappingURL=audit-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-log.d.ts","sourceRoot":"","sources":["../../src/telemetry/audit-log.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,gCAAgC;AAChC,MAAM,WAAW,UAAU;IACzB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAMD,uCAAuC;AACvC,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,UAAU;IAMxD;;;;;OAKG;IACH,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,EAAE;IAc9C,0CAA0C;IAC1C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,6DAA6D;IAC7D,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * AuditLog — append-only structured log for security-relevant and
4
+ * compliance-relevant actions within a babysitter agent runtime session.
5
+ *
6
+ * Each entry captures *who* did *what* to *which target*, with an optional
7
+ * telemetry span correlation. Entries are queryable by actor, action, and
8
+ * time range.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.AuditLog = void 0;
12
+ // ---------------------------------------------------------------------------
13
+ // Implementation
14
+ // ---------------------------------------------------------------------------
15
+ /** Append-only in-memory audit log. */
16
+ class AuditLog {
17
+ entries = [];
18
+ /**
19
+ * Record a new audit entry.
20
+ *
21
+ * The timestamp is auto-populated to the current time.
22
+ */
23
+ record(entry) {
24
+ const full = { ...entry, timestamp: new Date().toISOString() };
25
+ this.entries.push(full);
26
+ return full;
27
+ }
28
+ /**
29
+ * Query log entries with optional filters.
30
+ *
31
+ * All supplied filter fields are AND-ed together. Omitted fields match
32
+ * everything.
33
+ */
34
+ getEntries(filter) {
35
+ if (!filter) {
36
+ return [...this.entries];
37
+ }
38
+ return this.entries.filter((e) => {
39
+ if (filter.actor && e.actor !== filter.actor)
40
+ return false;
41
+ if (filter.action && e.action !== filter.action)
42
+ return false;
43
+ if (filter.from && e.timestamp < filter.from)
44
+ return false;
45
+ if (filter.to && e.timestamp > filter.to)
46
+ return false;
47
+ return true;
48
+ });
49
+ }
50
+ /** Total number of entries in the log. */
51
+ get size() {
52
+ return this.entries.length;
53
+ }
54
+ /** Clear all entries (useful in tests or session resets). */
55
+ clear() {
56
+ this.entries.length = 0;
57
+ }
58
+ }
59
+ exports.AuditLog = AuditLog;
@@ -0,0 +1,35 @@
1
+ import type { TelemetryExporter, TelemetryExportResult, TelemetrySpan } from "./types";
2
+ export declare class NoopTelemetryExporter implements TelemetryExporter {
3
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
4
+ flush(): Promise<TelemetryExportResult>;
5
+ }
6
+ export declare class InMemoryTelemetryExporter implements TelemetryExporter {
7
+ private readonly spans;
8
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
9
+ getSpans(): TelemetrySpan[];
10
+ clear(): void;
11
+ }
12
+ export declare class FileTelemetryExporter implements TelemetryExporter {
13
+ private readonly filePath;
14
+ constructor(filePath: string);
15
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
16
+ }
17
+ export interface OtlpHttpTraceExporterOptions {
18
+ endpoint: string;
19
+ headers?: Record<string, string>;
20
+ fetch?: (input: string, init: {
21
+ method: string;
22
+ headers: Record<string, string>;
23
+ body: string;
24
+ }) => Promise<{
25
+ ok: boolean;
26
+ status: number;
27
+ text?: () => Promise<string>;
28
+ }>;
29
+ }
30
+ export declare class OtlpHttpTraceExporter implements TelemetryExporter {
31
+ private readonly options;
32
+ constructor(options: OtlpHttpTraceExporterOptions);
33
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
34
+ }
35
+ //# sourceMappingURL=exporters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporters.d.ts","sourceRoot":"","sources":["../../src/telemetry/exporters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,qBAAa,qBAAsB,YAAW,iBAAiB;IACvD,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIvE,KAAK,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAG9C;AAED,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAEvC,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAK7E,QAAQ,IAAI,aAAa,EAAE;IAI3B,KAAK,IAAI,IAAI;CAGd;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAEvC,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAQ9E;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;QAC5B,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;CAC9E;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,4BAA4B;IAE5D,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAgC9E"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OtlpHttpTraceExporter = exports.FileTelemetryExporter = exports.InMemoryTelemetryExporter = exports.NoopTelemetryExporter = void 0;
37
+ const node_fs_1 = require("node:fs");
38
+ const path = __importStar(require("node:path"));
39
+ class NoopTelemetryExporter {
40
+ async export(spans) {
41
+ return { ok: true, exported: spans.length };
42
+ }
43
+ async flush() {
44
+ return { ok: true, exported: 0 };
45
+ }
46
+ }
47
+ exports.NoopTelemetryExporter = NoopTelemetryExporter;
48
+ class InMemoryTelemetryExporter {
49
+ spans = [];
50
+ async export(spans) {
51
+ this.spans.push(...spans.map(cloneSpan));
52
+ return { ok: true, exported: spans.length };
53
+ }
54
+ getSpans() {
55
+ return this.spans.map(cloneSpan);
56
+ }
57
+ clear() {
58
+ this.spans.length = 0;
59
+ }
60
+ }
61
+ exports.InMemoryTelemetryExporter = InMemoryTelemetryExporter;
62
+ class FileTelemetryExporter {
63
+ filePath;
64
+ constructor(filePath) {
65
+ this.filePath = filePath;
66
+ }
67
+ async export(spans) {
68
+ await node_fs_1.promises.mkdir(path.dirname(this.filePath), { recursive: true });
69
+ const lines = spans.map((span) => JSON.stringify(span)).join("\n");
70
+ if (lines) {
71
+ await node_fs_1.promises.appendFile(this.filePath, `${lines}\n`, "utf-8");
72
+ }
73
+ return { ok: true, exported: spans.length };
74
+ }
75
+ }
76
+ exports.FileTelemetryExporter = FileTelemetryExporter;
77
+ class OtlpHttpTraceExporter {
78
+ options;
79
+ constructor(options) {
80
+ this.options = options;
81
+ }
82
+ async export(spans) {
83
+ const fetchImpl = this.options.fetch ?? globalThis.fetch;
84
+ if (!fetchImpl) {
85
+ return { ok: false, exported: 0, error: "fetch is not available" };
86
+ }
87
+ try {
88
+ const response = await fetchImpl(this.options.endpoint, {
89
+ method: "POST",
90
+ headers: {
91
+ "content-type": "application/json",
92
+ ...this.options.headers,
93
+ },
94
+ body: JSON.stringify({ resourceSpans: spans.map(toOtlpSpan) }),
95
+ });
96
+ if (!response.ok) {
97
+ const text = response.text ? await response.text() : "";
98
+ return {
99
+ ok: false,
100
+ exported: 0,
101
+ error: `OTLP HTTP export failed with status ${response.status}${text ? `: ${text}` : ""}`,
102
+ };
103
+ }
104
+ return { ok: true, exported: spans.length };
105
+ }
106
+ catch (error) {
107
+ return {
108
+ ok: false,
109
+ exported: 0,
110
+ error: error instanceof Error ? error.message : String(error),
111
+ };
112
+ }
113
+ }
114
+ }
115
+ exports.OtlpHttpTraceExporter = OtlpHttpTraceExporter;
116
+ function cloneSpan(span) {
117
+ return {
118
+ ...span,
119
+ attributes: { ...span.attributes },
120
+ events: span.events.map((event) => ({
121
+ ...event,
122
+ attributes: event.attributes ? { ...event.attributes } : undefined,
123
+ })),
124
+ };
125
+ }
126
+ function toOtlpSpan(span) {
127
+ return {
128
+ traceId: span.traceId,
129
+ spanId: span.spanId,
130
+ parentSpanId: span.parentSpanId,
131
+ name: span.name,
132
+ startTimeUnixNano: Date.parse(span.startTime) * 1_000_000,
133
+ endTimeUnixNano: span.endTime ? Date.parse(span.endTime) * 1_000_000 : undefined,
134
+ status: { code: span.status },
135
+ attributes: Object.entries(span.attributes).map(([key, value]) => ({
136
+ key,
137
+ value,
138
+ })),
139
+ events: span.events,
140
+ };
141
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Telemetry module — OpenTelemetry-aligned structured telemetry interfaces
3
+ * and in-memory implementations.
4
+ */
5
+ export { TelemetrySpanStatus, type TelemetryEvent, type TelemetrySpan, type TelemetryProvider, type TelemetryExporter, type TelemetryConfig, type TraceContext, type TelemetrySpanStartOptions, type TelemetryExportResult, } from "./types";
6
+ export { HttpTelemetryExporter, InMemoryTelemetryProvider, } from "./provider";
7
+ export type { HttpTelemetrySend, InMemoryTelemetryProviderOptions, } from "./provider";
8
+ export { AuditLog, type AuditEntry, type AuditFilter, } from "./audit-log";
9
+ export { SpanTree, type SpanTreeNode, type SerializedSpanTreeNode, } from "./span-tree";
10
+ export { createTraceContext, parseTraceParent, serializeTraceParent, type CreateTraceContextOptions, } from "./traceContext";
11
+ export { FileTelemetryExporter, InMemoryTelemetryExporter, NoopTelemetryExporter, OtlpHttpTraceExporter, type OtlpHttpTraceExporterOptions, } from "./exporters";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,QAAQ,EACR,KAAK,YAAY,EACjB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,KAAK,4BAA4B,GAClC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OtlpHttpTraceExporter = exports.NoopTelemetryExporter = exports.InMemoryTelemetryExporter = exports.FileTelemetryExporter = exports.serializeTraceParent = exports.parseTraceParent = exports.createTraceContext = exports.SpanTree = exports.AuditLog = exports.InMemoryTelemetryProvider = exports.HttpTelemetryExporter = exports.TelemetrySpanStatus = void 0;
4
+ /**
5
+ * Telemetry module — OpenTelemetry-aligned structured telemetry interfaces
6
+ * and in-memory implementations.
7
+ */
8
+ var types_1 = require("./types");
9
+ Object.defineProperty(exports, "TelemetrySpanStatus", { enumerable: true, get: function () { return types_1.TelemetrySpanStatus; } });
10
+ var provider_1 = require("./provider");
11
+ Object.defineProperty(exports, "HttpTelemetryExporter", { enumerable: true, get: function () { return provider_1.HttpTelemetryExporter; } });
12
+ Object.defineProperty(exports, "InMemoryTelemetryProvider", { enumerable: true, get: function () { return provider_1.InMemoryTelemetryProvider; } });
13
+ var audit_log_1 = require("./audit-log");
14
+ Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return audit_log_1.AuditLog; } });
15
+ var span_tree_1 = require("./span-tree");
16
+ Object.defineProperty(exports, "SpanTree", { enumerable: true, get: function () { return span_tree_1.SpanTree; } });
17
+ var traceContext_1 = require("./traceContext");
18
+ Object.defineProperty(exports, "createTraceContext", { enumerable: true, get: function () { return traceContext_1.createTraceContext; } });
19
+ Object.defineProperty(exports, "parseTraceParent", { enumerable: true, get: function () { return traceContext_1.parseTraceParent; } });
20
+ Object.defineProperty(exports, "serializeTraceParent", { enumerable: true, get: function () { return traceContext_1.serializeTraceParent; } });
21
+ var exporters_1 = require("./exporters");
22
+ Object.defineProperty(exports, "FileTelemetryExporter", { enumerable: true, get: function () { return exporters_1.FileTelemetryExporter; } });
23
+ Object.defineProperty(exports, "InMemoryTelemetryExporter", { enumerable: true, get: function () { return exporters_1.InMemoryTelemetryExporter; } });
24
+ Object.defineProperty(exports, "NoopTelemetryExporter", { enumerable: true, get: function () { return exporters_1.NoopTelemetryExporter; } });
25
+ Object.defineProperty(exports, "OtlpHttpTraceExporter", { enumerable: true, get: function () { return exporters_1.OtlpHttpTraceExporter; } });
@@ -0,0 +1,57 @@
1
+ /**
2
+ * InMemoryTelemetryProvider — in-process telemetry backend for development,
3
+ * testing, and single-process agent runtimes.
4
+ *
5
+ * Stores spans in memory and supports flush/drain for export pipelines.
6
+ */
7
+ import type { TelemetryExporter, TelemetryExportResult, TelemetryProvider, TelemetrySpan, TelemetryEvent, TelemetrySpanStartOptions } from "./types";
8
+ import { TelemetrySpanStatus } from "./types";
9
+ export interface InMemoryTelemetryProviderOptions {
10
+ exporters?: TelemetryExporter[];
11
+ }
12
+ export declare class FileTelemetryExporter implements TelemetryExporter {
13
+ private readonly filePath;
14
+ constructor(filePath: string);
15
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
16
+ }
17
+ export type HttpTelemetrySend = (url: string, payload: unknown) => Promise<void>;
18
+ export declare class HttpTelemetryExporter implements TelemetryExporter {
19
+ private readonly url;
20
+ private readonly send;
21
+ constructor(url: string, send?: HttpTelemetrySend);
22
+ export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
23
+ }
24
+ /**
25
+ * In-memory telemetry provider that satisfies the TelemetryProvider interface.
26
+ *
27
+ * - `startSpan` creates a new span and tracks it as active.
28
+ * - `endSpan` marks a span as completed and moves it to the completed set.
29
+ * - `recordEvent` appends a discrete event to an active span.
30
+ * - `flush` returns all completed spans and clears the completed buffer.
31
+ * - `getActiveSpans` returns all currently open (un-ended) spans.
32
+ */
33
+ export declare class InMemoryTelemetryProvider implements TelemetryProvider {
34
+ /** Active (in-flight) spans keyed by spanId. */
35
+ private readonly active;
36
+ /** Completed spans awaiting flush. */
37
+ private readonly completed;
38
+ /** Maps spanId -> traceId so child spans inherit the parent's trace. */
39
+ private readonly traceIndex;
40
+ private readonly exporters;
41
+ constructor(options?: InMemoryTelemetryProviderOptions);
42
+ startSpan(name: string, parentSpanId?: string): Promise<TelemetrySpan>;
43
+ startSpan(name: string, options?: TelemetrySpanStartOptions): Promise<TelemetrySpan>;
44
+ endSpan(spanId: string, status?: TelemetrySpanStatus): Promise<void>;
45
+ recordEvent(spanId: string, event: TelemetryEvent): Promise<void>;
46
+ flush(): Promise<void>;
47
+ /**
48
+ * Drain completed spans — returns and clears the completed buffer.
49
+ *
50
+ * Unlike `flush()` (which satisfies the TelemetryProvider interface and
51
+ * returns void), this method hands the span data back to the caller.
52
+ */
53
+ drain(): Promise<TelemetrySpan[]>;
54
+ /** Return a snapshot of all currently open (un-ended) spans. */
55
+ getActiveSpans(): TelemetrySpan[];
56
+ }
57
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/telemetry/provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAoB9C,MAAM,WAAW,gCAAgC;IAC/C,SAAS,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACjC;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAEvC,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAO9E;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjF,qBAAa,qBAAsB,YAAW,iBAAiB;IAE3D,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,iBAAmC;IAGtD,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAK9E;AAaD;;;;;;;;GAQG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;gBAEpC,OAAO,CAAC,EAAE,gCAAgC;IAMhD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACtE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC;IA2CpF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAapE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAMvC,gEAAgE;IAChE,cAAc,IAAI,aAAa,EAAE;CAGlC"}
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ /**
3
+ * InMemoryTelemetryProvider — in-process telemetry backend for development,
4
+ * testing, and single-process agent runtimes.
5
+ *
6
+ * Stores spans in memory and supports flush/drain for export pipelines.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.InMemoryTelemetryProvider = exports.HttpTelemetryExporter = exports.FileTelemetryExporter = void 0;
43
+ const node_crypto_1 = require("node:crypto");
44
+ const node_fs_1 = require("node:fs");
45
+ const path = __importStar(require("node:path"));
46
+ const types_1 = require("./types");
47
+ class FileTelemetryExporter {
48
+ filePath;
49
+ constructor(filePath) {
50
+ this.filePath = filePath;
51
+ }
52
+ async export(spans) {
53
+ if (spans.length === 0)
54
+ return { ok: true, exported: 0 };
55
+ await node_fs_1.promises.mkdir(path.dirname(this.filePath), { recursive: true });
56
+ const payload = spans.map((span) => JSON.stringify(redactSpan(span))).join("\n") + "\n";
57
+ await node_fs_1.promises.appendFile(this.filePath, payload, "utf-8");
58
+ return { ok: true, exported: spans.length };
59
+ }
60
+ }
61
+ exports.FileTelemetryExporter = FileTelemetryExporter;
62
+ class HttpTelemetryExporter {
63
+ url;
64
+ send;
65
+ constructor(url, send = defaultHttpSend) {
66
+ this.url = url;
67
+ this.send = send;
68
+ }
69
+ async export(spans) {
70
+ if (spans.length === 0)
71
+ return { ok: true, exported: 0 };
72
+ await this.send(this.url, toOtlpPayload(spans.map(redactSpan)));
73
+ return { ok: true, exported: spans.length };
74
+ }
75
+ }
76
+ exports.HttpTelemetryExporter = HttpTelemetryExporter;
77
+ function toReadonly(span) {
78
+ return {
79
+ ...span,
80
+ attributes: { ...span.attributes },
81
+ events: span.events.map((event) => ({
82
+ ...event,
83
+ attributes: event.attributes ? { ...event.attributes } : undefined,
84
+ })),
85
+ };
86
+ }
87
+ /**
88
+ * In-memory telemetry provider that satisfies the TelemetryProvider interface.
89
+ *
90
+ * - `startSpan` creates a new span and tracks it as active.
91
+ * - `endSpan` marks a span as completed and moves it to the completed set.
92
+ * - `recordEvent` appends a discrete event to an active span.
93
+ * - `flush` returns all completed spans and clears the completed buffer.
94
+ * - `getActiveSpans` returns all currently open (un-ended) spans.
95
+ */
96
+ class InMemoryTelemetryProvider {
97
+ /** Active (in-flight) spans keyed by spanId. */
98
+ active = new Map();
99
+ /** Completed spans awaiting flush. */
100
+ completed = [];
101
+ /** Maps spanId -> traceId so child spans inherit the parent's trace. */
102
+ traceIndex = new Map();
103
+ exporters;
104
+ constructor(options) {
105
+ this.exporters = options?.exporters ?? [];
106
+ }
107
+ async startSpan(name, optionsOrParentSpanId) {
108
+ const spanId = (0, node_crypto_1.randomUUID)();
109
+ const options = typeof optionsOrParentSpanId === "string"
110
+ ? { parentSpanId: optionsOrParentSpanId }
111
+ : optionsOrParentSpanId;
112
+ const parentSpanId = options?.traceContext?.spanId ?? options?.parentSpanId;
113
+ let traceId;
114
+ if (options?.traceContext) {
115
+ traceId = options.traceContext.traceId;
116
+ }
117
+ else if (parentSpanId) {
118
+ // Inherit traceId from the parent span.
119
+ traceId = this.traceIndex.get(parentSpanId) ?? (0, node_crypto_1.randomUUID)();
120
+ }
121
+ else {
122
+ traceId = (0, node_crypto_1.randomUUID)();
123
+ }
124
+ const span = {
125
+ name,
126
+ traceId,
127
+ spanId,
128
+ parentSpanId,
129
+ startTime: new Date().toISOString(),
130
+ status: types_1.TelemetrySpanStatus.Unset,
131
+ attributes: {
132
+ ...options?.attributes,
133
+ ...(options?.correlationId
134
+ ? { "babysitter.correlation_id": options.correlationId }
135
+ : {}),
136
+ ...(options?.traceContext?.correlationId && !options?.correlationId
137
+ ? { "babysitter.correlation_id": options.traceContext.correlationId }
138
+ : {}),
139
+ },
140
+ events: [],
141
+ };
142
+ this.active.set(spanId, span);
143
+ this.traceIndex.set(spanId, traceId);
144
+ return toReadonly(span);
145
+ }
146
+ async endSpan(spanId, status) {
147
+ const span = this.active.get(spanId);
148
+ if (!span) {
149
+ return; // Silently ignore unknown/already-ended spans.
150
+ }
151
+ span.endTime = new Date().toISOString();
152
+ span.status = status ?? types_1.TelemetrySpanStatus.Ok;
153
+ this.active.delete(spanId);
154
+ this.completed.push(span);
155
+ }
156
+ async recordEvent(spanId, event) {
157
+ const span = this.active.get(spanId);
158
+ if (!span) {
159
+ return; // Silently ignore events on unknown/ended spans.
160
+ }
161
+ span.events.push(event);
162
+ }
163
+ async flush() {
164
+ const spans = this.completed.map(toReadonly);
165
+ for (const exporter of this.exporters) {
166
+ await exporter.export(spans);
167
+ }
168
+ this.completed.length = 0;
169
+ }
170
+ /**
171
+ * Drain completed spans — returns and clears the completed buffer.
172
+ *
173
+ * Unlike `flush()` (which satisfies the TelemetryProvider interface and
174
+ * returns void), this method hands the span data back to the caller.
175
+ */
176
+ async drain() {
177
+ return this.completed.splice(0).map(toReadonly);
178
+ }
179
+ // ---------- Extra helpers (not on interface) ----------
180
+ /** Return a snapshot of all currently open (un-ended) spans. */
181
+ getActiveSpans() {
182
+ return [...this.active.values()].map(toReadonly);
183
+ }
184
+ }
185
+ exports.InMemoryTelemetryProvider = InMemoryTelemetryProvider;
186
+ function redactSpan(span) {
187
+ return {
188
+ ...span,
189
+ attributes: redactAttributes(span.attributes),
190
+ events: span.events.map((event) => ({
191
+ ...event,
192
+ attributes: event.attributes ? redactAttributes(event.attributes) : undefined,
193
+ })),
194
+ };
195
+ }
196
+ function redactAttributes(attributes) {
197
+ return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [
198
+ key,
199
+ isSecretKey(key) || (typeof value === "string" && looksSecretValue(value))
200
+ ? "[REDACTED]"
201
+ : value,
202
+ ]));
203
+ }
204
+ function isSecretKey(key) {
205
+ return /(token|secret|password|api[_-]?key|authorization|credential)/i.test(key);
206
+ }
207
+ function looksSecretValue(value) {
208
+ return /(bearer\s+\S+|token=\S+|password=\S+|secret=\S+)/i.test(value);
209
+ }
210
+ function toOtlpPayload(spans) {
211
+ return {
212
+ resourceSpans: [
213
+ {
214
+ resource: { attributes: [] },
215
+ scopeSpans: [
216
+ {
217
+ scope: { name: "@a5c-ai/genty-runtime" },
218
+ spans: spans.map((span) => ({
219
+ traceId: span.traceId,
220
+ spanId: span.spanId,
221
+ parentSpanId: span.parentSpanId,
222
+ name: span.name,
223
+ startTimeUnixNano: isoToUnixNano(span.startTime),
224
+ endTimeUnixNano: span.endTime ? isoToUnixNano(span.endTime) : undefined,
225
+ status: { code: span.status },
226
+ attributes: toOtlpAttributes(span.attributes),
227
+ events: span.events.map((event) => ({
228
+ name: event.name,
229
+ timeUnixNano: isoToUnixNano(event.timestamp),
230
+ attributes: event.attributes ? toOtlpAttributes(event.attributes) : [],
231
+ })),
232
+ })),
233
+ },
234
+ ],
235
+ },
236
+ ],
237
+ };
238
+ }
239
+ function toOtlpAttributes(attributes) {
240
+ return Object.entries(attributes).map(([key, value]) => ({
241
+ key,
242
+ value: typeof value === "string"
243
+ ? { stringValue: value }
244
+ : typeof value === "number"
245
+ ? { doubleValue: value }
246
+ : { boolValue: value },
247
+ }));
248
+ }
249
+ function isoToUnixNano(value) {
250
+ return String(BigInt(new Date(value).getTime()) * 1000000n);
251
+ }
252
+ async function defaultHttpSend(url, payload) {
253
+ const response = await fetch(url, {
254
+ method: "POST",
255
+ headers: { "content-type": "application/json" },
256
+ body: JSON.stringify(payload),
257
+ });
258
+ if (!response.ok) {
259
+ throw new Error(`Telemetry export failed with HTTP ${response.status}`);
260
+ }
261
+ }