@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.
@@ -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/core",
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
@@ -28,7 +28,7 @@
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 @@
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 @@
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 @@
14769
14772
  return spaceTrim$1.spaceTrim(`
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 @@
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.spaceTrim(`
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.spaceTrim(`
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.spaceTrim((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 @@
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 @@
26972
26922
  rawResponse: {},
26973
26923
  toolCalls: getActiveToolCalls(),
26974
26924
  });
26975
- sawToolCalls = true;
26976
26925
  isToolCallLine = true;
26977
26926
  }
26978
26927
  }
@@ -26982,22 +26931,16 @@
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;