@copilotkitnext/agent 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
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/.turbo/turbo-build.log +23 -0
- package/.turbo/turbo-test.log +276 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/dist/index.d.mts +199 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +629 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +606 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
- package/src/__tests__/basic-agent.test.ts +566 -0
- package/src/__tests__/config-tools-execution.test.ts +503 -0
- package/src/__tests__/property-overrides.test.ts +559 -0
- package/src/__tests__/state-tools.test.ts +391 -0
- package/src/__tests__/test-helpers.ts +130 -0
- package/src/__tests__/utils.test.ts +438 -0
- package/src/index.ts +1003 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +13 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Message, RunAgentInput, AbstractAgent, BaseEvent } from '@ag-ui/client';
|
|
2
|
+
import { LanguageModel, ModelMessage, ToolSet, ToolChoice } from 'ai';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Properties that can be overridden by forwardedProps
|
|
9
|
+
* These match the exact parameter names in streamText
|
|
10
|
+
*/
|
|
11
|
+
type OverridableProperty = "model" | "toolChoice" | "maxOutputTokens" | "temperature" | "topP" | "topK" | "presencePenalty" | "frequencyPenalty" | "stopSequences" | "seed" | "maxRetries" | "prompt";
|
|
12
|
+
/**
|
|
13
|
+
* Supported model identifiers for BuiltInAgent
|
|
14
|
+
*/
|
|
15
|
+
type BuiltInAgentModel = "openai/gpt-5" | "openai/gpt-5-mini" | "openai/gpt-4.1" | "openai/gpt-4.1-mini" | "openai/gpt-4.1-nano" | "openai/gpt-4o" | "openai/gpt-4o-mini" | "openai/o3" | "openai/o3-mini" | "openai/o4-mini" | "anthropic/claude-sonnet-4.5" | "anthropic/claude-sonnet-4" | "anthropic/claude-3.7-sonnet" | "anthropic/claude-opus-4.1" | "anthropic/claude-opus-4" | "anthropic/claude-3.5-haiku" | "google/gemini-2.5-pro" | "google/gemini-2.5-flash" | "google/gemini-2.5-flash-lite" | (string & {});
|
|
16
|
+
/**
|
|
17
|
+
* Model specifier - can be a string like "openai/gpt-4o" or a LanguageModel instance
|
|
18
|
+
*/
|
|
19
|
+
type ModelSpecifier = string | LanguageModel;
|
|
20
|
+
/**
|
|
21
|
+
* MCP Client configuration for HTTP transport
|
|
22
|
+
*/
|
|
23
|
+
interface MCPClientConfigHTTP {
|
|
24
|
+
/**
|
|
25
|
+
* Type of MCP client
|
|
26
|
+
*/
|
|
27
|
+
type: "http";
|
|
28
|
+
/**
|
|
29
|
+
* URL of the MCP server
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
/**
|
|
33
|
+
* Optional transport options for HTTP client
|
|
34
|
+
*/
|
|
35
|
+
options?: StreamableHTTPClientTransportOptions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* MCP Client configuration for SSE transport
|
|
39
|
+
*/
|
|
40
|
+
interface MCPClientConfigSSE {
|
|
41
|
+
/**
|
|
42
|
+
* Type of MCP client
|
|
43
|
+
*/
|
|
44
|
+
type: "sse";
|
|
45
|
+
/**
|
|
46
|
+
* URL of the MCP server
|
|
47
|
+
*/
|
|
48
|
+
url: string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional HTTP headers (e.g., for authentication)
|
|
51
|
+
*/
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* MCP Client configuration
|
|
56
|
+
*/
|
|
57
|
+
type MCPClientConfig = MCPClientConfigHTTP | MCPClientConfigSSE;
|
|
58
|
+
/**
|
|
59
|
+
* Resolves a model specifier to a LanguageModel instance
|
|
60
|
+
* @param spec - Model string (e.g., "openai/gpt-4o") or LanguageModel instance
|
|
61
|
+
* @returns LanguageModel instance
|
|
62
|
+
*/
|
|
63
|
+
declare function resolveModel(spec: ModelSpecifier): LanguageModel;
|
|
64
|
+
/**
|
|
65
|
+
* Tool definition for BuiltInAgent
|
|
66
|
+
*/
|
|
67
|
+
interface ToolDefinition<TParameters extends z.ZodTypeAny = z.ZodTypeAny> {
|
|
68
|
+
name: string;
|
|
69
|
+
description: string;
|
|
70
|
+
parameters: TParameters;
|
|
71
|
+
execute: (args: z.infer<TParameters>) => Promise<unknown>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Define a tool for use with BuiltInAgent
|
|
75
|
+
* @param name - The name of the tool
|
|
76
|
+
* @param description - Description of what the tool does
|
|
77
|
+
* @param parameters - Zod schema for the tool's input parameters
|
|
78
|
+
* @param execute - Function to execute the tool server-side
|
|
79
|
+
* @returns Tool definition
|
|
80
|
+
*/
|
|
81
|
+
declare function defineTool<TParameters extends z.ZodTypeAny>(config: {
|
|
82
|
+
name: string;
|
|
83
|
+
description: string;
|
|
84
|
+
parameters: TParameters;
|
|
85
|
+
execute: (args: z.infer<TParameters>) => Promise<unknown>;
|
|
86
|
+
}): ToolDefinition<TParameters>;
|
|
87
|
+
/**
|
|
88
|
+
* Converts AG-UI messages to Vercel AI SDK ModelMessage format
|
|
89
|
+
*/
|
|
90
|
+
declare function convertMessagesToVercelAISDKMessages(messages: Message[]): ModelMessage[];
|
|
91
|
+
/**
|
|
92
|
+
* JSON Schema type definition
|
|
93
|
+
*/
|
|
94
|
+
interface JsonSchema {
|
|
95
|
+
type: "object" | "string" | "number" | "boolean" | "array";
|
|
96
|
+
description?: string;
|
|
97
|
+
properties?: Record<string, JsonSchema>;
|
|
98
|
+
required?: string[];
|
|
99
|
+
items?: JsonSchema;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Converts JSON Schema to Zod schema
|
|
103
|
+
*/
|
|
104
|
+
declare function convertJsonSchemaToZodSchema(jsonSchema: JsonSchema, required: boolean): z.ZodSchema;
|
|
105
|
+
declare function convertToolsToVercelAITools(tools: RunAgentInput["tools"]): ToolSet;
|
|
106
|
+
/**
|
|
107
|
+
* Converts ToolDefinition array to Vercel AI SDK ToolSet
|
|
108
|
+
*/
|
|
109
|
+
declare function convertToolDefinitionsToVercelAITools(tools: ToolDefinition[]): ToolSet;
|
|
110
|
+
/**
|
|
111
|
+
* Configuration for BuiltInAgent
|
|
112
|
+
*/
|
|
113
|
+
interface BuiltInAgentConfiguration {
|
|
114
|
+
/**
|
|
115
|
+
* The model to use
|
|
116
|
+
*/
|
|
117
|
+
model: BuiltInAgentModel | LanguageModel;
|
|
118
|
+
/**
|
|
119
|
+
* Maximum number of steps/iterations for tool calling (default: 1)
|
|
120
|
+
*/
|
|
121
|
+
maxSteps?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Tool choice setting - how tools are selected for execution (default: "auto")
|
|
124
|
+
*/
|
|
125
|
+
toolChoice?: ToolChoice<Record<string, unknown>>;
|
|
126
|
+
/**
|
|
127
|
+
* Maximum number of tokens to generate
|
|
128
|
+
*/
|
|
129
|
+
maxOutputTokens?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Temperature setting (range depends on provider)
|
|
132
|
+
*/
|
|
133
|
+
temperature?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Nucleus sampling (topP)
|
|
136
|
+
*/
|
|
137
|
+
topP?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Top K sampling
|
|
140
|
+
*/
|
|
141
|
+
topK?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Presence penalty
|
|
144
|
+
*/
|
|
145
|
+
presencePenalty?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Frequency penalty
|
|
148
|
+
*/
|
|
149
|
+
frequencyPenalty?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Sequences that will stop the generation
|
|
152
|
+
*/
|
|
153
|
+
stopSequences?: string[];
|
|
154
|
+
/**
|
|
155
|
+
* Seed for deterministic results
|
|
156
|
+
*/
|
|
157
|
+
seed?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum number of retries
|
|
160
|
+
*/
|
|
161
|
+
maxRetries?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Prompt for the agent
|
|
164
|
+
*/
|
|
165
|
+
prompt?: string;
|
|
166
|
+
/**
|
|
167
|
+
* List of properties that can be overridden by forwardedProps.
|
|
168
|
+
*/
|
|
169
|
+
overridableProperties?: OverridableProperty[];
|
|
170
|
+
/**
|
|
171
|
+
* Optional list of MCP server configurations
|
|
172
|
+
*/
|
|
173
|
+
mcpServers?: MCPClientConfig[];
|
|
174
|
+
/**
|
|
175
|
+
* Optional tools available to the agent
|
|
176
|
+
*/
|
|
177
|
+
tools?: ToolDefinition[];
|
|
178
|
+
}
|
|
179
|
+
declare class BuiltInAgent extends AbstractAgent {
|
|
180
|
+
private config;
|
|
181
|
+
private abortController?;
|
|
182
|
+
constructor(config: BuiltInAgentConfiguration);
|
|
183
|
+
/**
|
|
184
|
+
* Check if a property can be overridden by forwardedProps
|
|
185
|
+
*/
|
|
186
|
+
canOverride(property: OverridableProperty): boolean;
|
|
187
|
+
run(input: RunAgentInput): Observable<BaseEvent>;
|
|
188
|
+
clone(): BuiltInAgent;
|
|
189
|
+
abortRun(): void;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @deprecated Use BuiltInAgent instead
|
|
193
|
+
*/
|
|
194
|
+
declare class BasicAgent extends BuiltInAgent {
|
|
195
|
+
constructor(config: BuiltInAgentConfiguration);
|
|
196
|
+
}
|
|
197
|
+
type BasicAgentConfiguration = BuiltInAgentConfiguration;
|
|
198
|
+
|
|
199
|
+
export { BasicAgent, type BasicAgentConfiguration, BuiltInAgent, type BuiltInAgentConfiguration, type BuiltInAgentModel, type MCPClientConfig, type MCPClientConfigHTTP, type MCPClientConfigSSE, type ModelSpecifier, type OverridableProperty, type ToolDefinition, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel };
|