@promptbook/node 0.110.0-8 → 0.110.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.
Files changed (39) hide show
  1. package/README.md +0 -4
  2. package/esm/index.es.js +487 -97
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +6 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +22 -21
  8. package/esm/typings/src/book-2.0/agent-source/AgentReferenceResolver.d.ts +18 -0
  9. package/esm/typings/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +12 -0
  10. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +8 -2
  11. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.agentReferenceResolver.test.d.ts +1 -0
  12. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.d.ts +4 -5
  13. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +42 -0
  14. package/esm/typings/src/book-components/Chat/Chat/ChatActionsBar.d.ts +0 -2
  15. package/esm/typings/src/book-components/Chat/Chat/ChatInputArea.d.ts +1 -0
  16. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  17. package/esm/typings/src/book-components/Chat/Chat/ChatMessageList.d.ts +1 -0
  18. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +26 -0
  19. package/esm/typings/src/book-components/Chat/Chat/ChatSoundToggle.d.ts +31 -0
  20. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +6 -0
  21. package/esm/typings/src/book-components/Chat/hooks/useChatRatings.d.ts +24 -2
  22. package/esm/typings/src/book-components/Chat/utils/getToolCallChipletInfo.d.ts +2 -10
  23. package/esm/typings/src/book-components/Chat/utils/parseCitationMarker.d.ts +75 -0
  24. package/esm/typings/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +3 -1
  25. package/esm/typings/src/book-components/Chat/utils/parseCitationsFromContent.test.d.ts +1 -0
  26. package/esm/typings/src/book-components/icons/ArrowIcon.d.ts +17 -4
  27. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +9 -0
  28. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.test.d.ts +1 -0
  29. package/esm/typings/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +39 -0
  30. package/esm/typings/src/types/LlmToolDefinition.d.ts +1 -0
  31. package/esm/typings/src/types/ModelRequirements.d.ts +9 -0
  32. package/esm/typings/src/utils/DEFAULT_THINKING_MESSAGES.d.ts +8 -0
  33. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +38 -0
  34. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.test.d.ts +1 -0
  35. package/esm/typings/src/utils/language/getBrowserPreferredSpeechRecognitionLanguage.d.ts +35 -0
  36. package/esm/typings/src/version.d.ts +1 -1
  37. package/package.json +2 -2
  38. package/umd/index.umd.js +487 -97
  39. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
35
35
  * @generated
36
36
  * @see https://github.com/webgptorg/promptbook
37
37
  */
38
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-8';
38
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
39
39
  /**
40
40
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
41
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -13710,6 +13710,28 @@ class BaseCommitmentDefinition {
13710
13710
  return currentMessage + separator + content;
13711
13711
  });
13712
13712
  }
13713
+ /**
13714
+ * Helper method to create a new requirements object with updated prompt suffix
13715
+ */
13716
+ updatePromptSuffix(requirements, contentUpdate) {
13717
+ const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
13718
+ return {
13719
+ ...requirements,
13720
+ promptSuffix: newSuffix,
13721
+ };
13722
+ }
13723
+ /**
13724
+ * Helper method to append content to the prompt suffix
13725
+ * Default separator is a single newline for bullet lists.
13726
+ */
13727
+ appendToPromptSuffix(requirements, content, separator = '\n') {
13728
+ return this.updatePromptSuffix(requirements, (currentSuffix) => {
13729
+ if (!currentSuffix.trim()) {
13730
+ return content;
13731
+ }
13732
+ return `${currentSuffix}${separator}${content}`;
13733
+ });
13734
+ }
13713
13735
  /**
13714
13736
  * Helper method to add a comment section to the system message
13715
13737
  * Comments are lines starting with # that will be removed from the final system message
@@ -13887,13 +13909,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
13887
13909
  `);
13888
13910
  }
13889
13911
  applyToAgentModelRequirements(requirements, _content) {
13890
- const updatedMetadata = {
13891
- ...requirements.metadata,
13892
- isClosed: true,
13893
- };
13894
13912
  return {
13895
13913
  ...requirements,
13896
- metadata: updatedMetadata,
13914
+ isClosed: true,
13897
13915
  };
13898
13916
  }
13899
13917
  }
@@ -14171,12 +14189,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
14171
14189
  return requirements;
14172
14190
  }
14173
14191
  // Get existing dictionary entries from metadata
14174
- const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
14192
+ const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
14175
14193
  // Merge the new dictionary entry with existing entries
14176
14194
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
14177
14195
  // Store the merged dictionary in metadata for debugging and inspection
14178
14196
  const updatedMetadata = {
14179
- ...requirements.metadata,
14197
+ ...requirements._metadata,
14180
14198
  DICTIONARY: mergedDictionary,
14181
14199
  };
14182
14200
  // Create the dictionary section for the system message
@@ -14184,7 +14202,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
14184
14202
  const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
14185
14203
  return {
14186
14204
  ...this.appendToSystemMessage(requirements, dictionarySection),
14187
- metadata: updatedMetadata,
14205
+ _metadata: updatedMetadata,
14188
14206
  };
14189
14207
  }
14190
14208
  }
@@ -14324,10 +14342,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
14324
14342
  applyToAgentModelRequirements(requirements, content) {
14325
14343
  const trimmedContent = content.trim();
14326
14344
  if (!trimmedContent) {
14327
- return {
14328
- ...requirements,
14329
- parentAgentUrl: undefined,
14330
- };
14345
+ return requirements;
14331
14346
  }
14332
14347
  if (trimmedContent.toUpperCase() === 'VOID' ||
14333
14348
  trimmedContent.toUpperCase() === 'NULL' ||
@@ -14541,6 +14556,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
14541
14556
  * Note: [💞] Ignore a discrepancy between file name and entity name
14542
14557
  */
14543
14558
 
14559
+ /**
14560
+ * @@@
14561
+ *
14562
+ * @private thing of inline knowledge
14563
+ */
14564
+ const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
14565
+ /**
14566
+ * @@@
14567
+ *
14568
+ * @private thing of inline knowledge
14569
+ */
14570
+ const INLINE_KNOWLEDGE_EXTENSION = '.txt';
14571
+ /**
14572
+ * @@@
14573
+ *
14574
+ * @private thing of inline knowledge
14575
+ */
14576
+ const DATA_URL_PREFIX = 'data:';
14577
+ /**
14578
+ * @@@
14579
+ *
14580
+ * @private thing of inline knowledge
14581
+ */
14582
+ function getFirstNonEmptyLine(content) {
14583
+ const lines = content.split(/\r?\n/);
14584
+ for (const line of lines) {
14585
+ const trimmed = line.trim();
14586
+ if (trimmed) {
14587
+ return trimmed;
14588
+ }
14589
+ }
14590
+ return null;
14591
+ }
14592
+ /**
14593
+ * @@@
14594
+ *
14595
+ * @private thing of inline knowledge
14596
+ */
14597
+ function deriveBaseFilename(content) {
14598
+ const firstLine = getFirstNonEmptyLine(content);
14599
+ if (!firstLine) {
14600
+ return INLINE_KNOWLEDGE_BASE_NAME;
14601
+ }
14602
+ const normalized = normalizeToKebabCase(firstLine);
14603
+ return normalized || INLINE_KNOWLEDGE_BASE_NAME;
14604
+ }
14605
+ /**
14606
+ * Creates a data URL that represents the inline knowledge content as a text file.
14607
+ *
14608
+ * @private thing of inline knowledge
14609
+ */
14610
+ function createInlineKnowledgeSourceFile(content) {
14611
+ const trimmedContent = content.trim();
14612
+ const baseName = deriveBaseFilename(trimmedContent);
14613
+ const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
14614
+ const mimeType = 'text/plain';
14615
+ const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
14616
+ const encodedFilename = encodeURIComponent(filename);
14617
+ const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
14618
+ return {
14619
+ filename,
14620
+ mimeType,
14621
+ url,
14622
+ };
14623
+ }
14624
+ /**
14625
+ * Checks whether the provided source string is a data URL that can be decoded.
14626
+ *
14627
+ * @private thing of inline knowledge
14628
+ */
14629
+ function isDataUrlKnowledgeSource(source) {
14630
+ return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
14631
+ }
14632
+ /**
14633
+ * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
14634
+ *
14635
+ * @private thing of inline knowledge
14636
+ */
14637
+ function parseDataUrlKnowledgeSource(source) {
14638
+ if (!isDataUrlKnowledgeSource(source)) {
14639
+ return null;
14640
+ }
14641
+ const commaIndex = source.indexOf(',');
14642
+ if (commaIndex === -1) {
14643
+ return null;
14644
+ }
14645
+ const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
14646
+ const payload = source.slice(commaIndex + 1);
14647
+ const tokens = header.split(';');
14648
+ const mediaType = tokens[0] || 'text/plain';
14649
+ let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
14650
+ let isBase64 = false;
14651
+ for (let i = 1; i < tokens.length; i++) {
14652
+ const token = tokens[i];
14653
+ if (!token) {
14654
+ continue;
14655
+ }
14656
+ if (token.toLowerCase() === 'base64') {
14657
+ isBase64 = true;
14658
+ continue;
14659
+ }
14660
+ const [key, value] = token.split('=');
14661
+ if (key === 'name' && value !== undefined) {
14662
+ try {
14663
+ filename = decodeURIComponent(value);
14664
+ }
14665
+ catch (_a) {
14666
+ filename = value;
14667
+ }
14668
+ }
14669
+ }
14670
+ if (!isBase64) {
14671
+ return null;
14672
+ }
14673
+ try {
14674
+ const buffer = Buffer.from(payload, 'base64');
14675
+ return {
14676
+ buffer,
14677
+ filename,
14678
+ mimeType: mediaType,
14679
+ };
14680
+ }
14681
+ catch (_b) {
14682
+ return null;
14683
+ }
14684
+ }
14685
+ /**
14686
+ * Note: [💞] Ignore a discrepancy between file name and entity name
14687
+ */
14688
+
14544
14689
  /**
14545
14690
  * KNOWLEDGE commitment definition
14546
14691
  *
@@ -14639,9 +14784,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
14639
14784
  return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
14640
14785
  }
14641
14786
  else {
14642
- // Direct text knowledge - add to system message
14643
- const knowledgeSection = `Knowledge: ${trimmedContent}`;
14644
- return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
14787
+ const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
14788
+ const updatedRequirements = {
14789
+ ...requirements,
14790
+ knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
14791
+ };
14792
+ const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
14793
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
14645
14794
  }
14646
14795
  }
14647
14796
  }
@@ -14888,16 +15037,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
14888
15037
  // and typically doesn't need to be added to the system prompt or model requirements directly.
14889
15038
  // It is extracted separately for the chat interface.
14890
15039
  var _a;
14891
- const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
15040
+ const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
14892
15041
  if (pendingUserMessage) {
14893
15042
  const newSample = { question: pendingUserMessage, answer: content };
14894
15043
  const newSamples = [...(requirements.samples || []), newSample];
14895
- const newMetadata = { ...requirements.metadata };
15044
+ const newMetadata = { ...requirements._metadata };
14896
15045
  delete newMetadata.pendingUserMessage;
14897
15046
  return {
14898
15047
  ...requirements,
14899
15048
  samples: newSamples,
14900
- metadata: newMetadata,
15049
+ _metadata: newMetadata,
14901
15050
  };
14902
15051
  }
14903
15052
  return requirements;
@@ -15145,8 +15294,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
15145
15294
  applyToAgentModelRequirements(requirements, content) {
15146
15295
  return {
15147
15296
  ...requirements,
15148
- metadata: {
15149
- ...requirements.metadata,
15297
+ _metadata: {
15298
+ ...requirements._metadata,
15150
15299
  pendingUserMessage: content,
15151
15300
  },
15152
15301
  };
@@ -16004,11 +16153,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
16004
16153
  if (trimmedContent === '') {
16005
16154
  return requirements;
16006
16155
  }
16007
- // Return requirements with updated notes but no changes to system message
16008
- return {
16009
- ...requirements,
16010
- notes: [...(requirements.notes || []), trimmedContent],
16011
- };
16156
+ return requirements;
16012
16157
  }
16013
16158
  }
16014
16159
  /**
@@ -16070,12 +16215,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
16070
16215
  // Since OPEN is default, we can just ensure isClosed is false
16071
16216
  // But to be explicit we can set it
16072
16217
  const updatedMetadata = {
16073
- ...requirements.metadata,
16218
+ ...requirements._metadata,
16074
16219
  isClosed: false,
16075
16220
  };
16076
16221
  return {
16077
16222
  ...requirements,
16078
- metadata: updatedMetadata,
16223
+ _metadata: updatedMetadata,
16079
16224
  };
16080
16225
  }
16081
16226
  }
@@ -16156,7 +16301,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
16156
16301
  return requirements;
16157
16302
  }
16158
16303
  // Get existing persona content from metadata
16159
- const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
16304
+ const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
16160
16305
  // Merge the new content with existing persona content
16161
16306
  // When multiple PERSONA commitments exist, they are merged into one
16162
16307
  const mergedPersonaContent = existingPersonaContent
@@ -16164,12 +16309,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
16164
16309
  : trimmedContent;
16165
16310
  // Store the merged persona content in metadata for debugging and inspection
16166
16311
  const updatedMetadata = {
16167
- ...requirements.metadata,
16312
+ ...requirements._metadata,
16168
16313
  PERSONA: mergedPersonaContent,
16169
16314
  };
16170
16315
  // Get the agent name from metadata (which should contain the first line of agent source)
16171
16316
  // If not available, extract from current system message as fallback
16172
- let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
16317
+ let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
16173
16318
  if (!agentName) {
16174
16319
  // Fallback: extract from current system message
16175
16320
  const currentMessage = requirements.systemMessage.trim();
@@ -16216,7 +16361,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
16216
16361
  return {
16217
16362
  ...requirements,
16218
16363
  systemMessage: newSystemMessage,
16219
- metadata: updatedMetadata,
16364
+ _metadata: updatedMetadata,
16220
16365
  };
16221
16366
  }
16222
16367
  }
@@ -16299,7 +16444,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
16299
16444
  }
16300
16445
  // Add rule to the system message
16301
16446
  const ruleSection = `Rule: ${trimmedContent}`;
16302
- return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
16447
+ const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
16448
+ const ruleLines = trimmedContent
16449
+ .split(/\r?\n/)
16450
+ .map((line) => line.trim())
16451
+ .filter(Boolean)
16452
+ .map((line) => `- ${line}`);
16453
+ if (ruleLines.length === 0) {
16454
+ return requirementsWithRule;
16455
+ }
16456
+ return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
16303
16457
  }
16304
16458
  }
16305
16459
  /**
@@ -16801,11 +16955,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
16801
16955
  if (!trimmedContent) {
16802
16956
  return requirements;
16803
16957
  }
16804
- const teammates = parseTeamCommitmentContent(trimmedContent, { strict: true });
16958
+ // Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
16959
+ const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
16805
16960
  if (teammates.length === 0) {
16806
16961
  return requirements;
16807
16962
  }
16808
- const agentName = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
16963
+ const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
16809
16964
  const teamEntries = teammates.map((teammate) => ({
16810
16965
  toolName: createTeamToolName(teammate.url),
16811
16966
  teammate,
@@ -16845,7 +17000,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
16845
17000
  },
16846
17001
  });
16847
17002
  }
16848
- const existingTeammates = ((_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
17003
+ const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
16849
17004
  const updatedTeammates = [...existingTeammates];
16850
17005
  for (const entry of teamEntries) {
16851
17006
  if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
@@ -16874,8 +17029,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
16874
17029
  return this.appendToSystemMessage({
16875
17030
  ...requirements,
16876
17031
  tools: updatedTools,
16877
- metadata: {
16878
- ...requirements.metadata,
17032
+ _metadata: {
17033
+ ...requirements._metadata,
16879
17034
  teammates: updatedTeammates,
16880
17035
  },
16881
17036
  }, teamSystemMessage);
@@ -17107,7 +17262,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
17107
17262
  if (!trimmedContent) {
17108
17263
  // Store template mode flag in metadata
17109
17264
  const updatedMetadata = {
17110
- ...requirements.metadata,
17265
+ ...requirements._metadata,
17111
17266
  templateMode: true,
17112
17267
  };
17113
17268
  // Add a general instruction about using structured templates
@@ -17117,21 +17272,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
17117
17272
  `);
17118
17273
  return {
17119
17274
  ...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
17120
- metadata: updatedMetadata,
17275
+ _metadata: updatedMetadata,
17121
17276
  };
17122
17277
  }
17123
17278
  // If content is provided, add the specific template instructions
17124
17279
  const templateSection = `Response Template: ${trimmedContent}`;
17125
17280
  // Store the template in metadata for potential programmatic access
17126
- const existingTemplates = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
17281
+ const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
17127
17282
  const updatedMetadata = {
17128
- ...requirements.metadata,
17283
+ ...requirements._metadata,
17129
17284
  templates: [...existingTemplates, trimmedContent],
17130
17285
  templateMode: true,
17131
17286
  };
17132
17287
  return {
17133
17288
  ...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
17134
- metadata: updatedMetadata,
17289
+ _metadata: updatedMetadata,
17135
17290
  };
17136
17291
  }
17137
17292
  }
@@ -17468,8 +17623,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
17468
17623
  return this.appendToSystemMessage({
17469
17624
  ...requirements,
17470
17625
  tools: updatedTools,
17471
- metadata: {
17472
- ...requirements.metadata,
17626
+ _metadata: {
17627
+ ...requirements._metadata,
17473
17628
  useBrowser: true,
17474
17629
  },
17475
17630
  }, spaceTrim$1(`
@@ -17698,8 +17853,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
17698
17853
  return this.appendToSystemMessage({
17699
17854
  ...requirements,
17700
17855
  tools: updatedTools,
17701
- metadata: {
17702
- ...requirements.metadata,
17856
+ _metadata: {
17857
+ ...requirements._metadata,
17703
17858
  useEmail: content || true,
17704
17859
  },
17705
17860
  }, spaceTrim$1((block) => `
@@ -17834,8 +17989,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
17834
17989
  return this.appendToSystemMessage({
17835
17990
  ...requirements,
17836
17991
  tools: updatedTools,
17837
- metadata: {
17838
- ...requirements.metadata,
17992
+ _metadata: {
17993
+ ...requirements._metadata,
17839
17994
  useImageGenerator: content || true,
17840
17995
  },
17841
17996
  }, spaceTrim$1(`
@@ -18126,8 +18281,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
18126
18281
  return this.appendToSystemMessage({
18127
18282
  ...requirements,
18128
18283
  tools: updatedTools,
18129
- metadata: {
18130
- ...requirements.metadata,
18284
+ _metadata: {
18285
+ ...requirements._metadata,
18131
18286
  useSearchEngine: content || true,
18132
18287
  },
18133
18288
  }, spaceTrim$1((block) => `
@@ -18275,8 +18430,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
18275
18430
  return this.appendToSystemMessage({
18276
18431
  ...requirements,
18277
18432
  tools: updatedTools,
18278
- metadata: {
18279
- ...requirements.metadata,
18433
+ _metadata: {
18434
+ ...requirements._metadata,
18280
18435
  },
18281
18436
  }, spaceTrim$1((block) => `
18282
18437
  Time and date context:
@@ -20982,11 +21137,14 @@ function asUpdatableSubject(value) {
20982
21137
  function createEmptyAgentModelRequirements() {
20983
21138
  return {
20984
21139
  systemMessage: '',
21140
+ promptSuffix: '',
20985
21141
  // modelName: 'gpt-5',
20986
21142
  modelName: 'gemini-2.5-flash-lite',
20987
21143
  temperature: 0.7,
20988
21144
  topP: 0.9,
20989
21145
  topK: 50,
21146
+ parentAgentUrl: null,
21147
+ isClosed: false,
20990
21148
  };
20991
21149
  }
20992
21150
  /**
@@ -21132,14 +21290,42 @@ function removeCommentsFromSystemMessage(systemMessage) {
21132
21290
  }
21133
21291
 
21134
21292
  /**
21135
- * Creates agent model requirements using the new commitment system
21293
+ * Creates agent model requirements using the new commitment system.
21294
+ *
21136
21295
  * This function uses a reduce-like pattern where each commitment applies its changes
21137
- * to build the final requirements starting from a basic empty model
21296
+ * to build the final requirements starting from a basic empty model.
21138
21297
  *
21139
- * @public exported from `@promptbook/core`
21298
+ * @param agentSource - Agent source book to parse.
21299
+ * @param modelName - Optional override for the agent model name.
21300
+ * @param options - Additional options such as the agent reference resolver.
21301
+ *
21302
+ * @private @@@
21303
+ */
21304
+ const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
21305
+ /**
21306
+ * Returns a safe fallback content when a resolver fails to transform a reference commitment.
21307
+ *
21308
+ * @param commitmentType - Commitment being resolved.
21309
+ * @param originalContent - Original unresolved commitment content.
21310
+ * @returns Fallback content that keeps requirement creation resilient.
21311
+ */
21312
+ function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
21313
+ if (commitmentType === 'FROM') {
21314
+ return 'VOID';
21315
+ }
21316
+ if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
21317
+ return '';
21318
+ }
21319
+ return originalContent;
21320
+ }
21321
+ /**
21322
+ * @@@
21323
+ *
21324
+ * @private @@@
21140
21325
  */
21141
- async function createAgentModelRequirementsWithCommitments(agentSource, modelName) {
21326
+ async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
21142
21327
  var _a;
21328
+ const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
21143
21329
  // Parse the agent source to extract commitments
21144
21330
  const parseResult = parseAgentSourceWithCommitments(agentSource);
21145
21331
  // Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
@@ -21176,8 +21362,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
21176
21362
  // Store the agent name in metadata so commitments can access it
21177
21363
  requirements = {
21178
21364
  ...requirements,
21179
- metadata: {
21180
- ...requirements.metadata,
21365
+ _metadata: {
21366
+ ...requirements._metadata,
21181
21367
  agentName: parseResult.agentName,
21182
21368
  },
21183
21369
  };
@@ -21191,6 +21377,17 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
21191
21377
  // Apply each commitment in order using reduce-like pattern
21192
21378
  for (let i = 0; i < filteredCommitments.length; i++) {
21193
21379
  const commitment = filteredCommitments[i];
21380
+ const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
21381
+ let commitmentContent = commitment.content;
21382
+ if (isReferenceCommitment && agentReferenceResolver) {
21383
+ try {
21384
+ commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
21385
+ }
21386
+ catch (error) {
21387
+ console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
21388
+ commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
21389
+ }
21390
+ }
21194
21391
  // CLOSED commitment should work only if its the last commitment in the book
21195
21392
  if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
21196
21393
  continue;
@@ -21198,7 +21395,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
21198
21395
  const definition = getCommitmentDefinition(commitment.type);
21199
21396
  if (definition) {
21200
21397
  try {
21201
- requirements = definition.applyToAgentModelRequirements(requirements, commitment.content);
21398
+ requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
21202
21399
  }
21203
21400
  catch (error) {
21204
21401
  console.warn(`Failed to apply commitment ${commitment.type}:`, error);
@@ -21346,23 +21543,28 @@ function isBinaryMimeType(mimeType) {
21346
21543
  }
21347
21544
 
21348
21545
  /**
21349
- * Creates model requirements for an agent based on its source
21546
+ * Creates model requirements for an agent based on its source.
21350
21547
  *
21351
21548
  * There are 2 similar functions:
21352
21549
  * - `parseAgentSource` which is a lightweight parser for agent source, it parses basic information and its purpose is to be quick and synchronous. The commitments there are hardcoded.
21353
21550
  * - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
21354
21551
  *
21552
+ * @param agentSource - Book describing the agent.
21553
+ * @param modelName - Optional override for the agent's model.
21554
+ * @param availableModels - Models that could fulfill the agent.
21555
+ * @param llmTools - Execution tools used when selecting a best model.
21556
+ * @param options - Optional hooks such as the agent reference resolver.
21355
21557
  * @public exported from `@promptbook/core`
21356
21558
  */
21357
- async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
21559
+ async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
21358
21560
  // If availableModels are provided and no specific modelName is given,
21359
21561
  // use preparePersona to select the best model
21360
21562
  if (availableModels && !modelName && llmTools) {
21361
21563
  const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
21362
- return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
21564
+ return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
21363
21565
  }
21364
21566
  // Use the new commitment-based system with provided or default model
21365
- return createAgentModelRequirementsWithCommitments(agentSource, modelName);
21567
+ return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
21366
21568
  }
21367
21569
  /**
21368
21570
  * Selects the best model using the preparePersona function
@@ -21660,6 +21862,66 @@ const OPENAI_MODELS = exportJson({
21660
21862
  },
21661
21863
  /**/
21662
21864
  /**/
21865
+ {
21866
+ modelVariant: 'CHAT',
21867
+ modelTitle: 'gpt-5.2-codex',
21868
+ modelName: 'gpt-5.2-codex',
21869
+ modelDescription: 'High-capability Codex variant tuned for agentic code generation with large contexts and reasoning effort controls. Ideal for long-horizon coding workflows and multi-step reasoning.',
21870
+ pricing: {
21871
+ prompt: pricing(`$1.75 / 1M tokens`),
21872
+ output: pricing(`$14.00 / 1M tokens`),
21873
+ },
21874
+ },
21875
+ /**/
21876
+ /**/
21877
+ {
21878
+ modelVariant: 'CHAT',
21879
+ modelTitle: 'gpt-5.1-codex-max',
21880
+ modelName: 'gpt-5.1-codex-max',
21881
+ modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
21882
+ pricing: {
21883
+ prompt: pricing(`$1.25 / 1M tokens`),
21884
+ output: pricing(`$10.00 / 1M tokens`),
21885
+ },
21886
+ },
21887
+ /**/
21888
+ /**/
21889
+ {
21890
+ modelVariant: 'CHAT',
21891
+ modelTitle: 'gpt-5.1-codex',
21892
+ modelName: 'gpt-5.1-codex',
21893
+ modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
21894
+ pricing: {
21895
+ prompt: pricing(`$1.25 / 1M tokens`),
21896
+ output: pricing(`$10.00 / 1M tokens`),
21897
+ },
21898
+ },
21899
+ /**/
21900
+ /**/
21901
+ {
21902
+ modelVariant: 'CHAT',
21903
+ modelTitle: 'gpt-5.1-codex-mini',
21904
+ modelName: 'gpt-5.1-codex-mini',
21905
+ modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
21906
+ pricing: {
21907
+ prompt: pricing(`$0.25 / 1M tokens`),
21908
+ output: pricing(`$2.00 / 1M tokens`),
21909
+ },
21910
+ },
21911
+ /**/
21912
+ /**/
21913
+ {
21914
+ modelVariant: 'CHAT',
21915
+ modelTitle: 'gpt-5-codex',
21916
+ modelName: 'gpt-5-codex',
21917
+ modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
21918
+ pricing: {
21919
+ prompt: pricing(`$1.25 / 1M tokens`),
21920
+ output: pricing(`$10.00 / 1M tokens`),
21921
+ },
21922
+ },
21923
+ /**/
21924
+ /**/
21663
21925
  {
21664
21926
  modelVariant: 'CHAT',
21665
21927
  modelTitle: 'gpt-5-mini',
@@ -22364,6 +22626,32 @@ function isUnsupportedParameterError(error) {
22364
22626
  errorMessage.includes('does not support'));
22365
22627
  }
22366
22628
 
22629
+ /**
22630
+ * Provides access to the structured clone implementation when available.
22631
+ */
22632
+ function getStructuredCloneFunction() {
22633
+ return globalThis.structuredClone;
22634
+ }
22635
+ /**
22636
+ * Checks whether the prompt is a chat prompt that carries file attachments.
22637
+ */
22638
+ function hasChatPromptFiles(prompt) {
22639
+ return 'files' in prompt && Array.isArray(prompt.files);
22640
+ }
22641
+ /**
22642
+ * Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
22643
+ */
22644
+ function clonePromptPreservingFiles(prompt) {
22645
+ const structuredCloneFn = getStructuredCloneFunction();
22646
+ if (typeof structuredCloneFn === 'function') {
22647
+ return structuredCloneFn(prompt);
22648
+ }
22649
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
22650
+ if (hasChatPromptFiles(prompt)) {
22651
+ clonedPrompt.files = prompt.files;
22652
+ }
22653
+ return clonedPrompt;
22654
+ }
22367
22655
  /**
22368
22656
  * Execution Tools for calling OpenAI API or other OpenAI compatible provider
22369
22657
  *
@@ -22448,7 +22736,7 @@ class OpenAiCompatibleExecutionTools {
22448
22736
  */
22449
22737
  async callChatModelStream(prompt, onProgress) {
22450
22738
  // Deep clone prompt and modelRequirements to avoid mutation across calls
22451
- const clonedPrompt = JSON.parse(JSON.stringify(prompt));
22739
+ const clonedPrompt = clonePromptPreservingFiles(prompt);
22452
22740
  // Use local Set for retried parameters to ensure independence and thread safety
22453
22741
  const retriedUnsupportedParameters = new Set();
22454
22742
  return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
@@ -22475,7 +22763,10 @@ class OpenAiCompatibleExecutionTools {
22475
22763
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
22476
22764
  // <- Note: [🧆]
22477
22765
  }; // <- TODO: [💩] Guard here types better
22478
- if (format === 'JSON') {
22766
+ if (currentModelRequirements.responseFormat !== undefined) {
22767
+ modelSettings.response_format = currentModelRequirements.responseFormat;
22768
+ }
22769
+ else if (format === 'JSON') {
22479
22770
  modelSettings.response_format = {
22480
22771
  type: 'json_object',
22481
22772
  };
@@ -23956,7 +24247,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
23956
24247
  const processingStartedAtMs = Date.now();
23957
24248
  for (const [index, source] of knowledgeSources.entries()) {
23958
24249
  try {
23959
- const sourceType = source.startsWith('http') || source.startsWith('https') ? 'url' : 'file';
24250
+ const isDataUrl = isDataUrlKnowledgeSource(source);
24251
+ const isHttp = source.startsWith('http://') || source.startsWith('https://');
24252
+ const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
23960
24253
  if (this.options.isVerbose) {
23961
24254
  console.info('[🤰]', 'Processing knowledge source', {
23962
24255
  index: index + 1,
@@ -23966,8 +24259,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
23966
24259
  logLabel,
23967
24260
  });
23968
24261
  }
23969
- // Check if it's a URL
23970
- if (source.startsWith('http://') || source.startsWith('https://')) {
24262
+ if (isDataUrl) {
24263
+ const parsed = parseDataUrlKnowledgeSource(source);
24264
+ if (!parsed) {
24265
+ skippedSources.push({ source, reason: 'invalid_data_url' });
24266
+ if (this.options.isVerbose) {
24267
+ console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
24268
+ source,
24269
+ sourceType,
24270
+ logLabel,
24271
+ });
24272
+ }
24273
+ continue;
24274
+ }
24275
+ const dataUrlFile = new File([parsed.buffer], parsed.filename, {
24276
+ type: parsed.mimeType,
24277
+ });
24278
+ fileStreams.push(dataUrlFile);
24279
+ totalBytes += parsed.buffer.length;
24280
+ continue;
24281
+ }
24282
+ if (isHttp) {
23971
24283
  const downloadResult = await this.downloadKnowledgeSourceFile({
23972
24284
  source,
23973
24285
  timeoutMs: downloadTimeoutMs,
@@ -24069,6 +24381,64 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
24069
24381
  }
24070
24382
 
24071
24383
  const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
24384
+ const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
24385
+ /*
24386
+ TODO: Use or remove
24387
+ const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
24388
+ type: 'object',
24389
+ properties: {},
24390
+ required: [],
24391
+ additionalProperties: true,
24392
+ };
24393
+ */
24394
+ function buildJsonSchemaDefinition(jsonSchema) {
24395
+ var _a, _b, _c;
24396
+ const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
24397
+ return {
24398
+ type: 'json_schema',
24399
+ name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
24400
+ strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
24401
+ schema: {
24402
+ type: 'object',
24403
+ properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
24404
+ required: Array.isArray(schema.required) ? schema.required : [],
24405
+ additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
24406
+ description: schema.description,
24407
+ },
24408
+ };
24409
+ }
24410
+ /**
24411
+ * Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
24412
+ * structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
24413
+ *
24414
+ * @param responseFormat - The OpenAI `response_format` payload from the user request.
24415
+ * @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
24416
+ * @private utility of Open AI
24417
+ */
24418
+ function mapResponseFormatToAgentOutputType(responseFormat) {
24419
+ if (!responseFormat) {
24420
+ return undefined;
24421
+ }
24422
+ if (typeof responseFormat === 'string') {
24423
+ if (responseFormat === 'text') {
24424
+ return 'text';
24425
+ }
24426
+ if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
24427
+ return buildJsonSchemaDefinition();
24428
+ }
24429
+ return 'text';
24430
+ }
24431
+ switch (responseFormat.type) {
24432
+ case 'text':
24433
+ return 'text';
24434
+ case 'json_schema':
24435
+ return buildJsonSchemaDefinition(responseFormat.json_schema);
24436
+ case 'json_object':
24437
+ return buildJsonSchemaDefinition();
24438
+ default:
24439
+ return undefined;
24440
+ }
24441
+ }
24072
24442
  /**
24073
24443
  * Execution tools for OpenAI AgentKit (Agents SDK).
24074
24444
  *
@@ -24116,6 +24486,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
24116
24486
  ...parameters,
24117
24487
  modelName: this.agentKitModelName,
24118
24488
  });
24489
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
24119
24490
  const preparedAgentKitAgent = await this.prepareAgentKitAgent({
24120
24491
  name: (prompt.title || 'Agent'),
24121
24492
  instructions: modelRequirements.systemMessage || '',
@@ -24127,6 +24498,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
24127
24498
  prompt,
24128
24499
  rawPromptContent,
24129
24500
  onProgress,
24501
+ responseFormatOutputType,
24130
24502
  });
24131
24503
  }
24132
24504
  /**
@@ -24308,16 +24680,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
24308
24680
  ...prompt.parameters,
24309
24681
  modelName: this.agentKitModelName,
24310
24682
  });
24683
+ const agentForRun = options.responseFormatOutputType !== undefined
24684
+ ? openAiAgentKitAgent.clone({
24685
+ outputType: options.responseFormatOutputType,
24686
+ })
24687
+ : openAiAgentKitAgent;
24311
24688
  const start = $getCurrentDate();
24312
24689
  let latestContent = '';
24313
24690
  const toolCalls = [];
24314
24691
  const toolCallIndexById = new Map();
24315
24692
  const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
24316
24693
  const rawRequest = {
24317
- agentName: openAiAgentKitAgent.name,
24694
+ agentName: agentForRun.name,
24318
24695
  input: inputItems,
24319
24696
  };
24320
- const streamResult = await run(openAiAgentKitAgent, inputItems, {
24697
+ const streamResult = await run(agentForRun, inputItems, {
24321
24698
  stream: true,
24322
24699
  context: { parameters: prompt.parameters },
24323
24700
  });
@@ -25306,22 +25683,28 @@ class AgentLlmExecutionTools {
25306
25683
  throw new Error('AgentLlmExecutionTools only supports chat prompts');
25307
25684
  }
25308
25685
  const modelRequirements = await this.getModelRequirements();
25686
+ const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
25309
25687
  const chatPrompt = prompt;
25310
25688
  let underlyingLlmResult;
25311
- // Create modified chat prompt with agent system message
25689
+ const chatPromptContentWithSuffix = promptSuffix
25690
+ ? `${chatPrompt.content}\n\n${promptSuffix}`
25691
+ : chatPrompt.content;
25312
25692
  const promptWithAgentModelRequirements = {
25313
25693
  ...chatPrompt,
25694
+ content: chatPromptContentWithSuffix,
25314
25695
  modelRequirements: {
25315
25696
  ...chatPrompt.modelRequirements,
25316
- ...modelRequirements,
25697
+ ...sanitizedRequirements,
25317
25698
  // Spread tools to convert readonly array to mutable
25318
- tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
25699
+ tools: sanitizedRequirements.tools
25700
+ ? [...sanitizedRequirements.tools]
25701
+ : chatPrompt.modelRequirements.tools,
25319
25702
  // Spread knowledgeSources to convert readonly array to mutable
25320
- knowledgeSources: modelRequirements.knowledgeSources
25321
- ? [...modelRequirements.knowledgeSources]
25703
+ knowledgeSources: sanitizedRequirements.knowledgeSources
25704
+ ? [...sanitizedRequirements.knowledgeSources]
25322
25705
  : undefined,
25323
25706
  // Prepend agent system message to existing system message
25324
- systemMessage: modelRequirements.systemMessage +
25707
+ systemMessage: sanitizedRequirements.systemMessage +
25325
25708
  (chatPrompt.modelRequirements.systemMessage
25326
25709
  ? `\n\n${chatPrompt.modelRequirements.systemMessage}`
25327
25710
  : ''),
@@ -25329,8 +25712,8 @@ class AgentLlmExecutionTools {
25329
25712
  };
25330
25713
  console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
25331
25714
  if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
25332
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
25333
- const vectorStoreHash = SHA256(JSON.stringify((_a = modelRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
25715
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
25716
+ const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
25334
25717
  const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
25335
25718
  const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
25336
25719
  let preparedAgentKit = this.options.assistantPreparationMode === 'external'
@@ -25357,7 +25740,7 @@ class AgentLlmExecutionTools {
25357
25740
  agent: this.title,
25358
25741
  });
25359
25742
  }
25360
- if (!vectorStoreId && ((_b = modelRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
25743
+ if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
25361
25744
  emitAssistantPreparationProgress({
25362
25745
  onProgress,
25363
25746
  prompt,
@@ -25373,9 +25756,9 @@ class AgentLlmExecutionTools {
25373
25756
  });
25374
25757
  preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
25375
25758
  name: this.title,
25376
- instructions: modelRequirements.systemMessage || '',
25377
- knowledgeSources: modelRequirements.knowledgeSources,
25378
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
25759
+ instructions: sanitizedRequirements.systemMessage || '',
25760
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
25761
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
25379
25762
  vectorStoreId,
25380
25763
  });
25381
25764
  }
@@ -25390,15 +25773,17 @@ class AgentLlmExecutionTools {
25390
25773
  requirementsHash,
25391
25774
  vectorStoreId: preparedAgentKit.vectorStoreId,
25392
25775
  });
25776
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
25393
25777
  underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
25394
25778
  openAiAgentKitAgent: preparedAgentKit.agent,
25395
25779
  prompt: promptWithAgentModelRequirements,
25396
25780
  onProgress,
25781
+ responseFormatOutputType,
25397
25782
  });
25398
25783
  }
25399
25784
  else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
25400
25785
  // ... deprecated path ...
25401
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
25786
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
25402
25787
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
25403
25788
  let assistant;
25404
25789
  if (this.options.assistantPreparationMode === 'external') {
@@ -25440,9 +25825,9 @@ class AgentLlmExecutionTools {
25440
25825
  assistant = await this.options.llmTools.updateAssistant({
25441
25826
  assistantId: cached.assistantId,
25442
25827
  name: this.title,
25443
- instructions: modelRequirements.systemMessage,
25444
- knowledgeSources: modelRequirements.knowledgeSources,
25445
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
25828
+ instructions: sanitizedRequirements.systemMessage,
25829
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
25830
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
25446
25831
  });
25447
25832
  AgentLlmExecutionTools.assistantCache.set(this.title, {
25448
25833
  assistantId: assistant.assistantId,
@@ -25465,9 +25850,9 @@ class AgentLlmExecutionTools {
25465
25850
  });
25466
25851
  assistant = await this.options.llmTools.createNewAssistant({
25467
25852
  name: this.title,
25468
- instructions: modelRequirements.systemMessage,
25469
- knowledgeSources: modelRequirements.knowledgeSources,
25470
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
25853
+ instructions: sanitizedRequirements.systemMessage,
25854
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
25855
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
25471
25856
  /*
25472
25857
  !!!
25473
25858
  metadata: {
@@ -25509,13 +25894,19 @@ class AgentLlmExecutionTools {
25509
25894
  }
25510
25895
  }
25511
25896
  let content = underlyingLlmResult.content;
25512
- // Note: Cleanup the AI artifacts from the content
25513
- content = humanizeAiText(content);
25514
- // Note: Make sure the content is Promptbook-like
25515
- content = promptbookifyAiText(content);
25897
+ if (typeof content === 'string') {
25898
+ // Note: Cleanup the AI artifacts from the content
25899
+ content = humanizeAiText(content);
25900
+ // Note: Make sure the content is Promptbook-like
25901
+ content = promptbookifyAiText(content);
25902
+ }
25903
+ else {
25904
+ // TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
25905
+ content = JSON.stringify(content);
25906
+ }
25516
25907
  const agentResult = {
25517
25908
  ...underlyingLlmResult,
25518
- content,
25909
+ content: content,
25519
25910
  modelName: this.modelName,
25520
25911
  };
25521
25912
  return agentResult;
@@ -25704,7 +26095,6 @@ class Agent extends AgentLlmExecutionTools {
25704
26095
  * Note: This method also implements the learning mechanism
25705
26096
  */
25706
26097
  async callChatModelStream(prompt, onProgress) {
25707
- var _a;
25708
26098
  // [1] Check if the user is asking the same thing as in the samples
25709
26099
  const modelRequirements = await this.getModelRequirements();
25710
26100
  if (modelRequirements.samples) {
@@ -25752,7 +26142,7 @@ class Agent extends AgentLlmExecutionTools {
25752
26142
  if (result.rawResponse && 'sample' in result.rawResponse) {
25753
26143
  return result;
25754
26144
  }
25755
- if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
26145
+ if (modelRequirements.isClosed) {
25756
26146
  return result;
25757
26147
  }
25758
26148
  // Note: [0] Notify start of self-learning