@promptbook/types 0.105.0-0 → 0.105.0-10

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 (66) hide show
  1. package/README.md +36 -77
  2. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  3. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +16 -0
  5. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +15 -3
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
  8. package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
  10. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
  12. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
  13. package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +5 -0
  14. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +15 -1
  15. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +20 -9
  16. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
  17. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +43 -0
  18. package/esm/typings/src/commitments/NOTE/NOTE.d.ts +2 -2
  19. package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +4 -0
  20. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +10 -0
  21. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.test.d.ts +1 -0
  22. package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +44 -0
  23. package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
  24. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +14 -0
  25. package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +14 -0
  26. package/esm/typings/src/commitments/index.d.ts +17 -2
  27. package/esm/typings/src/config.d.ts +1 -0
  28. package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
  29. package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
  30. package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
  31. package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
  32. package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
  33. package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
  34. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
  35. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
  36. package/esm/typings/src/llm-providers/agent/Agent.d.ts +14 -2
  37. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
  38. package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +7 -0
  39. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +1 -0
  40. package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +1 -1
  41. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
  42. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +7 -0
  43. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  44. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
  45. package/esm/typings/src/search-engines/SearchEngine.d.ts +1 -1
  46. package/esm/typings/src/search-engines/_index.d.ts +6 -0
  47. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +1 -1
  48. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +1 -1
  49. package/esm/typings/src/search-engines/google/GoogleSearchEngine.d.ts +18 -0
  50. package/esm/typings/src/search-engines/serp/SerpSearchEngine.d.ts +15 -0
  51. package/esm/typings/src/speech-recognition/BrowserSpeechRecognition.d.ts +21 -0
  52. package/esm/typings/src/speech-recognition/OpenAiSpeechRecognition.d.ts +32 -0
  53. package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
  54. package/esm/typings/src/types/SpeechRecognition.d.ts +58 -0
  55. package/esm/typings/src/types/typeAliases.d.ts +4 -0
  56. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
  57. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
  58. package/esm/typings/src/utils/misc/linguisticHash.d.ts +6 -0
  59. package/esm/typings/src/utils/misc/linguisticHash.test.d.ts +1 -0
  60. package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
  61. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
  62. package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +4 -0
  63. package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +2 -1
  64. package/esm/typings/src/utils/random/$randomAgentRule.d.ts +14 -0
  65. package/esm/typings/src/version.d.ts +1 -1
  66. package/package.json +2 -2
@@ -1,4 +1,6 @@
1
+ import { string_javascript_name } from '../../_packages/types.index';
1
2
  import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
3
+ import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
2
4
  import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
3
5
  /**
4
6
  * USE SEARCH ENGINE commitment definition
@@ -32,6 +34,14 @@ export declare class UseSearchEngineCommitmentDefinition extends BaseCommitmentD
32
34
  */
33
35
  get documentation(): string;
34
36
  applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
37
+ /**
38
+ * Gets human-readable titles for tool functions provided by this commitment.
39
+ */
40
+ getToolTitles(): Record<string_javascript_name, string>;
41
+ /**
42
+ * Gets the `web_search` tool function implementation.
43
+ */
44
+ getToolFunctions(): Record<string_javascript_name, ToolFunction>;
35
45
  }
36
46
  /**
37
47
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -0,0 +1,44 @@
1
+ import { string_javascript_name } from '../../_packages/types.index';
2
+ import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
3
+ import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
4
+ import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
5
+ /**
6
+ * USE TIME commitment definition
7
+ *
8
+ * The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
9
+ *
10
+ * Example usage in agent source:
11
+ *
12
+ * ```book
13
+ * USE TIME
14
+ * ```
15
+ *
16
+ * @private [🪔] Maybe export the commitments through some package
17
+ */
18
+ export declare class UseTimeCommitmentDefinition extends BaseCommitmentDefinition<'USE TIME'> {
19
+ constructor();
20
+ /**
21
+ * Short one-line description of USE TIME.
22
+ */
23
+ get description(): string;
24
+ /**
25
+ * Icon for this commitment.
26
+ */
27
+ get icon(): string;
28
+ /**
29
+ * Markdown documentation for USE TIME commitment.
30
+ */
31
+ get documentation(): string;
32
+ applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
33
+ /**
34
+ * Gets human-readable titles for tool functions provided by this commitment.
35
+ */
36
+ getToolTitles(): Record<string_javascript_name, string>;
37
+ /**
38
+ * Gets the `get_current_time` tool function implementation.
39
+ */
40
+ getToolFunctions(): Record<string_javascript_name, ToolFunction>;
41
+ }
42
+ /**
43
+ * Note: [💞] Ignore a discrepancy between file name and entity name
44
+ */
@@ -1,4 +1,6 @@
1
1
  import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
2
+ import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
3
+ import { string_javascript_name } from '../../types/typeAliases';
2
4
  import type { CommitmentDefinition } from './CommitmentDefinition';
3
5
  /**
4
6
  * Base implementation of CommitmentDefinition that provides common functionality
@@ -61,4 +63,16 @@ export declare abstract class BaseCommitmentDefinition<TBookCommitment extends s
61
63
  * but can be useful for organizing and structuring the message during processing
62
64
  */
63
65
  protected addCommentSection(requirements: AgentModelRequirements, commentTitle: string, content: string, position?: 'beginning' | 'end'): AgentModelRequirements;
66
+ /**
67
+ * Gets tool function implementations provided by this commitment
68
+ *
69
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
70
+ */
71
+ getToolFunctions(): Record<string_javascript_name, ToolFunction>;
72
+ /**
73
+ * Gets human-readable titles for tool functions provided by this commitment
74
+ *
75
+ * This is used in the UI to show a user-friendly name instead of the technical function name.
76
+ */
77
+ getToolTitles(): Record<string_javascript_name, string>;
64
78
  }
@@ -1,4 +1,6 @@
1
+ import { string_javascript_name } from '../../_packages/types.index';
1
2
  import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
3
+ import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
2
4
  /**
3
5
  * Definition of a commitment that can be applied to agent model requirements
4
6
  *
@@ -50,4 +52,16 @@ export type CommitmentDefinition = {
50
52
  * @returns Updated agent model requirements
51
53
  */
52
54
  applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
55
+ /**
56
+ * Gets tool function implementations provided by this commitment
57
+ *
58
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
59
+ */
60
+ getToolFunctions(): Record<string_javascript_name, ToolFunction>;
61
+ /**
62
+ * Gets human-readable titles for tool functions provided by this commitment
63
+ *
64
+ * This is used in the UI to show a user-friendly name instead of the technical function name.
65
+ */
66
+ getToolTitles(): Record<string_javascript_name, string>;
53
67
  };
@@ -1,5 +1,7 @@
1
1
  import type { BookCommitment } from './_base/BookCommitment';
2
2
  import type { CommitmentDefinition } from './_base/CommitmentDefinition';
3
+ import { ToolFunction } from '../scripting/javascript/JavascriptExecutionToolsOptions';
4
+ import { string_javascript_name } from '../types/typeAliases';
3
5
  import { ActionCommitmentDefinition } from './ACTION/ACTION';
4
6
  import { ClosedCommitmentDefinition } from './CLOSED/CLOSED';
5
7
  import { ComponentCommitmentDefinition } from './COMPONENT/COMPONENT';
@@ -7,8 +9,8 @@ import { DeleteCommitmentDefinition } from './DELETE/DELETE';
7
9
  import { DictionaryCommitmentDefinition } from './DICTIONARY/DICTIONARY';
8
10
  import { FormatCommitmentDefinition } from './FORMAT/FORMAT';
9
11
  import { FromCommitmentDefinition } from './FROM/FROM';
10
- import { ImportCommitmentDefinition } from './IMPORT/IMPORT';
11
12
  import { GoalCommitmentDefinition } from './GOAL/GOAL';
13
+ import { ImportCommitmentDefinition } from './IMPORT/IMPORT';
12
14
  import { KnowledgeCommitmentDefinition } from './KNOWLEDGE/KNOWLEDGE';
13
15
  import { LanguageCommitmentDefinition } from './LANGUAGE/LANGUAGE';
14
16
  import { MemoryCommitmentDefinition } from './MEMORY/MEMORY';
@@ -33,6 +35,7 @@ import { UseCommitmentDefinition } from './USE/USE';
33
35
  import { UseBrowserCommitmentDefinition } from './USE_BROWSER/USE_BROWSER';
34
36
  import { UseMcpCommitmentDefinition } from './USE_MCP/USE_MCP';
35
37
  import { UseSearchEngineCommitmentDefinition } from './USE_SEARCH_ENGINE/USE_SEARCH_ENGINE';
38
+ import { UseTimeCommitmentDefinition } from './USE_TIME/USE_TIME';
36
39
  import { NotYetImplementedCommitmentDefinition } from './_base/NotYetImplementedCommitmentDefinition';
37
40
  /**
38
41
  * Registry of all available commitment definitions
@@ -41,7 +44,7 @@ import { NotYetImplementedCommitmentDefinition } from './_base/NotYetImplemented
41
44
  *
42
45
  * @private Use functions to access commitments instead of this array directly
43
46
  */
44
- export declare const COMMITMENT_REGISTRY: readonly [PersonaCommitmentDefinition, PersonaCommitmentDefinition, KnowledgeCommitmentDefinition, MemoryCommitmentDefinition, MemoryCommitmentDefinition, StyleCommitmentDefinition, StyleCommitmentDefinition, RuleCommitmentDefinition, RuleCommitmentDefinition, LanguageCommitmentDefinition, LanguageCommitmentDefinition, SampleCommitmentDefinition, SampleCommitmentDefinition, FormatCommitmentDefinition, FormatCommitmentDefinition, FromCommitmentDefinition, ImportCommitmentDefinition, ImportCommitmentDefinition, ModelCommitmentDefinition, ModelCommitmentDefinition, ActionCommitmentDefinition, ActionCommitmentDefinition, ComponentCommitmentDefinition, MetaImageCommitmentDefinition, MetaColorCommitmentDefinition, MetaFontCommitmentDefinition, MetaLinkCommitmentDefinition, MetaCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, GoalCommitmentDefinition, GoalCommitmentDefinition, InitialMessageCommitmentDefinition, UserMessageCommitmentDefinition, AgentMessageCommitmentDefinition, MessageCommitmentDefinition, MessageCommitmentDefinition, ScenarioCommitmentDefinition, ScenarioCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DictionaryCommitmentDefinition, OpenCommitmentDefinition, ClosedCommitmentDefinition, UseBrowserCommitmentDefinition, UseSearchEngineCommitmentDefinition, UseMcpCommitmentDefinition, UseCommitmentDefinition, NotYetImplementedCommitmentDefinition<"EXPECT">, NotYetImplementedCommitmentDefinition<"BEHAVIOUR">, NotYetImplementedCommitmentDefinition<"BEHAVIOURS">, NotYetImplementedCommitmentDefinition<"AVOID">, NotYetImplementedCommitmentDefinition<"AVOIDANCE">, NotYetImplementedCommitmentDefinition<"CONTEXT">];
47
+ export declare const COMMITMENT_REGISTRY: readonly [PersonaCommitmentDefinition, PersonaCommitmentDefinition, KnowledgeCommitmentDefinition, MemoryCommitmentDefinition, MemoryCommitmentDefinition, StyleCommitmentDefinition, StyleCommitmentDefinition, RuleCommitmentDefinition, RuleCommitmentDefinition, LanguageCommitmentDefinition, LanguageCommitmentDefinition, SampleCommitmentDefinition, SampleCommitmentDefinition, FormatCommitmentDefinition, FormatCommitmentDefinition, FromCommitmentDefinition, ImportCommitmentDefinition, ImportCommitmentDefinition, ModelCommitmentDefinition, ModelCommitmentDefinition, ActionCommitmentDefinition, ActionCommitmentDefinition, ComponentCommitmentDefinition, MetaImageCommitmentDefinition, MetaColorCommitmentDefinition, MetaFontCommitmentDefinition, MetaLinkCommitmentDefinition, MetaCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, GoalCommitmentDefinition, GoalCommitmentDefinition, InitialMessageCommitmentDefinition, UserMessageCommitmentDefinition, AgentMessageCommitmentDefinition, MessageCommitmentDefinition, MessageCommitmentDefinition, ScenarioCommitmentDefinition, ScenarioCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DictionaryCommitmentDefinition, OpenCommitmentDefinition, ClosedCommitmentDefinition, UseBrowserCommitmentDefinition, UseSearchEngineCommitmentDefinition, UseTimeCommitmentDefinition, UseMcpCommitmentDefinition, UseCommitmentDefinition, NotYetImplementedCommitmentDefinition<"EXPECT">, NotYetImplementedCommitmentDefinition<"BEHAVIOUR">, NotYetImplementedCommitmentDefinition<"BEHAVIOURS">, NotYetImplementedCommitmentDefinition<"AVOID">, NotYetImplementedCommitmentDefinition<"AVOIDANCE">, NotYetImplementedCommitmentDefinition<"CONTEXT">];
45
48
  /**
46
49
  * Gets a commitment definition by its type
47
50
  * @param type The commitment type to look up
@@ -89,6 +92,18 @@ export type GroupedCommitmentDefinition = {
89
92
  * @public exported from `@promptbook/core`
90
93
  */
91
94
  export declare function getGroupedCommitmentDefinitions(): ReadonlyArray<GroupedCommitmentDefinition>;
95
+ /**
96
+ * Gets all function implementations provided by all commitments
97
+ *
98
+ * @public exported from `@promptbook/core`
99
+ */
100
+ export declare function getAllCommitmentsToolFunctions(): Record<string_javascript_name, ToolFunction>;
101
+ /**
102
+ * Gets all tool titles provided by all commitments
103
+ *
104
+ * @public exported from `@promptbook/core`
105
+ */
106
+ export declare function getAllCommitmentsToolTitles(): Record<string_javascript_name, string>;
92
107
  /**
93
108
  * TODO: [🧠] Maybe create through standardized $register
94
109
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -63,6 +63,7 @@ export declare const PROMPTBOOK_SYNTAX_COLORS: {
63
63
  readonly SEPARATOR: import("./utils/take/interfaces/ITakeChain").WithTake<Color>;
64
64
  readonly COMMITMENT: import("./utils/take/interfaces/ITakeChain").WithTake<Color>;
65
65
  readonly PARAMETER: import("./utils/take/interfaces/ITakeChain").WithTake<Color>;
66
+ readonly CODE_BLOCK: import("./utils/take/interfaces/ITakeChain").WithTake<Color>;
66
67
  };
67
68
  /**
68
69
  * Chat color of the Promptbook (in chat)
@@ -56,7 +56,9 @@ export type LlmExecutionTools = {
56
56
  /**
57
57
  * Calls a chat model with streaming
58
58
  */
59
- callChatModelStream?(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void): Promise<ChatPromptResult>;
59
+ callChatModelStream?(prompt: Prompt, onProgress: (chunk: ChatPromptResult & {
60
+ isFinished?: boolean;
61
+ }) => void): Promise<ChatPromptResult>;
60
62
  /**
61
63
  * Calls a voice chat model
62
64
  */
@@ -0,0 +1,7 @@
1
+ import type { FileImportPlugin } from './FileImportPlugin';
2
+ /**
3
+ * All available file import plugins
4
+ *
5
+ * @private [🥝] Maybe export the import plugins through some package
6
+ */
7
+ export declare const $fileImportPlugins: ReadonlyArray<FileImportPlugin>;
@@ -0,0 +1,7 @@
1
+ import type { FileImportPlugin } from './FileImportPlugin';
2
+ /**
3
+ * Plugin for importing agent books *(`.book` files)*
4
+ *
5
+ * @private [🥝] Maybe export the import plugins through some package
6
+ */
7
+ export declare const AgentFileImportPlugin: FileImportPlugin;
@@ -0,0 +1,24 @@
1
+ import type { string_mime_type } from '../types/typeAliases';
2
+ /**
3
+ * Type for file import plugins
4
+ *
5
+ * Each plugin handles a specific set of MIME types or file extensions.
6
+ */
7
+ export type FileImportPlugin = {
8
+ /**
9
+ * Unique name of the plugin
10
+ */
11
+ readonly name: string;
12
+ /**
13
+ * Checks if the plugin can handle the given MIME type or file extension
14
+ */
15
+ canImport(mimeType: string_mime_type): boolean;
16
+ /**
17
+ * Processes the file content and returns the string to be placed in the agent book
18
+ *
19
+ * @param content - The raw content of the file
20
+ * @param mimeType - The MIME type of the file
21
+ * @returns The processed content (e.g. wrapped in code block)
22
+ */
23
+ import(content: string, mimeType: string_mime_type): string | Promise<string>;
24
+ };
@@ -0,0 +1,7 @@
1
+ import type { FileImportPlugin } from './FileImportPlugin';
2
+ /**
3
+ * Plugin for importing JSON files
4
+ *
5
+ * @private [🥝] Maybe export the import plugins through some package
6
+ */
7
+ export declare const JsonFileImportPlugin: FileImportPlugin;
@@ -0,0 +1,7 @@
1
+ import type { FileImportPlugin } from './FileImportPlugin';
2
+ /**
3
+ * Plugin for importing generic text files
4
+ *
5
+ * @private [🥝] Maybe export the import plugins through some package
6
+ */
7
+ export declare const TextFileImportPlugin: FileImportPlugin;
@@ -4,9 +4,10 @@ import type { CacheLlmToolsOptions } from './CacheLlmToolsOptions';
4
4
  * Intercepts LLM tools and counts total usage of the tools
5
5
  *
6
6
  * Note: It can take extended `LlmExecutionTools` and cache the
7
+ * Note: Returns full proxy of all LLM tool properties and methods
7
8
  *
8
9
  * @param llmTools LLM tools to be intercepted with usage counting, it can contain extra methods like `totalUsage`
9
- * @returns LLM tools with same functionality with added total cost counting
10
+ * @returns Full proxy of LLM tools with same functionality with added caching
10
11
  * @public exported from `@promptbook/core`
11
12
  */
12
13
  export declare function cacheLlmTools<TLlmTools extends LlmExecutionTools>(llmTools: TLlmTools, options?: Partial<CacheLlmToolsOptions>): TLlmTools;
@@ -8,10 +8,10 @@ import type { LlmExecutionToolsWithTotalUsage } from './LlmExecutionToolsWithTot
8
8
  * in real-time through an observable.
9
9
  *
10
10
  * @param llmTools - The LLM tools to be intercepted and tracked
11
- * @returns An augmented version of the tools that includes usage tracking capabilities
11
+ * @returns Full proxy of the tools with added usage tracking capabilities
12
12
  * @public exported from `@promptbook/core`
13
13
  */
14
- export declare function countUsage(llmTools: LlmExecutionTools): LlmExecutionToolsWithTotalUsage;
14
+ export declare function countUsage<TLlmTools extends LlmExecutionTools>(llmTools: TLlmTools): TLlmTools & LlmExecutionToolsWithTotalUsage;
15
15
  /**
16
16
  * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
17
17
  * TODO: [🧠] Is there some meaningfull way how to test this util
@@ -42,7 +42,14 @@ export declare class Agent extends AgentLlmExecutionTools implements LlmExecutio
42
42
  * Capabilities of the agent
43
43
  * This is parsed from commitments like USE BROWSER, USE SEARCH ENGINE, KNOWLEDGE, etc.
44
44
  */
45
- capabilities: AgentCapability[];
45
+ capabilities: Array<AgentCapability>;
46
+ /**
47
+ * List of sample conversations (question/answer pairs)
48
+ */
49
+ samples: Array<{
50
+ question: string | null;
51
+ answer: string;
52
+ }>;
46
53
  /**
47
54
  * Computed hash of the agent source for integrity verification
48
55
  */
@@ -60,11 +67,16 @@ export declare class Agent extends AgentLlmExecutionTools implements LlmExecutio
60
67
  description?: string;
61
68
  [key: string]: string | undefined;
62
69
  };
70
+ /**
71
+ * Human-readable titles for tool functions
72
+ */
73
+ toolTitles: Record<string, string>;
63
74
  /**
64
75
  * Not used in Agent, always returns empty array
65
76
  */
66
- get parameters(): BookParameter[];
77
+ get parameters(): Array<BookParameter>;
67
78
  readonly agentSource: BehaviorSubject<string_book>;
79
+ private readonly teacherAgent;
68
80
  constructor(options: AgentOptions);
69
81
  /**
70
82
  * Calls the chat model with agent-specific system prompt and requirements with streaming
@@ -54,8 +54,10 @@ export declare class AgentLlmExecutionTools implements LlmExecutionTools {
54
54
  private getAgentInfo;
55
55
  /**
56
56
  * Get cached or create agent model requirements
57
+ *
58
+ * Note: [🐤] This is names `getModelRequirements` *(not `getAgentModelRequirements`)* because in future these two will be united
57
59
  */
58
- protected getAgentModelRequirements(): Promise<AgentModelRequirements>;
60
+ getModelRequirements(): Promise<AgentModelRequirements>;
59
61
  get title(): string_title & string_markdown_text;
60
62
  get description(): string_markdown;
61
63
  get profile(): ChatParticipant | undefined;
@@ -2,6 +2,7 @@ import type { string_book } from '../../book-2.0/agent-source/string_book';
2
2
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
3
3
  import type { ExecutionTools } from '../../execution/ExecutionTools';
4
4
  import type { Updatable } from '../../types/Updatable';
5
+ import { Agent } from './Agent';
5
6
  /**
6
7
  * Options for creating an Agent
7
8
  */
@@ -16,4 +17,10 @@ export type AgentOptions = CommonToolsOptions & {
16
17
  * The source of the agent
17
18
  */
18
19
  agentSource: Updatable<string_book>;
20
+ /**
21
+ * Teacher agent for self-learning
22
+ *
23
+ * Note: If provided, the agent can do full self-learning from the teacher agent during its operation.
24
+ */
25
+ teacherAgent: Agent | null;
19
26
  };
@@ -23,6 +23,7 @@ export declare class RemoteAgent extends Agent {
23
23
  private agentUrl;
24
24
  private _remoteAgentName;
25
25
  private _remoteAgentHash;
26
+ toolTitles: Record<string, string>;
26
27
  private _isVoiceCallingEnabled;
27
28
  private constructor();
28
29
  get agentName(): string_agent_name;
@@ -3,7 +3,7 @@ import type { string_agent_url } from '../../types/typeAliases';
3
3
  /**
4
4
  * Options for creating a Remote Agent
5
5
  */
6
- export type RemoteAgentOptions = CommonToolsOptions & {
6
+ export type RemoteAgentOptions = Omit<CommonToolsOptions, 'teacherAgent'> & {
7
7
  /**
8
8
  * Url of the remote agent
9
9
  */
@@ -1,5 +1,6 @@
1
1
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
2
2
  import type { ChatPromptResult } from '../../execution/PromptResult';
3
+ import type { ModelRequirements } from '../../types/ModelRequirements';
3
4
  import type { Prompt } from '../../types/Prompt';
4
5
  import type { string_markdown, string_markdown_text, string_title, string_token } from '../../types/typeAliases';
5
6
  import type { OpenAiAssistantExecutionToolsOptions } from './OpenAiAssistantExecutionToolsOptions';
@@ -54,6 +55,10 @@ export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools
54
55
  * Optional list of knowledge source links (URLs or file paths) to attach to the assistant via vector store
55
56
  */
56
57
  readonly knowledgeSources?: ReadonlyArray<string>;
58
+ /**
59
+ * Optional list of tools to attach to the assistant
60
+ */
61
+ readonly tools?: ModelRequirements['tools'];
57
62
  }): Promise<OpenAiAssistantExecutionTools>;
58
63
  updateAssistant(options: {
59
64
  /**
@@ -72,6 +77,10 @@ export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools
72
77
  * Optional list of knowledge source links (URLs or file paths) to attach to the assistant via vector store
73
78
  */
74
79
  readonly knowledgeSources?: ReadonlyArray<string>;
80
+ /**
81
+ * Optional list of tools to attach to the assistant
82
+ */
83
+ readonly tools?: ModelRequirements['tools'];
75
84
  }): Promise<OpenAiAssistantExecutionTools>;
76
85
  /**
77
86
  * Discriminant for type guards
@@ -85,6 +94,7 @@ export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools
85
94
  static isOpenAiAssistantExecutionTools(llmExecutionTools: LlmExecutionTools): llmExecutionTools is OpenAiAssistantExecutionTools;
86
95
  }
87
96
  /**
97
+ * TODO: [🙎] In `OpenAiAssistantExecutionTools` Allow to create abstract assistants with `isCreatingNewAssistantsAllowed`
88
98
  * TODO: [🧠][🧙‍♂️] Maybe there can be some wizard for those who want to use just OpenAI
89
99
  * TODO: Maybe make custom OpenAiError
90
100
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
@@ -39,10 +39,17 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
39
39
  * List all available OpenAI compatible models that can be used
40
40
  */
41
41
  listModels(): Promise<ReadonlyArray<AvailableModel>>;
42
+ /**
43
+ * Calls OpenAI compatible API to use a chat model.
44
+ */
42
45
  /**
43
46
  * Calls OpenAI compatible API to use a chat model.
44
47
  */
45
48
  callChatModel(prompt: Prompt): Promise<ChatPromptResult>;
49
+ /**
50
+ * Calls OpenAI compatible API to use a chat model with streaming.
51
+ */
52
+ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void): Promise<ChatPromptResult>;
46
53
  /**
47
54
  * Internal method that handles parameter retry for chat model calls
48
55
  */
@@ -46,7 +46,7 @@ export declare class RemoteLlmExecutionTools<TCustomOptions = undefined> impleme
46
46
  private callCommonModel;
47
47
  }
48
48
  /**
49
- * TODO: !!!! Deprecate pipeline server and all of its components
49
+ * TODO: [🕴] Deprecate pipeline server and all of its components
50
50
  * TODO: Maybe use `$exportJson`
51
51
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
52
52
  * TODO: [🍓] Allow to list compatible models with each variant
@@ -1,4 +1,5 @@
1
1
  import type { Promisable } from 'type-fest';
2
+ import { TODO_any } from '../../_packages/types.index';
2
3
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
3
4
  import type { string_postprocessing_function_name } from '../../types/typeAliases';
4
5
  /**
@@ -15,12 +16,16 @@ export type JavascriptExecutionToolsOptions = CommonToolsOptions & {
15
16
  * Note: There are also some built-in functions available:
16
17
  * @see ./JavascriptEvalExecutionTools.ts
17
18
  */
18
- functions?: Record<string_postprocessing_function_name, PostprocessingFunction>;
19
+ functions?: Record<string_postprocessing_function_name, PostprocessingFunction | ToolFunction>;
19
20
  };
20
21
  /**
21
22
  * Function that can be used to postprocess the output of the LLM
22
23
  */
23
24
  export type PostprocessingFunction = ((value: string) => Promisable<string>) | Function;
25
+ /**
26
+ * Function that can be used as tool for AI model
27
+ */
28
+ export type ToolFunction = (args: TODO_any) => Promise<TODO_any>;
24
29
  /**
25
30
  * TODO: [🧠][💙] Distinct between options passed into ExecutionTools and to ExecutionTools.execute
26
31
  */
@@ -5,5 +5,5 @@ export type SearchEngine = {
5
5
  readonly title: string_title & string_markdown_text;
6
6
  readonly description?: string_markdown;
7
7
  checkConfiguration(): Promisable<void>;
8
- search(query: string): Promise<SearchResult[]>;
8
+ search(query: string, options?: Record<string, unknown>): Promise<SearchResult[]>;
9
9
  };
@@ -0,0 +1,6 @@
1
+ export * from './bing/BingSearchEngine';
2
+ export * from './dummy/DummySearchEngine';
3
+ export * from './google/GoogleSearchEngine';
4
+ export * from './SearchEngine';
5
+ export * from './SearchResult';
6
+ export * from './serp/SerpSearchEngine';
@@ -11,5 +11,5 @@ export declare class BingSearchEngine implements SearchEngine {
11
11
  get title(): string_title & string_markdown_text;
12
12
  get description(): string_markdown;
13
13
  checkConfiguration(): Promisable<void>;
14
- search(query: string): Promise<SearchResult[]>;
14
+ search(query: string, options?: Record<string, unknown>): Promise<SearchResult[]>;
15
15
  }
@@ -11,5 +11,5 @@ export declare class DummySearchEngine implements SearchEngine {
11
11
  get title(): string_title & string_markdown_text;
12
12
  get description(): string_markdown;
13
13
  checkConfiguration(): Promisable<void>;
14
- search(query: string): Promise<SearchResult[]>;
14
+ search(query: string, options?: Record<string, unknown>): Promise<SearchResult[]>;
15
15
  }
@@ -0,0 +1,18 @@
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
3
+ import type { SearchEngine } from '../SearchEngine';
4
+ import type { SearchResult } from '../SearchResult';
5
+ /**
6
+ * A search engine implementation that uses the Google Custom Search JSON API.
7
+ *
8
+ * @private <- TODO: !!!! Export via some package
9
+ */
10
+ export declare class GoogleSearchEngine implements SearchEngine {
11
+ get title(): string_title & string_markdown_text;
12
+ get description(): string_markdown;
13
+ /**
14
+ * @see https://developers.google.com/custom-search/v1/overview
15
+ */
16
+ checkConfiguration(): Promisable<void>;
17
+ search(query: string, options?: Record<string, unknown>): Promise<SearchResult[]>;
18
+ }
@@ -0,0 +1,15 @@
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
3
+ import type { SearchEngine } from '../SearchEngine';
4
+ import type { SearchResult } from '../SearchResult';
5
+ /**
6
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
7
+ *
8
+ * @private <- TODO: !!!! Export via some package
9
+ */
10
+ export declare class SerpSearchEngine implements SearchEngine {
11
+ get title(): string_title & string_markdown_text;
12
+ get description(): string_markdown;
13
+ checkConfiguration(): Promisable<void>;
14
+ search(query: string, options?: Record<string, unknown>): Promise<SearchResult[]>;
15
+ }
@@ -0,0 +1,21 @@
1
+ import type { SpeechRecognition, SpeechRecognitionEvent, SpeechRecognitionStartOptions, SpeechRecognitionState } from '../types/SpeechRecognition';
2
+ /**
3
+ * Speech recognition using Web Speech API `SpeechRecognition` available in modern browsers
4
+ *
5
+ * @public exported from `@promptbook/browser`
6
+ */
7
+ export declare class BrowserSpeechRecognition implements SpeechRecognition {
8
+ private recognition;
9
+ private callbacks;
10
+ private _state;
11
+ get state(): SpeechRecognitionState;
12
+ constructor();
13
+ $start(options?: SpeechRecognitionStartOptions): void;
14
+ $stop(): void;
15
+ subscribe(callback: (event: SpeechRecognitionEvent) => void): () => void;
16
+ private emit;
17
+ }
18
+ /**
19
+ * TODO: !!!! Search ACRY for `window` and put -> [🔵]
20
+ * Note: [🔵] Code in this file should never be published outside of `@promptbook/browser`
21
+ */
@@ -0,0 +1,32 @@
1
+ import type { SpeechRecognition, SpeechRecognitionEvent, SpeechRecognitionStartOptions, SpeechRecognitionState } from '../types/SpeechRecognition';
2
+ /**
3
+ * Options for OpenAiSpeechRecognition
4
+ */
5
+ export type OpenAiSpeechRecognitionOptions = {
6
+ /**
7
+ * OpenAI API base URL or proxy endpoint
8
+ * @default '/api/openai/v1'
9
+ */
10
+ readonly baseUrl?: string;
11
+ };
12
+ /**
13
+ * Speech recognition using OpenAI Whisper API to transcribe audio into text
14
+ *
15
+ * @private because it requires server-client communication with a proxy endpoint
16
+ *
17
+ * Note: This implementation uses a server-side proxy to avoid exposing the OpenAI API key on the client.
18
+ */
19
+ export declare class OpenAiSpeechRecognition implements SpeechRecognition {
20
+ private readonly options;
21
+ private mediaRecorder;
22
+ private audioChunks;
23
+ private callbacks;
24
+ private _state;
25
+ get state(): SpeechRecognitionState;
26
+ constructor(options?: OpenAiSpeechRecognitionOptions);
27
+ $start(options?: SpeechRecognitionStartOptions): Promise<void>;
28
+ $stop(): void;
29
+ private transcribe;
30
+ subscribe(callback: (event: SpeechRecognitionEvent) => void): () => void;
31
+ private emit;
32
+ }
@@ -29,12 +29,6 @@ export type CompletionModelRequirements = CommonModelRequirements & {
29
29
  * Maximum number of tokens that can be generated by the model
30
30
  */
31
31
  readonly maxTokens?: number;
32
- /**
33
- * Tools available for the model
34
- *
35
- * Note: [🚉] This is fully serializable as JSON
36
- */
37
- readonly tools?: LlmToolDefinition[];
38
32
  };
39
33
  /**
40
34
  * Model requirements for the chat variant
@@ -60,12 +54,6 @@ export type ChatModelRequirements = CommonModelRequirements & {
60
54
  * Maximum number of tokens that can be generated by the model
61
55
  */
62
56
  readonly maxTokens?: number;
63
- /**
64
- * Tools available for the model
65
- *
66
- * Note: [🚉] This is fully serializable as JSON
67
- */
68
- readonly tools?: LlmToolDefinition[];
69
57
  };
70
58
  /**
71
59
  * Model requirements for the image generation variant
@@ -135,6 +123,12 @@ export type CommonModelRequirements = {
135
123
  * Seed for the model
136
124
  */
137
125
  readonly seed?: number_seed;
126
+ /**
127
+ * Tools available for the model
128
+ *
129
+ * Note: [🚉] This is fully serializable as JSON
130
+ */
131
+ readonly tools?: LlmToolDefinition[];
138
132
  };
139
133
  /**
140
134
  * TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (similar that `user` identification is not here)