@eight-atulya/atulya-client 0.8.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 +89 -0
- package/dist/generated/client/client.gen.d.ts +3 -0
- package/dist/generated/client/client.gen.d.ts.map +1 -0
- package/dist/generated/client/client.gen.js +233 -0
- package/dist/generated/client/client.gen.js.map +1 -0
- package/dist/generated/client/index.d.ts +9 -0
- package/dist/generated/client/index.d.ts.map +1 -0
- package/dist/generated/client/index.js +18 -0
- package/dist/generated/client/index.js.map +1 -0
- package/dist/generated/client/types.gen.d.ts +118 -0
- package/dist/generated/client/types.gen.d.ts.map +1 -0
- package/dist/generated/client/types.gen.js +4 -0
- package/dist/generated/client/types.gen.js.map +1 -0
- package/dist/generated/client/utils.gen.d.ts +34 -0
- package/dist/generated/client/utils.gen.d.ts.map +1 -0
- package/dist/generated/client/utils.gen.js +245 -0
- package/dist/generated/client/utils.gen.js.map +1 -0
- package/dist/generated/client.gen.d.ts +13 -0
- package/dist/generated/client.gen.d.ts.map +1 -0
- package/dist/generated/client.gen.js +7 -0
- package/dist/generated/client.gen.js.map +1 -0
- package/dist/generated/core/auth.gen.d.ts +19 -0
- package/dist/generated/core/auth.gen.d.ts.map +1 -0
- package/dist/generated/core/auth.gen.js +19 -0
- package/dist/generated/core/auth.gen.js.map +1 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +26 -0
- package/dist/generated/core/bodySerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/bodySerializer.gen.js +61 -0
- package/dist/generated/core/bodySerializer.gen.js.map +1 -0
- package/dist/generated/core/params.gen.d.ts +44 -0
- package/dist/generated/core/params.gen.d.ts.map +1 -0
- package/dist/generated/core/params.gen.js +105 -0
- package/dist/generated/core/params.gen.js.map +1 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +34 -0
- package/dist/generated/core/pathSerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/pathSerializer.gen.js +124 -0
- package/dist/generated/core/pathSerializer.gen.js.map +1 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +19 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/dist/generated/core/queryKeySerializer.gen.js +106 -0
- package/dist/generated/core/queryKeySerializer.gen.js.map +1 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +72 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts.map +1 -0
- package/dist/generated/core/serverSentEvents.gen.js +140 -0
- package/dist/generated/core/serverSentEvents.gen.js.map +1 -0
- package/dist/generated/core/types.gen.d.ts +79 -0
- package/dist/generated/core/types.gen.d.ts.map +1 -0
- package/dist/generated/core/types.gen.js +4 -0
- package/dist/generated/core/types.gen.js.map +1 -0
- package/dist/generated/core/utils.gen.d.ts +20 -0
- package/dist/generated/core/utils.gen.d.ts.map +1 -0
- package/dist/generated/core/utils.gen.js +94 -0
- package/dist/generated/core/utils.gen.js.map +1 -0
- package/dist/generated/index.d.ts +3 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +19 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/sdk.gen.d.ts +417 -0
- package/dist/generated/sdk.gen.d.ts.map +1 -0
- package/dist/generated/sdk.gen.js +608 -0
- package/dist/generated/sdk.gen.js.map +1 -0
- package/dist/generated/types.gen.d.ts +4147 -0
- package/dist/generated/types.gen.d.ts.map +1 -0
- package/dist/generated/types.gen.js +4 -0
- package/dist/generated/types.gen.js.map +1 -0
- package/dist/src/index.d.ts +310 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +518 -0
- package/dist/src/index.js.map +1 -0
- package/generated/client/client.gen.ts +301 -0
- package/generated/client/index.ts +25 -0
- package/generated/client/types.gen.ts +242 -0
- package/generated/client/utils.gen.ts +337 -0
- package/generated/client.gen.ts +23 -0
- package/generated/core/auth.gen.ts +42 -0
- package/generated/core/bodySerializer.gen.ts +100 -0
- package/generated/core/params.gen.ts +176 -0
- package/generated/core/pathSerializer.gen.ts +180 -0
- package/generated/core/queryKeySerializer.gen.ts +136 -0
- package/generated/core/serverSentEvents.gen.ts +264 -0
- package/generated/core/types.gen.ts +118 -0
- package/generated/core/utils.gen.ts +143 -0
- package/generated/index.ts +4 -0
- package/generated/sdk.gen.ts +1163 -0
- package/generated/types.gen.ts +4560 -0
- package/package.json +42 -0
- package/src/index.ts +749 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atulya Client - Clean, TypeScript SDK for the Atulya API.
|
|
3
|
+
*
|
|
4
|
+
* Example:
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { AtulyaClient } from '@eight-atulya/atulya-client';
|
|
7
|
+
*
|
|
8
|
+
* // Without authentication
|
|
9
|
+
* const client = new AtulyaClient({ baseUrl: 'http://localhost:8888' });
|
|
10
|
+
*
|
|
11
|
+
* // With API key authentication
|
|
12
|
+
* const client = new AtulyaClient({
|
|
13
|
+
* baseUrl: 'http://localhost:8888',
|
|
14
|
+
* apiKey: 'your-api-key'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Retain a memory
|
|
18
|
+
* await client.retain('alice', 'Alice loves AI');
|
|
19
|
+
*
|
|
20
|
+
* // Recall memories
|
|
21
|
+
* const results = await client.recall('alice', 'What does Alice like?');
|
|
22
|
+
*
|
|
23
|
+
* // Generate contextual answer
|
|
24
|
+
* const answer = await client.reflect('alice', 'What are my interests?');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { createClient, createConfig } from '../generated/client';
|
|
29
|
+
import type { Client } from '../generated/client';
|
|
30
|
+
import * as sdk from '../generated/sdk.gen';
|
|
31
|
+
import type {
|
|
32
|
+
RetainRequest,
|
|
33
|
+
RetainResponse,
|
|
34
|
+
RecallRequest,
|
|
35
|
+
RecallResponse,
|
|
36
|
+
RecallResult,
|
|
37
|
+
ReflectRequest,
|
|
38
|
+
ReflectResponse,
|
|
39
|
+
FileRetainResponse,
|
|
40
|
+
ListMemoryUnitsResponse,
|
|
41
|
+
BankProfileResponse,
|
|
42
|
+
BankConfigResponse,
|
|
43
|
+
CreateBankRequest,
|
|
44
|
+
Budget,
|
|
45
|
+
} from '../generated/types.gen';
|
|
46
|
+
|
|
47
|
+
export interface AtulyaClientOptions {
|
|
48
|
+
baseUrl: string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional API key for authentication (sent as Bearer token in Authorization header)
|
|
51
|
+
*/
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Error thrown by the Atulya client when an API request fails.
|
|
57
|
+
* Includes the HTTP status code and error details from the API.
|
|
58
|
+
*/
|
|
59
|
+
export class AtulyaError extends Error {
|
|
60
|
+
public statusCode?: number;
|
|
61
|
+
public details?: unknown;
|
|
62
|
+
|
|
63
|
+
constructor(message: string, statusCode?: number, details?: unknown) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = 'AtulyaError';
|
|
66
|
+
this.statusCode = statusCode;
|
|
67
|
+
this.details = details;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface EntityInput {
|
|
72
|
+
text: string;
|
|
73
|
+
type?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface MemoryItemInput {
|
|
77
|
+
content: string;
|
|
78
|
+
timestamp?: string | Date;
|
|
79
|
+
context?: string;
|
|
80
|
+
metadata?: Record<string, string>;
|
|
81
|
+
document_id?: string;
|
|
82
|
+
entities?: EntityInput[];
|
|
83
|
+
tags?: string[];
|
|
84
|
+
observation_scopes?: "per_tag" | "combined" | "all_combinations" | string[][];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class AtulyaClient {
|
|
88
|
+
private client: Client;
|
|
89
|
+
|
|
90
|
+
constructor(options: AtulyaClientOptions) {
|
|
91
|
+
this.client = createClient(
|
|
92
|
+
createConfig({
|
|
93
|
+
baseUrl: options.baseUrl,
|
|
94
|
+
headers: options.apiKey
|
|
95
|
+
? { Authorization: `Bearer ${options.apiKey}` }
|
|
96
|
+
: undefined,
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Validates the API response and throws an error if the request failed.
|
|
103
|
+
*/
|
|
104
|
+
private validateResponse<T>(response: { data?: T; error?: unknown; response?: Response }, operation: string): T {
|
|
105
|
+
if (!response.data) {
|
|
106
|
+
// The generated client returns { error, response, request }
|
|
107
|
+
// Status code is in response.status, not in the error object
|
|
108
|
+
const error = response.error as any;
|
|
109
|
+
const httpResponse = (response as any).response as Response | undefined;
|
|
110
|
+
|
|
111
|
+
// Extract status code from the HTTP response object
|
|
112
|
+
const statusCode = httpResponse?.status;
|
|
113
|
+
const details = error?.detail || error?.message || error;
|
|
114
|
+
|
|
115
|
+
throw new AtulyaError(
|
|
116
|
+
`${operation} failed: ${JSON.stringify(details)}`,
|
|
117
|
+
statusCode,
|
|
118
|
+
details
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return response.data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Retain a single memory for a bank.
|
|
126
|
+
*/
|
|
127
|
+
async retain(
|
|
128
|
+
bankId: string,
|
|
129
|
+
content: string,
|
|
130
|
+
options?: {
|
|
131
|
+
timestamp?: Date | string;
|
|
132
|
+
context?: string;
|
|
133
|
+
metadata?: Record<string, string>;
|
|
134
|
+
documentId?: string;
|
|
135
|
+
async?: boolean;
|
|
136
|
+
entities?: EntityInput[];
|
|
137
|
+
/** Optional list of tags for this memory */
|
|
138
|
+
tags?: string[];
|
|
139
|
+
}
|
|
140
|
+
): Promise<RetainResponse> {
|
|
141
|
+
const item: {
|
|
142
|
+
content: string;
|
|
143
|
+
timestamp?: string;
|
|
144
|
+
context?: string;
|
|
145
|
+
metadata?: Record<string, string>;
|
|
146
|
+
document_id?: string;
|
|
147
|
+
entities?: EntityInput[];
|
|
148
|
+
tags?: string[];
|
|
149
|
+
} = { content };
|
|
150
|
+
if (options?.timestamp) {
|
|
151
|
+
item.timestamp =
|
|
152
|
+
options.timestamp instanceof Date
|
|
153
|
+
? options.timestamp.toISOString()
|
|
154
|
+
: options.timestamp;
|
|
155
|
+
}
|
|
156
|
+
if (options?.context) {
|
|
157
|
+
item.context = options.context;
|
|
158
|
+
}
|
|
159
|
+
if (options?.metadata) {
|
|
160
|
+
item.metadata = options.metadata;
|
|
161
|
+
}
|
|
162
|
+
if (options?.documentId) {
|
|
163
|
+
item.document_id = options.documentId;
|
|
164
|
+
}
|
|
165
|
+
if (options?.entities) {
|
|
166
|
+
item.entities = options.entities;
|
|
167
|
+
}
|
|
168
|
+
if (options?.tags) {
|
|
169
|
+
item.tags = options.tags;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const response = await sdk.retainMemories({
|
|
173
|
+
client: this.client,
|
|
174
|
+
path: { bank_id: bankId },
|
|
175
|
+
body: { items: [item], async: options?.async },
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
return this.validateResponse(response, 'retain');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Retain multiple memories in batch.
|
|
183
|
+
*/
|
|
184
|
+
async retainBatch(bankId: string, items: MemoryItemInput[], options?: { documentId?: string; documentTags?: string[]; async?: boolean }): Promise<RetainResponse> {
|
|
185
|
+
const processedItems = items.map((item) => ({
|
|
186
|
+
content: item.content,
|
|
187
|
+
context: item.context,
|
|
188
|
+
metadata: item.metadata,
|
|
189
|
+
document_id: item.document_id,
|
|
190
|
+
entities: item.entities,
|
|
191
|
+
tags: item.tags,
|
|
192
|
+
observation_scopes: item.observation_scopes,
|
|
193
|
+
timestamp:
|
|
194
|
+
item.timestamp instanceof Date
|
|
195
|
+
? item.timestamp.toISOString()
|
|
196
|
+
: item.timestamp,
|
|
197
|
+
}));
|
|
198
|
+
|
|
199
|
+
// If documentId is provided at the batch level, add it to all items that don't have one
|
|
200
|
+
const itemsWithDocId = processedItems.map(item => ({
|
|
201
|
+
...item,
|
|
202
|
+
document_id: item.document_id || options?.documentId
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
const response = await sdk.retainMemories({
|
|
206
|
+
client: this.client,
|
|
207
|
+
path: { bank_id: bankId },
|
|
208
|
+
body: {
|
|
209
|
+
items: itemsWithDocId,
|
|
210
|
+
document_tags: options?.documentTags,
|
|
211
|
+
async: options?.async,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return this.validateResponse(response, 'retainBatch');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Upload files and retain their contents as memories.
|
|
220
|
+
*
|
|
221
|
+
* Files are automatically converted to text (PDF, DOCX, images via OCR, audio via
|
|
222
|
+
* transcription, and more) and ingested as memories. Processing is always asynchronous —
|
|
223
|
+
* use the returned operation IDs to track progress via the operations endpoint.
|
|
224
|
+
*
|
|
225
|
+
* @param bankId - The memory bank ID
|
|
226
|
+
* @param files - Array of File or Blob objects to upload
|
|
227
|
+
* @param options - Optional settings: context, documentTags, filesMetadata
|
|
228
|
+
*/
|
|
229
|
+
async retainFiles(
|
|
230
|
+
bankId: string,
|
|
231
|
+
files: Array<File | Blob>,
|
|
232
|
+
options?: {
|
|
233
|
+
context?: string;
|
|
234
|
+
filesMetadata?: Array<{ context?: string; document_id?: string; tags?: string[]; metadata?: Record<string, string> }>;
|
|
235
|
+
}
|
|
236
|
+
): Promise<FileRetainResponse> {
|
|
237
|
+
const meta = options?.filesMetadata ?? files.map(() => options?.context ? { context: options.context } : {});
|
|
238
|
+
|
|
239
|
+
const requestBody = JSON.stringify({
|
|
240
|
+
files_metadata: meta,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const response = await sdk.fileRetain({
|
|
244
|
+
client: this.client,
|
|
245
|
+
path: { bank_id: bankId },
|
|
246
|
+
body: { files, request: requestBody },
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return this.validateResponse(response, 'retainFiles');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Recall memories with a natural language query.
|
|
254
|
+
*/
|
|
255
|
+
async recall(
|
|
256
|
+
bankId: string,
|
|
257
|
+
query: string,
|
|
258
|
+
options?: {
|
|
259
|
+
types?: string[];
|
|
260
|
+
maxTokens?: number;
|
|
261
|
+
budget?: Budget;
|
|
262
|
+
trace?: boolean;
|
|
263
|
+
queryTimestamp?: string;
|
|
264
|
+
includeEntities?: boolean;
|
|
265
|
+
maxEntityTokens?: number;
|
|
266
|
+
includeChunks?: boolean;
|
|
267
|
+
maxChunkTokens?: number;
|
|
268
|
+
/** Include source facts for observation-type results */
|
|
269
|
+
includeSourceFacts?: boolean;
|
|
270
|
+
/** Maximum tokens for source facts (default: 4096) */
|
|
271
|
+
maxSourceFactsTokens?: number;
|
|
272
|
+
/** Optional list of tags to filter memories by */
|
|
273
|
+
tags?: string[];
|
|
274
|
+
/** How to match tags: 'any' (OR, includes untagged), 'all' (AND, includes untagged), 'any_strict' (OR, excludes untagged), 'all_strict' (AND, excludes untagged). Default: 'any' */
|
|
275
|
+
tagsMatch?: 'any' | 'all' | 'any_strict' | 'all_strict';
|
|
276
|
+
}
|
|
277
|
+
): Promise<RecallResponse> {
|
|
278
|
+
const response = await sdk.recallMemories({
|
|
279
|
+
client: this.client,
|
|
280
|
+
path: { bank_id: bankId },
|
|
281
|
+
body: {
|
|
282
|
+
query,
|
|
283
|
+
types: options?.types,
|
|
284
|
+
max_tokens: options?.maxTokens,
|
|
285
|
+
budget: options?.budget || 'mid',
|
|
286
|
+
trace: options?.trace,
|
|
287
|
+
query_timestamp: options?.queryTimestamp,
|
|
288
|
+
include: {
|
|
289
|
+
entities: options?.includeEntities === false ? null : options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : undefined,
|
|
290
|
+
chunks: options?.includeChunks ? { max_tokens: options?.maxChunkTokens ?? 8192 } : undefined,
|
|
291
|
+
source_facts: options?.includeSourceFacts ? { max_tokens: options?.maxSourceFactsTokens ?? 4096 } : undefined,
|
|
292
|
+
},
|
|
293
|
+
tags: options?.tags,
|
|
294
|
+
tags_match: options?.tagsMatch,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
return this.validateResponse(response, 'recall');
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Reflect and generate a contextual answer using the bank's identity and memories.
|
|
303
|
+
*/
|
|
304
|
+
async reflect(
|
|
305
|
+
bankId: string,
|
|
306
|
+
query: string,
|
|
307
|
+
options?: {
|
|
308
|
+
context?: string;
|
|
309
|
+
budget?: Budget;
|
|
310
|
+
/** Optional list of tags to filter memories by */
|
|
311
|
+
tags?: string[];
|
|
312
|
+
/** How to match tags: 'any' (OR, includes untagged), 'all' (AND, includes untagged), 'any_strict' (OR, excludes untagged), 'all_strict' (AND, excludes untagged). Default: 'any' */
|
|
313
|
+
tagsMatch?: 'any' | 'all' | 'any_strict' | 'all_strict';
|
|
314
|
+
}
|
|
315
|
+
): Promise<ReflectResponse> {
|
|
316
|
+
const response = await sdk.reflect({
|
|
317
|
+
client: this.client,
|
|
318
|
+
path: { bank_id: bankId },
|
|
319
|
+
body: {
|
|
320
|
+
query,
|
|
321
|
+
context: options?.context,
|
|
322
|
+
budget: options?.budget || 'low',
|
|
323
|
+
tags: options?.tags,
|
|
324
|
+
tags_match: options?.tagsMatch,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
return this.validateResponse(response, 'reflect');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* List memories with pagination.
|
|
333
|
+
*/
|
|
334
|
+
async listMemories(
|
|
335
|
+
bankId: string,
|
|
336
|
+
options?: { limit?: number; offset?: number; type?: string; q?: string }
|
|
337
|
+
): Promise<ListMemoryUnitsResponse> {
|
|
338
|
+
const response = await sdk.listMemories({
|
|
339
|
+
client: this.client,
|
|
340
|
+
path: { bank_id: bankId },
|
|
341
|
+
query: {
|
|
342
|
+
limit: options?.limit,
|
|
343
|
+
offset: options?.offset,
|
|
344
|
+
type: options?.type,
|
|
345
|
+
q: options?.q,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
return this.validateResponse(response, 'listMemories');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Create or update a bank with disposition, missions, and operational configuration.
|
|
354
|
+
*/
|
|
355
|
+
async createBank(
|
|
356
|
+
bankId: string,
|
|
357
|
+
options: {
|
|
358
|
+
/** @deprecated Display label only. */
|
|
359
|
+
name?: string;
|
|
360
|
+
/** @deprecated Use reflectMission instead. */
|
|
361
|
+
mission?: string;
|
|
362
|
+
/** Mission/context for Reflect operations. */
|
|
363
|
+
reflectMission?: string;
|
|
364
|
+
/** @deprecated Alias for mission. */
|
|
365
|
+
background?: string;
|
|
366
|
+
/** @deprecated Use dispositionSkepticism, dispositionLiteralism, dispositionEmpathy instead. */
|
|
367
|
+
disposition?: { skepticism: number; literalism: number; empathy: number };
|
|
368
|
+
/** @deprecated Use updateBankConfig({ dispositionSkepticism }) instead. */
|
|
369
|
+
dispositionSkepticism?: number;
|
|
370
|
+
/** @deprecated Use updateBankConfig({ dispositionLiteralism }) instead. */
|
|
371
|
+
dispositionLiteralism?: number;
|
|
372
|
+
/** @deprecated Use updateBankConfig({ dispositionEmpathy }) instead. */
|
|
373
|
+
dispositionEmpathy?: number;
|
|
374
|
+
/** Steers what gets extracted during retain(). Injected alongside built-in rules. */
|
|
375
|
+
retainMission?: string;
|
|
376
|
+
/** Fact extraction mode: 'concise' (default), 'verbose', or 'custom'. */
|
|
377
|
+
retainExtractionMode?: string;
|
|
378
|
+
/** Custom extraction prompt (only active when retainExtractionMode is 'custom'). */
|
|
379
|
+
retainCustomInstructions?: string;
|
|
380
|
+
/** Maximum token size for each content chunk during retain. */
|
|
381
|
+
retainChunkSize?: number;
|
|
382
|
+
/** Toggle automatic observation consolidation after retain(). */
|
|
383
|
+
enableObservations?: boolean;
|
|
384
|
+
/** Controls what gets synthesised into observations. Replaces built-in rules. */
|
|
385
|
+
observationsMission?: string;
|
|
386
|
+
} = {}
|
|
387
|
+
): Promise<BankProfileResponse> {
|
|
388
|
+
const response = await sdk.createOrUpdateBank({
|
|
389
|
+
client: this.client,
|
|
390
|
+
path: { bank_id: bankId },
|
|
391
|
+
body: {
|
|
392
|
+
name: options.name,
|
|
393
|
+
mission: options.mission,
|
|
394
|
+
reflect_mission: options.reflectMission,
|
|
395
|
+
background: options.background,
|
|
396
|
+
disposition: options.disposition,
|
|
397
|
+
disposition_skepticism: options.dispositionSkepticism,
|
|
398
|
+
disposition_literalism: options.dispositionLiteralism,
|
|
399
|
+
disposition_empathy: options.dispositionEmpathy,
|
|
400
|
+
retain_mission: options.retainMission,
|
|
401
|
+
retain_extraction_mode: options.retainExtractionMode,
|
|
402
|
+
retain_custom_instructions: options.retainCustomInstructions,
|
|
403
|
+
retain_chunk_size: options.retainChunkSize,
|
|
404
|
+
enable_observations: options.enableObservations,
|
|
405
|
+
observations_mission: options.observationsMission,
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
return this.validateResponse(response, 'createBank');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Set or update the reflect mission for a memory bank.
|
|
414
|
+
* @deprecated Use createBank({ reflectMission: '...' }) instead.
|
|
415
|
+
*/
|
|
416
|
+
async setMission(bankId: string, mission: string): Promise<BankProfileResponse> {
|
|
417
|
+
return this.createBank(bankId, { reflectMission: mission });
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Get a bank's profile.
|
|
422
|
+
*/
|
|
423
|
+
async getBankProfile(bankId: string): Promise<BankProfileResponse> {
|
|
424
|
+
const response = await sdk.getBankProfile({
|
|
425
|
+
client: this.client,
|
|
426
|
+
path: { bank_id: bankId },
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
return this.validateResponse(response, 'getBankProfile');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Get the resolved configuration for a bank, including any bank-level overrides.
|
|
435
|
+
*
|
|
436
|
+
* Can be disabled on the server by setting `ATULYA_API_ENABLE_BANK_CONFIG_API=false`.
|
|
437
|
+
*/
|
|
438
|
+
async getBankConfig(bankId: string): Promise<BankConfigResponse> {
|
|
439
|
+
const response = await sdk.getBankConfig({
|
|
440
|
+
client: this.client,
|
|
441
|
+
path: { bank_id: bankId },
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
return this.validateResponse(response, 'getBankConfig');
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Update configuration overrides for a bank.
|
|
449
|
+
*
|
|
450
|
+
* Can be disabled on the server by setting `ATULYA_API_ENABLE_BANK_CONFIG_API=false`.
|
|
451
|
+
*
|
|
452
|
+
* @param bankId - The memory bank ID
|
|
453
|
+
* @param options - Fields to override
|
|
454
|
+
*/
|
|
455
|
+
async updateBankConfig(
|
|
456
|
+
bankId: string,
|
|
457
|
+
options: {
|
|
458
|
+
reflectMission?: string;
|
|
459
|
+
retainMission?: string;
|
|
460
|
+
retainExtractionMode?: string;
|
|
461
|
+
retainCustomInstructions?: string;
|
|
462
|
+
retainChunkSize?: number;
|
|
463
|
+
enableObservations?: boolean;
|
|
464
|
+
observationsMission?: string;
|
|
465
|
+
/** How skeptical vs trusting (1=trusting, 5=skeptical). */
|
|
466
|
+
dispositionSkepticism?: number;
|
|
467
|
+
/** How literally to interpret information (1=flexible, 5=literal). */
|
|
468
|
+
dispositionLiteralism?: number;
|
|
469
|
+
/** How much to consider emotional context (1=detached, 5=empathetic). */
|
|
470
|
+
dispositionEmpathy?: number;
|
|
471
|
+
},
|
|
472
|
+
): Promise<BankConfigResponse> {
|
|
473
|
+
const updates: Record<string, unknown> = {};
|
|
474
|
+
if (options.reflectMission !== undefined) updates.reflect_mission = options.reflectMission;
|
|
475
|
+
if (options.retainMission !== undefined) updates.retain_mission = options.retainMission;
|
|
476
|
+
if (options.retainExtractionMode !== undefined) updates.retain_extraction_mode = options.retainExtractionMode;
|
|
477
|
+
if (options.retainCustomInstructions !== undefined)
|
|
478
|
+
updates.retain_custom_instructions = options.retainCustomInstructions;
|
|
479
|
+
if (options.retainChunkSize !== undefined) updates.retain_chunk_size = options.retainChunkSize;
|
|
480
|
+
if (options.enableObservations !== undefined) updates.enable_observations = options.enableObservations;
|
|
481
|
+
if (options.observationsMission !== undefined) updates.observations_mission = options.observationsMission;
|
|
482
|
+
if (options.dispositionSkepticism !== undefined) updates.disposition_skepticism = options.dispositionSkepticism;
|
|
483
|
+
if (options.dispositionLiteralism !== undefined) updates.disposition_literalism = options.dispositionLiteralism;
|
|
484
|
+
if (options.dispositionEmpathy !== undefined) updates.disposition_empathy = options.dispositionEmpathy;
|
|
485
|
+
|
|
486
|
+
const response = await sdk.updateBankConfig({
|
|
487
|
+
client: this.client,
|
|
488
|
+
path: { bank_id: bankId },
|
|
489
|
+
body: { updates },
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
return this.validateResponse(response, 'updateBankConfig');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Reset all bank-level configuration overrides, reverting to server defaults.
|
|
497
|
+
*
|
|
498
|
+
* Can be disabled on the server by setting `ATULYA_API_ENABLE_BANK_CONFIG_API=false`.
|
|
499
|
+
*/
|
|
500
|
+
async resetBankConfig(bankId: string): Promise<BankConfigResponse> {
|
|
501
|
+
const response = await sdk.resetBankConfig({
|
|
502
|
+
client: this.client,
|
|
503
|
+
path: { bank_id: bankId },
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
return this.validateResponse(response, 'resetBankConfig');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Delete a bank.
|
|
511
|
+
*/
|
|
512
|
+
async deleteBank(bankId: string): Promise<void> {
|
|
513
|
+
const response = await sdk.deleteBank({
|
|
514
|
+
client: this.client,
|
|
515
|
+
path: { bank_id: bankId },
|
|
516
|
+
});
|
|
517
|
+
if (response.error) {
|
|
518
|
+
throw new Error(`deleteBank failed: ${JSON.stringify(response.error)}`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Directive methods
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Create a directive (hard rule for reflect).
|
|
526
|
+
*/
|
|
527
|
+
async createDirective(
|
|
528
|
+
bankId: string,
|
|
529
|
+
name: string,
|
|
530
|
+
content: string,
|
|
531
|
+
options?: {
|
|
532
|
+
priority?: number;
|
|
533
|
+
isActive?: boolean;
|
|
534
|
+
tags?: string[];
|
|
535
|
+
}
|
|
536
|
+
): Promise<any> {
|
|
537
|
+
const response = await sdk.createDirective({
|
|
538
|
+
client: this.client,
|
|
539
|
+
path: { bank_id: bankId },
|
|
540
|
+
body: {
|
|
541
|
+
name,
|
|
542
|
+
content,
|
|
543
|
+
priority: options?.priority ?? 0,
|
|
544
|
+
is_active: options?.isActive ?? true,
|
|
545
|
+
tags: options?.tags,
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
return this.validateResponse(response, 'createDirective');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* List all directives in a bank.
|
|
554
|
+
*/
|
|
555
|
+
async listDirectives(bankId: string, options?: { tags?: string[] }): Promise<any> {
|
|
556
|
+
const response = await sdk.listDirectives({
|
|
557
|
+
client: this.client,
|
|
558
|
+
path: { bank_id: bankId },
|
|
559
|
+
query: { tags: options?.tags },
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
return this.validateResponse(response, 'listDirectives');
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Get a specific directive.
|
|
567
|
+
*/
|
|
568
|
+
async getDirective(bankId: string, directiveId: string): Promise<any> {
|
|
569
|
+
const response = await sdk.getDirective({
|
|
570
|
+
client: this.client,
|
|
571
|
+
path: { bank_id: bankId, directive_id: directiveId },
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
return this.validateResponse(response, 'getDirective');
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Update a directive.
|
|
579
|
+
*/
|
|
580
|
+
async updateDirective(
|
|
581
|
+
bankId: string,
|
|
582
|
+
directiveId: string,
|
|
583
|
+
options: {
|
|
584
|
+
name?: string;
|
|
585
|
+
content?: string;
|
|
586
|
+
priority?: number;
|
|
587
|
+
isActive?: boolean;
|
|
588
|
+
tags?: string[];
|
|
589
|
+
}
|
|
590
|
+
): Promise<any> {
|
|
591
|
+
const response = await sdk.updateDirective({
|
|
592
|
+
client: this.client,
|
|
593
|
+
path: { bank_id: bankId, directive_id: directiveId },
|
|
594
|
+
body: {
|
|
595
|
+
name: options.name,
|
|
596
|
+
content: options.content,
|
|
597
|
+
priority: options.priority,
|
|
598
|
+
is_active: options.isActive,
|
|
599
|
+
tags: options.tags,
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
return this.validateResponse(response, 'updateDirective');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Delete a directive.
|
|
608
|
+
*/
|
|
609
|
+
async deleteDirective(bankId: string, directiveId: string): Promise<void> {
|
|
610
|
+
const response = await sdk.deleteDirective({
|
|
611
|
+
client: this.client,
|
|
612
|
+
path: { bank_id: bankId, directive_id: directiveId },
|
|
613
|
+
});
|
|
614
|
+
if (response.error) {
|
|
615
|
+
throw new Error(`deleteDirective failed: ${JSON.stringify(response.error)}`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Mental Model methods
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Create a mental model (runs reflect in background).
|
|
623
|
+
*/
|
|
624
|
+
async createMentalModel(
|
|
625
|
+
bankId: string,
|
|
626
|
+
name: string,
|
|
627
|
+
sourceQuery: string,
|
|
628
|
+
options?: {
|
|
629
|
+
tags?: string[];
|
|
630
|
+
maxTokens?: number;
|
|
631
|
+
trigger?: { refreshAfterConsolidation?: boolean };
|
|
632
|
+
}
|
|
633
|
+
): Promise<any> {
|
|
634
|
+
const response = await sdk.createMentalModel({
|
|
635
|
+
client: this.client,
|
|
636
|
+
path: { bank_id: bankId },
|
|
637
|
+
body: {
|
|
638
|
+
name,
|
|
639
|
+
source_query: sourceQuery,
|
|
640
|
+
tags: options?.tags,
|
|
641
|
+
max_tokens: options?.maxTokens,
|
|
642
|
+
trigger: options?.trigger ? { refresh_after_consolidation: options.trigger.refreshAfterConsolidation } : undefined,
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
return this.validateResponse(response, 'createMentalModel');
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* List all mental models in a bank.
|
|
651
|
+
*/
|
|
652
|
+
async listMentalModels(bankId: string, options?: { tags?: string[] }): Promise<any> {
|
|
653
|
+
const response = await sdk.listMentalModels({
|
|
654
|
+
client: this.client,
|
|
655
|
+
path: { bank_id: bankId },
|
|
656
|
+
query: { tags: options?.tags },
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
return this.validateResponse(response, 'listMentalModels');
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Get a specific mental model.
|
|
664
|
+
*/
|
|
665
|
+
async getMentalModel(bankId: string, mentalModelId: string): Promise<any> {
|
|
666
|
+
const response = await sdk.getMentalModel({
|
|
667
|
+
client: this.client,
|
|
668
|
+
path: { bank_id: bankId, mental_model_id: mentalModelId },
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
return this.validateResponse(response, 'getMentalModel');
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Refresh a mental model to update with current knowledge.
|
|
676
|
+
*/
|
|
677
|
+
async refreshMentalModel(bankId: string, mentalModelId: string): Promise<any> {
|
|
678
|
+
const response = await sdk.refreshMentalModel({
|
|
679
|
+
client: this.client,
|
|
680
|
+
path: { bank_id: bankId, mental_model_id: mentalModelId },
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
return this.validateResponse(response, 'refreshMentalModel');
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Update a mental model's metadata.
|
|
688
|
+
*/
|
|
689
|
+
async updateMentalModel(
|
|
690
|
+
bankId: string,
|
|
691
|
+
mentalModelId: string,
|
|
692
|
+
options: {
|
|
693
|
+
name?: string;
|
|
694
|
+
sourceQuery?: string;
|
|
695
|
+
tags?: string[];
|
|
696
|
+
maxTokens?: number;
|
|
697
|
+
trigger?: { refreshAfterConsolidation?: boolean };
|
|
698
|
+
}
|
|
699
|
+
): Promise<any> {
|
|
700
|
+
const response = await sdk.updateMentalModel({
|
|
701
|
+
client: this.client,
|
|
702
|
+
path: { bank_id: bankId, mental_model_id: mentalModelId },
|
|
703
|
+
body: {
|
|
704
|
+
name: options.name,
|
|
705
|
+
source_query: options.sourceQuery,
|
|
706
|
+
tags: options.tags,
|
|
707
|
+
max_tokens: options.maxTokens,
|
|
708
|
+
trigger: options.trigger ? { refresh_after_consolidation: options.trigger.refreshAfterConsolidation } : undefined,
|
|
709
|
+
},
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
return this.validateResponse(response, 'updateMentalModel');
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Delete a mental model.
|
|
717
|
+
*/
|
|
718
|
+
async deleteMentalModel(bankId: string, mentalModelId: string): Promise<void> {
|
|
719
|
+
const response = await sdk.deleteMentalModel({
|
|
720
|
+
client: this.client,
|
|
721
|
+
path: { bank_id: bankId, mental_model_id: mentalModelId },
|
|
722
|
+
});
|
|
723
|
+
if (response.error) {
|
|
724
|
+
throw new Error(`deleteMentalModel failed: ${JSON.stringify(response.error)}`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Re-export types for convenience
|
|
730
|
+
export type {
|
|
731
|
+
RetainRequest,
|
|
732
|
+
RetainResponse,
|
|
733
|
+
RecallRequest,
|
|
734
|
+
RecallResponse,
|
|
735
|
+
RecallResult,
|
|
736
|
+
ReflectRequest,
|
|
737
|
+
ReflectResponse,
|
|
738
|
+
FileRetainResponse,
|
|
739
|
+
ListMemoryUnitsResponse,
|
|
740
|
+
BankProfileResponse,
|
|
741
|
+
BankConfigResponse,
|
|
742
|
+
CreateBankRequest,
|
|
743
|
+
Budget,
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// Also export low-level SDK functions for advanced usage
|
|
747
|
+
export * as sdk from '../generated/sdk.gen';
|
|
748
|
+
export { createClient, createConfig } from '../generated/client';
|
|
749
|
+
export type { Client } from '../generated/client';
|