@personize/sdk 0.2.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,567 @@
1
+ export type PropertyValue = string | number | boolean | null;
2
+ export interface PersonizeConfig {
3
+ secretKey: string;
4
+ baseURL?: string;
5
+ /** Request timeout in milliseconds (default: 30000) */
6
+ timeout?: number;
7
+ /** Maximum number of retry attempts for 429 and 5xx errors (default: 3) */
8
+ maxRetries?: number;
9
+ /** Base delay in milliseconds for exponential backoff (default: 1000) */
10
+ retryDelay?: number;
11
+ }
12
+ export interface ApiResponse<T = unknown> {
13
+ success: boolean;
14
+ data?: T;
15
+ error?: string;
16
+ message?: string;
17
+ }
18
+ export interface RateLimitError {
19
+ success: false;
20
+ error: 'rate_limit_exceeded';
21
+ message: string;
22
+ limit: number;
23
+ current: number;
24
+ window: 'per_minute' | 'per_month';
25
+ retryAfterSeconds?: number;
26
+ }
27
+ export interface MeResponse {
28
+ organization: {
29
+ id: string;
30
+ };
31
+ user: {
32
+ id: string;
33
+ };
34
+ key: {
35
+ id: string;
36
+ scope: string;
37
+ };
38
+ plan: {
39
+ id: string;
40
+ name: string;
41
+ description: string;
42
+ limits: {
43
+ maxApiCallsPerMonth: number;
44
+ maxApiCallsPerMinute: number;
45
+ };
46
+ features: string[];
47
+ };
48
+ }
49
+ export interface ListOptions {
50
+ /** Page size (default: 25, max: 100). */
51
+ limit?: number;
52
+ /** Cursor returned by the previous page. Pass to fetch the next page. */
53
+ nextToken?: string;
54
+ /** Filter by tags (comma-separated or array). */
55
+ tags?: string | string[];
56
+ /** Exclude items with these tags. */
57
+ excludeTags?: string | string[];
58
+ /** When true, strip the full `value` field for lighter payloads. */
59
+ summary?: boolean;
60
+ }
61
+ export interface VariablesResponse {
62
+ actions: Array<{
63
+ id: string;
64
+ type: string;
65
+ payload: {
66
+ name: string;
67
+ value: string;
68
+ [key: string]: PropertyValue;
69
+ };
70
+ }>;
71
+ count: number;
72
+ /** Cursor for the next page. Undefined when on the last page. */
73
+ nextToken?: string;
74
+ }
75
+ export interface VariableSectionOptions {
76
+ header: string;
77
+ }
78
+ export interface VariableUpdatePayload {
79
+ name?: string;
80
+ value?: string;
81
+ description?: string;
82
+ tags?: string[];
83
+ secure?: boolean;
84
+ updateMode?: 'replace' | 'append' | 'section' | 'appendToSection';
85
+ sectionHeader?: string;
86
+ separator?: string;
87
+ historyNote?: string;
88
+ }
89
+ export interface VariableCreatePayload {
90
+ name: string;
91
+ value?: string;
92
+ description?: string;
93
+ tags?: string[];
94
+ secure?: boolean;
95
+ }
96
+ export interface VariableHistoryEntry {
97
+ id: string;
98
+ originalActionId: string;
99
+ type: string;
100
+ timestamp: string;
101
+ changeType?: 'update' | 'restore' | 'delete';
102
+ modifiedBy?: string;
103
+ modifiedByEmail?: string;
104
+ note?: string;
105
+ versionSource?: 'manual' | 'auto-save' | 'restore';
106
+ payload: {
107
+ name: string;
108
+ value: string;
109
+ [key: string]: PropertyValue;
110
+ };
111
+ }
112
+ export interface VariableHistoryResponse {
113
+ actionId: string;
114
+ history: VariableHistoryEntry[];
115
+ count: number;
116
+ }
117
+ export interface VariableHistoryOptions {
118
+ /** Max number of history records to return (default: 20, max: 50).
119
+ * Each entry includes the full variable content snapshot, so use a small limit (3-5) in token-sensitive contexts. */
120
+ limit?: number;
121
+ }
122
+ export interface CollectionsResponse {
123
+ actions: Array<{
124
+ id: string;
125
+ type: string;
126
+ payload: {
127
+ collectionName: string;
128
+ collectionId: string;
129
+ [key: string]: PropertyValue;
130
+ };
131
+ }>;
132
+ count: number;
133
+ /** Cursor for the next page. Undefined when on the last page. */
134
+ nextToken?: string;
135
+ }
136
+ export interface CollectionCreatePayload {
137
+ collectionName: string;
138
+ collectionId?: string;
139
+ definition?: string;
140
+ entityType?: string;
141
+ properties?: Array<{
142
+ propertyName: string;
143
+ propertyId?: string;
144
+ systemName?: string;
145
+ type?: 'text' | 'date' | 'options' | 'number' | 'boolean' | 'array';
146
+ options?: string;
147
+ description?: string;
148
+ autoSystem?: boolean;
149
+ update?: boolean;
150
+ status?: 'Active' | 'Deleted';
151
+ }>;
152
+ status?: 'Active' | 'Deleted';
153
+ }
154
+ export interface CollectionUpdatePayload {
155
+ collectionName?: string;
156
+ definition?: string;
157
+ entityType?: string;
158
+ properties?: Array<{
159
+ propertyId?: string;
160
+ propertyName?: string;
161
+ systemName?: string;
162
+ type?: 'text' | 'date' | 'options' | 'number' | 'boolean' | 'array';
163
+ options?: string;
164
+ description?: string;
165
+ autoSystem?: boolean;
166
+ update?: boolean;
167
+ status?: 'Active' | 'Deleted';
168
+ }>;
169
+ status?: 'Active' | 'Deleted';
170
+ }
171
+ export interface CollectionHistoryOptions {
172
+ /** Max number of history records to return (default: 20, max: 50). */
173
+ limit?: number;
174
+ /** 'full' returns raw snapshots; 'diff' returns latest snapshot + compact per-version diffs (~80% fewer tokens). Default: 'full'. */
175
+ mode?: 'full' | 'diff';
176
+ }
177
+ export interface CollectionPropertyDiff {
178
+ propertiesAdded: Array<{
179
+ propertyId: string;
180
+ systemName: string;
181
+ propertyName: string;
182
+ }>;
183
+ propertiesRemoved: Array<{
184
+ propertyId: string;
185
+ systemName: string;
186
+ propertyName: string;
187
+ }>;
188
+ propertiesModified: Array<{
189
+ propertyId: string;
190
+ systemName: string;
191
+ fields: Record<string, {
192
+ from: unknown;
193
+ to: unknown;
194
+ }>;
195
+ }>;
196
+ metadataChanges: Record<string, {
197
+ from: unknown;
198
+ to: unknown;
199
+ }>;
200
+ }
201
+ export interface CollectionHistoryResponse {
202
+ actionId: string;
203
+ mode: 'full' | 'diff';
204
+ /** mode=full: raw history snapshots */
205
+ history?: Array<Record<string, unknown>>;
206
+ count?: number;
207
+ /** mode=diff: latest full snapshot */
208
+ current?: Record<string, unknown> | null;
209
+ /** mode=diff: compact per-version diffs (newest first) */
210
+ versions?: Array<{
211
+ timestamp: string;
212
+ historyNote?: string;
213
+ changes: CollectionPropertyDiff;
214
+ }>;
215
+ }
216
+ export interface SmartContextOptions {
217
+ message: string;
218
+ variableIds?: string[];
219
+ tags?: string[];
220
+ excludeTags?: string[];
221
+ model?: string;
222
+ /** Routing mode: "fast" for instant embedding-only (~200ms), "full" for deep LLM routing (~3s), "auto" to let the system decide. Default: "auto". */
223
+ mode?: 'fast' | 'full' | 'auto';
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
+ minScore?: number;
226
+ }
227
+ export interface SmartContextAnalysis {
228
+ taskUnderstanding: string;
229
+ qualityDimensions: string[];
230
+ refinedTask: string;
231
+ }
232
+ export interface SmartContextSelection {
233
+ variableId: string;
234
+ name?: string;
235
+ score?: number;
236
+ reason?: string;
237
+ priority?: string;
238
+ content?: string;
239
+ contentLength?: number;
240
+ mode?: string;
241
+ sections?: string[];
242
+ }
243
+ export interface SmartContextUsage {
244
+ durationMs: number;
245
+ tokensUsed?: number;
246
+ variablesScanned?: number;
247
+ selectedCount?: number;
248
+ preFilter?: {
249
+ total: number;
250
+ passed: number;
251
+ noEmbedding: number;
252
+ durationMs: number;
253
+ };
254
+ }
255
+ export interface SmartContextResponse {
256
+ success: boolean;
257
+ /** Which routing mode was actually used. */
258
+ mode: 'fast' | 'full';
259
+ /** LLM analysis of the task. Null in fast mode. */
260
+ analysis?: SmartContextAnalysis | null;
261
+ selection: SmartContextSelection[];
262
+ supplementary?: SmartContextSelection[];
263
+ compiledContext: string;
264
+ usage: SmartContextUsage;
265
+ }
266
+ /**
267
+ * Per-MCP tool selection override.
268
+ * Use enabledTools for an explicit allowlist, or disabledTools for a denylist.
269
+ */
270
+ export interface McpToolSelection {
271
+ mcpId: string;
272
+ enabledTools?: string[];
273
+ disabledTools?: string[];
274
+ }
275
+ /** Auto-memorize configuration for /prompt. */
276
+ export interface PromptMemorizeConfig {
277
+ /** Contact email identifier. */
278
+ email?: string;
279
+ /** Company website identifier. */
280
+ websiteUrl?: string;
281
+ /** Generic record identifier. */
282
+ recordId?: string;
283
+ /** Entity type. */
284
+ type?: 'Contact' | 'Company' | 'User';
285
+ /**
286
+ * When true, tool results from research tools (search_companies, tavily, etc.)
287
+ * are automatically captured and memorized. Meta tools (smart_context,
288
+ * recall_pro, memorize_pro, store_evaluation_log) are excluded.
289
+ */
290
+ captureToolResults?: boolean;
291
+ }
292
+ /** Server-side evaluation configuration. */
293
+ export type PromptEvaluateConfig = boolean | {
294
+ /** Evaluation criteria: preset name ('sales', 'research', etc.) or custom string. */
295
+ criteria?: string;
296
+ /** When true, server evaluates using gpt-4o-mini instead of relying on LLM tool call. */
297
+ serverSide?: boolean;
298
+ };
299
+ /** Named output to extract from LLM response via <output> XML markers. */
300
+ export interface PromptOutputDefinition {
301
+ /** Unique name for this output (used in <output name="..."> markers). */
302
+ name: string;
303
+ }
304
+ export interface PromptOptions {
305
+ prompt?: string;
306
+ instructions?: Array<string | {
307
+ prompt: string;
308
+ maxSteps?: number;
309
+ }>;
310
+ stream?: boolean;
311
+ model?: string;
312
+ provider?: string;
313
+ context?: string;
314
+ sessionId?: string;
315
+ /**
316
+ * Evaluation configuration.
317
+ * - `true` — server-side auto-evaluation with default criteria
318
+ * - `{ criteria: 'sales', serverSide: true }` — server-side with preset/custom criteria
319
+ */
320
+ evaluate?: PromptEvaluateConfig;
321
+ /**
322
+ * Auto-memorize extracted outputs and/or captured tool results.
323
+ * Requires at least one identifier (email, websiteUrl, or recordId).
324
+ */
325
+ memorize?: PromptMemorizeConfig;
326
+ /**
327
+ * Named outputs to extract from LLM response via `<output name="...">` XML markers.
328
+ * Server-side extraction replaces unreliable LLM tool calls for structured output.
329
+ */
330
+ outputs?: PromptOutputDefinition[];
331
+ metadata?: {
332
+ recordId?: string;
333
+ };
334
+ /** Per-MCP tool selection override (allowlist or denylist per MCP) */
335
+ mcpTools?: McpToolSelection[];
336
+ }
337
+ /** Prompt response when outputs/evaluation are used. */
338
+ export interface PromptResponse {
339
+ success: boolean;
340
+ text: string;
341
+ /** Extracted structured outputs (from <output> markers). */
342
+ outputs?: Record<string, unknown>;
343
+ /** Server-side evaluation result. */
344
+ evaluation?: {
345
+ finalScore: number;
346
+ criteriaScores: Array<{
347
+ name: string;
348
+ score: number;
349
+ maxScore: number;
350
+ reason: string;
351
+ }>;
352
+ explanation: string;
353
+ };
354
+ metadata?: {
355
+ model: string;
356
+ provider: string;
357
+ usage?: {
358
+ promptTokens: number;
359
+ completionTokens: number;
360
+ totalTokens: number;
361
+ };
362
+ toolCalls?: Array<{
363
+ toolName: string;
364
+ }>;
365
+ stepsExecuted?: number;
366
+ instructionsExecuted?: number;
367
+ };
368
+ steps?: Array<{
369
+ instructionIndex: number;
370
+ text: string;
371
+ usage?: {
372
+ promptTokens: number;
373
+ completionTokens: number;
374
+ totalTokens: number;
375
+ };
376
+ toolCalls?: Array<{
377
+ toolName: string;
378
+ }>;
379
+ stepsExecuted: number;
380
+ }>;
381
+ }
382
+ export interface AgentRunOptions {
383
+ inputs?: Record<string, unknown>;
384
+ stream?: boolean;
385
+ email?: string;
386
+ websiteUrl?: string;
387
+ recordId?: string;
388
+ /** Per-MCP tool selection override (allowlist or denylist per MCP) */
389
+ mcpTools?: McpToolSelection[];
390
+ }
391
+ export interface MemorizeProOptions {
392
+ content: string;
393
+ speaker?: string;
394
+ timestamp?: string;
395
+ schema?: Record<string, unknown>;
396
+ actionId?: string;
397
+ record_id?: string;
398
+ email?: string;
399
+ website_url?: string;
400
+ enhanced?: boolean;
401
+ tags?: string[];
402
+ max_properties?: number;
403
+ }
404
+ export interface RecallProOptions {
405
+ query: string;
406
+ limit?: number;
407
+ minScore?: number;
408
+ record_id?: string;
409
+ email?: string;
410
+ website_url?: string;
411
+ type?: string;
412
+ include_property_values?: boolean;
413
+ enable_reflection?: boolean;
414
+ generate_answer?: boolean;
415
+ /**
416
+ * Fast mode: skip reflection loop and answer generation, use minScore 0.3,
417
+ * return all results above the score threshold (no hard limit).
418
+ * Reduces latency from ~10-20s to ~500-700ms.
419
+ */
420
+ fast_mode?: boolean;
421
+ /**
422
+ * Minimum relevance score (0-1). Filters out results below this threshold.
423
+ * In fast_mode, defaults to 0.3 if not specified.
424
+ */
425
+ min_score?: number;
426
+ }
427
+ export interface UpsertOptions {
428
+ /** Entity type (e.g. 'Contact', 'Company') */
429
+ type: string;
430
+ /** Properties to store: { propertyName: { value, collectionId?, collectionName? } } */
431
+ properties: Record<string, {
432
+ value: PropertyValue;
433
+ collectionId?: string;
434
+ collectionName?: string;
435
+ }>;
436
+ /** Match keys for dedup (e.g. { email: 'john@example.com' }) */
437
+ matchKeys?: {
438
+ email?: string;
439
+ websiteUrl?: string;
440
+ };
441
+ /** Source label (e.g. 'CRM Sync') */
442
+ source?: string;
443
+ }
444
+ export interface UpsertBatchOptions {
445
+ /** Entity type */
446
+ type: string;
447
+ /** Array of memory items to upsert */
448
+ memories: Array<{
449
+ memoryName: string;
450
+ result: PropertyValue | Record<string, unknown>;
451
+ collection?: string;
452
+ collectionId?: string;
453
+ }>;
454
+ /** Contact email for record matching */
455
+ email?: string;
456
+ /** Company website for record matching */
457
+ websiteUrl?: string;
458
+ /** Source label */
459
+ source?: string;
460
+ }
461
+ export interface BatchMemorizePropertyMapping {
462
+ /** Source field name in the row data */
463
+ sourceField: string;
464
+ /** Target collection ID */
465
+ collectionId: string;
466
+ /** Target collection name */
467
+ collectionName: string;
468
+ /** If true, AI extraction + vector embeddings are created for this property. Default: false (structured storage only). */
469
+ extractMemories?: boolean;
470
+ }
471
+ export interface BatchMemorizeMapping {
472
+ /** Entity type (e.g. 'contact', 'company') */
473
+ entityType: string;
474
+ /** Source field name that contains the email (e.g. 'email') */
475
+ email?: string;
476
+ /** Source field name that contains the website URL (e.g. 'company_website_url') */
477
+ website?: string;
478
+ /** Run name for tracking (e.g. 'hubspot Sync (contact) - <uuid>') */
479
+ runName?: string;
480
+ /** Property mappings: target property name → mapping config */
481
+ properties: Record<string, BatchMemorizePropertyMapping>;
482
+ }
483
+ export interface BatchMemorizeOptions {
484
+ /** Source system label (e.g. 'Hubspot', 'Salesforce') */
485
+ source: string;
486
+ /** Mapping configuration for the sync */
487
+ mapping: BatchMemorizeMapping;
488
+ /** Array of source data rows (key-value objects matching sourceField names) */
489
+ rows: Record<string, unknown>[];
490
+ /** If true, validate without writing (default: false) */
491
+ dryRun?: boolean;
492
+ /** Number of rows to process per chunk (default: 1) */
493
+ chunkSize?: number;
494
+ }
495
+ export interface SmartDigestOptions {
496
+ /** CRM record ID */
497
+ record_id?: string;
498
+ /** Contact email */
499
+ email?: string;
500
+ /** Company website URL */
501
+ website_url?: string;
502
+ /** Entity type ('Contact', 'Company'). Auto-inferred if omitted. */
503
+ type?: string;
504
+ /** Max tokens for compiled context (default: 1000) */
505
+ token_budget?: number;
506
+ /** Max free-form memories to include (default: 20) */
507
+ max_memories?: number;
508
+ /** Include DynamoDB property snapshot (default: true) */
509
+ include_properties?: boolean;
510
+ /** Include LanceDB free-form memories (default: true) */
511
+ include_memories?: boolean;
512
+ }
513
+ export interface SmartDigestResponse {
514
+ success: boolean;
515
+ recordId?: string;
516
+ type?: string;
517
+ properties: Record<string, string>;
518
+ memories: Array<{
519
+ text: string;
520
+ createdAt?: string;
521
+ }>;
522
+ /** Ready-to-use markdown string for prompt injection */
523
+ compiledContext: string;
524
+ tokenEstimate: number;
525
+ tokenBudget: number;
526
+ }
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
+ }>;
538
+ type?: string;
539
+ email?: string;
540
+ websiteUrl?: string;
541
+ recordId?: string;
542
+ collectionIds?: string[];
543
+ page?: number;
544
+ pageSize?: number;
545
+ countOnly?: boolean;
546
+ returnRecords?: boolean;
547
+ includeMemories?: boolean;
548
+ }
549
+ export interface MemoryItem {
550
+ text: string;
551
+ createdAt?: string;
552
+ score?: number;
553
+ metadata?: Record<string, PropertyValue>;
554
+ }
555
+ export interface ExportResponse {
556
+ recordIds: string[];
557
+ totalMatched: number;
558
+ page: number;
559
+ pageSize: number;
560
+ totalPages: number;
561
+ records?: Record<string, Record<string, {
562
+ value: PropertyValue;
563
+ collectionId: string;
564
+ collectionName?: string;
565
+ }>>;
566
+ memories?: Record<string, MemoryItem[]>;
567
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // --- Utility Types ---
3
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@personize/sdk",
3
+ "version": "0.2.0",
4
+ "description": "Official Personize SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepublishOnly": "npm run build",
15
+ "test": "jest",
16
+ "test:watch": "jest --watch",
17
+ "test:coverage": "jest --coverage"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/hataheri/personize-sdk.git"
22
+ },
23
+ "homepage": "https://personize.ai",
24
+ "bugs": {
25
+ "url": "https://github.com/hataheri/personize-sdk/issues"
26
+ },
27
+ "keywords": [
28
+ "personize",
29
+ "ai",
30
+ "sdk",
31
+ "memory",
32
+ "agents"
33
+ ],
34
+ "author": "Personize",
35
+ "license": "Apache-2.0",
36
+ "devDependencies": {
37
+ "typescript": "^5.0.0",
38
+ "@types/node": "^18.0.0",
39
+ "@types/jest": "^29.5.0",
40
+ "jest": "^29.7.0",
41
+ "ts-jest": "^29.1.0",
42
+ "nock": "^14.0.0"
43
+ },
44
+ "dependencies": {
45
+ "axios": "^1.6.0"
46
+ }
47
+ }