@promptbook/core 0.111.0-0 → 0.111.0-2

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.
package/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.111.0-0';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-2';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -14734,8 +14734,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
14734
14734
  /**
14735
14735
  * USE IMAGE GENERATOR commitment definition
14736
14736
  *
14737
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
14738
- * to create images based on text prompts.
14737
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
14738
+ * markdown placeholders for UI-driven image generation.
14739
14739
  *
14740
14740
  * Example usage in agent source:
14741
14741
  *
@@ -14750,11 +14750,14 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
14750
14750
  constructor(type = 'USE IMAGE GENERATOR') {
14751
14751
  super(type, ['USE IMAGE GENERATION', 'IMAGE GENERATOR', 'IMAGE GENERATION', 'USE IMAGE']);
14752
14752
  }
14753
+ get requiresContent() {
14754
+ return false;
14755
+ }
14753
14756
  /**
14754
14757
  * Short one-line description of USE IMAGE GENERATOR.
14755
14758
  */
14756
14759
  get description() {
14757
- return 'Enable the agent to use an image generation tool for creating images from text prompts.';
14760
+ return 'Enable the agent to output markdown image placeholders that the UI turns into generated images.';
14758
14761
  }
14759
14762
  /**
14760
14763
  * Icon for this commitment.
@@ -14769,21 +14772,21 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
14769
14772
  return spaceTrim$1(`
14770
14773
  # USE IMAGE GENERATOR
14771
14774
 
14772
- Enables the agent to use an image generation tool to create images based on text prompts.
14775
+ Enables the agent to output markdown image placeholders that trigger image generation in the user interface.
14773
14776
 
14774
14777
  ## Key aspects
14775
14778
 
14776
14779
  - The content following \`USE IMAGE GENERATOR\` is an arbitrary text that the agent should know (e.g. style instructions or safety guidelines).
14777
- - The actual image generation is handled by the agent runtime using LLM execution tools.
14778
- - Allows the agent to generate visual content based on user requests.
14779
- - Returns the URL of the generated image.
14780
+ - The agent does **not** call an image-generation tool directly.
14781
+ - The agent inserts markdown notation: \`![alt](?image-prompt=...)\`.
14782
+ - The user interface detects the notation and generates the image asynchronously.
14780
14783
 
14781
14784
  ## Examples
14782
14785
 
14783
14786
  \`\`\`book
14784
14787
  Visual Artist
14785
14788
 
14786
- PERSONA You are a creative visual artist who can generate images.
14789
+ PERSONA You are a creative visual artist.
14787
14790
  USE IMAGE GENERATOR
14788
14791
  RULE Always describe the generated image to the user.
14789
14792
  \`\`\`
@@ -14793,80 +14796,28 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
14793
14796
 
14794
14797
  PERSONA You are an interior designer who helps users visualize their space.
14795
14798
  USE IMAGE GENERATOR Professional interior design renders.
14796
- ACTION Generate a preview of the designed room.
14799
+ ACTION Add one generated image placeholder whenever a user asks for a visual.
14797
14800
  \`\`\`
14798
14801
  `);
14799
14802
  }
14800
14803
  applyToAgentModelRequirements(requirements, content) {
14801
- // Get existing tools array or create new one
14802
- const existingTools = requirements.tools || [];
14803
- // Add 'generate_image' to tools if not already present
14804
- const updatedTools = existingTools.some((tool) => tool.name === 'generate_image')
14805
- ? existingTools
14806
- : [
14807
- ...existingTools,
14808
- {
14809
- name: 'generate_image',
14810
- description: spaceTrim$1(`
14811
- Generate an image from a text prompt.
14812
- Use this tool when the user asks to create, draw, or generate an image.
14813
- ${!content ? '' : `Style instructions / guidelines: ${content}`}
14814
- `),
14815
- parameters: {
14816
- type: 'object',
14817
- properties: {
14818
- prompt: {
14819
- type: 'string',
14820
- description: 'The detailed description of the image to generate',
14821
- },
14822
- },
14823
- required: ['prompt'],
14824
- },
14825
- },
14826
- ];
14827
- // Return requirements with updated tools and metadata
14804
+ const extraInstructions = formatOptionalInstructionBlock('Image instructions', content);
14828
14805
  return this.appendToSystemMessage({
14829
14806
  ...requirements,
14830
- tools: updatedTools,
14831
14807
  _metadata: {
14832
14808
  ...requirements._metadata,
14833
14809
  useImageGenerator: content || true,
14834
14810
  },
14835
- }, spaceTrim$1(`
14836
- You have access to an image generator. Use it to create images based on user requests.
14837
- When you generate an image, you will receive a URL of the generated image.
14838
- `));
14839
- }
14840
- /**
14841
- * Gets human-readable titles for tool functions provided by this commitment.
14842
- */
14843
- getToolTitles() {
14844
- return {
14845
- generate_image: 'Generate image',
14846
- };
14847
- }
14848
- /**
14849
- * Gets the `generate_image` tool function implementation.
14850
- */
14851
- getToolFunctions() {
14852
- return {
14853
- async generate_image(args, ...extra) {
14854
- console.log('!!!! [Tool] generate_image called', { args });
14855
- const { prompt } = args;
14856
- if (!prompt) {
14857
- throw new Error('Image prompt is required');
14858
- }
14859
- const { llmTools } = extra[0] || {};
14860
- if (!llmTools || !llmTools.callImageGenerationModel) {
14861
- throw new Error('Image generation is not supported by the current model provider');
14862
- }
14863
- const result = await llmTools.callImageGenerationModel({
14864
- content: prompt,
14865
- modelName: 'dall-e-3', // Defaulting to dall-e-3, but this could be configurable
14866
- });
14867
- return result.content;
14868
- },
14869
- };
14811
+ }, spaceTrim$1((block) => `
14812
+ Image generation:
14813
+ - You do not generate images directly and you do not call any image tool.
14814
+ - When the user asks for an image, include markdown notation in your message:
14815
+ \`![<alt text>](?image-prompt=<prompt>)\`
14816
+ - Keep \`<alt text>\` short and descriptive.
14817
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
14818
+ - You can include normal explanatory text before and after the notation.
14819
+ ${block(extraInstructions)}
14820
+ `));
14870
14821
  }
14871
14822
  }
14872
14823
  /**
@@ -26946,7 +26897,6 @@ class RemoteAgent extends Agent {
26946
26897
  doneReading = !!done;
26947
26898
  if (value) {
26948
26899
  const textChunk = decoder.decode(value, { stream: true });
26949
- let sawToolCalls = false;
26950
26900
  let hasNonEmptyText = false;
26951
26901
  const textLines = [];
26952
26902
  const lines = textChunk.split(/\r?\n/);
@@ -26972,7 +26922,6 @@ class RemoteAgent extends Agent {
26972
26922
  rawResponse: {},
26973
26923
  toolCalls: getActiveToolCalls(),
26974
26924
  });
26975
- sawToolCalls = true;
26976
26925
  isToolCallLine = true;
26977
26926
  }
26978
26927
  }
@@ -26982,22 +26931,16 @@ class RemoteAgent extends Agent {
26982
26931
  }
26983
26932
  if (!isToolCallLine) {
26984
26933
  textLines.push(line);
26985
- if (line.length > 0) {
26934
+ if (trimmedLine.length > 0) {
26986
26935
  hasNonEmptyText = true;
26987
26936
  }
26988
26937
  }
26989
26938
  }
26990
- if (sawToolCalls) {
26991
- if (!hasNonEmptyText) {
26992
- continue;
26993
- }
26994
- const textChunkWithoutToolCalls = textLines.join('\n');
26995
- content += textChunkWithoutToolCalls;
26996
- }
26997
- else {
26998
- // console.debug('RemoteAgent chunk:', textChunk);
26999
- content += textChunk;
26939
+ if (!hasNonEmptyText) {
26940
+ continue;
27000
26941
  }
26942
+ const textChunkWithoutToolCalls = textLines.join('\n');
26943
+ content += textChunkWithoutToolCalls;
27001
26944
  if (!hasReceivedModelOutput && content.trim().length > 0) {
27002
26945
  hasReceivedModelOutput = true;
27003
26946
  preparationToolCalls.length = 0;