cencori 1.2.0 → 1.3.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 (48) hide show
  1. package/README.md +3 -51
  2. package/dist/ai/index.d.mts +32 -1
  3. package/dist/ai/index.d.ts +32 -1
  4. package/dist/ai/index.js +131 -0
  5. package/dist/ai/index.js.map +1 -1
  6. package/dist/ai/index.mjs +131 -0
  7. package/dist/ai/index.mjs.map +1 -1
  8. package/dist/compute/index.d.mts +1 -1
  9. package/dist/compute/index.d.ts +1 -1
  10. package/dist/index.d.mts +208 -4
  11. package/dist/index.d.ts +208 -4
  12. package/dist/index.js +348 -8
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +345 -8
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/memory/index.d.mts +1 -1
  17. package/dist/memory/index.d.ts +1 -1
  18. package/dist/react/index.d.mts +52 -0
  19. package/dist/react/index.d.ts +52 -0
  20. package/dist/react/index.js +395 -0
  21. package/dist/react/index.js.map +1 -0
  22. package/dist/react/index.mjs +367 -0
  23. package/dist/react/index.mjs.map +1 -0
  24. package/dist/storage/index.d.mts +1 -1
  25. package/dist/storage/index.d.ts +1 -1
  26. package/dist/storage/index.js +7 -7
  27. package/dist/storage/index.js.map +1 -1
  28. package/dist/storage/index.mjs +7 -7
  29. package/dist/storage/index.mjs.map +1 -1
  30. package/dist/tanstack/index.d.mts +1 -1
  31. package/dist/tanstack/index.d.ts +1 -1
  32. package/dist/tanstack/index.js +3 -0
  33. package/dist/tanstack/index.js.map +1 -1
  34. package/dist/tanstack/index.mjs +3 -0
  35. package/dist/tanstack/index.mjs.map +1 -1
  36. package/dist/telemetry/index.d.mts +1 -1
  37. package/dist/telemetry/index.d.ts +1 -1
  38. package/dist/{types-Cr0muEt3.d.mts → types-kh1whvNH.d.mts} +135 -1
  39. package/dist/{types-Cr0muEt3.d.ts → types-kh1whvNH.d.ts} +135 -1
  40. package/dist/vision/index.d.mts +99 -0
  41. package/dist/vision/index.d.ts +99 -0
  42. package/dist/vision/index.js +93 -0
  43. package/dist/vision/index.js.map +1 -0
  44. package/dist/vision/index.mjs +68 -0
  45. package/dist/vision/index.mjs.map +1 -0
  46. package/dist/workflow/index.d.mts +1 -1
  47. package/dist/workflow/index.d.ts +1 -1
  48. package/package.json +20 -2
package/dist/index.mjs CHANGED
@@ -352,6 +352,137 @@ var AINamespace = class {
352
352
  latencyMs: data.latency_ms
353
353
  };
354
354
  }
355
+ /**
356
+ * Send a request to the OpenAI-compatible Responses API.
357
+ * Supports built-in tools: web_search_preview, file_search, code_interpreter.
358
+ *
359
+ * @example
360
+ * const response = await cencori.ai.responses({
361
+ * model: 'gpt-4o',
362
+ * input: 'What is the weather in San Francisco?',
363
+ * tools: [{ type: 'web_search_preview' }]
364
+ * });
365
+ * console.log(response.output[0].content?.[0]?.text);
366
+ */
367
+ async responses(request) {
368
+ const response = await fetch(`${this.config.baseUrl}/v1/responses`, {
369
+ method: "POST",
370
+ headers: {
371
+ "CENCORI_API_KEY": this.config.apiKey,
372
+ "Content-Type": "application/json",
373
+ ...this.config.headers
374
+ },
375
+ body: JSON.stringify({
376
+ model: request.model,
377
+ input: request.input,
378
+ instructions: request.instructions,
379
+ tools: request.tools,
380
+ tool_choice: request.tool_choice,
381
+ temperature: request.temperature,
382
+ max_output_tokens: request.max_output_tokens,
383
+ top_p: request.top_p,
384
+ store: request.store,
385
+ metadata: request.metadata,
386
+ previous_response_id: request.previous_response_id,
387
+ parallel_tool_calls: request.parallel_tool_calls,
388
+ truncation: request.truncation,
389
+ response_format: request.response_format,
390
+ include: request.include,
391
+ stream: false,
392
+ user: request.user
393
+ })
394
+ });
395
+ if (!response.ok) {
396
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
397
+ throw new Error(`Cencori API error: ${errorData.error || response.statusText}`);
398
+ }
399
+ return response.json();
400
+ }
401
+ /**
402
+ * Stream responses from the Responses API via SSE.
403
+ * Yields parsed events as they arrive.
404
+ *
405
+ * @example
406
+ * for await (const event of cencori.ai.responsesStream({
407
+ * model: 'gpt-4o',
408
+ * input: 'Tell me about AI',
409
+ * })) {
410
+ * if (event.type === 'response.output_text.delta') {
411
+ * process.stdout.write(event.data.delta);
412
+ * }
413
+ * }
414
+ */
415
+ async *responsesStream(request) {
416
+ const response = await fetch(`${this.config.baseUrl}/v1/responses`, {
417
+ method: "POST",
418
+ headers: {
419
+ "CENCORI_API_KEY": this.config.apiKey,
420
+ "Content-Type": "application/json",
421
+ ...this.config.headers
422
+ },
423
+ body: JSON.stringify({
424
+ model: request.model,
425
+ input: request.input,
426
+ instructions: request.instructions,
427
+ tools: request.tools,
428
+ tool_choice: request.tool_choice,
429
+ temperature: request.temperature,
430
+ max_output_tokens: request.max_output_tokens,
431
+ top_p: request.top_p,
432
+ store: request.store,
433
+ metadata: request.metadata,
434
+ previous_response_id: request.previous_response_id,
435
+ parallel_tool_calls: request.parallel_tool_calls,
436
+ truncation: request.truncation,
437
+ response_format: request.response_format,
438
+ include: request.include,
439
+ stream: true,
440
+ user: request.user
441
+ })
442
+ });
443
+ if (!response.ok) {
444
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
445
+ throw new Error(`Cencori API error: ${errorData.error || response.statusText}`);
446
+ }
447
+ if (!response.body) {
448
+ throw new Error("Response body is null");
449
+ }
450
+ const reader = response.body.getReader();
451
+ const decoder = new TextDecoder();
452
+ let buffer = "";
453
+ let eventType = "";
454
+ try {
455
+ while (true) {
456
+ const { done, value } = await reader.read();
457
+ if (done) break;
458
+ buffer += decoder.decode(value, { stream: true });
459
+ const lines = buffer.split("\n");
460
+ buffer = lines.pop() || "";
461
+ for (const line of lines) {
462
+ if (line.trim() === "") {
463
+ eventType = "";
464
+ continue;
465
+ }
466
+ if (line.startsWith("event: ")) {
467
+ eventType = line.slice(7).trim();
468
+ continue;
469
+ }
470
+ if (line.startsWith("data: ")) {
471
+ const data = line.slice(6).trim();
472
+ if (!data) continue;
473
+ try {
474
+ const parsed = JSON.parse(data);
475
+ yield { type: eventType || "message", data: parsed };
476
+ } catch {
477
+ }
478
+ eventType = "";
479
+ }
480
+ }
481
+ }
482
+ } finally {
483
+ reader.releaseLock();
484
+ }
485
+ }
355
486
  /**
356
487
  * Stream RAG responses with automatic memory context
357
488
  *
@@ -418,6 +549,206 @@ var AINamespace = class {
418
549
  }
419
550
  };
420
551
 
552
+ // src/agents/index.ts
553
+ var AgentsNamespace = class {
554
+ constructor(config) {
555
+ this.config = config;
556
+ }
557
+ async request(method, path, body) {
558
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
559
+ method,
560
+ headers: {
561
+ "CENCORI_API_KEY": this.config.apiKey,
562
+ "Content-Type": "application/json",
563
+ ...this.config.headers
564
+ },
565
+ body: body ? JSON.stringify(body) : void 0
566
+ });
567
+ if (!response.ok) {
568
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
569
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
570
+ }
571
+ if (response.status === 204) return void 0;
572
+ return response.json();
573
+ }
574
+ async create(params) {
575
+ return this.request("POST", "/v1/agents", params);
576
+ }
577
+ async list() {
578
+ return this.request("GET", "/v1/agents");
579
+ }
580
+ async get(agentId) {
581
+ return this.request("GET", `/v1/agents/${agentId}`);
582
+ }
583
+ async updateConfig(agentId, params) {
584
+ return this.request("PATCH", `/v1/agents/${agentId}`, params);
585
+ }
586
+ async delete(agentId) {
587
+ return this.request("DELETE", `/v1/agents/${agentId}`);
588
+ }
589
+ async createKey(agentId, params) {
590
+ return this.request("POST", `/v1/agents/${agentId}/keys`, params || {});
591
+ }
592
+ };
593
+
594
+ // src/vision/index.ts
595
+ function toBody(request) {
596
+ const body = {
597
+ prompt: request.prompt,
598
+ model: request.model,
599
+ max_tokens: request.maxTokens,
600
+ temperature: request.temperature,
601
+ response_format: request.responseFormat
602
+ };
603
+ if (request.image.url) {
604
+ body.image_url = request.image.url;
605
+ } else if (request.image.base64) {
606
+ body.image_base64 = request.image.base64;
607
+ body.mime_type = request.image.mimeType;
608
+ } else {
609
+ throw new Error("vision request requires image.url or image.base64");
610
+ }
611
+ return body;
612
+ }
613
+ var VisionNamespace = class {
614
+ constructor(config) {
615
+ this.config = config;
616
+ }
617
+ /**
618
+ * General image analysis — provide your own prompt.
619
+ * Default prompt: "Describe this image in detail."
620
+ */
621
+ async analyze(request) {
622
+ return this.post("/api/ai/vision", request);
623
+ }
624
+ /** Describe the image in rich detail. */
625
+ async describe(request) {
626
+ return this.post("/api/ai/vision/describe", request);
627
+ }
628
+ /** Extract all visible text from the image. */
629
+ async ocr(request) {
630
+ return this.post("/api/ai/vision/ocr", request);
631
+ }
632
+ /** Return structured tags, objects, and category classification. */
633
+ async classify(request) {
634
+ return this.post("/api/ai/vision/classify", request);
635
+ }
636
+ async post(path, request) {
637
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
638
+ method: "POST",
639
+ headers: {
640
+ "CENCORI_API_KEY": this.config.apiKey,
641
+ "Content-Type": "application/json",
642
+ ...this.config.headers
643
+ },
644
+ body: JSON.stringify(toBody(request))
645
+ });
646
+ const data = await response.json();
647
+ if (!response.ok) {
648
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision request failed with status ${response.status}`;
649
+ const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
650
+ const err = new Error(message);
651
+ err.code = code;
652
+ err.details = data;
653
+ throw err;
654
+ }
655
+ return data;
656
+ }
657
+ };
658
+
659
+ // src/sessions/index.ts
660
+ var SessionsNamespace = class {
661
+ constructor(config) {
662
+ this.config = config;
663
+ }
664
+ async request(method, path, body) {
665
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
666
+ method,
667
+ headers: {
668
+ "CENCORI_API_KEY": this.config.apiKey,
669
+ "Content-Type": "application/json",
670
+ ...this.config.headers
671
+ },
672
+ body: body ? JSON.stringify(body) : void 0
673
+ });
674
+ if (!response.ok) {
675
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
676
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
677
+ }
678
+ if (response.status === 204) return void 0;
679
+ return response.json();
680
+ }
681
+ async create(params) {
682
+ return this.request("POST", "/v1/sessions", params || {});
683
+ }
684
+ async list(params) {
685
+ const searchParams = new URLSearchParams();
686
+ if (params?.page) searchParams.set("page", String(params.page));
687
+ if (params?.limit) searchParams.set("limit", String(params.limit));
688
+ if (params?.status) searchParams.set("status", params.status);
689
+ if (params?.agent_id) searchParams.set("agent_id", params.agent_id);
690
+ const qs = searchParams.toString();
691
+ return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
692
+ }
693
+ async get(sessionId) {
694
+ return this.request("GET", `/v1/sessions/${sessionId}`);
695
+ }
696
+ async delete(sessionId) {
697
+ return this.request("DELETE", `/v1/sessions/${sessionId}`);
698
+ }
699
+ async submitTurn(sessionId, params) {
700
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/turns`;
701
+ return fetch(url, {
702
+ method: "POST",
703
+ headers: {
704
+ "CENCORI_API_KEY": this.config.apiKey,
705
+ "Content-Type": "application/json",
706
+ ...this.config.headers
707
+ },
708
+ body: JSON.stringify(params)
709
+ });
710
+ }
711
+ async submitTurnStream(sessionId, params) {
712
+ const response = await this.submitTurn(sessionId, params);
713
+ if (!response.ok) {
714
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
715
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
716
+ }
717
+ return response.body;
718
+ }
719
+ async getEvents(sessionId, params) {
720
+ const searchParams = new URLSearchParams();
721
+ if (params?.page) searchParams.set("page", String(params.page));
722
+ if (params?.limit) searchParams.set("limit", String(params.limit));
723
+ if (params?.turn_number) searchParams.set("turn_number", String(params.turn_number));
724
+ const qs = searchParams.toString();
725
+ return this.request("GET", `/v1/sessions/${sessionId}/events${qs ? `?${qs}` : ""}`);
726
+ }
727
+ async approve(sessionId, params) {
728
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/approve`;
729
+ return fetch(url, {
730
+ method: "POST",
731
+ headers: {
732
+ "CENCORI_API_KEY": this.config.apiKey,
733
+ "Content-Type": "application/json",
734
+ ...this.config.headers
735
+ },
736
+ body: JSON.stringify(params)
737
+ });
738
+ }
739
+ async approveStream(sessionId, params) {
740
+ const response = await this.approve(sessionId, params);
741
+ if (!response.ok) {
742
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
743
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
744
+ }
745
+ return response.body;
746
+ }
747
+ async reject(sessionId, params) {
748
+ return this.request("POST", `/v1/sessions/${sessionId}/reject`, params);
749
+ }
750
+ };
751
+
421
752
  // src/compute/index.ts
422
753
  var ComputeNamespace = class {
423
754
  /**
@@ -505,7 +836,7 @@ var VectorsNamespace = class {
505
836
  */
506
837
  async search(query, options) {
507
838
  throw new Error(
508
- `cencori.storage.vectors.search() is coming soon! Join our waitlist at https://cencori.com/storage`
839
+ `cencori.storage.vectors.search() is coming soon! Join our waitlist at https://cencori.com/memory`
509
840
  );
510
841
  }
511
842
  /**
@@ -515,7 +846,7 @@ var VectorsNamespace = class {
515
846
  */
516
847
  async upsert(vectors) {
517
848
  throw new Error(
518
- `cencori.storage.vectors.upsert() is coming soon! Join our waitlist at https://cencori.com/storage`
849
+ `cencori.storage.vectors.upsert() is coming soon! Join our waitlist at https://cencori.com/memory`
519
850
  );
520
851
  }
521
852
  /**
@@ -525,7 +856,7 @@ var VectorsNamespace = class {
525
856
  */
526
857
  async delete(ids) {
527
858
  throw new Error(
528
- `cencori.storage.vectors.delete() is coming soon! Join our waitlist at https://cencori.com/storage`
859
+ `cencori.storage.vectors.delete() is coming soon! Join our waitlist at https://cencori.com/memory`
529
860
  );
530
861
  }
531
862
  };
@@ -537,7 +868,7 @@ var KnowledgeNamespace = class {
537
868
  */
538
869
  async query(question) {
539
870
  throw new Error(
540
- `cencori.storage.knowledge.query() is coming soon! Join our waitlist at https://cencori.com/storage`
871
+ `cencori.storage.knowledge.query() is coming soon! Join our waitlist at https://cencori.com/memory`
541
872
  );
542
873
  }
543
874
  /**
@@ -547,7 +878,7 @@ var KnowledgeNamespace = class {
547
878
  */
548
879
  async add(documents) {
549
880
  throw new Error(
550
- `cencori.storage.knowledge.add() is coming soon! Join our waitlist at https://cencori.com/storage`
881
+ `cencori.storage.knowledge.add() is coming soon! Join our waitlist at https://cencori.com/memory`
551
882
  );
552
883
  }
553
884
  };
@@ -559,7 +890,7 @@ var FilesNamespace = class {
559
890
  */
560
891
  async upload(file, name) {
561
892
  throw new Error(
562
- `cencori.storage.files.upload() is coming soon! Join our waitlist at https://cencori.com/storage`
893
+ `cencori.storage.files.upload() is coming soon! Join our waitlist at https://cencori.com/memory`
563
894
  );
564
895
  }
565
896
  /**
@@ -569,7 +900,7 @@ var FilesNamespace = class {
569
900
  */
570
901
  async process(fileId) {
571
902
  throw new Error(
572
- `cencori.storage.files.process() is coming soon! Join our waitlist at https://cencori.com/storage`
903
+ `cencori.storage.files.process() is coming soon! Join our waitlist at https://cencori.com/memory`
573
904
  );
574
905
  }
575
906
  };
@@ -820,7 +1151,7 @@ var SafetyError = class _SafetyError extends CencoriError {
820
1151
  };
821
1152
 
822
1153
  // src/cencori.ts
823
- var DEFAULT_BASE_URL = "https://cencori.com";
1154
+ var DEFAULT_BASE_URL = "https://api.cencori.com";
824
1155
  var Cencori = class {
825
1156
  /**
826
1157
  * Create a new Cencori client
@@ -848,10 +1179,13 @@ var Cencori = class {
848
1179
  headers: config.headers ?? {}
849
1180
  };
850
1181
  this.ai = new AINamespace(this.config);
1182
+ this.vision = new VisionNamespace(this.config);
1183
+ this.agents = new AgentsNamespace(this.config);
851
1184
  this.compute = new ComputeNamespace();
852
1185
  this.workflow = new WorkflowNamespace();
853
1186
  this.storage = new StorageNamespace();
854
1187
  this.memory = new MemoryClient(this.config);
1188
+ this.sessions = new SessionsNamespace(this.config);
855
1189
  this.telemetry = new TelemetryClient(this.config);
856
1190
  }
857
1191
  /**
@@ -1267,6 +1601,7 @@ var cencori = function(modelId, settings) {
1267
1601
  cencori.chat = cencori;
1268
1602
  export {
1269
1603
  AINamespace,
1604
+ AgentsNamespace,
1270
1605
  AuthenticationError,
1271
1606
  Cencori,
1272
1607
  CencoriError,
@@ -1274,8 +1609,10 @@ export {
1274
1609
  MemoryClient,
1275
1610
  RateLimitError,
1276
1611
  SafetyError,
1612
+ SessionsNamespace,
1277
1613
  StorageNamespace,
1278
1614
  TelemetryClient,
1615
+ VisionNamespace,
1279
1616
  WorkflowNamespace,
1280
1617
  cencori,
1281
1618
  createCencori,