|
1 | 1 | import type { Message } from "@ag-ui/client"; |
2 | 2 | import { AbstractAgent } from "@ag-ui/client"; |
3 | | -import { |
4 | | - CopilotRuntime, |
5 | | - copilotRuntimeNodeHttpEndpoint, |
6 | | - CopilotServiceAdapter, |
7 | | - ExperimentalEmptyAdapter, |
8 | | -} from "@copilotkit/runtime"; |
9 | | -import type { CoreMessage } from "@mastra/core"; |
10 | | -import { registerApiRoute } from "@mastra/core/server"; |
11 | | -import type { Mastra } from "@mastra/core"; |
| 3 | +import { MastraClient } from "@mastra/client-js"; |
| 4 | +import type { CoreMessage, Mastra } from "@mastra/core"; |
12 | 5 | import { Agent as LocalMastraAgent } from "@mastra/core/agent"; |
13 | 6 | import { RuntimeContext } from "@mastra/core/runtime-context"; |
14 | | -import { MastraClient } from "@mastra/client-js"; |
15 | 7 | import { MastraAgent } from "./mastra"; |
16 | 8 |
|
17 | 9 | export function convertAGUIMessagesToMastra(messages: Message[]): CoreMessage[] { |
@@ -66,53 +58,6 @@ export function convertAGUIMessagesToMastra(messages: Message[]): CoreMessage[] |
66 | 58 | return result; |
67 | 59 | } |
68 | 60 |
|
69 | | -export function registerCopilotKit<T extends Record<string, any> | unknown = unknown>({ |
70 | | - path, |
71 | | - resourceId, |
72 | | - serviceAdapter = new ExperimentalEmptyAdapter(), |
73 | | - agents, |
74 | | - setContext, |
75 | | -}: { |
76 | | - path: string; |
77 | | - resourceId: string; |
78 | | - serviceAdapter?: CopilotServiceAdapter; |
79 | | - agents?: Record<string, AbstractAgent>; |
80 | | - setContext?: (c: any, runtimeContext: RuntimeContext<T>) => void | Promise<void>; |
81 | | -}) { |
82 | | - return registerApiRoute(path, { |
83 | | - method: `ALL`, |
84 | | - handler: async (c) => { |
85 | | - const mastra = c.get("mastra"); |
86 | | - |
87 | | - const runtimeContext = new RuntimeContext<T>(); |
88 | | - |
89 | | - if (setContext) { |
90 | | - await setContext(c, runtimeContext); |
91 | | - } |
92 | | - |
93 | | - const aguiAgents = |
94 | | - agents || |
95 | | - MastraAgent.getLocalAgents({ |
96 | | - resourceId, |
97 | | - mastra, |
98 | | - runtimeContext, |
99 | | - }); |
100 | | - |
101 | | - const runtime = new CopilotRuntime({ |
102 | | - agents: aguiAgents, |
103 | | - }); |
104 | | - |
105 | | - const handler = copilotRuntimeNodeHttpEndpoint({ |
106 | | - endpoint: path, |
107 | | - runtime, |
108 | | - serviceAdapter, |
109 | | - }); |
110 | | - |
111 | | - return handler.handle(c.req.raw, {}); |
112 | | - }, |
113 | | - }); |
114 | | -} |
115 | | - |
116 | 61 | export interface GetRemoteAgentsOptions { |
117 | 62 | mastraClient: MastraClient; |
118 | 63 | resourceId?: string; |
|
0 commit comments