@promptbook/remote-server 0.112.0-61 → 0.112.0-63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +785 -40
- package/esm/index.es.js.map +1 -1
- package/esm/src/_packages/components.index.d.ts +4 -0
- package/esm/src/_packages/core.index.d.ts +2 -0
- package/esm/src/_packages/types.index.d.ts +2 -0
- package/esm/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +0 -2
- package/esm/src/book-components/Chat/Chat/renderTimeoutToolCallDetails.d.ts +7 -1
- package/esm/src/book-components/Chat/Chat/useChatInputAreaComposer.d.ts +1 -1
- package/esm/src/book-components/Chat/Chat/useChatInputAreaDictation.d.ts +2 -2
- package/esm/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +6 -3
- package/esm/src/book-components/Chat/types/ChatMessage.d.ts +34 -0
- package/esm/src/cli/cli-commands/agent/agentProjectPaths.d.ts +54 -0
- package/esm/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +13 -0
- package/esm/src/cli/cli-commands/agent/init.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/initializeAgentProjectConfiguration.d.ts +21 -0
- package/esm/src/cli/cli-commands/agent/printAgentInitializationSummary.d.ts +7 -0
- package/esm/src/cli/cli-commands/agent/run.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent/tick.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent.d.ts +15 -0
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +86 -0
- package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +11 -0
- package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.test.d.ts +1 -0
- package/esm/src/commitments/_common/toolRuntimeContext.d.ts +6 -0
- package/esm/src/commitments/index.d.ts +2 -1
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +4 -2
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +9 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +785 -40
- package/umd/index.umd.js.map +1 -1
- package/umd/src/_packages/components.index.d.ts +4 -0
- package/umd/src/_packages/core.index.d.ts +2 -0
- package/umd/src/_packages/types.index.d.ts +2 -0
- package/umd/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +0 -2
- package/umd/src/book-components/Chat/Chat/renderTimeoutToolCallDetails.d.ts +7 -1
- package/umd/src/book-components/Chat/Chat/useChatInputAreaComposer.d.ts +1 -1
- package/umd/src/book-components/Chat/Chat/useChatInputAreaDictation.d.ts +2 -2
- package/umd/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +6 -3
- package/umd/src/book-components/Chat/types/ChatMessage.d.ts +34 -0
- package/umd/src/cli/cli-commands/agent/agentProjectPaths.d.ts +54 -0
- package/umd/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +13 -0
- package/umd/src/cli/cli-commands/agent/init.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/initializeAgentProjectConfiguration.d.ts +21 -0
- package/umd/src/cli/cli-commands/agent/printAgentInitializationSummary.d.ts +7 -0
- package/umd/src/cli/cli-commands/agent/run.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent/tick.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent.d.ts +15 -0
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +86 -0
- package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +11 -0
- package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.test.d.ts +1 -0
- package/umd/src/commitments/_common/toolRuntimeContext.d.ts +6 -0
- package/umd/src/commitments/index.d.ts +2 -1
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +4 -2
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +9 -0
- package/umd/src/version.d.ts +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
* @generated
|
|
51
51
|
* @see https://github.com/webgptorg/promptbook
|
|
52
52
|
*/
|
|
53
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
53
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-63';
|
|
54
54
|
/**
|
|
55
55
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
56
56
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -12689,6 +12689,18 @@
|
|
|
12689
12689
|
}
|
|
12690
12690
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12691
12691
|
|
|
12692
|
+
/**
|
|
12693
|
+
* Name of the tool used by agents to search configured `KNOWLEDGE` sources.
|
|
12694
|
+
*
|
|
12695
|
+
* @public exported from `@promptbook/core`
|
|
12696
|
+
*/
|
|
12697
|
+
const KNOWLEDGE_SEARCH_TOOL_NAME = 'knowledge_search';
|
|
12698
|
+
/**
|
|
12699
|
+
* Title of the system-message section generated for `KNOWLEDGE` commitments.
|
|
12700
|
+
*
|
|
12701
|
+
* @private constant of `KnowledgeCommitmentDefinition`
|
|
12702
|
+
*/
|
|
12703
|
+
const KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE = 'Knowledge Search';
|
|
12692
12704
|
/**
|
|
12693
12705
|
* KNOWLEDGE commitment definition
|
|
12694
12706
|
*
|
|
@@ -12810,9 +12822,17 @@
|
|
|
12810
12822
|
knowledgeInfoEntries.push(`Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`);
|
|
12811
12823
|
}
|
|
12812
12824
|
if (knowledgeInfoEntries.length === 0) {
|
|
12813
|
-
return nextRequirements;
|
|
12825
|
+
return addKnowledgeSearchToolAndSystemSection(nextRequirements);
|
|
12814
12826
|
}
|
|
12815
|
-
return
|
|
12827
|
+
return addKnowledgeSearchToolAndSystemSection(nextRequirements);
|
|
12828
|
+
}
|
|
12829
|
+
/**
|
|
12830
|
+
* Gets human-readable titles for tool functions provided by this commitment.
|
|
12831
|
+
*/
|
|
12832
|
+
getToolTitles() {
|
|
12833
|
+
return {
|
|
12834
|
+
[KNOWLEDGE_SEARCH_TOOL_NAME]: 'Knowledge search',
|
|
12835
|
+
};
|
|
12816
12836
|
}
|
|
12817
12837
|
}
|
|
12818
12838
|
/**
|
|
@@ -12826,6 +12846,128 @@
|
|
|
12826
12846
|
const significantText = contentWithoutUrls.replace(/[\s.,!?;:'"`()[\]{}<>/-]+/g, '');
|
|
12827
12847
|
return significantText.length > 0;
|
|
12828
12848
|
}
|
|
12849
|
+
/**
|
|
12850
|
+
* Adds the shared `knowledge_search` tool definition and the consolidated system-message section.
|
|
12851
|
+
*
|
|
12852
|
+
* @param requirements - Requirements after one `KNOWLEDGE` commitment was applied.
|
|
12853
|
+
* @returns Requirements with the knowledge search instructions and tool definition.
|
|
12854
|
+
*
|
|
12855
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12856
|
+
*/
|
|
12857
|
+
function addKnowledgeSearchToolAndSystemSection(requirements) {
|
|
12858
|
+
const nextRequirements = addKnowledgeSearchTool(requirements);
|
|
12859
|
+
const section = createKnowledgeSearchSystemSection(nextRequirements);
|
|
12860
|
+
const sectionHeader = `## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}`;
|
|
12861
|
+
if (nextRequirements.systemMessage.includes(sectionHeader)) {
|
|
12862
|
+
return {
|
|
12863
|
+
...nextRequirements,
|
|
12864
|
+
systemMessage: nextRequirements.systemMessage.replace(new RegExp(`## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), section),
|
|
12865
|
+
};
|
|
12866
|
+
}
|
|
12867
|
+
return {
|
|
12868
|
+
...nextRequirements,
|
|
12869
|
+
systemMessage: nextRequirements.systemMessage.trim()
|
|
12870
|
+
? `${nextRequirements.systemMessage}\n\n${section}`
|
|
12871
|
+
: section,
|
|
12872
|
+
};
|
|
12873
|
+
}
|
|
12874
|
+
/**
|
|
12875
|
+
* Adds the `knowledge_search` model tool when it is not already present.
|
|
12876
|
+
*
|
|
12877
|
+
* @param requirements - Current model requirements.
|
|
12878
|
+
* @returns Requirements with the tool definition available to the model.
|
|
12879
|
+
*
|
|
12880
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12881
|
+
*/
|
|
12882
|
+
function addKnowledgeSearchTool(requirements) {
|
|
12883
|
+
const existingTools = requirements.tools || [];
|
|
12884
|
+
if (existingTools.some((tool) => tool.name === KNOWLEDGE_SEARCH_TOOL_NAME)) {
|
|
12885
|
+
return requirements;
|
|
12886
|
+
}
|
|
12887
|
+
return {
|
|
12888
|
+
...requirements,
|
|
12889
|
+
tools: [
|
|
12890
|
+
...existingTools,
|
|
12891
|
+
{
|
|
12892
|
+
name: KNOWLEDGE_SEARCH_TOOL_NAME,
|
|
12893
|
+
description: _spaceTrim.spaceTrim(`
|
|
12894
|
+
Search the agent's configured knowledge sources and return relevant excerpts with citation ids.
|
|
12895
|
+
Use this before answering questions that may depend on the agent's KNOWLEDGE commitments.
|
|
12896
|
+
`),
|
|
12897
|
+
parameters: {
|
|
12898
|
+
type: 'object',
|
|
12899
|
+
properties: {
|
|
12900
|
+
query: {
|
|
12901
|
+
type: 'string',
|
|
12902
|
+
description: 'The natural-language search query for the knowledge base.',
|
|
12903
|
+
},
|
|
12904
|
+
limit: {
|
|
12905
|
+
type: 'integer',
|
|
12906
|
+
description: 'Maximum number of matching source excerpts to return.',
|
|
12907
|
+
},
|
|
12908
|
+
},
|
|
12909
|
+
required: ['query'],
|
|
12910
|
+
},
|
|
12911
|
+
},
|
|
12912
|
+
],
|
|
12913
|
+
};
|
|
12914
|
+
}
|
|
12915
|
+
/**
|
|
12916
|
+
* Creates the model-facing system-message section for knowledge search.
|
|
12917
|
+
*
|
|
12918
|
+
* @param requirements - Current model requirements.
|
|
12919
|
+
* @returns Markdown system-message section.
|
|
12920
|
+
*
|
|
12921
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12922
|
+
*/
|
|
12923
|
+
function createKnowledgeSearchSystemSection(requirements) {
|
|
12924
|
+
const sourceEntries = createKnowledgeSourceSystemEntries(requirements);
|
|
12925
|
+
const sourceList = sourceEntries.length > 0 ? sourceEntries.map((entry) => `- ${entry}`).join('\n') : '- None';
|
|
12926
|
+
return _spaceTrim.spaceTrim(`
|
|
12927
|
+
## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}
|
|
12928
|
+
|
|
12929
|
+
- Use \`${KNOWLEDGE_SEARCH_TOOL_NAME}\` to search the configured knowledge sources before answering questions that depend on this agent's knowledge base.
|
|
12930
|
+
- Base source-backed factual answers on the returned excerpts.
|
|
12931
|
+
- When you use a returned excerpt, include its citation marker in the answer body, for example \`[0:0]\`.
|
|
12932
|
+
- If the search returns no relevant information, say that the knowledge base did not contain the answer instead of inventing it.
|
|
12933
|
+
|
|
12934
|
+
Configured knowledge sources:
|
|
12935
|
+
${sourceList}
|
|
12936
|
+
`);
|
|
12937
|
+
}
|
|
12938
|
+
/**
|
|
12939
|
+
* Builds a stable list of configured knowledge sources for system-message diagnostics.
|
|
12940
|
+
*
|
|
12941
|
+
* @param requirements - Current model requirements.
|
|
12942
|
+
* @returns Human-readable source entries.
|
|
12943
|
+
*
|
|
12944
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12945
|
+
*/
|
|
12946
|
+
function createKnowledgeSourceSystemEntries(requirements) {
|
|
12947
|
+
var _a;
|
|
12948
|
+
const entries = [];
|
|
12949
|
+
const seenEntries = new Set();
|
|
12950
|
+
for (const source of requirements.knowledgeSources || []) {
|
|
12951
|
+
const entry = `Source URL: ${source} (processed for retrieval during chat)`;
|
|
12952
|
+
if (seenEntries.has(entry)) {
|
|
12953
|
+
continue;
|
|
12954
|
+
}
|
|
12955
|
+
seenEntries.add(entry);
|
|
12956
|
+
entries.push(entry);
|
|
12957
|
+
}
|
|
12958
|
+
const inlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || [])
|
|
12959
|
+
.map((source) => source.filename)
|
|
12960
|
+
.filter(Boolean);
|
|
12961
|
+
for (const filename of inlineSources) {
|
|
12962
|
+
const entry = `Knowledge Source Inline: ${filename} (Inline source: processed for retrieval during chat)`;
|
|
12963
|
+
if (seenEntries.has(entry)) {
|
|
12964
|
+
continue;
|
|
12965
|
+
}
|
|
12966
|
+
seenEntries.add(entry);
|
|
12967
|
+
entries.push(entry);
|
|
12968
|
+
}
|
|
12969
|
+
return entries;
|
|
12970
|
+
}
|
|
12829
12971
|
|
|
12830
12972
|
/**
|
|
12831
12973
|
* LANGUAGE commitment definition
|
|
@@ -20585,7 +20727,7 @@
|
|
|
20585
20727
|
const runtimeContext = (readToolRuntimeContextFromToolArgs(args) ||
|
|
20586
20728
|
{});
|
|
20587
20729
|
const configuredCalendars = normalizeConfiguredCalendars$1((_a = runtimeContext.calendars) === null || _a === void 0 ? void 0 : _a.connections);
|
|
20588
|
-
const calendarArgument = normalizeOptionalText$
|
|
20730
|
+
const calendarArgument = normalizeOptionalText$2(args.calendarUrl);
|
|
20589
20731
|
let calendarReference = null;
|
|
20590
20732
|
if (calendarArgument) {
|
|
20591
20733
|
calendarReference = parseGoogleCalendarReference(calendarArgument);
|
|
@@ -20605,7 +20747,7 @@
|
|
|
20605
20747
|
if (!calendarReference) {
|
|
20606
20748
|
throw new Error('Calendar is required but was not resolved.');
|
|
20607
20749
|
}
|
|
20608
|
-
const accessToken = normalizeOptionalText$
|
|
20750
|
+
const accessToken = normalizeOptionalText$2((_b = runtimeContext.calendars) === null || _b === void 0 ? void 0 : _b.googleAccessToken) || '';
|
|
20609
20751
|
if (!accessToken) {
|
|
20610
20752
|
throw new CalendarWalletCredentialRequiredError({
|
|
20611
20753
|
calendarReference,
|
|
@@ -20638,7 +20780,7 @@
|
|
|
20638
20780
|
continue;
|
|
20639
20781
|
}
|
|
20640
20782
|
const calendar = rawCalendar;
|
|
20641
|
-
const rawUrl = normalizeOptionalText$
|
|
20783
|
+
const rawUrl = normalizeOptionalText$2(calendar.url);
|
|
20642
20784
|
if (!rawUrl) {
|
|
20643
20785
|
continue;
|
|
20644
20786
|
}
|
|
@@ -20689,7 +20831,7 @@
|
|
|
20689
20831
|
*
|
|
20690
20832
|
* @private function of resolveUseCalendarToolRuntimeOrWalletCredentialResult
|
|
20691
20833
|
*/
|
|
20692
|
-
function normalizeOptionalText$
|
|
20834
|
+
function normalizeOptionalText$2(value) {
|
|
20693
20835
|
if (typeof value !== 'string') {
|
|
20694
20836
|
return undefined;
|
|
20695
20837
|
}
|
|
@@ -20721,13 +20863,13 @@
|
|
|
20721
20863
|
async [UseCalendarToolNames.listEvents](args) {
|
|
20722
20864
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
20723
20865
|
const query = {};
|
|
20724
|
-
if (normalizeOptionalText(args.timeMin)) {
|
|
20866
|
+
if (normalizeOptionalText$1(args.timeMin)) {
|
|
20725
20867
|
query.timeMin = args.timeMin.trim();
|
|
20726
20868
|
}
|
|
20727
|
-
if (normalizeOptionalText(args.timeMax)) {
|
|
20869
|
+
if (normalizeOptionalText$1(args.timeMax)) {
|
|
20728
20870
|
query.timeMax = args.timeMax.trim();
|
|
20729
20871
|
}
|
|
20730
|
-
if (normalizeOptionalText(args.query)) {
|
|
20872
|
+
if (normalizeOptionalText$1(args.query)) {
|
|
20731
20873
|
query.q = args.query.trim();
|
|
20732
20874
|
}
|
|
20733
20875
|
if (typeof args.maxResults === 'number' && Number.isFinite(args.maxResults) && args.maxResults > 0) {
|
|
@@ -20739,7 +20881,7 @@
|
|
|
20739
20881
|
if (args.orderBy === 'startTime' || args.orderBy === 'updated') {
|
|
20740
20882
|
query.orderBy = args.orderBy;
|
|
20741
20883
|
}
|
|
20742
|
-
if (normalizeOptionalText(args.timeZone)) {
|
|
20884
|
+
if (normalizeOptionalText$1(args.timeZone)) {
|
|
20743
20885
|
query.timeZone = args.timeZone.trim();
|
|
20744
20886
|
}
|
|
20745
20887
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -20777,11 +20919,11 @@
|
|
|
20777
20919
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
20778
20920
|
const requestBody = createGoogleCalendarEventPayload({
|
|
20779
20921
|
summary: normalizeRequiredText(args.summary, 'summary'),
|
|
20780
|
-
description: normalizeOptionalText(args.description),
|
|
20781
|
-
location: normalizeOptionalText(args.location),
|
|
20922
|
+
description: normalizeOptionalText$1(args.description),
|
|
20923
|
+
location: normalizeOptionalText$1(args.location),
|
|
20782
20924
|
start: normalizeRequiredText(args.start, 'start'),
|
|
20783
20925
|
end: normalizeRequiredText(args.end, 'end'),
|
|
20784
|
-
timeZone: normalizeOptionalText(args.timeZone),
|
|
20926
|
+
timeZone: normalizeOptionalText$1(args.timeZone),
|
|
20785
20927
|
attendees: normalizeAttendees(args.attendees),
|
|
20786
20928
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
20787
20929
|
});
|
|
@@ -20803,12 +20945,12 @@
|
|
|
20803
20945
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
20804
20946
|
const eventId = normalizeRequiredText(args.eventId, 'eventId');
|
|
20805
20947
|
const requestBody = createGoogleCalendarEventPayload({
|
|
20806
|
-
summary: normalizeOptionalText(args.summary),
|
|
20807
|
-
description: normalizeOptionalText(args.description),
|
|
20808
|
-
location: normalizeOptionalText(args.location),
|
|
20809
|
-
start: normalizeOptionalText(args.start),
|
|
20810
|
-
end: normalizeOptionalText(args.end),
|
|
20811
|
-
timeZone: normalizeOptionalText(args.timeZone),
|
|
20948
|
+
summary: normalizeOptionalText$1(args.summary),
|
|
20949
|
+
description: normalizeOptionalText$1(args.description),
|
|
20950
|
+
location: normalizeOptionalText$1(args.location),
|
|
20951
|
+
start: normalizeOptionalText$1(args.start),
|
|
20952
|
+
end: normalizeOptionalText$1(args.end),
|
|
20953
|
+
timeZone: normalizeOptionalText$1(args.timeZone),
|
|
20812
20954
|
attendees: normalizeAttendees(args.attendees),
|
|
20813
20955
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
20814
20956
|
});
|
|
@@ -20855,7 +20997,7 @@
|
|
|
20855
20997
|
path: `/calendars/${encodeGoogleCalendarId(calendarReference.calendarId)}/events/${encodeURIComponent(eventId)}`,
|
|
20856
20998
|
});
|
|
20857
20999
|
const existingAttendees = ((existingEvent === null || existingEvent === void 0 ? void 0 : existingEvent.attendees) || [])
|
|
20858
|
-
.map((attendee) => normalizeOptionalText(attendee.email))
|
|
21000
|
+
.map((attendee) => normalizeOptionalText$1(attendee.email))
|
|
20859
21001
|
.filter((email) => Boolean(email));
|
|
20860
21002
|
const mergedAttendees = [...new Set([...existingAttendees, ...guests])];
|
|
20861
21003
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -20903,7 +21045,7 @@
|
|
|
20903
21045
|
* @private function of createUseCalendarToolFunctions
|
|
20904
21046
|
*/
|
|
20905
21047
|
function normalizeRequiredText(value, fieldName) {
|
|
20906
|
-
const normalizedValue = normalizeOptionalText(value);
|
|
21048
|
+
const normalizedValue = normalizeOptionalText$1(value);
|
|
20907
21049
|
if (!normalizedValue) {
|
|
20908
21050
|
throw new Error(`Tool "${fieldName}" requires non-empty value.`);
|
|
20909
21051
|
}
|
|
@@ -20914,7 +21056,7 @@
|
|
|
20914
21056
|
*
|
|
20915
21057
|
* @private function of createUseCalendarToolFunctions
|
|
20916
21058
|
*/
|
|
20917
|
-
function normalizeOptionalText(value) {
|
|
21059
|
+
function normalizeOptionalText$1(value) {
|
|
20918
21060
|
if (typeof value !== 'string') {
|
|
20919
21061
|
return undefined;
|
|
20920
21062
|
}
|
|
@@ -25581,6 +25723,580 @@
|
|
|
25581
25723
|
}
|
|
25582
25724
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
25583
25725
|
|
|
25726
|
+
/**
|
|
25727
|
+
* Names of tools used by the WALLET commitment.
|
|
25728
|
+
*
|
|
25729
|
+
* @private constant of WalletCommitmentDefinition
|
|
25730
|
+
*/
|
|
25731
|
+
const WalletToolNames = {
|
|
25732
|
+
retrieve: 'retrieve_wallet_records',
|
|
25733
|
+
store: 'store_wallet_record',
|
|
25734
|
+
update: 'update_wallet_record',
|
|
25735
|
+
delete: 'delete_wallet_record',
|
|
25736
|
+
request: 'request_wallet_record',
|
|
25737
|
+
};
|
|
25738
|
+
|
|
25739
|
+
/**
|
|
25740
|
+
* Creates WALLET system-message instructions.
|
|
25741
|
+
*
|
|
25742
|
+
* @private function of WalletCommitmentDefinition
|
|
25743
|
+
*/
|
|
25744
|
+
function createWalletSystemMessage(extraInstructions) {
|
|
25745
|
+
return _spaceTrim.spaceTrim((block) => `
|
|
25746
|
+
Wallet:
|
|
25747
|
+
- Use "${WalletToolNames.retrieve}" before authenticated operations.
|
|
25748
|
+
- Use "${WalletToolNames.store}" and "${WalletToolNames.update}" to maintain credentials.
|
|
25749
|
+
- Use "${WalletToolNames.delete}" to remove invalid credentials.
|
|
25750
|
+
- Use "${WalletToolNames.request}" to request missing credentials via UI popup.
|
|
25751
|
+
- Scope records by user (\`isUserScoped\`) and/or by agent (\`isGlobal=false\`) as needed.
|
|
25752
|
+
- Never expose raw credentials in chat responses.
|
|
25753
|
+
${block(extraInstructions)}
|
|
25754
|
+
`);
|
|
25755
|
+
}
|
|
25756
|
+
|
|
25757
|
+
/**
|
|
25758
|
+
* Resolves disabled message for wallet runtime context.
|
|
25759
|
+
*
|
|
25760
|
+
* @private function of WalletCommitmentDefinition
|
|
25761
|
+
*/
|
|
25762
|
+
function resolveWalletDisabledMessage(runtimeContext) {
|
|
25763
|
+
if (runtimeContext.isPrivateMode) {
|
|
25764
|
+
return 'Wallet is disabled because private mode is active.';
|
|
25765
|
+
}
|
|
25766
|
+
if (runtimeContext.isTeamConversation) {
|
|
25767
|
+
return 'Wallet is disabled for TEAM conversations.';
|
|
25768
|
+
}
|
|
25769
|
+
if (!runtimeContext.enabled) {
|
|
25770
|
+
return 'Wallet is disabled for unauthenticated users.';
|
|
25771
|
+
}
|
|
25772
|
+
return null;
|
|
25773
|
+
}
|
|
25774
|
+
/**
|
|
25775
|
+
* Resolves runtime adapter for wallet tools or returns disabled payload when unavailable.
|
|
25776
|
+
*
|
|
25777
|
+
* @private function of WalletCommitmentDefinition
|
|
25778
|
+
*/
|
|
25779
|
+
function getWalletToolRuntimeAdapterOrDisabledResult(action, runtimeContext) {
|
|
25780
|
+
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
25781
|
+
if (disabledMessage) {
|
|
25782
|
+
return {
|
|
25783
|
+
adapter: null,
|
|
25784
|
+
disabledResult: {
|
|
25785
|
+
action,
|
|
25786
|
+
status: 'disabled',
|
|
25787
|
+
records: action === 'retrieve' ? [] : undefined,
|
|
25788
|
+
message: disabledMessage,
|
|
25789
|
+
},
|
|
25790
|
+
};
|
|
25791
|
+
}
|
|
25792
|
+
{
|
|
25793
|
+
return {
|
|
25794
|
+
adapter: null,
|
|
25795
|
+
disabledResult: {
|
|
25796
|
+
action,
|
|
25797
|
+
status: 'disabled',
|
|
25798
|
+
records: action === 'retrieve' ? [] : undefined,
|
|
25799
|
+
message: 'Wallet runtime is not available in this environment.',
|
|
25800
|
+
},
|
|
25801
|
+
};
|
|
25802
|
+
}
|
|
25803
|
+
}
|
|
25804
|
+
|
|
25805
|
+
/**
|
|
25806
|
+
* Parses store/update wallet payload.
|
|
25807
|
+
*
|
|
25808
|
+
* @private function of WalletCommitmentDefinition
|
|
25809
|
+
*/
|
|
25810
|
+
function parseWalletPayload(args) {
|
|
25811
|
+
const recordType = parseWalletRecordType(args.recordType);
|
|
25812
|
+
return {
|
|
25813
|
+
recordType,
|
|
25814
|
+
service: parseWalletService(args.service),
|
|
25815
|
+
key: parseWalletKey(args.key),
|
|
25816
|
+
isUserScoped: args.isUserScoped === true,
|
|
25817
|
+
isGlobal: args.isGlobal === true,
|
|
25818
|
+
...parseWalletSecrets({
|
|
25819
|
+
recordType,
|
|
25820
|
+
username: args.username,
|
|
25821
|
+
password: args.password,
|
|
25822
|
+
secret: args.secret,
|
|
25823
|
+
cookies: args.cookies,
|
|
25824
|
+
}),
|
|
25825
|
+
};
|
|
25826
|
+
}
|
|
25827
|
+
/**
|
|
25828
|
+
* Parses text argument and returns trimmed text when available.
|
|
25829
|
+
*
|
|
25830
|
+
* @private function of WalletCommitmentDefinition
|
|
25831
|
+
*/
|
|
25832
|
+
function normalizeOptionalText(value) {
|
|
25833
|
+
if (typeof value !== 'string') {
|
|
25834
|
+
return undefined;
|
|
25835
|
+
}
|
|
25836
|
+
const trimmed = value.trim();
|
|
25837
|
+
return trimmed || undefined;
|
|
25838
|
+
}
|
|
25839
|
+
/**
|
|
25840
|
+
* Parses wallet service argument.
|
|
25841
|
+
*
|
|
25842
|
+
* @private function of WalletCommitmentDefinition
|
|
25843
|
+
*/
|
|
25844
|
+
function parseWalletService(value) {
|
|
25845
|
+
return (normalizeOptionalText(value) || 'generic').toLowerCase();
|
|
25846
|
+
}
|
|
25847
|
+
/**
|
|
25848
|
+
* Parses wallet key argument.
|
|
25849
|
+
*
|
|
25850
|
+
* @private function of WalletCommitmentDefinition
|
|
25851
|
+
*/
|
|
25852
|
+
function parseWalletKey(value) {
|
|
25853
|
+
return normalizeOptionalText(value) || 'default';
|
|
25854
|
+
}
|
|
25855
|
+
/**
|
|
25856
|
+
* Parses one wallet record id argument.
|
|
25857
|
+
*
|
|
25858
|
+
* @private function of WalletCommitmentDefinition
|
|
25859
|
+
*/
|
|
25860
|
+
function parseWalletId(value) {
|
|
25861
|
+
const walletId = normalizeOptionalText(value);
|
|
25862
|
+
if (!walletId) {
|
|
25863
|
+
throw new Error('Wallet id is required.');
|
|
25864
|
+
}
|
|
25865
|
+
return walletId;
|
|
25866
|
+
}
|
|
25867
|
+
/**
|
|
25868
|
+
* Parses wallet record type.
|
|
25869
|
+
*
|
|
25870
|
+
* @private function of WalletCommitmentDefinition
|
|
25871
|
+
*/
|
|
25872
|
+
function parseWalletRecordType(value, fallback) {
|
|
25873
|
+
var _a;
|
|
25874
|
+
const normalizedType = (_a = normalizeOptionalText(value)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
25875
|
+
if (normalizedType === 'USERNAME_PASSWORD') {
|
|
25876
|
+
return 'USERNAME_PASSWORD';
|
|
25877
|
+
}
|
|
25878
|
+
if (normalizedType === 'SESSION_COOKIE') {
|
|
25879
|
+
return 'SESSION_COOKIE';
|
|
25880
|
+
}
|
|
25881
|
+
if (normalizedType === 'ACCESS_TOKEN') {
|
|
25882
|
+
return 'ACCESS_TOKEN';
|
|
25883
|
+
}
|
|
25884
|
+
if (fallback) {
|
|
25885
|
+
return fallback;
|
|
25886
|
+
}
|
|
25887
|
+
throw new Error('Unsupported wallet recordType. Expected one of: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.');
|
|
25888
|
+
}
|
|
25889
|
+
/**
|
|
25890
|
+
* Parses wallet secret fields according to record type.
|
|
25891
|
+
*
|
|
25892
|
+
* @private function of WalletCommitmentDefinition
|
|
25893
|
+
*/
|
|
25894
|
+
function parseWalletSecrets(args) {
|
|
25895
|
+
const username = normalizeOptionalText(args.username);
|
|
25896
|
+
const password = normalizeOptionalText(args.password);
|
|
25897
|
+
const secret = normalizeOptionalText(args.secret);
|
|
25898
|
+
const cookies = normalizeOptionalText(args.cookies);
|
|
25899
|
+
if (args.recordType === 'USERNAME_PASSWORD') {
|
|
25900
|
+
if (!username || !password) {
|
|
25901
|
+
throw new Error('Both username and password are required for USERNAME_PASSWORD.');
|
|
25902
|
+
}
|
|
25903
|
+
return { username, password };
|
|
25904
|
+
}
|
|
25905
|
+
if (args.recordType === 'SESSION_COOKIE') {
|
|
25906
|
+
if (!cookies) {
|
|
25907
|
+
throw new Error('Cookies are required for SESSION_COOKIE.');
|
|
25908
|
+
}
|
|
25909
|
+
return { cookies };
|
|
25910
|
+
}
|
|
25911
|
+
if (!secret) {
|
|
25912
|
+
throw new Error('Secret is required for ACCESS_TOKEN.');
|
|
25913
|
+
}
|
|
25914
|
+
return { secret };
|
|
25915
|
+
}
|
|
25916
|
+
/**
|
|
25917
|
+
* Collection of WALLET tool argument parsers.
|
|
25918
|
+
*
|
|
25919
|
+
* @private function of WalletCommitmentDefinition
|
|
25920
|
+
*/
|
|
25921
|
+
const parseWalletToolArgs = {
|
|
25922
|
+
/**
|
|
25923
|
+
* Parses retrieve arguments.
|
|
25924
|
+
*/
|
|
25925
|
+
retrieve(args) {
|
|
25926
|
+
const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : undefined;
|
|
25927
|
+
return {
|
|
25928
|
+
query: normalizeOptionalText(args.query),
|
|
25929
|
+
recordType: normalizeOptionalText(args.recordType) ? parseWalletRecordType(args.recordType) : undefined,
|
|
25930
|
+
service: normalizeOptionalText(args.service) ? parseWalletService(args.service) : undefined,
|
|
25931
|
+
key: normalizeOptionalText(args.key) ? parseWalletKey(args.key) : undefined,
|
|
25932
|
+
limit: limit && limit > 0 ? Math.min(limit, 20) : undefined,
|
|
25933
|
+
};
|
|
25934
|
+
},
|
|
25935
|
+
/**
|
|
25936
|
+
* Parses store payload.
|
|
25937
|
+
*/
|
|
25938
|
+
store(args) {
|
|
25939
|
+
return parseWalletPayload(args);
|
|
25940
|
+
},
|
|
25941
|
+
/**
|
|
25942
|
+
* Parses update payload.
|
|
25943
|
+
*/
|
|
25944
|
+
update(args) {
|
|
25945
|
+
const walletId = parseWalletId(args.walletId);
|
|
25946
|
+
const record = parseWalletPayload(args);
|
|
25947
|
+
return {
|
|
25948
|
+
...record,
|
|
25949
|
+
walletId,
|
|
25950
|
+
};
|
|
25951
|
+
},
|
|
25952
|
+
/**
|
|
25953
|
+
* Parses delete payload.
|
|
25954
|
+
*/
|
|
25955
|
+
delete(args) {
|
|
25956
|
+
return { walletId: parseWalletId(args.walletId) };
|
|
25957
|
+
},
|
|
25958
|
+
/**
|
|
25959
|
+
* Parses request payload for user wallet input prompt.
|
|
25960
|
+
*/
|
|
25961
|
+
request(args) {
|
|
25962
|
+
return {
|
|
25963
|
+
recordType: parseWalletRecordType(args.recordType, 'ACCESS_TOKEN'),
|
|
25964
|
+
service: parseWalletService(args.service),
|
|
25965
|
+
key: parseWalletKey(args.key),
|
|
25966
|
+
message: normalizeOptionalText(args.message),
|
|
25967
|
+
isUserScoped: args.isUserScoped === true,
|
|
25968
|
+
isGlobal: args.isGlobal === true,
|
|
25969
|
+
};
|
|
25970
|
+
},
|
|
25971
|
+
};
|
|
25972
|
+
|
|
25973
|
+
/**
|
|
25974
|
+
* Resolves runtime context from hidden tool arguments.
|
|
25975
|
+
*
|
|
25976
|
+
* @private function of WalletCommitmentDefinition
|
|
25977
|
+
*/
|
|
25978
|
+
function resolveWalletRuntimeContext(args) {
|
|
25979
|
+
const runtimeContext = readToolRuntimeContextFromToolArgs(args);
|
|
25980
|
+
const memoryContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.memory;
|
|
25981
|
+
return {
|
|
25982
|
+
enabled: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.enabled) === true,
|
|
25983
|
+
userId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.userId,
|
|
25984
|
+
username: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.username,
|
|
25985
|
+
agentId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentId,
|
|
25986
|
+
agentName: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentName,
|
|
25987
|
+
isTeamConversation: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isTeamConversation) === true,
|
|
25988
|
+
isPrivateMode: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isPrivateMode) === true,
|
|
25989
|
+
};
|
|
25990
|
+
}
|
|
25991
|
+
|
|
25992
|
+
/**
|
|
25993
|
+
* Creates runtime wallet tool function implementations.
|
|
25994
|
+
*
|
|
25995
|
+
* @private function of WalletCommitmentDefinition
|
|
25996
|
+
*/
|
|
25997
|
+
function createWalletToolFunctions() {
|
|
25998
|
+
return {
|
|
25999
|
+
async [WalletToolNames.retrieve](args) {
|
|
26000
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
26001
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('retrieve', runtimeContext);
|
|
26002
|
+
if (!adapter || disabledResult) {
|
|
26003
|
+
return JSON.stringify(disabledResult);
|
|
26004
|
+
}
|
|
26005
|
+
try {
|
|
26006
|
+
const parsedArgs = parseWalletToolArgs.retrieve(args);
|
|
26007
|
+
const records = await adapter.retrieveWalletRecords(parsedArgs, runtimeContext);
|
|
26008
|
+
return JSON.stringify({
|
|
26009
|
+
action: 'retrieve',
|
|
26010
|
+
status: 'ok',
|
|
26011
|
+
query: parsedArgs.query,
|
|
26012
|
+
records,
|
|
26013
|
+
});
|
|
26014
|
+
}
|
|
26015
|
+
catch (error) {
|
|
26016
|
+
return JSON.stringify({
|
|
26017
|
+
action: 'retrieve',
|
|
26018
|
+
status: 'error',
|
|
26019
|
+
records: [],
|
|
26020
|
+
message: error instanceof Error ? error.message : String(error),
|
|
26021
|
+
});
|
|
26022
|
+
}
|
|
26023
|
+
},
|
|
26024
|
+
async [WalletToolNames.store](args) {
|
|
26025
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
26026
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('store', runtimeContext);
|
|
26027
|
+
if (!adapter || disabledResult) {
|
|
26028
|
+
return JSON.stringify(disabledResult);
|
|
26029
|
+
}
|
|
26030
|
+
try {
|
|
26031
|
+
const parsedArgs = parseWalletToolArgs.store(args);
|
|
26032
|
+
const record = await adapter.storeWalletRecord(parsedArgs, runtimeContext);
|
|
26033
|
+
return JSON.stringify({
|
|
26034
|
+
action: 'store',
|
|
26035
|
+
status: 'stored',
|
|
26036
|
+
record,
|
|
26037
|
+
});
|
|
26038
|
+
}
|
|
26039
|
+
catch (error) {
|
|
26040
|
+
return JSON.stringify({
|
|
26041
|
+
action: 'store',
|
|
26042
|
+
status: 'error',
|
|
26043
|
+
message: error instanceof Error ? error.message : String(error),
|
|
26044
|
+
});
|
|
26045
|
+
}
|
|
26046
|
+
},
|
|
26047
|
+
async [WalletToolNames.update](args) {
|
|
26048
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
26049
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('update', runtimeContext);
|
|
26050
|
+
if (!adapter || disabledResult) {
|
|
26051
|
+
return JSON.stringify(disabledResult);
|
|
26052
|
+
}
|
|
26053
|
+
try {
|
|
26054
|
+
const parsedArgs = parseWalletToolArgs.update(args);
|
|
26055
|
+
const record = await adapter.updateWalletRecord(parsedArgs, runtimeContext);
|
|
26056
|
+
return JSON.stringify({
|
|
26057
|
+
action: 'update',
|
|
26058
|
+
status: 'updated',
|
|
26059
|
+
record,
|
|
26060
|
+
});
|
|
26061
|
+
}
|
|
26062
|
+
catch (error) {
|
|
26063
|
+
return JSON.stringify({
|
|
26064
|
+
action: 'update',
|
|
26065
|
+
status: 'error',
|
|
26066
|
+
message: error instanceof Error ? error.message : String(error),
|
|
26067
|
+
});
|
|
26068
|
+
}
|
|
26069
|
+
},
|
|
26070
|
+
async [WalletToolNames.delete](args) {
|
|
26071
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
26072
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('delete', runtimeContext);
|
|
26073
|
+
if (!adapter || disabledResult) {
|
|
26074
|
+
return JSON.stringify(disabledResult);
|
|
26075
|
+
}
|
|
26076
|
+
try {
|
|
26077
|
+
const parsedArgs = parseWalletToolArgs.delete(args);
|
|
26078
|
+
const deleted = await adapter.deleteWalletRecord(parsedArgs, runtimeContext);
|
|
26079
|
+
return JSON.stringify({
|
|
26080
|
+
action: 'delete',
|
|
26081
|
+
status: 'deleted',
|
|
26082
|
+
walletId: deleted.id,
|
|
26083
|
+
});
|
|
26084
|
+
}
|
|
26085
|
+
catch (error) {
|
|
26086
|
+
return JSON.stringify({
|
|
26087
|
+
action: 'delete',
|
|
26088
|
+
status: 'error',
|
|
26089
|
+
message: error instanceof Error ? error.message : String(error),
|
|
26090
|
+
});
|
|
26091
|
+
}
|
|
26092
|
+
},
|
|
26093
|
+
async [WalletToolNames.request](args) {
|
|
26094
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
26095
|
+
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
26096
|
+
if (disabledMessage) {
|
|
26097
|
+
return JSON.stringify({
|
|
26098
|
+
action: 'request',
|
|
26099
|
+
status: 'disabled',
|
|
26100
|
+
message: disabledMessage,
|
|
26101
|
+
});
|
|
26102
|
+
}
|
|
26103
|
+
const request = parseWalletToolArgs.request(args);
|
|
26104
|
+
return JSON.stringify({
|
|
26105
|
+
action: 'request',
|
|
26106
|
+
status: 'requested',
|
|
26107
|
+
request,
|
|
26108
|
+
message: request.message ||
|
|
26109
|
+
`Request user to provide ${request.recordType} credentials for service "${request.service}".`,
|
|
26110
|
+
});
|
|
26111
|
+
},
|
|
26112
|
+
};
|
|
26113
|
+
}
|
|
26114
|
+
|
|
26115
|
+
/**
|
|
26116
|
+
* Creates tool definitions required by WALLET commitment.
|
|
26117
|
+
*
|
|
26118
|
+
* @private function of WalletCommitmentDefinition
|
|
26119
|
+
*/
|
|
26120
|
+
function createWalletTools(existingTools) {
|
|
26121
|
+
const tools = [...(existingTools || [])];
|
|
26122
|
+
addWalletToolIfMissing(tools, {
|
|
26123
|
+
name: WalletToolNames.retrieve,
|
|
26124
|
+
description: 'Retrieve wallet records relevant to the current task.',
|
|
26125
|
+
parameters: {
|
|
26126
|
+
type: 'object',
|
|
26127
|
+
properties: {
|
|
26128
|
+
query: { type: 'string', description: 'Optional text query used to filter wallet records.' },
|
|
26129
|
+
recordType: {
|
|
26130
|
+
type: 'string',
|
|
26131
|
+
description: 'Optional record type filter (USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN).',
|
|
26132
|
+
},
|
|
26133
|
+
service: { type: 'string', description: 'Optional service filter, for example github.' },
|
|
26134
|
+
key: { type: 'string', description: 'Optional wallet key filter.' },
|
|
26135
|
+
limit: { type: 'integer', description: 'Optional maximum number of records (default 5, max 20).' },
|
|
26136
|
+
},
|
|
26137
|
+
required: [],
|
|
26138
|
+
},
|
|
26139
|
+
});
|
|
26140
|
+
addWalletToolIfMissing(tools, {
|
|
26141
|
+
name: WalletToolNames.store,
|
|
26142
|
+
description: 'Store one wallet record.',
|
|
26143
|
+
parameters: {
|
|
26144
|
+
type: 'object',
|
|
26145
|
+
properties: {
|
|
26146
|
+
recordType: {
|
|
26147
|
+
type: 'string',
|
|
26148
|
+
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
26149
|
+
},
|
|
26150
|
+
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
26151
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
26152
|
+
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
26153
|
+
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
26154
|
+
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
26155
|
+
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
26156
|
+
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
26157
|
+
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
26158
|
+
},
|
|
26159
|
+
required: ['recordType', 'service'],
|
|
26160
|
+
},
|
|
26161
|
+
});
|
|
26162
|
+
addWalletToolIfMissing(tools, {
|
|
26163
|
+
name: WalletToolNames.update,
|
|
26164
|
+
description: 'Update one existing wallet record.',
|
|
26165
|
+
parameters: {
|
|
26166
|
+
type: 'object',
|
|
26167
|
+
properties: {
|
|
26168
|
+
walletId: { type: 'string', description: 'Wallet record id to update.' },
|
|
26169
|
+
recordType: {
|
|
26170
|
+
type: 'string',
|
|
26171
|
+
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
26172
|
+
},
|
|
26173
|
+
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
26174
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
26175
|
+
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
26176
|
+
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
26177
|
+
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
26178
|
+
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
26179
|
+
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
26180
|
+
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
26181
|
+
},
|
|
26182
|
+
required: ['walletId', 'recordType', 'service'],
|
|
26183
|
+
},
|
|
26184
|
+
});
|
|
26185
|
+
addWalletToolIfMissing(tools, {
|
|
26186
|
+
name: WalletToolNames.delete,
|
|
26187
|
+
description: 'Delete one wallet record.',
|
|
26188
|
+
parameters: {
|
|
26189
|
+
type: 'object',
|
|
26190
|
+
properties: {
|
|
26191
|
+
walletId: { type: 'string', description: 'Wallet record id to delete.' },
|
|
26192
|
+
},
|
|
26193
|
+
required: ['walletId'],
|
|
26194
|
+
},
|
|
26195
|
+
});
|
|
26196
|
+
addWalletToolIfMissing(tools, {
|
|
26197
|
+
name: WalletToolNames.request,
|
|
26198
|
+
description: 'Request missing credential from user via popup.',
|
|
26199
|
+
parameters: {
|
|
26200
|
+
type: 'object',
|
|
26201
|
+
properties: {
|
|
26202
|
+
recordType: {
|
|
26203
|
+
type: 'string',
|
|
26204
|
+
description: 'Requested record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
26205
|
+
},
|
|
26206
|
+
service: { type: 'string', description: 'Service identifier.' },
|
|
26207
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
26208
|
+
message: { type: 'string', description: 'Optional UI message for user.' },
|
|
26209
|
+
isUserScoped: {
|
|
26210
|
+
type: 'boolean',
|
|
26211
|
+
description: 'Set true when record should be scoped to current user.',
|
|
26212
|
+
},
|
|
26213
|
+
isGlobal: { type: 'boolean', description: 'Set true when record should be global.' },
|
|
26214
|
+
},
|
|
26215
|
+
required: [],
|
|
26216
|
+
},
|
|
26217
|
+
});
|
|
26218
|
+
return tools;
|
|
26219
|
+
}
|
|
26220
|
+
/**
|
|
26221
|
+
* Registers one wallet tool when missing in current tool list.
|
|
26222
|
+
*
|
|
26223
|
+
* @private function of WalletCommitmentDefinition
|
|
26224
|
+
*/
|
|
26225
|
+
function addWalletToolIfMissing(tools, tool) {
|
|
26226
|
+
if (!tools.some((existingTool) => existingTool.name === tool.name)) {
|
|
26227
|
+
tools.push(tool);
|
|
26228
|
+
}
|
|
26229
|
+
}
|
|
26230
|
+
|
|
26231
|
+
/**
|
|
26232
|
+
* Gets markdown documentation for WALLET commitment.
|
|
26233
|
+
*
|
|
26234
|
+
* @private function of WalletCommitmentDefinition
|
|
26235
|
+
*/
|
|
26236
|
+
function getWalletCommitmentDocumentation(type) {
|
|
26237
|
+
return _spaceTrim.spaceTrim(`
|
|
26238
|
+
# ${type}
|
|
26239
|
+
|
|
26240
|
+
Enables private credential storage for tokens, usernames/passwords, and session cookies.
|
|
26241
|
+
`);
|
|
26242
|
+
}
|
|
26243
|
+
|
|
26244
|
+
/**
|
|
26245
|
+
* Gets human-readable titles for WALLET tool functions.
|
|
26246
|
+
*
|
|
26247
|
+
* @private function of WalletCommitmentDefinition
|
|
26248
|
+
*/
|
|
26249
|
+
function getWalletToolTitles() {
|
|
26250
|
+
return {
|
|
26251
|
+
[WalletToolNames.retrieve]: 'Wallet',
|
|
26252
|
+
[WalletToolNames.store]: 'Store wallet record',
|
|
26253
|
+
[WalletToolNames.update]: 'Update wallet record',
|
|
26254
|
+
[WalletToolNames.delete]: 'Delete wallet record',
|
|
26255
|
+
[WalletToolNames.request]: 'Request wallet record',
|
|
26256
|
+
};
|
|
26257
|
+
}
|
|
26258
|
+
|
|
26259
|
+
/**
|
|
26260
|
+
* WALLET commitment definition.
|
|
26261
|
+
*
|
|
26262
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
26263
|
+
*/
|
|
26264
|
+
class WalletCommitmentDefinition extends BaseCommitmentDefinition {
|
|
26265
|
+
constructor(type = 'WALLET') {
|
|
26266
|
+
super(type);
|
|
26267
|
+
}
|
|
26268
|
+
get requiresContent() {
|
|
26269
|
+
return false;
|
|
26270
|
+
}
|
|
26271
|
+
get description() {
|
|
26272
|
+
return 'Enable persistent private credential storage (tokens, logins, cookies) scoped per agent or globally.';
|
|
26273
|
+
}
|
|
26274
|
+
get icon() {
|
|
26275
|
+
return '👛';
|
|
26276
|
+
}
|
|
26277
|
+
get documentation() {
|
|
26278
|
+
return getWalletCommitmentDocumentation(this.type);
|
|
26279
|
+
}
|
|
26280
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
26281
|
+
const extraInstructions = formatOptionalInstructionBlock('Wallet instructions', content);
|
|
26282
|
+
return this.appendToSystemMessage({
|
|
26283
|
+
...requirements,
|
|
26284
|
+
tools: createWalletTools(requirements.tools),
|
|
26285
|
+
_metadata: {
|
|
26286
|
+
...requirements._metadata,
|
|
26287
|
+
useWallet: content || true,
|
|
26288
|
+
},
|
|
26289
|
+
}, createWalletSystemMessage(extraInstructions));
|
|
26290
|
+
}
|
|
26291
|
+
getToolTitles() {
|
|
26292
|
+
return getWalletToolTitles();
|
|
26293
|
+
}
|
|
26294
|
+
getToolFunctions() {
|
|
26295
|
+
return createWalletToolFunctions();
|
|
26296
|
+
}
|
|
26297
|
+
}
|
|
26298
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
26299
|
+
|
|
25584
26300
|
/**
|
|
25585
26301
|
* `WRITING RULES` commitment definition.
|
|
25586
26302
|
*
|
|
@@ -25855,6 +26571,8 @@
|
|
|
25855
26571
|
new MessageSuffixCommitmentDefinition(),
|
|
25856
26572
|
new MessageCommitmentDefinition('MESSAGE'),
|
|
25857
26573
|
new MessageCommitmentDefinition('MESSAGES'),
|
|
26574
|
+
new WalletCommitmentDefinition('WALLET'),
|
|
26575
|
+
new WalletCommitmentDefinition('WALLETS'),
|
|
25858
26576
|
new ScenarioCommitmentDefinition('SCENARIO'),
|
|
25859
26577
|
new ScenarioCommitmentDefinition('SCENARIOS'),
|
|
25860
26578
|
new DeleteCommitmentDefinition('DELETE'),
|
|
@@ -25901,11 +26619,11 @@
|
|
|
25901
26619
|
*/
|
|
25902
26620
|
const IMPORTANT_COMMITMENT_TYPE_SORT_ORDER = new Map([
|
|
25903
26621
|
['GOAL', 0],
|
|
25904
|
-
['
|
|
25905
|
-
['
|
|
25906
|
-
['
|
|
25907
|
-
['
|
|
25908
|
-
['
|
|
26622
|
+
['RULE', 1],
|
|
26623
|
+
['KNOWLEDGE', 2],
|
|
26624
|
+
['TEAM', 3],
|
|
26625
|
+
['GOALS', 4],
|
|
26626
|
+
['RULES', 5],
|
|
25909
26627
|
]);
|
|
25910
26628
|
/**
|
|
25911
26629
|
* Sort rank used when unfinished, low-level, and deprecated commitments should be grouped last.
|
|
@@ -28995,7 +29713,6 @@
|
|
|
28995
29713
|
if (isVoidPseudoAgentReference(reference)) {
|
|
28996
29714
|
label = VOID_PSEUDO_AGENT_REFERENCE; // <- {Void} label
|
|
28997
29715
|
iconName = 'ShieldAlert';
|
|
28998
|
-
return null; // <- Note: Do not show `{Void}` in capabilities, it's only used for internal logic
|
|
28999
29716
|
}
|
|
29000
29717
|
return {
|
|
29001
29718
|
type: 'inheritance',
|
|
@@ -29861,6 +30578,12 @@
|
|
|
29861
30578
|
['GOAL', 'GOAL'],
|
|
29862
30579
|
['GOALS', 'GOAL'],
|
|
29863
30580
|
]);
|
|
30581
|
+
/**
|
|
30582
|
+
* Legacy commitments that should be parsed for compatibility but ignored by the model-requirements pipeline.
|
|
30583
|
+
*
|
|
30584
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
30585
|
+
*/
|
|
30586
|
+
const IGNORED_COMMITMENT_TYPES = new Set(['WALLET', 'WALLETS']);
|
|
29864
30587
|
/**
|
|
29865
30588
|
* Applies the commitment filtering rules used before commitment definitions are executed.
|
|
29866
30589
|
*
|
|
@@ -29909,6 +30632,9 @@
|
|
|
29909
30632
|
function filterDeletedCommitments(commitments) {
|
|
29910
30633
|
const filteredCommitments = [];
|
|
29911
30634
|
for (const commitment of commitments) {
|
|
30635
|
+
if (isIgnoredCommitmentType(commitment.type)) {
|
|
30636
|
+
continue;
|
|
30637
|
+
}
|
|
29912
30638
|
if (!isDeleteCommitmentType(commitment.type)) {
|
|
29913
30639
|
filteredCommitments.push(commitment);
|
|
29914
30640
|
continue;
|
|
@@ -29939,6 +30665,17 @@
|
|
|
29939
30665
|
function isDeleteCommitmentType(commitmentType) {
|
|
29940
30666
|
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
29941
30667
|
}
|
|
30668
|
+
/**
|
|
30669
|
+
* Checks whether a parsed commitment is intentionally ignored by the current model compiler.
|
|
30670
|
+
*
|
|
30671
|
+
* @param commitmentType - Commitment type to check.
|
|
30672
|
+
* @returns `true` when the commitment should not affect model requirements.
|
|
30673
|
+
*
|
|
30674
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
30675
|
+
*/
|
|
30676
|
+
function isIgnoredCommitmentType(commitmentType) {
|
|
30677
|
+
return IGNORED_COMMITMENT_TYPES.has(commitmentType);
|
|
30678
|
+
}
|
|
29942
30679
|
/**
|
|
29943
30680
|
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
29944
30681
|
*
|
|
@@ -34347,8 +35084,8 @@
|
|
|
34347
35084
|
* Prepares an AgentKit agent with optional knowledge sources and tool definitions.
|
|
34348
35085
|
*/
|
|
34349
35086
|
async prepareAgentKitAgent(options) {
|
|
34350
|
-
var _a, _b
|
|
34351
|
-
const { name, instructions, knowledgeSources, tools,
|
|
35087
|
+
var _a, _b;
|
|
35088
|
+
const { name, instructions, knowledgeSources, tools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
|
|
34352
35089
|
await this.ensureAgentKitDefaults();
|
|
34353
35090
|
if (this.options.isVerbose) {
|
|
34354
35091
|
console.info('[🤰]', 'Preparing OpenAI AgentKit agent', {
|
|
@@ -34356,11 +35093,10 @@
|
|
|
34356
35093
|
instructionsLength: instructions.length,
|
|
34357
35094
|
knowledgeSourcesCount: (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0,
|
|
34358
35095
|
toolsCount: (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0,
|
|
34359
|
-
nativeAgentKitToolsCount: (_c = nativeAgentKitTools === null || nativeAgentKitTools === void 0 ? void 0 : nativeAgentKitTools.length) !== null && _c !== void 0 ? _c : 0,
|
|
34360
35096
|
});
|
|
34361
35097
|
}
|
|
34362
35098
|
let vectorStoreId = cachedVectorStoreId;
|
|
34363
|
-
if (!vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
35099
|
+
if (this.isNativeKnowledgeSearchEnabled && !vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
34364
35100
|
const vectorStoreResult = await this.createVectorStoreWithKnowledgeSources({
|
|
34365
35101
|
client: await this.getClient(),
|
|
34366
35102
|
name,
|
|
@@ -34369,13 +35105,19 @@
|
|
|
34369
35105
|
});
|
|
34370
35106
|
vectorStoreId = vectorStoreResult.vectorStoreId;
|
|
34371
35107
|
}
|
|
34372
|
-
else if (vectorStoreId && this.options.isVerbose) {
|
|
35108
|
+
else if (this.isNativeKnowledgeSearchEnabled && vectorStoreId && this.options.isVerbose) {
|
|
34373
35109
|
console.info('[🤰]', 'Using cached vector store for AgentKit agent', {
|
|
34374
35110
|
name,
|
|
34375
35111
|
vectorStoreId,
|
|
34376
35112
|
});
|
|
34377
35113
|
}
|
|
34378
|
-
|
|
35114
|
+
if (!this.isNativeKnowledgeSearchEnabled) {
|
|
35115
|
+
vectorStoreId = undefined;
|
|
35116
|
+
}
|
|
35117
|
+
const agentKitTools = this.buildAgentKitTools({
|
|
35118
|
+
tools,
|
|
35119
|
+
vectorStoreId,
|
|
35120
|
+
});
|
|
34379
35121
|
const openAiAgentKitAgent = new agents.Agent({
|
|
34380
35122
|
name,
|
|
34381
35123
|
model: this.agentKitModelName,
|
|
@@ -34394,7 +35136,7 @@
|
|
|
34394
35136
|
name,
|
|
34395
35137
|
model: this.agentKitModelName,
|
|
34396
35138
|
toolCount: agentKitTools.length,
|
|
34397
|
-
hasVectorStore: Boolean(vectorStoreId),
|
|
35139
|
+
hasVectorStore: this.isNativeKnowledgeSearchEnabled && Boolean(vectorStoreId),
|
|
34398
35140
|
});
|
|
34399
35141
|
}
|
|
34400
35142
|
return preparedAgent;
|
|
@@ -34414,14 +35156,11 @@
|
|
|
34414
35156
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
34415
35157
|
*/
|
|
34416
35158
|
buildAgentKitTools(options) {
|
|
34417
|
-
const { tools,
|
|
35159
|
+
const { tools, vectorStoreId } = options;
|
|
34418
35160
|
const agentKitTools = [];
|
|
34419
35161
|
if (vectorStoreId) {
|
|
34420
35162
|
agentKitTools.push(agents.fileSearchTool(vectorStoreId));
|
|
34421
35163
|
}
|
|
34422
|
-
if (nativeAgentKitTools && nativeAgentKitTools.length > 0) {
|
|
34423
|
-
agentKitTools.push(...nativeAgentKitTools);
|
|
34424
|
-
}
|
|
34425
35164
|
if (tools && tools.length > 0) {
|
|
34426
35165
|
let scriptTools = null;
|
|
34427
35166
|
for (const toolDefinition of tools) {
|
|
@@ -34896,6 +35635,12 @@
|
|
|
34896
35635
|
get agentKitOptions() {
|
|
34897
35636
|
return this.options;
|
|
34898
35637
|
}
|
|
35638
|
+
/**
|
|
35639
|
+
* Returns true when hosted OpenAI vector-store search should back `knowledgeSources`.
|
|
35640
|
+
*/
|
|
35641
|
+
get isNativeKnowledgeSearchEnabled() {
|
|
35642
|
+
return this.agentKitOptions.isNativeKnowledgeSearchEnabled !== false;
|
|
35643
|
+
}
|
|
34899
35644
|
/**
|
|
34900
35645
|
* Discriminant for type guards.
|
|
34901
35646
|
*/
|