@goharvest/simforge 0.4.7 → 0.5.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/dist/client.d.ts CHANGED
@@ -2,6 +2,7 @@
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";
6
7
  export interface SimforgeConfig {
7
8
  /** The API key for Simforge API authentication */
@@ -21,10 +22,31 @@ export interface CallResponse<T = unknown> {
21
22
  url?: string;
22
23
  traceId?: string;
23
24
  }
24
- export declare class SimforgeError extends Error {
25
- readonly url?: string | undefined;
26
- constructor(message: string, url?: string | undefined);
25
+ /**
26
+ * Span types matching the backend enum.
27
+ * - llm: LLM API calls
28
+ * - agent: Autonomous orchestrators
29
+ * - function: Tool implementations
30
+ * - guardrail: Safety/validation checks
31
+ * - handoff: Agent-to-agent transfers
32
+ * - custom: Application-specific tracing (default)
33
+ */
34
+ export type SpanType = "llm" | "agent" | "function" | "guardrail" | "handoff" | "custom";
35
+ /**
36
+ * Options for configuring span behavior.
37
+ */
38
+ export interface SpanOptions {
39
+ /**
40
+ * The name of the span. Defaults to the function name if available,
41
+ * otherwise falls back to the trace function key.
42
+ */
43
+ name?: string;
44
+ /**
45
+ * The type of span. Defaults to "custom" if not specified.
46
+ */
47
+ type?: SpanType;
27
48
  }
49
+ export { SimforgeError };
28
50
  /**
29
51
  * Client for making provider-based API calls via BAML.
30
52
  */
@@ -34,6 +56,7 @@ export declare class Simforge {
34
56
  private readonly timeout;
35
57
  private readonly envVars;
36
58
  private readonly executeLocally;
59
+ private readonly httpClient;
37
60
  /**
38
61
  * Initialize the Simforge client.
39
62
  *
@@ -57,11 +80,6 @@ export declare class Simforge {
57
80
  * @throws {SimforgeError} If service_url is not set, or if an error occurs
58
81
  */
59
82
  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
83
  /**
66
84
  * Get a tracing processor for OpenAI Agents SDK integration.
67
85
  *
@@ -80,5 +98,104 @@ export declare class Simforge {
80
98
  * @returns A SimforgeOpenAITracingProcessor instance configured for this client
81
99
  */
82
100
  getOpenAiTracingProcessor(): SimforgeOpenAITracingProcessor;
101
+ /**
102
+ * Wrap a function to automatically create a span for its inputs and outputs.
103
+ *
104
+ * The wrapped function behaves identically to the original, but sends
105
+ * span data to Simforge in the background after each call.
106
+ *
107
+ * Example usage:
108
+ * ```typescript
109
+ * const client = new Simforge({ apiKey: 'your-api-key' });
110
+ *
111
+ * async function processOrder(orderId: string, items: string[]): Promise<{ total: number }> {
112
+ * // ... process order
113
+ * return { total: 100 };
114
+ * }
115
+ *
116
+ * // Basic usage (defaults to "custom" span type)
117
+ * const tracedProcessOrder = client.withSpan('order-processing', processOrder);
118
+ *
119
+ * // With explicit span type
120
+ * const tracedProcessOrder = client.withSpan('order-processing', { type: 'function' }, processOrder);
121
+ *
122
+ * // Call the wrapped function normally
123
+ * const result = await tracedProcessOrder('order-123', ['item-1', 'item-2']);
124
+ * // Span is automatically sent to Simforge
125
+ * ```
126
+ *
127
+ * @param traceFunctionKey - A string identifier for grouping spans (e.g., 'order-processing', 'user-auth')
128
+ * @param optionsOrFn - Either SpanOptions or the function to wrap
129
+ * @param maybeFn - The function to wrap if options were provided
130
+ * @returns A wrapped function with the same signature that creates spans for inputs and outputs
131
+ */
132
+ withSpan<TArgs extends unknown[], TReturn>(traceFunctionKey: string, optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
133
+ /**
134
+ * Get a function wrapper for a specific trace function key.
135
+ *
136
+ * This provides a fluent API alternative to calling withSpan directly,
137
+ * allowing you to bind the traceFunctionKey once and wrap multiple functions.
138
+ *
139
+ * Example usage:
140
+ * ```typescript
141
+ * const client = new Simforge({ apiKey: 'your-api-key' });
142
+ *
143
+ * const orderFunc = client.getFunction('order-processing');
144
+ * const tracedProcessOrder = orderFunc.withSpan(processOrder);
145
+ * const tracedValidateOrder = orderFunc.withSpan(validateOrder);
146
+ * ```
147
+ *
148
+ * @param traceFunctionKey - A string identifier for grouping spans
149
+ * @returns A SimforgeFunction instance for wrapping functions
150
+ */
151
+ getFunction(traceFunctionKey: string): SimforgeFunction;
152
+ /**
153
+ * Send a wrapper span from function execution.
154
+ * Internal method to record spans when using withSpan.
155
+ * Fire-and-forget - sends to externalSpans endpoint via httpClient.
156
+ */
157
+ private sendWrapperSpan;
158
+ }
159
+ /**
160
+ * Represents a Simforge function that can wrap user functions for tracing.
161
+ *
162
+ * This provides a fluent API for binding a traceFunctionKey once and
163
+ * then wrapping multiple functions with that key.
164
+ *
165
+ * Example usage:
166
+ * ```typescript
167
+ * const client = new Simforge({ apiKey: 'your-api-key' });
168
+ *
169
+ * const orderFunc = client.getFunction('order-processing');
170
+ * const tracedProcessOrder = orderFunc.withSpan(processOrder);
171
+ * const tracedValidateOrder = orderFunc.withSpan(validateOrder);
172
+ * ```
173
+ */
174
+ export declare class SimforgeFunction {
175
+ private readonly client;
176
+ private readonly traceFunctionKey;
177
+ constructor(client: Simforge, traceFunctionKey: string);
178
+ /**
179
+ * Wrap a function to automatically create a span for its inputs and outputs.
180
+ *
181
+ * The wrapped function behaves identically to the original, but sends
182
+ * span data to Simforge in the background after each call.
183
+ *
184
+ * Example usage:
185
+ * ```typescript
186
+ * const orderFunc = client.getFunction('order-processing');
187
+ *
188
+ * // Basic usage (defaults to "custom" span type)
189
+ * const tracedProcessOrder = orderFunc.withSpan(processOrder);
190
+ *
191
+ * // With explicit span type
192
+ * const tracedProcessOrder = orderFunc.withSpan({ type: 'function' }, processOrder);
193
+ * ```
194
+ *
195
+ * @param optionsOrFn - Either SpanOptions or the function to wrap
196
+ * @param maybeFn - The function to wrap if options were provided
197
+ * @returns A wrapped function with the same signature that creates spans
198
+ */
199
+ withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
83
200
  }
84
201
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAA;AAoD7D,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yFAAyF;IACzF,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,oEAAoE;IACpE,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AA8BD,qBAAa,aAAc,SAAQ,KAAK;aAGpB,GAAG,CAAC,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,GAAG,CAAC,EAAE,MAAM,YAAA;CAK/B;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;I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