@runtypelabs/sdk 0.1.1
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 +398 -0
- package/dist/batch-builder.d.ts +106 -0
- package/dist/batch-builder.d.ts.map +1 -0
- package/dist/batch-builder.js +124 -0
- package/dist/batch-builder.js.map +1 -0
- package/dist/batches-namespace.d.ts +132 -0
- package/dist/batches-namespace.d.ts.map +1 -0
- package/dist/batches-namespace.js +128 -0
- package/dist/batches-namespace.js.map +1 -0
- package/dist/client.d.ts +121 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +485 -0
- package/dist/client.js.map +1 -0
- package/dist/endpoints.d.ts +560 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +725 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/eval-builder.d.ts +216 -0
- package/dist/eval-builder.d.ts.map +1 -0
- package/dist/eval-builder.js +225 -0
- package/dist/eval-builder.js.map +1 -0
- package/dist/evals-namespace.d.ts +205 -0
- package/dist/evals-namespace.d.ts.map +1 -0
- package/dist/evals-namespace.js +208 -0
- package/dist/evals-namespace.js.map +1 -0
- package/dist/flow-builder.d.ts +620 -0
- package/dist/flow-builder.d.ts.map +1 -0
- package/dist/flow-builder.js +565 -0
- package/dist/flow-builder.js.map +1 -0
- package/dist/flow-result.d.ts +117 -0
- package/dist/flow-result.d.ts.map +1 -0
- package/dist/flow-result.js +175 -0
- package/dist/flow-result.js.map +1 -0
- package/dist/flows-namespace.d.ts +430 -0
- package/dist/flows-namespace.d.ts.map +1 -0
- package/dist/flows-namespace.js +679 -0
- package/dist/flows-namespace.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts-namespace.d.ts +236 -0
- package/dist/prompts-namespace.d.ts.map +1 -0
- package/dist/prompts-namespace.js +222 -0
- package/dist/prompts-namespace.js.map +1 -0
- package/dist/runtype.d.ts +232 -0
- package/dist/runtype.d.ts.map +1 -0
- package/dist/runtype.js +367 -0
- package/dist/runtype.js.map +1 -0
- package/dist/stream-utils.d.ts +58 -0
- package/dist/stream-utils.d.ts.map +1 -0
- package/dist/stream-utils.js +348 -0
- package/dist/stream-utils.js.map +1 -0
- package/dist/transform.d.ts +21 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +170 -0
- package/dist/transform.js.map +1 -0
- package/dist/types.d.ts +626 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtype - The unified SDK client for building and executing flows, batches, evals, and prompts
|
|
3
|
+
*
|
|
4
|
+
* Provides a fluent API with static namespaces for all product areas.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Runtype } from '@runtypelabs/sdk'
|
|
9
|
+
*
|
|
10
|
+
* // Global configuration (once per app)
|
|
11
|
+
* Runtype.configure({ apiKey: process.env.RUNTYPE_API_KEY })
|
|
12
|
+
*
|
|
13
|
+
* // Build and stream a flow
|
|
14
|
+
* const stream = await Runtype.flows.upsert({ name: 'My Flow' })
|
|
15
|
+
* .withRecord({ name: 'Test', metadata: {} })
|
|
16
|
+
* .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
|
|
17
|
+
* .stream()
|
|
18
|
+
*
|
|
19
|
+
* // Get complete result
|
|
20
|
+
* const result = await Runtype.flows.use('flow_123')
|
|
21
|
+
* .withRecord({ name: 'Test' })
|
|
22
|
+
* .result()
|
|
23
|
+
*
|
|
24
|
+
* // Schedule a batch
|
|
25
|
+
* const batch = await Runtype.batches.schedule({
|
|
26
|
+
* flowId: 'flow_123',
|
|
27
|
+
* recordType: 'customers',
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* // Run an eval with streaming
|
|
31
|
+
* const evalStream = await Runtype.evals.run({
|
|
32
|
+
* flowId: 'flow_123',
|
|
33
|
+
* recordType: 'test_data',
|
|
34
|
+
* models: [{ stepName: 'Analyze', model: 'gpt-4o' }]
|
|
35
|
+
* }).stream()
|
|
36
|
+
*
|
|
37
|
+
* // Execute a prompt
|
|
38
|
+
* const promptResult = await Runtype.prompts.run('prompt_123', {
|
|
39
|
+
* recordId: 'rec_456'
|
|
40
|
+
* }).result()
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
import { FlowsNamespace } from './flows-namespace';
|
|
44
|
+
import { BatchesNamespace } from './batches-namespace';
|
|
45
|
+
import { EvalsNamespace } from './evals-namespace';
|
|
46
|
+
import { PromptsNamespace } from './prompts-namespace';
|
|
47
|
+
export interface RuntypeConfig {
|
|
48
|
+
/** API key for authentication */
|
|
49
|
+
apiKey?: string;
|
|
50
|
+
/** Base URL for the API (defaults to https://api.runtype.com) */
|
|
51
|
+
baseUrl?: string;
|
|
52
|
+
/** API version (defaults to 'v1') */
|
|
53
|
+
apiVersion?: string;
|
|
54
|
+
/** Request timeout in milliseconds (defaults to 30000) */
|
|
55
|
+
timeout?: number;
|
|
56
|
+
/** Additional headers to include in requests */
|
|
57
|
+
headers?: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Internal client implementation that handles HTTP requests
|
|
61
|
+
*/
|
|
62
|
+
export declare class RuntypeClient {
|
|
63
|
+
private baseUrl;
|
|
64
|
+
private apiVersion;
|
|
65
|
+
private timeout;
|
|
66
|
+
private headers;
|
|
67
|
+
constructor(config?: RuntypeConfig);
|
|
68
|
+
/**
|
|
69
|
+
* Set the API key for authentication
|
|
70
|
+
*/
|
|
71
|
+
setApiKey(apiKey: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Generic GET request
|
|
74
|
+
*/
|
|
75
|
+
get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Generic POST request
|
|
78
|
+
*/
|
|
79
|
+
post<T>(path: string, data?: any): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Generic request that returns raw Response for streaming
|
|
82
|
+
*/
|
|
83
|
+
requestStream(path: string, options?: RequestInit): Promise<Response>;
|
|
84
|
+
/**
|
|
85
|
+
* Dispatch flow execution (streaming)
|
|
86
|
+
*/
|
|
87
|
+
dispatch(config: any): Promise<Response>;
|
|
88
|
+
/**
|
|
89
|
+
* Build full URL with query parameters
|
|
90
|
+
*/
|
|
91
|
+
private buildUrl;
|
|
92
|
+
/**
|
|
93
|
+
* Make HTTP request with timeout and error handling
|
|
94
|
+
*/
|
|
95
|
+
private makeRequest;
|
|
96
|
+
/**
|
|
97
|
+
* Make HTTP request that returns raw Response (for streaming)
|
|
98
|
+
*/
|
|
99
|
+
private makeRawRequest;
|
|
100
|
+
/**
|
|
101
|
+
* Transform response (placeholder for snake_case to camelCase)
|
|
102
|
+
*/
|
|
103
|
+
private transformResponse;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Runtype - Main entry point for the SDK
|
|
107
|
+
*
|
|
108
|
+
* Use static methods and namespaces to interact with the API.
|
|
109
|
+
*/
|
|
110
|
+
export declare class Runtype {
|
|
111
|
+
/**
|
|
112
|
+
* Configure the global Runtype client
|
|
113
|
+
*
|
|
114
|
+
* Call this once at app startup to set the API key and other options.
|
|
115
|
+
* All subsequent calls to Runtype.flows, Runtype.batches, etc. will use this config.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* Runtype.configure({ apiKey: process.env.RUNTYPE_API_KEY })
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
static configure(config: RuntypeConfig): void;
|
|
123
|
+
/**
|
|
124
|
+
* Get the global client instance, creating one if needed
|
|
125
|
+
*/
|
|
126
|
+
static getClient(): RuntypeClient;
|
|
127
|
+
/**
|
|
128
|
+
* Create a new client instance with custom configuration
|
|
129
|
+
*
|
|
130
|
+
* Use this when you need a client with different settings than the global one.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const client = Runtype.createClient({ apiKey: 'different_key' })
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
static createClient(config?: RuntypeConfig): RuntypeClient;
|
|
138
|
+
/**
|
|
139
|
+
* Flows namespace - Build and execute flows
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Upsert a flow (create or update)
|
|
144
|
+
* const result = await Runtype.flows.upsert({ name: 'My Flow' })
|
|
145
|
+
* .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
|
|
146
|
+
* .stream()
|
|
147
|
+
*
|
|
148
|
+
* // Use an existing flow
|
|
149
|
+
* const result = await Runtype.flows.use('flow_123')
|
|
150
|
+
* .withRecord({ name: 'Test' })
|
|
151
|
+
* .result()
|
|
152
|
+
*
|
|
153
|
+
* // Virtual flow (one-off, not saved)
|
|
154
|
+
* const result = await Runtype.flows.virtual({ name: 'Temp Flow' })
|
|
155
|
+
* .prompt({ ... })
|
|
156
|
+
* .stream()
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
static get flows(): FlowsNamespace;
|
|
160
|
+
/**
|
|
161
|
+
* Batches namespace - Schedule and manage batch operations
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // Schedule a batch
|
|
166
|
+
* const batch = await Runtype.batches.schedule({
|
|
167
|
+
* flowId: 'flow_123',
|
|
168
|
+
* recordType: 'customers',
|
|
169
|
+
* })
|
|
170
|
+
*
|
|
171
|
+
* // Get batch status
|
|
172
|
+
* const status = await Runtype.batches.get('batch_456')
|
|
173
|
+
*
|
|
174
|
+
* // Cancel a batch
|
|
175
|
+
* await Runtype.batches.cancel('batch_456')
|
|
176
|
+
*
|
|
177
|
+
* // List batches
|
|
178
|
+
* const batches = await Runtype.batches.list({ status: 'running' })
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
static get batches(): BatchesNamespace;
|
|
182
|
+
/**
|
|
183
|
+
* Evals namespace - Run evaluations and compare models
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* // Run an eval with streaming
|
|
188
|
+
* const stream = await Runtype.evals.run({
|
|
189
|
+
* flowId: 'flow_123',
|
|
190
|
+
* recordType: 'test_data',
|
|
191
|
+
* models: [{ stepName: 'Analyze', model: 'gpt-4o' }]
|
|
192
|
+
* }).stream()
|
|
193
|
+
*
|
|
194
|
+
* // Submit eval as batch job
|
|
195
|
+
* const eval = await Runtype.evals.run({
|
|
196
|
+
* flowId: 'flow_123',
|
|
197
|
+
* recordType: 'test_data',
|
|
198
|
+
* models: [
|
|
199
|
+
* [{ stepName: 'Analyze', model: 'gpt-4o' }],
|
|
200
|
+
* [{ stepName: 'Analyze', model: 'claude-3-opus' }],
|
|
201
|
+
* ]
|
|
202
|
+
* }).submit()
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
static get evals(): EvalsNamespace;
|
|
206
|
+
/**
|
|
207
|
+
* Prompts namespace - Manage and execute prompts
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Execute a prompt with streaming
|
|
212
|
+
* const stream = await Runtype.prompts.run('prompt_123', {
|
|
213
|
+
* recordId: 'rec_456'
|
|
214
|
+
* }).stream()
|
|
215
|
+
*
|
|
216
|
+
* // Get complete result
|
|
217
|
+
* const result = await Runtype.prompts.run('prompt_123', {
|
|
218
|
+
* recordId: 'rec_456'
|
|
219
|
+
* }).result()
|
|
220
|
+
*
|
|
221
|
+
* // CRUD operations
|
|
222
|
+
* const prompts = await Runtype.prompts.list()
|
|
223
|
+
* const prompt = await Runtype.prompts.get('prompt_123')
|
|
224
|
+
* const newPrompt = await Runtype.prompts.create({ ... })
|
|
225
|
+
* await Runtype.prompts.update('prompt_123', { ... })
|
|
226
|
+
* await Runtype.prompts.delete('prompt_123')
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
static get prompts(): PromptsNamespace;
|
|
230
|
+
}
|
|
231
|
+
export default Runtype;
|
|
232
|
+
//# sourceMappingURL=runtype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtype.d.ts","sourceRoot":"","sources":["../src/runtype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAOtD,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAaD;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAwB;gBAE3B,MAAM,GAAE,aAAkB;IAetC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACG,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IASpE;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAUnD;;OAEG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAa/E;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAO9C;;OAEG;IACH,OAAO,CAAC,QAAQ;IAgBhB;;OAEG;YACW,WAAW;IAsCzB;;OAEG;YACW,cAAc;IA6B5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAI1B;AAMD;;;;GAIG;AACH,qBAAa,OAAO;IAKlB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAK7C;;OAEG;IACH,MAAM,CAAC,SAAS,IAAI,aAAa;IAOjC;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,aAAa;IAQ1D;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,KAAK,KAAK,IAAI,cAAc,CAEjC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,KAAK,OAAO,IAAI,gBAAgB,CAErC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,KAAK,KAAK,IAAI,cAAc,CAEjC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,KAAK,OAAO,IAAI,gBAAgB,CAErC;CACF;AAED,eAAe,OAAO,CAAA"}
|
package/dist/runtype.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runtype - The unified SDK client for building and executing flows, batches, evals, and prompts
|
|
4
|
+
*
|
|
5
|
+
* Provides a fluent API with static namespaces for all product areas.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Runtype } from '@runtypelabs/sdk'
|
|
10
|
+
*
|
|
11
|
+
* // Global configuration (once per app)
|
|
12
|
+
* Runtype.configure({ apiKey: process.env.RUNTYPE_API_KEY })
|
|
13
|
+
*
|
|
14
|
+
* // Build and stream a flow
|
|
15
|
+
* const stream = await Runtype.flows.upsert({ name: 'My Flow' })
|
|
16
|
+
* .withRecord({ name: 'Test', metadata: {} })
|
|
17
|
+
* .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
|
|
18
|
+
* .stream()
|
|
19
|
+
*
|
|
20
|
+
* // Get complete result
|
|
21
|
+
* const result = await Runtype.flows.use('flow_123')
|
|
22
|
+
* .withRecord({ name: 'Test' })
|
|
23
|
+
* .result()
|
|
24
|
+
*
|
|
25
|
+
* // Schedule a batch
|
|
26
|
+
* const batch = await Runtype.batches.schedule({
|
|
27
|
+
* flowId: 'flow_123',
|
|
28
|
+
* recordType: 'customers',
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* // Run an eval with streaming
|
|
32
|
+
* const evalStream = await Runtype.evals.run({
|
|
33
|
+
* flowId: 'flow_123',
|
|
34
|
+
* recordType: 'test_data',
|
|
35
|
+
* models: [{ stepName: 'Analyze', model: 'gpt-4o' }]
|
|
36
|
+
* }).stream()
|
|
37
|
+
*
|
|
38
|
+
* // Execute a prompt
|
|
39
|
+
* const promptResult = await Runtype.prompts.run('prompt_123', {
|
|
40
|
+
* recordId: 'rec_456'
|
|
41
|
+
* }).result()
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.Runtype = exports.RuntypeClient = void 0;
|
|
46
|
+
const flows_namespace_1 = require("./flows-namespace");
|
|
47
|
+
const batches_namespace_1 = require("./batches-namespace");
|
|
48
|
+
const evals_namespace_1 = require("./evals-namespace");
|
|
49
|
+
const prompts_namespace_1 = require("./prompts-namespace");
|
|
50
|
+
const transform_1 = require("./transform");
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Global State
|
|
53
|
+
// ============================================================================
|
|
54
|
+
let globalConfig = {};
|
|
55
|
+
let globalClient = null;
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// RuntypeClient Class (internal implementation)
|
|
58
|
+
// ============================================================================
|
|
59
|
+
/**
|
|
60
|
+
* Internal client implementation that handles HTTP requests
|
|
61
|
+
*/
|
|
62
|
+
class RuntypeClient {
|
|
63
|
+
constructor(config = {}) {
|
|
64
|
+
const baseUrl = config.baseUrl || 'https://api.runtype.com';
|
|
65
|
+
this.apiVersion = config.apiVersion || 'v1';
|
|
66
|
+
this.baseUrl = this.apiVersion ? `${baseUrl}/${this.apiVersion}` : baseUrl;
|
|
67
|
+
this.timeout = config.timeout || 30000;
|
|
68
|
+
this.headers = {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
...(config.headers || {})
|
|
71
|
+
};
|
|
72
|
+
if (config.apiKey) {
|
|
73
|
+
this.headers.Authorization = `Bearer ${config.apiKey}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Set the API key for authentication
|
|
78
|
+
*/
|
|
79
|
+
setApiKey(apiKey) {
|
|
80
|
+
this.headers.Authorization = `Bearer ${apiKey}`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Generic GET request
|
|
84
|
+
*/
|
|
85
|
+
async get(path, params) {
|
|
86
|
+
const url = this.buildUrl(path, params);
|
|
87
|
+
const response = await this.makeRequest(url, {
|
|
88
|
+
method: 'GET',
|
|
89
|
+
headers: this.headers
|
|
90
|
+
});
|
|
91
|
+
return this.transformResponse(response);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Generic POST request
|
|
95
|
+
*/
|
|
96
|
+
async post(path, data) {
|
|
97
|
+
const url = this.buildUrl(path);
|
|
98
|
+
const response = await this.makeRequest(url, {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: this.headers,
|
|
101
|
+
body: data ? JSON.stringify(data) : undefined
|
|
102
|
+
});
|
|
103
|
+
return this.transformResponse(response);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generic request that returns raw Response for streaming
|
|
107
|
+
*/
|
|
108
|
+
async requestStream(path, options = {}) {
|
|
109
|
+
const url = this.buildUrl(path);
|
|
110
|
+
const headers = {
|
|
111
|
+
...this.headers,
|
|
112
|
+
...options.headers
|
|
113
|
+
};
|
|
114
|
+
return this.makeRawRequest(url, {
|
|
115
|
+
...options,
|
|
116
|
+
headers,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Dispatch flow execution (streaming)
|
|
121
|
+
*/
|
|
122
|
+
async dispatch(config) {
|
|
123
|
+
return this.requestStream('/dispatch', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
body: JSON.stringify((0, transform_1.transformRequest)(config))
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build full URL with query parameters
|
|
130
|
+
*/
|
|
131
|
+
buildUrl(path, params) {
|
|
132
|
+
const base = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
133
|
+
const relPath = path.startsWith('/') ? path.slice(1) : path;
|
|
134
|
+
const url = new URL(relPath, base);
|
|
135
|
+
if (params) {
|
|
136
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
137
|
+
if (value !== undefined && value !== null) {
|
|
138
|
+
url.searchParams.set(key, String(value));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return url.toString();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Make HTTP request with timeout and error handling
|
|
146
|
+
*/
|
|
147
|
+
async makeRequest(url, options) {
|
|
148
|
+
const controller = new AbortController();
|
|
149
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
150
|
+
try {
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
...options,
|
|
153
|
+
signal: controller.signal
|
|
154
|
+
});
|
|
155
|
+
clearTimeout(timeoutId);
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
const errorText = await response.text();
|
|
158
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
159
|
+
}
|
|
160
|
+
if (response.status === 204) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const contentType = response.headers.get('content-type');
|
|
164
|
+
if (contentType?.includes('application/json')) {
|
|
165
|
+
return response.json();
|
|
166
|
+
}
|
|
167
|
+
return response.text();
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
clearTimeout(timeoutId);
|
|
171
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
172
|
+
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Make HTTP request that returns raw Response (for streaming)
|
|
179
|
+
*/
|
|
180
|
+
async makeRawRequest(url, options) {
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
183
|
+
try {
|
|
184
|
+
const response = await fetch(url, {
|
|
185
|
+
...options,
|
|
186
|
+
signal: controller.signal
|
|
187
|
+
});
|
|
188
|
+
clearTimeout(timeoutId);
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
const errorText = await response.text();
|
|
191
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
192
|
+
}
|
|
193
|
+
return response;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
clearTimeout(timeoutId);
|
|
197
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
198
|
+
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Transform response (placeholder for snake_case to camelCase)
|
|
205
|
+
*/
|
|
206
|
+
transformResponse(response) {
|
|
207
|
+
// For now, return as-is. Can add transformation later if needed.
|
|
208
|
+
return response;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.RuntypeClient = RuntypeClient;
|
|
212
|
+
// ============================================================================
|
|
213
|
+
// Runtype Static Class
|
|
214
|
+
// ============================================================================
|
|
215
|
+
/**
|
|
216
|
+
* Runtype - Main entry point for the SDK
|
|
217
|
+
*
|
|
218
|
+
* Use static methods and namespaces to interact with the API.
|
|
219
|
+
*/
|
|
220
|
+
class Runtype {
|
|
221
|
+
// ============================================================================
|
|
222
|
+
// Global Configuration
|
|
223
|
+
// ============================================================================
|
|
224
|
+
/**
|
|
225
|
+
* Configure the global Runtype client
|
|
226
|
+
*
|
|
227
|
+
* Call this once at app startup to set the API key and other options.
|
|
228
|
+
* All subsequent calls to Runtype.flows, Runtype.batches, etc. will use this config.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* Runtype.configure({ apiKey: process.env.RUNTYPE_API_KEY })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
static configure(config) {
|
|
236
|
+
globalConfig = { ...globalConfig, ...config };
|
|
237
|
+
globalClient = new RuntypeClient(globalConfig);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get the global client instance, creating one if needed
|
|
241
|
+
*/
|
|
242
|
+
static getClient() {
|
|
243
|
+
if (!globalClient) {
|
|
244
|
+
globalClient = new RuntypeClient(globalConfig);
|
|
245
|
+
}
|
|
246
|
+
return globalClient;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Create a new client instance with custom configuration
|
|
250
|
+
*
|
|
251
|
+
* Use this when you need a client with different settings than the global one.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const client = Runtype.createClient({ apiKey: 'different_key' })
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
static createClient(config) {
|
|
259
|
+
return new RuntypeClient({ ...globalConfig, ...config });
|
|
260
|
+
}
|
|
261
|
+
// ============================================================================
|
|
262
|
+
// Static Namespaces
|
|
263
|
+
// ============================================================================
|
|
264
|
+
/**
|
|
265
|
+
* Flows namespace - Build and execute flows
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* // Upsert a flow (create or update)
|
|
270
|
+
* const result = await Runtype.flows.upsert({ name: 'My Flow' })
|
|
271
|
+
* .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
|
|
272
|
+
* .stream()
|
|
273
|
+
*
|
|
274
|
+
* // Use an existing flow
|
|
275
|
+
* const result = await Runtype.flows.use('flow_123')
|
|
276
|
+
* .withRecord({ name: 'Test' })
|
|
277
|
+
* .result()
|
|
278
|
+
*
|
|
279
|
+
* // Virtual flow (one-off, not saved)
|
|
280
|
+
* const result = await Runtype.flows.virtual({ name: 'Temp Flow' })
|
|
281
|
+
* .prompt({ ... })
|
|
282
|
+
* .stream()
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
static get flows() {
|
|
286
|
+
return new flows_namespace_1.FlowsNamespace(() => this.getClient());
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Batches namespace - Schedule and manage batch operations
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* // Schedule a batch
|
|
294
|
+
* const batch = await Runtype.batches.schedule({
|
|
295
|
+
* flowId: 'flow_123',
|
|
296
|
+
* recordType: 'customers',
|
|
297
|
+
* })
|
|
298
|
+
*
|
|
299
|
+
* // Get batch status
|
|
300
|
+
* const status = await Runtype.batches.get('batch_456')
|
|
301
|
+
*
|
|
302
|
+
* // Cancel a batch
|
|
303
|
+
* await Runtype.batches.cancel('batch_456')
|
|
304
|
+
*
|
|
305
|
+
* // List batches
|
|
306
|
+
* const batches = await Runtype.batches.list({ status: 'running' })
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
static get batches() {
|
|
310
|
+
return new batches_namespace_1.BatchesNamespace(() => this.getClient());
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Evals namespace - Run evaluations and compare models
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* // Run an eval with streaming
|
|
318
|
+
* const stream = await Runtype.evals.run({
|
|
319
|
+
* flowId: 'flow_123',
|
|
320
|
+
* recordType: 'test_data',
|
|
321
|
+
* models: [{ stepName: 'Analyze', model: 'gpt-4o' }]
|
|
322
|
+
* }).stream()
|
|
323
|
+
*
|
|
324
|
+
* // Submit eval as batch job
|
|
325
|
+
* const eval = await Runtype.evals.run({
|
|
326
|
+
* flowId: 'flow_123',
|
|
327
|
+
* recordType: 'test_data',
|
|
328
|
+
* models: [
|
|
329
|
+
* [{ stepName: 'Analyze', model: 'gpt-4o' }],
|
|
330
|
+
* [{ stepName: 'Analyze', model: 'claude-3-opus' }],
|
|
331
|
+
* ]
|
|
332
|
+
* }).submit()
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
static get evals() {
|
|
336
|
+
return new evals_namespace_1.EvalsNamespace(() => this.getClient());
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Prompts namespace - Manage and execute prompts
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* // Execute a prompt with streaming
|
|
344
|
+
* const stream = await Runtype.prompts.run('prompt_123', {
|
|
345
|
+
* recordId: 'rec_456'
|
|
346
|
+
* }).stream()
|
|
347
|
+
*
|
|
348
|
+
* // Get complete result
|
|
349
|
+
* const result = await Runtype.prompts.run('prompt_123', {
|
|
350
|
+
* recordId: 'rec_456'
|
|
351
|
+
* }).result()
|
|
352
|
+
*
|
|
353
|
+
* // CRUD operations
|
|
354
|
+
* const prompts = await Runtype.prompts.list()
|
|
355
|
+
* const prompt = await Runtype.prompts.get('prompt_123')
|
|
356
|
+
* const newPrompt = await Runtype.prompts.create({ ... })
|
|
357
|
+
* await Runtype.prompts.update('prompt_123', { ... })
|
|
358
|
+
* await Runtype.prompts.delete('prompt_123')
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
static get prompts() {
|
|
362
|
+
return new prompts_namespace_1.PromptsNamespace(() => this.getClient());
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
exports.Runtype = Runtype;
|
|
366
|
+
exports.default = Runtype;
|
|
367
|
+
//# sourceMappingURL=runtype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtype.js","sourceRoot":"","sources":["../src/runtype.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;AAGH,uDAAkD;AAClD,2DAAsD;AACtD,uDAAkD;AAClD,2DAAsD;AACtD,2CAA8C;AAmB9C,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,IAAI,YAAY,GAAkB,EAAE,CAAA;AACpC,IAAI,YAAY,GAAyB,IAAI,CAAA;AAE7C,+EAA+E;AAC/E,gDAAgD;AAChD,+EAA+E;AAE/E;;GAEG;AACH,MAAa,aAAa;IAMxB,YAAY,SAAwB,EAAE;QACpC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,yBAAyB,CAAA;QAC3D,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,IAAI,CAAA;QAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,IAAI,CAAC,OAAO,GA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,KAAK,OAAO;QAChB,OAAO,IAAI,oCAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;IACrD,CAAC;CACF;AAxJD,0BAwJC;AAED,kBAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE Stream Utilities for FlowBuilder
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for parsing Server-Sent Events (SSE) streams
|
|
5
|
+
* from the Runtype API dispatch endpoint.
|
|
6
|
+
*/
|
|
7
|
+
import type { StreamCallbacks, StreamEvent, FlowSummary } from './flow-builder';
|
|
8
|
+
/**
|
|
9
|
+
* Parse SSE stream chunks into individual events
|
|
10
|
+
*
|
|
11
|
+
* @param chunk - New chunk from the stream
|
|
12
|
+
* @param buffer - Previous incomplete buffer
|
|
13
|
+
* @returns Parsed events and remaining buffer
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseSSEChunk(chunk: string, buffer: string): {
|
|
16
|
+
events: string[];
|
|
17
|
+
remainingBuffer: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Parse final buffer if it contains a complete event
|
|
21
|
+
*
|
|
22
|
+
* @param buffer - Remaining buffer after stream ends
|
|
23
|
+
* @returns Parsed event JSON string or null
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseFinalBuffer(buffer: string): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Process a streaming response with callbacks
|
|
28
|
+
*
|
|
29
|
+
* @param response - Fetch Response object with streaming body
|
|
30
|
+
* @param callbacks - Callbacks for different event types
|
|
31
|
+
* @returns Promise resolving to FlowSummary when complete
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const response = await client.dispatch(config)
|
|
36
|
+
* const summary = await processStream(response, {
|
|
37
|
+
* onStepChunk: (chunk) => process.stdout.write(chunk),
|
|
38
|
+
* onFlowComplete: (event) => console.log('Done!'),
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function processStream(response: Response, callbacks?: StreamCallbacks): Promise<FlowSummary>;
|
|
43
|
+
/**
|
|
44
|
+
* Create an async iterator over SSE events
|
|
45
|
+
*
|
|
46
|
+
* @param response - Fetch Response object with streaming body
|
|
47
|
+
* @yields Parsed SSE events
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const response = await client.dispatch(config)
|
|
52
|
+
* for await (const event of streamEvents(response)) {
|
|
53
|
+
* console.log(event.type, event)
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function streamEvents(response: Response): AsyncGenerator<StreamEvent>;
|
|
58
|
+
//# sourceMappingURL=stream-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-utils.d.ts","sourceRoot":"","sources":["../src/stream-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EASX,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAMvB;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAgB/C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ9D;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,eAAoB,GAC9B,OAAO,CAAC,WAAW,CAAC,CA8ItB;AAgED;;;;;;;;;;;;;GAaG;AACH,wBAAuB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,CAyEnF"}
|