@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.
Files changed (62) hide show
  1. package/README.md +398 -0
  2. package/dist/batch-builder.d.ts +106 -0
  3. package/dist/batch-builder.d.ts.map +1 -0
  4. package/dist/batch-builder.js +124 -0
  5. package/dist/batch-builder.js.map +1 -0
  6. package/dist/batches-namespace.d.ts +132 -0
  7. package/dist/batches-namespace.d.ts.map +1 -0
  8. package/dist/batches-namespace.js +128 -0
  9. package/dist/batches-namespace.js.map +1 -0
  10. package/dist/client.d.ts +121 -0
  11. package/dist/client.d.ts.map +1 -0
  12. package/dist/client.js +485 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/endpoints.d.ts +560 -0
  15. package/dist/endpoints.d.ts.map +1 -0
  16. package/dist/endpoints.js +725 -0
  17. package/dist/endpoints.js.map +1 -0
  18. package/dist/eval-builder.d.ts +216 -0
  19. package/dist/eval-builder.d.ts.map +1 -0
  20. package/dist/eval-builder.js +225 -0
  21. package/dist/eval-builder.js.map +1 -0
  22. package/dist/evals-namespace.d.ts +205 -0
  23. package/dist/evals-namespace.d.ts.map +1 -0
  24. package/dist/evals-namespace.js +208 -0
  25. package/dist/evals-namespace.js.map +1 -0
  26. package/dist/flow-builder.d.ts +620 -0
  27. package/dist/flow-builder.d.ts.map +1 -0
  28. package/dist/flow-builder.js +565 -0
  29. package/dist/flow-builder.js.map +1 -0
  30. package/dist/flow-result.d.ts +117 -0
  31. package/dist/flow-result.d.ts.map +1 -0
  32. package/dist/flow-result.js +175 -0
  33. package/dist/flow-result.js.map +1 -0
  34. package/dist/flows-namespace.d.ts +430 -0
  35. package/dist/flows-namespace.d.ts.map +1 -0
  36. package/dist/flows-namespace.js +679 -0
  37. package/dist/flows-namespace.js.map +1 -0
  38. package/dist/index.d.ts +23 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +76 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/prompts-namespace.d.ts +236 -0
  43. package/dist/prompts-namespace.d.ts.map +1 -0
  44. package/dist/prompts-namespace.js +222 -0
  45. package/dist/prompts-namespace.js.map +1 -0
  46. package/dist/runtype.d.ts +232 -0
  47. package/dist/runtype.d.ts.map +1 -0
  48. package/dist/runtype.js +367 -0
  49. package/dist/runtype.js.map +1 -0
  50. package/dist/stream-utils.d.ts +58 -0
  51. package/dist/stream-utils.d.ts.map +1 -0
  52. package/dist/stream-utils.js +348 -0
  53. package/dist/stream-utils.js.map +1 -0
  54. package/dist/transform.d.ts +21 -0
  55. package/dist/transform.d.ts.map +1 -0
  56. package/dist/transform.js +170 -0
  57. package/dist/transform.js.map +1 -0
  58. package/dist/types.d.ts +626 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +7 -0
  61. package/dist/types.js.map +1 -0
  62. package/package.json +61 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * FlowResult - Wrapper for streaming flow execution responses
3
+ *
4
+ * Provides convenient methods for processing streaming responses
5
+ * from the Runtype API dispatch endpoint.
6
+ */
7
+ import type { StreamCallbacks, FlowSummary } from './flow-builder';
8
+ /**
9
+ * Result wrapper for flow execution
10
+ *
11
+ * Provides multiple ways to consume the streaming response:
12
+ * - `.stream(callbacks)` - Process with callbacks
13
+ * - `.getResult(stepName)` - Get result from a specific step
14
+ * - `.getAllResults()` - Get all step results
15
+ * - `.raw` - Access the raw Response for manual handling
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const result = await flow.run(apiClient, options)
20
+ *
21
+ * // Option 1: Process with callbacks
22
+ * const summary = await result.stream({
23
+ * onStepChunk: (chunk) => process.stdout.write(chunk),
24
+ * })
25
+ *
26
+ * // Option 2: Just get a specific step's result
27
+ * const analysis = await result.getResult('Analyze Data')
28
+ *
29
+ * // Option 3: Get all results
30
+ * const allResults = await result.getAllResults()
31
+ * ```
32
+ */
33
+ export declare class FlowResult {
34
+ private response;
35
+ private consumed;
36
+ private cachedSummary;
37
+ constructor(response: Response, summary?: FlowSummary);
38
+ /**
39
+ * Get the raw Response object for manual handling
40
+ *
41
+ * Note: The response body can only be consumed once.
42
+ * Using this will prevent using other methods like stream() or getResult().
43
+ */
44
+ get raw(): Response;
45
+ /**
46
+ * Check if the response has already been consumed
47
+ */
48
+ get isConsumed(): boolean;
49
+ /**
50
+ * Process the streaming response with callbacks
51
+ *
52
+ * @param callbacks - Callbacks for different event types
53
+ * @returns Promise resolving to FlowSummary when complete
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const summary = await result.stream({
58
+ * onStepStart: (event) => console.log('Starting:', event.name),
59
+ * onStepChunk: (chunk) => process.stdout.write(chunk),
60
+ * onStepComplete: (result, event) => console.log('Done:', event.name),
61
+ * onFlowComplete: (event) => console.log('Flow complete!'),
62
+ * })
63
+ * ```
64
+ */
65
+ stream(callbacks?: StreamCallbacks): Promise<FlowSummary>;
66
+ /**
67
+ * Get the result from a specific step by its name
68
+ *
69
+ * Matches against the `name` property you set when creating the step.
70
+ * - **Case-sensitive**: `'Analyze'` ≠ `'analyze'`
71
+ * - **Exact match only**: no partial or fuzzy matching
72
+ * - Returns `undefined` if no step with that name is found
73
+ *
74
+ * @param stepName - The exact step name (from the `name` property when creating the step)
75
+ * @returns The step's result, or undefined if not found
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // When building:
80
+ * .prompt({ name: 'Analyze Screenshot', model: 'gpt-4', ... })
81
+ *
82
+ * // When retrieving (must match exactly):
83
+ * const analysis = await result.getResult('Analyze Screenshot') // ✓ Works
84
+ * const analysis = await result.getResult('analyze screenshot') // ✗ undefined
85
+ * ```
86
+ */
87
+ getResult(stepName: string): Promise<any>;
88
+ /**
89
+ * Get all step results as a Map
90
+ *
91
+ * @returns Map of step name to result
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const allResults = await result.getAllResults()
96
+ * for (const [stepName, result] of allResults) {
97
+ * console.log(stepName, result)
98
+ * }
99
+ * ```
100
+ */
101
+ getAllResults(): Promise<Map<string, any>>;
102
+ /**
103
+ * Get the flow summary after processing
104
+ *
105
+ * @returns FlowSummary with execution details
106
+ */
107
+ getSummary(): Promise<FlowSummary>;
108
+ /**
109
+ * Ensure the stream has been processed and return the summary
110
+ */
111
+ private ensureSummary;
112
+ /**
113
+ * Ensure the response hasn't been consumed yet
114
+ */
115
+ private ensureNotConsumed;
116
+ }
117
+ //# sourceMappingURL=flow-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-result.d.ts","sourceRoot":"","sources":["../src/flow-result.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAGlE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,aAAa,CAA2B;gBAEpC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,WAAW;IAQrD;;;;;OAKG;IACH,IAAI,GAAG,IAAI,QAAQ,CAElB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CAAC,SAAS,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAyBnE;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAW/C;;;;;;;;;;;;OAYG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAKhD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAIxC;;OAEG;YACW,aAAa;IAS3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAS1B"}
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ /**
3
+ * FlowResult - Wrapper for streaming flow execution responses
4
+ *
5
+ * Provides convenient methods for processing streaming responses
6
+ * from the Runtype API dispatch endpoint.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FlowResult = void 0;
10
+ const stream_utils_1 = require("./stream-utils");
11
+ /**
12
+ * Result wrapper for flow execution
13
+ *
14
+ * Provides multiple ways to consume the streaming response:
15
+ * - `.stream(callbacks)` - Process with callbacks
16
+ * - `.getResult(stepName)` - Get result from a specific step
17
+ * - `.getAllResults()` - Get all step results
18
+ * - `.raw` - Access the raw Response for manual handling
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const result = await flow.run(apiClient, options)
23
+ *
24
+ * // Option 1: Process with callbacks
25
+ * const summary = await result.stream({
26
+ * onStepChunk: (chunk) => process.stdout.write(chunk),
27
+ * })
28
+ *
29
+ * // Option 2: Just get a specific step's result
30
+ * const analysis = await result.getResult('Analyze Data')
31
+ *
32
+ * // Option 3: Get all results
33
+ * const allResults = await result.getAllResults()
34
+ * ```
35
+ */
36
+ class FlowResult {
37
+ constructor(response, summary) {
38
+ this.consumed = false;
39
+ this.cachedSummary = null;
40
+ this.response = response;
41
+ if (summary) {
42
+ this.cachedSummary = summary;
43
+ this.consumed = true;
44
+ }
45
+ }
46
+ /**
47
+ * Get the raw Response object for manual handling
48
+ *
49
+ * Note: The response body can only be consumed once.
50
+ * Using this will prevent using other methods like stream() or getResult().
51
+ */
52
+ get raw() {
53
+ return this.response;
54
+ }
55
+ /**
56
+ * Check if the response has already been consumed
57
+ */
58
+ get isConsumed() {
59
+ return this.consumed;
60
+ }
61
+ /**
62
+ * Process the streaming response with callbacks
63
+ *
64
+ * @param callbacks - Callbacks for different event types
65
+ * @returns Promise resolving to FlowSummary when complete
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const summary = await result.stream({
70
+ * onStepStart: (event) => console.log('Starting:', event.name),
71
+ * onStepChunk: (chunk) => process.stdout.write(chunk),
72
+ * onStepComplete: (result, event) => console.log('Done:', event.name),
73
+ * onFlowComplete: (event) => console.log('Flow complete!'),
74
+ * })
75
+ * ```
76
+ */
77
+ async stream(callbacks = {}) {
78
+ if (this.consumed && this.cachedSummary) {
79
+ // Replay events from cached summary if available?
80
+ // For now, just return the summary immediately as we can't replay the stream.
81
+ // Callbacks for completion might be relevant though.
82
+ if (callbacks.onFlowComplete) {
83
+ callbacks.onFlowComplete({
84
+ type: 'flow_complete',
85
+ flowId: this.cachedSummary.flowId,
86
+ totalSteps: this.cachedSummary.totalSteps,
87
+ successfulSteps: this.cachedSummary.successfulSteps,
88
+ failedSteps: this.cachedSummary.failedSteps,
89
+ executionTime: this.cachedSummary.executionTime
90
+ });
91
+ }
92
+ return this.cachedSummary;
93
+ }
94
+ this.ensureNotConsumed();
95
+ this.consumed = true;
96
+ this.cachedSummary = await (0, stream_utils_1.processStream)(this.response, callbacks);
97
+ return this.cachedSummary;
98
+ }
99
+ /**
100
+ * Get the result from a specific step by its name
101
+ *
102
+ * Matches against the `name` property you set when creating the step.
103
+ * - **Case-sensitive**: `'Analyze'` ≠ `'analyze'`
104
+ * - **Exact match only**: no partial or fuzzy matching
105
+ * - Returns `undefined` if no step with that name is found
106
+ *
107
+ * @param stepName - The exact step name (from the `name` property when creating the step)
108
+ * @returns The step's result, or undefined if not found
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // When building:
113
+ * .prompt({ name: 'Analyze Screenshot', model: 'gpt-4', ... })
114
+ *
115
+ * // When retrieving (must match exactly):
116
+ * const analysis = await result.getResult('Analyze Screenshot') // ✓ Works
117
+ * const analysis = await result.getResult('analyze screenshot') // ✗ undefined
118
+ * ```
119
+ */
120
+ async getResult(stepName) {
121
+ const summary = await this.ensureSummary();
122
+ // Exact name match only
123
+ if (summary.results.has(stepName)) {
124
+ return summary.results.get(stepName);
125
+ }
126
+ return undefined;
127
+ }
128
+ /**
129
+ * Get all step results as a Map
130
+ *
131
+ * @returns Map of step name to result
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const allResults = await result.getAllResults()
136
+ * for (const [stepName, result] of allResults) {
137
+ * console.log(stepName, result)
138
+ * }
139
+ * ```
140
+ */
141
+ async getAllResults() {
142
+ const summary = await this.ensureSummary();
143
+ return summary.results;
144
+ }
145
+ /**
146
+ * Get the flow summary after processing
147
+ *
148
+ * @returns FlowSummary with execution details
149
+ */
150
+ async getSummary() {
151
+ return this.ensureSummary();
152
+ }
153
+ /**
154
+ * Ensure the stream has been processed and return the summary
155
+ */
156
+ async ensureSummary() {
157
+ if (this.cachedSummary) {
158
+ return this.cachedSummary;
159
+ }
160
+ // Process the stream silently to get results
161
+ return this.stream({});
162
+ }
163
+ /**
164
+ * Ensure the response hasn't been consumed yet
165
+ */
166
+ ensureNotConsumed() {
167
+ if (this.consumed) {
168
+ throw new Error('Response has already been consumed. ' +
169
+ 'The streaming response body can only be read once. ' +
170
+ 'Use the cached results from stream(), getResult(), or getAllResults() instead.');
171
+ }
172
+ }
173
+ }
174
+ exports.FlowResult = FlowResult;
175
+ //# sourceMappingURL=flow-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-result.js","sourceRoot":"","sources":["../src/flow-result.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,iDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,UAAU;IAKrB,YAAY,QAAkB,EAAE,OAAqB;QAH7C,aAAQ,GAAG,KAAK,CAAA;QAChB,kBAAa,GAAuB,IAAI,CAAA;QAG9C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,aAAa,GAAG,OAAO,CAAA;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACtB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QAC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