@uncoil.dev/sdk 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +88 -0
- package/dist/doctor.d.ts +33 -0
- package/dist/doctor.js +156 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +652 -0
- package/dist/integrations/auto.d.ts +16 -0
- package/dist/integrations/auto.js +54 -0
- package/dist/integrations/langgraph.d.ts +24 -0
- package/dist/integrations/langgraph.js +80 -0
- package/dist/integrations/observation.d.ts +31 -0
- package/dist/integrations/observation.js +108 -0
- package/dist/integrations/providers.d.ts +7 -0
- package/dist/integrations/providers.js +224 -0
- package/dist/integrations/tools.d.ts +10 -0
- package/dist/integrations/tools.js +48 -0
- package/dist/integrations/vercel-ai.d.ts +24 -0
- package/dist/integrations/vercel-ai.js +72 -0
- package/dist/login.d.ts +37 -0
- package/dist/login.js +214 -0
- package/package.json +52 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export interface UncoilConfig {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
host?: string;
|
|
4
|
+
/** Uncoil Cloud data region. Ignored when `host` is provided. Defaults to UNCOIL_REGION or EU. */
|
|
5
|
+
region?: UncoilRegion;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
/** Release and environment are copied onto observations created by this client. */
|
|
8
|
+
release?: string;
|
|
9
|
+
environment?: string;
|
|
10
|
+
deploymentId?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
endUserId?: string;
|
|
13
|
+
tags?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Share of runs to record, from 0 (none) to 1 (all, the default). The choice is made per run, so a kept
|
|
16
|
+
* run is always complete and a dropped run leaves nothing behind. Spans that report an error are still
|
|
17
|
+
* kept unless `keepErrors` is false.
|
|
18
|
+
*/
|
|
19
|
+
sampleRate?: number;
|
|
20
|
+
/** Keep spans that report an error even when their run was not sampled. Defaults to true. */
|
|
21
|
+
keepErrors?: boolean;
|
|
22
|
+
/** Extra clean-up of prompts and answers before they leave your app. Secret removal always runs, and emails, phone numbers and card numbers are masked unless you set `pii: false`. */
|
|
23
|
+
redact?: RedactionOptions;
|
|
24
|
+
/** Called instead of printing a warning when the SDK has a problem sending data. */
|
|
25
|
+
onError?: (error: UncoilError) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface RedactionOptions {
|
|
28
|
+
/** Mask emails, phone numbers and card numbers. On by default; set to false to send them as they are. */
|
|
29
|
+
pii?: boolean;
|
|
30
|
+
/** Extra patterns to mask. Strings are matched as plain text. */
|
|
31
|
+
patterns?: Array<RegExp | string>;
|
|
32
|
+
/** Your own last-step cleaner; its result is what gets sent. */
|
|
33
|
+
fn?: (text: string) => string;
|
|
34
|
+
/** What masked text is replaced with. Defaults to "[redacted]". */
|
|
35
|
+
replacement?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A problem the SDK ran into, with a plain-language fix in `hint`. */
|
|
38
|
+
export declare class UncoilError extends Error {
|
|
39
|
+
readonly code: string;
|
|
40
|
+
readonly hint: string;
|
|
41
|
+
readonly status?: number;
|
|
42
|
+
constructor(code: string, message: string, hint: string, status?: number);
|
|
43
|
+
}
|
|
44
|
+
export type UncoilRegion = "eu" | "us";
|
|
45
|
+
export declare const UNCOIL_REGION_HOSTS: Record<UncoilRegion, string>;
|
|
46
|
+
export interface SpanData {
|
|
47
|
+
spanId?: string;
|
|
48
|
+
runId?: string;
|
|
49
|
+
spanType: string;
|
|
50
|
+
input?: any;
|
|
51
|
+
output?: any;
|
|
52
|
+
latencyMs?: number;
|
|
53
|
+
costUsd?: number;
|
|
54
|
+
modelId?: string;
|
|
55
|
+
toolName?: string;
|
|
56
|
+
metadata?: Record<string, any>;
|
|
57
|
+
parentSpanId?: string;
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
endUserId?: string;
|
|
60
|
+
deploymentId?: string;
|
|
61
|
+
environment?: string;
|
|
62
|
+
release?: string;
|
|
63
|
+
tags?: string[];
|
|
64
|
+
traceName?: string;
|
|
65
|
+
inputTokens?: number;
|
|
66
|
+
outputTokens?: number;
|
|
67
|
+
ttftMs?: number;
|
|
68
|
+
retryCount?: number;
|
|
69
|
+
errorType?: string;
|
|
70
|
+
errorMessage?: string;
|
|
71
|
+
isStreamChunk?: boolean;
|
|
72
|
+
streamSequence?: number;
|
|
73
|
+
streamFinal?: boolean;
|
|
74
|
+
payloadFormat?: string;
|
|
75
|
+
createdAt?: string;
|
|
76
|
+
promptVersionId?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface PromptResolution {
|
|
79
|
+
prompt: {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
type: "text" | "chat";
|
|
84
|
+
};
|
|
85
|
+
version: {
|
|
86
|
+
id: string;
|
|
87
|
+
version: number;
|
|
88
|
+
content: string;
|
|
89
|
+
variables: string[];
|
|
90
|
+
labels: string[];
|
|
91
|
+
model?: string;
|
|
92
|
+
createdAt: number;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export interface PromptResolutionOptions {
|
|
96
|
+
cacheTtlMs?: number;
|
|
97
|
+
fallback?: PromptResolution;
|
|
98
|
+
}
|
|
99
|
+
export interface RuntimePolicy {
|
|
100
|
+
enforcementMode: "observe" | "enforce";
|
|
101
|
+
maxCostPerRun?: number;
|
|
102
|
+
maxCostPerDay?: number;
|
|
103
|
+
fallbackChain: string[];
|
|
104
|
+
retryPolicy: {
|
|
105
|
+
maxAttempts: number;
|
|
106
|
+
backoffMs: number;
|
|
107
|
+
backoffMultiplier: number;
|
|
108
|
+
retryableErrors: string[];
|
|
109
|
+
};
|
|
110
|
+
latencyBudgetMs?: number;
|
|
111
|
+
}
|
|
112
|
+
export interface OrchestrateOptions<T> {
|
|
113
|
+
policy: RuntimePolicy;
|
|
114
|
+
call: (model: string, signal: AbortSignal) => Promise<T>;
|
|
115
|
+
model: string;
|
|
116
|
+
input?: any;
|
|
117
|
+
calculateCost?: (result: T, model: string) => number;
|
|
118
|
+
runId?: string;
|
|
119
|
+
}
|
|
120
|
+
export declare function currentRunId(): string;
|
|
121
|
+
export declare function currentTraceContext(): {
|
|
122
|
+
runId: string;
|
|
123
|
+
spanId?: string;
|
|
124
|
+
traceName?: string;
|
|
125
|
+
client?: UncoilClient;
|
|
126
|
+
} | undefined;
|
|
127
|
+
export declare function integrationPayload(value: unknown): string;
|
|
128
|
+
export declare function currentSpanId(): string | undefined;
|
|
129
|
+
export declare const MAX_PAYLOAD_CHARS = 10000;
|
|
130
|
+
/** Build the clean-up for `redact`. Emails, phone numbers and card numbers are masked unless `pii: false`. */
|
|
131
|
+
export declare function buildRedactor(options?: RedactionOptions): ((text: string) => string) | undefined;
|
|
132
|
+
/** Stable number in [0, 1) for a run id, so every span of a run gets the same sampling decision. */
|
|
133
|
+
export declare function sampleBucket(runId: string): number;
|
|
134
|
+
export declare class UncoilClient {
|
|
135
|
+
protected apiKey: string;
|
|
136
|
+
protected host: string;
|
|
137
|
+
protected ingestUrl: string;
|
|
138
|
+
protected projectId?: string;
|
|
139
|
+
private checkCostUrl;
|
|
140
|
+
private _lastFailOpen;
|
|
141
|
+
private promptCache;
|
|
142
|
+
private release?;
|
|
143
|
+
private environment?;
|
|
144
|
+
private deploymentId?;
|
|
145
|
+
private sessionId?;
|
|
146
|
+
private endUserId?;
|
|
147
|
+
private tags?;
|
|
148
|
+
private sampleRate;
|
|
149
|
+
private keepErrors;
|
|
150
|
+
private redactor?;
|
|
151
|
+
private onError?;
|
|
152
|
+
private warned;
|
|
153
|
+
constructor(config?: UncoilConfig);
|
|
154
|
+
private clean;
|
|
155
|
+
/** Tell the app about a problem once per kind: through `onError` if given, otherwise as a console warning. */
|
|
156
|
+
private report;
|
|
157
|
+
/** True when this span should be dropped by sampling. */
|
|
158
|
+
private sampledOut;
|
|
159
|
+
private checkIngestResponse;
|
|
160
|
+
ingest(data: SpanData): Promise<void>;
|
|
161
|
+
/** Resolve a prompt version labeled for an environment without redeploying application code. */
|
|
162
|
+
getPrompt(name: string, environment?: string, options?: PromptResolutionOptions): Promise<PromptResolution>;
|
|
163
|
+
/** Attach end-user feedback to a trace or span. The request is fire-and-forget like span ingestion. */
|
|
164
|
+
feedback(traceId: string, value: boolean | number | string, options?: {
|
|
165
|
+
kind?: 'thumb' | 'star' | 'text';
|
|
166
|
+
spanId?: string;
|
|
167
|
+
reason?: string;
|
|
168
|
+
comment?: string;
|
|
169
|
+
endUserId?: string;
|
|
170
|
+
dedupeKey?: string;
|
|
171
|
+
projectId?: string;
|
|
172
|
+
}): void;
|
|
173
|
+
/** Attach a typed score to a trace or span through the feedback API. */
|
|
174
|
+
score(traceId: string, name: string, value: boolean | number | string, options?: {
|
|
175
|
+
dataType?: 'numeric' | 'boolean' | 'categorical' | 'text';
|
|
176
|
+
spanId?: string;
|
|
177
|
+
comment?: string;
|
|
178
|
+
projectId?: string;
|
|
179
|
+
}): void;
|
|
180
|
+
/**
|
|
181
|
+
* Server-side cost check. Returns the server's decision on whether
|
|
182
|
+
* the next call would exceed the ceiling.
|
|
183
|
+
*/
|
|
184
|
+
private checkCost;
|
|
185
|
+
orchestrate<T>(options: OrchestrateOptions<T>): Promise<T>;
|
|
186
|
+
}
|
|
187
|
+
export type StepType = 'agent' | 'llm' | 'tool' | 'retrieval' | 'span' | (string & {});
|
|
188
|
+
/** A step in progress. Set its output and anything it measured before it ends. */
|
|
189
|
+
export declare class Step {
|
|
190
|
+
readonly name: string;
|
|
191
|
+
readonly type: StepType;
|
|
192
|
+
readonly input?: unknown | undefined;
|
|
193
|
+
readonly id: string;
|
|
194
|
+
output: unknown;
|
|
195
|
+
metadata: Record<string, any>;
|
|
196
|
+
fields: Partial<Pick<SpanData, 'modelId' | 'inputTokens' | 'outputTokens' | 'costUsd'>>;
|
|
197
|
+
constructor(name: string, type: StepType, input?: unknown | undefined, metadata?: Record<string, any>);
|
|
198
|
+
setOutput(output: unknown): this;
|
|
199
|
+
/** Record what the step measured; anything not listed goes into metadata. */
|
|
200
|
+
set({ model, inputTokens, outputTokens, costUsd, ...metadata }: {
|
|
201
|
+
model?: string;
|
|
202
|
+
inputTokens?: number;
|
|
203
|
+
outputTokens?: number;
|
|
204
|
+
costUsd?: number;
|
|
205
|
+
[key: string]: any;
|
|
206
|
+
}): this;
|
|
207
|
+
}
|
|
208
|
+
export interface StepOptions {
|
|
209
|
+
type?: StepType;
|
|
210
|
+
input?: unknown;
|
|
211
|
+
metadata?: Record<string, any>;
|
|
212
|
+
client?: UncoilClient;
|
|
213
|
+
/** Start a new run with this id (used by traceAgent). */
|
|
214
|
+
runId?: string;
|
|
215
|
+
/** Send this step as the run's end (run_end or error), which marks the run completed or failed. */
|
|
216
|
+
root?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Record one step of the agent. Steps started inside `fn` become its children, so the trace shows which step
|
|
220
|
+
* called which. The step ends when `fn` settles; its return value is the output unless one was set.
|
|
221
|
+
*
|
|
222
|
+
* const docs = await span("search-docs", (step) => search(query), { type: "tool", input: query });
|
|
223
|
+
*/
|
|
224
|
+
export declare function span<T>(name: string, fn: (step: Step) => T | Promise<T>, options?: StepOptions): Promise<T>;
|
|
225
|
+
/** Wrap a function so each call is recorded as a step, with its arguments and result. */
|
|
226
|
+
export declare function observe<A extends any[], R>(fn: (...args: A) => R | Promise<R>, options?: StepOptions & {
|
|
227
|
+
name?: string;
|
|
228
|
+
captureInput?: boolean;
|
|
229
|
+
}): (...args: A) => Promise<R>;
|
|
230
|
+
/**
|
|
231
|
+
* Wrap an agent's entry point. Each call is one trace: a new run id, and a root step that every step recorded
|
|
232
|
+
* inside it hangs from. The root is sent as run_end (or error) when the call settles.
|
|
233
|
+
*/
|
|
234
|
+
export declare function traceAgent<T extends (...args: any[]) => Promise<any>>(func: T, config?: UncoilConfig & {
|
|
235
|
+
name?: string;
|
|
236
|
+
}): T;
|
|
237
|
+
/** Record a finished model call. It is attached to the step it was made in. */
|
|
238
|
+
export declare const llmCall: (data: Omit<SpanData, "spanType">) => Promise<void>;
|
|
239
|
+
/** Record a finished tool call. It is attached to the step it was made in. */
|
|
240
|
+
export declare const toolCall: (data: Omit<SpanData, "spanType">) => Promise<void>;
|
|
241
|
+
export declare const decision: (data: Omit<SpanData, "spanType">) => Promise<void>;
|
|
242
|
+
export { wrapOpenAI, wrapAnthropic, type IntegrationOptions } from "./integrations/providers";
|
|
243
|
+
export { UncoilLangGraphHandler } from "./integrations/langgraph";
|
|
244
|
+
export { uncoilMiddleware } from "./integrations/vercel-ai";
|
|
245
|
+
export { traceTools } from "./integrations/tools";
|
|
246
|
+
export { init, uninit } from "./integrations/auto";
|
|
247
|
+
export { runDoctor, formatReport, maskKey, type DoctorReport, type DoctorCheck, type DoctorOptions } from "./doctor";
|