tevrocsdk 0.1.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.
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "tevrocsdk",
3
+ "version": "0.1.0",
4
+ "description": "Base44-style JavaScript SDK for the Tevroc Worker API.",
5
+ "main": "./tevroc-sdk.umd.js",
6
+ "module": "./tevroc-sdk.esm.js",
7
+ "license": "MIT"
8
+ }
@@ -0,0 +1,291 @@
1
+ // src/index.js
2
+ var DEFAULT_TIMEOUT_MS = 3e4;
3
+ var TevrocError = class extends Error {
4
+ constructor(message, options = {}) {
5
+ super(message);
6
+ this.name = "TevrocError";
7
+ this.status = options.status;
8
+ this.code = options.code;
9
+ this.details = options.details;
10
+ this.response = options.response;
11
+ }
12
+ };
13
+ function createClient(options = {}) {
14
+ return new TevrocClient(options);
15
+ }
16
+ var TevrocClient = class {
17
+ constructor(options = {}) {
18
+ const baseUrl = options.baseUrl ?? options.url;
19
+ if (!baseUrl) throw new TypeError("createClient requires a baseUrl");
20
+ this.baseUrl = normalizeBaseUrl(baseUrl);
21
+ this.fetch = options.fetch ?? globalThis.fetch;
22
+ if (typeof this.fetch !== "function") throw new TypeError("No fetch implementation available");
23
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
24
+ this.defaultHeaders = normalizeHeaders(options.headers);
25
+ this.token = options.token ?? null;
26
+ this.auth = createAuthApi(this);
27
+ this.entities = createEntityRegistry(this);
28
+ this.functions = createFunctionRegistry(this);
29
+ this.integrations = createIntegrationApi(this);
30
+ this.agents = createAgentRegistry(this);
31
+ this.logs = createLogApi(this);
32
+ this.connectors = createConnectorApi(this);
33
+ this.customIntegrations = createCustomIntegrationRegistry(this);
34
+ this.sso = createSsoApi(this);
35
+ this.files = createFileApi(this);
36
+ }
37
+ setToken(token) {
38
+ this.token = token || null;
39
+ return this;
40
+ }
41
+ clearToken() {
42
+ this.token = null;
43
+ return this;
44
+ }
45
+ async request(path, options = {}) {
46
+ const method = (options.method ?? "GET").toUpperCase();
47
+ const headers = new Headers(this.defaultHeaders);
48
+ const query = options.query ? toSearchParams(options.query) : "";
49
+ const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
50
+ const controller = new AbortController();
51
+ const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.timeoutMs);
52
+ if (this.token && options.auth !== false) headers.set("authorization", `Bearer ${this.token}`);
53
+ let body = options.body;
54
+ if (body !== void 0 && body !== null && isJsonBody(body)) {
55
+ headers.set("content-type", "application/json");
56
+ body = JSON.stringify(body);
57
+ }
58
+ if (options.headers) {
59
+ for (const [key, value] of Object.entries(options.headers)) {
60
+ if (value !== void 0 && value !== null) headers.set(key, String(value));
61
+ }
62
+ }
63
+ try {
64
+ const response = await this.fetch(url, {
65
+ method,
66
+ headers,
67
+ body,
68
+ signal: options.signal ?? controller.signal
69
+ });
70
+ return await parseResponse(response, options.parseAs);
71
+ } catch (error) {
72
+ if (error?.name === "AbortError") throw new TevrocError("Request timed out", { code: "timeout" });
73
+ if (error instanceof TevrocError) throw error;
74
+ throw new TevrocError(error?.message ?? "Network request failed", { code: "network_error", details: error });
75
+ } finally {
76
+ clearTimeout(timeout);
77
+ }
78
+ }
79
+ };
80
+ function createAuthApi(client) {
81
+ return {
82
+ async register(input) {
83
+ const result = await client.request("/auth/register", { method: "POST", body: input, auth: false });
84
+ if (result.token) client.setToken(result.token);
85
+ return result;
86
+ },
87
+ async login(input) {
88
+ const result = await client.request("/auth/login", { method: "POST", body: input, auth: false });
89
+ if (result.token) client.setToken(result.token);
90
+ return result;
91
+ },
92
+ async logout() {
93
+ const result = await client.request("/auth/logout", { method: "POST" });
94
+ client.clearToken();
95
+ return result;
96
+ },
97
+ me: () => client.request("/auth/me"),
98
+ verifyOtp: (input) => client.request("/auth/verify-otp", { method: "POST", body: input, auth: false }),
99
+ changePassword: (input) => client.request("/auth/change-password", { method: "POST", body: input }),
100
+ resetPassword: (input) => client.request("/auth/reset-password", { method: "POST", body: input, auth: false }),
101
+ loginUrl: (redirectTo) => client.request("/auth/login-url", { query: redirectTo ? { redirectTo } : void 0, auth: false })
102
+ };
103
+ }
104
+ function createEntityRegistry(client) {
105
+ return new Proxy(
106
+ {},
107
+ {
108
+ get(_target, entity) {
109
+ if (typeof entity !== "string") return void 0;
110
+ return createEntityApi(client, entity);
111
+ }
112
+ }
113
+ );
114
+ }
115
+ function createEntityApi(client, entity) {
116
+ const base = `/entities/${encodeURIComponent(entity)}`;
117
+ return {
118
+ list: (options) => client.request(base, { query: options }),
119
+ get: (id) => client.request(`${base}/${encodeURIComponent(id)}`),
120
+ create: (record) => client.request(base, { method: "POST", body: record }),
121
+ update: (id, patch) => client.request(`${base}/${encodeURIComponent(id)}`, { method: "PATCH", body: patch }),
122
+ delete: (id) => client.request(`${base}/${encodeURIComponent(id)}`, { method: "DELETE" }),
123
+ query: (input = {}) => client.request(`${base}/query`, { method: "POST", body: input }),
124
+ bulkCreate: (records) => client.request(`${base}/bulk`, { method: "POST", body: { records } }),
125
+ bulkUpdate: (records) => client.request(`${base}/bulk`, { method: "PATCH", body: { records } }),
126
+ bulkDelete: (ids) => client.request(`${base}/bulk`, { method: "DELETE", body: { ids } }),
127
+ import: (records) => client.request(`${base}/import`, { method: "POST", body: { records } })
128
+ };
129
+ }
130
+ function createFunctionRegistry(client) {
131
+ return new Proxy(
132
+ {
133
+ invoke: (name, payload) => client.request(`/functions/${encodeURIComponent(name)}`, { method: "POST", body: payload })
134
+ },
135
+ {
136
+ get(target, name) {
137
+ if (name in target) return target[name];
138
+ if (typeof name !== "string") return void 0;
139
+ return (payload) => target.invoke(name, payload);
140
+ }
141
+ }
142
+ );
143
+ }
144
+ function createIntegrationApi(client) {
145
+ return {
146
+ Core: {
147
+ InvokeLLM: (payload) => client.request("/integrations/core/invoke-llm", { method: "POST", body: payload }),
148
+ GenerateImage: (payload) => client.request("/integrations/core/generate-image", { method: "POST", body: payload }),
149
+ UploadFile: (file, options = {}) => upload(client, "/integrations/core/upload-file", file, options),
150
+ UploadPrivateFile: (file, options = {}) => upload(client, "/integrations/core/upload-private-file", file, options),
151
+ CreateFileSignedUrl: (payload) => client.request("/integrations/core/create-file-signed-url", { method: "POST", body: payload }),
152
+ SendEmail: (payload) => client.request("/integrations/core/send-email", { method: "POST", body: payload }),
153
+ ExtractDataFromUploadedFile: (payload) => client.request("/integrations/core/extract-data-from-uploaded-file", { method: "POST", body: payload })
154
+ }
155
+ };
156
+ }
157
+ function createAgentRegistry(client) {
158
+ return new Proxy(
159
+ {},
160
+ {
161
+ get(_target, agentName) {
162
+ if (typeof agentName !== "string") return void 0;
163
+ return createAgentApi(client, agentName);
164
+ }
165
+ }
166
+ );
167
+ }
168
+ function createAgentApi(client, agentName) {
169
+ const base = `/agents/${encodeURIComponent(agentName)}/conversations`;
170
+ return {
171
+ createConversation: (input = {}) => client.request(base, { method: "POST", body: input }),
172
+ listConversations: () => client.request(base),
173
+ getConversation: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}`),
174
+ deleteConversation: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}`, { method: "DELETE" }),
175
+ addMessage: (conversationId, input) => client.request(`${base}/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input }),
176
+ listMessages: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}/messages`)
177
+ };
178
+ }
179
+ function createLogApi(client) {
180
+ return {
181
+ list: (options) => client.request("/app-logs", { query: options }),
182
+ create: (input) => client.request("/app-logs", { method: "POST", body: input }),
183
+ get: (id) => client.request(`/app-logs/${encodeURIComponent(id)}`)
184
+ };
185
+ }
186
+ function createConnectorApi(client) {
187
+ return {
188
+ list: () => client.request("/connectors"),
189
+ get: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}`),
190
+ connect: (connectorName, input = {}) => client.request(`/connectors/${encodeURIComponent(connectorName)}/connect`, { method: "POST", body: input }),
191
+ disconnect: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}/disconnect`, { method: "POST" }),
192
+ status: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}/status`),
193
+ user: {
194
+ list: () => client.request("/user-connectors"),
195
+ get: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}`),
196
+ refresh: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}/refresh`, { method: "POST" }),
197
+ delete: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}`, { method: "DELETE" })
198
+ }
199
+ };
200
+ }
201
+ function createCustomIntegrationRegistry(client) {
202
+ return new Proxy(
203
+ {
204
+ invoke: (integrationName, endpointName, payload) => client.request(`/custom-integrations/${encodeURIComponent(integrationName)}/${encodeURIComponent(endpointName)}`, {
205
+ method: "POST",
206
+ body: payload
207
+ })
208
+ },
209
+ {
210
+ get(target, integrationName) {
211
+ if (integrationName in target) return target[integrationName];
212
+ if (typeof integrationName !== "string") return void 0;
213
+ return new Proxy(
214
+ {},
215
+ {
216
+ get(_innerTarget, endpointName) {
217
+ if (typeof endpointName !== "string") return void 0;
218
+ return (payload) => target.invoke(integrationName, endpointName, payload);
219
+ }
220
+ }
221
+ );
222
+ }
223
+ }
224
+ );
225
+ }
226
+ function createSsoApi(client) {
227
+ return {
228
+ accessToken: (input) => client.request("/sso/access-token", { method: "POST", body: input, auth: false }),
229
+ callback: (query) => client.request("/sso/callback", { query, auth: false })
230
+ };
231
+ }
232
+ function createFileApi(client) {
233
+ return {
234
+ url: (key) => `${client.baseUrl}/files/${encodeURIComponent(key)}`,
235
+ privateUrl: (key) => `${client.baseUrl}/private-files/${encodeURIComponent(key)}`,
236
+ get: (key) => client.request(`/files/${encodeURIComponent(key)}`, { parseAs: "response", auth: false }),
237
+ getPrivate: (key) => client.request(`/private-files/${encodeURIComponent(key)}`, { parseAs: "response" })
238
+ };
239
+ }
240
+ function upload(client, path, file, options) {
241
+ const headers = {};
242
+ if (options.filename) headers["x-filename"] = options.filename;
243
+ if (options.contentType) headers["content-type"] = options.contentType;
244
+ return client.request(path, { method: "POST", body: file, headers });
245
+ }
246
+ async function parseResponse(response, parseAs) {
247
+ if (parseAs === "response") return response;
248
+ const contentType = response.headers.get("content-type") ?? "";
249
+ const isJson = contentType.includes("application/json");
250
+ const data = isJson ? await response.json() : await response.text();
251
+ if (!response.ok) {
252
+ const error = isJson && data?.error ? data.error : {};
253
+ throw new TevrocError(error.message ?? response.statusText, {
254
+ status: response.status,
255
+ code: error.code ?? "api_error",
256
+ details: error.details ?? data,
257
+ response
258
+ });
259
+ }
260
+ return data;
261
+ }
262
+ function toSearchParams(query) {
263
+ const params = new URLSearchParams();
264
+ for (const [key, value2] of Object.entries(query)) {
265
+ if (value2 === void 0 || value2 === null) continue;
266
+ if (Array.isArray(value2)) {
267
+ for (const item of value2) params.append(key, String(item));
268
+ } else {
269
+ params.set(key, String(value2));
270
+ }
271
+ }
272
+ const value = params.toString();
273
+ return value ? `?${value}` : "";
274
+ }
275
+ function normalizeBaseUrl(url) {
276
+ return String(url).replace(/\/+$/, "");
277
+ }
278
+ function normalizeHeaders(headers = {}) {
279
+ return Object.fromEntries(new Headers(headers).entries());
280
+ }
281
+ function isJsonBody(body) {
282
+ const isArrayBuffer = typeof ArrayBuffer !== "undefined" && body instanceof ArrayBuffer;
283
+ const isBlob = typeof Blob !== "undefined" && body instanceof Blob;
284
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
285
+ return typeof body === "object" && !isArrayBuffer && !isBlob && !isFormData;
286
+ }
287
+ export {
288
+ TevrocClient,
289
+ TevrocError,
290
+ createClient
291
+ };
@@ -0,0 +1 @@
1
+ var Tevroc=(()=>{var f=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},T=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of g(e))!q.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(o=p(e,n))||o.enumerable});return t};var U=t=>T(f({},"__esModule",{value:!0}),t);var _={};b(_,{TevrocClient:()=>d,TevrocError:()=>u,createClient:()=>$});var u=class extends Error{constructor(e,r={}){super(e),this.name="TevrocError",this.status=r.status,this.code=r.code,this.details=r.details,this.response=r.response}};function $(t={}){return new d(t)}var d=class{constructor(e={}){let r=e.baseUrl??e.url;if(!r)throw new TypeError("createClient requires a baseUrl");if(this.baseUrl=M(r),this.fetch=e.fetch??globalThis.fetch,typeof this.fetch!="function")throw new TypeError("No fetch implementation available");this.timeoutMs=e.timeoutMs??3e4,this.defaultHeaders=L(e.headers),this.token=e.token??null,this.auth=C(this),this.entities=P(this),this.functions=k(this),this.integrations=w(this),this.agents=O(this),this.logs=R(this),this.connectors=E(this),this.customIntegrations=A(this),this.sso=v(this),this.files=x(this)}setToken(e){return this.token=e||null,this}clearToken(){return this.token=null,this}async request(e,r={}){let o=(r.method??"GET").toUpperCase(),n=new Headers(this.defaultHeaders),s=r.query?D(r.query):"",m=`${this.baseUrl}${e.startsWith("/")?e:`/${e}`}${s}`,h=new AbortController,y=setTimeout(()=>h.abort(),r.timeoutMs??this.timeoutMs);this.token&&r.auth!==!1&&n.set("authorization",`Bearer ${this.token}`);let i=r.body;if(i!=null&&B(i)&&(n.set("content-type","application/json"),i=JSON.stringify(i)),r.headers)for(let[a,c]of Object.entries(r.headers))c!=null&&n.set(a,String(c));try{let a=await this.fetch(m,{method:o,headers:n,body:i,signal:r.signal??h.signal});return await F(a,r.parseAs)}catch(a){throw a?.name==="AbortError"?new u("Request timed out",{code:"timeout"}):a instanceof u?a:new u(a?.message??"Network request failed",{code:"network_error",details:a})}finally{clearTimeout(y)}}};function C(t){return{async register(e){let r=await t.request("/auth/register",{method:"POST",body:e,auth:!1});return r.token&&t.setToken(r.token),r},async login(e){let r=await t.request("/auth/login",{method:"POST",body:e,auth:!1});return r.token&&t.setToken(r.token),r},async logout(){let e=await t.request("/auth/logout",{method:"POST"});return t.clearToken(),e},me:()=>t.request("/auth/me"),verifyOtp:e=>t.request("/auth/verify-otp",{method:"POST",body:e,auth:!1}),changePassword:e=>t.request("/auth/change-password",{method:"POST",body:e}),resetPassword:e=>t.request("/auth/reset-password",{method:"POST",body:e,auth:!1}),loginUrl:e=>t.request("/auth/login-url",{query:e?{redirectTo:e}:void 0,auth:!1})}}function P(t){return new Proxy({},{get(e,r){if(typeof r=="string")return S(t,r)}})}function S(t,e){let r=`/entities/${encodeURIComponent(e)}`;return{list:o=>t.request(r,{query:o}),get:o=>t.request(`${r}/${encodeURIComponent(o)}`),create:o=>t.request(r,{method:"POST",body:o}),update:(o,n)=>t.request(`${r}/${encodeURIComponent(o)}`,{method:"PATCH",body:n}),delete:o=>t.request(`${r}/${encodeURIComponent(o)}`,{method:"DELETE"}),query:(o={})=>t.request(`${r}/query`,{method:"POST",body:o}),bulkCreate:o=>t.request(`${r}/bulk`,{method:"POST",body:{records:o}}),bulkUpdate:o=>t.request(`${r}/bulk`,{method:"PATCH",body:{records:o}}),bulkDelete:o=>t.request(`${r}/bulk`,{method:"DELETE",body:{ids:o}}),import:o=>t.request(`${r}/import`,{method:"POST",body:{records:o}})}}function k(t){return new Proxy({invoke:(e,r)=>t.request(`/functions/${encodeURIComponent(e)}`,{method:"POST",body:r})},{get(e,r){if(r in e)return e[r];if(typeof r=="string")return o=>e.invoke(r,o)}})}function w(t){return{Core:{InvokeLLM:e=>t.request("/integrations/core/invoke-llm",{method:"POST",body:e}),GenerateImage:e=>t.request("/integrations/core/generate-image",{method:"POST",body:e}),UploadFile:(e,r={})=>l(t,"/integrations/core/upload-file",e,r),UploadPrivateFile:(e,r={})=>l(t,"/integrations/core/upload-private-file",e,r),CreateFileSignedUrl:e=>t.request("/integrations/core/create-file-signed-url",{method:"POST",body:e}),SendEmail:e=>t.request("/integrations/core/send-email",{method:"POST",body:e}),ExtractDataFromUploadedFile:e=>t.request("/integrations/core/extract-data-from-uploaded-file",{method:"POST",body:e})}}}function O(t){return new Proxy({},{get(e,r){if(typeof r=="string")return I(t,r)}})}function I(t,e){let r=`/agents/${encodeURIComponent(e)}/conversations`;return{createConversation:(o={})=>t.request(r,{method:"POST",body:o}),listConversations:()=>t.request(r),getConversation:o=>t.request(`${r}/${encodeURIComponent(o)}`),deleteConversation:o=>t.request(`${r}/${encodeURIComponent(o)}`,{method:"DELETE"}),addMessage:(o,n)=>t.request(`${r}/${encodeURIComponent(o)}/messages`,{method:"POST",body:n}),listMessages:o=>t.request(`${r}/${encodeURIComponent(o)}/messages`)}}function R(t){return{list:e=>t.request("/app-logs",{query:e}),create:e=>t.request("/app-logs",{method:"POST",body:e}),get:e=>t.request(`/app-logs/${encodeURIComponent(e)}`)}}function E(t){return{list:()=>t.request("/connectors"),get:e=>t.request(`/connectors/${encodeURIComponent(e)}`),connect:(e,r={})=>t.request(`/connectors/${encodeURIComponent(e)}/connect`,{method:"POST",body:r}),disconnect:e=>t.request(`/connectors/${encodeURIComponent(e)}/disconnect`,{method:"POST"}),status:e=>t.request(`/connectors/${encodeURIComponent(e)}/status`),user:{list:()=>t.request("/user-connectors"),get:e=>t.request(`/user-connectors/${encodeURIComponent(e)}`),refresh:e=>t.request(`/user-connectors/${encodeURIComponent(e)}/refresh`,{method:"POST"}),delete:e=>t.request(`/user-connectors/${encodeURIComponent(e)}`,{method:"DELETE"})}}}function A(t){return new Proxy({invoke:(e,r,o)=>t.request(`/custom-integrations/${encodeURIComponent(e)}/${encodeURIComponent(r)}`,{method:"POST",body:o})},{get(e,r){if(r in e)return e[r];if(typeof r=="string")return new Proxy({},{get(o,n){if(typeof n=="string")return s=>e.invoke(r,n,s)}})}})}function v(t){return{accessToken:e=>t.request("/sso/access-token",{method:"POST",body:e,auth:!1}),callback:e=>t.request("/sso/callback",{query:e,auth:!1})}}function x(t){return{url:e=>`${t.baseUrl}/files/${encodeURIComponent(e)}`,privateUrl:e=>`${t.baseUrl}/private-files/${encodeURIComponent(e)}`,get:e=>t.request(`/files/${encodeURIComponent(e)}`,{parseAs:"response",auth:!1}),getPrivate:e=>t.request(`/private-files/${encodeURIComponent(e)}`,{parseAs:"response"})}}function l(t,e,r,o){let n={};return o.filename&&(n["x-filename"]=o.filename),o.contentType&&(n["content-type"]=o.contentType),t.request(e,{method:"POST",body:r,headers:n})}async function F(t,e){if(e==="response")return t;let o=(t.headers.get("content-type")??"").includes("application/json"),n=o?await t.json():await t.text();if(!t.ok){let s=o&&n?.error?n.error:{};throw new u(s.message??t.statusText,{status:t.status,code:s.code??"api_error",details:s.details??n,response:t})}return n}function D(t){let e=new URLSearchParams;for(let[o,n]of Object.entries(t))if(n!=null)if(Array.isArray(n))for(let s of n)e.append(o,String(s));else e.set(o,String(n));let r=e.toString();return r?`?${r}`:""}function M(t){return String(t).replace(/\/+$/,"")}function L(t={}){return Object.fromEntries(new Headers(t).entries())}function B(t){let e=typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer,r=typeof Blob<"u"&&t instanceof Blob,o=typeof FormData<"u"&&t instanceof FormData;return typeof t=="object"&&!e&&!r&&!o}return U(_);})();
@@ -0,0 +1,313 @@
1
+ var Tevroc = (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.js
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TevrocClient: () => TevrocClient,
24
+ TevrocError: () => TevrocError,
25
+ createClient: () => createClient
26
+ });
27
+ var DEFAULT_TIMEOUT_MS = 3e4;
28
+ var TevrocError = class extends Error {
29
+ constructor(message, options = {}) {
30
+ super(message);
31
+ this.name = "TevrocError";
32
+ this.status = options.status;
33
+ this.code = options.code;
34
+ this.details = options.details;
35
+ this.response = options.response;
36
+ }
37
+ };
38
+ function createClient(options = {}) {
39
+ return new TevrocClient(options);
40
+ }
41
+ var TevrocClient = class {
42
+ constructor(options = {}) {
43
+ const baseUrl = options.baseUrl ?? options.url;
44
+ if (!baseUrl) throw new TypeError("createClient requires a baseUrl");
45
+ this.baseUrl = normalizeBaseUrl(baseUrl);
46
+ this.fetch = options.fetch ?? globalThis.fetch;
47
+ if (typeof this.fetch !== "function") throw new TypeError("No fetch implementation available");
48
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
49
+ this.defaultHeaders = normalizeHeaders(options.headers);
50
+ this.token = options.token ?? null;
51
+ this.auth = createAuthApi(this);
52
+ this.entities = createEntityRegistry(this);
53
+ this.functions = createFunctionRegistry(this);
54
+ this.integrations = createIntegrationApi(this);
55
+ this.agents = createAgentRegistry(this);
56
+ this.logs = createLogApi(this);
57
+ this.connectors = createConnectorApi(this);
58
+ this.customIntegrations = createCustomIntegrationRegistry(this);
59
+ this.sso = createSsoApi(this);
60
+ this.files = createFileApi(this);
61
+ }
62
+ setToken(token) {
63
+ this.token = token || null;
64
+ return this;
65
+ }
66
+ clearToken() {
67
+ this.token = null;
68
+ return this;
69
+ }
70
+ async request(path, options = {}) {
71
+ const method = (options.method ?? "GET").toUpperCase();
72
+ const headers = new Headers(this.defaultHeaders);
73
+ const query = options.query ? toSearchParams(options.query) : "";
74
+ const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
75
+ const controller = new AbortController();
76
+ const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.timeoutMs);
77
+ if (this.token && options.auth !== false) headers.set("authorization", `Bearer ${this.token}`);
78
+ let body = options.body;
79
+ if (body !== void 0 && body !== null && isJsonBody(body)) {
80
+ headers.set("content-type", "application/json");
81
+ body = JSON.stringify(body);
82
+ }
83
+ if (options.headers) {
84
+ for (const [key, value] of Object.entries(options.headers)) {
85
+ if (value !== void 0 && value !== null) headers.set(key, String(value));
86
+ }
87
+ }
88
+ try {
89
+ const response = await this.fetch(url, {
90
+ method,
91
+ headers,
92
+ body,
93
+ signal: options.signal ?? controller.signal
94
+ });
95
+ return await parseResponse(response, options.parseAs);
96
+ } catch (error) {
97
+ if (error?.name === "AbortError") throw new TevrocError("Request timed out", { code: "timeout" });
98
+ if (error instanceof TevrocError) throw error;
99
+ throw new TevrocError(error?.message ?? "Network request failed", { code: "network_error", details: error });
100
+ } finally {
101
+ clearTimeout(timeout);
102
+ }
103
+ }
104
+ };
105
+ function createAuthApi(client) {
106
+ return {
107
+ async register(input) {
108
+ const result = await client.request("/auth/register", { method: "POST", body: input, auth: false });
109
+ if (result.token) client.setToken(result.token);
110
+ return result;
111
+ },
112
+ async login(input) {
113
+ const result = await client.request("/auth/login", { method: "POST", body: input, auth: false });
114
+ if (result.token) client.setToken(result.token);
115
+ return result;
116
+ },
117
+ async logout() {
118
+ const result = await client.request("/auth/logout", { method: "POST" });
119
+ client.clearToken();
120
+ return result;
121
+ },
122
+ me: () => client.request("/auth/me"),
123
+ verifyOtp: (input) => client.request("/auth/verify-otp", { method: "POST", body: input, auth: false }),
124
+ changePassword: (input) => client.request("/auth/change-password", { method: "POST", body: input }),
125
+ resetPassword: (input) => client.request("/auth/reset-password", { method: "POST", body: input, auth: false }),
126
+ loginUrl: (redirectTo) => client.request("/auth/login-url", { query: redirectTo ? { redirectTo } : void 0, auth: false })
127
+ };
128
+ }
129
+ function createEntityRegistry(client) {
130
+ return new Proxy(
131
+ {},
132
+ {
133
+ get(_target, entity) {
134
+ if (typeof entity !== "string") return void 0;
135
+ return createEntityApi(client, entity);
136
+ }
137
+ }
138
+ );
139
+ }
140
+ function createEntityApi(client, entity) {
141
+ const base = `/entities/${encodeURIComponent(entity)}`;
142
+ return {
143
+ list: (options) => client.request(base, { query: options }),
144
+ get: (id) => client.request(`${base}/${encodeURIComponent(id)}`),
145
+ create: (record) => client.request(base, { method: "POST", body: record }),
146
+ update: (id, patch) => client.request(`${base}/${encodeURIComponent(id)}`, { method: "PATCH", body: patch }),
147
+ delete: (id) => client.request(`${base}/${encodeURIComponent(id)}`, { method: "DELETE" }),
148
+ query: (input = {}) => client.request(`${base}/query`, { method: "POST", body: input }),
149
+ bulkCreate: (records) => client.request(`${base}/bulk`, { method: "POST", body: { records } }),
150
+ bulkUpdate: (records) => client.request(`${base}/bulk`, { method: "PATCH", body: { records } }),
151
+ bulkDelete: (ids) => client.request(`${base}/bulk`, { method: "DELETE", body: { ids } }),
152
+ import: (records) => client.request(`${base}/import`, { method: "POST", body: { records } })
153
+ };
154
+ }
155
+ function createFunctionRegistry(client) {
156
+ return new Proxy(
157
+ {
158
+ invoke: (name, payload) => client.request(`/functions/${encodeURIComponent(name)}`, { method: "POST", body: payload })
159
+ },
160
+ {
161
+ get(target, name) {
162
+ if (name in target) return target[name];
163
+ if (typeof name !== "string") return void 0;
164
+ return (payload) => target.invoke(name, payload);
165
+ }
166
+ }
167
+ );
168
+ }
169
+ function createIntegrationApi(client) {
170
+ return {
171
+ Core: {
172
+ InvokeLLM: (payload) => client.request("/integrations/core/invoke-llm", { method: "POST", body: payload }),
173
+ GenerateImage: (payload) => client.request("/integrations/core/generate-image", { method: "POST", body: payload }),
174
+ UploadFile: (file, options = {}) => upload(client, "/integrations/core/upload-file", file, options),
175
+ UploadPrivateFile: (file, options = {}) => upload(client, "/integrations/core/upload-private-file", file, options),
176
+ CreateFileSignedUrl: (payload) => client.request("/integrations/core/create-file-signed-url", { method: "POST", body: payload }),
177
+ SendEmail: (payload) => client.request("/integrations/core/send-email", { method: "POST", body: payload }),
178
+ ExtractDataFromUploadedFile: (payload) => client.request("/integrations/core/extract-data-from-uploaded-file", { method: "POST", body: payload })
179
+ }
180
+ };
181
+ }
182
+ function createAgentRegistry(client) {
183
+ return new Proxy(
184
+ {},
185
+ {
186
+ get(_target, agentName) {
187
+ if (typeof agentName !== "string") return void 0;
188
+ return createAgentApi(client, agentName);
189
+ }
190
+ }
191
+ );
192
+ }
193
+ function createAgentApi(client, agentName) {
194
+ const base = `/agents/${encodeURIComponent(agentName)}/conversations`;
195
+ return {
196
+ createConversation: (input = {}) => client.request(base, { method: "POST", body: input }),
197
+ listConversations: () => client.request(base),
198
+ getConversation: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}`),
199
+ deleteConversation: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}`, { method: "DELETE" }),
200
+ addMessage: (conversationId, input) => client.request(`${base}/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input }),
201
+ listMessages: (conversationId) => client.request(`${base}/${encodeURIComponent(conversationId)}/messages`)
202
+ };
203
+ }
204
+ function createLogApi(client) {
205
+ return {
206
+ list: (options) => client.request("/app-logs", { query: options }),
207
+ create: (input) => client.request("/app-logs", { method: "POST", body: input }),
208
+ get: (id) => client.request(`/app-logs/${encodeURIComponent(id)}`)
209
+ };
210
+ }
211
+ function createConnectorApi(client) {
212
+ return {
213
+ list: () => client.request("/connectors"),
214
+ get: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}`),
215
+ connect: (connectorName, input = {}) => client.request(`/connectors/${encodeURIComponent(connectorName)}/connect`, { method: "POST", body: input }),
216
+ disconnect: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}/disconnect`, { method: "POST" }),
217
+ status: (connectorName) => client.request(`/connectors/${encodeURIComponent(connectorName)}/status`),
218
+ user: {
219
+ list: () => client.request("/user-connectors"),
220
+ get: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}`),
221
+ refresh: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}/refresh`, { method: "POST" }),
222
+ delete: (id) => client.request(`/user-connectors/${encodeURIComponent(id)}`, { method: "DELETE" })
223
+ }
224
+ };
225
+ }
226
+ function createCustomIntegrationRegistry(client) {
227
+ return new Proxy(
228
+ {
229
+ invoke: (integrationName, endpointName, payload) => client.request(`/custom-integrations/${encodeURIComponent(integrationName)}/${encodeURIComponent(endpointName)}`, {
230
+ method: "POST",
231
+ body: payload
232
+ })
233
+ },
234
+ {
235
+ get(target, integrationName) {
236
+ if (integrationName in target) return target[integrationName];
237
+ if (typeof integrationName !== "string") return void 0;
238
+ return new Proxy(
239
+ {},
240
+ {
241
+ get(_innerTarget, endpointName) {
242
+ if (typeof endpointName !== "string") return void 0;
243
+ return (payload) => target.invoke(integrationName, endpointName, payload);
244
+ }
245
+ }
246
+ );
247
+ }
248
+ }
249
+ );
250
+ }
251
+ function createSsoApi(client) {
252
+ return {
253
+ accessToken: (input) => client.request("/sso/access-token", { method: "POST", body: input, auth: false }),
254
+ callback: (query) => client.request("/sso/callback", { query, auth: false })
255
+ };
256
+ }
257
+ function createFileApi(client) {
258
+ return {
259
+ url: (key) => `${client.baseUrl}/files/${encodeURIComponent(key)}`,
260
+ privateUrl: (key) => `${client.baseUrl}/private-files/${encodeURIComponent(key)}`,
261
+ get: (key) => client.request(`/files/${encodeURIComponent(key)}`, { parseAs: "response", auth: false }),
262
+ getPrivate: (key) => client.request(`/private-files/${encodeURIComponent(key)}`, { parseAs: "response" })
263
+ };
264
+ }
265
+ function upload(client, path, file, options) {
266
+ const headers = {};
267
+ if (options.filename) headers["x-filename"] = options.filename;
268
+ if (options.contentType) headers["content-type"] = options.contentType;
269
+ return client.request(path, { method: "POST", body: file, headers });
270
+ }
271
+ async function parseResponse(response, parseAs) {
272
+ if (parseAs === "response") return response;
273
+ const contentType = response.headers.get("content-type") ?? "";
274
+ const isJson = contentType.includes("application/json");
275
+ const data = isJson ? await response.json() : await response.text();
276
+ if (!response.ok) {
277
+ const error = isJson && data?.error ? data.error : {};
278
+ throw new TevrocError(error.message ?? response.statusText, {
279
+ status: response.status,
280
+ code: error.code ?? "api_error",
281
+ details: error.details ?? data,
282
+ response
283
+ });
284
+ }
285
+ return data;
286
+ }
287
+ function toSearchParams(query) {
288
+ const params = new URLSearchParams();
289
+ for (const [key, value2] of Object.entries(query)) {
290
+ if (value2 === void 0 || value2 === null) continue;
291
+ if (Array.isArray(value2)) {
292
+ for (const item of value2) params.append(key, String(item));
293
+ } else {
294
+ params.set(key, String(value2));
295
+ }
296
+ }
297
+ const value = params.toString();
298
+ return value ? `?${value}` : "";
299
+ }
300
+ function normalizeBaseUrl(url) {
301
+ return String(url).replace(/\/+$/, "");
302
+ }
303
+ function normalizeHeaders(headers = {}) {
304
+ return Object.fromEntries(new Headers(headers).entries());
305
+ }
306
+ function isJsonBody(body) {
307
+ const isArrayBuffer = typeof ArrayBuffer !== "undefined" && body instanceof ArrayBuffer;
308
+ const isBlob = typeof Blob !== "undefined" && body instanceof Blob;
309
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
310
+ return typeof body === "object" && !isArrayBuffer && !isBlob && !isFormData;
311
+ }
312
+ return __toCommonJS(index_exports);
313
+ })();