@promptbook/core 0.103.0-49 → 0.103.0-50

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.
@@ -51,6 +51,7 @@ import { ResetIcon } from '../book-components/icons/ResetIcon';
51
51
  import { SaveIcon } from '../book-components/icons/SaveIcon';
52
52
  import { SendIcon } from '../book-components/icons/SendIcon';
53
53
  import { TemplateIcon } from '../book-components/icons/TemplateIcon';
54
+ import { PromptbookAgent } from '../book-components/PromptbookAgent/PromptbookAgent';
54
55
  import { BrandedQrCode } from '../book-components/Qr/BrandedQrCode';
55
56
  import { GenericQrCode } from '../book-components/Qr/GenericQrCode';
56
57
  import { PromptbookQrCode } from '../book-components/Qr/PromptbookQrCode';
@@ -109,6 +110,7 @@ export { ResetIcon };
109
110
  export { SaveIcon };
110
111
  export { SendIcon };
111
112
  export { TemplateIcon };
113
+ export { PromptbookAgent };
112
114
  export { BrandedQrCode };
113
115
  export { GenericQrCode };
114
116
  export { PromptbookQrCode };
@@ -0,0 +1,20 @@
1
+ import './PromptbookAgent.css';
2
+ type PromptbookAgentProps = {
3
+ /**
4
+ * URL of the agent to connect to
5
+ *
6
+ * @example "http://s6.ptbk.io/benjamin-white"
7
+ */
8
+ agentUrl: string;
9
+ };
10
+ /**
11
+ * Renders a floating agent button that opens a chat window with the remote agent.
12
+ *
13
+ * @public exported from `@promptbook/components`
14
+ */
15
+ export declare function PromptbookAgent(props: PromptbookAgentProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
17
+ /**
18
+ * TODO: !!! Load the full branding
19
+ * TODO: !!! <promptbook-agent> element
20
+ */
@@ -2,6 +2,8 @@ import { BehaviorSubject } from 'rxjs';
2
2
  import type { AgentBasicInformation, BookParameter } from '../../book-2.0/agent-source/AgentBasicInformation';
3
3
  import type { string_book } from '../../book-2.0/agent-source/string_book';
4
4
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
5
+ import type { ChatPromptResult } from '../../execution/PromptResult';
6
+ import type { Prompt } from '../../types/Prompt';
5
7
  import type { string_agent_hash, string_agent_name, string_agent_url, string_url_image } from '../../types/typeAliases';
6
8
  import { AgentLlmExecutionTools } from './AgentLlmExecutionTools';
7
9
  import type { AgentOptions } from './AgentOptions';
@@ -55,6 +57,12 @@ export declare class Agent extends AgentLlmExecutionTools implements LlmExecutio
55
57
  get parameters(): BookParameter[];
56
58
  readonly agentSource: BehaviorSubject<string_book>;
57
59
  constructor(options: AgentOptions);
60
+ /**
61
+ * Calls the chat model with agent-specific system prompt and requirements with streaming
62
+ *
63
+ * Note: This method also implements the learning mechanism
64
+ */
65
+ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void): Promise<ChatPromptResult>;
58
66
  }
59
67
  /**
60
68
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
@@ -1,4 +1,5 @@
1
1
  import type { Promisable } from 'type-fest';
2
+ import type { string_book } from '../../book-2.0/agent-source/string_book';
2
3
  import type { ChatParticipant } from '../../book-components/Chat/types/ChatParticipant';
3
4
  import type { AvailableModel } from '../../execution/AvailableModel';
4
5
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
@@ -40,6 +41,12 @@ export declare class AgentLlmExecutionTools implements LlmExecutionTools {
40
41
  * @param agentSource The agent source string that defines the agent's behavior
41
42
  */
42
43
  constructor(options: CreateAgentLlmExecutionToolsOptions);
44
+ /**
45
+ * Updates the agent source and clears the cache
46
+ *
47
+ * @param agentSource The new agent source string
48
+ */
49
+ protected updateAgentSource(agentSource: string_book): void;
43
50
  /**
44
51
  * Get cached or parse agent information
45
52
  */
@@ -1,5 +1,6 @@
1
1
  import type { ChatPromptResult } from '../../execution/PromptResult';
2
2
  import type { Prompt } from '../../types/Prompt';
3
+ import type { string_agent_hash, string_agent_name } from '../../types/typeAliases';
3
4
  import { Agent } from './Agent';
4
5
  import type { RemoteAgentOptions } from './RemoteAgentOptions';
5
6
  /**
@@ -20,7 +21,11 @@ export declare class RemoteAgent extends Agent {
20
21
  * The source of the agent
21
22
  */
22
23
  private agentUrl;
24
+ private _remoteAgentName;
25
+ private _remoteAgentHash;
23
26
  private constructor();
27
+ get agentName(): string_agent_name;
28
+ get agentHash(): string_agent_hash;
24
29
  /**
25
30
  * Calls the agent on agents remote server
26
31
  */
@@ -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.103.0-48`).
18
+ * It follows semantic versioning (e.g., `0.103.0-49`).
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.103.0-49",
3
+ "version": "0.103.0-50",
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.103.0-49';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-50';
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
@@ -10488,23 +10488,21 @@
10488
10488
  const selectResult = await this.supabaseClient
10489
10489
  .from(this.getTableName('Agent'))
10490
10490
  .select('agentSource')
10491
- .eq('agentName', agentName)
10492
- .single();
10493
- /*
10494
- if (selectResult.data===null) {
10491
+ .eq('agentName', agentName);
10492
+ if (selectResult.data && selectResult.data.length === 0) {
10495
10493
  throw new NotFoundError(`Agent "${agentName}" not found`);
10496
10494
  }
10497
- */
10498
- if (selectResult.error) {
10495
+ else if (selectResult.data && selectResult.data.length > 1) {
10496
+ throw new UnexpectedError(`More agents with agentName="${agentName}" found`);
10497
+ }
10498
+ else if (selectResult.error) {
10499
10499
  throw new DatabaseError(spaceTrim((block) => `
10500
-
10501
10500
  Error fetching agent "${agentName}" from Supabase:
10502
10501
 
10503
10502
  ${block(selectResult.error.message)}
10504
10503
  `));
10505
- // <- TODO: [🐱‍🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`
10506
10504
  }
10507
- return selectResult.data.agentSource;
10505
+ return selectResult.data[0].agentSource;
10508
10506
  }
10509
10507
  /**
10510
10508
  * Creates a new agent in the collection
@@ -10559,7 +10557,7 @@
10559
10557
 
10560
10558
  ${block(selectPreviousAgentResult.error.message)}
10561
10559
  `));
10562
- // <- TODO: [🐱‍🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`
10560
+ // <- TODO: [🐱‍🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`, look at `getAgentSource` implementation
10563
10561
  }
10564
10562
  selectPreviousAgentResult.data.agentName;
10565
10563
  const previousAgentHash = selectPreviousAgentResult.data.agentHash;
@@ -17234,6 +17232,16 @@
17234
17232
  */
17235
17233
  this._cachedAgentInfo = null;
17236
17234
  }
17235
+ /**
17236
+ * Updates the agent source and clears the cache
17237
+ *
17238
+ * @param agentSource The new agent source string
17239
+ */
17240
+ updateAgentSource(agentSource) {
17241
+ this.options.agentSource = agentSource;
17242
+ this._cachedAgentInfo = null;
17243
+ this._cachedModelRequirements = null;
17244
+ }
17237
17245
  /**
17238
17246
  * Get cached or parse agent information
17239
17247
  */
@@ -17480,6 +17488,7 @@
17480
17488
  // TODO: [🐱‍🚀] Add `Agent` learning by promptbookAgent
17481
17489
  this.agentSource = agentSource;
17482
17490
  this.agentSource.subscribe((source) => {
17491
+ this.updateAgentSource(source);
17483
17492
  const { agentName, personaDescription, initialMessage, links, meta } = parseAgentSource(source);
17484
17493
  this._agentName = agentName;
17485
17494
  this.personaDescription = personaDescription;
@@ -17488,6 +17497,35 @@
17488
17497
  this.meta = { ...this.meta, ...meta };
17489
17498
  });
17490
17499
  }
17500
+ /**
17501
+ * Calls the chat model with agent-specific system prompt and requirements with streaming
17502
+ *
17503
+ * Note: This method also implements the learning mechanism
17504
+ */
17505
+ async callChatModelStream(prompt, onProgress) {
17506
+ const result = await super.callChatModelStream(prompt, onProgress);
17507
+ // TODO: !!! Extract learning to separate method
17508
+ // Learning: Append the conversation sample to the agent source
17509
+ const learningExample = spaceTrim__default["default"]((block) => `
17510
+
17511
+ ---
17512
+
17513
+ SAMPLE
17514
+
17515
+ User:
17516
+ ${block(prompt.content)}
17517
+
17518
+ ${this.title} (Me, the Agent):
17519
+ ${block(result.content)}
17520
+
17521
+ `);
17522
+ // Append to the current source
17523
+ const currentSource = this.agentSource.value;
17524
+ const newSource = padBook(validateBook(spaceTrim__default["default"](currentSource) + '\n\n' + learningExample));
17525
+ // Update the source (which will trigger the subscription and update the underlying tools)
17526
+ this.agentSource.next(newSource);
17527
+ return result;
17528
+ }
17491
17529
  }
17492
17530
  /**
17493
17531
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
@@ -17567,14 +17605,20 @@
17567
17605
  */
17568
17606
  class RemoteAgent extends Agent {
17569
17607
  static async connect(options) {
17570
- console.log('[🐱‍🚀]', `${options.agentUrl}/api/book`);
17571
- const bookResponse = await fetch(`${options.agentUrl}/api/book`);
17608
+ console.log('[🐱‍🚀]', `${options.agentUrl}/api/profile`);
17609
+ const profileResponse = await fetch(`${options.agentUrl}/api/profile`);
17572
17610
  // <- TODO: [🐱‍🚀] What about closed-source agents?
17573
17611
  // <- TODO: [🐱‍🚀] Maybe use promptbookFetch
17574
- const agentSourceValue = (await bookResponse.text());
17575
- const agentSource = new rxjs.BehaviorSubject(agentSourceValue);
17612
+ const profile = await profileResponse.json();
17613
+ // Note: We are creating dummy agent source because we don't have the source from the remote agent
17614
+ // But we populate the metadata from the profile
17615
+ const agentSource = new rxjs.BehaviorSubject(`
17616
+ # ${profile.agentName}
17617
+
17618
+ ${profile.personaDescription}
17619
+ `);
17576
17620
  // <- TODO: [🐱‍🚀] Support updating and self-updating
17577
- return new RemoteAgent({
17621
+ const remoteAgent = new RemoteAgent({
17578
17622
  ...options,
17579
17623
  executionTools: {
17580
17624
  /* Note: These tools are not used */
@@ -17591,11 +17635,24 @@
17591
17635
  },
17592
17636
  agentSource,
17593
17637
  });
17638
+ remoteAgent._remoteAgentName = profile.agentName;
17639
+ remoteAgent._remoteAgentHash = profile.agentHash;
17640
+ remoteAgent.personaDescription = profile.personaDescription;
17641
+ remoteAgent.initialMessage = profile.initialMessage;
17642
+ remoteAgent.links = profile.links;
17643
+ remoteAgent.meta = profile.meta;
17644
+ return remoteAgent;
17594
17645
  }
17595
17646
  constructor(options) {
17596
17647
  super(options);
17597
17648
  this.agentUrl = options.agentUrl;
17598
17649
  }
17650
+ get agentName() {
17651
+ return this._remoteAgentName || super.agentName;
17652
+ }
17653
+ get agentHash() {
17654
+ return this._remoteAgentHash || super.agentHash;
17655
+ }
17599
17656
  /**
17600
17657
  * Calls the agent on agents remote server
17601
17658
  */