@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.
@@ -0,0 +1,17 @@
1
+ import 'leaflet/dist/leaflet.css';
2
+ import type { GeoJsonObject } from 'geojson';
3
+ /**
4
+ * Props for `<ChatMessageMap/>`.
5
+ *
6
+ * @private internal helper of `<ChatMessageItem/>`
7
+ */
8
+ type ChatMessageMapProps = {
9
+ data: GeoJsonObject;
10
+ };
11
+ /**
12
+ * Renders a Leaflet map for GeoJSON data inside the chat bubble.
13
+ *
14
+ * @private internal helper of `<ChatMessageItem/>`
15
+ */
16
+ export declare function ChatMessageMap({ data }: ChatMessageMapProps): import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -17,6 +17,12 @@ export type ChatActionsOverlapConfig = {
17
17
  * Selector used to locate message elements for overlap checks.
18
18
  */
19
19
  messageSelector: string;
20
+ /**
21
+ * Optional selector for the actual message content region used for overlap checks.
22
+ *
23
+ * When not provided or when no matching element is found, the full message element is used.
24
+ */
25
+ messageCollisionSelector?: string;
20
26
  /**
21
27
  * Messages used to trigger overlap recalculation.
22
28
  */
@@ -0,0 +1,38 @@
1
+ import { ChatParticipant } from '../types/ChatParticipant';
2
+ import type { ParsedCitation } from './parseCitationsFromContent';
3
+ /**
4
+ * Returns whether the provided value is a valid HTTP(S) URL.
5
+ *
6
+ * @param value - Candidate string to inspect.
7
+ * @returns True when the value parses as an HTTP or HTTPS URL.
8
+ * @private utility of `<Chat/>` citation rendering
9
+ */
10
+ export declare function isCitationUrl(value: string): boolean;
11
+ /**
12
+ * Determines whether a citation should be displayed as a text snippet instead of a file/URL.
13
+ *
14
+ * @param citation - Parsed citation metadata.
15
+ * @returns True when the citation looks like inline text instead of a document or URL.
16
+ * @private utility of `<Chat/>` citation rendering
17
+ */
18
+ export declare function isPlainTextCitation(citation: ParsedCitation): boolean;
19
+ /**
20
+ * Builds a label that matches the desired chip/modal title for a citation.
21
+ *
22
+ * @param citation - Parsed citation metadata.
23
+ * @returns The friendly label shown on chips and modal headers.
24
+ * @private utility of `<Chat/>` citation rendering
25
+ */
26
+ export declare function getCitationLabel(citation: ParsedCitation): string;
27
+ /**
28
+ * Resolves the preview URL used inside the citation modal iframe.
29
+ *
30
+ * @param citation - Parsed citation metadata.
31
+ * @param participants - Known chat participants for agent knowledge lookup.
32
+ * @returns URL string suitable for iframe preview or null when unavailable.
33
+ * @private utility of `<Chat/>` citation rendering
34
+ */
35
+ export declare function resolveCitationPreviewUrl(citation: ParsedCitation, participants: ReadonlyArray<ChatParticipant>): string | null;
36
+ /**
37
+ * TODO: [💞] Spread into multiple files
38
+ */
@@ -0,0 +1,41 @@
1
+ import type { GeoJsonObject } from 'geojson';
2
+ import type { ImagePromptSegment } from './parseImagePrompts';
3
+ /**
4
+ * Segment that represents plain markdown text inside a chat message.
5
+ */
6
+ /**
7
+ * Segment that represents plain markdown text inside a chat message.
8
+ *
9
+ * @private internal helper of `<ChatMessageItem/>`
10
+ */
11
+ export type ChatTextSegment = {
12
+ type: 'text';
13
+ content: string;
14
+ };
15
+ /**
16
+ * Segment that represents a Leaflet-ready map rendered from GeoJSON data.
17
+ */
18
+ /**
19
+ * Segment that represents a Leaflet-ready map rendered from GeoJSON data.
20
+ *
21
+ * @private internal helper of `<ChatMessageItem/>`
22
+ */
23
+ export type ChatMapSegment = {
24
+ type: 'map';
25
+ data: GeoJsonObject;
26
+ };
27
+ /**
28
+ * Composite segment type that covers text, image prompts, and map features.
29
+ */
30
+ /**
31
+ * Composite segment type that covers text, image prompts, and map features.
32
+ *
33
+ * @private internal helper of `<ChatMessageItem/>`
34
+ */
35
+ export type ChatMessageContentSegment = ImagePromptSegment | ChatTextSegment | ChatMapSegment;
36
+ /**
37
+ * Splits chat message content into markdown, image prompt, and map segments while preserving their order.
38
+ *
39
+ * @private internal helper of `<ChatMessageItem/>`
40
+ */
41
+ export declare function splitMessageContentIntoSegments(content: string): ReadonlyArray<ChatMessageContentSegment>;
@@ -1,12 +1,10 @@
1
- import { string_javascript_name } from '../../_packages/types.index';
2
1
  import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
3
- import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
4
2
  import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
5
3
  /**
6
4
  * USE IMAGE GENERATOR commitment definition
7
5
  *
8
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
9
- * to create images based on text prompts.
6
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
7
+ * markdown placeholders for UI-driven image generation.
10
8
  *
11
9
  * Example usage in agent source:
12
10
  *
@@ -19,6 +17,7 @@ import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
19
17
  */
20
18
  export declare class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition<'USE IMAGE GENERATOR' | 'USE IMAGE GENERATION' | 'IMAGE GENERATOR' | 'IMAGE GENERATION' | 'USE IMAGE'> {
21
19
  constructor(type?: 'USE IMAGE GENERATOR' | 'USE IMAGE GENERATION' | 'IMAGE GENERATOR' | 'IMAGE GENERATION' | 'USE IMAGE');
20
+ get requiresContent(): boolean;
22
21
  /**
23
22
  * Short one-line description of USE IMAGE GENERATOR.
24
23
  */
@@ -32,14 +31,6 @@ export declare class UseImageGeneratorCommitmentDefinition extends BaseCommitmen
32
31
  */
33
32
  get documentation(): string;
34
33
  applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
35
- /**
36
- * Gets human-readable titles for tool functions provided by this commitment.
37
- */
38
- getToolTitles(): Record<string_javascript_name, string>;
39
- /**
40
- * Gets the `generate_image` tool function implementation.
41
- */
42
- getToolFunctions(): Record<string_javascript_name, ToolFunction>;
43
34
  }
44
35
  /**
45
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Simplifies knowledge labels for UI chips by:
3
+ * - extracting filename from URL/path-like values,
4
+ * - removing extension,
5
+ * - removing trailing random ID segment when detected,
6
+ * - truncating to 20 characters with ellipsis.
7
+ *
8
+ * @param label - Raw knowledge label or source value.
9
+ * @returns Display-friendly chip label.
10
+ * @private utility of knowledge/source chip rendering
11
+ */
12
+ export declare function simplifyKnowledgeLabel(label: string): string;
13
+ /**
14
+ * Heuristic that classifies a short text as human-readable, identifier-like, or unknown.
15
+ *
16
+ * @param text - Candidate value (typically a filename segment).
17
+ * @returns `'HUMAN'`, `'ID'`, or `'UNKNOWN'`.
18
+ * @private utility of knowledge/source chip rendering
19
+ */
20
+ export declare function isHumanOrID(text: string): 'HUMAN' | 'ID' | 'UNKNOWN';
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.110.0`).
18
+ * It follows semantic versioning (e.g., `0.111.0-1`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.111.0-0",
3
+ "version": "0.111.0-2",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -56,7 +56,7 @@
56
56
  * @generated
57
57
  * @see https://github.com/webgptorg/promptbook
58
58
  */
59
- const PROMPTBOOK_ENGINE_VERSION = '0.111.0-0';
59
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-2';
60
60
  /**
61
61
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
62
62
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -20484,8 +20484,8 @@
20484
20484
  /**
20485
20485
  * USE IMAGE GENERATOR commitment definition
20486
20486
  *
20487
- * The `USE IMAGE GENERATOR` commitment indicates that the agent should utilize an image generation tool
20488
- * to create images based on text prompts.
20487
+ * The `USE IMAGE GENERATOR` commitment indicates that the agent can output
20488
+ * markdown placeholders for UI-driven image generation.
20489
20489
  *
20490
20490
  * Example usage in agent source:
20491
20491
  *
@@ -20500,11 +20500,14 @@
20500
20500
  constructor(type = 'USE IMAGE GENERATOR') {
20501
20501
  super(type, ['USE IMAGE GENERATION', 'IMAGE GENERATOR', 'IMAGE GENERATION', 'USE IMAGE']);
20502
20502
  }
20503
+ get requiresContent() {
20504
+ return false;
20505
+ }
20503
20506
  /**
20504
20507
  * Short one-line description of USE IMAGE GENERATOR.
20505
20508
  */
20506
20509
  get description() {
20507
- return 'Enable the agent to use an image generation tool for creating images from text prompts.';
20510
+ return 'Enable the agent to output markdown image placeholders that the UI turns into generated images.';
20508
20511
  }
20509
20512
  /**
20510
20513
  * Icon for this commitment.
@@ -20519,21 +20522,21 @@
20519
20522
  return spaceTrim$1.spaceTrim(`
20520
20523
  # USE IMAGE GENERATOR
20521
20524
 
20522
- Enables the agent to use an image generation tool to create images based on text prompts.
20525
+ Enables the agent to output markdown image placeholders that trigger image generation in the user interface.
20523
20526
 
20524
20527
  ## Key aspects
20525
20528
 
20526
20529
  - The content following \`USE IMAGE GENERATOR\` is an arbitrary text that the agent should know (e.g. style instructions or safety guidelines).
20527
- - The actual image generation is handled by the agent runtime using LLM execution tools.
20528
- - Allows the agent to generate visual content based on user requests.
20529
- - Returns the URL of the generated image.
20530
+ - The agent does **not** call an image-generation tool directly.
20531
+ - The agent inserts markdown notation: \`![alt](?image-prompt=...)\`.
20532
+ - The user interface detects the notation and generates the image asynchronously.
20530
20533
 
20531
20534
  ## Examples
20532
20535
 
20533
20536
  \`\`\`book
20534
20537
  Visual Artist
20535
20538
 
20536
- PERSONA You are a creative visual artist who can generate images.
20539
+ PERSONA You are a creative visual artist.
20537
20540
  USE IMAGE GENERATOR
20538
20541
  RULE Always describe the generated image to the user.
20539
20542
  \`\`\`
@@ -20543,80 +20546,28 @@
20543
20546
 
20544
20547
  PERSONA You are an interior designer who helps users visualize their space.
20545
20548
  USE IMAGE GENERATOR Professional interior design renders.
20546
- ACTION Generate a preview of the designed room.
20549
+ ACTION Add one generated image placeholder whenever a user asks for a visual.
20547
20550
  \`\`\`
20548
20551
  `);
20549
20552
  }
20550
20553
  applyToAgentModelRequirements(requirements, content) {
20551
- // Get existing tools array or create new one
20552
- const existingTools = requirements.tools || [];
20553
- // Add 'generate_image' to tools if not already present
20554
- const updatedTools = existingTools.some((tool) => tool.name === 'generate_image')
20555
- ? existingTools
20556
- : [
20557
- ...existingTools,
20558
- {
20559
- name: 'generate_image',
20560
- description: spaceTrim$1.spaceTrim(`
20561
- Generate an image from a text prompt.
20562
- Use this tool when the user asks to create, draw, or generate an image.
20563
- ${!content ? '' : `Style instructions / guidelines: ${content}`}
20564
- `),
20565
- parameters: {
20566
- type: 'object',
20567
- properties: {
20568
- prompt: {
20569
- type: 'string',
20570
- description: 'The detailed description of the image to generate',
20571
- },
20572
- },
20573
- required: ['prompt'],
20574
- },
20575
- },
20576
- ];
20577
- // Return requirements with updated tools and metadata
20554
+ const extraInstructions = formatOptionalInstructionBlock('Image instructions', content);
20578
20555
  return this.appendToSystemMessage({
20579
20556
  ...requirements,
20580
- tools: updatedTools,
20581
20557
  _metadata: {
20582
20558
  ...requirements._metadata,
20583
20559
  useImageGenerator: content || true,
20584
20560
  },
20585
- }, spaceTrim$1.spaceTrim(`
20586
- You have access to an image generator. Use it to create images based on user requests.
20587
- When you generate an image, you will receive a URL of the generated image.
20588
- `));
20589
- }
20590
- /**
20591
- * Gets human-readable titles for tool functions provided by this commitment.
20592
- */
20593
- getToolTitles() {
20594
- return {
20595
- generate_image: 'Generate image',
20596
- };
20597
- }
20598
- /**
20599
- * Gets the `generate_image` tool function implementation.
20600
- */
20601
- getToolFunctions() {
20602
- return {
20603
- async generate_image(args, ...extra) {
20604
- console.log('!!!! [Tool] generate_image called', { args });
20605
- const { prompt } = args;
20606
- if (!prompt) {
20607
- throw new Error('Image prompt is required');
20608
- }
20609
- const { llmTools } = extra[0] || {};
20610
- if (!llmTools || !llmTools.callImageGenerationModel) {
20611
- throw new Error('Image generation is not supported by the current model provider');
20612
- }
20613
- const result = await llmTools.callImageGenerationModel({
20614
- content: prompt,
20615
- modelName: 'dall-e-3', // Defaulting to dall-e-3, but this could be configurable
20616
- });
20617
- return result.content;
20618
- },
20619
- };
20561
+ }, spaceTrim$1.spaceTrim((block) => `
20562
+ Image generation:
20563
+ - You do not generate images directly and you do not call any image tool.
20564
+ - When the user asks for an image, include markdown notation in your message:
20565
+ \`![<alt text>](?image-prompt=<prompt>)\`
20566
+ - Keep \`<alt text>\` short and descriptive.
20567
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
20568
+ - You can include normal explanatory text before and after the notation.
20569
+ ${block(extraInstructions)}
20570
+ `));
20620
20571
  }
20621
20572
  }
20622
20573
  /**
@@ -35113,7 +35064,6 @@
35113
35064
  doneReading = !!done;
35114
35065
  if (value) {
35115
35066
  const textChunk = decoder.decode(value, { stream: true });
35116
- let sawToolCalls = false;
35117
35067
  let hasNonEmptyText = false;
35118
35068
  const textLines = [];
35119
35069
  const lines = textChunk.split(/\r?\n/);
@@ -35139,7 +35089,6 @@
35139
35089
  rawResponse: {},
35140
35090
  toolCalls: getActiveToolCalls(),
35141
35091
  });
35142
- sawToolCalls = true;
35143
35092
  isToolCallLine = true;
35144
35093
  }
35145
35094
  }
@@ -35149,22 +35098,16 @@
35149
35098
  }
35150
35099
  if (!isToolCallLine) {
35151
35100
  textLines.push(line);
35152
- if (line.length > 0) {
35101
+ if (trimmedLine.length > 0) {
35153
35102
  hasNonEmptyText = true;
35154
35103
  }
35155
35104
  }
35156
35105
  }
35157
- if (sawToolCalls) {
35158
- if (!hasNonEmptyText) {
35159
- continue;
35160
- }
35161
- const textChunkWithoutToolCalls = textLines.join('\n');
35162
- content += textChunkWithoutToolCalls;
35163
- }
35164
- else {
35165
- // console.debug('RemoteAgent chunk:', textChunk);
35166
- content += textChunk;
35106
+ if (!hasNonEmptyText) {
35107
+ continue;
35167
35108
  }
35109
+ const textChunkWithoutToolCalls = textLines.join('\n');
35110
+ content += textChunkWithoutToolCalls;
35168
35111
  if (!hasReceivedModelOutput && content.trim().length > 0) {
35169
35112
  hasReceivedModelOutput = true;
35170
35113
  preparationToolCalls.length = 0;