@personize/sdk 0.6.5 → 0.7.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
@@ -109,6 +109,27 @@ const ctx = await client.ai.smartGuidelines({
109
109
  console.log(ctx.data.compiledContext);
110
110
  ```
111
111
 
112
+ #### Content Budget
113
+
114
+ Control how much guideline content is delivered:
115
+
116
+ ```typescript
117
+ const result = await client.ai.smartGuidelines({
118
+ message: "write a cold email",
119
+ maxContentTokens: 5000, // deliver ~2-3 full guidelines, rest as summaries
120
+ });
121
+
122
+ // Demoted guidelines (over budget) returned with id + description for follow-up
123
+ if (result.data.budgetMetadata?.demotedGuidelines) {
124
+ for (const g of result.data.budgetMetadata.demotedGuidelines) {
125
+ // Fetch specific section: client.guidelines.getSection(g.id, { header: "Cold Email" })
126
+ console.log(`${g.name}: ${g.description} — sections: ${g.sections.join(', ')}`);
127
+ }
128
+ }
129
+ ```
130
+
131
+ Default: 10,000 tokens. Guidelines too large for the budget are automatically trimmed to relevant sections. Remaining guidelines are returned as summaries with `id`, `description`, and `sections[]` for follow-up via `client.guidelines.getSection()`.
132
+
112
133
  ### Prompt Execution
113
134
 
114
135
  ```typescript
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PersonizeConfig, ApiResponse, MeResponse, TestResponse, ListOptions, GuidelinesResponse, GuidelineSectionOptions, GuidelineUpdatePayload, GuidelineCreatePayload, GuidelineHistoryResponse, GuidelineHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartGuidelinesOptions, SmartGuidelinesResponse, PromptOptions, PromptResponse, PromptStreamOptions, PromptSSEEvent, AgentRunOptions, AgentResponse, MemorizeOptions, SmartRecallOptions, RecallOptions, RecallResponse, SearchOptions, SearchResponse, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse, EvaluateMemorizationOptions, EvaluateMemorizationResponse, UpdatePropertyOptions, UpdateResult, BulkUpdateOptions, BulkUpdateResult, PropertyHistoryOptions, PropertyHistoryResult, QueryPropertiesOptions, QueryPropertiesResult, DeleteMemoriesOptions, DeleteRecordOptions, DeletionResult, CancelDeletionOptions, CancelDeletionResult, FilterByPropertyOptions, FilterByPropertyResult, GetPropertiesOptions, GetPropertiesResponse } from './types';
1
+ import { PersonizeConfig, ApiResponse, MeResponse, TestResponse, ListOptions, GuidelinesResponse, GuidelineSectionOptions, GuidelineUpdatePayload, GuidelineCreatePayload, GuidelineHistoryResponse, GuidelineHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartGuidelinesOptions, SmartGuidelinesResponse, PromptOptions, PromptResponse, PromptStreamOptions, PromptSSEEvent, AgentRunOptions, AgentResponse, MemorizeOptions, SmartRecallOptions, RecallOptions, RecallResponse, SearchOptions, SearchResponse, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse, EvaluateMemorizationOptions, EvaluateMemorizationResponse, UpdatePropertyOptions, UpdateResult, BulkUpdateOptions, BulkUpdateResult, PropertyHistoryOptions, PropertyHistoryResult, QueryPropertiesOptions, QueryPropertiesResult, DeleteMemoriesOptions, DeleteRecordOptions, DeletionResult, CancelDeletionOptions, CancelDeletionResult, FilterByPropertyOptions, FilterByPropertyResult, GetPropertiesOptions, GetPropertiesResponse, ResponsesCreateOptions, ResponsesCompletedResult, ChatCompletionsOptions, ChatCompletionResult } from './types';
2
2
  export declare class Personize {
3
3
  private client;
4
4
  private _organizationId?;
@@ -237,4 +237,22 @@ export declare class Personize {
237
237
  */
238
238
  memorizationAccuracy: (data: EvaluateMemorizationOptions) => Promise<ApiResponse<EvaluateMemorizationResponse>>;
239
239
  };
240
+ responses: {
241
+ /**
242
+ * POST /api/v1/responses — Execute step-driven orchestration.
243
+ *
244
+ * If tools with execute functions are provided (Record format), the SDK
245
+ * automatically handles the tool execution loop: execute locally, send
246
+ * results back, repeat until completed.
247
+ */
248
+ create: (options: ResponsesCreateOptions) => Promise<ResponsesCompletedResult>;
249
+ };
250
+ chat: {
251
+ completions: {
252
+ /**
253
+ * POST /api/v1/chat/completions — OpenAI-compatible chat completion.
254
+ */
255
+ create: (options: ChatCompletionsOptions) => Promise<ChatCompletionResult>;
256
+ };
257
+ };
240
258
  }
package/dist/client.js CHANGED
@@ -153,7 +153,13 @@ class Personize {
153
153
  * POST /api/v1/ai/smart-guidelines — Smart guidelines routing. Selects relevant organizational guidelines for a task.
154
154
  */
155
155
  smartGuidelines: async (options) => {
156
- const response = await this.client.post('/api/v1/ai/smart-guidelines', options);
156
+ // Normalize snake_case alias camelCase
157
+ const { max_content_tokens, ...rest } = options;
158
+ const normalized = {
159
+ ...rest,
160
+ maxContentTokens: rest.maxContentTokens ?? max_content_tokens,
161
+ };
162
+ const response = await this.client.post('/api/v1/ai/smart-guidelines', normalized);
157
163
  return response.data;
158
164
  },
159
165
  /**
@@ -461,6 +467,84 @@ class Personize {
461
467
  return response.data;
462
468
  },
463
469
  };
470
+ this.responses = {
471
+ /**
472
+ * POST /api/v1/responses — Execute step-driven orchestration.
473
+ *
474
+ * If tools with execute functions are provided (Record format), the SDK
475
+ * automatically handles the tool execution loop: execute locally, send
476
+ * results back, repeat until completed.
477
+ */
478
+ create: async (options) => {
479
+ // Extract execute functions from tools (they don't get sent to server)
480
+ let toolSchemas;
481
+ let executeMap;
482
+ if (options.tools && !Array.isArray(options.tools)) {
483
+ // Record format — extract execute functions
484
+ executeMap = new Map();
485
+ toolSchemas = [];
486
+ for (const [name, def] of Object.entries(options.tools)) {
487
+ executeMap.set(name, def.execute);
488
+ toolSchemas.push({
489
+ type: 'function',
490
+ function: { name, description: def.description, parameters: def.parameters },
491
+ });
492
+ }
493
+ }
494
+ else if (Array.isArray(options.tools)) {
495
+ toolSchemas = options.tools;
496
+ }
497
+ // Build request body (exclude execute functions)
498
+ const body = { ...options, tools: toolSchemas };
499
+ // Tool execution loop
500
+ let maxRounds = 20;
501
+ while (maxRounds-- > 0) {
502
+ const response = await this.client.post('/api/v1/responses', body);
503
+ const result = response.data;
504
+ if (result.status === 'completed') {
505
+ return result;
506
+ }
507
+ // requires_action — execute tools locally
508
+ if (!executeMap || executeMap.size === 0) {
509
+ // No execute functions provided — return as-is (caller handles manually)
510
+ return result;
511
+ }
512
+ const toolResults = [];
513
+ for (const tc of result.required_action.tool_calls) {
514
+ const executeFn = executeMap.get(tc.name);
515
+ if (!executeFn) {
516
+ toolResults.push({ tool_call_id: tc.id, output: JSON.stringify({ error: `No execute function for tool: ${tc.name}` }) });
517
+ continue;
518
+ }
519
+ try {
520
+ const output = await executeFn(tc.args);
521
+ toolResults.push({ tool_call_id: tc.id, output: typeof output === 'string' ? output : JSON.stringify(output) });
522
+ }
523
+ catch (err) {
524
+ toolResults.push({ tool_call_id: tc.id, output: JSON.stringify({ error: err.message }) });
525
+ }
526
+ }
527
+ // Send continuation request
528
+ body.conversation = result.conversation;
529
+ body.conversation_signature = result.conversation_signature;
530
+ body.remaining_steps = result.remaining_steps;
531
+ body.completed_step_count = result.completed_step_count;
532
+ body.tool_results = toolResults;
533
+ }
534
+ throw new Error('Tool execution loop exceeded maximum rounds (20)');
535
+ },
536
+ };
537
+ this.chat = {
538
+ completions: {
539
+ /**
540
+ * POST /api/v1/chat/completions — OpenAI-compatible chat completion.
541
+ */
542
+ create: async (options) => {
543
+ const response = await this.client.post('/api/v1/chat/completions', options);
544
+ return response.data;
545
+ },
546
+ },
547
+ };
464
548
  this.maxRetries = config.maxRetries ?? 3;
465
549
  this.retryDelay = config.retryDelay ?? 1000;
466
550
  this.client = axios_1.default.create({
package/dist/types.d.ts CHANGED
@@ -292,6 +292,10 @@ export interface SmartGuidelinesOptions {
292
292
  minScore?: number;
293
293
  /** Session ID for conversation continuity. */
294
294
  sessionId?: string;
295
+ /** Maximum tokens of guideline content to deliver. The system selects the most relevant guidelines and trims to fit. Default: 10000. */
296
+ maxContentTokens?: number;
297
+ /** @deprecated Use maxContentTokens instead. */
298
+ max_content_tokens?: number;
295
299
  }
296
300
  /** @deprecated Use SmartGuidelinesOptions instead. */
297
301
  export type SmartContextOptions = SmartGuidelinesOptions;
@@ -1367,3 +1371,185 @@ export interface EvaluateMemorizationResponse {
1367
1371
  propertiesAttempted: number;
1368
1372
  };
1369
1373
  }
1374
+ export interface StepDefinition {
1375
+ prompt: string;
1376
+ order?: number;
1377
+ tools?: string[];
1378
+ max_steps?: number;
1379
+ }
1380
+ export interface PersonizeExtensions {
1381
+ governance?: {
1382
+ guideline_ids?: string[];
1383
+ mode?: 'fast' | 'deep';
1384
+ };
1385
+ memory?: {
1386
+ record_id?: string;
1387
+ recall?: boolean;
1388
+ };
1389
+ mcp_integration_ids?: string[];
1390
+ outputs?: Array<{
1391
+ key: string;
1392
+ type: string;
1393
+ }>;
1394
+ memorize?: {
1395
+ record_id?: string;
1396
+ collection?: string;
1397
+ capture_tool_results?: boolean;
1398
+ };
1399
+ }
1400
+ export interface ClientToolDefinition {
1401
+ type: 'function';
1402
+ function: {
1403
+ name: string;
1404
+ description: string;
1405
+ parameters: Record<string, unknown>;
1406
+ };
1407
+ }
1408
+ export interface ResponsesCreateOptions {
1409
+ steps?: StepDefinition[];
1410
+ messages?: Array<{
1411
+ role: string;
1412
+ content: string;
1413
+ }>;
1414
+ tools?: ClientToolDefinition[] | Record<string, {
1415
+ description: string;
1416
+ parameters: Record<string, unknown>;
1417
+ execute: (args: any) => Promise<any>;
1418
+ }>;
1419
+ model?: string;
1420
+ provider?: string;
1421
+ tier?: string;
1422
+ temperature?: number;
1423
+ max_tokens?: number;
1424
+ system_prompt?: string;
1425
+ session_id?: string;
1426
+ llm_api_key?: string;
1427
+ openrouter_api_key?: string;
1428
+ personize?: PersonizeExtensions;
1429
+ attachments?: Array<{
1430
+ name: string;
1431
+ mimeType: string;
1432
+ url?: string;
1433
+ content?: string;
1434
+ }>;
1435
+ conversation?: any[];
1436
+ conversation_signature?: string;
1437
+ remaining_steps?: StepDefinition[];
1438
+ completed_step_count?: number;
1439
+ }
1440
+ export interface ResponsesToolCall {
1441
+ id: string;
1442
+ name: string;
1443
+ args: Record<string, unknown>;
1444
+ }
1445
+ export interface ResponsesStepResult {
1446
+ order: number;
1447
+ text: string;
1448
+ tool_calls: Array<{
1449
+ name: string;
1450
+ args: Record<string, unknown>;
1451
+ result?: unknown;
1452
+ }>;
1453
+ usage: {
1454
+ prompt_tokens: number;
1455
+ completion_tokens: number;
1456
+ };
1457
+ }
1458
+ export interface ResponsesCompletedResult {
1459
+ id: string;
1460
+ status: 'completed';
1461
+ session_id: string;
1462
+ output: Array<{
1463
+ type: string;
1464
+ role: string;
1465
+ content: Array<{
1466
+ type: string;
1467
+ text: string;
1468
+ }>;
1469
+ }>;
1470
+ steps: ResponsesStepResult[];
1471
+ outputs?: Record<string, unknown>;
1472
+ usage: {
1473
+ prompt_tokens: number;
1474
+ completion_tokens: number;
1475
+ total_tokens: number;
1476
+ };
1477
+ metadata: {
1478
+ tier: string;
1479
+ credits_charged: number;
1480
+ byok?: boolean;
1481
+ model?: string;
1482
+ provider?: string;
1483
+ };
1484
+ }
1485
+ export interface ResponsesRequiresActionResult {
1486
+ id: string;
1487
+ status: 'requires_action';
1488
+ session_id: string;
1489
+ required_action: {
1490
+ type: 'tool_calls';
1491
+ tool_calls: ResponsesToolCall[];
1492
+ };
1493
+ conversation: any[];
1494
+ remaining_steps: StepDefinition[];
1495
+ completed_step_count: number;
1496
+ conversation_signature: string;
1497
+ usage: {
1498
+ prompt_tokens: number;
1499
+ completion_tokens: number;
1500
+ total_tokens: number;
1501
+ };
1502
+ }
1503
+ export type ResponsesResult = ResponsesCompletedResult | ResponsesRequiresActionResult;
1504
+ export interface ChatCompletionsOptions {
1505
+ model?: string;
1506
+ provider?: string;
1507
+ tier?: string;
1508
+ messages: Array<{
1509
+ role: 'system' | 'user' | 'assistant' | 'tool';
1510
+ content: string | null;
1511
+ tool_call_id?: string;
1512
+ tool_calls?: any[];
1513
+ }>;
1514
+ tools?: ClientToolDefinition[];
1515
+ tool_choice?: 'auto' | 'none' | 'required';
1516
+ temperature?: number;
1517
+ max_tokens?: number;
1518
+ llm_api_key?: string;
1519
+ openrouter_api_key?: string;
1520
+ personize?: PersonizeExtensions;
1521
+ }
1522
+ export interface ChatCompletionChoice {
1523
+ index: number;
1524
+ message: {
1525
+ role: 'assistant';
1526
+ content: string | null;
1527
+ tool_calls?: Array<{
1528
+ id: string;
1529
+ type: 'function';
1530
+ function: {
1531
+ name: string;
1532
+ arguments: string;
1533
+ };
1534
+ }>;
1535
+ };
1536
+ finish_reason: 'stop' | 'tool_calls' | 'length';
1537
+ }
1538
+ export interface ChatCompletionResult {
1539
+ id: string;
1540
+ object: 'chat.completion';
1541
+ created: number;
1542
+ model: string;
1543
+ choices: ChatCompletionChoice[];
1544
+ usage: {
1545
+ prompt_tokens: number;
1546
+ completion_tokens: number;
1547
+ total_tokens: number;
1548
+ };
1549
+ session_id?: string;
1550
+ metadata?: {
1551
+ tier: string;
1552
+ credits_charged: number;
1553
+ byok?: boolean;
1554
+ };
1555
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@personize/sdk",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Official Personize SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",