@promptbook/wizard 0.104.0-2 → 0.104.0-4

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.
@@ -185,6 +185,7 @@ import type { BookTranspiler } from '../transpilers/_common/BookTranspiler';
185
185
  import type { BookTranspilerOptions } from '../transpilers/_common/BookTranspilerOptions';
186
186
  import type { IntermediateFilesStrategy } from '../types/IntermediateFilesStrategy';
187
187
  import type { LlmCall } from '../types/LlmCall';
188
+ import type { Message } from '../types/Message';
188
189
  import type { ModelRequirements } from '../types/ModelRequirements';
189
190
  import type { CompletionModelRequirements } from '../types/ModelRequirements';
190
191
  import type { ChatModelRequirements } from '../types/ModelRequirements';
@@ -551,6 +552,7 @@ export type { BookTranspiler };
551
552
  export type { BookTranspilerOptions };
552
553
  export type { IntermediateFilesStrategy };
553
554
  export type { LlmCall };
555
+ export type { Message };
554
556
  export type { ModelRequirements };
555
557
  export type { CompletionModelRequirements };
556
558
  export type { ChatModelRequirements };
@@ -1,22 +1,17 @@
1
+ import { Message } from '../../../types/Message';
1
2
  import type { id, string_markdown } from '../../../types/typeAliases';
2
3
  /**
3
4
  * A message in the chat
4
5
  *
5
6
  * @public exported from `@promptbook/components`
6
7
  */
7
- export type ChatMessage = {
8
+ export type ChatMessage = Omit<Message<id>, 'direction' | 'recipients' | 'threadId' | 'metadata'> & {
8
9
  /**
9
- * Unique identifier of the message
10
- */
11
- id?: id;
12
- /**
13
- * Date when the message was created
14
- */
15
- date?: Date;
16
- /**
17
- * The name of the participant who sent the message
10
+ * Force the channel to be 'PROMPTBOOK_CHAT'
11
+ *
12
+ * @default 'PROMPTBOOK_CHAT'
18
13
  */
19
- from: id;
14
+ channel?: 'PROMPTBOOK_CHAT';
20
15
  /**
21
16
  * The content of the message with optional markdown formatting
22
17
  */
@@ -37,6 +32,7 @@ export type ChatMessage = {
37
32
  isVoiceCall?: boolean;
38
33
  };
39
34
  /**
35
+ * TODO: Make all fields readonly
40
36
  * TODO: Delete `expectedAnswer` from ChatMessage
41
37
  * TODO: Rename `date` into `created`+`modified`
42
38
  */
@@ -1,8 +1,8 @@
1
1
  import type { ChatParticipant } from '../../book-components/Chat/types/ChatParticipant';
2
2
  import type { AvailableModel } from '../../execution/AvailableModel';
3
3
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
4
- import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult, PromptResult } from '../../execution/PromptResult';
5
- import type { ChatPrompt, CompletionPrompt, EmbeddingPrompt, Prompt } from '../../types/Prompt';
4
+ import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult, ImagePromptResult, PromptResult } from '../../execution/PromptResult';
5
+ import type { ChatPrompt, CompletionPrompt, EmbeddingPrompt, ImagePrompt, Prompt } from '../../types/Prompt';
6
6
  import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
7
7
  /**
8
8
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
@@ -43,6 +43,10 @@ export declare class MultipleLlmExecutionTools implements LlmExecutionTools {
43
43
  * Calls the best available embedding model
44
44
  */
45
45
  callEmbeddingModel(prompt: EmbeddingPrompt): Promise<EmbeddingPromptResult>;
46
+ /**
47
+ * Calls the best available embedding model
48
+ */
49
+ callImageGenerationModel(prompt: ImagePrompt): Promise<ImagePromptResult>;
46
50
  /**
47
51
  * Calls the best available model
48
52
  *
@@ -46,6 +46,7 @@ export declare class RemoteLlmExecutionTools<TCustomOptions = undefined> impleme
46
46
  private callCommonModel;
47
47
  }
48
48
  /**
49
+ * TODO: !!!! Deprecate pipeline server and all of its components
49
50
  * TODO: Maybe use `$exportJson`
50
51
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
51
52
  * TODO: [🍓] Allow to list compatible models with each variant
@@ -0,0 +1,49 @@
1
+ import { Arrayable } from 'type-fest';
2
+ import { really_any } from '../_packages/types.index';
3
+ import { id, string_date_iso8601, string_markdown } from './typeAliases';
4
+ /**
5
+ * A generic message structure for various communication channels
6
+ */
7
+ export type Message<TParticipant> = {
8
+ /**
9
+ * Unique identifier of the message
10
+ */
11
+ readonly id?: id;
12
+ /**
13
+ * Date when the message was created
14
+ */
15
+ readonly createdAt?: Date | string_date_iso8601;
16
+ /**
17
+ * The communication channel of the message
18
+ */
19
+ readonly channel?: 'PROMPTBOOK_CHAT' | 'EMAIL' | 'SMS' | 'WHATSAPP' | 'TELEGRAM' | 'SIGNAL' | string | 'UNKNOWN';
20
+ /**
21
+ * Is the message send from the Promptbook or to the Promptbook
22
+ */
23
+ readonly direction?: 'INBOUND' | 'OUTBOUND' | 'INTERNAL' | 'INITIAL';
24
+ /**
25
+ * Who sent the message
26
+ */
27
+ readonly sender: TParticipant;
28
+ /**
29
+ * Who are the recipients of the message
30
+ */
31
+ readonly recipients?: Readonly<Arrayable<TParticipant>>;
32
+ /**
33
+ * The content of the message as markdown
34
+ *
35
+ * Note: We are converting all message content to markdown for consistency
36
+ */
37
+ readonly content: string_markdown;
38
+ /**
39
+ * The thread identifier the message belongs to
40
+ *
41
+ * - `null` means the message is not part of any thread
42
+ * - `undefined` means that we don't know if the message is part of a thread or not
43
+ */
44
+ readonly threadId?: id | null;
45
+ /**
46
+ * Arbitrary metadata associated with the message
47
+ */
48
+ readonly metadata?: Readonly<Record<string, really_any>>;
49
+ };
@@ -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.104.0-1`).
18
+ * It follows semantic versioning (e.g., `0.104.0-3`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/wizard",
3
- "version": "0.104.0-2",
3
+ "version": "0.104.0-4",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/wizard.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.104.0-2"
98
+ "@promptbook/core": "0.104.0-4"
99
99
  },
100
100
  "dependencies": {
101
101
  "@ai-sdk/deepseek": "0.1.17",
package/umd/index.umd.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-2';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-4';
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
@@ -2538,6 +2538,7 @@
2538
2538
  }
2539
2539
  }
2540
2540
  /**
2541
+ * TODO: !!!! Deprecate pipeline server and all of its components
2541
2542
  * TODO: Maybe use `$exportJson`
2542
2543
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
2543
2544
  * TODO: [🍓] Allow to list compatible models with each variant
@@ -5840,7 +5841,7 @@
5840
5841
  let threadMessages = [];
5841
5842
  if ('thread' in prompt && Array.isArray(prompt.thread)) {
5842
5843
  threadMessages = prompt.thread.map((msg) => ({
5843
- role: msg.role === 'assistant' ? 'assistant' : 'user',
5844
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
5844
5845
  content: msg.content,
5845
5846
  }));
5846
5847
  }
@@ -9429,6 +9430,15 @@
9429
9430
  return promptResult;
9430
9431
  };
9431
9432
  }
9433
+ if (llmTools.callImageGenerationModel !== undefined) {
9434
+ proxyTools.callImageGenerationModel = async (prompt) => {
9435
+ // console.info('[🚕] callImageGenerationModel through countTotalUsage');
9436
+ const promptResult = await llmTools.callImageGenerationModel(prompt);
9437
+ totalUsage = addUsage(totalUsage, promptResult.usage);
9438
+ spending.next(promptResult.usage);
9439
+ return promptResult;
9440
+ };
9441
+ }
9432
9442
  // <- Note: [🤖]
9433
9443
  return proxyTools;
9434
9444
  }
@@ -9538,6 +9548,12 @@
9538
9548
  callEmbeddingModel(prompt) {
9539
9549
  return this.callCommonModel(prompt);
9540
9550
  }
9551
+ /**
9552
+ * Calls the best available embedding model
9553
+ */
9554
+ callImageGenerationModel(prompt) {
9555
+ return this.callCommonModel(prompt);
9556
+ }
9541
9557
  // <- Note: [🤖]
9542
9558
  /**
9543
9559
  * Calls the best available model
@@ -9564,6 +9580,11 @@
9564
9580
  continue llm;
9565
9581
  }
9566
9582
  return await llmExecutionTools.callEmbeddingModel(prompt);
9583
+ case 'IMAGE_GENERATION':
9584
+ if (llmExecutionTools.callImageGenerationModel === undefined) {
9585
+ continue llm;
9586
+ }
9587
+ return await llmExecutionTools.callImageGenerationModel(prompt);
9567
9588
  // <- case [🤖]:
9568
9589
  default:
9569
9590
  throw new UnexpectedError(`Unknown model variant "${prompt.modelRequirements.modelVariant}" in ${llmExecutionTools.title}`);
@@ -11267,8 +11288,9 @@
11267
11288
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
11268
11289
  break variant;
11269
11290
  case 'EMBEDDING':
11291
+ case 'IMAGE_GENERATION':
11270
11292
  throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
11271
- Embedding model can not be used in pipeline
11293
+ ${modelRequirements.modelVariant} model can not be used in pipeline
11272
11294
 
11273
11295
  This should be catched during parsing
11274
11296
 
@@ -17149,17 +17171,64 @@
17149
17171
  };
17150
17172
  }
17151
17173
  const lines = agentSource.split('\n');
17152
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
17174
+ let agentName = null;
17175
+ let agentNameLineIndex = -1;
17176
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
17177
+ for (let i = 0; i < lines.length; i++) {
17178
+ const line = lines[i];
17179
+ if (line === undefined) {
17180
+ continue;
17181
+ }
17182
+ const trimmed = line.trim();
17183
+ if (!trimmed) {
17184
+ continue;
17185
+ }
17186
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17187
+ if (isHorizontal) {
17188
+ continue;
17189
+ }
17190
+ let isCommitment = false;
17191
+ for (const definition of COMMITMENT_REGISTRY) {
17192
+ const typeRegex = definition.createTypeRegex();
17193
+ const match = typeRegex.exec(trimmed);
17194
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
17195
+ isCommitment = true;
17196
+ break;
17197
+ }
17198
+ }
17199
+ if (!isCommitment) {
17200
+ agentName = trimmed;
17201
+ agentNameLineIndex = i;
17202
+ break;
17203
+ }
17204
+ }
17153
17205
  const commitments = [];
17154
17206
  const nonCommitmentLines = [];
17155
- // Always add the first line (agent name) to non-commitment lines
17156
- if (lines[0] !== undefined) {
17157
- nonCommitmentLines.push(lines[0]);
17207
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
17208
+ for (let i = 0; i < agentNameLineIndex; i++) {
17209
+ const line = lines[i];
17210
+ if (line === undefined) {
17211
+ continue;
17212
+ }
17213
+ const trimmed = line.trim();
17214
+ if (!trimmed) {
17215
+ continue;
17216
+ }
17217
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17218
+ if (isHorizontal) {
17219
+ nonCommitmentLines.push(line);
17220
+ }
17221
+ // Note: Commitments before agentName are not added to nonCommitmentLines
17222
+ }
17223
+ // Add the agent name line to non-commitment lines
17224
+ if (agentNameLineIndex >= 0) {
17225
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
17158
17226
  }
17159
17227
  // Parse commitments with multiline support
17160
17228
  let currentCommitment = null;
17161
- // Process lines starting from the second line (skip agent name)
17162
- for (let i = 1; i < lines.length; i++) {
17229
+ // Process lines starting from after the agent name line
17230
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
17231
+ for (let i = startIndex; i < lines.length; i++) {
17163
17232
  const line = lines[i];
17164
17233
  if (line === undefined) {
17165
17234
  continue;
@@ -19074,6 +19143,9 @@
19074
19143
  case 'EMBEDDING':
19075
19144
  promptResult = await llmTools.callEmbeddingModel(prompt);
19076
19145
  break variant;
19146
+ case 'IMAGE_GENERATION':
19147
+ promptResult = await llmTools.callImageGenerationModel(prompt);
19148
+ break variant;
19077
19149
  // <- case [🤖]:
19078
19150
  default:
19079
19151
  throw new PipelineExecutionError(`Unknown model variant "${prompt.modelRequirements.modelVariant}"`);
@@ -19161,6 +19233,11 @@
19161
19233
  return /* not await */ callCommonModel(prompt);
19162
19234
  };
19163
19235
  }
19236
+ if (llmTools.callImageGenerationModel !== undefined) {
19237
+ proxyTools.callImageGenerationModel = async (prompt) => {
19238
+ return /* not await */ callCommonModel(prompt);
19239
+ };
19240
+ }
19164
19241
  // <- Note: [🤖]
19165
19242
  return proxyTools;
19166
19243
  }