@copilotkit/runtime 0.0.0-fix-mcp-parameters-extract-20250710161807 → 0.0.0-fix-surface-agui-stream-errors-20250730142248
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/CHANGELOG.md +175 -5
- package/README.md +55 -100
- package/dist/{chunk-SLWI7Q35.mjs → chunk-6AOVTAEA.mjs} +2 -2
- package/dist/{chunk-LEVX5WVT.mjs → chunk-CD4OMUHR.mjs} +2 -2
- package/dist/{chunk-ZR75BDYK.mjs → chunk-EGLSN24F.mjs} +4 -3
- package/dist/chunk-EGLSN24F.mjs.map +1 -0
- package/dist/{chunk-QLLV2QVK.mjs → chunk-F7IANE7Z.mjs} +66 -6
- package/dist/chunk-F7IANE7Z.mjs.map +1 -0
- package/dist/{chunk-4XLIU5H5.mjs → chunk-NHCMVCN6.mjs} +133 -67
- package/dist/chunk-NHCMVCN6.mjs.map +1 -0
- package/dist/{chunk-T45TCFBL.mjs → chunk-QGC44CV4.mjs} +2 -2
- package/dist/{groq-adapter-098f97f6.d.ts → groq-adapter-742818f2.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +208 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-fc5cac89.d.ts → langserve-3e8d0e06.d.ts} +6 -0
- package/dist/lib/index.d.ts +156 -5
- package/dist/lib/index.js +144 -76
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -7
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +12 -11
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +12 -11
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +12 -11
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +12 -11
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +36 -6
- package/dist/service-adapters/index.js +65 -5
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/dist/{shared-6b6dbf8b.d.ts → shared-96b46379.d.ts} +1 -1
- package/package.json +13 -12
- package/src/lib/runtime/agui-action.ts +19 -4
- package/src/lib/runtime/copilot-runtime.ts +46 -28
- package/src/lib/runtime/langgraph/langgraph-agent.ts +3 -0
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/streaming.ts +1 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +106 -5
- package/src/service-adapters/anthropic/utils.ts +1 -1
- package/src/service-adapters/events.ts +40 -1
- package/src/service-adapters/openai/openai-adapter.ts +3 -1
- package/dist/chunk-4XLIU5H5.mjs.map +0 -1
- package/dist/chunk-QLLV2QVK.mjs.map +0 -1
- package/dist/chunk-ZR75BDYK.mjs.map +0 -1
- /package/dist/{chunk-SLWI7Q35.mjs.map → chunk-6AOVTAEA.mjs.map} +0 -0
- /package/dist/{chunk-LEVX5WVT.mjs.map → chunk-CD4OMUHR.mjs.map} +0 -0
- /package/dist/{chunk-T45TCFBL.mjs.map → chunk-QGC44CV4.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,141 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
-
## 0.0.0-fix-
|
|
3
|
+
## 0.0.0-fix-surface-agui-stream-errors-20250730142248
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
8
|
+
|
|
9
|
+
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
10
|
+
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
11
|
+
|
|
12
|
+
- 6f2f54b: - fix(openai): update maxTokens parameter to max_completion_tokens in OpenAIAdapter
|
|
13
|
+
- ece31a9: - fix: throw errors when they happen with agui streams
|
|
14
|
+
- 824fb69: - fix: pass config to the forwarded props of an agui agent
|
|
15
|
+
- 59b0e16: - feat: add native prompt caching support to AnthropicAdapter
|
|
16
|
+
- a31443c: removed unused dependency on ip module
|
|
17
|
+
- Updated dependencies [a8c0263]
|
|
18
|
+
- Updated dependencies [8674da1]
|
|
19
|
+
- @copilotkit/shared@0.0.0-fix-surface-agui-stream-errors-20250730142248
|
|
20
|
+
|
|
21
|
+
## 1.10.0-next.8
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- @copilotkit/shared@1.10.0-next.8
|
|
26
|
+
|
|
27
|
+
## 1.10.0-next.7
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 59b0e16: - feat: add native prompt caching support to AnthropicAdapter
|
|
32
|
+
- @copilotkit/shared@1.10.0-next.7
|
|
33
|
+
|
|
34
|
+
## 1.10.0-next.6
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 6f2f54b: - fix(openai): update maxTokens parameter to max_completion_tokens in OpenAIAdapter
|
|
39
|
+
- @copilotkit/shared@1.10.0-next.6
|
|
40
|
+
|
|
41
|
+
## 1.10.0-next.5
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [a8c0263]
|
|
46
|
+
- @copilotkit/shared@1.10.0-next.5
|
|
47
|
+
|
|
48
|
+
## 1.10.0-next.4
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- @copilotkit/shared@1.10.0-next.4
|
|
53
|
+
|
|
54
|
+
## 1.10.0-next.3
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- 824fb69: - fix: pass config to the forwarded props of an agui agent
|
|
59
|
+
- @copilotkit/shared@1.10.0-next.3
|
|
60
|
+
|
|
61
|
+
## 1.10.0-next.2
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- a31443c: removed unused dependency on ip module
|
|
66
|
+
- @copilotkit/shared@1.10.0-next.2
|
|
67
|
+
|
|
68
|
+
## 1.10.0-next.1
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
73
|
+
|
|
74
|
+
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
75
|
+
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
76
|
+
- @copilotkit/shared@1.10.0-next.1
|
|
77
|
+
|
|
78
|
+
## 1.10.0-next.0
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [8674da1]
|
|
83
|
+
- @copilotkit/shared@1.10.0-next.0
|
|
84
|
+
|
|
85
|
+
## 1.9.3
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- 1bda332: - chore(telemetry): integrate Scarf for usage analytics
|
|
90
|
+
- df25f34: - feat: add agui fastAPI compatible langgraph agent
|
|
91
|
+
- chore: release 0.1.55 with agui langgraph fastapi support
|
|
92
|
+
- 589ae52: - adds scarf deps to runtime
|
|
93
|
+
- 88ceae2: - upgrade AG-UI packages
|
|
94
|
+
- Updated dependencies [1bda332]
|
|
95
|
+
- @copilotkit/shared@1.9.3
|
|
96
|
+
|
|
97
|
+
## 1.9.3-next.4
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- @copilotkit/shared@1.9.3-next.4
|
|
102
|
+
|
|
103
|
+
## 1.9.3-next.3
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- 1bda332: - chore(telemetry): integrate Scarf for usage analytics
|
|
108
|
+
- Updated dependencies [1bda332]
|
|
109
|
+
- @copilotkit/shared@1.9.3-next.3
|
|
110
|
+
|
|
111
|
+
## 1.9.3-next.2
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- df25f34: - feat: add agui fastAPI compatible langgraph agent
|
|
116
|
+
- chore: release 0.1.55 with agui langgraph fastapi support
|
|
117
|
+
- @copilotkit/shared@1.9.3-next.2
|
|
118
|
+
|
|
119
|
+
## 1.9.3-next.1
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- 589ae52: - adds scarf deps to runtime
|
|
124
|
+
- @copilotkit/shared@1.9.3-next.1
|
|
125
|
+
|
|
126
|
+
## 1.9.3-next.0
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- 88ceae2: - upgrade AG-UI packages
|
|
131
|
+
- @copilotkit/shared@1.9.3-next.0
|
|
132
|
+
|
|
133
|
+
## 1.9.2
|
|
134
|
+
|
|
135
|
+
### Patch Changes
|
|
136
|
+
|
|
137
|
+
- f3f0181: - fix: connect streaming errors to runtime onError handler
|
|
138
|
+
- remove request logging
|
|
7
139
|
- 3a7f45f: - fix: resolve agui agents only after all other endpoints
|
|
8
140
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
9
141
|
|
|
@@ -14,7 +146,9 @@
|
|
|
14
146
|
- 4fd92d1: - fix: enable resolving of langgraph agents when cpk starts
|
|
15
147
|
- 1f4949a: - fix: remove agent discovery for agui agents
|
|
16
148
|
- 9169ad7: - feat: add onTrace handler for runtime and UI error/event tracking
|
|
149
|
+
- f3f0181: - fix: connect streaming errors to runtime onError handler
|
|
17
150
|
- 8e67158: - fixes gemini adapter
|
|
151
|
+
- 83822d2: - fix: do not show error on state loading if thread does not exist
|
|
18
152
|
- fe9009c: - feat(langgraph): new thread metadata
|
|
19
153
|
- f295375: - fix: remove all agents as tools when there is an active agent session
|
|
20
154
|
- fix formatting
|
|
@@ -23,21 +157,57 @@
|
|
|
23
157
|
- dec5527: - fix: only fetch agent state for langgraph agents
|
|
24
158
|
- 9b81464: - fix: use latest langgraph agui
|
|
25
159
|
- 10345a5: - feat: structured error visibility system for streaming errors
|
|
160
|
+
- 8ef8199: - fix: use latest agui dependencies to include required fixes
|
|
26
161
|
- 20e8c3c: - fix(anthropic-adapter): resolve infinite loop caused by duplicate result messages
|
|
27
162
|
- 9169ad7: - feat: add onTrace handler for comprehensive debugging and observability - Add CopilotTraceEvent interfaces with rich debugging context, implement runtime-side tracing with publicApiKey gating, add UI-side error tracing, include comprehensive test coverage, and fix tsup build config to exclude test files
|
|
28
163
|
- fix: extract publicApiKey for all requests + trace GraphQL errors
|
|
29
|
-
-
|
|
164
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
30
165
|
- Ensures consistency in how parameters are passed to the execute function across the codebase.
|
|
31
|
-
-
|
|
166
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
32
167
|
- Fixed generateMcpToolInstructions to properly extract parameters from schema.parameters.properties
|
|
33
168
|
- fix: enhance MCP schema support for complex types and remove duplicate headers
|
|
34
|
-
-
|
|
169
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
35
170
|
- Updated dependencies [fac89c2]
|
|
36
171
|
- Updated dependencies [9169ad7]
|
|
37
172
|
- Updated dependencies [1d1c51d]
|
|
38
173
|
- Updated dependencies [10345a5]
|
|
39
174
|
- Updated dependencies [9169ad7]
|
|
40
|
-
- @copilotkit/shared@
|
|
175
|
+
- @copilotkit/shared@1.9.2
|
|
176
|
+
|
|
177
|
+
## 1.9.2-next.26
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- 83822d2: - fix: do not show error on state loading if thread does not exist
|
|
182
|
+
- @copilotkit/shared@1.9.2-next.26
|
|
183
|
+
|
|
184
|
+
## 1.9.2-next.25
|
|
185
|
+
|
|
186
|
+
### Patch Changes
|
|
187
|
+
|
|
188
|
+
- f3f0181: - fix: connect streaming errors to runtime onError handler
|
|
189
|
+
- remove request logging
|
|
190
|
+
- f3f0181: - fix: connect streaming errors to runtime onError handler
|
|
191
|
+
- @copilotkit/shared@1.9.2-next.25
|
|
192
|
+
|
|
193
|
+
## 1.9.2-next.24
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- 8ef8199: - fix: use latest agui dependencies to include required fixes
|
|
198
|
+
- @copilotkit/shared@1.9.2-next.24
|
|
199
|
+
|
|
200
|
+
## 1.9.2-next.23
|
|
201
|
+
|
|
202
|
+
### Patch Changes
|
|
203
|
+
|
|
204
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
205
|
+
- Ensures consistency in how parameters are passed to the execute function across the codebase.
|
|
206
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
207
|
+
- Fixed generateMcpToolInstructions to properly extract parameters from schema.parameters.properties
|
|
208
|
+
- fix: enhance MCP schema support for complex types and remove duplicate headers
|
|
209
|
+
- fc6b653: - Fix extract toolParameters in extractParametersFromSchema
|
|
210
|
+
- @copilotkit/shared@1.9.2-next.23
|
|
41
211
|
|
|
42
212
|
## 1.9.2-next.22
|
|
43
213
|
|
package/README.md
CHANGED
|
@@ -1,121 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://copilotkit.ai" target="_blank">
|
|
3
|
-
<img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo">
|
|
4
|
-
</a>
|
|
5
|
-
|
|
6
|
-
<br/>
|
|
7
|
-
|
|
8
|
-
<strong>
|
|
9
|
-
CopilotKit is the open-source framework for integrating powerful AI Copilots into any application. Easily implement custom AI Chatbots, AI Agents, AI Textareas, and more.
|
|
10
|
-
</strong>
|
|
11
|
-
</div>
|
|
1
|
+
# CopilotKit - Runtime
|
|
12
2
|
|
|
13
|
-
<
|
|
3
|
+
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
|
|
14
4
|
|
|
15
|
-
<
|
|
5
|
+
<br>
|
|
6
|
+
<div align="center" style="display:flex;justify-content:center;gap:16px;height:20px;margin: 0;">
|
|
16
7
|
<a href="https://www.npmjs.com/package/@copilotkit/react-core" target="_blank">
|
|
17
|
-
<img src="https://img.shields.io/npm/v/%40copilotkit%
|
|
8
|
+
<img src="https://img.shields.io/npm/v/%40copilotkit%2Fruntime?logo=npm&logoColor=%23FFFFFF&label=Version&color=%236963ff" alt="NPM">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/copilotkit/copilotkit/blob/main/LICENSE" target="_blank">
|
|
11
|
+
<img src="https://img.shields.io/github/license/copilotkit/copilotkit?color=%236963ff&label=License" alt="MIT">
|
|
18
12
|
</a>
|
|
19
|
-
<img src="https://img.shields.io/github/license/copilotkit/copilotkit?color=%236963ff&label=License" alt="MIT">
|
|
20
13
|
<a href="https://discord.gg/6dffbvGU3D" target="_blank">
|
|
21
14
|
<img src="https://img.shields.io/discord/1122926057641742418?logo=discord&logoColor=%23FFFFFF&label=Discord&color=%236963ff" alt="Discord">
|
|
22
15
|
</a>
|
|
23
16
|
</div>
|
|
24
17
|
<br/>
|
|
25
|
-
|
|
26
18
|
<div align="center">
|
|
27
|
-
<a href="https://
|
|
28
|
-
<img src="https://
|
|
29
|
-
</a>
|
|
30
|
-
<a href="https://docs.copilotkit.ai?ref=github_readme" target="_blank">
|
|
31
|
-
<img src="https://github.com/copilotkit/copilotkit/raw/main/assets/btn_docs.png" alt="CopilotKit GitHub" height="40px">
|
|
32
|
-
</a>
|
|
33
|
-
<a href="https://cloud.copilotkit.ai?ref=github_readme" target="_blank">
|
|
34
|
-
<img src="https://github.com/copilotkit/copilotkit/raw/main/assets/btn_cloud.png" alt="CopilotKit GitHub" height="40px">
|
|
19
|
+
<a href="https://www.producthunt.com/posts/copilotkit" target="_blank">
|
|
20
|
+
<img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=428778&theme=light&period=daily">
|
|
35
21
|
</a>
|
|
36
22
|
</div>
|
|
37
23
|
|
|
38
|
-
|
|
24
|
+
## ✨ Why CopilotKit?
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
- Minutes to integrate - Get started quickly with our CLI
|
|
27
|
+
- Framework agnostic - Works with React, Next.js, AGUI and more
|
|
28
|
+
- Production-ready UI - Use customizable components or build with headless UI
|
|
29
|
+
- Built-in security - Prompt injection protection
|
|
30
|
+
- Open source - Full transparency and community-driven
|
|
31
|
+
|
|
32
|
+
<img src="https://github.com/user-attachments/assets/6cb425f8-ffcb-49d2-9bbb-87cab5995b78" alt="class-support-ecosystem" style="border-radius: 12px; border: 2px solid #d6d4fa;">
|
|
33
|
+
|
|
34
|
+
## 🧑💻 Real life use cases
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
<span>Deploy deeply-integrated AI assistants & agents that work alongside your users inside your applications.</span>
|
|
37
|
+
|
|
38
|
+
<img src="https://github.com/user-attachments/assets/3b810240-e9f8-43ae-acec-31a58095e223" alt="headless-ui" style="border-radius: 12px; border: 2px solid #d6d4fa;">
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## 🏆 Featured Examples
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<a href="https://www.copilotkit.ai/examples/form-filling-copilot">
|
|
45
|
+
<img src="https://github.com/user-attachments/assets/874da84a-67ff-47fa-a6b4-cbc3c65eb704" width="300" style="border-radius: 16px;" />
|
|
46
|
+
</a>
|
|
47
|
+
<a href="https://www.copilotkit.ai/examples/state-machine-copilot">
|
|
48
|
+
<img src="https://github.com/user-attachments/assets/0b5e45b3-2704-4678-82dc-2f3e1c58e2dd" width="300" style="border-radius: 16px;" />
|
|
49
|
+
</a>
|
|
50
|
+
<a href="https://www.copilotkit.ai/examples/chat-with-your-data">
|
|
51
|
+
<img src="https://github.com/user-attachments/assets/0fed66be-a4c2-4093-8eab-75c0b27a62f6" width="300" style="border-radius: 16px;" />
|
|
52
|
+
</a>
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
## Documentation
|
|
45
56
|
|
|
46
57
|
To get started with CopilotKit, please check out the [documentation](https://docs.copilotkit.ai).
|
|
47
58
|
|
|
48
|
-
## LangFuse Logging Integration
|
|
49
|
-
|
|
50
|
-
CopilotKit now supports LangFuse logging integration to help you monitor, analyze, and debug your LLM requests and responses.
|
|
51
|
-
|
|
52
|
-
### Setup
|
|
53
|
-
|
|
54
|
-
To enable LangFuse logging, you can configure it when initializing the CopilotRuntime:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
|
|
58
|
-
import { LangfuseClient } from "langfuse";
|
|
59
|
-
|
|
60
|
-
// Initialize your LangFuse client
|
|
61
|
-
const langfuse = new LangfuseClient({
|
|
62
|
-
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
|
|
63
|
-
secretKey: process.env.LANGFUSE_SECRET_KEY!,
|
|
64
|
-
baseUrl: process.env.LANGFUSE_BASE_URL,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Create a CopilotRuntime with LangFuse logging enabled
|
|
68
|
-
const runtime = new CopilotRuntime({
|
|
69
|
-
adapter: new OpenAIAdapter({ apiKey: process.env.OPENAI_API_KEY }),
|
|
70
|
-
logging: {
|
|
71
|
-
enabled: true,
|
|
72
|
-
progressive: true, // Set to false for buffered logging
|
|
73
|
-
logger: {
|
|
74
|
-
logRequest: (data) => langfuse.trace({ name: "LLM Request", input: data }),
|
|
75
|
-
logResponse: (data) => langfuse.trace({ name: "LLM Response", output: data }),
|
|
76
|
-
logError: (errorData) => langfuse.trace({ name: "LLM Error", metadata: errorData }),
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
59
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### Custom Logging Integrations
|
|
94
|
-
|
|
95
|
-
You can integrate with any logging service by implementing the logger interface:
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
const runtime = new CopilotRuntime({
|
|
99
|
-
adapter: new OpenAIAdapter({ apiKey: "YOUR_API_KEY" }),
|
|
100
|
-
logging: {
|
|
101
|
-
enabled: true,
|
|
102
|
-
progressive: false,
|
|
103
|
-
logger: {
|
|
104
|
-
logRequest: (data) => {
|
|
105
|
-
// Implement your custom logging logic
|
|
106
|
-
console.log("LLM Request:", JSON.stringify(data));
|
|
107
|
-
},
|
|
108
|
-
logResponse: (data) => {
|
|
109
|
-
// Implement your custom logging logic
|
|
110
|
-
console.log("LLM Response:", JSON.stringify(data));
|
|
111
|
-
},
|
|
112
|
-
logError: (error) => {
|
|
113
|
-
// Implement your custom error logging
|
|
114
|
-
console.error("LLM Error:", error);
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
});
|
|
60
|
+
## Analytics & Privacy
|
|
61
|
+
|
|
62
|
+
CopilotKit uses [Scarf](https://scarf.sh) for anonymous usage analytics to help improve the product. Scarf handles all privacy compliance and does not store raw IP addresses. This helps us understand how CopilotKit is being used and prioritize improvements.
|
|
63
|
+
|
|
64
|
+
### Opting Out
|
|
65
|
+
|
|
66
|
+
To disable analytics, set the environment variable:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
export COPILOTKIT_TELEMETRY_DISABLED=true
|
|
119
70
|
```
|
|
120
71
|
|
|
121
|
-
|
|
72
|
+
Or use the `DO_NOT_TRACK` standard:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
export DO_NOT_TRACK=1
|
|
76
|
+
```
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-NHCMVCN6.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNestEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-6AOVTAEA.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
copilotRuntimeNodeHttpEndpoint,
|
|
3
3
|
getRuntimeInstanceTelemetryInfo,
|
|
4
4
|
telemetry_client_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-NHCMVCN6.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -22,4 +22,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
|
|
|
22
22
|
export {
|
|
23
23
|
copilotRuntimeNodeExpressEndpoint
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-CD4OMUHR.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LangGraphEventTypes
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NHCMVCN6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-FHD4JECV.mjs";
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/lib/runtime/langgraph/langgraph-agent.ts
|
|
9
9
|
import { EventType } from "@ag-ui/client";
|
|
10
10
|
import { map } from "rxjs";
|
|
11
|
-
import { LangGraphAgent as AGUILangGraphAgent } from "@ag-ui/langgraph";
|
|
11
|
+
import { LangGraphAgent as AGUILangGraphAgent, LangGraphHttpAgent } from "@ag-ui/langgraph";
|
|
12
12
|
var CustomEventNames;
|
|
13
13
|
(function(CustomEventNames2) {
|
|
14
14
|
CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
|
|
@@ -152,7 +152,8 @@ var LangGraphAgent = class extends AGUILangGraphAgent {
|
|
|
152
152
|
__name(LangGraphAgent, "LangGraphAgent");
|
|
153
153
|
|
|
154
154
|
export {
|
|
155
|
+
LangGraphHttpAgent,
|
|
155
156
|
CustomEventNames,
|
|
156
157
|
LangGraphAgent
|
|
157
158
|
};
|
|
158
|
-
//# sourceMappingURL=chunk-
|
|
159
|
+
//# sourceMappingURL=chunk-EGLSN24F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/runtime/langgraph/langgraph-agent.ts"],"sourcesContent":["import {\n RunAgentInput,\n EventType,\n CustomEvent,\n TextMessageStartEvent,\n TextMessageContentEvent,\n TextMessageEndEvent,\n ToolCallStartEvent,\n ToolCallArgsEvent,\n ToolCallEndEvent,\n} from \"@ag-ui/client\";\nimport { map } from \"rxjs\";\nimport { LangGraphEventTypes } from \"../../../agents/langgraph/events\";\nimport { RawEvent } from \"@ag-ui/core\";\nimport {\n LangGraphAgent as AGUILangGraphAgent,\n LangGraphHttpAgent,\n type LangGraphAgentConfig,\n ProcessedEvents,\n SchemaKeys,\n} from \"@ag-ui/langgraph\";\nimport { Message as LangGraphMessage } from \"@langchain/langgraph-sdk/dist/types.messages\";\n\nexport interface PredictStateTool {\n tool: string;\n state_key: string;\n tool_argument: string;\n}\nexport type State = Record<string, any>;\n\nexport type TextMessageEvents =\n | TextMessageStartEvent\n | TextMessageContentEvent\n | TextMessageEndEvent;\n\nexport type ToolCallEvents = ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;\n\nexport enum CustomEventNames {\n CopilotKitManuallyEmitMessage = \"copilotkit_manually_emit_message\",\n CopilotKitManuallyEmitToolCall = \"copilotkit_manually_emit_tool_call\",\n CopilotKitManuallyEmitIntermediateState = \"copilotkit_manually_emit_intermediate_state\",\n CopilotKitExit = \"copilotkit_exit\",\n}\n\nexport class LangGraphAgent extends AGUILangGraphAgent {\n constructor(config: LangGraphAgentConfig) {\n super(config);\n }\n\n dispatchEvent(event: ProcessedEvents) {\n if (event.type === EventType.CUSTOM) {\n // const event = processedEvent as unknown as CustomEvent;\n const customEvent = event as unknown as CustomEvent;\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitMessage) {\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_START,\n role: \"assistant\",\n messageId: customEvent.value.message_id,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId: customEvent.value.message_id,\n delta: customEvent.value.message,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TEXT_MESSAGE_END,\n messageId: customEvent.value.message_id,\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {\n this.subscriber.next({\n type: EventType.TOOL_CALL_START,\n toolCallId: customEvent.value.id,\n toolCallName: customEvent.value.name,\n parentMessageId: customEvent.value.id,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TOOL_CALL_ARGS,\n toolCallId: customEvent.value.id,\n delta: customEvent.value.args,\n rawEvent: event,\n });\n this.subscriber.next({\n type: EventType.TOOL_CALL_END,\n toolCallId: customEvent.value.id,\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState) {\n this.activeRun.manuallyEmittedState = customEvent.value;\n this.dispatchEvent({\n type: EventType.STATE_SNAPSHOT,\n snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),\n rawEvent: event,\n });\n return true;\n }\n\n if (customEvent.name === CustomEventNames.CopilotKitExit) {\n this.subscriber.next({\n type: EventType.CUSTOM,\n name: \"Exit\",\n value: true,\n });\n return true;\n }\n }\n\n // Intercept all text message and tool call events and check if should disable\n const rawEvent = (event as ToolCallEvents | TextMessageEvents).rawEvent;\n if (!rawEvent) {\n this.subscriber.next(event);\n return true;\n }\n\n const isMessageEvent =\n event.type === EventType.TEXT_MESSAGE_START ||\n event.type === EventType.TEXT_MESSAGE_CONTENT ||\n event.type === EventType.TEXT_MESSAGE_END;\n const isToolEvent =\n event.type === EventType.TOOL_CALL_START ||\n event.type === EventType.TOOL_CALL_ARGS ||\n event.type === EventType.TOOL_CALL_END;\n if (\"copilotkit:emit-tool-calls\" in (rawEvent.metadata || {})) {\n if (rawEvent.metadata[\"copilotkit:emit-tool-calls\"] === false && isToolEvent) {\n return false;\n }\n }\n if (\"copilotkit:emit-messages\" in (rawEvent.metadata || {})) {\n if (rawEvent.metadata[\"copilotkit:emit-messages\"] === false && isMessageEvent) {\n return false;\n }\n }\n\n this.subscriber.next(event);\n return true;\n }\n\n // @ts-ignore\n run(input: RunAgentInput) {\n return super.run(input).pipe(\n map((processedEvent) => {\n // Turn raw event into emit state snapshot from tool call event\n if (processedEvent.type === EventType.RAW) {\n // Get the LangGraph event from the AGUI event.\n const event = (processedEvent as RawEvent).event ?? (processedEvent as RawEvent).rawEvent;\n\n const eventType = event.event;\n const toolCallData = event.data?.chunk?.tool_call_chunks?.[0];\n const toolCallUsedToPredictState = event.metadata?.[\n \"copilotkit:emit-intermediate-state\"\n ]?.some(\n (predictStateTool: PredictStateTool) => predictStateTool.tool === toolCallData?.name,\n );\n\n if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {\n return {\n type: EventType.CUSTOM,\n name: \"PredictState\",\n value: event.metadata[\"copilotkit:emit-intermediate-state\"],\n };\n }\n }\n\n return processedEvent;\n }),\n );\n }\n\n langGraphDefaultMergeState(state: State, messages: LangGraphMessage[], tools: any): State {\n const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(\n state,\n messages,\n tools,\n );\n\n return {\n ...rest,\n copilotkit: {\n actions: returnedTools,\n },\n };\n }\n\n async getSchemaKeys(): Promise<SchemaKeys> {\n const CONSTANT_KEYS = [\"copilotkit\"];\n const schemaKeys = await super.getSchemaKeys();\n return {\n config: schemaKeys.config,\n input: schemaKeys.input ? [...schemaKeys.input, ...CONSTANT_KEYS] : null,\n output: schemaKeys.output ? [...schemaKeys.output, ...CONSTANT_KEYS] : null,\n };\n }\n}\n\nexport { LangGraphHttpAgent };\n"],"mappings":"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","names":["EventType","map","LangGraphAgent","AGUILangGraphAgent","LangGraphHttpAgent","CustomEventNames","LangGraphAgent","AGUILangGraphAgent","constructor","config","dispatchEvent","event","type","EventType","CUSTOM","customEvent","name","subscriber","next","TEXT_MESSAGE_START","role","messageId","value","message_id","rawEvent","TEXT_MESSAGE_CONTENT","delta","message","TEXT_MESSAGE_END","TOOL_CALL_START","toolCallId","id","toolCallName","parentMessageId","TOOL_CALL_ARGS","args","TOOL_CALL_END","activeRun","manuallyEmittedState","STATE_SNAPSHOT","snapshot","getStateSnapshot","isMessageEvent","isToolEvent","metadata","run","input","pipe","map","processedEvent","RAW","eventType","toolCallData","data","chunk","tool_call_chunks","toolCallUsedToPredictState","some","predictStateTool","tool","LangGraphEventTypes","OnChatModelStream","langGraphDefaultMergeState","state","messages","tools","returnedTools","rest","copilotkit","actions","getSchemaKeys","CONSTANT_KEYS","schemaKeys","output"]}
|
|
@@ -329,7 +329,7 @@ var OpenAIAdapter = class {
|
|
|
329
329
|
tools
|
|
330
330
|
},
|
|
331
331
|
...(forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) && {
|
|
332
|
-
|
|
332
|
+
max_completion_tokens: forwardedParameters.maxTokens
|
|
333
333
|
},
|
|
334
334
|
...(forwardedParameters == null ? void 0 : forwardedParameters.stop) && {
|
|
335
335
|
stop: forwardedParameters.stop
|
|
@@ -1320,6 +1320,7 @@ import { randomId as randomId3, randomUUID as randomUUID5 } from "@copilotkit/sh
|
|
|
1320
1320
|
var DEFAULT_MODEL3 = "claude-3-5-sonnet-latest";
|
|
1321
1321
|
var AnthropicAdapter = class {
|
|
1322
1322
|
model = DEFAULT_MODEL3;
|
|
1323
|
+
promptCaching;
|
|
1323
1324
|
_anthropic;
|
|
1324
1325
|
get anthropic() {
|
|
1325
1326
|
return this._anthropic;
|
|
@@ -1329,6 +1330,63 @@ var AnthropicAdapter = class {
|
|
|
1329
1330
|
if (params == null ? void 0 : params.model) {
|
|
1330
1331
|
this.model = params.model;
|
|
1331
1332
|
}
|
|
1333
|
+
this.promptCaching = (params == null ? void 0 : params.promptCaching) || {
|
|
1334
|
+
enabled: false
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Adds cache control to system prompt
|
|
1339
|
+
*/
|
|
1340
|
+
addSystemPromptCaching(system, debug = false) {
|
|
1341
|
+
if (!this.promptCaching.enabled || !system) {
|
|
1342
|
+
return system;
|
|
1343
|
+
}
|
|
1344
|
+
const originalTextLength = system.length;
|
|
1345
|
+
if (debug) {
|
|
1346
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to system prompt (${originalTextLength} chars).`);
|
|
1347
|
+
}
|
|
1348
|
+
return [
|
|
1349
|
+
{
|
|
1350
|
+
type: "text",
|
|
1351
|
+
text: system,
|
|
1352
|
+
cache_control: {
|
|
1353
|
+
type: "ephemeral"
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
];
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Adds cache control to the final message
|
|
1360
|
+
*/
|
|
1361
|
+
addIncrementalMessageCaching(messages, debug = false) {
|
|
1362
|
+
if (!this.promptCaching.enabled || messages.length === 0) {
|
|
1363
|
+
return messages;
|
|
1364
|
+
}
|
|
1365
|
+
const finalMessage = messages[messages.length - 1];
|
|
1366
|
+
const messageNumber = messages.length;
|
|
1367
|
+
if (Array.isArray(finalMessage.content) && finalMessage.content.length > 0) {
|
|
1368
|
+
const finalBlock = finalMessage.content[finalMessage.content.length - 1];
|
|
1369
|
+
const updatedMessages = [
|
|
1370
|
+
...messages.slice(0, -1),
|
|
1371
|
+
{
|
|
1372
|
+
...finalMessage,
|
|
1373
|
+
content: [
|
|
1374
|
+
...finalMessage.content.slice(0, -1),
|
|
1375
|
+
{
|
|
1376
|
+
...finalBlock,
|
|
1377
|
+
cache_control: {
|
|
1378
|
+
type: "ephemeral"
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
]
|
|
1382
|
+
}
|
|
1383
|
+
];
|
|
1384
|
+
if (debug) {
|
|
1385
|
+
console.log(`[ANTHROPIC CACHE DEBUG] Added cache control to final message (message ${messageNumber}).`);
|
|
1386
|
+
}
|
|
1387
|
+
return updatedMessages;
|
|
1388
|
+
}
|
|
1389
|
+
return messages;
|
|
1332
1390
|
}
|
|
1333
1391
|
shouldGenerateFallbackResponse(messages) {
|
|
1334
1392
|
var _a, _b, _c;
|
|
@@ -1390,6 +1448,8 @@ var AnthropicAdapter = class {
|
|
|
1390
1448
|
return true;
|
|
1391
1449
|
});
|
|
1392
1450
|
const limitedMessages = limitMessagesToTokenCount2(anthropicMessages, tools, model);
|
|
1451
|
+
const cachedSystemPrompt = this.addSystemPromptCaching(instructions, this.promptCaching.debug);
|
|
1452
|
+
const cachedMessages = this.addIncrementalMessageCaching(limitedMessages, this.promptCaching.debug);
|
|
1393
1453
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
1394
1454
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
1395
1455
|
toolChoice = {
|
|
@@ -1399,9 +1459,9 @@ var AnthropicAdapter = class {
|
|
|
1399
1459
|
}
|
|
1400
1460
|
try {
|
|
1401
1461
|
const createParams = {
|
|
1402
|
-
system:
|
|
1462
|
+
system: cachedSystemPrompt,
|
|
1403
1463
|
model: this.model,
|
|
1404
|
-
messages:
|
|
1464
|
+
messages: cachedMessages,
|
|
1405
1465
|
max_tokens: (forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) || 1024,
|
|
1406
1466
|
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) ? {
|
|
1407
1467
|
temperature: forwardedParameters.temperature
|
|
@@ -1479,9 +1539,9 @@ var AnthropicAdapter = class {
|
|
|
1479
1539
|
} catch (error) {
|
|
1480
1540
|
throw convertServiceAdapterError(error, "Anthropic");
|
|
1481
1541
|
}
|
|
1482
|
-
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(
|
|
1542
|
+
if (!hasReceivedContent && this.shouldGenerateFallbackResponse(cachedMessages)) {
|
|
1483
1543
|
let fallbackContent = "Task completed successfully.";
|
|
1484
|
-
const lastMessage =
|
|
1544
|
+
const lastMessage = cachedMessages[cachedMessages.length - 1];
|
|
1485
1545
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "user" && Array.isArray(lastMessage.content)) {
|
|
1486
1546
|
const toolResult = lastMessage.content.find((c) => c.type === "tool_result");
|
|
1487
1547
|
if ((toolResult == null ? void 0 : toolResult.content) && toolResult.content !== "Action completed successfully") {
|
|
@@ -1635,4 +1695,4 @@ export {
|
|
|
1635
1695
|
EmptyAdapter,
|
|
1636
1696
|
ExperimentalEmptyAdapter
|
|
1637
1697
|
};
|
|
1638
|
-
//# sourceMappingURL=chunk-
|
|
1698
|
+
//# sourceMappingURL=chunk-F7IANE7Z.mjs.map
|