@promptbook/browser 0.112.0-62 → 0.112.0-64
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/esm/index.es.js
CHANGED
|
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
29
29
|
* @generated
|
|
30
30
|
* @see https://github.com/webgptorg/promptbook
|
|
31
31
|
*/
|
|
32
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-64';
|
|
33
33
|
/**
|
|
34
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
35
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -6977,6 +6977,18 @@ function parseDataUrlKnowledgeSource(source) {
|
|
|
6977
6977
|
}
|
|
6978
6978
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6979
6979
|
|
|
6980
|
+
/**
|
|
6981
|
+
* Name of the tool used by agents to search configured `KNOWLEDGE` sources.
|
|
6982
|
+
*
|
|
6983
|
+
* @public exported from `@promptbook/core`
|
|
6984
|
+
*/
|
|
6985
|
+
const KNOWLEDGE_SEARCH_TOOL_NAME = 'knowledge_search';
|
|
6986
|
+
/**
|
|
6987
|
+
* Title of the system-message section generated for `KNOWLEDGE` commitments.
|
|
6988
|
+
*
|
|
6989
|
+
* @private constant of `KnowledgeCommitmentDefinition`
|
|
6990
|
+
*/
|
|
6991
|
+
const KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE = 'Knowledge Search';
|
|
6980
6992
|
/**
|
|
6981
6993
|
* KNOWLEDGE commitment definition
|
|
6982
6994
|
*
|
|
@@ -7098,9 +7110,17 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7098
7110
|
knowledgeInfoEntries.push(`Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`);
|
|
7099
7111
|
}
|
|
7100
7112
|
if (knowledgeInfoEntries.length === 0) {
|
|
7101
|
-
return nextRequirements;
|
|
7113
|
+
return addKnowledgeSearchToolAndSystemSection(nextRequirements);
|
|
7102
7114
|
}
|
|
7103
|
-
return
|
|
7115
|
+
return addKnowledgeSearchToolAndSystemSection(nextRequirements);
|
|
7116
|
+
}
|
|
7117
|
+
/**
|
|
7118
|
+
* Gets human-readable titles for tool functions provided by this commitment.
|
|
7119
|
+
*/
|
|
7120
|
+
getToolTitles() {
|
|
7121
|
+
return {
|
|
7122
|
+
[KNOWLEDGE_SEARCH_TOOL_NAME]: 'Knowledge search',
|
|
7123
|
+
};
|
|
7104
7124
|
}
|
|
7105
7125
|
}
|
|
7106
7126
|
/**
|
|
@@ -7114,6 +7134,128 @@ function hasMeaningfulNonUrlText(content, urls) {
|
|
|
7114
7134
|
const significantText = contentWithoutUrls.replace(/[\s.,!?;:'"`()[\]{}<>/-]+/g, '');
|
|
7115
7135
|
return significantText.length > 0;
|
|
7116
7136
|
}
|
|
7137
|
+
/**
|
|
7138
|
+
* Adds the shared `knowledge_search` tool definition and the consolidated system-message section.
|
|
7139
|
+
*
|
|
7140
|
+
* @param requirements - Requirements after one `KNOWLEDGE` commitment was applied.
|
|
7141
|
+
* @returns Requirements with the knowledge search instructions and tool definition.
|
|
7142
|
+
*
|
|
7143
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7144
|
+
*/
|
|
7145
|
+
function addKnowledgeSearchToolAndSystemSection(requirements) {
|
|
7146
|
+
const nextRequirements = addKnowledgeSearchTool(requirements);
|
|
7147
|
+
const section = createKnowledgeSearchSystemSection(nextRequirements);
|
|
7148
|
+
const sectionHeader = `## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}`;
|
|
7149
|
+
if (nextRequirements.systemMessage.includes(sectionHeader)) {
|
|
7150
|
+
return {
|
|
7151
|
+
...nextRequirements,
|
|
7152
|
+
systemMessage: nextRequirements.systemMessage.replace(new RegExp(`## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), section),
|
|
7153
|
+
};
|
|
7154
|
+
}
|
|
7155
|
+
return {
|
|
7156
|
+
...nextRequirements,
|
|
7157
|
+
systemMessage: nextRequirements.systemMessage.trim()
|
|
7158
|
+
? `${nextRequirements.systemMessage}\n\n${section}`
|
|
7159
|
+
: section,
|
|
7160
|
+
};
|
|
7161
|
+
}
|
|
7162
|
+
/**
|
|
7163
|
+
* Adds the `knowledge_search` model tool when it is not already present.
|
|
7164
|
+
*
|
|
7165
|
+
* @param requirements - Current model requirements.
|
|
7166
|
+
* @returns Requirements with the tool definition available to the model.
|
|
7167
|
+
*
|
|
7168
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7169
|
+
*/
|
|
7170
|
+
function addKnowledgeSearchTool(requirements) {
|
|
7171
|
+
const existingTools = requirements.tools || [];
|
|
7172
|
+
if (existingTools.some((tool) => tool.name === KNOWLEDGE_SEARCH_TOOL_NAME)) {
|
|
7173
|
+
return requirements;
|
|
7174
|
+
}
|
|
7175
|
+
return {
|
|
7176
|
+
...requirements,
|
|
7177
|
+
tools: [
|
|
7178
|
+
...existingTools,
|
|
7179
|
+
{
|
|
7180
|
+
name: KNOWLEDGE_SEARCH_TOOL_NAME,
|
|
7181
|
+
description: spaceTrim$1(`
|
|
7182
|
+
Search the agent's configured knowledge sources and return relevant excerpts with citation ids.
|
|
7183
|
+
Use this before answering questions that may depend on the agent's KNOWLEDGE commitments.
|
|
7184
|
+
`),
|
|
7185
|
+
parameters: {
|
|
7186
|
+
type: 'object',
|
|
7187
|
+
properties: {
|
|
7188
|
+
query: {
|
|
7189
|
+
type: 'string',
|
|
7190
|
+
description: 'The natural-language search query for the knowledge base.',
|
|
7191
|
+
},
|
|
7192
|
+
limit: {
|
|
7193
|
+
type: 'integer',
|
|
7194
|
+
description: 'Maximum number of matching source excerpts to return.',
|
|
7195
|
+
},
|
|
7196
|
+
},
|
|
7197
|
+
required: ['query'],
|
|
7198
|
+
},
|
|
7199
|
+
},
|
|
7200
|
+
],
|
|
7201
|
+
};
|
|
7202
|
+
}
|
|
7203
|
+
/**
|
|
7204
|
+
* Creates the model-facing system-message section for knowledge search.
|
|
7205
|
+
*
|
|
7206
|
+
* @param requirements - Current model requirements.
|
|
7207
|
+
* @returns Markdown system-message section.
|
|
7208
|
+
*
|
|
7209
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7210
|
+
*/
|
|
7211
|
+
function createKnowledgeSearchSystemSection(requirements) {
|
|
7212
|
+
const sourceEntries = createKnowledgeSourceSystemEntries(requirements);
|
|
7213
|
+
const sourceList = sourceEntries.length > 0 ? sourceEntries.map((entry) => `- ${entry}`).join('\n') : '- None';
|
|
7214
|
+
return spaceTrim$1(`
|
|
7215
|
+
## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}
|
|
7216
|
+
|
|
7217
|
+
- Use \`${KNOWLEDGE_SEARCH_TOOL_NAME}\` to search the configured knowledge sources before answering questions that depend on this agent's knowledge base.
|
|
7218
|
+
- Base source-backed factual answers on the returned excerpts.
|
|
7219
|
+
- When you use a returned excerpt, include its citation marker in the answer body, for example \`[0:0]\`.
|
|
7220
|
+
- If the search returns no relevant information, say that the knowledge base did not contain the answer instead of inventing it.
|
|
7221
|
+
|
|
7222
|
+
Configured knowledge sources:
|
|
7223
|
+
${sourceList}
|
|
7224
|
+
`);
|
|
7225
|
+
}
|
|
7226
|
+
/**
|
|
7227
|
+
* Builds a stable list of configured knowledge sources for system-message diagnostics.
|
|
7228
|
+
*
|
|
7229
|
+
* @param requirements - Current model requirements.
|
|
7230
|
+
* @returns Human-readable source entries.
|
|
7231
|
+
*
|
|
7232
|
+
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7233
|
+
*/
|
|
7234
|
+
function createKnowledgeSourceSystemEntries(requirements) {
|
|
7235
|
+
var _a;
|
|
7236
|
+
const entries = [];
|
|
7237
|
+
const seenEntries = new Set();
|
|
7238
|
+
for (const source of requirements.knowledgeSources || []) {
|
|
7239
|
+
const entry = `Source URL: ${source} (processed for retrieval during chat)`;
|
|
7240
|
+
if (seenEntries.has(entry)) {
|
|
7241
|
+
continue;
|
|
7242
|
+
}
|
|
7243
|
+
seenEntries.add(entry);
|
|
7244
|
+
entries.push(entry);
|
|
7245
|
+
}
|
|
7246
|
+
const inlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || [])
|
|
7247
|
+
.map((source) => source.filename)
|
|
7248
|
+
.filter(Boolean);
|
|
7249
|
+
for (const filename of inlineSources) {
|
|
7250
|
+
const entry = `Knowledge Source Inline: ${filename} (Inline source: processed for retrieval during chat)`;
|
|
7251
|
+
if (seenEntries.has(entry)) {
|
|
7252
|
+
continue;
|
|
7253
|
+
}
|
|
7254
|
+
seenEntries.add(entry);
|
|
7255
|
+
entries.push(entry);
|
|
7256
|
+
}
|
|
7257
|
+
return entries;
|
|
7258
|
+
}
|
|
7117
7259
|
|
|
7118
7260
|
/**
|
|
7119
7261
|
* LANGUAGE commitment definition
|
|
@@ -14873,7 +15015,7 @@ function resolveUseCalendarToolRuntime(args) {
|
|
|
14873
15015
|
const runtimeContext = (readToolRuntimeContextFromToolArgs(args) ||
|
|
14874
15016
|
{});
|
|
14875
15017
|
const configuredCalendars = normalizeConfiguredCalendars$1((_a = runtimeContext.calendars) === null || _a === void 0 ? void 0 : _a.connections);
|
|
14876
|
-
const calendarArgument = normalizeOptionalText$
|
|
15018
|
+
const calendarArgument = normalizeOptionalText$2(args.calendarUrl);
|
|
14877
15019
|
let calendarReference = null;
|
|
14878
15020
|
if (calendarArgument) {
|
|
14879
15021
|
calendarReference = parseGoogleCalendarReference(calendarArgument);
|
|
@@ -14893,7 +15035,7 @@ function resolveUseCalendarToolRuntime(args) {
|
|
|
14893
15035
|
if (!calendarReference) {
|
|
14894
15036
|
throw new Error('Calendar is required but was not resolved.');
|
|
14895
15037
|
}
|
|
14896
|
-
const accessToken = normalizeOptionalText$
|
|
15038
|
+
const accessToken = normalizeOptionalText$2((_b = runtimeContext.calendars) === null || _b === void 0 ? void 0 : _b.googleAccessToken) || '';
|
|
14897
15039
|
if (!accessToken) {
|
|
14898
15040
|
throw new CalendarWalletCredentialRequiredError({
|
|
14899
15041
|
calendarReference,
|
|
@@ -14926,7 +15068,7 @@ function normalizeConfiguredCalendars$1(rawCalendars) {
|
|
|
14926
15068
|
continue;
|
|
14927
15069
|
}
|
|
14928
15070
|
const calendar = rawCalendar;
|
|
14929
|
-
const rawUrl = normalizeOptionalText$
|
|
15071
|
+
const rawUrl = normalizeOptionalText$2(calendar.url);
|
|
14930
15072
|
if (!rawUrl) {
|
|
14931
15073
|
continue;
|
|
14932
15074
|
}
|
|
@@ -14977,7 +15119,7 @@ function createCalendarWalletCredentialRequiredResult(error) {
|
|
|
14977
15119
|
*
|
|
14978
15120
|
* @private function of resolveUseCalendarToolRuntimeOrWalletCredentialResult
|
|
14979
15121
|
*/
|
|
14980
|
-
function normalizeOptionalText$
|
|
15122
|
+
function normalizeOptionalText$2(value) {
|
|
14981
15123
|
if (typeof value !== 'string') {
|
|
14982
15124
|
return undefined;
|
|
14983
15125
|
}
|
|
@@ -15009,13 +15151,13 @@ function createUseCalendarToolFunctions() {
|
|
|
15009
15151
|
async [UseCalendarToolNames.listEvents](args) {
|
|
15010
15152
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
15011
15153
|
const query = {};
|
|
15012
|
-
if (normalizeOptionalText(args.timeMin)) {
|
|
15154
|
+
if (normalizeOptionalText$1(args.timeMin)) {
|
|
15013
15155
|
query.timeMin = args.timeMin.trim();
|
|
15014
15156
|
}
|
|
15015
|
-
if (normalizeOptionalText(args.timeMax)) {
|
|
15157
|
+
if (normalizeOptionalText$1(args.timeMax)) {
|
|
15016
15158
|
query.timeMax = args.timeMax.trim();
|
|
15017
15159
|
}
|
|
15018
|
-
if (normalizeOptionalText(args.query)) {
|
|
15160
|
+
if (normalizeOptionalText$1(args.query)) {
|
|
15019
15161
|
query.q = args.query.trim();
|
|
15020
15162
|
}
|
|
15021
15163
|
if (typeof args.maxResults === 'number' && Number.isFinite(args.maxResults) && args.maxResults > 0) {
|
|
@@ -15027,7 +15169,7 @@ function createUseCalendarToolFunctions() {
|
|
|
15027
15169
|
if (args.orderBy === 'startTime' || args.orderBy === 'updated') {
|
|
15028
15170
|
query.orderBy = args.orderBy;
|
|
15029
15171
|
}
|
|
15030
|
-
if (normalizeOptionalText(args.timeZone)) {
|
|
15172
|
+
if (normalizeOptionalText$1(args.timeZone)) {
|
|
15031
15173
|
query.timeZone = args.timeZone.trim();
|
|
15032
15174
|
}
|
|
15033
15175
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -15065,11 +15207,11 @@ function createUseCalendarToolFunctions() {
|
|
|
15065
15207
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
15066
15208
|
const requestBody = createGoogleCalendarEventPayload({
|
|
15067
15209
|
summary: normalizeRequiredText(args.summary, 'summary'),
|
|
15068
|
-
description: normalizeOptionalText(args.description),
|
|
15069
|
-
location: normalizeOptionalText(args.location),
|
|
15210
|
+
description: normalizeOptionalText$1(args.description),
|
|
15211
|
+
location: normalizeOptionalText$1(args.location),
|
|
15070
15212
|
start: normalizeRequiredText(args.start, 'start'),
|
|
15071
15213
|
end: normalizeRequiredText(args.end, 'end'),
|
|
15072
|
-
timeZone: normalizeOptionalText(args.timeZone),
|
|
15214
|
+
timeZone: normalizeOptionalText$1(args.timeZone),
|
|
15073
15215
|
attendees: normalizeAttendees(args.attendees),
|
|
15074
15216
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
15075
15217
|
});
|
|
@@ -15091,12 +15233,12 @@ function createUseCalendarToolFunctions() {
|
|
|
15091
15233
|
return withUseCalendarRuntime(args, async ({ calendarReference, accessToken }) => {
|
|
15092
15234
|
const eventId = normalizeRequiredText(args.eventId, 'eventId');
|
|
15093
15235
|
const requestBody = createGoogleCalendarEventPayload({
|
|
15094
|
-
summary: normalizeOptionalText(args.summary),
|
|
15095
|
-
description: normalizeOptionalText(args.description),
|
|
15096
|
-
location: normalizeOptionalText(args.location),
|
|
15097
|
-
start: normalizeOptionalText(args.start),
|
|
15098
|
-
end: normalizeOptionalText(args.end),
|
|
15099
|
-
timeZone: normalizeOptionalText(args.timeZone),
|
|
15236
|
+
summary: normalizeOptionalText$1(args.summary),
|
|
15237
|
+
description: normalizeOptionalText$1(args.description),
|
|
15238
|
+
location: normalizeOptionalText$1(args.location),
|
|
15239
|
+
start: normalizeOptionalText$1(args.start),
|
|
15240
|
+
end: normalizeOptionalText$1(args.end),
|
|
15241
|
+
timeZone: normalizeOptionalText$1(args.timeZone),
|
|
15100
15242
|
attendees: normalizeAttendees(args.attendees),
|
|
15101
15243
|
reminderMinutes: normalizeReminderMinutes(args.reminderMinutes),
|
|
15102
15244
|
});
|
|
@@ -15143,7 +15285,7 @@ function createUseCalendarToolFunctions() {
|
|
|
15143
15285
|
path: `/calendars/${encodeGoogleCalendarId(calendarReference.calendarId)}/events/${encodeURIComponent(eventId)}`,
|
|
15144
15286
|
});
|
|
15145
15287
|
const existingAttendees = ((existingEvent === null || existingEvent === void 0 ? void 0 : existingEvent.attendees) || [])
|
|
15146
|
-
.map((attendee) => normalizeOptionalText(attendee.email))
|
|
15288
|
+
.map((attendee) => normalizeOptionalText$1(attendee.email))
|
|
15147
15289
|
.filter((email) => Boolean(email));
|
|
15148
15290
|
const mergedAttendees = [...new Set([...existingAttendees, ...guests])];
|
|
15149
15291
|
const payload = await callGoogleCalendarApi(accessToken, {
|
|
@@ -15191,7 +15333,7 @@ function encodeGoogleCalendarId(calendarId) {
|
|
|
15191
15333
|
* @private function of createUseCalendarToolFunctions
|
|
15192
15334
|
*/
|
|
15193
15335
|
function normalizeRequiredText(value, fieldName) {
|
|
15194
|
-
const normalizedValue = normalizeOptionalText(value);
|
|
15336
|
+
const normalizedValue = normalizeOptionalText$1(value);
|
|
15195
15337
|
if (!normalizedValue) {
|
|
15196
15338
|
throw new Error(`Tool "${fieldName}" requires non-empty value.`);
|
|
15197
15339
|
}
|
|
@@ -15202,7 +15344,7 @@ function normalizeRequiredText(value, fieldName) {
|
|
|
15202
15344
|
*
|
|
15203
15345
|
* @private function of createUseCalendarToolFunctions
|
|
15204
15346
|
*/
|
|
15205
|
-
function normalizeOptionalText(value) {
|
|
15347
|
+
function normalizeOptionalText$1(value) {
|
|
15206
15348
|
if (typeof value !== 'string') {
|
|
15207
15349
|
return undefined;
|
|
15208
15350
|
}
|
|
@@ -19888,6 +20030,580 @@ class UseUserLocationCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19888
20030
|
}
|
|
19889
20031
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
19890
20032
|
|
|
20033
|
+
/**
|
|
20034
|
+
* Names of tools used by the WALLET commitment.
|
|
20035
|
+
*
|
|
20036
|
+
* @private constant of WalletCommitmentDefinition
|
|
20037
|
+
*/
|
|
20038
|
+
const WalletToolNames = {
|
|
20039
|
+
retrieve: 'retrieve_wallet_records',
|
|
20040
|
+
store: 'store_wallet_record',
|
|
20041
|
+
update: 'update_wallet_record',
|
|
20042
|
+
delete: 'delete_wallet_record',
|
|
20043
|
+
request: 'request_wallet_record',
|
|
20044
|
+
};
|
|
20045
|
+
|
|
20046
|
+
/**
|
|
20047
|
+
* Creates WALLET system-message instructions.
|
|
20048
|
+
*
|
|
20049
|
+
* @private function of WalletCommitmentDefinition
|
|
20050
|
+
*/
|
|
20051
|
+
function createWalletSystemMessage(extraInstructions) {
|
|
20052
|
+
return spaceTrim$1((block) => `
|
|
20053
|
+
Wallet:
|
|
20054
|
+
- Use "${WalletToolNames.retrieve}" before authenticated operations.
|
|
20055
|
+
- Use "${WalletToolNames.store}" and "${WalletToolNames.update}" to maintain credentials.
|
|
20056
|
+
- Use "${WalletToolNames.delete}" to remove invalid credentials.
|
|
20057
|
+
- Use "${WalletToolNames.request}" to request missing credentials via UI popup.
|
|
20058
|
+
- Scope records by user (\`isUserScoped\`) and/or by agent (\`isGlobal=false\`) as needed.
|
|
20059
|
+
- Never expose raw credentials in chat responses.
|
|
20060
|
+
${block(extraInstructions)}
|
|
20061
|
+
`);
|
|
20062
|
+
}
|
|
20063
|
+
|
|
20064
|
+
/**
|
|
20065
|
+
* Resolves disabled message for wallet runtime context.
|
|
20066
|
+
*
|
|
20067
|
+
* @private function of WalletCommitmentDefinition
|
|
20068
|
+
*/
|
|
20069
|
+
function resolveWalletDisabledMessage(runtimeContext) {
|
|
20070
|
+
if (runtimeContext.isPrivateMode) {
|
|
20071
|
+
return 'Wallet is disabled because private mode is active.';
|
|
20072
|
+
}
|
|
20073
|
+
if (runtimeContext.isTeamConversation) {
|
|
20074
|
+
return 'Wallet is disabled for TEAM conversations.';
|
|
20075
|
+
}
|
|
20076
|
+
if (!runtimeContext.enabled) {
|
|
20077
|
+
return 'Wallet is disabled for unauthenticated users.';
|
|
20078
|
+
}
|
|
20079
|
+
return null;
|
|
20080
|
+
}
|
|
20081
|
+
/**
|
|
20082
|
+
* Resolves runtime adapter for wallet tools or returns disabled payload when unavailable.
|
|
20083
|
+
*
|
|
20084
|
+
* @private function of WalletCommitmentDefinition
|
|
20085
|
+
*/
|
|
20086
|
+
function getWalletToolRuntimeAdapterOrDisabledResult(action, runtimeContext) {
|
|
20087
|
+
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
20088
|
+
if (disabledMessage) {
|
|
20089
|
+
return {
|
|
20090
|
+
adapter: null,
|
|
20091
|
+
disabledResult: {
|
|
20092
|
+
action,
|
|
20093
|
+
status: 'disabled',
|
|
20094
|
+
records: action === 'retrieve' ? [] : undefined,
|
|
20095
|
+
message: disabledMessage,
|
|
20096
|
+
},
|
|
20097
|
+
};
|
|
20098
|
+
}
|
|
20099
|
+
{
|
|
20100
|
+
return {
|
|
20101
|
+
adapter: null,
|
|
20102
|
+
disabledResult: {
|
|
20103
|
+
action,
|
|
20104
|
+
status: 'disabled',
|
|
20105
|
+
records: action === 'retrieve' ? [] : undefined,
|
|
20106
|
+
message: 'Wallet runtime is not available in this environment.',
|
|
20107
|
+
},
|
|
20108
|
+
};
|
|
20109
|
+
}
|
|
20110
|
+
}
|
|
20111
|
+
|
|
20112
|
+
/**
|
|
20113
|
+
* Parses store/update wallet payload.
|
|
20114
|
+
*
|
|
20115
|
+
* @private function of WalletCommitmentDefinition
|
|
20116
|
+
*/
|
|
20117
|
+
function parseWalletPayload(args) {
|
|
20118
|
+
const recordType = parseWalletRecordType(args.recordType);
|
|
20119
|
+
return {
|
|
20120
|
+
recordType,
|
|
20121
|
+
service: parseWalletService(args.service),
|
|
20122
|
+
key: parseWalletKey(args.key),
|
|
20123
|
+
isUserScoped: args.isUserScoped === true,
|
|
20124
|
+
isGlobal: args.isGlobal === true,
|
|
20125
|
+
...parseWalletSecrets({
|
|
20126
|
+
recordType,
|
|
20127
|
+
username: args.username,
|
|
20128
|
+
password: args.password,
|
|
20129
|
+
secret: args.secret,
|
|
20130
|
+
cookies: args.cookies,
|
|
20131
|
+
}),
|
|
20132
|
+
};
|
|
20133
|
+
}
|
|
20134
|
+
/**
|
|
20135
|
+
* Parses text argument and returns trimmed text when available.
|
|
20136
|
+
*
|
|
20137
|
+
* @private function of WalletCommitmentDefinition
|
|
20138
|
+
*/
|
|
20139
|
+
function normalizeOptionalText(value) {
|
|
20140
|
+
if (typeof value !== 'string') {
|
|
20141
|
+
return undefined;
|
|
20142
|
+
}
|
|
20143
|
+
const trimmed = value.trim();
|
|
20144
|
+
return trimmed || undefined;
|
|
20145
|
+
}
|
|
20146
|
+
/**
|
|
20147
|
+
* Parses wallet service argument.
|
|
20148
|
+
*
|
|
20149
|
+
* @private function of WalletCommitmentDefinition
|
|
20150
|
+
*/
|
|
20151
|
+
function parseWalletService(value) {
|
|
20152
|
+
return (normalizeOptionalText(value) || 'generic').toLowerCase();
|
|
20153
|
+
}
|
|
20154
|
+
/**
|
|
20155
|
+
* Parses wallet key argument.
|
|
20156
|
+
*
|
|
20157
|
+
* @private function of WalletCommitmentDefinition
|
|
20158
|
+
*/
|
|
20159
|
+
function parseWalletKey(value) {
|
|
20160
|
+
return normalizeOptionalText(value) || 'default';
|
|
20161
|
+
}
|
|
20162
|
+
/**
|
|
20163
|
+
* Parses one wallet record id argument.
|
|
20164
|
+
*
|
|
20165
|
+
* @private function of WalletCommitmentDefinition
|
|
20166
|
+
*/
|
|
20167
|
+
function parseWalletId(value) {
|
|
20168
|
+
const walletId = normalizeOptionalText(value);
|
|
20169
|
+
if (!walletId) {
|
|
20170
|
+
throw new Error('Wallet id is required.');
|
|
20171
|
+
}
|
|
20172
|
+
return walletId;
|
|
20173
|
+
}
|
|
20174
|
+
/**
|
|
20175
|
+
* Parses wallet record type.
|
|
20176
|
+
*
|
|
20177
|
+
* @private function of WalletCommitmentDefinition
|
|
20178
|
+
*/
|
|
20179
|
+
function parseWalletRecordType(value, fallback) {
|
|
20180
|
+
var _a;
|
|
20181
|
+
const normalizedType = (_a = normalizeOptionalText(value)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
20182
|
+
if (normalizedType === 'USERNAME_PASSWORD') {
|
|
20183
|
+
return 'USERNAME_PASSWORD';
|
|
20184
|
+
}
|
|
20185
|
+
if (normalizedType === 'SESSION_COOKIE') {
|
|
20186
|
+
return 'SESSION_COOKIE';
|
|
20187
|
+
}
|
|
20188
|
+
if (normalizedType === 'ACCESS_TOKEN') {
|
|
20189
|
+
return 'ACCESS_TOKEN';
|
|
20190
|
+
}
|
|
20191
|
+
if (fallback) {
|
|
20192
|
+
return fallback;
|
|
20193
|
+
}
|
|
20194
|
+
throw new Error('Unsupported wallet recordType. Expected one of: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.');
|
|
20195
|
+
}
|
|
20196
|
+
/**
|
|
20197
|
+
* Parses wallet secret fields according to record type.
|
|
20198
|
+
*
|
|
20199
|
+
* @private function of WalletCommitmentDefinition
|
|
20200
|
+
*/
|
|
20201
|
+
function parseWalletSecrets(args) {
|
|
20202
|
+
const username = normalizeOptionalText(args.username);
|
|
20203
|
+
const password = normalizeOptionalText(args.password);
|
|
20204
|
+
const secret = normalizeOptionalText(args.secret);
|
|
20205
|
+
const cookies = normalizeOptionalText(args.cookies);
|
|
20206
|
+
if (args.recordType === 'USERNAME_PASSWORD') {
|
|
20207
|
+
if (!username || !password) {
|
|
20208
|
+
throw new Error('Both username and password are required for USERNAME_PASSWORD.');
|
|
20209
|
+
}
|
|
20210
|
+
return { username, password };
|
|
20211
|
+
}
|
|
20212
|
+
if (args.recordType === 'SESSION_COOKIE') {
|
|
20213
|
+
if (!cookies) {
|
|
20214
|
+
throw new Error('Cookies are required for SESSION_COOKIE.');
|
|
20215
|
+
}
|
|
20216
|
+
return { cookies };
|
|
20217
|
+
}
|
|
20218
|
+
if (!secret) {
|
|
20219
|
+
throw new Error('Secret is required for ACCESS_TOKEN.');
|
|
20220
|
+
}
|
|
20221
|
+
return { secret };
|
|
20222
|
+
}
|
|
20223
|
+
/**
|
|
20224
|
+
* Collection of WALLET tool argument parsers.
|
|
20225
|
+
*
|
|
20226
|
+
* @private function of WalletCommitmentDefinition
|
|
20227
|
+
*/
|
|
20228
|
+
const parseWalletToolArgs = {
|
|
20229
|
+
/**
|
|
20230
|
+
* Parses retrieve arguments.
|
|
20231
|
+
*/
|
|
20232
|
+
retrieve(args) {
|
|
20233
|
+
const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : undefined;
|
|
20234
|
+
return {
|
|
20235
|
+
query: normalizeOptionalText(args.query),
|
|
20236
|
+
recordType: normalizeOptionalText(args.recordType) ? parseWalletRecordType(args.recordType) : undefined,
|
|
20237
|
+
service: normalizeOptionalText(args.service) ? parseWalletService(args.service) : undefined,
|
|
20238
|
+
key: normalizeOptionalText(args.key) ? parseWalletKey(args.key) : undefined,
|
|
20239
|
+
limit: limit && limit > 0 ? Math.min(limit, 20) : undefined,
|
|
20240
|
+
};
|
|
20241
|
+
},
|
|
20242
|
+
/**
|
|
20243
|
+
* Parses store payload.
|
|
20244
|
+
*/
|
|
20245
|
+
store(args) {
|
|
20246
|
+
return parseWalletPayload(args);
|
|
20247
|
+
},
|
|
20248
|
+
/**
|
|
20249
|
+
* Parses update payload.
|
|
20250
|
+
*/
|
|
20251
|
+
update(args) {
|
|
20252
|
+
const walletId = parseWalletId(args.walletId);
|
|
20253
|
+
const record = parseWalletPayload(args);
|
|
20254
|
+
return {
|
|
20255
|
+
...record,
|
|
20256
|
+
walletId,
|
|
20257
|
+
};
|
|
20258
|
+
},
|
|
20259
|
+
/**
|
|
20260
|
+
* Parses delete payload.
|
|
20261
|
+
*/
|
|
20262
|
+
delete(args) {
|
|
20263
|
+
return { walletId: parseWalletId(args.walletId) };
|
|
20264
|
+
},
|
|
20265
|
+
/**
|
|
20266
|
+
* Parses request payload for user wallet input prompt.
|
|
20267
|
+
*/
|
|
20268
|
+
request(args) {
|
|
20269
|
+
return {
|
|
20270
|
+
recordType: parseWalletRecordType(args.recordType, 'ACCESS_TOKEN'),
|
|
20271
|
+
service: parseWalletService(args.service),
|
|
20272
|
+
key: parseWalletKey(args.key),
|
|
20273
|
+
message: normalizeOptionalText(args.message),
|
|
20274
|
+
isUserScoped: args.isUserScoped === true,
|
|
20275
|
+
isGlobal: args.isGlobal === true,
|
|
20276
|
+
};
|
|
20277
|
+
},
|
|
20278
|
+
};
|
|
20279
|
+
|
|
20280
|
+
/**
|
|
20281
|
+
* Resolves runtime context from hidden tool arguments.
|
|
20282
|
+
*
|
|
20283
|
+
* @private function of WalletCommitmentDefinition
|
|
20284
|
+
*/
|
|
20285
|
+
function resolveWalletRuntimeContext(args) {
|
|
20286
|
+
const runtimeContext = readToolRuntimeContextFromToolArgs(args);
|
|
20287
|
+
const memoryContext = runtimeContext === null || runtimeContext === void 0 ? void 0 : runtimeContext.memory;
|
|
20288
|
+
return {
|
|
20289
|
+
enabled: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.enabled) === true,
|
|
20290
|
+
userId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.userId,
|
|
20291
|
+
username: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.username,
|
|
20292
|
+
agentId: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentId,
|
|
20293
|
+
agentName: memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.agentName,
|
|
20294
|
+
isTeamConversation: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isTeamConversation) === true,
|
|
20295
|
+
isPrivateMode: (memoryContext === null || memoryContext === void 0 ? void 0 : memoryContext.isPrivateMode) === true,
|
|
20296
|
+
};
|
|
20297
|
+
}
|
|
20298
|
+
|
|
20299
|
+
/**
|
|
20300
|
+
* Creates runtime wallet tool function implementations.
|
|
20301
|
+
*
|
|
20302
|
+
* @private function of WalletCommitmentDefinition
|
|
20303
|
+
*/
|
|
20304
|
+
function createWalletToolFunctions() {
|
|
20305
|
+
return {
|
|
20306
|
+
async [WalletToolNames.retrieve](args) {
|
|
20307
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20308
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('retrieve', runtimeContext);
|
|
20309
|
+
if (!adapter || disabledResult) {
|
|
20310
|
+
return JSON.stringify(disabledResult);
|
|
20311
|
+
}
|
|
20312
|
+
try {
|
|
20313
|
+
const parsedArgs = parseWalletToolArgs.retrieve(args);
|
|
20314
|
+
const records = await adapter.retrieveWalletRecords(parsedArgs, runtimeContext);
|
|
20315
|
+
return JSON.stringify({
|
|
20316
|
+
action: 'retrieve',
|
|
20317
|
+
status: 'ok',
|
|
20318
|
+
query: parsedArgs.query,
|
|
20319
|
+
records,
|
|
20320
|
+
});
|
|
20321
|
+
}
|
|
20322
|
+
catch (error) {
|
|
20323
|
+
return JSON.stringify({
|
|
20324
|
+
action: 'retrieve',
|
|
20325
|
+
status: 'error',
|
|
20326
|
+
records: [],
|
|
20327
|
+
message: error instanceof Error ? error.message : String(error),
|
|
20328
|
+
});
|
|
20329
|
+
}
|
|
20330
|
+
},
|
|
20331
|
+
async [WalletToolNames.store](args) {
|
|
20332
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20333
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('store', runtimeContext);
|
|
20334
|
+
if (!adapter || disabledResult) {
|
|
20335
|
+
return JSON.stringify(disabledResult);
|
|
20336
|
+
}
|
|
20337
|
+
try {
|
|
20338
|
+
const parsedArgs = parseWalletToolArgs.store(args);
|
|
20339
|
+
const record = await adapter.storeWalletRecord(parsedArgs, runtimeContext);
|
|
20340
|
+
return JSON.stringify({
|
|
20341
|
+
action: 'store',
|
|
20342
|
+
status: 'stored',
|
|
20343
|
+
record,
|
|
20344
|
+
});
|
|
20345
|
+
}
|
|
20346
|
+
catch (error) {
|
|
20347
|
+
return JSON.stringify({
|
|
20348
|
+
action: 'store',
|
|
20349
|
+
status: 'error',
|
|
20350
|
+
message: error instanceof Error ? error.message : String(error),
|
|
20351
|
+
});
|
|
20352
|
+
}
|
|
20353
|
+
},
|
|
20354
|
+
async [WalletToolNames.update](args) {
|
|
20355
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20356
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('update', runtimeContext);
|
|
20357
|
+
if (!adapter || disabledResult) {
|
|
20358
|
+
return JSON.stringify(disabledResult);
|
|
20359
|
+
}
|
|
20360
|
+
try {
|
|
20361
|
+
const parsedArgs = parseWalletToolArgs.update(args);
|
|
20362
|
+
const record = await adapter.updateWalletRecord(parsedArgs, runtimeContext);
|
|
20363
|
+
return JSON.stringify({
|
|
20364
|
+
action: 'update',
|
|
20365
|
+
status: 'updated',
|
|
20366
|
+
record,
|
|
20367
|
+
});
|
|
20368
|
+
}
|
|
20369
|
+
catch (error) {
|
|
20370
|
+
return JSON.stringify({
|
|
20371
|
+
action: 'update',
|
|
20372
|
+
status: 'error',
|
|
20373
|
+
message: error instanceof Error ? error.message : String(error),
|
|
20374
|
+
});
|
|
20375
|
+
}
|
|
20376
|
+
},
|
|
20377
|
+
async [WalletToolNames.delete](args) {
|
|
20378
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20379
|
+
const { adapter, disabledResult } = getWalletToolRuntimeAdapterOrDisabledResult('delete', runtimeContext);
|
|
20380
|
+
if (!adapter || disabledResult) {
|
|
20381
|
+
return JSON.stringify(disabledResult);
|
|
20382
|
+
}
|
|
20383
|
+
try {
|
|
20384
|
+
const parsedArgs = parseWalletToolArgs.delete(args);
|
|
20385
|
+
const deleted = await adapter.deleteWalletRecord(parsedArgs, runtimeContext);
|
|
20386
|
+
return JSON.stringify({
|
|
20387
|
+
action: 'delete',
|
|
20388
|
+
status: 'deleted',
|
|
20389
|
+
walletId: deleted.id,
|
|
20390
|
+
});
|
|
20391
|
+
}
|
|
20392
|
+
catch (error) {
|
|
20393
|
+
return JSON.stringify({
|
|
20394
|
+
action: 'delete',
|
|
20395
|
+
status: 'error',
|
|
20396
|
+
message: error instanceof Error ? error.message : String(error),
|
|
20397
|
+
});
|
|
20398
|
+
}
|
|
20399
|
+
},
|
|
20400
|
+
async [WalletToolNames.request](args) {
|
|
20401
|
+
const runtimeContext = resolveWalletRuntimeContext(args);
|
|
20402
|
+
const disabledMessage = resolveWalletDisabledMessage(runtimeContext);
|
|
20403
|
+
if (disabledMessage) {
|
|
20404
|
+
return JSON.stringify({
|
|
20405
|
+
action: 'request',
|
|
20406
|
+
status: 'disabled',
|
|
20407
|
+
message: disabledMessage,
|
|
20408
|
+
});
|
|
20409
|
+
}
|
|
20410
|
+
const request = parseWalletToolArgs.request(args);
|
|
20411
|
+
return JSON.stringify({
|
|
20412
|
+
action: 'request',
|
|
20413
|
+
status: 'requested',
|
|
20414
|
+
request,
|
|
20415
|
+
message: request.message ||
|
|
20416
|
+
`Request user to provide ${request.recordType} credentials for service "${request.service}".`,
|
|
20417
|
+
});
|
|
20418
|
+
},
|
|
20419
|
+
};
|
|
20420
|
+
}
|
|
20421
|
+
|
|
20422
|
+
/**
|
|
20423
|
+
* Creates tool definitions required by WALLET commitment.
|
|
20424
|
+
*
|
|
20425
|
+
* @private function of WalletCommitmentDefinition
|
|
20426
|
+
*/
|
|
20427
|
+
function createWalletTools(existingTools) {
|
|
20428
|
+
const tools = [...(existingTools || [])];
|
|
20429
|
+
addWalletToolIfMissing(tools, {
|
|
20430
|
+
name: WalletToolNames.retrieve,
|
|
20431
|
+
description: 'Retrieve wallet records relevant to the current task.',
|
|
20432
|
+
parameters: {
|
|
20433
|
+
type: 'object',
|
|
20434
|
+
properties: {
|
|
20435
|
+
query: { type: 'string', description: 'Optional text query used to filter wallet records.' },
|
|
20436
|
+
recordType: {
|
|
20437
|
+
type: 'string',
|
|
20438
|
+
description: 'Optional record type filter (USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN).',
|
|
20439
|
+
},
|
|
20440
|
+
service: { type: 'string', description: 'Optional service filter, for example github.' },
|
|
20441
|
+
key: { type: 'string', description: 'Optional wallet key filter.' },
|
|
20442
|
+
limit: { type: 'integer', description: 'Optional maximum number of records (default 5, max 20).' },
|
|
20443
|
+
},
|
|
20444
|
+
required: [],
|
|
20445
|
+
},
|
|
20446
|
+
});
|
|
20447
|
+
addWalletToolIfMissing(tools, {
|
|
20448
|
+
name: WalletToolNames.store,
|
|
20449
|
+
description: 'Store one wallet record.',
|
|
20450
|
+
parameters: {
|
|
20451
|
+
type: 'object',
|
|
20452
|
+
properties: {
|
|
20453
|
+
recordType: {
|
|
20454
|
+
type: 'string',
|
|
20455
|
+
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20456
|
+
},
|
|
20457
|
+
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
20458
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
20459
|
+
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
20460
|
+
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
20461
|
+
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
20462
|
+
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
20463
|
+
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
20464
|
+
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
20465
|
+
},
|
|
20466
|
+
required: ['recordType', 'service'],
|
|
20467
|
+
},
|
|
20468
|
+
});
|
|
20469
|
+
addWalletToolIfMissing(tools, {
|
|
20470
|
+
name: WalletToolNames.update,
|
|
20471
|
+
description: 'Update one existing wallet record.',
|
|
20472
|
+
parameters: {
|
|
20473
|
+
type: 'object',
|
|
20474
|
+
properties: {
|
|
20475
|
+
walletId: { type: 'string', description: 'Wallet record id to update.' },
|
|
20476
|
+
recordType: {
|
|
20477
|
+
type: 'string',
|
|
20478
|
+
description: 'Record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20479
|
+
},
|
|
20480
|
+
service: { type: 'string', description: 'Service identifier, for example github.' },
|
|
20481
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
20482
|
+
username: { type: 'string', description: 'Username for USERNAME_PASSWORD.' },
|
|
20483
|
+
password: { type: 'string', description: 'Password for USERNAME_PASSWORD.' },
|
|
20484
|
+
secret: { type: 'string', description: 'Token/API key for ACCESS_TOKEN.' },
|
|
20485
|
+
cookies: { type: 'string', description: 'Cookie header/json for SESSION_COOKIE.' },
|
|
20486
|
+
isUserScoped: { type: 'boolean', description: 'Set true to scope this record to current user.' },
|
|
20487
|
+
isGlobal: { type: 'boolean', description: 'Set true to make this record global.' },
|
|
20488
|
+
},
|
|
20489
|
+
required: ['walletId', 'recordType', 'service'],
|
|
20490
|
+
},
|
|
20491
|
+
});
|
|
20492
|
+
addWalletToolIfMissing(tools, {
|
|
20493
|
+
name: WalletToolNames.delete,
|
|
20494
|
+
description: 'Delete one wallet record.',
|
|
20495
|
+
parameters: {
|
|
20496
|
+
type: 'object',
|
|
20497
|
+
properties: {
|
|
20498
|
+
walletId: { type: 'string', description: 'Wallet record id to delete.' },
|
|
20499
|
+
},
|
|
20500
|
+
required: ['walletId'],
|
|
20501
|
+
},
|
|
20502
|
+
});
|
|
20503
|
+
addWalletToolIfMissing(tools, {
|
|
20504
|
+
name: WalletToolNames.request,
|
|
20505
|
+
description: 'Request missing credential from user via popup.',
|
|
20506
|
+
parameters: {
|
|
20507
|
+
type: 'object',
|
|
20508
|
+
properties: {
|
|
20509
|
+
recordType: {
|
|
20510
|
+
type: 'string',
|
|
20511
|
+
description: 'Requested record type: USERNAME_PASSWORD, SESSION_COOKIE, ACCESS_TOKEN.',
|
|
20512
|
+
},
|
|
20513
|
+
service: { type: 'string', description: 'Service identifier.' },
|
|
20514
|
+
key: { type: 'string', description: 'Logical credential key.' },
|
|
20515
|
+
message: { type: 'string', description: 'Optional UI message for user.' },
|
|
20516
|
+
isUserScoped: {
|
|
20517
|
+
type: 'boolean',
|
|
20518
|
+
description: 'Set true when record should be scoped to current user.',
|
|
20519
|
+
},
|
|
20520
|
+
isGlobal: { type: 'boolean', description: 'Set true when record should be global.' },
|
|
20521
|
+
},
|
|
20522
|
+
required: [],
|
|
20523
|
+
},
|
|
20524
|
+
});
|
|
20525
|
+
return tools;
|
|
20526
|
+
}
|
|
20527
|
+
/**
|
|
20528
|
+
* Registers one wallet tool when missing in current tool list.
|
|
20529
|
+
*
|
|
20530
|
+
* @private function of WalletCommitmentDefinition
|
|
20531
|
+
*/
|
|
20532
|
+
function addWalletToolIfMissing(tools, tool) {
|
|
20533
|
+
if (!tools.some((existingTool) => existingTool.name === tool.name)) {
|
|
20534
|
+
tools.push(tool);
|
|
20535
|
+
}
|
|
20536
|
+
}
|
|
20537
|
+
|
|
20538
|
+
/**
|
|
20539
|
+
* Gets markdown documentation for WALLET commitment.
|
|
20540
|
+
*
|
|
20541
|
+
* @private function of WalletCommitmentDefinition
|
|
20542
|
+
*/
|
|
20543
|
+
function getWalletCommitmentDocumentation(type) {
|
|
20544
|
+
return spaceTrim$1(`
|
|
20545
|
+
# ${type}
|
|
20546
|
+
|
|
20547
|
+
Enables private credential storage for tokens, usernames/passwords, and session cookies.
|
|
20548
|
+
`);
|
|
20549
|
+
}
|
|
20550
|
+
|
|
20551
|
+
/**
|
|
20552
|
+
* Gets human-readable titles for WALLET tool functions.
|
|
20553
|
+
*
|
|
20554
|
+
* @private function of WalletCommitmentDefinition
|
|
20555
|
+
*/
|
|
20556
|
+
function getWalletToolTitles() {
|
|
20557
|
+
return {
|
|
20558
|
+
[WalletToolNames.retrieve]: 'Wallet',
|
|
20559
|
+
[WalletToolNames.store]: 'Store wallet record',
|
|
20560
|
+
[WalletToolNames.update]: 'Update wallet record',
|
|
20561
|
+
[WalletToolNames.delete]: 'Delete wallet record',
|
|
20562
|
+
[WalletToolNames.request]: 'Request wallet record',
|
|
20563
|
+
};
|
|
20564
|
+
}
|
|
20565
|
+
|
|
20566
|
+
/**
|
|
20567
|
+
* WALLET commitment definition.
|
|
20568
|
+
*
|
|
20569
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
20570
|
+
*/
|
|
20571
|
+
class WalletCommitmentDefinition extends BaseCommitmentDefinition {
|
|
20572
|
+
constructor(type = 'WALLET') {
|
|
20573
|
+
super(type);
|
|
20574
|
+
}
|
|
20575
|
+
get requiresContent() {
|
|
20576
|
+
return false;
|
|
20577
|
+
}
|
|
20578
|
+
get description() {
|
|
20579
|
+
return 'Enable persistent private credential storage (tokens, logins, cookies) scoped per agent or globally.';
|
|
20580
|
+
}
|
|
20581
|
+
get icon() {
|
|
20582
|
+
return '👛';
|
|
20583
|
+
}
|
|
20584
|
+
get documentation() {
|
|
20585
|
+
return getWalletCommitmentDocumentation(this.type);
|
|
20586
|
+
}
|
|
20587
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
20588
|
+
const extraInstructions = formatOptionalInstructionBlock('Wallet instructions', content);
|
|
20589
|
+
return this.appendToSystemMessage({
|
|
20590
|
+
...requirements,
|
|
20591
|
+
tools: createWalletTools(requirements.tools),
|
|
20592
|
+
_metadata: {
|
|
20593
|
+
...requirements._metadata,
|
|
20594
|
+
useWallet: content || true,
|
|
20595
|
+
},
|
|
20596
|
+
}, createWalletSystemMessage(extraInstructions));
|
|
20597
|
+
}
|
|
20598
|
+
getToolTitles() {
|
|
20599
|
+
return getWalletToolTitles();
|
|
20600
|
+
}
|
|
20601
|
+
getToolFunctions() {
|
|
20602
|
+
return createWalletToolFunctions();
|
|
20603
|
+
}
|
|
20604
|
+
}
|
|
20605
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
20606
|
+
|
|
19891
20607
|
/**
|
|
19892
20608
|
* `WRITING RULES` commitment definition.
|
|
19893
20609
|
*
|
|
@@ -20162,6 +20878,8 @@ const COMMITMENT_REGISTRY = [
|
|
|
20162
20878
|
new MessageSuffixCommitmentDefinition(),
|
|
20163
20879
|
new MessageCommitmentDefinition('MESSAGE'),
|
|
20164
20880
|
new MessageCommitmentDefinition('MESSAGES'),
|
|
20881
|
+
new WalletCommitmentDefinition('WALLET'),
|
|
20882
|
+
new WalletCommitmentDefinition('WALLETS'),
|
|
20165
20883
|
new ScenarioCommitmentDefinition('SCENARIO'),
|
|
20166
20884
|
new ScenarioCommitmentDefinition('SCENARIOS'),
|
|
20167
20885
|
new DeleteCommitmentDefinition('DELETE'),
|
|
@@ -20208,11 +20926,11 @@ const COMMITMENT_REGISTRY = [
|
|
|
20208
20926
|
*/
|
|
20209
20927
|
const IMPORTANT_COMMITMENT_TYPE_SORT_ORDER = new Map([
|
|
20210
20928
|
['GOAL', 0],
|
|
20211
|
-
['
|
|
20212
|
-
['
|
|
20213
|
-
['
|
|
20214
|
-
['
|
|
20215
|
-
['
|
|
20929
|
+
['RULE', 1],
|
|
20930
|
+
['KNOWLEDGE', 2],
|
|
20931
|
+
['TEAM', 3],
|
|
20932
|
+
['GOALS', 4],
|
|
20933
|
+
['RULES', 5],
|
|
20216
20934
|
]);
|
|
20217
20935
|
/**
|
|
20218
20936
|
* Sort rank used when unfinished, low-level, and deprecated commitments should be grouped last.
|
|
@@ -21461,7 +22179,6 @@ function createInheritanceCapability(content) {
|
|
|
21461
22179
|
if (isVoidPseudoAgentReference(reference)) {
|
|
21462
22180
|
label = VOID_PSEUDO_AGENT_REFERENCE; // <- {Void} label
|
|
21463
22181
|
iconName = 'ShieldAlert';
|
|
21464
|
-
return null; // <- Note: Do not show `{Void}` in capabilities, it's only used for internal logic
|
|
21465
22182
|
}
|
|
21466
22183
|
return {
|
|
21467
22184
|
type: 'inheritance',
|
|
@@ -27090,6 +27807,12 @@ const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
|
27090
27807
|
['GOAL', 'GOAL'],
|
|
27091
27808
|
['GOALS', 'GOAL'],
|
|
27092
27809
|
]);
|
|
27810
|
+
/**
|
|
27811
|
+
* Legacy commitments that should be parsed for compatibility but ignored by the model-requirements pipeline.
|
|
27812
|
+
*
|
|
27813
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
27814
|
+
*/
|
|
27815
|
+
const IGNORED_COMMITMENT_TYPES = new Set(['WALLET', 'WALLETS']);
|
|
27093
27816
|
/**
|
|
27094
27817
|
* Applies the commitment filtering rules used before commitment definitions are executed.
|
|
27095
27818
|
*
|
|
@@ -27138,6 +27861,9 @@ function filterOverwrittenCommitments(commitments) {
|
|
|
27138
27861
|
function filterDeletedCommitments(commitments) {
|
|
27139
27862
|
const filteredCommitments = [];
|
|
27140
27863
|
for (const commitment of commitments) {
|
|
27864
|
+
if (isIgnoredCommitmentType(commitment.type)) {
|
|
27865
|
+
continue;
|
|
27866
|
+
}
|
|
27141
27867
|
if (!isDeleteCommitmentType(commitment.type)) {
|
|
27142
27868
|
filteredCommitments.push(commitment);
|
|
27143
27869
|
continue;
|
|
@@ -27168,6 +27894,17 @@ function filterDeletedCommitments(commitments) {
|
|
|
27168
27894
|
function isDeleteCommitmentType(commitmentType) {
|
|
27169
27895
|
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
27170
27896
|
}
|
|
27897
|
+
/**
|
|
27898
|
+
* Checks whether a parsed commitment is intentionally ignored by the current model compiler.
|
|
27899
|
+
*
|
|
27900
|
+
* @param commitmentType - Commitment type to check.
|
|
27901
|
+
* @returns `true` when the commitment should not affect model requirements.
|
|
27902
|
+
*
|
|
27903
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
27904
|
+
*/
|
|
27905
|
+
function isIgnoredCommitmentType(commitmentType) {
|
|
27906
|
+
return IGNORED_COMMITMENT_TYPES.has(commitmentType);
|
|
27907
|
+
}
|
|
27171
27908
|
/**
|
|
27172
27909
|
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
27173
27910
|
*
|
|
@@ -31576,8 +32313,8 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
31576
32313
|
* Prepares an AgentKit agent with optional knowledge sources and tool definitions.
|
|
31577
32314
|
*/
|
|
31578
32315
|
async prepareAgentKitAgent(options) {
|
|
31579
|
-
var _a, _b
|
|
31580
|
-
const { name, instructions, knowledgeSources, tools,
|
|
32316
|
+
var _a, _b;
|
|
32317
|
+
const { name, instructions, knowledgeSources, tools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
|
|
31581
32318
|
await this.ensureAgentKitDefaults();
|
|
31582
32319
|
if (this.options.isVerbose) {
|
|
31583
32320
|
console.info('[🤰]', 'Preparing OpenAI AgentKit agent', {
|
|
@@ -31585,11 +32322,10 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
31585
32322
|
instructionsLength: instructions.length,
|
|
31586
32323
|
knowledgeSourcesCount: (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0,
|
|
31587
32324
|
toolsCount: (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0,
|
|
31588
|
-
nativeAgentKitToolsCount: (_c = nativeAgentKitTools === null || nativeAgentKitTools === void 0 ? void 0 : nativeAgentKitTools.length) !== null && _c !== void 0 ? _c : 0,
|
|
31589
32325
|
});
|
|
31590
32326
|
}
|
|
31591
32327
|
let vectorStoreId = cachedVectorStoreId;
|
|
31592
|
-
if (!vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
32328
|
+
if (this.isNativeKnowledgeSearchEnabled && !vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
31593
32329
|
const vectorStoreResult = await this.createVectorStoreWithKnowledgeSources({
|
|
31594
32330
|
client: await this.getClient(),
|
|
31595
32331
|
name,
|
|
@@ -31598,13 +32334,19 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
31598
32334
|
});
|
|
31599
32335
|
vectorStoreId = vectorStoreResult.vectorStoreId;
|
|
31600
32336
|
}
|
|
31601
|
-
else if (vectorStoreId && this.options.isVerbose) {
|
|
32337
|
+
else if (this.isNativeKnowledgeSearchEnabled && vectorStoreId && this.options.isVerbose) {
|
|
31602
32338
|
console.info('[🤰]', 'Using cached vector store for AgentKit agent', {
|
|
31603
32339
|
name,
|
|
31604
32340
|
vectorStoreId,
|
|
31605
32341
|
});
|
|
31606
32342
|
}
|
|
31607
|
-
|
|
32343
|
+
if (!this.isNativeKnowledgeSearchEnabled) {
|
|
32344
|
+
vectorStoreId = undefined;
|
|
32345
|
+
}
|
|
32346
|
+
const agentKitTools = this.buildAgentKitTools({
|
|
32347
|
+
tools,
|
|
32348
|
+
vectorStoreId,
|
|
32349
|
+
});
|
|
31608
32350
|
const openAiAgentKitAgent = new Agent$1({
|
|
31609
32351
|
name,
|
|
31610
32352
|
model: this.agentKitModelName,
|
|
@@ -31623,7 +32365,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
31623
32365
|
name,
|
|
31624
32366
|
model: this.agentKitModelName,
|
|
31625
32367
|
toolCount: agentKitTools.length,
|
|
31626
|
-
hasVectorStore: Boolean(vectorStoreId),
|
|
32368
|
+
hasVectorStore: this.isNativeKnowledgeSearchEnabled && Boolean(vectorStoreId),
|
|
31627
32369
|
});
|
|
31628
32370
|
}
|
|
31629
32371
|
return preparedAgent;
|
|
@@ -31643,14 +32385,11 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
31643
32385
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
31644
32386
|
*/
|
|
31645
32387
|
buildAgentKitTools(options) {
|
|
31646
|
-
const { tools,
|
|
32388
|
+
const { tools, vectorStoreId } = options;
|
|
31647
32389
|
const agentKitTools = [];
|
|
31648
32390
|
if (vectorStoreId) {
|
|
31649
32391
|
agentKitTools.push(fileSearchTool(vectorStoreId));
|
|
31650
32392
|
}
|
|
31651
|
-
if (nativeAgentKitTools && nativeAgentKitTools.length > 0) {
|
|
31652
|
-
agentKitTools.push(...nativeAgentKitTools);
|
|
31653
|
-
}
|
|
31654
32393
|
if (tools && tools.length > 0) {
|
|
31655
32394
|
let scriptTools = null;
|
|
31656
32395
|
for (const toolDefinition of tools) {
|
|
@@ -32125,6 +32864,12 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32125
32864
|
get agentKitOptions() {
|
|
32126
32865
|
return this.options;
|
|
32127
32866
|
}
|
|
32867
|
+
/**
|
|
32868
|
+
* Returns true when hosted OpenAI vector-store search should back `knowledgeSources`.
|
|
32869
|
+
*/
|
|
32870
|
+
get isNativeKnowledgeSearchEnabled() {
|
|
32871
|
+
return this.agentKitOptions.isNativeKnowledgeSearchEnabled !== false;
|
|
32872
|
+
}
|
|
32128
32873
|
/**
|
|
32129
32874
|
* Discriminant for type guards.
|
|
32130
32875
|
*/
|