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.mjs CHANGED
@@ -549,6 +549,257 @@ var AINamespace = class {
549
549
  }
550
550
  };
551
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
+ /**
637
+ * Stream a vision analysis. Yields `{ delta }` chunks as text arrives, then
638
+ * a final `{ done: true, model, provider, usage, cost }` chunk with totals.
639
+ *
640
+ * @example
641
+ * for await (const chunk of cencori.vision.analyzeStream({ image: { url } })) {
642
+ * if (chunk.delta) process.stdout.write(chunk.delta);
643
+ * if (chunk.done) console.log(chunk.cost);
644
+ * }
645
+ */
646
+ async *analyzeStream(request) {
647
+ const body = { ...toBody(request), stream: true };
648
+ const response = await fetch(`${this.config.baseUrl}/api/ai/vision`, {
649
+ method: "POST",
650
+ headers: {
651
+ "CENCORI_API_KEY": this.config.apiKey,
652
+ "Content-Type": "application/json",
653
+ ...this.config.headers
654
+ },
655
+ body: JSON.stringify(body)
656
+ });
657
+ if (!response.ok) {
658
+ const data = await response.json().catch(() => ({}));
659
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision stream request failed with status ${response.status}`;
660
+ throw new Error(message);
661
+ }
662
+ if (!response.body) throw new Error("Response body is null");
663
+ const reader = response.body.getReader();
664
+ const decoder = new TextDecoder();
665
+ let buffer = "";
666
+ try {
667
+ while (true) {
668
+ const { done, value } = await reader.read();
669
+ if (done) break;
670
+ buffer += decoder.decode(value, { stream: true });
671
+ const lines = buffer.split("\n");
672
+ buffer = lines.pop() ?? "";
673
+ for (const line of lines) {
674
+ if (!line.startsWith("data: ")) continue;
675
+ const data = line.slice(6);
676
+ if (data === "[DONE]") return;
677
+ try {
678
+ yield JSON.parse(data);
679
+ } catch {
680
+ }
681
+ }
682
+ }
683
+ } finally {
684
+ reader.releaseLock();
685
+ }
686
+ }
687
+ async post(path, request) {
688
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
689
+ method: "POST",
690
+ headers: {
691
+ "CENCORI_API_KEY": this.config.apiKey,
692
+ "Content-Type": "application/json",
693
+ ...this.config.headers
694
+ },
695
+ body: JSON.stringify(toBody(request))
696
+ });
697
+ const data = await response.json();
698
+ if (!response.ok) {
699
+ const message = data && typeof data === "object" && "message" in data && typeof data.message === "string" ? data.message : `Vision request failed with status ${response.status}`;
700
+ const code = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : "request_failed";
701
+ const err = new Error(message);
702
+ err.code = code;
703
+ err.details = data;
704
+ throw err;
705
+ }
706
+ return data;
707
+ }
708
+ };
709
+
710
+ // src/sessions/index.ts
711
+ var SessionsNamespace = class {
712
+ constructor(config) {
713
+ this.config = config;
714
+ }
715
+ async request(method, path, body) {
716
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
717
+ method,
718
+ headers: {
719
+ "CENCORI_API_KEY": this.config.apiKey,
720
+ "Content-Type": "application/json",
721
+ ...this.config.headers
722
+ },
723
+ body: body ? JSON.stringify(body) : void 0
724
+ });
725
+ if (!response.ok) {
726
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
727
+ throw new Error(`Cencori API error: ${errorData.error?.message || response.statusText}`);
728
+ }
729
+ if (response.status === 204) return void 0;
730
+ return response.json();
731
+ }
732
+ async create(params) {
733
+ return this.request("POST", "/v1/sessions", params || {});
734
+ }
735
+ async list(params) {
736
+ const searchParams = new URLSearchParams();
737
+ if (params?.page) searchParams.set("page", String(params.page));
738
+ if (params?.limit) searchParams.set("limit", String(params.limit));
739
+ if (params?.status) searchParams.set("status", params.status);
740
+ if (params?.agent_id) searchParams.set("agent_id", params.agent_id);
741
+ const qs = searchParams.toString();
742
+ return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
743
+ }
744
+ async get(sessionId) {
745
+ return this.request("GET", `/v1/sessions/${sessionId}`);
746
+ }
747
+ async delete(sessionId) {
748
+ return this.request("DELETE", `/v1/sessions/${sessionId}`);
749
+ }
750
+ async submitTurn(sessionId, params) {
751
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/turns`;
752
+ return fetch(url, {
753
+ method: "POST",
754
+ headers: {
755
+ "CENCORI_API_KEY": this.config.apiKey,
756
+ "Content-Type": "application/json",
757
+ ...this.config.headers
758
+ },
759
+ body: JSON.stringify(params)
760
+ });
761
+ }
762
+ async submitTurnStream(sessionId, params) {
763
+ const response = await this.submitTurn(sessionId, params);
764
+ if (!response.ok) {
765
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
766
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
767
+ }
768
+ return response.body;
769
+ }
770
+ async getEvents(sessionId, params) {
771
+ const searchParams = new URLSearchParams();
772
+ if (params?.page) searchParams.set("page", String(params.page));
773
+ if (params?.limit) searchParams.set("limit", String(params.limit));
774
+ if (params?.turn_number) searchParams.set("turn_number", String(params.turn_number));
775
+ const qs = searchParams.toString();
776
+ return this.request("GET", `/v1/sessions/${sessionId}/events${qs ? `?${qs}` : ""}`);
777
+ }
778
+ async approve(sessionId, params) {
779
+ const url = `${this.config.baseUrl}/v1/sessions/${sessionId}/approve`;
780
+ return fetch(url, {
781
+ method: "POST",
782
+ headers: {
783
+ "CENCORI_API_KEY": this.config.apiKey,
784
+ "Content-Type": "application/json",
785
+ ...this.config.headers
786
+ },
787
+ body: JSON.stringify(params)
788
+ });
789
+ }
790
+ async approveStream(sessionId, params) {
791
+ const response = await this.approve(sessionId, params);
792
+ if (!response.ok) {
793
+ const err = await response.json().catch(() => ({ error: "Unknown error" }));
794
+ throw new Error(`Cencori API error: ${err.error?.message || response.statusText}`);
795
+ }
796
+ return response.body;
797
+ }
798
+ async reject(sessionId, params) {
799
+ return this.request("POST", `/v1/sessions/${sessionId}/reject`, params);
800
+ }
801
+ };
802
+
552
803
  // src/compute/index.ts
553
804
  var ComputeNamespace = class {
554
805
  /**
@@ -951,7 +1202,7 @@ var SafetyError = class _SafetyError extends CencoriError {
951
1202
  };
952
1203
 
953
1204
  // src/cencori.ts
954
- var DEFAULT_BASE_URL = "https://cencori.com";
1205
+ var DEFAULT_BASE_URL = "https://api.cencori.com";
955
1206
  var Cencori = class {
956
1207
  /**
957
1208
  * Create a new Cencori client
@@ -979,10 +1230,13 @@ var Cencori = class {
979
1230
  headers: config.headers ?? {}
980
1231
  };
981
1232
  this.ai = new AINamespace(this.config);
1233
+ this.vision = new VisionNamespace(this.config);
1234
+ this.agents = new AgentsNamespace(this.config);
982
1235
  this.compute = new ComputeNamespace();
983
1236
  this.workflow = new WorkflowNamespace();
984
1237
  this.storage = new StorageNamespace();
985
1238
  this.memory = new MemoryClient(this.config);
1239
+ this.sessions = new SessionsNamespace(this.config);
986
1240
  this.telemetry = new TelemetryClient(this.config);
987
1241
  }
988
1242
  /**
@@ -1398,6 +1652,7 @@ var cencori = function(modelId, settings) {
1398
1652
  cencori.chat = cencori;
1399
1653
  export {
1400
1654
  AINamespace,
1655
+ AgentsNamespace,
1401
1656
  AuthenticationError,
1402
1657
  Cencori,
1403
1658
  CencoriError,
@@ -1405,8 +1660,10 @@ export {
1405
1660
  MemoryClient,
1406
1661
  RateLimitError,
1407
1662
  SafetyError,
1663
+ SessionsNamespace,
1408
1664
  StorageNamespace,
1409
1665
  TelemetryClient,
1666
+ VisionNamespace,
1410
1667
  WorkflowNamespace,
1411
1668
  cencori,
1412
1669
  createCencori,