@datalayer/agent-runtimes 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -1
- package/lib/AgentNode.d.ts +3 -0
- package/lib/AgentNode.js +676 -0
- package/lib/App.js +1 -1
- package/lib/agent-node/themeStore.d.ts +3 -0
- package/lib/agent-node/themeStore.js +156 -0
- package/lib/agent-node-main.d.ts +1 -0
- package/lib/agent-node-main.js +14 -0
- package/lib/agents/AgentDetails.d.ts +22 -1
- package/lib/agents/AgentDetails.js +34 -47
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +4 -2
- package/lib/chat/Chat.d.ts +5 -106
- package/lib/chat/Chat.js +20 -14
- package/lib/chat/ChatFloating.d.ts +7 -140
- package/lib/chat/ChatFloating.js +3 -3
- package/lib/chat/ChatPopupStandalone.d.ts +8 -47
- package/lib/chat/ChatPopupStandalone.js +3 -3
- package/lib/chat/ChatSidebar.d.ts +4 -69
- package/lib/chat/ChatSidebar.js +83 -51
- package/lib/chat/ChatStandalone.d.ts +4 -54
- package/lib/chat/ChatStandalone.js +3 -3
- package/lib/chat/base/ChatBase.js +1414 -174
- package/lib/chat/display/FloatingBrandButton.js +8 -1
- package/lib/chat/header/ChatHeader.d.ts +3 -1
- package/lib/chat/header/ChatHeader.js +15 -12
- package/lib/chat/header/ChatHeaderBase.d.ts +30 -5
- package/lib/chat/header/ChatHeaderBase.js +41 -16
- package/lib/chat/indicators/McpStatusIndicator.d.ts +7 -4
- package/lib/chat/indicators/McpStatusIndicator.js +7 -32
- package/lib/chat/indicators/SandboxStatusIndicator.d.ts +4 -1
- package/lib/chat/indicators/SandboxStatusIndicator.js +91 -56
- package/lib/chat/indicators/SkillsStatusIndicator.d.ts +7 -0
- package/lib/chat/indicators/SkillsStatusIndicator.js +88 -0
- package/lib/chat/indicators/index.d.ts +1 -0
- package/lib/chat/indicators/index.js +1 -0
- package/lib/chat/messages/ChatMessageList.d.ts +1 -1
- package/lib/chat/messages/ChatMessageList.js +154 -114
- package/lib/chat/messages/ChatMessages.js +6 -2
- package/lib/chat/prompt/InputFooter.d.ts +21 -6
- package/lib/chat/prompt/InputFooter.js +76 -20
- package/lib/chat/prompt/InputPrompt.d.ts +5 -1
- package/lib/chat/prompt/InputPrompt.js +4 -4
- package/lib/chat/prompt/InputPromptFooter.d.ts +3 -1
- package/lib/chat/prompt/InputPromptFooter.js +3 -3
- package/lib/chat/prompt/InputPromptLexical.d.ts +3 -1
- package/lib/chat/prompt/InputPromptLexical.js +12 -5
- package/lib/chat/prompt/InputPromptText.d.ts +3 -1
- package/lib/chat/prompt/InputPromptText.js +2 -2
- package/lib/chat/tools/ToolApprovalBanner.js +1 -1
- package/lib/chat/tools/ToolCallDisplay.d.ts +3 -1
- package/lib/chat/tools/ToolCallDisplay.js +2 -2
- package/lib/chat/usage/TokenUsageBar.js +20 -2
- package/lib/client/AgentRuntimesClientContext.d.ts +53 -0
- package/lib/client/AgentRuntimesClientContext.js +55 -0
- package/lib/client/AgentsMixin.d.ts +0 -18
- package/lib/client/AgentsMixin.js +20 -30
- package/lib/client/IAgentRuntimesClient.d.ts +215 -0
- package/lib/client/IAgentRuntimesClient.js +5 -0
- package/lib/client/SdkAgentRuntimesClient.d.ts +151 -0
- package/lib/client/SdkAgentRuntimesClient.js +134 -0
- package/lib/client/index.d.ts +4 -1
- package/lib/client/index.js +3 -1
- package/lib/components/NotificationEventCard.js +5 -1
- package/lib/config/AgentConfiguration.d.ts +22 -0
- package/lib/config/AgentConfiguration.js +319 -64
- package/lib/context/ContextDistribution.d.ts +3 -1
- package/lib/context/ContextDistribution.js +8 -27
- package/lib/context/ContextInspector.d.ts +3 -1
- package/lib/context/ContextInspector.js +19 -67
- package/lib/context/ContextPanel.d.ts +3 -1
- package/lib/context/ContextPanel.js +104 -64
- package/lib/context/ContextUsage.d.ts +3 -1
- package/lib/context/ContextUsage.js +3 -3
- package/lib/context/CostTracker.d.ts +9 -3
- package/lib/context/CostTracker.js +26 -47
- package/lib/context/CostUsageChart.d.ts +12 -0
- package/lib/context/CostUsageChart.js +378 -0
- package/lib/context/GraphFlowChart.d.ts +16 -0
- package/lib/context/GraphFlowChart.js +182 -0
- package/lib/context/TokenUsageChart.d.ts +8 -1
- package/lib/context/TokenUsageChart.js +349 -211
- package/lib/context/TurnGraphChart.d.ts +39 -0
- package/lib/context/TurnGraphChart.js +538 -0
- package/lib/context/otelWsPool.d.ts +20 -0
- package/lib/context/otelWsPool.js +69 -0
- package/lib/examples/A2UiComponentGalleryExample.d.ts +0 -17
- package/lib/examples/A2UiComponentGalleryExample.js +315 -522
- package/lib/examples/A2UiContactCardExample.d.ts +0 -18
- package/lib/examples/A2UiContactCardExample.js +154 -411
- package/lib/examples/A2UiRestaurantExample.d.ts +0 -30
- package/lib/examples/A2UiRestaurantExample.js +114 -212
- package/lib/examples/A2UiViewerExample.d.ts +0 -18
- package/lib/examples/A2UiViewerExample.js +283 -532
- package/lib/examples/AgUiBackendToolRenderingExample.js +1 -1
- package/lib/examples/AgUiHaikuGenUiExample.d.ts +1 -1
- package/lib/examples/AgUiHaikuGenUiExample.js +1 -1
- package/lib/examples/AgUiSharedStateExample.js +2 -1
- package/lib/examples/AgentCheckpointsExample.js +14 -28
- package/lib/examples/AgentCodemodeExample.d.ts +4 -6
- package/lib/examples/AgentCodemodeExample.js +603 -169
- package/lib/examples/AgentEvalsExample.js +339 -53
- package/lib/examples/AgentGuardrailsExample.js +383 -66
- package/lib/examples/AgentHooksExample.d.ts +3 -0
- package/lib/examples/AgentHooksExample.js +122 -0
- package/lib/examples/AgentInferenceProviderExample.d.ts +3 -0
- package/lib/examples/AgentInferenceProviderExample.js +329 -0
- package/lib/examples/AgentMCPExample.d.ts +3 -0
- package/lib/examples/AgentMCPExample.js +481 -0
- package/lib/examples/AgentMemoryExample.d.ts +1 -2
- package/lib/examples/AgentMemoryExample.js +78 -33
- package/lib/examples/AgentMonitoringExample.js +261 -200
- package/lib/examples/AgentNotificationsExample.d.ts +1 -2
- package/lib/examples/AgentNotificationsExample.js +114 -33
- package/lib/examples/AgentOtelExample.js +32 -42
- package/lib/examples/AgentOutputsExample.d.ts +11 -6
- package/lib/examples/AgentOutputsExample.js +433 -81
- package/lib/examples/AgentParametersExample.d.ts +3 -0
- package/lib/examples/AgentParametersExample.js +248 -0
- package/lib/examples/AgentSandboxExample.d.ts +3 -3
- package/lib/examples/AgentSandboxExample.js +74 -45
- package/lib/examples/AgentSkillsExample.js +95 -103
- package/lib/examples/AgentSubagentsExample.d.ts +14 -0
- package/lib/examples/AgentSubagentsExample.js +228 -0
- package/lib/examples/AgentToolApprovalsExample.js +49 -561
- package/lib/examples/AgentTriggersExample.js +823 -569
- package/lib/examples/{AgentspecExample.d.ts → AgentspecsExample.d.ts} +2 -2
- package/lib/examples/AgentspecsExample.js +1096 -0
- package/lib/examples/ChatCustomExample.js +16 -28
- package/lib/examples/ChatExample.js +13 -29
- package/lib/examples/CopilotKitLexicalExample.js +2 -1
- package/lib/examples/CopilotKitNotebookExample.js +2 -1
- package/lib/examples/HomeExample.d.ts +15 -0
- package/lib/examples/HomeExample.js +77 -0
- package/lib/examples/Lexical2Example.js +4 -2
- package/lib/examples/{LexicalExample.d.ts → LexicalAgentExample.d.ts} +4 -4
- package/lib/examples/{LexicalExample.js → LexicalAgentExample.js} +66 -17
- package/lib/examples/{LexicalSidebarExample.d.ts → LexicalAgentSidebarExample.d.ts} +5 -5
- package/lib/examples/LexicalAgentSidebarExample.js +261 -0
- package/lib/examples/NotebookAgentExample.d.ts +9 -0
- package/lib/examples/NotebookAgentExample.js +192 -0
- package/lib/examples/{NotebookSidebarExample.d.ts → NotebookAgentSidebarExample.d.ts} +2 -2
- package/lib/examples/NotebookAgentSidebarExample.js +221 -0
- package/lib/examples/{DatalayerNotebookExample.d.ts → NotebookCollaborationExample.d.ts} +4 -4
- package/lib/examples/{DatalayerNotebookExample.js → NotebookCollaborationExample.js} +3 -3
- package/lib/examples/NotebookExample.d.ts +4 -7
- package/lib/examples/NotebookExample.js +14 -146
- package/lib/examples/components/AuthRequiredView.d.ts +6 -0
- package/lib/examples/components/AuthRequiredView.js +33 -0
- package/lib/examples/components/ExampleWrapper.d.ts +9 -3
- package/lib/examples/components/ExampleWrapper.js +45 -9
- package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.js +1 -1
- package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.js +1 -1
- package/lib/examples/{ag-ui → components}/haiku/index.d.ts +1 -1
- package/lib/examples/{ag-ui → components}/haiku/index.js +1 -1
- package/lib/examples/components/index.d.ts +3 -0
- package/lib/examples/components/index.js +4 -0
- package/lib/examples/{ag-ui → components}/weather/index.d.ts +1 -1
- package/lib/examples/{ag-ui → components}/weather/index.js +1 -1
- package/lib/examples/example-selector.d.ts +17 -4
- package/lib/examples/example-selector.js +108 -41
- package/lib/examples/index.d.ts +10 -6
- package/lib/examples/index.js +10 -6
- package/lib/examples/lexical/initial-content.json +6 -6
- package/lib/examples/main.js +257 -27
- package/lib/examples/utils/a2ui.d.ts +18 -0
- package/lib/examples/utils/a2ui.js +69 -0
- package/lib/examples/utils/a2uiMarkdownProvider.d.ts +7 -0
- package/lib/examples/utils/a2uiMarkdownProvider.js +9 -0
- package/lib/examples/utils/agentId.d.ts +18 -0
- package/lib/examples/utils/agentId.js +54 -0
- package/lib/examples/utils/agents/earthquake-detector.json +11 -11
- package/lib/examples/utils/agents/sales-forecaster.json +11 -11
- package/lib/examples/utils/agents/social-post-generator.json +11 -11
- package/lib/examples/utils/agents/stock-market.json +11 -11
- package/lib/examples/utils/examplesStore.js +82 -27
- package/lib/examples/utils/useExampleAgentRuntimesUrl.d.ts +5 -0
- package/lib/examples/utils/useExampleAgentRuntimesUrl.js +19 -0
- package/lib/hooks/index.d.ts +8 -8
- package/lib/hooks/index.js +7 -7
- package/lib/hooks/useA2A.d.ts +2 -3
- package/lib/hooks/useAIAgentsWebSocket.d.ts +43 -4
- package/lib/hooks/useAIAgentsWebSocket.js +153 -12
- package/lib/hooks/useAcp.d.ts +1 -2
- package/lib/hooks/useAgUi.d.ts +1 -1
- package/lib/hooks/{useAgents.d.ts → useAgentRuntimes.d.ts} +70 -4
- package/lib/hooks/{useAgents.js → useAgentRuntimes.js} +237 -32
- package/lib/hooks/useAgentsCatalog.js +1 -1
- package/lib/hooks/useAgentsService.d.ts +2 -2
- package/lib/hooks/useAgentsService.js +7 -7
- package/lib/hooks/useCheckpoints.js +1 -1
- package/lib/hooks/useConfig.d.ts +4 -1
- package/lib/hooks/useConfig.js +10 -3
- package/lib/hooks/useContextSnapshot.d.ts +9 -4
- package/lib/hooks/useContextSnapshot.js +9 -37
- package/lib/hooks/useMonitoring.js +3 -0
- package/lib/hooks/useSandbox.d.ts +20 -8
- package/lib/hooks/useSandbox.js +105 -40
- package/lib/hooks/useSkills.d.ts +23 -5
- package/lib/hooks/useSkills.js +94 -39
- package/lib/hooks/useToolApprovals.d.ts +60 -36
- package/lib/hooks/useToolApprovals.js +318 -69
- package/lib/hooks/useVercelAI.d.ts +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/inference/index.d.ts +0 -1
- package/lib/middleware/index.d.ts +0 -1
- package/lib/protocols/AGUIAdapter.js +6 -0
- package/lib/protocols/VercelAIAdapter.d.ts +7 -0
- package/lib/protocols/VercelAIAdapter.js +59 -7
- package/lib/specs/agents/agents.d.ts +21 -4
- package/lib/specs/agents/agents.js +2879 -316
- package/lib/specs/agents/index.js +3 -1
- package/lib/specs/benchmarks.d.ts +20 -0
- package/lib/specs/benchmarks.js +205 -0
- package/lib/specs/envvars.js +27 -20
- package/lib/specs/evals.d.ts +10 -9
- package/lib/specs/evals.js +128 -88
- package/lib/specs/events.d.ts +3 -10
- package/lib/specs/events.js +127 -84
- package/lib/specs/frontendTools.js +2 -2
- package/lib/specs/guardrails.d.ts +0 -7
- package/lib/specs/guardrails.js +240 -159
- package/lib/specs/mcpServers.js +35 -6
- package/lib/specs/memory.d.ts +0 -2
- package/lib/specs/memory.js +4 -17
- package/lib/specs/models.d.ts +0 -2
- package/lib/specs/models.js +20 -15
- package/lib/specs/notifications.js +102 -18
- package/lib/specs/outputs.js +15 -9
- package/lib/specs/personas.d.ts +41 -0
- package/lib/specs/personas.js +168 -0
- package/lib/specs/skills.d.ts +1 -1
- package/lib/specs/skills.js +23 -23
- package/lib/specs/teams/index.js +3 -1
- package/lib/specs/teams/teams.js +468 -348
- package/lib/specs/tools.js +4 -4
- package/lib/specs/triggers.js +61 -11
- package/lib/stores/agentRuntimeStore.d.ts +208 -0
- package/lib/stores/agentRuntimeStore.js +650 -0
- package/lib/stores/conversationStore.js +2 -2
- package/lib/stores/index.d.ts +1 -1
- package/lib/stores/index.js +1 -1
- package/lib/tools/adapters/copilotkit/lexicalHooks.d.ts +1 -2
- package/lib/tools/adapters/copilotkit/lexicalHooks.js +1 -3
- package/lib/tools/adapters/copilotkit/notebookHooks.d.ts +1 -2
- package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -3
- package/lib/tools/index.d.ts +0 -2
- package/lib/tools/index.js +0 -1
- package/lib/types/agents-lifecycle.d.ts +18 -0
- package/lib/types/agents.d.ts +6 -0
- package/lib/types/agentspecs.d.ts +54 -1
- package/lib/types/benchmarks.d.ts +43 -0
- package/lib/types/benchmarks.js +5 -0
- package/lib/types/chat.d.ts +325 -8
- package/lib/types/context.d.ts +27 -0
- package/lib/types/cost.d.ts +2 -2
- package/lib/types/evals.d.ts +26 -17
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +3 -0
- package/lib/types/mcp.d.ts +8 -0
- package/lib/types/models.d.ts +2 -2
- package/lib/types/personas.d.ts +25 -0
- package/lib/types/personas.js +5 -0
- package/lib/types/skills.d.ts +43 -1
- package/lib/types/stream.d.ts +110 -0
- package/lib/types/stream.js +36 -0
- package/lib/utils/utils.d.ts +9 -5
- package/lib/utils/utils.js +9 -5
- package/package.json +19 -11
- package/scripts/codegen/__pycache__/generate_agents.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_benchmarks.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_evals.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_events.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
- package/scripts/codegen/generate_agents.py +187 -45
- package/scripts/codegen/generate_benchmarks.py +441 -0
- package/scripts/codegen/generate_evals.py +94 -16
- package/scripts/codegen/generate_events.py +35 -14
- package/scripts/codegen/generate_personas.py +319 -0
- package/scripts/codegen/generate_skills.py +9 -9
- package/scripts/sync-jupyter.sh +26 -7
- package/lib/api/tool-approvals.d.ts +0 -62
- package/lib/api/tool-approvals.js +0 -145
- package/lib/examples/AgentspecExample.js +0 -705
- package/lib/examples/LexicalSidebarExample.js +0 -163
- package/lib/examples/NotebookSidebarExample.js +0 -119
- package/lib/examples/NotebookSimpleExample.d.ts +0 -6
- package/lib/examples/NotebookSimpleExample.js +0 -22
- package/lib/examples/ag-ui/index.d.ts +0 -10
- package/lib/examples/ag-ui/index.js +0 -16
- package/lib/hooks/useAgentsRegistry.d.ts +0 -10
- package/lib/hooks/useAgentsRegistry.js +0 -20
- package/lib/stores/agentsStore.d.ts +0 -123
- package/lib/stores/agentsStore.js +0 -270
- /package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.js +0 -0
|
@@ -3,99 +3,348 @@
|
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Agent tool approval hooks.
|
|
6
|
+
* Agent tool approval hooks (WebSocket-only).
|
|
7
|
+
*
|
|
8
|
+
* All tool-approval interactions flow over the AI Agents websocket stream.
|
|
9
|
+
* There are no REST endpoints — the server publishes approval snapshots and
|
|
10
|
+
* `tool_approval_*` events, and the client sends `tool_approval_decision`
|
|
11
|
+
* messages to approve/reject pending requests.
|
|
12
|
+
*
|
|
13
|
+
* Consumers use the familiar React Query-style API below. Internally the
|
|
14
|
+
* hooks:
|
|
15
|
+
* - subscribe to the shared AI Agents WS once per component tree
|
|
16
|
+
* - seed/update the `['tool-approvals', filters]` query cache from events
|
|
17
|
+
* - send decision messages over the same socket for mutations
|
|
7
18
|
*
|
|
8
19
|
* @module hooks/useToolApprovals
|
|
9
20
|
*/
|
|
10
|
-
import { useMemo } from 'react';
|
|
11
|
-
import { useQuery,
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
22
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
23
|
+
import { useAIAgentsWebSocket } from './useAIAgentsWebSocket';
|
|
24
|
+
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
25
|
+
const APPROVALS_ROOT_KEY = ['tool-approvals'];
|
|
26
|
+
function str(value) {
|
|
27
|
+
return typeof value === 'string' ? value : value == null ? '' : String(value);
|
|
28
|
+
}
|
|
29
|
+
function normalizeApproval(raw) {
|
|
30
|
+
if (!raw || typeof raw !== 'object')
|
|
31
|
+
return null;
|
|
32
|
+
const rec = raw;
|
|
33
|
+
const id = typeof rec.id === 'string' ? rec.id : undefined;
|
|
34
|
+
if (!id)
|
|
35
|
+
return null;
|
|
36
|
+
const agent = str(rec.agent_id ?? rec.agentId);
|
|
37
|
+
const pod = str(rec.pod_name ?? rec.podName);
|
|
38
|
+
const tool = str(rec.tool_name ?? rec.toolName ?? 'unknown');
|
|
39
|
+
const toolCall = rec.tool_call_id ?? rec.toolCallId;
|
|
40
|
+
const args = rec.tool_args ??
|
|
41
|
+
rec.toolArgs ??
|
|
42
|
+
{};
|
|
43
|
+
const created = str(rec.created_at ?? rec.createdAt);
|
|
44
|
+
const updated = str(rec.updated_at ?? rec.updatedAt);
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
agent_id: agent,
|
|
48
|
+
agentId: agent,
|
|
49
|
+
pod_name: pod,
|
|
50
|
+
podName: pod,
|
|
51
|
+
tool_name: tool,
|
|
52
|
+
toolName: tool,
|
|
53
|
+
tool_call_id: typeof toolCall === 'string' ? toolCall : undefined,
|
|
54
|
+
toolCallId: typeof toolCall === 'string' ? toolCall : undefined,
|
|
55
|
+
tool_args: args,
|
|
56
|
+
toolArgs: args,
|
|
57
|
+
status: str(rec.status ?? 'pending'),
|
|
58
|
+
note: typeof rec.note === 'string'
|
|
59
|
+
? rec.note
|
|
60
|
+
: rec.note === null
|
|
61
|
+
? null
|
|
62
|
+
: undefined,
|
|
63
|
+
created_at: created,
|
|
64
|
+
createdAt: created,
|
|
65
|
+
updated_at: updated || undefined,
|
|
66
|
+
updatedAt: updated || undefined,
|
|
67
|
+
read: typeof rec.read === 'boolean' ? rec.read : undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function matchesFilter(a, filters) {
|
|
71
|
+
if (!filters)
|
|
72
|
+
return true;
|
|
73
|
+
if (filters.agentId && a.agent_id !== filters.agentId)
|
|
74
|
+
return false;
|
|
75
|
+
if (filters.status && a.status !== filters.status)
|
|
76
|
+
return false;
|
|
77
|
+
if (filters.toolName && a.tool_name !== filters.toolName)
|
|
78
|
+
return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function upsertApproval(list, approval) {
|
|
82
|
+
const idx = list.findIndex(item => item.id === approval.id);
|
|
83
|
+
if (idx === -1)
|
|
84
|
+
return [approval, ...list];
|
|
85
|
+
const copy = list.slice();
|
|
86
|
+
copy[idx] = { ...copy[idx], ...approval };
|
|
87
|
+
return copy;
|
|
88
|
+
}
|
|
89
|
+
function removeApproval(list, id) {
|
|
90
|
+
return list.filter(item => item.id !== id);
|
|
91
|
+
}
|
|
92
|
+
function writeSnapshot(queryClient, approvals) {
|
|
93
|
+
const queries = queryClient
|
|
94
|
+
.getQueryCache()
|
|
95
|
+
.findAll({ queryKey: APPROVALS_ROOT_KEY });
|
|
96
|
+
for (const q of queries) {
|
|
97
|
+
const [, second] = q.queryKey;
|
|
98
|
+
if (second === 'pending-count') {
|
|
99
|
+
queryClient.setQueryData(q.queryKey, {
|
|
100
|
+
count: approvals.filter(a => a.status === 'pending').length,
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const filters = (second ?? undefined);
|
|
105
|
+
const filtered = approvals.filter(a => matchesFilter(a, filters));
|
|
106
|
+
queryClient.setQueryData(q.queryKey, {
|
|
107
|
+
approvals: filtered,
|
|
108
|
+
total: filtered.length,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// Ensure there's always a root cache entry so downstream consumers can
|
|
112
|
+
// compute derived values (like pending-count refetches) even when no
|
|
113
|
+
// filter query has been mounted yet.
|
|
114
|
+
queryClient.setQueryData(APPROVALS_ROOT_KEY, {
|
|
115
|
+
approvals,
|
|
116
|
+
total: approvals.length,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function patchApproval(queryClient, approval, mode) {
|
|
120
|
+
const queries = queryClient
|
|
121
|
+
.getQueryCache()
|
|
122
|
+
.findAll({ queryKey: APPROVALS_ROOT_KEY });
|
|
123
|
+
for (const q of queries) {
|
|
124
|
+
const [, second] = q.queryKey;
|
|
125
|
+
if (second === 'pending-count') {
|
|
126
|
+
// Recompute from the root cache after we finish patching below.
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const filters = (second ?? undefined);
|
|
130
|
+
const current = queryClient.getQueryData(q.queryKey)?.approvals ?? [];
|
|
131
|
+
let next;
|
|
132
|
+
if (mode === 'remove') {
|
|
133
|
+
next = removeApproval(current, approval.id);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
next = matchesFilter(approval, filters)
|
|
137
|
+
? upsertApproval(current, approval)
|
|
138
|
+
: removeApproval(current, approval.id);
|
|
139
|
+
}
|
|
140
|
+
queryClient.setQueryData(q.queryKey, {
|
|
141
|
+
approvals: next,
|
|
142
|
+
total: next.length,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// Recompute pending-count from the unfiltered root cache.
|
|
146
|
+
const root = queryClient.getQueryData(APPROVALS_ROOT_KEY)?.approvals;
|
|
147
|
+
if (root) {
|
|
148
|
+
queryClient.setQueryData(['tool-approvals', 'pending-count'], { count: root.filter(a => a.status === 'pending').length });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// ─── Shared WS bridge ─────────────────────────────────────────────────
|
|
152
|
+
/**
|
|
153
|
+
* Opens a WS connection and streams snapshots + events into the React
|
|
154
|
+
* Query cache. Returns a `send` function so sibling hooks can dispatch
|
|
155
|
+
* decisions over the same socket.
|
|
156
|
+
*/
|
|
157
|
+
function useApprovalsSocket() {
|
|
158
|
+
const queryClient = useQueryClient();
|
|
159
|
+
const { connectionState, send } = useAIAgentsWebSocket({
|
|
160
|
+
onMessage: msg => {
|
|
161
|
+
const type = (msg.type ?? msg.event);
|
|
162
|
+
if (!type)
|
|
163
|
+
return;
|
|
164
|
+
// Response to our { type: 'tool-approvals-history' } request.
|
|
165
|
+
// Shape: { type: "tool-approvals-history", data: { approvals: [...] } }
|
|
166
|
+
if (type === 'tool-approvals-history') {
|
|
167
|
+
const data = msg.data;
|
|
168
|
+
const rawList = Array.isArray(data?.approvals) ? data.approvals : [];
|
|
169
|
+
const list = rawList
|
|
170
|
+
.map(normalizeApproval)
|
|
171
|
+
.filter((a) => a !== null)
|
|
172
|
+
.filter(a => a.status !== 'deleted');
|
|
173
|
+
writeSnapshot(queryClient, list);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// Incremental broadcast events from datalayer-ai-agents.
|
|
177
|
+
// Shape: { channel: "user:<uid>", event: "tool_approval_*", data: record }
|
|
178
|
+
if (type.startsWith('tool_approval_')) {
|
|
179
|
+
const rawPayload = msg.payload ??
|
|
180
|
+
msg.data ??
|
|
181
|
+
undefined;
|
|
182
|
+
const approval = normalizeApproval(rawPayload);
|
|
183
|
+
if (!approval)
|
|
184
|
+
return;
|
|
185
|
+
patchApproval(queryClient, approval, type === 'tool_approval_deleted' ? 'remove' : 'upsert');
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
// Request the full approval history once connected so the sidebar badge
|
|
190
|
+
// and any pending-count consumers always show the correct count.
|
|
191
|
+
const historyAskedRef = useRef(false);
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (connectionState !== 'connected') {
|
|
194
|
+
historyAskedRef.current = false;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (historyAskedRef.current)
|
|
198
|
+
return;
|
|
199
|
+
historyAskedRef.current = send({ type: 'tool-approvals-history' });
|
|
200
|
+
}, [connectionState, send]);
|
|
201
|
+
return { send, connectionState };
|
|
23
202
|
}
|
|
24
203
|
// ─── Base hooks ──────────────────────────────────────────────────────
|
|
25
204
|
export function useToolApprovalsQuery(filters) {
|
|
26
|
-
|
|
27
|
-
const
|
|
205
|
+
useApprovalsSocket();
|
|
206
|
+
const queryClient = useQueryClient();
|
|
207
|
+
const queryKey = useMemo(() => ['tool-approvals', filters], [filters]);
|
|
28
208
|
return useQuery({
|
|
29
|
-
queryKey
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
209
|
+
queryKey,
|
|
210
|
+
// Data is populated via the WS bridge. On invalidation, return the
|
|
211
|
+
// cached value so the fresh WS snapshot is preserved.
|
|
212
|
+
queryFn: async () => queryClient.getQueryData(queryKey) ?? {
|
|
213
|
+
approvals: [],
|
|
214
|
+
total: 0,
|
|
215
|
+
},
|
|
216
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
217
|
+
refetchOnMount: false,
|
|
218
|
+
refetchOnWindowFocus: false,
|
|
219
|
+
refetchOnReconnect: false,
|
|
33
220
|
});
|
|
34
221
|
}
|
|
35
222
|
export function usePendingApprovalCount() {
|
|
36
|
-
|
|
37
|
-
const
|
|
223
|
+
useApprovalsSocket();
|
|
224
|
+
const queryClient = useQueryClient();
|
|
38
225
|
return useQuery({
|
|
39
226
|
queryKey: ['tool-approvals', 'pending-count'],
|
|
40
|
-
queryFn: () =>
|
|
41
|
-
|
|
42
|
-
|
|
227
|
+
queryFn: async () => {
|
|
228
|
+
const cached = queryClient.getQueryData([
|
|
229
|
+
'tool-approvals',
|
|
230
|
+
'pending-count',
|
|
231
|
+
]);
|
|
232
|
+
if (cached && typeof cached.count === 'number')
|
|
233
|
+
return cached;
|
|
234
|
+
const root = queryClient.getQueryData(APPROVALS_ROOT_KEY);
|
|
235
|
+
const pending = (root?.approvals ?? []).filter(a => a.status === 'pending').length;
|
|
236
|
+
return { count: pending };
|
|
237
|
+
},
|
|
238
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
239
|
+
refetchOnMount: false,
|
|
240
|
+
refetchOnWindowFocus: false,
|
|
241
|
+
refetchOnReconnect: false,
|
|
43
242
|
});
|
|
44
243
|
}
|
|
244
|
+
/** Build a mutation-style object that sends a WS decision. */
|
|
245
|
+
function useDecisionMutation(approved) {
|
|
246
|
+
const { send } = useApprovalsSocket();
|
|
247
|
+
const [isPending, setIsPending] = useState(false);
|
|
248
|
+
const mutateAsync = useCallback(async ({ id, note }) => {
|
|
249
|
+
setIsPending(true);
|
|
250
|
+
try {
|
|
251
|
+
const ok = send({
|
|
252
|
+
type: 'tool_approval_decision',
|
|
253
|
+
approvalId: id,
|
|
254
|
+
approved,
|
|
255
|
+
...(note ? { note } : {}),
|
|
256
|
+
});
|
|
257
|
+
if (!ok) {
|
|
258
|
+
throw new Error('Approvals WebSocket is not connected; decision was not sent');
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
setIsPending(false);
|
|
263
|
+
}
|
|
264
|
+
}, [approved, send]);
|
|
265
|
+
const mutate = useCallback((vars) => {
|
|
266
|
+
void mutateAsync(vars);
|
|
267
|
+
}, [mutateAsync]);
|
|
268
|
+
return { isPending, mutate, mutateAsync };
|
|
269
|
+
}
|
|
45
270
|
export function useApproveToolRequest() {
|
|
46
|
-
|
|
47
|
-
const baseUrl = useDashboardBaseUrl();
|
|
48
|
-
const queryClient = useQueryClient();
|
|
49
|
-
return useMutation({
|
|
50
|
-
mutationFn: ({ id, note }) => toolApprovals.approveToolRequest(token, id, note, baseUrl),
|
|
51
|
-
onSuccess: () => {
|
|
52
|
-
queryClient.invalidateQueries({ queryKey: ['tool-approvals'] });
|
|
53
|
-
},
|
|
54
|
-
});
|
|
271
|
+
return useDecisionMutation(true);
|
|
55
272
|
}
|
|
56
273
|
export function useRejectToolRequest() {
|
|
57
|
-
|
|
58
|
-
|
|
274
|
+
return useDecisionMutation(false);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Mark a tool approval as read/unread in the local cache.
|
|
278
|
+
*
|
|
279
|
+
* Read-state isn't part of the websocket contract, so this hook patches
|
|
280
|
+
* only the React Query cache. The patch survives until the next snapshot.
|
|
281
|
+
*/
|
|
282
|
+
function useLocalReadMutation(target) {
|
|
59
283
|
const queryClient = useQueryClient();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
284
|
+
const [isPending, setIsPending] = useState(false);
|
|
285
|
+
const mutateAsync = useCallback(async ({ id }) => {
|
|
286
|
+
setIsPending(true);
|
|
287
|
+
try {
|
|
288
|
+
const queries = queryClient
|
|
289
|
+
.getQueryCache()
|
|
290
|
+
.findAll({ queryKey: APPROVALS_ROOT_KEY });
|
|
291
|
+
for (const q of queries) {
|
|
292
|
+
const [, second] = q.queryKey;
|
|
293
|
+
if (second === 'pending-count')
|
|
294
|
+
continue;
|
|
295
|
+
const current = queryClient.getQueryData(q.queryKey);
|
|
296
|
+
if (!current?.approvals)
|
|
297
|
+
continue;
|
|
298
|
+
queryClient.setQueryData(q.queryKey, {
|
|
299
|
+
...current,
|
|
300
|
+
approvals: current.approvals.map(a => a.id === id ? { ...a, read: target } : a),
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
setIsPending(false);
|
|
306
|
+
}
|
|
307
|
+
}, [queryClient, target]);
|
|
308
|
+
const mutate = useCallback((vars) => {
|
|
309
|
+
void mutateAsync(vars);
|
|
310
|
+
}, [mutateAsync]);
|
|
311
|
+
return { isPending, mutate, mutateAsync };
|
|
66
312
|
}
|
|
67
313
|
export function useMarkToolApprovalRead() {
|
|
68
|
-
|
|
69
|
-
const baseUrl = useDashboardBaseUrl();
|
|
70
|
-
const queryClient = useQueryClient();
|
|
71
|
-
return useMutation({
|
|
72
|
-
mutationFn: ({ id }) => toolApprovals.markToolApprovalRead(token, id, baseUrl),
|
|
73
|
-
onSuccess: () => {
|
|
74
|
-
queryClient.invalidateQueries({ queryKey: ['tool-approvals'] });
|
|
75
|
-
},
|
|
76
|
-
});
|
|
314
|
+
return useLocalReadMutation(true);
|
|
77
315
|
}
|
|
78
316
|
export function useMarkToolApprovalUnread() {
|
|
79
|
-
|
|
80
|
-
const baseUrl = useDashboardBaseUrl();
|
|
81
|
-
const queryClient = useQueryClient();
|
|
82
|
-
return useMutation({
|
|
83
|
-
mutationFn: ({ id }) => toolApprovals.markToolApprovalUnread(token, id, baseUrl),
|
|
84
|
-
onSuccess: () => {
|
|
85
|
-
queryClient.invalidateQueries({ queryKey: ['tool-approvals'] });
|
|
86
|
-
},
|
|
87
|
-
});
|
|
317
|
+
return useLocalReadMutation(false);
|
|
88
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Delete a tool approval.
|
|
321
|
+
*
|
|
322
|
+
* Sends a ``tool_approval_delete`` message over the shared websocket.
|
|
323
|
+
* The local cache is updated only after the server emits
|
|
324
|
+
* ``tool_approval_deleted``.
|
|
325
|
+
*/
|
|
89
326
|
export function useDeleteToolApproval() {
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
327
|
+
const { send } = useApprovalsSocket();
|
|
328
|
+
const [isPending, setIsPending] = useState(false);
|
|
329
|
+
const mutateAsync = useCallback(async ({ id }) => {
|
|
330
|
+
setIsPending(true);
|
|
331
|
+
try {
|
|
332
|
+
const ok = send({
|
|
333
|
+
type: 'tool_approval_delete',
|
|
334
|
+
approvalId: id,
|
|
335
|
+
});
|
|
336
|
+
if (!ok) {
|
|
337
|
+
throw new Error('Approvals WebSocket is not connected; delete was not sent');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
finally {
|
|
341
|
+
setIsPending(false);
|
|
342
|
+
}
|
|
343
|
+
}, [send]);
|
|
344
|
+
const mutate = useCallback((vars) => {
|
|
345
|
+
void mutateAsync(vars);
|
|
346
|
+
}, [mutateAsync]);
|
|
347
|
+
return { isPending, mutate, mutateAsync };
|
|
99
348
|
}
|
|
100
349
|
// ─── Composite hook ──────────────────────────────────────────────────
|
|
101
350
|
export function useToolApprovals(filters) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './chat';
|
|
2
|
+
export * from './client';
|
|
2
3
|
export * from './components';
|
|
3
4
|
export * from './mcp';
|
|
4
5
|
export * from './stores';
|
|
5
6
|
export * from './identity';
|
|
6
7
|
export * from './config';
|
|
7
8
|
export * from './specs';
|
|
8
|
-
export type { AgentRuntimeData, AgentSpec, TeamSpec, GuardrailSpec, EvalSpec, TriggerSpec, OutputSpec, NotificationChannelSpec, MCPServer, SkillSpec, EnvvarSpec, } from './types';
|
|
9
|
+
export type { AgentRuntimeData, AgentSpec, BenchmarkSpec, ChatCommonProps, TeamSpec, GuardrailSpec, EvalSpec, TriggerSpec, OutputSpec, NotificationChannelSpec, MCPServer, SkillSpec, SkillInfo, SkillStatus, EnvvarSpec, ToolCallStartContext, ToolCallCompleteContext, } from './types';
|
package/lib/index.js
CHANGED
package/lib/inference/index.d.ts
CHANGED
|
@@ -6,4 +6,3 @@
|
|
|
6
6
|
export { BaseInferenceProvider } from './BaseInferenceProvider';
|
|
7
7
|
export { DatalayerInferenceProvider, type DatalayerInferenceConfig, } from './DatalayerInferenceProvider';
|
|
8
8
|
export { SelfHostedInferenceProvider, type SelfHostedInferenceConfig, } from './SelfHostedInferenceProvider';
|
|
9
|
-
export type { InferenceProvider, InferenceProviderConfig, InferenceProviderFactory, InferenceProviderType, InferenceRequestOptions, InferenceResponse, StreamEvent, StreamEventType, StreamEventHandler, } from '../types/inference';
|
|
@@ -168,6 +168,12 @@ export class AGUIAdapter extends BaseProtocolAdapter {
|
|
|
168
168
|
messages: aguiMessages,
|
|
169
169
|
state: null,
|
|
170
170
|
tools: options?.tools || [],
|
|
171
|
+
...(options?.builtinTools !== undefined && {
|
|
172
|
+
builtinTools: options.builtinTools,
|
|
173
|
+
}),
|
|
174
|
+
...(options?.skills !== undefined && {
|
|
175
|
+
skills: options.skills,
|
|
176
|
+
}),
|
|
171
177
|
context: [],
|
|
172
178
|
forwardedProps: null,
|
|
173
179
|
// Include model for per-request model override
|
|
@@ -48,6 +48,13 @@ export declare class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
48
48
|
private _streamParsingDepth;
|
|
49
49
|
private _streamDonePromise;
|
|
50
50
|
private _streamDoneResolve;
|
|
51
|
+
/**
|
|
52
|
+
* Return the toolCallId for the first deferred tool whose name matches
|
|
53
|
+
* toolName, or the first deferred tool if toolName is empty/unmatched.
|
|
54
|
+
* Used by external callers (e.g. approval handlers) that need to send a
|
|
55
|
+
* continuation without access to the original tool-call-id.
|
|
56
|
+
*/
|
|
57
|
+
getDeferredToolCallId(toolName: string): string | undefined;
|
|
51
58
|
constructor(config: VercelAIAdapterConfig);
|
|
52
59
|
/**
|
|
53
60
|
* Connect to Vercel AI endpoint (SSE doesn't require persistent connection)
|
|
@@ -33,6 +33,26 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
33
33
|
_streamParsingDepth = 0;
|
|
34
34
|
_streamDonePromise = null;
|
|
35
35
|
_streamDoneResolve = null;
|
|
36
|
+
/**
|
|
37
|
+
* Return the toolCallId for the first deferred tool whose name matches
|
|
38
|
+
* toolName, or the first deferred tool if toolName is empty/unmatched.
|
|
39
|
+
* Used by external callers (e.g. approval handlers) that need to send a
|
|
40
|
+
* continuation without access to the original tool-call-id.
|
|
41
|
+
*/
|
|
42
|
+
getDeferredToolCallId(toolName) {
|
|
43
|
+
if (!toolName) {
|
|
44
|
+
return this.deferredToolMeta.keys().next().value;
|
|
45
|
+
}
|
|
46
|
+
for (const [id, meta] of this.deferredToolMeta) {
|
|
47
|
+
if (meta.toolName === toolName ||
|
|
48
|
+
meta.toolName === toolName.replace(/-/g, '_') ||
|
|
49
|
+
meta.toolName === toolName.replace(/_/g, '-')) {
|
|
50
|
+
return id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Fall back to first entry if name didn't match (handles name normalisation edge cases)
|
|
54
|
+
return this.deferredToolMeta.keys().next().value;
|
|
55
|
+
}
|
|
36
56
|
constructor(config) {
|
|
37
57
|
super(config);
|
|
38
58
|
this.vercelConfig = config;
|
|
@@ -175,12 +195,10 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
175
195
|
trigger: 'submit-message',
|
|
176
196
|
...(options?.tools && { tools: options.tools }),
|
|
177
197
|
...(options?.model && { model: options.model }),
|
|
178
|
-
...(options?.builtinTools &&
|
|
179
|
-
options.builtinTools.length > 0 && {
|
|
198
|
+
...(options?.builtinTools !== undefined && {
|
|
180
199
|
builtinTools: options.builtinTools,
|
|
181
200
|
}),
|
|
182
|
-
...(options?.skills &&
|
|
183
|
-
options.skills.length > 0 && {
|
|
201
|
+
...(options?.skills !== undefined && {
|
|
184
202
|
skills: options.skills,
|
|
185
203
|
}),
|
|
186
204
|
...(options?.identities &&
|
|
@@ -253,6 +271,7 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
253
271
|
let currentMessageId = generateMessageId();
|
|
254
272
|
let accumulatedText = '';
|
|
255
273
|
const pendingToolInputs = new Map();
|
|
274
|
+
const pendingApprovalIds = new Map();
|
|
256
275
|
let doneEmitted = false;
|
|
257
276
|
// Consume the continuation flag — set by sendToolResult for this call only
|
|
258
277
|
this.isContinuation = false;
|
|
@@ -399,6 +418,7 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
399
418
|
// not frontend tools that will be handled by sendToolResult)
|
|
400
419
|
for (const [toolCallId] of pendingToolInputs.entries()) {
|
|
401
420
|
if (!this.pendingToolCalls.has(toolCallId)) {
|
|
421
|
+
const approvalId = pendingApprovalIds.get(toolCallId);
|
|
402
422
|
this.emit({
|
|
403
423
|
type: 'tool-result',
|
|
404
424
|
toolResult: {
|
|
@@ -406,6 +426,7 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
406
426
|
success: true,
|
|
407
427
|
result: {
|
|
408
428
|
pending_approval: true,
|
|
429
|
+
approval_id: approvalId,
|
|
409
430
|
message: 'Awaiting user approval',
|
|
410
431
|
},
|
|
411
432
|
},
|
|
@@ -499,6 +520,7 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
499
520
|
timestamp: new Date(),
|
|
500
521
|
});
|
|
501
522
|
pendingToolInputs.delete(toolCallId);
|
|
523
|
+
pendingApprovalIds.delete(toolCallId);
|
|
502
524
|
// Server already executed this tool — remove from pending
|
|
503
525
|
// frontend tool calls so emitDoneOnce is not blocked.
|
|
504
526
|
this.pendingToolCalls.delete(toolCallId);
|
|
@@ -529,6 +551,7 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
529
551
|
timestamp: new Date(),
|
|
530
552
|
});
|
|
531
553
|
pendingToolInputs.delete(toolCallId);
|
|
554
|
+
pendingApprovalIds.delete(toolCallId);
|
|
532
555
|
}
|
|
533
556
|
else if (event.type === 'error') {
|
|
534
557
|
const errorMessage = event.error ||
|
|
@@ -543,9 +566,18 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
543
566
|
timestamp: new Date(),
|
|
544
567
|
});
|
|
545
568
|
}
|
|
569
|
+
else if (event.type === 'tool-approval-request') {
|
|
570
|
+
const toolCallId = event.toolCallId ||
|
|
571
|
+
event.tool_call_id ||
|
|
572
|
+
event.id ||
|
|
573
|
+
generateMessageId();
|
|
574
|
+
const approvalId = event.approvalId || event.approval_id;
|
|
575
|
+
if (typeof approvalId === 'string' && approvalId.length > 0) {
|
|
576
|
+
pendingApprovalIds.set(toolCallId, approvalId);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
546
579
|
else if (event.type === 'tool-call' ||
|
|
547
|
-
event.type === 'tool-call-start'
|
|
548
|
-
event.type === 'tool-approval-request') {
|
|
580
|
+
event.type === 'tool-call-start') {
|
|
549
581
|
const toolName = event.toolName ||
|
|
550
582
|
event.tool_name ||
|
|
551
583
|
event.name ||
|
|
@@ -598,6 +630,16 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
598
630
|
* ONE continuation request once ALL pending tool calls have been resolved.
|
|
599
631
|
*/
|
|
600
632
|
async sendToolResult(toolCallId, result) {
|
|
633
|
+
console.info('[VercelAIAdapter] sendToolResult called', {
|
|
634
|
+
toolCallId,
|
|
635
|
+
success: result?.success,
|
|
636
|
+
hasApprovalDecision: !!result?.result &&
|
|
637
|
+
typeof result.result === 'object' &&
|
|
638
|
+
typeof result.result.approved ===
|
|
639
|
+
'boolean',
|
|
640
|
+
knownDeferredToolCallIds: Array.from(this.deferredToolMeta.keys()),
|
|
641
|
+
pendingToolCallIds: Array.from(this.pendingToolCalls.keys()),
|
|
642
|
+
});
|
|
601
643
|
// 1. Emit local event for UI updates
|
|
602
644
|
this.emit({
|
|
603
645
|
type: 'tool-result',
|
|
@@ -657,7 +699,9 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
657
699
|
? resultObj.approvalId
|
|
658
700
|
: tr.toolCallId;
|
|
659
701
|
const approved = Boolean(resultObj?.approved);
|
|
660
|
-
const reason = typeof resultObj?.message === 'string'
|
|
702
|
+
const reason = typeof resultObj?.message === 'string'
|
|
703
|
+
? resultObj.message
|
|
704
|
+
: undefined;
|
|
661
705
|
assistantParts.push({
|
|
662
706
|
type: 'dynamic-tool',
|
|
663
707
|
toolName: tr.toolName,
|
|
@@ -714,6 +758,14 @@ export class VercelAIAdapter extends BaseProtocolAdapter {
|
|
|
714
758
|
content: '',
|
|
715
759
|
createdAt: new Date(),
|
|
716
760
|
};
|
|
761
|
+
console.info('[VercelAIAdapter] Sending continuation request', {
|
|
762
|
+
messageCount: continuationMessages.length,
|
|
763
|
+
assistantParts: assistantParts.map(p => ({
|
|
764
|
+
type: p.type,
|
|
765
|
+
state: p.state,
|
|
766
|
+
toolName: p.toolName,
|
|
767
|
+
})),
|
|
768
|
+
});
|
|
717
769
|
await this.sendMessage(dummyMessage, {
|
|
718
770
|
_vercelMessages: continuationMessages,
|
|
719
771
|
tools: this.lastTools,
|
|
@@ -14,11 +14,28 @@ export declare const CLASSIFY_ROUTE_EMAILS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
|
14
14
|
export declare const COMPREHENSIVE_SALES_ANALYTICS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
15
15
|
export declare const CRAWLER_AGENT_SPEC_0_0_1: AgentSpec;
|
|
16
16
|
export declare const DATA_ACQUISITION_AGENT_SPEC_0_0_1: AgentSpec;
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const DEMO_ONE_TRIGGER_APPROVAL_AGENT_SPEC_0_0_1: AgentSpec;
|
|
19
|
-
export declare const DEMO_ONE_TRIGGER_AGENT_SPEC_0_0_1: AgentSpec;
|
|
20
|
-
export declare const DEMO_SIMPLE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
17
|
+
export declare const DEMO_OUTPUTS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
21
18
|
export declare const END_OF_MONTH_SALES_PERFORMANCE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
19
|
+
export declare const EVAL_EXPERIMENT_RUNNER_AGENT_SPEC_0_0_1: AgentSpec;
|
|
20
|
+
export declare const EXAMPLE_CODEMODE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
21
|
+
export declare const EXAMPLE_EVALS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
22
|
+
export declare const EXAMPLE_FULL_AGENT_SPEC_0_0_1: AgentSpec;
|
|
23
|
+
export declare const EXAMPLE_GUARDRAILS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
24
|
+
export declare const EXAMPLE_HOOKS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
25
|
+
export declare const EXAMPLE_INFERENCE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
26
|
+
export declare const EXAMPLE_MCP_AGENT_SPEC_0_0_1: AgentSpec;
|
|
27
|
+
export declare const EXAMPLE_MEMORY_AGENT_SPEC_0_0_1: AgentSpec;
|
|
28
|
+
export declare const EXAMPLE_MONITORING_AGENT_SPEC_0_0_1: AgentSpec;
|
|
29
|
+
export declare const EXAMPLE_NO_CODEMODE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
30
|
+
export declare const EXAMPLE_NOTIFICATIONS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
31
|
+
export declare const EXAMPLE_ONE_TRIGGER_APPROVAL_AGENT_SPEC_0_0_1: AgentSpec;
|
|
32
|
+
export declare const EXAMPLE_ONE_TRIGGER_AGENT_SPEC_0_0_1: AgentSpec;
|
|
33
|
+
export declare const EXAMPLE_OTEL_AGENT_SPEC_0_0_1: AgentSpec;
|
|
34
|
+
export declare const EXAMPLE_PARAMETERS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
35
|
+
export declare const EXAMPLE_SIMPLE_AGENT_SPEC_0_0_1: AgentSpec;
|
|
36
|
+
export declare const EXAMPLE_SKILLS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
37
|
+
export declare const EXAMPLE_SUBAGENTS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
38
|
+
export declare const EXAMPLE_TOOL_APPROVALS_AGENT_SPEC_0_0_1: AgentSpec;
|
|
22
39
|
export declare const EXTRACT_DATA_FROM_FILES_AGENT_SPEC_0_0_1: AgentSpec;
|
|
23
40
|
export declare const FINANCIAL_VIZ_AGENT_SPEC_0_0_1: AgentSpec;
|
|
24
41
|
export declare const FINANCIAL_AGENT_SPEC_0_0_1: AgentSpec;
|