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.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  AINamespace: () => AINamespace,
24
+ AgentsNamespace: () => AgentsNamespace,
24
25
  AuthenticationError: () => AuthenticationError,
25
26
  Cencori: () => Cencori,
26
27
  CencoriError: () => CencoriError,
@@ -28,8 +29,10 @@ __export(src_exports, {
28
29
  MemoryClient: () => MemoryClient,
29
30
  RateLimitError: () => RateLimitError,
30
31
  SafetyError: () => SafetyError,
32
+ SessionsNamespace: () => SessionsNamespace,
31
33
  StorageNamespace: () => StorageNamespace,
32
34
  TelemetryClient: () => TelemetryClient,
35
+ VisionNamespace: () => VisionNamespace,
33
36
  WorkflowNamespace: () => WorkflowNamespace,
34
37
  cencori: () => cencori,
35
38
  createCencori: () => createCencori,
@@ -392,6 +395,137 @@ var AINamespace = class {
392
395
  latencyMs: data.latency_ms
393
396
  };
394
397
  }
398
+ /**
399
+ * Send a request to the OpenAI-compatible Responses API.
400
+ * Supports built-in tools: web_search_preview, file_search, code_interpreter.
401
+ *
402
+ * @example
403
+ * const response = await cencori.ai.responses({
404
+ * model: 'gpt-4o',
405
+ * input: 'What is the weather in San Francisco?',
406
+ * tools: [{ type: 'web_search_preview' }]
407
+ * });
408
+ * console.log(response.output[0].content?.[0]?.text);
409
+ */
410
+ async responses(request) {
411
+ const response = await fetch(`${this.config.baseUrl}/v1/responses`, {
412
+ method: "POST",
413
+ headers: {
414
+ "CENCORI_API_KEY": this.config.apiKey,
415
+ "Content-Type": "application/json",
416
+ ...this.config.headers
417
+ },
418
+ body: JSON.stringify({
419
+ model: request.model,
420
+ input: request.input,
421
+ instructions: request.instructions,
422
+ tools: request.tools,
423
+ tool_choice: request.tool_choice,
424
+ temperature: request.temperature,
425
+ max_output_tokens: request.max_output_tokens,
426
+ top_p: request.top_p,
427
+ store: request.store,
428
+ metadata: request.metadata,
429
+ previous_response_id: request.previous_response_id,
430
+ parallel_tool_calls: request.parallel_tool_calls,
431
+ truncation: request.truncation,
432
+ response_format: request.response_format,
433
+ include: request.include,
434
+ stream: false,
435
+ user: request.user
436
+ })
437
+ });
438
+ if (!response.ok) {
439
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
440
+ throw new Error(`Cencori API error: ${errorData.error || response.statusText}`);
441
+ }
442
+ return response.json();
443
+ }
444
+ /**
445
+ * Stream responses from the Responses API via SSE.
446
+ * Yields parsed events as they arrive.
447
+ *
448
+ * @example
449
+ * for await (const event of cencori.ai.responsesStream({
450
+ * model: 'gpt-4o',
451
+ * input: 'Tell me about AI',
452
+ * })) {
453
+ * if (event.type === 'response.output_text.delta') {
454
+ * process.stdout.write(event.data.delta);
455
+ * }
456
+ * }
457
+ */
458
+ async *responsesStream(request) {
459
+ const response = await fetch(`${this.config.baseUrl}/v1/responses`, {
460
+ method: "POST",
461
+ headers: {
462
+ "CENCORI_API_KEY": this.config.apiKey,
463
+ "Content-Type": "application/json",
464
+ ...this.config.headers
465
+ },
466
+ body: JSON.stringify({
467
+ model: request.model,
468
+ input: request.input,
469
+ instructions: request.instructions,
470
+ tools: request.tools,
471
+ tool_choice: request.tool_choice,
472
+ temperature: request.temperature,
473
+ max_output_tokens: request.max_output_tokens,
474
+ top_p: request.top_p,
475
+ store: request.store,
476
+ metadata: request.metadata,
477
+ previous_response_id: request.previous_response_id,
478
+ parallel_tool_calls: request.parallel_tool_calls,
479
+ truncation: request.truncation,
480
+ response_format: request.response_format,
481
+ include: request.include,
482
+ stream: true,
483
+ user: request.user
484
+ })
485
+ });
486
+ if (!response.ok) {
487
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
488
+ throw new Error(`Cencori API error: ${errorData.error || response.statusText}`);
489
+ }
490
+ if (!response.body) {
491
+ throw new Error("Response body is null");
492
+ }
493
+ const reader = response.body.getReader();
494
+ const decoder = new TextDecoder();
495
+ let buffer = "";
496
+ let eventType = "";
497
+ try {
498
+ while (true) {
499
+ const { done, value } = await reader.read();
500
+ if (done) break;
501
+ buffer += decoder.decode(value, { stream: true });
502
+ const lines = buffer.split("\n");
503
+ buffer = lines.pop() || "";
504
+ for (const line of lines) {
505
+ if (line.trim() === "") {
506
+ eventType = "";
507
+ continue;
508
+ }
509
+ if (line.startsWith("event: ")) {
510
+ eventType = line.slice(7).trim();
511
+ continue;
512
+ }
513
+ if (line.startsWith("data: ")) {
514
+ const data = line.slice(6).trim();
515
+ if (!data) continue;
516
+ try {
517
+ const parsed = JSON.parse(data);
518
+ yield { type: eventType || "message", data: parsed };
519
+ } catch {
520
+ }
521
+ eventType = "";
522
+ }
523
+ }
524
+ }
525
+ } finally {
526
+ reader.releaseLock();
527
+ }
528
+ }
395
529
  /**
396
530
  * Stream RAG responses with automatic memory context
397
531
  *
@@ -458,6 +592,206 @@ var AINamespace = class {
458
592
  }
459
593
  };
460
594
 
595
+ // src/agents/index.ts
596
+ var AgentsNamespace = class {
597
+ constructor(config) {
598
+ this.config = config;
599
+ }
600
+ async request(method, path, body) {
601
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
602
+ method,
603
+ headers: {
604
+ "CENCORI_API_KEY": this.config.apiKey,
605
+ "Content-Type": "application/json",
606
+ ...this.config.headers
607
+ },
608
+ body: body ? JSON.stringify(body) : void 0
609
+ });
610
+ if (!response.ok) {
611
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
612
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
613
+ }
614
+ if (response.status === 204) return void 0;
615
+ return response.json();
616
+ }
617
+ async create(params) {
618
+ return this.request("POST", "/v1/agents", params);
619
+ }
620
+ async list() {
621
+ return this.request("GET", "/v1/agents");
622
+ }
623
+ async get(agentId) {
624
+ return this.request("GET", `/v1/agents/${agentId}`);
625
+ }
626
+ async updateConfig(agentId, params) {
627
+ return this.request("PATCH", `/v1/agents/${agentId}`, params);
628
+ }
629
+ async delete(agentId) {
630
+ return this.request("DELETE", `/v1/agents/${agentId}`);
631
+ }
632
+ async createKey(agentId, params) {
633
+ return this.request("POST", `/v1/agents/${agentId}/keys`, params || {});
634
+ }
635
+ };
636
+
637
+ // src/vision/index.ts
638
+ function toBody(request) {
639
+ const body = {
640
+ prompt: request.prompt,
641
+ model: request.model,
642
+ max_tokens: request.maxTokens,
643
+ temperature: request.temperature,
644
+ response_format: request.responseFormat
645
+ };
646
+ if (request.image.url) {
647
+ body.image_url = request.image.url;
648
+ } else if (request.image.base64) {
649
+ body.image_base64 = request.image.base64;
650
+ body.mime_type = request.image.mimeType;
651
+ } else {
652
+ throw new Error("vision request requires image.url or image.base64");
653
+ }
654
+ return body;
655
+ }
656
+ var VisionNamespace = class {
657
+ constructor(config) {
658
+ this.config = config;
659
+ }
660
+ /**
661
+ * General image analysis — provide your own prompt.
662
+ * Default prompt: "Describe this image in detail."
663
+ */
664
+ async analyze(request) {
665
+ return this.post("/api/ai/vision", request);
666
+ }
667
+ /** Describe the image in rich detail. */
668
+ async describe(request) {
669
+ return this.post("/api/ai/vision/describe", request);
670
+ }
671
+ /** Extract all visible text from the image. */
672
+ async ocr(request) {
673
+ return this.post("/api/ai/vision/ocr", request);
674
+ }
675
+ /** Return structured tags, objects, and category classification. */
676
+ async classify(request) {
677
+ return this.post("/api/ai/vision/classify", request);
678
+ }
679
+ async post(path, request) {
680
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
681
+ method: "POST",
682
+ headers: {
683
+ "CENCORI_API_KEY": this.config.apiKey,
684
+ "Content-Type": "application/json",
685
+ ...this.config.headers
686
+ },
687
+ body: JSON.stringify(toBody(request))
688
+ });
689
+ const data = await response.json();
690
+ if (!response.ok) {
691
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision request failed with status ${response.status}`;
692
+ const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
693
+ const err = new Error(message);
694
+ err.code = code;
695
+ err.details = data;
696
+ throw err;
697
+ }
698
+ return data;
699
+ }
700
+ };
701
+
702
+ // src/sessions/index.ts
703
+ var SessionsNamespace = class {
704
+ constructor(config) {
705
+ this.config = config;
706
+ }
707
+ async request(method, path, body) {
708
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
709
+ method,
710
+ headers: {
711
+ "CENCORI_API_KEY": this.config.apiKey,
712
+ "Content-Type": "application/json",
713
+ ...this.config.headers
714
+ },
715
+ body: body ? JSON.stringify(body) : void 0
716
+ });
717
+ if (!response.ok) {
718
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
719
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
720
+ }
721
+ if (response.status === 204) return void 0;
722
+ return response.json();
723
+ }
724
+ async create(params) {
725
+ return this.request("POST", "/v1/sessions", params || {});
726
+ }
727
+ async list(params) {
728
+ const searchParams = new URLSearchParams();
729
+ if (params?.page) searchParams.set("page", String(params.page));
730
+ if (params?.limit) searchParams.set("limit", String(params.limit));
731
+ if (params?.status) searchParams.set("status", params.status);
732
+ if (params?.agent_id) searchParams.set("agent_id", params.agent_id);
733
+ const qs = searchParams.toString();
734
+ return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
735
+ }
736
+ async get(sessionId) {
737
+ return this.request("GET", `/v1/sessions/${sessionId}`);
738
+ }
739
+ async delete(sessionId) {
740
+ return this.request("DELETE", `/v1/sessions/${sessionId}`);
741
+ }
742
+ async submitTurn(sessionId, params) {
743
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/turns`;
744
+ return fetch(url, {
745
+ method: "POST",
746
+ headers: {
747
+ "CENCORI_API_KEY": this.config.apiKey,
748
+ "Content-Type": "application/json",
749
+ ...this.config.headers
750
+ },
751
+ body: JSON.stringify(params)
752
+ });
753
+ }
754
+ async submitTurnStream(sessionId, params) {
755
+ const response = await this.submitTurn(sessionId, params);
756
+ if (!response.ok) {
757
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
758
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
759
+ }
760
+ return response.body;
761
+ }
762
+ async getEvents(sessionId, params) {
763
+ const searchParams = new URLSearchParams();
764
+ if (params?.page) searchParams.set("page", String(params.page));
765
+ if (params?.limit) searchParams.set("limit", String(params.limit));
766
+ if (params?.turn_number) searchParams.set("turn_number", String(params.turn_number));
767
+ const qs = searchParams.toString();
768
+ return this.request("GET", `/v1/sessions/${sessionId}/events${qs ? `?${qs}` : ""}`);
769
+ }
770
+ async approve(sessionId, params) {
771
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/approve`;
772
+ return fetch(url, {
773
+ method: "POST",
774
+ headers: {
775
+ "CENCORI_API_KEY": this.config.apiKey,
776
+ "Content-Type": "application/json",
777
+ ...this.config.headers
778
+ },
779
+ body: JSON.stringify(params)
780
+ });
781
+ }
782
+ async approveStream(sessionId, params) {
783
+ const response = await this.approve(sessionId, params);
784
+ if (!response.ok) {
785
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
786
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
787
+ }
788
+ return response.body;
789
+ }
790
+ async reject(sessionId, params) {
791
+ return this.request("POST", `/v1/sessions/${sessionId}/reject`, params);
792
+ }
793
+ };
794
+
461
795
  // src/compute/index.ts
462
796
  var ComputeNamespace = class {
463
797
  /**
@@ -545,7 +879,7 @@ var VectorsNamespace = class {
545
879
  */
546
880
  async search(query, options) {
547
881
  throw new Error(
548
- `cencori.storage.vectors.search() is coming soon! Join our waitlist at https://cencori.com/storage`
882
+ `cencori.storage.vectors.search() is coming soon! Join our waitlist at https://cencori.com/memory`
549
883
  );
550
884
  }
551
885
  /**
@@ -555,7 +889,7 @@ var VectorsNamespace = class {
555
889
  */
556
890
  async upsert(vectors) {
557
891
  throw new Error(
558
- `cencori.storage.vectors.upsert() is coming soon! Join our waitlist at https://cencori.com/storage`
892
+ `cencori.storage.vectors.upsert() is coming soon! Join our waitlist at https://cencori.com/memory`
559
893
  );
560
894
  }
561
895
  /**
@@ -565,7 +899,7 @@ var VectorsNamespace = class {
565
899
  */
566
900
  async delete(ids) {
567
901
  throw new Error(
568
- `cencori.storage.vectors.delete() is coming soon! Join our waitlist at https://cencori.com/storage`
902
+ `cencori.storage.vectors.delete() is coming soon! Join our waitlist at https://cencori.com/memory`
569
903
  );
570
904
  }
571
905
  };
@@ -577,7 +911,7 @@ var KnowledgeNamespace = class {
577
911
  */
578
912
  async query(question) {
579
913
  throw new Error(
580
- `cencori.storage.knowledge.query() is coming soon! Join our waitlist at https://cencori.com/storage`
914
+ `cencori.storage.knowledge.query() is coming soon! Join our waitlist at https://cencori.com/memory`
581
915
  );
582
916
  }
583
917
  /**
@@ -587,7 +921,7 @@ var KnowledgeNamespace = class {
587
921
  */
588
922
  async add(documents) {
589
923
  throw new Error(
590
- `cencori.storage.knowledge.add() is coming soon! Join our waitlist at https://cencori.com/storage`
924
+ `cencori.storage.knowledge.add() is coming soon! Join our waitlist at https://cencori.com/memory`
591
925
  );
592
926
  }
593
927
  };
@@ -599,7 +933,7 @@ var FilesNamespace = class {
599
933
  */
600
934
  async upload(file, name) {
601
935
  throw new Error(
602
- `cencori.storage.files.upload() is coming soon! Join our waitlist at https://cencori.com/storage`
936
+ `cencori.storage.files.upload() is coming soon! Join our waitlist at https://cencori.com/memory`
603
937
  );
604
938
  }
605
939
  /**
@@ -609,7 +943,7 @@ var FilesNamespace = class {
609
943
  */
610
944
  async process(fileId) {
611
945
  throw new Error(
612
- `cencori.storage.files.process() is coming soon! Join our waitlist at https://cencori.com/storage`
946
+ `cencori.storage.files.process() is coming soon! Join our waitlist at https://cencori.com/memory`
613
947
  );
614
948
  }
615
949
  };
@@ -860,7 +1194,7 @@ var SafetyError = class _SafetyError extends CencoriError {
860
1194
  };
861
1195
 
862
1196
  // src/cencori.ts
863
- var DEFAULT_BASE_URL = "https://cencori.com";
1197
+ var DEFAULT_BASE_URL = "https://api.cencori.com";
864
1198
  var Cencori = class {
865
1199
  /**
866
1200
  * Create a new Cencori client
@@ -888,10 +1222,13 @@ var Cencori = class {
888
1222
  headers: config.headers ?? {}
889
1223
  };
890
1224
  this.ai = new AINamespace(this.config);
1225
+ this.vision = new VisionNamespace(this.config);
1226
+ this.agents = new AgentsNamespace(this.config);
891
1227
  this.compute = new ComputeNamespace();
892
1228
  this.workflow = new WorkflowNamespace();
893
1229
  this.storage = new StorageNamespace();
894
1230
  this.memory = new MemoryClient(this.config);
1231
+ this.sessions = new SessionsNamespace(this.config);
895
1232
  this.telemetry = new TelemetryClient(this.config);
896
1233
  }
897
1234
  /**
@@ -1308,6 +1645,7 @@ cencori.chat = cencori;
1308
1645
  // Annotate the CommonJS export names for ESM import in node:
1309
1646
  0 && (module.exports = {
1310
1647
  AINamespace,
1648
+ AgentsNamespace,
1311
1649
  AuthenticationError,
1312
1650
  Cencori,
1313
1651
  CencoriError,
@@ -1315,8 +1653,10 @@ cencori.chat = cencori;
1315
1653
  MemoryClient,
1316
1654
  RateLimitError,
1317
1655
  SafetyError,
1656
+ SessionsNamespace,
1318
1657
  StorageNamespace,
1319
1658
  TelemetryClient,
1659
+ VisionNamespace,
1320
1660
  WorkflowNamespace,
1321
1661
  cencori,
1322
1662
  createCencori,