@vertesia/client 0.80.1 → 0.81.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 (246) hide show
  1. package/lib/cjs/AccountApi.js +85 -0
  2. package/lib/cjs/AccountApi.js.map +1 -0
  3. package/lib/cjs/AccountsApi.js +16 -0
  4. package/lib/cjs/AccountsApi.js.map +1 -0
  5. package/lib/cjs/AnalyticsApi.js +13 -0
  6. package/lib/cjs/AnalyticsApi.js.map +1 -0
  7. package/lib/cjs/ApiKeysApi.js +63 -0
  8. package/lib/cjs/ApiKeysApi.js.map +1 -0
  9. package/lib/cjs/AppsApi.js +119 -0
  10. package/lib/cjs/AppsApi.js.map +1 -0
  11. package/lib/cjs/CommandsApi.js +19 -0
  12. package/lib/cjs/CommandsApi.js.map +1 -0
  13. package/lib/cjs/EnvironmentsApi.js +58 -0
  14. package/lib/cjs/EnvironmentsApi.js.map +1 -0
  15. package/lib/cjs/GroupsApi.js +78 -0
  16. package/lib/cjs/GroupsApi.js.map +1 -0
  17. package/lib/cjs/IamApi.js +53 -0
  18. package/lib/cjs/IamApi.js.map +1 -0
  19. package/lib/cjs/InteractionBase.js +44 -0
  20. package/lib/cjs/InteractionBase.js.map +1 -0
  21. package/lib/cjs/InteractionCatalogApi.js +64 -0
  22. package/lib/cjs/InteractionCatalogApi.js.map +1 -0
  23. package/lib/cjs/InteractionOutput.js +300 -0
  24. package/lib/cjs/InteractionOutput.js.map +1 -0
  25. package/lib/cjs/InteractionResult.example.js +57 -0
  26. package/lib/cjs/InteractionResult.example.js.map +1 -0
  27. package/lib/cjs/InteractionsApi.js +243 -0
  28. package/lib/cjs/InteractionsApi.js.map +1 -0
  29. package/lib/cjs/ProjectsApi.js +53 -0
  30. package/lib/cjs/ProjectsApi.js.map +1 -0
  31. package/lib/cjs/PromptsApi.js +133 -0
  32. package/lib/cjs/PromptsApi.js.map +1 -0
  33. package/lib/cjs/RefsApi.js +14 -0
  34. package/lib/cjs/RefsApi.js.map +1 -0
  35. package/lib/cjs/RunsApi.js +113 -0
  36. package/lib/cjs/RunsApi.js.map +1 -0
  37. package/lib/cjs/SkillsApi.js +39 -0
  38. package/lib/cjs/SkillsApi.js.map +1 -0
  39. package/lib/cjs/StreamSource.js +17 -0
  40. package/lib/cjs/StreamSource.js.map +1 -0
  41. package/lib/cjs/TrainingApi.js +54 -0
  42. package/lib/cjs/TrainingApi.js.map +1 -0
  43. package/lib/cjs/UsersApi.js +13 -0
  44. package/lib/cjs/UsersApi.js.map +1 -0
  45. package/lib/cjs/client.js +351 -0
  46. package/lib/cjs/client.js.map +1 -0
  47. package/lib/cjs/execute.js +158 -0
  48. package/lib/cjs/execute.js.map +1 -0
  49. package/lib/cjs/index.js +22 -0
  50. package/lib/cjs/index.js.map +1 -0
  51. package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
  52. package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
  53. package/lib/cjs/nodejs/index.js +18 -0
  54. package/lib/cjs/nodejs/index.js.map +1 -0
  55. package/lib/cjs/package.json +3 -0
  56. package/lib/cjs/store/AnalyzeDocApi.js +56 -0
  57. package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
  58. package/lib/cjs/store/CollectionsApi.js +131 -0
  59. package/lib/cjs/store/CollectionsApi.js.map +1 -0
  60. package/lib/cjs/store/CommandsApi.js +17 -0
  61. package/lib/cjs/store/CommandsApi.js.map +1 -0
  62. package/lib/cjs/store/EmbeddingsApi.js +29 -0
  63. package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
  64. package/lib/cjs/store/FilesApi.js +225 -0
  65. package/lib/cjs/store/FilesApi.js.map +1 -0
  66. package/lib/cjs/store/ObjectsApi.js +283 -0
  67. package/lib/cjs/store/ObjectsApi.js.map +1 -0
  68. package/lib/cjs/store/TypesApi.js +57 -0
  69. package/lib/cjs/store/TypesApi.js.map +1 -0
  70. package/lib/cjs/store/WorkersApi.js +16 -0
  71. package/lib/cjs/store/WorkersApi.js.map +1 -0
  72. package/lib/cjs/store/WorkflowsApi.js +425 -0
  73. package/lib/cjs/store/WorkflowsApi.js.map +1 -0
  74. package/lib/cjs/store/client.js +71 -0
  75. package/lib/cjs/store/client.js.map +1 -0
  76. package/lib/cjs/store/errors.js +11 -0
  77. package/lib/cjs/store/errors.js.map +1 -0
  78. package/lib/cjs/store/index.js +23 -0
  79. package/lib/cjs/store/index.js.map +1 -0
  80. package/lib/cjs/store/version.js +6 -0
  81. package/lib/cjs/store/version.js.map +1 -0
  82. package/lib/esm/AccountApi.js +82 -0
  83. package/lib/esm/AccountApi.js.map +1 -0
  84. package/lib/esm/AccountsApi.js +13 -0
  85. package/lib/esm/AccountsApi.js.map +1 -0
  86. package/lib/esm/AnalyticsApi.js +10 -0
  87. package/lib/esm/AnalyticsApi.js.map +1 -0
  88. package/lib/esm/ApiKeysApi.js +59 -0
  89. package/lib/esm/ApiKeysApi.js.map +1 -0
  90. package/lib/esm/AppsApi.js +116 -0
  91. package/lib/esm/AppsApi.js.map +1 -0
  92. package/lib/esm/CommandsApi.js +16 -0
  93. package/lib/esm/CommandsApi.js.map +1 -0
  94. package/lib/esm/EnvironmentsApi.js +55 -0
  95. package/lib/esm/EnvironmentsApi.js.map +1 -0
  96. package/lib/esm/GroupsApi.js +74 -0
  97. package/lib/esm/GroupsApi.js.map +1 -0
  98. package/lib/esm/IamApi.js +47 -0
  99. package/lib/esm/IamApi.js.map +1 -0
  100. package/lib/esm/InteractionBase.js +40 -0
  101. package/lib/esm/InteractionBase.js.map +1 -0
  102. package/lib/esm/InteractionCatalogApi.js +60 -0
  103. package/lib/esm/InteractionCatalogApi.js.map +1 -0
  104. package/lib/esm/InteractionOutput.js +293 -0
  105. package/lib/esm/InteractionOutput.js.map +1 -0
  106. package/lib/esm/InteractionResult.example.js +55 -0
  107. package/lib/esm/InteractionResult.example.js.map +1 -0
  108. package/lib/esm/InteractionsApi.js +240 -0
  109. package/lib/esm/InteractionsApi.js.map +1 -0
  110. package/lib/esm/ProjectsApi.js +50 -0
  111. package/lib/esm/ProjectsApi.js.map +1 -0
  112. package/lib/esm/PromptsApi.js +130 -0
  113. package/lib/esm/PromptsApi.js.map +1 -0
  114. package/lib/esm/RefsApi.js +10 -0
  115. package/lib/esm/RefsApi.js.map +1 -0
  116. package/lib/esm/RunsApi.js +109 -0
  117. package/lib/esm/RunsApi.js.map +1 -0
  118. package/lib/esm/SkillsApi.js +36 -0
  119. package/lib/esm/SkillsApi.js.map +1 -0
  120. package/lib/esm/StreamSource.js +13 -0
  121. package/lib/esm/StreamSource.js.map +1 -0
  122. package/lib/esm/TrainingApi.js +51 -0
  123. package/lib/esm/TrainingApi.js.map +1 -0
  124. package/lib/esm/UsersApi.js +10 -0
  125. package/lib/esm/UsersApi.js.map +1 -0
  126. package/lib/esm/client.js +342 -0
  127. package/lib/esm/client.js.map +1 -0
  128. package/lib/esm/execute.js +118 -0
  129. package/lib/esm/execute.js.map +1 -0
  130. package/lib/esm/index.js +6 -0
  131. package/lib/esm/index.js.map +1 -0
  132. package/lib/esm/nodejs/NodeStreamSource.js +41 -0
  133. package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
  134. package/lib/esm/nodejs/index.js +2 -0
  135. package/lib/esm/nodejs/index.js.map +1 -0
  136. package/lib/esm/store/AnalyzeDocApi.js +52 -0
  137. package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
  138. package/lib/esm/store/CollectionsApi.js +127 -0
  139. package/lib/esm/store/CollectionsApi.js.map +1 -0
  140. package/lib/esm/store/CommandsApi.js +13 -0
  141. package/lib/esm/store/CommandsApi.js.map +1 -0
  142. package/lib/esm/store/EmbeddingsApi.js +25 -0
  143. package/lib/esm/store/EmbeddingsApi.js.map +1 -0
  144. package/lib/esm/store/FilesApi.js +219 -0
  145. package/lib/esm/store/FilesApi.js.map +1 -0
  146. package/lib/esm/store/ObjectsApi.js +279 -0
  147. package/lib/esm/store/ObjectsApi.js.map +1 -0
  148. package/lib/esm/store/TypesApi.js +53 -0
  149. package/lib/esm/store/TypesApi.js.map +1 -0
  150. package/lib/esm/store/WorkersApi.js +12 -0
  151. package/lib/esm/store/WorkersApi.js.map +1 -0
  152. package/lib/esm/store/WorkflowsApi.js +419 -0
  153. package/lib/esm/store/WorkflowsApi.js.map +1 -0
  154. package/lib/esm/store/client.js +67 -0
  155. package/lib/esm/store/client.js.map +1 -0
  156. package/lib/esm/store/errors.js +7 -0
  157. package/lib/esm/store/errors.js.map +1 -0
  158. package/lib/esm/store/index.js +7 -0
  159. package/lib/esm/store/index.js.map +1 -0
  160. package/lib/esm/store/version.js +3 -0
  161. package/lib/esm/store/version.js.map +1 -0
  162. package/lib/tsconfig.tsbuildinfo +1 -0
  163. package/lib/types/AccountApi.d.ts +59 -0
  164. package/lib/types/AccountApi.d.ts.map +1 -0
  165. package/lib/types/AccountsApi.d.ts +7 -0
  166. package/lib/types/AccountsApi.d.ts.map +1 -0
  167. package/lib/types/AnalyticsApi.d.ts +6 -0
  168. package/lib/types/AnalyticsApi.d.ts.map +1 -0
  169. package/lib/types/ApiKeysApi.d.ts +42 -0
  170. package/lib/types/ApiKeysApi.d.ts.map +1 -0
  171. package/lib/types/AppsApi.d.ts +65 -0
  172. package/lib/types/AppsApi.d.ts.map +1 -0
  173. package/lib/types/CommandsApi.d.ts +10 -0
  174. package/lib/types/CommandsApi.d.ts.map +1 -0
  175. package/lib/types/EnvironmentsApi.d.ts +30 -0
  176. package/lib/types/EnvironmentsApi.d.ts.map +1 -0
  177. package/lib/types/GroupsApi.d.ts +65 -0
  178. package/lib/types/GroupsApi.d.ts.map +1 -0
  179. package/lib/types/IamApi.d.ts +41 -0
  180. package/lib/types/IamApi.d.ts.map +1 -0
  181. package/lib/types/InteractionBase.d.ts +22 -0
  182. package/lib/types/InteractionBase.d.ts.map +1 -0
  183. package/lib/types/InteractionCatalogApi.d.ts +36 -0
  184. package/lib/types/InteractionCatalogApi.d.ts.map +1 -0
  185. package/lib/types/InteractionOutput.d.ts +174 -0
  186. package/lib/types/InteractionOutput.d.ts.map +1 -0
  187. package/lib/types/InteractionResult.example.d.ts +6 -0
  188. package/lib/types/InteractionResult.example.d.ts.map +1 -0
  189. package/lib/types/InteractionsApi.d.ts +165 -0
  190. package/lib/types/InteractionsApi.d.ts.map +1 -0
  191. package/lib/types/ProjectsApi.d.ts +18 -0
  192. package/lib/types/ProjectsApi.d.ts.map +1 -0
  193. package/lib/types/PromptsApi.d.ts +106 -0
  194. package/lib/types/PromptsApi.d.ts.map +1 -0
  195. package/lib/types/RefsApi.d.ts +6 -0
  196. package/lib/types/RefsApi.d.ts.map +1 -0
  197. package/lib/types/RunsApi.d.ts +79 -0
  198. package/lib/types/RunsApi.d.ts.map +1 -0
  199. package/lib/types/SkillsApi.d.ts +26 -0
  200. package/lib/types/SkillsApi.d.ts.map +1 -0
  201. package/lib/types/StreamSource.d.ts +7 -0
  202. package/lib/types/StreamSource.d.ts.map +1 -0
  203. package/lib/types/TrainingApi.d.ts +27 -0
  204. package/lib/types/TrainingApi.d.ts.map +1 -0
  205. package/lib/types/UsersApi.d.ts +6 -0
  206. package/lib/types/UsersApi.d.ts.map +1 -0
  207. package/lib/types/client.d.ts +125 -0
  208. package/lib/types/client.d.ts.map +1 -0
  209. package/lib/types/execute.d.ts +37 -0
  210. package/lib/types/execute.d.ts.map +1 -0
  211. package/lib/types/index.d.ts +10 -0
  212. package/lib/types/index.d.ts.map +1 -0
  213. package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
  214. package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
  215. package/lib/types/nodejs/index.d.ts +1 -0
  216. package/lib/types/nodejs/index.d.ts.map +1 -0
  217. package/lib/types/store/AnalyzeDocApi.d.ts +17 -0
  218. package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
  219. package/lib/types/store/CollectionsApi.d.ts +82 -0
  220. package/lib/types/store/CollectionsApi.d.ts.map +1 -0
  221. package/lib/types/store/CommandsApi.d.ts +10 -0
  222. package/lib/types/store/CommandsApi.d.ts.map +1 -0
  223. package/lib/types/store/EmbeddingsApi.d.ts +12 -0
  224. package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
  225. package/lib/types/store/FilesApi.d.ts +103 -0
  226. package/lib/types/store/FilesApi.d.ts.map +1 -0
  227. package/lib/types/store/ObjectsApi.d.ts +117 -0
  228. package/lib/types/store/ObjectsApi.d.ts.map +1 -0
  229. package/lib/types/store/TypesApi.d.ts +23 -0
  230. package/lib/types/store/TypesApi.d.ts.map +1 -0
  231. package/lib/types/store/WorkersApi.d.ts +6 -0
  232. package/lib/types/store/WorkersApi.d.ts.map +1 -0
  233. package/lib/types/store/WorkflowsApi.d.ts +71 -0
  234. package/lib/types/store/WorkflowsApi.d.ts.map +1 -0
  235. package/lib/types/store/client.d.ts +35 -0
  236. package/lib/types/store/client.d.ts.map +1 -0
  237. package/lib/types/store/errors.d.ts +4 -0
  238. package/lib/types/store/errors.d.ts.map +1 -0
  239. package/lib/types/store/index.d.ts +6 -0
  240. package/lib/types/store/index.d.ts.map +1 -0
  241. package/lib/types/store/version.d.ts +2 -0
  242. package/lib/types/store/version.d.ts.map +1 -0
  243. package/lib/vertesia-client.js +2 -0
  244. package/lib/vertesia-client.js.map +1 -0
  245. package/package.json +4 -4
  246. package/src/store/WorkflowsApi.ts +12 -0
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Symbol used to mark InteractionOutputArray instances.
3
+ * This allows us to detect if a CompletionResult[] has already been wrapped.
4
+ */
5
+ export const IS_INTERACTION_OUTPUT = Symbol('InteractionOutput');
6
+ export function enhanceInteractionExecutionResult(r) {
7
+ r.result = InteractionOutput.from(r.result);
8
+ return r;
9
+ }
10
+ export function enhanceExecutionRun(r) {
11
+ r.result = InteractionOutput.from(r.result);
12
+ return r;
13
+ }
14
+ /**
15
+ * A convenient wrapper around CompletionResult[] that provides ergonomic accessors
16
+ * for different result types (text, JSON/objects, images) from interaction executions.
17
+ *
18
+ * Use the static from() method to create a proxied array that acts as both
19
+ * an array and has these convenience methods.
20
+ *
21
+ * @template T - The expected type of JSON/object results. Defaults to any.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Recommended: Using the static from() method
26
+ * const output = InteractionOutput.from<MyResponse>(run.result);
27
+ * output[0]; // CompletionResult (array access)
28
+ * output.length; // number (array property)
29
+ * const obj = output.object(); // MyResponse (custom method)
30
+ * const text = output.text(); // string (custom getter)
31
+ *
32
+ * // Alternative: Using the class directly (less common)
33
+ * const output = new InteractionOutput<MyResponse>(run.result);
34
+ * const obj = output.object(); // Returns MyResponse
35
+ * const objs = output.objects(); // Returns MyResponse[]
36
+ *
37
+ * // Override type for specific objects
38
+ * interface OtherType { title: string; }
39
+ * ```
40
+ */
41
+ export class InteractionOutput {
42
+ results;
43
+ /**
44
+ * The raw completion results array.
45
+ * Access this when you need to work with the underlying CompletionResult[] directly.
46
+ */
47
+ constructor(results) {
48
+ this.results = results;
49
+ }
50
+ /**
51
+ * Create an interaction output that acts as both an array and has convenience methods.
52
+ * This is the recommended way to work with interaction execution results.
53
+ *
54
+ * @template T - The expected type of JSON/object results. Defaults to any.
55
+ * @param results - The raw CompletionResult array from an interaction execution
56
+ * @returns A proxied array with convenience methods
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * interface MyResponse { name: string; age: number; }
61
+ * const output = InteractionOutput.from<MyResponse>(run.result);
62
+ *
63
+ * // Array access
64
+ * output[0]; // CompletionResult
65
+ * output.length; // number
66
+ *
67
+ * // Convenience methods
68
+ * const obj = output.object(); // MyResponse
69
+ * const text = output.text(); // string
70
+ * ```
71
+ */
72
+ static from(results) {
73
+ if (!results) {
74
+ return createInteractionOutput([]);
75
+ }
76
+ // Check if already wrapped using the symbol marker
77
+ if (results[IS_INTERACTION_OUTPUT]) {
78
+ return results;
79
+ }
80
+ if (Array.isArray(results)) {
81
+ return createInteractionOutput(results);
82
+ }
83
+ else if (typeof results === 'object') {
84
+ return createInteractionOutput([{ type: 'json', value: results }]);
85
+ }
86
+ else {
87
+ return createInteractionOutput([{ type: 'text', value: String(results) }]);
88
+ }
89
+ }
90
+ static isInteractionOutputArray(obj) {
91
+ return obj && obj[IS_INTERACTION_OUTPUT] === true;
92
+ }
93
+ get isEmpty() {
94
+ return this.results.length === 0;
95
+ }
96
+ hasObject() {
97
+ return this.results.some(r => r.type === 'json');
98
+ }
99
+ hasText() {
100
+ return this.results.some(r => r.type === 'text');
101
+ }
102
+ hasImage() {
103
+ return this.results.some(r => r.type === 'image');
104
+ }
105
+ /**
106
+ * Get the concatenated text from all text results.
107
+ * Returns an empty string if no text results exist.
108
+ */
109
+ text(delimiter = '\n') {
110
+ return this.results
111
+ .filter(r => r.type === 'text')
112
+ .map(r => r.value)
113
+ .join(delimiter);
114
+ }
115
+ /**
116
+ * Get an array of all text values from text results.
117
+ */
118
+ texts() {
119
+ return this.results
120
+ .filter(r => r.type === 'text')
121
+ .map(r => r.value);
122
+ }
123
+ /**
124
+ * Get the first JSON result as a parsed object.
125
+ * If no JSON result exists, attempts to parse the concatenated text as JSON.
126
+ * @returns The first JSON result typed as T (the class generic type)
127
+ * @throws Error if no JSON result found and text cannot be parsed as JSON
128
+ */
129
+ object() {
130
+ const jsonResult = this.results.find(r => r.type === 'json');
131
+ if (jsonResult) {
132
+ return jsonResult.value;
133
+ }
134
+ // Fallback: try to parse the other text parts as JSON
135
+ return parseCompletionResultAsJson(this.results);
136
+ }
137
+ /**
138
+ * Get all JSON results as parsed objects.
139
+ * @returns An array of all JSON results typed as T[] (the class generic type)
140
+ */
141
+ objects() {
142
+ return this.results
143
+ .filter(r => r.type === 'json')
144
+ .map(r => r.value);
145
+ }
146
+ /**
147
+ * Get a specific JSON result by index as a parsed object.
148
+ * @template U - The type of the object at this index. Defaults to T (the class generic).
149
+ * @param index - The zero-based index of the JSON result
150
+ * @returns The JSON result at the specified index typed as U
151
+ * @throws Error if the index is out of bounds
152
+ */
153
+ objectAt(index) {
154
+ let i = 0;
155
+ for (const result of this.results) {
156
+ if (result.type === 'json') {
157
+ if (i === index) {
158
+ return result.value;
159
+ }
160
+ i++;
161
+ }
162
+ }
163
+ throw new Error(`Object at index ${index} not found`);
164
+ }
165
+ /**
166
+ * Get the first image result (base64 data URL or URL).
167
+ * @throws Error if no image result exists
168
+ */
169
+ image() {
170
+ const imageResult = this.results.find(r => r.type === 'image');
171
+ if (!imageResult) {
172
+ throw new Error('No image result found');
173
+ }
174
+ return imageResult.value;
175
+ }
176
+ /**
177
+ * Get an array of all image values (base64 data URLs or URLs).
178
+ */
179
+ images() {
180
+ return this.results
181
+ .filter(r => r.type === 'image')
182
+ .map(r => r.value);
183
+ }
184
+ /**
185
+ * Convert all results to a string representation.
186
+ * Text and image results are used as-is, JSON results are stringified with the specified indent.
187
+ * All parts are joined using the specified separator.
188
+ *
189
+ * @param separator - The separator to use between parts (default: '\n')
190
+ * @param indent - The indentation to use for JSON.stringify (default: 0 = no formatting)
191
+ * @returns A string representation of all results
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const output = InteractionOutput.from(results);
196
+ * output.stringify(); // Each part on a new line, compact JSON
197
+ * output.stringify('\n\n', 2); // Double newlines between parts, formatted JSON
198
+ * output.stringify(' '); // Space-separated, compact JSON
199
+ * ```
200
+ */
201
+ stringify(separator = '\n', indent = 2) {
202
+ return this.results
203
+ .map(r => {
204
+ switch (r.type) {
205
+ case 'json':
206
+ return JSON.stringify(r.value, null, indent);
207
+ default:
208
+ return String(r.value);
209
+ }
210
+ })
211
+ .join(separator);
212
+ }
213
+ /**
214
+ * Convert to string representation (concatenated text).
215
+ * Useful for template literals or string coercion.
216
+ */
217
+ toString() {
218
+ return this.text();
219
+ }
220
+ /**
221
+ * Convert to JSON representation.
222
+ * Attempts to return the first JSON object, falls back to concatenated text.
223
+ */
224
+ toJSON() {
225
+ return this.results;
226
+ }
227
+ }
228
+ /**
229
+ * Creates a proxied array that acts as both a CompletionResult[] and has InteractionOutput convenience methods.
230
+ * Note: It's recommended to use InteractionOutput.from() instead of calling this function directly.
231
+ *
232
+ * @template T - The expected type of JSON/object results. Defaults to any.
233
+ * @param results - The raw CompletionResult array from the interaction execution
234
+ * @returns A proxy that behaves as both an array and has convenience methods
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * interface MyResponse { name: string; age: number; }
239
+ * const output = createInteractionOutput<MyResponse>(run.result);
240
+ *
241
+ * // Array access
242
+ * output[0]; // CompletionResult
243
+ * output.length; // number
244
+ * output.map(r => r.type) // string[]
245
+ *
246
+ * // Convenience methods
247
+ * const obj = output.object(); // MyResponse
248
+ * const text = output.text(); // string
249
+ * const img = output.image(); // string
250
+ * ```
251
+ */
252
+ export function createInteractionOutput(results) {
253
+ const wrapper = new InteractionOutput(results);
254
+ return new Proxy(results, {
255
+ get(target, prop, receiver) {
256
+ // Return the marker symbol to identify wrapped arrays
257
+ if (prop === IS_INTERACTION_OUTPUT) {
258
+ return true;
259
+ }
260
+ // Check if the wrapper has this property/method
261
+ if (prop in wrapper) {
262
+ const value = wrapper[prop];
263
+ // If it's a function, bind it to the wrapper so 'this' works correctly
264
+ if (typeof value === 'function') {
265
+ return value.bind(wrapper);
266
+ }
267
+ // For getters and regular properties, just return the value
268
+ return value;
269
+ }
270
+ // Otherwise delegate to the array
271
+ return Reflect.get(target, prop, receiver);
272
+ }
273
+ });
274
+ }
275
+ function parseCompletionResultAsJson(data) {
276
+ let lastError;
277
+ for (const part of data) {
278
+ if (part.type === "text") {
279
+ const text = part.value.trim();
280
+ try {
281
+ return JSON.parse(text);
282
+ }
283
+ catch (error) {
284
+ lastError = error;
285
+ }
286
+ }
287
+ }
288
+ if (!lastError) {
289
+ lastError = new Error("No JSON result found and no text available to parse");
290
+ }
291
+ throw lastError;
292
+ }
293
+ //# sourceMappingURL=InteractionOutput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InteractionOutput.js","sourceRoot":"","sources":["../../src/InteractionOutput.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,mB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BAC/B,CAAC;gBACD,4DAA4D;gBAC5D,OAAO,KAAK,CAAC;YACjB,CAAC;YACD,kCAAkC;YAClC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;KACJ,CAA8B,CAAC;AACpC,CAAC;AAGD,SAAS,2BAA2B,CAAC,IAAwB;IACzD,IAAI,SAA4B,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACtB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBAClB,SAAS,GAAG,KAAK,CAAC;YACtB,CAAC;QACL,CAAC;IACL,CAAC;IACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACjF,CAAC;IACD,MAAM,SAAS,CAAC;AACpB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Example usage of InteractionOutput
3
+ * This file demonstrates the Proxy-based approach where the result acts as both
4
+ * an array and has convenience methods.
5
+ */
6
+ import { InteractionOutput } from './InteractionOutput.js';
7
+ // Sample data
8
+ const sampleResults = [
9
+ { type: 'text', value: 'Hello, ' },
10
+ { type: 'text', value: 'World!' },
11
+ { type: 'json', value: { name: 'Alice', age: 30 } },
12
+ { type: 'json', value: { title: 'Engineer', level: 'Senior' } },
13
+ { type: 'image', value: 'data:image/png;base64,iVBORw0K...' }
14
+ ];
15
+ // Example 1: Using InteractionOutput.from() (Proxy approach - RECOMMENDED)
16
+ console.log('=== Example 1: Proxy Approach ===');
17
+ const output = InteractionOutput.from(sampleResults);
18
+ // Works as an array
19
+ console.log('Array length:', output.length); // 5
20
+ console.log('First item:', output[0]); // { type: 'text', value: 'Hello, ' }
21
+ console.log('Types:', output.map(r => r.type)); // ['text', 'text', 'json', 'json', 'image']
22
+ // Has convenience methods
23
+ console.log('All text:', output.text); // 'Hello, World!'
24
+ console.log('First object:', output.object()); // { name: 'Alice', age: 30 } (typed as Person)
25
+ console.log('All objects:', output.objects()); // [{ name: 'Alice', age: 30 }, { title: 'Engineer', level: 'Senior' }]
26
+ console.log('First image:', output.image); // 'data:image/png;base64,iVBORw0K...'
27
+ console.log('Second object:', output.objectAt(1)); // { title: 'Engineer', level: 'Senior' } (typed as Job)
28
+ // Example 2: Using InteractionOutput class directly
29
+ console.log('\n=== Example 2: Class Approach ===');
30
+ const wrapper = new InteractionOutput(sampleResults);
31
+ // Access through wrapper properties (no array access)
32
+ console.log('All text:', wrapper.text);
33
+ console.log('Raw results:', wrapper.results); // Original array
34
+ console.log('First object:', wrapper.object());
35
+ // Example 3: Type safety demonstration
36
+ console.log('\n=== Example 3: Type Safety ===');
37
+ const contractResults = [
38
+ { type: 'json', value: { title: 'Sales Agreement', parties: ['Alice', 'Bob'] } }
39
+ ];
40
+ const contractOutput = InteractionOutput.from(contractResults);
41
+ const contract = contractOutput.object(); // TypeScript knows this is Contract
42
+ console.log('Contract title:', contract.title);
43
+ console.log('Parties:', contract.parties.join(', '));
44
+ // Example 4: Mixed content
45
+ console.log('\n=== Example 4: Mixed Content ===');
46
+ const mixedResults = [
47
+ { type: 'text', value: 'Analysis complete. Results: ' },
48
+ { type: 'json', value: { score: 0.95, confidence: 'high' } },
49
+ { type: 'text', value: '\nThank you!' }
50
+ ];
51
+ const mixed = InteractionOutput.from(mixedResults);
52
+ console.log('Full text:', mixed.text); // 'Analysis complete. Results: \nThank you!'
53
+ console.log('Analysis:', mixed.object()); // { score: 0.95, confidence: 'high' }
54
+ console.log('Text parts:', mixed.texts); // ['Analysis complete. Results: ', '\nThank you!']
55
+ //# sourceMappingURL=InteractionResult.example.js.map
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,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAErD,2BAA2B;AAC3B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAClD,MAAM,YAAY,GAAuB;IACrC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,EAAE;IACvD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;IAC5D,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE;CAC1C,CAAC;AAEF,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACnD,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAiB,6CAA6C;AACpG,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAc,sCAAsC;AAC7F,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAe,mDAAmD"}
@@ -0,0 +1,240 @@
1
+ import { ApiTopic, ServerError } from "@vertesia/api-fetch-client";
2
+ import { checkRateLimit, executeInteraction, executeInteractionAsync, executeInteractionByName } from "./execute.js";
3
+ import { InteractionCatalogApi } from "./InteractionCatalogApi.js";
4
+ import { enhanceExecutionRun, enhanceInteractionExecutionResult } from "./InteractionOutput.js";
5
+ export default class InteractionsApi extends ApiTopic {
6
+ catalog;
7
+ constructor(parent) {
8
+ super(parent, "/api/v1/interactions");
9
+ this.catalog = new InteractionCatalogApi(parent);
10
+ }
11
+ /**
12
+ * Get the list of all interactions in the current project
13
+ * @returns InteractionRef[]
14
+ **/
15
+ list(payload = {}) {
16
+ const query = payload.query || {};
17
+ return this.get("/", {
18
+ query: {
19
+ ...query
20
+ }
21
+ });
22
+ }
23
+ /**
24
+ * Find interactions given a mongo match query.
25
+ * You can also specify if prompts schemas are included in the result
26
+ */
27
+ listEndpoints(payload) {
28
+ return this.post("/endpoints", {
29
+ payload
30
+ });
31
+ }
32
+ /**
33
+ * List all interaction versions in the project having the given endpoint name.
34
+ * This is useful to list orphaned versions
35
+ * @param name
36
+ */
37
+ listVersionsByName(name) {
38
+ return this.get(`/versions/${name}`);
39
+ }
40
+ /**
41
+ * Get the list of all interaction tags in the current project
42
+ * @param query optional query parameters to filter the tags
43
+ * @returns InteractionTags[]
44
+ **/
45
+ listTags(query) {
46
+ return this.get("/tags", {
47
+ query: {
48
+ ...query
49
+ }
50
+ });
51
+ }
52
+ /**
53
+ * Get the list of all interactions facets
54
+ * @param payload query payload to filter facet search
55
+ * @returns ComputeInteractionFacetsResponse[]
56
+ **/
57
+ computeFacets(query) {
58
+ return this.post("/facets", {
59
+ payload: query
60
+ });
61
+ }
62
+ /**
63
+ * List interaction names in the current project
64
+ * @returns
65
+ */
66
+ listNames() {
67
+ return this.get('/names');
68
+ }
69
+ /**
70
+ * Get the list of all interactions in the current project. Schemas will be returned too.
71
+ * @returns InteractionRefWithSchema[]
72
+ **/
73
+ export(payload) {
74
+ return this.post('/export', { payload });
75
+ }
76
+ /**
77
+ * Create a new interaction
78
+ * @param payload InteractionCreatePayload
79
+ * @returns Interaction
80
+ * @throws ApiError
81
+ * @throws 400 if payload is invalid
82
+ * @throws 500 if interaction creation fails
83
+ **/
84
+ create(payload) {
85
+ return this.post('/', {
86
+ payload
87
+ });
88
+ }
89
+ /**
90
+ * Retrieve an existing interaction definition
91
+ * @param id of the interaction to retrieve
92
+ * @returns Interaction
93
+ **/
94
+ retrieve(id) {
95
+ return this.get(`/${id}`);
96
+ }
97
+ /**
98
+ * Update an existing interaction definition
99
+ * @param id of the interaction to update
100
+ * @param payload InteractionUpdatePayload
101
+ * @returns Interaction
102
+ * @throws ApiError
103
+ * @throws 400 if payload is invalid
104
+ * @throws 500 if interaction update fails
105
+ * @throws 404 if interaction not found
106
+ **/
107
+ update(id, payload) {
108
+ return this.put(`/${id}`, {
109
+ payload
110
+ });
111
+ }
112
+ /**
113
+ * Execute an interaction and return a promise which will be resolved with the executed run when
114
+ * the run completes or fails.
115
+ * If the onChunk callback is passed then the streaming of the result is enabled.
116
+ * The onChunk callback with be called with the next chunk of the result as soon as it is available.
117
+ * When all chunks are received the function will return the resolved promise
118
+ * @param id of the interaction to execute
119
+ * @param payload InteractionExecutionPayload
120
+ * @param onChunk callback to be called when the next chunk of the response is available
121
+ * @returns Promise<ExecutionRun>
122
+ * @throws ApiError
123
+ * @throws 404 if interaction not found
124
+ * @throws 400 if payload is invalid
125
+ * @throws 500 if interaction execution fails
126
+ * @throws 500 if interaction execution times out
127
+ **/
128
+ async execute(id, payload = {}, onChunk) {
129
+ const r = await executeInteraction(this.client, id, payload, onChunk).catch(err => {
130
+ if (err instanceof ServerError && err.payload?.id) {
131
+ throw err.updateDetails({ run_id: err.payload.id });
132
+ }
133
+ else {
134
+ throw err;
135
+ }
136
+ });
137
+ return enhanceInteractionExecutionResult(r);
138
+ }
139
+ /**
140
+ * Same as execute but uses the interaction name selector instead of the id.
141
+ *
142
+ * A name selector is the interaction endpoint name suffixed with an optional tag or version which is starting with a `@` character.
143
+ * The special `draft` tag is used to select the draft version of the interaction. If no tag or version is specified then the latest version is selected.
144
+ * Examples of selectors:
145
+ * - `ReviewContract` - select the latest version of the ReviewContract interaction
146
+ * - `ReviewContract@1` - select the version 1 of the ReviewContract interaction
147
+ * - `ReviewContract@draft` - select the draft version of the ReviewContract interaction
148
+ * - `ReviewContract@fixed` - select the ReviewContract interaction which is tagged with 'fixed' tag.
149
+ * @param nameWithTag
150
+ * @param payload
151
+ * @param onChunk
152
+ * @returns
153
+ */
154
+ async executeByName(nameWithTag, payload = {}, onChunk) {
155
+ const r = await executeInteractionByName(this.client, nameWithTag, payload, onChunk).catch(err => {
156
+ if (err instanceof ServerError && err.payload?.id) {
157
+ throw err.updateDetails({ run_id: err.payload.id });
158
+ }
159
+ else {
160
+ throw err;
161
+ }
162
+ });
163
+ return enhanceInteractionExecutionResult(r);
164
+ }
165
+ /**
166
+ * Execute an interaction in an workflow
167
+ * @param payload
168
+ * @returns
169
+ */
170
+ executeAsync(payload) {
171
+ return executeInteractionAsync(this.client, payload);
172
+ }
173
+ publish(id, payload) {
174
+ return this.post(`/${id}/publish`, {
175
+ payload
176
+ });
177
+ }
178
+ fork(id, payload) {
179
+ return this.post(`/${id}/fork`, {
180
+ payload
181
+ });
182
+ }
183
+ /**
184
+ * Generate Composable definition of an interaction
185
+ **/
186
+ generateInteraction(id, payload) {
187
+ return this.post(`${id}/generate-interaction`, {
188
+ payload
189
+ });
190
+ }
191
+ /**
192
+ * Generate Test Data for an interaction
193
+ **/
194
+ generateTestData(id, payload) {
195
+ return this.post(`${id}/generate-test-data`, {
196
+ payload
197
+ });
198
+ }
199
+ /**
200
+ * Suggest Improvement for a prompt
201
+ * @deprecated use suggestPromptImprovements instead
202
+ */
203
+ async suggestImprovements(id, payload) {
204
+ const r = await this.post(`${id}/suggest-prompt-improvements`, {
205
+ payload
206
+ });
207
+ return enhanceExecutionRun(r);
208
+ }
209
+ async suggestPromptImprovements(payload) {
210
+ const r = await this.post(`/improve`, {
211
+ payload
212
+ });
213
+ return enhanceInteractionExecutionResult(r);
214
+ }
215
+ /**
216
+ * List the versions of the interaction. Returns an empty array if no versions are found
217
+ * @param id
218
+ * @returns the versions list or an empty array if no versions are found
219
+ */
220
+ listVersions(id) {
221
+ return this.get(`/${id}/versions`);
222
+ }
223
+ /**
224
+ * List the forks of the interaction. Returns an empty array if no forks are found
225
+ * @param id
226
+ * @returns the versions list or an empty array if no forks are found
227
+ */
228
+ listForks(id) {
229
+ return this.get(`/${id}/forks`);
230
+ }
231
+ /**
232
+ * Request a time slot to execute an interaction with a given environment / model
233
+ * @param payload RateLimitRequestPayload
234
+ * @returns RateLimitRequestResponse with delay_ms
235
+ */
236
+ requestSlot(payload) {
237
+ return checkRateLimit(this.client, payload);
238
+ }
239
+ }
240
+ //# sourceMappingURL=InteractionsApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InteractionsApi.js","sourceRoot":"","sources":["../../src/InteractionsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAW/E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAA4D,mBAAmB,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAY1J,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,QAAQ;IACjD,OAAO,CAAwB;IAE/B,YAAY,MAAkB;QAC1B,KAAK,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAED;;;QAGI;IACJ,IAAI,CAAC,UAAoC,EAAE;QACvC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAA4B,CAAC;QAE5D,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;YACjB,KAAK,EAAE;gBACH,GAAG,KAAK;aACX;SACJ,CAAC,CAAC;IACP,CAAC;IACD;;;OAGG;IACH,aAAa,CAAC,OAAiC;QAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YAC3B,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,kBAAkB,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;;;QAII;IACJ,QAAQ,CAAC,KAA8B;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;YACrB,KAAK,EAAE;gBAC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;SACV,CAAC,CAAC;IAEP,CAAC;IAED;;QAEI;IACJ,gBAAgB,CAAC,EAAU,EAAE,OAAgC;QAEzD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,qBAAqB,EAAE;YACzC,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,mBAAmB,CAA+B,EAAU,EAAE,OAAmC;QACnG,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,8BAA8B,EAAE;YAC3D,OAAO;SACV,CAAC,CAAC;QACH,OAAO,mBAAmB,CAAmB,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,yBAAyB,CAA+B,OAA6B;QACvF,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAClC,OAAO;SACV,CAAC,CAAC;QACH,OAAO,iCAAiC,CAAmB,CAAC,CAAC,CAAC;IAClE,CAAC;IAGD;;;;OAIG;IACH,YAAY,CAAC,EAAU;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,OAAgC;QACxC,OAAO,cAAc,CAAC,IAAI,CAAC,MAAwB,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CAEJ"}
@@ -0,0 +1,50 @@
1
+ import { ApiTopic } from "@vertesia/api-fetch-client";
2
+ export default class ProjectsApi extends ApiTopic {
3
+ constructor(parent) {
4
+ super(parent, "/api/v1/projects");
5
+ }
6
+ list(account) {
7
+ return this.get('/', { query: { account } });
8
+ }
9
+ retrieve(projectId) {
10
+ return this.get(`/${projectId}`);
11
+ }
12
+ create(payload) {
13
+ return this.post('/', {
14
+ payload
15
+ });
16
+ }
17
+ update(projectId, payload) {
18
+ return this.put(`/${projectId}`, {
19
+ payload
20
+ });
21
+ }
22
+ updateConfiguration(projectId, payload) {
23
+ return this.put(`/${projectId}/configuration`, {
24
+ payload
25
+ });
26
+ }
27
+ integrations = new IntegrationsConfigurationApi(this);
28
+ }
29
+ class IntegrationsConfigurationApi extends ApiTopic {
30
+ constructor(parent) {
31
+ super(parent, "/");
32
+ }
33
+ list(projectId) {
34
+ return this.get(`/${projectId}/integrations`).then(res => res.integrations);
35
+ }
36
+ retrieve(projectId, integrationId) {
37
+ return this.get(`/${projectId}/integrations/${integrationId}`).catch(err => {
38
+ if (err.status === 404) {
39
+ return undefined;
40
+ }
41
+ throw err;
42
+ });
43
+ }
44
+ update(projectId, integrationId, payload) {
45
+ return this.put(`/${projectId}/integrations/${integrationId}`, {
46
+ payload
47
+ });
48
+ }
49
+ }
50
+ //# sourceMappingURL=ProjectsApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProjectsApi.js","sourceRoot":"","sources":["../../src/ProjectsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,4BAA4B,CAAC;AAGlE,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,QAAQ;IAC7C,YAAY,MAAkB;QAC1B,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,OAAkB;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,QAAQ,CAAC,SAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,OAA8B;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YAClB,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,S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