@personize/sdk 0.2.0 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Personize SDK
2
2
 
3
- The official Node.js/TypeScript SDK for the Personize Product API. Authenticate with your secret key to access variables, smart context, RAG memory, prompt execution, and agents.
3
+ The official Node.js/TypeScript SDK for the Personize Product API. Authenticate with your secret key to access variables, smart context, RAG memory, prompt execution, agents, and evaluation tools.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,11 @@ const client = new Personize({
18
18
  // baseURL: 'http://localhost:3000' // Optional: for local development
19
19
  });
20
20
 
21
- // Verify auth and read plan limits
21
+ // Verify API key
22
+ const testResult = await client.test();
23
+ console.log(testResult.data.organizationId);
24
+
25
+ // Read plan limits
22
26
  const me = await client.me();
23
27
  console.log(me.data.plan.name);
24
28
  console.log(me.data.plan.limits);
@@ -28,25 +32,41 @@ console.log(me.data.plan.limits);
28
32
 
29
33
  | Method | Path | SDK Method |
30
34
  | :--- | :--- | :--- |
35
+ | **Identity** | | |
36
+ | GET | `/api/v1/test` | `client.test()` |
31
37
  | GET | `/api/v1/me` | `client.me()` |
38
+ | **AI** | | |
39
+ | POST | `/api/v1/ai/smart-context` | `client.ai.smartContext(opts)` |
40
+ | POST | `/api/v1/prompt` | `client.ai.prompt(opts)` |
41
+ | **Memory** | | |
42
+ | POST | `/api/v1/memorize` | `client.memory.memorize(opts)` |
43
+ | POST | `/api/v1/smart-recall` | `client.memory.smartRecall(opts)` |
44
+ | POST | `/api/v1/recall` | `client.memory.recall(opts)` |
45
+ | POST | `/api/v1/search` | `client.memory.search(opts)` |
46
+ | POST | `/api/v1/upsert` | `client.memory.upsert(opts)` |
47
+ | POST | `/api/v1/upsert` | `client.memory.upsertBatch(opts)` |
48
+ | POST | `/api/v1/batch-memorize` | `client.memory.memorizeBatch(opts)` |
49
+ | POST | `/api/v1/smart-memory-digest` | `client.memory.smartDigest(opts)` |
50
+ | **Variables** | | |
32
51
  | GET | `/api/v1/variables` | `client.variables.list()` |
52
+ | POST | `/api/v1/variables` | `client.variables.create(payload)` |
33
53
  | GET | `/api/v1/variables/:id/structure` | `client.variables.getStructure(id)` |
34
54
  | GET | `/api/v1/variables/:id/section` | `client.variables.getSection(id, opts)` |
35
55
  | PATCH | `/api/v1/variables/:id` | `client.variables.update(id, payload)` |
36
- | POST | `/api/v1/variables` | `client.variables.create(payload)` |
37
56
  | DELETE | `/api/v1/variables/:id` | `client.variables.delete(id)` |
57
+ | GET | `/api/v1/actions/:id/history` | `client.variables.history(id)` |
58
+ | **Collections** | | |
38
59
  | GET | `/api/v1/collections` | `client.collections.list()` |
39
- | POST | `/api/v1/ai/smart-context` | `client.ai.smartContext(opts)` |
40
- | POST | `/api/v1/prompt` | `client.ai.prompt(opts)` |
60
+ | POST | `/api/v1/collections` | `client.collections.create(payload)` |
61
+ | PATCH | `/api/v1/collections/:id` | `client.collections.update(id, payload)` |
62
+ | DELETE | `/api/v1/collections/:id` | `client.collections.delete(id)` |
63
+ | GET | `/api/v1/collections/:id/history` | `client.collections.history(id)` |
64
+ | **Agents** | | |
41
65
  | GET | `/api/v1/agents` | `client.agents.list()` |
66
+ | GET | `/api/v1/agents/:id` | `client.agents.get(id)` |
42
67
  | POST | `/api/v1/agents/:id/run` | `client.agents.run(id, opts)` |
43
- | POST | `/api/v1/memorize_pro` | `client.memory.memorize(opts)` |
44
- | POST | `/api/v1/batch-memorize` | `client.memory.memorizeBatch(opts)` |
45
- | POST | `/api/v1/recall_pro` | `client.memory.recall(opts)` |
46
- | POST | `/api/v1/export` | `client.memory.export(opts)` |
47
- | POST | `/api/v1/smart-memory-digest` | `client.memory.smartDigest(opts)` |
48
- | POST | `/api/v1/upsert` | `client.memory.upsert(opts)` |
49
- | POST | `/api/v1/upsert` | `client.memory.upsertBatch(opts)` |
68
+ | **Evaluation** | | |
69
+ | POST | `/api/v1/evaluate/memorization-accuracy` | `client.evaluate.memorizationAccuracy(opts)` |
50
70
 
51
71
  All endpoints require `Authorization: Bearer sk_live_...` and count against your plan limits.
52
72
 
@@ -72,6 +92,9 @@ const section = await client.variables.getSection(variableId, { header: '## Pric
72
92
 
73
93
  // Delete a variable
74
94
  await client.variables.delete(variableId);
95
+
96
+ // Version history
97
+ const history = await client.variables.history(variableId, { limit: 5 });
75
98
  ```
76
99
 
77
100
  ### Smart Context
@@ -81,6 +104,7 @@ const ctx = await client.ai.smartContext({
81
104
  message: 'Write a sales sequence for our top 3 ICPs',
82
105
  tags: ['sales'],
83
106
  excludeTags: ['internal'],
107
+ sessionId: 'my-session', // for incremental context delivery
84
108
  });
85
109
  console.log(ctx.data.compiledContext);
86
110
  ```
@@ -102,6 +126,23 @@ const result = await client.ai.prompt({
102
126
  evaluate: { criteria: 'sales', serverSide: true },
103
127
  });
104
128
 
129
+ // Multimodal — image analysis
130
+ const analysis = await client.ai.prompt({
131
+ prompt: 'Describe what you see in this screenshot.',
132
+ attachments: [
133
+ { name: 'dashboard.png', mimeType: 'image/png', data: base64EncodedImage },
134
+ ],
135
+ model: 'anthropic/claude-sonnet-4-20250514',
136
+ });
137
+
138
+ // Multimodal — PDF extraction via URL
139
+ const extraction = await client.ai.prompt({
140
+ prompt: 'Extract the key terms from this contract.',
141
+ attachments: [
142
+ { name: 'contract.pdf', mimeType: 'application/pdf', url: 'https://your-bucket.s3.amazonaws.com/contract.pdf' },
143
+ ],
144
+ });
145
+
105
146
  // Output extraction + auto-memorize
106
147
  const research = await client.ai.prompt({
107
148
  instructions: [
@@ -128,7 +169,7 @@ console.log(research.data?.evaluation?.finalScore);
128
169
  ### Memory (RAG)
129
170
 
130
171
  ```typescript
131
- // Memorize content
172
+ // Memorize content (dual extraction: structured + free-form)
132
173
  await client.memory.memorize({
133
174
  content: 'Meeting notes: John prefers email contact.',
134
175
  speaker: 'Sales Rep',
@@ -137,19 +178,32 @@ await client.memory.memorize({
137
178
  email: 'john@example.com',
138
179
  });
139
180
 
140
- // Recall memories
141
- const results = await client.memory.recall({
181
+ // Smart recall — advanced recall with reflection
182
+ const results = await client.memory.smartRecall({
142
183
  query: 'What does John prefer?',
143
184
  limit: 5,
144
185
  minScore: 0.7,
186
+ enable_reflection: true,
187
+ generate_answer: true,
145
188
  });
146
189
 
147
- // Export/filter records
148
- const exported = await client.memory.export({
190
+ // Fast recall — low-latency mode (~500ms)
191
+ const fast = await client.memory.smartRecall({
192
+ query: 'contact info for John',
193
+ email: 'john@example.com',
194
+ fast_mode: true,
195
+ });
196
+
197
+ // Direct recall — simple memory lookup (no reflection)
198
+ const direct = await client.memory.recall({
199
+ query: 'What do we know about Acme?',
200
+ email: 'john@acme.com',
201
+ });
202
+
203
+ // Search/filter records by property conditions
204
+ const found = await client.memory.search({
149
205
  groups: [{
150
- id: 'g1',
151
- logic: 'AND',
152
- conditions: [{ field: 'Company', operator: 'EQ', value: 'Acme Corp' }],
206
+ conditions: [{ property: 'company-name', operator: 'equals', value: 'Acme Corp' }],
153
207
  }],
154
208
  returnRecords: true,
155
209
  pageSize: 50,
@@ -180,7 +234,7 @@ const digest = await client.memory.smartDigest({
180
234
  });
181
235
  console.log(digest.data?.compiledContext); // ready-to-use markdown for LLM prompts
182
236
 
183
- // Structured upsert — legacy, no AI extraction
237
+ // Structured upsert — no AI extraction
184
238
  await client.memory.upsert({
185
239
  type: 'Contact',
186
240
  properties: {
@@ -195,10 +249,16 @@ await client.memory.upsert({
195
249
  ### Agents
196
250
 
197
251
  ```typescript
252
+ // List agents
198
253
  const agents = await client.agents.list();
199
254
 
255
+ // Get agent details and expected inputs
256
+ const agent = await client.agents.get(agentId);
257
+ console.log(agent.data.expectedInputs); // ['companyName', 'industry']
258
+
259
+ // Run an agent
200
260
  const result = await client.agents.run(agentId, {
201
- inputs: { userMessage: 'Help with onboarding' },
261
+ inputs: { companyName: 'Acme Corp', industry: 'SaaS' },
202
262
  email: 'customer@example.com',
203
263
  });
204
264
  ```
@@ -206,7 +266,40 @@ const result = await client.agents.run(agentId, {
206
266
  ### Collections
207
267
 
208
268
  ```typescript
269
+ // List collections
209
270
  const collections = await client.collections.list();
271
+
272
+ // Create a collection
273
+ await client.collections.create({
274
+ collectionName: 'Deal Properties',
275
+ entityType: 'Contact',
276
+ properties: [
277
+ { propertyName: 'Deal Stage', type: 'options', options: 'Discovery,Proposal,Closed' },
278
+ ],
279
+ });
280
+
281
+ // Update a collection
282
+ await client.collections.update(collectionId, {
283
+ properties: [{ propertyName: 'Budget', type: 'number', description: 'Estimated budget' }],
284
+ });
285
+
286
+ // Delete a collection
287
+ await client.collections.delete(collectionId);
288
+
289
+ // Version history (full snapshots or compact diffs)
290
+ const history = await client.collections.history(collectionId, { mode: 'diff', limit: 10 });
291
+ ```
292
+
293
+ ### Evaluation
294
+
295
+ ```typescript
296
+ // Run memorization accuracy evaluation against a collection
297
+ const evaluation = await client.evaluate.memorizationAccuracy({
298
+ collectionId: 'col_123',
299
+ input: 'John Smith is VP of Sales at Acme Corp, based in NYC.',
300
+ skipStorage: true,
301
+ });
302
+ console.log(evaluation.data.summary.propertiesOptimized);
210
303
  ```
211
304
 
212
305
  ## Configuration
@@ -215,6 +308,9 @@ const collections = await client.collections.list();
215
308
  | :--- | :--- | :--- | :--- |
216
309
  | `secretKey` | string | Yes | Your secret key (`sk_live_...`). |
217
310
  | `baseURL` | string | No | Custom API endpoint (default: `https://api.personize.ai`). |
311
+ | `timeout` | number | No | Request timeout in ms (default: `30000`). |
312
+ | `maxRetries` | number | No | Max retry attempts for 429/5xx errors (default: `3`). |
313
+ | `retryDelay` | number | No | Base delay in ms for exponential backoff (default: `1000`). |
218
314
 
219
315
  ## Test Key (Local Development)
220
316
 
@@ -225,6 +321,29 @@ const client = new Personize({
225
321
  });
226
322
  ```
227
323
 
324
+ ## Migration from 0.3.x
325
+
326
+ **Breaking changes in 0.4.0:**
327
+
328
+ | 0.3.x | 0.4.0 | Notes |
329
+ | :--- | :--- | :--- |
330
+ | `client.memory.recall(opts)` | `client.memory.smartRecall(opts)` | Advanced recall with reflection (route changed to `/smart-recall`) |
331
+ | `client.memory.export(opts)` | `client.memory.search(opts)` | Filter/search records (route changed to `/search`) |
332
+ | `MemorizeProOptions` | `MemorizeOptions` | Type renamed (old name still available as deprecated alias) |
333
+ | `RecallProOptions` | `SmartRecallOptions` | Type renamed (old name still available as deprecated alias) |
334
+ | `ExportOptions` / `ExportResponse` | `SearchOptions` / `SearchResponse` | Types renamed (old names still available as deprecated aliases) |
335
+
336
+ **New in 0.4.0:**
337
+ - `client.test()` — Verify API key validity
338
+ - `client.agents.get(id)` — Get agent details and expected inputs
339
+ - `client.memory.recall(opts)` — Direct memory lookup (no reflection, low latency)
340
+ - `client.memory.search(opts)` — Search/filter records with `property`-based conditions
341
+ - `client.evaluate.memorizationAccuracy(opts)` — Three-phase memorization evaluation
342
+ - `attachments` on `PromptOptions` — Multimodal support (images, PDFs, documents)
343
+ - `sessionId` on `SmartContextOptions` — Progressive context delivery across multi-step workflows
344
+ - New fields on `MemorizeOptions`: `collectionIds`, `skipStorage`, `skipDualWrite`, `skipPropertySelection`
345
+ - New fields on `SmartRecallOptions`: `max_reflection_rounds`, `filters`
346
+
228
347
  ## Skills
229
348
 
230
349
  The SDK ships with AI-assistant skills in `skills/` that teach Claude Code, Codex, and Cursor how to use the SDK for common workflows.
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PersonizeConfig, ApiResponse, MeResponse, ListOptions, VariablesResponse, VariableSectionOptions, VariableUpdatePayload, VariableCreatePayload, VariableHistoryResponse, VariableHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartContextOptions, SmartContextResponse, PromptOptions, PromptResponse, AgentRunOptions, MemorizeProOptions, RecallProOptions, ExportOptions, ExportResponse, UpsertOptions, UpsertBatchOptions, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse } from './types';
1
+ import { PersonizeConfig, ApiResponse, MeResponse, TestResponse, ListOptions, VariablesResponse, VariableSectionOptions, VariableUpdatePayload, VariableCreatePayload, VariableHistoryResponse, VariableHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartContextOptions, SmartContextResponse, PromptOptions, PromptResponse, AgentRunOptions, AgentResponse, MemorizeOptions, SmartRecallOptions, RecallOptions, SearchOptions, SearchResponse, UpsertOptions, UpsertBatchOptions, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse, EvaluateMemorizationOptions, EvaluateMemorizationResponse } from './types';
2
2
  export declare class Personize {
3
3
  private client;
4
4
  private _organizationId?;
@@ -8,6 +8,10 @@ export declare class Personize {
8
8
  constructor(config: PersonizeConfig);
9
9
  private resolveIdentity;
10
10
  private getOrganizationId;
11
+ /**
12
+ * GET /api/v1/test — Verify API key is valid. Returns request metadata and resolved identity.
13
+ */
14
+ test(): Promise<ApiResponse<TestResponse>>;
11
15
  /**
12
16
  * GET /api/v1/me — Current context (org, user, plan)
13
17
  */
@@ -88,6 +92,10 @@ export declare class Personize {
88
92
  * Pass `limit` and `nextToken` for cursor-based pagination.
89
93
  */
90
94
  list: (options?: ListOptions) => Promise<ApiResponse>;
95
+ /**
96
+ * GET /api/v1/agents/:id — Get agent details and expected inputs.
97
+ */
98
+ get: (id: string) => Promise<ApiResponse<AgentResponse>>;
91
99
  /**
92
100
  * POST /api/v1/agents/:id/run — Run an agent
93
101
  */
@@ -95,17 +103,24 @@ export declare class Personize {
95
103
  };
96
104
  memory: {
97
105
  /**
98
- * POST /api/v1/memorize_pro — Advanced memorization (RAG)
106
+ * POST /api/v1/memorize — Advanced memorization with dual extraction (RAG).
107
+ * Performs structured property extraction and free-form memory creation.
99
108
  */
100
- memorize: (data: MemorizeProOptions) => Promise<ApiResponse>;
109
+ memorize: (data: MemorizeOptions) => Promise<ApiResponse>;
101
110
  /**
102
- * POST /api/v1/recall_pro — Advanced recall with reflection (RAG)
111
+ * POST /api/v1/smart-recall — Advanced recall with reflection (RAG).
112
+ * Supports reflection loops for improved coverage, answer generation, and entity scoping.
103
113
  */
104
- recall: (data: RecallProOptions) => Promise<ApiResponse>;
114
+ smartRecall: (data: SmartRecallOptions) => Promise<ApiResponse>;
105
115
  /**
106
- * POST /api/v1/exportFilter and export records
116
+ * POST /api/v1/recallDirect memory lookup (no reflection).
107
117
  */
108
- export: (data: ExportOptions) => Promise<ApiResponse<ExportResponse>>;
118
+ recall: (data: RecallOptions) => Promise<ApiResponse>;
119
+ /**
120
+ * POST /api/v1/search — Filter and search records by property conditions.
121
+ * Returns matching record IDs with optional property values and memories.
122
+ */
123
+ search: (data: SearchOptions) => Promise<ApiResponse<SearchResponse>>;
109
124
  /**
110
125
  * POST /api/v1/upsert — Structured upsert (no AI extraction)
111
126
  */
@@ -126,4 +141,11 @@ export declare class Personize {
126
141
  */
127
142
  smartDigest: (data: SmartDigestOptions) => Promise<ApiResponse<SmartDigestResponse>>;
128
143
  };
144
+ evaluate: {
145
+ /**
146
+ * POST /api/v1/evaluate/memorization-accuracy — Run memorization accuracy evaluation.
147
+ * Three-phase evaluation: extraction → analysis → schema optimization.
148
+ */
149
+ memorizationAccuracy: (data: EvaluateMemorizationOptions) => Promise<ApiResponse<EvaluateMemorizationResponse>>;
150
+ };
129
151
  }
package/dist/client.js CHANGED
@@ -180,6 +180,13 @@ class Personize {
180
180
  const response = await this.client.get('/api/v1/agents', { params });
181
181
  return response.data;
182
182
  },
183
+ /**
184
+ * GET /api/v1/agents/:id — Get agent details and expected inputs.
185
+ */
186
+ get: async (id) => {
187
+ const response = await this.client.get(`/api/v1/agents/${id}`);
188
+ return response.data;
189
+ },
183
190
  /**
184
191
  * POST /api/v1/agents/:id/run — Run an agent
185
192
  */
@@ -190,24 +197,34 @@ class Personize {
190
197
  };
191
198
  this.memory = {
192
199
  /**
193
- * POST /api/v1/memorize_pro — Advanced memorization (RAG)
200
+ * POST /api/v1/memorize — Advanced memorization with dual extraction (RAG).
201
+ * Performs structured property extraction and free-form memory creation.
194
202
  */
195
203
  memorize: async (data) => {
196
- const response = await this.client.post('/api/v1/memorize_pro', data);
204
+ const response = await this.client.post('/api/v1/memorize', data);
197
205
  return response.data;
198
206
  },
199
207
  /**
200
- * POST /api/v1/recall_pro — Advanced recall with reflection (RAG)
208
+ * POST /api/v1/smart-recall — Advanced recall with reflection (RAG).
209
+ * Supports reflection loops for improved coverage, answer generation, and entity scoping.
210
+ */
211
+ smartRecall: async (data) => {
212
+ const response = await this.client.post('/api/v1/smart-recall', data);
213
+ return response.data;
214
+ },
215
+ /**
216
+ * POST /api/v1/recall — Direct memory lookup (no reflection).
201
217
  */
202
218
  recall: async (data) => {
203
- const response = await this.client.post('/api/v1/recall_pro', data);
219
+ const response = await this.client.post('/api/v1/recall', data);
204
220
  return response.data;
205
221
  },
206
222
  /**
207
- * POST /api/v1/export — Filter and export records
223
+ * POST /api/v1/search — Filter and search records by property conditions.
224
+ * Returns matching record IDs with optional property values and memories.
208
225
  */
209
- export: async (data) => {
210
- const response = await this.client.post('/api/v1/export', data);
226
+ search: async (data) => {
227
+ const response = await this.client.post('/api/v1/search', data);
211
228
  return response.data;
212
229
  },
213
230
  /**
@@ -255,6 +272,16 @@ class Personize {
255
272
  return response.data;
256
273
  },
257
274
  };
275
+ this.evaluate = {
276
+ /**
277
+ * POST /api/v1/evaluate/memorization-accuracy — Run memorization accuracy evaluation.
278
+ * Three-phase evaluation: extraction → analysis → schema optimization.
279
+ */
280
+ memorizationAccuracy: async (data) => {
281
+ const response = await this.client.post('/api/v1/evaluate/memorization-accuracy', data);
282
+ return response.data;
283
+ },
284
+ };
258
285
  this.maxRetries = config.maxRetries ?? 3;
259
286
  this.retryDelay = config.retryDelay ?? 1000;
260
287
  this.client = axios_1.default.create({
@@ -307,6 +334,13 @@ class Personize {
307
334
  const { organizationId } = await this.resolveIdentity();
308
335
  return organizationId;
309
336
  }
337
+ /**
338
+ * GET /api/v1/test — Verify API key is valid. Returns request metadata and resolved identity.
339
+ */
340
+ async test() {
341
+ const response = await this.client.get('/api/v1/test');
342
+ return response.data;
343
+ }
310
344
  /**
311
345
  * GET /api/v1/me — Current context (org, user, plan)
312
346
  */
package/dist/types.d.ts CHANGED
@@ -223,6 +223,8 @@ export interface SmartContextOptions {
223
223
  mode?: 'fast' | 'full' | 'auto';
224
224
  /** Minimum cosine similarity score (0-1) for fast mode results. Lower values return more results. Default: 0.4 for supplementary, 0.7 for critical. */
225
225
  minScore?: number;
226
+ /** Session ID for conversation continuity. */
227
+ sessionId?: string;
226
228
  }
227
229
  export interface SmartContextAnalysis {
228
230
  taskUnderstanding: string;
@@ -301,6 +303,17 @@ export interface PromptOutputDefinition {
301
303
  /** Unique name for this output (used in <output name="..."> markers). */
302
304
  name: string;
303
305
  }
306
+ /** Multimodal attachment for prompt requests (images, PDFs, documents). */
307
+ export interface PromptAttachment {
308
+ /** Filename (e.g. 'screenshot.png'). Max 255 chars. */
309
+ name?: string;
310
+ /** MIME type. Supported: image/png, image/jpeg, image/gif, image/webp, image/svg+xml, application/pdf, text/plain, text/csv, text/html, text/markdown, application/json. */
311
+ mimeType: string;
312
+ /** Base64-encoded content. Required if url is not provided. */
313
+ data?: string;
314
+ /** Public URL to the content. Required if data is not provided. */
315
+ url?: string;
316
+ }
304
317
  export interface PromptOptions {
305
318
  prompt?: string;
306
319
  instructions?: Array<string | {
@@ -312,6 +325,12 @@ export interface PromptOptions {
312
325
  provider?: string;
313
326
  context?: string;
314
327
  sessionId?: string;
328
+ /**
329
+ * Multimodal attachments (images, PDFs, documents).
330
+ * Max 10 attachments, 20 MB per attachment, 50 MB total.
331
+ * In multi-step mode, attachments are sent with the first instruction only.
332
+ */
333
+ attachments?: PromptAttachment[];
315
334
  /**
316
335
  * Evaluation configuration.
317
336
  * - `true` — server-side auto-evaluation with default criteria
@@ -359,14 +378,27 @@ export interface PromptResponse {
359
378
  completionTokens: number;
360
379
  totalTokens: number;
361
380
  };
381
+ /** Tool calls made during execution (name + args). */
362
382
  toolCalls?: Array<{
363
383
  toolName: string;
384
+ args?: Record<string, unknown>;
364
385
  }>;
386
+ /** Tool call return values (name + result). Always present regardless of captureToolResults. */
387
+ toolResults?: Array<{
388
+ toolName: string;
389
+ result: unknown;
390
+ }>;
391
+ /** Number of AI SDK steps (simple mode). */
365
392
  stepsExecuted?: number;
393
+ /** Number of instruction steps executed (multi-step mode). */
366
394
  instructionsExecuted?: number;
367
395
  };
396
+ /** Per-step breakdown (multi-step mode only). */
368
397
  steps?: Array<{
369
398
  instructionIndex: number;
399
+ /** Instruction prompt that was executed. */
400
+ prompt: string;
401
+ /** Raw response text for this step (may include <output> markers). */
370
402
  text: string;
371
403
  usage?: {
372
404
  promptTokens: number;
@@ -375,10 +407,34 @@ export interface PromptResponse {
375
407
  };
376
408
  toolCalls?: Array<{
377
409
  toolName: string;
410
+ args?: Record<string, unknown>;
378
411
  }>;
379
412
  stepsExecuted: number;
380
413
  }>;
381
414
  }
415
+ export interface TestResponse {
416
+ timestamp: string;
417
+ ip: string;
418
+ userAgent: string;
419
+ userId: string;
420
+ organizationId: string;
421
+ }
422
+ export interface AgentInstructionStep {
423
+ prompt: string;
424
+ order: number;
425
+ }
426
+ export interface AgentResponse {
427
+ id: string;
428
+ type: string;
429
+ payload: {
430
+ name: string;
431
+ instructions: AgentInstructionStep[];
432
+ actions: Array<Record<string, unknown>>;
433
+ aiConfig?: Record<string, unknown>;
434
+ };
435
+ /** Variable names extracted from {{placeholder}} tokens in the agent's instructions. */
436
+ expectedInputs: string[];
437
+ }
382
438
  export interface AgentRunOptions {
383
439
  inputs?: Record<string, unknown>;
384
440
  stream?: boolean;
@@ -388,29 +444,62 @@ export interface AgentRunOptions {
388
444
  /** Per-MCP tool selection override (allowlist or denylist per MCP) */
389
445
  mcpTools?: McpToolSelection[];
390
446
  }
391
- export interface MemorizeProOptions {
447
+ export interface MemorizeOptions {
448
+ /** Content to memorize. */
392
449
  content: string;
450
+ /** Speaker/source label. */
393
451
  speaker?: string;
452
+ /** Timestamp of the content. */
394
453
  timestamp?: string;
454
+ /** Schema hint for extraction. */
395
455
  schema?: Record<string, unknown>;
456
+ /** Action ID for linking. */
396
457
  actionId?: string;
458
+ /** CRM record ID for entity scoping. */
397
459
  record_id?: string;
460
+ /** Email for CRM linking. */
398
461
  email?: string;
462
+ /** Website URL for CRM linking. */
399
463
  website_url?: string;
464
+ /** Enable enhanced dual extraction (structured + free-form). */
400
465
  enhanced?: boolean;
466
+ /** Tags for property selection. */
401
467
  tags?: string[];
468
+ /** Limit extraction to specific collections. */
469
+ collectionIds?: string[];
470
+ /** Max properties to select for extraction. */
402
471
  max_properties?: number;
403
- }
404
- export interface RecallProOptions {
472
+ /** If true, extract without persisting (dry run). */
473
+ skipStorage?: boolean;
474
+ /** If true, skip the secondary write path. */
475
+ skipDualWrite?: boolean;
476
+ /** If true, skip property selection step. */
477
+ skipPropertySelection?: boolean;
478
+ }
479
+ /** @deprecated Use MemorizeOptions instead. */
480
+ export type MemorizeProOptions = MemorizeOptions;
481
+ export interface SmartRecallOptions {
482
+ /** Natural-language query. */
405
483
  query: string;
484
+ /** Max results to return (default: 10). */
406
485
  limit?: number;
486
+ /** Minimum similarity score threshold. */
407
487
  minScore?: number;
488
+ /** CRM record ID for entity scoping. */
408
489
  record_id?: string;
490
+ /** Filter results to a specific entity by email. */
409
491
  email?: string;
492
+ /** Website URL for entity scoping. */
410
493
  website_url?: string;
494
+ /** Entity type filter (e.g. 'Contact', 'Company'). */
411
495
  type?: string;
496
+ /** Return schema-enforced property values separately from free-form memories. */
412
497
  include_property_values?: boolean;
498
+ /** Enable reflection loop to improve recall coverage (default: true). */
413
499
  enable_reflection?: boolean;
500
+ /** Maximum reflection iterations (default: 2). Only used when enable_reflection is true. */
501
+ max_reflection_rounds?: number;
502
+ /** Generate a synthesized answer from recalled memories. */
414
503
  generate_answer?: boolean;
415
504
  /**
416
505
  * Fast mode: skip reflection loop and answer generation, use minScore 0.3,
@@ -423,6 +512,22 @@ export interface RecallProOptions {
423
512
  * In fast_mode, defaults to 0.3 if not specified.
424
513
  */
425
514
  min_score?: number;
515
+ /** Metadata filters for narrowing results. */
516
+ filters?: Record<string, unknown>;
517
+ }
518
+ /** @deprecated Use SmartRecallOptions instead. */
519
+ export type RecallProOptions = SmartRecallOptions;
520
+ export interface RecallOptions {
521
+ /** Natural-language query. */
522
+ query: string;
523
+ /** CRM record ID for entity scoping. */
524
+ record_id?: string;
525
+ /** Filter results to a specific entity by email. */
526
+ email?: string;
527
+ /** Website URL for entity scoping. */
528
+ website_url?: string;
529
+ /** Additional filters. */
530
+ filters?: Record<string, unknown>;
426
531
  }
427
532
  export interface UpsertOptions {
428
533
  /** Entity type (e.g. 'Contact', 'Company') */
@@ -524,44 +629,130 @@ export interface SmartDigestResponse {
524
629
  tokenEstimate: number;
525
630
  tokenBudget: number;
526
631
  }
527
- export interface ExportOptions {
528
- groups?: Array<{
529
- id: string;
530
- logic: 'AND' | 'OR';
531
- conditions: Array<{
532
- field: string;
533
- operator: string;
534
- value?: PropertyValue;
535
- collectionId?: string;
536
- }>;
537
- }>;
632
+ export interface SearchFilterCondition {
633
+ /** Property system name to filter on. */
634
+ property: string;
635
+ /** Comparison operator (e.g. 'equals', 'contains', 'gt', 'lt'). */
636
+ operator: string;
637
+ /** Value to compare against. */
638
+ value?: PropertyValue;
639
+ /** Scope to a specific collection. */
640
+ collectionId?: string;
641
+ }
642
+ export interface SearchFilterGroup {
643
+ /** Filter conditions within this group. */
644
+ conditions: SearchFilterCondition[];
645
+ }
646
+ export interface SearchOptions {
647
+ /** Filter groups with conditions. To list all records, send one group with empty conditions. */
648
+ groups?: SearchFilterGroup[];
649
+ /** Entity type (e.g. 'Contact', 'Company'). */
538
650
  type?: string;
651
+ /** Scope to a specific entity by email. */
539
652
  email?: string;
653
+ /** Scope to a specific entity by website URL. */
540
654
  websiteUrl?: string;
655
+ /** Scope to a specific record ID. */
541
656
  recordId?: string;
657
+ /** Scope to specific collections. */
542
658
  collectionIds?: string[];
659
+ /** Page number (1-based, default: 1). */
543
660
  page?: number;
661
+ /** Results per page (max 200, default: 50). */
544
662
  pageSize?: number;
663
+ /** Return only totalMatched count. */
545
664
  countOnly?: boolean;
665
+ /** Include property values per record. */
546
666
  returnRecords?: boolean;
667
+ /** Include free-form memories. */
547
668
  includeMemories?: boolean;
669
+ /** Data source: 'lancedb' or 'snapshot' (default: 'lancedb'). */
670
+ dataSource?: 'lancedb' | 'snapshot';
548
671
  }
672
+ /** @deprecated Use SearchOptions instead. */
673
+ export type ExportOptions = SearchOptions;
549
674
  export interface MemoryItem {
550
675
  text: string;
551
676
  createdAt?: string;
552
677
  score?: number;
553
678
  metadata?: Record<string, PropertyValue>;
554
679
  }
555
- export interface ExportResponse {
680
+ export interface SearchResponse {
556
681
  recordIds: string[];
557
682
  totalMatched: number;
558
683
  page: number;
559
684
  pageSize: number;
560
685
  totalPages: number;
686
+ /** Property values per record (when returnRecords is true). */
561
687
  records?: Record<string, Record<string, {
562
688
  value: PropertyValue;
563
689
  collectionId: string;
564
690
  collectionName?: string;
565
691
  }>>;
692
+ /** Main property summary per record. */
693
+ mainProperties?: Record<string, Record<string, string>>;
694
+ /** Free-form memories per record (when includeMemories is true). */
566
695
  memories?: Record<string, MemoryItem[]>;
567
696
  }
697
+ /** @deprecated Use SearchResponse instead. */
698
+ export type ExportResponse = SearchResponse;
699
+ export interface EvaluateMemorizationOptions {
700
+ /** Collection to evaluate against. */
701
+ collectionId: string;
702
+ /** Text to extract from. */
703
+ input: string;
704
+ /** Model for extraction phase. */
705
+ extractionModel?: string;
706
+ /** Model for analysis phase. */
707
+ analysisModel?: string;
708
+ /** Model for schema optimization phase. */
709
+ optimizerModel?: string;
710
+ /** If true, don't persist extracted values. Default: true. */
711
+ skipStorage?: boolean;
712
+ /** Stream response as SSE events. Default: false. */
713
+ stream?: boolean;
714
+ /** Include free-form memories in extraction. Default: false. */
715
+ includeFreeformMemories?: boolean;
716
+ /** CRM scope for entity context. */
717
+ crmKeys?: {
718
+ recordId?: string;
719
+ email?: string;
720
+ websiteUrl?: string;
721
+ };
722
+ }
723
+ export interface EvaluateMemorizationResponse {
724
+ success: boolean;
725
+ phases: Array<{
726
+ phase: string;
727
+ model?: string;
728
+ duration?: number;
729
+ collectionName?: string;
730
+ totalProperties?: number;
731
+ extraction?: {
732
+ propertyValues: Array<{
733
+ propertyId: string;
734
+ propertyName: string;
735
+ value: unknown;
736
+ type: string;
737
+ confidence: number;
738
+ }>;
739
+ duration: number;
740
+ };
741
+ metrics?: Record<string, unknown>;
742
+ optimizedCollection?: {
743
+ properties: Array<{
744
+ propertyId: string;
745
+ propertyName: string;
746
+ description?: string;
747
+ type: string;
748
+ wasModified: boolean;
749
+ changeReason?: string;
750
+ }>;
751
+ };
752
+ }>;
753
+ summary: {
754
+ totalDuration: number;
755
+ propertiesOptimized: number;
756
+ propertiesAttempted: number;
757
+ };
758
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@personize/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official Personize SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",