@promptbook/node 0.110.0-2 → 0.110.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.
package/esm/index.es.js CHANGED
@@ -34,7 +34,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
34
34
  * @generated
35
35
  * @see https://github.com/webgptorg/promptbook
36
36
  */
37
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-2';
37
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0-4';
38
38
  /**
39
39
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
40
40
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -16974,11 +16974,16 @@ function createTeamToolFunction(entry) {
16974
16974
  const request = buildTeammateRequest(message, args.context);
16975
16975
  let response = '';
16976
16976
  let error = null;
16977
+ let toolCalls;
16977
16978
  try {
16978
16979
  const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url);
16979
16980
  const prompt = buildTeammatePrompt(request);
16980
16981
  const teammateResult = await remoteAgent.callChatModel(prompt);
16981
16982
  response = teammateResult.content || '';
16983
+ toolCalls =
16984
+ 'toolCalls' in teammateResult && Array.isArray(teammateResult.toolCalls)
16985
+ ? teammateResult.toolCalls
16986
+ : undefined;
16982
16987
  }
16983
16988
  catch (err) {
16984
16989
  error = err instanceof Error ? err.message : String(err);
@@ -16988,6 +16993,7 @@ function createTeamToolFunction(entry) {
16988
16993
  teammate: teammateMetadata,
16989
16994
  request,
16990
16995
  response: teammateReply,
16996
+ toolCalls: toolCalls && toolCalls.length > 0 ? toolCalls : undefined,
16991
16997
  error,
16992
16998
  conversation: [
16993
16999
  {
@@ -24552,7 +24558,20 @@ class AgentLlmExecutionTools {
24552
24558
  const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
24553
24559
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
24554
24560
  let assistant;
24555
- if (cached) {
24561
+ if (this.options.assistantPreparationMode === 'external') {
24562
+ assistant = this.options.llmTools;
24563
+ if (this.options.isVerbose) {
24564
+ console.info('[🤰]', 'Using externally managed OpenAI Assistant', {
24565
+ agent: this.title,
24566
+ assistantId: assistant.assistantId,
24567
+ });
24568
+ }
24569
+ AgentLlmExecutionTools.assistantCache.set(this.title, {
24570
+ assistantId: assistant.assistantId,
24571
+ requirementsHash,
24572
+ });
24573
+ }
24574
+ else if (cached) {
24556
24575
  if (cached.requirementsHash === requirementsHash) {
24557
24576
  if (this.options.isVerbose) {
24558
24577
  console.info('[🤰]', 'Using cached OpenAI Assistant', {
@@ -24771,6 +24790,7 @@ class Agent extends AgentLlmExecutionTools {
24771
24790
  super({
24772
24791
  isVerbose: options.isVerbose,
24773
24792
  llmTools: getSingleLlmExecutionTools(options.executionTools.llm),
24793
+ assistantPreparationMode: options.assistantPreparationMode,
24774
24794
  agentSource: agentSource.value, // <- TODO: [🐱‍🚀] Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
24775
24795
  });
24776
24796
  _Agent_instances.add(this);
@@ -25046,6 +25066,63 @@ async function _Agent_selfLearnTeacher(prompt, result) {
25046
25066
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
25047
25067
  */
25048
25068
 
25069
+ /**
25070
+ * Resolve a remote META IMAGE value into an absolute URL when possible.
25071
+ */
25072
+ function resolveRemoteImageUrl(imageUrl, agentUrl) {
25073
+ if (!imageUrl) {
25074
+ return undefined;
25075
+ }
25076
+ if (imageUrl.startsWith('http://') ||
25077
+ imageUrl.startsWith('https://') ||
25078
+ imageUrl.startsWith('data:') ||
25079
+ imageUrl.startsWith('blob:')) {
25080
+ return imageUrl;
25081
+ }
25082
+ try {
25083
+ return new URL(imageUrl, agentUrl).href;
25084
+ }
25085
+ catch (_a) {
25086
+ return imageUrl;
25087
+ }
25088
+ }
25089
+ /**
25090
+ * Format a META commitment line when the value is provided.
25091
+ */
25092
+ function formatMetaLine(label, value) {
25093
+ if (!value) {
25094
+ return null;
25095
+ }
25096
+ return `META ${label} ${value}`;
25097
+ }
25098
+ /**
25099
+ * Build a minimal agent source snapshot for remote agents.
25100
+ */
25101
+ function buildRemoteAgentSource(profile, meta) {
25102
+ const metaLines = [
25103
+ formatMetaLine('FULLNAME', meta === null || meta === void 0 ? void 0 : meta.fullname),
25104
+ formatMetaLine('IMAGE', meta === null || meta === void 0 ? void 0 : meta.image),
25105
+ formatMetaLine('DESCRIPTION', meta === null || meta === void 0 ? void 0 : meta.description),
25106
+ formatMetaLine('COLOR', meta === null || meta === void 0 ? void 0 : meta.color),
25107
+ formatMetaLine('FONT', meta === null || meta === void 0 ? void 0 : meta.font),
25108
+ formatMetaLine('LINK', meta === null || meta === void 0 ? void 0 : meta.link),
25109
+ ]
25110
+ .filter((line) => Boolean(line))
25111
+ .join('\n');
25112
+ const personaBlock = profile.personaDescription
25113
+ ? spaceTrim$2((block) => `
25114
+ PERSONA
25115
+ ${block(profile.personaDescription || '')}
25116
+ `)
25117
+ : '';
25118
+ return book `
25119
+ ${profile.agentName}
25120
+
25121
+ ${metaLines}
25122
+
25123
+ ${personaBlock}
25124
+ `;
25125
+ }
25049
25126
  /**
25050
25127
  * Represents one AI Agent
25051
25128
  *
@@ -25060,6 +25137,7 @@ async function _Agent_selfLearnTeacher(prompt, result) {
25060
25137
  */
25061
25138
  class RemoteAgent extends Agent {
25062
25139
  static async connect(options) {
25140
+ var _a, _b, _c;
25063
25141
  const agentProfileUrl = `${options.agentUrl}/api/profile`;
25064
25142
  const profileResponse = await fetch(agentProfileUrl);
25065
25143
  // <- TODO: [🐱‍🚀] What about closed-source agents?
@@ -25079,14 +25157,14 @@ class RemoteAgent extends Agent {
25079
25157
 
25080
25158
  `));
25081
25159
  }
25082
- const profile = await profileResponse.json();
25160
+ const profile = (await profileResponse.json());
25161
+ const resolvedMeta = {
25162
+ ...(profile.meta || {}),
25163
+ image: resolveRemoteImageUrl((_a = profile.meta) === null || _a === void 0 ? void 0 : _a.image, options.agentUrl),
25164
+ };
25083
25165
  // Note: We are creating dummy agent source because we don't have the source from the remote agent
25084
25166
  // But we populate the metadata from the profile
25085
- const agentSource = new BehaviorSubject(book `
25086
- ${profile.agentName}
25087
-
25088
- ${profile.personaDescription}
25089
- `);
25167
+ const agentSource = new BehaviorSubject(buildRemoteAgentSource(profile, resolvedMeta));
25090
25168
  // <- TODO: [🐱‍🚀] createBookFromProfile
25091
25169
  // <- TODO: [🐱‍🚀] Support updating and self-updating
25092
25170
  const remoteAgent = new RemoteAgent({
@@ -25109,10 +25187,10 @@ class RemoteAgent extends Agent {
25109
25187
  });
25110
25188
  remoteAgent._remoteAgentName = profile.agentName;
25111
25189
  remoteAgent._remoteAgentHash = profile.agentHash;
25112
- remoteAgent.personaDescription = profile.personaDescription;
25113
- remoteAgent.initialMessage = profile.initialMessage;
25114
- remoteAgent.links = profile.links;
25115
- remoteAgent.meta = profile.meta;
25190
+ remoteAgent.personaDescription = (_b = profile.personaDescription) !== null && _b !== void 0 ? _b : null;
25191
+ remoteAgent.initialMessage = (_c = profile.initialMessage) !== null && _c !== void 0 ? _c : null;
25192
+ remoteAgent.links = profile.links || [];
25193
+ remoteAgent.meta = resolvedMeta;
25116
25194
  remoteAgent.capabilities = profile.capabilities || [];
25117
25195
  remoteAgent.samples = profile.samples || [];
25118
25196
  remoteAgent.toolTitles = profile.toolTitles || {};