@lumi0/sdk 0.0.5 → 0.0.7

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 CHANGED
@@ -450,7 +450,7 @@ The client accepts configuration options:
450
450
  ```ts
451
451
  const client = new Lumi0({
452
452
  apiKey: process.env.LUMI0_API_KEY!,
453
- baseUrl: "https://api.lumi0.com/api/v1",
453
+ baseUrl: "https://api.lumi0.com/memory/v1",
454
454
  timeout: 30_000,
455
455
  });
456
456
  ```
@@ -470,7 +470,7 @@ The Lumi0 API endpoint.
470
470
  Default:
471
471
 
472
472
  ```text
473
- https://api.lumi0.com/api/v1
473
+ https://api.lumi0.com/memory/v1
474
474
  ```
475
475
 
476
476
  You can override it:
@@ -478,7 +478,7 @@ You can override it:
478
478
  ```ts
479
479
  const client = new Lumi0({
480
480
  apiKey: process.env.LUMI0_API_KEY!,
481
- baseUrl: "https://api.lumi0.com/api/v1",
481
+ baseUrl: "https://api.lumi0.com/memory/v1",
482
482
  });
483
483
  ```
484
484
 
package/dist/index.d.mts CHANGED
@@ -23,20 +23,28 @@ interface StoreMemoryInput {
23
23
  content: string;
24
24
  dedupeThreshold?: number;
25
25
  id: string;
26
+ /** Required for universal (org-wide) API keys. */
27
+ collectionId?: string;
26
28
  }
27
29
  interface BuildContextInput {
28
30
  id: string;
29
31
  query: string;
30
32
  limit?: number;
31
33
  minSimilarity?: number;
34
+ /** Required for universal (org-wide) API keys. */
35
+ collectionId?: string;
32
36
  }
33
37
  interface UploadFileInput {
34
38
  id: string;
35
39
  url: string;
40
+ /** Required for universal (org-wide) API keys. */
41
+ collectionId?: string;
36
42
  }
37
43
  interface MemoryRollbackInput {
38
44
  memoryId: string;
39
45
  version: number;
46
+ /** Required for universal (org-wide) API keys. */
47
+ collectionId?: string;
40
48
  }
41
49
  interface SearchMemoryInput {
42
50
  query: string;
@@ -44,10 +52,14 @@ interface SearchMemoryInput {
44
52
  minSimilarity?: number;
45
53
  memoryType?: string;
46
54
  id: string;
55
+ /** Required for universal (org-wide) API keys. */
56
+ collectionId?: string;
47
57
  }
48
58
  interface GetMemoryInput {
49
59
  id: string;
50
60
  version?: number;
61
+ /** Required for universal (org-wide) API keys. */
62
+ collectionId?: string;
51
63
  }
52
64
  interface CompressMemoryInput {
53
65
  content: string;
@@ -85,6 +97,8 @@ interface Compress {
85
97
  }
86
98
  interface ForgetMemoryInput {
87
99
  id: string;
100
+ /** Required for universal (org-wide) API keys. */
101
+ collectionId?: string;
88
102
  }
89
103
  interface Context {
90
104
  data: string;
@@ -110,11 +124,11 @@ declare class HttpClient {
110
124
  private readonly options;
111
125
  constructor(options: HttpClientOptions);
112
126
  request<T>(path: string, init?: RequestInit): Promise<T>;
113
- get<T>(path: string): Promise<T>;
114
- post<T>(path: string, body?: unknown): Promise<T>;
127
+ get<T>(path: string, init?: RequestInit): Promise<T>;
128
+ post<T>(path: string, body?: unknown, init?: RequestInit): Promise<T>;
115
129
  put<T>(path: string, body?: unknown): Promise<T>;
116
130
  patch<T>(path: string, body?: unknown): Promise<T>;
117
- delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
131
+ delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>, init?: RequestInit): Promise<T>;
118
132
  private parseError;
119
133
  }
120
134
  //#endregion
@@ -122,7 +136,15 @@ declare class HttpClient {
122
136
  declare class MemoryApi {
123
137
  private readonly http;
124
138
  constructor(http: HttpClient);
125
- history(id: string): Promise<MemoryVersion[]>;
139
+ store(input: StoreMemoryInput): Promise<unknown>;
140
+ search(input: SearchMemoryInput): Promise<Search>;
141
+ get(input: GetMemoryInput): Promise<Search>;
142
+ forget(input: ForgetMemoryInput): Promise<unknown>;
143
+ batch(input: StoreMemoryInput[]): Promise<unknown>;
144
+ context(input: BuildContextInput): Promise<Context>;
145
+ files(input: UploadFileInput): Promise<unknown>;
146
+ compress(input: CompressMemoryInput): Promise<Compress>;
147
+ history(id: string, collectionId?: string): Promise<MemoryVersion[]>;
126
148
  rollback(input: MemoryRollbackInput): Promise<unknown>;
127
149
  }
128
150
  //#endregion
@@ -141,4 +163,4 @@ declare class Lumi0 {
141
163
  compress(input: CompressMemoryInput): Promise<Compress>;
142
164
  }
143
165
  //#endregion
144
- export { BuildContextInput, Compress, CompressMemoryInput, Context, ErrorResponse, ForgetMemoryInput, GetMemoryInput, HttpClientOptions, IPostBody, Lumi0, Lumi0Options, MemoryRollbackInput, MemoryVersion, PostBody, Search, SearchMemoryInput, StoreMemoryInput, UploadFileInput };
166
+ export { BuildContextInput, Compress, CompressMemoryInput, Context, ErrorResponse, ForgetMemoryInput, GetMemoryInput, HttpClient, HttpClientOptions, IPostBody, Lumi0, Lumi0Options, MemoryApi, MemoryRollbackInput, MemoryVersion, PostBody, Search, SearchMemoryInput, StoreMemoryInput, UploadFileInput };
package/dist/index.mjs CHANGED
@@ -27,11 +27,12 @@ var HttpClient = class {
27
27
  clearTimeout(timeout);
28
28
  }
29
29
  }
30
- get(path) {
31
- return this.request(path);
30
+ get(path, init) {
31
+ return this.request(path, init);
32
32
  }
33
- post(path, body) {
33
+ post(path, body, init) {
34
34
  return this.request(path, {
35
+ ...init,
35
36
  method: "POST",
36
37
  body: body ? JSON.stringify(body) : void 0
37
38
  });
@@ -48,13 +49,16 @@ var HttpClient = class {
48
49
  body: body ? JSON.stringify(body) : void 0
49
50
  });
50
51
  }
51
- delete(path, query) {
52
+ delete(path, query, init) {
52
53
  const params = new URLSearchParams();
53
54
  if (query) {
54
55
  for (const [key, value] of Object.entries(query)) if (value !== void 0) params.append(key, String(value));
55
56
  }
56
57
  const url = params.toString() ? `${path}?${params}` : path;
57
- return this.request(url, { method: "DELETE" });
58
+ return this.request(url, {
59
+ ...init,
60
+ method: "DELETE"
61
+ });
58
62
  }
59
63
  async parseError(response) {
60
64
  let message = response.statusText;
@@ -67,16 +71,62 @@ var HttpClient = class {
67
71
  };
68
72
  //#endregion
69
73
  //#region src/memory.ts
74
+ /**
75
+ * Universal (org-wide) API keys must target a collection per request. The
76
+ * memory service reads it from the `X-Collection-Id` header for routes
77
+ * without a body channel (`DELETE /memory/:id`, history, rollback), so the
78
+ * SDK sends it as a header instead of a query param.
79
+ */
80
+ function collectionHeader(collectionId) {
81
+ return collectionId ? { headers: { "X-Collection-Id": collectionId } } : void 0;
82
+ }
70
83
  var MemoryApi = class {
71
84
  http;
72
85
  constructor(http) {
73
86
  this.http = http;
74
87
  }
75
- history(id) {
76
- return this.http.get(`/memories/history/${id}`).then((response) => response.data);
88
+ store(input) {
89
+ return this.http.post("/memory", {
90
+ ...input,
91
+ externalId: input.id
92
+ });
93
+ }
94
+ search(input) {
95
+ return this.http.post("/memory/search", {
96
+ ...input,
97
+ externalId: input.id
98
+ }).then((res) => res.data);
99
+ }
100
+ get(input) {
101
+ return this.http.post("/memory/get", input).then((res) => res.data);
102
+ }
103
+ forget(input) {
104
+ return this.http.delete(`/memory/${input.id}`, void 0, collectionHeader(input.collectionId));
105
+ }
106
+ batch(input) {
107
+ return this.http.post("/memory/batch", input.map((item) => ({ ...item })));
108
+ }
109
+ context(input) {
110
+ return this.http.post("/memory/context", {
111
+ ...input,
112
+ externalId: input.id
113
+ }).then((res) => res.data);
114
+ }
115
+ files(input) {
116
+ return this.http.post("/file/uploads", {
117
+ url: input.url,
118
+ id: input.id,
119
+ collectionId: input.collectionId
120
+ });
121
+ }
122
+ compress(input) {
123
+ return this.http.post("/compress", input).then((res) => res.data);
124
+ }
125
+ history(id, collectionId) {
126
+ return this.http.get(`/memories/history/${id}`, collectionHeader(collectionId)).then((response) => response.data);
77
127
  }
78
128
  rollback(input) {
79
- return this.http.post(`/memories/${input.memoryId}/versions/${input.version}/rollback`);
129
+ return this.http.post(`/memories/${input.memoryId}/versions/${input.version}/rollback`, void 0, collectionHeader(input.collectionId));
80
130
  }
81
131
  };
82
132
  //#endregion
@@ -87,48 +137,36 @@ var Lumi0 = class {
87
137
  constructor(option) {
88
138
  const apiKey = option.apiKey;
89
139
  this.http = new HttpClient({
90
- baseUrl: option.baseUrl ?? "https://api.lumi0.com/api/v1",
140
+ baseUrl: option.baseUrl ?? "https://api.lumi0.com/memory/v1",
91
141
  apiKey,
92
142
  timeout: option.timeout ?? 3e4
93
143
  });
94
144
  this.mem = new MemoryApi(this.http);
95
145
  }
96
146
  store(input) {
97
- return this.http.post("/memory", {
98
- ...input,
99
- externalId: input.id
100
- });
147
+ return this.mem.store(input);
101
148
  }
102
149
  search(input) {
103
- return this.http.post("/memory/search", {
104
- ...input,
105
- externalId: input.id
106
- }).then((res) => res.data);
150
+ return this.mem.search(input);
107
151
  }
108
152
  get(input) {
109
- return this.http.post("/memory/get", input).then((res) => res.data);
153
+ return this.mem.get(input);
110
154
  }
111
155
  forget(input) {
112
- return this.http.delete(`/memory/${input.id}`);
156
+ return this.mem.forget(input);
113
157
  }
114
158
  batch(input) {
115
- return this.http.post("/memory/batch", input.map((item) => ({ ...item })));
159
+ return this.mem.batch(input);
116
160
  }
117
161
  context(input) {
118
- return this.http.post("/memory/context", {
119
- ...input,
120
- externalId: input.id
121
- }).then((res) => res.data);
162
+ return this.mem.context(input);
122
163
  }
123
164
  files(input) {
124
- return this.http.post("/memory/batch", {
125
- ...input,
126
- externalId: input.id
127
- });
165
+ return this.mem.files(input);
128
166
  }
129
167
  compress(input) {
130
- return this.http.post("/compress", input).then((res) => res.data);
168
+ return this.mem.compress(input);
131
169
  }
132
170
  };
133
171
  //#endregion
134
- export { Lumi0 };
172
+ export { HttpClient, Lumi0, MemoryApi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumi0/sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Official TypeScript SDK for Lumi0",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,6 +33,7 @@
33
33
  "scripts": {
34
34
  "build": "tsdown index.ts",
35
35
  "dev": "bun --watch index.ts",
36
+ "test": "bun test",
36
37
  "typecheck": "tsc --noEmit",
37
38
  "prepublishOnly": "bun run typecheck && bun run build"
38
39
  },