@promptbook/cli 0.104.0-11 → 0.104.0-12

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 (27) hide show
  1. package/apps/agents-server/src/app/api/upload/route.ts +4 -2
  2. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +1 -1
  3. package/apps/agents-server/src/utils/messages/sendMessage.ts +6 -5
  4. package/esm/index.es.js +89 -27
  5. package/esm/index.es.js.map +1 -1
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -0
  8. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +5 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.tools.test.d.ts +1 -0
  10. package/esm/typings/src/commitments/META/META_DESCRIPTION.d.ts +41 -0
  11. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
  12. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
  14. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
  18. package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
  19. package/esm/typings/src/search-engines/SearchResult.d.ts +4 -4
  20. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +1 -1
  21. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +1 -1
  22. package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
  23. package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
  24. package/esm/typings/src/version.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/umd/index.umd.js +89 -27
  27. package/umd/index.umd.js.map +1 -1
@@ -1,3 +1,4 @@
1
+ import type { PostgrestSingleResponse, SupabaseClient } from '@supabase/supabase-js';
1
2
  import { $getTableName } from '@/src/database/$getTableName';
2
3
  import { $provideSupabase } from '@/src/database/$provideSupabase';
3
4
  import { serializeError } from '@promptbook-local/utils';
@@ -6,12 +7,13 @@ import { NextRequest, NextResponse } from 'next/server';
6
7
  import { assertsError } from '../../../../../../src/errors/assertsError';
7
8
  import { getUserIdFromRequest } from '../../../../src/utils/getUserIdFromRequest';
8
9
  import { getMetadata } from '../../../database/getMetadata';
10
+ import type { AgentsServerDatabase } from '../../../database/schema';
9
11
 
10
12
  export async function POST(request: NextRequest) {
11
13
  try {
12
14
  const body = (await request.json()) as HandleUploadBody;
13
15
  const userId = await getUserIdFromRequest(request);
14
- const supabase = $provideSupabase();
16
+ const supabase: SupabaseClient<AgentsServerDatabase> = $provideSupabase();
15
17
 
16
18
  // Handle Vercel Blob client upload protocol
17
19
  const jsonResponse = await handleUpload({
@@ -38,7 +40,7 @@ export async function POST(request: NextRequest) {
38
40
 
39
41
  // Create a DB record at the start of the upload to track it
40
42
  const uploadPurpose = purpose || 'GENERIC_UPLOAD';
41
- const { data: insertedFile, error: insertError } = await supabase
43
+ const { data: insertedFile, error: insertError }: PostgrestSingleResponse<Pick<AgentsServerDatabase['public']['Tables']['File']['Row'], 'id'>> = await supabase
42
44
  .from(await $getTableName('File'))
43
45
  .insert({
44
46
  userId: userId || null,
@@ -83,7 +83,7 @@ export function AgentProfile(props: AgentProfileProps) {
83
83
 
84
84
  const { meta, agentName } = agent;
85
85
  const fullname = (meta.fullname as string) || agentName || 'Agent';
86
- const personaDescription = agent.personaDescription || '';
86
+ const personaDescription = meta.description || agent.personaDescription || '';
87
87
  const imageUrl = meta.image || generatePlaceholderAgentProfileImageUrl(permanentId, publicUrl);
88
88
 
89
89
  const [isQrModalOpen, setIsQrModalOpen] = useState(false);
@@ -1,3 +1,4 @@
1
+ import type { PostgrestSingleResponse, SupabaseClient } from '@supabase/supabase-js';
1
2
  import type { really_any } from '@promptbook-local/types';
2
3
  import { serializeError } from '@promptbook-local/utils';
3
4
  import { assertsError } from '../../../../../src/errors/assertsError';
@@ -5,15 +6,16 @@ import { $getTableName } from '../../database/$getTableName';
5
6
  import { $provideSupabaseForServer } from '../../database/$provideSupabaseForServer';
6
7
  import { EMAIL_PROVIDERS } from '../../message-providers';
7
8
  import { OutboundEmail } from '../../message-providers/email/_common/Email';
9
+ import type { AgentsServerDatabase } from '../../database/schema';
8
10
 
9
11
  /**
10
12
  * Sends a message
11
13
  */
12
14
  export async function sendMessage(message: OutboundEmail): Promise<void> {
13
- const supabase = await $provideSupabaseForServer();
15
+ const supabase: SupabaseClient<AgentsServerDatabase> = await $provideSupabaseForServer();
14
16
 
15
17
  // 1. Insert message
16
- const { data: insertedMessage, error: insertError } = await supabase
18
+ const { data: insertedMessage, error: insertError }: PostgrestSingleResponse<AgentsServerDatabase['public']['Tables']['Message']['Row']> = await supabase
17
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
20
  .from(await $getTableName('Message'))
19
21
  .insert({
@@ -46,11 +48,11 @@ export async function sendMessage(message: OutboundEmail): Promise<void> {
46
48
  return;
47
49
  }
48
50
 
49
- let isSent = false;
51
+ let isSent: boolean = false;
50
52
 
51
53
  for (const providerName of providers) {
52
54
  const provider = EMAIL_PROVIDERS[providerName];
53
- let isSuccessful = false;
55
+ let isSuccessful: boolean = false;
54
56
  let raw: really_any = null;
55
57
 
56
58
  try {
@@ -67,7 +69,6 @@ export async function sendMessage(message: OutboundEmail): Promise<void> {
67
69
  // 3. Log attempt
68
70
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
71
  await supabase.from(await $getTableName('MessageSendAttempt')).insert({
70
- // @ts-expect-error: insertedMessage is any
71
72
  messageId: insertedMessage.id,
72
73
  providerName,
73
74
  isSuccessful,
package/esm/index.es.js CHANGED
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-11';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-12';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5663,7 +5663,7 @@ function joinLlmExecutionTools(title, ...llmExecutionTools) {
5663
5663
  }
5664
5664
  /**
5665
5665
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
5666
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
5666
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
5667
5667
  */
5668
5668
 
5669
5669
  /**
@@ -5848,7 +5848,7 @@ async function $provideLlmToolsForWizardOrCli(options) {
5848
5848
  }
5849
5849
  /**
5850
5850
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
5851
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
5851
+ * TODO: [👷‍♂️] Write a comprehensive manual about the construction of LLM tools
5852
5852
  * TODO: [🥃] Allow `ptbk make` without llm tools
5853
5853
  * TODO: This should be maybe not under `_common` but under `utils-internal` / `utils/internal`
5854
5854
  * TODO: [®] DRY Register logic
@@ -8005,7 +8005,7 @@ function getSingleLlmExecutionTools(oneOrMoreLlmExecutionTools) {
8005
8005
  }
8006
8006
  /**
8007
8007
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
8008
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
8008
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
8009
8009
  */
8010
8010
 
8011
8011
  /**
@@ -19302,6 +19302,22 @@ resultContent, rawResponse) {
19302
19302
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
19303
19303
  */
19304
19304
 
19305
+ /**
19306
+ * Maps Promptbook tools to OpenAI tools.
19307
+ *
19308
+ * @private
19309
+ */
19310
+ function mapToolsToOpenAi(tools) {
19311
+ return tools.map((tool) => ({
19312
+ type: 'function',
19313
+ function: {
19314
+ name: tool.name,
19315
+ description: tool.description,
19316
+ parameters: tool.parameters,
19317
+ },
19318
+ }));
19319
+ }
19320
+
19305
19321
  /**
19306
19322
  * Parses an OpenAI error message to identify which parameter is unsupported
19307
19323
  *
@@ -19499,6 +19515,9 @@ class OpenAiCompatibleExecutionTools {
19499
19515
  },
19500
19516
  ],
19501
19517
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
19518
+ tools: currentModelRequirements.tools === undefined
19519
+ ? undefined
19520
+ : mapToolsToOpenAi(currentModelRequirements.tools),
19502
19521
  };
19503
19522
  const start = $getCurrentDate();
19504
19523
  if (this.options.isVerbose) {
@@ -19643,6 +19662,7 @@ class OpenAiCompatibleExecutionTools {
19643
19662
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
19644
19663
  const rawRequest = {
19645
19664
  ...modelSettings,
19665
+ model: modelName,
19646
19666
  prompt: rawPromptContent,
19647
19667
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
19648
19668
  };
@@ -19897,8 +19917,8 @@ class OpenAiCompatibleExecutionTools {
19897
19917
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
19898
19918
  const rawRequest = {
19899
19919
  ...modelSettings,
19900
- size: modelSettings.size || '1024x1024',
19901
19920
  prompt: rawPromptContent,
19921
+ size: modelSettings.size || '1024x1024',
19902
19922
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
19903
19923
  response_format: 'url', // TODO: [🧠] Maybe allow b64_json
19904
19924
  };
@@ -20796,6 +20816,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
20796
20816
  thread: {
20797
20817
  messages: threadMessages,
20798
20818
  },
20819
+ tools: modelRequirements.tools === undefined ? undefined : mapToolsToOpenAi(modelRequirements.tools),
20799
20820
  // <- TODO: Add user identification here> user: this.options.user,
20800
20821
  };
20801
20822
  const start = $getCurrentDate();
@@ -25749,19 +25770,37 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
25749
25770
  `);
25750
25771
  }
25751
25772
  applyToAgentModelRequirements(requirements, content) {
25752
- // We simply mark that browser capability is enabled in metadata
25753
- // Get existing metadata
25754
- const existingMetadata = requirements.metadata || {};
25755
25773
  // Get existing tools array or create new one
25756
- const existingTools = existingMetadata.tools || [];
25757
- // Add 'browser' to tools if not already present
25758
- const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
25759
- // Return requirements with updated metadata
25774
+ const existingTools = requirements.tools || [];
25775
+ // Add 'web_browser' to tools if not already present
25776
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
25777
+ ? existingTools
25778
+ : [
25779
+ ...existingTools,
25780
+ {
25781
+ name: 'web_browser',
25782
+ description: spaceTrim$1(`
25783
+ A tool that can browse the web.
25784
+ Use this tool when you need to access specific websites or browse the internet.
25785
+ `),
25786
+ parameters: {
25787
+ type: 'object',
25788
+ properties: {
25789
+ url: {
25790
+ type: 'string',
25791
+ description: 'The URL to browse',
25792
+ },
25793
+ },
25794
+ required: ['url'],
25795
+ },
25796
+ },
25797
+ ];
25798
+ // Return requirements with updated tools and metadata
25760
25799
  return {
25761
25800
  ...requirements,
25801
+ tools: updatedTools,
25762
25802
  metadata: {
25763
- ...existingMetadata,
25764
- tools: updatedTools,
25803
+ ...requirements.metadata,
25765
25804
  useBrowser: true,
25766
25805
  },
25767
25806
  };
@@ -25854,13 +25893,13 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
25854
25893
  * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
25855
25894
  * to access and retrieve up-to-date information from the internet when necessary.
25856
25895
  *
25857
- * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
25896
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
25858
25897
  *
25859
25898
  * Example usage in agent source:
25860
25899
  *
25861
25900
  * ```book
25862
25901
  * USE SEARCH ENGINE
25863
- * USE SEARCH ENGINE This will be ignored
25902
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
25864
25903
  * ```
25865
25904
  *
25866
25905
  * @private [🪔] Maybe export the commitments through some package
@@ -25892,7 +25931,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
25892
25931
 
25893
25932
  ## Key aspects
25894
25933
 
25895
- - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
25934
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
25896
25935
  - The actual search engine tool usage is handled by the agent runtime
25897
25936
  - Allows the agent to search for current information from the web
25898
25937
  - Useful for research tasks, finding facts, and accessing dynamic content
@@ -25917,20 +25956,39 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
25917
25956
  `);
25918
25957
  }
25919
25958
  applyToAgentModelRequirements(requirements, content) {
25920
- // We simply mark that search engine capability is enabled in metadata
25921
- // Get existing metadata
25922
- const existingMetadata = requirements.metadata || {};
25923
25959
  // Get existing tools array or create new one
25924
- const existingTools = existingMetadata.tools || [];
25925
- // Add 'search-engine' to tools if not already present
25926
- const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
25927
- // Return requirements with updated metadata
25960
+ const existingTools = requirements.tools || [];
25961
+ // Add 'web_search' to tools if not already present
25962
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
25963
+ ? existingTools
25964
+ : [
25965
+ ...existingTools,
25966
+ {
25967
+ name: 'web_search',
25968
+ description: spaceTrim$1(`
25969
+ Search the internet for information.
25970
+ Use this tool when you need to find up-to-date information or facts that you don't know.
25971
+ ${!content ? '' : `Search scope / instructions: ${content}`}
25972
+ `),
25973
+ parameters: {
25974
+ type: 'object',
25975
+ properties: {
25976
+ query: {
25977
+ type: 'string',
25978
+ description: 'The search query',
25979
+ },
25980
+ },
25981
+ required: ['query'],
25982
+ },
25983
+ },
25984
+ ];
25985
+ // Return requirements with updated tools and metadata
25928
25986
  return {
25929
25987
  ...requirements,
25988
+ tools: updatedTools,
25930
25989
  metadata: {
25931
- ...existingMetadata,
25932
- tools: updatedTools,
25933
- useSearchEngine: true,
25990
+ ...requirements.metadata,
25991
+ useSearchEngine: content || true,
25934
25992
  },
25935
25993
  };
25936
25994
  }
@@ -26595,6 +26653,10 @@ function parseAgentSource(agentSource) {
26595
26653
  meta.image = spaceTrim$2(commitment.content);
26596
26654
  continue;
26597
26655
  }
26656
+ if (commitment.type === 'META DESCRIPTION') {
26657
+ meta.description = spaceTrim$2(commitment.content);
26658
+ continue;
26659
+ }
26598
26660
  if (commitment.type === 'META COLOR') {
26599
26661
  meta.color = normalizeSeparator(commitment.content);
26600
26662
  continue;