@vectorize-io/hindsight-client 0.2.0 → 0.3.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/generated/sdk.gen.d.ts +15 -3
- package/dist/generated/sdk.gen.d.ts.map +1 -1
- package/dist/generated/sdk.gen.js +17 -3
- package/dist/generated/sdk.gen.js.map +1 -1
- package/dist/generated/types.gen.d.ts +271 -0
- package/dist/generated/types.gen.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -10
- package/dist/src/index.js.map +1 -1
- package/generated/sdk.gen.ts +36 -2
- package/generated/types.gen.ts +284 -0
- package/package.json +2 -2
- package/src/index.ts +21 -12
package/src/index.ts
CHANGED
|
@@ -62,6 +62,7 @@ export interface MemoryItemInput {
|
|
|
62
62
|
metadata?: Record<string, string>;
|
|
63
63
|
document_id?: string;
|
|
64
64
|
entities?: EntityInput[];
|
|
65
|
+
tags?: string[];
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export class HindsightClient {
|
|
@@ -78,6 +79,16 @@ export class HindsightClient {
|
|
|
78
79
|
);
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Validates the API response and throws an error if the request failed.
|
|
84
|
+
*/
|
|
85
|
+
private validateResponse<T>(response: { data?: T; error?: unknown }, operation: string): T {
|
|
86
|
+
if (!response.data) {
|
|
87
|
+
throw new Error(`${operation} failed: ${JSON.stringify(response.error || 'Unknown error')}`);
|
|
88
|
+
}
|
|
89
|
+
return response.data;
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
/**
|
|
82
93
|
* Retain a single memory for a bank.
|
|
83
94
|
*/
|
|
@@ -126,19 +137,20 @@ export class HindsightClient {
|
|
|
126
137
|
body: { items: [item], async: options?.async },
|
|
127
138
|
});
|
|
128
139
|
|
|
129
|
-
return response
|
|
140
|
+
return this.validateResponse(response, 'retain');
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
/**
|
|
133
144
|
* Retain multiple memories in batch.
|
|
134
145
|
*/
|
|
135
|
-
async retainBatch(bankId: string, items: MemoryItemInput[], options?: { documentId?: string; async?: boolean }): Promise<RetainResponse> {
|
|
146
|
+
async retainBatch(bankId: string, items: MemoryItemInput[], options?: { documentId?: string; documentTags?: string[]; async?: boolean }): Promise<RetainResponse> {
|
|
136
147
|
const processedItems = items.map((item) => ({
|
|
137
148
|
content: item.content,
|
|
138
149
|
context: item.context,
|
|
139
150
|
metadata: item.metadata,
|
|
140
151
|
document_id: item.document_id,
|
|
141
152
|
entities: item.entities,
|
|
153
|
+
tags: item.tags,
|
|
142
154
|
timestamp:
|
|
143
155
|
item.timestamp instanceof Date
|
|
144
156
|
? item.timestamp.toISOString()
|
|
@@ -156,11 +168,12 @@ export class HindsightClient {
|
|
|
156
168
|
path: { bank_id: bankId },
|
|
157
169
|
body: {
|
|
158
170
|
items: itemsWithDocId,
|
|
171
|
+
document_tags: options?.documentTags,
|
|
159
172
|
async: options?.async,
|
|
160
173
|
},
|
|
161
174
|
});
|
|
162
175
|
|
|
163
|
-
return response
|
|
176
|
+
return this.validateResponse(response, 'retainBatch');
|
|
164
177
|
}
|
|
165
178
|
|
|
166
179
|
/**
|
|
@@ -198,11 +211,7 @@ export class HindsightClient {
|
|
|
198
211
|
},
|
|
199
212
|
});
|
|
200
213
|
|
|
201
|
-
|
|
202
|
-
throw new Error(`API returned no data: ${JSON.stringify(response.error || 'Unknown error')}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return response.data;
|
|
214
|
+
return this.validateResponse(response, 'recall');
|
|
206
215
|
}
|
|
207
216
|
|
|
208
217
|
/**
|
|
@@ -223,7 +232,7 @@ export class HindsightClient {
|
|
|
223
232
|
},
|
|
224
233
|
});
|
|
225
234
|
|
|
226
|
-
return response
|
|
235
|
+
return this.validateResponse(response, 'reflect');
|
|
227
236
|
}
|
|
228
237
|
|
|
229
238
|
/**
|
|
@@ -244,7 +253,7 @@ export class HindsightClient {
|
|
|
244
253
|
},
|
|
245
254
|
});
|
|
246
255
|
|
|
247
|
-
return response
|
|
256
|
+
return this.validateResponse(response, 'listMemories');
|
|
248
257
|
}
|
|
249
258
|
|
|
250
259
|
/**
|
|
@@ -264,7 +273,7 @@ export class HindsightClient {
|
|
|
264
273
|
},
|
|
265
274
|
});
|
|
266
275
|
|
|
267
|
-
return response
|
|
276
|
+
return this.validateResponse(response, 'createBank');
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
/**
|
|
@@ -276,7 +285,7 @@ export class HindsightClient {
|
|
|
276
285
|
path: { bank_id: bankId },
|
|
277
286
|
});
|
|
278
287
|
|
|
279
|
-
return response
|
|
288
|
+
return this.validateResponse(response, 'getBankProfile');
|
|
280
289
|
}
|
|
281
290
|
}
|
|
282
291
|
|