@promptbook/browser 0.114.0-3 → 0.114.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/README.md +1 -9
- package/esm/index.es.js +504 -4004
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +3 -3
- package/esm/src/cli/cli-commands/coder/boilerplateCount.d.ts +52 -0
- package/esm/src/cli/cli-commands/coder/generate-boilerplates.d.ts +3 -2
- package/esm/src/commitments/{COMPONENT/COMPONENT.d.ts → META_FULLNAME/META_FULLNAME.d.ts} +8 -5
- package/esm/src/commitments/META_ID/META_ID.d.ts +32 -0
- package/esm/src/commitments/index.d.ts +4 -12
- package/esm/src/llm-providers/agent/Agent.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
- package/esm/src/{commitments/USE_BROWSER → scrapers/_common/utils}/fetchUrlContent.d.ts +2 -3
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -3
- package/umd/index.umd.js +508 -4008
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +3 -3
- package/umd/src/cli/cli-commands/coder/boilerplateCount.d.ts +52 -0
- package/umd/src/cli/cli-commands/coder/generate-boilerplates.d.ts +3 -2
- package/umd/src/commitments/{COMPONENT/COMPONENT.d.ts → META_FULLNAME/META_FULLNAME.d.ts} +8 -5
- package/umd/src/commitments/META_ID/META_ID.d.ts +32 -0
- package/umd/src/commitments/index.d.ts +4 -12
- package/umd/src/llm-providers/agent/Agent.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
- package/umd/src/{commitments/USE_BROWSER → scrapers/_common/utils}/fetchUrlContent.d.ts +2 -3
- package/umd/src/version.d.ts +1 -1
- package/esm/src/commitments/MEMORY/MEMORY.d.ts +0 -48
- package/esm/src/commitments/MEMORY/MemoryToolNames.d.ts +0 -11
- package/esm/src/commitments/MEMORY/MemoryToolRuntimeAdapter.d.ts +0 -149
- package/esm/src/commitments/MEMORY/createMemorySystemMessage.d.ts +0 -6
- package/esm/src/commitments/MEMORY/createMemoryToolFunctions.d.ts +0 -8
- package/esm/src/commitments/MEMORY/createMemoryTools.d.ts +0 -14
- package/esm/src/commitments/MEMORY/getMemoryCommitmentDocumentation.d.ts +0 -6
- package/esm/src/commitments/MEMORY/getMemoryToolRuntimeAdapterOrDisabledResult.d.ts +0 -17
- package/esm/src/commitments/MEMORY/getMemoryToolTitles.d.ts +0 -7
- package/esm/src/commitments/MEMORY/parseMemoryToolArgs.d.ts +0 -61
- package/esm/src/commitments/MEMORY/resolveMemoryRuntimeContext.d.ts +0 -8
- package/esm/src/commitments/MEMORY/setMemoryToolRuntimeAdapter.d.ts +0 -13
- package/esm/src/commitments/META/META.d.ts +0 -65
- package/esm/src/commitments/USE/aggregateUseCommitmentSystemMessages.d.ts +0 -32
- package/esm/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +0 -58
- package/esm/src/commitments/USE_BROWSER/fetchUrlContentViaBrowser.d.ts +0 -13
- package/esm/src/commitments/USE_BROWSER/resolveRunBrowserToolForNode.d.ts +0 -10
- package/esm/src/commitments/USE_DEEPSEARCH/USE_DEEPSEARCH.d.ts +0 -47
- package/esm/src/commitments/USE_EMAIL/USE_EMAIL.d.ts +0 -38
- package/esm/src/commitments/USE_EMAIL/parseUseEmailCommitmentContent.d.ts +0 -21
- package/esm/src/commitments/USE_EMAIL/parseUseEmailCommitmentContent.test.d.ts +0 -1
- package/esm/src/commitments/USE_EMAIL/resolveSendEmailToolForNode.d.ts +0 -11
- package/esm/src/commitments/USE_EMAIL/sendEmailViaBrowser.d.ts +0 -13
- package/esm/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +0 -46
- package/esm/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.test.d.ts +0 -1
- package/esm/src/commitments/USE_SPAWN/USE_SPAWN.d.ts +0 -38
- package/esm/src/commitments/USE_SPAWN/USE_SPAWN.test.d.ts +0 -1
- package/esm/src/commitments/USE_SPAWN/resolveSpawnAgentToolForNode.d.ts +0 -9
- package/esm/src/commitments/USE_SPAWN/spawnAgentViaBrowser.d.ts +0 -12
- package/esm/src/commitments/USE_TIME/USE_TIME.d.ts +0 -43
- package/esm/src/commitments/USE_TIME/USE_TIME.test.d.ts +0 -1
- package/esm/src/commitments/USE_TIMEOUT/TimeoutToolNames.d.ts +0 -11
- package/esm/src/commitments/USE_TIMEOUT/TimeoutToolRuntimeAdapter.d.ts +0 -212
- package/esm/src/commitments/USE_TIMEOUT/USE_TIMEOUT.d.ts +0 -38
- package/esm/src/commitments/USE_TIMEOUT/USE_TIMEOUT.test.d.ts +0 -1
- package/esm/src/commitments/USE_TIMEOUT/createTimeoutSystemMessage.d.ts +0 -6
- package/esm/src/commitments/USE_TIMEOUT/createTimeoutToolFunctions.d.ts +0 -8
- package/esm/src/commitments/USE_TIMEOUT/createTimeoutTools.d.ts +0 -7
- package/esm/src/commitments/USE_TIMEOUT/getTimeoutToolRuntimeAdapterOrDisabledResult.d.ts +0 -17
- package/esm/src/commitments/USE_TIMEOUT/parseTimeoutToolArgs.d.ts +0 -78
- package/esm/src/commitments/USE_TIMEOUT/resolveTimeoutRuntimeContext.d.ts +0 -8
- package/esm/src/commitments/USE_TIMEOUT/setTimeoutToolRuntimeAdapter.d.ts +0 -13
- package/esm/src/commitments/WALLET/WALLET.d.ts +0 -21
- package/esm/src/commitments/WALLET/WALLET.test.d.ts +0 -1
- package/esm/src/commitments/WALLET/WalletToolNames.d.ts +0 -12
- package/esm/src/commitments/WALLET/WalletToolRuntimeAdapter.d.ts +0 -163
- package/esm/src/commitments/WALLET/createWalletSystemMessage.d.ts +0 -6
- package/esm/src/commitments/WALLET/createWalletToolFunctions.d.ts +0 -8
- package/esm/src/commitments/WALLET/createWalletTools.d.ts +0 -7
- package/esm/src/commitments/WALLET/getWalletCommitmentDocumentation.d.ts +0 -6
- package/esm/src/commitments/WALLET/getWalletToolRuntimeAdapterOrDisabledResult.d.ts +0 -16
- package/esm/src/commitments/WALLET/getWalletToolTitles.d.ts +0 -7
- package/esm/src/commitments/WALLET/parseWalletToolArgs.d.ts +0 -51
- package/esm/src/commitments/WALLET/resolveWalletRuntimeContext.d.ts +0 -8
- package/esm/src/commitments/WALLET/setWalletToolRuntimeAdapter.d.ts +0 -13
- package/esm/src/commitments/_common/createSerpSearchToolFunction.d.ts +0 -12
- package/umd/src/book-2.0/agent-source/createAgentModelRequirements.useCommitmentAggregation.test.d.ts +0 -1
- package/umd/src/commitments/MEMORY/MEMORY.d.ts +0 -48
- package/umd/src/commitments/MEMORY/MEMORY.test.d.ts +0 -1
- package/umd/src/commitments/MEMORY/MemoryToolNames.d.ts +0 -11
- package/umd/src/commitments/MEMORY/MemoryToolRuntimeAdapter.d.ts +0 -149
- package/umd/src/commitments/MEMORY/createMemorySystemMessage.d.ts +0 -6
- package/umd/src/commitments/MEMORY/createMemoryToolFunctions.d.ts +0 -8
- package/umd/src/commitments/MEMORY/createMemoryTools.d.ts +0 -14
- package/umd/src/commitments/MEMORY/getMemoryCommitmentDocumentation.d.ts +0 -6
- package/umd/src/commitments/MEMORY/getMemoryToolRuntimeAdapterOrDisabledResult.d.ts +0 -17
- package/umd/src/commitments/MEMORY/getMemoryToolTitles.d.ts +0 -7
- package/umd/src/commitments/MEMORY/parseMemoryToolArgs.d.ts +0 -61
- package/umd/src/commitments/MEMORY/resolveMemoryRuntimeContext.d.ts +0 -8
- package/umd/src/commitments/MEMORY/setMemoryToolRuntimeAdapter.d.ts +0 -13
- package/umd/src/commitments/META/META.d.ts +0 -65
- package/umd/src/commitments/USE/aggregateUseCommitmentSystemMessages.d.ts +0 -32
- package/umd/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +0 -58
- package/umd/src/commitments/USE_BROWSER/USE_BROWSER.test.d.ts +0 -1
- package/umd/src/commitments/USE_BROWSER/fetchUrlContentViaBrowser.d.ts +0 -13
- package/umd/src/commitments/USE_BROWSER/resolveRunBrowserToolForNode.d.ts +0 -10
- package/umd/src/commitments/USE_BROWSER/resolveRunBrowserToolForNode.test.d.ts +0 -1
- package/umd/src/commitments/USE_DEEPSEARCH/USE_DEEPSEARCH.d.ts +0 -47
- package/umd/src/commitments/USE_DEEPSEARCH/USE_DEEPSEARCH.test.d.ts +0 -1
- package/umd/src/commitments/USE_EMAIL/USE_EMAIL.d.ts +0 -38
- package/umd/src/commitments/USE_EMAIL/USE_EMAIL.test.d.ts +0 -1
- package/umd/src/commitments/USE_EMAIL/parseUseEmailCommitmentContent.d.ts +0 -21
- package/umd/src/commitments/USE_EMAIL/parseUseEmailCommitmentContent.test.d.ts +0 -1
- package/umd/src/commitments/USE_EMAIL/resolveSendEmailToolForNode.d.ts +0 -11
- package/umd/src/commitments/USE_EMAIL/sendEmailViaBrowser.d.ts +0 -13
- package/umd/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +0 -46
- package/umd/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.test.d.ts +0 -1
- package/umd/src/commitments/USE_SPAWN/USE_SPAWN.d.ts +0 -38
- package/umd/src/commitments/USE_SPAWN/USE_SPAWN.test.d.ts +0 -1
- package/umd/src/commitments/USE_SPAWN/resolveSpawnAgentToolForNode.d.ts +0 -9
- package/umd/src/commitments/USE_SPAWN/spawnAgentViaBrowser.d.ts +0 -12
- package/umd/src/commitments/USE_TIME/USE_TIME.d.ts +0 -43
- package/umd/src/commitments/USE_TIME/USE_TIME.test.d.ts +0 -1
- package/umd/src/commitments/USE_TIMEOUT/TimeoutToolNames.d.ts +0 -11
- package/umd/src/commitments/USE_TIMEOUT/TimeoutToolRuntimeAdapter.d.ts +0 -212
- package/umd/src/commitments/USE_TIMEOUT/USE_TIMEOUT.d.ts +0 -38
- package/umd/src/commitments/USE_TIMEOUT/USE_TIMEOUT.test.d.ts +0 -1
- package/umd/src/commitments/USE_TIMEOUT/createTimeoutSystemMessage.d.ts +0 -6
- package/umd/src/commitments/USE_TIMEOUT/createTimeoutToolFunctions.d.ts +0 -8
- package/umd/src/commitments/USE_TIMEOUT/createTimeoutTools.d.ts +0 -7
- package/umd/src/commitments/USE_TIMEOUT/getTimeoutToolRuntimeAdapterOrDisabledResult.d.ts +0 -17
- package/umd/src/commitments/USE_TIMEOUT/parseTimeoutToolArgs.d.ts +0 -78
- package/umd/src/commitments/USE_TIMEOUT/resolveTimeoutRuntimeContext.d.ts +0 -8
- package/umd/src/commitments/USE_TIMEOUT/setTimeoutToolRuntimeAdapter.d.ts +0 -13
- package/umd/src/commitments/WALLET/WALLET.d.ts +0 -21
- package/umd/src/commitments/WALLET/WALLET.test.d.ts +0 -1
- package/umd/src/commitments/WALLET/WalletToolNames.d.ts +0 -12
- package/umd/src/commitments/WALLET/WalletToolRuntimeAdapter.d.ts +0 -163
- package/umd/src/commitments/WALLET/createWalletSystemMessage.d.ts +0 -6
- package/umd/src/commitments/WALLET/createWalletToolFunctions.d.ts +0 -8
- package/umd/src/commitments/WALLET/createWalletTools.d.ts +0 -7
- package/umd/src/commitments/WALLET/getWalletCommitmentDocumentation.d.ts +0 -6
- package/umd/src/commitments/WALLET/getWalletToolRuntimeAdapterOrDisabledResult.d.ts +0 -16
- package/umd/src/commitments/WALLET/getWalletToolTitles.d.ts +0 -7
- package/umd/src/commitments/WALLET/parseWalletToolArgs.d.ts +0 -51
- package/umd/src/commitments/WALLET/resolveWalletRuntimeContext.d.ts +0 -8
- package/umd/src/commitments/WALLET/setWalletToolRuntimeAdapter.d.ts +0 -13
- package/umd/src/commitments/_common/createSerpSearchToolFunction.d.ts +0 -12
- /package/esm/src/book-2.0/agent-source/{createAgentModelRequirements.useCommitmentAggregation.test.d.ts → createAgentModelRequirements.commitmentAggregation.test.d.ts} +0 -0
- /package/esm/src/{commitments/MEMORY/MEMORY.test.d.ts → cli/cli-commands/coder/boilerplateCount.test.d.ts} +0 -0
- /package/esm/src/{commitments/USE_BROWSER/USE_BROWSER.test.d.ts → cli/cli-commands/coder/generate-boilerplates.test.d.ts} +0 -0
- /package/esm/src/commitments/{META → META_DESCRIPTION}/META_DESCRIPTION.d.ts +0 -0
- /package/{esm/src/commitments/USE_BROWSER/resolveRunBrowserToolForNode.test.d.ts → umd/src/book-2.0/agent-source/createAgentModelRequirements.commitmentAggregation.test.d.ts} +0 -0
- /package/{esm/src/commitments/USE_DEEPSEARCH/USE_DEEPSEARCH.test.d.ts → umd/src/cli/cli-commands/coder/boilerplateCount.test.d.ts} +0 -0
- /package/{esm/src/commitments/USE_EMAIL/USE_EMAIL.test.d.ts → umd/src/cli/cli-commands/coder/generate-boilerplates.test.d.ts} +0 -0
- /package/umd/src/commitments/{META → META_DESCRIPTION}/META_DESCRIPTION.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -5,7 +5,6 @@ import CryptoJS from 'crypto-js';
|
|
|
5
5
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
6
6
|
import { basename, join, dirname, isAbsolute } from 'path';
|
|
7
7
|
import 'crypto';
|
|
8
|
-
import moment from 'moment';
|
|
9
8
|
import { lookup, extension } from 'mime-types';
|
|
10
9
|
import { forTime } from 'waitasecond';
|
|
11
10
|
import sha256 from 'crypto-js/sha256';
|
|
@@ -27,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
26
|
* @generated
|
|
28
27
|
* @see https://github.com/webgptorg/promptbook
|
|
29
28
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-4';
|
|
31
30
|
/**
|
|
32
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1672,7 +1671,7 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1672
1671
|
Research Assistant
|
|
1673
1672
|
|
|
1674
1673
|
PERSONA You are a helpful research assistant
|
|
1675
|
-
USE
|
|
1674
|
+
USE MCP https://mcp.example.com/server
|
|
1676
1675
|
RULE Always cite your sources when providing information from the web
|
|
1677
1676
|
\`\`\`
|
|
1678
1677
|
|
|
@@ -1692,8 +1691,8 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1692
1691
|
Code Assistant
|
|
1693
1692
|
|
|
1694
1693
|
PERSONA You are a programming assistant
|
|
1695
|
-
USE
|
|
1696
|
-
USE
|
|
1694
|
+
USE PROJECT https://github.com/example/project
|
|
1695
|
+
USE MCP https://mcp.example.com/server
|
|
1697
1696
|
RULE Prefer the narrowest useful capability for the task.
|
|
1698
1697
|
\`\`\`
|
|
1699
1698
|
`);
|
|
@@ -1794,65 +1793,6 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1794
1793
|
}
|
|
1795
1794
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1796
1795
|
|
|
1797
|
-
/**
|
|
1798
|
-
* COMPONENT commitment definition
|
|
1799
|
-
*
|
|
1800
|
-
* The COMPONENT commitment defines a UI component that the agent can render in the chat.
|
|
1801
|
-
*
|
|
1802
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
1803
|
-
*/
|
|
1804
|
-
class ComponentCommitmentDefinition extends BaseCommitmentDefinition {
|
|
1805
|
-
constructor() {
|
|
1806
|
-
super('COMPONENT');
|
|
1807
|
-
}
|
|
1808
|
-
/**
|
|
1809
|
-
* Short one-line description of COMPONENT.
|
|
1810
|
-
*/
|
|
1811
|
-
get description() {
|
|
1812
|
-
return 'Define a UI component that the agent can render in the chat.';
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Icon for this commitment.
|
|
1816
|
-
*/
|
|
1817
|
-
get icon() {
|
|
1818
|
-
return '🧩';
|
|
1819
|
-
}
|
|
1820
|
-
/**
|
|
1821
|
-
* Markdown documentation for COMPONENT commitment.
|
|
1822
|
-
*/
|
|
1823
|
-
get documentation() {
|
|
1824
|
-
return spaceTrim$1(`
|
|
1825
|
-
# COMPONENT
|
|
1826
|
-
|
|
1827
|
-
Defines a UI component that the agent can render in the chat.
|
|
1828
|
-
|
|
1829
|
-
## Key aspects
|
|
1830
|
-
|
|
1831
|
-
- Tells the agent that a specific component is available.
|
|
1832
|
-
- Provides syntax for using the component.
|
|
1833
|
-
|
|
1834
|
-
## Example
|
|
1835
|
-
|
|
1836
|
-
\`\`\`book
|
|
1837
|
-
COMPONENT Arrow
|
|
1838
|
-
The agent should render an arrow component in the chat UI.
|
|
1839
|
-
Syntax:
|
|
1840
|
-
<Arrow direction="up" color="red" />
|
|
1841
|
-
\`\`\`
|
|
1842
|
-
`);
|
|
1843
|
-
}
|
|
1844
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
1845
|
-
const trimmedContent = content.trim();
|
|
1846
|
-
if (!trimmedContent) {
|
|
1847
|
-
return requirements;
|
|
1848
|
-
}
|
|
1849
|
-
// Add component capability to the system message
|
|
1850
|
-
const componentSection = `Component: ${trimmedContent}`;
|
|
1851
|
-
return this.appendToSystemMessage(requirements, componentSection, '\n\n');
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1855
|
-
|
|
1856
1796
|
/**
|
|
1857
1797
|
* DELETE commitment definition
|
|
1858
1798
|
*
|
|
@@ -3704,653 +3644,6 @@ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
3704
3644
|
}
|
|
3705
3645
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3706
3646
|
|
|
3707
|
-
/**
|
|
3708
|
-
* @@@
|
|
3709
|
-
*
|
|
3710
|
-
* @private utility for commitments
|
|
3711
|
-
*/
|
|
3712
|
-
function formatOptionalInstructionBlock(label, content) {
|
|
3713
|
-
const trimmedContent = spaceTrim$1(content);
|
|
3714
|
-
if (!trimmedContent) {
|
|
3715
|
-
return '';
|
|
3716
|
-
}
|
|
3717
|
-
return spaceTrim$1((block) => `
|
|
3718
|
-
- ${label}:
|
|
3719
|
-
${block(trimmedContent
|
|
3720
|
-
.split(/\r?\n/)
|
|
3721
|
-
.map((line) => `- ${line}`)
|
|
3722
|
-
.join('\n'))}
|
|
3723
|
-
`);
|
|
3724
|
-
}
|
|
3725
|
-
|
|
3726
|
-
/**
|
|
3727
|
-
* Names of tools used by the MEMORY commitment.
|
|
3728
|
-
*
|
|
3729
|
-
* @private function of MemoryCommitmentDefinition
|
|
3730
|
-
*/
|
|
3731
|
-
const MemoryToolNames = {
|
|
3732
|
-
retrieve: 'retrieve_user_memory',
|
|
3733
|
-
store: 'store_user_memory',
|
|
3734
|
-
update: 'update_user_memory',
|
|
3735
|
-
delete: 'delete_user_memory',
|
|
3736
|
-
};
|
|
3737
|
-
|
|
3738
|
-
/**
|
|
3739
|
-
* Builds the MEMORY instruction block appended to the system message.
|
|
3740
|
-
*
|
|
3741
|
-
* @private function of MemoryCommitmentDefinition
|
|
3742
|
-
*/
|
|
3743
|
-
function createMemorySystemMessage(extraInstructions) {
|
|
3744
|
-
return spaceTrim$1((block) => `
|
|
3745
|
-
## Memory
|
|
3746
|
-
|
|
3747
|
-
- Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
|
|
3748
|
-
- You can use persistent user memory tools.
|
|
3749
|
-
- Use \`${MemoryToolNames.retrieve}\` to load relevant memory before answering.
|
|
3750
|
-
- Use \`${MemoryToolNames.store}\` to save stable user-specific facts that improve future help.
|
|
3751
|
-
- Use \`${MemoryToolNames.update}\` to refresh an existing memory when the content changes.
|
|
3752
|
-
- Use \`${MemoryToolNames.delete}\` to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
|
|
3753
|
-
- Store concise memory items and avoid duplicates.
|
|
3754
|
-
- Never claim memory was saved or loaded unless the tool confirms it.
|
|
3755
|
-
${block(extraInstructions)}
|
|
3756
|
-
`);
|
|
3757
|
-
}
|
|
3758
|
-
|
|
3759
|
-
/**
|
|
3760
|
-
* Builds a disabled memory-tool response payload.
|
|
3761
|
-
*
|
|
3762
|
-
* @private function of MemoryCommitmentDefinition
|
|
3763
|
-
*/
|
|
3764
|
-
function createDisabledMemoryResult(action, message) {
|
|
3765
|
-
if (action === 'retrieve') {
|
|
3766
|
-
return {
|
|
3767
|
-
action,
|
|
3768
|
-
status: 'disabled',
|
|
3769
|
-
memories: [],
|
|
3770
|
-
message,
|
|
3771
|
-
};
|
|
3772
|
-
}
|
|
3773
|
-
if (action === 'store') {
|
|
3774
|
-
return {
|
|
3775
|
-
action,
|
|
3776
|
-
status: 'disabled',
|
|
3777
|
-
message,
|
|
3778
|
-
};
|
|
3779
|
-
}
|
|
3780
|
-
if (action === 'update') {
|
|
3781
|
-
return {
|
|
3782
|
-
action,
|
|
3783
|
-
status: 'disabled',
|
|
3784
|
-
message,
|
|
3785
|
-
};
|
|
3786
|
-
}
|
|
3787
|
-
if (action === 'delete') {
|
|
3788
|
-
return {
|
|
3789
|
-
action,
|
|
3790
|
-
status: 'disabled',
|
|
3791
|
-
message,
|
|
3792
|
-
};
|
|
3793
|
-
}
|
|
3794
|
-
throw new Error(`Unsupported memory tool action: ${action}`);
|
|
3795
|
-
}
|
|
3796
|
-
/**
|
|
3797
|
-
* Gets the runtime adapter and returns a disabled result when unavailable.
|
|
3798
|
-
*
|
|
3799
|
-
* @private function of MemoryCommitmentDefinition
|
|
3800
|
-
*/
|
|
3801
|
-
function getMemoryToolRuntimeAdapterOrDisabledResult(action, runtimeContext) {
|
|
3802
|
-
if (!runtimeContext.enabled || runtimeContext.isTeamConversation || runtimeContext.isPrivateMode) {
|
|
3803
|
-
const message = runtimeContext.isPrivateMode
|
|
3804
|
-
? 'Memory is disabled because private mode is active.'
|
|
3805
|
-
: runtimeContext.isTeamConversation
|
|
3806
|
-
? 'Memory is disabled for TEAM conversations.'
|
|
3807
|
-
: 'Memory is disabled for unauthenticated users.';
|
|
3808
|
-
return {
|
|
3809
|
-
adapter: null,
|
|
3810
|
-
disabledResult: createDisabledMemoryResult(action, message),
|
|
3811
|
-
};
|
|
3812
|
-
}
|
|
3813
|
-
{
|
|
3814
|
-
return {
|
|
3815
|
-
adapter: null,
|
|
3816
|
-
disabledResult: createDisabledMemoryResult(action, 'Memory runtime is not available in this environment.'),
|
|
3817
|
-
};
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
/**
|
|
3822
|
-
* Parses a memory identifier argument shared across MEMORY tools.
|
|
3823
|
-
*
|
|
3824
|
-
* @private function of MemoryCommitmentDefinition
|
|
3825
|
-
*/
|
|
3826
|
-
function parseMemoryIdArg(value) {
|
|
3827
|
-
const memoryId = typeof value === 'string' ? value.trim() : '';
|
|
3828
|
-
if (!memoryId) {
|
|
3829
|
-
throw new Error('Memory id is required.');
|
|
3830
|
-
}
|
|
3831
|
-
return memoryId;
|
|
3832
|
-
}
|
|
3833
|
-
/**
|
|
3834
|
-
* Collection of MEMORY tool argument parsers.
|
|
3835
|
-
*
|
|
3836
|
-
* @private function of MemoryCommitmentDefinition
|
|
3837
|
-
*/
|
|
3838
|
-
const parseMemoryToolArgs = {
|
|
3839
|
-
/**
|
|
3840
|
-
* Parses retrieve memory arguments.
|
|
3841
|
-
*/
|
|
3842
|
-
retrieve(args) {
|
|
3843
|
-
const query = typeof args.query === 'string' ? args.query.trim() : undefined;
|
|
3844
|
-
const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : undefined;
|
|
3845
|
-
return {
|
|
3846
|
-
query: query && query.length > 0 ? query : undefined,
|
|
3847
|
-
limit: limit && limit > 0 ? Math.min(limit, 20) : undefined,
|
|
3848
|
-
};
|
|
3849
|
-
},
|
|
3850
|
-
/**
|
|
3851
|
-
* Parses store memory arguments.
|
|
3852
|
-
*/
|
|
3853
|
-
store(args) {
|
|
3854
|
-
const content = typeof args.content === 'string' ? args.content.trim() : '';
|
|
3855
|
-
if (!content) {
|
|
3856
|
-
throw new Error('Memory content is required.');
|
|
3857
|
-
}
|
|
3858
|
-
return {
|
|
3859
|
-
content,
|
|
3860
|
-
isGlobal: args.isGlobal === true,
|
|
3861
|
-
};
|
|
3862
|
-
},
|
|
3863
|
-
/**
|
|
3864
|
-
* Parses update memory arguments.
|
|
3865
|
-
*/
|
|
3866
|
-
update(args) {
|
|
3867
|
-
const memoryId = parseMemoryIdArg(args.memoryId);
|
|
3868
|
-
const content = typeof args.content === 'string' ? args.content.trim() : '';
|
|
3869
|
-
if (!content) {
|
|
3870
|
-
throw new Error('Memory content is required.');
|
|
3871
|
-
}
|
|
3872
|
-
const isGlobal = typeof args.isGlobal === 'boolean' ? args.isGlobal : undefined;
|
|
3873
|
-
return {
|
|
3874
|
-
memoryId,
|
|
3875
|
-
content,
|
|
3876
|
-
isGlobal,
|
|
3877
|
-
};
|
|
3878
|
-
},
|
|
3879
|
-
/**
|
|
3880
|
-
* Parses delete memory arguments.
|
|
3881
|
-
*/
|
|
3882
|
-
delete(args) {
|
|
3883
|
-
return {
|
|
3884
|
-
memoryId: parseMemoryIdArg(args.memoryId),
|
|
3885
|
-
};
|
|
3886
|
-
},
|
|
3887
|
-
};
|
|
3888
|
-
|
|
3889
|
-
/**
|
|
3890
|
-
* Prompt parameter key used to pass hidden runtime context to tool execution.
|
|
3891
|
-
*
|
|
3892
|
-
* @private internal runtime wiring for commitment tools
|
|
3893
|
-
*/
|
|
3894
|
-
const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
|
|
3895
|
-
/**
|
|
3896
|
-
* Hidden argument key used to pass runtime context into individual tool calls.
|
|
3897
|
-
*
|
|
3898
|
-
* @private internal runtime wiring for commitment tools
|
|
3899
|
-
*/
|
|
3900
|
-
const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
|
|
3901
|
-
/**
|
|
3902
|
-
* Prompt parameter key used to pass a hidden tool-progress listener token into script execution.
|
|
3903
|
-
*
|
|
3904
|
-
* @private internal runtime wiring for commitment tools
|
|
3905
|
-
*/
|
|
3906
|
-
const TOOL_PROGRESS_TOKEN_PARAMETER = 'promptbookToolProgressToken';
|
|
3907
|
-
/**
|
|
3908
|
-
* Hidden argument key used to pass a tool-progress listener token into individual tool calls.
|
|
3909
|
-
*
|
|
3910
|
-
* @private internal runtime wiring for commitment tools
|
|
3911
|
-
*/
|
|
3912
|
-
const TOOL_PROGRESS_TOKEN_ARGUMENT = '__promptbookToolProgressToken';
|
|
3913
|
-
/**
|
|
3914
|
-
* Monotonic counter used for hidden progress-listener tokens.
|
|
3915
|
-
*
|
|
3916
|
-
* @private internal runtime wiring for commitment tools
|
|
3917
|
-
*/
|
|
3918
|
-
let toolCallProgressListenerCounter = 0;
|
|
3919
|
-
/**
|
|
3920
|
-
* Active tool-progress listeners keyed by hidden execution token.
|
|
3921
|
-
*
|
|
3922
|
-
* @private internal runtime wiring for commitment tools
|
|
3923
|
-
*/
|
|
3924
|
-
const toolCallProgressListeners = new Map();
|
|
3925
|
-
/**
|
|
3926
|
-
* Parses unknown runtime context payload into a normalized object.
|
|
3927
|
-
*
|
|
3928
|
-
* @private internal runtime wiring for commitment tools
|
|
3929
|
-
*/
|
|
3930
|
-
function parseToolRuntimeContext(rawValue) {
|
|
3931
|
-
if (!rawValue) {
|
|
3932
|
-
return null;
|
|
3933
|
-
}
|
|
3934
|
-
let parsed = rawValue;
|
|
3935
|
-
if (typeof rawValue === 'string') {
|
|
3936
|
-
try {
|
|
3937
|
-
parsed = JSON.parse(rawValue);
|
|
3938
|
-
}
|
|
3939
|
-
catch (_a) {
|
|
3940
|
-
return null;
|
|
3941
|
-
}
|
|
3942
|
-
}
|
|
3943
|
-
if (!parsed || typeof parsed !== 'object') {
|
|
3944
|
-
return null;
|
|
3945
|
-
}
|
|
3946
|
-
return parsed;
|
|
3947
|
-
}
|
|
3948
|
-
/**
|
|
3949
|
-
* Reads runtime context attached to tool call arguments.
|
|
3950
|
-
*
|
|
3951
|
-
* @private internal runtime wiring for commitment tools
|
|
3952
|
-
*/
|
|
3953
|
-
function readToolRuntimeContextFromToolArgs(args) {
|
|
3954
|
-
return parseToolRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
|
|
3955
|
-
}
|
|
3956
|
-
/**
|
|
3957
|
-
* Serializes runtime context for prompt parameters.
|
|
3958
|
-
*
|
|
3959
|
-
* @private internal runtime wiring for commitment tools
|
|
3960
|
-
*/
|
|
3961
|
-
function serializeToolRuntimeContext(context) {
|
|
3962
|
-
return JSON.stringify(context);
|
|
3963
|
-
}
|
|
3964
|
-
/**
|
|
3965
|
-
* Registers one in-memory listener that receives progress updates emitted by a running tool.
|
|
3966
|
-
*
|
|
3967
|
-
* The returned token is passed into script execution as a hidden argument so tool implementations
|
|
3968
|
-
* can stream progress without exposing extra parameters to the model.
|
|
3969
|
-
*
|
|
3970
|
-
* @param listener - Listener notified about tool progress.
|
|
3971
|
-
* @returns Hidden token used to route progress updates.
|
|
3972
|
-
*
|
|
3973
|
-
* @private internal runtime wiring for commitment tools
|
|
3974
|
-
*/
|
|
3975
|
-
function registerToolCallProgressListener(listener) {
|
|
3976
|
-
toolCallProgressListenerCounter += 1;
|
|
3977
|
-
const token = `tool-progress:${Date.now()}:${toolCallProgressListenerCounter}`;
|
|
3978
|
-
toolCallProgressListeners.set(token, listener);
|
|
3979
|
-
return token;
|
|
3980
|
-
}
|
|
3981
|
-
/**
|
|
3982
|
-
* Unregisters one in-memory progress listener.
|
|
3983
|
-
*
|
|
3984
|
-
* @param token - Token previously created by `registerToolCallProgressListener`.
|
|
3985
|
-
*
|
|
3986
|
-
* @private internal runtime wiring for commitment tools
|
|
3987
|
-
*/
|
|
3988
|
-
function unregisterToolCallProgressListener(token) {
|
|
3989
|
-
toolCallProgressListeners.delete(token);
|
|
3990
|
-
}
|
|
3991
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3992
|
-
|
|
3993
|
-
/**
|
|
3994
|
-
* Resolves runtime context from hidden tool arguments.
|
|
3995
|
-
*
|
|
3996
|
-
* @private function of MemoryCommitmentDefinition
|
|
3997
|
-
*/
|
|
3998
|
-
function resolveMemoryRuntimeContext(args) {
|
|
3999
|
-
const runtimeContext = readToolRuntimeContextFromToolArgs(args);
|
|
4000
|
-
const memoryContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.memory;
|
|
4001
|
-
return {
|
|
4002
|
-
enabled: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.enabled) === true,
|
|
4003
|
-
userId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.userId,
|
|
4004
|
-
username: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.username,
|
|
4005
|
-
agentId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentId,
|
|
4006
|
-
agentName: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentName,
|
|
4007
|
-
isTeamConversation: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isTeamConversation) === true,
|
|
4008
|
-
isPrivateMode: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isPrivateMode) === true,
|
|
4009
|
-
};
|
|
4010
|
-
}
|
|
4011
|
-
|
|
4012
|
-
/**
|
|
4013
|
-
* Gets MEMORY tool function implementations.
|
|
4014
|
-
*
|
|
4015
|
-
* @private function of MemoryCommitmentDefinition
|
|
4016
|
-
*/
|
|
4017
|
-
function createMemoryToolFunctions() {
|
|
4018
|
-
return {
|
|
4019
|
-
async [MemoryToolNames.retrieve](args) {
|
|
4020
|
-
const runtimeContext = resolveMemoryRuntimeContext(args);
|
|
4021
|
-
const { adapter, disabledResult } = getMemoryToolRuntimeAdapterOrDisabledResult('retrieve', runtimeContext);
|
|
4022
|
-
if (!adapter || disabledResult) {
|
|
4023
|
-
return JSON.stringify(disabledResult);
|
|
4024
|
-
}
|
|
4025
|
-
const parsedArgs = parseMemoryToolArgs.retrieve(args);
|
|
4026
|
-
try {
|
|
4027
|
-
const memories = await adapter.retrieveMemories(parsedArgs, runtimeContext);
|
|
4028
|
-
const result = {
|
|
4029
|
-
action: 'retrieve',
|
|
4030
|
-
status: 'ok',
|
|
4031
|
-
query: parsedArgs.query,
|
|
4032
|
-
memories,
|
|
4033
|
-
};
|
|
4034
|
-
return JSON.stringify(result);
|
|
4035
|
-
}
|
|
4036
|
-
catch (error) {
|
|
4037
|
-
const result = {
|
|
4038
|
-
action: 'retrieve',
|
|
4039
|
-
status: 'error',
|
|
4040
|
-
query: parsedArgs.query,
|
|
4041
|
-
memories: [],
|
|
4042
|
-
message: error instanceof Error ? error.message : String(error),
|
|
4043
|
-
};
|
|
4044
|
-
return JSON.stringify(result);
|
|
4045
|
-
}
|
|
4046
|
-
},
|
|
4047
|
-
async [MemoryToolNames.store](args) {
|
|
4048
|
-
const runtimeContext = resolveMemoryRuntimeContext(args);
|
|
4049
|
-
const { adapter, disabledResult } = getMemoryToolRuntimeAdapterOrDisabledResult('store', runtimeContext);
|
|
4050
|
-
if (!adapter || disabledResult) {
|
|
4051
|
-
return JSON.stringify(disabledResult);
|
|
4052
|
-
}
|
|
4053
|
-
try {
|
|
4054
|
-
const parsedArgs = parseMemoryToolArgs.store(args);
|
|
4055
|
-
const memory = await adapter.storeMemory(parsedArgs, runtimeContext);
|
|
4056
|
-
const result = {
|
|
4057
|
-
action: 'store',
|
|
4058
|
-
status: 'stored',
|
|
4059
|
-
memory,
|
|
4060
|
-
};
|
|
4061
|
-
return JSON.stringify(result);
|
|
4062
|
-
}
|
|
4063
|
-
catch (error) {
|
|
4064
|
-
const result = {
|
|
4065
|
-
action: 'store',
|
|
4066
|
-
status: 'error',
|
|
4067
|
-
message: error instanceof Error ? error.message : String(error),
|
|
4068
|
-
};
|
|
4069
|
-
return JSON.stringify(result);
|
|
4070
|
-
}
|
|
4071
|
-
},
|
|
4072
|
-
async [MemoryToolNames.update](args) {
|
|
4073
|
-
const runtimeContext = resolveMemoryRuntimeContext(args);
|
|
4074
|
-
const { adapter, disabledResult } = getMemoryToolRuntimeAdapterOrDisabledResult('update', runtimeContext);
|
|
4075
|
-
if (!adapter || disabledResult) {
|
|
4076
|
-
return JSON.stringify(disabledResult);
|
|
4077
|
-
}
|
|
4078
|
-
try {
|
|
4079
|
-
const parsedArgs = parseMemoryToolArgs.update(args);
|
|
4080
|
-
const memory = await adapter.updateMemory(parsedArgs, runtimeContext);
|
|
4081
|
-
const result = {
|
|
4082
|
-
action: 'update',
|
|
4083
|
-
status: 'updated',
|
|
4084
|
-
memory,
|
|
4085
|
-
};
|
|
4086
|
-
return JSON.stringify(result);
|
|
4087
|
-
}
|
|
4088
|
-
catch (error) {
|
|
4089
|
-
const result = {
|
|
4090
|
-
action: 'update',
|
|
4091
|
-
status: 'error',
|
|
4092
|
-
message: error instanceof Error ? error.message : String(error),
|
|
4093
|
-
};
|
|
4094
|
-
return JSON.stringify(result);
|
|
4095
|
-
}
|
|
4096
|
-
},
|
|
4097
|
-
async [MemoryToolNames.delete](args) {
|
|
4098
|
-
const runtimeContext = resolveMemoryRuntimeContext(args);
|
|
4099
|
-
const { adapter, disabledResult } = getMemoryToolRuntimeAdapterOrDisabledResult('delete', runtimeContext);
|
|
4100
|
-
if (!adapter || disabledResult) {
|
|
4101
|
-
return JSON.stringify(disabledResult);
|
|
4102
|
-
}
|
|
4103
|
-
try {
|
|
4104
|
-
const parsedArgs = parseMemoryToolArgs.delete(args);
|
|
4105
|
-
const deleted = await adapter.deleteMemory(parsedArgs, runtimeContext);
|
|
4106
|
-
const result = {
|
|
4107
|
-
action: 'delete',
|
|
4108
|
-
status: 'deleted',
|
|
4109
|
-
memoryId: deleted.id,
|
|
4110
|
-
};
|
|
4111
|
-
return JSON.stringify(result);
|
|
4112
|
-
}
|
|
4113
|
-
catch (error) {
|
|
4114
|
-
const result = {
|
|
4115
|
-
action: 'delete',
|
|
4116
|
-
status: 'error',
|
|
4117
|
-
message: error instanceof Error ? error.message : String(error),
|
|
4118
|
-
};
|
|
4119
|
-
return JSON.stringify(result);
|
|
4120
|
-
}
|
|
4121
|
-
},
|
|
4122
|
-
};
|
|
4123
|
-
}
|
|
4124
|
-
|
|
4125
|
-
/**
|
|
4126
|
-
* Creates MEMORY tool definitions while preserving already-registered tools.
|
|
4127
|
-
*
|
|
4128
|
-
* @private function of MemoryCommitmentDefinition
|
|
4129
|
-
*/
|
|
4130
|
-
function createMemoryTools(existingTools) {
|
|
4131
|
-
const tools = [...(existingTools || [])];
|
|
4132
|
-
if (!tools.some((tool) => tool.name === MemoryToolNames.retrieve)) {
|
|
4133
|
-
tools.push({
|
|
4134
|
-
name: MemoryToolNames.retrieve,
|
|
4135
|
-
description: spaceTrim$1(`
|
|
4136
|
-
Retrieve previously stored user memories relevant to the current conversation.
|
|
4137
|
-
Use this before responding when user context can improve the answer.
|
|
4138
|
-
`),
|
|
4139
|
-
parameters: {
|
|
4140
|
-
type: 'object',
|
|
4141
|
-
properties: {
|
|
4142
|
-
query: {
|
|
4143
|
-
type: 'string',
|
|
4144
|
-
description: 'Optional query used to filter relevant memories.',
|
|
4145
|
-
},
|
|
4146
|
-
limit: {
|
|
4147
|
-
type: 'integer',
|
|
4148
|
-
description: 'Optional maximum number of memories to return (default 5, max 20).',
|
|
4149
|
-
},
|
|
4150
|
-
},
|
|
4151
|
-
},
|
|
4152
|
-
});
|
|
4153
|
-
}
|
|
4154
|
-
if (!tools.some((tool) => tool.name === MemoryToolNames.store)) {
|
|
4155
|
-
tools.push({
|
|
4156
|
-
name: MemoryToolNames.store,
|
|
4157
|
-
description: spaceTrim$1(`
|
|
4158
|
-
Store a durable user memory that should be remembered in future conversations.
|
|
4159
|
-
Store only stable and useful user-specific facts or preferences.
|
|
4160
|
-
`),
|
|
4161
|
-
parameters: {
|
|
4162
|
-
type: 'object',
|
|
4163
|
-
properties: {
|
|
4164
|
-
content: {
|
|
4165
|
-
type: 'string',
|
|
4166
|
-
description: 'Memory text to store.',
|
|
4167
|
-
},
|
|
4168
|
-
isGlobal: {
|
|
4169
|
-
type: 'boolean',
|
|
4170
|
-
description: 'Set true to make this memory global across all user agents.',
|
|
4171
|
-
},
|
|
4172
|
-
},
|
|
4173
|
-
required: ['content'],
|
|
4174
|
-
},
|
|
4175
|
-
});
|
|
4176
|
-
}
|
|
4177
|
-
if (!tools.some((tool) => tool.name === MemoryToolNames.update)) {
|
|
4178
|
-
tools.push({
|
|
4179
|
-
name: MemoryToolNames.update,
|
|
4180
|
-
description: spaceTrim$1(`
|
|
4181
|
-
Update an existing user memory after retrieving it, so the stored fact stays accurate.
|
|
4182
|
-
Always pass the memory id you retrieved along with the new content.
|
|
4183
|
-
`),
|
|
4184
|
-
parameters: {
|
|
4185
|
-
type: 'object',
|
|
4186
|
-
properties: {
|
|
4187
|
-
memoryId: {
|
|
4188
|
-
type: 'string',
|
|
4189
|
-
description: 'Unique identifier of the memory entry to update.',
|
|
4190
|
-
},
|
|
4191
|
-
content: {
|
|
4192
|
-
type: 'string',
|
|
4193
|
-
description: 'Updated memory text.',
|
|
4194
|
-
},
|
|
4195
|
-
isGlobal: {
|
|
4196
|
-
type: 'boolean',
|
|
4197
|
-
description: 'Set true to keep the fact global; omit or false to keep it agent-scoped.',
|
|
4198
|
-
},
|
|
4199
|
-
},
|
|
4200
|
-
required: ['memoryId', 'content'],
|
|
4201
|
-
},
|
|
4202
|
-
});
|
|
4203
|
-
}
|
|
4204
|
-
if (!tools.some((tool) => tool.name === MemoryToolNames.delete)) {
|
|
4205
|
-
tools.push({
|
|
4206
|
-
name: MemoryToolNames.delete,
|
|
4207
|
-
description: spaceTrim$1(`
|
|
4208
|
-
Delete a user memory that is no longer relevant. Deletions are soft so the record is hidden from future queries.
|
|
4209
|
-
`),
|
|
4210
|
-
parameters: {
|
|
4211
|
-
type: 'object',
|
|
4212
|
-
properties: {
|
|
4213
|
-
memoryId: {
|
|
4214
|
-
type: 'string',
|
|
4215
|
-
description: 'Unique identifier of the memory entry to delete.',
|
|
4216
|
-
},
|
|
4217
|
-
},
|
|
4218
|
-
required: ['memoryId'],
|
|
4219
|
-
},
|
|
4220
|
-
});
|
|
4221
|
-
}
|
|
4222
|
-
return tools;
|
|
4223
|
-
}
|
|
4224
|
-
|
|
4225
|
-
/**
|
|
4226
|
-
* Markdown documentation for MEMORY commitment.
|
|
4227
|
-
*
|
|
4228
|
-
* @private function of MemoryCommitmentDefinition
|
|
4229
|
-
*/
|
|
4230
|
-
function getMemoryCommitmentDocumentation(type) {
|
|
4231
|
-
return spaceTrim$1(`
|
|
4232
|
-
# ${type}
|
|
4233
|
-
|
|
4234
|
-
Enables persistent user memory for the current agent. The memory is stored by the runtime and can be retrieved in future conversations.
|
|
4235
|
-
|
|
4236
|
-
## Key aspects
|
|
4237
|
-
|
|
4238
|
-
- Both \`MEMORY\` and \`MEMORIES\` work identically.
|
|
4239
|
-
- Stores user-specific details through runtime tools.
|
|
4240
|
-
- Retrieves relevant memories for personalized responses.
|
|
4241
|
-
- Supports optional extra instructions in the commitment content.
|
|
4242
|
-
|
|
4243
|
-
## Examples
|
|
4244
|
-
|
|
4245
|
-
\`\`\`book
|
|
4246
|
-
Personal Assistant
|
|
4247
|
-
|
|
4248
|
-
PERSONA You are a personal productivity assistant
|
|
4249
|
-
MEMORY Remember user projects and long-term preferences.
|
|
4250
|
-
GOAL Help optimize daily productivity and workflow
|
|
4251
|
-
\`\`\`
|
|
4252
|
-
|
|
4253
|
-
\`\`\`book
|
|
4254
|
-
Learning Companion
|
|
4255
|
-
|
|
4256
|
-
PERSONA You are an educational companion for programming students
|
|
4257
|
-
MEMORY Remember only the student's learning progress and preferred study style.
|
|
4258
|
-
GOAL Provide progressive learning experiences tailored to student's pace
|
|
4259
|
-
\`\`\`
|
|
4260
|
-
|
|
4261
|
-
\`\`\`book
|
|
4262
|
-
Customer Support Agent
|
|
4263
|
-
|
|
4264
|
-
PERSONA You are a customer support representative
|
|
4265
|
-
MEMORY Remember only important support history and communication preferences.
|
|
4266
|
-
GOAL Provide personalized support based on customer history
|
|
4267
|
-
\`\`\`
|
|
4268
|
-
`);
|
|
4269
|
-
}
|
|
4270
|
-
|
|
4271
|
-
/**
|
|
4272
|
-
* Gets human-readable titles for MEMORY tool functions.
|
|
4273
|
-
*
|
|
4274
|
-
* @private function of MemoryCommitmentDefinition
|
|
4275
|
-
*/
|
|
4276
|
-
function getMemoryToolTitles() {
|
|
4277
|
-
return {
|
|
4278
|
-
[MemoryToolNames.retrieve]: 'User memory',
|
|
4279
|
-
[MemoryToolNames.store]: 'Store user memory',
|
|
4280
|
-
[MemoryToolNames.update]: 'Update user memory',
|
|
4281
|
-
[MemoryToolNames.delete]: 'Delete user memory',
|
|
4282
|
-
};
|
|
4283
|
-
}
|
|
4284
|
-
|
|
4285
|
-
/**
|
|
4286
|
-
* MEMORY commitment definition
|
|
4287
|
-
*
|
|
4288
|
-
* The MEMORY commitment is similar to KNOWLEDGE but has a focus on remembering past
|
|
4289
|
-
* interactions and user preferences. It helps the agent maintain context about the
|
|
4290
|
-
* user's history, preferences, and previous conversations.
|
|
4291
|
-
*
|
|
4292
|
-
* Example usage in agent source:
|
|
4293
|
-
*
|
|
4294
|
-
* ```book
|
|
4295
|
-
* MEMORY User prefers detailed technical explanations
|
|
4296
|
-
* MEMORY Previously worked on React projects
|
|
4297
|
-
* MEMORY Timezone: UTC-5 (Eastern Time)
|
|
4298
|
-
* ```
|
|
4299
|
-
*
|
|
4300
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
4301
|
-
*/
|
|
4302
|
-
class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
4303
|
-
constructor(type = 'MEMORY') {
|
|
4304
|
-
super(type);
|
|
4305
|
-
}
|
|
4306
|
-
get requiresContent() {
|
|
4307
|
-
return false;
|
|
4308
|
-
}
|
|
4309
|
-
/**
|
|
4310
|
-
* Short one-line description of MEMORY.
|
|
4311
|
-
*/
|
|
4312
|
-
get description() {
|
|
4313
|
-
return 'Remember past interactions and user **preferences** for personalized responses.';
|
|
4314
|
-
}
|
|
4315
|
-
/**
|
|
4316
|
-
* Icon for this commitment.
|
|
4317
|
-
*/
|
|
4318
|
-
get icon() {
|
|
4319
|
-
return '🧠';
|
|
4320
|
-
}
|
|
4321
|
-
/**
|
|
4322
|
-
* Markdown documentation for MEMORY commitment.
|
|
4323
|
-
*/
|
|
4324
|
-
get documentation() {
|
|
4325
|
-
return getMemoryCommitmentDocumentation(this.type);
|
|
4326
|
-
}
|
|
4327
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
4328
|
-
const extraInstructions = formatOptionalInstructionBlock('Memory instructions', content);
|
|
4329
|
-
const tools = createMemoryTools(requirements.tools);
|
|
4330
|
-
return this.appendToSystemMessage({
|
|
4331
|
-
...requirements,
|
|
4332
|
-
tools,
|
|
4333
|
-
_metadata: {
|
|
4334
|
-
...requirements._metadata,
|
|
4335
|
-
useMemory: content || true,
|
|
4336
|
-
},
|
|
4337
|
-
}, createMemorySystemMessage(extraInstructions));
|
|
4338
|
-
}
|
|
4339
|
-
/**
|
|
4340
|
-
* Gets human-readable titles for MEMORY tool functions.
|
|
4341
|
-
*/
|
|
4342
|
-
getToolTitles() {
|
|
4343
|
-
return getMemoryToolTitles();
|
|
4344
|
-
}
|
|
4345
|
-
/**
|
|
4346
|
-
* Gets MEMORY tool function implementations.
|
|
4347
|
-
*/
|
|
4348
|
-
getToolFunctions() {
|
|
4349
|
-
return createMemoryToolFunctions();
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4352
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4353
|
-
|
|
4354
3647
|
/**
|
|
4355
3648
|
* AGENT MESSAGE commitment definition
|
|
4356
3649
|
*
|
|
@@ -4810,161 +4103,6 @@ class MessageSuffixCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
4810
4103
|
}
|
|
4811
4104
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4812
4105
|
|
|
4813
|
-
/**
|
|
4814
|
-
* META commitment definition
|
|
4815
|
-
*
|
|
4816
|
-
* The META commitment handles all meta-information about the agent such as:
|
|
4817
|
-
* - META AVATAR / META VISUAL: Sets the agent's built-in default avatar visual
|
|
4818
|
-
* - META IMAGE: Sets the agent's avatar/profile image URL
|
|
4819
|
-
* - META LINK: Provides profile/source links for the person the agent models
|
|
4820
|
-
* - META DOMAIN: Sets the canonical custom domain/host of the agent
|
|
4821
|
-
* - META TITLE: Sets the agent's display title
|
|
4822
|
-
* - META DESCRIPTION: Sets the agent's description
|
|
4823
|
-
* - META INPUT PLACEHOLDER: Sets chat input placeholder text
|
|
4824
|
-
* - META THINKING MESSAGE: Adds custom thinking placeholder variants
|
|
4825
|
-
* - META [ANYTHING]: Any other meta information in uppercase format
|
|
4826
|
-
*
|
|
4827
|
-
* These commitments are special because they don't affect the system message,
|
|
4828
|
-
* but are handled separately in the parsing logic for profile display.
|
|
4829
|
-
*
|
|
4830
|
-
* Example usage in agent source:
|
|
4831
|
-
*
|
|
4832
|
-
* ```book
|
|
4833
|
-
* META VISUAL pixel-art
|
|
4834
|
-
* META IMAGE https://example.com/avatar.jpg
|
|
4835
|
-
* META LINK https://twitter.com/username
|
|
4836
|
-
* META DOMAIN my-agent.com
|
|
4837
|
-
* META TITLE Professional Assistant
|
|
4838
|
-
* META DESCRIPTION An AI assistant specialized in business tasks
|
|
4839
|
-
* META INPUT PLACEHOLDER Write a message...
|
|
4840
|
-
* META THINKING MESSAGE Thinking...
|
|
4841
|
-
* META AUTHOR John Doe
|
|
4842
|
-
* META VERSION 1.0
|
|
4843
|
-
* ```
|
|
4844
|
-
*
|
|
4845
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
4846
|
-
*/
|
|
4847
|
-
class MetaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
4848
|
-
constructor() {
|
|
4849
|
-
super('META');
|
|
4850
|
-
}
|
|
4851
|
-
/**
|
|
4852
|
-
* Short one-line description of META commitments.
|
|
4853
|
-
*/
|
|
4854
|
-
get description() {
|
|
4855
|
-
return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
|
|
4856
|
-
}
|
|
4857
|
-
/**
|
|
4858
|
-
* Icon for this commitment.
|
|
4859
|
-
*/
|
|
4860
|
-
get icon() {
|
|
4861
|
-
return 'ℹ️';
|
|
4862
|
-
}
|
|
4863
|
-
/**
|
|
4864
|
-
* Markdown documentation for META commitment.
|
|
4865
|
-
*/
|
|
4866
|
-
get documentation() {
|
|
4867
|
-
return spaceTrim$1(`
|
|
4868
|
-
# META
|
|
4869
|
-
|
|
4870
|
-
Sets meta-information about the agent that is used for display and attribution purposes.
|
|
4871
|
-
|
|
4872
|
-
## Supported META types
|
|
4873
|
-
|
|
4874
|
-
- **META AVATAR** / **META VISUAL** - Sets the agent's built-in default avatar visual
|
|
4875
|
-
- **META IMAGE** - Sets the agent's avatar/profile image URL
|
|
4876
|
-
- **META LINK** - Provides profile/source links for the person the agent models
|
|
4877
|
-
- **META DOMAIN** - Sets the canonical custom domain/host of the agent
|
|
4878
|
-
- **META TITLE** - Sets the agent's display title
|
|
4879
|
-
- **META DESCRIPTION** - Sets the agent's description
|
|
4880
|
-
- **META INPUT PLACEHOLDER** - Sets chat input placeholder text
|
|
4881
|
-
- **META THINKING MESSAGE** - Adds custom thinking placeholder variants
|
|
4882
|
-
- **META [ANYTHING]** - Any other meta information in uppercase format
|
|
4883
|
-
|
|
4884
|
-
## Key aspects
|
|
4885
|
-
|
|
4886
|
-
- Does not modify the agent's behavior or responses
|
|
4887
|
-
- Used for visual representation and attribution in user interfaces
|
|
4888
|
-
- Multiple META commitments of different types can be used
|
|
4889
|
-
- Multiple META LINK commitments can be used for different social profiles
|
|
4890
|
-
- Multiple META THINKING MESSAGE commitments can be used for different thinking placeholder variants
|
|
4891
|
-
- If multiple META commitments of the same type are specified, the last one takes precedence (except for LINK)
|
|
4892
|
-
|
|
4893
|
-
## Examples
|
|
4894
|
-
|
|
4895
|
-
### Basic meta information
|
|
4896
|
-
|
|
4897
|
-
\`\`\`book
|
|
4898
|
-
Professional Assistant
|
|
4899
|
-
|
|
4900
|
-
META VISUAL octopus3
|
|
4901
|
-
META IMAGE https://example.com/professional-avatar.jpg
|
|
4902
|
-
META TITLE Senior Business Consultant
|
|
4903
|
-
META DESCRIPTION Specialized in strategic planning and project management
|
|
4904
|
-
META LINK https://linkedin.com/in/professional
|
|
4905
|
-
\`\`\`
|
|
4906
|
-
|
|
4907
|
-
### Multiple links and custom meta
|
|
4908
|
-
|
|
4909
|
-
\`\`\`book
|
|
4910
|
-
Open Source Developer
|
|
4911
|
-
|
|
4912
|
-
META IMAGE /assets/dev-avatar.png
|
|
4913
|
-
META LINK https://github.com/developer
|
|
4914
|
-
META LINK https://twitter.com/devhandle
|
|
4915
|
-
META AUTHOR Jane Smith
|
|
4916
|
-
META VERSION 2.1
|
|
4917
|
-
META LICENSE MIT
|
|
4918
|
-
\`\`\`
|
|
4919
|
-
|
|
4920
|
-
### Creative assistant
|
|
4921
|
-
|
|
4922
|
-
\`\`\`book
|
|
4923
|
-
Creative Helper
|
|
4924
|
-
|
|
4925
|
-
META IMAGE https://example.com/creative-bot.jpg
|
|
4926
|
-
META TITLE Creative Writing Assistant
|
|
4927
|
-
META DESCRIPTION Helps with brainstorming, storytelling, and creative projects
|
|
4928
|
-
META INSPIRATION Books, movies, and real-world experiences
|
|
4929
|
-
\`\`\`
|
|
4930
|
-
`);
|
|
4931
|
-
}
|
|
4932
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
4933
|
-
// META commitments don't modify the system message or model requirements
|
|
4934
|
-
// They are handled separately in the parsing logic for meta information extraction
|
|
4935
|
-
// This method exists for consistency with the CommitmentDefinition interface
|
|
4936
|
-
return requirements;
|
|
4937
|
-
}
|
|
4938
|
-
/**
|
|
4939
|
-
* Extracts meta information from the content based on the meta type
|
|
4940
|
-
* This is used by the parsing logic
|
|
4941
|
-
*/
|
|
4942
|
-
extractMetaValue(metaType, content) {
|
|
4943
|
-
const trimmedContent = content.trim();
|
|
4944
|
-
return trimmedContent || null;
|
|
4945
|
-
}
|
|
4946
|
-
/**
|
|
4947
|
-
* Validates if the provided content is a valid URL (for IMAGE and LINK types)
|
|
4948
|
-
*/
|
|
4949
|
-
isValidUrl(content) {
|
|
4950
|
-
try {
|
|
4951
|
-
new URL(content.trim());
|
|
4952
|
-
return true;
|
|
4953
|
-
}
|
|
4954
|
-
catch (_a) {
|
|
4955
|
-
return false;
|
|
4956
|
-
}
|
|
4957
|
-
}
|
|
4958
|
-
/**
|
|
4959
|
-
* Checks if this is a known meta type
|
|
4960
|
-
*/
|
|
4961
|
-
isKnownMetaType(metaType) {
|
|
4962
|
-
const knownTypes = ['AVATAR', 'IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
|
|
4963
|
-
return knownTypes.includes(metaType.toUpperCase());
|
|
4964
|
-
}
|
|
4965
|
-
}
|
|
4966
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4967
|
-
|
|
4968
4106
|
/**
|
|
4969
4107
|
* Makes color transformer which darker the given color
|
|
4970
4108
|
*
|
|
@@ -11215,6 +10353,81 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11215
10353
|
}
|
|
11216
10354
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11217
10355
|
|
|
10356
|
+
/**
|
|
10357
|
+
* META DESCRIPTION commitment definition
|
|
10358
|
+
*
|
|
10359
|
+
* The META DESCRIPTION commitment sets the agent's meta description for the profile page.
|
|
10360
|
+
* This commitment is special because it doesn't affect the system message,
|
|
10361
|
+
* but is handled separately in the parsing logic.
|
|
10362
|
+
*
|
|
10363
|
+
* Example usage in agent source:
|
|
10364
|
+
*
|
|
10365
|
+
* ```book
|
|
10366
|
+
* META DESCRIPTION An AI assistant specialized in business tasks
|
|
10367
|
+
* ```
|
|
10368
|
+
*
|
|
10369
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
10370
|
+
*/
|
|
10371
|
+
class MetaDescriptionCommitmentDefinition extends BaseCommitmentDefinition {
|
|
10372
|
+
constructor() {
|
|
10373
|
+
super('META DESCRIPTION');
|
|
10374
|
+
}
|
|
10375
|
+
/**
|
|
10376
|
+
* Short one-line description of META DESCRIPTION.
|
|
10377
|
+
*/
|
|
10378
|
+
get description() {
|
|
10379
|
+
return "Set the agent's meta description.";
|
|
10380
|
+
}
|
|
10381
|
+
/**
|
|
10382
|
+
* Icon for this commitment.
|
|
10383
|
+
*/
|
|
10384
|
+
get icon() {
|
|
10385
|
+
return '📝';
|
|
10386
|
+
}
|
|
10387
|
+
/**
|
|
10388
|
+
* Markdown documentation for META DESCRIPTION commitment.
|
|
10389
|
+
*/
|
|
10390
|
+
get documentation() {
|
|
10391
|
+
return spaceTrim$1(`
|
|
10392
|
+
# META DESCRIPTION
|
|
10393
|
+
|
|
10394
|
+
Sets the agent's meta description for the profile page.
|
|
10395
|
+
|
|
10396
|
+
## Key aspects
|
|
10397
|
+
|
|
10398
|
+
- Does not modify the agent's behavior or responses.
|
|
10399
|
+
- Only one \`META DESCRIPTION\` should be used per agent.
|
|
10400
|
+
- If multiple are specified, the last one takes precedence.
|
|
10401
|
+
- Used for SEO and display in user interfaces.
|
|
10402
|
+
- If not present, the agent description falls back to \`PERSONA\` or the first few lines of the agent source.
|
|
10403
|
+
|
|
10404
|
+
## Examples
|
|
10405
|
+
|
|
10406
|
+
\`\`\`book
|
|
10407
|
+
Professional Assistant
|
|
10408
|
+
|
|
10409
|
+
META DESCRIPTION Specialized in strategic planning and project management
|
|
10410
|
+
PERSONA You are a professional business assistant
|
|
10411
|
+
WRITING RULES Maintain a formal and courteous tone
|
|
10412
|
+
\`\`\`
|
|
10413
|
+
`);
|
|
10414
|
+
}
|
|
10415
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
10416
|
+
// META DESCRIPTION doesn't modify the system message or model requirements
|
|
10417
|
+
// It's handled separately in the parsing logic
|
|
10418
|
+
return requirements;
|
|
10419
|
+
}
|
|
10420
|
+
/**
|
|
10421
|
+
* Extracts the meta description from the content
|
|
10422
|
+
* This is used by the parsing logic
|
|
10423
|
+
*/
|
|
10424
|
+
extractMetaDescription(content) {
|
|
10425
|
+
const trimmedContent = content.trim();
|
|
10426
|
+
return trimmedContent || null;
|
|
10427
|
+
}
|
|
10428
|
+
}
|
|
10429
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10430
|
+
|
|
11218
10431
|
/**
|
|
11219
10432
|
* META DOMAIN commitment definition
|
|
11220
10433
|
*
|
|
@@ -11431,6 +10644,131 @@ class MetaFontCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11431
10644
|
}
|
|
11432
10645
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11433
10646
|
|
|
10647
|
+
/**
|
|
10648
|
+
* META FULLNAME commitment definition
|
|
10649
|
+
*
|
|
10650
|
+
* The `META FULLNAME` commitment sets the full display name of the agent, which can differ
|
|
10651
|
+
* from the agent name on the first line of the agent source, for example when the agent
|
|
10652
|
+
* should be presented with academic titles.
|
|
10653
|
+
* This commitment is metadata-only and does not modify model requirements.
|
|
10654
|
+
*
|
|
10655
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
10656
|
+
*/
|
|
10657
|
+
class MetaFullnameCommitmentDefinition extends BaseCommitmentDefinition {
|
|
10658
|
+
constructor() {
|
|
10659
|
+
super('META FULLNAME');
|
|
10660
|
+
}
|
|
10661
|
+
/**
|
|
10662
|
+
* Short one-line description of META FULLNAME.
|
|
10663
|
+
*/
|
|
10664
|
+
get description() {
|
|
10665
|
+
return "Set the agent's full display name.";
|
|
10666
|
+
}
|
|
10667
|
+
/**
|
|
10668
|
+
* Icon for this commitment.
|
|
10669
|
+
*/
|
|
10670
|
+
get icon() {
|
|
10671
|
+
return '🪪';
|
|
10672
|
+
}
|
|
10673
|
+
/**
|
|
10674
|
+
* Markdown documentation for META FULLNAME commitment.
|
|
10675
|
+
*/
|
|
10676
|
+
get documentation() {
|
|
10677
|
+
return spaceTrim$1(`
|
|
10678
|
+
# META FULLNAME
|
|
10679
|
+
|
|
10680
|
+
Sets the full display name of the agent shown in profiles, chats, and exports.
|
|
10681
|
+
|
|
10682
|
+
## Key aspects
|
|
10683
|
+
|
|
10684
|
+
- Does not modify the agent's behavior or responses.
|
|
10685
|
+
- If not present, the agent name from the first line of the agent source is used.
|
|
10686
|
+
- If multiple \`META FULLNAME\` commitments are specified, the last one takes precedence.
|
|
10687
|
+
|
|
10688
|
+
## Examples
|
|
10689
|
+
|
|
10690
|
+
\`\`\`book
|
|
10691
|
+
Pavol Hejný
|
|
10692
|
+
|
|
10693
|
+
META FULLNAME Dr. Ing. Pavol Hejný, PhD.
|
|
10694
|
+
PERSONA Developer with 10 years of experience in building AI applications.
|
|
10695
|
+
\`\`\`
|
|
10696
|
+
`);
|
|
10697
|
+
}
|
|
10698
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
10699
|
+
// META FULLNAME does not modify the model requirements.
|
|
10700
|
+
// It is consumed by profile parsing.
|
|
10701
|
+
return requirements;
|
|
10702
|
+
}
|
|
10703
|
+
}
|
|
10704
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10705
|
+
|
|
10706
|
+
/**
|
|
10707
|
+
* META ID commitment definition
|
|
10708
|
+
*
|
|
10709
|
+
* The `META ID` commitment carries the permanent id of the agent when an agent source is moved
|
|
10710
|
+
* between systems. It is a low-level commitment which is normally written and stripped by the
|
|
10711
|
+
* persistence layer instead of being written by hand.
|
|
10712
|
+
* This commitment is metadata-only and does not modify model requirements.
|
|
10713
|
+
*
|
|
10714
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
10715
|
+
*/
|
|
10716
|
+
class MetaIdCommitmentDefinition extends BaseCommitmentDefinition {
|
|
10717
|
+
constructor() {
|
|
10718
|
+
super('META ID');
|
|
10719
|
+
}
|
|
10720
|
+
/**
|
|
10721
|
+
* Short one-line description of META ID.
|
|
10722
|
+
*/
|
|
10723
|
+
get description() {
|
|
10724
|
+
return "Set the agent's permanent id.";
|
|
10725
|
+
}
|
|
10726
|
+
/**
|
|
10727
|
+
* Icon for this commitment.
|
|
10728
|
+
*/
|
|
10729
|
+
get icon() {
|
|
10730
|
+
return '🔖';
|
|
10731
|
+
}
|
|
10732
|
+
/**
|
|
10733
|
+
* `META ID` is written by the persistence layer, not by agent authors.
|
|
10734
|
+
*/
|
|
10735
|
+
get isLowLevel() {
|
|
10736
|
+
return true;
|
|
10737
|
+
}
|
|
10738
|
+
/**
|
|
10739
|
+
* Markdown documentation for META ID commitment.
|
|
10740
|
+
*/
|
|
10741
|
+
get documentation() {
|
|
10742
|
+
return spaceTrim$1(`
|
|
10743
|
+
# META ID
|
|
10744
|
+
|
|
10745
|
+
Carries the permanent id of the agent inside the agent source.
|
|
10746
|
+
|
|
10747
|
+
## Key aspects
|
|
10748
|
+
|
|
10749
|
+
- Does not modify the agent's behavior or responses.
|
|
10750
|
+
- Written and stripped by the persistence layer, it should not be written by hand.
|
|
10751
|
+
- When an agent source without \`META ID\` is stored, a fresh permanent id is assigned.
|
|
10752
|
+
- If multiple \`META ID\` commitments are specified, the last one takes precedence.
|
|
10753
|
+
|
|
10754
|
+
## Examples
|
|
10755
|
+
|
|
10756
|
+
\`\`\`book
|
|
10757
|
+
My agent
|
|
10758
|
+
|
|
10759
|
+
META ID doQMRg82izNfJa
|
|
10760
|
+
PERSONA My agent is an expert in something.
|
|
10761
|
+
\`\`\`
|
|
10762
|
+
`);
|
|
10763
|
+
}
|
|
10764
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
10765
|
+
// META ID does not modify the model requirements.
|
|
10766
|
+
// It is consumed by profile parsing and agent persistence.
|
|
10767
|
+
return requirements;
|
|
10768
|
+
}
|
|
10769
|
+
}
|
|
10770
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10771
|
+
|
|
11434
10772
|
/**
|
|
11435
10773
|
* META IMAGE commitment definition
|
|
11436
10774
|
*
|
|
@@ -13214,6 +12552,110 @@ function isSameOriginAgentUrl(agentUrl, localServerUrl) {
|
|
|
13214
12552
|
}
|
|
13215
12553
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13216
12554
|
|
|
12555
|
+
/**
|
|
12556
|
+
* Prompt parameter key used to pass hidden runtime context to tool execution.
|
|
12557
|
+
*
|
|
12558
|
+
* @private internal runtime wiring for commitment tools
|
|
12559
|
+
*/
|
|
12560
|
+
const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
|
|
12561
|
+
/**
|
|
12562
|
+
* Hidden argument key used to pass runtime context into individual tool calls.
|
|
12563
|
+
*
|
|
12564
|
+
* @private internal runtime wiring for commitment tools
|
|
12565
|
+
*/
|
|
12566
|
+
const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
|
|
12567
|
+
/**
|
|
12568
|
+
* Prompt parameter key used to pass a hidden tool-progress listener token into script execution.
|
|
12569
|
+
*
|
|
12570
|
+
* @private internal runtime wiring for commitment tools
|
|
12571
|
+
*/
|
|
12572
|
+
const TOOL_PROGRESS_TOKEN_PARAMETER = 'promptbookToolProgressToken';
|
|
12573
|
+
/**
|
|
12574
|
+
* Hidden argument key used to pass a tool-progress listener token into individual tool calls.
|
|
12575
|
+
*
|
|
12576
|
+
* @private internal runtime wiring for commitment tools
|
|
12577
|
+
*/
|
|
12578
|
+
const TOOL_PROGRESS_TOKEN_ARGUMENT = '__promptbookToolProgressToken';
|
|
12579
|
+
/**
|
|
12580
|
+
* Monotonic counter used for hidden progress-listener tokens.
|
|
12581
|
+
*
|
|
12582
|
+
* @private internal runtime wiring for commitment tools
|
|
12583
|
+
*/
|
|
12584
|
+
let toolCallProgressListenerCounter = 0;
|
|
12585
|
+
/**
|
|
12586
|
+
* Active tool-progress listeners keyed by hidden execution token.
|
|
12587
|
+
*
|
|
12588
|
+
* @private internal runtime wiring for commitment tools
|
|
12589
|
+
*/
|
|
12590
|
+
const toolCallProgressListeners = new Map();
|
|
12591
|
+
/**
|
|
12592
|
+
* Parses unknown runtime context payload into a normalized object.
|
|
12593
|
+
*
|
|
12594
|
+
* @private internal runtime wiring for commitment tools
|
|
12595
|
+
*/
|
|
12596
|
+
function parseToolRuntimeContext(rawValue) {
|
|
12597
|
+
if (!rawValue) {
|
|
12598
|
+
return null;
|
|
12599
|
+
}
|
|
12600
|
+
let parsed = rawValue;
|
|
12601
|
+
if (typeof rawValue === 'string') {
|
|
12602
|
+
try {
|
|
12603
|
+
parsed = JSON.parse(rawValue);
|
|
12604
|
+
}
|
|
12605
|
+
catch (_a) {
|
|
12606
|
+
return null;
|
|
12607
|
+
}
|
|
12608
|
+
}
|
|
12609
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
12610
|
+
return null;
|
|
12611
|
+
}
|
|
12612
|
+
return parsed;
|
|
12613
|
+
}
|
|
12614
|
+
/**
|
|
12615
|
+
* Reads runtime context attached to tool call arguments.
|
|
12616
|
+
*
|
|
12617
|
+
* @private internal runtime wiring for commitment tools
|
|
12618
|
+
*/
|
|
12619
|
+
function readToolRuntimeContextFromToolArgs(args) {
|
|
12620
|
+
return parseToolRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
|
|
12621
|
+
}
|
|
12622
|
+
/**
|
|
12623
|
+
* Serializes runtime context for prompt parameters.
|
|
12624
|
+
*
|
|
12625
|
+
* @private internal runtime wiring for commitment tools
|
|
12626
|
+
*/
|
|
12627
|
+
function serializeToolRuntimeContext(context) {
|
|
12628
|
+
return JSON.stringify(context);
|
|
12629
|
+
}
|
|
12630
|
+
/**
|
|
12631
|
+
* Registers one in-memory listener that receives progress updates emitted by a running tool.
|
|
12632
|
+
*
|
|
12633
|
+
* The returned token is passed into script execution as a hidden argument so tool implementations
|
|
12634
|
+
* can stream progress without exposing extra parameters to the model.
|
|
12635
|
+
*
|
|
12636
|
+
* @param listener - Listener notified about tool progress.
|
|
12637
|
+
* @returns Hidden token used to route progress updates.
|
|
12638
|
+
*
|
|
12639
|
+
* @private internal runtime wiring for commitment tools
|
|
12640
|
+
*/
|
|
12641
|
+
function registerToolCallProgressListener(listener) {
|
|
12642
|
+
toolCallProgressListenerCounter += 1;
|
|
12643
|
+
const token = `tool-progress:${Date.now()}:${toolCallProgressListenerCounter}`;
|
|
12644
|
+
toolCallProgressListeners.set(token, listener);
|
|
12645
|
+
return token;
|
|
12646
|
+
}
|
|
12647
|
+
/**
|
|
12648
|
+
* Unregisters one in-memory progress listener.
|
|
12649
|
+
*
|
|
12650
|
+
* @param token - Token previously created by `registerToolCallProgressListener`.
|
|
12651
|
+
*
|
|
12652
|
+
* @private internal runtime wiring for commitment tools
|
|
12653
|
+
*/
|
|
12654
|
+
function unregisterToolCallProgressListener(token) {
|
|
12655
|
+
toolCallProgressListeners.delete(token);
|
|
12656
|
+
}
|
|
12657
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12658
|
+
|
|
13217
12659
|
/**
|
|
13218
12660
|
* Map of team tool functions.
|
|
13219
12661
|
*/
|
|
@@ -13801,430 +13243,23 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13801
13243
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13802
13244
|
|
|
13803
13245
|
/**
|
|
13804
|
-
*
|
|
13805
|
-
*
|
|
13806
|
-
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
13807
|
-
*/
|
|
13808
|
-
const AGGREGATED_USE_COMMITMENT_TYPES = [
|
|
13809
|
-
'USE BROWSER',
|
|
13810
|
-
'USE DEEPSEARCH',
|
|
13811
|
-
'USE SEARCH ENGINE',
|
|
13812
|
-
'USE TIME',
|
|
13813
|
-
];
|
|
13814
|
-
/**
|
|
13815
|
-
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
13816
|
-
*
|
|
13817
|
-
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
13818
|
-
*/
|
|
13819
|
-
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
13820
|
-
/**
|
|
13821
|
-
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
13822
|
-
*
|
|
13823
|
-
* @param type - Commitment type to check.
|
|
13824
|
-
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
13825
|
-
*
|
|
13826
|
-
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
13827
|
-
*/
|
|
13828
|
-
function isAggregatedUseCommitmentType(type) {
|
|
13829
|
-
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
13830
|
-
}
|
|
13831
|
-
/**
|
|
13832
|
-
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
13833
|
-
*
|
|
13834
|
-
* @param type - Aggregated `USE` commitment type.
|
|
13835
|
-
* @returns Single-line placeholder comment stored in the interim system message.
|
|
13836
|
-
*
|
|
13837
|
-
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
13838
|
-
*/
|
|
13839
|
-
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
13840
|
-
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
13841
|
-
}
|
|
13842
|
-
/**
|
|
13843
|
-
* Combines distinct additional instruction blocks in source order.
|
|
13844
|
-
*
|
|
13845
|
-
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
13846
|
-
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
13847
|
-
*
|
|
13848
|
-
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
13849
|
-
*/
|
|
13850
|
-
function combineAdditionalInstructions(additionalInstructions) {
|
|
13851
|
-
return additionalInstructions.join('\n');
|
|
13852
|
-
}
|
|
13853
|
-
/**
|
|
13854
|
-
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
13855
|
-
*
|
|
13856
|
-
* @param type - Aggregated `USE` commitment type.
|
|
13857
|
-
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
13858
|
-
* @returns Final system-message block for the commitment type.
|
|
13859
|
-
*
|
|
13860
|
-
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
13861
|
-
*/
|
|
13862
|
-
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
13863
|
-
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
13864
|
-
switch (type) {
|
|
13865
|
-
case 'USE TIME':
|
|
13866
|
-
return spaceTrim$1((block) => `
|
|
13867
|
-
## Time and date context
|
|
13868
|
-
|
|
13869
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
13870
|
-
- If you need more precise current time information, use the tool \`get_current_time\`.
|
|
13871
|
-
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
13872
|
-
`);
|
|
13873
|
-
case 'USE BROWSER':
|
|
13874
|
-
return spaceTrim$1((block) => `
|
|
13875
|
-
## Browser
|
|
13876
|
-
|
|
13877
|
-
- Use \`fetch_url_content\` to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
13878
|
-
- Use \`run_browser\` for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
13879
|
-
- When you need to know information from a specific website or document, use the tools provided.
|
|
13880
|
-
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
13881
|
-
`);
|
|
13882
|
-
case 'USE SEARCH ENGINE':
|
|
13883
|
-
return spaceTrim$1((block) => `
|
|
13884
|
-
## Web Search
|
|
13885
|
-
|
|
13886
|
-
- Use \`web_search\` to find up-to-date information or facts.
|
|
13887
|
-
- When you need to know some information from the internet, use the search tool provided.
|
|
13888
|
-
- Do not make up information when you can search for it.
|
|
13889
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
13890
|
-
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
13891
|
-
`);
|
|
13892
|
-
case 'USE DEEPSEARCH':
|
|
13893
|
-
return spaceTrim$1((block) => `
|
|
13894
|
-
## Deep Research
|
|
13895
|
-
|
|
13896
|
-
- Use \`deep_search\` for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
|
|
13897
|
-
- Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
|
|
13898
|
-
- Do not pretend you cannot research current information when this tool is available.
|
|
13899
|
-
${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
|
|
13900
|
-
`);
|
|
13901
|
-
}
|
|
13902
|
-
}
|
|
13903
|
-
/**
|
|
13904
|
-
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
13905
|
-
*
|
|
13906
|
-
* @param requirements - Current model requirements.
|
|
13907
|
-
* @param type - Aggregated `USE` commitment type being applied.
|
|
13908
|
-
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
13909
|
-
*
|
|
13910
|
-
* @private internal utility of `USE` commitments
|
|
13911
|
-
*/
|
|
13912
|
-
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
13913
|
-
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
13914
|
-
if (requirements.systemMessage.includes(placeholder)) {
|
|
13915
|
-
return requirements;
|
|
13916
|
-
}
|
|
13917
|
-
const systemMessage = requirements.systemMessage.trim()
|
|
13918
|
-
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
13919
|
-
: placeholder;
|
|
13920
|
-
return {
|
|
13921
|
-
...requirements,
|
|
13922
|
-
systemMessage,
|
|
13923
|
-
};
|
|
13924
|
-
}
|
|
13925
|
-
/**
|
|
13926
|
-
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
13927
|
-
*
|
|
13928
|
-
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
13929
|
-
*
|
|
13930
|
-
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
13931
|
-
* @param commitments - Filtered commitments in their original source order.
|
|
13932
|
-
* @returns Requirements with aggregated `USE` system-message sections.
|
|
13933
|
-
*
|
|
13934
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
13935
|
-
*/
|
|
13936
|
-
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
13937
|
-
const additionalInstructionsByType = new Map();
|
|
13938
|
-
for (const commitment of commitments) {
|
|
13939
|
-
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
13940
|
-
continue;
|
|
13941
|
-
}
|
|
13942
|
-
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
13943
|
-
if (!additionalInstructions) {
|
|
13944
|
-
additionalInstructions = [];
|
|
13945
|
-
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
13946
|
-
}
|
|
13947
|
-
const normalizedContent = spaceTrim$1(commitment.content);
|
|
13948
|
-
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
13949
|
-
additionalInstructions.push(normalizedContent);
|
|
13950
|
-
}
|
|
13951
|
-
}
|
|
13952
|
-
let systemMessage = requirements.systemMessage;
|
|
13953
|
-
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
13954
|
-
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
13955
|
-
if (!systemMessage.includes(placeholder)) {
|
|
13956
|
-
continue;
|
|
13957
|
-
}
|
|
13958
|
-
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
13959
|
-
}
|
|
13960
|
-
return {
|
|
13961
|
-
...requirements,
|
|
13962
|
-
systemMessage,
|
|
13963
|
-
};
|
|
13964
|
-
}
|
|
13965
|
-
|
|
13966
|
-
/**
|
|
13967
|
-
* Client-side safe wrapper for fetching URL content
|
|
13968
|
-
*
|
|
13969
|
-
* This function proxies requests to the Agents Server API endpoint for scraping,
|
|
13970
|
-
* making it safe to use in browser environments.
|
|
13971
|
-
*
|
|
13972
|
-
* @param url The URL to fetch and scrape
|
|
13973
|
-
* @param agentsServerUrl The base URL of the agents server (defaults to current origin)
|
|
13974
|
-
* @returns Markdown content from the URL
|
|
13975
|
-
*
|
|
13976
|
-
* @private internal utility for USE BROWSER commitment
|
|
13977
|
-
*/
|
|
13978
|
-
async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
13979
|
-
try {
|
|
13980
|
-
// Determine the agents server URL
|
|
13981
|
-
const baseUrl = agentsServerUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
13982
|
-
if (!baseUrl) {
|
|
13983
|
-
throw new Error('Agents server URL is required in non-browser environments');
|
|
13984
|
-
}
|
|
13985
|
-
// Build the API endpoint URL
|
|
13986
|
-
const apiUrl = new URL('/api/scrape', baseUrl);
|
|
13987
|
-
apiUrl.searchParams.set('url', url);
|
|
13988
|
-
// Fetch from the API endpoint
|
|
13989
|
-
const response = await fetch(apiUrl.toString());
|
|
13990
|
-
if (!response.ok) {
|
|
13991
|
-
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
13992
|
-
throw new Error(`Failed to scrape URL: ${errorData.error || response.statusText}`);
|
|
13993
|
-
}
|
|
13994
|
-
const data = await response.json();
|
|
13995
|
-
if (!data.success || !data.content) {
|
|
13996
|
-
throw new Error(`Scraping failed: ${data.error || 'No content returned'}`);
|
|
13997
|
-
}
|
|
13998
|
-
return data.content;
|
|
13999
|
-
}
|
|
14000
|
-
catch (error) {
|
|
14001
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
14002
|
-
throw new Error(`Error fetching URL content via browser: ${errorMessage}`);
|
|
14003
|
-
}
|
|
14004
|
-
}
|
|
14005
|
-
|
|
14006
|
-
/**
|
|
14007
|
-
* USE BROWSER commitment definition
|
|
14008
|
-
*
|
|
14009
|
-
* The `USE BROWSER` commitment indicates that the agent should utilize browser tools
|
|
14010
|
-
* to access and retrieve up-to-date information from the internet when necessary.
|
|
14011
|
-
*
|
|
14012
|
-
* This commitment provides two levels of browser access:
|
|
14013
|
-
* 1. One-shot URL fetching: Simple function to fetch and scrape URL content
|
|
14014
|
-
* 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
|
|
14015
|
-
*
|
|
14016
|
-
* The content following `USE BROWSER` is an arbitrary text that the agent should know
|
|
14017
|
-
* (e.g. browsing scope or preferred sources).
|
|
14018
|
-
*
|
|
14019
|
-
* Example usage in agent source:
|
|
14020
|
-
*
|
|
14021
|
-
* ```book
|
|
14022
|
-
* USE BROWSER
|
|
14023
|
-
* USE BROWSER Prefer official documentation and source websites.
|
|
14024
|
-
* ```
|
|
13246
|
+
* @@@
|
|
14025
13247
|
*
|
|
14026
|
-
* @private
|
|
13248
|
+
* @private utility for commitments
|
|
14027
13249
|
*/
|
|
14028
|
-
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
/**
|
|
14033
|
-
* The `USE BROWSER` commitment is standalone.
|
|
14034
|
-
*/
|
|
14035
|
-
get requiresContent() {
|
|
14036
|
-
return false;
|
|
14037
|
-
}
|
|
14038
|
-
/**
|
|
14039
|
-
* Short one-line description of USE BROWSER.
|
|
14040
|
-
*/
|
|
14041
|
-
get description() {
|
|
14042
|
-
return 'Enable the agent to use browser tools for accessing internet information.';
|
|
14043
|
-
}
|
|
14044
|
-
/**
|
|
14045
|
-
* Icon for this commitment.
|
|
14046
|
-
*/
|
|
14047
|
-
get icon() {
|
|
14048
|
-
return '🌐';
|
|
14049
|
-
}
|
|
14050
|
-
/**
|
|
14051
|
-
* Markdown documentation for USE BROWSER commitment.
|
|
14052
|
-
*/
|
|
14053
|
-
get documentation() {
|
|
14054
|
-
return spaceTrim$1(`
|
|
14055
|
-
# USE BROWSER
|
|
14056
|
-
|
|
14057
|
-
Enables the agent to use browser tools to access and retrieve up-to-date information from the internet.
|
|
14058
|
-
|
|
14059
|
-
## Key aspects
|
|
14060
|
-
|
|
14061
|
-
- The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
|
|
14062
|
-
- Provides two levels of browser access:
|
|
14063
|
-
1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
|
|
14064
|
-
2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
|
|
14065
|
-
- The actual browser tool usage is handled by the agent runtime
|
|
14066
|
-
- On the Agents Server, every agent browses in its own persistent isolated browser profile, so cookies and logged-in sessions survive across chats (the profile is linked from the agent wallet)
|
|
14067
|
-
- Allows the agent to fetch current information from websites and documents
|
|
14068
|
-
- Useful for research tasks, fact-checking, and accessing dynamic content
|
|
14069
|
-
- Supports various content types including HTML pages and PDF documents
|
|
14070
|
-
|
|
14071
|
-
## Examples
|
|
14072
|
-
|
|
14073
|
-
\`\`\`book
|
|
14074
|
-
Research Assistant
|
|
14075
|
-
|
|
14076
|
-
PERSONA You are a helpful research assistant specialized in finding current information
|
|
14077
|
-
USE BROWSER
|
|
14078
|
-
RULE Always cite your sources when providing information from the web
|
|
14079
|
-
\`\`\`
|
|
14080
|
-
|
|
14081
|
-
\`\`\`book
|
|
14082
|
-
News Analyst
|
|
14083
|
-
|
|
14084
|
-
PERSONA You are a news analyst who stays up-to-date with current events
|
|
14085
|
-
USE BROWSER
|
|
14086
|
-
WRITING RULES Present news in a balanced and objective manner
|
|
14087
|
-
ACTION Can search for and summarize news articles
|
|
14088
|
-
\`\`\`
|
|
14089
|
-
|
|
14090
|
-
\`\`\`book
|
|
14091
|
-
Company Lawyer
|
|
14092
|
-
|
|
14093
|
-
PERSONA You are a company lawyer providing legal advice
|
|
14094
|
-
USE BROWSER
|
|
14095
|
-
KNOWLEDGE Corporate law and legal procedures
|
|
14096
|
-
RULE Always recommend consulting with a licensed attorney for specific legal matters
|
|
14097
|
-
\`\`\`
|
|
14098
|
-
`);
|
|
14099
|
-
}
|
|
14100
|
-
/**
|
|
14101
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
14102
|
-
*/
|
|
14103
|
-
getToolTitles() {
|
|
14104
|
-
return {
|
|
14105
|
-
fetch_url_content: 'Fetch URL content',
|
|
14106
|
-
run_browser: 'Run browser',
|
|
14107
|
-
};
|
|
14108
|
-
}
|
|
14109
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
14110
|
-
// Get existing tools array or create new one
|
|
14111
|
-
const existingTools = requirements.tools || [];
|
|
14112
|
-
// Add browser tools if not already present
|
|
14113
|
-
const toolsToAdd = [];
|
|
14114
|
-
// Tool 1: One-shot URL content fetching
|
|
14115
|
-
if (!existingTools.some((tool) => tool.name === 'fetch_url_content')) {
|
|
14116
|
-
toolsToAdd.push({
|
|
14117
|
-
name: 'fetch_url_content',
|
|
14118
|
-
description: spaceTrim$1(`
|
|
14119
|
-
Fetches and scrapes the content from a URL (webpage or document).
|
|
14120
|
-
This tool retrieves the content of the specified URL and converts it to markdown format.
|
|
14121
|
-
Use this when you need to access information from a specific website or document.
|
|
14122
|
-
Supports various content types including HTML pages and PDF documents.
|
|
14123
|
-
`),
|
|
14124
|
-
parameters: {
|
|
14125
|
-
type: 'object',
|
|
14126
|
-
properties: {
|
|
14127
|
-
url: {
|
|
14128
|
-
type: 'string',
|
|
14129
|
-
description: 'The URL to fetch and scrape (e.g., "https://example.com" or "https://example.com/document.pdf")',
|
|
14130
|
-
},
|
|
14131
|
-
},
|
|
14132
|
-
required: ['url'],
|
|
14133
|
-
},
|
|
14134
|
-
});
|
|
14135
|
-
}
|
|
14136
|
-
// Tool 2: Running browser for complex page interactions
|
|
14137
|
-
if (!existingTools.some((tool) => tool.name === 'run_browser')) {
|
|
14138
|
-
toolsToAdd.push({
|
|
14139
|
-
name: 'run_browser',
|
|
14140
|
-
description: spaceTrim$1(`
|
|
14141
|
-
Launches a browser session for complex interactions.
|
|
14142
|
-
This tool is for advanced browser automation tasks like scrolling, clicking, form filling, etc.
|
|
14143
|
-
Use this when simple one-shot URL fetching is not enough.
|
|
14144
|
-
`),
|
|
14145
|
-
parameters: {
|
|
14146
|
-
type: 'object',
|
|
14147
|
-
properties: {
|
|
14148
|
-
url: {
|
|
14149
|
-
type: 'string',
|
|
14150
|
-
description: 'The initial URL to navigate to',
|
|
14151
|
-
},
|
|
14152
|
-
actions: {
|
|
14153
|
-
type: 'array',
|
|
14154
|
-
description: 'Array of actions to perform in the browser',
|
|
14155
|
-
items: {
|
|
14156
|
-
type: 'object',
|
|
14157
|
-
properties: {
|
|
14158
|
-
type: {
|
|
14159
|
-
type: 'string',
|
|
14160
|
-
enum: ['navigate', 'click', 'scroll', 'type', 'wait'],
|
|
14161
|
-
},
|
|
14162
|
-
selector: {
|
|
14163
|
-
type: 'string',
|
|
14164
|
-
description: 'CSS selector for the element (for click, type actions)',
|
|
14165
|
-
},
|
|
14166
|
-
value: {
|
|
14167
|
-
type: 'string',
|
|
14168
|
-
description: 'Value to type or navigate to',
|
|
14169
|
-
},
|
|
14170
|
-
},
|
|
14171
|
-
},
|
|
14172
|
-
},
|
|
14173
|
-
},
|
|
14174
|
-
required: ['url'],
|
|
14175
|
-
},
|
|
14176
|
-
});
|
|
14177
|
-
}
|
|
14178
|
-
const updatedTools = [...existingTools, ...toolsToAdd];
|
|
14179
|
-
return appendAggregatedUseCommitmentPlaceholder({
|
|
14180
|
-
...requirements,
|
|
14181
|
-
tools: updatedTools,
|
|
14182
|
-
_metadata: {
|
|
14183
|
-
...requirements._metadata,
|
|
14184
|
-
useBrowser: true,
|
|
14185
|
-
},
|
|
14186
|
-
}, this.type);
|
|
14187
|
-
}
|
|
14188
|
-
/**
|
|
14189
|
-
* Gets the browser tool function implementations.
|
|
14190
|
-
*
|
|
14191
|
-
* This method automatically detects the environment and uses:
|
|
14192
|
-
* - Server-side: Direct scraping via fetchUrlContent (Node.js)
|
|
14193
|
-
* - Browser: Proxy through Agents Server API via fetchUrlContentViaBrowser
|
|
14194
|
-
*/
|
|
14195
|
-
getToolFunctions() {
|
|
14196
|
-
return {
|
|
14197
|
-
/**
|
|
14198
|
-
* @@@
|
|
14199
|
-
*
|
|
14200
|
-
* Note: [🛺] This function has implementation both for browser and node, this is the proxied one for browser
|
|
14201
|
-
*/
|
|
14202
|
-
async fetch_url_content(args) {
|
|
14203
|
-
console.log('!!!! [Tool] fetch_url_content called', { args });
|
|
14204
|
-
const { url } = args;
|
|
14205
|
-
return await fetchUrlContentViaBrowser(url);
|
|
14206
|
-
},
|
|
14207
|
-
/**
|
|
14208
|
-
* @@@
|
|
14209
|
-
*/
|
|
14210
|
-
async run_browser(args) {
|
|
14211
|
-
console.log('!!!! [Tool] run_browser called', { args });
|
|
14212
|
-
const { url } = args;
|
|
14213
|
-
return spaceTrim$1(`
|
|
14214
|
-
# Running browser
|
|
14215
|
-
|
|
14216
|
-
The running browser tool is not available in this runtime.
|
|
14217
|
-
|
|
14218
|
-
This environment does not provide the server-side browser automation backend.
|
|
14219
|
-
In Agents Server Node runtime, this tool is resolved to a Playwright CLI implementation.
|
|
14220
|
-
|
|
14221
|
-
Requested URL: ${url}
|
|
14222
|
-
`);
|
|
14223
|
-
},
|
|
14224
|
-
};
|
|
13250
|
+
function formatOptionalInstructionBlock(label, content) {
|
|
13251
|
+
const trimmedContent = spaceTrim$1(content);
|
|
13252
|
+
if (!trimmedContent) {
|
|
13253
|
+
return '';
|
|
14225
13254
|
}
|
|
13255
|
+
return spaceTrim$1((block) => `
|
|
13256
|
+
- ${label}:
|
|
13257
|
+
${block(trimmedContent
|
|
13258
|
+
.split(/\r?\n/)
|
|
13259
|
+
.map((line) => `- ${line}`)
|
|
13260
|
+
.join('\n'))}
|
|
13261
|
+
`);
|
|
14226
13262
|
}
|
|
14227
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
14228
13263
|
|
|
14229
13264
|
/**
|
|
14230
13265
|
* Hostnames accepted for Google Calendar references.
|
|
@@ -14549,7 +13584,7 @@ function resolveUseCalendarToolRuntime(args) {
|
|
|
14549
13584
|
const runtimeContext = (readToolRuntimeContextFromToolArgs(args) ||
|
|
14550
13585
|
{});
|
|
14551
13586
|
const configuredCalendars = normalizeConfiguredCalendars$1((_a = runtimeContext.calendars) === null || _a === void 0 ? void 0 : _a.connections);
|
|
14552
|
-
const calendarArgument = normalizeOptionalText$
|
|
13587
|
+
const calendarArgument = normalizeOptionalText$1(args.calendarUrl);
|
|
14553
13588
|
let calendarReference = null;
|
|
14554
13589
|
if (calendarArgument) {
|
|
14555
13590
|
calendarReference = parseGoogleCalendarReference(calendarArgument);
|
|
@@ -14569,7 +13604,7 @@ function resolveUseCalendarToolRuntime(args) {
|
|
|
14569
13604
|
if (!calendarReference) {
|
|
14570
13605
|
throw new Error('Calendar is required but was not resolved.');
|
|
14571
13606
|
}
|
|
14572
|
-
const accessToken = normalizeOptionalText$
|
|
13607
|
+
const accessToken = normalizeOptionalText$1((_b = runtimeContext.calendars) === null || _b === void 0 ? void 0 : _b.googleAccessToken) || '';
|
|
14573
13608
|
if (!accessToken) {
|
|
14574
13609
|
throw new CalendarWalletCredentialRequiredError({
|
|
14575
13610
|
calendarReference,
|
|
@@ -14602,7 +13637,7 @@ function normalizeConfiguredCalendars$1(rawCalendars) {
|
|
|
14602
13637
|
continue;
|
|
14603
13638
|
}
|
|
14604
13639
|
const calendar = rawCalendar;
|
|
14605
|
-
const rawUrl = normalizeOptionalText$
|
|
13640
|
+
const rawUrl = normalizeOptionalText$1(calendar.url);
|
|
14606
13641
|
if (!rawUrl) {
|
|
14607
13642
|
continue;
|
|
14608
13643
|
}
|
|
@@ -14653,7 +13688,7 @@ function createCalendarWalletCredentialRequiredResult(error) {
|
|
|
14653
13688
|
*
|
|
14654
13689
|
* @private function of resolveUseCalendarToolRuntimeOrWalletCredentialResult
|
|
14655
13690
|
*/
|
|
14656
|
-
function normalizeOptionalText$
|
|
13691
|
+
function normalizeOptionalText$1(value) {
|
|
14657
13692
|
if (typeof value !== 'string') {
|
|
14658
13693
|
return undefined;
|
|
14659
13694
|
}
|
|
@@ -14685,13 +13720,13 @@ function createUseCalendarToolFunctions() {
|
|
|
14685
13720
|
async [UseCalendarToolNames.listEvents](args) {
|
|
14686
13721
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
14687
13722
|
const query = {};
|
|
14688
|
-
if (normalizeOptionalText
|
|
13723
|
+
if (normalizeOptionalText(args.timeMin)) {
|
|
14689
13724
|
query.timeMin = args.timeMin.trim();
|
|
14690
13725
|
}
|
|
14691
|
-
if (normalizeOptionalText
|
|
13726
|
+
if (normalizeOptionalText(args.timeMax)) {
|
|
14692
13727
|
query.timeMax = args.timeMax.trim();
|
|
14693
13728
|
}
|
|
14694
|
-
if (normalizeOptionalText
|
|
13729
|
+
if (normalizeOptionalText(args.query)) {
|
|
14695
13730
|
query.q = args.query.trim();
|
|
14696
13731
|
}
|
|
14697
13732
|
if (typeof args.maxResults === 'number' && Number.isFinite(args.maxResults) && args.maxResults > 0) {
|
|
@@ -14703,7 +13738,7 @@ function createUseCalendarToolFunctions() {
|
|
|
14703
13738
|
if (args.orderBy === 'startTime' || args.orderBy === 'updated') {
|
|
14704
13739
|
query.orderBy = args.orderBy;
|
|
14705
13740
|
}
|
|
14706
|
-
if (normalizeOptionalText
|
|
13741
|
+
if (normalizeOptionalText(args.timeZone)) {
|
|
14707
13742
|
query.timeZone = args.timeZone.trim();
|
|
14708
13743
|
}
|
|
14709
13744
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -14741,11 +13776,11 @@ function createUseCalendarToolFunctions() {
|
|
|
14741
13776
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
14742
13777
|
const requestBody = createGoogleCalendarEventPayload({
|
|
14743
13778
|
summary: normalizeRequiredText(args.summary, 'summary'),
|
|
14744
|
-
description: normalizeOptionalText
|
|
14745
|
-
location: normalizeOptionalText
|
|
13779
|
+
description: normalizeOptionalText(args.description),
|
|
13780
|
+
location: normalizeOptionalText(args.location),
|
|
14746
13781
|
start: normalizeRequiredText(args.start, 'start'),
|
|
14747
13782
|
end: normalizeRequiredText(args.end, 'end'),
|
|
14748
|
-
timeZone: normalizeOptionalText
|
|
13783
|
+
timeZone: normalizeOptionalText(args.timeZone),
|
|
14749
13784
|
attendees: normalizeAttendees(args.attendees),
|
|
14750
13785
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
14751
13786
|
});
|
|
@@ -14767,12 +13802,12 @@ function createUseCalendarToolFunctions() {
|
|
|
14767
13802
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
14768
13803
|
const eventId = normalizeRequiredText(args.eventId, 'eventId');
|
|
14769
13804
|
const requestBody = createGoogleCalendarEventPayload({
|
|
14770
|
-
summary: normalizeOptionalText
|
|
14771
|
-
description: normalizeOptionalText
|
|
14772
|
-
location: normalizeOptionalText
|
|
14773
|
-
start: normalizeOptionalText
|
|
14774
|
-
end: normalizeOptionalText
|
|
14775
|
-
timeZone: normalizeOptionalText
|
|
13805
|
+
summary: normalizeOptionalText(args.summary),
|
|
13806
|
+
description: normalizeOptionalText(args.description),
|
|
13807
|
+
location: normalizeOptionalText(args.location),
|
|
13808
|
+
start: normalizeOptionalText(args.start),
|
|
13809
|
+
end: normalizeOptionalText(args.end),
|
|
13810
|
+
timeZone: normalizeOptionalText(args.timeZone),
|
|
14776
13811
|
attendees: normalizeAttendees(args.attendees),
|
|
14777
13812
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
14778
13813
|
});
|
|
@@ -14819,7 +13854,7 @@ function createUseCalendarToolFunctions() {
|
|
|
14819
13854
|
path: `/calendars/${encodeGoogleCalendarId(calendarReference.calendarId)}/events/${encodeURIComponent(eventId)}`,
|
|
14820
13855
|
});
|
|
14821
13856
|
const existingAttendees = ((existingEvent === null || existingEvent === void 0 ? void 0 : existingEvent.attendees) || [])
|
|
14822
|
-
.map((attendee) => normalizeOptionalText
|
|
13857
|
+
.map((attendee) => normalizeOptionalText(attendee.email))
|
|
14823
13858
|
.filter((email) => Boolean(email));
|
|
14824
13859
|
const mergedAttendees = [...new Set([...existingAttendees, ...guests])];
|
|
14825
13860
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -14867,7 +13902,7 @@ function encodeGoogleCalendarId(calendarId) {
|
|
|
14867
13902
|
* @private function of createUseCalendarToolFunctions
|
|
14868
13903
|
*/
|
|
14869
13904
|
function normalizeRequiredText(value, fieldName) {
|
|
14870
|
-
const normalizedValue = normalizeOptionalText
|
|
13905
|
+
const normalizedValue = normalizeOptionalText(value);
|
|
14871
13906
|
if (!normalizedValue) {
|
|
14872
13907
|
throw new Error(`Tool "${fieldName}" requires non-empty value.`);
|
|
14873
13908
|
}
|
|
@@ -14878,7 +13913,7 @@ function normalizeRequiredText(value, fieldName) {
|
|
|
14878
13913
|
*
|
|
14879
13914
|
* @private function of createUseCalendarToolFunctions
|
|
14880
13915
|
*/
|
|
14881
|
-
function normalizeOptionalText
|
|
13916
|
+
function normalizeOptionalText(value) {
|
|
14882
13917
|
if (typeof value !== 'string') {
|
|
14883
13918
|
return undefined;
|
|
14884
13919
|
}
|
|
@@ -15452,484 +14487,6 @@ function addConfiguredCalendarIfMissing(configuredCalendars, calendarReference)
|
|
|
15452
14487
|
}
|
|
15453
14488
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15454
14489
|
|
|
15455
|
-
/**
|
|
15456
|
-
* A search engine implementation that uses the SerpApi to fetch Google search results.
|
|
15457
|
-
*
|
|
15458
|
-
* @private <- TODO: !!!! Export via some package
|
|
15459
|
-
*/
|
|
15460
|
-
class SerpSearchEngine {
|
|
15461
|
-
get title() {
|
|
15462
|
-
return 'SerpApi Search Engine';
|
|
15463
|
-
}
|
|
15464
|
-
get description() {
|
|
15465
|
-
return 'Search engine that uses SerpApi to fetch Google search results';
|
|
15466
|
-
}
|
|
15467
|
-
checkConfiguration() {
|
|
15468
|
-
if (!process.env.SERP_API_KEY) {
|
|
15469
|
-
throw new Error('SERP_API_KEY is not configured');
|
|
15470
|
-
}
|
|
15471
|
-
}
|
|
15472
|
-
async search(query, options = {}) {
|
|
15473
|
-
const apiKey = process.env.SERP_API_KEY;
|
|
15474
|
-
if (!apiKey) {
|
|
15475
|
-
throw new Error('SERP_API_KEY is not configured');
|
|
15476
|
-
}
|
|
15477
|
-
const url = new URL('https://serpapi.com/search');
|
|
15478
|
-
url.searchParams.set('api_key', apiKey);
|
|
15479
|
-
url.searchParams.set('engine', 'google');
|
|
15480
|
-
url.searchParams.set('q', query);
|
|
15481
|
-
for (const [key, value] of Object.entries(options)) {
|
|
15482
|
-
url.searchParams.set(key, String(value));
|
|
15483
|
-
}
|
|
15484
|
-
const response = await fetch(url.toString());
|
|
15485
|
-
if (!response.ok) {
|
|
15486
|
-
const body = await response.text();
|
|
15487
|
-
throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
|
|
15488
|
-
}
|
|
15489
|
-
const data = (await response.json());
|
|
15490
|
-
return (data.organic_results || []).map((item) => ({
|
|
15491
|
-
title: item.title,
|
|
15492
|
-
url: item.link,
|
|
15493
|
-
snippet: item.snippet || '',
|
|
15494
|
-
}));
|
|
15495
|
-
}
|
|
15496
|
-
}
|
|
15497
|
-
|
|
15498
|
-
/**
|
|
15499
|
-
* Creates one SERP-backed tool function used as a local fallback for search-like commitments.
|
|
15500
|
-
*
|
|
15501
|
-
* @param toolName - Technical tool name used for validation messages.
|
|
15502
|
-
* @param resultLabel - Human-readable label used in formatted results.
|
|
15503
|
-
* @returns Async tool function compatible with commitment tool registration.
|
|
15504
|
-
*
|
|
15505
|
-
* @private internal helper for search-like commitments
|
|
15506
|
-
*/
|
|
15507
|
-
function createSerpSearchToolFunction(toolName, resultLabel) {
|
|
15508
|
-
return async (rawArgs) => {
|
|
15509
|
-
const { query, ...searchOptions } = rawArgs;
|
|
15510
|
-
if (typeof query !== 'string' || !query.trim()) {
|
|
15511
|
-
throw new Error(`${toolName} query is required`);
|
|
15512
|
-
}
|
|
15513
|
-
const searchEngine = new SerpSearchEngine();
|
|
15514
|
-
const results = await searchEngine.search(query, searchOptions);
|
|
15515
|
-
return spaceTrim$1((block) => `
|
|
15516
|
-
${resultLabel} results for "${query}"${Object.keys(searchOptions).length === 0 ? '' : ` with options ${JSON.stringify(searchOptions)}`}:
|
|
15517
|
-
|
|
15518
|
-
${block(results
|
|
15519
|
-
.map((result) => spaceTrim$1(`
|
|
15520
|
-
- **${result.title}**
|
|
15521
|
-
${result.url}
|
|
15522
|
-
${result.snippet}
|
|
15523
|
-
`))
|
|
15524
|
-
.join('\n\n'))}
|
|
15525
|
-
`);
|
|
15526
|
-
};
|
|
15527
|
-
}
|
|
15528
|
-
|
|
15529
|
-
/**
|
|
15530
|
-
* USE DEEPSEARCH commitment definition
|
|
15531
|
-
*
|
|
15532
|
-
* The `USE DEEPSEARCH` commitment indicates that the agent should use a deeper research-oriented
|
|
15533
|
-
* search workflow instead of lightweight web search when it needs fresh information from the internet.
|
|
15534
|
-
*
|
|
15535
|
-
* The content following `USE DEEPSEARCH` is an arbitrary text that the agent should know
|
|
15536
|
-
* (e.g. search scope or research instructions).
|
|
15537
|
-
*
|
|
15538
|
-
* Example usage in agent source:
|
|
15539
|
-
*
|
|
15540
|
-
* ```book
|
|
15541
|
-
* USE DEEPSEARCH
|
|
15542
|
-
* USE DEEPSEARCH Compare official vendor documentation with independent benchmarks.
|
|
15543
|
-
* ```
|
|
15544
|
-
*
|
|
15545
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
15546
|
-
*/
|
|
15547
|
-
class UseDeepSearchCommitmentDefinition extends BaseCommitmentDefinition {
|
|
15548
|
-
constructor() {
|
|
15549
|
-
super('USE DEEPSEARCH');
|
|
15550
|
-
}
|
|
15551
|
-
get requiresContent() {
|
|
15552
|
-
return false;
|
|
15553
|
-
}
|
|
15554
|
-
/**
|
|
15555
|
-
* Short one-line description of USE DEEPSEARCH.
|
|
15556
|
-
*/
|
|
15557
|
-
get description() {
|
|
15558
|
-
return 'Enable the agent to use DeepSearch for more thorough internet research.';
|
|
15559
|
-
}
|
|
15560
|
-
/**
|
|
15561
|
-
* Icon for this commitment.
|
|
15562
|
-
*/
|
|
15563
|
-
get icon() {
|
|
15564
|
-
return '🔬';
|
|
15565
|
-
}
|
|
15566
|
-
/**
|
|
15567
|
-
* Markdown documentation for USE DEEPSEARCH commitment.
|
|
15568
|
-
*/
|
|
15569
|
-
get documentation() {
|
|
15570
|
-
return spaceTrim$1(`
|
|
15571
|
-
# USE DEEPSEARCH
|
|
15572
|
-
|
|
15573
|
-
Enables the agent to use DeepSearch for broader, more thorough internet research than lightweight web search.
|
|
15574
|
-
|
|
15575
|
-
## Key aspects
|
|
15576
|
-
|
|
15577
|
-
- The content following \`USE DEEPSEARCH\` is arbitrary guidance for the research workflow.
|
|
15578
|
-
- In Agents Server, the OpenAI Agents SDK runtime uses a nested deep-research agent for this tool.
|
|
15579
|
-
- Use this for investigations, comparisons, market scans, or other tasks that benefit from deeper synthesis.
|
|
15580
|
-
- Prefer regular \`USE SEARCH ENGINE\` when a quick factual lookup is enough.
|
|
15581
|
-
|
|
15582
|
-
## Examples
|
|
15583
|
-
|
|
15584
|
-
\`\`\`book
|
|
15585
|
-
Due Diligence Researcher
|
|
15586
|
-
|
|
15587
|
-
GOAL Investigate vendors thoroughly before making recommendations.
|
|
15588
|
-
USE DEEPSEARCH Compare official sources with credible third-party analysis.
|
|
15589
|
-
RULE Cite the strongest supporting sources in the final answer.
|
|
15590
|
-
\`\`\`
|
|
15591
|
-
|
|
15592
|
-
\`\`\`book
|
|
15593
|
-
Market Analyst
|
|
15594
|
-
|
|
15595
|
-
GOAL Build concise but well-grounded research briefs.
|
|
15596
|
-
USE DEEPSEARCH Focus on recent public information and competing viewpoints.
|
|
15597
|
-
CLOSED
|
|
15598
|
-
\`\`\`
|
|
15599
|
-
`);
|
|
15600
|
-
}
|
|
15601
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
15602
|
-
const existingTools = requirements.tools || [];
|
|
15603
|
-
const updatedTools = existingTools.some((tool) => tool.name === 'deep_search')
|
|
15604
|
-
? existingTools
|
|
15605
|
-
: [
|
|
15606
|
-
...existingTools,
|
|
15607
|
-
{
|
|
15608
|
-
name: 'deep_search',
|
|
15609
|
-
description: spaceTrim$1(`
|
|
15610
|
-
Research the internet deeply and synthesize a grounded answer.
|
|
15611
|
-
Use this tool for broader investigations, comparisons, and requests that need more than a quick search.
|
|
15612
|
-
`),
|
|
15613
|
-
parameters: {
|
|
15614
|
-
type: 'object',
|
|
15615
|
-
properties: {
|
|
15616
|
-
query: {
|
|
15617
|
-
type: 'string',
|
|
15618
|
-
description: 'The research question or investigation request.',
|
|
15619
|
-
},
|
|
15620
|
-
},
|
|
15621
|
-
required: ['query'],
|
|
15622
|
-
additionalProperties: false,
|
|
15623
|
-
},
|
|
15624
|
-
},
|
|
15625
|
-
];
|
|
15626
|
-
return appendAggregatedUseCommitmentPlaceholder({
|
|
15627
|
-
...requirements,
|
|
15628
|
-
tools: updatedTools,
|
|
15629
|
-
_metadata: {
|
|
15630
|
-
...requirements._metadata,
|
|
15631
|
-
useDeepSearch: content || true,
|
|
15632
|
-
},
|
|
15633
|
-
}, this.type);
|
|
15634
|
-
}
|
|
15635
|
-
/**
|
|
15636
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
15637
|
-
*/
|
|
15638
|
-
getToolTitles() {
|
|
15639
|
-
return {
|
|
15640
|
-
deep_search: 'DeepSearch',
|
|
15641
|
-
};
|
|
15642
|
-
}
|
|
15643
|
-
/**
|
|
15644
|
-
* Gets the local fallback implementation for the `deep_search` tool.
|
|
15645
|
-
*/
|
|
15646
|
-
getToolFunctions() {
|
|
15647
|
-
return {
|
|
15648
|
-
deep_search: createSerpSearchToolFunction('deep_search', 'DeepSearch'),
|
|
15649
|
-
};
|
|
15650
|
-
}
|
|
15651
|
-
}
|
|
15652
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15653
|
-
|
|
15654
|
-
/**
|
|
15655
|
-
* Checks if value is valid email
|
|
15656
|
-
*
|
|
15657
|
-
* @public exported from `@promptbook/utils`
|
|
15658
|
-
*/
|
|
15659
|
-
function isValidEmail(email) {
|
|
15660
|
-
if (typeof email !== 'string') {
|
|
15661
|
-
return false;
|
|
15662
|
-
}
|
|
15663
|
-
if (email.split(/\r?\n/).length > 1) {
|
|
15664
|
-
return false;
|
|
15665
|
-
}
|
|
15666
|
-
return /^.+@.+\..+$/.test(email);
|
|
15667
|
-
}
|
|
15668
|
-
|
|
15669
|
-
/**
|
|
15670
|
-
* Lightweight email token matcher used for `USE EMAIL` first-line parsing.
|
|
15671
|
-
*
|
|
15672
|
-
* @private internal USE EMAIL constant
|
|
15673
|
-
*/
|
|
15674
|
-
const EMAIL_TOKEN_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/;
|
|
15675
|
-
/**
|
|
15676
|
-
* Parses `USE EMAIL` commitment content into optional sender email + additional instructions.
|
|
15677
|
-
*
|
|
15678
|
-
* Examples:
|
|
15679
|
-
* - `agent@example.com`
|
|
15680
|
-
* - `agent@example.com Keep emails concise`
|
|
15681
|
-
* - `Keep emails concise`
|
|
15682
|
-
*
|
|
15683
|
-
* @private internal utility of USE EMAIL commitment
|
|
15684
|
-
*/
|
|
15685
|
-
function parseUseEmailCommitmentContent(content) {
|
|
15686
|
-
const trimmedContent = spaceTrim$1(content);
|
|
15687
|
-
if (!trimmedContent) {
|
|
15688
|
-
return {
|
|
15689
|
-
senderEmail: null,
|
|
15690
|
-
senderEmailRaw: null,
|
|
15691
|
-
instructions: '',
|
|
15692
|
-
};
|
|
15693
|
-
}
|
|
15694
|
-
const lines = trimmedContent
|
|
15695
|
-
.split(/\r?\n/)
|
|
15696
|
-
.map((line) => line.trim())
|
|
15697
|
-
.filter(Boolean);
|
|
15698
|
-
if (lines.length === 0) {
|
|
15699
|
-
return {
|
|
15700
|
-
senderEmail: null,
|
|
15701
|
-
senderEmailRaw: null,
|
|
15702
|
-
instructions: '',
|
|
15703
|
-
};
|
|
15704
|
-
}
|
|
15705
|
-
const firstLine = lines[0] || '';
|
|
15706
|
-
const senderMatch = firstLine.match(EMAIL_TOKEN_PATTERN);
|
|
15707
|
-
const senderEmailRaw = (senderMatch === null || senderMatch === void 0 ? void 0 : senderMatch[0]) || null;
|
|
15708
|
-
const senderEmail = senderEmailRaw && isValidEmail(senderEmailRaw) ? senderEmailRaw : null;
|
|
15709
|
-
let firstLineWithoutSender = firstLine;
|
|
15710
|
-
if (senderEmailRaw) {
|
|
15711
|
-
const matchIndex = firstLine.indexOf(senderEmailRaw);
|
|
15712
|
-
const prefix = firstLine.slice(0, matchIndex).trim();
|
|
15713
|
-
const suffix = firstLine.slice(matchIndex + senderEmailRaw.length).trim();
|
|
15714
|
-
firstLineWithoutSender = [prefix, suffix].filter(Boolean).join(' ').trim();
|
|
15715
|
-
}
|
|
15716
|
-
const instructionLines = [firstLineWithoutSender, ...lines.slice(1)].filter(Boolean);
|
|
15717
|
-
const instructions = instructionLines.join('\n').trim();
|
|
15718
|
-
return {
|
|
15719
|
-
senderEmail,
|
|
15720
|
-
senderEmailRaw,
|
|
15721
|
-
instructions,
|
|
15722
|
-
};
|
|
15723
|
-
}
|
|
15724
|
-
|
|
15725
|
-
/**
|
|
15726
|
-
* Client-side safe wrapper for sending emails.
|
|
15727
|
-
*
|
|
15728
|
-
* This function proxies requests to the Agents Server API endpoint for email queuing,
|
|
15729
|
-
* making it safe to use in browser environments.
|
|
15730
|
-
*
|
|
15731
|
-
* @param args Email payload forwarded to the server-side `send_email` tool
|
|
15732
|
-
* @param agentsServerUrl The base URL of the agents server (defaults to current origin)
|
|
15733
|
-
* @returns Result string from the server-side send_email tool
|
|
15734
|
-
*
|
|
15735
|
-
* @private internal utility for USE EMAIL commitment
|
|
15736
|
-
*/
|
|
15737
|
-
async function sendEmailViaBrowser(args, agentsServerUrl) {
|
|
15738
|
-
try {
|
|
15739
|
-
const baseUrl = agentsServerUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
15740
|
-
if (!baseUrl) {
|
|
15741
|
-
throw new Error('Agents server URL is required in non-browser environments');
|
|
15742
|
-
}
|
|
15743
|
-
const apiUrl = new URL('/api/send-email', baseUrl);
|
|
15744
|
-
const response = await fetch(apiUrl.toString(), {
|
|
15745
|
-
method: 'POST',
|
|
15746
|
-
headers: {
|
|
15747
|
-
'Content-Type': 'application/json',
|
|
15748
|
-
},
|
|
15749
|
-
body: JSON.stringify(args),
|
|
15750
|
-
});
|
|
15751
|
-
if (!response.ok) {
|
|
15752
|
-
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
15753
|
-
throw new Error(`Failed to send email: ${errorData.error || response.statusText}`);
|
|
15754
|
-
}
|
|
15755
|
-
const data = await response.json();
|
|
15756
|
-
if (!data.success) {
|
|
15757
|
-
throw new Error(`Email sending failed: ${data.error || 'Unknown error'}`);
|
|
15758
|
-
}
|
|
15759
|
-
return typeof data.result === 'string' ? data.result : JSON.stringify(data.result);
|
|
15760
|
-
}
|
|
15761
|
-
catch (error) {
|
|
15762
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
15763
|
-
throw new Error(`Error sending email via browser: ${errorMessage}`);
|
|
15764
|
-
}
|
|
15765
|
-
}
|
|
15766
|
-
|
|
15767
|
-
/**
|
|
15768
|
-
* Tool name used by USE EMAIL.
|
|
15769
|
-
*
|
|
15770
|
-
* @private internal USE EMAIL constant
|
|
15771
|
-
*/
|
|
15772
|
-
const SEND_EMAIL_TOOL_NAME = 'send_email';
|
|
15773
|
-
/**
|
|
15774
|
-
* USE EMAIL commitment definition.
|
|
15775
|
-
*
|
|
15776
|
-
* The `USE EMAIL` commitment enables outbound email sending through the `send_email` tool.
|
|
15777
|
-
*
|
|
15778
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
15779
|
-
*/
|
|
15780
|
-
class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
15781
|
-
constructor() {
|
|
15782
|
-
super('USE EMAIL', ['EMAIL', 'MAIL']);
|
|
15783
|
-
}
|
|
15784
|
-
get requiresContent() {
|
|
15785
|
-
return false;
|
|
15786
|
-
}
|
|
15787
|
-
/**
|
|
15788
|
-
* Short one-line description of USE EMAIL.
|
|
15789
|
-
*/
|
|
15790
|
-
get description() {
|
|
15791
|
-
return 'Enable outbound email sending through a wallet-backed SMTP configuration.';
|
|
15792
|
-
}
|
|
15793
|
-
/**
|
|
15794
|
-
* Icon for this commitment.
|
|
15795
|
-
*/
|
|
15796
|
-
get icon() {
|
|
15797
|
-
return '📧';
|
|
15798
|
-
}
|
|
15799
|
-
/**
|
|
15800
|
-
* Markdown documentation for USE EMAIL commitment.
|
|
15801
|
-
*/
|
|
15802
|
-
get documentation() {
|
|
15803
|
-
return spaceTrim$1(`
|
|
15804
|
-
# USE EMAIL
|
|
15805
|
-
|
|
15806
|
-
Enables the agent to send outbound emails through SMTP.
|
|
15807
|
-
|
|
15808
|
-
## Key aspects
|
|
15809
|
-
|
|
15810
|
-
- The agent sends email via the \`send_email\` tool.
|
|
15811
|
-
- SMTP credentials are expected from wallet records (\`ACCESS_TOKEN\`, service \`smtp\`, key \`use-email-smtp-credentials\`).
|
|
15812
|
-
- Commitment content can optionally begin with a default sender email address:
|
|
15813
|
-
- \`USE EMAIL agent@example.com\`
|
|
15814
|
-
- Remaining commitment content is treated as optional email-writing instructions.
|
|
15815
|
-
|
|
15816
|
-
## Examples
|
|
15817
|
-
|
|
15818
|
-
\`\`\`book
|
|
15819
|
-
Writing Agent
|
|
15820
|
-
USE EMAIL agent@example.com
|
|
15821
|
-
RULE Write emails to customers according to the instructions from user.
|
|
15822
|
-
\`\`\`
|
|
15823
|
-
|
|
15824
|
-
\`\`\`book
|
|
15825
|
-
Formal Email Assistant
|
|
15826
|
-
USE EMAIL agent@example.com Keep emails concise and formal.
|
|
15827
|
-
\`\`\`
|
|
15828
|
-
`);
|
|
15829
|
-
}
|
|
15830
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
15831
|
-
var _a;
|
|
15832
|
-
const parsedCommitment = parseUseEmailCommitmentContent(content);
|
|
15833
|
-
const updatedTools = addUseEmailTools(requirements.tools || []);
|
|
15834
|
-
// Collect all configured sender emails across multiple USE EMAIL commitments
|
|
15835
|
-
const existingSenders = Array.isArray((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useEmailSenders)
|
|
15836
|
-
? [...requirements._metadata.useEmailSenders]
|
|
15837
|
-
: [];
|
|
15838
|
-
if (parsedCommitment.senderEmail && !existingSenders.includes(parsedCommitment.senderEmail)) {
|
|
15839
|
-
existingSenders.push(parsedCommitment.senderEmail);
|
|
15840
|
-
}
|
|
15841
|
-
const senderBullets = existingSenders.length > 0
|
|
15842
|
-
? existingSenders
|
|
15843
|
-
.map((email, index) => index === 0
|
|
15844
|
-
? `- Default sender address: "${email}".`
|
|
15845
|
-
: `- Additional sender address: "${email}".`)
|
|
15846
|
-
.join('\n')
|
|
15847
|
-
: '';
|
|
15848
|
-
const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
|
|
15849
|
-
const emailSectionContent = spaceTrim$1((block) => `
|
|
15850
|
-
## Emails
|
|
15851
|
-
|
|
15852
|
-
- Use \`${SEND_EMAIL_TOOL_NAME}\` to send outbound emails.
|
|
15853
|
-
${block(senderBullets)}
|
|
15854
|
-
${block(extraInstructions)}
|
|
15855
|
-
`);
|
|
15856
|
-
return this.replaceOrCreateSection({
|
|
15857
|
-
...requirements,
|
|
15858
|
-
tools: updatedTools,
|
|
15859
|
-
_metadata: {
|
|
15860
|
-
...requirements._metadata,
|
|
15861
|
-
useEmail: true,
|
|
15862
|
-
...(parsedCommitment.senderEmail ? { useEmailSender: parsedCommitment.senderEmail } : {}),
|
|
15863
|
-
useEmailSenders: existingSenders,
|
|
15864
|
-
},
|
|
15865
|
-
}, 'Emails', emailSectionContent);
|
|
15866
|
-
}
|
|
15867
|
-
/**
|
|
15868
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
15869
|
-
*/
|
|
15870
|
-
getToolTitles() {
|
|
15871
|
-
return {
|
|
15872
|
-
[SEND_EMAIL_TOOL_NAME]: 'Send email',
|
|
15873
|
-
};
|
|
15874
|
-
}
|
|
15875
|
-
/**
|
|
15876
|
-
* Gets the browser-safe `send_email` implementation.
|
|
15877
|
-
*
|
|
15878
|
-
* Node.js runtime overrides this via `getAllCommitmentsToolFunctionsForNode`.
|
|
15879
|
-
*/
|
|
15880
|
-
getToolFunctions() {
|
|
15881
|
-
return {
|
|
15882
|
-
async [SEND_EMAIL_TOOL_NAME](args) {
|
|
15883
|
-
return sendEmailViaBrowser(args);
|
|
15884
|
-
},
|
|
15885
|
-
};
|
|
15886
|
-
}
|
|
15887
|
-
}
|
|
15888
|
-
/**
|
|
15889
|
-
* Adds USE EMAIL tool definition while keeping already registered tools untouched.
|
|
15890
|
-
*
|
|
15891
|
-
* @private utility of USE EMAIL commitment
|
|
15892
|
-
*/
|
|
15893
|
-
function addUseEmailTools(existingTools) {
|
|
15894
|
-
if (existingTools.some((tool) => tool.name === SEND_EMAIL_TOOL_NAME)) {
|
|
15895
|
-
return [...existingTools];
|
|
15896
|
-
}
|
|
15897
|
-
return [
|
|
15898
|
-
...existingTools,
|
|
15899
|
-
{
|
|
15900
|
-
name: SEND_EMAIL_TOOL_NAME,
|
|
15901
|
-
description: 'Send an outbound email.',
|
|
15902
|
-
parameters: {
|
|
15903
|
-
type: 'object',
|
|
15904
|
-
properties: {
|
|
15905
|
-
message: {
|
|
15906
|
-
type: 'object',
|
|
15907
|
-
description: 'Email payload. Use metadata.subject for the subject line.',
|
|
15908
|
-
},
|
|
15909
|
-
to: {
|
|
15910
|
-
type: 'string',
|
|
15911
|
-
description: 'Legacy alias for recipients (use comma-separated emails or JSON array encoded as string).',
|
|
15912
|
-
},
|
|
15913
|
-
cc: {
|
|
15914
|
-
type: 'string',
|
|
15915
|
-
description: 'Optional CC recipients (use comma-separated emails or JSON array encoded as string).',
|
|
15916
|
-
},
|
|
15917
|
-
subject: {
|
|
15918
|
-
type: 'string',
|
|
15919
|
-
description: 'Legacy alias for subject.',
|
|
15920
|
-
},
|
|
15921
|
-
body: {
|
|
15922
|
-
type: 'string',
|
|
15923
|
-
description: 'Legacy alias for markdown body content.',
|
|
15924
|
-
},
|
|
15925
|
-
},
|
|
15926
|
-
required: [],
|
|
15927
|
-
},
|
|
15928
|
-
},
|
|
15929
|
-
];
|
|
15930
|
-
}
|
|
15931
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15932
|
-
|
|
15933
14490
|
/**
|
|
15934
14491
|
* USE IMAGE GENERATOR commitment definition
|
|
15935
14492
|
*
|
|
@@ -18158,1503 +16715,6 @@ function addConfiguredProjectIfMissing(configuredProjects, repositoryReference)
|
|
|
18158
16715
|
}
|
|
18159
16716
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18160
16717
|
|
|
18161
|
-
/**
|
|
18162
|
-
* USE SEARCH ENGINE commitment definition
|
|
18163
|
-
*
|
|
18164
|
-
* The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
|
|
18165
|
-
* to access and retrieve up-to-date information from the internet when necessary.
|
|
18166
|
-
*
|
|
18167
|
-
* The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
|
|
18168
|
-
*
|
|
18169
|
-
* Example usage in agent source:
|
|
18170
|
-
*
|
|
18171
|
-
* ```book
|
|
18172
|
-
* USE SEARCH ENGINE
|
|
18173
|
-
* USE SEARCH ENGINE Hledej informace o Přemyslovcích
|
|
18174
|
-
* ```
|
|
18175
|
-
*
|
|
18176
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
18177
|
-
*/
|
|
18178
|
-
class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
18179
|
-
constructor() {
|
|
18180
|
-
super('USE SEARCH ENGINE', ['USE SEARCH']);
|
|
18181
|
-
}
|
|
18182
|
-
get requiresContent() {
|
|
18183
|
-
return false;
|
|
18184
|
-
}
|
|
18185
|
-
/**
|
|
18186
|
-
* Short one-line description of USE SEARCH ENGINE.
|
|
18187
|
-
*/
|
|
18188
|
-
get description() {
|
|
18189
|
-
return 'Enable the agent to use a search engine tool for accessing internet information.';
|
|
18190
|
-
}
|
|
18191
|
-
/**
|
|
18192
|
-
* Icon for this commitment.
|
|
18193
|
-
*/
|
|
18194
|
-
get icon() {
|
|
18195
|
-
return '🔍';
|
|
18196
|
-
}
|
|
18197
|
-
/**
|
|
18198
|
-
* Markdown documentation for USE SEARCH ENGINE commitment.
|
|
18199
|
-
*/
|
|
18200
|
-
get documentation() {
|
|
18201
|
-
return spaceTrim$1(`
|
|
18202
|
-
# USE SEARCH ENGINE
|
|
18203
|
-
|
|
18204
|
-
Enables the agent to use a search engine tool to access and retrieve up-to-date information from the internet.
|
|
18205
|
-
|
|
18206
|
-
## Key aspects
|
|
18207
|
-
|
|
18208
|
-
- The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
|
|
18209
|
-
- The actual search engine tool usage is handled by the agent runtime
|
|
18210
|
-
- Allows the agent to search for current information from the web
|
|
18211
|
-
- Useful for research tasks, finding facts, and accessing dynamic content
|
|
18212
|
-
|
|
18213
|
-
## Examples
|
|
18214
|
-
|
|
18215
|
-
\`\`\`book
|
|
18216
|
-
Research Assistant
|
|
18217
|
-
|
|
18218
|
-
PERSONA You are a helpful research assistant specialized in finding current information
|
|
18219
|
-
USE SEARCH ENGINE
|
|
18220
|
-
RULE Always cite your sources when providing information from the web
|
|
18221
|
-
\`\`\`
|
|
18222
|
-
|
|
18223
|
-
\`\`\`book
|
|
18224
|
-
Fact Checker
|
|
18225
|
-
|
|
18226
|
-
PERSONA You are a fact checker
|
|
18227
|
-
USE SEARCH ENGINE
|
|
18228
|
-
ACTION Search for claims and verify them against reliable sources
|
|
18229
|
-
\`\`\`
|
|
18230
|
-
`);
|
|
18231
|
-
}
|
|
18232
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
18233
|
-
// Get existing tools array or create new one
|
|
18234
|
-
const existingTools = requirements.tools || [];
|
|
18235
|
-
// Add 'web_search' to tools if not already present
|
|
18236
|
-
const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
|
|
18237
|
-
? existingTools
|
|
18238
|
-
: [
|
|
18239
|
-
...existingTools,
|
|
18240
|
-
{
|
|
18241
|
-
name: 'web_search',
|
|
18242
|
-
description: spaceTrim$1(`
|
|
18243
|
-
Search the internet for information.
|
|
18244
|
-
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
18245
|
-
`),
|
|
18246
|
-
parameters: {
|
|
18247
|
-
type: 'object',
|
|
18248
|
-
properties: {
|
|
18249
|
-
query: {
|
|
18250
|
-
type: 'string',
|
|
18251
|
-
description: 'The search query',
|
|
18252
|
-
},
|
|
18253
|
-
location: {
|
|
18254
|
-
type: 'string',
|
|
18255
|
-
description: 'The location for the search (e.g., "Austin, Texas, United States" or "Prague, Czechia")',
|
|
18256
|
-
},
|
|
18257
|
-
gl: {
|
|
18258
|
-
type: 'string',
|
|
18259
|
-
description: 'The country code (e.g., "us" for United States, "cz" for Czechia)',
|
|
18260
|
-
},
|
|
18261
|
-
hl: {
|
|
18262
|
-
type: 'string',
|
|
18263
|
-
description: 'The language code (e.g., "en" for English, "cs" for Czech)',
|
|
18264
|
-
},
|
|
18265
|
-
num: {
|
|
18266
|
-
type: 'integer',
|
|
18267
|
-
description: 'Number of results to return',
|
|
18268
|
-
},
|
|
18269
|
-
engine: {
|
|
18270
|
-
type: 'string',
|
|
18271
|
-
description: 'The search engine to use (e.g., "google", "bing", "yahoo", "baidu")',
|
|
18272
|
-
},
|
|
18273
|
-
google_domain: {
|
|
18274
|
-
type: 'string',
|
|
18275
|
-
description: 'The Google domain to use (e.g., "google.com", "google.cz")',
|
|
18276
|
-
},
|
|
18277
|
-
},
|
|
18278
|
-
required: ['query'],
|
|
18279
|
-
},
|
|
18280
|
-
},
|
|
18281
|
-
];
|
|
18282
|
-
return appendAggregatedUseCommitmentPlaceholder({
|
|
18283
|
-
...requirements,
|
|
18284
|
-
tools: updatedTools,
|
|
18285
|
-
_metadata: {
|
|
18286
|
-
...requirements._metadata,
|
|
18287
|
-
useSearchEngine: content || true,
|
|
18288
|
-
},
|
|
18289
|
-
}, this.type);
|
|
18290
|
-
}
|
|
18291
|
-
/**
|
|
18292
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
18293
|
-
*/
|
|
18294
|
-
getToolTitles() {
|
|
18295
|
-
return {
|
|
18296
|
-
web_search: 'Web search',
|
|
18297
|
-
};
|
|
18298
|
-
}
|
|
18299
|
-
/**
|
|
18300
|
-
* Gets the `web_search` tool function implementation.
|
|
18301
|
-
*/
|
|
18302
|
-
getToolFunctions() {
|
|
18303
|
-
return {
|
|
18304
|
-
web_search: createSerpSearchToolFunction('web_search', 'Search'),
|
|
18305
|
-
};
|
|
18306
|
-
}
|
|
18307
|
-
}
|
|
18308
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18309
|
-
|
|
18310
|
-
/**
|
|
18311
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
18312
|
-
*
|
|
18313
|
-
* @public exported from `@promptbook/core`
|
|
18314
|
-
*/
|
|
18315
|
-
class ParseError extends Error {
|
|
18316
|
-
constructor(message) {
|
|
18317
|
-
super(message);
|
|
18318
|
-
this.name = 'ParseError';
|
|
18319
|
-
Object.setPrototypeOf(this, ParseError.prototype);
|
|
18320
|
-
}
|
|
18321
|
-
}
|
|
18322
|
-
// TODO: Maybe split `ParseError` and `ApplyError`
|
|
18323
|
-
|
|
18324
|
-
/**
|
|
18325
|
-
* Supported visibility states for persisted agents.
|
|
18326
|
-
*
|
|
18327
|
-
* @public exported from `@promptbook/core`
|
|
18328
|
-
*/
|
|
18329
|
-
const AGENT_VISIBILITY_VALUES = ['PRIVATE', 'UNLISTED', 'PUBLIC'];
|
|
18330
|
-
/**
|
|
18331
|
-
* Returns `true` when the value is one of supported visibility states.
|
|
18332
|
-
*
|
|
18333
|
-
* @param value - Raw value to validate.
|
|
18334
|
-
* @returns Whether the value is a valid `AgentVisibility`.
|
|
18335
|
-
*
|
|
18336
|
-
* @public exported from `@promptbook/core`
|
|
18337
|
-
*/
|
|
18338
|
-
function isAgentVisibility(value) {
|
|
18339
|
-
return typeof value === 'string' && AGENT_VISIBILITY_VALUES.includes(value);
|
|
18340
|
-
}
|
|
18341
|
-
/**
|
|
18342
|
-
* Normalizes raw visibility text into a supported value.
|
|
18343
|
-
*
|
|
18344
|
-
* @param value - Raw visibility value.
|
|
18345
|
-
* @returns Normalized visibility, or `null` when invalid.
|
|
18346
|
-
*
|
|
18347
|
-
* @public exported from `@promptbook/core`
|
|
18348
|
-
*/
|
|
18349
|
-
function normalizeAgentVisibility(value) {
|
|
18350
|
-
if (typeof value !== 'string') {
|
|
18351
|
-
return null;
|
|
18352
|
-
}
|
|
18353
|
-
const normalized = value.trim().toUpperCase();
|
|
18354
|
-
return isAgentVisibility(normalized) ? normalized : null;
|
|
18355
|
-
}
|
|
18356
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18357
|
-
|
|
18358
|
-
/**
|
|
18359
|
-
* This error type indicates that some limit was reached
|
|
18360
|
-
*
|
|
18361
|
-
* @public exported from `@promptbook/core`
|
|
18362
|
-
*/
|
|
18363
|
-
class LimitReachedError extends Error {
|
|
18364
|
-
constructor(message) {
|
|
18365
|
-
super(message);
|
|
18366
|
-
this.name = 'LimitReachedError';
|
|
18367
|
-
Object.setPrototypeOf(this, LimitReachedError.prototype);
|
|
18368
|
-
}
|
|
18369
|
-
}
|
|
18370
|
-
|
|
18371
|
-
/**
|
|
18372
|
-
* Maximum allowed source length for create-agent payloads.
|
|
18373
|
-
*
|
|
18374
|
-
* @private shared create-agent contract
|
|
18375
|
-
*/
|
|
18376
|
-
const CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH = 120000;
|
|
18377
|
-
/**
|
|
18378
|
-
* Builds strict JSON schema for create-agent tool parameters.
|
|
18379
|
-
*
|
|
18380
|
-
* @private shared create-agent contract
|
|
18381
|
-
*/
|
|
18382
|
-
function createCreateAgentInputToolParametersSchema() {
|
|
18383
|
-
return {
|
|
18384
|
-
type: 'object',
|
|
18385
|
-
additionalProperties: false,
|
|
18386
|
-
properties: {
|
|
18387
|
-
source: {
|
|
18388
|
-
type: 'string',
|
|
18389
|
-
description: 'Full source of the new persisted agent (Promptbook/book markdown).',
|
|
18390
|
-
},
|
|
18391
|
-
folderId: {
|
|
18392
|
-
type: 'number',
|
|
18393
|
-
description: 'Optional folder identifier where the new agent should be placed.',
|
|
18394
|
-
},
|
|
18395
|
-
sortOrder: {
|
|
18396
|
-
type: 'number',
|
|
18397
|
-
description: 'Optional sort order inside the selected folder.',
|
|
18398
|
-
},
|
|
18399
|
-
visibility: {
|
|
18400
|
-
type: 'string',
|
|
18401
|
-
description: 'Optional visibility: PRIVATE, UNLISTED, or PUBLIC.',
|
|
18402
|
-
},
|
|
18403
|
-
},
|
|
18404
|
-
required: ['source'],
|
|
18405
|
-
};
|
|
18406
|
-
}
|
|
18407
|
-
|
|
18408
|
-
/**
|
|
18409
|
-
* Browser-safe wrapper for spawning one persisted Agents Server agent.
|
|
18410
|
-
*
|
|
18411
|
-
* This function proxies requests to the Agents Server `/api/spawn-agent` endpoint.
|
|
18412
|
-
*
|
|
18413
|
-
* @param args Tool payload forwarded to server-side `spawn_agent` tool.
|
|
18414
|
-
* @param agentsServerUrl Optional explicit agents server base URL.
|
|
18415
|
-
* @returns JSON string with structured spawn result.
|
|
18416
|
-
*
|
|
18417
|
-
* @private internal utility for USE SPAWN commitment
|
|
18418
|
-
*/
|
|
18419
|
-
async function spawnAgentViaBrowser(args, agentsServerUrl) {
|
|
18420
|
-
try {
|
|
18421
|
-
const baseUrl = agentsServerUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
18422
|
-
if (!baseUrl) {
|
|
18423
|
-
throw new Error('Agents server URL is required in non-browser environments');
|
|
18424
|
-
}
|
|
18425
|
-
const apiUrl = new URL('/api/spawn-agent', baseUrl);
|
|
18426
|
-
const response = await fetch(apiUrl.toString(), {
|
|
18427
|
-
method: 'POST',
|
|
18428
|
-
headers: {
|
|
18429
|
-
'Content-Type': 'application/json',
|
|
18430
|
-
},
|
|
18431
|
-
body: JSON.stringify(args),
|
|
18432
|
-
});
|
|
18433
|
-
const payload = (await response.json().catch(() => ({})));
|
|
18434
|
-
if (payload.result !== undefined) {
|
|
18435
|
-
return typeof payload.result === 'string' ? payload.result : JSON.stringify(payload.result);
|
|
18436
|
-
}
|
|
18437
|
-
if (!response.ok || payload.success === false) {
|
|
18438
|
-
throw new Error(`Failed to spawn agent: ${typeof payload.error === 'string' ? payload.error : response.statusText}`);
|
|
18439
|
-
}
|
|
18440
|
-
return JSON.stringify(payload);
|
|
18441
|
-
}
|
|
18442
|
-
catch (error) {
|
|
18443
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
18444
|
-
throw new Error(`Error spawning agent via browser: ${errorMessage}`);
|
|
18445
|
-
}
|
|
18446
|
-
}
|
|
18447
|
-
|
|
18448
|
-
/**
|
|
18449
|
-
* Tool name used by USE SPAWN.
|
|
18450
|
-
*
|
|
18451
|
-
* @private internal USE SPAWN constant
|
|
18452
|
-
*/
|
|
18453
|
-
const SPAWN_AGENT_TOOL_NAME = 'spawn_agent';
|
|
18454
|
-
/**
|
|
18455
|
-
* USE SPAWN commitment definition.
|
|
18456
|
-
*
|
|
18457
|
-
* The `USE SPAWN` commitment enables creating new persistent child agents through one tool call.
|
|
18458
|
-
*
|
|
18459
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
18460
|
-
*/
|
|
18461
|
-
class UseSpawnCommitmentDefinition extends BaseCommitmentDefinition {
|
|
18462
|
-
constructor() {
|
|
18463
|
-
super('USE SPAWN', ['SPAWN']);
|
|
18464
|
-
}
|
|
18465
|
-
get requiresContent() {
|
|
18466
|
-
return false;
|
|
18467
|
-
}
|
|
18468
|
-
/**
|
|
18469
|
-
* Short one-line description of USE SPAWN.
|
|
18470
|
-
*/
|
|
18471
|
-
get description() {
|
|
18472
|
-
return 'Enable the agent to create persistent child agents via Agents Server create-agent flow.';
|
|
18473
|
-
}
|
|
18474
|
-
/**
|
|
18475
|
-
* Icon for this commitment.
|
|
18476
|
-
*/
|
|
18477
|
-
get icon() {
|
|
18478
|
-
return '🧬';
|
|
18479
|
-
}
|
|
18480
|
-
/**
|
|
18481
|
-
* Markdown documentation for USE SPAWN commitment.
|
|
18482
|
-
*/
|
|
18483
|
-
get documentation() {
|
|
18484
|
-
return spaceTrim$1(`
|
|
18485
|
-
# USE SPAWN
|
|
18486
|
-
|
|
18487
|
-
Enables the agent to create a new persistent child agent using the \`spawn_agent\` tool.
|
|
18488
|
-
|
|
18489
|
-
## Key aspects
|
|
18490
|
-
|
|
18491
|
-
- The spawned agent is persisted exactly like manually created agents.
|
|
18492
|
-
- Tool input mirrors create-agent fields currently supported by Agents Server:
|
|
18493
|
-
- \`source\` (required)
|
|
18494
|
-
- \`folderId\` (optional)
|
|
18495
|
-
- \`sortOrder\` (optional)
|
|
18496
|
-
- \`visibility\` (optional)
|
|
18497
|
-
- Unknown fields are rejected to avoid silent misconfiguration.
|
|
18498
|
-
- \`source\` payload is size-limited.
|
|
18499
|
-
- Agents Server applies permission and abuse protections (auth checks, limits).
|
|
18500
|
-
- Optional text after \`USE SPAWN\` is treated as spawn-policy instructions.
|
|
18501
|
-
|
|
18502
|
-
## Examples
|
|
18503
|
-
|
|
18504
|
-
\`\`\`book
|
|
18505
|
-
Team Builder
|
|
18506
|
-
|
|
18507
|
-
PERSONA You can create specialized assistants for the user.
|
|
18508
|
-
USE SPAWN Spawn only when the user explicitly asks for a new persistent agent.
|
|
18509
|
-
\`\`\`
|
|
18510
|
-
`);
|
|
18511
|
-
}
|
|
18512
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
18513
|
-
const extraInstructions = formatOptionalInstructionBlock('Spawn instructions', content);
|
|
18514
|
-
const existingTools = requirements.tools || [];
|
|
18515
|
-
const tools = existingTools.some((tool) => tool.name === SPAWN_AGENT_TOOL_NAME)
|
|
18516
|
-
? existingTools
|
|
18517
|
-
: [
|
|
18518
|
-
...existingTools,
|
|
18519
|
-
{
|
|
18520
|
-
name: SPAWN_AGENT_TOOL_NAME,
|
|
18521
|
-
description: spaceTrim$1(`
|
|
18522
|
-
Creates one new persistent child agent in Agents Server.
|
|
18523
|
-
Use this when the user asks to create a new dedicated agent profile.
|
|
18524
|
-
The tool returns JSON with \`status\`, \`agentId\`, and created \`agent\` or \`error\`.
|
|
18525
|
-
`),
|
|
18526
|
-
parameters: createCreateAgentInputToolParametersSchema(),
|
|
18527
|
-
},
|
|
18528
|
-
];
|
|
18529
|
-
return this.appendToSystemMessage({
|
|
18530
|
-
...requirements,
|
|
18531
|
-
tools,
|
|
18532
|
-
_metadata: {
|
|
18533
|
-
...requirements._metadata,
|
|
18534
|
-
useSpawn: content || true,
|
|
18535
|
-
},
|
|
18536
|
-
}, spaceTrim$1((block) => `
|
|
18537
|
-
## Spawning agents
|
|
18538
|
-
|
|
18539
|
-
- Use \`${SPAWN_AGENT_TOOL_NAME}\` only when user asks to create a persistent new agent.
|
|
18540
|
-
- Pass full agent source in \`source\`.
|
|
18541
|
-
- Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
|
|
18542
|
-
- Do not add unknown fields in tool arguments.
|
|
18543
|
-
${block(extraInstructions)}
|
|
18544
|
-
`));
|
|
18545
|
-
}
|
|
18546
|
-
/**
|
|
18547
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
18548
|
-
*/
|
|
18549
|
-
getToolTitles() {
|
|
18550
|
-
return {
|
|
18551
|
-
[SPAWN_AGENT_TOOL_NAME]: 'Spawn agent',
|
|
18552
|
-
};
|
|
18553
|
-
}
|
|
18554
|
-
/**
|
|
18555
|
-
* Gets browser-safe `spawn_agent` implementation.
|
|
18556
|
-
*
|
|
18557
|
-
* Node.js runtime overrides this through `getAllCommitmentsToolFunctionsForNode`.
|
|
18558
|
-
*/
|
|
18559
|
-
getToolFunctions() {
|
|
18560
|
-
return {
|
|
18561
|
-
async [SPAWN_AGENT_TOOL_NAME](args) {
|
|
18562
|
-
return spawnAgentViaBrowser(args);
|
|
18563
|
-
},
|
|
18564
|
-
};
|
|
18565
|
-
}
|
|
18566
|
-
}
|
|
18567
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18568
|
-
|
|
18569
|
-
/**
|
|
18570
|
-
* Creates system-message instructions for `USE TIMEOUT`.
|
|
18571
|
-
*
|
|
18572
|
-
* @private internal utility of USE TIMEOUT
|
|
18573
|
-
*/
|
|
18574
|
-
function createTimeoutSystemMessage(extraInstructions) {
|
|
18575
|
-
return spaceTrim$1((block) => `
|
|
18576
|
-
## Timeout scheduling
|
|
18577
|
-
|
|
18578
|
-
- Use \`set_timeout\` to wake this same chat thread in the future.
|
|
18579
|
-
- Use \`list_timeouts\` to review timeout ids/details across all chats for the same user+agent scope.
|
|
18580
|
-
- \`cancel_timeout\` accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
|
|
18581
|
-
- Use \`update_timeout\` to pause/resume, edit next run, edit recurrence, or update timeout payload details.
|
|
18582
|
-
- When one timeout elapses, you will receive a new user-like message that explicitly says it is a timeout wake-up and includes the \`timeoutId\`.
|
|
18583
|
-
- Do not claim a timer was set or cancelled unless the tool confirms it.
|
|
18584
|
-
${block(extraInstructions)}
|
|
18585
|
-
`);
|
|
18586
|
-
}
|
|
18587
|
-
|
|
18588
|
-
/**
|
|
18589
|
-
* Marker property stored inside serialized tool-execution envelopes.
|
|
18590
|
-
*
|
|
18591
|
-
* @private internal tool-execution transport
|
|
18592
|
-
*/
|
|
18593
|
-
const TOOL_EXECUTION_ENVELOPE_MARKER = '__promptbookToolExecutionEnvelope';
|
|
18594
|
-
/**
|
|
18595
|
-
* Creates one serialized tool-execution envelope.
|
|
18596
|
-
*
|
|
18597
|
-
* @private internal tool-execution transport
|
|
18598
|
-
*/
|
|
18599
|
-
function createToolExecutionEnvelope(options) {
|
|
18600
|
-
const envelope = {
|
|
18601
|
-
[TOOL_EXECUTION_ENVELOPE_MARKER]: true,
|
|
18602
|
-
assistantMessage: options.assistantMessage,
|
|
18603
|
-
toolResult: options.toolResult,
|
|
18604
|
-
};
|
|
18605
|
-
return JSON.stringify(envelope);
|
|
18606
|
-
}
|
|
18607
|
-
/**
|
|
18608
|
-
* Parses one serialized tool-execution envelope when present.
|
|
18609
|
-
*
|
|
18610
|
-
* @private internal tool-execution transport
|
|
18611
|
-
*/
|
|
18612
|
-
function parseToolExecutionEnvelope(rawValue) {
|
|
18613
|
-
if (typeof rawValue !== 'string') {
|
|
18614
|
-
return null;
|
|
18615
|
-
}
|
|
18616
|
-
try {
|
|
18617
|
-
const parsedValue = JSON.parse(rawValue);
|
|
18618
|
-
if (!parsedValue ||
|
|
18619
|
-
typeof parsedValue !== 'object' ||
|
|
18620
|
-
parsedValue[TOOL_EXECUTION_ENVELOPE_MARKER] !== true ||
|
|
18621
|
-
typeof parsedValue.assistantMessage !== 'string') {
|
|
18622
|
-
return null;
|
|
18623
|
-
}
|
|
18624
|
-
return {
|
|
18625
|
-
assistantMessage: parsedValue.assistantMessage,
|
|
18626
|
-
toolResult: parsedValue.toolResult,
|
|
18627
|
-
};
|
|
18628
|
-
}
|
|
18629
|
-
catch (_a) {
|
|
18630
|
-
return null;
|
|
18631
|
-
}
|
|
18632
|
-
}
|
|
18633
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18634
|
-
|
|
18635
|
-
/**
|
|
18636
|
-
* Builds a disabled timeout-tool payload.
|
|
18637
|
-
*
|
|
18638
|
-
* @private internal utility of USE TIMEOUT
|
|
18639
|
-
*/
|
|
18640
|
-
function createDisabledTimeoutResult(action, message) {
|
|
18641
|
-
return {
|
|
18642
|
-
action,
|
|
18643
|
-
status: 'disabled',
|
|
18644
|
-
message,
|
|
18645
|
-
};
|
|
18646
|
-
}
|
|
18647
|
-
/**
|
|
18648
|
-
* Resolves the runtime adapter for timeout tools or returns disabled payload when unavailable.
|
|
18649
|
-
*
|
|
18650
|
-
* @private internal utility of USE TIMEOUT
|
|
18651
|
-
*/
|
|
18652
|
-
function getTimeoutToolRuntimeAdapterOrDisabledResult(action, runtimeContext) {
|
|
18653
|
-
if (!runtimeContext.enabled || !runtimeContext.chatId) {
|
|
18654
|
-
return {
|
|
18655
|
-
adapter: null,
|
|
18656
|
-
disabledResult: createDisabledTimeoutResult(action, 'Timeouts are unavailable because this conversation is not running inside a chat thread.'),
|
|
18657
|
-
};
|
|
18658
|
-
}
|
|
18659
|
-
{
|
|
18660
|
-
return {
|
|
18661
|
-
adapter: null,
|
|
18662
|
-
disabledResult: createDisabledTimeoutResult(action, 'Timeout runtime is not available in this environment.'),
|
|
18663
|
-
};
|
|
18664
|
-
}
|
|
18665
|
-
}
|
|
18666
|
-
|
|
18667
|
-
/**
|
|
18668
|
-
* Generates random token
|
|
18669
|
-
*
|
|
18670
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
18671
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
18672
|
-
*
|
|
18673
|
-
* @returns secure random token
|
|
18674
|
-
*
|
|
18675
|
-
* @private internal helper function
|
|
18676
|
-
*/
|
|
18677
|
-
function $randomToken(randomness) {
|
|
18678
|
-
return CryptoJS.lib.WordArray.random(randomness).toString(CryptoJS.enc.Hex);
|
|
18679
|
-
}
|
|
18680
|
-
// TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18681
|
-
// TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
18682
|
-
|
|
18683
|
-
/**
|
|
18684
|
-
* This error indicates errors during the execution of the pipeline
|
|
18685
|
-
*
|
|
18686
|
-
* @public exported from `@promptbook/core`
|
|
18687
|
-
*/
|
|
18688
|
-
class PipelineExecutionError extends Error {
|
|
18689
|
-
constructor(message) {
|
|
18690
|
-
// Added id parameter
|
|
18691
|
-
super(message);
|
|
18692
|
-
this.name = 'PipelineExecutionError';
|
|
18693
|
-
// TODO: [🐙] DRY - Maybe $randomId
|
|
18694
|
-
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
18695
|
-
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
18696
|
-
}
|
|
18697
|
-
}
|
|
18698
|
-
// TODO: [🧠][🌂] Add id to all errors
|
|
18699
|
-
|
|
18700
|
-
/**
|
|
18701
|
-
* Default number of rows returned by `list_timeouts`.
|
|
18702
|
-
*
|
|
18703
|
-
* @private internal USE TIMEOUT constant
|
|
18704
|
-
*/
|
|
18705
|
-
const DEFAULT_LIST_TIMEOUTS_LIMIT = 20;
|
|
18706
|
-
/**
|
|
18707
|
-
* Hard cap for `list_timeouts` page size.
|
|
18708
|
-
*
|
|
18709
|
-
* @private internal USE TIMEOUT constant
|
|
18710
|
-
*/
|
|
18711
|
-
const MAX_LIST_TIMEOUTS_LIMIT = 100;
|
|
18712
|
-
/**
|
|
18713
|
-
* Creates one formatted timeout-argument validation error.
|
|
18714
|
-
*
|
|
18715
|
-
* @private internal utility of USE TIMEOUT
|
|
18716
|
-
*/
|
|
18717
|
-
function createTimeoutToolArgsError(message) {
|
|
18718
|
-
return new PipelineExecutionError(spaceTrim$1(`
|
|
18719
|
-
${message}
|
|
18720
|
-
`));
|
|
18721
|
-
}
|
|
18722
|
-
/**
|
|
18723
|
-
* Normalizes one optional timeout id string.
|
|
18724
|
-
*
|
|
18725
|
-
* @private internal utility of USE TIMEOUT
|
|
18726
|
-
*/
|
|
18727
|
-
function normalizeOptionalTimeoutId(value) {
|
|
18728
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
18729
|
-
}
|
|
18730
|
-
/**
|
|
18731
|
-
* Parses timeout target selection for tools that accept either `timeoutId` or `allActive: true`.
|
|
18732
|
-
*
|
|
18733
|
-
* @private internal utility of USE TIMEOUT
|
|
18734
|
-
*/
|
|
18735
|
-
function parseTimeoutTargetSelection(args, options) {
|
|
18736
|
-
const timeoutId = normalizeOptionalTimeoutId(args.timeoutId);
|
|
18737
|
-
const allActive = args.allActive === true;
|
|
18738
|
-
if (timeoutId && allActive) {
|
|
18739
|
-
throw createTimeoutToolArgsError(options.bothMessage);
|
|
18740
|
-
}
|
|
18741
|
-
if (allActive) {
|
|
18742
|
-
return { allActive: true };
|
|
18743
|
-
}
|
|
18744
|
-
if (!timeoutId) {
|
|
18745
|
-
throw createTimeoutToolArgsError(options.missingMessage);
|
|
18746
|
-
}
|
|
18747
|
-
return {
|
|
18748
|
-
timeoutId,
|
|
18749
|
-
allActive: false,
|
|
18750
|
-
};
|
|
18751
|
-
}
|
|
18752
|
-
/**
|
|
18753
|
-
* Parses one explicit `dueAt` update value.
|
|
18754
|
-
*
|
|
18755
|
-
* @private internal utility of USE TIMEOUT
|
|
18756
|
-
*/
|
|
18757
|
-
function parseOptionalTimeoutDueAt(value) {
|
|
18758
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
18759
|
-
return undefined;
|
|
18760
|
-
}
|
|
18761
|
-
const normalizedDueAt = value.trim();
|
|
18762
|
-
const dueAtTimestamp = Date.parse(normalizedDueAt);
|
|
18763
|
-
if (!Number.isFinite(dueAtTimestamp)) {
|
|
18764
|
-
throw createTimeoutToolArgsError('Timeout `dueAt` must be one valid ISO timestamp.');
|
|
18765
|
-
}
|
|
18766
|
-
return new Date(dueAtTimestamp).toISOString();
|
|
18767
|
-
}
|
|
18768
|
-
/**
|
|
18769
|
-
* Parses one explicit `extendByMs` update value.
|
|
18770
|
-
*
|
|
18771
|
-
* @private internal utility of USE TIMEOUT
|
|
18772
|
-
*/
|
|
18773
|
-
function parseOptionalTimeoutExtendByMs(value) {
|
|
18774
|
-
if (typeof value !== 'number') {
|
|
18775
|
-
return undefined;
|
|
18776
|
-
}
|
|
18777
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
18778
|
-
throw createTimeoutToolArgsError('Timeout `extendByMs` must be a positive number of milliseconds.');
|
|
18779
|
-
}
|
|
18780
|
-
return Math.floor(value);
|
|
18781
|
-
}
|
|
18782
|
-
/**
|
|
18783
|
-
* Parses one explicit `recurrenceIntervalMs` update value.
|
|
18784
|
-
*
|
|
18785
|
-
* @private internal utility of USE TIMEOUT
|
|
18786
|
-
*/
|
|
18787
|
-
function parseOptionalTimeoutRecurrenceInterval(value) {
|
|
18788
|
-
if (value === null) {
|
|
18789
|
-
return null;
|
|
18790
|
-
}
|
|
18791
|
-
if (typeof value !== 'number') {
|
|
18792
|
-
return undefined;
|
|
18793
|
-
}
|
|
18794
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
18795
|
-
throw createTimeoutToolArgsError('Timeout `recurrenceIntervalMs` must be a positive number of milliseconds or `null`.');
|
|
18796
|
-
}
|
|
18797
|
-
return Math.floor(value);
|
|
18798
|
-
}
|
|
18799
|
-
/**
|
|
18800
|
-
* Parses one explicit `message` update value.
|
|
18801
|
-
*
|
|
18802
|
-
* @private internal utility of USE TIMEOUT
|
|
18803
|
-
*/
|
|
18804
|
-
function parseOptionalTimeoutMessage(value) {
|
|
18805
|
-
if (value === null) {
|
|
18806
|
-
return null;
|
|
18807
|
-
}
|
|
18808
|
-
if (typeof value !== 'string') {
|
|
18809
|
-
return undefined;
|
|
18810
|
-
}
|
|
18811
|
-
const normalizedMessage = value.trim();
|
|
18812
|
-
return normalizedMessage.length > 0 ? normalizedMessage : null;
|
|
18813
|
-
}
|
|
18814
|
-
/**
|
|
18815
|
-
* Parses one explicit `parameters` update value.
|
|
18816
|
-
*
|
|
18817
|
-
* @private internal utility of USE TIMEOUT
|
|
18818
|
-
*/
|
|
18819
|
-
function parseOptionalTimeoutParameters(value) {
|
|
18820
|
-
if (value === undefined) {
|
|
18821
|
-
return undefined;
|
|
18822
|
-
}
|
|
18823
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
18824
|
-
throw createTimeoutToolArgsError('Timeout `parameters` must be one JSON object.');
|
|
18825
|
-
}
|
|
18826
|
-
return value;
|
|
18827
|
-
}
|
|
18828
|
-
/**
|
|
18829
|
-
* Parses one explicit `paused` update value.
|
|
18830
|
-
*
|
|
18831
|
-
* @private internal utility of USE TIMEOUT
|
|
18832
|
-
*/
|
|
18833
|
-
function parseOptionalTimeoutPaused(value) {
|
|
18834
|
-
return typeof value === 'boolean' ? value : undefined;
|
|
18835
|
-
}
|
|
18836
|
-
/**
|
|
18837
|
-
* Parses patch fields for `update_timeout`.
|
|
18838
|
-
*
|
|
18839
|
-
* @private internal utility of USE TIMEOUT
|
|
18840
|
-
*/
|
|
18841
|
-
function parseTimeoutUpdatePatch(args) {
|
|
18842
|
-
const patch = {};
|
|
18843
|
-
const dueAt = parseOptionalTimeoutDueAt(args.dueAt);
|
|
18844
|
-
const extendByMs = parseOptionalTimeoutExtendByMs(args.extendByMs);
|
|
18845
|
-
const recurrenceIntervalMs = parseOptionalTimeoutRecurrenceInterval(args.recurrenceIntervalMs);
|
|
18846
|
-
const message = parseOptionalTimeoutMessage(args.message);
|
|
18847
|
-
const parameters = parseOptionalTimeoutParameters(args.parameters);
|
|
18848
|
-
const paused = parseOptionalTimeoutPaused(args.paused);
|
|
18849
|
-
if (dueAt !== undefined) {
|
|
18850
|
-
patch.dueAt = dueAt;
|
|
18851
|
-
}
|
|
18852
|
-
if (extendByMs !== undefined) {
|
|
18853
|
-
patch.extendByMs = extendByMs;
|
|
18854
|
-
}
|
|
18855
|
-
if (patch.dueAt !== undefined && patch.extendByMs !== undefined) {
|
|
18856
|
-
throw createTimeoutToolArgsError('Timeout update cannot include both `dueAt` and `extendByMs`.');
|
|
18857
|
-
}
|
|
18858
|
-
if (recurrenceIntervalMs !== undefined) {
|
|
18859
|
-
patch.recurrenceIntervalMs = recurrenceIntervalMs;
|
|
18860
|
-
}
|
|
18861
|
-
if (message !== undefined) {
|
|
18862
|
-
patch.message = message;
|
|
18863
|
-
}
|
|
18864
|
-
if (parameters !== undefined) {
|
|
18865
|
-
patch.parameters = parameters;
|
|
18866
|
-
}
|
|
18867
|
-
if (paused !== undefined) {
|
|
18868
|
-
patch.paused = paused;
|
|
18869
|
-
}
|
|
18870
|
-
return patch;
|
|
18871
|
-
}
|
|
18872
|
-
/**
|
|
18873
|
-
* Determines whether the patch contains fields that are only supported for single-timeout updates.
|
|
18874
|
-
*
|
|
18875
|
-
* @private internal utility of USE TIMEOUT
|
|
18876
|
-
*/
|
|
18877
|
-
function hasSingleTimeoutOnlyPatchFields(patch) {
|
|
18878
|
-
return (patch.dueAt !== undefined ||
|
|
18879
|
-
patch.extendByMs !== undefined ||
|
|
18880
|
-
patch.recurrenceIntervalMs !== undefined ||
|
|
18881
|
-
patch.message !== undefined ||
|
|
18882
|
-
patch.parameters !== undefined);
|
|
18883
|
-
}
|
|
18884
|
-
/**
|
|
18885
|
-
* Parses bulk timeout update arguments.
|
|
18886
|
-
*
|
|
18887
|
-
* @private internal utility of USE TIMEOUT
|
|
18888
|
-
*/
|
|
18889
|
-
function parseBulkTimeoutUpdateArgs(patch) {
|
|
18890
|
-
if (patch.paused === undefined) {
|
|
18891
|
-
throw createTimeoutToolArgsError('Bulk timeout update with `allActive: true` requires `paused` to be explicitly set.');
|
|
18892
|
-
}
|
|
18893
|
-
if (hasSingleTimeoutOnlyPatchFields(patch)) {
|
|
18894
|
-
throw createTimeoutToolArgsError('Bulk timeout update only supports the `paused` field.');
|
|
18895
|
-
}
|
|
18896
|
-
return {
|
|
18897
|
-
allActive: true,
|
|
18898
|
-
paused: patch.paused,
|
|
18899
|
-
};
|
|
18900
|
-
}
|
|
18901
|
-
/**
|
|
18902
|
-
* Parses single-timeout update arguments.
|
|
18903
|
-
*
|
|
18904
|
-
* @private internal utility of USE TIMEOUT
|
|
18905
|
-
*/
|
|
18906
|
-
function parseSingleTimeoutUpdateArgs(timeoutId, patch) {
|
|
18907
|
-
if (!timeoutId) {
|
|
18908
|
-
throw createTimeoutToolArgsError('Timeout `timeoutId` is required for single-timeout updates.');
|
|
18909
|
-
}
|
|
18910
|
-
if (Object.keys(patch).length === 0) {
|
|
18911
|
-
throw createTimeoutToolArgsError('Timeout update must include at least one editable field.');
|
|
18912
|
-
}
|
|
18913
|
-
return {
|
|
18914
|
-
timeoutId,
|
|
18915
|
-
patch,
|
|
18916
|
-
};
|
|
18917
|
-
}
|
|
18918
|
-
/**
|
|
18919
|
-
* Parses and validates `USE TIMEOUT` tool arguments.
|
|
18920
|
-
*
|
|
18921
|
-
* @private internal utility of USE TIMEOUT
|
|
18922
|
-
*/
|
|
18923
|
-
const parseTimeoutToolArgs = {
|
|
18924
|
-
/**
|
|
18925
|
-
* Parses `set_timeout` input.
|
|
18926
|
-
*/
|
|
18927
|
-
set(args) {
|
|
18928
|
-
const parsedMilliseconds = Number(args.milliseconds);
|
|
18929
|
-
if (!Number.isFinite(parsedMilliseconds) || parsedMilliseconds <= 0) {
|
|
18930
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
18931
|
-
Timeout \`milliseconds\` must be a positive number.
|
|
18932
|
-
`));
|
|
18933
|
-
}
|
|
18934
|
-
const message = typeof args.message === 'string' ? args.message.trim() : '';
|
|
18935
|
-
return {
|
|
18936
|
-
milliseconds: Math.floor(parsedMilliseconds),
|
|
18937
|
-
...(message ? { message } : {}),
|
|
18938
|
-
};
|
|
18939
|
-
},
|
|
18940
|
-
/**
|
|
18941
|
-
* Parses `cancel_timeout` input.
|
|
18942
|
-
*/
|
|
18943
|
-
cancel(args) {
|
|
18944
|
-
const target = parseTimeoutTargetSelection(args, {
|
|
18945
|
-
bothMessage: 'Timeout cancellation must target either one `timeoutId` or `allActive: true`, not both.',
|
|
18946
|
-
missingMessage: 'Timeout `timeoutId` is required unless you pass `allActive: true`.',
|
|
18947
|
-
});
|
|
18948
|
-
if (target.allActive) {
|
|
18949
|
-
return { allActive: true };
|
|
18950
|
-
}
|
|
18951
|
-
return { timeoutId: target.timeoutId };
|
|
18952
|
-
},
|
|
18953
|
-
/**
|
|
18954
|
-
* Parses `list_timeouts` input.
|
|
18955
|
-
*/
|
|
18956
|
-
list(args) {
|
|
18957
|
-
if (args.includeFinished !== undefined && typeof args.includeFinished !== 'boolean') {
|
|
18958
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
18959
|
-
Timeout \`includeFinished\` must be a boolean when provided.
|
|
18960
|
-
`));
|
|
18961
|
-
}
|
|
18962
|
-
const parsedLimit = args.limit === undefined ? DEFAULT_LIST_TIMEOUTS_LIMIT : Math.floor(Number(args.limit));
|
|
18963
|
-
if (!Number.isFinite(parsedLimit) || parsedLimit <= 0) {
|
|
18964
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
18965
|
-
Timeout \`limit\` must be a positive number.
|
|
18966
|
-
`));
|
|
18967
|
-
}
|
|
18968
|
-
if (parsedLimit > MAX_LIST_TIMEOUTS_LIMIT) {
|
|
18969
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
18970
|
-
Timeout \`limit\` must be at most \`${MAX_LIST_TIMEOUTS_LIMIT}\`.
|
|
18971
|
-
`));
|
|
18972
|
-
}
|
|
18973
|
-
return {
|
|
18974
|
-
includeFinished: args.includeFinished === true,
|
|
18975
|
-
limit: parsedLimit,
|
|
18976
|
-
};
|
|
18977
|
-
},
|
|
18978
|
-
/**
|
|
18979
|
-
* Parses `update_timeout` input.
|
|
18980
|
-
*/
|
|
18981
|
-
update(args) {
|
|
18982
|
-
const target = parseTimeoutTargetSelection(args, {
|
|
18983
|
-
bothMessage: 'Timeout update must target either one `timeoutId` or `allActive: true`, not both.',
|
|
18984
|
-
missingMessage: 'Timeout update requires one `timeoutId` or `allActive: true`.',
|
|
18985
|
-
});
|
|
18986
|
-
const patch = parseTimeoutUpdatePatch(args);
|
|
18987
|
-
return target.allActive
|
|
18988
|
-
? parseBulkTimeoutUpdateArgs(patch)
|
|
18989
|
-
: parseSingleTimeoutUpdateArgs(target.timeoutId, patch);
|
|
18990
|
-
},
|
|
18991
|
-
};
|
|
18992
|
-
|
|
18993
|
-
/**
|
|
18994
|
-
* Resolves timeout runtime context from hidden tool arguments.
|
|
18995
|
-
*
|
|
18996
|
-
* @private internal utility of USE TIMEOUT
|
|
18997
|
-
*/
|
|
18998
|
-
function resolveTimeoutRuntimeContext(args) {
|
|
18999
|
-
const runtimeContext = readToolRuntimeContextFromToolArgs(args);
|
|
19000
|
-
const chatContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.chat;
|
|
19001
|
-
return {
|
|
19002
|
-
enabled: Boolean(chatContext === null || chatContext === void 0 ? void 0 : chatContext.chatId),
|
|
19003
|
-
chatId: chatContext === null || chatContext === void 0 ? void 0 : chatContext.chatId,
|
|
19004
|
-
userId: chatContext === null || chatContext === void 0 ? void 0 : chatContext.userId,
|
|
19005
|
-
agentId: chatContext === null || chatContext === void 0 ? void 0 : chatContext.agentId,
|
|
19006
|
-
agentName: chatContext === null || chatContext === void 0 ? void 0 : chatContext.agentName,
|
|
19007
|
-
promptParameters: normalizePromptParameters(chatContext === null || chatContext === void 0 ? void 0 : chatContext.parameters),
|
|
19008
|
-
};
|
|
19009
|
-
}
|
|
19010
|
-
/**
|
|
19011
|
-
* Normalizes stored prompt parameters carried by timeout runtime context.
|
|
19012
|
-
*
|
|
19013
|
-
* @private internal utility of USE TIMEOUT
|
|
19014
|
-
*/
|
|
19015
|
-
function normalizePromptParameters(rawParameters) {
|
|
19016
|
-
if (!rawParameters || typeof rawParameters !== 'object' || Array.isArray(rawParameters)) {
|
|
19017
|
-
return {};
|
|
19018
|
-
}
|
|
19019
|
-
const normalizedEntries = Object.entries(rawParameters).filter(([, value]) => typeof value === 'string');
|
|
19020
|
-
return Object.fromEntries(normalizedEntries);
|
|
19021
|
-
}
|
|
19022
|
-
|
|
19023
|
-
/**
|
|
19024
|
-
* Tool names provided by the `USE TIMEOUT` commitment.
|
|
19025
|
-
*
|
|
19026
|
-
* @private internal USE TIMEOUT constant
|
|
19027
|
-
*/
|
|
19028
|
-
const TimeoutToolNames = {
|
|
19029
|
-
set: 'set_timeout',
|
|
19030
|
-
cancel: 'cancel_timeout',
|
|
19031
|
-
list: 'list_timeouts',
|
|
19032
|
-
update: 'update_timeout',
|
|
19033
|
-
};
|
|
19034
|
-
|
|
19035
|
-
/**
|
|
19036
|
-
* Maximum number of timeout rows rendered into the assistant-visible `list_timeouts` message.
|
|
19037
|
-
*
|
|
19038
|
-
* @private internal USE TIMEOUT constant
|
|
19039
|
-
*/
|
|
19040
|
-
const MAX_ASSISTANT_VISIBLE_TIMEOUT_ROWS = 20;
|
|
19041
|
-
/**
|
|
19042
|
-
* Maximum number of timeout ids rendered in bulk-action summaries.
|
|
19043
|
-
*
|
|
19044
|
-
* @private internal USE TIMEOUT constant
|
|
19045
|
-
*/
|
|
19046
|
-
const MAX_ASSISTANT_VISIBLE_BULK_TIMEOUT_IDS = 10;
|
|
19047
|
-
/**
|
|
19048
|
-
* Gets `USE TIMEOUT` tool function implementations.
|
|
19049
|
-
*
|
|
19050
|
-
* @private internal utility of USE TIMEOUT
|
|
19051
|
-
*/
|
|
19052
|
-
function createTimeoutToolFunctions() {
|
|
19053
|
-
return {
|
|
19054
|
-
async [TimeoutToolNames.set](args) {
|
|
19055
|
-
const runtimeContext = resolveTimeoutRuntimeContext(args);
|
|
19056
|
-
const { adapter, disabledResult } = getTimeoutToolRuntimeAdapterOrDisabledResult('set', runtimeContext);
|
|
19057
|
-
if (!adapter || disabledResult) {
|
|
19058
|
-
return JSON.stringify(disabledResult);
|
|
19059
|
-
}
|
|
19060
|
-
try {
|
|
19061
|
-
const parsedArgs = parseTimeoutToolArgs.set(args);
|
|
19062
|
-
const scheduledTimeout = await adapter.scheduleTimeout(parsedArgs, runtimeContext);
|
|
19063
|
-
const result = {
|
|
19064
|
-
action: 'set',
|
|
19065
|
-
status: 'set',
|
|
19066
|
-
timeoutId: scheduledTimeout.timeoutId,
|
|
19067
|
-
dueAt: scheduledTimeout.dueAt,
|
|
19068
|
-
};
|
|
19069
|
-
return createToolExecutionEnvelope({
|
|
19070
|
-
assistantMessage: 'The timer was set.',
|
|
19071
|
-
toolResult: result,
|
|
19072
|
-
});
|
|
19073
|
-
}
|
|
19074
|
-
catch (error) {
|
|
19075
|
-
const result = {
|
|
19076
|
-
action: 'set',
|
|
19077
|
-
status: 'error',
|
|
19078
|
-
message: error instanceof Error ? error.message : String(error),
|
|
19079
|
-
};
|
|
19080
|
-
return JSON.stringify(result);
|
|
19081
|
-
}
|
|
19082
|
-
},
|
|
19083
|
-
async [TimeoutToolNames.cancel](args) {
|
|
19084
|
-
const runtimeContext = resolveTimeoutRuntimeContext(args);
|
|
19085
|
-
const { adapter, disabledResult } = getTimeoutToolRuntimeAdapterOrDisabledResult('cancel', runtimeContext);
|
|
19086
|
-
if (!adapter || disabledResult) {
|
|
19087
|
-
return JSON.stringify(disabledResult);
|
|
19088
|
-
}
|
|
19089
|
-
try {
|
|
19090
|
-
const parsedArgs = parseTimeoutToolArgs.cancel(args);
|
|
19091
|
-
const cancelledTimeout = await adapter.cancelTimeout(parsedArgs, runtimeContext);
|
|
19092
|
-
if (cancelledTimeout.status === 'cancelled_all') {
|
|
19093
|
-
const result = {
|
|
19094
|
-
action: 'cancel',
|
|
19095
|
-
status: 'cancelled_all',
|
|
19096
|
-
cancelledCount: cancelledTimeout.cancelledCount || 0,
|
|
19097
|
-
cancelledTimeoutIds: cancelledTimeout.cancelledTimeoutIds || [],
|
|
19098
|
-
hasMore: cancelledTimeout.hasMore,
|
|
19099
|
-
};
|
|
19100
|
-
return createToolExecutionEnvelope({
|
|
19101
|
-
assistantMessage: createBulkCancelAssistantMessage({
|
|
19102
|
-
cancelledCount: result.cancelledCount || 0,
|
|
19103
|
-
cancelledTimeoutIds: result.cancelledTimeoutIds || [],
|
|
19104
|
-
hasMore: result.hasMore,
|
|
19105
|
-
}),
|
|
19106
|
-
toolResult: result,
|
|
19107
|
-
});
|
|
19108
|
-
}
|
|
19109
|
-
const result = {
|
|
19110
|
-
action: 'cancel',
|
|
19111
|
-
status: cancelledTimeout.status,
|
|
19112
|
-
timeoutId: cancelledTimeout.timeoutId,
|
|
19113
|
-
dueAt: cancelledTimeout.dueAt,
|
|
19114
|
-
};
|
|
19115
|
-
return createToolExecutionEnvelope({
|
|
19116
|
-
assistantMessage: cancelledTimeout.status === 'cancelled'
|
|
19117
|
-
? 'The timer was cancelled.'
|
|
19118
|
-
: 'The timer was already inactive.',
|
|
19119
|
-
toolResult: result,
|
|
19120
|
-
});
|
|
19121
|
-
}
|
|
19122
|
-
catch (error) {
|
|
19123
|
-
const result = {
|
|
19124
|
-
action: 'cancel',
|
|
19125
|
-
status: 'error',
|
|
19126
|
-
message: error instanceof Error ? error.message : String(error),
|
|
19127
|
-
};
|
|
19128
|
-
return JSON.stringify(result);
|
|
19129
|
-
}
|
|
19130
|
-
},
|
|
19131
|
-
async [TimeoutToolNames.list](args) {
|
|
19132
|
-
const runtimeContext = resolveTimeoutRuntimeContext(args);
|
|
19133
|
-
const { adapter, disabledResult } = getTimeoutToolRuntimeAdapterOrDisabledResult('list', runtimeContext);
|
|
19134
|
-
if (!adapter || disabledResult) {
|
|
19135
|
-
return JSON.stringify(disabledResult);
|
|
19136
|
-
}
|
|
19137
|
-
try {
|
|
19138
|
-
const parsedArgs = parseTimeoutToolArgs.list(args);
|
|
19139
|
-
const listedTimeouts = await adapter.listTimeouts(parsedArgs, runtimeContext);
|
|
19140
|
-
const result = {
|
|
19141
|
-
action: 'list',
|
|
19142
|
-
status: 'listed',
|
|
19143
|
-
items: listedTimeouts.items,
|
|
19144
|
-
total: listedTimeouts.total,
|
|
19145
|
-
};
|
|
19146
|
-
return createToolExecutionEnvelope({
|
|
19147
|
-
assistantMessage: createListedTimeoutsAssistantMessage({
|
|
19148
|
-
total: listedTimeouts.total,
|
|
19149
|
-
items: listedTimeouts.items,
|
|
19150
|
-
}),
|
|
19151
|
-
toolResult: result,
|
|
19152
|
-
});
|
|
19153
|
-
}
|
|
19154
|
-
catch (error) {
|
|
19155
|
-
const result = {
|
|
19156
|
-
action: 'list',
|
|
19157
|
-
status: 'error',
|
|
19158
|
-
message: error instanceof Error ? error.message : String(error),
|
|
19159
|
-
};
|
|
19160
|
-
return JSON.stringify(result);
|
|
19161
|
-
}
|
|
19162
|
-
},
|
|
19163
|
-
async [TimeoutToolNames.update](args) {
|
|
19164
|
-
const runtimeContext = resolveTimeoutRuntimeContext(args);
|
|
19165
|
-
const { adapter, disabledResult } = getTimeoutToolRuntimeAdapterOrDisabledResult('update', runtimeContext);
|
|
19166
|
-
if (!adapter || disabledResult) {
|
|
19167
|
-
return JSON.stringify(disabledResult);
|
|
19168
|
-
}
|
|
19169
|
-
try {
|
|
19170
|
-
const parsedArgs = parseTimeoutToolArgs.update(args);
|
|
19171
|
-
const updatedTimeout = await adapter.updateTimeout(parsedArgs, runtimeContext);
|
|
19172
|
-
if (updatedTimeout.status === 'updated_all') {
|
|
19173
|
-
const result = {
|
|
19174
|
-
action: 'update',
|
|
19175
|
-
status: 'updated_all',
|
|
19176
|
-
updatedCount: updatedTimeout.updatedCount,
|
|
19177
|
-
matchedCount: updatedTimeout.matchedCount,
|
|
19178
|
-
updatedTimeoutIds: updatedTimeout.updatedTimeoutIds,
|
|
19179
|
-
hasMore: updatedTimeout.hasMore,
|
|
19180
|
-
};
|
|
19181
|
-
return createToolExecutionEnvelope({
|
|
19182
|
-
assistantMessage: createBulkUpdateAssistantMessage({
|
|
19183
|
-
paused: 'allActive' in parsedArgs && parsedArgs.allActive ? parsedArgs.paused : false,
|
|
19184
|
-
updatedCount: updatedTimeout.updatedCount,
|
|
19185
|
-
matchedCount: updatedTimeout.matchedCount,
|
|
19186
|
-
updatedTimeoutIds: updatedTimeout.updatedTimeoutIds,
|
|
19187
|
-
hasMore: updatedTimeout.hasMore,
|
|
19188
|
-
}),
|
|
19189
|
-
toolResult: result,
|
|
19190
|
-
});
|
|
19191
|
-
}
|
|
19192
|
-
if (updatedTimeout.status === 'not_found') {
|
|
19193
|
-
const result = {
|
|
19194
|
-
action: 'update',
|
|
19195
|
-
status: 'not_found',
|
|
19196
|
-
timeoutId: updatedTimeout.timeoutId,
|
|
19197
|
-
};
|
|
19198
|
-
return createToolExecutionEnvelope({
|
|
19199
|
-
assistantMessage: 'The timeout was not found.',
|
|
19200
|
-
toolResult: result,
|
|
19201
|
-
});
|
|
19202
|
-
}
|
|
19203
|
-
if (updatedTimeout.status === 'conflict') {
|
|
19204
|
-
const conflictMessage = updatedTimeout.reason === 'running'
|
|
19205
|
-
? 'Running timeout cannot be edited.'
|
|
19206
|
-
: 'Finished timeout cannot be edited.';
|
|
19207
|
-
const result = {
|
|
19208
|
-
action: 'update',
|
|
19209
|
-
status: 'conflict',
|
|
19210
|
-
timeoutId: updatedTimeout.timeoutId,
|
|
19211
|
-
message: conflictMessage,
|
|
19212
|
-
};
|
|
19213
|
-
return createToolExecutionEnvelope({
|
|
19214
|
-
assistantMessage: conflictMessage,
|
|
19215
|
-
toolResult: result,
|
|
19216
|
-
});
|
|
19217
|
-
}
|
|
19218
|
-
const result = {
|
|
19219
|
-
action: 'update',
|
|
19220
|
-
status: 'updated',
|
|
19221
|
-
timeoutId: updatedTimeout.timeout.timeoutId,
|
|
19222
|
-
dueAt: updatedTimeout.timeout.dueAt,
|
|
19223
|
-
paused: updatedTimeout.timeout.paused,
|
|
19224
|
-
recurrenceIntervalMs: updatedTimeout.timeout.recurrenceIntervalMs,
|
|
19225
|
-
};
|
|
19226
|
-
return createToolExecutionEnvelope({
|
|
19227
|
-
assistantMessage: `Updated timeout ${JSON.stringify(updatedTimeout.timeout.timeoutId)}.`,
|
|
19228
|
-
toolResult: result,
|
|
19229
|
-
});
|
|
19230
|
-
}
|
|
19231
|
-
catch (error) {
|
|
19232
|
-
const result = {
|
|
19233
|
-
action: 'update',
|
|
19234
|
-
status: 'error',
|
|
19235
|
-
message: error instanceof Error ? error.message : String(error),
|
|
19236
|
-
};
|
|
19237
|
-
return JSON.stringify(result);
|
|
19238
|
-
}
|
|
19239
|
-
},
|
|
19240
|
-
};
|
|
19241
|
-
}
|
|
19242
|
-
/**
|
|
19243
|
-
* Creates assistant-visible summary for one `list_timeouts` response.
|
|
19244
|
-
*
|
|
19245
|
-
* @private internal utility of USE TIMEOUT
|
|
19246
|
-
*/
|
|
19247
|
-
function createListedTimeoutsAssistantMessage(options) {
|
|
19248
|
-
if (options.total <= 0 || options.items.length === 0) {
|
|
19249
|
-
return 'Found 0 timeouts.';
|
|
19250
|
-
}
|
|
19251
|
-
const visibleItems = options.items.slice(0, MAX_ASSISTANT_VISIBLE_TIMEOUT_ROWS);
|
|
19252
|
-
const summaryRows = visibleItems.map((item, index) => `${index + 1}. ${formatTimeoutListRow(item)}`);
|
|
19253
|
-
const hiddenCount = Math.max(0, options.total - visibleItems.length);
|
|
19254
|
-
if (hiddenCount > 0) {
|
|
19255
|
-
summaryRows.push(`...and ${hiddenCount} more.`);
|
|
19256
|
-
}
|
|
19257
|
-
return spaceTrim$1((block) => `
|
|
19258
|
-
Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
|
|
19259
|
-
${block(summaryRows.join('\n'))}
|
|
19260
|
-
`);
|
|
19261
|
-
}
|
|
19262
|
-
/**
|
|
19263
|
-
* Formats one timeout row for assistant-visible timeout listings.
|
|
19264
|
-
*
|
|
19265
|
-
* @private internal utility of USE TIMEOUT
|
|
19266
|
-
*/
|
|
19267
|
-
function formatTimeoutListRow(item) {
|
|
19268
|
-
const normalizedMessage = typeof item.message === 'string' ? item.message.trim() : '';
|
|
19269
|
-
const messageSuffix = normalizedMessage ? ` | message ${JSON.stringify(normalizedMessage)}` : '';
|
|
19270
|
-
const recurrenceSuffix = typeof item.recurrenceIntervalMs === 'number' && item.recurrenceIntervalMs > 0
|
|
19271
|
-
? ` | recurrence ${item.recurrenceIntervalMs}ms`
|
|
19272
|
-
: '';
|
|
19273
|
-
const pausedSuffix = item.paused ? ' (paused)' : '';
|
|
19274
|
-
return `${item.timeoutId} | ${item.status}${pausedSuffix} | chat ${item.chatId} | due ${item.dueAt}${recurrenceSuffix}${messageSuffix}`;
|
|
19275
|
-
}
|
|
19276
|
-
/**
|
|
19277
|
-
* Creates assistant-visible summary for bulk timeout cancellation.
|
|
19278
|
-
*
|
|
19279
|
-
* @private internal utility of USE TIMEOUT
|
|
19280
|
-
*/
|
|
19281
|
-
function createBulkCancelAssistantMessage(options) {
|
|
19282
|
-
if (options.cancelledCount <= 0) {
|
|
19283
|
-
return 'No active timeouts were found to cancel.';
|
|
19284
|
-
}
|
|
19285
|
-
const visibleTimeoutIds = options.cancelledTimeoutIds.slice(0, MAX_ASSISTANT_VISIBLE_BULK_TIMEOUT_IDS);
|
|
19286
|
-
const hiddenIdsCount = Math.max(0, options.cancelledTimeoutIds.length - visibleTimeoutIds.length);
|
|
19287
|
-
const hasMoreSuffix = options.hasMore ? ' Additional active timeouts may still exist.' : '';
|
|
19288
|
-
const idsSuffix = visibleTimeoutIds.length > 0
|
|
19289
|
-
? ` Cancelled ids: ${visibleTimeoutIds.join(', ')}${hiddenIdsCount > 0 ? `, and ${hiddenIdsCount} more.` : '.'}`
|
|
19290
|
-
: '';
|
|
19291
|
-
return `Cancelled ${options.cancelledCount} active ${options.cancelledCount === 1 ? 'timeout' : 'timeouts'}.${idsSuffix}${hasMoreSuffix}`;
|
|
19292
|
-
}
|
|
19293
|
-
/**
|
|
19294
|
-
* Creates assistant-visible summary for bulk timeout pause/resume updates.
|
|
19295
|
-
*
|
|
19296
|
-
* @private internal utility of USE TIMEOUT
|
|
19297
|
-
*/
|
|
19298
|
-
function createBulkUpdateAssistantMessage(options) {
|
|
19299
|
-
if (options.matchedCount <= 0) {
|
|
19300
|
-
return options.paused
|
|
19301
|
-
? 'No active queued timeouts were found to pause.'
|
|
19302
|
-
: 'No paused queued timeouts were found to resume.';
|
|
19303
|
-
}
|
|
19304
|
-
const verb = options.paused ? 'Paused' : 'Resumed';
|
|
19305
|
-
const visibleTimeoutIds = options.updatedTimeoutIds.slice(0, MAX_ASSISTANT_VISIBLE_BULK_TIMEOUT_IDS);
|
|
19306
|
-
const hiddenIdsCount = Math.max(0, options.updatedTimeoutIds.length - visibleTimeoutIds.length);
|
|
19307
|
-
const skippedCount = Math.max(0, options.matchedCount - options.updatedCount);
|
|
19308
|
-
const idsSuffix = visibleTimeoutIds.length > 0
|
|
19309
|
-
? ` Updated ids: ${visibleTimeoutIds.join(', ')}${hiddenIdsCount > 0 ? `, and ${hiddenIdsCount} more.` : '.'}`
|
|
19310
|
-
: '';
|
|
19311
|
-
const skippedSuffix = skippedCount > 0 ? ` Skipped ${skippedCount} due to concurrent changes.` : '';
|
|
19312
|
-
const hasMoreSuffix = options.hasMore ? ' Additional matching timeouts may still exist.' : '';
|
|
19313
|
-
return `${verb} ${options.updatedCount} ${options.updatedCount === 1 ? 'timeout' : 'timeouts'}.${idsSuffix}${skippedSuffix}${hasMoreSuffix}`;
|
|
19314
|
-
}
|
|
19315
|
-
|
|
19316
|
-
/**
|
|
19317
|
-
* Adds `USE TIMEOUT` tool definitions while preserving already registered tools.
|
|
19318
|
-
*
|
|
19319
|
-
* @private internal utility of USE TIMEOUT
|
|
19320
|
-
*/
|
|
19321
|
-
function createTimeoutTools(existingTools = []) {
|
|
19322
|
-
const tools = [...existingTools];
|
|
19323
|
-
if (!tools.some((tool) => tool.name === TimeoutToolNames.set)) {
|
|
19324
|
-
tools.push({
|
|
19325
|
-
name: TimeoutToolNames.set,
|
|
19326
|
-
description: 'Schedule one thread-scoped wake-up in the current chat. The timer returns immediately and wakes this same conversation later.',
|
|
19327
|
-
parameters: {
|
|
19328
|
-
type: 'object',
|
|
19329
|
-
properties: {
|
|
19330
|
-
milliseconds: {
|
|
19331
|
-
type: 'number',
|
|
19332
|
-
description: 'Delay in milliseconds before the timeout wakes the same chat thread.',
|
|
19333
|
-
},
|
|
19334
|
-
message: {
|
|
19335
|
-
type: 'string',
|
|
19336
|
-
description: 'Optional note appended to the future timeout wake-up message.',
|
|
19337
|
-
},
|
|
19338
|
-
},
|
|
19339
|
-
required: ['milliseconds'],
|
|
19340
|
-
},
|
|
19341
|
-
});
|
|
19342
|
-
}
|
|
19343
|
-
if (!tools.some((tool) => tool.name === TimeoutToolNames.cancel)) {
|
|
19344
|
-
tools.push({
|
|
19345
|
-
name: TimeoutToolNames.cancel,
|
|
19346
|
-
description: 'Cancel one timeout by id or cancel all active timeouts across chats for the same user+agent scope.',
|
|
19347
|
-
parameters: {
|
|
19348
|
-
type: 'object',
|
|
19349
|
-
properties: {
|
|
19350
|
-
timeoutId: {
|
|
19351
|
-
type: 'string',
|
|
19352
|
-
description: 'Identifier returned earlier by `set_timeout` or `list_timeouts`.',
|
|
19353
|
-
},
|
|
19354
|
-
allActive: {
|
|
19355
|
-
type: 'boolean',
|
|
19356
|
-
description: 'When true, cancel all currently active timeouts across chats in this user+agent scope.',
|
|
19357
|
-
},
|
|
19358
|
-
},
|
|
19359
|
-
},
|
|
19360
|
-
});
|
|
19361
|
-
}
|
|
19362
|
-
if (!tools.some((tool) => tool.name === TimeoutToolNames.list)) {
|
|
19363
|
-
tools.push({
|
|
19364
|
-
name: TimeoutToolNames.list,
|
|
19365
|
-
description: 'List timeout details across all chats for this same user+agent scope so they can be reviewed and managed.',
|
|
19366
|
-
parameters: {
|
|
19367
|
-
type: 'object',
|
|
19368
|
-
properties: {
|
|
19369
|
-
includeFinished: {
|
|
19370
|
-
type: 'boolean',
|
|
19371
|
-
description: 'When true, include completed, failed, and cancelled rows in addition to active timeouts.',
|
|
19372
|
-
},
|
|
19373
|
-
limit: {
|
|
19374
|
-
type: 'number',
|
|
19375
|
-
description: 'Maximum number of rows to return (default 20, max 100).',
|
|
19376
|
-
},
|
|
19377
|
-
},
|
|
19378
|
-
},
|
|
19379
|
-
});
|
|
19380
|
-
}
|
|
19381
|
-
if (!tools.some((tool) => tool.name === TimeoutToolNames.update)) {
|
|
19382
|
-
tools.push({
|
|
19383
|
-
name: TimeoutToolNames.update,
|
|
19384
|
-
description: 'Update one timeout (pause/resume, next run, recurrence, payload) or pause/resume all active queued timeouts across chats.',
|
|
19385
|
-
parameters: {
|
|
19386
|
-
type: 'object',
|
|
19387
|
-
properties: {
|
|
19388
|
-
timeoutId: {
|
|
19389
|
-
type: 'string',
|
|
19390
|
-
description: 'Identifier returned earlier by `set_timeout` or `list_timeouts` for one timeout update.',
|
|
19391
|
-
},
|
|
19392
|
-
allActive: {
|
|
19393
|
-
type: 'boolean',
|
|
19394
|
-
description: 'When true, run one bulk pause/resume across all active queued timeouts in this same user+agent scope.',
|
|
19395
|
-
},
|
|
19396
|
-
paused: {
|
|
19397
|
-
type: 'boolean',
|
|
19398
|
-
description: 'Pause (`true`) or resume (`false`) one timeout; with `allActive: true` this pauses/resumes all active queued timeouts.',
|
|
19399
|
-
},
|
|
19400
|
-
dueAt: {
|
|
19401
|
-
type: 'string',
|
|
19402
|
-
description: 'Set the next run timestamp (ISO string). Cannot be used with `extendByMs`.',
|
|
19403
|
-
},
|
|
19404
|
-
extendByMs: {
|
|
19405
|
-
type: 'number',
|
|
19406
|
-
description: 'Move next run by this many milliseconds. Cannot be used with `dueAt`.',
|
|
19407
|
-
},
|
|
19408
|
-
recurrenceIntervalMs: {
|
|
19409
|
-
type: 'number',
|
|
19410
|
-
description: 'Set recurrence interval in milliseconds; pass `null` to disable recurrence.',
|
|
19411
|
-
},
|
|
19412
|
-
message: {
|
|
19413
|
-
type: 'string',
|
|
19414
|
-
description: 'Set wake-up message text for this timeout; pass empty string to clear.',
|
|
19415
|
-
},
|
|
19416
|
-
parameters: {
|
|
19417
|
-
type: 'object',
|
|
19418
|
-
description: 'Replace stored JSON parameters passed back when timeout fires.',
|
|
19419
|
-
},
|
|
19420
|
-
},
|
|
19421
|
-
},
|
|
19422
|
-
});
|
|
19423
|
-
}
|
|
19424
|
-
return tools;
|
|
19425
|
-
}
|
|
19426
|
-
|
|
19427
|
-
/**
|
|
19428
|
-
* `USE TIMEOUT` commitment definition.
|
|
19429
|
-
*
|
|
19430
|
-
* The `USE TIMEOUT` commitment enables timeout wake-ups and scoped timeout management.
|
|
19431
|
-
*
|
|
19432
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
19433
|
-
*/
|
|
19434
|
-
class UseTimeoutCommitmentDefinition extends BaseCommitmentDefinition {
|
|
19435
|
-
constructor() {
|
|
19436
|
-
super('USE TIMEOUT');
|
|
19437
|
-
}
|
|
19438
|
-
get requiresContent() {
|
|
19439
|
-
return false;
|
|
19440
|
-
}
|
|
19441
|
-
/**
|
|
19442
|
-
* Short one-line description of `USE TIMEOUT`.
|
|
19443
|
-
*/
|
|
19444
|
-
get description() {
|
|
19445
|
-
return 'Enable timeout wake-ups plus scoped timeout listing, updates, and cancellation across chats.';
|
|
19446
|
-
}
|
|
19447
|
-
/**
|
|
19448
|
-
* Icon for this commitment.
|
|
19449
|
-
*/
|
|
19450
|
-
get icon() {
|
|
19451
|
-
return '⏱️';
|
|
19452
|
-
}
|
|
19453
|
-
/**
|
|
19454
|
-
* Markdown documentation for `USE TIMEOUT`.
|
|
19455
|
-
*/
|
|
19456
|
-
get documentation() {
|
|
19457
|
-
return spaceTrim$1(`
|
|
19458
|
-
# USE TIMEOUT
|
|
19459
|
-
|
|
19460
|
-
Enables timeout wake-ups and timeout management for the same user+agent scope.
|
|
19461
|
-
|
|
19462
|
-
## Key aspects
|
|
19463
|
-
|
|
19464
|
-
- The agent uses \`set_timeout\` to schedule a future wake-up in the same chat thread.
|
|
19465
|
-
- The tool returns immediately while the timeout is stored and executed by the runtime later.
|
|
19466
|
-
- The wake-up arrives as a new user-like timeout message in the same conversation.
|
|
19467
|
-
- The agent can inspect known timeout details via \`list_timeouts\`.
|
|
19468
|
-
- The agent can cancel one timeout by \`timeoutId\` or cancel all active timeouts via \`cancel_timeout\`.
|
|
19469
|
-
- The agent can pause/resume and edit timeout details via \`update_timeout\`.
|
|
19470
|
-
- Commitment content is treated as optional timeout policy instructions.
|
|
19471
|
-
|
|
19472
|
-
## Examples
|
|
19473
|
-
|
|
19474
|
-
\`\`\`book
|
|
19475
|
-
Follow-up Agent
|
|
19476
|
-
USE TIMEOUT Remind yourself only when follow-up work is explicitly requested.
|
|
19477
|
-
\`\`\`
|
|
19478
|
-
`);
|
|
19479
|
-
}
|
|
19480
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
19481
|
-
const extraInstructions = formatOptionalInstructionBlock('Timeout instructions', content);
|
|
19482
|
-
return this.appendToSystemMessage({
|
|
19483
|
-
...requirements,
|
|
19484
|
-
tools: createTimeoutTools(requirements.tools || []),
|
|
19485
|
-
_metadata: {
|
|
19486
|
-
...requirements._metadata,
|
|
19487
|
-
useTimeout: content || true,
|
|
19488
|
-
},
|
|
19489
|
-
}, createTimeoutSystemMessage(extraInstructions));
|
|
19490
|
-
}
|
|
19491
|
-
/**
|
|
19492
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
19493
|
-
*/
|
|
19494
|
-
getToolTitles() {
|
|
19495
|
-
return {
|
|
19496
|
-
[TimeoutToolNames.set]: 'Set timer',
|
|
19497
|
-
[TimeoutToolNames.cancel]: 'Cancel timer',
|
|
19498
|
-
[TimeoutToolNames.list]: 'List timers',
|
|
19499
|
-
[TimeoutToolNames.update]: 'Update timer',
|
|
19500
|
-
};
|
|
19501
|
-
}
|
|
19502
|
-
/**
|
|
19503
|
-
* Gets `USE TIMEOUT` tool function implementations.
|
|
19504
|
-
*/
|
|
19505
|
-
getToolFunctions() {
|
|
19506
|
-
return createTimeoutToolFunctions();
|
|
19507
|
-
}
|
|
19508
|
-
}
|
|
19509
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
19510
|
-
|
|
19511
|
-
/**
|
|
19512
|
-
* USE TIME commitment definition
|
|
19513
|
-
*
|
|
19514
|
-
* The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
|
|
19515
|
-
*
|
|
19516
|
-
* Example usage in agent source:
|
|
19517
|
-
*
|
|
19518
|
-
* ```book
|
|
19519
|
-
* USE TIME
|
|
19520
|
-
* USE TIME Prefer the user's local timezone.
|
|
19521
|
-
* ```
|
|
19522
|
-
*
|
|
19523
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
19524
|
-
*/
|
|
19525
|
-
class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
19526
|
-
constructor() {
|
|
19527
|
-
super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
|
|
19528
|
-
}
|
|
19529
|
-
get requiresContent() {
|
|
19530
|
-
return false;
|
|
19531
|
-
}
|
|
19532
|
-
/**
|
|
19533
|
-
* Short one-line description of USE TIME.
|
|
19534
|
-
*/
|
|
19535
|
-
get description() {
|
|
19536
|
-
return 'Enable the agent to determine the current date and time.';
|
|
19537
|
-
}
|
|
19538
|
-
/**
|
|
19539
|
-
* Icon for this commitment.
|
|
19540
|
-
*/
|
|
19541
|
-
get icon() {
|
|
19542
|
-
return '🕒';
|
|
19543
|
-
}
|
|
19544
|
-
/**
|
|
19545
|
-
* Markdown documentation for USE TIME commitment.
|
|
19546
|
-
*/
|
|
19547
|
-
get documentation() {
|
|
19548
|
-
return spaceTrim$1(`
|
|
19549
|
-
# USE TIME
|
|
19550
|
-
|
|
19551
|
-
Enables the agent to determine the current date and time.
|
|
19552
|
-
|
|
19553
|
-
## Key aspects
|
|
19554
|
-
|
|
19555
|
-
- This tool won't receive any input.
|
|
19556
|
-
- It outputs the current date and time as an ISO 8601 string.
|
|
19557
|
-
- Allows the agent to answer questions about the current time or date.
|
|
19558
|
-
- The content following \`USE TIME\` is an arbitrary text that the agent should know (e.g. timezone preference).
|
|
19559
|
-
|
|
19560
|
-
## Examples
|
|
19561
|
-
|
|
19562
|
-
\`\`\`book
|
|
19563
|
-
Time-aware Assistant
|
|
19564
|
-
|
|
19565
|
-
PERSONA You are a helpful assistant who knows the current time.
|
|
19566
|
-
USE TIME
|
|
19567
|
-
\`\`\`
|
|
19568
|
-
|
|
19569
|
-
\`\`\`book
|
|
19570
|
-
Travel Assistant
|
|
19571
|
-
|
|
19572
|
-
PERSONA You help travelers with planning.
|
|
19573
|
-
USE TIME Prefer the user's local timezone.
|
|
19574
|
-
\`\`\`
|
|
19575
|
-
`);
|
|
19576
|
-
}
|
|
19577
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
19578
|
-
// Get existing tools array or create new one
|
|
19579
|
-
const existingTools = requirements.tools || [];
|
|
19580
|
-
// Add 'get_current_time' to tools if not already present
|
|
19581
|
-
const updatedTools = existingTools.some((tool) => tool.name === 'get_current_time')
|
|
19582
|
-
? existingTools
|
|
19583
|
-
: [
|
|
19584
|
-
...existingTools,
|
|
19585
|
-
{
|
|
19586
|
-
name: 'get_current_time',
|
|
19587
|
-
description: 'Get the current date and time in ISO 8601 format.',
|
|
19588
|
-
parameters: {
|
|
19589
|
-
type: 'object',
|
|
19590
|
-
properties: {
|
|
19591
|
-
timezone: {
|
|
19592
|
-
type: 'string',
|
|
19593
|
-
description: 'Optional timezone name (e.g. "Europe/Prague", "UTC", "America/New_York").',
|
|
19594
|
-
},
|
|
19595
|
-
},
|
|
19596
|
-
required: [],
|
|
19597
|
-
},
|
|
19598
|
-
},
|
|
19599
|
-
// <- TODO: !!!! define the function in LLM tools
|
|
19600
|
-
];
|
|
19601
|
-
return appendAggregatedUseCommitmentPlaceholder({
|
|
19602
|
-
...requirements,
|
|
19603
|
-
tools: updatedTools,
|
|
19604
|
-
_metadata: {
|
|
19605
|
-
...requirements._metadata,
|
|
19606
|
-
},
|
|
19607
|
-
}, this.type);
|
|
19608
|
-
}
|
|
19609
|
-
/**
|
|
19610
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
19611
|
-
*/
|
|
19612
|
-
getToolTitles() {
|
|
19613
|
-
return {
|
|
19614
|
-
get_current_time: 'Get current time',
|
|
19615
|
-
};
|
|
19616
|
-
}
|
|
19617
|
-
/**
|
|
19618
|
-
* Gets the `get_current_time` tool function implementation.
|
|
19619
|
-
*/
|
|
19620
|
-
getToolFunctions() {
|
|
19621
|
-
return {
|
|
19622
|
-
async get_current_time(args) {
|
|
19623
|
-
var _a;
|
|
19624
|
-
console.log('!!!! [Tool] get_current_time called', { args });
|
|
19625
|
-
const { timezone } = args;
|
|
19626
|
-
if (!timezone) {
|
|
19627
|
-
return new Date().toISOString();
|
|
19628
|
-
}
|
|
19629
|
-
try {
|
|
19630
|
-
// Note: Returning ISO 8601 string but in the requested timezone
|
|
19631
|
-
const formatter = new Intl.DateTimeFormat('en-CA', {
|
|
19632
|
-
timeZone: timezone,
|
|
19633
|
-
year: 'numeric',
|
|
19634
|
-
month: '2-digit',
|
|
19635
|
-
day: '2-digit',
|
|
19636
|
-
hour: '2-digit',
|
|
19637
|
-
minute: '2-digit',
|
|
19638
|
-
second: '2-digit',
|
|
19639
|
-
hour12: false,
|
|
19640
|
-
timeZoneName: 'shortOffset',
|
|
19641
|
-
});
|
|
19642
|
-
const parts = formatter.formatToParts(new Date());
|
|
19643
|
-
const part = (type) => { var _a; return (_a = parts.find((p) => p.type === type)) === null || _a === void 0 ? void 0 : _a.value; };
|
|
19644
|
-
// en-CA format is YYYY-MM-DD
|
|
19645
|
-
const isoString = `${part('year')}-${part('month')}-${part('day')}T${part('hour')}:${part('minute')}:${part('second')}${(_a = part('timeZoneName')) === null || _a === void 0 ? void 0 : _a.replace('GMT', '')}`;
|
|
19646
|
-
return isoString;
|
|
19647
|
-
}
|
|
19648
|
-
catch (error) {
|
|
19649
|
-
// Fallback to UTC if timezone is invalid
|
|
19650
|
-
return new Date().toISOString();
|
|
19651
|
-
}
|
|
19652
|
-
},
|
|
19653
|
-
};
|
|
19654
|
-
}
|
|
19655
|
-
}
|
|
19656
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
19657
|
-
|
|
19658
16718
|
/**
|
|
19659
16719
|
* Tool name used by the USE USER LOCATION commitment.
|
|
19660
16720
|
*
|
|
@@ -19869,580 +16929,6 @@ class UseUserLocationCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19869
16929
|
}
|
|
19870
16930
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
19871
16931
|
|
|
19872
|
-
/**
|
|
19873
|
-
* Names of tools used by the WALLET commitment.
|
|
19874
|
-
*
|
|
19875
|
-
* @private constant of WalletCommitmentDefinition
|
|
19876
|
-
*/
|
|
19877
|
-
const WalletToolNames = {
|
|
19878
|
-
retrieve: 'retrieve_wallet_records',
|
|
19879
|
-
store: 'store_wallet_record',
|
|
19880
|
-
update: 'update_wallet_record',
|
|
19881
|
-
delete: 'delete_wallet_record',
|
|
19882
|
-
request: 'request_wallet_record',
|
|
19883
|
-
};
|
|
19884
|
-
|
|
19885
|
-
/**
|
|
19886
|
-
* Creates WALLET system-message instructions.
|
|
19887
|
-
*
|
|
19888
|
-
* @private function of WalletCommitmentDefinition
|
|
19889
|
-
*/
|
|
19890
|
-
function createWalletSystemMessage(extraInstructions) {
|
|
19891
|
-
return spaceTrim$1((block) => `
|
|
19892
|
-
Wallet:
|
|
19893
|
-
- Use "${WalletToolNames.retrieve}" before authenticated operations.
|
|
19894
|
-
- Use "${WalletToolNames.store}" and "${WalletToolNames.update}" to maintain credentials.
|
|
19895
|
-
- Use "${WalletToolNames.delete}" to remove invalid credentials.
|
|
19896
|
-
- Use "${WalletToolNames.request}" to request missing credentials via UI popup.
|
|
19897
|
-
- Scope records by user (\`isUserScoped\`) and/or by agent (\`isGlobal=false\`) as needed.
|
|
19898
|
-
- Never expose raw credentials in chat responses.
|
|
19899
|
-
${block(extraInstructions)}
|
|
19900
|
-
`);
|
|
19901
|
-
}
|
|
19902
|
-
|
|
19903
|
-
/**
|
|
19904
|
-
* Resolves disabled message for wallet runtime context.
|
|
19905
|
-
*
|
|
19906
|
-
* @private function of WalletCommitmentDefinition
|
|
19907
|
-
*/
|
|
19908
|
-
function resolveWalletDisabledMessage(runtimeContext) {
|
|
19909
|
-
if (runtimeContext.isPrivateMode) {
|
|
19910
|
-
return 'Wallet is disabled because private mode is active.';
|
|
19911
|
-
}
|
|
19912
|
-
if (runtimeContext.isTeamConversation) {
|
|
19913
|
-
return 'Wallet is disabled for TEAM conversations.';
|
|
19914
|
-
}
|
|
19915
|
-
if (!runtimeContext.enabled) {
|
|
19916
|
-
return 'Wallet is disabled for unauthenticated users.';
|
|
19917
|
-
}
|
|
19918
|
-
return null;
|
|
19919
|
-
}
|
|
19920
|
-
/**
|
|
19921
|
-
* Resolves runtime adapter for wallet tools or returns disabled payload when unavailable.
|
|
19922
|
-
*
|
|
19923
|
-
* @private function of WalletCommitmentDefinition
|
|
19924
|
-
*/
|
|
19925
|
-
function getWalletToolRuntimeAdapterOrDisabledResult(action, runtimeContext) {
|
|
19926
|
-
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
19927
|
-
if (disabledMessage) {
|
|
19928
|
-
return {
|
|
19929
|
-
adapter: null,
|
|
19930
|
-
disabledResult: {
|
|
19931
|
-
action,
|
|
19932
|
-
status: 'disabled',
|
|
19933
|
-
records: action === 'retrieve' ? [] : undefined,
|
|
19934
|
-
message: disabledMessage,
|
|
19935
|
-
},
|
|
19936
|
-
};
|
|
19937
|
-
}
|
|
19938
|
-
{
|
|
19939
|
-
return {
|
|
19940
|
-
adapter: null,
|
|
19941
|
-
disabledResult: {
|
|
19942
|
-
action,
|
|
19943
|
-
status: 'disabled',
|
|
19944
|
-
records: action === 'retrieve' ? [] : undefined,
|
|
19945
|
-
message: 'Wallet runtime is not available in this environment.',
|
|
19946
|
-
},
|
|
19947
|
-
};
|
|
19948
|
-
}
|
|
19949
|
-
}
|
|
19950
|
-
|
|
19951
|
-
/**
|
|
19952
|
-
* Parses store/update wallet payload.
|
|
19953
|
-
*
|
|
19954
|
-
* @private function of WalletCommitmentDefinition
|
|
19955
|
-
*/
|
|
19956
|
-
function parseWalletPayload(args) {
|
|
19957
|
-
const recordType = parseWalletRecordType(args.recordType);
|
|
19958
|
-
return {
|
|
19959
|
-
recordType,
|
|
19960
|
-
service: parseWalletService(args.service),
|
|
19961
|
-
key: parseWalletKey(args.key),
|
|
19962
|
-
isUserScoped: args.isUserScoped === true,
|
|
19963
|
-
isGlobal: args.isGlobal === true,
|
|
19964
|
-
...parseWalletSecrets({
|
|
19965
|
-
recordType,
|
|
19966
|
-
username: args.username,
|
|
19967
|
-
password: args.password,
|
|
19968
|
-
secret: args.secret,
|
|
19969
|
-
cookies: args.cookies,
|
|
19970
|
-
}),
|
|
19971
|
-
};
|
|
19972
|
-
}
|
|
19973
|
-
/**
|
|
19974
|
-
* Parses text argument and returns trimmed text when available.
|
|
19975
|
-
*
|
|
19976
|
-
* @private function of WalletCommitmentDefinition
|
|
19977
|
-
*/
|
|
19978
|
-
function normalizeOptionalText(value) {
|
|
19979
|
-
if (typeof value !== 'string') {
|
|
19980
|
-
return undefined;
|
|
19981
|
-
}
|
|
19982
|
-
const trimmed = value.trim();
|
|
19983
|
-
return trimmed || undefined;
|
|
19984
|
-
}
|
|
19985
|
-
/**
|
|
19986
|
-
* Parses wallet service argument.
|
|
19987
|
-
*
|
|
19988
|
-
* @private function of WalletCommitmentDefinition
|
|
19989
|
-
*/
|
|
19990
|
-
function parseWalletService(value) {
|
|
19991
|
-
return (normalizeOptionalText(value) || 'generic').toLowerCase();
|
|
19992
|
-
}
|
|
19993
|
-
/**
|
|
19994
|
-
* Parses wallet key argument.
|
|
19995
|
-
*
|
|
19996
|
-
* @private function of WalletCommitmentDefinition
|
|
19997
|
-
*/
|
|
19998
|
-
function parseWalletKey(value) {
|
|
19999
|
-
return normalizeOptionalText(value) || 'default';
|
|
20000
|
-
}
|
|
20001
|
-
/**
|
|
20002
|
-
* Parses one wallet record id argument.
|
|
20003
|
-
*
|
|
20004
|
-
* @private function of WalletCommitmentDefinition
|
|
20005
|
-
*/
|
|
20006
|
-
function parseWalletId(value) {
|
|
20007
|
-
const walletId = normalizeOptionalText(value);
|
|
20008
|
-
if (!walletId) {
|
|
20009
|
-
throw new Error('Wallet id is required.');
|
|
20010
|
-
}
|
|
20011
|
-
return walletId;
|
|
20012
|
-
}
|
|
20013
|
-
/**
|
|
20014
|
-
* Parses wallet record type.
|
|
20015
|
-
*
|
|
20016
|
-
* @private function of WalletCommitmentDefinition
|
|
20017
|
-
*/
|
|
20018
|
-
function parseWalletRecordType(value, fallback) {
|
|
20019
|
-
var _a;
|
|
20020
|
-
const normalizedType = (_a = normalizeOptionalText(value)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
20021
|
-
if (normalizedType === 'USERNAME_PASSWORD') {
|
|
20022
|
-
return 'USERNAME_PASSWORD';
|
|
20023
|
-
}
|
|
20024
|
-
if (normalizedType === 'SESSION_COOKIE') {
|
|
20025
|
-
return 'SESSION_COOKIE';
|
|
20026
|
-
}
|
|
20027
|
-
if (normalizedType === 'ACCESS_TOKEN') {
|
|
20028
|
-
return 'ACCESS_TOKEN';
|
|
20029
|
-
}
|
|
20030
|
-
if (fallback) {
|
|
20031
|
-
return fallback;
|
|
20032
|
-
}
|
|
20033
|
-
throw new Error('Unsupported wallet recordType. Expected one of: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.');
|
|
20034
|
-
}
|
|
20035
|
-
/**
|
|
20036
|
-
* Parses wallet secret fields according to record type.
|
|
20037
|
-
*
|
|
20038
|
-
* @private function of WalletCommitmentDefinition
|
|
20039
|
-
*/
|
|
20040
|
-
function parseWalletSecrets(args) {
|
|
20041
|
-
const username = normalizeOptionalText(args.username);
|
|
20042
|
-
const password = normalizeOptionalText(args.password);
|
|
20043
|
-
const secret = normalizeOptionalText(args.secret);
|
|
20044
|
-
const cookies = normalizeOptionalText(args.cookies);
|
|
20045
|
-
if (args.recordType === 'USERNAME_PASSWORD') {
|
|
20046
|
-
if (!username || !password) {
|
|
20047
|
-
throw new Error('Both username and password are required for USERNAME_PASSWORD.');
|
|
20048
|
-
}
|
|
20049
|
-
return { username, password };
|
|
20050
|
-
}
|
|
20051
|
-
if (args.recordType === 'SESSION_COOKIE') {
|
|
20052
|
-
if (!cookies) {
|
|
20053
|
-
throw new Error('Cookies are required for SESSION_COOKIE.');
|
|
20054
|
-
}
|
|
20055
|
-
return { cookies };
|
|
20056
|
-
}
|
|
20057
|
-
if (!secret) {
|
|
20058
|
-
throw new Error('Secret is required for ACCESS_TOKEN.');
|
|
20059
|
-
}
|
|
20060
|
-
return { secret };
|
|
20061
|
-
}
|
|
20062
|
-
/**
|
|
20063
|
-
* Collection of WALLET tool argument parsers.
|
|
20064
|
-
*
|
|
20065
|
-
* @private function of WalletCommitmentDefinition
|
|
20066
|
-
*/
|
|
20067
|
-
const parseWalletToolArgs = {
|
|
20068
|
-
/**
|
|
20069
|
-
* Parses retrieve arguments.
|
|
20070
|
-
*/
|
|
20071
|
-
retrieve(args) {
|
|
20072
|
-
const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : undefined;
|
|
20073
|
-
return {
|
|
20074
|
-
query: normalizeOptionalText(args.query),
|
|
20075
|
-
recordType: normalizeOptionalText(args.recordType) ? parseWalletRecordType(args.recordType) : undefined,
|
|
20076
|
-
service: normalizeOptionalText(args.service) ? parseWalletService(args.service) : undefined,
|
|
20077
|
-
key: normalizeOptionalText(args.key) ? parseWalletKey(args.key) : undefined,
|
|
20078
|
-
limit: limit && limit > 0 ? Math.min(limit, 20) : undefined,
|
|
20079
|
-
};
|
|
20080
|
-
},
|
|
20081
|
-
/**
|
|
20082
|
-
* Parses store payload.
|
|
20083
|
-
*/
|
|
20084
|
-
store(args) {
|
|
20085
|
-
return parseWalletPayload(args);
|
|
20086
|
-
},
|
|
20087
|
-
/**
|
|
20088
|
-
* Parses update payload.
|
|
20089
|
-
*/
|
|
20090
|
-
update(args) {
|
|
20091
|
-
const walletId = parseWalletId(args.walletId);
|
|
20092
|
-
const record = parseWalletPayload(args);
|
|
20093
|
-
return {
|
|
20094
|
-
...record,
|
|
20095
|
-
walletId,
|
|
20096
|
-
};
|
|
20097
|
-
},
|
|
20098
|
-
/**
|
|
20099
|
-
* Parses delete payload.
|
|
20100
|
-
*/
|
|
20101
|
-
delete(args) {
|
|
20102
|
-
return { walletId: parseWalletId(args.walletId) };
|
|
20103
|
-
},
|
|
20104
|
-
/**
|
|
20105
|
-
* Parses request payload for user wallet input prompt.
|
|
20106
|
-
*/
|
|
20107
|
-
request(args) {
|
|
20108
|
-
return {
|
|
20109
|
-
recordType: parseWalletRecordType(args.recordType, 'ACCESS_TOKEN'),
|
|
20110
|
-
service: parseWalletService(args.service),
|
|
20111
|
-
key: parseWalletKey(args.key),
|
|
20112
|
-
message: normalizeOptionalText(args.message),
|
|
20113
|
-
isUserScoped: args.isUserScoped === true,
|
|
20114
|
-
isGlobal: args.isGlobal === true,
|
|
20115
|
-
};
|
|
20116
|
-
},
|
|
20117
|
-
};
|
|
20118
|
-
|
|
20119
|
-
/**
|
|
20120
|
-
* Resolves runtime context from hidden tool arguments.
|
|
20121
|
-
*
|
|
20122
|
-
* @private function of WalletCommitmentDefinition
|
|
20123
|
-
*/
|
|
20124
|
-
function resolveWalletRuntimeContext(args) {
|
|
20125
|
-
const runtimeContext = readToolRuntimeContextFromToolArgs(args);
|
|
20126
|
-
const memoryContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.memory;
|
|
20127
|
-
return {
|
|
20128
|
-
enabled: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.enabled) === true,
|
|
20129
|
-
userId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.userId,
|
|
20130
|
-
username: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.username,
|
|
20131
|
-
agentId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentId,
|
|
20132
|
-
agentName: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentName,
|
|
20133
|
-
isTeamConversation: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isTeamConversation) === true,
|
|
20134
|
-
isPrivateMode: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isPrivateMode) === true,
|
|
20135
|
-
};
|
|
20136
|
-
}
|
|
20137
|
-
|
|
20138
|
-
/**
|
|
20139
|
-
* Creates runtime wallet tool function implementations.
|
|
20140
|
-
*
|
|
20141
|
-
* @private function of WalletCommitmentDefinition
|
|
20142
|
-
*/
|
|
20143
|
-
function createWalletToolFunctions() {
|
|
20144
|
-
return {
|
|
20145
|
-
async [WalletToolNames.retrieve](args) {
|
|
20146
|
-
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20147
|
-
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('retrieve', runtimeContext);
|
|
20148
|
-
if (!adapter || disabledResult) {
|
|
20149
|
-
return JSON.stringify(disabledResult);
|
|
20150
|
-
}
|
|
20151
|
-
try {
|
|
20152
|
-
const parsedArgs = parseWalletToolArgs.retrieve(args);
|
|
20153
|
-
const records = await adapter.retrieveWalletRecords(parsedArgs, runtimeContext);
|
|
20154
|
-
return JSON.stringify({
|
|
20155
|
-
action: 'retrieve',
|
|
20156
|
-
status: 'ok',
|
|
20157
|
-
query: parsedArgs.query,
|
|
20158
|
-
records,
|
|
20159
|
-
});
|
|
20160
|
-
}
|
|
20161
|
-
catch (error) {
|
|
20162
|
-
return JSON.stringify({
|
|
20163
|
-
action: 'retrieve',
|
|
20164
|
-
status: 'error',
|
|
20165
|
-
records: [],
|
|
20166
|
-
message: error instanceof Error ? error.message : String(error),
|
|
20167
|
-
});
|
|
20168
|
-
}
|
|
20169
|
-
},
|
|
20170
|
-
async [WalletToolNames.store](args) {
|
|
20171
|
-
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20172
|
-
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('store', runtimeContext);
|
|
20173
|
-
if (!adapter || disabledResult) {
|
|
20174
|
-
return JSON.stringify(disabledResult);
|
|
20175
|
-
}
|
|
20176
|
-
try {
|
|
20177
|
-
const parsedArgs = parseWalletToolArgs.store(args);
|
|
20178
|
-
const record = await adapter.storeWalletRecord(parsedArgs, runtimeContext);
|
|
20179
|
-
return JSON.stringify({
|
|
20180
|
-
action: 'store',
|
|
20181
|
-
status: 'stored',
|
|
20182
|
-
record,
|
|
20183
|
-
});
|
|
20184
|
-
}
|
|
20185
|
-
catch (error) {
|
|
20186
|
-
return JSON.stringify({
|
|
20187
|
-
action: 'store',
|
|
20188
|
-
status: 'error',
|
|
20189
|
-
message: error instanceof Error ? error.message : String(error),
|
|
20190
|
-
});
|
|
20191
|
-
}
|
|
20192
|
-
},
|
|
20193
|
-
async [WalletToolNames.update](args) {
|
|
20194
|
-
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20195
|
-
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('update', runtimeContext);
|
|
20196
|
-
if (!adapter || disabledResult) {
|
|
20197
|
-
return JSON.stringify(disabledResult);
|
|
20198
|
-
}
|
|
20199
|
-
try {
|
|
20200
|
-
const parsedArgs = parseWalletToolArgs.update(args);
|
|
20201
|
-
const record = await adapter.updateWalletRecord(parsedArgs, runtimeContext);
|
|
20202
|
-
return JSON.stringify({
|
|
20203
|
-
action: 'update',
|
|
20204
|
-
status: 'updated',
|
|
20205
|
-
record,
|
|
20206
|
-
});
|
|
20207
|
-
}
|
|
20208
|
-
catch (error) {
|
|
20209
|
-
return JSON.stringify({
|
|
20210
|
-
action: 'update',
|
|
20211
|
-
status: 'error',
|
|
20212
|
-
message: error instanceof Error ? error.message : String(error),
|
|
20213
|
-
});
|
|
20214
|
-
}
|
|
20215
|
-
},
|
|
20216
|
-
async [WalletToolNames.delete](args) {
|
|
20217
|
-
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20218
|
-
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('delete', runtimeContext);
|
|
20219
|
-
if (!adapter || disabledResult) {
|
|
20220
|
-
return JSON.stringify(disabledResult);
|
|
20221
|
-
}
|
|
20222
|
-
try {
|
|
20223
|
-
const parsedArgs = parseWalletToolArgs.delete(args);
|
|
20224
|
-
const deleted = await adapter.deleteWalletRecord(parsedArgs, runtimeContext);
|
|
20225
|
-
return JSON.stringify({
|
|
20226
|
-
action: 'delete',
|
|
20227
|
-
status: 'deleted',
|
|
20228
|
-
walletId: deleted.id,
|
|
20229
|
-
});
|
|
20230
|
-
}
|
|
20231
|
-
catch (error) {
|
|
20232
|
-
return JSON.stringify({
|
|
20233
|
-
action: 'delete',
|
|
20234
|
-
status: 'error',
|
|
20235
|
-
message: error instanceof Error ? error.message : String(error),
|
|
20236
|
-
});
|
|
20237
|
-
}
|
|
20238
|
-
},
|
|
20239
|
-
async [WalletToolNames.request](args) {
|
|
20240
|
-
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20241
|
-
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
20242
|
-
if (disabledMessage) {
|
|
20243
|
-
return JSON.stringify({
|
|
20244
|
-
action: 'request',
|
|
20245
|
-
status: 'disabled',
|
|
20246
|
-
message: disabledMessage,
|
|
20247
|
-
});
|
|
20248
|
-
}
|
|
20249
|
-
const request = parseWalletToolArgs.request(args);
|
|
20250
|
-
return JSON.stringify({
|
|
20251
|
-
action: 'request',
|
|
20252
|
-
status: 'requested',
|
|
20253
|
-
request,
|
|
20254
|
-
message: request.message ||
|
|
20255
|
-
`Request user to provide ${request.recordType} credentials for service "${request.service}".`,
|
|
20256
|
-
});
|
|
20257
|
-
},
|
|
20258
|
-
};
|
|
20259
|
-
}
|
|
20260
|
-
|
|
20261
|
-
/**
|
|
20262
|
-
* Creates tool definitions required by WALLET commitment.
|
|
20263
|
-
*
|
|
20264
|
-
* @private function of WalletCommitmentDefinition
|
|
20265
|
-
*/
|
|
20266
|
-
function createWalletTools(existingTools) {
|
|
20267
|
-
const tools = [...(existingTools || [])];
|
|
20268
|
-
addWalletToolIfMissing(tools, {
|
|
20269
|
-
name: WalletToolNames.retrieve,
|
|
20270
|
-
description: 'Retrieve wallet records relevant to the current task.',
|
|
20271
|
-
parameters: {
|
|
20272
|
-
type: 'object',
|
|
20273
|
-
properties: {
|
|
20274
|
-
query: { type: 'string', description: 'Optional text query used to filter wallet records.' },
|
|
20275
|
-
recordType: {
|
|
20276
|
-
type: 'string',
|
|
20277
|
-
description: 'Optional record type filter (USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN).',
|
|
20278
|
-
},
|
|
20279
|
-
service: { type: 'string', description: 'Optional service filter, for example github.' },
|
|
20280
|
-
key: { type: 'string', description: 'Optional wallet key filter.' },
|
|
20281
|
-
limit: { type: 'integer', description: 'Optional maximum number of records (default 5, max 20).' },
|
|
20282
|
-
},
|
|
20283
|
-
required: [],
|
|
20284
|
-
},
|
|
20285
|
-
});
|
|
20286
|
-
addWalletToolIfMissing(tools, {
|
|
20287
|
-
name: WalletToolNames.store,
|
|
20288
|
-
description: 'Store one wallet record.',
|
|
20289
|
-
parameters: {
|
|
20290
|
-
type: 'object',
|
|
20291
|
-
properties: {
|
|
20292
|
-
recordType: {
|
|
20293
|
-
type: 'string',
|
|
20294
|
-
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20295
|
-
},
|
|
20296
|
-
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
20297
|
-
key: { type: 'string', description: 'Logical credential key.' },
|
|
20298
|
-
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
20299
|
-
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
20300
|
-
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
20301
|
-
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
20302
|
-
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
20303
|
-
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
20304
|
-
},
|
|
20305
|
-
required: ['recordType', 'service'],
|
|
20306
|
-
},
|
|
20307
|
-
});
|
|
20308
|
-
addWalletToolIfMissing(tools, {
|
|
20309
|
-
name: WalletToolNames.update,
|
|
20310
|
-
description: 'Update one existing wallet record.',
|
|
20311
|
-
parameters: {
|
|
20312
|
-
type: 'object',
|
|
20313
|
-
properties: {
|
|
20314
|
-
walletId: { type: 'string', description: 'Wallet record id to update.' },
|
|
20315
|
-
recordType: {
|
|
20316
|
-
type: 'string',
|
|
20317
|
-
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20318
|
-
},
|
|
20319
|
-
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
20320
|
-
key: { type: 'string', description: 'Logical credential key.' },
|
|
20321
|
-
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
20322
|
-
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
20323
|
-
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
20324
|
-
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
20325
|
-
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
20326
|
-
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
20327
|
-
},
|
|
20328
|
-
required: ['walletId', 'recordType', 'service'],
|
|
20329
|
-
},
|
|
20330
|
-
});
|
|
20331
|
-
addWalletToolIfMissing(tools, {
|
|
20332
|
-
name: WalletToolNames.delete,
|
|
20333
|
-
description: 'Delete one wallet record.',
|
|
20334
|
-
parameters: {
|
|
20335
|
-
type: 'object',
|
|
20336
|
-
properties: {
|
|
20337
|
-
walletId: { type: 'string', description: 'Wallet record id to delete.' },
|
|
20338
|
-
},
|
|
20339
|
-
required: ['walletId'],
|
|
20340
|
-
},
|
|
20341
|
-
});
|
|
20342
|
-
addWalletToolIfMissing(tools, {
|
|
20343
|
-
name: WalletToolNames.request,
|
|
20344
|
-
description: 'Request missing credential from user via popup.',
|
|
20345
|
-
parameters: {
|
|
20346
|
-
type: 'object',
|
|
20347
|
-
properties: {
|
|
20348
|
-
recordType: {
|
|
20349
|
-
type: 'string',
|
|
20350
|
-
description: 'Requested record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20351
|
-
},
|
|
20352
|
-
service: { type: 'string', description: 'Service identifier.' },
|
|
20353
|
-
key: { type: 'string', description: 'Logical credential key.' },
|
|
20354
|
-
message: { type: 'string', description: 'Optional UI message for user.' },
|
|
20355
|
-
isUserScoped: {
|
|
20356
|
-
type: 'boolean',
|
|
20357
|
-
description: 'Set true when record should be scoped to current user.',
|
|
20358
|
-
},
|
|
20359
|
-
isGlobal: { type: 'boolean', description: 'Set true when record should be global.' },
|
|
20360
|
-
},
|
|
20361
|
-
required: [],
|
|
20362
|
-
},
|
|
20363
|
-
});
|
|
20364
|
-
return tools;
|
|
20365
|
-
}
|
|
20366
|
-
/**
|
|
20367
|
-
* Registers one wallet tool when missing in current tool list.
|
|
20368
|
-
*
|
|
20369
|
-
* @private function of WalletCommitmentDefinition
|
|
20370
|
-
*/
|
|
20371
|
-
function addWalletToolIfMissing(tools, tool) {
|
|
20372
|
-
if (!tools.some((existingTool) => existingTool.name === tool.name)) {
|
|
20373
|
-
tools.push(tool);
|
|
20374
|
-
}
|
|
20375
|
-
}
|
|
20376
|
-
|
|
20377
|
-
/**
|
|
20378
|
-
* Gets markdown documentation for WALLET commitment.
|
|
20379
|
-
*
|
|
20380
|
-
* @private function of WalletCommitmentDefinition
|
|
20381
|
-
*/
|
|
20382
|
-
function getWalletCommitmentDocumentation(type) {
|
|
20383
|
-
return spaceTrim$1(`
|
|
20384
|
-
# ${type}
|
|
20385
|
-
|
|
20386
|
-
Enables private credential storage for tokens, usernames/passwords, and session cookies.
|
|
20387
|
-
`);
|
|
20388
|
-
}
|
|
20389
|
-
|
|
20390
|
-
/**
|
|
20391
|
-
* Gets human-readable titles for WALLET tool functions.
|
|
20392
|
-
*
|
|
20393
|
-
* @private function of WalletCommitmentDefinition
|
|
20394
|
-
*/
|
|
20395
|
-
function getWalletToolTitles() {
|
|
20396
|
-
return {
|
|
20397
|
-
[WalletToolNames.retrieve]: 'Wallet',
|
|
20398
|
-
[WalletToolNames.store]: 'Store wallet record',
|
|
20399
|
-
[WalletToolNames.update]: 'Update wallet record',
|
|
20400
|
-
[WalletToolNames.delete]: 'Delete wallet record',
|
|
20401
|
-
[WalletToolNames.request]: 'Request wallet record',
|
|
20402
|
-
};
|
|
20403
|
-
}
|
|
20404
|
-
|
|
20405
|
-
/**
|
|
20406
|
-
* WALLET commitment definition.
|
|
20407
|
-
*
|
|
20408
|
-
* @private [🪔] Maybe export the commitments through some package
|
|
20409
|
-
*/
|
|
20410
|
-
class WalletCommitmentDefinition extends BaseCommitmentDefinition {
|
|
20411
|
-
constructor(type = 'WALLET') {
|
|
20412
|
-
super(type);
|
|
20413
|
-
}
|
|
20414
|
-
get requiresContent() {
|
|
20415
|
-
return false;
|
|
20416
|
-
}
|
|
20417
|
-
get description() {
|
|
20418
|
-
return 'Enable persistent private credential storage (tokens, logins, cookies) scoped per agent or globally.';
|
|
20419
|
-
}
|
|
20420
|
-
get icon() {
|
|
20421
|
-
return '👛';
|
|
20422
|
-
}
|
|
20423
|
-
get documentation() {
|
|
20424
|
-
return getWalletCommitmentDocumentation(this.type);
|
|
20425
|
-
}
|
|
20426
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
20427
|
-
const extraInstructions = formatOptionalInstructionBlock('Wallet instructions', content);
|
|
20428
|
-
return this.appendToSystemMessage({
|
|
20429
|
-
...requirements,
|
|
20430
|
-
tools: createWalletTools(requirements.tools),
|
|
20431
|
-
_metadata: {
|
|
20432
|
-
...requirements._metadata,
|
|
20433
|
-
useWallet: content || true,
|
|
20434
|
-
},
|
|
20435
|
-
}, createWalletSystemMessage(extraInstructions));
|
|
20436
|
-
}
|
|
20437
|
-
getToolTitles() {
|
|
20438
|
-
return getWalletToolTitles();
|
|
20439
|
-
}
|
|
20440
|
-
getToolFunctions() {
|
|
20441
|
-
return createWalletToolFunctions();
|
|
20442
|
-
}
|
|
20443
|
-
}
|
|
20444
|
-
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
20445
|
-
|
|
20446
16932
|
/**
|
|
20447
16933
|
* `WRITING RULES` commitment definition.
|
|
20448
16934
|
*
|
|
@@ -20669,8 +17155,6 @@ const COMMITMENT_REGISTRY = [
|
|
|
20669
17155
|
new PersonaCommitmentDefinition('PERSONA'),
|
|
20670
17156
|
new PersonaCommitmentDefinition('PERSONAE'),
|
|
20671
17157
|
new KnowledgeCommitmentDefinition(),
|
|
20672
|
-
new MemoryCommitmentDefinition('MEMORY'),
|
|
20673
|
-
new MemoryCommitmentDefinition('MEMORIES'),
|
|
20674
17158
|
new StyleCommitmentDefinition('STYLE'),
|
|
20675
17159
|
new StyleCommitmentDefinition('STYLES'),
|
|
20676
17160
|
new RuleCommitmentDefinition('RULE'),
|
|
@@ -20692,7 +17176,6 @@ const COMMITMENT_REGISTRY = [
|
|
|
20692
17176
|
new ModelCommitmentDefinition('MODELS'),
|
|
20693
17177
|
new ActionCommitmentDefinition('ACTION'),
|
|
20694
17178
|
new ActionCommitmentDefinition('ACTIONS'),
|
|
20695
|
-
new ComponentCommitmentDefinition(),
|
|
20696
17179
|
new MetaAvatarCommitmentDefinition(),
|
|
20697
17180
|
new MetaAvatarCommitmentDefinition('META VISUAL'),
|
|
20698
17181
|
new MetaImageCommitmentDefinition(),
|
|
@@ -20700,11 +17183,13 @@ const COMMITMENT_REGISTRY = [
|
|
|
20700
17183
|
new MetaFontCommitmentDefinition(),
|
|
20701
17184
|
new MetaLinkCommitmentDefinition(),
|
|
20702
17185
|
new MetaDomainCommitmentDefinition(),
|
|
17186
|
+
new MetaDescriptionCommitmentDefinition(),
|
|
20703
17187
|
new MetaDisclaimerCommitmentDefinition(),
|
|
17188
|
+
new MetaFullnameCommitmentDefinition(),
|
|
17189
|
+
new MetaIdCommitmentDefinition(),
|
|
20704
17190
|
new MetaInputPlaceholderCommitmentDefinition(),
|
|
20705
17191
|
new MetaThinkingMessageCommitmentDefinition(),
|
|
20706
17192
|
new MetaVisibilityCommitmentDefinition(),
|
|
20707
|
-
new MetaCommitmentDefinition(),
|
|
20708
17193
|
new MetaVoiceCommitmentDefinition(),
|
|
20709
17194
|
new NoteCommitmentDefinition('NOTE'),
|
|
20710
17195
|
new NoteCommitmentDefinition('NOTES'),
|
|
@@ -20720,8 +17205,6 @@ const COMMITMENT_REGISTRY = [
|
|
|
20720
17205
|
new MessageSuffixCommitmentDefinition(),
|
|
20721
17206
|
new MessageCommitmentDefinition('MESSAGE'),
|
|
20722
17207
|
new MessageCommitmentDefinition('MESSAGES'),
|
|
20723
|
-
new WalletCommitmentDefinition('WALLET'),
|
|
20724
|
-
new WalletCommitmentDefinition('WALLETS'),
|
|
20725
17208
|
new ScenarioCommitmentDefinition('SCENARIO'),
|
|
20726
17209
|
new ScenarioCommitmentDefinition('SCENARIOS'),
|
|
20727
17210
|
new DeleteCommitmentDefinition('DELETE'),
|
|
@@ -20732,15 +17215,8 @@ const COMMITMENT_REGISTRY = [
|
|
|
20732
17215
|
new OpenCommitmentDefinition(),
|
|
20733
17216
|
new ClosedCommitmentDefinition(),
|
|
20734
17217
|
new TeamCommitmentDefinition(),
|
|
20735
|
-
new UseBrowserCommitmentDefinition(),
|
|
20736
|
-
new UseDeepSearchCommitmentDefinition(),
|
|
20737
|
-
new UseSearchEngineCommitmentDefinition(),
|
|
20738
|
-
new UseSpawnCommitmentDefinition(),
|
|
20739
|
-
new UseTimeoutCommitmentDefinition(),
|
|
20740
|
-
new UseTimeCommitmentDefinition(),
|
|
20741
17218
|
new UseUserLocationCommitmentDefinition(),
|
|
20742
17219
|
new UseCalendarCommitmentDefinition(),
|
|
20743
|
-
new UseEmailCommitmentDefinition(),
|
|
20744
17220
|
new UsePopupCommitmentDefinition(),
|
|
20745
17221
|
new UseImageGeneratorCommitmentDefinition('USE IMAGE GENERATOR'),
|
|
20746
17222
|
new UseMcpCommitmentDefinition(),
|
|
@@ -20936,6 +17412,39 @@ function getAllCommitmentsToolFunctionsForBrowser() {
|
|
|
20936
17412
|
return commitmentToolFunctionsProxy;
|
|
20937
17413
|
}
|
|
20938
17414
|
|
|
17415
|
+
/**
|
|
17416
|
+
* Generates random token
|
|
17417
|
+
*
|
|
17418
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
17419
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
17420
|
+
*
|
|
17421
|
+
* @returns secure random token
|
|
17422
|
+
*
|
|
17423
|
+
* @private internal helper function
|
|
17424
|
+
*/
|
|
17425
|
+
function $randomToken(randomness) {
|
|
17426
|
+
return CryptoJS.lib.WordArray.random(randomness).toString(CryptoJS.enc.Hex);
|
|
17427
|
+
}
|
|
17428
|
+
// TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
17429
|
+
// TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
17430
|
+
|
|
17431
|
+
/**
|
|
17432
|
+
* This error indicates errors during the execution of the pipeline
|
|
17433
|
+
*
|
|
17434
|
+
* @public exported from `@promptbook/core`
|
|
17435
|
+
*/
|
|
17436
|
+
class PipelineExecutionError extends Error {
|
|
17437
|
+
constructor(message) {
|
|
17438
|
+
// Added id parameter
|
|
17439
|
+
super(message);
|
|
17440
|
+
this.name = 'PipelineExecutionError';
|
|
17441
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
17442
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
17443
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
17444
|
+
}
|
|
17445
|
+
}
|
|
17446
|
+
// TODO: [🧠][🌂] Add id to all errors
|
|
17447
|
+
|
|
20939
17448
|
/**
|
|
20940
17449
|
* Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
|
|
20941
17450
|
*
|
|
@@ -22252,59 +18761,6 @@ function extractInitialMessage(commitments) {
|
|
|
22252
18761
|
return initialMessage;
|
|
22253
18762
|
}
|
|
22254
18763
|
|
|
22255
|
-
/**
|
|
22256
|
-
* Normalizes a given text to camelCase format.
|
|
22257
|
-
*
|
|
22258
|
-
* Note: [🔂] This function is idempotent.
|
|
22259
|
-
*
|
|
22260
|
-
* @param text The text to be normalized.
|
|
22261
|
-
* @param _isFirstLetterCapital Whether the first letter should be capitalized.
|
|
22262
|
-
* @returns The camelCase formatted string.
|
|
22263
|
-
* @example 'helloWorld'
|
|
22264
|
-
* @example 'iLovePromptbook'
|
|
22265
|
-
*
|
|
22266
|
-
* @public exported from `@promptbook/utils`
|
|
22267
|
-
*/
|
|
22268
|
-
function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
22269
|
-
let charType;
|
|
22270
|
-
let lastCharType = null;
|
|
22271
|
-
let normalizedName = '';
|
|
22272
|
-
for (const char of text) {
|
|
22273
|
-
let normalizedChar;
|
|
22274
|
-
if (/^[a-z]$/.test(char)) {
|
|
22275
|
-
charType = 'LOWERCASE';
|
|
22276
|
-
normalizedChar = char;
|
|
22277
|
-
}
|
|
22278
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
22279
|
-
charType = 'UPPERCASE';
|
|
22280
|
-
normalizedChar = char.toLowerCase();
|
|
22281
|
-
}
|
|
22282
|
-
else if (/^[0-9]$/.test(char)) {
|
|
22283
|
-
charType = 'NUMBER';
|
|
22284
|
-
normalizedChar = char;
|
|
22285
|
-
}
|
|
22286
|
-
else {
|
|
22287
|
-
charType = 'OTHER';
|
|
22288
|
-
normalizedChar = '';
|
|
22289
|
-
}
|
|
22290
|
-
if (!lastCharType) {
|
|
22291
|
-
if (_isFirstLetterCapital) {
|
|
22292
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
22293
|
-
}
|
|
22294
|
-
}
|
|
22295
|
-
else if (charType !== lastCharType &&
|
|
22296
|
-
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
22297
|
-
!(lastCharType === 'NUMBER') &&
|
|
22298
|
-
!(charType === 'NUMBER')) {
|
|
22299
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
22300
|
-
}
|
|
22301
|
-
normalizedName += normalizedChar;
|
|
22302
|
-
lastCharType = charType;
|
|
22303
|
-
}
|
|
22304
|
-
return normalizedName;
|
|
22305
|
-
}
|
|
22306
|
-
// TODO: [🌺] Use some intermediate util splitWords
|
|
22307
|
-
|
|
22308
18764
|
/**
|
|
22309
18765
|
* Normalizes a domain-like string into a comparable hostname form.
|
|
22310
18766
|
*
|
|
@@ -22343,6 +18799,54 @@ function hasHttpProtocol(value) {
|
|
|
22343
18799
|
return value.startsWith('http://') || value.startsWith('https://');
|
|
22344
18800
|
}
|
|
22345
18801
|
|
|
18802
|
+
/**
|
|
18803
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
18804
|
+
*
|
|
18805
|
+
* @public exported from `@promptbook/core`
|
|
18806
|
+
*/
|
|
18807
|
+
class ParseError extends Error {
|
|
18808
|
+
constructor(message) {
|
|
18809
|
+
super(message);
|
|
18810
|
+
this.name = 'ParseError';
|
|
18811
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
18812
|
+
}
|
|
18813
|
+
}
|
|
18814
|
+
// TODO: Maybe split `ParseError` and `ApplyError`
|
|
18815
|
+
|
|
18816
|
+
/**
|
|
18817
|
+
* Supported visibility states for persisted agents.
|
|
18818
|
+
*
|
|
18819
|
+
* @public exported from `@promptbook/core`
|
|
18820
|
+
*/
|
|
18821
|
+
const AGENT_VISIBILITY_VALUES = ['PRIVATE', 'UNLISTED', 'PUBLIC'];
|
|
18822
|
+
/**
|
|
18823
|
+
* Returns `true` when the value is one of supported visibility states.
|
|
18824
|
+
*
|
|
18825
|
+
* @param value - Raw value to validate.
|
|
18826
|
+
* @returns Whether the value is a valid `AgentVisibility`.
|
|
18827
|
+
*
|
|
18828
|
+
* @public exported from `@promptbook/core`
|
|
18829
|
+
*/
|
|
18830
|
+
function isAgentVisibility(value) {
|
|
18831
|
+
return typeof value === 'string' && AGENT_VISIBILITY_VALUES.includes(value);
|
|
18832
|
+
}
|
|
18833
|
+
/**
|
|
18834
|
+
* Normalizes raw visibility text into a supported value.
|
|
18835
|
+
*
|
|
18836
|
+
* @param value - Raw visibility value.
|
|
18837
|
+
* @returns Normalized visibility, or `null` when invalid.
|
|
18838
|
+
*
|
|
18839
|
+
* @public exported from `@promptbook/core`
|
|
18840
|
+
*/
|
|
18841
|
+
function normalizeAgentVisibility(value) {
|
|
18842
|
+
if (typeof value !== 'string') {
|
|
18843
|
+
return null;
|
|
18844
|
+
}
|
|
18845
|
+
const normalized = value.trim().toUpperCase();
|
|
18846
|
+
return isAgentVisibility(normalized) ? normalized : null;
|
|
18847
|
+
}
|
|
18848
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18849
|
+
|
|
22346
18850
|
/**
|
|
22347
18851
|
* Dedicated handlers for META-style commitments that directly map onto parsed meta fields.
|
|
22348
18852
|
*/
|
|
@@ -22354,6 +18858,8 @@ const META_COMMITMENT_APPLIERS = {
|
|
|
22354
18858
|
'META IMAGE': applyMetaImageContent,
|
|
22355
18859
|
'META DESCRIPTION': applyMetaDescriptionContent,
|
|
22356
18860
|
'META DISCLAIMER': applyMetaDisclaimerContent,
|
|
18861
|
+
'META FULLNAME': applyMetaFullnameContent,
|
|
18862
|
+
'META ID': applyMetaIdContent,
|
|
22357
18863
|
'META INPUT PLACEHOLDER': applyMetaInputPlaceholderContent,
|
|
22358
18864
|
'META THINKING MESSAGE': applyMetaThinkingMessageContent,
|
|
22359
18865
|
'MESSAGE SUFFIX': applyMessageSuffixContent,
|
|
@@ -22371,32 +18877,8 @@ function applyMetaCommitment(state, commitment) {
|
|
|
22371
18877
|
const applyMetaContent = META_COMMITMENT_APPLIERS[commitment.type];
|
|
22372
18878
|
if (applyMetaContent) {
|
|
22373
18879
|
applyMetaContent(state, commitment.content);
|
|
22374
|
-
return;
|
|
22375
|
-
}
|
|
22376
|
-
if (commitment.type === 'META') {
|
|
22377
|
-
applyGenericMetaCommitment(state, commitment.content);
|
|
22378
18880
|
}
|
|
22379
18881
|
}
|
|
22380
|
-
/**
|
|
22381
|
-
* Applies the generic META commitment form (`META TYPE value`).
|
|
22382
|
-
*/
|
|
22383
|
-
function applyGenericMetaCommitment(state, content) {
|
|
22384
|
-
const metaTypeRaw = content.split(' ')[0] || 'NONE';
|
|
22385
|
-
const metaValue = spaceTrim$1(content.substring(metaTypeRaw.length));
|
|
22386
|
-
if (metaTypeRaw === 'LINK') {
|
|
22387
|
-
state.links.push(metaValue);
|
|
22388
|
-
}
|
|
22389
|
-
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
22390
|
-
applyMetaAvatarContent(state, metaValue);
|
|
22391
|
-
return;
|
|
22392
|
-
}
|
|
22393
|
-
if (metaTypeRaw.toUpperCase() === 'VISIBILITY') {
|
|
22394
|
-
applyMetaVisibilityContent(state, metaValue);
|
|
22395
|
-
return;
|
|
22396
|
-
}
|
|
22397
|
-
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
22398
|
-
state.meta[metaType] = metaValue;
|
|
22399
|
-
}
|
|
22400
18882
|
/**
|
|
22401
18883
|
* Applies META AVATAR / META VISUAL content into the canonical `meta.avatar` field.
|
|
22402
18884
|
*/
|
|
@@ -22440,6 +18922,18 @@ function applyMetaDescriptionContent(state, content) {
|
|
|
22440
18922
|
function applyMetaDisclaimerContent(state, content) {
|
|
22441
18923
|
state.meta.disclaimer = content;
|
|
22442
18924
|
}
|
|
18925
|
+
/**
|
|
18926
|
+
* Applies META FULLNAME content into the canonical `meta.fullname` field.
|
|
18927
|
+
*/
|
|
18928
|
+
function applyMetaFullnameContent(state, content) {
|
|
18929
|
+
state.meta.fullname = spaceTrim$1(content);
|
|
18930
|
+
}
|
|
18931
|
+
/**
|
|
18932
|
+
* Applies META ID content into the canonical `meta.id` field.
|
|
18933
|
+
*/
|
|
18934
|
+
function applyMetaIdContent(state, content) {
|
|
18935
|
+
state.meta.id = spaceTrim$1(content);
|
|
18936
|
+
}
|
|
22443
18937
|
/**
|
|
22444
18938
|
* Applies META INPUT PLACEHOLDER content into the canonical `meta.inputPlaceholder` field.
|
|
22445
18939
|
*/
|
|
@@ -22544,46 +19038,11 @@ function consumeConversationSampleCommitment(state, commitment) {
|
|
|
22544
19038
|
* Static capability descriptors for commitments that map one-to-one to a visible capability.
|
|
22545
19039
|
*/
|
|
22546
19040
|
const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
|
|
22547
|
-
'USE BROWSER': {
|
|
22548
|
-
type: 'browser',
|
|
22549
|
-
label: 'Browser',
|
|
22550
|
-
iconName: 'Globe',
|
|
22551
|
-
},
|
|
22552
|
-
'USE SEARCH ENGINE': {
|
|
22553
|
-
type: 'search-engine',
|
|
22554
|
-
label: 'Internet',
|
|
22555
|
-
iconName: 'Search',
|
|
22556
|
-
},
|
|
22557
|
-
'USE SEARCH': {
|
|
22558
|
-
type: 'search-engine',
|
|
22559
|
-
label: 'Internet',
|
|
22560
|
-
iconName: 'Search',
|
|
22561
|
-
},
|
|
22562
|
-
'USE DEEPSEARCH': {
|
|
22563
|
-
type: 'search-engine',
|
|
22564
|
-
label: 'DeepSearch',
|
|
22565
|
-
iconName: 'Search',
|
|
22566
|
-
},
|
|
22567
|
-
'USE TIME': {
|
|
22568
|
-
type: 'time',
|
|
22569
|
-
label: 'Time',
|
|
22570
|
-
iconName: 'Clock',
|
|
22571
|
-
},
|
|
22572
|
-
'USE TIMEOUT': {
|
|
22573
|
-
type: 'timeout',
|
|
22574
|
-
label: 'Timers',
|
|
22575
|
-
iconName: 'Clock',
|
|
22576
|
-
},
|
|
22577
19041
|
'USE USER LOCATION': {
|
|
22578
19042
|
type: 'user-location',
|
|
22579
19043
|
label: 'User location',
|
|
22580
19044
|
iconName: 'MapPin',
|
|
22581
19045
|
},
|
|
22582
|
-
'USE EMAIL': {
|
|
22583
|
-
type: 'email',
|
|
22584
|
-
label: 'Email',
|
|
22585
|
-
iconName: 'Mail',
|
|
22586
|
-
},
|
|
22587
19046
|
'USE POPUP': {
|
|
22588
19047
|
type: 'popup',
|
|
22589
19048
|
label: 'Popup',
|
|
@@ -23093,6 +19552,21 @@ padBook(validateBook(spaceTrim$1(`
|
|
|
23093
19552
|
// <- [🐱🚀] Buttons into genesis book
|
|
23094
19553
|
// <- TODO: [🐱🚀] generateBookBoilerplate and deprecate `DEFAULT_BOOK`
|
|
23095
19554
|
|
|
19555
|
+
/**
|
|
19556
|
+
* Checks if value is valid email
|
|
19557
|
+
*
|
|
19558
|
+
* @public exported from `@promptbook/utils`
|
|
19559
|
+
*/
|
|
19560
|
+
function isValidEmail(email) {
|
|
19561
|
+
if (typeof email !== 'string') {
|
|
19562
|
+
return false;
|
|
19563
|
+
}
|
|
19564
|
+
if (email.split(/\r?\n/).length > 1) {
|
|
19565
|
+
return false;
|
|
19566
|
+
}
|
|
19567
|
+
return /^.+@.+\..+$/.test(email);
|
|
19568
|
+
}
|
|
19569
|
+
|
|
23096
19570
|
/**
|
|
23097
19571
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
23098
19572
|
*
|
|
@@ -23166,6 +19640,19 @@ function isValidPipelineString(pipelineString) {
|
|
|
23166
19640
|
}
|
|
23167
19641
|
// TODO: [🧠][🈴] Where is the best location for this file
|
|
23168
19642
|
|
|
19643
|
+
/**
|
|
19644
|
+
* This error type indicates that some limit was reached
|
|
19645
|
+
*
|
|
19646
|
+
* @public exported from `@promptbook/core`
|
|
19647
|
+
*/
|
|
19648
|
+
class LimitReachedError extends Error {
|
|
19649
|
+
constructor(message) {
|
|
19650
|
+
super(message);
|
|
19651
|
+
this.name = 'LimitReachedError';
|
|
19652
|
+
Object.setPrototypeOf(this, LimitReachedError.prototype);
|
|
19653
|
+
}
|
|
19654
|
+
}
|
|
19655
|
+
|
|
23169
19656
|
/**
|
|
23170
19657
|
* Replaces parameters in template with values from parameters object
|
|
23171
19658
|
*
|
|
@@ -30217,12 +26704,6 @@ const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
|
30217
26704
|
['GOAL', 'GOAL'],
|
|
30218
26705
|
['GOALS', 'GOAL'],
|
|
30219
26706
|
]);
|
|
30220
|
-
/**
|
|
30221
|
-
* Legacy commitments that should be parsed for compatibility but ignored by the model-requirements pipeline.
|
|
30222
|
-
*
|
|
30223
|
-
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
30224
|
-
*/
|
|
30225
|
-
const IGNORED_COMMITMENT_TYPES = new Set(['WALLET', 'WALLETS']);
|
|
30226
26707
|
/**
|
|
30227
26708
|
* Applies the commitment filtering rules used before commitment definitions are executed.
|
|
30228
26709
|
*
|
|
@@ -30271,9 +26752,6 @@ function filterOverwrittenCommitments(commitments) {
|
|
|
30271
26752
|
function filterDeletedCommitments(commitments) {
|
|
30272
26753
|
const filteredCommitments = [];
|
|
30273
26754
|
for (const commitment of commitments) {
|
|
30274
|
-
if (isIgnoredCommitmentType(commitment.type)) {
|
|
30275
|
-
continue;
|
|
30276
|
-
}
|
|
30277
26755
|
if (!isDeleteCommitmentType(commitment.type)) {
|
|
30278
26756
|
filteredCommitments.push(commitment);
|
|
30279
26757
|
continue;
|
|
@@ -30304,17 +26782,6 @@ function filterDeletedCommitments(commitments) {
|
|
|
30304
26782
|
function isDeleteCommitmentType(commitmentType) {
|
|
30305
26783
|
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
30306
26784
|
}
|
|
30307
|
-
/**
|
|
30308
|
-
* Checks whether a parsed commitment is intentionally ignored by the current model compiler.
|
|
30309
|
-
*
|
|
30310
|
-
* @param commitmentType - Commitment type to check.
|
|
30311
|
-
* @returns `true` when the commitment should not affect model requirements.
|
|
30312
|
-
*
|
|
30313
|
-
* @private internal utility of `filterDeletedCommitments`
|
|
30314
|
-
*/
|
|
30315
|
-
function isIgnoredCommitmentType(commitmentType) {
|
|
30316
|
-
return IGNORED_COMMITMENT_TYPES.has(commitmentType);
|
|
30317
|
-
}
|
|
30318
26785
|
/**
|
|
30319
26786
|
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
30320
26787
|
*
|
|
@@ -30448,7 +26915,6 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
30448
26915
|
const filteredCommitments = filterCommitmentsForAgentModelRequirements(parseResult.commitments);
|
|
30449
26916
|
let requirements = createInitialAgentModelRequirements(parseResult.agentName, modelName);
|
|
30450
26917
|
requirements = await applyCommitmentsToAgentModelRequirements(requirements, filteredCommitments, options);
|
|
30451
|
-
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
30452
26918
|
requirements = await augmentAgentModelRequirementsFromSource(requirements, parseResult, agentSource);
|
|
30453
26919
|
requirements = await materializeInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
|
|
30454
26920
|
return finalizeRequirements(requirements);
|
|
@@ -31125,6 +27591,40 @@ class OpenAiAgentKitExecutionToolsOutputTypeMapper {
|
|
|
31125
27591
|
}
|
|
31126
27592
|
}
|
|
31127
27593
|
|
|
27594
|
+
/**
|
|
27595
|
+
* Marker property stored inside serialized tool-execution envelopes.
|
|
27596
|
+
*
|
|
27597
|
+
* @private internal tool-execution transport
|
|
27598
|
+
*/
|
|
27599
|
+
const TOOL_EXECUTION_ENVELOPE_MARKER = '__promptbookToolExecutionEnvelope';
|
|
27600
|
+
/**
|
|
27601
|
+
* Parses one serialized tool-execution envelope when present.
|
|
27602
|
+
*
|
|
27603
|
+
* @private internal tool-execution transport
|
|
27604
|
+
*/
|
|
27605
|
+
function parseToolExecutionEnvelope(rawValue) {
|
|
27606
|
+
if (typeof rawValue !== 'string') {
|
|
27607
|
+
return null;
|
|
27608
|
+
}
|
|
27609
|
+
try {
|
|
27610
|
+
const parsedValue = JSON.parse(rawValue);
|
|
27611
|
+
if (!parsedValue ||
|
|
27612
|
+
typeof parsedValue !== 'object' ||
|
|
27613
|
+
parsedValue[TOOL_EXECUTION_ENVELOPE_MARKER] !== true ||
|
|
27614
|
+
typeof parsedValue.assistantMessage !== 'string') {
|
|
27615
|
+
return null;
|
|
27616
|
+
}
|
|
27617
|
+
return {
|
|
27618
|
+
assistantMessage: parsedValue.assistantMessage,
|
|
27619
|
+
toolResult: parsedValue.toolResult,
|
|
27620
|
+
};
|
|
27621
|
+
}
|
|
27622
|
+
catch (_a) {
|
|
27623
|
+
return null;
|
|
27624
|
+
}
|
|
27625
|
+
}
|
|
27626
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
27627
|
+
|
|
31128
27628
|
/**
|
|
31129
27629
|
* Builds a tool invocation script that injects hidden runtime context into tool args.
|
|
31130
27630
|
*
|
|
@@ -31196,7 +27696,7 @@ const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agen
|
|
|
31196
27696
|
*/
|
|
31197
27697
|
const DEFAULT_DEEP_SEARCH_MODEL_NAME = 'o4-mini-deep-research';
|
|
31198
27698
|
/**
|
|
31199
|
-
* Tool name used by the
|
|
27699
|
+
* Tool name used by the DeepSearch capability.
|
|
31200
27700
|
*/
|
|
31201
27701
|
const DEEP_SEARCH_TOOL_NAME = 'deep_search';
|
|
31202
27702
|
/**
|
|
@@ -31466,7 +27966,7 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
31466
27966
|
};
|
|
31467
27967
|
}
|
|
31468
27968
|
/**
|
|
31469
|
-
* Creates the native Agent SDK tool used for
|
|
27969
|
+
* Creates the native Agent SDK tool used for the DeepSearch capability.
|
|
31470
27970
|
*/
|
|
31471
27971
|
async createDeepSearchAgentKitTool(toolDefinition) {
|
|
31472
27972
|
const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
|
|
@@ -39563,7 +36063,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
39563
36063
|
this.links = [];
|
|
39564
36064
|
/**
|
|
39565
36065
|
* Capabilities of the agent
|
|
39566
|
-
* This is parsed from commitments like USE
|
|
36066
|
+
* This is parsed from commitments like USE CALENDAR, USE PROJECT, KNOWLEDGE, etc.
|
|
39567
36067
|
*/
|
|
39568
36068
|
this.capabilities = [];
|
|
39569
36069
|
/**
|