@promptbook/cli 0.110.0-8 → 0.110.0-9

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 (24) hide show
  1. package/esm/index.es.js +432 -87
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +22 -21
  6. package/esm/typings/src/book-components/Chat/Chat/ChatInputArea.d.ts +1 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  8. package/esm/typings/src/book-components/Chat/Chat/ChatMessageList.d.ts +1 -0
  9. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +15 -0
  10. package/esm/typings/src/book-components/Chat/Chat/ChatSoundToggle.d.ts +19 -0
  11. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +6 -0
  12. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +9 -0
  13. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.test.d.ts +1 -0
  14. package/esm/typings/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +39 -0
  15. package/esm/typings/src/types/LlmToolDefinition.d.ts +1 -0
  16. package/esm/typings/src/types/ModelRequirements.d.ts +9 -0
  17. package/esm/typings/src/utils/DEFAULT_THINKING_MESSAGES.d.ts +8 -0
  18. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +38 -0
  19. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.test.d.ts +1 -0
  20. package/esm/typings/src/utils/language/getBrowserPreferredSpeechRecognitionLanguage.d.ts +35 -0
  21. package/esm/typings/src/version.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/umd/index.umd.js +432 -87
  24. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -48,7 +48,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-8';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0-9';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -15828,6 +15828,28 @@ class BaseCommitmentDefinition {
15828
15828
  return currentMessage + separator + content;
15829
15829
  });
15830
15830
  }
15831
+ /**
15832
+ * Helper method to create a new requirements object with updated prompt suffix
15833
+ */
15834
+ updatePromptSuffix(requirements, contentUpdate) {
15835
+ const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
15836
+ return {
15837
+ ...requirements,
15838
+ promptSuffix: newSuffix,
15839
+ };
15840
+ }
15841
+ /**
15842
+ * Helper method to append content to the prompt suffix
15843
+ * Default separator is a single newline for bullet lists.
15844
+ */
15845
+ appendToPromptSuffix(requirements, content, separator = '\n') {
15846
+ return this.updatePromptSuffix(requirements, (currentSuffix) => {
15847
+ if (!currentSuffix.trim()) {
15848
+ return content;
15849
+ }
15850
+ return `${currentSuffix}${separator}${content}`;
15851
+ });
15852
+ }
15831
15853
  /**
15832
15854
  * Helper method to add a comment section to the system message
15833
15855
  * Comments are lines starting with # that will be removed from the final system message
@@ -16005,13 +16027,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
16005
16027
  `);
16006
16028
  }
16007
16029
  applyToAgentModelRequirements(requirements, _content) {
16008
- const updatedMetadata = {
16009
- ...requirements.metadata,
16010
- isClosed: true,
16011
- };
16012
16030
  return {
16013
16031
  ...requirements,
16014
- metadata: updatedMetadata,
16032
+ isClosed: true,
16015
16033
  };
16016
16034
  }
16017
16035
  }
@@ -16289,12 +16307,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
16289
16307
  return requirements;
16290
16308
  }
16291
16309
  // Get existing dictionary entries from metadata
16292
- const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
16310
+ const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
16293
16311
  // Merge the new dictionary entry with existing entries
16294
16312
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
16295
16313
  // Store the merged dictionary in metadata for debugging and inspection
16296
16314
  const updatedMetadata = {
16297
- ...requirements.metadata,
16315
+ ...requirements._metadata,
16298
16316
  DICTIONARY: mergedDictionary,
16299
16317
  };
16300
16318
  // Create the dictionary section for the system message
@@ -16302,7 +16320,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
16302
16320
  const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
16303
16321
  return {
16304
16322
  ...this.appendToSystemMessage(requirements, dictionarySection),
16305
- metadata: updatedMetadata,
16323
+ _metadata: updatedMetadata,
16306
16324
  };
16307
16325
  }
16308
16326
  }
@@ -16442,10 +16460,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
16442
16460
  applyToAgentModelRequirements(requirements, content) {
16443
16461
  const trimmedContent = content.trim();
16444
16462
  if (!trimmedContent) {
16445
- return {
16446
- ...requirements,
16447
- parentAgentUrl: undefined,
16448
- };
16463
+ return requirements;
16449
16464
  }
16450
16465
  if (trimmedContent.toUpperCase() === 'VOID' ||
16451
16466
  trimmedContent.toUpperCase() === 'NULL' ||
@@ -16659,6 +16674,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
16659
16674
  * Note: [💞] Ignore a discrepancy between file name and entity name
16660
16675
  */
16661
16676
 
16677
+ /**
16678
+ * @@@
16679
+ *
16680
+ * @private thing of inline knowledge
16681
+ */
16682
+ const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
16683
+ /**
16684
+ * @@@
16685
+ *
16686
+ * @private thing of inline knowledge
16687
+ */
16688
+ const INLINE_KNOWLEDGE_EXTENSION = '.txt';
16689
+ /**
16690
+ * @@@
16691
+ *
16692
+ * @private thing of inline knowledge
16693
+ */
16694
+ const DATA_URL_PREFIX = 'data:';
16695
+ /**
16696
+ * @@@
16697
+ *
16698
+ * @private thing of inline knowledge
16699
+ */
16700
+ function getFirstNonEmptyLine(content) {
16701
+ const lines = content.split(/\r?\n/);
16702
+ for (const line of lines) {
16703
+ const trimmed = line.trim();
16704
+ if (trimmed) {
16705
+ return trimmed;
16706
+ }
16707
+ }
16708
+ return null;
16709
+ }
16710
+ /**
16711
+ * @@@
16712
+ *
16713
+ * @private thing of inline knowledge
16714
+ */
16715
+ function deriveBaseFilename(content) {
16716
+ const firstLine = getFirstNonEmptyLine(content);
16717
+ if (!firstLine) {
16718
+ return INLINE_KNOWLEDGE_BASE_NAME;
16719
+ }
16720
+ const normalized = normalizeToKebabCase(firstLine);
16721
+ return normalized || INLINE_KNOWLEDGE_BASE_NAME;
16722
+ }
16723
+ /**
16724
+ * Creates a data URL that represents the inline knowledge content as a text file.
16725
+ *
16726
+ * @private thing of inline knowledge
16727
+ */
16728
+ function createInlineKnowledgeSourceFile(content) {
16729
+ const trimmedContent = content.trim();
16730
+ const baseName = deriveBaseFilename(trimmedContent);
16731
+ const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
16732
+ const mimeType = 'text/plain';
16733
+ const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
16734
+ const encodedFilename = encodeURIComponent(filename);
16735
+ const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
16736
+ return {
16737
+ filename,
16738
+ mimeType,
16739
+ url,
16740
+ };
16741
+ }
16742
+ /**
16743
+ * Checks whether the provided source string is a data URL that can be decoded.
16744
+ *
16745
+ * @private thing of inline knowledge
16746
+ */
16747
+ function isDataUrlKnowledgeSource(source) {
16748
+ return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
16749
+ }
16750
+ /**
16751
+ * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
16752
+ *
16753
+ * @private thing of inline knowledge
16754
+ */
16755
+ function parseDataUrlKnowledgeSource(source) {
16756
+ if (!isDataUrlKnowledgeSource(source)) {
16757
+ return null;
16758
+ }
16759
+ const commaIndex = source.indexOf(',');
16760
+ if (commaIndex === -1) {
16761
+ return null;
16762
+ }
16763
+ const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
16764
+ const payload = source.slice(commaIndex + 1);
16765
+ const tokens = header.split(';');
16766
+ const mediaType = tokens[0] || 'text/plain';
16767
+ let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
16768
+ let isBase64 = false;
16769
+ for (let i = 1; i < tokens.length; i++) {
16770
+ const token = tokens[i];
16771
+ if (!token) {
16772
+ continue;
16773
+ }
16774
+ if (token.toLowerCase() === 'base64') {
16775
+ isBase64 = true;
16776
+ continue;
16777
+ }
16778
+ const [key, value] = token.split('=');
16779
+ if (key === 'name' && value !== undefined) {
16780
+ try {
16781
+ filename = decodeURIComponent(value);
16782
+ }
16783
+ catch (_a) {
16784
+ filename = value;
16785
+ }
16786
+ }
16787
+ }
16788
+ if (!isBase64) {
16789
+ return null;
16790
+ }
16791
+ try {
16792
+ const buffer = Buffer.from(payload, 'base64');
16793
+ return {
16794
+ buffer,
16795
+ filename,
16796
+ mimeType: mediaType,
16797
+ };
16798
+ }
16799
+ catch (_b) {
16800
+ return null;
16801
+ }
16802
+ }
16803
+ /**
16804
+ * Note: [💞] Ignore a discrepancy between file name and entity name
16805
+ */
16806
+
16662
16807
  /**
16663
16808
  * KNOWLEDGE commitment definition
16664
16809
  *
@@ -16757,9 +16902,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
16757
16902
  return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
16758
16903
  }
16759
16904
  else {
16760
- // Direct text knowledge - add to system message
16761
- const knowledgeSection = `Knowledge: ${trimmedContent}`;
16762
- return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
16905
+ const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
16906
+ const updatedRequirements = {
16907
+ ...requirements,
16908
+ knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
16909
+ };
16910
+ const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
16911
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
16763
16912
  }
16764
16913
  }
16765
16914
  }
@@ -17006,16 +17155,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
17006
17155
  // and typically doesn't need to be added to the system prompt or model requirements directly.
17007
17156
  // It is extracted separately for the chat interface.
17008
17157
  var _a;
17009
- const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
17158
+ const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
17010
17159
  if (pendingUserMessage) {
17011
17160
  const newSample = { question: pendingUserMessage, answer: content };
17012
17161
  const newSamples = [...(requirements.samples || []), newSample];
17013
- const newMetadata = { ...requirements.metadata };
17162
+ const newMetadata = { ...requirements._metadata };
17014
17163
  delete newMetadata.pendingUserMessage;
17015
17164
  return {
17016
17165
  ...requirements,
17017
17166
  samples: newSamples,
17018
- metadata: newMetadata,
17167
+ _metadata: newMetadata,
17019
17168
  };
17020
17169
  }
17021
17170
  return requirements;
@@ -17263,8 +17412,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
17263
17412
  applyToAgentModelRequirements(requirements, content) {
17264
17413
  return {
17265
17414
  ...requirements,
17266
- metadata: {
17267
- ...requirements.metadata,
17415
+ _metadata: {
17416
+ ...requirements._metadata,
17268
17417
  pendingUserMessage: content,
17269
17418
  },
17270
17419
  };
@@ -18122,11 +18271,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
18122
18271
  if (trimmedContent === '') {
18123
18272
  return requirements;
18124
18273
  }
18125
- // Return requirements with updated notes but no changes to system message
18126
- return {
18127
- ...requirements,
18128
- notes: [...(requirements.notes || []), trimmedContent],
18129
- };
18274
+ return requirements;
18130
18275
  }
18131
18276
  }
18132
18277
  /**
@@ -18188,12 +18333,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
18188
18333
  // Since OPEN is default, we can just ensure isClosed is false
18189
18334
  // But to be explicit we can set it
18190
18335
  const updatedMetadata = {
18191
- ...requirements.metadata,
18336
+ ...requirements._metadata,
18192
18337
  isClosed: false,
18193
18338
  };
18194
18339
  return {
18195
18340
  ...requirements,
18196
- metadata: updatedMetadata,
18341
+ _metadata: updatedMetadata,
18197
18342
  };
18198
18343
  }
18199
18344
  }
@@ -18274,7 +18419,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
18274
18419
  return requirements;
18275
18420
  }
18276
18421
  // Get existing persona content from metadata
18277
- const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
18422
+ const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
18278
18423
  // Merge the new content with existing persona content
18279
18424
  // When multiple PERSONA commitments exist, they are merged into one
18280
18425
  const mergedPersonaContent = existingPersonaContent
@@ -18282,12 +18427,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
18282
18427
  : trimmedContent;
18283
18428
  // Store the merged persona content in metadata for debugging and inspection
18284
18429
  const updatedMetadata = {
18285
- ...requirements.metadata,
18430
+ ...requirements._metadata,
18286
18431
  PERSONA: mergedPersonaContent,
18287
18432
  };
18288
18433
  // Get the agent name from metadata (which should contain the first line of agent source)
18289
18434
  // If not available, extract from current system message as fallback
18290
- let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
18435
+ let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
18291
18436
  if (!agentName) {
18292
18437
  // Fallback: extract from current system message
18293
18438
  const currentMessage = requirements.systemMessage.trim();
@@ -18334,7 +18479,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
18334
18479
  return {
18335
18480
  ...requirements,
18336
18481
  systemMessage: newSystemMessage,
18337
- metadata: updatedMetadata,
18482
+ _metadata: updatedMetadata,
18338
18483
  };
18339
18484
  }
18340
18485
  }
@@ -18417,7 +18562,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
18417
18562
  }
18418
18563
  // Add rule to the system message
18419
18564
  const ruleSection = `Rule: ${trimmedContent}`;
18420
- return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
18565
+ const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
18566
+ const ruleLines = trimmedContent
18567
+ .split(/\r?\n/)
18568
+ .map((line) => line.trim())
18569
+ .filter(Boolean)
18570
+ .map((line) => `- ${line}`);
18571
+ if (ruleLines.length === 0) {
18572
+ return requirementsWithRule;
18573
+ }
18574
+ return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
18421
18575
  }
18422
18576
  }
18423
18577
  /**
@@ -18923,7 +19077,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
18923
19077
  if (teammates.length === 0) {
18924
19078
  return requirements;
18925
19079
  }
18926
- const agentName = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
19080
+ const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
18927
19081
  const teamEntries = teammates.map((teammate) => ({
18928
19082
  toolName: createTeamToolName(teammate.url),
18929
19083
  teammate,
@@ -18963,7 +19117,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
18963
19117
  },
18964
19118
  });
18965
19119
  }
18966
- const existingTeammates = ((_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
19120
+ const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
18967
19121
  const updatedTeammates = [...existingTeammates];
18968
19122
  for (const entry of teamEntries) {
18969
19123
  if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
@@ -18992,8 +19146,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
18992
19146
  return this.appendToSystemMessage({
18993
19147
  ...requirements,
18994
19148
  tools: updatedTools,
18995
- metadata: {
18996
- ...requirements.metadata,
19149
+ _metadata: {
19150
+ ...requirements._metadata,
18997
19151
  teammates: updatedTeammates,
18998
19152
  },
18999
19153
  }, teamSystemMessage);
@@ -19225,7 +19379,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
19225
19379
  if (!trimmedContent) {
19226
19380
  // Store template mode flag in metadata
19227
19381
  const updatedMetadata = {
19228
- ...requirements.metadata,
19382
+ ...requirements._metadata,
19229
19383
  templateMode: true,
19230
19384
  };
19231
19385
  // Add a general instruction about using structured templates
@@ -19235,21 +19389,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
19235
19389
  `);
19236
19390
  return {
19237
19391
  ...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
19238
- metadata: updatedMetadata,
19392
+ _metadata: updatedMetadata,
19239
19393
  };
19240
19394
  }
19241
19395
  // If content is provided, add the specific template instructions
19242
19396
  const templateSection = `Response Template: ${trimmedContent}`;
19243
19397
  // Store the template in metadata for potential programmatic access
19244
- const existingTemplates = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
19398
+ const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
19245
19399
  const updatedMetadata = {
19246
- ...requirements.metadata,
19400
+ ...requirements._metadata,
19247
19401
  templates: [...existingTemplates, trimmedContent],
19248
19402
  templateMode: true,
19249
19403
  };
19250
19404
  return {
19251
19405
  ...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
19252
- metadata: updatedMetadata,
19406
+ _metadata: updatedMetadata,
19253
19407
  };
19254
19408
  }
19255
19409
  }
@@ -19586,8 +19740,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
19586
19740
  return this.appendToSystemMessage({
19587
19741
  ...requirements,
19588
19742
  tools: updatedTools,
19589
- metadata: {
19590
- ...requirements.metadata,
19743
+ _metadata: {
19744
+ ...requirements._metadata,
19591
19745
  useBrowser: true,
19592
19746
  },
19593
19747
  }, spaceTrim$1(`
@@ -19816,8 +19970,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
19816
19970
  return this.appendToSystemMessage({
19817
19971
  ...requirements,
19818
19972
  tools: updatedTools,
19819
- metadata: {
19820
- ...requirements.metadata,
19973
+ _metadata: {
19974
+ ...requirements._metadata,
19821
19975
  useEmail: content || true,
19822
19976
  },
19823
19977
  }, spaceTrim$1((block) => `
@@ -19952,8 +20106,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
19952
20106
  return this.appendToSystemMessage({
19953
20107
  ...requirements,
19954
20108
  tools: updatedTools,
19955
- metadata: {
19956
- ...requirements.metadata,
20109
+ _metadata: {
20110
+ ...requirements._metadata,
19957
20111
  useImageGenerator: content || true,
19958
20112
  },
19959
20113
  }, spaceTrim$1(`
@@ -20244,8 +20398,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
20244
20398
  return this.appendToSystemMessage({
20245
20399
  ...requirements,
20246
20400
  tools: updatedTools,
20247
- metadata: {
20248
- ...requirements.metadata,
20401
+ _metadata: {
20402
+ ...requirements._metadata,
20249
20403
  useSearchEngine: content || true,
20250
20404
  },
20251
20405
  }, spaceTrim$1((block) => `
@@ -20393,8 +20547,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
20393
20547
  return this.appendToSystemMessage({
20394
20548
  ...requirements,
20395
20549
  tools: updatedTools,
20396
- metadata: {
20397
- ...requirements.metadata,
20550
+ _metadata: {
20551
+ ...requirements._metadata,
20398
20552
  },
20399
20553
  }, spaceTrim$1((block) => `
20400
20554
  Time and date context:
@@ -24972,6 +25126,66 @@ const OPENAI_MODELS = exportJson({
24972
25126
  },
24973
25127
  /**/
24974
25128
  /**/
25129
+ {
25130
+ modelVariant: 'CHAT',
25131
+ modelTitle: 'gpt-5.2-codex',
25132
+ modelName: 'gpt-5.2-codex',
25133
+ 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.',
25134
+ pricing: {
25135
+ prompt: pricing(`$1.75 / 1M tokens`),
25136
+ output: pricing(`$14.00 / 1M tokens`),
25137
+ },
25138
+ },
25139
+ /**/
25140
+ /**/
25141
+ {
25142
+ modelVariant: 'CHAT',
25143
+ modelTitle: 'gpt-5.1-codex-max',
25144
+ modelName: 'gpt-5.1-codex-max',
25145
+ modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
25146
+ pricing: {
25147
+ prompt: pricing(`$1.25 / 1M tokens`),
25148
+ output: pricing(`$10.00 / 1M tokens`),
25149
+ },
25150
+ },
25151
+ /**/
25152
+ /**/
25153
+ {
25154
+ modelVariant: 'CHAT',
25155
+ modelTitle: 'gpt-5.1-codex',
25156
+ modelName: 'gpt-5.1-codex',
25157
+ modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
25158
+ pricing: {
25159
+ prompt: pricing(`$1.25 / 1M tokens`),
25160
+ output: pricing(`$10.00 / 1M tokens`),
25161
+ },
25162
+ },
25163
+ /**/
25164
+ /**/
25165
+ {
25166
+ modelVariant: 'CHAT',
25167
+ modelTitle: 'gpt-5.1-codex-mini',
25168
+ modelName: 'gpt-5.1-codex-mini',
25169
+ modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
25170
+ pricing: {
25171
+ prompt: pricing(`$0.25 / 1M tokens`),
25172
+ output: pricing(`$2.00 / 1M tokens`),
25173
+ },
25174
+ },
25175
+ /**/
25176
+ /**/
25177
+ {
25178
+ modelVariant: 'CHAT',
25179
+ modelTitle: 'gpt-5-codex',
25180
+ modelName: 'gpt-5-codex',
25181
+ modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
25182
+ pricing: {
25183
+ prompt: pricing(`$1.25 / 1M tokens`),
25184
+ output: pricing(`$10.00 / 1M tokens`),
25185
+ },
25186
+ },
25187
+ /**/
25188
+ /**/
24975
25189
  {
24976
25190
  modelVariant: 'CHAT',
24977
25191
  modelTitle: 'gpt-5-mini',
@@ -27000,6 +27214,32 @@ function isUnsupportedParameterError(error) {
27000
27214
  errorMessage.includes('does not support'));
27001
27215
  }
27002
27216
 
27217
+ /**
27218
+ * Provides access to the structured clone implementation when available.
27219
+ */
27220
+ function getStructuredCloneFunction() {
27221
+ return globalThis.structuredClone;
27222
+ }
27223
+ /**
27224
+ * Checks whether the prompt is a chat prompt that carries file attachments.
27225
+ */
27226
+ function hasChatPromptFiles(prompt) {
27227
+ return 'files' in prompt && Array.isArray(prompt.files);
27228
+ }
27229
+ /**
27230
+ * Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
27231
+ */
27232
+ function clonePromptPreservingFiles(prompt) {
27233
+ const structuredCloneFn = getStructuredCloneFunction();
27234
+ if (typeof structuredCloneFn === 'function') {
27235
+ return structuredCloneFn(prompt);
27236
+ }
27237
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
27238
+ if (hasChatPromptFiles(prompt)) {
27239
+ clonedPrompt.files = prompt.files;
27240
+ }
27241
+ return clonedPrompt;
27242
+ }
27003
27243
  /**
27004
27244
  * Execution Tools for calling OpenAI API or other OpenAI compatible provider
27005
27245
  *
@@ -27084,7 +27324,7 @@ class OpenAiCompatibleExecutionTools {
27084
27324
  */
27085
27325
  async callChatModelStream(prompt, onProgress) {
27086
27326
  // Deep clone prompt and modelRequirements to avoid mutation across calls
27087
- const clonedPrompt = JSON.parse(JSON.stringify(prompt));
27327
+ const clonedPrompt = clonePromptPreservingFiles(prompt);
27088
27328
  // Use local Set for retried parameters to ensure independence and thread safety
27089
27329
  const retriedUnsupportedParameters = new Set();
27090
27330
  return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
@@ -27111,7 +27351,10 @@ class OpenAiCompatibleExecutionTools {
27111
27351
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
27112
27352
  // <- Note: [🧆]
27113
27353
  }; // <- TODO: [💩] Guard here types better
27114
- if (format === 'JSON') {
27354
+ if (currentModelRequirements.responseFormat !== undefined) {
27355
+ modelSettings.response_format = currentModelRequirements.responseFormat;
27356
+ }
27357
+ else if (format === 'JSON') {
27115
27358
  modelSettings.response_format = {
27116
27359
  type: 'json_object',
27117
27360
  };
@@ -29089,7 +29332,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
29089
29332
  const processingStartedAtMs = Date.now();
29090
29333
  for (const [index, source] of knowledgeSources.entries()) {
29091
29334
  try {
29092
- const sourceType = source.startsWith('http') || source.startsWith('https') ? 'url' : 'file';
29335
+ const isDataUrl = isDataUrlKnowledgeSource(source);
29336
+ const isHttp = source.startsWith('http://') || source.startsWith('https://');
29337
+ const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
29093
29338
  if (this.options.isVerbose) {
29094
29339
  console.info('[🤰]', 'Processing knowledge source', {
29095
29340
  index: index + 1,
@@ -29099,8 +29344,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
29099
29344
  logLabel,
29100
29345
  });
29101
29346
  }
29102
- // Check if it's a URL
29103
- if (source.startsWith('http://') || source.startsWith('https://')) {
29347
+ if (isDataUrl) {
29348
+ const parsed = parseDataUrlKnowledgeSource(source);
29349
+ if (!parsed) {
29350
+ skippedSources.push({ source, reason: 'invalid_data_url' });
29351
+ if (this.options.isVerbose) {
29352
+ console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
29353
+ source,
29354
+ sourceType,
29355
+ logLabel,
29356
+ });
29357
+ }
29358
+ continue;
29359
+ }
29360
+ const dataUrlFile = new File([parsed.buffer], parsed.filename, {
29361
+ type: parsed.mimeType,
29362
+ });
29363
+ fileStreams.push(dataUrlFile);
29364
+ totalBytes += parsed.buffer.length;
29365
+ continue;
29366
+ }
29367
+ if (isHttp) {
29104
29368
  const downloadResult = await this.downloadKnowledgeSourceFile({
29105
29369
  source,
29106
29370
  timeoutMs: downloadTimeoutMs,
@@ -30985,11 +31249,14 @@ const _FormattedBookInMarkdownTranspilerRegistration = $bookTranspilersRegister.
30985
31249
  function createEmptyAgentModelRequirements() {
30986
31250
  return {
30987
31251
  systemMessage: '',
31252
+ promptSuffix: '',
30988
31253
  // modelName: 'gpt-5',
30989
31254
  modelName: 'gemini-2.5-flash-lite',
30990
31255
  temperature: 0.7,
30991
31256
  topP: 0.9,
30992
31257
  topK: 50,
31258
+ parentAgentUrl: null,
31259
+ isClosed: false,
30993
31260
  };
30994
31261
  }
30995
31262
  /**
@@ -31423,8 +31690,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
31423
31690
  // Store the agent name in metadata so commitments can access it
31424
31691
  requirements = {
31425
31692
  ...requirements,
31426
- metadata: {
31427
- ...requirements.metadata,
31693
+ _metadata: {
31694
+ ...requirements._metadata,
31428
31695
  agentName: parseResult.agentName,
31429
31696
  },
31430
31697
  };
@@ -32674,6 +32941,64 @@ function promptbookifyAiText(text) {
32674
32941
  */
32675
32942
 
32676
32943
  const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
32944
+ const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
32945
+ /*
32946
+ TODO: Use or remove
32947
+ const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
32948
+ type: 'object',
32949
+ properties: {},
32950
+ required: [],
32951
+ additionalProperties: true,
32952
+ };
32953
+ */
32954
+ function buildJsonSchemaDefinition(jsonSchema) {
32955
+ var _a, _b, _c;
32956
+ const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
32957
+ return {
32958
+ type: 'json_schema',
32959
+ name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
32960
+ strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
32961
+ schema: {
32962
+ type: 'object',
32963
+ properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
32964
+ required: Array.isArray(schema.required) ? schema.required : [],
32965
+ additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
32966
+ description: schema.description,
32967
+ },
32968
+ };
32969
+ }
32970
+ /**
32971
+ * Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
32972
+ * structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
32973
+ *
32974
+ * @param responseFormat - The OpenAI `response_format` payload from the user request.
32975
+ * @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
32976
+ * @private utility of Open AI
32977
+ */
32978
+ function mapResponseFormatToAgentOutputType(responseFormat) {
32979
+ if (!responseFormat) {
32980
+ return undefined;
32981
+ }
32982
+ if (typeof responseFormat === 'string') {
32983
+ if (responseFormat === 'text') {
32984
+ return 'text';
32985
+ }
32986
+ if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
32987
+ return buildJsonSchemaDefinition();
32988
+ }
32989
+ return 'text';
32990
+ }
32991
+ switch (responseFormat.type) {
32992
+ case 'text':
32993
+ return 'text';
32994
+ case 'json_schema':
32995
+ return buildJsonSchemaDefinition(responseFormat.json_schema);
32996
+ case 'json_object':
32997
+ return buildJsonSchemaDefinition();
32998
+ default:
32999
+ return undefined;
33000
+ }
33001
+ }
32677
33002
  /**
32678
33003
  * Execution tools for OpenAI AgentKit (Agents SDK).
32679
33004
  *
@@ -32721,6 +33046,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
32721
33046
  ...parameters,
32722
33047
  modelName: this.agentKitModelName,
32723
33048
  });
33049
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
32724
33050
  const preparedAgentKitAgent = await this.prepareAgentKitAgent({
32725
33051
  name: (prompt.title || 'Agent'),
32726
33052
  instructions: modelRequirements.systemMessage || '',
@@ -32732,6 +33058,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
32732
33058
  prompt,
32733
33059
  rawPromptContent,
32734
33060
  onProgress,
33061
+ responseFormatOutputType,
32735
33062
  });
32736
33063
  }
32737
33064
  /**
@@ -32913,16 +33240,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
32913
33240
  ...prompt.parameters,
32914
33241
  modelName: this.agentKitModelName,
32915
33242
  });
33243
+ const agentForRun = options.responseFormatOutputType !== undefined
33244
+ ? openAiAgentKitAgent.clone({
33245
+ outputType: options.responseFormatOutputType,
33246
+ })
33247
+ : openAiAgentKitAgent;
32916
33248
  const start = $getCurrentDate();
32917
33249
  let latestContent = '';
32918
33250
  const toolCalls = [];
32919
33251
  const toolCallIndexById = new Map();
32920
33252
  const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
32921
33253
  const rawRequest = {
32922
- agentName: openAiAgentKitAgent.name,
33254
+ agentName: agentForRun.name,
32923
33255
  input: inputItems,
32924
33256
  };
32925
- const streamResult = await run(openAiAgentKitAgent, inputItems, {
33257
+ const streamResult = await run(agentForRun, inputItems, {
32926
33258
  stream: true,
32927
33259
  context: { parameters: prompt.parameters },
32928
33260
  });
@@ -33270,22 +33602,28 @@ class AgentLlmExecutionTools {
33270
33602
  throw new Error('AgentLlmExecutionTools only supports chat prompts');
33271
33603
  }
33272
33604
  const modelRequirements = await this.getModelRequirements();
33605
+ const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
33273
33606
  const chatPrompt = prompt;
33274
33607
  let underlyingLlmResult;
33275
- // Create modified chat prompt with agent system message
33608
+ const chatPromptContentWithSuffix = promptSuffix
33609
+ ? `${chatPrompt.content}\n\n${promptSuffix}`
33610
+ : chatPrompt.content;
33276
33611
  const promptWithAgentModelRequirements = {
33277
33612
  ...chatPrompt,
33613
+ content: chatPromptContentWithSuffix,
33278
33614
  modelRequirements: {
33279
33615
  ...chatPrompt.modelRequirements,
33280
- ...modelRequirements,
33616
+ ...sanitizedRequirements,
33281
33617
  // Spread tools to convert readonly array to mutable
33282
- tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
33618
+ tools: sanitizedRequirements.tools
33619
+ ? [...sanitizedRequirements.tools]
33620
+ : chatPrompt.modelRequirements.tools,
33283
33621
  // Spread knowledgeSources to convert readonly array to mutable
33284
- knowledgeSources: modelRequirements.knowledgeSources
33285
- ? [...modelRequirements.knowledgeSources]
33622
+ knowledgeSources: sanitizedRequirements.knowledgeSources
33623
+ ? [...sanitizedRequirements.knowledgeSources]
33286
33624
  : undefined,
33287
33625
  // Prepend agent system message to existing system message
33288
- systemMessage: modelRequirements.systemMessage +
33626
+ systemMessage: sanitizedRequirements.systemMessage +
33289
33627
  (chatPrompt.modelRequirements.systemMessage
33290
33628
  ? `\n\n${chatPrompt.modelRequirements.systemMessage}`
33291
33629
  : ''),
@@ -33293,8 +33631,8 @@ class AgentLlmExecutionTools {
33293
33631
  };
33294
33632
  console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
33295
33633
  if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
33296
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
33297
- const vectorStoreHash = SHA256(JSON.stringify((_a = modelRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
33634
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
33635
+ const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
33298
33636
  const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
33299
33637
  const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
33300
33638
  let preparedAgentKit = this.options.assistantPreparationMode === 'external'
@@ -33321,7 +33659,7 @@ class AgentLlmExecutionTools {
33321
33659
  agent: this.title,
33322
33660
  });
33323
33661
  }
33324
- if (!vectorStoreId && ((_b = modelRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
33662
+ if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
33325
33663
  emitAssistantPreparationProgress({
33326
33664
  onProgress,
33327
33665
  prompt,
@@ -33337,9 +33675,9 @@ class AgentLlmExecutionTools {
33337
33675
  });
33338
33676
  preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
33339
33677
  name: this.title,
33340
- instructions: modelRequirements.systemMessage || '',
33341
- knowledgeSources: modelRequirements.knowledgeSources,
33342
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
33678
+ instructions: sanitizedRequirements.systemMessage || '',
33679
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
33680
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
33343
33681
  vectorStoreId,
33344
33682
  });
33345
33683
  }
@@ -33354,15 +33692,17 @@ class AgentLlmExecutionTools {
33354
33692
  requirementsHash,
33355
33693
  vectorStoreId: preparedAgentKit.vectorStoreId,
33356
33694
  });
33695
+ const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
33357
33696
  underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
33358
33697
  openAiAgentKitAgent: preparedAgentKit.agent,
33359
33698
  prompt: promptWithAgentModelRequirements,
33360
33699
  onProgress,
33700
+ responseFormatOutputType,
33361
33701
  });
33362
33702
  }
33363
33703
  else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
33364
33704
  // ... deprecated path ...
33365
- const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
33705
+ const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
33366
33706
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
33367
33707
  let assistant;
33368
33708
  if (this.options.assistantPreparationMode === 'external') {
@@ -33404,9 +33744,9 @@ class AgentLlmExecutionTools {
33404
33744
  assistant = await this.options.llmTools.updateAssistant({
33405
33745
  assistantId: cached.assistantId,
33406
33746
  name: this.title,
33407
- instructions: modelRequirements.systemMessage,
33408
- knowledgeSources: modelRequirements.knowledgeSources,
33409
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
33747
+ instructions: sanitizedRequirements.systemMessage,
33748
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
33749
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
33410
33750
  });
33411
33751
  AgentLlmExecutionTools.assistantCache.set(this.title, {
33412
33752
  assistantId: assistant.assistantId,
@@ -33429,9 +33769,9 @@ class AgentLlmExecutionTools {
33429
33769
  });
33430
33770
  assistant = await this.options.llmTools.createNewAssistant({
33431
33771
  name: this.title,
33432
- instructions: modelRequirements.systemMessage,
33433
- knowledgeSources: modelRequirements.knowledgeSources,
33434
- tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
33772
+ instructions: sanitizedRequirements.systemMessage,
33773
+ knowledgeSources: sanitizedRequirements.knowledgeSources,
33774
+ tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
33435
33775
  /*
33436
33776
  !!!
33437
33777
  metadata: {
@@ -33473,13 +33813,19 @@ class AgentLlmExecutionTools {
33473
33813
  }
33474
33814
  }
33475
33815
  let content = underlyingLlmResult.content;
33476
- // Note: Cleanup the AI artifacts from the content
33477
- content = humanizeAiText(content);
33478
- // Note: Make sure the content is Promptbook-like
33479
- content = promptbookifyAiText(content);
33816
+ if (typeof content === 'string') {
33817
+ // Note: Cleanup the AI artifacts from the content
33818
+ content = humanizeAiText(content);
33819
+ // Note: Make sure the content is Promptbook-like
33820
+ content = promptbookifyAiText(content);
33821
+ }
33822
+ else {
33823
+ // TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
33824
+ content = JSON.stringify(content);
33825
+ }
33480
33826
  const agentResult = {
33481
33827
  ...underlyingLlmResult,
33482
- content,
33828
+ content: content,
33483
33829
  modelName: this.modelName,
33484
33830
  };
33485
33831
  return agentResult;
@@ -33668,7 +34014,6 @@ class Agent extends AgentLlmExecutionTools {
33668
34014
  * Note: This method also implements the learning mechanism
33669
34015
  */
33670
34016
  async callChatModelStream(prompt, onProgress) {
33671
- var _a;
33672
34017
  // [1] Check if the user is asking the same thing as in the samples
33673
34018
  const modelRequirements = await this.getModelRequirements();
33674
34019
  if (modelRequirements.samples) {
@@ -33716,7 +34061,7 @@ class Agent extends AgentLlmExecutionTools {
33716
34061
  if (result.rawResponse && 'sample' in result.rawResponse) {
33717
34062
  return result;
33718
34063
  }
33719
- if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
34064
+ if (modelRequirements.isClosed) {
33720
34065
  return result;
33721
34066
  }
33722
34067
  // Note: [0] Notify start of self-learning