@promptbook/core 0.103.0-52 → 0.103.0-53

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.
Files changed (24) hide show
  1. package/esm/index.es.js +462 -73
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +8 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  8. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +7 -0
  9. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
  10. package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +12 -0
  11. package/esm/typings/src/book-components/icons/MicIcon.d.ts +8 -0
  12. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +17 -0
  13. package/esm/typings/src/commitments/MESSAGE/AgentMessageCommitmentDefinition.d.ts +28 -0
  14. package/esm/typings/src/commitments/MESSAGE/UserMessageCommitmentDefinition.d.ts +28 -0
  15. package/esm/typings/src/commitments/index.d.ts +20 -1
  16. package/esm/typings/src/execution/LlmExecutionTools.d.ts +9 -0
  17. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +2 -1
  18. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +10 -1
  19. package/esm/typings/src/utils/normalization/normalizeMessageText.d.ts +9 -0
  20. package/esm/typings/src/utils/normalization/normalizeMessageText.test.d.ts +1 -0
  21. package/esm/typings/src/version.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/umd/index.umd.js +463 -72
  24. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -28,12 +28,23 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-52';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-53';
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
35
35
  */
36
36
 
37
+ /**
38
+ * Core Promptbook server configuration.
39
+ *
40
+ * This server is also used for auto-federation in the Agents Server.
41
+ */
42
+ const CORE_SERVER = {
43
+ title: 'Promptbook Core',
44
+ description: `Core Promptbook server used for auto-federation`,
45
+ owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
46
+ urls: ['https://core.ptbk.io/'],
47
+ };
37
48
  /**
38
49
  * Available remote servers for the Promptbook
39
50
  *
@@ -55,6 +66,7 @@
55
66
  owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
56
67
  urls: ['https://s6.ptbk.io/'],
57
68
  },
69
+ CORE_SERVER,
58
70
  /*
59
71
  Note: Working on older version of Promptbook and not supported anymore
60
72
  {
@@ -67,7 +79,14 @@
67
79
  */
68
80
  ];
69
81
  /**
70
- * TODO: [🐱‍🚀] Auto-federated server from url in here
82
+ * Remote servers that are auto-federated by the Agents Server.
83
+ *
84
+ * These servers are always added in addition to the `FEDERATED_SERVERS` metadata.
85
+ *
86
+ * @public exported from `@promptbook/core`
87
+ */
88
+ const AUTO_FEDERATED_AGENT_SERVER_URLS = CORE_SERVER.urls;
89
+ /**
71
90
  * Note: [💞] Ignore a discrepancy between file name and entity name
72
91
  */
73
92
 
@@ -8109,6 +8128,77 @@
8109
8128
  * Note: [💞] Ignore a discrepancy between file name and entity name
8110
8129
  */
8111
8130
 
8131
+ /**
8132
+ * AGENT MESSAGE commitment definition
8133
+ *
8134
+ * The AGENT MESSAGE commitment defines a message from the agent in the conversation history.
8135
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
8136
+ *
8137
+ * Example usage in agent source:
8138
+ *
8139
+ * ```book
8140
+ * AGENT MESSAGE What seems to be the issue?
8141
+ * ```
8142
+ *
8143
+ * @private [🪔] Maybe export the commitments through some package
8144
+ */
8145
+ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
8146
+ constructor() {
8147
+ super('AGENT MESSAGE');
8148
+ }
8149
+ /**
8150
+ * Short one-line description of AGENT MESSAGE.
8151
+ */
8152
+ get description() {
8153
+ return 'Defines a **message from the agent** in the conversation history.';
8154
+ }
8155
+ /**
8156
+ * Markdown documentation for AGENT MESSAGE commitment.
8157
+ */
8158
+ get documentation() {
8159
+ return spaceTrim$1.spaceTrim(`
8160
+ # ${this.type}
8161
+
8162
+ Defines a message from the agent in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
8163
+
8164
+ ## Key aspects
8165
+
8166
+ - Represents a message sent by the agent.
8167
+ - Used for setting up conversation context.
8168
+ - Can be used in conjunction with USER MESSAGE.
8169
+
8170
+ ## Examples
8171
+
8172
+ \`\`\`book
8173
+ Conversation History
8174
+
8175
+ USER MESSAGE Hello, I have a problem.
8176
+ AGENT MESSAGE What seems to be the issue?
8177
+ USER MESSAGE My computer is not starting.
8178
+ \`\`\`
8179
+ `);
8180
+ }
8181
+ applyToAgentModelRequirements(requirements, content) {
8182
+ // AGENT MESSAGE is for UI display purposes / conversation history construction
8183
+ // and typically doesn't need to be added to the system prompt or model requirements directly.
8184
+ // It is extracted separately for the chat interface.
8185
+ var _a;
8186
+ const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
8187
+ if (pendingUserMessage) {
8188
+ const newSample = { question: pendingUserMessage, answer: content };
8189
+ const newSamples = [...(requirements.samples || []), newSample];
8190
+ const newMetadata = { ...requirements.metadata };
8191
+ delete newMetadata.pendingUserMessage;
8192
+ return {
8193
+ ...requirements,
8194
+ samples: newSamples,
8195
+ metadata: newMetadata,
8196
+ };
8197
+ }
8198
+ return requirements;
8199
+ }
8200
+ }
8201
+
8112
8202
  /**
8113
8203
  * INITIAL MESSAGE commitment definition
8114
8204
  *
@@ -8273,6 +8363,67 @@
8273
8363
  * Note: [💞] Ignore a discrepancy between file name and entity name
8274
8364
  */
8275
8365
 
8366
+ /**
8367
+ * USER MESSAGE commitment definition
8368
+ *
8369
+ * The USER MESSAGE commitment defines a message from the user in the conversation history.
8370
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
8371
+ *
8372
+ * Example usage in agent source:
8373
+ *
8374
+ * ```book
8375
+ * USER MESSAGE Hello, I have a problem.
8376
+ * ```
8377
+ *
8378
+ * @private [🪔] Maybe export the commitments through some package
8379
+ */
8380
+ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
8381
+ constructor() {
8382
+ super('USER MESSAGE');
8383
+ }
8384
+ /**
8385
+ * Short one-line description of USER MESSAGE.
8386
+ */
8387
+ get description() {
8388
+ return 'Defines a **message from the user** in the conversation history.';
8389
+ }
8390
+ /**
8391
+ * Markdown documentation for USER MESSAGE commitment.
8392
+ */
8393
+ get documentation() {
8394
+ return spaceTrim$1.spaceTrim(`
8395
+ # ${this.type}
8396
+
8397
+ Defines a message from the user in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
8398
+
8399
+ ## Key aspects
8400
+
8401
+ - Represents a message sent by the user.
8402
+ - Used for setting up conversation context.
8403
+ - Can be used in conjunction with AGENT MESSAGE.
8404
+
8405
+ ## Examples
8406
+
8407
+ \`\`\`book
8408
+ Conversation History
8409
+
8410
+ USER MESSAGE Hello, I have a problem.
8411
+ AGENT MESSAGE What seems to be the issue?
8412
+ USER MESSAGE My computer is not starting.
8413
+ \`\`\`
8414
+ `);
8415
+ }
8416
+ applyToAgentModelRequirements(requirements, content) {
8417
+ return {
8418
+ ...requirements,
8419
+ metadata: {
8420
+ ...requirements.metadata,
8421
+ pendingUserMessage: content,
8422
+ },
8423
+ };
8424
+ }
8425
+ }
8426
+
8276
8427
  /**
8277
8428
  * META commitment definition
8278
8429
  *
@@ -9486,6 +9637,8 @@
9486
9637
  new GoalCommitmentDefinition('GOAL'),
9487
9638
  new GoalCommitmentDefinition('GOALS'),
9488
9639
  new InitialMessageCommitmentDefinition(),
9640
+ new UserMessageCommitmentDefinition(),
9641
+ new AgentMessageCommitmentDefinition(),
9489
9642
  new MessageCommitmentDefinition('MESSAGE'),
9490
9643
  new MessageCommitmentDefinition('MESSAGES'),
9491
9644
  new ScenarioCommitmentDefinition('SCENARIO'),
@@ -9540,6 +9693,45 @@
9540
9693
  function isCommitmentSupported(type) {
9541
9694
  return COMMITMENT_REGISTRY.some((commitmentDefinition) => commitmentDefinition.type === type);
9542
9695
  }
9696
+ /**
9697
+ * Gets all commitment definitions grouped by their aliases
9698
+ *
9699
+ * @returns Array of grouped commitment definitions
9700
+ *
9701
+ * @public exported from `@promptbook/core`
9702
+ */
9703
+ function getGroupedCommitmentDefinitions() {
9704
+ const groupedCommitments = [];
9705
+ for (const commitment of COMMITMENT_REGISTRY) {
9706
+ const lastGroup = groupedCommitments[groupedCommitments.length - 1];
9707
+ // Check if we should group with the previous item
9708
+ let shouldGroup = false;
9709
+ if (lastGroup) {
9710
+ const lastPrimary = lastGroup.primary;
9711
+ // Case 1: Same class constructor (except NotYetImplemented)
9712
+ if (!(commitment instanceof NotYetImplementedCommitmentDefinition) &&
9713
+ commitment.constructor === lastPrimary.constructor) {
9714
+ shouldGroup = true;
9715
+ }
9716
+ // Case 2: NotYetImplemented with prefix matching (e.g. BEHAVIOUR -> BEHAVIOURS)
9717
+ else if (commitment instanceof NotYetImplementedCommitmentDefinition &&
9718
+ lastPrimary instanceof NotYetImplementedCommitmentDefinition &&
9719
+ commitment.type.startsWith(lastPrimary.type)) {
9720
+ shouldGroup = true;
9721
+ }
9722
+ }
9723
+ if (shouldGroup && lastGroup) {
9724
+ lastGroup.aliases.push(commitment.type);
9725
+ }
9726
+ else {
9727
+ groupedCommitments.push({
9728
+ primary: commitment,
9729
+ aliases: [],
9730
+ });
9731
+ }
9732
+ }
9733
+ return $deepFreeze(groupedCommitments);
9734
+ }
9543
9735
  /**
9544
9736
  * TODO: [🧠] Maybe create through standardized $register
9545
9737
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -10279,6 +10471,18 @@
10279
10471
  * TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
10280
10472
  */
10281
10473
 
10474
+ /**
10475
+ * Normalizes message text for comparison
10476
+ *
10477
+ * @param text The message text to normalize
10478
+ * @returns The normalized message text
10479
+ *
10480
+ * @public exported from `@promptbook/utils`
10481
+ */
10482
+ function normalizeMessageText(text) {
10483
+ return spaceTrim$1.spaceTrim(text);
10484
+ }
10485
+
10282
10486
  /**
10283
10487
  * Removes quotes from a string
10284
10488
  *
@@ -10783,7 +10987,96 @@
10783
10987
  * Deletes an agent from the collection
10784
10988
  */
10785
10989
  async deleteAgent(agentName) {
10786
- throw new NotYetImplementedError('Method not implemented.');
10990
+ const deleteResult = await this.supabaseClient
10991
+ .from(this.getTableName('Agent'))
10992
+ .delete()
10993
+ .eq('agentName', agentName);
10994
+ if (deleteResult.error) {
10995
+ throw new DatabaseError(spaceTrim((block) => `
10996
+ Error deleting agent "${agentName}" from Supabase:
10997
+
10998
+ ${block(deleteResult.error.message)}
10999
+ `));
11000
+ }
11001
+ }
11002
+ /**
11003
+ * List history of an agent
11004
+ */
11005
+ async listAgentHistory(agentName) {
11006
+ const result = await this.supabaseClient
11007
+ .from(this.getTableName('AgentHistory'))
11008
+ .select('id, createdAt, agentHash, promptbookEngineVersion')
11009
+ .eq('agentName', agentName)
11010
+ .order('createdAt', { ascending: false });
11011
+ if (result.error) {
11012
+ throw new DatabaseError(spaceTrim((block) => `
11013
+ Error listing history for agent "${agentName}" from Supabase:
11014
+
11015
+ ${block(result.error.message)}
11016
+ `));
11017
+ }
11018
+ return result.data;
11019
+ }
11020
+ /**
11021
+ * List agents that are in history but not in the active agents list
11022
+ */
11023
+ async listDeletedAgents() {
11024
+ const historyNamesResult = await this.supabaseClient.from(this.getTableName('AgentHistory')).select('agentName');
11025
+ const currentNamesResult = await this.supabaseClient.from(this.getTableName('Agent')).select('agentName');
11026
+ if (historyNamesResult.error) {
11027
+ throw new DatabaseError(spaceTrim((block) => `
11028
+ Error fetching agent history names from Supabase:
11029
+
11030
+ ${block(historyNamesResult.error.message)}
11031
+ `));
11032
+ }
11033
+ if (currentNamesResult.error) {
11034
+ throw new DatabaseError(spaceTrim((block) => `
11035
+ Error fetching current agent names from Supabase:
11036
+
11037
+ ${block(currentNamesResult.error.message)}
11038
+ `));
11039
+ }
11040
+ const currentNames = new Set(currentNamesResult.data.map((d) => d.agentName));
11041
+ const deletedNames = new Set();
11042
+ for (const { agentName } of historyNamesResult.data) {
11043
+ if (!currentNames.has(agentName)) {
11044
+ deletedNames.add(agentName);
11045
+ }
11046
+ }
11047
+ return Array.from(deletedNames);
11048
+ }
11049
+ /**
11050
+ * Restore an agent from history
11051
+ */
11052
+ async restoreAgent(historyId) {
11053
+ const historyResult = await this.supabaseClient
11054
+ .from(this.getTableName('AgentHistory'))
11055
+ .select('*')
11056
+ .eq('id', historyId)
11057
+ .single();
11058
+ if (historyResult.error) {
11059
+ throw new DatabaseError(spaceTrim((block) => `
11060
+ Error fetching agent history item "${historyId}" from Supabase:
11061
+
11062
+ ${block(historyResult.error.message)}
11063
+ `));
11064
+ }
11065
+ const { agentName, agentSource } = historyResult.data;
11066
+ // Check if agent exists
11067
+ const agentResult = await this.supabaseClient
11068
+ .from(this.getTableName('Agent'))
11069
+ .select('id')
11070
+ .eq('agentName', agentName)
11071
+ .single();
11072
+ if (agentResult.data) {
11073
+ // Update
11074
+ await this.updateAgentSource(agentName, agentSource);
11075
+ }
11076
+ else {
11077
+ // Insert (Restore from deleted)
11078
+ await this.createAgent(agentSource);
11079
+ }
10787
11080
  }
10788
11081
  /**
10789
11082
  * Get the Supabase table name with prefix
@@ -17212,12 +17505,15 @@
17212
17505
  fileStreams.push(file);
17213
17506
  }
17214
17507
  else {
17508
+ /*
17509
+ TODO: [🐱‍🚀] Resolve problem with browser environment
17215
17510
  // Assume it's a local file path
17216
17511
  // Note: This will work in Node.js environment
17217
17512
  // For browser environments, this would need different handling
17218
17513
  const fs = await import('fs');
17219
17514
  const fileStream = fs.createReadStream(source);
17220
17515
  fileStreams.push(fileStream);
17516
+ */
17221
17517
  }
17222
17518
  }
17223
17519
  catch (error) {
@@ -17306,12 +17602,15 @@
17306
17602
  fileStreams.push(file);
17307
17603
  }
17308
17604
  else {
17605
+ /*
17606
+ TODO: [🐱‍🚀] Resolve problem with browser environment
17309
17607
  // Assume it's a local file path
17310
17608
  // Note: This will work in Node.js environment
17311
17609
  // For browser environments, this would need different handling
17312
17610
  const fs = await import('fs');
17313
17611
  const fileStream = fs.createReadStream(source);
17314
17612
  fileStreams.push(fileStream);
17613
+ */
17315
17614
  }
17316
17615
  }
17317
17616
  catch (error) {
@@ -17685,7 +17984,53 @@
17685
17984
  * Note: This method also implements the learning mechanism
17686
17985
  */
17687
17986
  async callChatModelStream(prompt, onProgress) {
17987
+ // [1] Check if the user is asking the same thing as in the samples
17988
+ const modelRequirements = await this.getAgentModelRequirements();
17989
+ if (modelRequirements.samples) {
17990
+ const normalizedPrompt = normalizeMessageText(prompt.content);
17991
+ const sample = modelRequirements.samples.find((s) => normalizeMessageText(s.question) === normalizedPrompt);
17992
+ if (sample) {
17993
+ const now = new Date().toISOString();
17994
+ const result = {
17995
+ content: sample.answer,
17996
+ modelName: this.modelName,
17997
+ timing: {
17998
+ start: now,
17999
+ complete: now,
18000
+ },
18001
+ usage: {
18002
+ price: { value: 0, isUncertain: true },
18003
+ input: {
18004
+ tokensCount: { value: 0, isUncertain: true },
18005
+ charactersCount: { value: 0, isUncertain: true },
18006
+ wordsCount: { value: 0, isUncertain: true },
18007
+ linesCount: { value: 0, isUncertain: true },
18008
+ sentencesCount: { value: 0, isUncertain: true },
18009
+ paragraphsCount: { value: 0, isUncertain: true },
18010
+ pagesCount: { value: 0, isUncertain: true },
18011
+ },
18012
+ output: {
18013
+ tokensCount: { value: 0, isUncertain: true },
18014
+ charactersCount: { value: 0, isUncertain: true },
18015
+ wordsCount: { value: 0, isUncertain: true },
18016
+ linesCount: { value: 0, isUncertain: true },
18017
+ sentencesCount: { value: 0, isUncertain: true },
18018
+ paragraphsCount: { value: 0, isUncertain: true },
18019
+ pagesCount: { value: 0, isUncertain: true },
18020
+ },
18021
+ },
18022
+ rawPromptContent: prompt.content,
18023
+ rawRequest: null,
18024
+ rawResponse: { sample },
18025
+ };
18026
+ onProgress(result);
18027
+ return result;
18028
+ }
18029
+ }
17688
18030
  const result = await super.callChatModelStream(prompt, onProgress);
18031
+ if (result.rawResponse && 'sample' in result.rawResponse) {
18032
+ return result;
18033
+ }
17689
18034
  // TODO: !!! Extract learning to separate method
17690
18035
  // Learning: Append the conversation sample to the agent source
17691
18036
  const learningExample = spaceTrim__default["default"]((block) => `
@@ -17771,6 +18116,70 @@
17771
18116
  * Note: [💞] Ignore a discrepancy between file name and entity name
17772
18117
  */
17773
18118
 
18119
+ /**
18120
+ * Function `isValidPipelineString` will validate the if the string is a valid pipeline string
18121
+ * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
18122
+ *
18123
+ * @param {string} pipelineString the candidate for a pipeline string
18124
+ * @returns {boolean} if the string is a valid pipeline string
18125
+ * @public exported from `@promptbook/core`
18126
+ */
18127
+ function isValidPipelineString(pipelineString) {
18128
+ try {
18129
+ validatePipelineString(pipelineString);
18130
+ return true;
18131
+ }
18132
+ catch (error) {
18133
+ assertsError(error);
18134
+ return false;
18135
+ }
18136
+ }
18137
+ /**
18138
+ * TODO: [🧠][🈴] Where is the best location for this file
18139
+ */
18140
+
18141
+ /**
18142
+ * Tag function for notating a pipeline with a book\`...\ notation as template literal
18143
+ *
18144
+ * Note: There are 3 similar functions:
18145
+ * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
18146
+ * 2) `promptTemplate` alias for `prompt`
18147
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
18148
+ *
18149
+ * @param strings The static string parts of the template literal
18150
+ * @param values The dynamic values embedded within the template literal used as data
18151
+ * @returns the pipeline string
18152
+ * @public exported from `@promptbook/core`
18153
+ */
18154
+ function book(strings, ...values) {
18155
+ const bookString = prompt(strings, ...values);
18156
+ if (!isValidPipelineString(bookString)) {
18157
+ // TODO: Make the CustomError for this
18158
+ throw new Error(spaceTrim__default["default"](`
18159
+ The string is not a valid pipeline string
18160
+
18161
+ book\`
18162
+ ${bookString}
18163
+ \`
18164
+ `));
18165
+ }
18166
+ if (!isValidBook(bookString)) {
18167
+ // TODO: Make the CustomError for this
18168
+ throw new Error(spaceTrim__default["default"](`
18169
+ The string is not a valid book
18170
+
18171
+ book\`
18172
+ ${bookString}
18173
+ \`
18174
+ `));
18175
+ }
18176
+ return padBook(bookString);
18177
+ }
18178
+ /**
18179
+ * TODO: [🧠][🈴] Where is the best location for this file
18180
+ * Note: [💞] Ignore a discrepancy between file name and entity name
18181
+ */
18182
+
17774
18183
  /**
17775
18184
  * Represents one AI Agent
17776
18185
  *
@@ -17792,11 +18201,12 @@
17792
18201
  const profile = await profileResponse.json();
17793
18202
  // Note: We are creating dummy agent source because we don't have the source from the remote agent
17794
18203
  // But we populate the metadata from the profile
17795
- const agentSource = new rxjs.BehaviorSubject(`
17796
- # ${profile.agentName}
18204
+ const agentSource = new rxjs.BehaviorSubject(book `
18205
+ ${profile.agentName}
17797
18206
 
17798
- ${profile.personaDescription}
18207
+ ${profile.personaDescription}
17799
18208
  `);
18209
+ // <- TODO: [🐱‍🚀] createBookFromProfile
17800
18210
  // <- TODO: [🐱‍🚀] Support updating and self-updating
17801
18211
  const remoteAgent = new RemoteAgent({
17802
18212
  ...options,
@@ -17821,10 +18231,12 @@ ${profile.personaDescription}
17821
18231
  remoteAgent.initialMessage = profile.initialMessage;
17822
18232
  remoteAgent.links = profile.links;
17823
18233
  remoteAgent.meta = profile.meta;
18234
+ remoteAgent._isVoiceCallingEnabled = profile.isVoiceCallingEnabled === true; // [✨✷] Store voice calling status
17824
18235
  return remoteAgent;
17825
18236
  }
17826
18237
  constructor(options) {
17827
18238
  super(options);
18239
+ this._isVoiceCallingEnabled = false; // [✨✷] Track voice calling status
17828
18240
  this.agentUrl = options.agentUrl;
17829
18241
  }
17830
18242
  get agentName() {
@@ -17840,8 +18252,49 @@ ${profile.personaDescription}
17840
18252
  return this.callChatModelStream(prompt, () => { });
17841
18253
  }
17842
18254
  /**
17843
- * Calls the agent on agents remote server with streaming
18255
+ * Calls the agent on agents remote server with voice
18256
+ * [✨✷] Only available when voice calling is enabled on the server
18257
+ * Returns undefined if voice calling is disabled
17844
18258
  */
18259
+ get callVoiceChatModel() {
18260
+ if (!this._isVoiceCallingEnabled) {
18261
+ return undefined;
18262
+ }
18263
+ return async (audio, prompt) => {
18264
+ // Ensure we're working with a chat prompt
18265
+ if (prompt.modelRequirements.modelVariant !== 'CHAT') {
18266
+ throw new Error('Agents only supports chat prompts');
18267
+ }
18268
+ const chatPrompt = prompt;
18269
+ const formData = new FormData();
18270
+ formData.append('audio', audio, 'voice.webm');
18271
+ formData.append('message', prompt.content);
18272
+ if (chatPrompt.thread) {
18273
+ formData.append('thread', JSON.stringify(chatPrompt.thread));
18274
+ }
18275
+ const response = await fetch(`${this.agentUrl}/api/voice`, {
18276
+ method: 'POST',
18277
+ body: formData,
18278
+ });
18279
+ if (!response.ok) {
18280
+ throw new Error(`Voice chat failed: ${response.statusText}`);
18281
+ }
18282
+ const result = await response.json();
18283
+ // Convert base64 audio back to Blob
18284
+ const binaryString = atob(result.audio);
18285
+ const bytes = new Uint8Array(binaryString.length);
18286
+ for (let i = 0; i < binaryString.length; i++) {
18287
+ bytes[i] = binaryString.charCodeAt(i);
18288
+ }
18289
+ const audioBlob = new Blob([bytes], { type: 'audio/mp3' });
18290
+ return {
18291
+ text: result.agentMessage || result.text,
18292
+ userMessage: result.userMessage,
18293
+ agentMessage: result.agentMessage || result.text,
18294
+ audio: audioBlob,
18295
+ };
18296
+ };
18297
+ }
17845
18298
  async callChatModelStream(prompt, onProgress) {
17846
18299
  // Ensure we're working with a chat prompt
17847
18300
  if (prompt.modelRequirements.modelVariant !== 'CHAT') {
@@ -18378,70 +18831,6 @@ ${profile.personaDescription}
18378
18831
  return migratedPipeline;
18379
18832
  }
18380
18833
 
18381
- /**
18382
- * Function `isValidPipelineString` will validate the if the string is a valid pipeline string
18383
- * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
18384
- *
18385
- * @param {string} pipelineString the candidate for a pipeline string
18386
- * @returns {boolean} if the string is a valid pipeline string
18387
- * @public exported from `@promptbook/core`
18388
- */
18389
- function isValidPipelineString(pipelineString) {
18390
- try {
18391
- validatePipelineString(pipelineString);
18392
- return true;
18393
- }
18394
- catch (error) {
18395
- assertsError(error);
18396
- return false;
18397
- }
18398
- }
18399
- /**
18400
- * TODO: [🧠][🈴] Where is the best location for this file
18401
- */
18402
-
18403
- /**
18404
- * Tag function for notating a pipeline with a book\`...\ notation as template literal
18405
- *
18406
- * Note: There are 3 similar functions:
18407
- * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
18408
- * 2) `promptTemplate` alias for `prompt`
18409
- * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
18410
- *
18411
- * @param strings The static string parts of the template literal
18412
- * @param values The dynamic values embedded within the template literal used as data
18413
- * @returns the pipeline string
18414
- * @public exported from `@promptbook/core`
18415
- */
18416
- function book(strings, ...values) {
18417
- const bookString = prompt(strings, ...values);
18418
- if (!isValidPipelineString(bookString)) {
18419
- // TODO: Make the CustomError for this
18420
- throw new Error(spaceTrim__default["default"](`
18421
- The string is not a valid pipeline string
18422
-
18423
- book\`
18424
- ${bookString}
18425
- \`
18426
- `));
18427
- }
18428
- if (!isValidBook(bookString)) {
18429
- // TODO: Make the CustomError for this
18430
- throw new Error(spaceTrim__default["default"](`
18431
- The string is not a valid book
18432
-
18433
- book\`
18434
- ${bookString}
18435
- \`
18436
- `));
18437
- }
18438
- return padBook(bookString);
18439
- }
18440
- /**
18441
- * TODO: [🧠][🈴] Where is the best location for this file
18442
- * Note: [💞] Ignore a discrepancy between file name and entity name
18443
- */
18444
-
18445
18834
  /**
18446
18835
  * Convert identification to Promptbook token
18447
18836
  *
@@ -19204,7 +19593,7 @@ ${profile.personaDescription}
19204
19593
  const agentSource = validateBook(spaceTrim__default["default"]((block) => `
19205
19594
  ${agentName}
19206
19595
 
19207
- META COLOR ${color || '#3498db' /* <- TODO: [🧠] [🐱‍🚀] Best default color */}
19596
+ META COLOR ${color || PROMPTBOOK_COLOR.toHex()}
19208
19597
  PERSONA ${block(personaDescription)}
19209
19598
  `));
19210
19599
  return agentSource;
@@ -19222,6 +19611,7 @@ ${profile.personaDescription}
19222
19611
  exports.ADMIN_EMAIL = ADMIN_EMAIL;
19223
19612
  exports.ADMIN_GITHUB_NAME = ADMIN_GITHUB_NAME;
19224
19613
  exports.API_REQUEST_TIMEOUT = API_REQUEST_TIMEOUT;
19614
+ exports.AUTO_FEDERATED_AGENT_SERVER_URLS = AUTO_FEDERATED_AGENT_SERVER_URLS;
19225
19615
  exports.AbstractFormatError = AbstractFormatError;
19226
19616
  exports.Agent = Agent;
19227
19617
  exports.AgentCollectionInSupabase = AgentCollectionInSupabase;
@@ -19370,6 +19760,7 @@ ${profile.personaDescription}
19370
19760
  exports.getAllCommitmentDefinitions = getAllCommitmentDefinitions;
19371
19761
  exports.getAllCommitmentTypes = getAllCommitmentTypes;
19372
19762
  exports.getCommitmentDefinition = getCommitmentDefinition;
19763
+ exports.getGroupedCommitmentDefinitions = getGroupedCommitmentDefinitions;
19373
19764
  exports.getPipelineInterface = getPipelineInterface;
19374
19765
  exports.getSingleLlmExecutionTools = getSingleLlmExecutionTools;
19375
19766
  exports.identificationToPromptbookToken = identificationToPromptbookToken;