@promptbook/remote-server 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
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
40
40
  * @generated
41
41
  * @see https://github.com/webgptorg/promptbook
42
42
  */
43
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-8';
43
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
44
44
  /**
45
45
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
46
46
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -10801,6 +10801,28 @@ class BaseCommitmentDefinition {
10801
10801
  return currentMessage + separator + content;
10802
10802
  });
10803
10803
  }
10804
+ /**
10805
+ * Helper method to create a new requirements object with updated prompt suffix
10806
+ */
10807
+ updatePromptSuffix(requirements, contentUpdate) {
10808
+ const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
10809
+ return {
10810
+ ...requirements,
10811
+ promptSuffix: newSuffix,
10812
+ };
10813
+ }
10814
+ /**
10815
+ * Helper method to append content to the prompt suffix
10816
+ * Default separator is a single newline for bullet lists.
10817
+ */
10818
+ appendToPromptSuffix(requirements, content, separator = '\n') {
10819
+ return this.updatePromptSuffix(requirements, (currentSuffix) => {
10820
+ if (!currentSuffix.trim()) {
10821
+ return content;
10822
+ }
10823
+ return `${currentSuffix}${separator}${content}`;
10824
+ });
10825
+ }
10804
10826
  /**
10805
10827
  * Helper method to add a comment section to the system message
10806
10828
  * Comments are lines starting with # that will be removed from the final system message
@@ -10978,13 +11000,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
10978
11000
  `);
10979
11001
  }
10980
11002
  applyToAgentModelRequirements(requirements, _content) {
10981
- const updatedMetadata = {
10982
- ...requirements.metadata,
10983
- isClosed: true,
10984
- };
10985
11003
  return {
10986
11004
  ...requirements,
10987
- metadata: updatedMetadata,
11005
+ isClosed: true,
10988
11006
  };
10989
11007
  }
10990
11008
  }
@@ -11262,12 +11280,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
11262
11280
  return requirements;
11263
11281
  }
11264
11282
  // Get existing dictionary entries from metadata
11265
- const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
11283
+ const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
11266
11284
  // Merge the new dictionary entry with existing entries
11267
11285
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
11268
11286
  // Store the merged dictionary in metadata for debugging and inspection
11269
11287
  const updatedMetadata = {
11270
- ...requirements.metadata,
11288
+ ...requirements._metadata,
11271
11289
  DICTIONARY: mergedDictionary,
11272
11290
  };
11273
11291
  // Create the dictionary section for the system message
@@ -11275,7 +11293,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
11275
11293
  const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
11276
11294
  return {
11277
11295
  ...this.appendToSystemMessage(requirements, dictionarySection),
11278
- metadata: updatedMetadata,
11296
+ _metadata: updatedMetadata,
11279
11297
  };
11280
11298
  }
11281
11299
  }
@@ -11415,10 +11433,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
11415
11433
  applyToAgentModelRequirements(requirements, content) {
11416
11434
  const trimmedContent = content.trim();
11417
11435
  if (!trimmedContent) {
11418
- return {
11419
- ...requirements,
11420
- parentAgentUrl: undefined,
11421
- };
11436
+ return requirements;
11422
11437
  }
11423
11438
  if (trimmedContent.toUpperCase() === 'VOID' ||
11424
11439
  trimmedContent.toUpperCase() === 'NULL' ||
@@ -11632,6 +11647,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
11632
11647
  * Note: [💞] Ignore a discrepancy between file name and entity name
11633
11648
  */
11634
11649
 
11650
+ /**
11651
+ * @@@
11652
+ *
11653
+ * @private thing of inline knowledge
11654
+ */
11655
+ const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
11656
+ /**
11657
+ * @@@
11658
+ *
11659
+ * @private thing of inline knowledge
11660
+ */
11661
+ const INLINE_KNOWLEDGE_EXTENSION = '.txt';
11662
+ /**
11663
+ * @@@
11664
+ *
11665
+ * @private thing of inline knowledge
11666
+ */
11667
+ const DATA_URL_PREFIX = 'data:';
11668
+ /**
11669
+ * @@@
11670
+ *
11671
+ * @private thing of inline knowledge
11672
+ */
11673
+ function getFirstNonEmptyLine(content) {
11674
+ const lines = content.split(/\r?\n/);
11675
+ for (const line of lines) {
11676
+ const trimmed = line.trim();
11677
+ if (trimmed) {
11678
+ return trimmed;
11679
+ }
11680
+ }
11681
+ return null;
11682
+ }
11683
+ /**
11684
+ * @@@
11685
+ *
11686
+ * @private thing of inline knowledge
11687
+ */
11688
+ function deriveBaseFilename(content) {
11689
+ const firstLine = getFirstNonEmptyLine(content);
11690
+ if (!firstLine) {
11691
+ return INLINE_KNOWLEDGE_BASE_NAME;
11692
+ }
11693
+ const normalized = normalizeToKebabCase(firstLine);
11694
+ return normalized || INLINE_KNOWLEDGE_BASE_NAME;
11695
+ }
11696
+ /**
11697
+ * Creates a data URL that represents the inline knowledge content as a text file.
11698
+ *
11699
+ * @private thing of inline knowledge
11700
+ */
11701
+ function createInlineKnowledgeSourceFile(content) {
11702
+ const trimmedContent = content.trim();
11703
+ const baseName = deriveBaseFilename(trimmedContent);
11704
+ const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
11705
+ const mimeType = 'text/plain';
11706
+ const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
11707
+ const encodedFilename = encodeURIComponent(filename);
11708
+ const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
11709
+ return {
11710
+ filename,
11711
+ mimeType,
11712
+ url,
11713
+ };
11714
+ }
11715
+ /**
11716
+ * Checks whether the provided source string is a data URL that can be decoded.
11717
+ *
11718
+ * @private thing of inline knowledge
11719
+ */
11720
+ function isDataUrlKnowledgeSource(source) {
11721
+ return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
11722
+ }
11723
+ /**
11724
+ * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
11725
+ *
11726
+ * @private thing of inline knowledge
11727
+ */
11728
+ function parseDataUrlKnowledgeSource(source) {
11729
+ if (!isDataUrlKnowledgeSource(source)) {
11730
+ return null;
11731
+ }
11732
+ const commaIndex = source.indexOf(',');
11733
+ if (commaIndex === -1) {
11734
+ return null;
11735
+ }
11736
+ const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
11737
+ const payload = source.slice(commaIndex + 1);
11738
+ const tokens = header.split(';');
11739
+ const mediaType = tokens[0] || 'text/plain';
11740
+ let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
11741
+ let isBase64 = false;
11742
+ for (let i = 1; i < tokens.length; i++) {
11743
+ const token = tokens[i];
11744
+ if (!token) {
11745
+ continue;
11746
+ }
11747
+ if (token.toLowerCase() === 'base64') {
11748
+ isBase64 = true;
11749
+ continue;
11750
+ }
11751
+ const [key, value] = token.split('=');
11752
+ if (key === 'name' && value !== undefined) {
11753
+ try {
11754
+ filename = decodeURIComponent(value);
11755
+ }
11756
+ catch (_a) {
11757
+ filename = value;
11758
+ }
11759
+ }
11760
+ }
11761
+ if (!isBase64) {
11762
+ return null;
11763
+ }
11764
+ try {
11765
+ const buffer = Buffer.from(payload, 'base64');
11766
+ return {
11767
+ buffer,
11768
+ filename,
11769
+ mimeType: mediaType,
11770
+ };
11771
+ }
11772
+ catch (_b) {
11773
+ return null;
11774
+ }
11775
+ }
11776
+ /**
11777
+ * Note: [💞] Ignore a discrepancy between file name and entity name
11778
+ */
11779
+
11635
11780
  /**
11636
11781
  * KNOWLEDGE commitment definition
11637
11782
  *
@@ -11730,9 +11875,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
11730
11875
  return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
11731
11876
  }
11732
11877
  else {
11733
- // Direct text knowledge - add to system message
11734
- const knowledgeSection = `Knowledge: ${trimmedContent}`;
11735
- return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
11878
+ const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
11879
+ const updatedRequirements = {
11880
+ ...requirements,
11881
+ knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
11882
+ };
11883
+ const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
11884
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
11736
11885
  }
11737
11886
  }
11738
11887
  }
@@ -11979,16 +12128,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
11979
12128
  // and typically doesn't need to be added to the system prompt or model requirements directly.
11980
12129
  // It is extracted separately for the chat interface.
11981
12130
  var _a;
11982
- const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
12131
+ const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
11983
12132
  if (pendingUserMessage) {
11984
12133
  const newSample = { question: pendingUserMessage, answer: content };
11985
12134
  const newSamples = [...(requirements.samples || []), newSample];
11986
- const newMetadata = { ...requirements.metadata };
12135
+ const newMetadata = { ...requirements._metadata };
11987
12136
  delete newMetadata.pendingUserMessage;
11988
12137
  return {
11989
12138
  ...requirements,
11990
12139
  samples: newSamples,
11991
- metadata: newMetadata,
12140
+ _metadata: newMetadata,
11992
12141
  };
11993
12142
  }
11994
12143
  return requirements;
@@ -12236,8 +12385,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
12236
12385
  applyToAgentModelRequirements(requirements, content) {
12237
12386
  return {
12238
12387
  ...requirements,
12239
- metadata: {
12240
- ...requirements.metadata,
12388
+ _metadata: {
12389
+ ...requirements._metadata,
12241
12390
  pendingUserMessage: content,
12242
12391
  },
12243
12392
  };
@@ -13095,11 +13244,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
13095
13244
  if (trimmedContent === '') {
13096
13245
  return requirements;
13097
13246
  }
13098
- // Return requirements with updated notes but no changes to system message
13099
- return {
13100
- ...requirements,
13101
- notes: [...(requirements.notes || []), trimmedContent],
13102
- };
13247
+ return requirements;
13103
13248
  }
13104
13249
  }
13105
13250
  /**
@@ -13161,12 +13306,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
13161
13306
  // Since OPEN is default, we can just ensure isClosed is false
13162
13307
  // But to be explicit we can set it
13163
13308
  const updatedMetadata = {
13164
- ...requirements.metadata,
13309
+ ...requirements._metadata,
13165
13310
  isClosed: false,
13166
13311
  };
13167
13312
  return {
13168
13313
  ...requirements,
13169
- metadata: updatedMetadata,
13314
+ _metadata: updatedMetadata,
13170
13315
  };
13171
13316
  }
13172
13317
  }
@@ -13247,7 +13392,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
13247
13392
  return requirements;
13248
13393
  }
13249
13394
  // Get existing persona content from metadata
13250
- const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
13395
+ const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
13251
13396
  // Merge the new content with existing persona content
13252
13397
  // When multiple PERSONA commitments exist, they are merged into one
13253
13398
  const mergedPersonaContent = existingPersonaContent
@@ -13255,12 +13400,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
13255
13400
  : trimmedContent;
13256
13401
  // Store the merged persona content in metadata for debugging and inspection
13257
13402
  const updatedMetadata = {
13258
- ...requirements.metadata,
13403
+ ...requirements._metadata,
13259
13404
  PERSONA: mergedPersonaContent,
13260
13405
  };
13261
13406
  // Get the agent name from metadata (which should contain the first line of agent source)
13262
13407
  // If not available, extract from current system message as fallback
13263
- let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
13408
+ let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
13264
13409
  if (!agentName) {
13265
13410
  // Fallback: extract from current system message
13266
13411
  const currentMessage = requirements.systemMessage.trim();
@@ -13307,7 +13452,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
13307
13452
  return {
13308
13453
  ...requirements,
13309
13454
  systemMessage: newSystemMessage,
13310
- metadata: updatedMetadata,
13455
+ _metadata: updatedMetadata,
13311
13456
  };
13312
13457
  }
13313
13458
  }
@@ -13390,7 +13535,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
13390
13535
  }
13391
13536
  // Add rule to the system message
13392
13537
  const ruleSection = `Rule: ${trimmedContent}`;
13393
- return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
13538
+ const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
13539
+ const ruleLines = trimmedContent
13540
+ .split(/\r?\n/)
13541
+ .map((line) => line.trim())
13542
+ .filter(Boolean)
13543
+ .map((line) => `- ${line}`);
13544
+ if (ruleLines.length === 0) {
13545
+ return requirementsWithRule;
13546
+ }
13547
+ return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
13394
13548
  }
13395
13549
  }
13396
13550
  /**
@@ -13892,11 +14046,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
13892
14046
  if (!trimmedContent) {
13893
14047
  return requirements;
13894
14048
  }
13895
- const teammates = parseTeamCommitmentContent(trimmedContent, { strict: true });
14049
+ // Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
14050
+ const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
13896
14051
  if (teammates.length === 0) {
13897
14052
  return requirements;
13898
14053
  }
13899
- const agentName = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
14054
+ const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
13900
14055
  const teamEntries = teammates.map((teammate) => ({
13901
14056
  toolName: createTeamToolName(teammate.url),
13902
14057
  teammate,
@@ -13936,7 +14091,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
13936
14091
  },
13937
14092
  });
13938
14093
  }
13939
- const existingTeammates = ((_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
14094
+ const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
13940
14095
  const updatedTeammates = [...existingTeammates];
13941
14096
  for (const entry of teamEntries) {
13942
14097
  if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
@@ -13965,8 +14120,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
13965
14120
  return this.appendToSystemMessage({
13966
14121
  ...requirements,
13967
14122
  tools: updatedTools,
13968
- metadata: {
13969
- ...requirements.metadata,
14123
+ _metadata: {
14124
+ ...requirements._metadata,
13970
14125
  teammates: updatedTeammates,
13971
14126
  },
13972
14127
  }, teamSystemMessage);
@@ -14198,7 +14353,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
14198
14353
  if (!trimmedContent) {
14199
14354
  // Store template mode flag in metadata
14200
14355
  const updatedMetadata = {
14201
- ...requirements.metadata,
14356
+ ...requirements._metadata,
14202
14357
  templateMode: true,
14203
14358
  };
14204
14359
  // Add a general instruction about using structured templates
@@ -14208,21 +14363,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
14208
14363
  `);
14209
14364
  return {
14210
14365
  ...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
14211
- metadata: updatedMetadata,
14366
+ _metadata: updatedMetadata,
14212
14367
  };
14213
14368
  }
14214
14369
  // If content is provided, add the specific template instructions
14215
14370
  const templateSection = `Response Template: ${trimmedContent}`;
14216
14371
  // Store the template in metadata for potential programmatic access
14217
- const existingTemplates = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
14372
+ const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
14218
14373
  const updatedMetadata = {
14219
- ...requirements.metadata,
14374
+ ...requirements._metadata,
14220
14375
  templates: [...existingTemplates, trimmedContent],
14221
14376
  templateMode: true,
14222
14377
  };
14223
14378
  return {
14224
14379
  ...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
14225
- metadata: updatedMetadata,
14380
+ _metadata: updatedMetadata,
14226
14381
  };
14227
14382
  }
14228
14383
  }
@@ -14559,8 +14714,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
14559
14714
  return this.appendToSystemMessage({
14560
14715
  ...requirements,
14561
14716
  tools: updatedTools,
14562
- metadata: {
14563
- ...requirements.metadata,
14717
+ _metadata: {
14718
+ ...requirements._metadata,
14564
14719
  useBrowser: true,
14565
14720
  },
14566
14721
  }, spaceTrim$1(`
@@ -14789,8 +14944,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
14789
14944
  return this.appendToSystemMessage({
14790
14945
  ...requirements,
14791
14946
  tools: updatedTools,
14792
- metadata: {
14793
- ...requirements.metadata,
14947
+ _metadata: {
14948
+ ...requirements._metadata,
14794
14949
  useEmail: content || true,
14795
14950
  },
14796
14951
  }, spaceTrim$1((block) => `
@@ -14925,8 +15080,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
14925
15080
  return this.appendToSystemMessage({
14926
15081
  ...requirements,
14927
15082
  tools: updatedTools,
14928
- metadata: {
14929
- ...requirements.metadata,
15083
+ _metadata: {
15084
+ ...requirements._metadata,
14930
15085
  useImageGenerator: content || true,
14931
15086
  },
14932
15087
  }, spaceTrim$1(`
@@ -15217,8 +15372,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
15217
15372
  return this.appendToSystemMessage({
15218
15373
  ...requirements,
15219
15374
  tools: updatedTools,
15220
- metadata: {
15221
- ...requirements.metadata,
15375
+ _metadata: {
15376
+ ...requirements._metadata,
15222
15377
  useSearchEngine: content || true,
15223
15378
  },
15224
15379
  }, spaceTrim$1((block) => `
@@ -15366,8 +15521,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
15366
15521
  return this.appendToSystemMessage({
15367
15522
  ...requirements,
15368
15523
  tools: updatedTools,
15369
- metadata: {
15370
- ...requirements.metadata,
15524
+ _metadata: {
15525
+ ...requirements._metadata,
15371
15526
  },
15372
15527
  }, spaceTrim$1((block) => `
15373
15528
  Time and date context:
@@ -18086,11 +18241,14 @@ function asUpdatableSubject(value) {
18086
18241
  function createEmptyAgentModelRequirements() {
18087
18242
  return {
18088
18243
  systemMessage: '',
18244
+ promptSuffix: '',
18089
18245
  // modelName: 'gpt-5',
18090
18246
  modelName: 'gemini-2.5-flash-lite',
18091
18247
  temperature: 0.7,
18092
18248
  topP: 0.9,
18093
18249
  topK: 50,
18250
+ parentAgentUrl: null,
18251
+ isClosed: false,
18094
18252
  };
18095
18253
  }
18096
18254
  /**
@@ -18236,14 +18394,42 @@ function removeCommentsFromSystemMessage(systemMessage) {
18236
18394
  }
18237
18395
 
18238
18396
  /**
18239
- * Creates agent model requirements using the new commitment system
18397
+ * Creates agent model requirements using the new commitment system.
18398
+ *
18240
18399
  * This function uses a reduce-like pattern where each commitment applies its changes
18241
- * to build the final requirements starting from a basic empty model
18400
+ * to build the final requirements starting from a basic empty model.
18242
18401
  *
18243
- * @public exported from `@promptbook/core`
18402
+ * @param agentSource - Agent source book to parse.
18403
+ * @param modelName - Optional override for the agent model name.
18404
+ * @param options - Additional options such as the agent reference resolver.
18405
+ *
18406
+ * @private @@@
18407
+ */
18408
+ const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
18409
+ /**
18410
+ * Returns a safe fallback content when a resolver fails to transform a reference commitment.
18411
+ *
18412
+ * @param commitmentType - Commitment being resolved.
18413
+ * @param originalContent - Original unresolved commitment content.
18414
+ * @returns Fallback content that keeps requirement creation resilient.
18415
+ */
18416
+ function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
18417
+ if (commitmentType === 'FROM') {
18418
+ return 'VOID';
18419
+ }
18420
+ if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
18421
+ return '';
18422
+ }
18423
+ return originalContent;
18424
+ }
18425
+ /**
18426
+ * @@@
18427
+ *
18428
+ * @private @@@
18244
18429
  */
18245
- async function createAgentModelRequirementsWithCommitments(agentSource, modelName) {
18430
+ async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
18246
18431
  var _a;
18432
+ const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
18247
18433
  // Parse the agent source to extract commitments
18248
18434
  const parseResult = parseAgentSourceWithCommitments(agentSource);
18249
18435
  // Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
@@ -18280,8 +18466,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
18280
18466
  // Store the agent name in metadata so commitments can access it
18281
18467
  requirements = {
18282
18468
  ...requirements,
18283
- metadata: {
18284
- ...requirements.metadata,
18469
+ _metadata: {
18470
+ ...requirements._metadata,
18285
18471
  agentName: parseResult.agentName,
18286
18472
  },
18287
18473
  };
@@ -18295,6 +18481,17 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
18295
18481
  // Apply each commitment in order using reduce-like pattern
18296
18482
  for (let i = 0; i < filteredCommitments.length; i++) {
18297
18483
  const commitment = filteredCommitments[i];
18484
+ const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
18485
+ let commitmentContent = commitment.content;
18486
+ if (isReferenceCommitment && agentReferenceResolver) {
18487
+ try {
18488
+ commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
18489
+ }
18490
+ catch (error) {
18491
+ console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
18492
+ commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
18493
+ }
18494
+ }
18298
18495
  // CLOSED commitment should work only if its the last commitment in the book
18299
18496
  if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
18300
18497
  continue;
@@ -18302,7 +18499,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
18302
18499
  const definition = getCommitmentDefinition(commitment.type);
18303
18500
  if (definition) {
18304
18501
  try {
18305
- requirements = definition.applyToAgentModelRequirements(requirements, commitment.content);
18502
+ requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
18306
18503
  }
18307
18504
  catch (error) {
18308
18505
  console.warn(`Failed to apply commitment ${commitment.type}:`, error);
@@ -18450,23 +18647,28 @@ function isBinaryMimeType(mimeType) {
18450
18647
  }
18451
18648
 
18452
18649
  /**
18453
- * Creates model requirements for an agent based on its source
18650
+ * Creates model requirements for an agent based on its source.
18454
18651
  *
18455
18652
  * There are 2 similar functions:
18456
18653
  * - `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.
18457
18654
  * - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
18458
18655
  *
18656
+ * @param agentSource - Book describing the agent.
18657
+ * @param modelName - Optional override for the agent's model.
18658
+ * @param availableModels - Models that could fulfill the agent.
18659
+ * @param llmTools - Execution tools used when selecting a best model.
18660
+ * @param options - Optional hooks such as the agent reference resolver.
18459
18661
  * @public exported from `@promptbook/core`
18460
18662
  */
18461
- async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
18663
+ async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
18462
18664
  // If availableModels are provided and no specific modelName is given,
18463
18665
  // use preparePersona to select the best model
18464
18666
  if (availableModels && !modelName && llmTools) {
18465
18667
  const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
18466
- return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
18668
+ return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
18467
18669
  }
18468
18670
  // Use the new commitment-based system with provided or default model
18469
- return createAgentModelRequirementsWithCommitments(agentSource, modelName);
18671
+ return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
18470
18672
  }
18471
18673
  /**
18472
18674
  * Selects the best model using the preparePersona function
@@ -18764,6 +18966,66 @@ const OPENAI_MODELS = exportJson({
18764
18966
  },
18765
18967
  /**/
18766
18968
  /**/
18969
+ {
18970
+ modelVariant: 'CHAT',
18971
+ modelTitle: 'gpt-5.2-codex',
18972
+ modelName: 'gpt-5.2-codex',
18973
+ 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.',
18974
+ pricing: {
18975
+ prompt: pricing(`$1.75 / 1M tokens`),
18976
+ output: pricing(`$14.00 / 1M tokens`),
18977
+ },
18978
+ },
18979
+ /**/
18980
+ /**/
18981
+ {
18982
+ modelVariant: 'CHAT',
18983
+ modelTitle: 'gpt-5.1-codex-max',
18984
+ modelName: 'gpt-5.1-codex-max',
18985
+ modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
18986
+ pricing: {
18987
+ prompt: pricing(`$1.25 / 1M tokens`),
18988
+ output: pricing(`$10.00 / 1M tokens`),
18989
+ },
18990
+ },
18991
+ /**/
18992
+ /**/
18993
+ {
18994
+ modelVariant: 'CHAT',
18995
+ modelTitle: 'gpt-5.1-codex',
18996
+ modelName: 'gpt-5.1-codex',
18997
+ modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
18998
+ pricing: {
18999
+ prompt: pricing(`$1.25 / 1M tokens`),
19000
+ output: pricing(`$10.00 / 1M tokens`),
19001
+ },
19002
+ },
19003
+ /**/
19004
+ /**/
19005
+ {
19006
+ modelVariant: 'CHAT',
19007
+ modelTitle: 'gpt-5.1-codex-mini',
19008
+ modelName: 'gpt-5.1-codex-mini',
19009
+ modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
19010
+ pricing: {
19011
+ prompt: pricing(`$0.25 / 1M tokens`),
19012
+ output: pricing(`$2.00 / 1M tokens`),
19013
+ },
19014
+ },
19015
+ /**/
19016
+ /**/
19017
+ {
19018
+ modelVariant: 'CHAT',
19019
+ modelTitle: 'gpt-5-codex',
19020
+ modelName: 'gpt-5-codex',
19021
+ modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
19022
+ pricing: {
19023
+ prompt: pricing(`$1.25 / 1M tokens`),
19024
+ output: pricing(`$10.00 / 1M tokens`),
19025
+ },
19026
+ },
19027
+ /**/
19028
+ /**/
18767
19029
  {
18768
19030
  modelVariant: 'CHAT',
18769
19031
  modelTitle: 'gpt-5-mini',
@@ -19468,6 +19730,32 @@ function isUnsupportedParameterError(error) {
19468
19730
  errorMessage.includes('does not support'));
19469
19731
  }
19470
19732
 
19733
+ /**
19734
+ * Provides access to the structured clone implementation when available.
19735
+ */
19736
+ function getStructuredCloneFunction() {
19737
+ return globalThis.structuredClone;
19738
+ }
19739
+ /**
19740
+ * Checks whether the prompt is a chat prompt that carries file attachments.
19741
+ */
19742
+ function hasChatPromptFiles(prompt) {
19743
+ return 'files' in prompt && Array.isArray(prompt.files);
19744
+ }
19745
+ /**
19746
+ * Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
19747
+ */
19748
+ function clonePromptPreservingFiles(prompt) {
19749
+ const structuredCloneFn = getStructuredCloneFunction();
19750
+ if (typeof structuredCloneFn === 'function') {
19751
+ return structuredCloneFn(prompt);
19752
+ }
19753
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
19754
+ if (hasChatPromptFiles(prompt)) {
19755
+ clonedPrompt.files = prompt.files;
19756
+ }
19757
+ return clonedPrompt;
19758
+ }
19471
19759
  /**
19472
19760
  * Execution Tools for calling OpenAI API or other OpenAI compatible provider
19473
19761
  *
@@ -19552,7 +19840,7 @@ class OpenAiCompatibleExecutionTools {
19552
19840
  */
19553
19841
  async callChatModelStream(prompt, onProgress) {
19554
19842
  // Deep clone prompt and modelRequirements to avoid mutation across calls
19555
- const clonedPrompt = JSON.parse(JSON.stringify(prompt));
19843
+ const clonedPrompt = clonePromptPreservingFiles(prompt);
19556
19844
  // Use local Set for retried parameters to ensure independence and thread safety
19557
19845
  const retriedUnsupportedParameters = new Set();
19558
19846
  return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
@@ -19579,7 +19867,10 @@ class OpenAiCompatibleExecutionTools {
19579
19867
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
19580
19868
  // <- Note: [🧆]
19581
19869
  }; // <- TODO: [💩] Guard here types better
19582
- if (format === 'JSON') {
19870
+ if (currentModelRequirements.responseFormat !== undefined) {
19871
+ modelSettings.response_format = currentModelRequirements.responseFormat;
19872
+ }
19873
+ else if (format === 'JSON') {
19583
19874
  modelSettings.response_format = {
19584
19875
  type: 'json_object',
19585
19876
  };
@@ -21060,7 +21351,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
21060
21351
  const processingStartedAtMs = Date.now();
21061
21352
  for (const [index, source] of knowledgeSources.entries()) {
21062
21353
  try {
21063
- const sourceType = source.startsWith('http') || source.startsWith('https') ? 'url' : 'file';
21354
+ const isDataUrl = isDataUrlKnowledgeSource(source);
21355
+ const isHttp = source.startsWith('http://') || source.startsWith('https://');
21356
+ const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
21064
21357
  if (this.options.isVerbose) {
21065
21358
  console.info('[🤰]', 'Processing knowledge source', {
21066
21359
  index: index + 1,
@@ -21070,8 +21363,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
21070
21363
  logLabel,
21071
21364
  });
21072
21365
  }
21073
- // Check if it's a URL
21074
- if (source.startsWith('http://') || source.startsWith('https://')) {
21366
+ if (isDataUrl) {
21367
+ const parsed = parseDataUrlKnowledgeSource(source);
21368
+ if (!parsed) {
21369
+ skippedSources.push({ source, reason: 'invalid_data_url' });
21370
+ if (this.options.isVerbose) {
21371
+ console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
21372
+ source,
21373
+ sourceType,
21374
+ logLabel,
21375
+ });
21376
+ }
21377
+ continue;
21378
+ }
21379
+ const dataUrlFile = new File([parsed.buffer], parsed.filename, {
21380
+ type: parsed.mimeType,
21381
+ });
21382
+ fileStreams.push(dataUrlFile);
21383
+ totalBytes += parsed.buffer.length;
21384
+ continue;
21385
+ }
21386
+ if (isHttp) {
21075
21387
  const downloadResult = await this.downloadKnowledgeSourceFile({
21076
21388
  source,
21077
21389
  timeoutMs: downloadTimeoutMs,
@@ -21173,6 +21485,64 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
21173
21485
  }
21174
21486
 
21175
21487
  const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
21488
+ const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
21489
+ /*
21490
+ TODO: Use or remove
21491
+ const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
21492
+ type: 'object',
21493
+ properties: {},
21494
+ required: [],
21495
+ additionalProperties: true,
21496
+ };
21497
+ */
21498
+ function buildJsonSchemaDefinition(jsonSchema) {
21499
+ var _a, _b, _c;
21500
+ const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
21501
+ return {
21502
+ type: 'json_schema',
21503
+ name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
21504
+ strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
21505
+ schema: {
21506
+ type: 'object',
21507
+ properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
21508
+ required: Array.isArray(schema.required) ? schema.required : [],
21509
+ additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
21510
+ description: schema.description,
21511
+ },
21512
+ };
21513
+ }
21514
+ /**
21515
+ * Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
21516
+ * structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
21517
+ *
21518
+ * @param responseFormat - The OpenAI `response_format` payload from the user request.
21519
+ * @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
21520
+ * @private utility of Open AI
21521
+ */
21522
+ function mapResponseFormatToAgentOutputType(responseFormat) {
21523
+ if (!responseFormat) {
21524
+ return undefined;
21525
+ }
21526
+ if (typeof responseFormat === 'string') {
21527
+ if (responseFormat === 'text') {
21528
+ return 'text';
21529
+ }
21530
+ if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
21531
+ return buildJsonSchemaDefinition();
21532
+ }
21533
+ return 'text';
21534
+ }
21535
+ switch (responseFormat.type) {
21536
+ case 'text':
21537
+ return 'text';
21538
+ case 'json_schema':
21539
+ return buildJsonSchemaDefinition(responseFormat.json_schema);
21540
+ case 'json_object':
21541
+ return buildJsonSchemaDefinition();
21542
+ default:
21543
+ return undefined;
21544
+ }
21545
+ }
21176
21546
  /**
21177
21547
  * Execution tools for OpenAI AgentKit (Agents SDK).
21178
21548
  *
@@ -21220,6 +21590,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
21220
21590
  ...parameters,
21221
21591
  modelName: this.agentKitModelName,
21222
21592
  });
21593
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
21223
21594
  const preparedAgentKitAgent = await this.prepareAgentKitAgent({
21224
21595
  name: (prompt.title || 'Agent'),
21225
21596
  instructions: modelRequirements.systemMessage || '',
@@ -21231,6 +21602,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
21231
21602
  prompt,
21232
21603
  rawPromptContent,
21233
21604
  onProgress,
21605
+ responseFormatOutputType,
21234
21606
  });
21235
21607
  }
21236
21608
  /**
@@ -21412,16 +21784,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
21412
21784
  ...prompt.parameters,
21413
21785
  modelName: this.agentKitModelName,
21414
21786
  });
21787
+ const agentForRun = options.responseFormatOutputType !== undefined
21788
+ ? openAiAgentKitAgent.clone({
21789
+ outputType: options.responseFormatOutputType,
21790
+ })
21791
+ : openAiAgentKitAgent;
21415
21792
  const start = $getCurrentDate();
21416
21793
  let latestContent = '';
21417
21794
  const toolCalls = [];
21418
21795
  const toolCallIndexById = new Map();
21419
21796
  const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
21420
21797
  const rawRequest = {
21421
- agentName: openAiAgentKitAgent.name,
21798
+ agentName: agentForRun.name,
21422
21799
  input: inputItems,
21423
21800
  };
21424
- const streamResult = await run(openAiAgentKitAgent, inputItems, {
21801
+ const streamResult = await run(agentForRun, inputItems, {
21425
21802
  stream: true,
21426
21803
  context: { parameters: prompt.parameters },
21427
21804
  });
@@ -22410,22 +22787,28 @@ class AgentLlmExecutionTools {
22410
22787
  throw new Error('AgentLlmExecutionTools only supports chat prompts');
22411
22788
  }
22412
22789
  const modelRequirements = await this.getModelRequirements();
22790
+ const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
22413
22791
  const chatPrompt = prompt;
22414
22792
  let underlyingLlmResult;
22415
- // Create modified chat prompt with agent system message
22793
+ const chatPromptContentWithSuffix = promptSuffix
22794
+ ? `${chatPrompt.content}\n\n${promptSuffix}`
22795
+ : chatPrompt.content;
22416
22796
  const promptWithAgentModelRequirements = {
22417
22797
  ...chatPrompt,
22798
+ content: chatPromptContentWithSuffix,
22418
22799
  modelRequirements: {
22419
22800
  ...chatPrompt.modelRequirements,
22420
- ...modelRequirements,
22801
+ ...sanitizedRequirements,
22421
22802
  // Spread tools to convert readonly array to mutable
22422
- tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
22803
+ tools: sanitizedRequirements.tools
22804
+ ? [...sanitizedRequirements.tools]
22805
+ : chatPrompt.modelRequirements.tools,
22423
22806
  // Spread knowledgeSources to convert readonly array to mutable
22424
- knowledgeSources: modelRequirements.knowledgeSources
22425
- ? [...modelRequirements.knowledgeSources]
22807
+ knowledgeSources: sanitizedRequirements.knowledgeSources
22808
+ ? [...sanitizedRequirements.knowledgeSources]
22426
22809
  : undefined,
22427
22810
  // Prepend agent system message to existing system message
22428
- systemMessage: modelRequirements.systemMessage +
22811
+ systemMessage: sanitizedRequirements.systemMessage +
22429
22812
  (chatPrompt.modelRequirements.systemMessage
22430
22813
  ? `\n\n${chatPrompt.modelRequirements.systemMessage}`
22431
22814
  : ''),
@@ -22433,8 +22816,8 @@ class AgentLlmExecutionTools {
22433
22816
  };
22434
22817
  console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
22435
22818
  if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
22436
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
22437
- const vectorStoreHash = SHA256(JSON.stringify((_a = modelRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
22819
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
22820
+ const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
22438
22821
  const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
22439
22822
  const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
22440
22823
  let preparedAgentKit = this.options.assistantPreparationMode === 'external'
@@ -22461,7 +22844,7 @@ class AgentLlmExecutionTools {
22461
22844
  agent: this.title,
22462
22845
  });
22463
22846
  }
22464
- if (!vectorStoreId && ((_b = modelRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
22847
+ if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
22465
22848
  emitAssistantPreparationProgress({
22466
22849
  onProgress,
22467
22850
  prompt,
@@ -22477,9 +22860,9 @@ class AgentLlmExecutionTools {
22477
22860
  });
22478
22861
  preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
22479
22862
  name: this.title,
22480
- instructions: modelRequirements.systemMessage || '',
22481
- knowledgeSources: modelRequirements.knowledgeSources,
22482
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22863
+ instructions: sanitizedRequirements.systemMessage || '',
22864
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22865
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22483
22866
  vectorStoreId,
22484
22867
  });
22485
22868
  }
@@ -22494,15 +22877,17 @@ class AgentLlmExecutionTools {
22494
22877
  requirementsHash,
22495
22878
  vectorStoreId: preparedAgentKit.vectorStoreId,
22496
22879
  });
22880
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
22497
22881
  underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
22498
22882
  openAiAgentKitAgent: preparedAgentKit.agent,
22499
22883
  prompt: promptWithAgentModelRequirements,
22500
22884
  onProgress,
22885
+ responseFormatOutputType,
22501
22886
  });
22502
22887
  }
22503
22888
  else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
22504
22889
  // ... deprecated path ...
22505
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
22890
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
22506
22891
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
22507
22892
  let assistant;
22508
22893
  if (this.options.assistantPreparationMode === 'external') {
@@ -22544,9 +22929,9 @@ class AgentLlmExecutionTools {
22544
22929
  assistant = await this.options.llmTools.updateAssistant({
22545
22930
  assistantId: cached.assistantId,
22546
22931
  name: this.title,
22547
- instructions: modelRequirements.systemMessage,
22548
- knowledgeSources: modelRequirements.knowledgeSources,
22549
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22932
+ instructions: sanitizedRequirements.systemMessage,
22933
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22934
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22550
22935
  });
22551
22936
  AgentLlmExecutionTools.assistantCache.set(this.title, {
22552
22937
  assistantId: assistant.assistantId,
@@ -22569,9 +22954,9 @@ class AgentLlmExecutionTools {
22569
22954
  });
22570
22955
  assistant = await this.options.llmTools.createNewAssistant({
22571
22956
  name: this.title,
22572
- instructions: modelRequirements.systemMessage,
22573
- knowledgeSources: modelRequirements.knowledgeSources,
22574
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22957
+ instructions: sanitizedRequirements.systemMessage,
22958
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22959
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22575
22960
  /*
22576
22961
  !!!
22577
22962
  metadata: {
@@ -22613,13 +22998,19 @@ class AgentLlmExecutionTools {
22613
22998
  }
22614
22999
  }
22615
23000
  let content = underlyingLlmResult.content;
22616
- // Note: Cleanup the AI artifacts from the content
22617
- content = humanizeAiText(content);
22618
- // Note: Make sure the content is Promptbook-like
22619
- content = promptbookifyAiText(content);
23001
+ if (typeof content === 'string') {
23002
+ // Note: Cleanup the AI artifacts from the content
23003
+ content = humanizeAiText(content);
23004
+ // Note: Make sure the content is Promptbook-like
23005
+ content = promptbookifyAiText(content);
23006
+ }
23007
+ else {
23008
+ // TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
23009
+ content = JSON.stringify(content);
23010
+ }
22620
23011
  const agentResult = {
22621
23012
  ...underlyingLlmResult,
22622
- content,
23013
+ content: content,
22623
23014
  modelName: this.modelName,
22624
23015
  };
22625
23016
  return agentResult;
@@ -22808,7 +23199,6 @@ class Agent extends AgentLlmExecutionTools {
22808
23199
  * Note: This method also implements the learning mechanism
22809
23200
  */
22810
23201
  async callChatModelStream(prompt, onProgress) {
22811
- var _a;
22812
23202
  // [1] Check if the user is asking the same thing as in the samples
22813
23203
  const modelRequirements = await this.getModelRequirements();
22814
23204
  if (modelRequirements.samples) {
@@ -22856,7 +23246,7 @@ class Agent extends AgentLlmExecutionTools {
22856
23246
  if (result.rawResponse && 'sample' in result.rawResponse) {
22857
23247
  return result;
22858
23248
  }
22859
- if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
23249
+ if (modelRequirements.isClosed) {
22860
23250
  return result;
22861
23251
  }
22862
23252
  // Note: [0] Notify start of self-learning