@promptbook/cli 0.112.0-132 → 0.112.0-134
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/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +4 -1
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +3 -0
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackTable.tsx +13 -8
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +3 -0
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryTable.tsx +13 -8
- package/apps/agents-server/src/app/admin/custom-css/CustomCssClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/custom-css/CustomCssEditorPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-css/CustomCssFilesPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-js/CustomJsClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/custom-js/CustomJsEditorPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-js/CustomJsFilesPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/files/FilesGalleryClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/files/FilesGalleryGrid.tsx +9 -11
- package/apps/agents-server/src/app/admin/files/FilesGalleryTable.tsx +9 -8
- package/apps/agents-server/src/app/admin/images/ImagesGalleryClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/images/ImagesGalleryGrid.tsx +16 -11
- package/apps/agents-server/src/app/admin/images/ImagesGalleryTable.tsx +18 -9
- package/apps/agents-server/src/app/admin/login-methods/shibboleth/page.tsx +9 -9
- package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +7 -6
- package/apps/agents-server/src/app/admin/servers/ServersRegistryTable.tsx +11 -10
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +4 -2
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +14 -15
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTasksCard.tsx +4 -1
- package/apps/agents-server/src/app/admin/task-manager/useTaskManagerState.ts +6 -9
- package/apps/agents-server/src/app/admin/update/CustomCommitPicker.tsx +258 -0
- package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +305 -108
- package/apps/agents-server/src/app/admin/usage/UsageClient.tsx +4 -2
- package/apps/agents-server/src/app/admin/usage/UsageClientAnalyticsPanels.tsx +6 -4
- package/apps/agents-server/src/app/admin/usage/UsageClientFormatting.ts +6 -12
- package/apps/agents-server/src/app/admin/usage/UsageClientTimelineChart.tsx +6 -3
- package/apps/agents-server/src/app/admin/usage/useUsageClientState.ts +12 -4
- package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +8 -3
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +6 -20
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorHistory.ts +9 -2
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistoryClientState.ts +2 -15
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +6 -1
- package/apps/agents-server/src/app/agents/[agentName]/integration/CalendarIntegrationSection.tsx +23 -5
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +4 -2
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +9 -4
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +4 -1
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +10 -3
- package/apps/agents-server/src/app/api/admin/update/commits/route.ts +35 -0
- package/apps/agents-server/src/app/api/admin/update/route.ts +10 -2
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +5 -0
- package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +14 -2
- package/apps/agents-server/src/app/api/v1/agents/[agentId]/route.ts +4 -0
- package/apps/agents-server/src/app/api/v1/agents/route.ts +2 -0
- package/apps/agents-server/src/app/dashboard/page.tsx +11 -16
- package/apps/agents-server/src/app/recycle-bin/actions.ts +3 -0
- package/apps/agents-server/src/app/swagger/SwaggerApiKeysPanel.tsx +4 -1
- package/apps/agents-server/src/app/system/user-memory/UserMemoryClient.tsx +4 -2
- package/apps/agents-server/src/app/system/user-wallet/UserWalletClient.tsx +3 -0
- package/apps/agents-server/src/app/system/user-wallet/UserWalletRecordsTable.tsx +5 -1
- package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorClient.tsx +3 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorSidebar.tsx +7 -8
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -2
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +4 -2
- package/apps/agents-server/src/database/migrations/2026-06-2600-agent-directory-performance-indexes.sql +14 -0
- package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +92 -1
- package/apps/agents-server/src/tools/createAgentProgressTools.ts +8 -6
- package/apps/agents-server/src/utils/localization/formatServerLanguageHumanReadableDate.ts +70 -0
- package/apps/agents-server/src/utils/localization/getRequestServerLanguage.ts +32 -0
- package/apps/agents-server/src/utils/userChat/createRunUserChatJobExecutionContext.ts +17 -0
- package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +0 -21
- package/apps/agents-server/src/utils/userChat/listUserChats.ts +5 -1
- package/apps/agents-server/src/utils/userChat/persistUserChatJobProgressCard.ts +31 -0
- package/apps/agents-server/src/utils/userChat/retryUserChatJob.ts +0 -4
- package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +29 -0
- package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +2 -2
- package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +99 -401
- package/apps/agents-server/src/utils/vpsSelfUpdate.ts +625 -51
- package/esm/index.es.js +252 -41
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
- package/esm/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
- package/esm/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
- package/esm/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
- package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
- package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +7 -0
- package/esm/src/book-3.0/cliAgentEnv.d.ts +1 -1
- package/esm/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/book-3.0/cliAgentEnv.ts +1 -1
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +1 -1
- package/src/cli/cli-commands/coder/ThinkingLevel.ts +3 -1
- package/src/other/templates/getTemplatesPipelineCollection.ts +911 -741
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +254 -44
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
- package/umd/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
- package/umd/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
- package/umd/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
- package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
- package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +7 -0
- package/umd/src/book-3.0/cliAgentEnv.d.ts +1 -1
- package/umd/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
- package/umd/src/version.d.ts +1 -1
|
@@ -1,423 +1,121 @@
|
|
|
1
|
-
import type { ChatMessage
|
|
2
|
-
import { ASSISTANT_PREPARATION_TOOL_CALL_NAME } from '../../../../../src/types/ToolCall';
|
|
1
|
+
import type { ChatMessage } from '@promptbook-local/types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @private internal helper for Agents Server durable chat progress
|
|
4
|
+
* User-facing phases shown while one durable chat answer is being prepared.
|
|
8
5
|
*/
|
|
9
|
-
|
|
6
|
+
export type UserChatProgressPhase =
|
|
7
|
+
| 'queued'
|
|
8
|
+
| 'reading_context'
|
|
9
|
+
| 'preparing_agent'
|
|
10
|
+
| 'checking_capabilities'
|
|
11
|
+
| 'starting_response';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @private internal helper for Agents Server durable chat progress
|
|
14
|
+
* Default title used by durable chat progress cards.
|
|
15
15
|
*/
|
|
16
|
-
const
|
|
16
|
+
const USER_CHAT_PROGRESS_TITLE = 'Working on your request';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `agent_progress` is the model's own progress channel; we never want to advertise this
|
|
22
|
-
* internal tool to the user as if it were doing visible work.
|
|
23
|
-
*
|
|
24
|
-
* @private internal helper for Agents Server durable chat progress
|
|
19
|
+
* Ordered progress item identifiers shared across all durable chat phases.
|
|
25
20
|
*/
|
|
26
|
-
const
|
|
21
|
+
const USER_CHAT_PROGRESS_ITEM_IDS = {
|
|
22
|
+
RECEIVE_MESSAGE: 'receive-message',
|
|
23
|
+
PREPARE_AGENT: 'prepare-agent',
|
|
24
|
+
CHECK_CAPABILITIES: 'check-capabilities',
|
|
25
|
+
CREATE_RESPONSE: 'create-response',
|
|
26
|
+
} as const;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @private internal helper for Agents Server durable chat progress
|
|
29
|
+
* Static progress copy for one durable chat phase.
|
|
32
30
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
* Used so users see "Searching the web" instead of "Web search" or "search_web" in
|
|
39
|
-
* the progress card. Unknown tools fall back to a sentence-cased version of their raw name.
|
|
40
|
-
*
|
|
41
|
-
* @private internal helper for Agents Server durable chat progress
|
|
42
|
-
*/
|
|
43
|
-
const FRIENDLY_TOOL_NAME_OVERRIDES: ReadonlyMap<string, string> = new Map([
|
|
44
|
-
[ASSISTANT_PREPARATION_TOOL_CALL_NAME, 'Preparing the agent'],
|
|
45
|
-
['web_search', 'Searching the web'],
|
|
46
|
-
['search_web', 'Searching the web'],
|
|
47
|
-
['search_engine_search', 'Searching the web'],
|
|
48
|
-
['browser', 'Browsing the web'],
|
|
49
|
-
['browser_open_url', 'Opening a web page'],
|
|
50
|
-
['browser_read', 'Reading a web page'],
|
|
51
|
-
['get_url_content', 'Reading a web page'],
|
|
52
|
-
['read_url', 'Reading a web page'],
|
|
53
|
-
['scrape', 'Reading a web page'],
|
|
54
|
-
['file_read', 'Reading a file'],
|
|
55
|
-
['project_read_file', 'Reading a project file'],
|
|
56
|
-
['file_write', 'Writing a file'],
|
|
57
|
-
['email_send', 'Sending an email'],
|
|
58
|
-
['send_email', 'Sending an email'],
|
|
59
|
-
]);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Options for building an automatic running progress card snapshot.
|
|
63
|
-
*
|
|
64
|
-
* @private internal helper for Agents Server durable chat progress
|
|
65
|
-
*/
|
|
66
|
-
type CreateRunningUserChatProgressCardOptions = {
|
|
67
|
-
readonly currentProgressCard?: ChatMessage['progressCard'];
|
|
68
|
-
readonly content: string;
|
|
69
|
-
readonly toolCalls?: ReadonlyArray<ToolCall>;
|
|
70
|
-
readonly updatedAt: NonNullable<ChatMessage['progressCard']>['updatedAt'];
|
|
31
|
+
type UserChatProgressPhasePresentation = {
|
|
32
|
+
readonly now: string;
|
|
33
|
+
readonly next: string;
|
|
34
|
+
readonly completedItemIds: ReadonlySet<string>;
|
|
71
35
|
};
|
|
72
36
|
|
|
73
37
|
/**
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
38
|
+
* User-facing progress copy for durable chat phases.
|
|
39
|
+
*/
|
|
40
|
+
const USER_CHAT_PROGRESS_PHASE_PRESENTATIONS: Record<UserChatProgressPhase, UserChatProgressPhasePresentation> = {
|
|
41
|
+
queued: {
|
|
42
|
+
now: 'Your message is queued and the agent will pick it up shortly.',
|
|
43
|
+
next: 'The agent will read the conversation and prepare the answer.',
|
|
44
|
+
completedItemIds: new Set([]),
|
|
45
|
+
},
|
|
46
|
+
reading_context: {
|
|
47
|
+
now: 'Reading your message and the relevant conversation context.',
|
|
48
|
+
next: 'Prepare the agent instructions and working context.',
|
|
49
|
+
completedItemIds: new Set([USER_CHAT_PROGRESS_ITEM_IDS.RECEIVE_MESSAGE]),
|
|
50
|
+
},
|
|
51
|
+
preparing_agent: {
|
|
52
|
+
now: 'Preparing the agent instructions and context needed for this request.',
|
|
53
|
+
next: 'Check which tools and inputs are available.',
|
|
54
|
+
completedItemIds: new Set([
|
|
55
|
+
USER_CHAT_PROGRESS_ITEM_IDS.RECEIVE_MESSAGE,
|
|
56
|
+
USER_CHAT_PROGRESS_ITEM_IDS.PREPARE_AGENT,
|
|
57
|
+
]),
|
|
58
|
+
},
|
|
59
|
+
checking_capabilities: {
|
|
60
|
+
now: 'Checking available tools, attachments, and context before answering.',
|
|
61
|
+
next: 'Start working through the response.',
|
|
62
|
+
completedItemIds: new Set([
|
|
63
|
+
USER_CHAT_PROGRESS_ITEM_IDS.RECEIVE_MESSAGE,
|
|
64
|
+
USER_CHAT_PROGRESS_ITEM_IDS.PREPARE_AGENT,
|
|
65
|
+
USER_CHAT_PROGRESS_ITEM_IDS.CHECK_CAPABILITIES,
|
|
66
|
+
]),
|
|
67
|
+
},
|
|
68
|
+
starting_response: {
|
|
69
|
+
now: 'Working through the response. Progress updates will stay focused on visible actions and results.',
|
|
70
|
+
next: 'Stream the final answer as soon as it is ready.',
|
|
71
|
+
completedItemIds: new Set([
|
|
72
|
+
USER_CHAT_PROGRESS_ITEM_IDS.RECEIVE_MESSAGE,
|
|
73
|
+
USER_CHAT_PROGRESS_ITEM_IDS.PREPARE_AGENT,
|
|
74
|
+
USER_CHAT_PROGRESS_ITEM_IDS.CHECK_CAPABILITIES,
|
|
75
|
+
]),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
104
78
|
|
|
105
79
|
/**
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
80
|
+
* Base progress items shown for durable chat jobs before model-specific progress arrives.
|
|
81
|
+
*/
|
|
82
|
+
const USER_CHAT_PROGRESS_ITEMS: ReadonlyArray<{
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly text: string;
|
|
85
|
+
}> = [
|
|
86
|
+
{
|
|
87
|
+
id: USER_CHAT_PROGRESS_ITEM_IDS.RECEIVE_MESSAGE,
|
|
88
|
+
text: 'Read the user request',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: USER_CHAT_PROGRESS_ITEM_IDS.PREPARE_AGENT,
|
|
92
|
+
text: 'Prepare the agent context',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: USER_CHAT_PROGRESS_ITEM_IDS.CHECK_CAPABILITIES,
|
|
96
|
+
text: 'Check available tools and inputs',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: USER_CHAT_PROGRESS_ITEM_IDS.CREATE_RESPONSE,
|
|
100
|
+
text: 'Create the response',
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates one user-facing durable chat progress card for the current job phase.
|
|
106
|
+
*/
|
|
107
|
+
export function createUserChatProgressCard(phase: UserChatProgressPhase): NonNullable<ChatMessage['progressCard']> {
|
|
108
|
+
const presentation = USER_CHAT_PROGRESS_PHASE_PRESENTATIONS[phase];
|
|
128
109
|
|
|
129
110
|
return {
|
|
130
|
-
title:
|
|
131
|
-
now:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
activeToolCalls,
|
|
139
|
-
}),
|
|
140
|
-
items: [
|
|
141
|
-
{
|
|
142
|
-
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}queued`,
|
|
143
|
-
text: 'Message added to the chat queue',
|
|
144
|
-
status: 'completed',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}runtime-prepared`,
|
|
148
|
-
text: 'Agent is ready',
|
|
149
|
-
status: 'completed',
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}generating-response`,
|
|
153
|
-
text: hasStartedWriting ? 'Writing the answer for you' : 'Thinking through your request',
|
|
154
|
-
status: hasStartedWriting ? 'completed' : 'pending',
|
|
155
|
-
},
|
|
156
|
-
...visibleToolCalls.map(createToolCallProgressItem),
|
|
157
|
-
],
|
|
158
|
-
updatedAt: options.updatedAt,
|
|
111
|
+
title: USER_CHAT_PROGRESS_TITLE,
|
|
112
|
+
now: presentation.now,
|
|
113
|
+
next: presentation.next,
|
|
114
|
+
items: USER_CHAT_PROGRESS_ITEMS.map((item) => ({
|
|
115
|
+
...item,
|
|
116
|
+
status: presentation.completedItemIds.has(item.id) ? 'completed' : 'pending',
|
|
117
|
+
})),
|
|
118
|
+
updatedAt: new Date().toISOString() as NonNullable<ChatMessage['progressCard']>['updatedAt'],
|
|
159
119
|
isVisible: true,
|
|
160
120
|
};
|
|
161
121
|
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Returns true when an existing progress card was authored by the model and should not be overwritten.
|
|
165
|
-
*
|
|
166
|
-
* @param progressCard Existing progress-card payload on the assistant message.
|
|
167
|
-
* @returns Whether automatic runner progress should leave the card untouched.
|
|
168
|
-
*
|
|
169
|
-
* @private internal helper for Agents Server durable chat progress
|
|
170
|
-
*/
|
|
171
|
-
function shouldPreserveModelProgressCard(
|
|
172
|
-
progressCard: ChatMessage['progressCard'],
|
|
173
|
-
): progressCard is NonNullable<ChatMessage['progressCard']> {
|
|
174
|
-
if (!progressCard || progressCard.isVisible === false) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (progressCard.title !== AUTOMATIC_PROGRESS_TITLE) {
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return (progressCard.items || []).some((item) => !item.id.startsWith(AUTOMATIC_PROGRESS_ITEM_ID_PREFIX));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Resolves the current-work copy for a running progress card.
|
|
187
|
-
*
|
|
188
|
-
* Prefers a friendly preview of the latest tool log so the user can see what is
|
|
189
|
-
* actually happening, then falls back to higher-level phase descriptions.
|
|
190
|
-
*
|
|
191
|
-
* @param options Running output and tool-call snapshot summary.
|
|
192
|
-
* @returns Concise user-facing progress-card "now" text.
|
|
193
|
-
*
|
|
194
|
-
* @private internal helper for Agents Server durable chat progress
|
|
195
|
-
*/
|
|
196
|
-
function resolveRunningProgressNowText(options: {
|
|
197
|
-
readonly hasStartedWriting: boolean;
|
|
198
|
-
readonly visibleToolCalls: ReadonlyArray<ToolCall>;
|
|
199
|
-
readonly activeToolCalls: ReadonlyArray<ToolCall>;
|
|
200
|
-
}): string {
|
|
201
|
-
const latestActiveLogText = resolveLatestToolLogPhrase(options.activeToolCalls);
|
|
202
|
-
if (latestActiveLogText) {
|
|
203
|
-
return latestActiveLogText;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (options.activeToolCalls.length > 0) {
|
|
207
|
-
return `${formatToolCallActionList(options.activeToolCalls)}.`;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (options.hasStartedWriting) {
|
|
211
|
-
return 'Writing the answer for you.';
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (options.visibleToolCalls.length > 0) {
|
|
215
|
-
return 'Reviewing what the tools returned.';
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return 'Thinking through your request.';
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Resolves the upcoming-work copy for a running progress card.
|
|
223
|
-
*
|
|
224
|
-
* @param options Running output and tool-call snapshot summary.
|
|
225
|
-
* @returns Concise user-facing progress-card "next" text.
|
|
226
|
-
*
|
|
227
|
-
* @private internal helper for Agents Server durable chat progress
|
|
228
|
-
*/
|
|
229
|
-
function resolveRunningProgressNextText(options: {
|
|
230
|
-
readonly hasStartedWriting: boolean;
|
|
231
|
-
readonly activeToolCalls: ReadonlyArray<ToolCall>;
|
|
232
|
-
}): string {
|
|
233
|
-
if (options.hasStartedWriting) {
|
|
234
|
-
return 'Finishing up the answer.';
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (options.activeToolCalls.length > 0) {
|
|
238
|
-
return 'The results will be turned into your answer.';
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return 'The answer will appear here once it is ready.';
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Creates one checklist item from an observed tool-call snapshot.
|
|
246
|
-
*
|
|
247
|
-
* @param toolCall Tool call observed while the model is running.
|
|
248
|
-
* @param index Position of the tool call in the current snapshot.
|
|
249
|
-
* @returns Progress item describing the tool action.
|
|
250
|
-
*
|
|
251
|
-
* @private internal helper for Agents Server durable chat progress
|
|
252
|
-
*/
|
|
253
|
-
function createToolCallProgressItem(
|
|
254
|
-
toolCall: ToolCall,
|
|
255
|
-
index: number,
|
|
256
|
-
): NonNullable<ChatMessage['progressCard']>['items'][number] {
|
|
257
|
-
return {
|
|
258
|
-
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}tool-${resolveToolCallProgressId(toolCall, index)}`,
|
|
259
|
-
text: resolveToolCallProgressText(toolCall),
|
|
260
|
-
status: isToolCallComplete(toolCall) ? 'completed' : 'pending',
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Creates a stable progress item id from one tool-call snapshot so partial updates re-use the same row.
|
|
266
|
-
*
|
|
267
|
-
* @param toolCall Tool call observed while the model is running.
|
|
268
|
-
* @param index Position of the tool call in the current snapshot.
|
|
269
|
-
* @returns Stable id suffix for the rendered progress item.
|
|
270
|
-
*
|
|
271
|
-
* @private internal helper for Agents Server durable chat progress
|
|
272
|
-
*/
|
|
273
|
-
function resolveToolCallProgressId(toolCall: ToolCall, index: number): string {
|
|
274
|
-
const rawId = toolCall.idempotencyKey || `${toolCall.name}-${index}`;
|
|
275
|
-
return rawId
|
|
276
|
-
.toLowerCase()
|
|
277
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
278
|
-
.replace(/^-+|-+$/g, '')
|
|
279
|
-
.slice(0, 80);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Resolves user-facing progress text for one tool-call snapshot.
|
|
284
|
-
*
|
|
285
|
-
* @param toolCall Tool call observed while the model is running.
|
|
286
|
-
* @returns Concise description of the tool action or its result.
|
|
287
|
-
*
|
|
288
|
-
* @private internal helper for Agents Server durable chat progress
|
|
289
|
-
*/
|
|
290
|
-
function resolveToolCallProgressText(toolCall: ToolCall): string {
|
|
291
|
-
const toolAction = resolveFriendlyToolAction(toolCall.name);
|
|
292
|
-
|
|
293
|
-
if (Array.isArray(toolCall.errors) && toolCall.errors.length > 0) {
|
|
294
|
-
return `${toolAction} ran into a problem`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const latestLogText = resolveToolCallLatestLogText(toolCall);
|
|
298
|
-
if (isToolCallComplete(toolCall)) {
|
|
299
|
-
return latestLogText ? `${toolAction} – ${latestLogText}` : `${toolAction} done`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (latestLogText) {
|
|
303
|
-
return `${toolAction}: ${latestLogText}`;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return `${toolAction}…`;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Returns a friendly phrase for the latest log line observed across the given tool calls.
|
|
311
|
-
*
|
|
312
|
-
* @param toolCalls Tool calls to inspect.
|
|
313
|
-
* @returns Compact phrase suitable for the progress-card "now" field, or null when no log is informative.
|
|
314
|
-
*
|
|
315
|
-
* @private internal helper for Agents Server durable chat progress
|
|
316
|
-
*/
|
|
317
|
-
function resolveLatestToolLogPhrase(toolCalls: ReadonlyArray<ToolCall>): string | null {
|
|
318
|
-
for (let index = toolCalls.length - 1; index >= 0; index--) {
|
|
319
|
-
const toolCall = toolCalls[index]!;
|
|
320
|
-
const latestLogText = resolveToolCallLatestLogText(toolCall);
|
|
321
|
-
if (!latestLogText) {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return `${resolveFriendlyToolAction(toolCall.name)}: ${latestLogText}`;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Returns the most recent informative log line for one tool call, truncated for compact display.
|
|
333
|
-
*
|
|
334
|
-
* @param toolCall Tool call to inspect.
|
|
335
|
-
* @returns Compact log preview or null when no informative log was observed.
|
|
336
|
-
*
|
|
337
|
-
* @private internal helper for Agents Server durable chat progress
|
|
338
|
-
*/
|
|
339
|
-
function resolveToolCallLatestLogText(toolCall: ToolCall): string | null {
|
|
340
|
-
if (!toolCall.logs || toolCall.logs.length === 0) {
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
for (let index = toolCall.logs.length - 1; index >= 0; index--) {
|
|
345
|
-
const logEntry = toolCall.logs[index];
|
|
346
|
-
const logText = logEntry?.title?.trim() || logEntry?.message?.trim();
|
|
347
|
-
if (!logText) {
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (logText.length <= MAX_TOOL_LOG_PREVIEW_LENGTH) {
|
|
352
|
-
return logText;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return `${logText.slice(0, MAX_TOOL_LOG_PREVIEW_LENGTH - 1).trimEnd()}…`;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Formats a short comma-separated description of active tool actions.
|
|
363
|
-
*
|
|
364
|
-
* @param toolCalls Visible tool calls that are still in progress.
|
|
365
|
-
* @returns Human-readable tool action list.
|
|
366
|
-
*
|
|
367
|
-
* @private internal helper for Agents Server durable chat progress
|
|
368
|
-
*/
|
|
369
|
-
function formatToolCallActionList(toolCalls: ReadonlyArray<ToolCall>): string {
|
|
370
|
-
const uniqueToolActions = [...new Set(toolCalls.map((toolCall) => resolveFriendlyToolAction(toolCall.name)))];
|
|
371
|
-
|
|
372
|
-
if (uniqueToolActions.length === 1) {
|
|
373
|
-
return uniqueToolActions[0]!;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const finalToolAction = uniqueToolActions[uniqueToolActions.length - 1]!;
|
|
377
|
-
return `${uniqueToolActions.slice(0, -1).join(', ')} and ${finalToolAction.toLowerCase()}`;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Converts one technical tool name into compact user-facing copy.
|
|
382
|
-
*
|
|
383
|
-
* Falls back to a sentence-cased version of the raw name when no friendly mapping is known.
|
|
384
|
-
*
|
|
385
|
-
* @param toolName Tool function name reported by the model.
|
|
386
|
-
* @returns Human-readable action phrase such as "Searching the web".
|
|
387
|
-
*
|
|
388
|
-
* @private internal helper for Agents Server durable chat progress
|
|
389
|
-
*/
|
|
390
|
-
function resolveFriendlyToolAction(toolName: string): string {
|
|
391
|
-
const overriddenAction = FRIENDLY_TOOL_NAME_OVERRIDES.get(toolName);
|
|
392
|
-
if (overriddenAction) {
|
|
393
|
-
return overriddenAction;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const sentenceCasedName = toolName
|
|
397
|
-
.replace(/[_-]+/g, ' ')
|
|
398
|
-
.replace(/\s+/g, ' ')
|
|
399
|
-
.trim()
|
|
400
|
-
.replace(/^\w/, (character) => character.toUpperCase());
|
|
401
|
-
|
|
402
|
-
return sentenceCasedName.length > 0 ? sentenceCasedName : 'Running a tool';
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Infers whether a tool-call snapshot has reached a terminal successful state.
|
|
407
|
-
*
|
|
408
|
-
* @param toolCall Tool call observed while the model is running.
|
|
409
|
-
* @returns Whether the tool call has a completed result and should be rendered as such.
|
|
410
|
-
*
|
|
411
|
-
* @private internal helper for Agents Server durable chat progress
|
|
412
|
-
*/
|
|
413
|
-
function isToolCallComplete(toolCall: ToolCall): boolean {
|
|
414
|
-
if (toolCall.state === 'COMPLETE') {
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
if (toolCall.state === 'ERROR' || toolCall.state === 'PARTIAL' || toolCall.state === 'PENDING') {
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return toolCall.result !== undefined && toolCall.result !== '';
|
|
423
|
-
}
|