@promptbook/wizard 0.110.0 → 0.111.0-1

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.
Files changed (33) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +677 -171
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/utils.index.d.ts +12 -0
  5. package/esm/typings/src/book-2.0/agent-source/BookEditable.d.ts +41 -0
  6. package/esm/typings/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +5 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ImagePromptRenderer.d.ts +21 -0
  8. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
  9. package/esm/typings/src/book-components/Chat/LlmChat/defaults.d.ts +9 -0
  10. package/esm/typings/src/book-components/Chat/hooks/useChatActionsOverlap.d.ts +6 -0
  11. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +7 -1
  12. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +6 -5
  13. package/esm/typings/src/book-components/Chat/save/index.d.ts +3 -3
  14. package/esm/typings/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +11 -0
  15. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +2 -2
  16. package/esm/typings/src/book-components/Chat/utils/parseImagePrompts.d.ts +42 -0
  17. package/esm/typings/src/book-components/Chat/utils/parseImagePrompts.test.d.ts +1 -0
  18. package/esm/typings/src/commitments/MEMORY/MEMORY.d.ts +67 -0
  19. package/esm/typings/src/commitments/MEMORY/MEMORY.test.d.ts +1 -0
  20. package/esm/typings/src/commitments/USE_IMAGE_GENERATOR/USE_IMAGE_GENERATOR.d.ts +3 -12
  21. package/esm/typings/src/commitments/_common/toolRuntimeContext.d.ts +49 -0
  22. package/esm/typings/src/constants/streaming.d.ts +20 -0
  23. package/esm/typings/src/llm-providers/openai/utils/buildToolInvocationScript.d.ts +9 -0
  24. package/esm/typings/src/utils/clientVersion.d.ts +51 -0
  25. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +13 -9
  26. package/esm/typings/src/utils/knowledge/simplifyKnowledgeLabel.d.ts +20 -0
  27. package/esm/typings/src/utils/knowledge/simplifyKnowledgeLabel.test.d.ts +1 -0
  28. package/esm/typings/src/utils/normalization/constructImageFilename.d.ts +18 -0
  29. package/esm/typings/src/utils/normalization/constructImageFilename.test.d.ts +1 -0
  30. package/esm/typings/src/version.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/umd/index.umd.js +677 -171
  33. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -49,7 +49,7 @@
49
49
  * @generated
50
50
  * @see https://github.com/webgptorg/promptbook
51
51
  */
52
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
52
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-1';
53
53
  /**
54
54
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
55
55
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6578,6 +6578,36 @@
6578
6578
  * Note: [💞] Ignore a discrepancy between file name and entity name
6579
6579
  */
6580
6580
 
6581
+ /**
6582
+ * HTTP header used by Promptbook clients to advertise their release version.
6583
+ *
6584
+ * @public exported from `@promptbook/utils`
6585
+ */
6586
+ const CLIENT_VERSION_HEADER = 'x-promptbook-client-version';
6587
+ /**
6588
+ * The latest client (engine) version that the server expects.
6589
+ *
6590
+ * @public exported from `@promptbook/utils`
6591
+ */
6592
+ const CLIENT_LATEST_VERSION = PROMPTBOOK_ENGINE_VERSION;
6593
+ /**
6594
+ * Creates a headers object that includes the client version header.
6595
+ *
6596
+ * @param headers - Optional base headers to clone.
6597
+ * @returns New headers object augmented with `CLIENT_VERSION_HEADER`.
6598
+ *
6599
+ * @public exported from `@promptbook/utils`
6600
+ */
6601
+ function attachClientVersionHeader(headers) {
6602
+ return {
6603
+ ...(headers !== null && headers !== void 0 ? headers : {}),
6604
+ [CLIENT_VERSION_HEADER]: CLIENT_LATEST_VERSION,
6605
+ };
6606
+ }
6607
+ /**
6608
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6609
+ */
6610
+
6581
6611
  /**
6582
6612
  * Detects if the code is running in a Node.js environment
6583
6613
  *
@@ -8686,6 +8716,83 @@
8686
8716
  }));
8687
8717
  }
8688
8718
 
8719
+ /**
8720
+ * Prompt parameter key used to pass hidden runtime context to tool execution.
8721
+ *
8722
+ * @private internal runtime wiring for commitment tools
8723
+ */
8724
+ const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
8725
+ /**
8726
+ * Hidden argument key used to pass runtime context into individual tool calls.
8727
+ *
8728
+ * @private internal runtime wiring for commitment tools
8729
+ */
8730
+ const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
8731
+ /**
8732
+ * Parses unknown runtime context payload into a normalized object.
8733
+ *
8734
+ * @private internal runtime wiring for commitment tools
8735
+ */
8736
+ function parseToolRuntimeContext(rawValue) {
8737
+ if (!rawValue) {
8738
+ return null;
8739
+ }
8740
+ let parsed = rawValue;
8741
+ if (typeof rawValue === 'string') {
8742
+ try {
8743
+ parsed = JSON.parse(rawValue);
8744
+ }
8745
+ catch (_a) {
8746
+ return null;
8747
+ }
8748
+ }
8749
+ if (!parsed || typeof parsed !== 'object') {
8750
+ return null;
8751
+ }
8752
+ return parsed;
8753
+ }
8754
+ /**
8755
+ * Reads runtime context attached to tool call arguments.
8756
+ *
8757
+ * @private internal runtime wiring for commitment tools
8758
+ */
8759
+ function readToolRuntimeContextFromToolArgs(args) {
8760
+ return parseToolRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
8761
+ }
8762
+ /**
8763
+ * Serializes runtime context for prompt parameters.
8764
+ *
8765
+ * @private internal runtime wiring for commitment tools
8766
+ */
8767
+ function serializeToolRuntimeContext(context) {
8768
+ return JSON.stringify(context);
8769
+ }
8770
+ /**
8771
+ * Note: [💞] Ignore a discrepancy between file name and entity name
8772
+ */
8773
+
8774
+ /**
8775
+ * Builds a tool invocation script that injects hidden runtime context into tool args.
8776
+ *
8777
+ * @private utility of OpenAI tool execution wrappers
8778
+ */
8779
+ function buildToolInvocationScript(options) {
8780
+ const { functionName, functionArgsExpression } = options;
8781
+ return `
8782
+ const args = ${functionArgsExpression};
8783
+ const runtimeContextRaw =
8784
+ typeof ${TOOL_RUNTIME_CONTEXT_PARAMETER} === 'undefined'
8785
+ ? undefined
8786
+ : ${TOOL_RUNTIME_CONTEXT_PARAMETER};
8787
+
8788
+ if (runtimeContextRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
8789
+ args.${TOOL_RUNTIME_CONTEXT_ARGUMENT} = runtimeContextRaw;
8790
+ }
8791
+
8792
+ return await ${functionName}(args);
8793
+ `;
8794
+ }
8795
+
8689
8796
  /**
8690
8797
  * Parses an OpenAI error message to identify which parameter is unsupported
8691
8798
  *
@@ -9039,10 +9146,10 @@
9039
9146
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
9040
9147
  functionResponse = await scriptTool.execute({
9041
9148
  scriptLanguage: 'javascript',
9042
- script: `
9043
- const args = ${functionArgs};
9044
- return await ${functionName}(args);
9045
- `,
9149
+ script: buildToolInvocationScript({
9150
+ functionName,
9151
+ functionArgsExpression: functionArgs,
9152
+ }),
9046
9153
  parameters: prompt.parameters,
9047
9154
  });
9048
9155
  }
@@ -10224,28 +10331,14 @@
10224
10331
  }
10225
10332
  }
10226
10333
 
10227
- /**
10228
- * @@@
10229
- *
10230
- * @private thing of inline knowledge
10231
- */
10334
+ /** @private The default base name for inline knowledge files when the content lacks identifying text */
10232
10335
  const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
10233
- /**
10234
- * @@@
10235
- *
10236
- * @private thing of inline knowledge
10237
- */
10336
+ /** @private The default file extension used for inline knowledge uploads */
10238
10337
  const INLINE_KNOWLEDGE_EXTENSION = '.txt';
10239
- /**
10240
- * @@@
10241
- *
10242
- * @private thing of inline knowledge
10243
- */
10338
+ /** @private Prefix that identifies base64 data URLs */
10244
10339
  const DATA_URL_PREFIX = 'data:';
10245
10340
  /**
10246
- * @@@
10247
- *
10248
- * @private thing of inline knowledge
10341
+ * @private Retrieves the first meaningful line from the inline content.
10249
10342
  */
10250
10343
  function getFirstNonEmptyLine(content) {
10251
10344
  const lines = content.split(/\r?\n/);
@@ -10258,9 +10351,7 @@
10258
10351
  return null;
10259
10352
  }
10260
10353
  /**
10261
- * @@@
10262
- *
10263
- * @private thing of inline knowledge
10354
+ * @private Determines the base file name by normalizing the first non-empty line.
10264
10355
  */
10265
10356
  function deriveBaseFilename(content) {
10266
10357
  const firstLine = getFirstNonEmptyLine(content);
@@ -10271,22 +10362,18 @@
10271
10362
  return normalized || INLINE_KNOWLEDGE_BASE_NAME;
10272
10363
  }
10273
10364
  /**
10274
- * Creates a data URL that represents the inline knowledge content as a text file.
10275
- *
10276
- * @private thing of inline knowledge
10365
+ * @private Converts inline knowledge into the internal metadata form used for uploads.
10277
10366
  */
10278
10367
  function createInlineKnowledgeSourceFile(content) {
10279
10368
  const trimmedContent = content.trim();
10280
10369
  const baseName = deriveBaseFilename(trimmedContent);
10281
10370
  const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
10282
10371
  const mimeType = 'text/plain';
10283
- const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
10284
- const encodedFilename = encodeURIComponent(filename);
10285
- const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
10372
+ const buffer = Buffer.from(trimmedContent, 'utf-8');
10286
10373
  return {
10287
10374
  filename,
10288
10375
  mimeType,
10289
- url,
10376
+ buffer,
10290
10377
  };
10291
10378
  }
10292
10379
  /**
@@ -10297,10 +10384,18 @@
10297
10384
  function isDataUrlKnowledgeSource(source) {
10298
10385
  return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
10299
10386
  }
10387
+ /**
10388
+ * @private Converts a stored inline knowledge file into a data URL for backwards compatibility.
10389
+ */
10390
+ function inlineKnowledgeSourceToDataUrl(source) {
10391
+ const base64 = source.buffer.toString('base64');
10392
+ const encodedFilename = encodeURIComponent(source.filename);
10393
+ return `${DATA_URL_PREFIX}${source.mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
10394
+ }
10300
10395
  /**
10301
10396
  * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
10302
10397
  *
10303
- * @private thing of inline knowledge
10398
+ * @private utility of inline knowledge processing
10304
10399
  */
10305
10400
  function parseDataUrlKnowledgeSource(source) {
10306
10401
  if (!isDataUrlKnowledgeSource(source)) {
@@ -11342,10 +11437,10 @@
11342
11437
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
11343
11438
  functionResponse = await scriptTool.execute({
11344
11439
  scriptLanguage: 'javascript',
11345
- script: `
11346
- const args = ${JSON.stringify(functionArgs)};
11347
- return await ${functionName}(args);
11348
- `,
11440
+ script: buildToolInvocationScript({
11441
+ functionName,
11442
+ functionArgsExpression: JSON.stringify(functionArgs),
11443
+ }),
11349
11444
  parameters: prompt.parameters,
11350
11445
  });
11351
11446
  if (this.options.isVerbose) {
@@ -18475,6 +18570,7 @@
18475
18570
  `);
18476
18571
  }
18477
18572
  applyToAgentModelRequirements(requirements, content) {
18573
+ var _a;
18478
18574
  const trimmedContent = content.trim();
18479
18575
  if (!trimmedContent) {
18480
18576
  return requirements;
@@ -18495,9 +18591,13 @@
18495
18591
  }
18496
18592
  else {
18497
18593
  const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
18594
+ const existingInlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || []).slice();
18498
18595
  const updatedRequirements = {
18499
18596
  ...requirements,
18500
- knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
18597
+ _metadata: {
18598
+ ...requirements._metadata,
18599
+ inlineKnowledgeSources: [...existingInlineSources, inlineSource],
18600
+ },
18501
18601
  };
18502
18602
  const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
18503
18603
  return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
@@ -18579,6 +18679,182 @@
18579
18679
  * Note: [💞] Ignore a discrepancy between file name and entity name
18580
18680
  */
18581
18681
 
18682
+ /**
18683
+ * @@@
18684
+ *
18685
+ * @private utility for commitments
18686
+ */
18687
+ function formatOptionalInstructionBlock(label, content) {
18688
+ const trimmedContent = spaceTrim$1.spaceTrim(content);
18689
+ if (!trimmedContent) {
18690
+ return '';
18691
+ }
18692
+ return spaceTrim$1.spaceTrim((block) => `
18693
+ - ${label}:
18694
+ ${block(trimmedContent
18695
+ .split(/\r?\n/)
18696
+ .map((line) => `- ${line}`)
18697
+ .join('\n'))}
18698
+ `);
18699
+ }
18700
+
18701
+ /**
18702
+ * Tool name used to retrieve persisted user memory.
18703
+ *
18704
+ * @private internal MEMORY commitment constant
18705
+ */
18706
+ const RETRIEVE_USER_MEMORY_TOOL_NAME = 'retrieve_user_memory';
18707
+ /**
18708
+ * Tool name used to store persisted user memory.
18709
+ *
18710
+ * @private internal MEMORY commitment constant
18711
+ */
18712
+ const STORE_USER_MEMORY_TOOL_NAME = 'store_user_memory';
18713
+ const UPDATE_USER_MEMORY_TOOL_NAME = 'update_user_memory';
18714
+ const DELETE_USER_MEMORY_TOOL_NAME = 'delete_user_memory';
18715
+ /**
18716
+ * Resolves runtime context from hidden tool arguments.
18717
+ *
18718
+ * @private utility of MEMORY commitment
18719
+ */
18720
+ function resolveMemoryRuntimeContext(args) {
18721
+ const runtimeContext = readToolRuntimeContextFromToolArgs(args);
18722
+ const memoryContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.memory;
18723
+ return {
18724
+ enabled: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.enabled) === true,
18725
+ userId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.userId,
18726
+ username: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.username,
18727
+ agentId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentId,
18728
+ agentName: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentName,
18729
+ isTeamConversation: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isTeamConversation) === true,
18730
+ };
18731
+ }
18732
+ /**
18733
+ * Builds a disabled memory-tool response payload.
18734
+ *
18735
+ * @private utility of MEMORY commitment
18736
+ */
18737
+ function createDisabledMemoryResult(action, message) {
18738
+ if (action === 'retrieve') {
18739
+ return {
18740
+ action,
18741
+ status: 'disabled',
18742
+ memories: [],
18743
+ message,
18744
+ };
18745
+ }
18746
+ if (action === 'store') {
18747
+ return {
18748
+ action,
18749
+ status: 'disabled',
18750
+ message,
18751
+ };
18752
+ }
18753
+ if (action === 'update') {
18754
+ return {
18755
+ action,
18756
+ status: 'disabled',
18757
+ message,
18758
+ };
18759
+ }
18760
+ if (action === 'delete') {
18761
+ return {
18762
+ action,
18763
+ status: 'disabled',
18764
+ message,
18765
+ };
18766
+ }
18767
+ throw new Error(`Unsupported memory tool action: ${action}`);
18768
+ }
18769
+ /**
18770
+ * Gets the runtime adapter and returns a disabled result when unavailable.
18771
+ *
18772
+ * @private utility of MEMORY commitment
18773
+ */
18774
+ function getRuntimeAdapterOrDisabledResult(action, runtimeContext) {
18775
+ if (!runtimeContext.enabled || runtimeContext.isTeamConversation) {
18776
+ return {
18777
+ adapter: null,
18778
+ disabledResult: createDisabledMemoryResult(action, runtimeContext.isTeamConversation
18779
+ ? 'Memory is disabled for TEAM conversations.'
18780
+ : 'Memory is disabled for unauthenticated users.'),
18781
+ };
18782
+ }
18783
+ {
18784
+ return {
18785
+ adapter: null,
18786
+ disabledResult: createDisabledMemoryResult(action, 'Memory runtime is not available in this environment.'),
18787
+ };
18788
+ }
18789
+ }
18790
+ /**
18791
+ * Parses retrieve memory arguments.
18792
+ *
18793
+ * @private utility of MEMORY commitment
18794
+ */
18795
+ function parseRetrieveMemoryArgs(args) {
18796
+ const query = typeof args.query === 'string' ? args.query.trim() : undefined;
18797
+ const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : undefined;
18798
+ return {
18799
+ query: query && query.length > 0 ? query : undefined,
18800
+ limit: limit && limit > 0 ? Math.min(limit, 20) : undefined,
18801
+ };
18802
+ }
18803
+ /**
18804
+ * Parses store memory arguments.
18805
+ *
18806
+ * @private utility of MEMORY commitment
18807
+ */
18808
+ function parseStoreMemoryArgs(args) {
18809
+ const content = typeof args.content === 'string' ? args.content.trim() : '';
18810
+ if (!content) {
18811
+ throw new Error('Memory content is required.');
18812
+ }
18813
+ return {
18814
+ content,
18815
+ isGlobal: args.isGlobal === true,
18816
+ };
18817
+ }
18818
+ /**
18819
+ * Parses a memory identifier argument shared across MEMORY tools.
18820
+ *
18821
+ * @private utility of MEMORY commitment
18822
+ */
18823
+ function parseMemoryIdArg(value) {
18824
+ const memoryId = typeof value === 'string' ? value.trim() : '';
18825
+ if (!memoryId) {
18826
+ throw new Error('Memory id is required.');
18827
+ }
18828
+ return memoryId;
18829
+ }
18830
+ /**
18831
+ * Parses update memory arguments.
18832
+ *
18833
+ * @private utility of MEMORY commitment
18834
+ */
18835
+ function parseUpdateMemoryArgs(args) {
18836
+ const memoryId = parseMemoryIdArg(args.memoryId);
18837
+ const content = typeof args.content === 'string' ? args.content.trim() : '';
18838
+ if (!content) {
18839
+ throw new Error('Memory content is required.');
18840
+ }
18841
+ const isGlobal = typeof args.isGlobal === 'boolean' ? args.isGlobal : undefined;
18842
+ return {
18843
+ memoryId,
18844
+ content,
18845
+ isGlobal,
18846
+ };
18847
+ }
18848
+ /**
18849
+ * Parses delete memory arguments.
18850
+ *
18851
+ * @private utility of MEMORY commitment
18852
+ */
18853
+ function parseDeleteMemoryArgs(args) {
18854
+ return {
18855
+ memoryId: parseMemoryIdArg(args.memoryId),
18856
+ };
18857
+ }
18582
18858
  /**
18583
18859
  * MEMORY commitment definition
18584
18860
  *
@@ -18600,6 +18876,9 @@
18600
18876
  constructor(type = 'MEMORY') {
18601
18877
  super(type);
18602
18878
  }
18879
+ get requiresContent() {
18880
+ return false;
18881
+ }
18603
18882
  /**
18604
18883
  * Short one-line description of MEMORY.
18605
18884
  */
@@ -18619,21 +18898,14 @@
18619
18898
  return spaceTrim$1.spaceTrim(`
18620
18899
  # ${this.type}
18621
18900
 
18622
- Similar to KNOWLEDGE but focuses on remembering past interactions and user preferences. This commitment helps the agent maintain context about the user's history, preferences, and previous conversations.
18901
+ Enables persistent user memory for the current agent. The memory is stored by the runtime and can be retrieved in future conversations.
18623
18902
 
18624
18903
  ## Key aspects
18625
18904
 
18626
- - Both terms work identically and can be used interchangeably.
18627
- - Focuses on user-specific information and interaction history.
18628
- - Helps personalize responses based on past interactions.
18629
- - Maintains continuity across conversations.
18630
-
18631
- ## Differences from KNOWLEDGE
18632
-
18633
- - \`KNOWLEDGE\` is for domain expertise and factual information
18634
- - \`MEMORY\` is for user-specific context and preferences
18635
- - \`MEMORY\` creates more personalized interactions
18636
- - \`MEMORY\` often includes temporal or preference-based information
18905
+ - Both \`MEMORY\` and \`MEMORIES\` work identically.
18906
+ - Stores user-specific details through runtime tools.
18907
+ - Retrieves relevant memories for personalized responses.
18908
+ - Supports optional extra instructions in the commitment content.
18637
18909
 
18638
18910
  ## Examples
18639
18911
 
@@ -18641,10 +18913,7 @@
18641
18913
  Personal Assistant
18642
18914
 
18643
18915
  PERSONA You are a personal productivity assistant
18644
- MEMORY User is a software developer working in JavaScript/React
18645
- MEMORY User prefers morning work sessions and afternoon meetings
18646
- MEMORY Previously helped with project planning for mobile apps
18647
- MEMORY User timezone: UTC-8 (Pacific Time)
18916
+ MEMORY Remember user projects and long-term preferences.
18648
18917
  GOAL Help optimize daily productivity and workflow
18649
18918
  \`\`\`
18650
18919
 
@@ -18652,10 +18921,7 @@
18652
18921
  Learning Companion
18653
18922
 
18654
18923
  PERSONA You are an educational companion for programming students
18655
- MEMORY Student is learning Python as their first programming language
18656
- MEMORY Previous topics covered: variables, loops, functions
18657
- MEMORY Student learns best with practical examples and exercises
18658
- MEMORY Last session: working on list comprehensions
18924
+ MEMORY Remember only the student's learning progress and preferred study style.
18659
18925
  GOAL Provide progressive learning experiences tailored to student's pace
18660
18926
  \`\`\`
18661
18927
 
@@ -18663,23 +18929,245 @@
18663
18929
  Customer Support Agent
18664
18930
 
18665
18931
  PERSONA You are a customer support representative
18666
- MEMORY Customer has premium subscription since 2023
18667
- MEMORY Previous issue: billing question resolved last month
18668
- MEMORY Customer prefers email communication over phone calls
18669
- MEMORY Account shows frequent use of advanced features
18932
+ MEMORY Remember only important support history and communication preferences.
18670
18933
  GOAL Provide personalized support based on customer history
18671
18934
  \`\`\`
18672
18935
  `);
18673
18936
  }
18674
18937
  applyToAgentModelRequirements(requirements, content) {
18675
- const trimmedContent = content.trim();
18676
- if (!trimmedContent) {
18677
- return requirements;
18938
+ const extraInstructions = formatOptionalInstructionBlock('Memory instructions', content);
18939
+ const existingTools = requirements.tools || [];
18940
+ const tools = [...existingTools];
18941
+ if (!tools.some((tool) => tool.name === RETRIEVE_USER_MEMORY_TOOL_NAME)) {
18942
+ tools.push({
18943
+ name: RETRIEVE_USER_MEMORY_TOOL_NAME,
18944
+ description: spaceTrim$1.spaceTrim(`
18945
+ Retrieve previously stored user memories relevant to the current conversation.
18946
+ Use this before responding when user context can improve the answer.
18947
+ `),
18948
+ parameters: {
18949
+ type: 'object',
18950
+ properties: {
18951
+ query: {
18952
+ type: 'string',
18953
+ description: 'Optional query used to filter relevant memories.',
18954
+ },
18955
+ limit: {
18956
+ type: 'integer',
18957
+ description: 'Optional maximum number of memories to return (default 5, max 20).',
18958
+ },
18959
+ },
18960
+ },
18961
+ });
18962
+ }
18963
+ if (!tools.some((tool) => tool.name === STORE_USER_MEMORY_TOOL_NAME)) {
18964
+ tools.push({
18965
+ name: STORE_USER_MEMORY_TOOL_NAME,
18966
+ description: spaceTrim$1.spaceTrim(`
18967
+ Store a durable user memory that should be remembered in future conversations.
18968
+ Store only stable and useful user-specific facts or preferences.
18969
+ `),
18970
+ parameters: {
18971
+ type: 'object',
18972
+ properties: {
18973
+ content: {
18974
+ type: 'string',
18975
+ description: 'Memory text to store.',
18976
+ },
18977
+ isGlobal: {
18978
+ type: 'boolean',
18979
+ description: 'Set true to make this memory global across all user agents.',
18980
+ },
18981
+ },
18982
+ required: ['content'],
18983
+ },
18984
+ });
18985
+ }
18986
+ if (!tools.some((tool) => tool.name === UPDATE_USER_MEMORY_TOOL_NAME)) {
18987
+ tools.push({
18988
+ name: UPDATE_USER_MEMORY_TOOL_NAME,
18989
+ description: spaceTrim$1.spaceTrim(`
18990
+ Update an existing user memory after retrieving it, so the stored fact stays accurate.
18991
+ Always pass the memory id you retrieved along with the new content.
18992
+ `),
18993
+ parameters: {
18994
+ type: 'object',
18995
+ properties: {
18996
+ memoryId: {
18997
+ type: 'string',
18998
+ description: 'Unique identifier of the memory entry to update.',
18999
+ },
19000
+ content: {
19001
+ type: 'string',
19002
+ description: 'Updated memory text.',
19003
+ },
19004
+ isGlobal: {
19005
+ type: 'boolean',
19006
+ description: 'Set true to keep the fact global; omit or false to keep it agent-scoped.',
19007
+ },
19008
+ },
19009
+ required: ['memoryId', 'content'],
19010
+ },
19011
+ });
18678
19012
  }
18679
- // Create memory section for system message
18680
- const memorySection = `Memory: ${trimmedContent}`;
18681
- // Memory information is contextual and should be included in the system message
18682
- return this.appendToSystemMessage(requirements, memorySection, '\n\n');
19013
+ if (!tools.some((tool) => tool.name === DELETE_USER_MEMORY_TOOL_NAME)) {
19014
+ tools.push({
19015
+ name: DELETE_USER_MEMORY_TOOL_NAME,
19016
+ description: spaceTrim$1.spaceTrim(`
19017
+ Delete a user memory that is no longer relevant. Deletions are soft so the record is hidden from future queries.
19018
+ `),
19019
+ parameters: {
19020
+ type: 'object',
19021
+ properties: {
19022
+ memoryId: {
19023
+ type: 'string',
19024
+ description: 'Unique identifier of the memory entry to delete.',
19025
+ },
19026
+ },
19027
+ required: ['memoryId'],
19028
+ },
19029
+ });
19030
+ }
19031
+ return this.appendToSystemMessage({
19032
+ ...requirements,
19033
+ tools,
19034
+ _metadata: {
19035
+ ...requirements._metadata,
19036
+ useMemory: content || true,
19037
+ },
19038
+ }, spaceTrim$1.spaceTrim((block) => `
19039
+ Memory:
19040
+ - Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
19041
+ - You can use persistent user memory tools.
19042
+ - Use "${RETRIEVE_USER_MEMORY_TOOL_NAME}" to load relevant memory before answering.
19043
+ - Use "${STORE_USER_MEMORY_TOOL_NAME}" to save stable user-specific facts that improve future help.
19044
+ - Use "${UPDATE_USER_MEMORY_TOOL_NAME}" to refresh an existing memory when the content changes.
19045
+ - Use "${DELETE_USER_MEMORY_TOOL_NAME}" to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
19046
+ - Store concise memory items and avoid duplicates.
19047
+ - Never claim memory was saved or loaded unless the tool confirms it.
19048
+ ${block(extraInstructions)}
19049
+ `));
19050
+ }
19051
+ /**
19052
+ * Gets human-readable titles for MEMORY tool functions.
19053
+ */
19054
+ getToolTitles() {
19055
+ return {
19056
+ [RETRIEVE_USER_MEMORY_TOOL_NAME]: 'User memory',
19057
+ [STORE_USER_MEMORY_TOOL_NAME]: 'Store user memory',
19058
+ [UPDATE_USER_MEMORY_TOOL_NAME]: 'Update user memory',
19059
+ [DELETE_USER_MEMORY_TOOL_NAME]: 'Delete user memory',
19060
+ };
19061
+ }
19062
+ /**
19063
+ * Gets MEMORY tool function implementations.
19064
+ */
19065
+ getToolFunctions() {
19066
+ return {
19067
+ async [RETRIEVE_USER_MEMORY_TOOL_NAME](args) {
19068
+ const runtimeContext = resolveMemoryRuntimeContext(args);
19069
+ const { adapter, disabledResult } = getRuntimeAdapterOrDisabledResult('retrieve', runtimeContext);
19070
+ if (!adapter || disabledResult) {
19071
+ return JSON.stringify(disabledResult);
19072
+ }
19073
+ const parsedArgs = parseRetrieveMemoryArgs(args);
19074
+ try {
19075
+ const memories = await adapter.retrieveMemories(parsedArgs, runtimeContext);
19076
+ const result = {
19077
+ action: 'retrieve',
19078
+ status: 'ok',
19079
+ query: parsedArgs.query,
19080
+ memories,
19081
+ };
19082
+ return JSON.stringify(result);
19083
+ }
19084
+ catch (error) {
19085
+ const result = {
19086
+ action: 'retrieve',
19087
+ status: 'error',
19088
+ query: parsedArgs.query,
19089
+ memories: [],
19090
+ message: error instanceof Error ? error.message : String(error),
19091
+ };
19092
+ return JSON.stringify(result);
19093
+ }
19094
+ },
19095
+ async [STORE_USER_MEMORY_TOOL_NAME](args) {
19096
+ const runtimeContext = resolveMemoryRuntimeContext(args);
19097
+ const { adapter, disabledResult } = getRuntimeAdapterOrDisabledResult('store', runtimeContext);
19098
+ if (!adapter || disabledResult) {
19099
+ return JSON.stringify(disabledResult);
19100
+ }
19101
+ try {
19102
+ const parsedArgs = parseStoreMemoryArgs(args);
19103
+ const memory = await adapter.storeMemory(parsedArgs, runtimeContext);
19104
+ const result = {
19105
+ action: 'store',
19106
+ status: 'stored',
19107
+ memory,
19108
+ };
19109
+ return JSON.stringify(result);
19110
+ }
19111
+ catch (error) {
19112
+ const result = {
19113
+ action: 'store',
19114
+ status: 'error',
19115
+ message: error instanceof Error ? error.message : String(error),
19116
+ };
19117
+ return JSON.stringify(result);
19118
+ }
19119
+ },
19120
+ async [UPDATE_USER_MEMORY_TOOL_NAME](args) {
19121
+ const runtimeContext = resolveMemoryRuntimeContext(args);
19122
+ const { adapter, disabledResult } = getRuntimeAdapterOrDisabledResult('update', runtimeContext);
19123
+ if (!adapter || disabledResult) {
19124
+ return JSON.stringify(disabledResult);
19125
+ }
19126
+ try {
19127
+ const parsedArgs = parseUpdateMemoryArgs(args);
19128
+ const memory = await adapter.updateMemory(parsedArgs, runtimeContext);
19129
+ const result = {
19130
+ action: 'update',
19131
+ status: 'updated',
19132
+ memory,
19133
+ };
19134
+ return JSON.stringify(result);
19135
+ }
19136
+ catch (error) {
19137
+ const result = {
19138
+ action: 'update',
19139
+ status: 'error',
19140
+ message: error instanceof Error ? error.message : String(error),
19141
+ };
19142
+ return JSON.stringify(result);
19143
+ }
19144
+ },
19145
+ async [DELETE_USER_MEMORY_TOOL_NAME](args) {
19146
+ const runtimeContext = resolveMemoryRuntimeContext(args);
19147
+ const { adapter, disabledResult } = getRuntimeAdapterOrDisabledResult('delete', runtimeContext);
19148
+ if (!adapter || disabledResult) {
19149
+ return JSON.stringify(disabledResult);
19150
+ }
19151
+ try {
19152
+ const parsedArgs = parseDeleteMemoryArgs(args);
19153
+ const deleted = await adapter.deleteMemory(parsedArgs, runtimeContext);
19154
+ const result = {
19155
+ action: 'delete',
19156
+ status: 'deleted',
19157
+ memoryId: deleted.id,
19158
+ };
19159
+ return JSON.stringify(result);
19160
+ }
19161
+ catch (error) {
19162
+ const result = {
19163
+ action: 'delete',
19164
+ status: 'error',
19165
+ message: error instanceof Error ? error.message : String(error),
19166
+ };
19167
+ return JSON.stringify(result);
19168
+ }
19169
+ },
19170
+ };
18683
19171
  }
18684
19172
  }
18685
19173
  /**
@@ -20792,14 +21280,30 @@
20792
21280
  /**
20793
21281
  * Builds a minimal chat prompt for teammate calls.
20794
21282
  */
20795
- function buildTeammatePrompt(request) {
21283
+ function buildTeammatePrompt(request, runtimeContext) {
20796
21284
  return {
20797
21285
  title: 'Teammate consultation',
20798
21286
  modelRequirements: {
20799
21287
  modelVariant: 'CHAT',
20800
21288
  },
20801
21289
  content: request,
20802
- parameters: {},
21290
+ parameters: {
21291
+ [TOOL_RUNTIME_CONTEXT_PARAMETER]: serializeToolRuntimeContext(runtimeContext),
21292
+ },
21293
+ };
21294
+ }
21295
+ /**
21296
+ * Creates teammate runtime context and marks conversation as team-only memory-disabled.
21297
+ */
21298
+ function createTeamConversationRuntimeContext(value) {
21299
+ const runtimeContext = parseToolRuntimeContext(value) || {};
21300
+ return {
21301
+ ...runtimeContext,
21302
+ memory: {
21303
+ ...(runtimeContext.memory || {}),
21304
+ enabled: false,
21305
+ isTeamConversation: true,
21306
+ },
20803
21307
  };
20804
21308
  }
20805
21309
  /**
@@ -20843,7 +21347,7 @@
20843
21347
  let toolCalls;
20844
21348
  try {
20845
21349
  const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url);
20846
- const prompt = buildTeammatePrompt(request);
21350
+ const prompt = buildTeammatePrompt(request, createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]));
20847
21351
  const teammateResult = await remoteAgent.callChatModel(prompt);
20848
21352
  response = teammateResult.content || '';
20849
21353
  toolCalls =
@@ -21393,25 +21897,6 @@
21393
21897
  * Note: [💞] Ignore a discrepancy between file name and entity name
21394
21898
  */
21395
21899
 
21396
- /**
21397
- * @@@
21398
- *
21399
- * @private utility for commitments
21400
- */
21401
- function formatOptionalInstructionBlock(label, content) {
21402
- const trimmedContent = spaceTrim$1.spaceTrim(content);
21403
- if (!trimmedContent) {
21404
- return '';
21405
- }
21406
- return spaceTrim$1.spaceTrim((block) => `
21407
- - ${label}:
21408
- ${block(trimmedContent
21409
- .split(/\r?\n/)
21410
- .map((line) => `- ${line}`)
21411
- .join('\n'))}
21412
- `);
21413
- }
21414
-
21415
21900
  /**
21416
21901
  * Client-side safe wrapper for sending emails.
21417
21902
  *
@@ -21605,8 +22090,8 @@
21605
22090
  /**
21606
22091
  * USE IMAGE GENERATOR commitment definition
21607
22092
  *
21608
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
21609
- * to create images based on text prompts.
22093
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
22094
+ * markdown placeholders for UI-driven image generation.
21610
22095
  *
21611
22096
  * Example usage in agent source:
21612
22097
  *
@@ -21621,11 +22106,14 @@
21621
22106
  constructor(type = 'USE IMAGE GENERATOR') {
21622
22107
  super(type, ['USE IMAGE GENERATION', 'IMAGE GENERATOR', 'IMAGE GENERATION', 'USE IMAGE']);
21623
22108
  }
22109
+ get requiresContent() {
22110
+ return false;
22111
+ }
21624
22112
  /**
21625
22113
  * Short one-line description of USE IMAGE GENERATOR.
21626
22114
  */
21627
22115
  get description() {
21628
- return 'Enable the agent to use an image generation tool for creating images from text prompts.';
22116
+ return 'Enable the agent to output markdown image placeholders that the UI turns into generated images.';
21629
22117
  }
21630
22118
  /**
21631
22119
  * Icon for this commitment.
@@ -21640,21 +22128,21 @@
21640
22128
  return spaceTrim$1.spaceTrim(`
21641
22129
  # USE IMAGE GENERATOR
21642
22130
 
21643
- Enables the agent to use an image generation tool to create images based on text prompts.
22131
+ Enables the agent to output markdown image placeholders that trigger image generation in the user interface.
21644
22132
 
21645
22133
  ## Key aspects
21646
22134
 
21647
22135
  - The content following \`USE IMAGE GENERATOR\` is an arbitrary text that the agent should know (e.g. style instructions or safety guidelines).
21648
- - The actual image generation is handled by the agent runtime using LLM execution tools.
21649
- - Allows the agent to generate visual content based on user requests.
21650
- - Returns the URL of the generated image.
22136
+ - The agent does **not** call an image-generation tool directly.
22137
+ - The agent inserts markdown notation: \`![alt](?image-prompt=...)\`.
22138
+ - The user interface detects the notation and generates the image asynchronously.
21651
22139
 
21652
22140
  ## Examples
21653
22141
 
21654
22142
  \`\`\`book
21655
22143
  Visual Artist
21656
22144
 
21657
- PERSONA You are a creative visual artist who can generate images.
22145
+ PERSONA You are a creative visual artist.
21658
22146
  USE IMAGE GENERATOR
21659
22147
  RULE Always describe the generated image to the user.
21660
22148
  \`\`\`
@@ -21664,80 +22152,28 @@
21664
22152
 
21665
22153
  PERSONA You are an interior designer who helps users visualize their space.
21666
22154
  USE IMAGE GENERATOR Professional interior design renders.
21667
- ACTION Generate a preview of the designed room.
22155
+ ACTION Add one generated image placeholder whenever a user asks for a visual.
21668
22156
  \`\`\`
21669
22157
  `);
21670
22158
  }
21671
22159
  applyToAgentModelRequirements(requirements, content) {
21672
- // Get existing tools array or create new one
21673
- const existingTools = requirements.tools || [];
21674
- // Add 'generate_image' to tools if not already present
21675
- const updatedTools = existingTools.some((tool) => tool.name === 'generate_image')
21676
- ? existingTools
21677
- : [
21678
- ...existingTools,
21679
- {
21680
- name: 'generate_image',
21681
- description: spaceTrim$1.spaceTrim(`
21682
- Generate an image from a text prompt.
21683
- Use this tool when the user asks to create, draw, or generate an image.
21684
- ${!content ? '' : `Style instructions / guidelines: ${content}`}
21685
- `),
21686
- parameters: {
21687
- type: 'object',
21688
- properties: {
21689
- prompt: {
21690
- type: 'string',
21691
- description: 'The detailed description of the image to generate',
21692
- },
21693
- },
21694
- required: ['prompt'],
21695
- },
21696
- },
21697
- ];
21698
- // Return requirements with updated tools and metadata
22160
+ const extraInstructions = formatOptionalInstructionBlock('Image instructions', content);
21699
22161
  return this.appendToSystemMessage({
21700
22162
  ...requirements,
21701
- tools: updatedTools,
21702
22163
  _metadata: {
21703
22164
  ...requirements._metadata,
21704
22165
  useImageGenerator: content || true,
21705
22166
  },
21706
- }, spaceTrim$1.spaceTrim(`
21707
- You have access to an image generator. Use it to create images based on user requests.
21708
- When you generate an image, you will receive a URL of the generated image.
21709
- `));
21710
- }
21711
- /**
21712
- * Gets human-readable titles for tool functions provided by this commitment.
21713
- */
21714
- getToolTitles() {
21715
- return {
21716
- generate_image: 'Generate image',
21717
- };
21718
- }
21719
- /**
21720
- * Gets the `generate_image` tool function implementation.
21721
- */
21722
- getToolFunctions() {
21723
- return {
21724
- async generate_image(args, ...extra) {
21725
- console.log('!!!! [Tool] generate_image called', { args });
21726
- const { prompt } = args;
21727
- if (!prompt) {
21728
- throw new Error('Image prompt is required');
21729
- }
21730
- const { llmTools } = extra[0] || {};
21731
- if (!llmTools || !llmTools.callImageGenerationModel) {
21732
- throw new Error('Image generation is not supported by the current model provider');
21733
- }
21734
- const result = await llmTools.callImageGenerationModel({
21735
- content: prompt,
21736
- modelName: 'dall-e-3', // Defaulting to dall-e-3, but this could be configurable
21737
- });
21738
- return result.content;
21739
- },
21740
- };
22167
+ }, spaceTrim$1.spaceTrim((block) => `
22168
+ Image generation:
22169
+ - You do not generate images directly and you do not call any image tool.
22170
+ - When the user asks for an image, include markdown notation in your message:
22171
+ \`![<alt text>](?image-prompt=<prompt>)\`
22172
+ - Keep \`<alt text>\` short and descriptive.
22173
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
22174
+ - You can include normal explanatory text before and after the notation.
22175
+ ${block(extraInstructions)}
22176
+ `));
21741
22177
  }
21742
22178
  }
21743
22179
  /**
@@ -22938,6 +23374,7 @@
22938
23374
  systemMessage: requirements.systemMessage + '\n\n' + exampleInteractionsContent,
22939
23375
  };
22940
23376
  }
23377
+ requirements = await applyPendingInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
22941
23378
  // Remove comment lines (lines starting with #) from the final system message
22942
23379
  // while preserving the original content with comments in metadata
22943
23380
  const cleanedSystemMessage = removeCommentsFromSystemMessage(requirements.systemMessage);
@@ -22946,6 +23383,54 @@
22946
23383
  systemMessage: cleanedSystemMessage,
22947
23384
  };
22948
23385
  }
23386
+ /**
23387
+ * @private Attempts to upload inline knowledge entries, falling back to legacy data URLs when the upload fails or is not configured.
23388
+ */
23389
+ async function applyPendingInlineKnowledgeSources(requirements, uploader) {
23390
+ var _a;
23391
+ const inlineSources = extractInlineKnowledgeSources(requirements._metadata);
23392
+ if (inlineSources.length === 0) {
23393
+ return requirements;
23394
+ }
23395
+ const knowledgeSources = [...((_a = requirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])];
23396
+ for (const inlineSource of inlineSources) {
23397
+ const url = uploader
23398
+ ? await uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader)
23399
+ : inlineKnowledgeSourceToDataUrl(inlineSource);
23400
+ knowledgeSources.push(url);
23401
+ }
23402
+ return {
23403
+ ...requirements,
23404
+ knowledgeSources,
23405
+ _metadata: stripInlineKnowledgeMetadata(requirements._metadata),
23406
+ };
23407
+ }
23408
+ async function uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader) {
23409
+ try {
23410
+ return await uploader(inlineSource);
23411
+ }
23412
+ catch (error) {
23413
+ console.error('[inline-knowledge] Failed to upload inline source', {
23414
+ filename: inlineSource.filename,
23415
+ error,
23416
+ });
23417
+ return inlineKnowledgeSourceToDataUrl(inlineSource);
23418
+ }
23419
+ }
23420
+ function extractInlineKnowledgeSources(metadata) {
23421
+ if (!metadata) {
23422
+ return [];
23423
+ }
23424
+ const value = metadata.inlineKnowledgeSources;
23425
+ return Array.isArray(value) ? value : [];
23426
+ }
23427
+ function stripInlineKnowledgeMetadata(metadata) {
23428
+ if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, 'inlineKnowledgeSources')) {
23429
+ return metadata;
23430
+ }
23431
+ const { inlineKnowledgeSources: _unusedInlineKnowledgeSources, ...rest } = metadata;
23432
+ return Object.keys(rest).length > 0 ? rest : undefined;
23433
+ }
22949
23434
  /**
22950
23435
  * Mocked security check for imported files
22951
23436
  *
@@ -30110,10 +30595,10 @@
30110
30595
  try {
30111
30596
  return await scriptTool.execute({
30112
30597
  scriptLanguage: 'javascript',
30113
- script: `
30114
- const args = ${JSON.stringify(functionArgs)};
30115
- return await ${functionName}(args);
30116
- `,
30598
+ script: buildToolInvocationScript({
30599
+ functionName,
30600
+ functionArgsExpression: JSON.stringify(functionArgs),
30601
+ }),
30117
30602
  parameters: (_c = (_b = runContext === null || runContext === void 0 ? void 0 : runContext.context) === null || _b === void 0 ? void 0 : _b.parameters) !== null && _c !== void 0 ? _c : {},
30118
30603
  });
30119
30604
  }
@@ -31144,6 +31629,20 @@
31144
31629
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
31145
31630
  */
31146
31631
 
31632
+ /**
31633
+ * Keep-alive helpers used for streaming chat responses.
31634
+ *
31635
+ * These constants coordinate the signal sent by the Agents Server streaming
31636
+ * endpoint and the parser in the SDK so we can distinguish between
31637
+ * real content and occasional pings.
31638
+ *
31639
+ * @private internal streaming helper for Promptbook chat connections
31640
+ */
31641
+ const CHAT_STREAM_KEEP_ALIVE_TOKEN = 'STREAM_KEEP_ALIVE';
31642
+ /**
31643
+ * Note: [💞] Ignore a discrepancy between file name and entity name
31644
+ */
31645
+
31147
31646
  /**
31148
31647
  * Resolve a remote META IMAGE value into an absolute URL when possible.
31149
31648
  */
@@ -31218,7 +31717,9 @@
31218
31717
  static async connect(options) {
31219
31718
  var _a, _b, _c;
31220
31719
  const agentProfileUrl = `${options.agentUrl}/api/profile`;
31221
- const profileResponse = await fetch(agentProfileUrl);
31720
+ const profileResponse = await fetch(agentProfileUrl, {
31721
+ headers: attachClientVersionHeader(),
31722
+ });
31222
31723
  // <- TODO: [🐱‍🚀] What about closed-source agents?
31223
31724
  // <- TODO: [🐱‍🚀] Maybe use promptbookFetch
31224
31725
  if (!profileResponse.ok) {
@@ -31319,6 +31820,7 @@
31319
31820
  }
31320
31821
  const response = await fetch(`${this.agentUrl}/api/voice`, {
31321
31822
  method: 'POST',
31823
+ headers: attachClientVersionHeader(),
31322
31824
  body: formData,
31323
31825
  });
31324
31826
  if (!response.ok) {
@@ -31348,13 +31850,14 @@
31348
31850
  const chatPrompt = prompt;
31349
31851
  const bookResponse = await fetch(`${this.agentUrl}/api/chat`, {
31350
31852
  method: 'POST',
31351
- headers: {
31853
+ headers: attachClientVersionHeader({
31352
31854
  'Content-Type': 'application/json',
31353
- },
31855
+ }),
31354
31856
  body: JSON.stringify({
31355
31857
  message: prompt.content,
31356
31858
  thread: chatPrompt.thread,
31357
31859
  attachments: chatPrompt.attachments,
31860
+ parameters: chatPrompt.parameters,
31358
31861
  }),
31359
31862
  });
31360
31863
  // <- TODO: [🐱‍🚀] What about closed-source agents?
@@ -31436,6 +31939,9 @@
31436
31939
  const lines = textChunk.split(/\r?\n/);
31437
31940
  for (const line of lines) {
31438
31941
  const trimmedLine = line.trim();
31942
+ if (trimmedLine === CHAT_STREAM_KEEP_ALIVE_TOKEN) {
31943
+ continue;
31944
+ }
31439
31945
  let isToolCallLine = false;
31440
31946
  if (trimmedLine.startsWith('{') && trimmedLine.endsWith('}')) {
31441
31947
  try {