@runtypelabs/sdk 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7254 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5195 -0
- package/dist/index.d.ts +5194 -27
- package/dist/index.js +7182 -77
- package/dist/index.js.map +1 -1
- package/package.json +14 -7
- package/dist/batch-builder.d.ts +0 -106
- package/dist/batch-builder.d.ts.map +0 -1
- package/dist/batch-builder.js +0 -124
- package/dist/batch-builder.js.map +0 -1
- package/dist/batches-namespace.d.ts +0 -132
- package/dist/batches-namespace.d.ts.map +0 -1
- package/dist/batches-namespace.js +0 -128
- package/dist/batches-namespace.js.map +0 -1
- package/dist/case-types.d.ts +0 -42
- package/dist/case-types.d.ts.map +0 -1
- package/dist/case-types.js +0 -16
- package/dist/case-types.js.map +0 -1
- package/dist/client-token-types.d.ts +0 -143
- package/dist/client-token-types.d.ts.map +0 -1
- package/dist/client-token-types.js +0 -11
- package/dist/client-token-types.js.map +0 -1
- package/dist/client.d.ts +0 -135
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -522
- package/dist/client.js.map +0 -1
- package/dist/endpoints.d.ts +0 -1353
- package/dist/endpoints.d.ts.map +0 -1
- package/dist/endpoints.js +0 -2936
- package/dist/endpoints.js.map +0 -1
- package/dist/error-handling-types.d.ts +0 -71
- package/dist/error-handling-types.d.ts.map +0 -1
- package/dist/error-handling-types.js +0 -12
- package/dist/error-handling-types.js.map +0 -1
- package/dist/eval-builder.d.ts +0 -216
- package/dist/eval-builder.d.ts.map +0 -1
- package/dist/eval-builder.js +0 -225
- package/dist/eval-builder.js.map +0 -1
- package/dist/evals-namespace.d.ts +0 -205
- package/dist/evals-namespace.d.ts.map +0 -1
- package/dist/evals-namespace.js +0 -208
- package/dist/evals-namespace.js.map +0 -1
- package/dist/flow-builder.d.ts +0 -717
- package/dist/flow-builder.d.ts.map +0 -1
- package/dist/flow-builder.js +0 -592
- package/dist/flow-builder.js.map +0 -1
- package/dist/flow-result.d.ts +0 -117
- package/dist/flow-result.d.ts.map +0 -1
- package/dist/flow-result.js +0 -175
- package/dist/flow-result.js.map +0 -1
- package/dist/flows-namespace.d.ts +0 -442
- package/dist/flows-namespace.d.ts.map +0 -1
- package/dist/flows-namespace.js +0 -686
- package/dist/flows-namespace.js.map +0 -1
- package/dist/generated-tool-gate.d.ts +0 -75
- package/dist/generated-tool-gate.d.ts.map +0 -1
- package/dist/generated-tool-gate.js +0 -314
- package/dist/generated-tool-gate.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/prompts-namespace.d.ts +0 -237
- package/dist/prompts-namespace.d.ts.map +0 -1
- package/dist/prompts-namespace.js +0 -222
- package/dist/prompts-namespace.js.map +0 -1
- package/dist/runtype.d.ts +0 -232
- package/dist/runtype.d.ts.map +0 -1
- package/dist/runtype.js +0 -367
- package/dist/runtype.js.map +0 -1
- package/dist/stream-utils.d.ts +0 -58
- package/dist/stream-utils.d.ts.map +0 -1
- package/dist/stream-utils.js +0 -373
- package/dist/stream-utils.js.map +0 -1
- package/dist/transform.d.ts +0 -30
- package/dist/transform.d.ts.map +0 -1
- package/dist/transform.js +0 -196
- package/dist/transform.js.map +0 -1
- package/dist/types.d.ts +0 -717
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -7
- package/dist/types.js.map +0 -1
package/dist/flow-builder.d.ts
DELETED
|
@@ -1,717 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowBuilder - Fluent builder for constructing dispatch configurations
|
|
3
|
-
*
|
|
4
|
-
* Provides a chainable API for building flows with steps, making flow
|
|
5
|
-
* construction more readable and type-safe.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { FlowBuilder } from '@runtypelabs/sdk'
|
|
10
|
-
*
|
|
11
|
-
* const config = new FlowBuilder()
|
|
12
|
-
* .createFlow({ name: "My Flow" })
|
|
13
|
-
* .withRecord({ name: "Record", type: "data", metadata: { key: "value" } })
|
|
14
|
-
* .fetchUrl({ name: "Fetch", url: "https://api.example.com", outputVariable: "data" })
|
|
15
|
-
* .prompt({ name: "Process", model: "gpt-4", userPrompt: "Analyze: {{data}}" })
|
|
16
|
-
* .withOptions({ streamResponse: true, flowMode: "virtual" })
|
|
17
|
-
* .build()
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
import type { DispatchRequest, MessageContent, ToolsConfig, RuntimeTool, ReasoningConfig } from './types';
|
|
21
|
-
import type { ErrorHandlingMode, PromptErrorHandling, ContextErrorHandling } from './error-handling-types';
|
|
22
|
-
import { FlowResult } from './flow-result';
|
|
23
|
-
export interface PromptStepConfig {
|
|
24
|
-
name: string;
|
|
25
|
-
model: string;
|
|
26
|
-
userPrompt: string;
|
|
27
|
-
systemPrompt?: string;
|
|
28
|
-
previousMessages?: string | Array<{
|
|
29
|
-
role: string;
|
|
30
|
-
content: string;
|
|
31
|
-
}>;
|
|
32
|
-
outputVariable?: string;
|
|
33
|
-
responseFormat?: 'text' | 'json';
|
|
34
|
-
temperature?: number;
|
|
35
|
-
maxTokens?: number;
|
|
36
|
-
/**
|
|
37
|
-
* Enable reasoning/extended thinking for models that support it.
|
|
38
|
-
* - `true`: Enable with provider defaults
|
|
39
|
-
* - `ReasoningConfig`: Fine-grained control over reasoning behavior
|
|
40
|
-
*
|
|
41
|
-
* @example GPT-5 with streaming reasoning
|
|
42
|
-
* ```typescript
|
|
43
|
-
* reasoning: { enabled: true, reasoningSummary: 'auto' }
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
reasoning?: boolean | ReasoningConfig;
|
|
47
|
-
streamOutput?: boolean;
|
|
48
|
-
/** Tools configuration - supports saved tools (toolIds) and inline runtime tools */
|
|
49
|
-
tools?: ToolsConfig;
|
|
50
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
51
|
-
errorHandling?: ErrorHandlingMode | PromptErrorHandling;
|
|
52
|
-
enabled?: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface FetchUrlStepConfig {
|
|
55
|
-
name: string;
|
|
56
|
-
url: string;
|
|
57
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
58
|
-
headers?: Record<string, string>;
|
|
59
|
-
body?: string;
|
|
60
|
-
responseType?: 'json' | 'text' | 'xml';
|
|
61
|
-
markdownIfAvailable?: boolean;
|
|
62
|
-
outputVariable?: string;
|
|
63
|
-
fetchMethod?: 'http' | 'firecrawl';
|
|
64
|
-
firecrawl?: {
|
|
65
|
-
formats?: string[];
|
|
66
|
-
[key: string]: any;
|
|
67
|
-
};
|
|
68
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
69
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
70
|
-
streamOutput?: boolean;
|
|
71
|
-
enabled?: boolean;
|
|
72
|
-
}
|
|
73
|
-
export interface TransformDataStepConfig {
|
|
74
|
-
name: string;
|
|
75
|
-
script: string;
|
|
76
|
-
outputVariable?: string;
|
|
77
|
-
sandboxProvider?: 'quickjs' | 'daytona' | 'cloudflare-worker';
|
|
78
|
-
streamOutput?: boolean;
|
|
79
|
-
enabled?: boolean;
|
|
80
|
-
}
|
|
81
|
-
export interface SetVariableStepConfig {
|
|
82
|
-
name: string;
|
|
83
|
-
variableName: string;
|
|
84
|
-
value: string | number | boolean | object;
|
|
85
|
-
enabled?: boolean;
|
|
86
|
-
}
|
|
87
|
-
export interface ConditionalStepConfig {
|
|
88
|
-
name: string;
|
|
89
|
-
condition: string;
|
|
90
|
-
trueSteps?: any[];
|
|
91
|
-
falseSteps?: any[];
|
|
92
|
-
enabled?: boolean;
|
|
93
|
-
}
|
|
94
|
-
export interface SearchStepConfig {
|
|
95
|
-
name: string;
|
|
96
|
-
provider: string;
|
|
97
|
-
query: string;
|
|
98
|
-
maxResults?: number;
|
|
99
|
-
outputVariable?: string;
|
|
100
|
-
returnCitations?: boolean;
|
|
101
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
102
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
103
|
-
streamOutput?: boolean;
|
|
104
|
-
enabled?: boolean;
|
|
105
|
-
}
|
|
106
|
-
export interface SendEmailStepConfig {
|
|
107
|
-
name: string;
|
|
108
|
-
to: string;
|
|
109
|
-
from?: string;
|
|
110
|
-
subject: string;
|
|
111
|
-
html: string;
|
|
112
|
-
outputVariable?: string;
|
|
113
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
114
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
115
|
-
streamOutput?: boolean;
|
|
116
|
-
enabled?: boolean;
|
|
117
|
-
}
|
|
118
|
-
export interface SendStreamStepConfig {
|
|
119
|
-
name: string;
|
|
120
|
-
message: string;
|
|
121
|
-
enabled?: boolean;
|
|
122
|
-
}
|
|
123
|
-
export interface RetrieveRecordStepConfig {
|
|
124
|
-
name: string;
|
|
125
|
-
recordType?: string;
|
|
126
|
-
recordName?: string;
|
|
127
|
-
fieldsToInclude?: string[];
|
|
128
|
-
fieldsToExclude?: string[];
|
|
129
|
-
outputVariable?: string;
|
|
130
|
-
streamOutput?: boolean;
|
|
131
|
-
enabled?: boolean;
|
|
132
|
-
}
|
|
133
|
-
export interface UpsertRecordStepConfig {
|
|
134
|
-
name: string;
|
|
135
|
-
recordType: string;
|
|
136
|
-
recordName?: string;
|
|
137
|
-
sourceVariable?: string;
|
|
138
|
-
mergeStrategy?: 'merge' | 'replace';
|
|
139
|
-
outputVariable?: string;
|
|
140
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
141
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
142
|
-
streamOutput?: boolean;
|
|
143
|
-
enabled?: boolean;
|
|
144
|
-
}
|
|
145
|
-
export interface VectorSearchStepConfig {
|
|
146
|
-
name: string;
|
|
147
|
-
query: string;
|
|
148
|
-
recordType?: string;
|
|
149
|
-
embeddingModel?: string;
|
|
150
|
-
limit?: number;
|
|
151
|
-
threshold?: number;
|
|
152
|
-
outputVariable?: string;
|
|
153
|
-
streamOutput?: boolean;
|
|
154
|
-
enabled?: boolean;
|
|
155
|
-
}
|
|
156
|
-
export interface GenerateEmbeddingStepConfig {
|
|
157
|
-
name: string;
|
|
158
|
-
text: string;
|
|
159
|
-
embeddingModel?: string;
|
|
160
|
-
maxLength?: number;
|
|
161
|
-
outputVariable?: string;
|
|
162
|
-
streamOutput?: boolean;
|
|
163
|
-
enabled?: boolean;
|
|
164
|
-
}
|
|
165
|
-
export interface WaitUntilStepConfig {
|
|
166
|
-
name: string;
|
|
167
|
-
delayMs?: number;
|
|
168
|
-
continueOnTimeout?: boolean;
|
|
169
|
-
poll?: {
|
|
170
|
-
enabled: boolean;
|
|
171
|
-
intervalMs?: number;
|
|
172
|
-
maxAttempts?: number;
|
|
173
|
-
condition?: string;
|
|
174
|
-
};
|
|
175
|
-
outputVariable?: string;
|
|
176
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
177
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
178
|
-
streamOutput?: boolean;
|
|
179
|
-
enabled?: boolean;
|
|
180
|
-
}
|
|
181
|
-
export interface SendEventStepConfig {
|
|
182
|
-
name: string;
|
|
183
|
-
provider: string;
|
|
184
|
-
eventName: string;
|
|
185
|
-
properties?: Record<string, any>;
|
|
186
|
-
outputVariable?: string;
|
|
187
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
188
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
189
|
-
streamOutput?: boolean;
|
|
190
|
-
enabled?: boolean;
|
|
191
|
-
}
|
|
192
|
-
export interface SendTextStepConfig {
|
|
193
|
-
name: string;
|
|
194
|
-
to: string;
|
|
195
|
-
from?: string;
|
|
196
|
-
message: string;
|
|
197
|
-
outputVariable?: string;
|
|
198
|
-
/** Error handling configuration - supports simple mode or fallback chains */
|
|
199
|
-
errorHandling?: ErrorHandlingMode | ContextErrorHandling;
|
|
200
|
-
streamOutput?: boolean;
|
|
201
|
-
enabled?: boolean;
|
|
202
|
-
}
|
|
203
|
-
export interface FetchGitHubStepConfig {
|
|
204
|
-
name: string;
|
|
205
|
-
repository: string;
|
|
206
|
-
branch?: string;
|
|
207
|
-
path?: string;
|
|
208
|
-
outputVariable?: string;
|
|
209
|
-
streamOutput?: boolean;
|
|
210
|
-
enabled?: boolean;
|
|
211
|
-
}
|
|
212
|
-
export interface FlowConfig {
|
|
213
|
-
name: string;
|
|
214
|
-
description?: string;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Configuration for upsert flow - includes flow name and upsert behavior options
|
|
218
|
-
*/
|
|
219
|
-
export interface UpsertFlowConfig extends FlowConfig {
|
|
220
|
-
/** Whether to create a version snapshot before updating (default: true) */
|
|
221
|
-
createVersionOnChange?: boolean;
|
|
222
|
-
/** Allow overwriting changes made via dashboard/API (default: false) */
|
|
223
|
-
allowOverwriteExternalChanges?: boolean;
|
|
224
|
-
}
|
|
225
|
-
export interface RecordConfig {
|
|
226
|
-
id?: number | string;
|
|
227
|
-
name?: string;
|
|
228
|
-
type?: string;
|
|
229
|
-
metadata?: Record<string, any>;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Options for upsert mode - controls conflict detection and versioning
|
|
233
|
-
*/
|
|
234
|
-
export interface UpsertOptions {
|
|
235
|
-
/** Whether to create a version snapshot before updating (default: true) */
|
|
236
|
-
createVersionOnChange?: boolean;
|
|
237
|
-
/** Allow overwriting changes made via dashboard/API (default: false) */
|
|
238
|
-
allowOverwriteExternalChanges?: boolean;
|
|
239
|
-
}
|
|
240
|
-
export interface DispatchOptions {
|
|
241
|
-
streamResponse?: boolean;
|
|
242
|
-
modelOverride?: string;
|
|
243
|
-
recordMode?: 'existing' | 'create' | 'virtual';
|
|
244
|
-
flowMode?: 'existing' | 'create' | 'virtual' | 'upsert';
|
|
245
|
-
storeResults?: boolean;
|
|
246
|
-
autoAppendMetadata?: boolean;
|
|
247
|
-
debugMode?: boolean;
|
|
248
|
-
createVersion?: boolean;
|
|
249
|
-
versionType?: 'published' | 'draft' | 'test' | 'virtual';
|
|
250
|
-
versionLabel?: string;
|
|
251
|
-
versionNotes?: string;
|
|
252
|
-
flowVersionId?: string;
|
|
253
|
-
/** Options for upsert mode (only used when flowMode is 'upsert') */
|
|
254
|
-
upsertOptions?: UpsertOptions;
|
|
255
|
-
}
|
|
256
|
-
export interface Message {
|
|
257
|
-
role: 'system' | 'user' | 'assistant';
|
|
258
|
-
content: MessageContent;
|
|
259
|
-
}
|
|
260
|
-
export interface FlowPausedEvent {
|
|
261
|
-
type: 'flow_await';
|
|
262
|
-
executionId: string;
|
|
263
|
-
flowId: string;
|
|
264
|
-
toolId: string;
|
|
265
|
-
toolName: string;
|
|
266
|
-
awaitedAt: string;
|
|
267
|
-
}
|
|
268
|
-
export interface StepWaitingLocalEvent {
|
|
269
|
-
type: 'step_await';
|
|
270
|
-
id: string;
|
|
271
|
-
name: string;
|
|
272
|
-
index: number;
|
|
273
|
-
stepType: string;
|
|
274
|
-
toolId: string;
|
|
275
|
-
toolName: string;
|
|
276
|
-
executionId: string;
|
|
277
|
-
parameters: any;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Emitted when a fallback chain starts execution
|
|
281
|
-
*/
|
|
282
|
-
export interface FallbacksInitiatedEvent {
|
|
283
|
-
type: 'fallbacks_initiated';
|
|
284
|
-
id: string;
|
|
285
|
-
totalFallbacks: number;
|
|
286
|
-
originalError: string;
|
|
287
|
-
timestamp: string;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Emitted when a fallback attempt starts
|
|
291
|
-
*/
|
|
292
|
-
export interface FallbackStartEvent {
|
|
293
|
-
type: 'fallback_start';
|
|
294
|
-
id: string;
|
|
295
|
-
attempt: number;
|
|
296
|
-
fallbackType: string;
|
|
297
|
-
timestamp: string;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Emitted when a fallback attempt succeeds
|
|
301
|
-
*/
|
|
302
|
-
export interface FallbackSuccessEvent {
|
|
303
|
-
type: 'fallback_success';
|
|
304
|
-
id: string;
|
|
305
|
-
attempt: number;
|
|
306
|
-
fallbackType: string;
|
|
307
|
-
timestamp: string;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Emitted when a fallback attempt fails
|
|
311
|
-
*/
|
|
312
|
-
export interface FallbackFailEvent {
|
|
313
|
-
type: 'fallback_fail';
|
|
314
|
-
id: string;
|
|
315
|
-
attempt: number;
|
|
316
|
-
fallbackType: string;
|
|
317
|
-
error: string;
|
|
318
|
-
timestamp: string;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Emitted when all fallbacks in the chain have been exhausted
|
|
322
|
-
*/
|
|
323
|
-
export interface FallbacksExhaustedEvent {
|
|
324
|
-
type: 'fallbacks_exhausted';
|
|
325
|
-
id: string;
|
|
326
|
-
totalAttempts: number;
|
|
327
|
-
finalError: string;
|
|
328
|
-
timestamp: string;
|
|
329
|
-
}
|
|
330
|
-
export interface FlowStartEvent {
|
|
331
|
-
type: 'flow_start';
|
|
332
|
-
flowId: string;
|
|
333
|
-
flowName: string;
|
|
334
|
-
totalSteps: number;
|
|
335
|
-
}
|
|
336
|
-
export interface StepStartEvent {
|
|
337
|
-
type: 'step_start';
|
|
338
|
-
id: string;
|
|
339
|
-
name: string;
|
|
340
|
-
index: number;
|
|
341
|
-
stepType: string;
|
|
342
|
-
}
|
|
343
|
-
export interface StepDeltaEvent {
|
|
344
|
-
type: 'step_delta';
|
|
345
|
-
id: string;
|
|
346
|
-
chunk: string;
|
|
347
|
-
index: number;
|
|
348
|
-
}
|
|
349
|
-
/** @deprecated Use StepDeltaEvent instead */
|
|
350
|
-
export type StepChunkEvent = StepDeltaEvent;
|
|
351
|
-
export interface StepCompleteEvent {
|
|
352
|
-
type: 'step_complete';
|
|
353
|
-
id: string;
|
|
354
|
-
name: string;
|
|
355
|
-
index: number;
|
|
356
|
-
stepType: string;
|
|
357
|
-
/** Step result - used by all step types */
|
|
358
|
-
result?: any;
|
|
359
|
-
executionTime: number;
|
|
360
|
-
}
|
|
361
|
-
export interface FlowCompleteEvent {
|
|
362
|
-
type: 'flow_complete';
|
|
363
|
-
flowId: string;
|
|
364
|
-
totalSteps: number;
|
|
365
|
-
successfulSteps: number;
|
|
366
|
-
failedSteps: number;
|
|
367
|
-
executionTime: number;
|
|
368
|
-
}
|
|
369
|
-
export interface FlowErrorEvent {
|
|
370
|
-
type: 'flow_error';
|
|
371
|
-
error: string;
|
|
372
|
-
stepId?: string;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Union type of all possible SSE events
|
|
376
|
-
*/
|
|
377
|
-
export type StreamEvent = FlowStartEvent | StepStartEvent | StepDeltaEvent | StepCompleteEvent | FlowCompleteEvent | FlowErrorEvent | FlowPausedEvent | StepWaitingLocalEvent | FallbacksInitiatedEvent | FallbackStartEvent | FallbackSuccessEvent | FallbackFailEvent | FallbacksExhaustedEvent;
|
|
378
|
-
/**
|
|
379
|
-
* Callbacks for streaming flow execution
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```typescript
|
|
383
|
-
* await flow.run(apiClient, options, {
|
|
384
|
-
* onStepStart: (event) => console.log('Starting:', event.name),
|
|
385
|
-
* onStepDelta: (chunk, event) => process.stdout.write(chunk),
|
|
386
|
-
* onStepComplete: (result, event) => console.log('Done:', event.name),
|
|
387
|
-
* onFlowComplete: (event) => console.log('Flow complete'),
|
|
388
|
-
* onError: (error) => console.error(error),
|
|
389
|
-
* })
|
|
390
|
-
* ```
|
|
391
|
-
*/
|
|
392
|
-
export interface StreamCallbacks {
|
|
393
|
-
/** Called when flow execution starts */
|
|
394
|
-
onFlowStart?: (event: FlowStartEvent) => void;
|
|
395
|
-
/** Called when a step starts executing */
|
|
396
|
-
onStepStart?: (event: StepStartEvent) => void;
|
|
397
|
-
/** Called for each chunk of streaming output from a step */
|
|
398
|
-
onStepDelta?: (chunk: string, event: StepDeltaEvent) => void;
|
|
399
|
-
/**
|
|
400
|
-
* @deprecated Use onStepDelta instead
|
|
401
|
-
* Called for each chunk of streaming output from a step
|
|
402
|
-
*/
|
|
403
|
-
onStepChunk?: (chunk: string, event: StepDeltaEvent) => void;
|
|
404
|
-
/** Called when a step completes */
|
|
405
|
-
onStepComplete?: (result: any, event: StepCompleteEvent) => void;
|
|
406
|
-
/** Called when the entire flow completes */
|
|
407
|
-
onFlowComplete?: (event: FlowCompleteEvent) => void;
|
|
408
|
-
/** Called when an error occurs */
|
|
409
|
-
onError?: (error: Error) => void;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Summary returned after flow execution completes
|
|
413
|
-
*/
|
|
414
|
-
export interface FlowSummary {
|
|
415
|
-
flowId: string;
|
|
416
|
-
flowName: string;
|
|
417
|
-
totalSteps: number;
|
|
418
|
-
successfulSteps: number;
|
|
419
|
-
failedSteps: number;
|
|
420
|
-
executionTime: number;
|
|
421
|
-
/** Results from each step, keyed by step name */
|
|
422
|
-
results: Map<string, any>;
|
|
423
|
-
/** Whether the flow completed successfully */
|
|
424
|
-
success: boolean;
|
|
425
|
-
}
|
|
426
|
-
export declare class FlowBuilder {
|
|
427
|
-
private flowConfig;
|
|
428
|
-
private steps;
|
|
429
|
-
private recordConfig;
|
|
430
|
-
private messagesConfig;
|
|
431
|
-
private inputsConfig;
|
|
432
|
-
private optionsConfig;
|
|
433
|
-
private stepCounter;
|
|
434
|
-
private existingFlowId;
|
|
435
|
-
/**
|
|
436
|
-
* Initialize the flow with a name and optional description.
|
|
437
|
-
* Use this for virtual/one-off flows or when specifying flowMode in run().
|
|
438
|
-
*/
|
|
439
|
-
createFlow(config: FlowConfig): this;
|
|
440
|
-
/**
|
|
441
|
-
* Define a flow for upsert - creates if it doesn't exist, updates if steps changed.
|
|
442
|
-
* This is the recommended pattern for code-first flow management.
|
|
443
|
-
*
|
|
444
|
-
* @example
|
|
445
|
-
* ```typescript
|
|
446
|
-
* const result = await new FlowBuilder()
|
|
447
|
-
* .upsertFlow({
|
|
448
|
-
* name: 'My Flow',
|
|
449
|
-
* createVersionOnChange: true
|
|
450
|
-
* })
|
|
451
|
-
* .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
|
|
452
|
-
* .run(apiClient, { streamResponse: true })
|
|
453
|
-
* ```
|
|
454
|
-
*/
|
|
455
|
-
upsertFlow(config: UpsertFlowConfig): this;
|
|
456
|
-
/**
|
|
457
|
-
* Use an existing flow by ID instead of defining steps inline
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```typescript
|
|
461
|
-
* const result = await new FlowBuilder()
|
|
462
|
-
* .useExistingFlow('flow_abc123')
|
|
463
|
-
* .withRecord({ name: 'Test', type: 'data' })
|
|
464
|
-
* .run(apiClient, { streamResponse: true })
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
useExistingFlow(flowId: string): this;
|
|
468
|
-
/**
|
|
469
|
-
* Set the record configuration
|
|
470
|
-
*/
|
|
471
|
-
withRecord(config: RecordConfig): this;
|
|
472
|
-
/**
|
|
473
|
-
* Set conversation messages
|
|
474
|
-
*/
|
|
475
|
-
withMessages(messages: Message[]): this;
|
|
476
|
-
/**
|
|
477
|
-
* Set top-level input variables accessible as {{varName}} in templates
|
|
478
|
-
*
|
|
479
|
-
* @example
|
|
480
|
-
* ```typescript
|
|
481
|
-
* const result = await new FlowBuilder()
|
|
482
|
-
* .useExistingFlow('flow_abc123')
|
|
483
|
-
* .withInputs({
|
|
484
|
-
* customerName: 'John',
|
|
485
|
-
* topic: 'billing'
|
|
486
|
-
* })
|
|
487
|
-
* .run(apiClient, { streamResponse: true })
|
|
488
|
-
* ```
|
|
489
|
-
*/
|
|
490
|
-
withInputs(inputs: Record<string, unknown>): this;
|
|
491
|
-
/**
|
|
492
|
-
* Set dispatch options
|
|
493
|
-
*/
|
|
494
|
-
withOptions(options: DispatchOptions): this;
|
|
495
|
-
/**
|
|
496
|
-
* Add a prompt step
|
|
497
|
-
*/
|
|
498
|
-
prompt(config: PromptStepConfig): this;
|
|
499
|
-
/**
|
|
500
|
-
* Add a fetch URL step
|
|
501
|
-
*/
|
|
502
|
-
fetchUrl(config: FetchUrlStepConfig): this;
|
|
503
|
-
/**
|
|
504
|
-
* Add a transform data step
|
|
505
|
-
*/
|
|
506
|
-
transformData(config: TransformDataStepConfig): this;
|
|
507
|
-
/**
|
|
508
|
-
* Add a set variable step
|
|
509
|
-
*/
|
|
510
|
-
setVariable(config: SetVariableStepConfig): this;
|
|
511
|
-
/**
|
|
512
|
-
* Add a conditional step
|
|
513
|
-
*/
|
|
514
|
-
conditional(config: ConditionalStepConfig): this;
|
|
515
|
-
/**
|
|
516
|
-
* Add a search step
|
|
517
|
-
*/
|
|
518
|
-
search(config: SearchStepConfig): this;
|
|
519
|
-
/**
|
|
520
|
-
* Add a send email step
|
|
521
|
-
*/
|
|
522
|
-
sendEmail(config: SendEmailStepConfig): this;
|
|
523
|
-
/**
|
|
524
|
-
* Add a send stream step
|
|
525
|
-
*/
|
|
526
|
-
sendStream(config: SendStreamStepConfig): this;
|
|
527
|
-
/**
|
|
528
|
-
* Add a retrieve record step
|
|
529
|
-
*/
|
|
530
|
-
retrieveRecord(config: RetrieveRecordStepConfig): this;
|
|
531
|
-
/**
|
|
532
|
-
* Add an upsert record step
|
|
533
|
-
*/
|
|
534
|
-
upsertRecord(config: UpsertRecordStepConfig): this;
|
|
535
|
-
/**
|
|
536
|
-
* Add a vector search step
|
|
537
|
-
*/
|
|
538
|
-
vectorSearch(config: VectorSearchStepConfig): this;
|
|
539
|
-
/**
|
|
540
|
-
* Add a generate embedding step
|
|
541
|
-
*/
|
|
542
|
-
generateEmbedding(config: GenerateEmbeddingStepConfig): this;
|
|
543
|
-
/**
|
|
544
|
-
* Add a wait until step
|
|
545
|
-
*/
|
|
546
|
-
waitUntil(config: WaitUntilStepConfig): this;
|
|
547
|
-
/**
|
|
548
|
-
* Add a send event step
|
|
549
|
-
*/
|
|
550
|
-
sendEvent(config: SendEventStepConfig): this;
|
|
551
|
-
/**
|
|
552
|
-
* Add a send text step
|
|
553
|
-
*/
|
|
554
|
-
sendText(config: SendTextStepConfig): this;
|
|
555
|
-
/**
|
|
556
|
-
* Add a fetch GitHub step
|
|
557
|
-
*/
|
|
558
|
-
fetchGitHub(config: FetchGitHubStepConfig): this;
|
|
559
|
-
/**
|
|
560
|
-
* Build the final dispatch request configuration
|
|
561
|
-
*/
|
|
562
|
-
build(): DispatchRequest;
|
|
563
|
-
/**
|
|
564
|
-
* Build and execute the flow with the provided client
|
|
565
|
-
*
|
|
566
|
-
* Returns a FlowResult that can be used to:
|
|
567
|
-
* - Process with callbacks via `.stream(callbacks)`
|
|
568
|
-
* - Get a specific step result via `.getResult(stepName)`
|
|
569
|
-
* - Get all results via `.getAllResults()`
|
|
570
|
-
* - Access raw response via `.raw`
|
|
571
|
-
*
|
|
572
|
-
* @param client - Client with dispatch capability
|
|
573
|
-
* @param options - Optional execution options (merged with any .withOptions() settings)
|
|
574
|
-
* @returns FlowResult for processing the streaming response
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* ```typescript
|
|
578
|
-
* // Simple execution with result extraction
|
|
579
|
-
* const result = await flow.run(apiClient, { streamResponse: true })
|
|
580
|
-
* const analysis = await result.getResult('Analyze Data')
|
|
581
|
-
*
|
|
582
|
-
* // With streaming callbacks
|
|
583
|
-
* const result = await flow.run(apiClient, options)
|
|
584
|
-
* await result.stream({
|
|
585
|
-
* onStepDelta: (chunk) => process.stdout.write(chunk),
|
|
586
|
-
* onFlowComplete: () => console.log('Done!'),
|
|
587
|
-
* })
|
|
588
|
-
* ```
|
|
589
|
-
*/
|
|
590
|
-
run(client: DispatchClient, options?: DispatchOptions): Promise<FlowResult>;
|
|
591
|
-
/**
|
|
592
|
-
* Build and execute the flow with callbacks for streaming events
|
|
593
|
-
*
|
|
594
|
-
* @param client - Client with dispatch capability
|
|
595
|
-
* @param options - Execution options (merged with any .withOptions() settings)
|
|
596
|
-
* @param callbacks - Callbacks for streaming events
|
|
597
|
-
* @returns FlowSummary when execution completes
|
|
598
|
-
*
|
|
599
|
-
* @example
|
|
600
|
-
* ```typescript
|
|
601
|
-
* const summary = await flow.run(apiClient, options, {
|
|
602
|
-
* onStepStart: (event) => console.log('Starting:', event.name),
|
|
603
|
-
* onStepDelta: (chunk) => process.stdout.write(chunk),
|
|
604
|
-
* onStepComplete: (result, event) => console.log('Done:', event.name),
|
|
605
|
-
* onFlowComplete: (event) => console.log('Flow complete!'),
|
|
606
|
-
* })
|
|
607
|
-
* ```
|
|
608
|
-
*/
|
|
609
|
-
run(client: DispatchClient, options: DispatchOptions, callbacks: StreamCallbacks): Promise<FlowSummary>;
|
|
610
|
-
private addStep;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Interface for clients that can dispatch flows
|
|
614
|
-
*/
|
|
615
|
-
export interface DispatchClient {
|
|
616
|
-
/**
|
|
617
|
-
* Run a flow with local tools (automatic pause/resume loop)
|
|
618
|
-
*
|
|
619
|
-
* @param config - The dispatch request configuration
|
|
620
|
-
* @param localTools - Map of tool names to async functions that execute the tool logic
|
|
621
|
-
* @param callbacks - Optional callbacks for streaming events
|
|
622
|
-
* @returns The final result of the flow execution or summary if streaming
|
|
623
|
-
*/
|
|
624
|
-
runWithLocalTools(config: DispatchRequest, localTools: Record<string, (args: any) => Promise<any>>, callbacks?: StreamCallbacks): Promise<FlowResult | FlowSummary>;
|
|
625
|
-
dispatch(config: DispatchRequest): Promise<Response>;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* FlowBuilder that is bound to a client for direct execution
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```typescript
|
|
632
|
-
* // Via RuntypeClient.flow()
|
|
633
|
-
* const result = await runtype
|
|
634
|
-
* .flow('My Flow')
|
|
635
|
-
* .fetchUrl({ name: 'Fetch', url: '...', outputVariable: 'data' })
|
|
636
|
-
* .prompt({ name: 'Process', model: 'gpt-4', userPrompt: '...' })
|
|
637
|
-
* .run({ streamResponse: true })
|
|
638
|
-
*
|
|
639
|
-
* const data = await result.getResult('Process')
|
|
640
|
-
* ```
|
|
641
|
-
*/
|
|
642
|
-
export declare class ClientFlowBuilder extends FlowBuilder {
|
|
643
|
-
private boundClient;
|
|
644
|
-
constructor(client: DispatchClient, name: string);
|
|
645
|
-
/**
|
|
646
|
-
* Build and execute the flow using the bound client
|
|
647
|
-
*
|
|
648
|
-
* For ClientFlowBuilder, you can either:
|
|
649
|
-
* 1. Pass a client (which is ignored, the bound client is used)
|
|
650
|
-
* 2. Pass options directly as the first argument
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* ```typescript
|
|
654
|
-
* // Simple execution (no args needed)
|
|
655
|
-
* const result = await builder.run()
|
|
656
|
-
* const data = await result.getResult('Process')
|
|
657
|
-
*
|
|
658
|
-
* // With options only
|
|
659
|
-
* const result = await builder.run({ streamResponse: true, flowMode: 'virtual' })
|
|
660
|
-
*
|
|
661
|
-
* // With options and callbacks
|
|
662
|
-
* const summary = await builder.run({ streamResponse: true }, {
|
|
663
|
-
* onStepDelta: (chunk) => process.stdout.write(chunk),
|
|
664
|
-
* onFlowComplete: () => console.log('Done!'),
|
|
665
|
-
* })
|
|
666
|
-
*
|
|
667
|
-
* // Parent class signature (client ignored)
|
|
668
|
-
* const result = await builder.run(someClient, { streamResponse: true })
|
|
669
|
-
* ```
|
|
670
|
-
*/
|
|
671
|
-
run(): Promise<FlowResult>;
|
|
672
|
-
run(options: DispatchOptions): Promise<FlowResult>;
|
|
673
|
-
run(options: DispatchOptions, callbacks: StreamCallbacks): Promise<FlowSummary>;
|
|
674
|
-
run(localTools: Record<string, (args: any) => Promise<any>>): Promise<FlowResult>;
|
|
675
|
-
run(options: DispatchOptions, localTools: Record<string, (args: any) => Promise<any>>): Promise<FlowResult>;
|
|
676
|
-
run(localTools: Record<string, (args: any) => Promise<any>>, callbacks: StreamCallbacks): Promise<FlowSummary>;
|
|
677
|
-
run(options: DispatchOptions, localTools: Record<string, (args: any) => Promise<any>>, callbacks: StreamCallbacks): Promise<FlowSummary>;
|
|
678
|
-
run(client: DispatchClient, options?: DispatchOptions): Promise<FlowResult>;
|
|
679
|
-
run(client: DispatchClient, options: DispatchOptions, callbacks: StreamCallbacks): Promise<FlowSummary>;
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Create an external runtime tool definition.
|
|
683
|
-
*
|
|
684
|
-
* External tools make HTTP requests to external APIs with support for
|
|
685
|
-
* variable substitution in URLs and headers.
|
|
686
|
-
*
|
|
687
|
-
* Special internal variables are available for auth:
|
|
688
|
-
* - `{{_internal.auth_token}}` - Bearer token for Runtype API auth
|
|
689
|
-
* - `{{_internal.user_id}}` - Current user ID
|
|
690
|
-
* - `{{_internal.org_id}}` - Current organization ID
|
|
691
|
-
*
|
|
692
|
-
* @example
|
|
693
|
-
* ```typescript
|
|
694
|
-
* const listFlowsTool = createExternalTool({
|
|
695
|
-
* name: 'list_flows',
|
|
696
|
-
* description: 'List all flows in the workspace',
|
|
697
|
-
* parametersSchema: {
|
|
698
|
-
* type: 'object',
|
|
699
|
-
* properties: {
|
|
700
|
-
* limit: { type: 'number', description: 'Max results', default: 20 }
|
|
701
|
-
* }
|
|
702
|
-
* },
|
|
703
|
-
* url: 'https://api.runtype.com/v1/flows',
|
|
704
|
-
* method: 'GET',
|
|
705
|
-
* headers: { Authorization: '{{_internal.auth_token}}' }
|
|
706
|
-
* })
|
|
707
|
-
* ```
|
|
708
|
-
*/
|
|
709
|
-
export declare function createExternalTool(config: {
|
|
710
|
-
name: string;
|
|
711
|
-
description: string;
|
|
712
|
-
parametersSchema: any;
|
|
713
|
-
url: string;
|
|
714
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
715
|
-
headers?: Record<string, string>;
|
|
716
|
-
}): RuntimeTool;
|
|
717
|
-
//# sourceMappingURL=flow-builder.d.ts.map
|