@datalayer/agent-runtimes 0.0.5 → 0.0.8
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 +150 -22
- package/lib/components/chat/components/AgentDetails.d.ts +15 -2
- package/lib/components/chat/components/AgentDetails.js +9 -93
- package/lib/components/chat/components/AgentIdentity.d.ts +92 -0
- package/lib/components/chat/components/AgentIdentity.js +318 -0
- package/lib/components/chat/components/Chat.d.ts +24 -1
- package/lib/components/chat/components/Chat.js +41 -19
- package/lib/components/chat/components/ChatFloating.d.ts +6 -1
- package/lib/components/chat/components/ChatFloating.js +12 -6
- package/lib/components/chat/components/ContextDistribution.d.ts +47 -0
- package/lib/components/chat/components/ContextDistribution.js +146 -0
- package/lib/components/chat/components/ContextUsage.d.ts +33 -0
- package/lib/components/chat/components/ContextUsage.js +127 -0
- package/lib/components/chat/components/base/ChatBase.d.ts +51 -1
- package/lib/components/chat/components/base/ChatBase.js +278 -74
- package/lib/components/chat/components/display/ToolCallDisplay.d.ts +16 -2
- package/lib/components/chat/components/display/ToolCallDisplay.js +148 -6
- package/lib/components/chat/components/display/index.d.ts +1 -1
- package/lib/components/chat/components/display/index.js +1 -1
- package/lib/components/chat/components/elements/ChatInputPrompt.d.ts +12 -1
- package/lib/components/chat/components/elements/ChatInputPrompt.js +8 -3
- package/lib/components/chat/components/index.d.ts +3 -0
- package/lib/components/chat/components/index.js +3 -0
- package/lib/components/chat/components/parts/ToolPart.d.ts +1 -1
- package/lib/components/chat/components/parts/ToolPart.js +142 -6
- package/lib/components/chat/index.d.ts +1 -1
- package/lib/components/chat/index.js +1 -1
- package/lib/components/chat/protocols/A2AAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/A2AAdapter.js +13 -2
- package/lib/components/chat/protocols/ACPAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/ACPAdapter.js +13 -2
- package/lib/components/chat/protocols/AGUIAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/AGUIAdapter.js +19 -1
- package/lib/components/chat/protocols/VercelAIAdapter.d.ts +7 -0
- package/lib/components/chat/protocols/VercelAIAdapter.js +19 -0
- package/lib/components/chat/types/execution.d.ts +78 -0
- package/lib/components/chat/types/execution.js +64 -0
- package/lib/components/chat/types/index.d.ts +1 -0
- package/lib/components/chat/types/index.js +1 -0
- package/lib/components/chat/types/protocol.d.ts +9 -0
- package/lib/components/ui/pagination.d.ts +2 -2
- package/lib/components/ui/pagination.js +4 -4
- package/lib/components/ui/resizable.d.ts +4 -4
- package/lib/components/ui/resizable.js +4 -4
- package/lib/examples/A2UiRestaurantExample.js +2 -2
- package/lib/examples/AgUiAgenticExample.js +2 -2
- package/lib/examples/AgUiBackendToolRenderingExample.js +2 -2
- package/lib/examples/AgUiHaikuGenUIExample.js +2 -2
- package/lib/examples/AgUiHumanInTheLoopExample.js +2 -2
- package/lib/examples/AgUiSharedStateExample.js +2 -2
- package/lib/examples/AgUiToolsBasedGenUIExample.js +2 -2
- package/lib/examples/AgentRuntimeCustomExample.js +2 -2
- package/lib/examples/AgentRuntimeLexical2Example.js +2 -1
- package/lib/examples/AgentRuntimeLexicalExample.js +5 -2
- package/lib/examples/AgentRuntimeLexicalSidebarExample.js +4 -2
- package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
- package/lib/examples/AgentRuntimeStandaloneExample.js +2 -2
- package/lib/examples/AgentSpaceFormExample.d.ts +70 -2
- package/lib/examples/AgentSpaceFormExample.js +204 -35
- package/lib/examples/CopilotKitLexicalExample.js +2 -1
- package/lib/examples/components/AgentConfiguration.d.ts +37 -0
- package/lib/examples/components/AgentConfiguration.js +239 -8
- package/lib/examples/components/Header.d.ts +0 -2
- package/lib/examples/components/Header.js +2 -16
- package/lib/examples/components/LexicalEditor.js +2 -1
- package/lib/examples/components/MockFileBrowser.js +6 -2
- package/lib/examples/components/index.d.ts +0 -1
- package/lib/examples/components/index.js +0 -1
- package/lib/examples/example-selector.js +0 -1
- package/lib/examples/index.d.ts +0 -1
- package/lib/examples/index.js +0 -1
- package/lib/examples/lexical/editorConfig.d.ts +3 -2
- package/lib/examples/lexical/editorConfig.js +7 -1
- package/lib/examples/lexical/initial-content.json +2210 -0
- package/lib/examples/main.js +15 -1
- package/lib/identity/IdentityConnect.d.ts +90 -0
- package/lib/identity/IdentityConnect.js +316 -0
- package/lib/identity/OAuthCallback.d.ts +58 -0
- package/lib/identity/OAuthCallback.js +223 -0
- package/lib/identity/dcr.d.ts +257 -0
- package/lib/identity/dcr.js +282 -0
- package/lib/identity/identityStore.d.ts +72 -0
- package/lib/identity/identityStore.js +529 -0
- package/lib/identity/index.d.ts +46 -0
- package/lib/identity/index.js +17 -0
- package/lib/identity/pkce.d.ts +30 -0
- package/lib/identity/pkce.js +65 -0
- package/lib/identity/types.d.ts +293 -0
- package/lib/identity/types.js +73 -0
- package/lib/identity/useIdentity.d.ts +108 -0
- package/lib/identity/useIdentity.js +323 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/lib/utils.js +1 -1
- package/lib/renderers/a2ui/lib/utils.js +1 -1
- package/lib/runtime/index.d.ts +35 -0
- package/lib/runtime/index.js +40 -0
- package/lib/runtime/runtimeStore.d.ts +77 -0
- package/lib/runtime/runtimeStore.js +184 -0
- package/lib/runtime/types.d.ts +84 -0
- package/lib/runtime/types.js +15 -0
- package/lib/runtime/useAgentConnection.d.ts +46 -0
- package/lib/runtime/useAgentConnection.js +112 -0
- package/lib/runtime/useAgentRuntime.d.ts +94 -0
- package/lib/runtime/useAgentRuntime.js +125 -0
- package/lib/test-setup.d.ts +1 -1
- package/lib/test-setup.js +1 -0
- package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.js +32 -1
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +6 -0
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +16 -17
- package/package.json +20 -7
- package/patches/@datalayer+jupyter-lexical+1.0.8.patch +11628 -0
- package/patches/@datalayer+jupyter-react+2.0.2.patch +5338 -0
- package/lib/examples/AgentSpaceHomeExample.d.ts +0 -8
- package/lib/examples/AgentSpaceHomeExample.js +0 -171
- package/lib/examples/components/AgentsDataTable.d.ts +0 -13
- package/lib/examples/components/AgentsDataTable.js +0 -74
- package/lib/examples/components/Rating.d.ts +0 -14
- package/lib/examples/components/Rating.js +0 -12
package/README.md
CHANGED
|
@@ -2,37 +2,34 @@
|
|
|
2
2
|
~ Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
3
|
~
|
|
4
4
|
~ BSD 3-Clause License
|
|
5
|
+
-->
|
|
5
6
|
|
|
7
|
+
[](https://datalayer.io)
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
yes, that is my goal to implement https://github.com/datalayer/jupyter-ai-agents/issues/53
|
|
9
|
+
[](https://github.com/sponsors/datalayer)
|
|
9
10
|
|
|
11
|
+
# 🤖 Agent Runtimes
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
The vercel ai-element tool approval has been merged 3 weeks ago https://github.com/vercel/ai-elements/pull/163
|
|
14
|
-
That's great! It doesn't look like they have events for that in the Data Stream Protocol yet though, so it's not clear how they expect agent backends to represent tool calls that require approval, or how they'll send approval to the backend...
|
|
15
|
-
I guess having a kind of reference implementation for common use cases/patterns will be good for the community. I would say that kind of case (external mcp server with tool approval like done by eg claude desktop) is quite common, or will become common
|
|
16
|
-
Definitely, which is partly why github.com/pydantic/pydantic-ai/issues/3295 exists, but there's currently a missing link in how approvals should be represented on the event stream going from agent to frontend, and in approval results going from frontend to agent. I'd expect Vercel AI to come up with something sooner rather than later since they have their own (TypeScript) agent SDK as well, which they'd then document in the Data Stream Protocol, which we can then support as well.
|
|
17
|
-
In the meantime, you could do something like this:
|
|
18
|
-
Wrap your MCPServer in ApprovalRequiredToolset (assuming all tools require approval). This means that when any of the tools are called, the agent run will end with a DeferredToolRequests object as result.output
|
|
19
|
-
When you use VercelAIAdapter.dispatch_request, you can add an on_complete handler that is passed the AgentRunResult and can yield additional Vercel AI events. In that handler, you can check result.output , and if it's DeferredToolRequests , you can yield a custom pydantic_ai.ui.vercel_ai.response_types.DataChunk wrapping those deferred tool requests, which will be sent to frontend
|
|
20
|
-
On the frontend you can handle that custom data part by showing the user the tool call that needs approval
|
|
21
|
-
When the user approves, you'll need to perform a new request to the backend containing that approval, by listing the approved tool_call_ids on the SubmitMessage payload (I'm not an expert on how this part of AI Elements works...)
|
|
22
|
-
In the backend endpoint, you then have to parse this value out of the SubmitMessage payload (similar to this: https://github.com/pydantic/ai-chat-ui/blob/b0ac18d2dbbef3cf1636c17a29fb7578a59b32c8/agent/chatbot/server.py#L115-L122), turn it into a DeferredToolResults object and pass it to the dispatch/run method as deferred_tool_results
|
|
13
|
+
[](https://github.com/datalayer/agent-runtimes/actions/workflows/build.yml)
|
|
14
|
+
[](https://pypi.org/project/agent-runtimes)
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
**Agent Runtimes** is a unified platform for deploying, managing, and interacting with AI agents across multiple protocols and frameworks. It provides both a Python server for hosting agents and React components for seamless integration into web and desktop applications.
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
## 🎯 What is Agent Runtimes?
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
Agent Runtimes solves the complexity of deploying AI agents by providing:
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
1. **Protocol Abstraction**: One agent, multiple protocols - deploy your agent once and access it through ACP, Vercel AI SDK, AG-UI, MCP-UI, or A2A without changing your code.
|
|
23
|
+
|
|
24
|
+
2. **Framework Flexibility**: Write agents using your preferred framework (Pydantic AI, LangChain, Jupyter AI) while maintaining a consistent API.
|
|
25
|
+
|
|
26
|
+
3. **Cloud Runtime Management**: Built-in integration with Datalayer Cloud Runtimes for launching and managing compute resources with Zustand-based state management.
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
[](https://pypi.org/project/code-sandboxes)
|
|
28
|
+
4. **UI Components**: Pre-built React components (ChatBase, ChatSidebar, ChatFloating) that connect to agents and execute tools directly in the browser.
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
5. **Tool Ecosystem**: Seamless integration with MCP (Model Context Protocol) tools, custom tools, and built-in utilities for Jupyter notebooks and Lexical documents.
|
|
31
|
+
|
|
32
|
+

|
|
36
33
|
|
|
37
34
|
## 🌟 Features
|
|
38
35
|
|
|
@@ -49,8 +46,139 @@ In the backend endpoint, you then have to parse this value out of the SubmitMess
|
|
|
49
46
|
- **Jupyter AI**: Notebook integration (adapter ready)
|
|
50
47
|
|
|
51
48
|
### Built-in Features
|
|
52
|
-
- 🔌 **
|
|
49
|
+
- 🔌 **Flexible Architecture**: Easy to add new agents and protocols
|
|
53
50
|
- 🛠️ **Tool Support**: MCP, custom tools, built-in utilities
|
|
54
51
|
- 📊 **Observability**: OpenTelemetry integration
|
|
55
52
|
- 💾 **Persistence**: DBOS support for durable execution
|
|
56
53
|
- 🔒 **Context Optimization**: LLM context management
|
|
54
|
+
|
|
55
|
+
## 🏗️ Architecture
|
|
56
|
+
|
|
57
|
+
Agent Runtimes consists of three main components:
|
|
58
|
+
|
|
59
|
+
### 1. Python Server (`agent_runtimes/`)
|
|
60
|
+
The backend server that hosts AI agents and handles protocol routing:
|
|
61
|
+
- **Agent Adapters**: Unified interface for Pydantic AI, LangChain, and Jupyter AI
|
|
62
|
+
- **Protocol Adapters**: Convert between different agent protocols (ACP, AG-UI, Vercel AI, etc.)
|
|
63
|
+
- **FastAPI Server**: High-performance async server with automatic API documentation
|
|
64
|
+
- **Tool Registry**: Manages and executes tools from various sources (MCP, custom, built-in)
|
|
65
|
+
|
|
66
|
+
### 2. React Components (`src/components/`)
|
|
67
|
+
Pre-built UI components for interacting with agents:
|
|
68
|
+
- **ChatBase**: Core chat interface with customizable styling
|
|
69
|
+
- **ChatSidebar**: Collapsible sidebar for agent interactions
|
|
70
|
+
- **ChatFloating**: Floating chat widget for non-intrusive agent access
|
|
71
|
+
- **All components support**: Frontend tool execution, markdown rendering, code highlighting, and real-time streaming
|
|
72
|
+
|
|
73
|
+
### 3. Runtime Management (`src/runtime/`)
|
|
74
|
+
Cloud runtime lifecycle management with Zustand store:
|
|
75
|
+
- **Launch & Connect**: Create new cloud runtimes or connect to existing ones
|
|
76
|
+
- **Agent Creation**: Automatically create and configure agents on runtimes
|
|
77
|
+
- **State Management**: Track runtime status, agent connections, and errors
|
|
78
|
+
- **Hooks**: React hooks for easy integration (`useAgentRuntime`, `useRuntimeStore`)
|
|
79
|
+
|
|
80
|
+
## 🚀 Use Cases
|
|
81
|
+
|
|
82
|
+
### Notebook AI Assistant
|
|
83
|
+
Add an AI agent to Jupyter notebooks that can:
|
|
84
|
+
- Execute cells, insert code, and modify notebook content
|
|
85
|
+
- Explain code and data analysis
|
|
86
|
+
- Debug errors and suggest improvements
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { NotebookAgentsRuntime } from '@datalayer/agent-runtimes';
|
|
90
|
+
|
|
91
|
+
<NotebookAgentsRuntime
|
|
92
|
+
notebookId={notebookId}
|
|
93
|
+
environmentName="python-simple"
|
|
94
|
+
runtimeName={runtimeName}
|
|
95
|
+
serviceManager={serviceManager}
|
|
96
|
+
/>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Document Editor AI
|
|
100
|
+
Integrate AI into Lexical-based document editors:
|
|
101
|
+
- Insert headings, lists, code blocks, and formatted text
|
|
102
|
+
- Summarize content and proofread text
|
|
103
|
+
- Generate ideas and help with writing
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { DocumentAgentRuntime } from '@datalayer/agent-runtimes';
|
|
107
|
+
|
|
108
|
+
<DocumentAgentRuntime
|
|
109
|
+
documentId={documentId}
|
|
110
|
+
environmentName="python-simple"
|
|
111
|
+
runtimeName={runtimeName}
|
|
112
|
+
serviceManager={serviceManager}
|
|
113
|
+
/>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Custom Agent Deployment
|
|
117
|
+
Deploy your own Pydantic AI agent with custom tools:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from agent_runtimes import AgentRuntimesApp
|
|
121
|
+
from pydantic_ai import Agent
|
|
122
|
+
|
|
123
|
+
# Create your agent
|
|
124
|
+
agent = Agent(
|
|
125
|
+
model='anthropic:claude-sonnet-4-5',
|
|
126
|
+
system_prompt='You are a helpful assistant.',
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Launch the server
|
|
130
|
+
app = AgentRuntimesApp()
|
|
131
|
+
app.add_agent(agent, name='my-agent', transport='ag-ui')
|
|
132
|
+
app.run(port=8000)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 🧪 Run the examples
|
|
136
|
+
|
|
137
|
+
Run the Codemode + MCP example UI:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cd src/ai/agent-runtimes
|
|
141
|
+
EXAMPLE=AgentCodemodeMcpExample npm run dev
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 🔧 Key Concepts
|
|
145
|
+
|
|
146
|
+
### Protocols
|
|
147
|
+
Agent Runtimes supports multiple protocols for agent communication:
|
|
148
|
+
|
|
149
|
+
- **AG-UI**: Lightweight protocol for web UIs (POST-based, Pydantic AI native)
|
|
150
|
+
- **ACP**: WebSocket-based Agent Client Protocol for real-time interaction
|
|
151
|
+
- **Vercel AI SDK**: Compatible with Vercel's AI SDK streaming
|
|
152
|
+
- **MCP-UI**: Model Context Protocol with UI resources
|
|
153
|
+
- **A2A**: Agent-to-agent communication protocol
|
|
154
|
+
|
|
155
|
+
### Tools
|
|
156
|
+
Tools extend agent capabilities by allowing them to perform actions:
|
|
157
|
+
|
|
158
|
+
- **Frontend Tools**: Execute in the browser (notebook editing, document manipulation)
|
|
159
|
+
- **MCP Tools**: Tools from Model Context Protocol servers
|
|
160
|
+
- **Custom Tools**: Your own Python functions decorated with tool metadata
|
|
161
|
+
- **Built-in Tools**: File operations, web search, code execution
|
|
162
|
+
- **Code Mode**: Tool discovery includes `output_schema` and `input_examples` for reliable calls; code execution returns `stdout`/`stderr` and a summarized `result`.
|
|
163
|
+
|
|
164
|
+
### Runtime Management
|
|
165
|
+
Cloud runtimes provide compute resources for agents:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { useAgentRuntime } from '@datalayer/agent-runtimes/lib/runtime';
|
|
169
|
+
|
|
170
|
+
const { isReady, endpoint, tools, launchRuntime } = useAgentRuntime({
|
|
171
|
+
autoCreateAgent: true,
|
|
172
|
+
agentConfig: {
|
|
173
|
+
model: 'anthropic:claude-sonnet-4-5',
|
|
174
|
+
systemPrompt: 'You are a helpful AI assistant.',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Launch a new runtime
|
|
179
|
+
await launchRuntime({
|
|
180
|
+
environmentName: 'python-simple',
|
|
181
|
+
creditsLimit: 100,
|
|
182
|
+
type: 'notebook',
|
|
183
|
+
});
|
|
184
|
+
```
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OAuthProvider, OAuthProviderConfig, Identity } from '../../../identity';
|
|
1
2
|
export interface AgentDetailsProps {
|
|
2
3
|
/** Agent name/title */
|
|
3
4
|
name?: string;
|
|
@@ -7,13 +8,25 @@ export interface AgentDetailsProps {
|
|
|
7
8
|
url: string;
|
|
8
9
|
/** Number of messages in conversation */
|
|
9
10
|
messageCount: number;
|
|
10
|
-
/** Agent ID */
|
|
11
|
+
/** Agent ID for context usage tracking */
|
|
11
12
|
agentId?: string;
|
|
13
|
+
/** Identity provider configurations */
|
|
14
|
+
identityProviders?: {
|
|
15
|
+
[K in OAuthProvider]?: {
|
|
16
|
+
clientId: string;
|
|
17
|
+
scopes?: string[];
|
|
18
|
+
config?: Partial<OAuthProviderConfig>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** Callback when identity connects */
|
|
22
|
+
onIdentityConnect?: (identity: Identity) => void;
|
|
23
|
+
/** Callback when identity disconnects */
|
|
24
|
+
onIdentityDisconnect?: (provider: OAuthProvider) => void;
|
|
12
25
|
/** Callback to go back to chat view */
|
|
13
26
|
onBack: () => void;
|
|
14
27
|
}
|
|
15
28
|
/**
|
|
16
29
|
* AgentDetails component displays comprehensive information about the agent.
|
|
17
30
|
*/
|
|
18
|
-
export declare function AgentDetails({ name, protocol, url, messageCount, agentId, onBack, }: AgentDetailsProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare function AgentDetails({ name, protocol, url, messageCount, agentId, identityProviders, onIdentityConnect, onIdentityDisconnect, onBack, }: AgentDetailsProps): import("react/jsx-runtime").JSX.Element;
|
|
19
32
|
export default AgentDetails;
|
|
@@ -5,53 +5,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
* AgentDetails component - Shows detailed information about the agent
|
|
6
6
|
* including name, protocol, URL, message count, and context details.
|
|
7
7
|
*/
|
|
8
|
-
import { ArrowLeftIcon, GlobeIcon, CommentDiscussionIcon,
|
|
9
|
-
import { Box, Button, Heading, IconButton, Text, Label,
|
|
8
|
+
import { ArrowLeftIcon, GlobeIcon, CommentDiscussionIcon, CheckCircleIcon, XCircleIcon, } from '@primer/octicons-react';
|
|
9
|
+
import { Box, Button, Heading, IconButton, Text, Label, Spinner, } from '@primer/react';
|
|
10
10
|
import { AiAgentIcon } from '@datalayer/icons-react';
|
|
11
11
|
import { useQuery } from '@tanstack/react-query';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
totalTokens: 2520000,
|
|
16
|
-
usedTokens: 1523552,
|
|
17
|
-
children: [
|
|
18
|
-
{
|
|
19
|
-
name: 'Files',
|
|
20
|
-
value: 450000,
|
|
21
|
-
children: [
|
|
22
|
-
{ name: 'app.py', value: 125000 },
|
|
23
|
-
{ name: 'models.py', value: 98000 },
|
|
24
|
-
{ name: 'routes.py', value: 112000 },
|
|
25
|
-
{ name: 'utils.py', value: 115000 },
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'Messages',
|
|
30
|
-
value: 380000,
|
|
31
|
-
children: [
|
|
32
|
-
{ name: 'User messages', value: 180000 },
|
|
33
|
-
{ name: 'Assistant responses', value: 200000 },
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'Tools',
|
|
38
|
-
value: 220000,
|
|
39
|
-
children: [
|
|
40
|
-
{ name: 'Code execution', value: 95000 },
|
|
41
|
-
{ name: 'File operations', value: 75000 },
|
|
42
|
-
{ name: 'Search', value: 50000 },
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'Memory',
|
|
47
|
-
value: 473552,
|
|
48
|
-
children: [
|
|
49
|
-
{ name: 'Short term', value: 150000 },
|
|
50
|
-
{ name: 'Long term', value: 323552 },
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
};
|
|
12
|
+
import { ContextUsage } from './ContextUsage';
|
|
13
|
+
import { ContextDistribution } from './ContextDistribution';
|
|
14
|
+
import { AgentIdentity } from './AgentIdentity';
|
|
55
15
|
function getLocalApiBase() {
|
|
56
16
|
if (typeof window === 'undefined') {
|
|
57
17
|
return '';
|
|
@@ -61,40 +21,10 @@ function getLocalApiBase() {
|
|
|
61
21
|
? 'http://127.0.0.1:8765'
|
|
62
22
|
: '';
|
|
63
23
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Format token count for display
|
|
66
|
-
*/
|
|
67
|
-
function formatTokens(tokens) {
|
|
68
|
-
if (tokens >= 1000000) {
|
|
69
|
-
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
70
|
-
}
|
|
71
|
-
if (tokens >= 1000) {
|
|
72
|
-
return `${(tokens / 1000).toFixed(1)}K`;
|
|
73
|
-
}
|
|
74
|
-
return tokens.toString();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Get icon for context category
|
|
78
|
-
*/
|
|
79
|
-
function getCategoryIcon(name) {
|
|
80
|
-
switch (name.toLowerCase()) {
|
|
81
|
-
case 'files':
|
|
82
|
-
return FileIcon;
|
|
83
|
-
case 'messages':
|
|
84
|
-
return CommentDiscussionIcon;
|
|
85
|
-
case 'tools':
|
|
86
|
-
return ToolsIcon;
|
|
87
|
-
case 'memory':
|
|
88
|
-
return DatabaseIcon;
|
|
89
|
-
default:
|
|
90
|
-
return ClockIcon;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
24
|
/**
|
|
94
25
|
* AgentDetails component displays comprehensive information about the agent.
|
|
95
26
|
*/
|
|
96
|
-
export function AgentDetails({ name = 'AI Agent', protocol, url, messageCount, agentId, onBack, }) {
|
|
97
|
-
const contextUsagePercent = (MOCK_CONTEXT_DATA.usedTokens / MOCK_CONTEXT_DATA.totalTokens) * 100;
|
|
27
|
+
export function AgentDetails({ name = 'AI Agent', protocol, url, messageCount, agentId, identityProviders, onIdentityConnect, onIdentityDisconnect, onBack, }) {
|
|
98
28
|
// Fetch MCP toolsets status
|
|
99
29
|
const { data: mcpStatus, isLoading: mcpLoading } = useQuery({
|
|
100
30
|
queryKey: ['mcp-toolsets-status'],
|
|
@@ -203,31 +133,17 @@ export function AgentDetails({ name = 'AI Agent', protocol, url, messageCount, a
|
|
|
203
133
|
pl: 4,
|
|
204
134
|
whiteSpace: 'pre-wrap',
|
|
205
135
|
wordBreak: 'break-word',
|
|
206
|
-
}, children: error.split('\n')[0] })] }, server)))] }))] })) : (_jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Failed to load MCP status" })) })] }), _jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
136
|
+
}, children: error.split('\n')[0] })] }, server)))] }))] })) : (_jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Failed to load MCP status" })) })] }), agentId && _jsx(ContextUsage, { agentId: agentId }), agentId && (_jsxs(Box, { sx: { mt: 3 }, children: [_jsx(Heading, { as: "h4", sx: {
|
|
207
137
|
fontSize: 1,
|
|
208
138
|
fontWeight: 'semibold',
|
|
209
139
|
mb: 2,
|
|
210
140
|
color: 'fg.muted',
|
|
211
|
-
}, children: "Context
|
|
141
|
+
}, children: "Current Context Distribution" }), _jsx(Box, { sx: {
|
|
212
142
|
p: 3,
|
|
213
143
|
bg: 'canvas.subtle',
|
|
214
144
|
borderRadius: 2,
|
|
215
145
|
border: '1px solid',
|
|
216
146
|
borderColor: 'border.default',
|
|
217
|
-
}, children:
|
|
218
|
-
display: 'flex',
|
|
219
|
-
justifyContent: 'space-between',
|
|
220
|
-
mb: 1,
|
|
221
|
-
}, children: [_jsxs(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: [formatTokens(MOCK_CONTEXT_DATA.usedTokens), " /", ' ', formatTokens(MOCK_CONTEXT_DATA.totalTokens), " tokens"] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: [contextUsagePercent.toFixed(0), "%"] })] }), _jsx(ProgressBar, { progress: contextUsagePercent, sx: { height: 8 }, bg: contextUsagePercent > 80
|
|
222
|
-
? 'danger.emphasis'
|
|
223
|
-
: 'accent.emphasis' })] }), _jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: MOCK_CONTEXT_DATA.children.map(category => {
|
|
224
|
-
const CategoryIcon = getCategoryIcon(category.name);
|
|
225
|
-
const categoryPercent = (category.value / MOCK_CONTEXT_DATA.totalTokens) * 100;
|
|
226
|
-
return (_jsxs(Box, { sx: {
|
|
227
|
-
display: 'flex',
|
|
228
|
-
alignItems: 'center',
|
|
229
|
-
gap: 2,
|
|
230
|
-
}, children: [_jsx(Box, { sx: { color: 'fg.muted', width: 20 }, children: _jsx(CategoryIcon, { size: 16 }) }), _jsx(Text, { sx: { fontSize: 1, flex: 1 }, children: category.name }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted', minWidth: 60 }, children: formatTokens(category.value) }), _jsx(Box, { sx: { width: 80 }, children: _jsx(ProgressBar, { progress: categoryPercent, sx: { height: 4 } }) })] }, category.name));
|
|
231
|
-
}) })] })] }), _jsx(Box, { sx: { mt: 2 }, children: _jsx(Button, { variant: "primary", onClick: onBack, sx: { width: '100%' }, children: "Back to Chat" }) })] })] }));
|
|
147
|
+
}, children: _jsx(ContextDistribution, { agentId: agentId, height: "250px" }) })] })), _jsx(AgentIdentity, { providers: identityProviders, title: "Connected Accounts", showHeader: true, showDescription: true, description: "OAuth identities connected to this agent. Agents can use these to access external services like GitHub repositories on your behalf.", showExpirationDetails: true, allowReconnect: Boolean(identityProviders), onConnect: onIdentityConnect, onDisconnect: onIdentityDisconnect }), _jsx(Box, { sx: { mt: 2 }, children: _jsx(Button, { variant: "primary", onClick: onBack, sx: { width: '100%' }, children: "Back to Chat" }) })] })] }));
|
|
232
148
|
}
|
|
233
149
|
export default AgentDetails;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { OAuthProvider, OAuthProviderConfig, Identity } from '../../../identity';
|
|
2
|
+
/**
|
|
3
|
+
* Token status information
|
|
4
|
+
*/
|
|
5
|
+
export interface TokenStatus {
|
|
6
|
+
isExpired: boolean;
|
|
7
|
+
isExpiringSoon: boolean;
|
|
8
|
+
expiresAt?: Date;
|
|
9
|
+
timeUntilExpiry?: number;
|
|
10
|
+
timeSinceExpiry?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Calculate token status from expiration timestamp
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTokenStatus(expiresAt?: number): TokenStatus;
|
|
16
|
+
/**
|
|
17
|
+
* Format duration for display
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatDuration(ms: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Format expiration status text
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatExpirationStatus(status: TokenStatus): string;
|
|
24
|
+
/**
|
|
25
|
+
* Props for IdentityCard component
|
|
26
|
+
*/
|
|
27
|
+
export interface IdentityCardProps {
|
|
28
|
+
/** Identity to display */
|
|
29
|
+
identity: Identity;
|
|
30
|
+
/** Provider configuration */
|
|
31
|
+
providerConfig?: {
|
|
32
|
+
clientId: string;
|
|
33
|
+
scopes?: string[];
|
|
34
|
+
config?: Partial<OAuthProviderConfig>;
|
|
35
|
+
};
|
|
36
|
+
/** Show detailed expiration info */
|
|
37
|
+
showExpirationDetails?: boolean;
|
|
38
|
+
/** Allow reconnection */
|
|
39
|
+
allowReconnect?: boolean;
|
|
40
|
+
/** Callback when connected */
|
|
41
|
+
onConnect?: (identity: Identity) => void;
|
|
42
|
+
/** Callback when disconnected */
|
|
43
|
+
onDisconnect?: (provider: OAuthProvider) => void;
|
|
44
|
+
/** Callback on error */
|
|
45
|
+
onError?: (error: Error) => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Single identity card with status and actions
|
|
49
|
+
*/
|
|
50
|
+
export declare function IdentityCard({ identity, providerConfig, showExpirationDetails, allowReconnect, onConnect: _onConnect, onDisconnect, onError, }: IdentityCardProps): import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
/**
|
|
52
|
+
* Props for AgentIdentity component
|
|
53
|
+
*/
|
|
54
|
+
export interface AgentIdentityProps {
|
|
55
|
+
/** Provider configurations with client IDs */
|
|
56
|
+
providers?: {
|
|
57
|
+
[K in OAuthProvider]?: {
|
|
58
|
+
clientId: string;
|
|
59
|
+
scopes?: string[];
|
|
60
|
+
config?: Partial<OAuthProviderConfig>;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** Title for the section */
|
|
64
|
+
title?: string;
|
|
65
|
+
/** Show header */
|
|
66
|
+
showHeader?: boolean;
|
|
67
|
+
/** Show description */
|
|
68
|
+
showDescription?: boolean;
|
|
69
|
+
/** Description text */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** Show expiration details */
|
|
72
|
+
showExpirationDetails?: boolean;
|
|
73
|
+
/** Allow reconnection */
|
|
74
|
+
allowReconnect?: boolean;
|
|
75
|
+
/** Callback when identity connects */
|
|
76
|
+
onConnect?: (identity: Identity) => void;
|
|
77
|
+
/** Callback when identity disconnects */
|
|
78
|
+
onDisconnect?: (provider: OAuthProvider) => void;
|
|
79
|
+
/** Callback on error */
|
|
80
|
+
onError?: (provider: OAuthProvider, error: Error) => void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* AgentIdentity component - Displays all connected identities with status
|
|
84
|
+
*
|
|
85
|
+
* Features:
|
|
86
|
+
* - Shows connected OAuth identities (GitHub, Google, Kaggle, etc.)
|
|
87
|
+
* - Displays token expiration status with detailed timing
|
|
88
|
+
* - Allows reconnection if token expired
|
|
89
|
+
* - Reusable across AgentDetails, AgentConfiguration, etc.
|
|
90
|
+
*/
|
|
91
|
+
export declare function AgentIdentity({ providers, title, showHeader, showDescription, description, showExpirationDetails, allowReconnect, onConnect, onDisconnect, onError, }: AgentIdentityProps): import("react/jsx-runtime").JSX.Element | null;
|
|
92
|
+
export default AgentIdentity;
|