@inkeep/agents-sdk 0.39.5 → 0.40.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.
Files changed (59) hide show
  1. package/dist/_virtual/rolldown_runtime.js +7 -0
  2. package/dist/agent.d.ts +186 -0
  3. package/dist/agent.js +720 -0
  4. package/dist/agentFullClient.d.ts +22 -0
  5. package/dist/agentFullClient.js +120 -0
  6. package/dist/artifact-component.d.ts +34 -0
  7. package/dist/artifact-component.js +104 -0
  8. package/dist/builderFunctions.d.ts +283 -0
  9. package/dist/builderFunctions.js +327 -0
  10. package/dist/builderFunctionsExperimental.d.ts +24 -0
  11. package/dist/builderFunctionsExperimental.js +27 -0
  12. package/dist/builders.d.ts +111 -0
  13. package/dist/builders.js +52 -0
  14. package/dist/credential-provider.d.ts +176 -0
  15. package/dist/credential-provider.js +237 -0
  16. package/dist/credential-ref.d.ts +60 -0
  17. package/dist/credential-ref.js +33 -0
  18. package/dist/data-component.d.ts +39 -0
  19. package/dist/data-component.js +109 -0
  20. package/dist/environment-settings.d.ts +27 -0
  21. package/dist/environment-settings.js +41 -0
  22. package/dist/external-agent.d.ts +64 -0
  23. package/dist/external-agent.js +156 -0
  24. package/dist/function-tool.d.ts +37 -0
  25. package/dist/function-tool.js +66 -0
  26. package/dist/index.d.ts +19 -1825
  27. package/dist/index.js +19 -4058
  28. package/dist/module-hosted-tool-manager.d.ts +40 -0
  29. package/dist/module-hosted-tool-manager.js +359 -0
  30. package/dist/project.d.ts +214 -0
  31. package/dist/project.js +615 -0
  32. package/dist/projectFullClient.d.ts +23 -0
  33. package/dist/projectFullClient.js +162 -0
  34. package/dist/runner.d.ts +41 -0
  35. package/dist/runner.js +145 -0
  36. package/dist/status-component.d.ts +22 -0
  37. package/dist/status-component.js +36 -0
  38. package/dist/subAgent.d.ts +52 -0
  39. package/dist/subAgent.js +616 -0
  40. package/dist/telemetry-provider.d.ts +218 -0
  41. package/dist/telemetry-provider.js +390 -0
  42. package/dist/tool.d.ts +53 -0
  43. package/dist/tool.js +130 -0
  44. package/dist/types.d.ts +296 -0
  45. package/dist/types.js +39 -0
  46. package/dist/utils/generateIdFromName.d.ts +9 -0
  47. package/dist/utils/generateIdFromName.js +12 -0
  48. package/dist/utils/getFunctionToolDeps.d.ts +17 -0
  49. package/dist/utils/getFunctionToolDeps.js +131 -0
  50. package/dist/utils/tool-normalization.d.ts +42 -0
  51. package/dist/utils/tool-normalization.js +41 -0
  52. package/dist/utils/validateFunction.d.ts +10 -0
  53. package/dist/utils/validateFunction.js +13 -0
  54. package/package.json +11 -16
  55. package/dist/index.cjs +0 -4147
  56. package/dist/index.d.cts +0 -1825
  57. package/dist/index.d.cts.map +0 -1
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js.map +0 -1
@@ -0,0 +1,327 @@
1
+ import { generateIdFromName } from "./utils/generateIdFromName.js";
2
+ import { FunctionTool } from "./function-tool.js";
3
+ import { Agent } from "./agent.js";
4
+ import { ArtifactComponent } from "./artifact-component.js";
5
+ import { DataComponent } from "./data-component.js";
6
+ import { Project } from "./project.js";
7
+ import { StatusComponent as StatusComponent$1 } from "./status-component.js";
8
+ import { Tool } from "./tool.js";
9
+ import { SubAgent } from "./subAgent.js";
10
+ import { CredentialReferenceApiInsertSchema, MCPToolConfigSchema } from "@inkeep/agents-core";
11
+
12
+ //#region src/builderFunctions.ts
13
+ /**
14
+ * Helper function to create agent - OpenAI style
15
+ */
16
+ function agent(config) {
17
+ return new Agent(config);
18
+ }
19
+ /**
20
+ * Helper function to create projects - OpenAI style
21
+ *
22
+ * Projects are the top-level organizational unit that contains Agents, Sub Agents, and shared configurations.
23
+ * They provide model inheritance and execution limits that cascade down to Agents and Sub Agents.
24
+ *
25
+ * @param config - Project configuration
26
+ * @returns A new Project instance
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const customerSupport = project({
31
+ * id: 'customer-support-project',
32
+ * name: 'Customer Support System',
33
+ * description: 'Multi-agent customer support system',
34
+ * models: {
35
+ * base: { model: 'gpt-4.1-mini' },
36
+ * structuredOutput: { model: 'gpt-4.1' }
37
+ * },
38
+ * stopWhen: {
39
+ * transferCountIs: 10,
40
+ * stepCountIs: 50
41
+ * },
42
+ * agent: () => [
43
+ * agent({
44
+ * id: 'support-agent',
45
+ * name: 'Support Agent',
46
+ * // ... agent config
47
+ * })
48
+ * ]
49
+ * });
50
+ * ```
51
+ */
52
+ function project(config) {
53
+ return new Project(config);
54
+ }
55
+ /**
56
+ * Creates a new agent with stable ID enforcement.
57
+ *
58
+ * Agents require explicit stable IDs to ensure consistency across deployments.
59
+ * This is different from tools which auto-generate IDs from their names.
60
+ *
61
+ * @param config - Agent configuration including required stable ID
62
+ * @returns A new SubAgent instance
63
+ * @throws {Error} If config.id is not provided
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const myAgent = agent({
68
+ * id: 'customer-support-agent',
69
+ * name: 'Customer Support',
70
+ * prompt: 'Help customers with their questions'
71
+ * });
72
+ * ```
73
+ */
74
+ function subAgent(config) {
75
+ if (!config.id) throw new Error("Sub-Agent ID is required. Sub-Agents must have stable IDs for consistency across deployments.");
76
+ return new SubAgent(config);
77
+ }
78
+ /**
79
+ * Creates a credential reference for authentication.
80
+ *
81
+ * Credentials are used to authenticate with external services.
82
+ * They should be stored securely and referenced by ID.
83
+ *
84
+ * @param config - Credential configuration
85
+ * @returns A validated credential reference
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const apiCredential = credential({
90
+ * id: 'github-token',
91
+ * name: 'GitHub Token',
92
+ * type: 'bearer',
93
+ * value: process.env.GITHUB_TOKEN
94
+ * });
95
+ * ```
96
+ */
97
+ function credential(config) {
98
+ try {
99
+ return CredentialReferenceApiInsertSchema.parse(config);
100
+ } catch (error) {
101
+ if (error instanceof Error) {
102
+ const credId = config.id || "unknown";
103
+ throw new Error(`Invalid credential '${credId}': ${error.message}`);
104
+ }
105
+ throw error;
106
+ }
107
+ }
108
+ /**
109
+ * Creates an MCP (Model Context Protocol) server for tool functionality.
110
+ *
111
+ * MCP servers provide tool functionality through a standardized protocol.
112
+ * They can be remote services accessed via HTTP/WebSocket.
113
+ *
114
+ * @param config - MCP server configuration
115
+ * @returns A Tool instance configured as an MCP server
116
+ * @throws {Error} If serverUrl is not provided
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Remote MCP server
121
+ * const apiServer = mcpServer({
122
+ * name: 'external_api',
123
+ * description: 'External API service',
124
+ * serverUrl: 'https://api.example.com/mcp'
125
+ * });
126
+ *
127
+ * // With authentication
128
+ * const secureServer = mcpServer({
129
+ * name: 'secure_api',
130
+ * description: 'Secure API service',
131
+ * serverUrl: 'https://secure.example.com/mcp',
132
+ * credential: credential({
133
+ * id: 'api-key',
134
+ * name: 'API Key',
135
+ * type: 'bearer',
136
+ * value: process.env.API_KEY
137
+ * })
138
+ * });
139
+ * ```
140
+ */
141
+ function mcpServer(config) {
142
+ if (!config.serverUrl) throw new Error("MCP server requires a serverUrl");
143
+ return new Tool({
144
+ id: config.id || generateIdFromName(config.name),
145
+ name: config.name,
146
+ description: config.description,
147
+ serverUrl: config.serverUrl,
148
+ credential: config.credential,
149
+ activeTools: config.activeTools,
150
+ headers: config.headers,
151
+ imageUrl: config.imageUrl,
152
+ transport: config.transport ? { type: config.transport } : void 0
153
+ });
154
+ }
155
+ /**
156
+ * Creates an MCP tool from a raw configuration object.
157
+ *
158
+ * This is a low-level builder for advanced use cases where you need
159
+ * full control over the MCPToolConfig. For most cases, use `mcpServer()`.
160
+ *
161
+ * @param config - Complete MCP tool configuration
162
+ * @returns A Tool instance
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const customTool = mcpTool({
167
+ * id: 'custom-tool',
168
+ * name: 'Custom Tool',
169
+ * serverUrl: 'https://example.com/mcp',
170
+ * transport: { type: 'stdio' }
171
+ * });
172
+ * ```
173
+ */
174
+ function mcpTool(config) {
175
+ const configWithId = {
176
+ ...config,
177
+ id: config.id || generateIdFromName(config.name)
178
+ };
179
+ return new Tool(MCPToolConfigSchema.parse(configWithId));
180
+ }
181
+ /**
182
+ * Creates an artifact component with automatic ID generation.
183
+ *
184
+ * Artifact components represent structured UI components that can
185
+ * be rendered with different levels of detail (summary vs full).
186
+ *
187
+ * @param config - Artifact component configuration
188
+ * @returns An ArtifactComponent instance
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const productCard = artifactComponent({
193
+ * name: 'Product Card',
194
+ * description: 'Display product information',
195
+ * props: {
196
+ * type: 'object',
197
+ * properties: {
198
+ * title: { type: 'string', inPreview: true },
199
+ * price: { type: 'string', inPreview: true },
200
+ * description: { type: 'string' },
201
+ * image: { type: 'string' }
202
+ * }
203
+ * }
204
+ * });
205
+ * ```
206
+ */
207
+ function artifactComponent(config) {
208
+ return new ArtifactComponent({
209
+ ...config,
210
+ id: config.id || generateIdFromName(config.name)
211
+ });
212
+ }
213
+ /**
214
+ * Creates a data component with automatic ID generation.
215
+ *
216
+ * Data components represent structured data that can be
217
+ * passed between agents or used in processing.
218
+ *
219
+ * @param config - Data component configuration
220
+ * @returns A DataComponent instance
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const userProfile = dataComponent({
225
+ * name: 'User Profile',
226
+ * description: 'User profile data',
227
+ * props: {
228
+ * userId: '123',
229
+ * name: 'John Doe',
230
+ * email: 'john@example.com'
231
+ * }
232
+ * });
233
+ * ```
234
+ */
235
+ function dataComponent(config) {
236
+ return new DataComponent({
237
+ ...config,
238
+ id: config.id || generateIdFromName(config.name)
239
+ });
240
+ }
241
+ /**
242
+ * Creates a status component for structured status updates.
243
+ *
244
+ * Status components define the structure of status updates
245
+ * that agents can generate during long-running operations.
246
+ *
247
+ * @param config - Status component configuration
248
+ * @returns A StatusComponent instance
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * import { z } from 'zod';
253
+ *
254
+ * const toolCallStatus = statusComponent({
255
+ * type: 'tool_call_summary',
256
+ * description: 'Summary of a tool execution',
257
+ * detailsSchema: z.object({
258
+ * tool_name: z.string(),
259
+ * summary: z.string(),
260
+ * status: z.enum(['success', 'error', 'in_progress'])
261
+ * })
262
+ * });
263
+ * ```
264
+ */
265
+ function statusComponent(config) {
266
+ return new StatusComponent$1(config);
267
+ }
268
+ /**
269
+ * (deprecated in favor of mcpTool.with()) Creates an agent MCP configuration.
270
+ *
271
+ * Agent MCP configurations are used to configure the MCP server for an agent.
272
+ *
273
+ * @param config - Agent MCP configuration
274
+ * @returns An AgentMcpConfig instance
275
+ */
276
+ function agentMcp(config) {
277
+ return {
278
+ server: config.server,
279
+ selectedTools: config.selectedTools,
280
+ headers: config.headers
281
+ };
282
+ }
283
+ /**
284
+ * Creates a function tool that executes user-defined code in a sandboxed environment.
285
+ *
286
+ * Function tools allow users to define custom logic that runs securely in isolated
287
+ * environments. Dependencies are installed automatically in the sandbox.
288
+ *
289
+ * @param config - Function tool configuration
290
+ * @returns A FunctionTool instance
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const calculatorTool = functionTool({
295
+ * name: 'calculator',
296
+ * description: 'Performs basic math operations',
297
+ * inputSchema: {
298
+ * type: 'object',
299
+ * properties: {
300
+ * operation: { type: 'string', enum: ['add', 'subtract', 'multiply', 'divide'] },
301
+ * a: { type: 'number' },
302
+ * b: { type: 'number' }
303
+ * },
304
+ * required: ['operation', 'a', 'b']
305
+ * },
306
+ * dependencies: {
307
+ * 'lodash': '^4.17.21'
308
+ * },
309
+ * execute: async (params) => {
310
+ * const { operation, a, b } = params;
311
+ * switch (operation) {
312
+ * case 'add': return { result: a + b };
313
+ * case 'subtract': return { result: a - b };
314
+ * case 'multiply': return { result: a * b };
315
+ * case 'divide': return { result: a / b };
316
+ * default: throw new Error(`Unknown operation: ${operation}`);
317
+ * }
318
+ * }
319
+ * });
320
+ * ```
321
+ */
322
+ function functionTool(config) {
323
+ return new FunctionTool(config);
324
+ }
325
+
326
+ //#endregion
327
+ export { agent, agentMcp, artifactComponent, credential, dataComponent, functionTool, mcpServer, mcpTool, project, statusComponent, subAgent };
@@ -0,0 +1,24 @@
1
+ //#region src/builderFunctionsExperimental.d.ts
2
+ /**
3
+ * Creates an agent relation configuration.
4
+ *
5
+ * Relations define how agents can interact with each other.
6
+ * Transfer relations allow transfers, while delegate relations
7
+ * allow temporary task delegation.
8
+ *
9
+ * @param targetAgent - The ID of the target agent
10
+ * @param relationType - The type of relation (transfer or delegate)
11
+ * @returns An agent relation configuration
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const transferRelation = agentRelation('support-agent', 'transfer');
16
+ * const delegateRelation = agentRelation('specialist-agent', 'delegate');
17
+ * ```
18
+ */
19
+ declare function agentRelation(targetAgent: string, relationType?: 'transfer' | 'delegate'): {
20
+ targetAgent: string;
21
+ relationType: "transfer" | "delegate";
22
+ };
23
+ //#endregion
24
+ export { agentRelation };
@@ -0,0 +1,27 @@
1
+ //#region src/builderFunctionsExperimental.ts
2
+ /**
3
+ * Creates an agent relation configuration.
4
+ *
5
+ * Relations define how agents can interact with each other.
6
+ * Transfer relations allow transfers, while delegate relations
7
+ * allow temporary task delegation.
8
+ *
9
+ * @param targetAgent - The ID of the target agent
10
+ * @param relationType - The type of relation (transfer or delegate)
11
+ * @returns An agent relation configuration
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const transferRelation = agentRelation('support-agent', 'transfer');
16
+ * const delegateRelation = agentRelation('specialist-agent', 'delegate');
17
+ * ```
18
+ */
19
+ function agentRelation(targetAgent, relationType = "transfer") {
20
+ return {
21
+ targetAgent,
22
+ relationType
23
+ };
24
+ }
25
+
26
+ //#endregion
27
+ export { agentRelation };
@@ -0,0 +1,111 @@
1
+ import { Tool } from "./tool.js";
2
+ import { SubAgent } from "./subAgent.js";
3
+ import { TransferConfig } from "./types.js";
4
+ import { CredentialReferenceApiInsert, McpToolSelection, ToolPolicy } from "@inkeep/agents-core";
5
+ import { z } from "zod";
6
+
7
+ //#region src/builders.d.ts
8
+
9
+ /**
10
+ * Function signature for tool execution
11
+ * @template TParams - Type of input parameters
12
+ * @template TResult - Type of return value
13
+ */
14
+ type ToolExecuteFunction<TParams = unknown, TResult = unknown> = (params: TParams) => Promise<TResult>;
15
+ /**
16
+ * Function signature for transfer conditions
17
+ */
18
+ type TransferConditionFunction = (context: unknown) => boolean;
19
+ /**
20
+ * Configuration for MCP server builders
21
+ */
22
+ interface MCPServerConfig {
23
+ name: string;
24
+ description: string;
25
+ serverUrl: string;
26
+ id?: string;
27
+ parameters?: Record<string, z.ZodJSONSchema>;
28
+ credential?: CredentialReferenceApiInsert;
29
+ transport?: 'streamable_http' | 'sse';
30
+ activeTools?: string[];
31
+ headers?: Record<string, string>;
32
+ imageUrl?: string;
33
+ }
34
+ /**
35
+ * Configuration for component builders
36
+ */
37
+ interface ComponentConfig {
38
+ id?: string;
39
+ name: string;
40
+ description: string;
41
+ }
42
+ interface ArtifactComponentConfig extends ComponentConfig {
43
+ props: Record<string, unknown> | z.ZodObject<any>;
44
+ }
45
+ interface DataComponentConfig extends ComponentConfig {
46
+ props: Record<string, unknown> | z.ZodObject<any>;
47
+ render?: {
48
+ component: string;
49
+ mockData: Record<string, unknown>;
50
+ };
51
+ }
52
+ interface StatusComponentConfig {
53
+ type: string;
54
+ description?: string;
55
+ detailsSchema?: Record<string, unknown> | z.ZodObject<any>;
56
+ }
57
+ /**
58
+ * Schema for transfer configuration (excluding function properties)
59
+ */
60
+ declare const TransferConfigSchema: z.ZodObject<{
61
+ agent: z.ZodCustom<SubAgent, SubAgent>;
62
+ description: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strip>;
64
+ type AgentMcpConfig = {
65
+ server: Tool;
66
+ selectedTools?: string[];
67
+ headers?: Record<string, string>;
68
+ toolPolicies?: Record<string, ToolPolicy>;
69
+ };
70
+ /**
71
+ * Input configuration for MCP tool customization
72
+ * Supports flexible tool selection with per-tool policies
73
+ */
74
+ type AgentMcpConfigInput = {
75
+ /**
76
+ * Tools to enable from the MCP server - can be strings or objects with policies
77
+ * - undefined or null: all tools enabled (no filtering)
78
+ * - []: zero tools enabled (explicit empty selection)
79
+ * - ['tool1', 'tool2']: specific tools enabled
80
+ */
81
+ selectedTools?: McpToolSelection[] | null;
82
+ /** Custom headers for MCP server requests */
83
+ headers?: Record<string, string>;
84
+ };
85
+ /**
86
+ * Creates a transfer configuration for agent transfers.
87
+ *
88
+ * Transfers allow one agent to hand off control to another agent
89
+ * based on optional conditions.
90
+ *
91
+ * @param targetAgent - The agent to transfer to
92
+ * @param description - Optional description of when/why to transfer
93
+ * @param condition - Optional function to determine if transfer should occur
94
+ * @returns A validated transfer configuration
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Simple transfer
99
+ * const transfer = transfer(supportAgent, 'Transfer to support');
100
+ *
101
+ * // Conditional transfer
102
+ * const conditionalHandoff = transfer(
103
+ * specialistAgent,
104
+ * 'Transfer to specialist for complex issues',
105
+ * (context) => context.complexity > 0.8
106
+ * );
107
+ * ```
108
+ */
109
+ declare function transfer(targetAgent: SubAgent, description?: string, condition?: TransferConditionFunction): TransferConfig;
110
+ //#endregion
111
+ export { AgentMcpConfig, AgentMcpConfigInput, ArtifactComponentConfig, ComponentConfig, DataComponentConfig, MCPServerConfig, StatusComponentConfig, ToolExecuteFunction, TransferConditionFunction, TransferConfigSchema, transfer };
@@ -0,0 +1,52 @@
1
+ import { SubAgent } from "./subAgent.js";
2
+ import { validateFunction } from "./utils/validateFunction.js";
3
+ import { z } from "zod";
4
+
5
+ //#region src/builders.ts
6
+ /**
7
+ * Schema for transfer configuration (excluding function properties)
8
+ */
9
+ const TransferConfigSchema = z.object({
10
+ agent: z.instanceof(SubAgent),
11
+ description: z.string().optional()
12
+ });
13
+ /**
14
+ * Creates a transfer configuration for agent transfers.
15
+ *
16
+ * Transfers allow one agent to hand off control to another agent
17
+ * based on optional conditions.
18
+ *
19
+ * @param targetAgent - The agent to transfer to
20
+ * @param description - Optional description of when/why to transfer
21
+ * @param condition - Optional function to determine if transfer should occur
22
+ * @returns A validated transfer configuration
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Simple transfer
27
+ * const transfer = transfer(supportAgent, 'Transfer to support');
28
+ *
29
+ * // Conditional transfer
30
+ * const conditionalHandoff = transfer(
31
+ * specialistAgent,
32
+ * 'Transfer to specialist for complex issues',
33
+ * (context) => context.complexity > 0.8
34
+ * );
35
+ * ```
36
+ */
37
+ function transfer(targetAgent, description, condition) {
38
+ if (condition !== void 0) validateFunction(condition, "condition");
39
+ const config = {
40
+ agent: targetAgent,
41
+ description: description || `Hand off to ${targetAgent.getName()}`,
42
+ condition
43
+ };
44
+ TransferConfigSchema.parse({
45
+ agent: config.agent,
46
+ description: config.description
47
+ });
48
+ return config;
49
+ }
50
+
51
+ //#endregion
52
+ export { TransferConfigSchema, transfer };