@narumitw/pi-otel 0.0.0-stage → 0.54.3

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 (57) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/LICENSE +21 -0
  3. package/README.md +368 -2
  4. package/dist/chunks/chunk-DSQBXICE.ts +150 -0
  5. package/dist/chunks/chunk-DSQBXICE.ts.map +7 -0
  6. package/dist/chunks/runtime-X3YFJUNH.ts +404 -0
  7. package/dist/chunks/runtime-X3YFJUNH.ts.map +7 -0
  8. package/dist/config.d.ts +36 -0
  9. package/dist/durable-projection.d.ts +9 -0
  10. package/dist/durable-recorder.d.ts +57 -0
  11. package/dist/durable-state.d.ts +43 -0
  12. package/dist/durable.d.ts +25 -0
  13. package/dist/durable.js +897 -0
  14. package/dist/durable.js.map +7 -0
  15. package/dist/git.d.ts +5 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +1732 -0
  18. package/dist/index.js.map +7 -0
  19. package/dist/index.ts +1874 -0
  20. package/dist/index.ts.map +7 -0
  21. package/dist/library-chunks/chunk-7DN64UHE.js +158 -0
  22. package/dist/library-chunks/chunk-7DN64UHE.js.map +7 -0
  23. package/dist/library-chunks/chunk-7JGM5RS3.js +72 -0
  24. package/dist/library-chunks/chunk-7JGM5RS3.js.map +7 -0
  25. package/dist/library-chunks/chunk-BBL32ZV5.js +84 -0
  26. package/dist/library-chunks/chunk-BBL32ZV5.js.map +7 -0
  27. package/dist/library-chunks/runtime-554E6FVF.js +406 -0
  28. package/dist/library-chunks/runtime-554E6FVF.js.map +7 -0
  29. package/dist/otel.d.ts +13 -0
  30. package/dist/otlp-settings.d.ts +8 -0
  31. package/dist/pi-session.d.ts +43 -0
  32. package/dist/public-api.d.ts +2 -0
  33. package/dist/runtime-api.d.ts +6 -0
  34. package/dist/runtime-core.d.ts +26 -0
  35. package/dist/runtime-defaults.d.ts +1 -0
  36. package/dist/runtime.d.ts +26 -0
  37. package/dist/sanitizer.d.ts +2 -0
  38. package/dist/tracing.d.ts +198 -0
  39. package/docs/durable.md +128 -0
  40. package/package.json +87 -4
  41. package/src/config.ts +330 -0
  42. package/src/durable-projection.ts +112 -0
  43. package/src/durable-recorder.ts +539 -0
  44. package/src/durable-state.ts +135 -0
  45. package/src/durable.ts +364 -0
  46. package/src/git.ts +64 -0
  47. package/src/index.ts +12 -0
  48. package/src/otel.ts +397 -0
  49. package/src/otlp-settings.ts +72 -0
  50. package/src/pi-session.ts +570 -0
  51. package/src/public-api.ts +13 -0
  52. package/src/runtime-api.ts +16 -0
  53. package/src/runtime-core.ts +114 -0
  54. package/src/runtime-defaults.ts +1 -0
  55. package/src/runtime.ts +509 -0
  56. package/src/sanitizer.ts +157 -0
  57. package/src/tracing.ts +940 -0
@@ -0,0 +1,36 @@
1
+ import { type OtlpConnection } from "./otlp-settings.js";
2
+ export { DEFAULT_BASE_URL } from "./runtime-defaults.js";
3
+ export interface LangfuseConfig {
4
+ backend?: "langfuse";
5
+ publicKey: string;
6
+ secretKey: string;
7
+ baseUrl: string;
8
+ environment?: string;
9
+ release?: string;
10
+ userId?: string;
11
+ captureContent: boolean;
12
+ }
13
+ export type LangfuseConfigPatch = Partial<LangfuseConfig>;
14
+ interface OtlpSettings extends OtlpConnection {
15
+ backend: "otlp";
16
+ captureContent: boolean;
17
+ userId?: string;
18
+ }
19
+ export type TracingSettings = LangfuseConfig | OtlpSettings;
20
+ type NormalizedSettings<T> = {
21
+ ok: true;
22
+ config: T;
23
+ } | {
24
+ ok: false;
25
+ reason: string;
26
+ };
27
+ export type SettingsResult = NormalizedSettings<TracingSettings> & {
28
+ path: string;
29
+ warnings: string[];
30
+ missing?: true;
31
+ legacy?: true;
32
+ };
33
+ export declare function otelSettingsPath(): string;
34
+ export declare function writeLangfuseConfig(patch: LangfuseConfigPatch, path?: string): Promise<LangfuseConfig>;
35
+ export declare function loadSettings(path?: string): Promise<SettingsResult>;
36
+ export declare function normalizeLangfuseConfig(value: unknown): NormalizedSettings<LangfuseConfig>;
@@ -0,0 +1,9 @@
1
+ import type { EntryRecord } from "@earendil-works/pi-durable";
2
+ import type { ObservationAttributes } from "./tracing.js";
3
+ type Message = NonNullable<EntryRecord["model"]>[number];
4
+ export declare function durableAttributes(attributes: ObservationAttributes): ObservationAttributes;
5
+ export declare function durableDiagnosticCount(entry: EntryRecord | undefined): number;
6
+ /** Project committed messages without provider configuration, deltas or raw diagnostics. */
7
+ export declare function durableContent(messages: readonly Message[] | undefined, capture: boolean, diagnosticCount?: number): unknown;
8
+ export declare function durableUsage(message: Message): ObservationAttributes;
9
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { EntryId, EntryRecord, SubmissionId, SubmissionRecord } from "@earendil-works/pi-durable";
2
+ import type { DurableCommit, DurableSnapshot } from "./durable-state.js";
3
+ import type { TraceBackend } from "./tracing.js";
4
+ export interface DurableCorrelation {
5
+ requestId?: string;
6
+ userId?: string;
7
+ applicationId?: string;
8
+ }
9
+ export interface DurableRecorderOptions extends DurableCorrelation {
10
+ conversationId: number;
11
+ sessionId?: string;
12
+ traceName?: string;
13
+ captureContent?: boolean;
14
+ metadata?: Readonly<Record<string, unknown>>;
15
+ submissionCorrelation?: (record: SubmissionRecord) => DurableCorrelation;
16
+ onTraceId?: (traceId: string) => void | Promise<void>;
17
+ onError?: (stage: string) => void | Promise<void>;
18
+ }
19
+ /** Durable state machine using the same trace backend, ownership and capture core as the Pi adapter. */
20
+ export declare class DurableRecorder {
21
+ private readonly backend;
22
+ private readonly options;
23
+ private readonly root;
24
+ private run?;
25
+ private readonly submissions;
26
+ private readonly pendingSubmissions;
27
+ private readonly entries;
28
+ private readonly completedRuns;
29
+ private readonly completedGenerations;
30
+ private live;
31
+ private baselineEntry;
32
+ private disposed;
33
+ private gaps;
34
+ constructor(backend: TraceBackend, options: DurableRecorderOptions);
35
+ get submissionIds(): readonly SubmissionId[];
36
+ report(stage: string): void;
37
+ private callback;
38
+ private customMetadata;
39
+ private safe;
40
+ private start;
41
+ private update;
42
+ private end;
43
+ private interrupted;
44
+ private correlationAttributes;
45
+ submission(record: SubmissionRecord, readEntry: (id: EntryId) => Promise<EntryRecord | undefined>, correlation?: DurableCorrelation, snapshot?: boolean): Promise<void>;
46
+ snapshot(snapshot: DurableSnapshot, initial?: boolean): void;
47
+ private sameRun;
48
+ private beginRun;
49
+ private closeRound;
50
+ private closeRun;
51
+ private generation;
52
+ private entry;
53
+ private finishTool;
54
+ private task;
55
+ commit(commit: DurableCommit, readEntry: (id: EntryId) => Promise<EntryRecord | undefined>): Promise<void>;
56
+ dispose(reason?: string): void;
57
+ }
@@ -0,0 +1,43 @@
1
+ import { type CommitPublication, type ConversationId, type ConversationView, type EntryRecord, type JsonObject, type SubmissionId, type SubmissionRecord, type TaskId } from "@earendil-works/pi-durable";
2
+ export interface DurableLive {
3
+ run?: {
4
+ taskId: TaskId;
5
+ inputs: readonly SubmissionId[];
6
+ afterRun: boolean;
7
+ };
8
+ tools: readonly {
9
+ taskId?: TaskId;
10
+ callId: string;
11
+ name: string;
12
+ status: "pending" | "running" | "done";
13
+ }[];
14
+ }
15
+ export interface DurableSnapshot {
16
+ entries: readonly EntryRecord[];
17
+ live: DurableLive;
18
+ inbox: readonly SubmissionId[];
19
+ }
20
+ export interface DurableTask {
21
+ id: TaskId;
22
+ kind: string;
23
+ failed: boolean;
24
+ terminal: boolean;
25
+ phase?: string;
26
+ attempt?: number;
27
+ cutoff?: number;
28
+ callId?: string;
29
+ name?: string;
30
+ arguments?: JsonObject;
31
+ }
32
+ export interface DurableCommit {
33
+ entries: readonly EntryRecord[];
34
+ submissions: readonly SubmissionRecord[];
35
+ tasks: readonly DurableTask[];
36
+ live?: DurableLive;
37
+ inbox?: readonly SubmissionId[];
38
+ }
39
+ /** The view is a baseline only: never retain partial messages, running output, provider state or diagnostics. */
40
+ export declare function durableSnapshot(view: ConversationView): DurableSnapshot;
41
+ /** Record only the public committed fields tracing needs; never inspect request options or raw failure bodies. */
42
+ export declare function durableCommit(publication: CommitPublication, conversationId: ConversationId): DurableCommit;
43
+ export declare function advanceDurableSnapshot(snapshot: DurableSnapshot, commit: DurableCommit): DurableSnapshot;
@@ -0,0 +1,25 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import type { ConversationId, Harness, SubmissionId } from "@earendil-works/pi-durable";
3
+ import { type DurableCorrelation, type DurableRecorderOptions } from "./durable-recorder.js";
4
+ import { type LangfuseRuntime } from "./runtime-core.js";
5
+ export type { DurableCorrelation } from "./durable-recorder.js";
6
+ export { type CreateLangfuseRuntimeOptions, createLangfuseRuntime, createOtelRuntime, type LangfuseRuntime, type LangfuseRuntimeConfig, type OtlpRuntimeConfig, } from "./runtime-api.js";
7
+ export { createLangfuseRuntimeFromBackend } from "./runtime-core.js";
8
+ export type { Observation, ObservationAttributes, ObservationType, TraceBackend } from "./tracing.js";
9
+ export interface PiLangfuseDurableOptions extends Omit<DurableRecorderOptions, "conversationId" | "requestId"> {
10
+ harness: Harness;
11
+ conversationId: ConversationId;
12
+ /** Governs observation only. Cancellation never aborts execution or resumes recovery. */
13
+ context: Context;
14
+ }
15
+ export interface PiLangfuseDurableConversation {
16
+ readonly active: boolean;
17
+ /** Resolves after initialization, observer detachment, and owned delivery have joined. */
18
+ readonly closed: Promise<void>;
19
+ /** Read committed status without waiting for or starting agent work. Also supports late submission attachment. */
20
+ observeSubmission(id: SubmissionId, correlation?: DurableCorrelation): Promise<void>;
21
+ /** Detach and close observations, without flushing/shutting down the runtime or modifying durable work. */
22
+ dispose(): Promise<void>;
23
+ }
24
+ /** Attach a fail-open, committed-only observer. The host remains the sole owner of execution. */
25
+ export declare function createPiLangfuseDurableConversation(runtime: LangfuseRuntime, options: PiLangfuseDurableOptions): Promise<PiLangfuseDurableConversation>;