@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.
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Seizn Summer SDK - External Client Types
3
+ *
4
+ * Type definitions for external applications to integrate with
5
+ * Seizn's Summer RAG infrastructure.
6
+ */
7
+ interface Collection {
8
+ id: string;
9
+ name: string;
10
+ description?: string;
11
+ documentCount: number;
12
+ embeddingDimensions: number;
13
+ createdAt: string;
14
+ updatedAt?: string;
15
+ }
16
+ interface CreateCollectionRequest {
17
+ name: string;
18
+ description?: string;
19
+ embeddingModel?: 'voyage-3' | 'voyage-3-lite';
20
+ }
21
+ interface CreateCollectionResponse {
22
+ success: boolean;
23
+ collection: Collection;
24
+ }
25
+ interface Document {
26
+ id: string;
27
+ collectionId: string;
28
+ externalId?: string;
29
+ title?: string;
30
+ content: string;
31
+ metadata: Record<string, unknown>;
32
+ chunkCount: number;
33
+ createdAt: string;
34
+ updatedAt?: string;
35
+ }
36
+ interface IndexDocumentRequest {
37
+ collectionId: string;
38
+ externalId?: string;
39
+ title?: string;
40
+ content: string;
41
+ metadata?: Record<string, unknown>;
42
+ chunkingStrategy?: 'fixed' | 'semantic' | 'paragraph';
43
+ chunkSize?: number;
44
+ chunkOverlap?: number;
45
+ }
46
+ interface IndexDocumentResponse {
47
+ success: boolean;
48
+ document: Document;
49
+ chunksCreated: number;
50
+ }
51
+ interface BulkIndexRequest {
52
+ collectionId: string;
53
+ documents: Array<{
54
+ externalId?: string;
55
+ title?: string;
56
+ content: string;
57
+ metadata?: Record<string, unknown>;
58
+ }>;
59
+ chunkingStrategy?: 'fixed' | 'semantic' | 'paragraph';
60
+ }
61
+ interface BulkIndexResponse {
62
+ success: boolean;
63
+ indexed: number;
64
+ failed: number;
65
+ errors?: Array<{
66
+ index: number;
67
+ error: string;
68
+ }>;
69
+ }
70
+ type SearchMode = 'vector' | 'keyword' | 'hybrid';
71
+ interface SearchRequest {
72
+ collectionId: string;
73
+ query: string;
74
+ topK?: number;
75
+ threshold?: number;
76
+ mode?: SearchMode;
77
+ rerank?: boolean;
78
+ rerankTopN?: number;
79
+ filter?: Record<string, unknown>;
80
+ includeMetadata?: boolean;
81
+ }
82
+ interface SearchResult {
83
+ chunkId: string;
84
+ documentId: string;
85
+ externalId?: string;
86
+ title?: string;
87
+ content: string;
88
+ similarity: number;
89
+ rerankScore?: number;
90
+ metadata?: Record<string, unknown>;
91
+ }
92
+ interface SearchResponse {
93
+ success: boolean;
94
+ results: SearchResult[];
95
+ count: number;
96
+ mode: SearchMode;
97
+ timings: {
98
+ embedMs: number;
99
+ searchMs: number;
100
+ rerankMs?: number;
101
+ totalMs: number;
102
+ };
103
+ }
104
+ interface FederatedSource {
105
+ id: string;
106
+ name: string;
107
+ type: 'http' | 'agent';
108
+ priority: number;
109
+ weight: number;
110
+ }
111
+ interface FederatedSearchRequest {
112
+ query: string;
113
+ sources?: string[];
114
+ topK?: number;
115
+ mode?: SearchMode;
116
+ rerank?: boolean;
117
+ dedupe?: boolean;
118
+ }
119
+ interface FederatedSearchResponse {
120
+ success: boolean;
121
+ results: Array<SearchResult & {
122
+ source: string;
123
+ }>;
124
+ sourceStats: Array<{
125
+ sourceId: string;
126
+ resultsCount: number;
127
+ latencyMs: number;
128
+ }>;
129
+ timings: {
130
+ totalMs: number;
131
+ };
132
+ }
133
+ interface RAGQueryRequest {
134
+ collectionId: string;
135
+ query: string;
136
+ systemPrompt?: string;
137
+ contextLimit?: number;
138
+ citationStyle?: 'inline' | 'footnote' | 'none';
139
+ model?: 'claude-sonnet' | 'claude-haiku';
140
+ stream?: boolean;
141
+ }
142
+ interface Citation {
143
+ id: string;
144
+ documentId: string;
145
+ title?: string;
146
+ content: string;
147
+ relevance: number;
148
+ }
149
+ interface RAGQueryResponse {
150
+ success: boolean;
151
+ answer: string;
152
+ citations: Citation[];
153
+ usage: {
154
+ contextTokens: number;
155
+ responseTokens: number;
156
+ totalTokens: number;
157
+ };
158
+ timings: {
159
+ searchMs: number;
160
+ generationMs: number;
161
+ totalMs: number;
162
+ };
163
+ }
164
+ interface SummerClientConfig {
165
+ apiKey: string;
166
+ baseUrl?: string;
167
+ timeout?: number;
168
+ retries?: number;
169
+ onError?: (error: SummerError) => void;
170
+ }
171
+ interface SummerError {
172
+ code: string;
173
+ message: string;
174
+ status?: number;
175
+ details?: Record<string, unknown>;
176
+ }
177
+ interface CollectionStats {
178
+ collectionId: string;
179
+ documentCount: number;
180
+ chunkCount: number;
181
+ totalTokens: number;
182
+ storageBytes: number;
183
+ lastIndexedAt?: string;
184
+ }
185
+ interface SearchAnalytics {
186
+ period: 'day' | 'week' | 'month';
187
+ totalSearches: number;
188
+ averageLatencyMs: number;
189
+ topQueries: Array<{
190
+ query: string;
191
+ count: number;
192
+ }>;
193
+ modeDistribution: Record<SearchMode, number>;
194
+ }
195
+
196
+ /**
197
+ * Seizn Summer SDK Client
198
+ *
199
+ * TypeScript SDK for Seizn's Summer RAG infrastructure.
200
+ * Enables external applications to integrate with Seizn's
201
+ * vector search and RAG capabilities.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * import { SummerClient } from '@seizn/summer';
206
+ *
207
+ * const summer = new SummerClient({
208
+ * apiKey: process.env.SEIZN_API_KEY!,
209
+ * });
210
+ *
211
+ * // Index a document
212
+ * await summer.index({
213
+ * collectionId: 'my-collection',
214
+ * content: 'Document content...',
215
+ * metadata: { source: 'my-app' },
216
+ * });
217
+ *
218
+ * // Search
219
+ * const results = await summer.search({
220
+ * collectionId: 'my-collection',
221
+ * query: 'What is machine learning?',
222
+ * mode: 'hybrid',
223
+ * rerank: true,
224
+ * });
225
+ * ```
226
+ */
227
+
228
+ declare class SummerClient {
229
+ private readonly apiKey;
230
+ private readonly baseUrl;
231
+ private readonly timeout;
232
+ private readonly retries;
233
+ private readonly onError?;
234
+ constructor(config: SummerClientConfig);
235
+ /**
236
+ * Create a new collection
237
+ */
238
+ createCollection(request: CreateCollectionRequest): Promise<Collection>;
239
+ /**
240
+ * List all collections
241
+ */
242
+ listCollections(): Promise<Collection[]>;
243
+ /**
244
+ * Get collection by ID
245
+ */
246
+ getCollection(collectionId: string): Promise<Collection>;
247
+ /**
248
+ * Delete a collection
249
+ */
250
+ deleteCollection(collectionId: string): Promise<void>;
251
+ /**
252
+ * Get collection statistics
253
+ */
254
+ getCollectionStats(collectionId: string): Promise<CollectionStats>;
255
+ /**
256
+ * Index a single document
257
+ */
258
+ index(request: IndexDocumentRequest): Promise<IndexDocumentResponse>;
259
+ /**
260
+ * Bulk index multiple documents
261
+ */
262
+ bulkIndex(request: BulkIndexRequest): Promise<BulkIndexResponse>;
263
+ /**
264
+ * Get document by ID
265
+ */
266
+ getDocument(documentId: string): Promise<Document>;
267
+ /**
268
+ * Delete a document
269
+ */
270
+ deleteDocument(documentId: string): Promise<void>;
271
+ /**
272
+ * Update document metadata
273
+ */
274
+ updateDocumentMetadata(documentId: string, metadata: Record<string, unknown>): Promise<Document>;
275
+ /**
276
+ * Search within a collection
277
+ */
278
+ search(request: SearchRequest): Promise<SearchResponse>;
279
+ /**
280
+ * Quick search shorthand
281
+ */
282
+ query(collectionId: string, query: string, options?: {
283
+ topK?: number;
284
+ mode?: 'vector' | 'keyword' | 'hybrid';
285
+ rerank?: boolean;
286
+ }): Promise<SearchResponse>;
287
+ /**
288
+ * Federated search across multiple sources
289
+ */
290
+ federatedSearch(request: FederatedSearchRequest): Promise<FederatedSearchResponse>;
291
+ /**
292
+ * RAG query with answer generation
293
+ */
294
+ rag(request: RAGQueryRequest): Promise<RAGQueryResponse>;
295
+ /**
296
+ * Quick RAG query shorthand
297
+ */
298
+ ask(collectionId: string, question: string, options?: {
299
+ systemPrompt?: string;
300
+ contextLimit?: number;
301
+ }): Promise<RAGQueryResponse>;
302
+ /**
303
+ * Get search analytics
304
+ */
305
+ getAnalytics(collectionId: string, period?: 'day' | 'week' | 'month'): Promise<SearchAnalytics>;
306
+ /**
307
+ * Generate embedding for text (for external use)
308
+ */
309
+ embed(text: string | string[]): Promise<number[][]>;
310
+ /**
311
+ * Rerank results
312
+ */
313
+ rerank(query: string, documents: Array<{
314
+ id: string;
315
+ text: string;
316
+ }>, topN?: number): Promise<Array<{
317
+ id: string;
318
+ score: number;
319
+ }>>;
320
+ private request;
321
+ }
322
+ /**
323
+ * Create a Summer client instance
324
+ */
325
+ declare function createSummerClient(config: SummerClientConfig): SummerClient;
326
+
327
+ export { type BulkIndexRequest, type BulkIndexResponse, type Citation, type Collection, type CollectionStats, type CreateCollectionRequest, type CreateCollectionResponse, type Document, type FederatedSearchRequest, type FederatedSearchResponse, type FederatedSource, type IndexDocumentRequest, type IndexDocumentResponse, type RAGQueryRequest, type RAGQueryResponse, type SearchAnalytics, type SearchMode, type SearchRequest, type SearchResponse, type SearchResult, SummerClient, type SummerClientConfig, type SummerError, createSummerClient };
package/dist/index.js ADDED
@@ -0,0 +1,298 @@
1
+ "use strict";
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.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SummerClient: () => SummerClient,
24
+ createSummerClient: () => createSummerClient
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/client.ts
29
+ var DEFAULT_BASE_URL = "https://seizn.com/api/summer";
30
+ var DEFAULT_TIMEOUT = 6e4;
31
+ var DEFAULT_RETRIES = 3;
32
+ var SummerClient = class {
33
+ constructor(config) {
34
+ if (!config.apiKey) {
35
+ throw new Error("API key is required");
36
+ }
37
+ this.apiKey = config.apiKey;
38
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
39
+ this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
40
+ this.retries = config.retries ?? DEFAULT_RETRIES;
41
+ this.onError = config.onError;
42
+ }
43
+ // ============================================
44
+ // Collection Management
45
+ // ============================================
46
+ /**
47
+ * Create a new collection
48
+ */
49
+ async createCollection(request) {
50
+ const response = await this.request("/collections", {
51
+ method: "POST",
52
+ body: request
53
+ });
54
+ return response.collection;
55
+ }
56
+ /**
57
+ * List all collections
58
+ */
59
+ async listCollections() {
60
+ const response = await this.request("/collections");
61
+ return response.collections;
62
+ }
63
+ /**
64
+ * Get collection by ID
65
+ */
66
+ async getCollection(collectionId) {
67
+ const response = await this.request(
68
+ `/collections/${collectionId}`
69
+ );
70
+ return response.collection;
71
+ }
72
+ /**
73
+ * Delete a collection
74
+ */
75
+ async deleteCollection(collectionId) {
76
+ await this.request(`/collections/${collectionId}`, { method: "DELETE" });
77
+ }
78
+ /**
79
+ * Get collection statistics
80
+ */
81
+ async getCollectionStats(collectionId) {
82
+ return this.request(`/collections/${collectionId}/stats`);
83
+ }
84
+ // ============================================
85
+ // Document Indexing
86
+ // ============================================
87
+ /**
88
+ * Index a single document
89
+ */
90
+ async index(request) {
91
+ return this.request("/index", {
92
+ method: "POST",
93
+ body: request
94
+ });
95
+ }
96
+ /**
97
+ * Bulk index multiple documents
98
+ */
99
+ async bulkIndex(request) {
100
+ return this.request("/index/bulk", {
101
+ method: "POST",
102
+ body: request
103
+ });
104
+ }
105
+ /**
106
+ * Get document by ID
107
+ */
108
+ async getDocument(documentId) {
109
+ const response = await this.request(
110
+ `/documents/${documentId}`
111
+ );
112
+ return response.document;
113
+ }
114
+ /**
115
+ * Delete a document
116
+ */
117
+ async deleteDocument(documentId) {
118
+ await this.request(`/documents/${documentId}`, { method: "DELETE" });
119
+ }
120
+ /**
121
+ * Update document metadata
122
+ */
123
+ async updateDocumentMetadata(documentId, metadata) {
124
+ const response = await this.request(
125
+ `/documents/${documentId}`,
126
+ {
127
+ method: "PATCH",
128
+ body: { metadata }
129
+ }
130
+ );
131
+ return response.document;
132
+ }
133
+ // ============================================
134
+ // Search
135
+ // ============================================
136
+ /**
137
+ * Search within a collection
138
+ */
139
+ async search(request) {
140
+ return this.request("/search", {
141
+ method: "POST",
142
+ body: request
143
+ });
144
+ }
145
+ /**
146
+ * Quick search shorthand
147
+ */
148
+ async query(collectionId, query, options) {
149
+ return this.search({
150
+ collectionId,
151
+ query,
152
+ topK: options?.topK ?? 10,
153
+ mode: options?.mode ?? "hybrid",
154
+ rerank: options?.rerank ?? false
155
+ });
156
+ }
157
+ /**
158
+ * Federated search across multiple sources
159
+ */
160
+ async federatedSearch(request) {
161
+ return this.request("/search/federated", {
162
+ method: "POST",
163
+ body: request
164
+ });
165
+ }
166
+ // ============================================
167
+ // RAG Query
168
+ // ============================================
169
+ /**
170
+ * RAG query with answer generation
171
+ */
172
+ async rag(request) {
173
+ return this.request("/rag", {
174
+ method: "POST",
175
+ body: request
176
+ });
177
+ }
178
+ /**
179
+ * Quick RAG query shorthand
180
+ */
181
+ async ask(collectionId, question, options) {
182
+ return this.rag({
183
+ collectionId,
184
+ query: question,
185
+ systemPrompt: options?.systemPrompt,
186
+ contextLimit: options?.contextLimit ?? 8e3,
187
+ citationStyle: "inline"
188
+ });
189
+ }
190
+ // ============================================
191
+ // Analytics
192
+ // ============================================
193
+ /**
194
+ * Get search analytics
195
+ */
196
+ async getAnalytics(collectionId, period = "week") {
197
+ return this.request(
198
+ `/collections/${collectionId}/analytics?period=${period}`
199
+ );
200
+ }
201
+ // ============================================
202
+ // Utilities
203
+ // ============================================
204
+ /**
205
+ * Generate embedding for text (for external use)
206
+ */
207
+ async embed(text) {
208
+ const texts = Array.isArray(text) ? text : [text];
209
+ const response = await this.request("/embed", {
210
+ method: "POST",
211
+ body: { texts }
212
+ });
213
+ return response.embeddings;
214
+ }
215
+ /**
216
+ * Rerank results
217
+ */
218
+ async rerank(query, documents, topN) {
219
+ const response = await this.request(
220
+ "/rerank",
221
+ {
222
+ method: "POST",
223
+ body: { query, documents, topN }
224
+ }
225
+ );
226
+ return response.results;
227
+ }
228
+ // ============================================
229
+ // Internal
230
+ // ============================================
231
+ async request(path, options) {
232
+ const url = `${this.baseUrl}${path}`;
233
+ const method = options?.method ?? "GET";
234
+ let lastError = null;
235
+ for (let attempt = 0; attempt < this.retries; attempt++) {
236
+ try {
237
+ const controller = new AbortController();
238
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
239
+ const response = await fetch(url, {
240
+ method,
241
+ headers: {
242
+ Authorization: `Bearer ${this.apiKey}`,
243
+ "Content-Type": "application/json"
244
+ },
245
+ body: options?.body ? JSON.stringify(options.body) : void 0,
246
+ signal: controller.signal
247
+ });
248
+ clearTimeout(timeoutId);
249
+ if (!response.ok) {
250
+ const errorData = await response.json().catch(() => ({}));
251
+ const error = {
252
+ code: errorData.code ?? "REQUEST_FAILED",
253
+ message: errorData.error ?? errorData.message ?? `Request failed with status ${response.status}`,
254
+ status: response.status,
255
+ details: errorData
256
+ };
257
+ if (response.status >= 400 && response.status < 500) {
258
+ this.onError?.(error);
259
+ throw error;
260
+ }
261
+ lastError = error;
262
+ continue;
263
+ }
264
+ return response.json();
265
+ } catch (error) {
266
+ if (error instanceof Error && error.name === "AbortError") {
267
+ lastError = {
268
+ code: "TIMEOUT",
269
+ message: `Request timed out after ${this.timeout}ms`
270
+ };
271
+ } else if (error.code) {
272
+ throw error;
273
+ } else {
274
+ lastError = {
275
+ code: "NETWORK_ERROR",
276
+ message: error instanceof Error ? error.message : "Network error"
277
+ };
278
+ }
279
+ if (attempt < this.retries - 1) {
280
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1e3));
281
+ }
282
+ }
283
+ }
284
+ if (lastError) {
285
+ this.onError?.(lastError);
286
+ throw lastError;
287
+ }
288
+ throw { code: "UNKNOWN", message: "Unknown error" };
289
+ }
290
+ };
291
+ function createSummerClient(config) {
292
+ return new SummerClient(config);
293
+ }
294
+ // Annotate the CommonJS export names for ESM import in node:
295
+ 0 && (module.exports = {
296
+ SummerClient,
297
+ createSummerClient
298
+ });