@goharvest/simforge 0.1.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 +187 -7
- package/dist/baml.d.ts +61 -0
- package/dist/baml.d.ts.map +1 -0
- package/dist/baml.js +379 -0
- package/dist/baml.js.map +1 -0
- 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 +40 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +181 -1
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +454 -0
- package/dist/client.test.js.map +1 -0
- 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 +7 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -0
- 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 +29 -8
package/README.md
CHANGED
|
@@ -2,8 +2,88 @@
|
|
|
2
2
|
|
|
3
3
|
Simforge client for provider-based API calls.
|
|
4
4
|
|
|
5
|
+
## Monorepo Setup
|
|
6
|
+
|
|
7
|
+
This package is part of a **pnpm workspace** monorepo. The workspace structure separates concerns:
|
|
8
|
+
|
|
9
|
+
- **Root `package.json`**: Contains only shared dev dependencies (Biome, TypeScript, Vitest, Knip, Madge)
|
|
10
|
+
- **Package `package.json`**: Contains runtime dependencies specific to this package
|
|
11
|
+
- You can run tests and validation from the root directory: `pnpm test` or `pnpm validate`
|
|
12
|
+
- No need to manually update shared dev tooling versions across packages
|
|
13
|
+
|
|
14
|
+
### Installing Dependencies
|
|
15
|
+
|
|
16
|
+
Always install dependencies from the **root directory**:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# From the root directory
|
|
20
|
+
pnpm install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Updating pnpm
|
|
24
|
+
|
|
25
|
+
To update pnpm across the monorepo:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# From the root directory
|
|
29
|
+
pnpm pnpm:update
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This automatically updates pnpm and syncs the version in `package.json` and CI/CD workflows.
|
|
33
|
+
|
|
34
|
+
### Running Commands
|
|
35
|
+
|
|
36
|
+
You can run commands from this directory or from the root:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# From this directory
|
|
40
|
+
pnpm test
|
|
41
|
+
pnpm build
|
|
42
|
+
pnpm validate
|
|
43
|
+
|
|
44
|
+
# From the root directory (runs across all packages)
|
|
45
|
+
pnpm test # Run all tests
|
|
46
|
+
pnpm validate # Run lint + tsc + test
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Available Development Tools
|
|
50
|
+
|
|
51
|
+
This package includes the following shared development tools:
|
|
52
|
+
|
|
53
|
+
| Tool | Purpose | Command |
|
|
54
|
+
|------|---------|---------|
|
|
55
|
+
| **Vitest** | Unit testing with coverage | `pnpm test` |
|
|
56
|
+
| **Biome** | Fast linting & formatting | `pnpm lint` |
|
|
57
|
+
| **TypeScript** | Type checking | `pnpm tsc` |
|
|
58
|
+
| **Knip** | Find unused dependencies/exports | `pnpm knip` |
|
|
59
|
+
| **Madge** | Detect circular dependencies | `pnpm madge` |
|
|
60
|
+
|
|
61
|
+
**Run individual tools:**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Run tests with coverage
|
|
65
|
+
pnpm test
|
|
66
|
+
|
|
67
|
+
# Lint and format code
|
|
68
|
+
pnpm lint
|
|
69
|
+
|
|
70
|
+
# Type check without building
|
|
71
|
+
pnpm tsc
|
|
72
|
+
|
|
73
|
+
# Find unused dependencies
|
|
74
|
+
pnpm knip
|
|
75
|
+
|
|
76
|
+
# Check for circular dependencies
|
|
77
|
+
pnpm madge
|
|
78
|
+
|
|
79
|
+
# Run all validation checks
|
|
80
|
+
pnpm validate
|
|
81
|
+
```
|
|
82
|
+
|
|
5
83
|
## Installation
|
|
6
84
|
|
|
85
|
+
### Basic Installation
|
|
86
|
+
|
|
7
87
|
```bash
|
|
8
88
|
npm install @goharvest/simforge
|
|
9
89
|
# or
|
|
@@ -12,11 +92,22 @@ pnpm add @goharvest/simforge
|
|
|
12
92
|
yarn add @goharvest/simforge
|
|
13
93
|
```
|
|
14
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
|
+
|
|
15
107
|
## Local Development
|
|
16
108
|
|
|
17
109
|
```bash
|
|
18
110
|
cd simforge-typescript-sdk
|
|
19
|
-
pnpm install
|
|
20
111
|
pnpm build
|
|
21
112
|
```
|
|
22
113
|
|
|
@@ -39,12 +130,36 @@ pnpm add @harvest/simforge
|
|
|
39
130
|
|
|
40
131
|
## Usage
|
|
41
132
|
|
|
133
|
+
### Basic Usage (Local Execution)
|
|
134
|
+
|
|
135
|
+
By default, the SDK executes BAML functions **locally on the client** by fetching the BAML prompt from the server and running it with your own API keys:
|
|
136
|
+
|
|
42
137
|
```typescript
|
|
43
138
|
import { Simforge } from "@goharvest/simforge";
|
|
44
139
|
|
|
45
140
|
const client = new Simforge({
|
|
46
141
|
apiKey: "sf_your_api_key_here", // Required: Your Simforge API key
|
|
47
|
-
serviceUrl: "https://
|
|
142
|
+
serviceUrl: "https://simforge.goharvest.ai", // Optional
|
|
143
|
+
envVars: {
|
|
144
|
+
OPENAI_API_KEY: process.env.OPENAI_API_KEY, // Your LLM provider API keys
|
|
145
|
+
},
|
|
146
|
+
executeLocally: true, // Default: true
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const result = await client.call("method_name", {
|
|
150
|
+
arg1: "value1",
|
|
151
|
+
arg2: "value2",
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Server-Side Execution
|
|
156
|
+
|
|
157
|
+
If you prefer to execute BAML on the server (using the server's API keys), set `executeLocally: false`:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const client = new Simforge({
|
|
161
|
+
apiKey: "sf_your_api_key_here",
|
|
162
|
+
executeLocally: false, // Execute on server instead of locally
|
|
48
163
|
});
|
|
49
164
|
|
|
50
165
|
const result = await client.call("method_name", {
|
|
@@ -94,15 +209,80 @@ try {
|
|
|
94
209
|
|
|
95
210
|
## Configuration
|
|
96
211
|
|
|
97
|
-
| Option
|
|
98
|
-
|
|
|
99
|
-
| `apiKey`
|
|
100
|
-
| `serviceUrl`
|
|
101
|
-
| `timeout`
|
|
212
|
+
| Option | Required | Description |
|
|
213
|
+
| ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
214
|
+
| `apiKey` | Yes | Your Simforge API key (generate from your Simforge dashboard) |
|
|
215
|
+
| `serviceUrl` | No | The base URL for the Simforge API (default: https://simforge.goharvest.ai) |
|
|
216
|
+
| `timeout` | No | Request timeout in milliseconds (default: 120000) |
|
|
217
|
+
| `envVars` | No | Environment variables for LLM provider API keys (e.g., `{ OPENAI_API_KEY: "..." }`). Required for local execution. |
|
|
218
|
+
| `executeLocally` | No | Whether to execute BAML locally on the client (default: true). Set to false to execute on the server with the server's API keys. |
|
|
219
|
+
|
|
220
|
+
## Execution Modes
|
|
221
|
+
|
|
222
|
+
### Local Execution (Default)
|
|
223
|
+
|
|
224
|
+
When `executeLocally: true` (default), the SDK:
|
|
225
|
+
|
|
226
|
+
1. Fetches the BAML function definition from the Simforge server
|
|
227
|
+
2. Executes the BAML locally using the `@boundaryml/baml` runtime
|
|
228
|
+
3. Uses your own LLM provider API keys (passed via `envVars`)
|
|
229
|
+
4. Returns the result directly to you
|
|
230
|
+
|
|
231
|
+
**Benefits:**
|
|
232
|
+
|
|
233
|
+
- Full control over API keys and costs
|
|
234
|
+
- Lower latency (no server round-trip for execution)
|
|
235
|
+
- Privacy: Your data doesn't go through the Simforge server
|
|
236
|
+
|
|
237
|
+
**Requirements:**
|
|
238
|
+
|
|
239
|
+
- You must provide LLM provider API keys via `envVars`
|
|
240
|
+
- The BAML runtime runs in your environment (Node.js, browser with polyfills, etc.)
|
|
241
|
+
|
|
242
|
+
### Server-Side Execution
|
|
243
|
+
|
|
244
|
+
When `executeLocally: false`, the SDK:
|
|
245
|
+
|
|
246
|
+
1. Sends the function name and inputs to the Simforge server
|
|
247
|
+
2. The server executes the BAML using its own API keys
|
|
248
|
+
3. Returns the result to you
|
|
249
|
+
|
|
250
|
+
**Benefits:**
|
|
251
|
+
|
|
252
|
+
- No need to manage LLM provider API keys
|
|
253
|
+
- Simpler setup
|
|
254
|
+
- Works in any environment
|
|
255
|
+
|
|
256
|
+
**Requirements:**
|
|
257
|
+
|
|
258
|
+
- The Simforge server must have the necessary API keys configured
|
|
102
259
|
|
|
103
260
|
## Environment Variables
|
|
104
261
|
|
|
105
262
|
- `SIMFORGE_URL`: The base URL for the Simforge API (used if `serviceUrl` is not provided)
|
|
263
|
+
- `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.: LLM provider API keys (required for local execution)
|
|
264
|
+
|
|
265
|
+
## Testing
|
|
266
|
+
|
|
267
|
+
A test script is provided to verify both local and server-side execution:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# Set up environment variables
|
|
271
|
+
export SIMFORGE_API_KEY="sf_your_api_key"
|
|
272
|
+
export OPENAI_API_KEY="your_openai_key"
|
|
273
|
+
|
|
274
|
+
# Run the test script
|
|
275
|
+
pnpm tsx test-local-execution.ts [function-name] [query]
|
|
276
|
+
|
|
277
|
+
# Example
|
|
278
|
+
pnpm tsx test-local-execution.ts extract-entities "What is the capital of France?"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The test script will:
|
|
282
|
+
|
|
283
|
+
1. Test local execution with your API keys
|
|
284
|
+
2. Test server-side execution
|
|
285
|
+
3. Compare results and performance
|
|
106
286
|
|
|
107
287
|
## Publishing
|
|
108
288
|
|
package/dist/baml.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAML execution utilities for the Simforge TypeScript SDK.
|
|
3
|
+
* This module provides functions to execute BAML prompts dynamically on the client side.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Provider definition from the server.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProviderDefinition {
|
|
9
|
+
provider: string;
|
|
10
|
+
apiKeyEnv: string;
|
|
11
|
+
models: Array<{
|
|
12
|
+
model: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result of a BAML function execution with raw collector data.
|
|
18
|
+
*/
|
|
19
|
+
export interface BamlExecutionResult {
|
|
20
|
+
/** The parsed result of the function */
|
|
21
|
+
result: unknown;
|
|
22
|
+
/** Raw collector data for the server to parse */
|
|
23
|
+
rawCollector: Record<string, unknown> | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generate the BAML client name from provider and model.
|
|
27
|
+
* e.g., "openai" + "gpt-4.1-mini" -> "OpenAI_GPT4_1_mini"
|
|
28
|
+
*/
|
|
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[];
|
|
43
|
+
/**
|
|
44
|
+
* Type for allowed environment variables.
|
|
45
|
+
* Only OPENAI_API_KEY is currently supported.
|
|
46
|
+
*/
|
|
47
|
+
export type AllowedEnvVars = {
|
|
48
|
+
OPENAI_API_KEY?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Runs the BAML function with the given inputs using the BAML runtime directly.
|
|
52
|
+
* No file generation or subprocess spawning needed.
|
|
53
|
+
*
|
|
54
|
+
* @param bamlSource - The BAML source code containing the function
|
|
55
|
+
* @param inputs - Named arguments to pass to the function
|
|
56
|
+
* @param providers - Available provider definitions
|
|
57
|
+
* @param envVars - Environment variables for API keys (only OPENAI_API_KEY is allowed)
|
|
58
|
+
* @returns The result and execution metadata of the BAML function call
|
|
59
|
+
*/
|
|
60
|
+
export declare function runFunctionWithBaml(bamlSource: string, inputs: Record<string, unknown>, providers: ProviderDefinition[], envVars: AllowedEnvVars): Promise<BamlExecutionResult>;
|
|
61
|
+
//# sourceMappingURL=baml.d.ts.map
|
|
@@ -0,0 +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,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
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAML execution utilities for the Simforge TypeScript SDK.
|
|
3
|
+
* This module provides functions to execute BAML prompts dynamically on the client side.
|
|
4
|
+
*/
|
|
5
|
+
import { BamlRuntime, Collector } from "@boundaryml/baml";
|
|
6
|
+
/**
|
|
7
|
+
* Capitalize first letter of a string.
|
|
8
|
+
*/
|
|
9
|
+
function capitalize(str) {
|
|
10
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Convert provider name to PascalCase.
|
|
14
|
+
* e.g., "openai" -> "OpenAI", "anthropic" -> "Anthropic"
|
|
15
|
+
*/
|
|
16
|
+
function formatProvider(provider) {
|
|
17
|
+
const providerMap = {
|
|
18
|
+
openai: "OpenAI",
|
|
19
|
+
anthropic: "Anthropic",
|
|
20
|
+
google: "Google",
|
|
21
|
+
};
|
|
22
|
+
return providerMap[provider] ?? capitalize(provider);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert a model name to a valid BAML identifier part.
|
|
26
|
+
* e.g., "gpt-5-mini" -> "GPT5_mini", "gpt-4.1" -> "GPT4_1"
|
|
27
|
+
*/
|
|
28
|
+
function formatModel(model) {
|
|
29
|
+
return model
|
|
30
|
+
.replace(/^gpt-/, "GPT") // gpt- prefix -> GPT
|
|
31
|
+
.replace(/\./g, "_") // dots -> underscore
|
|
32
|
+
.replace(/-/g, "_"); // hyphens -> underscore
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate the BAML client name from provider and model.
|
|
36
|
+
* e.g., "openai" + "gpt-4.1-mini" -> "OpenAI_GPT4_1_mini"
|
|
37
|
+
*/
|
|
38
|
+
export function getClientName(provider, model) {
|
|
39
|
+
return `${formatProvider(provider)}_${formatModel(model)}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generates BAML client definition strings.
|
|
43
|
+
* BamlRuntime.fromFiles requires clients to be defined in source for parsing.
|
|
44
|
+
*/
|
|
45
|
+
function generateClientDefinitions(providers) {
|
|
46
|
+
const definitions = [];
|
|
47
|
+
for (const providerDef of providers) {
|
|
48
|
+
for (const model of providerDef.models) {
|
|
49
|
+
const clientName = getClientName(providerDef.provider, model.model);
|
|
50
|
+
definitions.push(`client<llm> ${clientName} {
|
|
51
|
+
provider ${providerDef.provider}
|
|
52
|
+
options {
|
|
53
|
+
model "${model.model}"
|
|
54
|
+
api_key env.${providerDef.apiKeyEnv}
|
|
55
|
+
}
|
|
56
|
+
}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return definitions.join("\n\n");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Prepends the default client definitions to a BAML source if it doesn't already define them.
|
|
63
|
+
*/
|
|
64
|
+
function withDefaultClients(bamlSource, providers) {
|
|
65
|
+
const hasDefaultClient = bamlSource.includes("client<llm> OpenAI_");
|
|
66
|
+
if (hasDefaultClient) {
|
|
67
|
+
return bamlSource;
|
|
68
|
+
}
|
|
69
|
+
const defaultClients = generateClientDefinitions(providers);
|
|
70
|
+
return `${defaultClients}\n\n${bamlSource}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extracts the first function name from BAML source code.
|
|
74
|
+
*/
|
|
75
|
+
function extractFunctionName(bamlSource) {
|
|
76
|
+
const match = bamlSource.match(/function\s+(\w+)\s*\(/);
|
|
77
|
+
return match?.[1] ?? null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extracts function parameter names and types from BAML source code.
|
|
81
|
+
* Used to properly coerce inputs based on expected types.
|
|
82
|
+
*/
|
|
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) {
|
|
204
|
+
const coerced = {};
|
|
205
|
+
for (const [key, value] of Object.entries(inputs)) {
|
|
206
|
+
if (typeof value === "string") {
|
|
207
|
+
const expectedType = expectedTypes.get(key);
|
|
208
|
+
if (expectedType) {
|
|
209
|
+
coerced[key] = coerceToType(value, expectedType);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// No expected type info - keep as string
|
|
213
|
+
coerced[key] = value;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
coerced[key] = value;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return coerced;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Recursively convert an object to a JSON-serializable structure.
|
|
224
|
+
* Similar to Python's _obj_to_dict function.
|
|
225
|
+
*/
|
|
226
|
+
function objToDict(obj, depth = 0, maxDepth = 5) {
|
|
227
|
+
if (depth > maxDepth) {
|
|
228
|
+
return `<max depth reached: ${typeof obj}>`;
|
|
229
|
+
}
|
|
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;
|
|
296
|
+
}
|
|
297
|
+
// Fallback for other types
|
|
298
|
+
return String(obj);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Serialize the BAML Collector to a JSON-serializable structure.
|
|
302
|
+
* Recursively extracts all properties from the Collector for server-side parsing.
|
|
303
|
+
*/
|
|
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
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Allowed environment variable keys for LLM providers.
|
|
315
|
+
* Only these keys will be passed to the BAML runtime.
|
|
316
|
+
*/
|
|
317
|
+
const ALLOWED_ENV_KEYS = ["OPENAI_API_KEY"];
|
|
318
|
+
/**
|
|
319
|
+
* Filters environment variables to only include allowed keys.
|
|
320
|
+
* This prevents accidentally passing sensitive environment variables to the BAML runtime.
|
|
321
|
+
*/
|
|
322
|
+
function filterEnvVars(envVars) {
|
|
323
|
+
const filtered = {};
|
|
324
|
+
for (const key of ALLOWED_ENV_KEYS) {
|
|
325
|
+
const value = envVars[key];
|
|
326
|
+
if (value) {
|
|
327
|
+
filtered[key] = value;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return filtered;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Runs the BAML function with the given inputs using the BAML runtime directly.
|
|
334
|
+
* No file generation or subprocess spawning needed.
|
|
335
|
+
*
|
|
336
|
+
* @param bamlSource - The BAML source code containing the function
|
|
337
|
+
* @param inputs - Named arguments to pass to the function
|
|
338
|
+
* @param providers - Available provider definitions
|
|
339
|
+
* @param envVars - Environment variables for API keys (only OPENAI_API_KEY is allowed)
|
|
340
|
+
* @returns The result and execution metadata of the BAML function call
|
|
341
|
+
*/
|
|
342
|
+
export async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
|
|
343
|
+
// Extract function name from the BAML source
|
|
344
|
+
const functionName = extractFunctionName(bamlSource);
|
|
345
|
+
if (!functionName) {
|
|
346
|
+
throw new Error("No function found in BAML source");
|
|
347
|
+
}
|
|
348
|
+
// Add default client definitions (runtime needs them for parsing)
|
|
349
|
+
const fullSource = withDefaultClients(bamlSource, providers);
|
|
350
|
+
// Filter env vars to only allowed keys
|
|
351
|
+
const filteredEnvVars = filterEnvVars(envVars);
|
|
352
|
+
// Create runtime from source with env vars
|
|
353
|
+
const runtime = BamlRuntime.fromFiles("/tmp/baml_runtime", { "source.baml": fullSource }, filteredEnvVars);
|
|
354
|
+
// Create context manager
|
|
355
|
+
const ctx = runtime.createContextManager();
|
|
356
|
+
// Create collector to capture execution metadata
|
|
357
|
+
const collector = new Collector("simforge-collector");
|
|
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);
|
|
363
|
+
// Call the function with collector
|
|
364
|
+
const functionResult = await runtime.callFunction(functionName, args, ctx, null, // TypeBuilder
|
|
365
|
+
null, // ClientRegistry
|
|
366
|
+
[collector], // Collectors - capture execution data
|
|
367
|
+
{}, // Tags
|
|
368
|
+
filteredEnvVars);
|
|
369
|
+
if (!functionResult.isOk()) {
|
|
370
|
+
throw new Error("BAML function execution failed");
|
|
371
|
+
}
|
|
372
|
+
// Serialize the collector to a dict for the server to parse
|
|
373
|
+
const rawCollector = serializeCollector(collector);
|
|
374
|
+
return {
|
|
375
|
+
result: functionResult.parsed(false),
|
|
376
|
+
rawCollector,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=baml.js.map
|
package/dist/baml.js.map
ADDED
|
@@ -0,0 +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;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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