@goharvest/simforge 0.4.7 → 0.5.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/dist/client.d.ts +152 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +342 -219
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +857 -62
- package/dist/client.test.js.map +1 -1
- package/dist/http.d.ts +73 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +192 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/serialize.d.ts +55 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +68 -0
- package/dist/serialize.js.map +1 -0
- package/dist/serialize.test.d.ts +8 -0
- package/dist/serialize.test.d.ts.map +1 -0
- package/dist/serialize.test.js +226 -0
- package/dist/serialize.test.js.map +1 -0
- package/dist/tracing.d.ts +6 -5
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +32 -126
- package/dist/tracing.js.map +1 -1
- package/dist/tracing.test.js +1 -1
- package/dist/tracing.test.js.map +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +4 -2
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,28 @@
|
|
|
2
2
|
* Simforge client for provider-based API calls.
|
|
3
3
|
*/
|
|
4
4
|
import { type AllowedEnvVars } from "./baml.js";
|
|
5
|
+
import { SimforgeError } from "./http.js";
|
|
5
6
|
import { SimforgeOpenAITracingProcessor } from "./tracing.js";
|
|
7
|
+
/**
|
|
8
|
+
* A handle to the current active span, allowing runtime metadata to be set.
|
|
9
|
+
*/
|
|
10
|
+
export interface CurrentSpan {
|
|
11
|
+
/**
|
|
12
|
+
* Set custom metadata on this span. Merges with any existing metadata
|
|
13
|
+
* (both definition-time and previous runtime calls), with later values
|
|
14
|
+
* taking precedence on conflict.
|
|
15
|
+
*/
|
|
16
|
+
setMetadata(metadata: Record<string, unknown>): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get a handle to the current active span.
|
|
20
|
+
*
|
|
21
|
+
* Call this from inside a traced function (wrapped with `withSpan`) to get
|
|
22
|
+
* a span handle that allows setting metadata at runtime.
|
|
23
|
+
*
|
|
24
|
+
* Returns `null` if called outside of a span context.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCurrentSpan(): CurrentSpan | null;
|
|
6
27
|
export interface SimforgeConfig {
|
|
7
28
|
/** The API key for Simforge API authentication */
|
|
8
29
|
apiKey: string;
|
|
@@ -12,19 +33,38 @@ export interface SimforgeConfig {
|
|
|
12
33
|
timeout?: number;
|
|
13
34
|
/** Environment variables for LLM provider API keys (only OPENAI_API_KEY is supported) */
|
|
14
35
|
envVars?: AllowedEnvVars;
|
|
15
|
-
/** Whether to
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export interface CallResponse<T = unknown> {
|
|
19
|
-
result?: T;
|
|
20
|
-
error?: string;
|
|
21
|
-
url?: string;
|
|
22
|
-
traceId?: string;
|
|
36
|
+
/** Whether the client is enabled. Defaults to true. When false, withSpan returns the original function unwrapped. */
|
|
37
|
+
enabled?: boolean;
|
|
23
38
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Span types matching the backend enum.
|
|
41
|
+
* - llm: LLM API calls
|
|
42
|
+
* - agent: Autonomous orchestrators
|
|
43
|
+
* - function: Tool implementations
|
|
44
|
+
* - guardrail: Safety/validation checks
|
|
45
|
+
* - handoff: Agent-to-agent transfers
|
|
46
|
+
* - custom: Application-specific tracing (default)
|
|
47
|
+
*/
|
|
48
|
+
export type SpanType = "llm" | "agent" | "function" | "guardrail" | "handoff" | "custom";
|
|
49
|
+
/**
|
|
50
|
+
* Options for configuring span behavior.
|
|
51
|
+
*/
|
|
52
|
+
export interface SpanOptions {
|
|
53
|
+
/**
|
|
54
|
+
* The name of the span. Defaults to the function name if available,
|
|
55
|
+
* otherwise falls back to the trace function key.
|
|
56
|
+
*/
|
|
57
|
+
name?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The type of span. Defaults to "custom" if not specified.
|
|
60
|
+
*/
|
|
61
|
+
type?: SpanType;
|
|
62
|
+
/**
|
|
63
|
+
* Custom metadata to attach to the span. Stored as-is in span_data.
|
|
64
|
+
*/
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
27
66
|
}
|
|
67
|
+
export { SimforgeError };
|
|
28
68
|
/**
|
|
29
69
|
* Client for making provider-based API calls via BAML.
|
|
30
70
|
*/
|
|
@@ -33,7 +73,8 @@ export declare class Simforge {
|
|
|
33
73
|
private readonly serviceUrl;
|
|
34
74
|
private readonly timeout;
|
|
35
75
|
private readonly envVars;
|
|
36
|
-
private readonly
|
|
76
|
+
private readonly enabled;
|
|
77
|
+
private readonly httpClient;
|
|
37
78
|
/**
|
|
38
79
|
* Initialize the Simforge client.
|
|
39
80
|
*
|
|
@@ -57,11 +98,6 @@ export declare class Simforge {
|
|
|
57
98
|
* @throws {SimforgeError} If service_url is not set, or if an error occurs
|
|
58
99
|
*/
|
|
59
100
|
call<T = unknown>(methodName: string, inputs?: Record<string, unknown>): Promise<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Create a trace from a local execution result.
|
|
62
|
-
* Internal method to record traces when executing BAML locally.
|
|
63
|
-
*/
|
|
64
|
-
private createTrace;
|
|
65
101
|
/**
|
|
66
102
|
* Get a tracing processor for OpenAI Agents SDK integration.
|
|
67
103
|
*
|
|
@@ -80,5 +116,104 @@ export declare class Simforge {
|
|
|
80
116
|
* @returns A SimforgeOpenAITracingProcessor instance configured for this client
|
|
81
117
|
*/
|
|
82
118
|
getOpenAiTracingProcessor(): SimforgeOpenAITracingProcessor;
|
|
119
|
+
/**
|
|
120
|
+
* Wrap a function to automatically create a span for its inputs and outputs.
|
|
121
|
+
*
|
|
122
|
+
* The wrapped function behaves identically to the original, but sends
|
|
123
|
+
* span data to Simforge in the background after each call.
|
|
124
|
+
*
|
|
125
|
+
* Example usage:
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const client = new Simforge({ apiKey: 'your-api-key' });
|
|
128
|
+
*
|
|
129
|
+
* async function processOrder(orderId: string, items: string[]): Promise<{ total: number }> {
|
|
130
|
+
* // ... process order
|
|
131
|
+
* return { total: 100 };
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* // Basic usage (defaults to "custom" span type)
|
|
135
|
+
* const tracedProcessOrder = client.withSpan('order-processing', processOrder);
|
|
136
|
+
*
|
|
137
|
+
* // With explicit span type
|
|
138
|
+
* const tracedProcessOrder = client.withSpan('order-processing', { type: 'function' }, processOrder);
|
|
139
|
+
*
|
|
140
|
+
* // Call the wrapped function normally
|
|
141
|
+
* const result = await tracedProcessOrder('order-123', ['item-1', 'item-2']);
|
|
142
|
+
* // Span is automatically sent to Simforge
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @param traceFunctionKey - A string identifier for grouping spans (e.g., 'order-processing', 'user-auth')
|
|
146
|
+
* @param optionsOrFn - Either SpanOptions or the function to wrap
|
|
147
|
+
* @param maybeFn - The function to wrap if options were provided
|
|
148
|
+
* @returns A wrapped function with the same signature that creates spans for inputs and outputs
|
|
149
|
+
*/
|
|
150
|
+
withSpan<TArgs extends unknown[], TReturn>(traceFunctionKey: string, optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
|
|
151
|
+
/**
|
|
152
|
+
* Get a function wrapper for a specific trace function key.
|
|
153
|
+
*
|
|
154
|
+
* This provides a fluent API alternative to calling withSpan directly,
|
|
155
|
+
* allowing you to bind the traceFunctionKey once and wrap multiple functions.
|
|
156
|
+
*
|
|
157
|
+
* Example usage:
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const client = new Simforge({ apiKey: 'your-api-key' });
|
|
160
|
+
*
|
|
161
|
+
* const orderFunc = client.getFunction('order-processing');
|
|
162
|
+
* const tracedProcessOrder = orderFunc.withSpan(processOrder);
|
|
163
|
+
* const tracedValidateOrder = orderFunc.withSpan(validateOrder);
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param traceFunctionKey - A string identifier for grouping spans
|
|
167
|
+
* @returns A SimforgeFunction instance for wrapping functions
|
|
168
|
+
*/
|
|
169
|
+
getFunction(traceFunctionKey: string): SimforgeFunction;
|
|
170
|
+
/**
|
|
171
|
+
* Send a wrapper span from function execution.
|
|
172
|
+
* Internal method to record spans when using withSpan.
|
|
173
|
+
* Fire-and-forget - sends to externalSpans endpoint via httpClient.
|
|
174
|
+
*/
|
|
175
|
+
private sendWrapperSpan;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Represents a Simforge function that can wrap user functions for tracing.
|
|
179
|
+
*
|
|
180
|
+
* This provides a fluent API for binding a traceFunctionKey once and
|
|
181
|
+
* then wrapping multiple functions with that key.
|
|
182
|
+
*
|
|
183
|
+
* Example usage:
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const client = new Simforge({ apiKey: 'your-api-key' });
|
|
186
|
+
*
|
|
187
|
+
* const orderFunc = client.getFunction('order-processing');
|
|
188
|
+
* const tracedProcessOrder = orderFunc.withSpan(processOrder);
|
|
189
|
+
* const tracedValidateOrder = orderFunc.withSpan(validateOrder);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare class SimforgeFunction {
|
|
193
|
+
private readonly client;
|
|
194
|
+
private readonly traceFunctionKey;
|
|
195
|
+
constructor(client: Simforge, traceFunctionKey: string);
|
|
196
|
+
/**
|
|
197
|
+
* Wrap a function to automatically create a span for its inputs and outputs.
|
|
198
|
+
*
|
|
199
|
+
* The wrapped function behaves identically to the original, but sends
|
|
200
|
+
* span data to Simforge in the background after each call.
|
|
201
|
+
*
|
|
202
|
+
* Example usage:
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const orderFunc = client.getFunction('order-processing');
|
|
205
|
+
*
|
|
206
|
+
* // Basic usage (defaults to "custom" span type)
|
|
207
|
+
* const tracedProcessOrder = orderFunc.withSpan(processOrder);
|
|
208
|
+
*
|
|
209
|
+
* // With explicit span type
|
|
210
|
+
* const tracedProcessOrder = orderFunc.withSpan({ type: 'function' }, processOrder);
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @param optionsOrFn - Either SpanOptions or the function to wrap
|
|
214
|
+
* @param maybeFn - The function to wrap if options were provided
|
|
215
|
+
* @returns A wrapped function with the same signature that creates spans
|
|
216
|
+
*/
|
|
217
|
+
withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
|
|
83
218
|
}
|
|
84
219
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAc,aAAa,EAAE,MAAM,WAAW,CAAA;AAErD,OAAO,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAA;AAoF7D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CACrD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAcnD;AAED,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,UAAU,CA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