@promptbook/node 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
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
35
35
  * @generated
36
36
  * @see https://github.com/webgptorg/promptbook
37
37
  */
38
- const PROMPTBOOK_ENGINE_VERSION = '0.111.0-0';
38
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-2';
39
39
  /**
40
40
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
41
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -18358,8 +18358,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
18358
18358
  /**
18359
18359
  * USE IMAGE GENERATOR commitment definition
18360
18360
  *
18361
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
18362
- * to create images based on text prompts.
18361
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
18362
+ * markdown placeholders for UI-driven image generation.
18363
18363
  *
18364
18364
  * Example usage in agent source:
18365
18365
  *
@@ -18374,11 +18374,14 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
18374
18374
  constructor(type = 'USE IMAGE GENERATOR') {
18375
18375
  super(type, ['USE IMAGE GENERATION', 'IMAGE GENERATOR', 'IMAGE GENERATION', 'USE IMAGE']);
18376
18376
  }
18377
+ get requiresContent() {
18378
+ return false;
18379
+ }
18377
18380
  /**
18378
18381
  * Short one-line description of USE IMAGE GENERATOR.
18379
18382
  */
18380
18383
  get description() {
18381
- return 'Enable the agent to use an image generation tool for creating images from text prompts.';
18384
+ return 'Enable the agent to output markdown image placeholders that the UI turns into generated images.';
18382
18385
  }
18383
18386
  /**
18384
18387
  * Icon for this commitment.
@@ -18393,21 +18396,21 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
18393
18396
  return spaceTrim$1(`
18394
18397
  # USE IMAGE GENERATOR
18395
18398
 
18396
- Enables the agent to use an image generation tool to create images based on text prompts.
18399
+ Enables the agent to output markdown image placeholders that trigger image generation in the user interface.
18397
18400
 
18398
18401
  ## Key aspects
18399
18402
 
18400
18403
  - The content following \`USE IMAGE GENERATOR\` is an arbitrary text that the agent should know (e.g. style instructions or safety guidelines).
18401
- - The actual image generation is handled by the agent runtime using LLM execution tools.
18402
- - Allows the agent to generate visual content based on user requests.
18403
- - Returns the URL of the generated image.
18404
+ - The agent does **not** call an image-generation tool directly.
18405
+ - The agent inserts markdown notation: \`![alt](?image-prompt=...)\`.
18406
+ - The user interface detects the notation and generates the image asynchronously.
18404
18407
 
18405
18408
  ## Examples
18406
18409
 
18407
18410
  \`\`\`book
18408
18411
  Visual Artist
18409
18412
 
18410
- PERSONA You are a creative visual artist who can generate images.
18413
+ PERSONA You are a creative visual artist.
18411
18414
  USE IMAGE GENERATOR
18412
18415
  RULE Always describe the generated image to the user.
18413
18416
  \`\`\`
@@ -18417,80 +18420,28 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
18417
18420
 
18418
18421
  PERSONA You are an interior designer who helps users visualize their space.
18419
18422
  USE IMAGE GENERATOR Professional interior design renders.
18420
- ACTION Generate a preview of the designed room.
18423
+ ACTION Add one generated image placeholder whenever a user asks for a visual.
18421
18424
  \`\`\`
18422
18425
  `);
18423
18426
  }
18424
18427
  applyToAgentModelRequirements(requirements, content) {
18425
- // Get existing tools array or create new one
18426
- const existingTools = requirements.tools || [];
18427
- // Add 'generate_image' to tools if not already present
18428
- const updatedTools = existingTools.some((tool) => tool.name === 'generate_image')
18429
- ? existingTools
18430
- : [
18431
- ...existingTools,
18432
- {
18433
- name: 'generate_image',
18434
- description: spaceTrim$1(`
18435
- Generate an image from a text prompt.
18436
- Use this tool when the user asks to create, draw, or generate an image.
18437
- ${!content ? '' : `Style instructions / guidelines: ${content}`}
18438
- `),
18439
- parameters: {
18440
- type: 'object',
18441
- properties: {
18442
- prompt: {
18443
- type: 'string',
18444
- description: 'The detailed description of the image to generate',
18445
- },
18446
- },
18447
- required: ['prompt'],
18448
- },
18449
- },
18450
- ];
18451
- // Return requirements with updated tools and metadata
18428
+ const extraInstructions = formatOptionalInstructionBlock('Image instructions', content);
18452
18429
  return this.appendToSystemMessage({
18453
18430
  ...requirements,
18454
- tools: updatedTools,
18455
18431
  _metadata: {
18456
18432
  ...requirements._metadata,
18457
18433
  useImageGenerator: content || true,
18458
18434
  },
18459
- }, spaceTrim$1(`
18460
- You have access to an image generator. Use it to create images based on user requests.
18461
- When you generate an image, you will receive a URL of the generated image.
18462
- `));
18463
- }
18464
- /**
18465
- * Gets human-readable titles for tool functions provided by this commitment.
18466
- */
18467
- getToolTitles() {
18468
- return {
18469
- generate_image: 'Generate image',
18470
- };
18471
- }
18472
- /**
18473
- * Gets the `generate_image` tool function implementation.
18474
- */
18475
- getToolFunctions() {
18476
- return {
18477
- async generate_image(args, ...extra) {
18478
- console.log('!!!! [Tool] generate_image called', { args });
18479
- const { prompt } = args;
18480
- if (!prompt) {
18481
- throw new Error('Image prompt is required');
18482
- }
18483
- const { llmTools } = extra[0] || {};
18484
- if (!llmTools || !llmTools.callImageGenerationModel) {
18485
- throw new Error('Image generation is not supported by the current model provider');
18486
- }
18487
- const result = await llmTools.callImageGenerationModel({
18488
- content: prompt,
18489
- modelName: 'dall-e-3', // Defaulting to dall-e-3, but this could be configurable
18490
- });
18491
- return result.content;
18492
- },
18493
- };
18435
+ }, spaceTrim$1((block) => `
18436
+ Image generation:
18437
+ - You do not generate images directly and you do not call any image tool.
18438
+ - When the user asks for an image, include markdown notation in your message:
18439
+ \`![<alt text>](?image-prompt=<prompt>)\`
18440
+ - Keep \`<alt text>\` short and descriptive.
18441
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
18442
+ - You can include normal explanatory text before and after the notation.
18443
+ ${block(extraInstructions)}
18444
+ `));
18494
18445
  }
18495
18446
  }
18496
18447
  /**
@@ -27141,7 +27092,6 @@ class RemoteAgent extends Agent {
27141
27092
  doneReading = !!done;
27142
27093
  if (value) {
27143
27094
  const textChunk = decoder.decode(value, { stream: true });
27144
- let sawToolCalls = false;
27145
27095
  let hasNonEmptyText = false;
27146
27096
  const textLines = [];
27147
27097
  const lines = textChunk.split(/\r?\n/);
@@ -27167,7 +27117,6 @@ class RemoteAgent extends Agent {
27167
27117
  rawResponse: {},
27168
27118
  toolCalls: getActiveToolCalls(),
27169
27119
  });
27170
- sawToolCalls = true;
27171
27120
  isToolCallLine = true;
27172
27121
  }
27173
27122
  }
@@ -27177,22 +27126,16 @@ class RemoteAgent extends Agent {
27177
27126
  }
27178
27127
  if (!isToolCallLine) {
27179
27128
  textLines.push(line);
27180
- if (line.length > 0) {
27129
+ if (trimmedLine.length > 0) {
27181
27130
  hasNonEmptyText = true;
27182
27131
  }
27183
27132
  }
27184
27133
  }
27185
- if (sawToolCalls) {
27186
- if (!hasNonEmptyText) {
27187
- continue;
27188
- }
27189
- const textChunkWithoutToolCalls = textLines.join('\n');
27190
- content += textChunkWithoutToolCalls;
27191
- }
27192
- else {
27193
- // console.debug('RemoteAgent chunk:', textChunk);
27194
- content += textChunk;
27134
+ if (!hasNonEmptyText) {
27135
+ continue;
27195
27136
  }
27137
+ const textChunkWithoutToolCalls = textLines.join('\n');
27138
+ content += textChunkWithoutToolCalls;
27196
27139
  if (!hasReceivedModelOutput && content.trim().length > 0) {
27197
27140
  hasReceivedModelOutput = true;
27198
27141
  preparationToolCalls.length = 0;