@promptbook/cli 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
@@ -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.111.0-0';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-2';
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
@@ -20476,8 +20476,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
20476
20476
  /**
20477
20477
  * USE IMAGE GENERATOR commitment definition
20478
20478
  *
20479
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
20480
- * to create images based on text prompts.
20479
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
20480
+ * markdown placeholders for UI-driven image generation.
20481
20481
  *
20482
20482
  * Example usage in agent source:
20483
20483
  *
@@ -20492,11 +20492,14 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
20492
20492
  constructor(type = 'USE IMAGE GENERATOR') {
20493
20493
  super(type, ['USE IMAGE GENERATION', 'IMAGE GENERATOR', 'IMAGE GENERATION', 'USE IMAGE']);
20494
20494
  }
20495
+ get requiresContent() {
20496
+ return false;
20497
+ }
20495
20498
  /**
20496
20499
  * Short one-line description of USE IMAGE GENERATOR.
20497
20500
  */
20498
20501
  get description() {
20499
- return 'Enable the agent to use an image generation tool for creating images from text prompts.';
20502
+ return 'Enable the agent to output markdown image placeholders that the UI turns into generated images.';
20500
20503
  }
20501
20504
  /**
20502
20505
  * Icon for this commitment.
@@ -20511,21 +20514,21 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
20511
20514
  return spaceTrim$1(`
20512
20515
  # USE IMAGE GENERATOR
20513
20516
 
20514
- Enables the agent to use an image generation tool to create images based on text prompts.
20517
+ Enables the agent to output markdown image placeholders that trigger image generation in the user interface.
20515
20518
 
20516
20519
  ## Key aspects
20517
20520
 
20518
20521
  - The content following \`USE IMAGE GENERATOR\` is an arbitrary text that the agent should know (e.g. style instructions or safety guidelines).
20519
- - The actual image generation is handled by the agent runtime using LLM execution tools.
20520
- - Allows the agent to generate visual content based on user requests.
20521
- - Returns the URL of the generated image.
20522
+ - The agent does **not** call an image-generation tool directly.
20523
+ - The agent inserts markdown notation: \`![alt](?image-prompt=...)\`.
20524
+ - The user interface detects the notation and generates the image asynchronously.
20522
20525
 
20523
20526
  ## Examples
20524
20527
 
20525
20528
  \`\`\`book
20526
20529
  Visual Artist
20527
20530
 
20528
- PERSONA You are a creative visual artist who can generate images.
20531
+ PERSONA You are a creative visual artist.
20529
20532
  USE IMAGE GENERATOR
20530
20533
  RULE Always describe the generated image to the user.
20531
20534
  \`\`\`
@@ -20535,80 +20538,28 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
20535
20538
 
20536
20539
  PERSONA You are an interior designer who helps users visualize their space.
20537
20540
  USE IMAGE GENERATOR Professional interior design renders.
20538
- ACTION Generate a preview of the designed room.
20541
+ ACTION Add one generated image placeholder whenever a user asks for a visual.
20539
20542
  \`\`\`
20540
20543
  `);
20541
20544
  }
20542
20545
  applyToAgentModelRequirements(requirements, content) {
20543
- // Get existing tools array or create new one
20544
- const existingTools = requirements.tools || [];
20545
- // Add 'generate_image' to tools if not already present
20546
- const updatedTools = existingTools.some((tool) => tool.name === 'generate_image')
20547
- ? existingTools
20548
- : [
20549
- ...existingTools,
20550
- {
20551
- name: 'generate_image',
20552
- description: spaceTrim$1(`
20553
- Generate an image from a text prompt.
20554
- Use this tool when the user asks to create, draw, or generate an image.
20555
- ${!content ? '' : `Style instructions / guidelines: ${content}`}
20556
- `),
20557
- parameters: {
20558
- type: 'object',
20559
- properties: {
20560
- prompt: {
20561
- type: 'string',
20562
- description: 'The detailed description of the image to generate',
20563
- },
20564
- },
20565
- required: ['prompt'],
20566
- },
20567
- },
20568
- ];
20569
- // Return requirements with updated tools and metadata
20546
+ const extraInstructions = formatOptionalInstructionBlock('Image instructions', content);
20570
20547
  return this.appendToSystemMessage({
20571
20548
  ...requirements,
20572
- tools: updatedTools,
20573
20549
  _metadata: {
20574
20550
  ...requirements._metadata,
20575
20551
  useImageGenerator: content || true,
20576
20552
  },
20577
- }, spaceTrim$1(`
20578
- You have access to an image generator. Use it to create images based on user requests.
20579
- When you generate an image, you will receive a URL of the generated image.
20580
- `));
20581
- }
20582
- /**
20583
- * Gets human-readable titles for tool functions provided by this commitment.
20584
- */
20585
- getToolTitles() {
20586
- return {
20587
- generate_image: 'Generate image',
20588
- };
20589
- }
20590
- /**
20591
- * Gets the `generate_image` tool function implementation.
20592
- */
20593
- getToolFunctions() {
20594
- return {
20595
- async generate_image(args, ...extra) {
20596
- console.log('!!!! [Tool] generate_image called', { args });
20597
- const { prompt } = args;
20598
- if (!prompt) {
20599
- throw new Error('Image prompt is required');
20600
- }
20601
- const { llmTools } = extra[0] || {};
20602
- if (!llmTools || !llmTools.callImageGenerationModel) {
20603
- throw new Error('Image generation is not supported by the current model provider');
20604
- }
20605
- const result = await llmTools.callImageGenerationModel({
20606
- content: prompt,
20607
- modelName: 'dall-e-3', // Defaulting to dall-e-3, but this could be configurable
20608
- });
20609
- return result.content;
20610
- },
20611
- };
20553
+ }, spaceTrim$1((block) => `
20554
+ Image generation:
20555
+ - You do not generate images directly and you do not call any image tool.
20556
+ - When the user asks for an image, include markdown notation in your message:
20557
+ \`![<alt text>](?image-prompt=<prompt>)\`
20558
+ - Keep \`<alt text>\` short and descriptive.
20559
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
20560
+ - You can include normal explanatory text before and after the notation.
20561
+ ${block(extraInstructions)}
20562
+ `));
20612
20563
  }
20613
20564
  }
20614
20565
  /**
@@ -35105,7 +35056,6 @@ class RemoteAgent extends Agent {
35105
35056
  doneReading = !!done;
35106
35057
  if (value) {
35107
35058
  const textChunk = decoder.decode(value, { stream: true });
35108
- let sawToolCalls = false;
35109
35059
  let hasNonEmptyText = false;
35110
35060
  const textLines = [];
35111
35061
  const lines = textChunk.split(/\r?\n/);
@@ -35131,7 +35081,6 @@ class RemoteAgent extends Agent {
35131
35081
  rawResponse: {},
35132
35082
  toolCalls: getActiveToolCalls(),
35133
35083
  });
35134
- sawToolCalls = true;
35135
35084
  isToolCallLine = true;
35136
35085
  }
35137
35086
  }
@@ -35141,22 +35090,16 @@ class RemoteAgent extends Agent {
35141
35090
  }
35142
35091
  if (!isToolCallLine) {
35143
35092
  textLines.push(line);
35144
- if (line.length > 0) {
35093
+ if (trimmedLine.length > 0) {
35145
35094
  hasNonEmptyText = true;
35146
35095
  }
35147
35096
  }
35148
35097
  }
35149
- if (sawToolCalls) {
35150
- if (!hasNonEmptyText) {
35151
- continue;
35152
- }
35153
- const textChunkWithoutToolCalls = textLines.join('\n');
35154
- content += textChunkWithoutToolCalls;
35155
- }
35156
- else {
35157
- // console.debug('RemoteAgent chunk:', textChunk);
35158
- content += textChunk;
35098
+ if (!hasNonEmptyText) {
35099
+ continue;
35159
35100
  }
35101
+ const textChunkWithoutToolCalls = textLines.join('\n');
35102
+ content += textChunkWithoutToolCalls;
35160
35103
  if (!hasReceivedModelOutput && content.trim().length > 0) {
35161
35104
  hasReceivedModelOutput = true;
35162
35105
  preparationToolCalls.length = 0;