@traceroot-ai/traceroot 0.1.6 → 0.1.8
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/attributes.d.ts +14 -0
- package/dist/attributes.d.ts.map +1 -0
- package/dist/attributes.js +110 -0
- package/dist/attributes.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +8 -2
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -34
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/instrumentation.d.ts.map +1 -1
- package/dist/instrumentation.js +4 -0
- package/dist/instrumentation.js.map +1 -1
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +5 -63
- package/dist/observe.js.map +1 -1
- package/dist/pi.d.ts +156 -0
- package/dist/pi.d.ts.map +1 -0
- package/dist/pi.js +615 -0
- package/dist/pi.js.map +1 -0
- package/dist/spans.d.ts +18 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +104 -0
- package/dist/spans.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -1
package/dist/pi.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { SpanStatusCode } from '@opentelemetry/api';
|
|
2
|
+
import type { Context, Span, Tracer } from '@opentelemetry/api';
|
|
3
|
+
/**
|
|
4
|
+
* Hand-transcribed local mirror of @earendil-works/pi-coding-agent / pi-agent-core, verified against published .d.ts at 0.80.6.
|
|
5
|
+
*/
|
|
6
|
+
export interface Usage {
|
|
7
|
+
input: number;
|
|
8
|
+
output: number;
|
|
9
|
+
cacheRead: number;
|
|
10
|
+
cacheWrite: number;
|
|
11
|
+
reasoning?: number;
|
|
12
|
+
totalTokens: number;
|
|
13
|
+
cost: {
|
|
14
|
+
input: number;
|
|
15
|
+
output: number;
|
|
16
|
+
cacheRead: number;
|
|
17
|
+
cacheWrite: number;
|
|
18
|
+
total: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type StopReason = 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
|
|
22
|
+
export interface AssistantMessage {
|
|
23
|
+
role: 'assistant';
|
|
24
|
+
content: unknown[];
|
|
25
|
+
api: string;
|
|
26
|
+
provider: string;
|
|
27
|
+
model: string;
|
|
28
|
+
responseModel?: string;
|
|
29
|
+
responseId?: string;
|
|
30
|
+
usage: Usage;
|
|
31
|
+
stopReason: StopReason;
|
|
32
|
+
errorMessage?: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
}
|
|
35
|
+
export interface UserMessage {
|
|
36
|
+
role: 'user';
|
|
37
|
+
content: unknown;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ToolResultMessage {
|
|
41
|
+
role: 'toolResult';
|
|
42
|
+
toolCallId: string;
|
|
43
|
+
toolName: string;
|
|
44
|
+
content: unknown[];
|
|
45
|
+
details?: unknown;
|
|
46
|
+
isError: boolean;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
}
|
|
49
|
+
export interface OtherAgentMessage {
|
|
50
|
+
role: 'bashExecution' | 'custom' | 'branchSummary' | 'compactionSummary';
|
|
51
|
+
timestamp?: number;
|
|
52
|
+
}
|
|
53
|
+
export type AgentMessage = AssistantMessage | UserMessage | ToolResultMessage | OtherAgentMessage;
|
|
54
|
+
export type AgentEvent = {
|
|
55
|
+
type: 'agent_start';
|
|
56
|
+
} | {
|
|
57
|
+
type: 'agent_end';
|
|
58
|
+
messages: AgentMessage[];
|
|
59
|
+
willRetry?: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'turn_start';
|
|
62
|
+
} | {
|
|
63
|
+
type: 'turn_end';
|
|
64
|
+
message: AgentMessage;
|
|
65
|
+
toolResults: ToolResultMessage[];
|
|
66
|
+
} | {
|
|
67
|
+
type: 'message_start';
|
|
68
|
+
message: AgentMessage;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'message_update';
|
|
71
|
+
message: AgentMessage;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'message_end';
|
|
74
|
+
message: AgentMessage;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'tool_execution_start';
|
|
77
|
+
toolCallId: string;
|
|
78
|
+
toolName: string;
|
|
79
|
+
args: unknown;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'tool_execution_update';
|
|
82
|
+
toolCallId: string;
|
|
83
|
+
toolName: string;
|
|
84
|
+
args: unknown;
|
|
85
|
+
partialResult: unknown;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'tool_execution_end';
|
|
88
|
+
toolCallId: string;
|
|
89
|
+
toolName: string;
|
|
90
|
+
result: unknown;
|
|
91
|
+
isError: boolean;
|
|
92
|
+
};
|
|
93
|
+
export interface PromptOptions {
|
|
94
|
+
images?: unknown[];
|
|
95
|
+
streamingBehavior?: 'steer' | 'followUp';
|
|
96
|
+
}
|
|
97
|
+
export interface AgentSessionInstance {
|
|
98
|
+
readonly sessionId?: string;
|
|
99
|
+
/** True while a run is actively executing; prompt() routes through steer()/followUp() instead of starting fresh (see isQueueOnlySteer). */
|
|
100
|
+
readonly isStreaming?: boolean;
|
|
101
|
+
prompt(text: string, options?: PromptOptions): Promise<void>;
|
|
102
|
+
/** Queue a steering message mid-run. Optional so a partial double doesn't disable instrumentation over one missing method. */
|
|
103
|
+
steer?(text: string, images?: unknown[]): Promise<void>;
|
|
104
|
+
/** Queue a follow-up message, processed once the agent has no more tool calls or steering messages left. */
|
|
105
|
+
followUp?(text: string, images?: unknown[]): Promise<void>;
|
|
106
|
+
subscribe(listener: (event: AgentEvent) => void): () => void;
|
|
107
|
+
/** dispose() reassigns the private _eventListeners array to a fresh empty array, so no listener (including this file's own) fires again after dispose(). */
|
|
108
|
+
dispose(): void;
|
|
109
|
+
}
|
|
110
|
+
export interface AgentSessionConstructor {
|
|
111
|
+
prototype: AgentSessionInstance;
|
|
112
|
+
}
|
|
113
|
+
/** Structural shape of the imported `@earendil-works/pi-coding-agent` module namespace. */
|
|
114
|
+
export interface PiCodingAgentModule {
|
|
115
|
+
AgentSession?: AgentSessionConstructor;
|
|
116
|
+
[key: string]: unknown;
|
|
117
|
+
}
|
|
118
|
+
export declare const TRACER_NAME = "@traceroot-ai/pi-coding-agent";
|
|
119
|
+
export interface PiInstrumentationConfig {
|
|
120
|
+
/** Capture prompt/response text as input.value/output.value on AGENT and LLM spans. Default true. */
|
|
121
|
+
captureContent?: boolean;
|
|
122
|
+
/** Capture tool call args/results as input.value/output.value on TOOL spans. Default true. */
|
|
123
|
+
captureToolIo?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface ResolvedPiInstrumentationConfig {
|
|
126
|
+
captureContent: boolean;
|
|
127
|
+
captureToolIo: boolean;
|
|
128
|
+
}
|
|
129
|
+
export declare function resolveConfig(config?: PiInstrumentationConfig): ResolvedPiInstrumentationConfig;
|
|
130
|
+
export declare function openRootSpan(tracer: Pick<Tracer, 'startSpan'>, parentCtx: Context, input: {
|
|
131
|
+
text: string | undefined;
|
|
132
|
+
sessionId: string | undefined;
|
|
133
|
+
captureContent: boolean;
|
|
134
|
+
}): Span;
|
|
135
|
+
export declare function stampRootOutput(span: Span, finalMessages: AgentMessage[], captureContent: boolean): void;
|
|
136
|
+
export declare function finalizeRootSpan(span: Span, retryCount: number, status: {
|
|
137
|
+
code: SpanStatusCode;
|
|
138
|
+
message?: string;
|
|
139
|
+
}, error?: unknown): void;
|
|
140
|
+
export declare function openLlmSpan(tracer: Pick<Tracer, 'startSpan'>, parentCtx: Context, message: AssistantMessage): Span;
|
|
141
|
+
export declare function closeLlmSpan(span: Span, message: AssistantMessage, captureContent: boolean): void;
|
|
142
|
+
export declare function describeToolCallSpan(toolName: string, args: unknown): string;
|
|
143
|
+
export declare function openToolSpan(tracer: Pick<Tracer, 'startSpan'>, parentCtx: Context, toolCallId: string, toolName: string, args: unknown, captureToolIo: boolean): Span;
|
|
144
|
+
export declare function closeToolSpan(span: Span, result: unknown, isError: boolean, captureToolIo: boolean): void;
|
|
145
|
+
export declare function closeDanglingSpan(span: Span | undefined): void;
|
|
146
|
+
/**
|
|
147
|
+
* Dispatcher entry point for pi, called once by wireInstrumentations() in
|
|
148
|
+
* instrumentation.ts. Kept here rather than inline in that shared file so the
|
|
149
|
+
* dispatcher stays symmetric with claude/openai (one import + one call). Unwraps
|
|
150
|
+
* the optional { module, config } form; pi carries its own captureContent/
|
|
151
|
+
* captureToolIo config, passed through unmerged (there is no apiKey/baseUrl to
|
|
152
|
+
* thread). A throw from instrumentPiCodingAgent() surfaces, same as claude's.
|
|
153
|
+
*/
|
|
154
|
+
export declare function wirePiCodingAgentInstrumentation(entry: unknown): void;
|
|
155
|
+
export declare function instrumentPiCodingAgent(sdk: unknown, config?: PiInstrumentationConfig): unknown;
|
|
156
|
+
//# sourceMappingURL=pi.d.ts.map
|
package/dist/pi.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../src/pi.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,cAAc,EAAS,MAAM,oBAAoB,CAAC;AAClG,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAiBhE;;GAEG;AAEH,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM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