@promptbook/remote-server 0.110.0-3 → 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
@@ -39,7 +39,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
39
39
  * @generated
40
40
  * @see https://github.com/webgptorg/promptbook
41
41
  */
42
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0-3';
42
+ const PROMPTBOOK_ENGINE_VERSION = '0.110.0-4';
43
43
  /**
44
44
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
45
45
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -14065,11 +14065,16 @@ function createTeamToolFunction(entry) {
14065
14065
  const request = buildTeammateRequest(message, args.context);
14066
14066
  let response = '';
14067
14067
  let error = null;
14068
+ let toolCalls;
14068
14069
  try {
14069
14070
  const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url);
14070
14071
  const prompt = buildTeammatePrompt(request);
14071
14072
  const teammateResult = await remoteAgent.callChatModel(prompt);
14072
14073
  response = teammateResult.content || '';
14074
+ toolCalls =
14075
+ 'toolCalls' in teammateResult && Array.isArray(teammateResult.toolCalls)
14076
+ ? teammateResult.toolCalls
14077
+ : undefined;
14073
14078
  }
14074
14079
  catch (err) {
14075
14080
  error = err instanceof Error ? err.message : String(err);
@@ -14079,6 +14084,7 @@ function createTeamToolFunction(entry) {
14079
14084
  teammate: teammateMetadata,
14080
14085
  request,
14081
14086
  response: teammateReply,
14087
+ toolCalls: toolCalls && toolCalls.length > 0 ? toolCalls : undefined,
14082
14088
  error,
14083
14089
  conversation: [
14084
14090
  {
@@ -21656,7 +21662,20 @@ class AgentLlmExecutionTools {
21656
21662
  const requirementsHash = SHA256(JSON.stringify(modelRequirements)).toString();
21657
21663
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
21658
21664
  let assistant;
21659
- if (cached) {
21665
+ if (this.options.assistantPreparationMode === 'external') {
21666
+ assistant = this.options.llmTools;
21667
+ if (this.options.isVerbose) {
21668
+ console.info('[🤰]', 'Using externally managed OpenAI Assistant', {
21669
+ agent: this.title,
21670
+ assistantId: assistant.assistantId,
21671
+ });
21672
+ }
21673
+ AgentLlmExecutionTools.assistantCache.set(this.title, {
21674
+ assistantId: assistant.assistantId,
21675
+ requirementsHash,
21676
+ });
21677
+ }
21678
+ else if (cached) {
21660
21679
  if (cached.requirementsHash === requirementsHash) {
21661
21680
  if (this.options.isVerbose) {
21662
21681
  console.info('[🤰]', 'Using cached OpenAI Assistant', {
@@ -21722,11 +21741,6 @@ class AgentLlmExecutionTools {
21722
21741
  requirementsHash,
21723
21742
  });
21724
21743
  }
21725
- // [0] Expose prepared externals
21726
- if (this.preparedExternals) {
21727
- this /* <- TODO: !!!!!! Remove */.preparedExternals.openaiAssistantId =
21728
- assistant.assistantId;
21729
- }
21730
21744
  // Create modified chat prompt with agent system message specific to OpenAI Assistant
21731
21745
  const promptWithAgentModelRequirementsForOpenAiAssistantExecutionTools = {
21732
21746
  ...promptWithAgentModelRequirements,
@@ -21880,6 +21894,7 @@ class Agent extends AgentLlmExecutionTools {
21880
21894
  super({
21881
21895
  isVerbose: options.isVerbose,
21882
21896
  llmTools: getSingleLlmExecutionTools(options.executionTools.llm),
21897
+ assistantPreparationMode: options.assistantPreparationMode,
21883
21898
  agentSource: agentSource.value, // <- TODO: [🐱‍🚀] Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
21884
21899
  });
21885
21900
  _Agent_instances.add(this);
@@ -21919,10 +21934,6 @@ class Agent extends AgentLlmExecutionTools {
21919
21934
  * Human-readable titles for tool functions
21920
21935
  */
21921
21936
  this.toolTitles = {};
21922
- /**
21923
- * Externals prepared for the agent, like OpenAI assistant, etc.
21924
- */
21925
- this.preparedExternals = {};
21926
21937
  // TODO: [🐱‍🚀] Add `Agent` simple "mocked" learning by appending to agent source
21927
21938
  // TODO: [🐱‍🚀] Add `Agent` learning by promptbookAgent
21928
21939
  this.teacherAgent = options.teacherAgent;
@@ -22159,6 +22170,63 @@ async function _Agent_selfLearnTeacher(prompt, result) {
22159
22170
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
22160
22171
  */
22161
22172
 
22173
+ /**
22174
+ * Resolve a remote META IMAGE value into an absolute URL when possible.
22175
+ */
22176
+ function resolveRemoteImageUrl(imageUrl, agentUrl) {
22177
+ if (!imageUrl) {
22178
+ return undefined;
22179
+ }
22180
+ if (imageUrl.startsWith('http://') ||
22181
+ imageUrl.startsWith('https://') ||
22182
+ imageUrl.startsWith('data:') ||
22183
+ imageUrl.startsWith('blob:')) {
22184
+ return imageUrl;
22185
+ }
22186
+ try {
22187
+ return new URL(imageUrl, agentUrl).href;
22188
+ }
22189
+ catch (_a) {
22190
+ return imageUrl;
22191
+ }
22192
+ }
22193
+ /**
22194
+ * Format a META commitment line when the value is provided.
22195
+ */
22196
+ function formatMetaLine(label, value) {
22197
+ if (!value) {
22198
+ return null;
22199
+ }
22200
+ return `META ${label} ${value}`;
22201
+ }
22202
+ /**
22203
+ * Build a minimal agent source snapshot for remote agents.
22204
+ */
22205
+ function buildRemoteAgentSource(profile, meta) {
22206
+ const metaLines = [
22207
+ formatMetaLine('FULLNAME', meta === null || meta === void 0 ? void 0 : meta.fullname),
22208
+ formatMetaLine('IMAGE', meta === null || meta === void 0 ? void 0 : meta.image),
22209
+ formatMetaLine('DESCRIPTION', meta === null || meta === void 0 ? void 0 : meta.description),
22210
+ formatMetaLine('COLOR', meta === null || meta === void 0 ? void 0 : meta.color),
22211
+ formatMetaLine('FONT', meta === null || meta === void 0 ? void 0 : meta.font),
22212
+ formatMetaLine('LINK', meta === null || meta === void 0 ? void 0 : meta.link),
22213
+ ]
22214
+ .filter((line) => Boolean(line))
22215
+ .join('\n');
22216
+ const personaBlock = profile.personaDescription
22217
+ ? spaceTrim$2((block) => `
22218
+ PERSONA
22219
+ ${block(profile.personaDescription || '')}
22220
+ `)
22221
+ : '';
22222
+ return book `
22223
+ ${profile.agentName}
22224
+
22225
+ ${metaLines}
22226
+
22227
+ ${personaBlock}
22228
+ `;
22229
+ }
22162
22230
  /**
22163
22231
  * Represents one AI Agent
22164
22232
  *
@@ -22173,6 +22241,7 @@ async function _Agent_selfLearnTeacher(prompt, result) {
22173
22241
  */
22174
22242
  class RemoteAgent extends Agent {
22175
22243
  static async connect(options) {
22244
+ var _a, _b, _c;
22176
22245
  const agentProfileUrl = `${options.agentUrl}/api/profile`;
22177
22246
  const profileResponse = await fetch(agentProfileUrl);
22178
22247
  // <- TODO: [🐱‍🚀] What about closed-source agents?
@@ -22192,14 +22261,14 @@ class RemoteAgent extends Agent {
22192
22261
 
22193
22262
  `));
22194
22263
  }
22195
- const profile = await profileResponse.json();
22264
+ const profile = (await profileResponse.json());
22265
+ const resolvedMeta = {
22266
+ ...(profile.meta || {}),
22267
+ image: resolveRemoteImageUrl((_a = profile.meta) === null || _a === void 0 ? void 0 : _a.image, options.agentUrl),
22268
+ };
22196
22269
  // Note: We are creating dummy agent source because we don't have the source from the remote agent
22197
22270
  // But we populate the metadata from the profile
22198
- const agentSource = new BehaviorSubject(book `
22199
- ${profile.agentName}
22200
-
22201
- ${profile.personaDescription}
22202
- `);
22271
+ const agentSource = new BehaviorSubject(buildRemoteAgentSource(profile, resolvedMeta));
22203
22272
  // <- TODO: [🐱‍🚀] createBookFromProfile
22204
22273
  // <- TODO: [🐱‍🚀] Support updating and self-updating
22205
22274
  const remoteAgent = new RemoteAgent({
@@ -22222,10 +22291,10 @@ class RemoteAgent extends Agent {
22222
22291
  });
22223
22292
  remoteAgent._remoteAgentName = profile.agentName;
22224
22293
  remoteAgent._remoteAgentHash = profile.agentHash;
22225
- remoteAgent.personaDescription = profile.personaDescription;
22226
- remoteAgent.initialMessage = profile.initialMessage;
22227
- remoteAgent.links = profile.links;
22228
- remoteAgent.meta = profile.meta;
22294
+ remoteAgent.personaDescription = (_b = profile.personaDescription) !== null && _b !== void 0 ? _b : null;
22295
+ remoteAgent.initialMessage = (_c = profile.initialMessage) !== null && _c !== void 0 ? _c : null;
22296
+ remoteAgent.links = profile.links || [];
22297
+ remoteAgent.meta = resolvedMeta;
22229
22298
  remoteAgent.capabilities = profile.capabilities || [];
22230
22299
  remoteAgent.samples = profile.samples || [];
22231
22300
  remoteAgent.toolTitles = profile.toolTitles || {};