@seizn/summer 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/dist/index.mjs ADDED
@@ -0,0 +1,270 @@
1
+ // src/client.ts
2
+ var DEFAULT_BASE_URL = "https://seizn.com/api/summer";
3
+ var DEFAULT_TIMEOUT = 6e4;
4
+ var DEFAULT_RETRIES = 3;
5
+ var SummerClient = class {
6
+ constructor(config) {
7
+ if (!config.apiKey) {
8
+ throw new Error("API key is required");
9
+ }
10
+ this.apiKey = config.apiKey;
11
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
12
+ this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
13
+ this.retries = config.retries ?? DEFAULT_RETRIES;
14
+ this.onError = config.onError;
15
+ }
16
+ // ============================================
17
+ // Collection Management
18
+ // ============================================
19
+ /**
20
+ * Create a new collection
21
+ */
22
+ async createCollection(request) {
23
+ const response = await this.request("/collections", {
24
+ method: "POST",
25
+ body: request
26
+ });
27
+ return response.collection;
28
+ }
29
+ /**
30
+ * List all collections
31
+ */
32
+ async listCollections() {
33
+ const response = await this.request("/collections");
34
+ return response.collections;
35
+ }
36
+ /**
37
+ * Get collection by ID
38
+ */
39
+ async getCollection(collectionId) {
40
+ const response = await this.request(
41
+ `/collections/${collectionId}`
42
+ );
43
+ return response.collection;
44
+ }
45
+ /**
46
+ * Delete a collection
47
+ */
48
+ async deleteCollection(collectionId) {
49
+ await this.request(`/collections/${collectionId}`, { method: "DELETE" });
50
+ }
51
+ /**
52
+ * Get collection statistics
53
+ */
54
+ async getCollectionStats(collectionId) {
55
+ return this.request(`/collections/${collectionId}/stats`);
56
+ }
57
+ // ============================================
58
+ // Document Indexing
59
+ // ============================================
60
+ /**
61
+ * Index a single document
62
+ */
63
+ async index(request) {
64
+ return this.request("/index", {
65
+ method: "POST",
66
+ body: request
67
+ });
68
+ }
69
+ /**
70
+ * Bulk index multiple documents
71
+ */
72
+ async bulkIndex(request) {
73
+ return this.request("/index/bulk", {
74
+ method: "POST",
75
+ body: request
76
+ });
77
+ }
78
+ /**
79
+ * Get document by ID
80
+ */
81
+ async getDocument(documentId) {
82
+ const response = await this.request(
83
+ `/documents/${documentId}`
84
+ );
85
+ return response.document;
86
+ }
87
+ /**
88
+ * Delete a document
89
+ */
90
+ async deleteDocument(documentId) {
91
+ await this.request(`/documents/${documentId}`, { method: "DELETE" });
92
+ }
93
+ /**
94
+ * Update document metadata
95
+ */
96
+ async updateDocumentMetadata(documentId, metadata) {
97
+ const response = await this.request(
98
+ `/documents/${documentId}`,
99
+ {
100
+ method: "PATCH",
101
+ body: { metadata }
102
+ }
103
+ );
104
+ return response.document;
105
+ }
106
+ // ============================================
107
+ // Search
108
+ // ============================================
109
+ /**
110
+ * Search within a collection
111
+ */
112
+ async search(request) {
113
+ return this.request("/search", {
114
+ method: "POST",
115
+ body: request
116
+ });
117
+ }
118
+ /**
119
+ * Quick search shorthand
120
+ */
121
+ async query(collectionId, query, options) {
122
+ return this.search({
123
+ collectionId,
124
+ query,
125
+ topK: options?.topK ?? 10,
126
+ mode: options?.mode ?? "hybrid",
127
+ rerank: options?.rerank ?? false
128
+ });
129
+ }
130
+ /**
131
+ * Federated search across multiple sources
132
+ */
133
+ async federatedSearch(request) {
134
+ return this.request("/search/federated", {
135
+ method: "POST",
136
+ body: request
137
+ });
138
+ }
139
+ // ============================================
140
+ // RAG Query
141
+ // ============================================
142
+ /**
143
+ * RAG query with answer generation
144
+ */
145
+ async rag(request) {
146
+ return this.request("/rag", {
147
+ method: "POST",
148
+ body: request
149
+ });
150
+ }
151
+ /**
152
+ * Quick RAG query shorthand
153
+ */
154
+ async ask(collectionId, question, options) {
155
+ return this.rag({
156
+ collectionId,
157
+ query: question,
158
+ systemPrompt: options?.systemPrompt,
159
+ contextLimit: options?.contextLimit ?? 8e3,
160
+ citationStyle: "inline"
161
+ });
162
+ }
163
+ // ============================================
164
+ // Analytics
165
+ // ============================================
166
+ /**
167
+ * Get search analytics
168
+ */
169
+ async getAnalytics(collectionId, period = "week") {
170
+ return this.request(
171
+ `/collections/${collectionId}/analytics?period=${period}`
172
+ );
173
+ }
174
+ // ============================================
175
+ // Utilities
176
+ // ============================================
177
+ /**
178
+ * Generate embedding for text (for external use)
179
+ */
180
+ async embed(text) {
181
+ const texts = Array.isArray(text) ? text : [text];
182
+ const response = await this.request("/embed", {
183
+ method: "POST",
184
+ body: { texts }
185
+ });
186
+ return response.embeddings;
187
+ }
188
+ /**
189
+ * Rerank results
190
+ */
191
+ async rerank(query, documents, topN) {
192
+ const response = await this.request(
193
+ "/rerank",
194
+ {
195
+ method: "POST",
196
+ body: { query, documents, topN }
197
+ }
198
+ );
199
+ return response.results;
200
+ }
201
+ // ============================================
202
+ // Internal
203
+ // ============================================
204
+ async request(path, options) {
205
+ const url = `${this.baseUrl}${path}`;
206
+ const method = options?.method ?? "GET";
207
+ let lastError = null;
208
+ for (let attempt = 0; attempt < this.retries; attempt++) {
209
+ try {
210
+ const controller = new AbortController();
211
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
212
+ const response = await fetch(url, {
213
+ method,
214
+ headers: {
215
+ Authorization: `Bearer ${this.apiKey}`,
216
+ "Content-Type": "application/json"
217
+ },
218
+ body: options?.body ? JSON.stringify(options.body) : void 0,
219
+ signal: controller.signal
220
+ });
221
+ clearTimeout(timeoutId);
222
+ if (!response.ok) {
223
+ const errorData = await response.json().catch(() => ({}));
224
+ const error = {
225
+ code: errorData.code ?? "REQUEST_FAILED",
226
+ message: errorData.error ?? errorData.message ?? `Request failed with status ${response.status}`,
227
+ status: response.status,
228
+ details: errorData
229
+ };
230
+ if (response.status >= 400 && response.status < 500) {
231
+ this.onError?.(error);
232
+ throw error;
233
+ }
234
+ lastError = error;
235
+ continue;
236
+ }
237
+ return response.json();
238
+ } catch (error) {
239
+ if (error instanceof Error && error.name === "AbortError") {
240
+ lastError = {
241
+ code: "TIMEOUT",
242
+ message: `Request timed out after ${this.timeout}ms`
243
+ };
244
+ } else if (error.code) {
245
+ throw error;
246
+ } else {
247
+ lastError = {
248
+ code: "NETWORK_ERROR",
249
+ message: error instanceof Error ? error.message : "Network error"
250
+ };
251
+ }
252
+ if (attempt < this.retries - 1) {
253
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1e3));
254
+ }
255
+ }
256
+ }
257
+ if (lastError) {
258
+ this.onError?.(lastError);
259
+ throw lastError;
260
+ }
261
+ throw { code: "UNKNOWN", message: "Unknown error" };
262
+ }
263
+ };
264
+ function createSummerClient(config) {
265
+ return new SummerClient(config);
266
+ }
267
+ export {
268
+ SummerClient,
269
+ createSummerClient
270
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@seizn/summer",
3
+ "version": "0.1.0",
4
+ "description": "Seizn Summer - RAG Infrastructure SDK for AI Applications",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
21
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
+ "lint": "eslint src/",
23
+ "test": "vitest run",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "keywords": [
27
+ "seizn",
28
+ "summer",
29
+ "rag",
30
+ "retrieval-augmented-generation",
31
+ "ai",
32
+ "vector-search",
33
+ "semantic-search",
34
+ "llm",
35
+ "embeddings"
36
+ ],
37
+ "author": "Seizn <support@seizn.com>",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/iruhana/seizn.git",
42
+ "directory": "packages/summer-sdk"
43
+ },
44
+ "homepage": "https://docs.seizn.com/summer",
45
+ "bugs": {
46
+ "url": "https://github.com/iruhana/seizn/issues"
47
+ },
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^20.0.0",
53
+ "tsup": "^8.0.0",
54
+ "typescript": "^5.0.0",
55
+ "vitest": "^1.0.0"
56
+ },
57
+ "peerDependencies": {
58
+ "typescript": ">=5.0.0"
59
+ },
60
+ "peerDependenciesMeta": {
61
+ "typescript": {
62
+ "optional": true
63
+ }
64
+ }
65
+ }