@calculator-5329/cloud-proxy 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/README.md +243 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +51 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +91 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/ai.d.ts +33 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +140 -0
- package/dist/modules/ai.js.map +1 -0
- package/dist/modules/auth.d.ts +49 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +80 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/firestore.d.ts +56 -0
- package/dist/modules/firestore.d.ts.map +1 -0
- package/dist/modules/firestore.js +89 -0
- package/dist/modules/firestore.js.map +1 -0
- package/dist/modules/setup.d.ts +26 -0
- package/dist/modules/setup.d.ts.map +1 -0
- package/dist/modules/setup.js +43 -0
- package/dist/modules/setup.js.map +1 -0
- package/dist/modules/storage.d.ts +28 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +62 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/vectors.d.ts +27 -0
- package/dist/modules/vectors.d.ts.map +1 -0
- package/dist/modules/vectors.js +66 -0
- package/dist/modules/vectors.js.map +1 -0
- package/dist/types.d.ts +320 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# @et2bo/cloud-proxy
|
|
2
|
+
|
|
3
|
+
TypeScript client SDK for the Cloud Run proxy server. Zero runtime dependencies, fully typed, ESM-only.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @et2bo/cloud-proxy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Requirements:** Node 18+ (uses global `fetch`)
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@et2bo/cloud-proxy";
|
|
17
|
+
|
|
18
|
+
const proxy = createClient({
|
|
19
|
+
baseUrl: process.env.PROXY_URL!,
|
|
20
|
+
token: process.env.PROXY_TOKEN!,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Health check
|
|
24
|
+
const { status } = await proxy.health();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Set two environment variables and you're done:
|
|
28
|
+
|
|
29
|
+
```env
|
|
30
|
+
PROXY_URL=https://your-service-xyz.run.app
|
|
31
|
+
PROXY_TOKEN=your-static-bearer-token
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Modules
|
|
35
|
+
|
|
36
|
+
Every module is accessible as a property on the client object. Modules are lazily instantiated on first access.
|
|
37
|
+
|
|
38
|
+
| Module | Accessor | Description |
|
|
39
|
+
|--------|----------|-------------|
|
|
40
|
+
| AI | `proxy.ai` | OpenAI, Anthropic, Gemini, OpenRouter passthrough |
|
|
41
|
+
| Auth | `proxy.auth` | Firebase Auth user management |
|
|
42
|
+
| Firestore | `proxy.firestore` | Firestore CRUD, queries, batch, aggregates |
|
|
43
|
+
| Storage | `proxy.storage` | GCS upload, download, signed URLs, buckets |
|
|
44
|
+
| Vectors | `proxy.vectors` | Vector search + Gemini embeddings |
|
|
45
|
+
| Setup | `proxy.setup` | Provisioning + project bootstrap |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## AI
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Direct provider passthrough
|
|
53
|
+
const response = await proxy.ai.openai("/v1/chat/completions", {
|
|
54
|
+
model: "gpt-4o",
|
|
55
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Convenience chat — normalized response across all providers
|
|
59
|
+
const reply = await proxy.ai.chat({
|
|
60
|
+
provider: "anthropic",
|
|
61
|
+
model: "claude-sonnet-4-20250514",
|
|
62
|
+
messages: [{ role: "user", content: "Explain quantum computing" }],
|
|
63
|
+
maxTokens: 1024,
|
|
64
|
+
});
|
|
65
|
+
console.log(reply.content);
|
|
66
|
+
|
|
67
|
+
// Streaming
|
|
68
|
+
const stream = await proxy.ai.chatStream({
|
|
69
|
+
provider: "openai",
|
|
70
|
+
model: "gpt-4o",
|
|
71
|
+
messages: [{ role: "user", content: "Write a poem" }],
|
|
72
|
+
});
|
|
73
|
+
for await (const chunk of stream) {
|
|
74
|
+
process.stdout.write(new TextDecoder().decode(chunk));
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Auth
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const user = await proxy.auth.createUser({
|
|
82
|
+
email: "alice@example.com",
|
|
83
|
+
password: "securepassword",
|
|
84
|
+
displayName: "Alice",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await proxy.auth.setClaims(user.uid, { admin: true });
|
|
88
|
+
|
|
89
|
+
const users = await proxy.auth.listUsers({ limit: 50 });
|
|
90
|
+
|
|
91
|
+
// Email links
|
|
92
|
+
const { link } = await proxy.auth.generatePasswordResetLink("alice@example.com");
|
|
93
|
+
|
|
94
|
+
// Session cookies
|
|
95
|
+
const { cookie } = await proxy.auth.createSessionCookie(idToken, 7 * 24 * 60 * 60 * 1000);
|
|
96
|
+
const decoded = await proxy.auth.verifySessionCookie(cookie, true);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Firestore
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// CRUD
|
|
103
|
+
const post = await proxy.firestore.create("posts", { title: "Hello", body: "World" });
|
|
104
|
+
const doc = await proxy.firestore.get<{ title: string }>("posts/abc123");
|
|
105
|
+
await proxy.firestore.update("posts/abc123", { title: "Updated" });
|
|
106
|
+
await proxy.firestore.delete("posts/abc123");
|
|
107
|
+
|
|
108
|
+
// Query
|
|
109
|
+
const published = await proxy.firestore.query("posts", {
|
|
110
|
+
filters: [{ field: "status", op: "==", value: "published" }],
|
|
111
|
+
orderBy: [{ field: "createdAt", direction: "desc" }],
|
|
112
|
+
limit: 50,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Subcollections
|
|
116
|
+
const comments = await proxy.firestore.list("posts/abc123/comments");
|
|
117
|
+
// Or scoped:
|
|
118
|
+
const scoped = proxy.firestore.sub("posts/abc123");
|
|
119
|
+
await scoped.list("comments");
|
|
120
|
+
|
|
121
|
+
// Atomic field operations
|
|
122
|
+
import { FieldOp } from "@et2bo/cloud-proxy";
|
|
123
|
+
|
|
124
|
+
await proxy.firestore.patch("posts/abc123", {
|
|
125
|
+
views: FieldOp.increment(1),
|
|
126
|
+
tags: FieldOp.arrayUnion("featured"),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Batch
|
|
130
|
+
await proxy.firestore.batch([
|
|
131
|
+
{ type: "create", collection: "posts", data: { title: "A" } },
|
|
132
|
+
{ type: "delete", collection: "posts", docId: "old" },
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
// Aggregates
|
|
136
|
+
const stats = await proxy.firestore.aggregate("orders", {
|
|
137
|
+
aggregations: [
|
|
138
|
+
{ type: "count", alias: "total" },
|
|
139
|
+
{ type: "sum", field: "amount", alias: "revenue" },
|
|
140
|
+
],
|
|
141
|
+
filters: [{ field: "status", op: "==", value: "completed" }],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Collection group queries
|
|
145
|
+
const allComments = await proxy.firestore.query("comments", {
|
|
146
|
+
collectionGroup: true,
|
|
147
|
+
filters: [{ field: "flagged", op: "==", value: true }],
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Storage
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// Direct upload
|
|
155
|
+
const result = await proxy.storage.upload("my-bucket", file, {
|
|
156
|
+
path: "avatars",
|
|
157
|
+
public: true,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Signed URL upload (large files)
|
|
161
|
+
const { uploadUrl } = await proxy.storage.getUploadUrl("my-bucket", {
|
|
162
|
+
filename: "video.mp4",
|
|
163
|
+
contentType: "video/mp4",
|
|
164
|
+
expiresInMinutes: 30,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Download
|
|
168
|
+
const { downloadUrl } = await proxy.storage.getDownloadUrl("my-bucket", "photo.jpg", 120);
|
|
169
|
+
const response = await proxy.storage.download("my-bucket", "report.pdf");
|
|
170
|
+
|
|
171
|
+
// List & delete
|
|
172
|
+
const files = await proxy.storage.listFiles("my-bucket", { prefix: "avatars/" });
|
|
173
|
+
await proxy.storage.deleteFile("my-bucket", "old-file.txt");
|
|
174
|
+
|
|
175
|
+
// Bucket management
|
|
176
|
+
await proxy.storage.createBucket({ name: "new-bucket", location: "US" });
|
|
177
|
+
const { buckets } = await proxy.storage.listBuckets();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Vectors
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// Embed and store
|
|
184
|
+
const doc = await proxy.vectors.embed("articles", "Quantum computing uses qubits...", {
|
|
185
|
+
data: { title: "Intro to Quantum", category: "science" },
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Batch embed
|
|
189
|
+
await proxy.vectors.embedBatch("articles", [
|
|
190
|
+
{ text: "First article...", data: { title: "AI" } },
|
|
191
|
+
{ text: "Second article...", data: { title: "ML" } },
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
// Semantic search
|
|
195
|
+
const hits = await proxy.vectors.semanticSearch("articles", "quantum physics basics", {
|
|
196
|
+
topK: 5,
|
|
197
|
+
filters: [{ field: "category", op: "==", value: "science" }],
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Update & delete
|
|
201
|
+
await proxy.vectors.update("articles", doc.id, { text: "Updated content..." });
|
|
202
|
+
await proxy.vectors.delete("articles", doc.id);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Setup
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Bootstrap an entire project
|
|
209
|
+
const status = await proxy.setup.bootstrapProject({
|
|
210
|
+
projectName: "my-app",
|
|
211
|
+
firestore: {
|
|
212
|
+
collections: [
|
|
213
|
+
{ name: "users" },
|
|
214
|
+
{ name: "documents", vectorIndex: true },
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
storage: { bucketName: "my-app-assets", public: true },
|
|
218
|
+
auth: { enableEmailPassword: true },
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Check status
|
|
222
|
+
const current = await proxy.setup.getStatus();
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Error Handling
|
|
226
|
+
|
|
227
|
+
All errors are thrown as `ProxyError` with `code`, `status`, and `details`:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { ProxyError } from "@et2bo/cloud-proxy";
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
await proxy.firestore.get("posts/nonexistent");
|
|
234
|
+
} catch (err) {
|
|
235
|
+
if (err instanceof ProxyError && err.code === "FIRESTORE_NOT_FOUND") {
|
|
236
|
+
// handle 404
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ClientConfig } from "./types.js";
|
|
2
|
+
import { AiModule } from "./modules/ai.js";
|
|
3
|
+
import { AuthModule } from "./modules/auth.js";
|
|
4
|
+
import { FirestoreModule } from "./modules/firestore.js";
|
|
5
|
+
import { StorageModule } from "./modules/storage.js";
|
|
6
|
+
import { VectorModule } from "./modules/vectors.js";
|
|
7
|
+
import { SetupModule } from "./modules/setup.js";
|
|
8
|
+
/**
|
|
9
|
+
* Main SDK entry object. Provides lazy access to every module
|
|
10
|
+
* and a shared HTTP client for all requests.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CloudProxy {
|
|
13
|
+
private readonly http;
|
|
14
|
+
private _ai?;
|
|
15
|
+
private _auth?;
|
|
16
|
+
private _firestore?;
|
|
17
|
+
private _storage?;
|
|
18
|
+
private _vectors?;
|
|
19
|
+
private _setup?;
|
|
20
|
+
constructor(config: ClientConfig);
|
|
21
|
+
get ai(): AiModule;
|
|
22
|
+
get auth(): AuthModule;
|
|
23
|
+
get firestore(): FirestoreModule;
|
|
24
|
+
get storage(): StorageModule;
|
|
25
|
+
get vectors(): VectorModule;
|
|
26
|
+
get setup(): SetupModule;
|
|
27
|
+
/** Quick health check against the proxy server. */
|
|
28
|
+
health(): Promise<{
|
|
29
|
+
status: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAElC,OAAO,CAAC,GAAG,CAAC,CAAW;IACvB,OAAO,CAAC,KAAK,CAAC,CAAa;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAC,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,CAAe;IAChC,OAAO,CAAC,MAAM,CAAC,CAAc;gBAEjB,MAAM,EAAE,YAAY;IAShC,IAAI,EAAE,IAAI,QAAQ,CAEjB;IAED,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,SAAS,IAAI,eAAe,CAE/B;IAED,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED,IAAI,OAAO,IAAI,YAAY,CAE1B;IAED,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,mDAAmD;IAC7C,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAG5C"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { HttpClient } from "./http.js";
|
|
2
|
+
import { AiModule } from "./modules/ai.js";
|
|
3
|
+
import { AuthModule } from "./modules/auth.js";
|
|
4
|
+
import { FirestoreModule } from "./modules/firestore.js";
|
|
5
|
+
import { StorageModule } from "./modules/storage.js";
|
|
6
|
+
import { VectorModule } from "./modules/vectors.js";
|
|
7
|
+
import { SetupModule } from "./modules/setup.js";
|
|
8
|
+
/**
|
|
9
|
+
* Main SDK entry object. Provides lazy access to every module
|
|
10
|
+
* and a shared HTTP client for all requests.
|
|
11
|
+
*/
|
|
12
|
+
export class CloudProxy {
|
|
13
|
+
http;
|
|
14
|
+
_ai;
|
|
15
|
+
_auth;
|
|
16
|
+
_firestore;
|
|
17
|
+
_storage;
|
|
18
|
+
_vectors;
|
|
19
|
+
_setup;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.http = new HttpClient({
|
|
22
|
+
baseUrl: config.baseUrl,
|
|
23
|
+
token: config.token,
|
|
24
|
+
defaultHeaders: config.defaultHeaders,
|
|
25
|
+
timeout: config.timeout,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
get ai() {
|
|
29
|
+
return (this._ai ??= new AiModule(this.http));
|
|
30
|
+
}
|
|
31
|
+
get auth() {
|
|
32
|
+
return (this._auth ??= new AuthModule(this.http));
|
|
33
|
+
}
|
|
34
|
+
get firestore() {
|
|
35
|
+
return (this._firestore ??= new FirestoreModule(this.http));
|
|
36
|
+
}
|
|
37
|
+
get storage() {
|
|
38
|
+
return (this._storage ??= new StorageModule(this.http));
|
|
39
|
+
}
|
|
40
|
+
get vectors() {
|
|
41
|
+
return (this._vectors ??= new VectorModule(this.http));
|
|
42
|
+
}
|
|
43
|
+
get setup() {
|
|
44
|
+
return (this._setup ??= new SetupModule(this.http));
|
|
45
|
+
}
|
|
46
|
+
/** Quick health check against the proxy server. */
|
|
47
|
+
async health() {
|
|
48
|
+
return this.http.request("GET", "/health");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;G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,CAAqB,KAAK,EAAE,SAAS,CAAC,CAAC;IACjE,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by the SDK when the proxy server returns a non-2xx response.
|
|
3
|
+
* Mirrors the server's error shape: `{ code, message, status }`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProxyError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly details?: unknown;
|
|
9
|
+
constructor(message: string, code: string, status: number, details?: unknown);
|
|
10
|
+
/** Parse a non-2xx fetch Response into a ProxyError. */
|
|
11
|
+
static fromResponse(response: Response): Promise<ProxyError>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAQ5E,wDAAwD;WAC3C,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAmBnE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by the SDK when the proxy server returns a non-2xx response.
|
|
3
|
+
* Mirrors the server's error shape: `{ code, message, status }`.
|
|
4
|
+
*/
|
|
5
|
+
export class ProxyError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
status;
|
|
8
|
+
details;
|
|
9
|
+
constructor(message, code, status, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "ProxyError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
/** Parse a non-2xx fetch Response into a ProxyError. */
|
|
17
|
+
static async fromResponse(response) {
|
|
18
|
+
let body;
|
|
19
|
+
try {
|
|
20
|
+
body = await response.json();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
body = await response.text().catch(() => null);
|
|
24
|
+
}
|
|
25
|
+
const obj = body;
|
|
26
|
+
const message = (typeof obj?.message === "string" ? obj.message : null) ??
|
|
27
|
+
(typeof obj?.error === "string" ? obj.error : null) ??
|
|
28
|
+
`Request failed with status ${response.status}`;
|
|
29
|
+
const code = (typeof obj?.code === "string" ? obj.code : null) ??
|
|
30
|
+
`HTTP_${response.status}`;
|
|
31
|
+
return new ProxyError(message, code, response.status, body);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAW;IAE3B,YAAY,OAAe,EAAE,IAAY,EAAE,MAAc,EAAE,OAAiB;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,wDAAwD;IACxD,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,QAAkB;QAC1C,IAAI,IAAa,CAAC;QAClB,IAAI,CAAC;YACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,GAAG,GAAG,IAAsC,CAAC;QACnD,MAAM,OAAO,GACX,CAAC,OAAO,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YACvD,CAAC,OAAO,GAAG,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YACnD,8BAA8B,QAAQ,CAAC,MAAM,EAAE,CAAC;QAClD,MAAM,IAAI,GACR,CAAC,OAAO,GAAG,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACjD,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QAE5B,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface HttpClientConfig {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
token: string;
|
|
4
|
+
defaultHeaders?: Record<string, string>;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
interface RequestOptions {
|
|
8
|
+
body?: unknown;
|
|
9
|
+
query?: Record<string, string>;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare class HttpClient {
|
|
13
|
+
private readonly baseUrl;
|
|
14
|
+
private readonly token;
|
|
15
|
+
private readonly defaultHeaders;
|
|
16
|
+
private readonly timeout;
|
|
17
|
+
constructor(config: HttpClientConfig);
|
|
18
|
+
/** JSON request → parsed JSON response. Throws ProxyError on non-2xx. */
|
|
19
|
+
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
20
|
+
/** Streaming response. Returns the raw ReadableStream body. */
|
|
21
|
+
stream(method: string, path: string, options?: Omit<RequestOptions, "query">): Promise<ReadableStream<Uint8Array>>;
|
|
22
|
+
/** Raw Response (for file downloads, etc.). Throws ProxyError on non-2xx. */
|
|
23
|
+
raw(method: string, path: string, options?: RequestOptions): Promise<Response>;
|
|
24
|
+
/** Multipart form upload. Throws ProxyError on non-2xx. */
|
|
25
|
+
upload<T>(path: string, formData: FormData): Promise<T>;
|
|
26
|
+
private send;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,gBAAgB;IAOpC,yEAAyE;IACnE,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAkBpF,+DAA+D;IACzD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAkBxH,6EAA6E;IACvE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAWpF,2DAA2D;IACrD,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;YAQ/C,IAAI;CAqCnB"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ProxyError } from "./errors.js";
|
|
2
|
+
export class HttpClient {
|
|
3
|
+
baseUrl;
|
|
4
|
+
token;
|
|
5
|
+
defaultHeaders;
|
|
6
|
+
timeout;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
9
|
+
this.token = config.token;
|
|
10
|
+
this.defaultHeaders = config.defaultHeaders ?? {};
|
|
11
|
+
this.timeout = config.timeout ?? 30_000;
|
|
12
|
+
}
|
|
13
|
+
/** JSON request → parsed JSON response. Throws ProxyError on non-2xx. */
|
|
14
|
+
async request(method, path, options) {
|
|
15
|
+
const response = await this.send(method, path, {
|
|
16
|
+
body: options?.body,
|
|
17
|
+
query: options?.query,
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
Accept: "application/json",
|
|
21
|
+
...options?.headers,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok)
|
|
25
|
+
throw await ProxyError.fromResponse(response);
|
|
26
|
+
const text = await response.text();
|
|
27
|
+
if (!text)
|
|
28
|
+
return undefined;
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
/** Streaming response. Returns the raw ReadableStream body. */
|
|
32
|
+
async stream(method, path, options) {
|
|
33
|
+
const response = await this.send(method, path, {
|
|
34
|
+
body: options?.body,
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Accept: "text/event-stream",
|
|
38
|
+
...options?.headers,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok)
|
|
42
|
+
throw await ProxyError.fromResponse(response);
|
|
43
|
+
if (!response.body) {
|
|
44
|
+
throw new ProxyError("Response body is null — streaming not supported", "STREAM_ERROR", 0);
|
|
45
|
+
}
|
|
46
|
+
return response.body;
|
|
47
|
+
}
|
|
48
|
+
/** Raw Response (for file downloads, etc.). Throws ProxyError on non-2xx. */
|
|
49
|
+
async raw(method, path, options) {
|
|
50
|
+
const response = await this.send(method, path, {
|
|
51
|
+
body: options?.body,
|
|
52
|
+
query: options?.query,
|
|
53
|
+
headers: options?.headers,
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
throw await ProxyError.fromResponse(response);
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
/** Multipart form upload. Throws ProxyError on non-2xx. */
|
|
60
|
+
async upload(path, formData) {
|
|
61
|
+
const response = await this.send("POST", path, { formData });
|
|
62
|
+
if (!response.ok)
|
|
63
|
+
throw await ProxyError.fromResponse(response);
|
|
64
|
+
return (await response.json());
|
|
65
|
+
}
|
|
66
|
+
// ── Internal ──
|
|
67
|
+
async send(method, path, options) {
|
|
68
|
+
let url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
69
|
+
if (options.query) {
|
|
70
|
+
const params = new URLSearchParams(options.query);
|
|
71
|
+
url += `?${params.toString()}`;
|
|
72
|
+
}
|
|
73
|
+
const headers = {
|
|
74
|
+
"x-api-key": this.token,
|
|
75
|
+
...this.defaultHeaders,
|
|
76
|
+
...options.headers,
|
|
77
|
+
};
|
|
78
|
+
// Don't set Content-Type for FormData — the browser/runtime sets it with boundary
|
|
79
|
+
if (options.formData) {
|
|
80
|
+
delete headers["Content-Type"];
|
|
81
|
+
}
|
|
82
|
+
const init = {
|
|
83
|
+
method,
|
|
84
|
+
headers,
|
|
85
|
+
body: options.formData ?? (options.body !== undefined ? JSON.stringify(options.body) : undefined),
|
|
86
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
87
|
+
};
|
|
88
|
+
return fetch(url, init);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAezC,MAAM,OAAO,UAAU;IACJ,OAAO,CAAS;IAChB,KAAK,CAAS;IACd,cAAc,CAAyB;IACvC,OAAO,CAAS;IAEjC,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;IAC1C,CAAC;IAED,yEAAyE;IACzE,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,IAAY,EAAE,OAAwB;QACrE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE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YACrB,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,IAAI,GAAgB;YACxB,MAAM;YACN,OAAO;YACP,IAAI,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACjG,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;SAC1C,CAAC;QAEF,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CloudProxy } from "./client.js";
|
|
2
|
+
import type { ClientConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a fully configured CloudProxy client.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { createClient } from "@et2bo/cloud-proxy";
|
|
9
|
+
*
|
|
10
|
+
* const proxy = createClient({
|
|
11
|
+
* baseUrl: process.env.PROXY_URL!,
|
|
12
|
+
* token: process.env.PROXY_TOKEN!,
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function createClient(config: ClientConfig): CloudProxy;
|
|
17
|
+
export { CloudProxy } from "./client.js";
|
|
18
|
+
export { ProxyError } from "./errors.js";
|
|
19
|
+
export { FieldOp } from "./types.js";
|
|
20
|
+
export type { ClientConfig, StreamOptions, ChatParams, ChatResponse, CreateUserParams, UpdateUserParams, UserRecord, UserListResult, DecodedToken, WhereOp, ListOptions, QueryParams, ListResult, BatchOperation, AggregateParams, FieldOpValue, UploadOptions, UploadResult, UploadUrlParams, SignedUploadUrl, SignedDownloadUrl, ListFilesOptions, FileListResult, CreateBucketParams, BucketInfo, EmbedOptions, EmbedBatchItem, StoreResult, EmbedResult, BatchEmbedResult, SearchOptions, SearchResult, SemanticSearchResult, UpdateVectorParams, CollectionSetup, SetupBucketParams, ProjectSetup, DatabaseStatus, CollectionsStatus, BucketSetupResult, AuthStatus, ProjectStatus, ProvisioningStatus, } from "./types.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAE7D;AAGD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,OAAO,EACP,WAAW,EACX,WAAW,EACX,UAAU,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CloudProxy } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a fully configured CloudProxy client.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createClient } from "@et2bo/cloud-proxy";
|
|
8
|
+
*
|
|
9
|
+
* const proxy = createClient({
|
|
10
|
+
* baseUrl: process.env.PROXY_URL!,
|
|
11
|
+
* token: process.env.PROXY_TOKEN!,
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function createClient(config) {
|
|
16
|
+
return new CloudProxy(config);
|
|
17
|
+
}
|
|
18
|
+
// Re-export the client class for advanced use
|
|
19
|
+
export { CloudProxy } from "./client.js";
|
|
20
|
+
// Re-export error class
|
|
21
|
+
export { ProxyError } from "./errors.js";
|
|
22
|
+
// Re-export FieldOp helpers
|
|
23
|
+
export { FieldOp } from "./types.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB;IAC/C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,8CAA8C;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,wBAAwB;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,4BAA4B;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import type { ChatParams, ChatResponse, StreamOptions } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* AI provider proxy. Forwards requests to upstream providers
|
|
5
|
+
* (OpenAI, Anthropic, Gemini, OpenRouter) through the proxy,
|
|
6
|
+
* which injects its own API keys.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AiModule {
|
|
9
|
+
private readonly http;
|
|
10
|
+
constructor(http: HttpClient);
|
|
11
|
+
/** Raw passthrough to OpenAI. Path is appended to `/ai/openai`. */
|
|
12
|
+
openai<T = unknown>(path: string, body: unknown, options?: StreamOptions): Promise<T>;
|
|
13
|
+
/** Raw passthrough to Anthropic. Path is appended to `/ai/anthropic`. */
|
|
14
|
+
anthropic<T = unknown>(path: string, body: unknown, options?: StreamOptions): Promise<T>;
|
|
15
|
+
/** Raw passthrough to Gemini. Path is appended to `/ai/gemini`. */
|
|
16
|
+
gemini<T = unknown>(path: string, body: unknown, options?: StreamOptions): Promise<T>;
|
|
17
|
+
/** Raw passthrough to OpenRouter. Path is appended to `/ai/openrouter`. */
|
|
18
|
+
openrouter<T = unknown>(path: string, body: unknown, options?: StreamOptions): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Convenience chat completion that normalizes the response across providers.
|
|
21
|
+
* The provider is auto-selected from `params.provider`.
|
|
22
|
+
*/
|
|
23
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Streaming chat completion. Sets `stream: true` and returns
|
|
26
|
+
* a `ReadableStream<Uint8Array>` suitable for `for await...of`.
|
|
27
|
+
*/
|
|
28
|
+
chatStream(params: ChatParams): Promise<ReadableStream<Uint8Array>>;
|
|
29
|
+
private providerRequest;
|
|
30
|
+
private buildChatRequest;
|
|
31
|
+
private normalizeChatResponse;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/modules/ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,O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