cencori 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,
@@ -589,6 +592,257 @@ var AINamespace = class {
589
592
  }
590
593
  };
591
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
+ /**
680
+ * Stream a vision analysis. Yields `{ delta }` chunks as text arrives, then
681
+ * a final `{ done: true, model, provider, usage, cost }` chunk with totals.
682
+ *
683
+ * @example
684
+ * for await (const chunk of cencori.vision.analyzeStream({ image: { url } })) {
685
+ * if (chunk.delta) process.stdout.write(chunk.delta);
686
+ * if (chunk.done) console.log(chunk.cost);
687
+ * }
688
+ */
689
+ async *analyzeStream(request) {
690
+ const body = { ...toBody(request), stream: true };
691
+ const response = await fetch(`${this.config.baseUrl}/api/ai/vision`, {
692
+ method: "POST",
693
+ headers: {
694
+ "CENCORI_API_KEY": this.config.apiKey,
695
+ "Content-Type": "application/json",
696
+ ...this.config.headers
697
+ },
698
+ body: JSON.stringify(body)
699
+ });
700
+ if (!response.ok) {
701
+ const data = await response.json().catch(() => ({}));
702
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision stream request failed with status ${response.status}`;
703
+ throw new Error(message);
704
+ }
705
+ if (!response.body) throw new Error("Response body is null");
706
+ const reader = response.body.getReader();
707
+ const decoder = new TextDecoder();
708
+ let buffer = "";
709
+ try {
710
+ while (true) {
711
+ const { done, value } = await reader.read();
712
+ if (done) break;
713
+ buffer += decoder.decode(value, { stream: true });
714
+ const lines = buffer.split("\n");
715
+ buffer = lines.pop() ?? "";
716
+ for (const line of lines) {
717
+ if (!line.startsWith("data: ")) continue;
718
+ const data = line.slice(6);
719
+ if (data === "[DONE]") return;
720
+ try {
721
+ yield JSON.parse(data);
722
+ } catch {
723
+ }
724
+ }
725
+ }
726
+ } finally {
727
+ reader.releaseLock();
728
+ }
729
+ }
730
+ async post(path, request) {
731
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
732
+ method: "POST",
733
+ headers: {
734
+ "CENCORI_API_KEY": this.config.apiKey,
735
+ "Content-Type": "application/json",
736
+ ...this.config.headers
737
+ },
738
+ body: JSON.stringify(toBody(request))
739
+ });
740
+ const data = await response.json();
741
+ if (!response.ok) {
742
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision request failed with status ${response.status}`;
743
+ const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
744
+ const err = new Error(message);
745
+ err.code = code;
746
+ err.details = data;
747
+ throw err;
748
+ }
749
+ return data;
750
+ }
751
+ };
752
+
753
+ // src/sessions/index.ts
754
+ var SessionsNamespace = class {
755
+ constructor(config) {
756
+ this.config = config;
757
+ }
758
+ async request(method, path, body) {
759
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
760
+ method,
761
+ headers: {
762
+ "CENCORI_API_KEY": this.config.apiKey,
763
+ "Content-Type": "application/json",
764
+ ...this.config.headers
765
+ },
766
+ body: body ? JSON.stringify(body) : void 0
767
+ });
768
+ if (!response.ok) {
769
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
770
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
771
+ }
772
+ if (response.status === 204) return void 0;
773
+ return response.json();
774
+ }
775
+ async create(params) {
776
+ return this.request("POST", "/v1/sessions", params || {});
777
+ }
778
+ async list(params) {
779
+ const searchParams = new URLSearchParams();
780
+ if (params?.page) searchParams.set("page", String(params.page));
781
+ if (params?.limit) searchParams.set("limit", String(params.limit));
782
+ if (params?.status) searchParams.set("status", params.status);
783
+ if (params?.agent_id) searchParams.set("agent_id", params.agent_id);
784
+ const qs = searchParams.toString();
785
+ return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
786
+ }
787
+ async get(sessionId) {
788
+ return this.request("GET", `/v1/sessions/${sessionId}`);
789
+ }
790
+ async delete(sessionId) {
791
+ return this.request("DELETE", `/v1/sessions/${sessionId}`);
792
+ }
793
+ async submitTurn(sessionId, params) {
794
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/turns`;
795
+ return fetch(url, {
796
+ method: "POST",
797
+ headers: {
798
+ "CENCORI_API_KEY": this.config.apiKey,
799
+ "Content-Type": "application/json",
800
+ ...this.config.headers
801
+ },
802
+ body: JSON.stringify(params)
803
+ });
804
+ }
805
+ async submitTurnStream(sessionId, params) {
806
+ const response = await this.submitTurn(sessionId, params);
807
+ if (!response.ok) {
808
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
809
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
810
+ }
811
+ return response.body;
812
+ }
813
+ async getEvents(sessionId, params) {
814
+ const searchParams = new URLSearchParams();
815
+ if (params?.page) searchParams.set("page", String(params.page));
816
+ if (params?.limit) searchParams.set("limit", String(params.limit));
817
+ if (params?.turn_number) searchParams.set("turn_number", String(params.turn_number));
818
+ const qs = searchParams.toString();
819
+ return this.request("GET", `/v1/sessions/${sessionId}/events${qs ? `?${qs}` : ""}`);
820
+ }
821
+ async approve(sessionId, params) {
822
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/approve`;
823
+ return fetch(url, {
824
+ method: "POST",
825
+ headers: {
826
+ "CENCORI_API_KEY": this.config.apiKey,
827
+ "Content-Type": "application/json",
828
+ ...this.config.headers
829
+ },
830
+ body: JSON.stringify(params)
831
+ });
832
+ }
833
+ async approveStream(sessionId, params) {
834
+ const response = await this.approve(sessionId, params);
835
+ if (!response.ok) {
836
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
837
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
838
+ }
839
+ return response.body;
840
+ }
841
+ async reject(sessionId, params) {
842
+ return this.request("POST", `/v1/sessions/${sessionId}/reject`, params);
843
+ }
844
+ };
845
+
592
846
  // src/compute/index.ts
593
847
  var ComputeNamespace = class {
594
848
  /**
@@ -991,7 +1245,7 @@ var SafetyError = class _SafetyError extends CencoriError {
991
1245
  };
992
1246
 
993
1247
  // src/cencori.ts
994
- var DEFAULT_BASE_URL = "https://cencori.com";
1248
+ var DEFAULT_BASE_URL = "https://api.cencori.com";
995
1249
  var Cencori = class {
996
1250
  /**
997
1251
  * Create a new Cencori client
@@ -1019,10 +1273,13 @@ var Cencori = class {
1019
1273
  headers: config.headers ?? {}
1020
1274
  };
1021
1275
  this.ai = new AINamespace(this.config);
1276
+ this.vision = new VisionNamespace(this.config);
1277
+ this.agents = new AgentsNamespace(this.config);
1022
1278
  this.compute = new ComputeNamespace();
1023
1279
  this.workflow = new WorkflowNamespace();
1024
1280
  this.storage = new StorageNamespace();
1025
1281
  this.memory = new MemoryClient(this.config);
1282
+ this.sessions = new SessionsNamespace(this.config);
1026
1283
  this.telemetry = new TelemetryClient(this.config);
1027
1284
  }
1028
1285
  /**
@@ -1439,6 +1696,7 @@ cencori.chat = cencori;
1439
1696
  // Annotate the CommonJS export names for ESM import in node:
1440
1697
  0 && (module.exports = {
1441
1698
  AINamespace,
1699
+ AgentsNamespace,
1442
1700
  AuthenticationError,
1443
1701
  Cencori,
1444
1702
  CencoriError,
@@ -1446,8 +1704,10 @@ cencori.chat = cencori;
1446
1704
  MemoryClient,
1447
1705
  RateLimitError,
1448
1706
  SafetyError,
1707
+ SessionsNamespace,
1449
1708
  StorageNamespace,
1450
1709
  TelemetryClient,
1710
+ VisionNamespace,
1451
1711
  WorkflowNamespace,
1452
1712
  cencori,
1453
1713
  createCencori,