@goharvest/simforge 0.2.0 → 0.4.5
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 +14 -0
- package/dist/baml.d.ts +16 -42
- package/dist/baml.d.ts.map +1 -1
- package/dist/baml.js +219 -87
- package/dist/baml.js.map +1 -1
- package/dist/baml.test.d.ts +2 -0
- package/dist/baml.test.d.ts.map +1 -0
- package/dist/baml.test.js +86 -0
- package/dist/baml.test.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +101 -3
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +137 -40
- package/dist/client.test.js.map +1 -1
- package/dist/constants.d.ts +17 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +33 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.test.d.ts +2 -0
- package/dist/constants.test.d.ts.map +1 -0
- package/dist/constants.test.js +30 -0
- package/dist/constants.test.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/openai-tracing.d.ts +91 -0
- package/dist/openai-tracing.d.ts.map +1 -0
- package/dist/openai-tracing.js +179 -0
- package/dist/openai-tracing.js.map +1 -0
- package/dist/tracing.d.ts +100 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +300 -0
- package/dist/tracing.js.map +1 -0
- package/dist/tracing.test.d.ts +2 -0
- package/dist/tracing.test.d.ts.map +1 -0
- package/dist/tracing.test.js +399 -0
- package/dist/tracing.test.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +22 -0
- package/dist/version.js.map +1 -0
- package/package.json +16 -5
package/README.md
CHANGED
|
@@ -82,6 +82,8 @@ pnpm validate
|
|
|
82
82
|
|
|
83
83
|
## Installation
|
|
84
84
|
|
|
85
|
+
### Basic Installation
|
|
86
|
+
|
|
85
87
|
```bash
|
|
86
88
|
npm install @goharvest/simforge
|
|
87
89
|
# or
|
|
@@ -90,6 +92,18 @@ pnpm add @goharvest/simforge
|
|
|
90
92
|
yarn add @goharvest/simforge
|
|
91
93
|
```
|
|
92
94
|
|
|
95
|
+
### With OpenAI Agents SDK Tracing
|
|
96
|
+
|
|
97
|
+
If you want to use the OpenAI Agents SDK tracing integration:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install @goharvest/simforge @openai/agents
|
|
101
|
+
# or
|
|
102
|
+
pnpm add @goharvest/simforge @openai/agents
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The `@openai/agents` package is an optional peer dependency - the SDK works fine without it unless you need tracing functionality.
|
|
106
|
+
|
|
93
107
|
## Local Development
|
|
94
108
|
|
|
95
109
|
```bash
|
package/dist/baml.d.ts
CHANGED
|
@@ -14,58 +14,32 @@ export interface ProviderDefinition {
|
|
|
14
14
|
}>;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
export interface ModelParameters {
|
|
20
|
-
temperature?: number;
|
|
21
|
-
max_tokens?: number;
|
|
22
|
-
top_p?: number;
|
|
23
|
-
frequency_penalty?: number;
|
|
24
|
-
presence_penalty?: number;
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Metadata extracted from BAML execution.
|
|
29
|
-
*/
|
|
30
|
-
export interface BamlExecutionMetadata {
|
|
31
|
-
/** The actual model/client used (e.g., "OpenAI_GPT4_1_mini") */
|
|
32
|
-
clientName: string | null;
|
|
33
|
-
/** The provider (e.g., "openai", "anthropic") */
|
|
34
|
-
provider: string | null;
|
|
35
|
-
/** The actual model name from the API request (e.g., "gpt-4o") */
|
|
36
|
-
model: string | null;
|
|
37
|
-
/** Model parameters (temperature, max_tokens, etc.) */
|
|
38
|
-
modelParameters: ModelParameters | null;
|
|
39
|
-
/** Input tokens used */
|
|
40
|
-
inputTokens: number | null;
|
|
41
|
-
/** Output tokens used */
|
|
42
|
-
outputTokens: number | null;
|
|
43
|
-
/** Cached input tokens (if any) */
|
|
44
|
-
cachedInputTokens: number | null;
|
|
45
|
-
/** Execution duration in milliseconds */
|
|
46
|
-
durationMs: number | null;
|
|
47
|
-
/** Raw LLM response before parsing */
|
|
48
|
-
rawLlmResponse: string | null;
|
|
49
|
-
/** The actual rendered messages sent to the LLM (with ctx.output_format filled in) */
|
|
50
|
-
renderedMessages: Array<{
|
|
51
|
-
role: string;
|
|
52
|
-
content: string;
|
|
53
|
-
}> | null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Result of a BAML function execution with metadata.
|
|
17
|
+
* Result of a BAML function execution with raw collector data.
|
|
57
18
|
*/
|
|
58
19
|
export interface BamlExecutionResult {
|
|
59
20
|
/** The parsed result of the function */
|
|
60
21
|
result: unknown;
|
|
61
|
-
/**
|
|
62
|
-
|
|
22
|
+
/** Raw collector data for the server to parse */
|
|
23
|
+
rawCollector: Record<string, unknown> | null;
|
|
63
24
|
}
|
|
64
25
|
/**
|
|
65
26
|
* Generate the BAML client name from provider and model.
|
|
66
27
|
* e.g., "openai" + "gpt-4.1-mini" -> "OpenAI_GPT4_1_mini"
|
|
67
28
|
*/
|
|
68
29
|
export declare function getClientName(provider: string, model: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parameter type information extracted from BAML function signature.
|
|
32
|
+
*/
|
|
33
|
+
export interface BamlParameterType {
|
|
34
|
+
name: string;
|
|
35
|
+
type: string;
|
|
36
|
+
isOptional: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extracts function parameter names and types from BAML source code.
|
|
40
|
+
* Used to properly coerce inputs based on expected types.
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractFunctionParameters(bamlSource: string): BamlParameterType[];
|
|
69
43
|
/**
|
|
70
44
|
* Type for allowed environment variables.
|
|
71
45
|
* Only OPENAI_API_KEY is currently supported.
|
package/dist/baml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baml.d.ts","sourceRoot":"","sources":["../src/baml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;CACH;AAED;;GAEG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"baml.d.ts","sourceRoot":"","sources":["../src/baml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;CACH;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAA;IACf,iDAAiD;IACjD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CAC7C;AAiCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE;AAgDD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,GACjB,iBAAiB,EAAE,CAiCrB;AAyOD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAiBD;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,kBAAkB,EAAE,EAC/B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAwD9B"}
|
package/dist/baml.js
CHANGED
|
@@ -77,19 +77,139 @@ function extractFunctionName(bamlSource) {
|
|
|
77
77
|
return match?.[1] ?? null;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
80
|
+
* Extracts function parameter names and types from BAML source code.
|
|
81
|
+
* Used to properly coerce inputs based on expected types.
|
|
82
82
|
*/
|
|
83
|
-
function
|
|
83
|
+
export function extractFunctionParameters(bamlSource) {
|
|
84
|
+
const functionMatch = bamlSource.match(/function\s+\w+\s*\(([^)]*)\)\s*->/);
|
|
85
|
+
if (!functionMatch) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const paramsString = functionMatch[1].trim();
|
|
89
|
+
if (!paramsString) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const params = [];
|
|
93
|
+
const paramParts = splitParameters(paramsString);
|
|
94
|
+
for (const part of paramParts) {
|
|
95
|
+
const trimmed = part.trim();
|
|
96
|
+
if (!trimmed) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const paramMatch = trimmed.match(/^(\w+)\s*:\s*(.+)$/);
|
|
100
|
+
if (paramMatch) {
|
|
101
|
+
const name = paramMatch[1];
|
|
102
|
+
let type = paramMatch[2].trim();
|
|
103
|
+
const isOptional = type.endsWith("?");
|
|
104
|
+
if (isOptional) {
|
|
105
|
+
type = type.slice(0, -1);
|
|
106
|
+
}
|
|
107
|
+
params.push({ name, type, isOptional });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return params;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Split parameter string by commas, respecting nested angle brackets.
|
|
114
|
+
*/
|
|
115
|
+
function splitParameters(paramsString) {
|
|
116
|
+
const parts = [];
|
|
117
|
+
let current = "";
|
|
118
|
+
let depth = 0;
|
|
119
|
+
for (const char of paramsString) {
|
|
120
|
+
if (char === "<") {
|
|
121
|
+
depth++;
|
|
122
|
+
current += char;
|
|
123
|
+
}
|
|
124
|
+
else if (char === ">") {
|
|
125
|
+
depth--;
|
|
126
|
+
current += char;
|
|
127
|
+
}
|
|
128
|
+
else if (char === "," && depth === 0) {
|
|
129
|
+
parts.push(current);
|
|
130
|
+
current = "";
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
current += char;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (current.trim()) {
|
|
137
|
+
parts.push(current);
|
|
138
|
+
}
|
|
139
|
+
return parts;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Coerce a single string value to the expected BAML type.
|
|
143
|
+
* Returns the coerced value, or the original string if coercion fails.
|
|
144
|
+
*/
|
|
145
|
+
function coerceToType(value, expectedType) {
|
|
146
|
+
// String type - keep as is
|
|
147
|
+
if (expectedType === "string") {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
// Integer type
|
|
151
|
+
if (expectedType === "int") {
|
|
152
|
+
const parsed = Number.parseInt(value, 10);
|
|
153
|
+
if (!Number.isNaN(parsed)) {
|
|
154
|
+
return parsed;
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
// Float type
|
|
159
|
+
if (expectedType === "float") {
|
|
160
|
+
const parsed = Number.parseFloat(value);
|
|
161
|
+
if (!Number.isNaN(parsed)) {
|
|
162
|
+
return parsed;
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
// Boolean type
|
|
167
|
+
if (expectedType === "bool") {
|
|
168
|
+
const lower = value.toLowerCase();
|
|
169
|
+
if (lower === "true") {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
if (lower === "false") {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
// Array types (e.g., string[], int[])
|
|
178
|
+
if (expectedType.endsWith("[]")) {
|
|
179
|
+
try {
|
|
180
|
+
const parsed = JSON.parse(value);
|
|
181
|
+
if (Array.isArray(parsed)) {
|
|
182
|
+
return parsed;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// Not valid JSON array
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
// Complex types (objects, classes, maps) - try JSON parse
|
|
191
|
+
try {
|
|
192
|
+
return JSON.parse(value);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Coerces input values from strings to their appropriate types based on expected BAML types.
|
|
200
|
+
* Actively coerces to the expected type (int, float, bool, etc.) rather than just avoiding
|
|
201
|
+
* unintended conversions.
|
|
202
|
+
*/
|
|
203
|
+
function coerceInputs(inputs, expectedTypes) {
|
|
84
204
|
const coerced = {};
|
|
85
205
|
for (const [key, value] of Object.entries(inputs)) {
|
|
86
206
|
if (typeof value === "string") {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
coerced[key] =
|
|
207
|
+
const expectedType = expectedTypes.get(key);
|
|
208
|
+
if (expectedType) {
|
|
209
|
+
coerced[key] = coerceToType(value, expectedType);
|
|
90
210
|
}
|
|
91
|
-
|
|
92
|
-
//
|
|
211
|
+
else {
|
|
212
|
+
// No expected type info - keep as string
|
|
93
213
|
coerced[key] = value;
|
|
94
214
|
}
|
|
95
215
|
}
|
|
@@ -100,86 +220,95 @@ function coerceInputs(inputs) {
|
|
|
100
220
|
return coerced;
|
|
101
221
|
}
|
|
102
222
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
223
|
+
* Recursively convert an object to a JSON-serializable structure.
|
|
224
|
+
* Similar to Python's _obj_to_dict function.
|
|
105
225
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!requestBody || typeof requestBody !== "object") {
|
|
110
|
-
return { model: null, modelParameters: null, renderedMessages: null };
|
|
111
|
-
}
|
|
112
|
-
// Extract the actual model name
|
|
113
|
-
const model = typeof requestBody.model === "string" ? requestBody.model : null;
|
|
114
|
-
// Extract model parameters
|
|
115
|
-
const modelParameters = {};
|
|
116
|
-
if (typeof requestBody.temperature === "number") {
|
|
117
|
-
modelParameters.temperature = requestBody.temperature;
|
|
118
|
-
}
|
|
119
|
-
if (requestBody.max_tokens !== undefined) {
|
|
120
|
-
modelParameters.max_tokens = requestBody.max_tokens;
|
|
121
|
-
}
|
|
122
|
-
if (typeof requestBody.top_p === "number") {
|
|
123
|
-
modelParameters.top_p = requestBody.top_p;
|
|
124
|
-
}
|
|
125
|
-
if (typeof requestBody.frequency_penalty === "number") {
|
|
126
|
-
modelParameters.frequency_penalty = requestBody.frequency_penalty;
|
|
127
|
-
}
|
|
128
|
-
if (typeof requestBody.presence_penalty === "number") {
|
|
129
|
-
modelParameters.presence_penalty = requestBody.presence_penalty;
|
|
130
|
-
}
|
|
131
|
-
// Include response_format if present (for JSON mode)
|
|
132
|
-
if (requestBody.response_format) {
|
|
133
|
-
modelParameters.response_format = requestBody.response_format;
|
|
134
|
-
}
|
|
135
|
-
// Extract rendered messages
|
|
136
|
-
let renderedMessages = null;
|
|
137
|
-
if (Array.isArray(requestBody.messages)) {
|
|
138
|
-
renderedMessages = requestBody.messages
|
|
139
|
-
.filter((msg) => typeof msg === "object" &&
|
|
140
|
-
msg !== null &&
|
|
141
|
-
"role" in msg &&
|
|
142
|
-
typeof msg.role === "string")
|
|
143
|
-
.map((msg) => ({
|
|
144
|
-
role: msg.role,
|
|
145
|
-
content: typeof msg.content === "string"
|
|
146
|
-
? msg.content
|
|
147
|
-
: JSON.stringify(msg.content),
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
model,
|
|
152
|
-
modelParameters: Object.keys(modelParameters).length > 0 ? modelParameters : null,
|
|
153
|
-
renderedMessages,
|
|
154
|
-
};
|
|
226
|
+
function objToDict(obj, depth = 0, maxDepth = 5) {
|
|
227
|
+
if (depth > maxDepth) {
|
|
228
|
+
return `<max depth reached: ${typeof obj}>`;
|
|
155
229
|
}
|
|
156
|
-
|
|
157
|
-
|
|
230
|
+
// Handle primitives
|
|
231
|
+
if (obj === null ||
|
|
232
|
+
obj === undefined ||
|
|
233
|
+
typeof obj === "string" ||
|
|
234
|
+
typeof obj === "number" ||
|
|
235
|
+
typeof obj === "boolean") {
|
|
236
|
+
return obj;
|
|
237
|
+
}
|
|
238
|
+
// Handle arrays
|
|
239
|
+
if (Array.isArray(obj)) {
|
|
240
|
+
return obj.map((item) => objToDict(item, depth + 1, maxDepth));
|
|
241
|
+
}
|
|
242
|
+
// Handle plain objects and class instances
|
|
243
|
+
if (typeof obj === "object") {
|
|
244
|
+
const result = {};
|
|
245
|
+
// Add type information for non-plain objects
|
|
246
|
+
if (obj.constructor && obj.constructor.name !== "Object") {
|
|
247
|
+
result.__type__ = obj.constructor.name;
|
|
248
|
+
}
|
|
249
|
+
// Extract all enumerable properties
|
|
250
|
+
for (const key of Object.keys(obj)) {
|
|
251
|
+
if (key.startsWith("_")) {
|
|
252
|
+
continue; // Skip private properties
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const value = obj[key];
|
|
256
|
+
// Skip functions
|
|
257
|
+
if (typeof value === "function") {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
result[key] = objToDict(value, depth + 1, maxDepth);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
result[key] =
|
|
264
|
+
`<error: ${error instanceof Error ? error.message : String(error)}>`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Also try to get non-enumerable properties from the prototype
|
|
268
|
+
// This helps capture getters and computed properties
|
|
269
|
+
try {
|
|
270
|
+
const proto = Object.getPrototypeOf(obj);
|
|
271
|
+
if (proto && proto !== Object.prototype) {
|
|
272
|
+
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
273
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
274
|
+
if (key.startsWith("_") || key === "constructor" || key in result) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
// Try to get the value if it has a getter
|
|
278
|
+
if (descriptor.get) {
|
|
279
|
+
try {
|
|
280
|
+
const value = obj[key];
|
|
281
|
+
if (typeof value !== "function") {
|
|
282
|
+
result[key] = objToDict(value, depth + 1, maxDepth);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// Getter might throw or be inaccessible
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// Prototype inspection might fail
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
158
296
|
}
|
|
297
|
+
// Fallback for other types
|
|
298
|
+
return String(obj);
|
|
159
299
|
}
|
|
160
300
|
/**
|
|
161
|
-
*
|
|
301
|
+
* Serialize the BAML Collector to a JSON-serializable structure.
|
|
302
|
+
* Recursively extracts all properties from the Collector for server-side parsing.
|
|
162
303
|
*/
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
clientName: selectedCall?.clientName ?? null,
|
|
173
|
-
provider: selectedCall?.provider ?? null,
|
|
174
|
-
model,
|
|
175
|
-
modelParameters,
|
|
176
|
-
inputTokens: usage?.inputTokens ?? selectedCall?.usage?.inputTokens ?? null,
|
|
177
|
-
outputTokens: usage?.outputTokens ?? selectedCall?.usage?.outputTokens ?? null,
|
|
178
|
-
cachedInputTokens: usage?.cachedInputTokens ?? null,
|
|
179
|
-
durationMs: lastLog?.timing?.durationMs ?? null,
|
|
180
|
-
rawLlmResponse: lastLog?.rawLlmResponse ?? null,
|
|
181
|
-
renderedMessages,
|
|
182
|
-
};
|
|
304
|
+
function serializeCollector(collector) {
|
|
305
|
+
try {
|
|
306
|
+
return objToDict(collector, 0, 5);
|
|
307
|
+
}
|
|
308
|
+
catch (_error) {
|
|
309
|
+
// Silently ignore serialization failures
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
183
312
|
}
|
|
184
313
|
/**
|
|
185
314
|
* Allowed environment variable keys for LLM providers.
|
|
@@ -226,8 +355,11 @@ export async function runFunctionWithBaml(bamlSource, inputs, providers, envVars
|
|
|
226
355
|
const ctx = runtime.createContextManager();
|
|
227
356
|
// Create collector to capture execution metadata
|
|
228
357
|
const collector = new Collector("simforge-collector");
|
|
229
|
-
//
|
|
230
|
-
const
|
|
358
|
+
// Extract expected parameter types from BAML source
|
|
359
|
+
const params = extractFunctionParameters(bamlSource);
|
|
360
|
+
const expectedTypes = new Map(params.map((p) => [p.name, p.type]));
|
|
361
|
+
// Coerce inputs from strings to proper types based on BAML signature
|
|
362
|
+
const args = coerceInputs(inputs, expectedTypes);
|
|
231
363
|
// Call the function with collector
|
|
232
364
|
const functionResult = await runtime.callFunction(functionName, args, ctx, null, // TypeBuilder
|
|
233
365
|
null, // ClientRegistry
|
|
@@ -237,11 +369,11 @@ export async function runFunctionWithBaml(bamlSource, inputs, providers, envVars
|
|
|
237
369
|
if (!functionResult.isOk()) {
|
|
238
370
|
throw new Error("BAML function execution failed");
|
|
239
371
|
}
|
|
240
|
-
//
|
|
241
|
-
const
|
|
372
|
+
// Serialize the collector to a dict for the server to parse
|
|
373
|
+
const rawCollector = serializeCollector(collector);
|
|
242
374
|
return {
|
|
243
375
|
result: functionResult.parsed(false),
|
|
244
|
-
|
|
376
|
+
rawCollector,
|
|
245
377
|
};
|
|
246
378
|
}
|
|
247
379
|
//# sourceMappingURL=baml.js.map
|
package/dist/baml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baml.js","sourceRoot":"","sources":["../src/baml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"baml.js","sourceRoot":"","sources":["../src/baml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAwBzD;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,WAAW,GAA2B;QAC1C,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,WAAW;QACtB,MAAM,EAAE,QAAQ;KACjB,CAAA;IACD,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA;AACtD,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,KAAa;IAChC,OAAO,KAAK;SACT,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,qBAAqB;SAC7C,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,qBAAqB;SACzC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA,CAAC,wBAAwB;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,KAAa;IAC3D,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAA;AAC5D,CAAC;AAED;;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,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baml.test.d.ts","sourceRoot":"","sources":["../src/baml.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { extractFunctionParameters } from "./baml";
|
|
3
|
+
describe("extractFunctionParameters", () => {
|
|
4
|
+
it("should extract single string parameter", () => {
|
|
5
|
+
const baml = `function Greet(name: string) -> string {
|
|
6
|
+
client "openai/gpt-4"
|
|
7
|
+
prompt #"Hello {{ name }}"#
|
|
8
|
+
}`;
|
|
9
|
+
const params = extractFunctionParameters(baml);
|
|
10
|
+
expect(params).toEqual([
|
|
11
|
+
{ name: "name", type: "string", isOptional: false },
|
|
12
|
+
]);
|
|
13
|
+
});
|
|
14
|
+
it("should extract multiple parameters with different types", () => {
|
|
15
|
+
const baml = `function Calculate(a: int, b: float, name: string) -> int {
|
|
16
|
+
client "openai/gpt-4"
|
|
17
|
+
prompt #"Calculate"#
|
|
18
|
+
}`;
|
|
19
|
+
const params = extractFunctionParameters(baml);
|
|
20
|
+
expect(params).toEqual([
|
|
21
|
+
{ name: "a", type: "int", isOptional: false },
|
|
22
|
+
{ name: "b", type: "float", isOptional: false },
|
|
23
|
+
{ name: "name", type: "string", isOptional: false },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
it("should handle optional parameters", () => {
|
|
27
|
+
const baml = `function Query(q: string, limit: int?) -> string[] {
|
|
28
|
+
client "openai/gpt-4"
|
|
29
|
+
prompt #"Query"#
|
|
30
|
+
}`;
|
|
31
|
+
const params = extractFunctionParameters(baml);
|
|
32
|
+
expect(params).toEqual([
|
|
33
|
+
{ name: "q", type: "string", isOptional: false },
|
|
34
|
+
{ name: "limit", type: "int", isOptional: true },
|
|
35
|
+
]);
|
|
36
|
+
});
|
|
37
|
+
it("should handle function with no parameters", () => {
|
|
38
|
+
const baml = `function GetTime() -> string {
|
|
39
|
+
client "openai/gpt-4"
|
|
40
|
+
prompt #"What time is it?"#
|
|
41
|
+
}`;
|
|
42
|
+
const params = extractFunctionParameters(baml);
|
|
43
|
+
expect(params).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
it("should handle array types", () => {
|
|
46
|
+
const baml = `function ProcessItems(items: string[]) -> int {
|
|
47
|
+
client "openai/gpt-4"
|
|
48
|
+
prompt #"Process"#
|
|
49
|
+
}`;
|
|
50
|
+
const params = extractFunctionParameters(baml);
|
|
51
|
+
expect(params).toEqual([
|
|
52
|
+
{ name: "items", type: "string[]", isOptional: false },
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
it("should handle nested generic types like Map<string, int>", () => {
|
|
56
|
+
const baml = `function ProcessMap(data: Map<string, int>, name: string) -> string {
|
|
57
|
+
client "openai/gpt-4"
|
|
58
|
+
prompt #"Process"#
|
|
59
|
+
}`;
|
|
60
|
+
const params = extractFunctionParameters(baml);
|
|
61
|
+
expect(params).toEqual([
|
|
62
|
+
{ name: "data", type: "Map<string, int>", isOptional: false },
|
|
63
|
+
{ name: "name", type: "string", isOptional: false },
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
it("should return empty array for non-function BAML", () => {
|
|
67
|
+
const baml = `class Person {
|
|
68
|
+
name string
|
|
69
|
+
}`;
|
|
70
|
+
const params = extractFunctionParameters(baml);
|
|
71
|
+
expect(params).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
it("should return empty array for invalid BAML", () => {
|
|
74
|
+
const params = extractFunctionParameters("not baml at all");
|
|
75
|
+
expect(params).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
it("should handle bool type", () => {
|
|
78
|
+
const baml = `function CheckFlag(flag: bool) -> string {
|
|
79
|
+
client "openai/gpt-4"
|
|
80
|
+
prompt #"Check"#
|
|
81
|
+
}`;
|
|
82
|
+
const params = extractFunctionParameters(baml);
|
|
83
|
+
expect(params).toEqual([{ name: "flag", type: "bool", isOptional: false }]);
|
|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,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,IAAI,GAAG;;EAEf,CAAA;QACE,MAAM,MAAM,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,yBAAyB,CAAC,iBAAiB,CAAC,CAAA;QAC3D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,IAAI,GAAG;;;EAGf,CAAA;QACE,MAAM,MAAM,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
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 { SimforgeOpenAITracingProcessor } from "./tracing.js";
|
|
5
6
|
export interface SimforgeConfig {
|
|
6
7
|
/** The API key for Simforge API authentication */
|
|
7
8
|
apiKey: string;
|
|
@@ -56,5 +57,28 @@ export declare class Simforge {
|
|
|
56
57
|
* @throws {SimforgeError} If service_url is not set, or if an error occurs
|
|
57
58
|
*/
|
|
58
59
|
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
|
+
/**
|
|
66
|
+
* Get a tracing processor for OpenAI Agents SDK integration.
|
|
67
|
+
*
|
|
68
|
+
* This processor automatically captures traces and spans from the OpenAI Agents SDK
|
|
69
|
+
* and sends them to Simforge for monitoring and analysis.
|
|
70
|
+
*
|
|
71
|
+
* Example usage:
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { addTraceProcessor } from '@openai/agents';
|
|
74
|
+
*
|
|
75
|
+
* const client = new Simforge({ apiKey: 'your-api-key' });
|
|
76
|
+
* const processor = client.getOpenAiTracingProcessor();
|
|
77
|
+
* addTraceProcessor(processor);
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @returns A SimforgeOpenAITracingProcessor instance configured for this client
|
|
81
|
+
*/
|
|
82
|
+
getOpenAiTracingProcessor(): SimforgeOpenAITracingProcessor;
|
|
59
83
|
}
|
|
60
84
|
//# sourceMappingURL=client.d.ts.map
|