@goharvest/simforge 0.1.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/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Simforge TypeScript SDK
2
+
3
+ Simforge client for provider-based API calls.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @goharvest/simforge
9
+ # or
10
+ pnpm add @goharvest/simforge
11
+ # or
12
+ yarn add @goharvest/simforge
13
+ ```
14
+
15
+ ## Local Development
16
+
17
+ ```bash
18
+ cd simforge-typescript-sdk
19
+ pnpm install
20
+ pnpm build
21
+ ```
22
+
23
+ To link for local development:
24
+
25
+ ```bash
26
+ # In this directory
27
+ pnpm link --global
28
+
29
+ # In your app directory
30
+ pnpm link --global @harvest/simforge
31
+ ```
32
+
33
+ To switch back to npm version:
34
+
35
+ ```bash
36
+ pnpm unlink @harvest/simforge
37
+ pnpm add @harvest/simforge
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```typescript
43
+ import { Simforge } from "@goharvest/simforge";
44
+
45
+ const client = new Simforge({
46
+ apiKey: "sf_your_api_key_here", // Required: Your Simforge API key
47
+ serviceUrl: "https://your-simforge-instance.com", // Optional, can use SIMFORGE_URL env var
48
+ });
49
+
50
+ const result = await client.call("method_name", {
51
+ arg1: "value1",
52
+ arg2: "value2",
53
+ });
54
+ ```
55
+
56
+ ### With TypeScript Generics
57
+
58
+ You can specify the return type for type safety:
59
+
60
+ ```typescript
61
+ interface MyResponse {
62
+ answer: string;
63
+ confidence: number;
64
+ }
65
+
66
+ const result = await client.call<MyResponse>("analyze", {
67
+ text: "Hello world",
68
+ });
69
+
70
+ console.log(result.answer); // TypeScript knows this is a string
71
+ ```
72
+
73
+ ### Error Handling
74
+
75
+ ```typescript
76
+ import { Simforge, SimforgeError } from "@goharvest/simforge";
77
+
78
+ const client = new Simforge({
79
+ apiKey: "sf_your_api_key_here",
80
+ serviceUrl: "https://your-simforge-instance.com",
81
+ });
82
+
83
+ try {
84
+ const result = await client.call("method_name", { input: "value" });
85
+ } catch (error) {
86
+ if (error instanceof SimforgeError) {
87
+ console.error("Simforge error:", error.message);
88
+ if (error.url) {
89
+ console.error("Configure at:", error.url);
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Configuration
96
+
97
+ | Option | Required | Description |
98
+ | ------------ | -------- | ----------------------------------------------------------------------------------------------- |
99
+ | `apiKey` | Yes | Your Simforge API key (generate from your Simforge dashboard) |
100
+ | `serviceUrl` | No | The base URL for the Simforge API. Can also be set via the `SIMFORGE_URL` environment variable. |
101
+ | `timeout` | No | Request timeout in milliseconds (default: 120000) |
102
+
103
+ ## Environment Variables
104
+
105
+ - `SIMFORGE_URL`: The base URL for the Simforge API (used if `serviceUrl` is not provided)
106
+
107
+ ## Publishing
108
+
109
+ ```bash
110
+ pnpm build
111
+ npm publish --access public
112
+ ```
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Simforge client for provider-based API calls.
3
+ */
4
+ export interface SimforgeConfig {
5
+ /** The API key for Simforge API authentication */
6
+ apiKey: string;
7
+ /** The base URL for the Simforge API (default: https://simforge.goharvest.ai) */
8
+ serviceUrl?: string;
9
+ /** Request timeout in milliseconds (default: 120000) */
10
+ timeout?: number;
11
+ }
12
+ export interface CallResponse<T = unknown> {
13
+ result?: T;
14
+ error?: string;
15
+ url?: string;
16
+ traceId?: string;
17
+ }
18
+ export declare class SimforgeError extends Error {
19
+ readonly url?: string | undefined;
20
+ constructor(message: string, url?: string | undefined);
21
+ }
22
+ /**
23
+ * Client for making provider-based API calls via BAML.
24
+ */
25
+ export declare class Simforge {
26
+ private readonly apiKey;
27
+ private readonly serviceUrl;
28
+ private readonly timeout;
29
+ /**
30
+ * Initialize the Simforge client.
31
+ *
32
+ * @param config - Configuration options for the client
33
+ */
34
+ constructor(config: SimforgeConfig);
35
+ /**
36
+ * Call a method with the given named arguments via BAML execution.
37
+ *
38
+ * @param methodName - The name of the method to call
39
+ * @param inputs - Named arguments to pass to the method
40
+ * @returns The result of the BAML function execution
41
+ * @throws {SimforgeError} If service_url is not set, or if an error occurs
42
+ */
43
+ call<T = unknown>(methodName: string, inputs?: Record<string, unknown>): Promise<T>;
44
+ }
package/dist/client.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Simforge client for provider-based API calls.
3
+ */
4
+ const DEFAULT_SERVICE_URL = "https://simforge.goharvest.ai";
5
+ export class SimforgeError extends Error {
6
+ constructor(message, url) {
7
+ super(message);
8
+ this.url = url;
9
+ this.name = "SimforgeError";
10
+ }
11
+ }
12
+ /**
13
+ * Client for making provider-based API calls via BAML.
14
+ */
15
+ export class Simforge {
16
+ /**
17
+ * Initialize the Simforge client.
18
+ *
19
+ * @param config - Configuration options for the client
20
+ */
21
+ constructor(config) {
22
+ this.apiKey = config.apiKey;
23
+ this.serviceUrl = config.serviceUrl ?? DEFAULT_SERVICE_URL;
24
+ this.timeout = config.timeout ?? 120000;
25
+ }
26
+ /**
27
+ * Call a method with the given named arguments via BAML execution.
28
+ *
29
+ * @param methodName - The name of the method to call
30
+ * @param inputs - Named arguments to pass to the method
31
+ * @returns The result of the BAML function execution
32
+ * @throws {SimforgeError} If service_url is not set, or if an error occurs
33
+ */
34
+ async call(methodName, inputs = {}) {
35
+ const url = `${this.serviceUrl}/api/sdk/call`;
36
+ const payload = {
37
+ name: methodName,
38
+ inputs,
39
+ };
40
+ const controller = new AbortController();
41
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
42
+ try {
43
+ const response = await fetch(url, {
44
+ method: "POST",
45
+ headers: {
46
+ "Content-Type": "application/json",
47
+ Authorization: `Bearer ${this.apiKey}`,
48
+ },
49
+ body: JSON.stringify(payload),
50
+ signal: controller.signal,
51
+ });
52
+ if (!response.ok) {
53
+ const errorText = await response.text();
54
+ throw new SimforgeError(`HTTP ${response.status}: ${errorText.slice(0, 500)}`);
55
+ }
56
+ const result = await response.json();
57
+ // Check for errors in the response
58
+ if (result.error) {
59
+ if (result.url) {
60
+ throw new SimforgeError(`${result.error} Configure it at: ${this.serviceUrl}${result.url}`, result.url);
61
+ }
62
+ throw new SimforgeError(result.error);
63
+ }
64
+ return result.result;
65
+ }
66
+ catch (error) {
67
+ if (error instanceof SimforgeError) {
68
+ throw error;
69
+ }
70
+ if (error instanceof Error) {
71
+ if (error.name === "AbortError") {
72
+ throw new SimforgeError(`Request timed out after ${this.timeout}ms`);
73
+ }
74
+ throw new SimforgeError(error.message);
75
+ }
76
+ throw new SimforgeError("Unknown error occurred");
77
+ }
78
+ finally {
79
+ clearTimeout(timeoutId);
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Simforge client for provider-based API calls.
3
+ */
4
+ export { Simforge, SimforgeError } from "./client";
5
+ export type { SimforgeConfig, CallResponse } from "./client";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Simforge client for provider-based API calls.
3
+ */
4
+ export { Simforge, SimforgeError } from "./client";
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@goharvest/simforge",
3
+ "version": "0.1.0",
4
+ "description": "Simforge client for provider-based API calls",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "keywords": [
22
+ "simforge",
23
+ "baml",
24
+ "llm",
25
+ "api",
26
+ "client"
27
+ ],
28
+ "author": "Harvest Team",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/anthropic-harvest/simforge-typescript-sdk"
33
+ },
34
+ "homepage": "https://github.com/anthropic-harvest/simforge-typescript-sdk#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/anthropic-harvest/simforge-typescript-sdk/issues"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.15.21",
40
+ "typescript": "^5.7.2"
41
+ }
42
+ }