@runflow-ai/sdk 1.0.70 → 1.0.71

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.
@@ -51,9 +51,9 @@ function loadRunflowConfig() {
51
51
  let currentDir = process.cwd();
52
52
  const root = path.parse(currentDir).root;
53
53
  while (currentDir !== root) {
54
- const configPath = path.join(currentDir, '.runflow', 'rf.json');
54
+ const configPath = path.join(currentDir, ".runflow", "rf.json");
55
55
  if (fs.existsSync(configPath)) {
56
- const configContent = fs.readFileSync(configPath, 'utf-8');
56
+ const configContent = fs.readFileSync(configPath, "utf-8");
57
57
  const config = JSON.parse(configContent);
58
58
  return config;
59
59
  }
@@ -62,7 +62,7 @@ function loadRunflowConfig() {
62
62
  return null;
63
63
  }
64
64
  catch (error) {
65
- console.warn('⚠️ [SDK] Failed to load .runflow/rf.json:', error);
65
+ console.warn("⚠️ [SDK] Failed to load .runflow/rf.json:", error);
66
66
  return null;
67
67
  }
68
68
  }
@@ -77,7 +77,7 @@ class RunflowAPIClientImpl {
77
77
  // Se não passar sessionId, usar da sessão identificada
78
78
  const memoryId = sessionId || this.resolveMemoryId();
79
79
  if (!memoryId) {
80
- throw new Error('Memory ID not provided and no active session identified. Use Runflow.identify() first.');
80
+ throw new Error("Memory ID not provided and no active session identified. Use Runflow.identify() first.");
81
81
  }
82
82
  // ✅ Use FileMemoryProvider if available
83
83
  if (this.memoryProvider) {
@@ -85,22 +85,22 @@ class RunflowAPIClientImpl {
85
85
  }
86
86
  // Fallback to API
87
87
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${memoryId}`, {
88
- method: 'GET',
88
+ method: "GET",
89
89
  headers: {
90
- 'x-api-key': this.apiKey,
91
- 'x-runflow-tenant-id': this.tenantId,
92
- 'x-runflow-agent-id': this.agentId,
90
+ "x-api-key": this.apiKey,
91
+ "x-runflow-tenant-id": this.tenantId,
92
+ "x-runflow-agent-id": this.agentId,
93
93
  },
94
94
  });
95
95
  if (!response.ok) {
96
96
  throw new Error(`Memory get API failed: ${response.statusText}`);
97
97
  }
98
- return await response.json();
98
+ return (await response.json());
99
99
  },
100
100
  set: async (sessionId, data) => {
101
101
  const memoryId = sessionId || this.resolveMemoryId();
102
102
  if (!memoryId) {
103
- throw new Error('Memory ID not provided and no active session identified. Use Runflow.identify() first.');
103
+ throw new Error("Memory ID not provided and no active session identified. Use Runflow.identify() first.");
104
104
  }
105
105
  // ✅ Use FileMemoryProvider if available
106
106
  if (this.memoryProvider) {
@@ -108,12 +108,12 @@ class RunflowAPIClientImpl {
108
108
  }
109
109
  // Fallback to API
110
110
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${memoryId}`, {
111
- method: 'PUT',
111
+ method: "PUT",
112
112
  headers: {
113
- 'Content-Type': 'application/json',
114
- 'x-api-key': this.apiKey,
115
- 'x-runflow-tenant-id': this.tenantId,
116
- 'x-runflow-agent-id': this.agentId,
113
+ "Content-Type": "application/json",
114
+ "x-api-key": this.apiKey,
115
+ "x-runflow-tenant-id": this.tenantId,
116
+ "x-runflow-agent-id": this.agentId,
117
117
  },
118
118
  body: JSON.stringify(data),
119
119
  });
@@ -124,7 +124,7 @@ class RunflowAPIClientImpl {
124
124
  append: async (sessionId, message) => {
125
125
  const memoryId = sessionId || this.resolveMemoryId();
126
126
  if (!memoryId) {
127
- throw new Error('Memory ID not provided and no active session identified. Use Runflow.identify() first.');
127
+ throw new Error("Memory ID not provided and no active session identified. Use Runflow.identify() first.");
128
128
  }
129
129
  // ✅ Use FileMemoryProvider if available
130
130
  if (this.memoryProvider) {
@@ -132,12 +132,12 @@ class RunflowAPIClientImpl {
132
132
  }
133
133
  // Fallback to API
134
134
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${memoryId}/append`, {
135
- method: 'POST',
135
+ method: "POST",
136
136
  headers: {
137
- 'Content-Type': 'application/json',
138
- 'x-api-key': this.apiKey,
139
- 'x-runflow-tenant-id': this.tenantId,
140
- 'x-runflow-agent-id': this.agentId,
137
+ "Content-Type": "application/json",
138
+ "x-api-key": this.apiKey,
139
+ "x-runflow-tenant-id": this.tenantId,
140
+ "x-runflow-agent-id": this.agentId,
141
141
  },
142
142
  body: JSON.stringify({
143
143
  role: message.role,
@@ -152,7 +152,7 @@ class RunflowAPIClientImpl {
152
152
  clear: async (sessionId) => {
153
153
  const memoryId = sessionId || this.resolveMemoryId();
154
154
  if (!memoryId) {
155
- throw new Error('Memory ID not provided and no active session identified. Use Runflow.identify() first.');
155
+ throw new Error("Memory ID not provided and no active session identified. Use Runflow.identify() first.");
156
156
  }
157
157
  // ✅ Use FileMemoryProvider if available
158
158
  if (this.memoryProvider) {
@@ -160,11 +160,11 @@ class RunflowAPIClientImpl {
160
160
  }
161
161
  // Fallback to API
162
162
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${memoryId}`, {
163
- method: 'DELETE',
163
+ method: "DELETE",
164
164
  headers: {
165
- 'x-api-key': this.apiKey,
166
- 'x-runflow-tenant-id': this.tenantId,
167
- 'x-runflow-agent-id': this.agentId,
165
+ "x-api-key": this.apiKey,
166
+ "x-runflow-tenant-id": this.tenantId,
167
+ "x-runflow-agent-id": this.agentId,
168
168
  },
169
169
  });
170
170
  if (!response.ok) {
@@ -182,12 +182,12 @@ class RunflowAPIClientImpl {
182
182
  requestBody.provider = options.model.provider;
183
183
  }
184
184
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${sessionId}/summarize`, {
185
- method: 'POST',
185
+ method: "POST",
186
186
  headers: {
187
- 'Content-Type': 'application/json',
188
- 'x-api-key': this.apiKey,
189
- 'x-runflow-tenant-id': this.tenantId,
190
- 'x-runflow-agent-id': this.agentId,
187
+ "Content-Type": "application/json",
188
+ "x-api-key": this.apiKey,
189
+ "x-runflow-tenant-id": this.tenantId,
190
+ "x-runflow-agent-id": this.agentId,
191
191
  },
192
192
  body: JSON.stringify(requestBody),
193
193
  });
@@ -199,7 +199,7 @@ class RunflowAPIClientImpl {
199
199
  search: async (query, sessionId, limit) => {
200
200
  const memoryId = sessionId || this.resolveMemoryId();
201
201
  if (!memoryId) {
202
- throw new Error('Memory ID not provided. Use Runflow.identify() first.');
202
+ throw new Error("Memory ID not provided. Use Runflow.identify() first.");
203
203
  }
204
204
  // ✅ Use FileMemoryProvider if available
205
205
  if (this.memoryProvider) {
@@ -207,19 +207,19 @@ class RunflowAPIClientImpl {
207
207
  }
208
208
  // Fallback to API
209
209
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/memory/${memoryId}/search`, {
210
- method: 'POST',
210
+ method: "POST",
211
211
  headers: {
212
- 'Content-Type': 'application/json',
213
- 'x-api-key': this.apiKey,
214
- 'x-runflow-tenant-id': this.tenantId,
215
- 'x-runflow-agent-id': this.agentId,
212
+ "Content-Type": "application/json",
213
+ "x-api-key": this.apiKey,
214
+ "x-runflow-tenant-id": this.tenantId,
215
+ "x-runflow-agent-id": this.agentId,
216
216
  },
217
217
  body: JSON.stringify({ query, limit }),
218
218
  });
219
219
  if (!response.ok) {
220
220
  throw new Error(`Memory search API failed: ${response.statusText}`);
221
221
  }
222
- return await response.json();
222
+ return (await response.json());
223
223
  },
224
224
  };
225
225
  // ============================================================================
@@ -228,14 +228,14 @@ class RunflowAPIClientImpl {
228
228
  this.documents = {
229
229
  add: async (request) => {
230
230
  const headers = {
231
- 'Content-Type': 'application/json',
232
- 'x-runflow-tenant-id': this.tenantId,
233
- 'x-runflow-agent-id': this.agentId,
231
+ "Content-Type": "application/json",
232
+ "x-runflow-tenant-id": this.tenantId,
233
+ "x-runflow-agent-id": this.agentId,
234
234
  };
235
235
  if (this.apiKey)
236
- headers['x-api-key'] = this.apiKey;
236
+ headers["x-api-key"] = this.apiKey;
237
237
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/vectors/documents`, {
238
- method: 'POST',
238
+ method: "POST",
239
239
  headers,
240
240
  body: JSON.stringify(request),
241
241
  });
@@ -243,33 +243,35 @@ class RunflowAPIClientImpl {
243
243
  const error = await response.text();
244
244
  throw new Error(`Add document API failed: ${error}`);
245
245
  }
246
- return await response.json();
246
+ return (await response.json());
247
247
  },
248
248
  addFile: async (request) => {
249
249
  const headers = {
250
- 'x-runflow-tenant-id': this.tenantId,
251
- 'x-runflow-agent-id': this.agentId,
250
+ "x-runflow-tenant-id": this.tenantId,
251
+ "x-runflow-agent-id": this.agentId,
252
252
  };
253
253
  if (this.apiKey)
254
- headers['x-api-key'] = this.apiKey;
254
+ headers["x-api-key"] = this.apiKey;
255
255
  const formData = new FormData();
256
256
  // Handle file (Node.js Buffer or Browser File)
257
257
  if (request.file instanceof Buffer) {
258
258
  // Node.js environment
259
- const blob = new Blob([request.file], { type: request.mimeType || 'application/octet-stream' });
260
- formData.append('file', blob, request.filename);
259
+ const blob = new Blob([request.file], {
260
+ type: request.mimeType || "application/octet-stream",
261
+ });
262
+ formData.append("file", blob, request.filename);
261
263
  }
262
264
  else {
263
265
  // Browser environment
264
- formData.append('file', request.file);
266
+ formData.append("file", request.file);
265
267
  }
266
- formData.append('vectorStore', request.vectorStore);
268
+ formData.append("vectorStore", request.vectorStore);
267
269
  if (request.title)
268
- formData.append('title', request.title);
270
+ formData.append("title", request.title);
269
271
  if (request.metadata)
270
- formData.append('metadata', JSON.stringify(request.metadata));
272
+ formData.append("metadata", JSON.stringify(request.metadata));
271
273
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/vectors/files/upload`, {
272
- method: 'POST',
274
+ method: "POST",
273
275
  headers,
274
276
  body: formData,
275
277
  });
@@ -277,44 +279,44 @@ class RunflowAPIClientImpl {
277
279
  const error = await response.text();
278
280
  throw new Error(`Add file API failed: ${error}`);
279
281
  }
280
- return await response.json();
282
+ return (await response.json());
281
283
  },
282
284
  list: async (vectorStore, options) => {
283
285
  const headers = {
284
- 'x-runflow-tenant-id': this.tenantId,
285
- 'x-runflow-agent-id': this.agentId,
286
+ "x-runflow-tenant-id": this.tenantId,
287
+ "x-runflow-agent-id": this.agentId,
286
288
  };
287
289
  if (this.apiKey)
288
- headers['x-api-key'] = this.apiKey;
290
+ headers["x-api-key"] = this.apiKey;
289
291
  const params = new URLSearchParams();
290
292
  if (options?.limit)
291
- params.append('limit', options.limit.toString());
293
+ params.append("limit", options.limit.toString());
292
294
  if (options?.offset)
293
- params.append('offset', options.offset.toString());
295
+ params.append("offset", options.offset.toString());
294
296
  if (options?.metadataFilters) {
295
- params.append('metadataFilters', JSON.stringify(options.metadataFilters));
297
+ params.append("metadataFilters", JSON.stringify(options.metadataFilters));
296
298
  }
297
299
  const url = `${this.baseUrl}/api/v1/runtime/v1/vectors/stores/${vectorStore}/documents?${params}`;
298
300
  const response = await fetch(url, {
299
- method: 'GET',
301
+ method: "GET",
300
302
  headers,
301
303
  });
302
304
  if (!response.ok) {
303
305
  const error = await response.text();
304
306
  throw new Error(`List documents API failed: ${error}`);
305
307
  }
306
- return await response.json();
308
+ return (await response.json());
307
309
  },
308
310
  delete: async (vectorStore, documentId) => {
309
311
  const headers = {
310
- 'Content-Type': 'application/json',
311
- 'x-runflow-tenant-id': this.tenantId,
312
- 'x-runflow-agent-id': this.agentId,
312
+ "Content-Type": "application/json",
313
+ "x-runflow-tenant-id": this.tenantId,
314
+ "x-runflow-agent-id": this.agentId,
313
315
  };
314
316
  if (this.apiKey)
315
- headers['x-api-key'] = this.apiKey;
317
+ headers["x-api-key"] = this.apiKey;
316
318
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/vectors/documents/${documentId}`, {
317
- method: 'DELETE',
319
+ method: "DELETE",
318
320
  headers,
319
321
  body: JSON.stringify({ vectorStore }),
320
322
  });
@@ -322,7 +324,7 @@ class RunflowAPIClientImpl {
322
324
  const error = await response.text();
323
325
  throw new Error(`Delete document API failed: ${error}`);
324
326
  }
325
- return await response.json();
327
+ return (await response.json());
326
328
  },
327
329
  };
328
330
  // ============================================================================
@@ -331,93 +333,148 @@ class RunflowAPIClientImpl {
331
333
  this.prompts = {
332
334
  get: async (nameOrId) => {
333
335
  const headers = {
334
- 'x-runflow-tenant-id': this.tenantId,
335
- 'x-runflow-agent-id': this.agentId,
336
+ "x-runflow-tenant-id": this.tenantId,
337
+ "x-runflow-agent-id": this.agentId,
336
338
  };
337
339
  if (this.apiKey)
338
- headers['x-api-key'] = this.apiKey;
339
- const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts/${nameOrId}`, { method: 'GET', headers });
340
+ headers["x-api-key"] = this.apiKey;
341
+ const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts/${nameOrId}`, { method: "GET", headers });
340
342
  if (!response.ok) {
341
343
  throw new Error(`Get prompt API failed: ${response.statusText}`);
342
344
  }
343
- return await response.json();
345
+ return (await response.json());
344
346
  },
345
347
  list: async (options) => {
346
348
  const headers = {
347
- 'x-runflow-tenant-id': this.tenantId,
348
- 'x-runflow-agent-id': this.agentId,
349
+ "x-runflow-tenant-id": this.tenantId,
350
+ "x-runflow-agent-id": this.agentId,
349
351
  };
350
352
  if (this.apiKey)
351
- headers['x-api-key'] = this.apiKey;
353
+ headers["x-api-key"] = this.apiKey;
352
354
  const params = new URLSearchParams();
353
355
  if (options?.limit)
354
- params.append('limit', options.limit.toString());
355
- const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts?${params}`, { method: 'GET', headers });
356
+ params.append("limit", options.limit.toString());
357
+ const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts?${params}`, { method: "GET", headers });
356
358
  if (!response.ok) {
357
359
  throw new Error(`List prompts API failed: ${response.statusText}`);
358
360
  }
359
- return await response.json();
361
+ return (await response.json());
360
362
  },
361
363
  create: async (request) => {
362
364
  const headers = {
363
- 'Content-Type': 'application/json',
364
- 'x-runflow-tenant-id': this.tenantId,
365
- 'x-runflow-agent-id': this.agentId,
365
+ "Content-Type": "application/json",
366
+ "x-runflow-tenant-id": this.tenantId,
367
+ "x-runflow-agent-id": this.agentId,
366
368
  };
367
369
  if (this.apiKey)
368
- headers['x-api-key'] = this.apiKey;
370
+ headers["x-api-key"] = this.apiKey;
369
371
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts`, {
370
- method: 'POST',
372
+ method: "POST",
371
373
  headers,
372
374
  body: JSON.stringify(request),
373
375
  });
374
376
  if (!response.ok) {
375
377
  throw new Error(`Create prompt API failed: ${response.statusText}`);
376
378
  }
377
- return await response.json();
379
+ return (await response.json());
378
380
  },
379
381
  update: async (nameOrId, request) => {
380
382
  const headers = {
381
- 'Content-Type': 'application/json',
382
- 'x-runflow-tenant-id': this.tenantId,
383
- 'x-runflow-agent-id': this.agentId,
383
+ "Content-Type": "application/json",
384
+ "x-runflow-tenant-id": this.tenantId,
385
+ "x-runflow-agent-id": this.agentId,
384
386
  };
385
387
  if (this.apiKey)
386
- headers['x-api-key'] = this.apiKey;
388
+ headers["x-api-key"] = this.apiKey;
387
389
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts/${nameOrId}`, {
388
- method: 'PATCH',
390
+ method: "PATCH",
389
391
  headers,
390
392
  body: JSON.stringify(request),
391
393
  });
392
394
  if (!response.ok) {
393
395
  throw new Error(`Update prompt API failed: ${response.statusText}`);
394
396
  }
395
- return await response.json();
397
+ return (await response.json());
396
398
  },
397
399
  delete: async (nameOrId) => {
398
400
  const headers = {
399
- 'x-runflow-tenant-id': this.tenantId,
400
- 'x-runflow-agent-id': this.agentId,
401
+ "x-runflow-tenant-id": this.tenantId,
402
+ "x-runflow-agent-id": this.agentId,
401
403
  };
402
404
  if (this.apiKey)
403
- headers['x-api-key'] = this.apiKey;
405
+ headers["x-api-key"] = this.apiKey;
404
406
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/prompts/${nameOrId}`, {
405
- method: 'DELETE',
407
+ method: "DELETE",
406
408
  headers,
407
409
  });
408
410
  if (!response.ok) {
409
411
  throw new Error(`Delete prompt API failed: ${response.statusText}`);
410
412
  }
411
- return await response.json();
413
+ return (await response.json());
414
+ },
415
+ };
416
+ // ============================================================================
417
+ // CREDENTIALS METHODS
418
+ // ============================================================================
419
+ this.credentials = {
420
+ getByName: async (name) => {
421
+ const headers = {
422
+ "x-runflow-tenant-id": this.tenantId,
423
+ "x-runflow-agent-id": this.agentId,
424
+ };
425
+ if (this.apiKey)
426
+ headers["x-api-key"] = this.apiKey;
427
+ const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/credentials/getByName/${encodeURIComponent(name)}`, { method: "GET", headers });
428
+ if (!response.ok) {
429
+ if (response.status === 404) {
430
+ return {
431
+ success: false,
432
+ data: null,
433
+ error: `Credential with name '${name}' not found`,
434
+ };
435
+ }
436
+ throw new Error(`Get credential API failed: ${response.statusText}`);
437
+ }
438
+ const data = (await response.json());
439
+ return {
440
+ success: true,
441
+ data: {
442
+ id: data?.id || "",
443
+ name: data?.name || "",
444
+ type: data?.type || "",
445
+ description: data?.description || "",
446
+ clientId: data?.clientId || "",
447
+ authUrl: data?.authUrl || "",
448
+ tokenUrl: data?.tokenUrl || "",
449
+ redirectUri: data?.redirectUri || "",
450
+ scopes: data?.scopes || [],
451
+ },
452
+ };
412
453
  },
413
454
  };
414
455
  // Load configuration from .runflow/rf.json if available
415
456
  const runflowConfig = loadRunflowConfig();
416
457
  // Priority: explicit config > .runflow/rf.json > environment > defaults
417
- this.baseUrl = config?.baseUrl || runflowConfig?.apiUrl || process.env.RUNFLOW_API_URL || 'http://localhost:3001';
418
- this.apiKey = config?.apiKey || runflowConfig?.apiKey || process.env.RUNFLOW_API_KEY || '';
419
- this.tenantId = config?.tenantId || runflowConfig?.tenantId || process.env.RUNFLOW_TENANT_ID || '';
420
- this.agentId = config?.agentId || runflowConfig?.agentId || process.env.RUNFLOW_AGENT_ID || '';
458
+ this.baseUrl =
459
+ config?.baseUrl ||
460
+ runflowConfig?.apiUrl ||
461
+ process.env.RUNFLOW_API_URL ||
462
+ "http://localhost:3001";
463
+ this.apiKey =
464
+ config?.apiKey ||
465
+ runflowConfig?.apiKey ||
466
+ process.env.RUNFLOW_API_KEY ||
467
+ "";
468
+ this.tenantId =
469
+ config?.tenantId ||
470
+ runflowConfig?.tenantId ||
471
+ process.env.RUNFLOW_TENANT_ID ||
472
+ "";
473
+ this.agentId =
474
+ config?.agentId ||
475
+ runflowConfig?.agentId ||
476
+ process.env.RUNFLOW_AGENT_ID ||
477
+ "";
421
478
  // ✅ Initialize memory provider based on environment
422
479
  this.memoryProvider = this.initializeMemoryProvider();
423
480
  }
@@ -425,10 +482,10 @@ class RunflowAPIClientImpl {
425
482
  * Initialize memory provider based on RUNFLOW_LOCAL_MEMORY environment variable
426
483
  */
427
484
  initializeMemoryProvider() {
428
- const useLocalMemory = process.env.RUNFLOW_LOCAL_MEMORY === 'true'
429
- || process.env.RUNFLOW_ENV === 'development';
485
+ const useLocalMemory = process.env.RUNFLOW_LOCAL_MEMORY === "true" ||
486
+ process.env.RUNFLOW_ENV === "development";
430
487
  if (useLocalMemory) {
431
- console.log('💾 [API CLIENT] Using FileMemoryProvider for local development');
488
+ console.log("💾 [API CLIENT] Using FileMemoryProvider for local development");
432
489
  return new file_memory_provider_1.FileMemoryProvider();
433
490
  }
434
491
  // Return null = use API calls
@@ -446,21 +503,21 @@ class RunflowAPIClientImpl {
446
503
  // ============================================================================
447
504
  async chat(request) {
448
505
  const headers = {
449
- 'Content-Type': 'application/json',
450
- 'x-runflow-tenant-id': this.tenantId,
451
- 'x-runflow-agent-id': this.agentId,
506
+ "Content-Type": "application/json",
507
+ "x-runflow-tenant-id": this.tenantId,
508
+ "x-runflow-agent-id": this.agentId,
452
509
  };
453
510
  if (this.apiKey)
454
- headers['x-api-key'] = this.apiKey;
511
+ headers["x-api-key"] = this.apiKey;
455
512
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/chat`, {
456
- method: 'POST',
513
+ method: "POST",
457
514
  headers,
458
515
  body: JSON.stringify(request),
459
516
  });
460
517
  if (!response.ok) {
461
518
  throw new Error(`Chat API failed: ${response.statusText}`);
462
519
  }
463
- return await response.json();
520
+ return (await response.json());
464
521
  }
465
522
  // ============================================================================
466
523
  // MEDIA METHODS (Audio, Image processing)
@@ -470,32 +527,32 @@ class RunflowAPIClientImpl {
470
527
  */
471
528
  async transcribe(request) {
472
529
  const headers = {
473
- 'Content-Type': 'application/json',
474
- 'x-runflow-tenant-id': this.tenantId,
475
- 'x-runflow-agent-id': this.agentId,
530
+ "Content-Type": "application/json",
531
+ "x-runflow-tenant-id": this.tenantId,
532
+ "x-runflow-agent-id": this.agentId,
476
533
  };
477
534
  if (this.apiKey)
478
- headers['x-api-key'] = this.apiKey;
535
+ headers["x-api-key"] = this.apiKey;
479
536
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/transcribe`, {
480
- method: 'POST',
537
+ method: "POST",
481
538
  headers,
482
539
  body: JSON.stringify(request),
483
540
  });
484
541
  if (!response.ok) {
485
542
  throw new Error(`Transcribe API failed: ${response.statusText}`);
486
543
  }
487
- return await response.json();
544
+ return (await response.json());
488
545
  }
489
546
  async *chatStream(request) {
490
547
  const headers = {
491
- 'Content-Type': 'application/json',
492
- 'x-runflow-tenant-id': this.tenantId,
493
- 'x-runflow-agent-id': this.agentId,
548
+ "Content-Type": "application/json",
549
+ "x-runflow-tenant-id": this.tenantId,
550
+ "x-runflow-agent-id": this.agentId,
494
551
  };
495
552
  if (this.apiKey)
496
- headers['x-api-key'] = this.apiKey;
553
+ headers["x-api-key"] = this.apiKey;
497
554
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/chat/stream`, {
498
- method: 'POST',
555
+ method: "POST",
499
556
  headers,
500
557
  body: JSON.stringify(request),
501
558
  });
@@ -505,7 +562,7 @@ class RunflowAPIClientImpl {
505
562
  const reader = response.body?.getReader();
506
563
  const decoder = new TextDecoder();
507
564
  if (!reader) {
508
- throw new Error('No response body');
565
+ throw new Error("No response body");
509
566
  }
510
567
  try {
511
568
  while (true) {
@@ -513,11 +570,11 @@ class RunflowAPIClientImpl {
513
570
  if (done)
514
571
  break;
515
572
  const chunk = decoder.decode(value);
516
- const lines = chunk.split('\n');
573
+ const lines = chunk.split("\n");
517
574
  for (const line of lines) {
518
- if (line.startsWith('data: ')) {
575
+ if (line.startsWith("data: ")) {
519
576
  const data = line.slice(6);
520
- if (data === '[DONE]') {
577
+ if (data === "[DONE]") {
521
578
  return;
522
579
  }
523
580
  try {
@@ -540,14 +597,14 @@ class RunflowAPIClientImpl {
540
597
  // ============================================================================
541
598
  async vectorSearch(query, options) {
542
599
  const headers = {
543
- 'Content-Type': 'application/json',
544
- 'x-runflow-tenant-id': this.tenantId,
545
- 'x-runflow-agent-id': this.agentId,
600
+ "Content-Type": "application/json",
601
+ "x-runflow-tenant-id": this.tenantId,
602
+ "x-runflow-agent-id": this.agentId,
546
603
  };
547
604
  if (this.apiKey)
548
- headers['x-api-key'] = this.apiKey;
605
+ headers["x-api-key"] = this.apiKey;
549
606
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/vectors/search`, {
550
- method: 'POST',
607
+ method: "POST",
551
608
  headers,
552
609
  body: JSON.stringify({
553
610
  query,
@@ -559,21 +616,20 @@ class RunflowAPIClientImpl {
559
616
  if (!response.ok) {
560
617
  throw new Error(`Vector search API failed: ${response.statusText}`);
561
618
  }
562
- return await response.json();
619
+ return (await response.json());
563
620
  }
564
621
  // ============================================================================
565
622
  // CONNECTOR METHODS
566
623
  // ============================================================================
567
- async connector(connector, resource, data, options // ConnectorExecutionOptions
568
- ) {
624
+ async connector(connector, resource, data, options) {
569
625
  const headers = {
570
- 'Content-Type': 'application/json',
571
- 'x-api-key': this.apiKey,
572
- 'x-runflow-tenant-id': this.tenantId,
573
- 'x-runflow-agent-id': this.agentId,
626
+ "Content-Type": "application/json",
627
+ "x-api-key": this.apiKey,
628
+ "x-runflow-tenant-id": this.tenantId,
629
+ "x-runflow-agent-id": this.agentId,
574
630
  };
575
631
  const response = await fetch(`${this.baseUrl}/api/v1/runtime/v1/connectors/${connector}`, {
576
- method: 'POST',
632
+ method: "POST",
577
633
  headers,
578
634
  body: JSON.stringify({
579
635
  resource,
@@ -613,25 +669,25 @@ class RunflowAPIClientImpl {
613
669
  const url = `${this.baseUrl}/api/v1/runtime/v1/observability/traces`;
614
670
  // Build headers conditionally - only add x-api-key if it exists
615
671
  const headers = {
616
- 'Content-Type': 'application/json',
617
- 'x-runflow-tenant-id': this.tenantId,
618
- 'x-runflow-agent-id': this.agentId,
672
+ "Content-Type": "application/json",
673
+ "x-runflow-tenant-id": this.tenantId,
674
+ "x-runflow-agent-id": this.agentId,
619
675
  };
620
676
  // Only add API key if it's not empty (Envoy proxy will inject it if needed)
621
677
  if (this.apiKey) {
622
- headers['x-api-key'] = this.apiKey;
678
+ headers["x-api-key"] = this.apiKey;
623
679
  }
624
680
  const response = await fetch(url, {
625
- method: 'POST',
681
+ method: "POST",
626
682
  headers,
627
683
  body: JSON.stringify(request),
628
684
  });
629
685
  if (!response.ok) {
630
686
  const errorText = await response.text();
631
- console.log('🔍 [SDK API CLIENT] Error response body:', errorText);
687
+ console.log("🔍 [SDK API CLIENT] Error response body:", errorText);
632
688
  throw new Error(`Traces API failed: ${response.statusText}`);
633
689
  }
634
- return await response.json();
690
+ return (await response.json());
635
691
  }
636
692
  // ============================================================================
637
693
  // LOGGING METHODS
@@ -639,21 +695,21 @@ class RunflowAPIClientImpl {
639
695
  log(message, data) {
640
696
  // Fire-and-forget logging
641
697
  fetch(`${this.baseUrl}/api/v1/runtime/v1/logs`, {
642
- method: 'POST',
698
+ method: "POST",
643
699
  headers: {
644
- 'Content-Type': 'application/json',
645
- 'x-api-key': this.apiKey,
646
- 'x-runflow-tenant-id': this.tenantId,
647
- 'x-runflow-agent-id': this.agentId,
700
+ "Content-Type": "application/json",
701
+ "x-api-key": this.apiKey,
702
+ "x-runflow-tenant-id": this.tenantId,
703
+ "x-runflow-agent-id": this.agentId,
648
704
  },
649
705
  body: JSON.stringify({
650
706
  message,
651
- level: 'info',
707
+ level: "info",
652
708
  data,
653
709
  timestamp: new Date().toISOString(),
654
710
  }),
655
- }).catch(error => {
656
- console.warn('Failed to send log to Runflow API:', error.message);
711
+ }).catch((error) => {
712
+ console.warn("Failed to send log to Runflow API:", error.message);
657
713
  });
658
714
  }
659
715
  }