@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.
Files changed (80) hide show
  1. package/dist/index.cjs +7254 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +5195 -0
  4. package/dist/index.d.ts +5194 -27
  5. package/dist/index.js +7182 -77
  6. package/dist/index.js.map +1 -1
  7. package/package.json +14 -7
  8. package/dist/batch-builder.d.ts +0 -106
  9. package/dist/batch-builder.d.ts.map +0 -1
  10. package/dist/batch-builder.js +0 -124
  11. package/dist/batch-builder.js.map +0 -1
  12. package/dist/batches-namespace.d.ts +0 -132
  13. package/dist/batches-namespace.d.ts.map +0 -1
  14. package/dist/batches-namespace.js +0 -128
  15. package/dist/batches-namespace.js.map +0 -1
  16. package/dist/case-types.d.ts +0 -42
  17. package/dist/case-types.d.ts.map +0 -1
  18. package/dist/case-types.js +0 -16
  19. package/dist/case-types.js.map +0 -1
  20. package/dist/client-token-types.d.ts +0 -143
  21. package/dist/client-token-types.d.ts.map +0 -1
  22. package/dist/client-token-types.js +0 -11
  23. package/dist/client-token-types.js.map +0 -1
  24. package/dist/client.d.ts +0 -135
  25. package/dist/client.d.ts.map +0 -1
  26. package/dist/client.js +0 -522
  27. package/dist/client.js.map +0 -1
  28. package/dist/endpoints.d.ts +0 -1353
  29. package/dist/endpoints.d.ts.map +0 -1
  30. package/dist/endpoints.js +0 -2936
  31. package/dist/endpoints.js.map +0 -1
  32. package/dist/error-handling-types.d.ts +0 -71
  33. package/dist/error-handling-types.d.ts.map +0 -1
  34. package/dist/error-handling-types.js +0 -12
  35. package/dist/error-handling-types.js.map +0 -1
  36. package/dist/eval-builder.d.ts +0 -216
  37. package/dist/eval-builder.d.ts.map +0 -1
  38. package/dist/eval-builder.js +0 -225
  39. package/dist/eval-builder.js.map +0 -1
  40. package/dist/evals-namespace.d.ts +0 -205
  41. package/dist/evals-namespace.d.ts.map +0 -1
  42. package/dist/evals-namespace.js +0 -208
  43. package/dist/evals-namespace.js.map +0 -1
  44. package/dist/flow-builder.d.ts +0 -717
  45. package/dist/flow-builder.d.ts.map +0 -1
  46. package/dist/flow-builder.js +0 -592
  47. package/dist/flow-builder.js.map +0 -1
  48. package/dist/flow-result.d.ts +0 -117
  49. package/dist/flow-result.d.ts.map +0 -1
  50. package/dist/flow-result.js +0 -175
  51. package/dist/flow-result.js.map +0 -1
  52. package/dist/flows-namespace.d.ts +0 -442
  53. package/dist/flows-namespace.d.ts.map +0 -1
  54. package/dist/flows-namespace.js +0 -686
  55. package/dist/flows-namespace.js.map +0 -1
  56. package/dist/generated-tool-gate.d.ts +0 -75
  57. package/dist/generated-tool-gate.d.ts.map +0 -1
  58. package/dist/generated-tool-gate.js +0 -314
  59. package/dist/generated-tool-gate.js.map +0 -1
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/prompts-namespace.d.ts +0 -237
  62. package/dist/prompts-namespace.d.ts.map +0 -1
  63. package/dist/prompts-namespace.js +0 -222
  64. package/dist/prompts-namespace.js.map +0 -1
  65. package/dist/runtype.d.ts +0 -232
  66. package/dist/runtype.d.ts.map +0 -1
  67. package/dist/runtype.js +0 -367
  68. package/dist/runtype.js.map +0 -1
  69. package/dist/stream-utils.d.ts +0 -58
  70. package/dist/stream-utils.d.ts.map +0 -1
  71. package/dist/stream-utils.js +0 -373
  72. package/dist/stream-utils.js.map +0 -1
  73. package/dist/transform.d.ts +0 -30
  74. package/dist/transform.d.ts.map +0 -1
  75. package/dist/transform.js +0 -196
  76. package/dist/transform.js.map +0 -1
  77. package/dist/types.d.ts +0 -717
  78. package/dist/types.d.ts.map +0 -1
  79. package/dist/types.js +0 -7
  80. package/dist/types.js.map +0 -1
@@ -1,686 +0,0 @@
1
- "use strict";
2
- /**
3
- * FlowsNamespace - Static namespace for flow operations
4
- *
5
- * Provides factory methods for creating flow builders with different modes:
6
- * - upsert: Create or update a flow by name
7
- * - virtual: One-off execution without saving
8
- * - use: Execute an existing flow by ID
9
- */
10
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- var desc = Object.getOwnPropertyDescriptor(m, k);
13
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
- desc = { enumerable: true, get: function() { return m[k]; } };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }) : (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- o[k2] = m[k];
20
- }));
21
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
- Object.defineProperty(o, "default", { enumerable: true, value: v });
23
- }) : function(o, v) {
24
- o["default"] = v;
25
- });
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.RuntypeFlowBuilder = exports.FlowsNamespace = void 0;
45
- const flow_result_1 = require("./flow-result");
46
- // ============================================================================
47
- // FlowsNamespace
48
- // ============================================================================
49
- class FlowsNamespace {
50
- constructor(getClient) {
51
- this.getClient = getClient;
52
- }
53
- /**
54
- * Create or update a flow by name (upsert mode)
55
- *
56
- * The recommended pattern for code-first flow management.
57
- * Creates the flow if it doesn't exist, updates if steps changed.
58
- *
59
- * @example
60
- * ```typescript
61
- * const result = await Runtype.flows.upsert({
62
- * name: 'My Flow',
63
- * createVersionOnChange: true
64
- * })
65
- * .prompt({ name: 'Analyze', model: 'gpt-4o', userPrompt: '...' })
66
- * .stream()
67
- * ```
68
- */
69
- upsert(config) {
70
- return new RuntypeFlowBuilder(this.getClient, 'upsert', config);
71
- }
72
- /**
73
- * Create a virtual flow (one-off, not saved)
74
- *
75
- * Use for temporary or ad-hoc flow execution.
76
- *
77
- * @example
78
- * ```typescript
79
- * const result = await Runtype.flows.virtual({ name: 'Temp Flow' })
80
- * .prompt({ name: 'Process', model: 'gpt-4o', userPrompt: '...' })
81
- * .stream()
82
- * ```
83
- */
84
- virtual(config) {
85
- return new RuntypeFlowBuilder(this.getClient, 'virtual', config);
86
- }
87
- /**
88
- * Use an existing flow by ID
89
- *
90
- * @example
91
- * ```typescript
92
- * const result = await Runtype.flows.use('flow_123')
93
- * .withRecord({ name: 'Test', type: 'data' })
94
- * .stream()
95
- * ```
96
- */
97
- use(flowId) {
98
- return new RuntypeFlowBuilder(this.getClient, 'existing', undefined, flowId);
99
- }
100
- /**
101
- * Quick execution of an existing flow
102
- *
103
- * @example
104
- * ```typescript
105
- * const result = await Runtype.flows.execute('flow_123', {
106
- * record: { name: 'Test', type: 'data' },
107
- * streamResponse: true
108
- * })
109
- * ```
110
- */
111
- async execute(flowId, options) {
112
- const builder = this.use(flowId);
113
- if (options?.record)
114
- builder.withRecord(options.record);
115
- if (options?.messages)
116
- builder.withMessages(options.messages);
117
- return options?.streamResponse !== false ? builder.stream() : builder.result();
118
- }
119
- }
120
- exports.FlowsNamespace = FlowsNamespace;
121
- // ============================================================================
122
- // RuntypeFlowBuilder
123
- // ============================================================================
124
- /**
125
- * Fluent builder for constructing and executing flows
126
- */
127
- class RuntypeFlowBuilder {
128
- constructor(getClient, mode, config, flowId) {
129
- this.getClient = getClient;
130
- this.steps = [];
131
- this.stepCounter = 0;
132
- this.upsertOptions = {};
133
- this.dispatchOptions = {};
134
- this.mode = mode;
135
- if (mode === 'existing' && flowId) {
136
- this.existingFlowId = flowId;
137
- this.flowConfig = { name: '' };
138
- }
139
- else if (config) {
140
- const { createVersionOnChange, allowOverwriteExternalChanges, ...flowConfig } = config;
141
- this.flowConfig = flowConfig;
142
- if (mode === 'upsert') {
143
- this.upsertOptions = {
144
- createVersionOnChange: createVersionOnChange ?? true,
145
- ...(allowOverwriteExternalChanges !== undefined && { allowOverwriteExternalChanges }),
146
- };
147
- }
148
- }
149
- else {
150
- this.flowConfig = { name: 'Untitled Flow' };
151
- }
152
- }
153
- // ============================================================================
154
- // Configuration Methods
155
- // ============================================================================
156
- /**
157
- * Set the record configuration
158
- */
159
- withRecord(config) {
160
- this.recordConfig = config;
161
- return this;
162
- }
163
- /**
164
- * Set conversation messages
165
- */
166
- withMessages(messages) {
167
- this.messagesConfig = messages;
168
- return this;
169
- }
170
- /**
171
- * Set dispatch options
172
- */
173
- withOptions(options) {
174
- this.dispatchOptions = { ...this.dispatchOptions, ...options };
175
- return this;
176
- }
177
- // ============================================================================
178
- // Step Methods
179
- // ============================================================================
180
- /**
181
- * Add a prompt step
182
- */
183
- prompt(config) {
184
- this.addStep('prompt', config.name, {
185
- model: config.model,
186
- userPrompt: config.userPrompt,
187
- text: config.userPrompt,
188
- systemPrompt: config.systemPrompt,
189
- previousMessages: config.previousMessages,
190
- outputVariable: config.outputVariable,
191
- responseFormat: config.responseFormat,
192
- temperature: config.temperature,
193
- maxTokens: config.maxTokens,
194
- reasoning: config.reasoning,
195
- streamOutput: config.streamOutput,
196
- tools: config.tools,
197
- errorHandling: config.errorHandling,
198
- }, config.enabled);
199
- return this;
200
- }
201
- /**
202
- * Add a fetch URL step
203
- */
204
- fetchUrl(config) {
205
- this.addStep('fetch-url', config.name, {
206
- http: {
207
- url: config.url,
208
- method: config.method || 'GET',
209
- headers: config.headers,
210
- body: config.body,
211
- },
212
- responseType: config.responseType,
213
- markdownIfAvailable: config.markdownIfAvailable,
214
- fetchMethod: config.fetchMethod,
215
- firecrawl: config.firecrawl,
216
- outputVariable: config.outputVariable,
217
- errorHandling: config.errorHandling,
218
- streamOutput: config.streamOutput,
219
- }, config.enabled);
220
- return this;
221
- }
222
- /**
223
- * Add a transform data step
224
- */
225
- transformData(config) {
226
- this.addStep('transform-data', config.name, {
227
- script: config.script,
228
- outputVariable: config.outputVariable,
229
- streamOutput: config.streamOutput,
230
- }, config.enabled);
231
- return this;
232
- }
233
- /**
234
- * Add a set variable step
235
- */
236
- setVariable(config) {
237
- this.addStep('set-variable', config.name, {
238
- variableName: config.variableName,
239
- value: config.value,
240
- }, config.enabled);
241
- return this;
242
- }
243
- /**
244
- * Add a conditional step
245
- */
246
- conditional(config) {
247
- this.addStep('conditional', config.name, {
248
- condition: config.condition,
249
- trueSteps: config.trueSteps || [],
250
- falseSteps: config.falseSteps || [],
251
- }, config.enabled);
252
- return this;
253
- }
254
- /**
255
- * Add a search step
256
- */
257
- search(config) {
258
- this.addStep('search', config.name, {
259
- provider: config.provider,
260
- query: config.query,
261
- maxResults: config.maxResults,
262
- outputVariable: config.outputVariable,
263
- returnCitations: config.returnCitations,
264
- errorHandling: config.errorHandling,
265
- streamOutput: config.streamOutput,
266
- }, config.enabled);
267
- return this;
268
- }
269
- /**
270
- * Add a send email step
271
- */
272
- sendEmail(config) {
273
- this.addStep('send-email', config.name, {
274
- to: config.to,
275
- from: config.from || '{{_flow.id}}@runtype.email',
276
- subject: config.subject,
277
- html: config.html,
278
- outputVariable: config.outputVariable,
279
- errorHandling: config.errorHandling,
280
- streamOutput: config.streamOutput,
281
- }, config.enabled);
282
- return this;
283
- }
284
- /**
285
- * Add a send stream step
286
- */
287
- sendStream(config) {
288
- this.addStep('send-stream', config.name, {
289
- message: config.message,
290
- }, config.enabled);
291
- return this;
292
- }
293
- /**
294
- * Add a retrieve record step
295
- */
296
- retrieveRecord(config) {
297
- this.addStep('retrieve-record', config.name, {
298
- recordType: config.recordType,
299
- recordName: config.recordName,
300
- fieldsToInclude: config.fieldsToInclude,
301
- fieldsToExclude: config.fieldsToExclude,
302
- outputVariable: config.outputVariable,
303
- streamOutput: config.streamOutput,
304
- }, config.enabled);
305
- return this;
306
- }
307
- /**
308
- * Add an upsert record step
309
- */
310
- upsertRecord(config) {
311
- this.addStep('upsert-record', config.name, {
312
- recordType: config.recordType,
313
- recordName: config.recordName,
314
- sourceVariable: config.sourceVariable,
315
- mergeStrategy: config.mergeStrategy,
316
- outputVariable: config.outputVariable,
317
- errorHandling: config.errorHandling,
318
- streamOutput: config.streamOutput,
319
- }, config.enabled);
320
- return this;
321
- }
322
- /**
323
- * Add a vector search step
324
- */
325
- vectorSearch(config) {
326
- this.addStep('vector-search', config.name, {
327
- query: config.query,
328
- recordType: config.recordType,
329
- embeddingModel: config.embeddingModel,
330
- limit: config.limit,
331
- threshold: config.threshold,
332
- outputVariable: config.outputVariable,
333
- streamOutput: config.streamOutput,
334
- }, config.enabled);
335
- return this;
336
- }
337
- /**
338
- * Add a generate embedding step
339
- */
340
- generateEmbedding(config) {
341
- this.addStep('generate-embedding', config.name, {
342
- inputSource: 'text',
343
- text: config.text,
344
- embeddingModel: config.embeddingModel,
345
- maxLength: config.maxLength,
346
- outputVariable: config.outputVariable,
347
- streamOutput: config.streamOutput,
348
- }, config.enabled);
349
- return this;
350
- }
351
- /**
352
- * Add a wait until step
353
- */
354
- waitUntil(config) {
355
- this.addStep('wait-until', config.name, {
356
- delayMs: config.delayMs,
357
- continueOnTimeout: config.continueOnTimeout,
358
- poll: config.poll,
359
- outputVariable: config.outputVariable,
360
- errorHandling: config.errorHandling,
361
- streamOutput: config.streamOutput,
362
- }, config.enabled);
363
- return this;
364
- }
365
- /**
366
- * Add a send event step
367
- */
368
- sendEvent(config) {
369
- this.addStep('send-event', config.name, {
370
- provider: config.provider,
371
- eventName: config.eventName,
372
- properties: config.properties,
373
- outputVariable: config.outputVariable,
374
- errorHandling: config.errorHandling,
375
- streamOutput: config.streamOutput,
376
- }, config.enabled);
377
- return this;
378
- }
379
- /**
380
- * Add a send text step
381
- */
382
- sendText(config) {
383
- this.addStep('send-text', config.name, {
384
- to: config.to,
385
- from: config.from,
386
- message: config.message,
387
- outputVariable: config.outputVariable,
388
- errorHandling: config.errorHandling,
389
- streamOutput: config.streamOutput,
390
- }, config.enabled);
391
- return this;
392
- }
393
- /**
394
- * Add a fetch GitHub step
395
- */
396
- fetchGitHub(config) {
397
- this.addStep('fetch-github', config.name, {
398
- repository: config.repository,
399
- branch: config.branch,
400
- path: config.path,
401
- outputVariable: config.outputVariable,
402
- streamOutput: config.streamOutput,
403
- }, config.enabled);
404
- return this;
405
- }
406
- async stream(arg1, arg2) {
407
- const config = this.build();
408
- let callbacks;
409
- let localTools;
410
- if (arg1) {
411
- if ('localTools' in arg1) {
412
- localTools = arg1.localTools;
413
- }
414
- else {
415
- callbacks = arg1;
416
- if (arg2) {
417
- localTools = arg2.localTools;
418
- }
419
- }
420
- }
421
- // Handle local tools if provided
422
- if (localTools) {
423
- return this.runWithLocalTools(localTools, callbacks);
424
- }
425
- config.options = { ...config.options, streamResponse: true };
426
- const client = this.getClient();
427
- const response = await client.dispatch(config);
428
- const result = new flow_result_1.FlowResult(response);
429
- // If callbacks provided, process immediately
430
- if (callbacks) {
431
- await result.stream(callbacks);
432
- }
433
- return result;
434
- }
435
- /**
436
- * Execute the flow and wait for complete result (no streaming)
437
- *
438
- * Returns a FlowResult after all steps have completed.
439
- *
440
- * @example
441
- * ```typescript
442
- * const result = await Runtype.flows.use('flow_123')
443
- * .withRecord({ ... })
444
- * .result()
445
- *
446
- * const analysis = await result.getResult('Analyze')
447
- * const allResults = await result.getAllResults()
448
- * ```
449
- */
450
- async result(options) {
451
- const config = this.build();
452
- // Handle local tools if provided
453
- if (options?.localTools) {
454
- return this.runWithLocalTools(options.localTools);
455
- }
456
- config.options = { ...config.options, streamResponse: true };
457
- const client = this.getClient();
458
- const response = await client.dispatch(config);
459
- const result = new flow_result_1.FlowResult(response);
460
- // Pre-process the stream to cache results
461
- await result.getSummary();
462
- return result;
463
- }
464
- /**
465
- * Execute the flow with local tools (automatic pause/resume loop)
466
- *
467
- * @param localTools - Map of tool names to async functions that execute the tool logic
468
- * @returns The final result of the flow execution
469
- */
470
- async runWithLocalTools(localTools, callbacks) {
471
- const config = this.build();
472
- const isStreaming = !!callbacks;
473
- // Force options
474
- config.options = {
475
- ...config.options,
476
- streamResponse: isStreaming,
477
- };
478
- const client = this.getClient();
479
- // Accumulated results across pause/resume cycles - moved outside processStep
480
- // so results persist when flow pauses and resumes
481
- const accumulatedSummary = {
482
- results: new Map(),
483
- success: true,
484
- };
485
- // Helper to process a step result (either from stream or JSON)
486
- const processStep = async (response) => {
487
- if (isStreaming) {
488
- // Stream processing
489
- let pausedState = null;
490
- // Wrap user callbacks to intercept paused event
491
- const wrappedCallbacks = {
492
- ...callbacks,
493
- onFlowStart: (event) => callbacks?.onFlowStart?.(event),
494
- onStepStart: (event) => callbacks?.onStepStart?.(event),
495
- onStepChunk: (chunk, event) => callbacks?.onStepChunk?.(chunk, event),
496
- onStepComplete: (result, event) => callbacks?.onStepComplete?.(result, event),
497
- onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
498
- onError: (error) => callbacks?.onError?.(error),
499
- };
500
- // Use streamEvents from stream-utils
501
- const { streamEvents } = await Promise.resolve().then(() => __importStar(require('./stream-utils')));
502
- try {
503
- for await (const event of streamEvents(response)) {
504
- if (event.type === 'flow_await') {
505
- pausedState = {
506
- toolName: event.toolName,
507
- parameters: event.parameters,
508
- executionId: event.executionId,
509
- };
510
- }
511
- if (event.type === 'step_await') {
512
- pausedState = {
513
- toolName: event.toolName,
514
- parameters: event.parameters,
515
- executionId: event.executionId,
516
- };
517
- }
518
- // Handle standard events via callbacks
519
- switch (event.type) {
520
- case 'flow_start':
521
- wrappedCallbacks.onFlowStart?.(event);
522
- break;
523
- case 'step_start':
524
- wrappedCallbacks.onStepStart?.(event);
525
- break;
526
- case 'step_delta': {
527
- // Normalize API's 'text' field to 'chunk' for consistency
528
- const chunkText = event.chunk || event.text || '';
529
- wrappedCallbacks.onStepChunk?.(chunkText, event);
530
- break;
531
- }
532
- case 'step_complete': {
533
- // Accumulate results in the outer summary that persists across pause/resume
534
- accumulatedSummary.results?.set(event.name, event.result);
535
- wrappedCallbacks.onStepComplete?.(event.result, event);
536
- break;
537
- }
538
- case 'flow_complete':
539
- wrappedCallbacks.onFlowComplete?.(event);
540
- break;
541
- case 'flow_error':
542
- wrappedCallbacks.onError?.(new Error(event.error));
543
- break;
544
- }
545
- }
546
- }
547
- catch (e) {
548
- wrappedCallbacks.onError?.(e instanceof Error ? e : new Error(String(e)));
549
- throw e;
550
- }
551
- if (pausedState) {
552
- return {
553
- done: false,
554
- result: { status: 'paused', pausedReason: { type: 'local_action', ...pausedState } },
555
- };
556
- }
557
- return { done: true, result: accumulatedSummary };
558
- }
559
- else {
560
- // Non-streaming (JSON)
561
- const data = await response.json();
562
- return {
563
- done: data.status !== 'paused',
564
- result: data,
565
- };
566
- }
567
- };
568
- // Initial dispatch
569
- let currentResponse;
570
- if (isStreaming) {
571
- currentResponse = await client.dispatch(config);
572
- }
573
- else {
574
- const data = await client.post('/dispatch', config);
575
- currentResponse = new Response(JSON.stringify(data), {
576
- headers: { 'content-type': 'application/json' },
577
- });
578
- }
579
- // Loop
580
- while (true) {
581
- const { done, result } = await processStep(currentResponse);
582
- if (done) {
583
- if (isStreaming) {
584
- // Create FlowResult with summary
585
- const finalResponse = new Response(JSON.stringify(result), {
586
- headers: { 'content-type': 'application/json' },
587
- });
588
- return new flow_result_1.FlowResult(finalResponse, result);
589
- }
590
- return new flow_result_1.FlowResult(new Response(JSON.stringify(result), { headers: { 'content-type': 'application/json' } }));
591
- }
592
- // Handle Pause
593
- if (result.status === 'paused' && result.pausedReason?.type === 'local_action') {
594
- const { toolName, parameters, executionId } = result.pausedReason;
595
- if (!localTools[toolName]) {
596
- throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
597
- }
598
- try {
599
- // Execute local tool logic
600
- const toolResult = await localTools[toolName](parameters);
601
- // Resume flow execution - API expects camelCase field names
602
- const resumeData = {
603
- executionId: executionId,
604
- toolOutputs: { [toolName]: toolResult },
605
- streamResponse: isStreaming,
606
- };
607
- if (isStreaming) {
608
- currentResponse = await client.requestStream('/dispatch/resume', {
609
- method: 'POST',
610
- body: JSON.stringify(resumeData),
611
- });
612
- }
613
- else {
614
- const data = await client.post('/dispatch/resume', resumeData);
615
- currentResponse = new Response(JSON.stringify(data), {
616
- headers: { 'content-type': 'application/json' },
617
- });
618
- }
619
- }
620
- catch (error) {
621
- throw new Error(`Error executing local tool "${toolName}": ${error instanceof Error ? error.message : String(error)}`);
622
- }
623
- }
624
- else {
625
- break;
626
- }
627
- }
628
- throw new Error('Unexpected end of flow execution loop');
629
- }
630
- build() {
631
- const flowMode = this.mode === 'existing' ? 'existing' : this.mode;
632
- const flow = this.existingFlowId
633
- ? { id: this.existingFlowId }
634
- : { name: this.flowConfig.name, steps: this.steps };
635
- const request = { flow };
636
- if (this.recordConfig) {
637
- request.record = this.recordConfig;
638
- }
639
- if (this.messagesConfig) {
640
- request.messages = this.messagesConfig;
641
- }
642
- const options = {
643
- flowMode,
644
- ...this.dispatchOptions,
645
- };
646
- // Auto-detect recordMode based on record config if not explicitly set
647
- if (this.recordConfig && !this.dispatchOptions.recordMode) {
648
- if (this.recordConfig.id) {
649
- options.recordMode = 'existing';
650
- }
651
- else if (this.recordConfig.name || this.recordConfig.type) {
652
- options.recordMode = 'create';
653
- }
654
- else {
655
- options.recordMode = 'virtual';
656
- }
657
- }
658
- if (this.mode === 'upsert' && Object.keys(this.upsertOptions).length > 0) {
659
- options.upsertOptions = this.upsertOptions;
660
- }
661
- request.options = options;
662
- return request;
663
- }
664
- // ============================================================================
665
- // Private Helpers
666
- // ============================================================================
667
- addStep(type, name, config, enabled = true) {
668
- this.stepCounter++;
669
- const cleanConfig = {};
670
- for (const [key, value] of Object.entries(config)) {
671
- if (value !== undefined) {
672
- cleanConfig[key] = value;
673
- }
674
- }
675
- this.steps.push({
676
- id: `step-${this.stepCounter}`,
677
- type,
678
- name,
679
- order: this.stepCounter,
680
- enabled,
681
- config: cleanConfig,
682
- });
683
- }
684
- }
685
- exports.RuntypeFlowBuilder = RuntypeFlowBuilder;
686
- //# sourceMappingURL=flows-namespace.js.map