@copilotkit/sdk-js 2.0.0-next.1 → 2.0.0-rc.0
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/LICENSE +21 -0
- package/README.md +0 -1
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/header-propagation.cjs +37 -0
- package/dist/header-propagation.cjs.map +1 -0
- package/dist/header-propagation.d.cts +16 -0
- package/dist/header-propagation.d.cts.map +1 -0
- package/dist/header-propagation.d.mts +16 -0
- package/dist/header-propagation.d.mts.map +1 -0
- package/dist/header-propagation.mjs +35 -0
- package/dist/header-propagation.mjs.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +3 -1
- package/dist/langchain.cjs +21 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +139 -0
- package/dist/langchain.d.mts +140 -0
- package/dist/langchain.mjs +7 -23
- package/dist/langchain.mjs.map +1 -1
- package/dist/langgraph/middleware.cjs +433 -0
- package/dist/langgraph/middleware.cjs.map +1 -0
- package/dist/langgraph/middleware.d.cts +86 -0
- package/dist/langgraph/middleware.d.cts.map +1 -0
- package/dist/langgraph/middleware.d.mts +86 -0
- package/dist/langgraph/middleware.d.mts.map +1 -0
- package/dist/langgraph/middleware.mjs +429 -0
- package/dist/langgraph/middleware.mjs.map +1 -0
- package/dist/langgraph/state-schema.cjs +37 -0
- package/dist/langgraph/state-schema.cjs.map +1 -0
- package/dist/langgraph/state-schema.d.cts +118 -0
- package/dist/langgraph/state-schema.d.cts.map +1 -0
- package/dist/langgraph/state-schema.d.mts +118 -0
- package/dist/langgraph/state-schema.d.mts.map +1 -0
- package/dist/langgraph/state-schema.mjs +36 -0
- package/dist/langgraph/state-schema.mjs.map +1 -0
- package/dist/langgraph/types.cjs +60 -0
- package/dist/langgraph/types.cjs.map +1 -0
- package/dist/langgraph/types.d.cts +335 -0
- package/dist/langgraph/types.d.cts.map +1 -0
- package/dist/langgraph/types.d.mts +335 -0
- package/dist/langgraph/types.d.mts.map +1 -0
- package/dist/langgraph/types.mjs +57 -0
- package/dist/langgraph/types.mjs.map +1 -0
- package/dist/langgraph/utils.cjs +297 -0
- package/dist/langgraph/utils.cjs.map +1 -0
- package/dist/langgraph/utils.d.cts +209 -0
- package/dist/langgraph/utils.d.cts.map +1 -0
- package/dist/langgraph/utils.d.mts +209 -0
- package/dist/langgraph/utils.d.mts.map +1 -0
- package/dist/langgraph/utils.mjs +289 -0
- package/dist/langgraph/utils.mjs.map +1 -0
- package/dist/langgraph-middlewares.cjs +22 -0
- package/dist/langgraph-middlewares.d.cts +30 -0
- package/dist/langgraph-middlewares.d.mts +30 -0
- package/dist/langgraph-middlewares.mjs +5 -0
- package/dist/langgraph.cjs +21 -0
- package/dist/langgraph.d.cts +5 -0
- package/dist/langgraph.d.mts +5 -0
- package/dist/langgraph.mjs +6 -27
- package/package.json +50 -47
- package/src/__tests__/error-handling.test.ts +54 -20
- package/src/__tests__/header-propagation.test.ts +131 -0
- package/src/header-propagation.ts +61 -0
- package/src/index.ts +41 -0
- package/src/langchain.ts +168 -8
- package/src/langgraph/__tests__/middleware.a2ui-params.test.ts +139 -0
- package/src/langgraph/__tests__/middleware.native-a2ui.test.ts +118 -0
- package/src/langgraph/__tests__/middleware.properties.test.ts +357 -0
- package/src/langgraph/__tests__/middleware.test.ts +1141 -0
- package/src/langgraph/__tests__/state-schema.test.ts +85 -0
- package/src/langgraph/__tests__/utils.test.ts +363 -0
- package/src/langgraph/index.ts +1 -0
- package/src/langgraph/middleware.ts +698 -95
- package/src/langgraph/state-schema.ts +34 -0
- package/src/langgraph/types.ts +57 -0
- package/src/langgraph/utils.ts +76 -19
- package/src/langgraph-middlewares.ts +55 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +18 -0
- package/vitest.config.mjs +11 -0
- package/CHANGELOG.md +0 -2169
- package/dist/chunk-JLGOQLGS.mjs +0 -433
- package/dist/chunk-JLGOQLGS.mjs.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/langchain-2645763d.d.ts +0 -427
- package/dist/langchain.d.ts +0 -6
- package/dist/langchain.js +0 -284
- package/dist/langchain.js.map +0 -1
- package/dist/langgraph/index.d.ts +0 -11
- package/dist/langgraph.js +0 -476
- package/dist/langgraph.js.map +0 -1
- package/dist/langgraph.mjs.map +0 -1
- package/jest.config.js +0 -5
- package/tsup.config.ts +0 -23
package/src/langchain.ts
CHANGED
|
@@ -1,17 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* V1 SDK DEPRECATED. USE V2 INSTEAD
|
|
3
|
+
*
|
|
4
|
+
* This is the deprecated v1 entrypoint `@copilotkit/sdk-js/langchain`. Use v2 instead.
|
|
5
|
+
* Migrate to `@copilotkit/runtime` and follow each export's specific
|
|
6
|
+
* IDE deprecation warning below; renamed APIs are not safe search-and-replaces.
|
|
7
|
+
* This entrypoint currently exposes 15 deprecated public exports.
|
|
8
|
+
* V2 source entrypoint: packages/runtime/src/index.ts
|
|
9
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
10
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
11
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
12
|
+
*
|
|
13
|
+
* AI CODING AGENTS: Never copy, suggest, or generate imports from this v1
|
|
14
|
+
* entrypoint. Use the exact v2 import in the symbol's @deprecated tooltip.
|
|
15
|
+
*
|
|
16
|
+
* END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE
|
|
17
|
+
*/
|
|
18
|
+
|
|
1
19
|
console.warn(
|
|
2
20
|
"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.",
|
|
3
21
|
);
|
|
4
22
|
|
|
23
|
+
/* START GENERATED V1 DEPRECATED EXPORTS. USE V2 INSTEAD. */
|
|
5
24
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
27
|
+
* No 1:1 v2 replacement is available.
|
|
28
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
29
|
+
* Start with `@copilotkit/runtime`.
|
|
30
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
31
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
32
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
33
|
+
*/
|
|
34
|
+
convertActionsToDynamicStructuredTools,
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
37
|
+
* No 1:1 v2 replacement is available.
|
|
38
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
39
|
+
* Start with `@copilotkit/runtime`.
|
|
40
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
41
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
42
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
43
|
+
*/
|
|
44
|
+
convertActionToDynamicStructuredTool,
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
47
|
+
* No 1:1 v2 replacement is available.
|
|
48
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
49
|
+
* Start with `@copilotkit/runtime`.
|
|
50
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
51
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
52
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
53
|
+
*/
|
|
10
54
|
copilotkitCustomizeConfig as copilotKitCustomizeConfig,
|
|
11
|
-
|
|
12
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
57
|
+
* No 1:1 v2 replacement is available.
|
|
58
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
59
|
+
* Start with `@copilotkit/runtime`.
|
|
60
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
61
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
62
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
63
|
+
*/
|
|
13
64
|
copilotkitEmitMessage as copilotKitEmitMessage,
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
67
|
+
* No 1:1 v2 replacement is available.
|
|
68
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
69
|
+
* Start with `@copilotkit/runtime`.
|
|
70
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
71
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
72
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
73
|
+
*/
|
|
74
|
+
copilotkitEmitState as copilotKitEmitState,
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
77
|
+
* No 1:1 v2 replacement is available.
|
|
78
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
79
|
+
* Start with `@copilotkit/runtime`.
|
|
80
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
81
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
82
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
83
|
+
*/
|
|
14
84
|
copilotkitEmitToolCall as copilotKitEmitToolCall,
|
|
15
|
-
|
|
16
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
87
|
+
* No 1:1 v2 replacement is available.
|
|
88
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
89
|
+
* Start with `@copilotkit/runtime`.
|
|
90
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
91
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
92
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
93
|
+
*/
|
|
94
|
+
copilotkitExit as copilotKitExit,
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
97
|
+
* No 1:1 v2 replacement is available.
|
|
98
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
99
|
+
* Start with `@copilotkit/runtime`.
|
|
100
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
101
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
102
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
103
|
+
*/
|
|
104
|
+
type CopilotKitProperties,
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
107
|
+
* No 1:1 v2 replacement is available.
|
|
108
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
109
|
+
* Start with `@copilotkit/runtime`.
|
|
110
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
111
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
112
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
113
|
+
*/
|
|
114
|
+
CopilotKitPropertiesAnnotation,
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
117
|
+
* No 1:1 v2 replacement is available.
|
|
118
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
119
|
+
* Start with `@copilotkit/runtime`.
|
|
120
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
121
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
122
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
123
|
+
*/
|
|
124
|
+
CopilotKitPropertiesSchema,
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
127
|
+
* No 1:1 v2 replacement is available.
|
|
128
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
129
|
+
* Start with `@copilotkit/runtime`.
|
|
130
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
131
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
132
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
133
|
+
*/
|
|
134
|
+
type CopilotKitSchemaState,
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
137
|
+
* No 1:1 v2 replacement is available.
|
|
138
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
139
|
+
* Start with `@copilotkit/runtime`.
|
|
140
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
141
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
142
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
143
|
+
*/
|
|
144
|
+
type CopilotKitSchemaUpdate,
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
147
|
+
* No 1:1 v2 replacement is available.
|
|
148
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
149
|
+
* Start with `@copilotkit/runtime`.
|
|
150
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
151
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
152
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
153
|
+
*/
|
|
154
|
+
type CopilotKitState,
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
157
|
+
* No 1:1 v2 replacement is available.
|
|
158
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
159
|
+
* Start with `@copilotkit/runtime`.
|
|
160
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
161
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
162
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
163
|
+
*/
|
|
164
|
+
CopilotKitStateAnnotation,
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Since 1.68.2. The v1 SDK is deprecated. Use v2 instead.
|
|
167
|
+
* No 1:1 v2 replacement is available.
|
|
168
|
+
* Related v2 docs (LangGraph agents): https://docs.copilotkit.ai/agent-spec/langgraph
|
|
169
|
+
* Start with `@copilotkit/runtime`.
|
|
170
|
+
* V2 docs: https://docs.copilotkit.ai/
|
|
171
|
+
* V2 reference docs: https://docs.copilotkit.ai/reference/v2
|
|
172
|
+
* Migration guide: https://docs.copilotkit.ai/migrate/v2
|
|
173
|
+
*/
|
|
174
|
+
CopilotKitStateSchema,
|
|
17
175
|
} from "./langgraph";
|
|
176
|
+
|
|
177
|
+
/* END GENERATED V1 DEPRECATED EXPORTS. USE V2 INSTEAD. */
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the host `a2uiParams` override on the auto-injected generate_a2ui
|
|
3
|
+
* tool (the design-guidelines parity gap).
|
|
4
|
+
*
|
|
5
|
+
* Before this, the auto-inject path hardwired getA2UITools to the toolkit
|
|
6
|
+
* defaults: a host serving via copilotkitMiddleware could NOT override the
|
|
7
|
+
* design/generation guidelines (e.g. to favor a repeating-card layout). The
|
|
8
|
+
* `a2uiParams` option threads a host override through; the middleware still
|
|
9
|
+
* injects the bound model and folds the registered catalog in (host wins).
|
|
10
|
+
*
|
|
11
|
+
* We mock @ag-ui/langgraph's getA2UITools to capture the params it is handed —
|
|
12
|
+
* the real factory's bound guidelines are a closure the tool object never
|
|
13
|
+
* exposes, so capture-at-the-boundary is the only way to assert what reached
|
|
14
|
+
* the subagent. Isolated in its own file so the module-wide mock does not
|
|
15
|
+
* affect the behavior tests in middleware.test.ts.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
19
|
+
|
|
20
|
+
import type { A2UIToolParams } from "@ag-ui/langgraph";
|
|
21
|
+
|
|
22
|
+
const { captured } = vi.hoisted(() => {
|
|
23
|
+
const params: A2UIToolParams[] = [];
|
|
24
|
+
return { captured: params };
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
vi.mock("@ag-ui/langgraph", () => ({
|
|
28
|
+
getA2UITools: (params: A2UIToolParams) => {
|
|
29
|
+
captured.push(params);
|
|
30
|
+
return { name: "generate_a2ui", invoke: async () => "ok" };
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
// Imported AFTER vi.mock so the middleware binds the mocked getA2UITools.
|
|
35
|
+
import { createCopilotkitMiddleware } from "../middleware";
|
|
36
|
+
|
|
37
|
+
function makeRequest(overrides: any = {}): any {
|
|
38
|
+
return {
|
|
39
|
+
model: { _modelType: () => "fake" },
|
|
40
|
+
messages: [],
|
|
41
|
+
systemPrompt: undefined,
|
|
42
|
+
tools: [],
|
|
43
|
+
state: { messages: [] },
|
|
44
|
+
runtime: {},
|
|
45
|
+
...overrides,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function runWrap(middleware: any, request: any) {
|
|
50
|
+
const handler = async (_req: any) => ({ content: "ok" }) as any;
|
|
51
|
+
await middleware.wrapModelCall(request, handler);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Native path: schema present but non-JSON, so no catalogId / compositionGuide.
|
|
55
|
+
const NATIVE_STATE = {
|
|
56
|
+
messages: [],
|
|
57
|
+
thread_id: "native",
|
|
58
|
+
"ag-ui": { a2ui_schema: "<components/>", inject_a2ui_tool: true },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Runtime-proxy path: the catalog arrives as a context entry, so the middleware
|
|
62
|
+
// derives a compositionGuide + catalogId to fold in.
|
|
63
|
+
const CONTEXT_STATE = {
|
|
64
|
+
messages: [],
|
|
65
|
+
thread_id: "context",
|
|
66
|
+
"ag-ui": { inject_a2ui_tool: true },
|
|
67
|
+
copilotkit: {
|
|
68
|
+
context: [
|
|
69
|
+
{
|
|
70
|
+
description: "A2UI catalog capabilities",
|
|
71
|
+
value: "Available A2UI catalog:\n- my-custom-catalog\n - Card: {...}",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
describe("auto-A2UI host a2uiParams override", () => {
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
captured.length = 0;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("threads host guidelines through to getA2UITools (native path)", async () => {
|
|
83
|
+
const middleware = createCopilotkitMiddleware({
|
|
84
|
+
a2uiParams: { guidelines: { designGuidelines: "REPEAT_CARDS_MARK" } },
|
|
85
|
+
});
|
|
86
|
+
const request = makeRequest({ state: { ...NATIVE_STATE } });
|
|
87
|
+
|
|
88
|
+
await runWrap(middleware, request);
|
|
89
|
+
|
|
90
|
+
expect(captured).toHaveLength(1);
|
|
91
|
+
const params = captured[0];
|
|
92
|
+
// Host override survives...
|
|
93
|
+
expect(params.guidelines.designGuidelines).toBe("REPEAT_CARDS_MARK");
|
|
94
|
+
// ...the middleware still injects the bound model...
|
|
95
|
+
expect(params.model).toBe(request.model);
|
|
96
|
+
// ...and the native path contributes no compositionGuide.
|
|
97
|
+
expect(params.guidelines.compositionGuide).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("merges host guidelines with the registered catalog (context path)", async () => {
|
|
101
|
+
const middleware = createCopilotkitMiddleware({
|
|
102
|
+
a2uiParams: { guidelines: { designGuidelines: "REPEAT_CARDS_MARK" } },
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await runWrap(middleware, makeRequest({ state: { ...CONTEXT_STATE } }));
|
|
106
|
+
|
|
107
|
+
const params = captured[0];
|
|
108
|
+
expect(params.guidelines.designGuidelines).toBe("REPEAT_CARDS_MARK");
|
|
109
|
+
expect(params.guidelines.compositionGuide).toContain("my-custom-catalog");
|
|
110
|
+
expect(params.defaultCatalogId).toBe("my-custom-catalog");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("host compositionGuide + defaultCatalogId win over the catalog", async () => {
|
|
114
|
+
const middleware = createCopilotkitMiddleware({
|
|
115
|
+
a2uiParams: {
|
|
116
|
+
defaultCatalogId: "host-catalog",
|
|
117
|
+
guidelines: { compositionGuide: "HOST_COMP" },
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await runWrap(middleware, makeRequest({ state: { ...CONTEXT_STATE } }));
|
|
122
|
+
|
|
123
|
+
const params = captured[0];
|
|
124
|
+
expect(params.guidelines.compositionGuide).toBe("HOST_COMP");
|
|
125
|
+
expect(params.defaultCatalogId).toBe("host-catalog");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("default (no a2uiParams) carries only the inferred model", async () => {
|
|
129
|
+
const middleware = createCopilotkitMiddleware();
|
|
130
|
+
const request = makeRequest({ state: { ...NATIVE_STATE } });
|
|
131
|
+
|
|
132
|
+
await runWrap(middleware, request);
|
|
133
|
+
|
|
134
|
+
const params = captured[0];
|
|
135
|
+
expect(params.model).toBe(request.model);
|
|
136
|
+
expect(params.guidelines).toBeUndefined();
|
|
137
|
+
expect(params.defaultCatalogId).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
AIMessage,
|
|
4
|
+
AIMessageChunk,
|
|
5
|
+
HumanMessage,
|
|
6
|
+
} from "@langchain/core/messages";
|
|
7
|
+
import type { BaseMessage } from "@langchain/core/messages";
|
|
8
|
+
import type { getA2UITools } from "@ag-ui/langgraph";
|
|
9
|
+
import { createCopilotkitMiddleware } from "../middleware";
|
|
10
|
+
|
|
11
|
+
const components = [{ id: "root", component: "Text", text: "Sales Dashboard" }];
|
|
12
|
+
|
|
13
|
+
// A deterministic in-process model drives the actual toolkit; no provider
|
|
14
|
+
// requests or SDK/factory mocks are involved in this adapter contract test.
|
|
15
|
+
async function generate(properties: object) {
|
|
16
|
+
const prompts: string[] = [];
|
|
17
|
+
const model = {
|
|
18
|
+
bindTools: () => ({
|
|
19
|
+
async *stream(messages: BaseMessage[]) {
|
|
20
|
+
prompts.push(String(messages[0].content));
|
|
21
|
+
yield new AIMessageChunk({
|
|
22
|
+
content: "",
|
|
23
|
+
tool_calls: [
|
|
24
|
+
{
|
|
25
|
+
id: "render",
|
|
26
|
+
name: "render_a2ui",
|
|
27
|
+
args: { surfaceId: "dashboard", components },
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
const state = {
|
|
35
|
+
messages: [
|
|
36
|
+
new HumanMessage("Dashboard"),
|
|
37
|
+
new AIMessage({
|
|
38
|
+
content: "",
|
|
39
|
+
tool_calls: [{ id: "generate", name: "generate_a2ui", args: {} }],
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
thread_id: "native-tool-contract",
|
|
43
|
+
...properties,
|
|
44
|
+
};
|
|
45
|
+
const before = JSON.stringify(state);
|
|
46
|
+
const middleware = createCopilotkitMiddleware();
|
|
47
|
+
let tool: ReturnType<typeof getA2UITools> | undefined;
|
|
48
|
+
await middleware.wrapModelCall(
|
|
49
|
+
{ model, state, tools: [], messages: [], runtime: {} },
|
|
50
|
+
async (request) => {
|
|
51
|
+
tool = request.tools.find(
|
|
52
|
+
(candidate: { name: string }) => candidate.name === "generate_a2ui",
|
|
53
|
+
);
|
|
54
|
+
return new AIMessage("ok");
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
if (!tool) throw new Error("Expected the native A2UI tool");
|
|
58
|
+
const result = await tool.invoke({ intent: "create" }, { state });
|
|
59
|
+
if (typeof result !== "string")
|
|
60
|
+
throw new Error("Expected a native operations envelope");
|
|
61
|
+
expect(JSON.stringify(state)).toBe(before);
|
|
62
|
+
expect(JSON.parse(result)).toEqual({
|
|
63
|
+
a2ui_operations: [
|
|
64
|
+
{
|
|
65
|
+
version: "v0.9",
|
|
66
|
+
createSurface: {
|
|
67
|
+
surfaceId: "dashboard",
|
|
68
|
+
catalogId: "copilotkit://app-dashboard-catalog",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
version: "v0.9",
|
|
73
|
+
updateComponents: { surfaceId: "dashboard", components },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
middleware.afterAgent(state);
|
|
78
|
+
return prompts[0];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe("native A2UI tool namespace contract", () => {
|
|
82
|
+
it("uses the merged schema in the real toolkit prompt and CopilotKit catalog in native operations", async () => {
|
|
83
|
+
const prompt = await generate({
|
|
84
|
+
"ag-ui": {
|
|
85
|
+
inject_a2ui_tool: true,
|
|
86
|
+
a2ui_schema: {
|
|
87
|
+
catalogId: "agui://base",
|
|
88
|
+
components: { Base: { description: "RETAINED_NATIVE_SCHEMA" } },
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
copilotkit: {
|
|
92
|
+
a2ui_schema: {
|
|
93
|
+
catalogId: "copilotkit://app-dashboard-catalog",
|
|
94
|
+
components: { Text: { description: "COPILOTKIT_SCHEMA" } },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
expect(prompt).toContain("RETAINED_NATIVE_SCHEMA");
|
|
99
|
+
expect(prompt).toContain("COPILOTKIT_SCHEMA");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("uses an AG-UI-only serialized context catalog in native operations", async () => {
|
|
103
|
+
const prompt = await generate({
|
|
104
|
+
"ag-ui": {
|
|
105
|
+
inject_a2ui_tool: true,
|
|
106
|
+
context: JSON.stringify([
|
|
107
|
+
{
|
|
108
|
+
description: "A2UI catalog capabilities",
|
|
109
|
+
value: JSON.stringify(
|
|
110
|
+
"Available A2UI catalog:\n- copilotkit://app-dashboard-catalog\n - Text: {...}",
|
|
111
|
+
),
|
|
112
|
+
},
|
|
113
|
+
]),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
expect(prompt).toContain("copilotkit://app-dashboard-catalog");
|
|
117
|
+
});
|
|
118
|
+
});
|