@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/umd/index.umd.js CHANGED
@@ -50,7 +50,7 @@
50
50
  * @generated
51
51
  * @see https://github.com/webgptorg/promptbook
52
52
  */
53
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-8';
53
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
54
54
  /**
55
55
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
56
56
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -10811,6 +10811,28 @@
10811
10811
  return currentMessage + separator + content;
10812
10812
  });
10813
10813
  }
10814
+ /**
10815
+ * Helper method to create a new requirements object with updated prompt suffix
10816
+ */
10817
+ updatePromptSuffix(requirements, contentUpdate) {
10818
+ const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
10819
+ return {
10820
+ ...requirements,
10821
+ promptSuffix: newSuffix,
10822
+ };
10823
+ }
10824
+ /**
10825
+ * Helper method to append content to the prompt suffix
10826
+ * Default separator is a single newline for bullet lists.
10827
+ */
10828
+ appendToPromptSuffix(requirements, content, separator = '\n') {
10829
+ return this.updatePromptSuffix(requirements, (currentSuffix) => {
10830
+ if (!currentSuffix.trim()) {
10831
+ return content;
10832
+ }
10833
+ return `${currentSuffix}${separator}${content}`;
10834
+ });
10835
+ }
10814
10836
  /**
10815
10837
  * Helper method to add a comment section to the system message
10816
10838
  * Comments are lines starting with # that will be removed from the final system message
@@ -10988,13 +11010,9 @@
10988
11010
  `);
10989
11011
  }
10990
11012
  applyToAgentModelRequirements(requirements, _content) {
10991
- const updatedMetadata = {
10992
- ...requirements.metadata,
10993
- isClosed: true,
10994
- };
10995
11013
  return {
10996
11014
  ...requirements,
10997
- metadata: updatedMetadata,
11015
+ isClosed: true,
10998
11016
  };
10999
11017
  }
11000
11018
  }
@@ -11272,12 +11290,12 @@
11272
11290
  return requirements;
11273
11291
  }
11274
11292
  // Get existing dictionary entries from metadata
11275
- const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
11293
+ const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
11276
11294
  // Merge the new dictionary entry with existing entries
11277
11295
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
11278
11296
  // Store the merged dictionary in metadata for debugging and inspection
11279
11297
  const updatedMetadata = {
11280
- ...requirements.metadata,
11298
+ ...requirements._metadata,
11281
11299
  DICTIONARY: mergedDictionary,
11282
11300
  };
11283
11301
  // Create the dictionary section for the system message
@@ -11285,7 +11303,7 @@
11285
11303
  const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
11286
11304
  return {
11287
11305
  ...this.appendToSystemMessage(requirements, dictionarySection),
11288
- metadata: updatedMetadata,
11306
+ _metadata: updatedMetadata,
11289
11307
  };
11290
11308
  }
11291
11309
  }
@@ -11425,10 +11443,7 @@
11425
11443
  applyToAgentModelRequirements(requirements, content) {
11426
11444
  const trimmedContent = content.trim();
11427
11445
  if (!trimmedContent) {
11428
- return {
11429
- ...requirements,
11430
- parentAgentUrl: undefined,
11431
- };
11446
+ return requirements;
11432
11447
  }
11433
11448
  if (trimmedContent.toUpperCase() === 'VOID' ||
11434
11449
  trimmedContent.toUpperCase() === 'NULL' ||
@@ -11642,6 +11657,136 @@
11642
11657
  * Note: [💞] Ignore a discrepancy between file name and entity name
11643
11658
  */
11644
11659
 
11660
+ /**
11661
+ * @@@
11662
+ *
11663
+ * @private thing of inline knowledge
11664
+ */
11665
+ const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
11666
+ /**
11667
+ * @@@
11668
+ *
11669
+ * @private thing of inline knowledge
11670
+ */
11671
+ const INLINE_KNOWLEDGE_EXTENSION = '.txt';
11672
+ /**
11673
+ * @@@
11674
+ *
11675
+ * @private thing of inline knowledge
11676
+ */
11677
+ const DATA_URL_PREFIX = 'data:';
11678
+ /**
11679
+ * @@@
11680
+ *
11681
+ * @private thing of inline knowledge
11682
+ */
11683
+ function getFirstNonEmptyLine(content) {
11684
+ const lines = content.split(/\r?\n/);
11685
+ for (const line of lines) {
11686
+ const trimmed = line.trim();
11687
+ if (trimmed) {
11688
+ return trimmed;
11689
+ }
11690
+ }
11691
+ return null;
11692
+ }
11693
+ /**
11694
+ * @@@
11695
+ *
11696
+ * @private thing of inline knowledge
11697
+ */
11698
+ function deriveBaseFilename(content) {
11699
+ const firstLine = getFirstNonEmptyLine(content);
11700
+ if (!firstLine) {
11701
+ return INLINE_KNOWLEDGE_BASE_NAME;
11702
+ }
11703
+ const normalized = normalizeToKebabCase(firstLine);
11704
+ return normalized || INLINE_KNOWLEDGE_BASE_NAME;
11705
+ }
11706
+ /**
11707
+ * Creates a data URL that represents the inline knowledge content as a text file.
11708
+ *
11709
+ * @private thing of inline knowledge
11710
+ */
11711
+ function createInlineKnowledgeSourceFile(content) {
11712
+ const trimmedContent = content.trim();
11713
+ const baseName = deriveBaseFilename(trimmedContent);
11714
+ const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
11715
+ const mimeType = 'text/plain';
11716
+ const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
11717
+ const encodedFilename = encodeURIComponent(filename);
11718
+ const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
11719
+ return {
11720
+ filename,
11721
+ mimeType,
11722
+ url,
11723
+ };
11724
+ }
11725
+ /**
11726
+ * Checks whether the provided source string is a data URL that can be decoded.
11727
+ *
11728
+ * @private thing of inline knowledge
11729
+ */
11730
+ function isDataUrlKnowledgeSource(source) {
11731
+ return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
11732
+ }
11733
+ /**
11734
+ * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
11735
+ *
11736
+ * @private thing of inline knowledge
11737
+ */
11738
+ function parseDataUrlKnowledgeSource(source) {
11739
+ if (!isDataUrlKnowledgeSource(source)) {
11740
+ return null;
11741
+ }
11742
+ const commaIndex = source.indexOf(',');
11743
+ if (commaIndex === -1) {
11744
+ return null;
11745
+ }
11746
+ const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
11747
+ const payload = source.slice(commaIndex + 1);
11748
+ const tokens = header.split(';');
11749
+ const mediaType = tokens[0] || 'text/plain';
11750
+ let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
11751
+ let isBase64 = false;
11752
+ for (let i = 1; i < tokens.length; i++) {
11753
+ const token = tokens[i];
11754
+ if (!token) {
11755
+ continue;
11756
+ }
11757
+ if (token.toLowerCase() === 'base64') {
11758
+ isBase64 = true;
11759
+ continue;
11760
+ }
11761
+ const [key, value] = token.split('=');
11762
+ if (key === 'name' && value !== undefined) {
11763
+ try {
11764
+ filename = decodeURIComponent(value);
11765
+ }
11766
+ catch (_a) {
11767
+ filename = value;
11768
+ }
11769
+ }
11770
+ }
11771
+ if (!isBase64) {
11772
+ return null;
11773
+ }
11774
+ try {
11775
+ const buffer = Buffer.from(payload, 'base64');
11776
+ return {
11777
+ buffer,
11778
+ filename,
11779
+ mimeType: mediaType,
11780
+ };
11781
+ }
11782
+ catch (_b) {
11783
+ return null;
11784
+ }
11785
+ }
11786
+ /**
11787
+ * Note: [💞] Ignore a discrepancy between file name and entity name
11788
+ */
11789
+
11645
11790
  /**
11646
11791
  * KNOWLEDGE commitment definition
11647
11792
  *
@@ -11740,9 +11885,13 @@
11740
11885
  return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
11741
11886
  }
11742
11887
  else {
11743
- // Direct text knowledge - add to system message
11744
- const knowledgeSection = `Knowledge: ${trimmedContent}`;
11745
- return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
11888
+ const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
11889
+ const updatedRequirements = {
11890
+ ...requirements,
11891
+ knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
11892
+ };
11893
+ const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
11894
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
11746
11895
  }
11747
11896
  }
11748
11897
  }
@@ -11989,16 +12138,16 @@
11989
12138
  // and typically doesn't need to be added to the system prompt or model requirements directly.
11990
12139
  // It is extracted separately for the chat interface.
11991
12140
  var _a;
11992
- const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
12141
+ const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
11993
12142
  if (pendingUserMessage) {
11994
12143
  const newSample = { question: pendingUserMessage, answer: content };
11995
12144
  const newSamples = [...(requirements.samples || []), newSample];
11996
- const newMetadata = { ...requirements.metadata };
12145
+ const newMetadata = { ...requirements._metadata };
11997
12146
  delete newMetadata.pendingUserMessage;
11998
12147
  return {
11999
12148
  ...requirements,
12000
12149
  samples: newSamples,
12001
- metadata: newMetadata,
12150
+ _metadata: newMetadata,
12002
12151
  };
12003
12152
  }
12004
12153
  return requirements;
@@ -12246,8 +12395,8 @@
12246
12395
  applyToAgentModelRequirements(requirements, content) {
12247
12396
  return {
12248
12397
  ...requirements,
12249
- metadata: {
12250
- ...requirements.metadata,
12398
+ _metadata: {
12399
+ ...requirements._metadata,
12251
12400
  pendingUserMessage: content,
12252
12401
  },
12253
12402
  };
@@ -13105,11 +13254,7 @@
13105
13254
  if (trimmedContent === '') {
13106
13255
  return requirements;
13107
13256
  }
13108
- // Return requirements with updated notes but no changes to system message
13109
- return {
13110
- ...requirements,
13111
- notes: [...(requirements.notes || []), trimmedContent],
13112
- };
13257
+ return requirements;
13113
13258
  }
13114
13259
  }
13115
13260
  /**
@@ -13171,12 +13316,12 @@
13171
13316
  // Since OPEN is default, we can just ensure isClosed is false
13172
13317
  // But to be explicit we can set it
13173
13318
  const updatedMetadata = {
13174
- ...requirements.metadata,
13319
+ ...requirements._metadata,
13175
13320
  isClosed: false,
13176
13321
  };
13177
13322
  return {
13178
13323
  ...requirements,
13179
- metadata: updatedMetadata,
13324
+ _metadata: updatedMetadata,
13180
13325
  };
13181
13326
  }
13182
13327
  }
@@ -13257,7 +13402,7 @@
13257
13402
  return requirements;
13258
13403
  }
13259
13404
  // Get existing persona content from metadata
13260
- const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
13405
+ const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
13261
13406
  // Merge the new content with existing persona content
13262
13407
  // When multiple PERSONA commitments exist, they are merged into one
13263
13408
  const mergedPersonaContent = existingPersonaContent
@@ -13265,12 +13410,12 @@
13265
13410
  : trimmedContent;
13266
13411
  // Store the merged persona content in metadata for debugging and inspection
13267
13412
  const updatedMetadata = {
13268
- ...requirements.metadata,
13413
+ ...requirements._metadata,
13269
13414
  PERSONA: mergedPersonaContent,
13270
13415
  };
13271
13416
  // Get the agent name from metadata (which should contain the first line of agent source)
13272
13417
  // If not available, extract from current system message as fallback
13273
- let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
13418
+ let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
13274
13419
  if (!agentName) {
13275
13420
  // Fallback: extract from current system message
13276
13421
  const currentMessage = requirements.systemMessage.trim();
@@ -13317,7 +13462,7 @@
13317
13462
  return {
13318
13463
  ...requirements,
13319
13464
  systemMessage: newSystemMessage,
13320
- metadata: updatedMetadata,
13465
+ _metadata: updatedMetadata,
13321
13466
  };
13322
13467
  }
13323
13468
  }
@@ -13400,7 +13545,16 @@
13400
13545
  }
13401
13546
  // Add rule to the system message
13402
13547
  const ruleSection = `Rule: ${trimmedContent}`;
13403
- return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
13548
+ const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
13549
+ const ruleLines = trimmedContent
13550
+ .split(/\r?\n/)
13551
+ .map((line) => line.trim())
13552
+ .filter(Boolean)
13553
+ .map((line) => `- ${line}`);
13554
+ if (ruleLines.length === 0) {
13555
+ return requirementsWithRule;
13556
+ }
13557
+ return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
13404
13558
  }
13405
13559
  }
13406
13560
  /**
@@ -13902,11 +14056,12 @@
13902
14056
  if (!trimmedContent) {
13903
14057
  return requirements;
13904
14058
  }
13905
- const teammates = parseTeamCommitmentContent(trimmedContent, { strict: true });
14059
+ // Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
14060
+ const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
13906
14061
  if (teammates.length === 0) {
13907
14062
  return requirements;
13908
14063
  }
13909
- const agentName = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
14064
+ const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
13910
14065
  const teamEntries = teammates.map((teammate) => ({
13911
14066
  toolName: createTeamToolName(teammate.url),
13912
14067
  teammate,
@@ -13946,7 +14101,7 @@
13946
14101
  },
13947
14102
  });
13948
14103
  }
13949
- const existingTeammates = ((_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
14104
+ const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
13950
14105
  const updatedTeammates = [...existingTeammates];
13951
14106
  for (const entry of teamEntries) {
13952
14107
  if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
@@ -13975,8 +14130,8 @@
13975
14130
  return this.appendToSystemMessage({
13976
14131
  ...requirements,
13977
14132
  tools: updatedTools,
13978
- metadata: {
13979
- ...requirements.metadata,
14133
+ _metadata: {
14134
+ ...requirements._metadata,
13980
14135
  teammates: updatedTeammates,
13981
14136
  },
13982
14137
  }, teamSystemMessage);
@@ -14208,7 +14363,7 @@
14208
14363
  if (!trimmedContent) {
14209
14364
  // Store template mode flag in metadata
14210
14365
  const updatedMetadata = {
14211
- ...requirements.metadata,
14366
+ ...requirements._metadata,
14212
14367
  templateMode: true,
14213
14368
  };
14214
14369
  // Add a general instruction about using structured templates
@@ -14218,21 +14373,21 @@
14218
14373
  `);
14219
14374
  return {
14220
14375
  ...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
14221
- metadata: updatedMetadata,
14376
+ _metadata: updatedMetadata,
14222
14377
  };
14223
14378
  }
14224
14379
  // If content is provided, add the specific template instructions
14225
14380
  const templateSection = `Response Template: ${trimmedContent}`;
14226
14381
  // Store the template in metadata for potential programmatic access
14227
- const existingTemplates = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
14382
+ const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
14228
14383
  const updatedMetadata = {
14229
- ...requirements.metadata,
14384
+ ...requirements._metadata,
14230
14385
  templates: [...existingTemplates, trimmedContent],
14231
14386
  templateMode: true,
14232
14387
  };
14233
14388
  return {
14234
14389
  ...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
14235
- metadata: updatedMetadata,
14390
+ _metadata: updatedMetadata,
14236
14391
  };
14237
14392
  }
14238
14393
  }
@@ -14569,8 +14724,8 @@
14569
14724
  return this.appendToSystemMessage({
14570
14725
  ...requirements,
14571
14726
  tools: updatedTools,
14572
- metadata: {
14573
- ...requirements.metadata,
14727
+ _metadata: {
14728
+ ...requirements._metadata,
14574
14729
  useBrowser: true,
14575
14730
  },
14576
14731
  }, spaceTrim$1.spaceTrim(`
@@ -14799,8 +14954,8 @@
14799
14954
  return this.appendToSystemMessage({
14800
14955
  ...requirements,
14801
14956
  tools: updatedTools,
14802
- metadata: {
14803
- ...requirements.metadata,
14957
+ _metadata: {
14958
+ ...requirements._metadata,
14804
14959
  useEmail: content || true,
14805
14960
  },
14806
14961
  }, spaceTrim$1.spaceTrim((block) => `
@@ -14935,8 +15090,8 @@
14935
15090
  return this.appendToSystemMessage({
14936
15091
  ...requirements,
14937
15092
  tools: updatedTools,
14938
- metadata: {
14939
- ...requirements.metadata,
15093
+ _metadata: {
15094
+ ...requirements._metadata,
14940
15095
  useImageGenerator: content || true,
14941
15096
  },
14942
15097
  }, spaceTrim$1.spaceTrim(`
@@ -15227,8 +15382,8 @@
15227
15382
  return this.appendToSystemMessage({
15228
15383
  ...requirements,
15229
15384
  tools: updatedTools,
15230
- metadata: {
15231
- ...requirements.metadata,
15385
+ _metadata: {
15386
+ ...requirements._metadata,
15232
15387
  useSearchEngine: content || true,
15233
15388
  },
15234
15389
  }, spaceTrim$1.spaceTrim((block) => `
@@ -15376,8 +15531,8 @@
15376
15531
  return this.appendToSystemMessage({
15377
15532
  ...requirements,
15378
15533
  tools: updatedTools,
15379
- metadata: {
15380
- ...requirements.metadata,
15534
+ _metadata: {
15535
+ ...requirements._metadata,
15381
15536
  },
15382
15537
  }, spaceTrim$1.spaceTrim((block) => `
15383
15538
  Time and date context:
@@ -18096,11 +18251,14 @@
18096
18251
  function createEmptyAgentModelRequirements() {
18097
18252
  return {
18098
18253
  systemMessage: '',
18254
+ promptSuffix: '',
18099
18255
  // modelName: 'gpt-5',
18100
18256
  modelName: 'gemini-2.5-flash-lite',
18101
18257
  temperature: 0.7,
18102
18258
  topP: 0.9,
18103
18259
  topK: 50,
18260
+ parentAgentUrl: null,
18261
+ isClosed: false,
18104
18262
  };
18105
18263
  }
18106
18264
  /**
@@ -18246,14 +18404,42 @@
18246
18404
  }
18247
18405
 
18248
18406
  /**
18249
- * Creates agent model requirements using the new commitment system
18407
+ * Creates agent model requirements using the new commitment system.
18408
+ *
18250
18409
  * This function uses a reduce-like pattern where each commitment applies its changes
18251
- * to build the final requirements starting from a basic empty model
18410
+ * to build the final requirements starting from a basic empty model.
18252
18411
  *
18253
- * @public exported from `@promptbook/core`
18412
+ * @param agentSource - Agent source book to parse.
18413
+ * @param modelName - Optional override for the agent model name.
18414
+ * @param options - Additional options such as the agent reference resolver.
18415
+ *
18416
+ * @private @@@
18417
+ */
18418
+ const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
18419
+ /**
18420
+ * Returns a safe fallback content when a resolver fails to transform a reference commitment.
18421
+ *
18422
+ * @param commitmentType - Commitment being resolved.
18423
+ * @param originalContent - Original unresolved commitment content.
18424
+ * @returns Fallback content that keeps requirement creation resilient.
18425
+ */
18426
+ function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
18427
+ if (commitmentType === 'FROM') {
18428
+ return 'VOID';
18429
+ }
18430
+ if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
18431
+ return '';
18432
+ }
18433
+ return originalContent;
18434
+ }
18435
+ /**
18436
+ * @@@
18437
+ *
18438
+ * @private @@@
18254
18439
  */
18255
- async function createAgentModelRequirementsWithCommitments(agentSource, modelName) {
18440
+ async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
18256
18441
  var _a;
18442
+ const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
18257
18443
  // Parse the agent source to extract commitments
18258
18444
  const parseResult = parseAgentSourceWithCommitments(agentSource);
18259
18445
  // Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
@@ -18290,8 +18476,8 @@
18290
18476
  // Store the agent name in metadata so commitments can access it
18291
18477
  requirements = {
18292
18478
  ...requirements,
18293
- metadata: {
18294
- ...requirements.metadata,
18479
+ _metadata: {
18480
+ ...requirements._metadata,
18295
18481
  agentName: parseResult.agentName,
18296
18482
  },
18297
18483
  };
@@ -18305,6 +18491,17 @@
18305
18491
  // Apply each commitment in order using reduce-like pattern
18306
18492
  for (let i = 0; i < filteredCommitments.length; i++) {
18307
18493
  const commitment = filteredCommitments[i];
18494
+ const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
18495
+ let commitmentContent = commitment.content;
18496
+ if (isReferenceCommitment && agentReferenceResolver) {
18497
+ try {
18498
+ commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
18499
+ }
18500
+ catch (error) {
18501
+ console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
18502
+ commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
18503
+ }
18504
+ }
18308
18505
  // CLOSED commitment should work only if its the last commitment in the book
18309
18506
  if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
18310
18507
  continue;
@@ -18312,7 +18509,7 @@
18312
18509
  const definition = getCommitmentDefinition(commitment.type);
18313
18510
  if (definition) {
18314
18511
  try {
18315
- requirements = definition.applyToAgentModelRequirements(requirements, commitment.content);
18512
+ requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
18316
18513
  }
18317
18514
  catch (error) {
18318
18515
  console.warn(`Failed to apply commitment ${commitment.type}:`, error);
@@ -18460,23 +18657,28 @@
18460
18657
  }
18461
18658
 
18462
18659
  /**
18463
- * Creates model requirements for an agent based on its source
18660
+ * Creates model requirements for an agent based on its source.
18464
18661
  *
18465
18662
  * There are 2 similar functions:
18466
18663
  * - `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.
18467
18664
  * - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
18468
18665
  *
18666
+ * @param agentSource - Book describing the agent.
18667
+ * @param modelName - Optional override for the agent's model.
18668
+ * @param availableModels - Models that could fulfill the agent.
18669
+ * @param llmTools - Execution tools used when selecting a best model.
18670
+ * @param options - Optional hooks such as the agent reference resolver.
18469
18671
  * @public exported from `@promptbook/core`
18470
18672
  */
18471
- async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
18673
+ async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
18472
18674
  // If availableModels are provided and no specific modelName is given,
18473
18675
  // use preparePersona to select the best model
18474
18676
  if (availableModels && !modelName && llmTools) {
18475
18677
  const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
18476
- return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
18678
+ return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
18477
18679
  }
18478
18680
  // Use the new commitment-based system with provided or default model
18479
- return createAgentModelRequirementsWithCommitments(agentSource, modelName);
18681
+ return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
18480
18682
  }
18481
18683
  /**
18482
18684
  * Selects the best model using the preparePersona function
@@ -18774,6 +18976,66 @@
18774
18976
  },
18775
18977
  /**/
18776
18978
  /**/
18979
+ {
18980
+ modelVariant: 'CHAT',
18981
+ modelTitle: 'gpt-5.2-codex',
18982
+ modelName: 'gpt-5.2-codex',
18983
+ 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.',
18984
+ pricing: {
18985
+ prompt: pricing(`$1.75 / 1M tokens`),
18986
+ output: pricing(`$14.00 / 1M tokens`),
18987
+ },
18988
+ },
18989
+ /**/
18990
+ /**/
18991
+ {
18992
+ modelVariant: 'CHAT',
18993
+ modelTitle: 'gpt-5.1-codex-max',
18994
+ modelName: 'gpt-5.1-codex-max',
18995
+ modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
18996
+ pricing: {
18997
+ prompt: pricing(`$1.25 / 1M tokens`),
18998
+ output: pricing(`$10.00 / 1M tokens`),
18999
+ },
19000
+ },
19001
+ /**/
19002
+ /**/
19003
+ {
19004
+ modelVariant: 'CHAT',
19005
+ modelTitle: 'gpt-5.1-codex',
19006
+ modelName: 'gpt-5.1-codex',
19007
+ modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
19008
+ pricing: {
19009
+ prompt: pricing(`$1.25 / 1M tokens`),
19010
+ output: pricing(`$10.00 / 1M tokens`),
19011
+ },
19012
+ },
19013
+ /**/
19014
+ /**/
19015
+ {
19016
+ modelVariant: 'CHAT',
19017
+ modelTitle: 'gpt-5.1-codex-mini',
19018
+ modelName: 'gpt-5.1-codex-mini',
19019
+ modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
19020
+ pricing: {
19021
+ prompt: pricing(`$0.25 / 1M tokens`),
19022
+ output: pricing(`$2.00 / 1M tokens`),
19023
+ },
19024
+ },
19025
+ /**/
19026
+ /**/
19027
+ {
19028
+ modelVariant: 'CHAT',
19029
+ modelTitle: 'gpt-5-codex',
19030
+ modelName: 'gpt-5-codex',
19031
+ modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
19032
+ pricing: {
19033
+ prompt: pricing(`$1.25 / 1M tokens`),
19034
+ output: pricing(`$10.00 / 1M tokens`),
19035
+ },
19036
+ },
19037
+ /**/
19038
+ /**/
18777
19039
  {
18778
19040
  modelVariant: 'CHAT',
18779
19041
  modelTitle: 'gpt-5-mini',
@@ -19478,6 +19740,32 @@
19478
19740
  errorMessage.includes('does not support'));
19479
19741
  }
19480
19742
 
19743
+ /**
19744
+ * Provides access to the structured clone implementation when available.
19745
+ */
19746
+ function getStructuredCloneFunction() {
19747
+ return globalThis.structuredClone;
19748
+ }
19749
+ /**
19750
+ * Checks whether the prompt is a chat prompt that carries file attachments.
19751
+ */
19752
+ function hasChatPromptFiles(prompt) {
19753
+ return 'files' in prompt && Array.isArray(prompt.files);
19754
+ }
19755
+ /**
19756
+ * Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
19757
+ */
19758
+ function clonePromptPreservingFiles(prompt) {
19759
+ const structuredCloneFn = getStructuredCloneFunction();
19760
+ if (typeof structuredCloneFn === 'function') {
19761
+ return structuredCloneFn(prompt);
19762
+ }
19763
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
19764
+ if (hasChatPromptFiles(prompt)) {
19765
+ clonedPrompt.files = prompt.files;
19766
+ }
19767
+ return clonedPrompt;
19768
+ }
19481
19769
  /**
19482
19770
  * Execution Tools for calling OpenAI API or other OpenAI compatible provider
19483
19771
  *
@@ -19562,7 +19850,7 @@
19562
19850
  */
19563
19851
  async callChatModelStream(prompt, onProgress) {
19564
19852
  // Deep clone prompt and modelRequirements to avoid mutation across calls
19565
- const clonedPrompt = JSON.parse(JSON.stringify(prompt));
19853
+ const clonedPrompt = clonePromptPreservingFiles(prompt);
19566
19854
  // Use local Set for retried parameters to ensure independence and thread safety
19567
19855
  const retriedUnsupportedParameters = new Set();
19568
19856
  return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
@@ -19589,7 +19877,10 @@
19589
19877
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
19590
19878
  // <- Note: [🧆]
19591
19879
  }; // <- TODO: [💩] Guard here types better
19592
- if (format === 'JSON') {
19880
+ if (currentModelRequirements.responseFormat !== undefined) {
19881
+ modelSettings.response_format = currentModelRequirements.responseFormat;
19882
+ }
19883
+ else if (format === 'JSON') {
19593
19884
  modelSettings.response_format = {
19594
19885
  type: 'json_object',
19595
19886
  };
@@ -21070,7 +21361,9 @@
21070
21361
  const processingStartedAtMs = Date.now();
21071
21362
  for (const [index, source] of knowledgeSources.entries()) {
21072
21363
  try {
21073
- const sourceType = source.startsWith('http') || source.startsWith('https') ? 'url' : 'file';
21364
+ const isDataUrl = isDataUrlKnowledgeSource(source);
21365
+ const isHttp = source.startsWith('http://') || source.startsWith('https://');
21366
+ const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
21074
21367
  if (this.options.isVerbose) {
21075
21368
  console.info('[🤰]', 'Processing knowledge source', {
21076
21369
  index: index + 1,
@@ -21080,8 +21373,27 @@
21080
21373
  logLabel,
21081
21374
  });
21082
21375
  }
21083
- // Check if it's a URL
21084
- if (source.startsWith('http://') || source.startsWith('https://')) {
21376
+ if (isDataUrl) {
21377
+ const parsed = parseDataUrlKnowledgeSource(source);
21378
+ if (!parsed) {
21379
+ skippedSources.push({ source, reason: 'invalid_data_url' });
21380
+ if (this.options.isVerbose) {
21381
+ console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
21382
+ source,
21383
+ sourceType,
21384
+ logLabel,
21385
+ });
21386
+ }
21387
+ continue;
21388
+ }
21389
+ const dataUrlFile = new File([parsed.buffer], parsed.filename, {
21390
+ type: parsed.mimeType,
21391
+ });
21392
+ fileStreams.push(dataUrlFile);
21393
+ totalBytes += parsed.buffer.length;
21394
+ continue;
21395
+ }
21396
+ if (isHttp) {
21085
21397
  const downloadResult = await this.downloadKnowledgeSourceFile({
21086
21398
  source,
21087
21399
  timeoutMs: downloadTimeoutMs,
@@ -21183,6 +21495,64 @@
21183
21495
  }
21184
21496
 
21185
21497
  const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
21498
+ const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
21499
+ /*
21500
+ TODO: Use or remove
21501
+ const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
21502
+ type: 'object',
21503
+ properties: {},
21504
+ required: [],
21505
+ additionalProperties: true,
21506
+ };
21507
+ */
21508
+ function buildJsonSchemaDefinition(jsonSchema) {
21509
+ var _a, _b, _c;
21510
+ const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
21511
+ return {
21512
+ type: 'json_schema',
21513
+ name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
21514
+ strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
21515
+ schema: {
21516
+ type: 'object',
21517
+ properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
21518
+ required: Array.isArray(schema.required) ? schema.required : [],
21519
+ additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
21520
+ description: schema.description,
21521
+ },
21522
+ };
21523
+ }
21524
+ /**
21525
+ * Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
21526
+ * structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
21527
+ *
21528
+ * @param responseFormat - The OpenAI `response_format` payload from the user request.
21529
+ * @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
21530
+ * @private utility of Open AI
21531
+ */
21532
+ function mapResponseFormatToAgentOutputType(responseFormat) {
21533
+ if (!responseFormat) {
21534
+ return undefined;
21535
+ }
21536
+ if (typeof responseFormat === 'string') {
21537
+ if (responseFormat === 'text') {
21538
+ return 'text';
21539
+ }
21540
+ if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
21541
+ return buildJsonSchemaDefinition();
21542
+ }
21543
+ return 'text';
21544
+ }
21545
+ switch (responseFormat.type) {
21546
+ case 'text':
21547
+ return 'text';
21548
+ case 'json_schema':
21549
+ return buildJsonSchemaDefinition(responseFormat.json_schema);
21550
+ case 'json_object':
21551
+ return buildJsonSchemaDefinition();
21552
+ default:
21553
+ return undefined;
21554
+ }
21555
+ }
21186
21556
  /**
21187
21557
  * Execution tools for OpenAI AgentKit (Agents SDK).
21188
21558
  *
@@ -21230,6 +21600,7 @@
21230
21600
  ...parameters,
21231
21601
  modelName: this.agentKitModelName,
21232
21602
  });
21603
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
21233
21604
  const preparedAgentKitAgent = await this.prepareAgentKitAgent({
21234
21605
  name: (prompt.title || 'Agent'),
21235
21606
  instructions: modelRequirements.systemMessage || '',
@@ -21241,6 +21612,7 @@
21241
21612
  prompt,
21242
21613
  rawPromptContent,
21243
21614
  onProgress,
21615
+ responseFormatOutputType,
21244
21616
  });
21245
21617
  }
21246
21618
  /**
@@ -21422,16 +21794,21 @@
21422
21794
  ...prompt.parameters,
21423
21795
  modelName: this.agentKitModelName,
21424
21796
  });
21797
+ const agentForRun = options.responseFormatOutputType !== undefined
21798
+ ? openAiAgentKitAgent.clone({
21799
+ outputType: options.responseFormatOutputType,
21800
+ })
21801
+ : openAiAgentKitAgent;
21425
21802
  const start = $getCurrentDate();
21426
21803
  let latestContent = '';
21427
21804
  const toolCalls = [];
21428
21805
  const toolCallIndexById = new Map();
21429
21806
  const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
21430
21807
  const rawRequest = {
21431
- agentName: openAiAgentKitAgent.name,
21808
+ agentName: agentForRun.name,
21432
21809
  input: inputItems,
21433
21810
  };
21434
- const streamResult = await agents.run(openAiAgentKitAgent, inputItems, {
21811
+ const streamResult = await agents.run(agentForRun, inputItems, {
21435
21812
  stream: true,
21436
21813
  context: { parameters: prompt.parameters },
21437
21814
  });
@@ -22420,22 +22797,28 @@
22420
22797
  throw new Error('AgentLlmExecutionTools only supports chat prompts');
22421
22798
  }
22422
22799
  const modelRequirements = await this.getModelRequirements();
22800
+ const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
22423
22801
  const chatPrompt = prompt;
22424
22802
  let underlyingLlmResult;
22425
- // Create modified chat prompt with agent system message
22803
+ const chatPromptContentWithSuffix = promptSuffix
22804
+ ? `${chatPrompt.content}\n\n${promptSuffix}`
22805
+ : chatPrompt.content;
22426
22806
  const promptWithAgentModelRequirements = {
22427
22807
  ...chatPrompt,
22808
+ content: chatPromptContentWithSuffix,
22428
22809
  modelRequirements: {
22429
22810
  ...chatPrompt.modelRequirements,
22430
- ...modelRequirements,
22811
+ ...sanitizedRequirements,
22431
22812
  // Spread tools to convert readonly array to mutable
22432
- tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
22813
+ tools: sanitizedRequirements.tools
22814
+ ? [...sanitizedRequirements.tools]
22815
+ : chatPrompt.modelRequirements.tools,
22433
22816
  // Spread knowledgeSources to convert readonly array to mutable
22434
- knowledgeSources: modelRequirements.knowledgeSources
22435
- ? [...modelRequirements.knowledgeSources]
22817
+ knowledgeSources: sanitizedRequirements.knowledgeSources
22818
+ ? [...sanitizedRequirements.knowledgeSources]
22436
22819
  : undefined,
22437
22820
  // Prepend agent system message to existing system message
22438
- systemMessage: modelRequirements.systemMessage +
22821
+ systemMessage: sanitizedRequirements.systemMessage +
22439
22822
  (chatPrompt.modelRequirements.systemMessage
22440
22823
  ? `\n\n${chatPrompt.modelRequirements.systemMessage}`
22441
22824
  : ''),
@@ -22443,8 +22826,8 @@
22443
22826
  };
22444
22827
  console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
22445
22828
  if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
22446
- const requirementsHash = cryptoJs.SHA256(JSON.stringify(modelRequirements)).toString();
22447
- const vectorStoreHash = cryptoJs.SHA256(JSON.stringify((_a = modelRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
22829
+ const requirementsHash = cryptoJs.SHA256(JSON.stringify(sanitizedRequirements)).toString();
22830
+ const vectorStoreHash = cryptoJs.SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
22448
22831
  const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
22449
22832
  const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
22450
22833
  let preparedAgentKit = this.options.assistantPreparationMode === 'external'
@@ -22471,7 +22854,7 @@
22471
22854
  agent: this.title,
22472
22855
  });
22473
22856
  }
22474
- if (!vectorStoreId && ((_b = modelRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
22857
+ if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
22475
22858
  emitAssistantPreparationProgress({
22476
22859
  onProgress,
22477
22860
  prompt,
@@ -22487,9 +22870,9 @@
22487
22870
  });
22488
22871
  preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
22489
22872
  name: this.title,
22490
- instructions: modelRequirements.systemMessage || '',
22491
- knowledgeSources: modelRequirements.knowledgeSources,
22492
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22873
+ instructions: sanitizedRequirements.systemMessage || '',
22874
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22875
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22493
22876
  vectorStoreId,
22494
22877
  });
22495
22878
  }
@@ -22504,15 +22887,17 @@
22504
22887
  requirementsHash,
22505
22888
  vectorStoreId: preparedAgentKit.vectorStoreId,
22506
22889
  });
22890
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
22507
22891
  underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
22508
22892
  openAiAgentKitAgent: preparedAgentKit.agent,
22509
22893
  prompt: promptWithAgentModelRequirements,
22510
22894
  onProgress,
22895
+ responseFormatOutputType,
22511
22896
  });
22512
22897
  }
22513
22898
  else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
22514
22899
  // ... deprecated path ...
22515
- const requirementsHash = cryptoJs.SHA256(JSON.stringify(modelRequirements)).toString();
22900
+ const requirementsHash = cryptoJs.SHA256(JSON.stringify(sanitizedRequirements)).toString();
22516
22901
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
22517
22902
  let assistant;
22518
22903
  if (this.options.assistantPreparationMode === 'external') {
@@ -22554,9 +22939,9 @@
22554
22939
  assistant = await this.options.llmTools.updateAssistant({
22555
22940
  assistantId: cached.assistantId,
22556
22941
  name: this.title,
22557
- instructions: modelRequirements.systemMessage,
22558
- knowledgeSources: modelRequirements.knowledgeSources,
22559
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22942
+ instructions: sanitizedRequirements.systemMessage,
22943
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22944
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22560
22945
  });
22561
22946
  AgentLlmExecutionTools.assistantCache.set(this.title, {
22562
22947
  assistantId: assistant.assistantId,
@@ -22579,9 +22964,9 @@
22579
22964
  });
22580
22965
  assistant = await this.options.llmTools.createNewAssistant({
22581
22966
  name: this.title,
22582
- instructions: modelRequirements.systemMessage,
22583
- knowledgeSources: modelRequirements.knowledgeSources,
22584
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
22967
+ instructions: sanitizedRequirements.systemMessage,
22968
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
22969
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
22585
22970
  /*
22586
22971
  !!!
22587
22972
  metadata: {
@@ -22623,13 +23008,19 @@
22623
23008
  }
22624
23009
  }
22625
23010
  let content = underlyingLlmResult.content;
22626
- // Note: Cleanup the AI artifacts from the content
22627
- content = humanizeAiText(content);
22628
- // Note: Make sure the content is Promptbook-like
22629
- content = promptbookifyAiText(content);
23011
+ if (typeof content === 'string') {
23012
+ // Note: Cleanup the AI artifacts from the content
23013
+ content = humanizeAiText(content);
23014
+ // Note: Make sure the content is Promptbook-like
23015
+ content = promptbookifyAiText(content);
23016
+ }
23017
+ else {
23018
+ // TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
23019
+ content = JSON.stringify(content);
23020
+ }
22630
23021
  const agentResult = {
22631
23022
  ...underlyingLlmResult,
22632
- content,
23023
+ content: content,
22633
23024
  modelName: this.modelName,
22634
23025
  };
22635
23026
  return agentResult;
@@ -22818,7 +23209,6 @@
22818
23209
  * Note: This method also implements the learning mechanism
22819
23210
  */
22820
23211
  async callChatModelStream(prompt, onProgress) {
22821
- var _a;
22822
23212
  // [1] Check if the user is asking the same thing as in the samples
22823
23213
  const modelRequirements = await this.getModelRequirements();
22824
23214
  if (modelRequirements.samples) {
@@ -22866,7 +23256,7 @@
22866
23256
  if (result.rawResponse && 'sample' in result.rawResponse) {
22867
23257
  return result;
22868
23258
  }
22869
- if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
23259
+ if (modelRequirements.isClosed) {
22870
23260
  return result;
22871
23261
  }
22872
23262
  // Note: [0] Notify start of self-learning