neatlogs 1.0.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/LICENSE +21 -0
- package/README.md +571 -0
- package/dist/index.cjs +6209 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +531 -0
- package/dist/index.d.ts +531 -0
- package/dist/index.mjs +6156 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +134 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
import { Span as Span$1 } from '@opentelemetry/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Span kind for categorizing instrumented operations.
|
|
5
|
+
*/
|
|
6
|
+
type SpanKind = 'WORKFLOW' | 'AGENT' | 'CHAIN' | 'TOOL' | 'RETRIEVER' | 'EMBEDDING' | 'MCP_TOOL' | 'GUARDRAIL';
|
|
7
|
+
/**
|
|
8
|
+
* A mask function that can redact or transform span data before export.
|
|
9
|
+
* Return null to drop the span entirely.
|
|
10
|
+
*/
|
|
11
|
+
type MaskFunction = (spanData: Record<string, any>) => Record<string, any> | null;
|
|
12
|
+
/**
|
|
13
|
+
* A prompt message with role and content.
|
|
14
|
+
*/
|
|
15
|
+
interface PromptMessage {
|
|
16
|
+
role: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for initializing the Neatlogs SDK.
|
|
21
|
+
*/
|
|
22
|
+
interface InitOptions {
|
|
23
|
+
/** Neatlogs API key. Falls back to NEATLOGS_API_KEY env var. */
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/** Base URL for the Neatlogs API. Defaults to https://app.neatlogs.com */
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
/** Name of the workflow being traced. Defaults to process.argv[1]. */
|
|
28
|
+
workflowName?: string;
|
|
29
|
+
/** Explicit session ID for grouping traces. */
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
/** Auto-generate a session ID if none provided. Defaults to false. */
|
|
32
|
+
autoSession?: boolean;
|
|
33
|
+
/** User identifier for the session. */
|
|
34
|
+
userId?: string;
|
|
35
|
+
/** Tags to attach to all spans. Must be string array. */
|
|
36
|
+
tags?: string[];
|
|
37
|
+
/** Custom metadata to attach to all spans. */
|
|
38
|
+
metadata?: Record<string, any>;
|
|
39
|
+
/** Enable debug logging. Defaults to false. */
|
|
40
|
+
debug?: boolean;
|
|
41
|
+
/** Disable export to Neatlogs backend. Defaults to false. */
|
|
42
|
+
disableExport?: boolean;
|
|
43
|
+
/** Libraries to auto-instrument (e.g., ['openai', 'anthropic']). */
|
|
44
|
+
instrumentations?: string[];
|
|
45
|
+
/** Global mask function applied to all spans. */
|
|
46
|
+
mask?: MaskFunction;
|
|
47
|
+
/** Sampling rate (0.0 to 1.0). Defaults to 1.0. */
|
|
48
|
+
sampleRate?: number;
|
|
49
|
+
/** Whether to capture log records. Defaults to true. */
|
|
50
|
+
captureLogs?: boolean;
|
|
51
|
+
/** Whether to capture input/output content. Defaults to true. */
|
|
52
|
+
traceContent?: boolean;
|
|
53
|
+
/** PII detection settings. */
|
|
54
|
+
pii?: 'redact' | 'hash' | false;
|
|
55
|
+
/** SDK version override. */
|
|
56
|
+
version?: string;
|
|
57
|
+
/** Backend endpoint URL. Defaults to https://staging-cloud.neatlogs.com/api/data/v4/batch */
|
|
58
|
+
endpoint?: string;
|
|
59
|
+
/** Maximum spans per export batch. Defaults to 100. */
|
|
60
|
+
batchSize?: number;
|
|
61
|
+
/** Seconds between batch flushes. Defaults to 5. */
|
|
62
|
+
flushInterval?: number;
|
|
63
|
+
/** Override team-level PII redaction toggle. true = enable, false = disable. */
|
|
64
|
+
piiEnabled?: boolean;
|
|
65
|
+
/** Override which span types have server-side PII redaction applied. */
|
|
66
|
+
piiSpanTypes?: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Options for the span() function wrapper.
|
|
70
|
+
*/
|
|
71
|
+
interface SpanOptions {
|
|
72
|
+
/** The kind of span. Required. */
|
|
73
|
+
kind: SpanKind;
|
|
74
|
+
/** Custom name for the span. Defaults to the function name. */
|
|
75
|
+
name?: string;
|
|
76
|
+
/** Human-readable description of what this span does. */
|
|
77
|
+
description?: string;
|
|
78
|
+
/** Whether to capture function input. Defaults to true. */
|
|
79
|
+
captureInput?: boolean;
|
|
80
|
+
/** Whether to capture function output. Defaults to true. */
|
|
81
|
+
captureOutput?: boolean;
|
|
82
|
+
/** Per-span mask function. */
|
|
83
|
+
mask?: MaskFunction;
|
|
84
|
+
/** Mark this span as internal (not user-facing). */
|
|
85
|
+
internal?: boolean;
|
|
86
|
+
/** Agent role (for kind: AGENT). */
|
|
87
|
+
role?: string;
|
|
88
|
+
/** Agent goal (for kind: AGENT). */
|
|
89
|
+
goal?: string;
|
|
90
|
+
/** Tool name (for kind: TOOL or MCP_TOOL). */
|
|
91
|
+
toolName?: string;
|
|
92
|
+
/** Tool parameters schema (for kind: TOOL). */
|
|
93
|
+
parameters?: Record<string, any>;
|
|
94
|
+
/** JSON schema describing the tool interface (for kind: MCP_TOOL). */
|
|
95
|
+
toolJsonSchema?: Record<string, any>;
|
|
96
|
+
/** Embedding model name (for kind: EMBEDDING). */
|
|
97
|
+
model?: string;
|
|
98
|
+
/** Embedding dimension (for kind: EMBEDDING). */
|
|
99
|
+
dimension?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options for the trace() context wrapper.
|
|
103
|
+
*/
|
|
104
|
+
interface TraceOptions {
|
|
105
|
+
/** Name for the trace span. */
|
|
106
|
+
name: string;
|
|
107
|
+
/** Span kind. Defaults to 'CHAIN'. */
|
|
108
|
+
kind?: SpanKind;
|
|
109
|
+
/** Input data for this span. Auto-serialized to input.value. */
|
|
110
|
+
input?: any;
|
|
111
|
+
/** Prompt template to associate with this trace (string or PromptTemplate instance). */
|
|
112
|
+
promptTemplate?: string | {
|
|
113
|
+
template: string | PromptMessage[];
|
|
114
|
+
variables: string[];
|
|
115
|
+
};
|
|
116
|
+
/** Prompt variables used in this trace. */
|
|
117
|
+
promptVariables?: Record<string, any>;
|
|
118
|
+
/** User prompt template (string or UserPromptTemplate instance). */
|
|
119
|
+
userPromptTemplate?: string | {
|
|
120
|
+
template: string | PromptMessage[];
|
|
121
|
+
variables: string[];
|
|
122
|
+
};
|
|
123
|
+
/** User prompt variables used in this trace. */
|
|
124
|
+
userPromptVariables?: Record<string, any>;
|
|
125
|
+
/** Prompt version identifier. */
|
|
126
|
+
version?: string;
|
|
127
|
+
/** Per-trace mask function. */
|
|
128
|
+
mask?: MaskFunction;
|
|
129
|
+
/** Custom attributes to set on the span. */
|
|
130
|
+
attributes?: Record<string, any>;
|
|
131
|
+
/** Allow extra attributes via index signature. */
|
|
132
|
+
[key: string]: any;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Cached prompt data from the Neatlogs API.
|
|
136
|
+
*/
|
|
137
|
+
interface CachedPrompt {
|
|
138
|
+
id: string;
|
|
139
|
+
name: string;
|
|
140
|
+
version: number;
|
|
141
|
+
content: string | null;
|
|
142
|
+
messages: PromptMessage[] | null;
|
|
143
|
+
config: Record<string, any>;
|
|
144
|
+
labels: string[];
|
|
145
|
+
updatedAt: string;
|
|
146
|
+
type: 'text' | 'chat';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Context wrapper for manual span creation.
|
|
151
|
+
*
|
|
152
|
+
* Provides the `trace()` function — the TypeScript equivalent of the Python
|
|
153
|
+
* `trace()` context manager. Creates an OTel span, sets prompt template/variable
|
|
154
|
+
* context, and executes the user callback within the span.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* await trace({ name: 'my-trace' }, async (span) => {
|
|
159
|
+
* // user code runs here with the span active
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get a copy of the current session configuration.
|
|
166
|
+
*/
|
|
167
|
+
declare function getSessionConfig(): Record<string, any>;
|
|
168
|
+
/**
|
|
169
|
+
* Async callback wrapper for manual span creation with prompt tracking.
|
|
170
|
+
*
|
|
171
|
+
* Creates an OTel span, optionally sets prompt template/variable context,
|
|
172
|
+
* and executes the provided callback within the span.
|
|
173
|
+
*
|
|
174
|
+
* **Session-Aware Trace Creation:**
|
|
175
|
+
* - If `session_id` is set in init() AND no active parent span exists,
|
|
176
|
+
* this creates a NEW root trace (for multi-turn conversations).
|
|
177
|
+
* - Otherwise, creates a normal child span within the existing trace.
|
|
178
|
+
*
|
|
179
|
+
* @param options - Trace configuration options
|
|
180
|
+
* @param fn - Callback that receives the active span
|
|
181
|
+
* @returns The return value of the callback
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Basic usage
|
|
186
|
+
* await trace({ name: 'my-pipeline' }, async (span) => {
|
|
187
|
+
* await step1();
|
|
188
|
+
* await step2();
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* // With prompt template
|
|
192
|
+
* const template = new PromptTemplate('Hello {{name}}');
|
|
193
|
+
* await trace({ name: 'prompt', promptTemplate: template }, async (span) => {
|
|
194
|
+
* const rendered = template.compile({ name: 'world' });
|
|
195
|
+
* // ...
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function trace<T>(options: TraceOptions, fn: (span: Span$1) => T | Promise<T>): Promise<T>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Neatlogs SDK initialisation, flush, and shutdown.
|
|
203
|
+
*
|
|
204
|
+
* Port of Python neatlogs/init.py to TypeScript.
|
|
205
|
+
*
|
|
206
|
+
* `init()` sets up the OTel TracerProvider, MeterProvider, LoggerProvider,
|
|
207
|
+
* span processors, exporters, and instrumentation.
|
|
208
|
+
* `flush()` and `shutdown()` handle graceful cleanup.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Initialise the Neatlogs SDK.
|
|
213
|
+
*
|
|
214
|
+
* Sets up OTel TracerProvider, MeterProvider, LoggerProvider, span processors,
|
|
215
|
+
* exporters and auto-instrumentation. Returns a Promise because library
|
|
216
|
+
* instrumentation uses dynamic `import()`.
|
|
217
|
+
*/
|
|
218
|
+
declare function init(options?: InitOptions): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Flush all pending spans, metrics, and log records.
|
|
221
|
+
*
|
|
222
|
+
* @returns true if all providers flushed successfully
|
|
223
|
+
*/
|
|
224
|
+
declare function flush(): Promise<boolean>;
|
|
225
|
+
/**
|
|
226
|
+
* Shutdown the SDK and flush all pending spans, metrics, and log records.
|
|
227
|
+
*
|
|
228
|
+
* Resets all module-level state so `init()` can be called again.
|
|
229
|
+
*
|
|
230
|
+
* @returns true if all providers shut down successfully
|
|
231
|
+
*/
|
|
232
|
+
declare function shutdown(): Promise<boolean>;
|
|
233
|
+
/**
|
|
234
|
+
* Return true if neatlogs was initialised with `debug: true`.
|
|
235
|
+
*/
|
|
236
|
+
declare function isDebugEnabled(): boolean;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* High-level span() function wrapper and Span() class-method decorator.
|
|
240
|
+
*
|
|
241
|
+
* Primary public API for instrumenting user code.
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Wrap a function with OpenTelemetry span instrumentation.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const myWorkflow = span({ kind: 'WORKFLOW' }, async (query: string) => {
|
|
250
|
+
* return await process(query);
|
|
251
|
+
* });
|
|
252
|
+
* await myWorkflow('What is TypeScript?');
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function span<TArgs extends any[], TReturn>(options: SpanOptions, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn extends Promise<any> ? TReturn : Promise<Awaited<TReturn>>;
|
|
256
|
+
/**
|
|
257
|
+
* TC39 Stage 3 class-method decorator variant.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* class MyAgent {
|
|
262
|
+
* @Span({ kind: 'AGENT', role: 'researcher' })
|
|
263
|
+
* async run(query: string) { ... }
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function Span(options: SpanOptions): <T extends (...args: any[]) => any>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Capture a timestamped log step within the current trace.
|
|
271
|
+
*
|
|
272
|
+
* @param msgTemplate - Message template with {key} placeholders
|
|
273
|
+
* @param options - Optional key-value pairs for template rendering and attributes
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* log('Processing query: {query}', { query: 'What is TypeScript?', level: 'info' });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function log(msgTemplate: string, options?: Record<string, any>): void;
|
|
281
|
+
|
|
282
|
+
interface ContextSetter {
|
|
283
|
+
set(template: string, variables: Record<string, any>): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Base class for prompt templates with `{{variable}}` placeholders.
|
|
287
|
+
*
|
|
288
|
+
* Extracts variables, compiles templates, and renders strings.
|
|
289
|
+
* Subclasses only need to specify the context class and display name.
|
|
290
|
+
*/
|
|
291
|
+
declare abstract class BasePromptTemplate {
|
|
292
|
+
protected readonly _template: string | PromptMessage[];
|
|
293
|
+
protected readonly _variables: string[];
|
|
294
|
+
/**
|
|
295
|
+
* @param template - Either a string with `{{variable}}` placeholders or
|
|
296
|
+
* an array of `PromptMessage` objects whose `content` fields contain placeholders.
|
|
297
|
+
*/
|
|
298
|
+
constructor(template: string | PromptMessage[]);
|
|
299
|
+
/** List of unique variable names found in this template. */
|
|
300
|
+
get variables(): string[];
|
|
301
|
+
/** The raw template (string or message array). */
|
|
302
|
+
get template(): string | PromptMessage[];
|
|
303
|
+
/** The context class to store template/variables for automatic tracing. */
|
|
304
|
+
protected abstract get _contextSetter(): ContextSetter;
|
|
305
|
+
/** Display name for toString(). */
|
|
306
|
+
protected abstract get _displayName(): string;
|
|
307
|
+
/**
|
|
308
|
+
* Compile the prompt template with the given variables.
|
|
309
|
+
*
|
|
310
|
+
* @param variables - Key/value pairs to substitute for `{{key}}` placeholders.
|
|
311
|
+
* @returns The rendered string or rendered message array.
|
|
312
|
+
* @throws {Error} If any required variables are missing.
|
|
313
|
+
*/
|
|
314
|
+
compile(variables?: Record<string, any>): string | PromptMessage[];
|
|
315
|
+
/**
|
|
316
|
+
* Replace `{{key}}` placeholders in a string with the corresponding values.
|
|
317
|
+
*/
|
|
318
|
+
_renderString(text: string, variables: Record<string, any>): string;
|
|
319
|
+
toString(): string;
|
|
320
|
+
private _extractVariables;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Template for the system/AI instruction prompt with `{{variable}}` placeholders.
|
|
324
|
+
*/
|
|
325
|
+
declare class PromptTemplate extends BasePromptTemplate {
|
|
326
|
+
protected get _contextSetter(): ContextSetter;
|
|
327
|
+
protected get _displayName(): string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Template for the user/human turn prompt with `{{variable}}` placeholders.
|
|
331
|
+
*
|
|
332
|
+
* Identical to {@link PromptTemplate} but stores context in {@link UserPromptContext}.
|
|
333
|
+
*/
|
|
334
|
+
declare class UserPromptTemplate extends BasePromptTemplate {
|
|
335
|
+
protected get _contextSetter(): ContextSetter;
|
|
336
|
+
protected get _displayName(): string;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Base exception for prompt client failures. */
|
|
340
|
+
declare class PromptClientError extends Error {
|
|
341
|
+
constructor(message: string);
|
|
342
|
+
}
|
|
343
|
+
/** Raised when the backend returns an API error. */
|
|
344
|
+
declare class PromptApiError extends PromptClientError {
|
|
345
|
+
constructor(message: string);
|
|
346
|
+
}
|
|
347
|
+
/** Raised when a prompt/label/version is not found. */
|
|
348
|
+
declare class PromptNotFoundError extends PromptClientError {
|
|
349
|
+
constructor(message: string);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Compiled prompt handle returned by {@link PromptClient.getPrompt}.
|
|
353
|
+
*/
|
|
354
|
+
declare class PromptHandle {
|
|
355
|
+
private readonly _prompt;
|
|
356
|
+
constructor(prompt: CachedPrompt);
|
|
357
|
+
get id(): string;
|
|
358
|
+
get name(): string;
|
|
359
|
+
get version(): number;
|
|
360
|
+
get content(): string | null;
|
|
361
|
+
get messages(): PromptMessage[] | null;
|
|
362
|
+
get config(): Record<string, any>;
|
|
363
|
+
get labels(): string[];
|
|
364
|
+
get updatedAt(): string;
|
|
365
|
+
get type(): string;
|
|
366
|
+
/**
|
|
367
|
+
* Compile string content with `{{variable}}` replacement.
|
|
368
|
+
*
|
|
369
|
+
* If the prompt has `content`, renders it directly.
|
|
370
|
+
* If it only has `messages`, renders and joins all message contents.
|
|
371
|
+
*/
|
|
372
|
+
compile(variables?: Record<string, any>): string;
|
|
373
|
+
/**
|
|
374
|
+
* Compile message list with `{{variable}}` replacement.
|
|
375
|
+
*
|
|
376
|
+
* If no messages exist, returns a single synthetic system message from content.
|
|
377
|
+
*/
|
|
378
|
+
compileMessages(variables?: Record<string, any>): PromptMessage[];
|
|
379
|
+
}
|
|
380
|
+
interface PromptClientOptions {
|
|
381
|
+
baseUrl: string;
|
|
382
|
+
apiKey: string;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Prompt client for Neatlogs managed prompts.
|
|
386
|
+
*
|
|
387
|
+
* Fetches prompts on-demand from the backend.
|
|
388
|
+
* Uses an in-memory cache to avoid redundant HTTP calls.
|
|
389
|
+
*/
|
|
390
|
+
declare class PromptClient {
|
|
391
|
+
private readonly baseUrl;
|
|
392
|
+
private readonly apiKey;
|
|
393
|
+
private readonly _cache;
|
|
394
|
+
constructor(options: PromptClientOptions);
|
|
395
|
+
/**
|
|
396
|
+
* Get a prompt by name, optionally pinned to a version or label.
|
|
397
|
+
* Results are cached in memory by cache key.
|
|
398
|
+
*/
|
|
399
|
+
getPrompt(name: string, options?: {
|
|
400
|
+
version?: number;
|
|
401
|
+
label?: string;
|
|
402
|
+
}): Promise<PromptHandle>;
|
|
403
|
+
/**
|
|
404
|
+
* Always fetch from the API (bypasses cache).
|
|
405
|
+
*/
|
|
406
|
+
fetchPrompt(name: string, options?: {
|
|
407
|
+
version?: number;
|
|
408
|
+
label?: string;
|
|
409
|
+
}): Promise<PromptHandle>;
|
|
410
|
+
/**
|
|
411
|
+
* List all prompts.
|
|
412
|
+
*/
|
|
413
|
+
listPrompts(): Promise<PromptHandle[]>;
|
|
414
|
+
/**
|
|
415
|
+
* Create a new prompt.
|
|
416
|
+
*/
|
|
417
|
+
createPrompt(data: {
|
|
418
|
+
name: string;
|
|
419
|
+
content?: string;
|
|
420
|
+
messages?: PromptMessage[];
|
|
421
|
+
config?: Record<string, any>;
|
|
422
|
+
labels?: string[];
|
|
423
|
+
}): Promise<PromptHandle>;
|
|
424
|
+
/**
|
|
425
|
+
* Update an existing prompt.
|
|
426
|
+
*/
|
|
427
|
+
updatePrompt(name: string, data: {
|
|
428
|
+
content?: string;
|
|
429
|
+
messages?: PromptMessage[];
|
|
430
|
+
config?: Record<string, any>;
|
|
431
|
+
labels?: string[];
|
|
432
|
+
}): Promise<PromptHandle>;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a prompt by name.
|
|
435
|
+
*/
|
|
436
|
+
deletePrompt(name: string): Promise<void>;
|
|
437
|
+
/**
|
|
438
|
+
* Remove a tag from a prompt.
|
|
439
|
+
*/
|
|
440
|
+
removeTag(name: string, tag: string): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Save the current prompt content as a new version, optionally with a label.
|
|
443
|
+
*/
|
|
444
|
+
saveAsVersion(name: string, options?: {
|
|
445
|
+
label?: string;
|
|
446
|
+
}): Promise<PromptHandle>;
|
|
447
|
+
/**
|
|
448
|
+
* Internal fetch wrapper with auth headers and OTel suppression.
|
|
449
|
+
*/
|
|
450
|
+
_request(path: string, options?: RequestInit): Promise<any>;
|
|
451
|
+
}
|
|
452
|
+
declare function getPrompt(name: string, options?: {
|
|
453
|
+
version?: number;
|
|
454
|
+
label?: string;
|
|
455
|
+
}): Promise<PromptHandle>;
|
|
456
|
+
declare function fetchPrompt(name: string, options?: {
|
|
457
|
+
version?: number;
|
|
458
|
+
label?: string;
|
|
459
|
+
}): Promise<PromptHandle>;
|
|
460
|
+
declare function listPrompts(): Promise<PromptHandle[]>;
|
|
461
|
+
declare function createPrompt(data: {
|
|
462
|
+
name: string;
|
|
463
|
+
content?: string;
|
|
464
|
+
messages?: PromptMessage[];
|
|
465
|
+
config?: Record<string, any>;
|
|
466
|
+
labels?: string[];
|
|
467
|
+
}): Promise<PromptHandle>;
|
|
468
|
+
declare function updatePrompt(name: string, data: {
|
|
469
|
+
content?: string;
|
|
470
|
+
messages?: PromptMessage[];
|
|
471
|
+
config?: Record<string, any>;
|
|
472
|
+
labels?: string[];
|
|
473
|
+
}): Promise<PromptHandle>;
|
|
474
|
+
declare function saveAsVersion(name: string, options?: {
|
|
475
|
+
label?: string;
|
|
476
|
+
}): Promise<PromptHandle>;
|
|
477
|
+
declare function deletePrompt(name: string): Promise<void>;
|
|
478
|
+
declare function removeTag(name: string, tag: string): Promise<void>;
|
|
479
|
+
|
|
480
|
+
declare function getMastraObservability(): Promise<any>;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* LLM template binding for frameworks that manage LLM calls internally (e.g. CrewAI).
|
|
484
|
+
*
|
|
485
|
+
* Usage:
|
|
486
|
+
* const boundLlm = bindTemplates(llm, systemTpl, userTpl, { content: '...' });
|
|
487
|
+
* const agent = new Agent({ llm: boundLlm, ... });
|
|
488
|
+
*
|
|
489
|
+
* When the LLM's invoke/call method runs, this wrapper fires first:
|
|
490
|
+
* 1. Sets prompt template + user prompt template in OTel context
|
|
491
|
+
* 2. Calls the instrumented class-level invoke (creates the LLM span)
|
|
492
|
+
* 3. span_processor reads context -> templates land on the LLM span
|
|
493
|
+
*/
|
|
494
|
+
/**
|
|
495
|
+
* Return a copy of `llm` whose invoke()/call() injects prompt template context
|
|
496
|
+
* before the instrumented LLM span is created.
|
|
497
|
+
*
|
|
498
|
+
* @param llm - Any LangChain-compatible chat model or crewai.LLM
|
|
499
|
+
* @param systemTpl - PromptTemplate for the agent backstory / system role
|
|
500
|
+
* @param userTpl - Optional UserPromptTemplate for the task description
|
|
501
|
+
* @param compiledVars - Variable values to pass to userTpl.compile()
|
|
502
|
+
* @returns A new LLM instance with template context pre-wired
|
|
503
|
+
*/
|
|
504
|
+
declare function bindTemplates(llm: any, systemTpl: any, userTpl?: any, compiledVars?: Record<string, any>): any;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Registry for CrewAI task template bindings.
|
|
508
|
+
*
|
|
509
|
+
* Call registerCrewaiTask(task, userTpl, vars) in your task setup after creating
|
|
510
|
+
* each Task. The span processor reads and clears the entry when the corresponding
|
|
511
|
+
* AGENT span ends, stamping the template onto that span.
|
|
512
|
+
*/
|
|
513
|
+
/**
|
|
514
|
+
* Register a user prompt template for a CrewAI task.
|
|
515
|
+
*
|
|
516
|
+
* @param task - A CrewAI Task instance (must have an .id property)
|
|
517
|
+
* @param userTpl - A neatlogs UserPromptTemplate describing the task prompt
|
|
518
|
+
* @param vars - Variable values passed to userTpl at task-creation time
|
|
519
|
+
*/
|
|
520
|
+
declare function registerCrewaiTask(task: {
|
|
521
|
+
id: string | number;
|
|
522
|
+
}, userTpl: {
|
|
523
|
+
template: string | any;
|
|
524
|
+
}, vars?: Record<string, any>): void;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* SDK version. Updated during release process.
|
|
528
|
+
*/
|
|
529
|
+
declare const __version__ = "1.0.0";
|
|
530
|
+
|
|
531
|
+
export { type CachedPrompt, type InitOptions, type MaskFunction, PromptApiError, PromptClient, PromptClientError, PromptHandle, type PromptMessage, PromptNotFoundError, PromptTemplate, Span, type SpanKind, type SpanOptions, type TraceOptions, UserPromptTemplate, __version__, bindTemplates, createPrompt, deletePrompt, fetchPrompt, flush, getMastraObservability, getPrompt, getSessionConfig, init, isDebugEnabled, listPrompts, log, registerCrewaiTask, removeTag, saveAsVersion, shutdown, span, trace, updatePrompt };
|