@composio/anthropic 0.3.4 → 0.5.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/dist/index.cjs +251 -264
- package/dist/index.d.cts +5195 -235
- package/dist/index.d.mts +5229 -0
- package/dist/index.mjs +253 -0
- package/package.json +19 -11
- package/dist/index.d.ts +0 -269
- package/dist/index.js +0 -244
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { BaseNonAgenticProvider, logger } from "@composio/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Anthropic Provider
|
|
6
|
+
*
|
|
7
|
+
* This provider provides a set of tools for interacting with Anthropic's API.
|
|
8
|
+
* It implements the non-agentic provider interface for Anthropic's Claude models.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
* @module providers/anthropic
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Anthropic Provider implementation for Composio
|
|
15
|
+
*/
|
|
16
|
+
var AnthropicProvider = class extends BaseNonAgenticProvider {
|
|
17
|
+
name = "anthropic";
|
|
18
|
+
chacheTools = false;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new instance of the AnthropicProvider.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} [options] - Configuration options for the provider
|
|
23
|
+
* @param {boolean} [options.cacheTools=false] - Whether to cache tools using Anthropic's ephemeral cache
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Initialize with default settings (no caching)
|
|
28
|
+
* const provider = new AnthropicProvider();
|
|
29
|
+
*
|
|
30
|
+
* // Initialize with tool caching enabled
|
|
31
|
+
* const providerWithCaching = new AnthropicProvider({
|
|
32
|
+
* cacheTools: true
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Use with Composio
|
|
36
|
+
* const composio = new Composio({
|
|
37
|
+
* apiKey: 'your-api-key',
|
|
38
|
+
* provider: new AnthropicProvider({
|
|
39
|
+
* cacheTools: true
|
|
40
|
+
* })
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
constructor(options) {
|
|
45
|
+
super();
|
|
46
|
+
this.chacheTools = options?.cacheTools ?? false;
|
|
47
|
+
logger.debug(`AnthropicProvider initialized [cacheTools: ${this.chacheTools}]`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Wraps a Composio tool in the Anthropic format.
|
|
51
|
+
*
|
|
52
|
+
* This method transforms a Composio tool definition into the format
|
|
53
|
+
* expected by Anthropic's Claude API for tool use.
|
|
54
|
+
*
|
|
55
|
+
* @param tool - The Composio tool to wrap
|
|
56
|
+
* @returns The wrapped tool in Anthropic format
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Wrap a single tool for use with Anthropic
|
|
61
|
+
* const composioTool = {
|
|
62
|
+
* slug: 'SEARCH_TOOL',
|
|
63
|
+
* description: 'Search for information',
|
|
64
|
+
* inputParameters: {
|
|
65
|
+
* type: 'object',
|
|
66
|
+
* properties: {
|
|
67
|
+
* query: { type: 'string' }
|
|
68
|
+
* },
|
|
69
|
+
* required: ['query']
|
|
70
|
+
* }
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* const anthropicTool = provider.wrapTool(composioTool);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
wrapTool(tool) {
|
|
77
|
+
return {
|
|
78
|
+
name: tool.slug,
|
|
79
|
+
description: tool.description || "",
|
|
80
|
+
input_schema: tool.inputParameters || {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {},
|
|
83
|
+
required: []
|
|
84
|
+
},
|
|
85
|
+
cache_control: this.chacheTools ? { type: "ephemeral" } : void 0
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Wraps a list of Composio tools in the Anthropic format.
|
|
90
|
+
*
|
|
91
|
+
* This method transforms multiple Composio tool definitions into the format
|
|
92
|
+
* expected by Anthropic's Claude API for tool use.
|
|
93
|
+
*
|
|
94
|
+
* @param tools - Array of Composio tools to wrap
|
|
95
|
+
* @returns Array of wrapped tools in Anthropic format
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Wrap multiple tools for use with Anthropic
|
|
100
|
+
* const composioTools = [
|
|
101
|
+
* {
|
|
102
|
+
* slug: 'SEARCH_TOOL',
|
|
103
|
+
* description: 'Search for information',
|
|
104
|
+
* inputParameters: {
|
|
105
|
+
* type: 'object',
|
|
106
|
+
* properties: {
|
|
107
|
+
* query: { type: 'string' }
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* },
|
|
111
|
+
* {
|
|
112
|
+
* slug: 'WEATHER_TOOL',
|
|
113
|
+
* description: 'Get weather information',
|
|
114
|
+
* inputParameters: {
|
|
115
|
+
* type: 'object',
|
|
116
|
+
* properties: {
|
|
117
|
+
* location: { type: 'string' }
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* ];
|
|
122
|
+
*
|
|
123
|
+
* const anthropicTools = provider.wrapTools(composioTools);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
wrapTools(tools) {
|
|
127
|
+
return tools.map((tool) => this.wrapTool(tool));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Executes a tool call from Anthropic's Claude API.
|
|
131
|
+
*
|
|
132
|
+
* This method processes a tool call from Anthropic's Claude API,
|
|
133
|
+
* executes the corresponding Composio tool, and returns the result.
|
|
134
|
+
*
|
|
135
|
+
* @param userId - The user ID for authentication and tracking
|
|
136
|
+
* @param toolUse - The tool use object from Anthropic
|
|
137
|
+
* @param options - Additional options for tool execution
|
|
138
|
+
* @param modifiers - Modifiers for tool execution
|
|
139
|
+
* @returns The result of the tool execution as a JSON string
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Execute a tool call from Anthropic
|
|
144
|
+
* const toolUse = {
|
|
145
|
+
* type: 'tool_use',
|
|
146
|
+
* id: 'tu_abc123',
|
|
147
|
+
* name: 'SEARCH_TOOL',
|
|
148
|
+
* input: {
|
|
149
|
+
* query: 'composio documentation'
|
|
150
|
+
* }
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* const result = await provider.executeToolCall(
|
|
154
|
+
* 'user123',
|
|
155
|
+
* toolUse,
|
|
156
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
157
|
+
* );
|
|
158
|
+
* console.log(JSON.parse(result));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
async executeToolCall(userId, toolUse, options, modifiers) {
|
|
162
|
+
const payload = {
|
|
163
|
+
arguments: toolUse.input,
|
|
164
|
+
connectedAccountId: options?.connectedAccountId,
|
|
165
|
+
customAuthParams: options?.customAuthParams,
|
|
166
|
+
customConnectionData: options?.customConnectionData,
|
|
167
|
+
userId
|
|
168
|
+
};
|
|
169
|
+
const result = await this.executeTool(toolUse.name, payload, modifiers);
|
|
170
|
+
return JSON.stringify(result.data);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Handles tool calls from Anthropic's message response.
|
|
174
|
+
*
|
|
175
|
+
* This method processes tool calls from an Anthropic message response,
|
|
176
|
+
* extracts the tool use blocks, executes each tool call, and returns the results.
|
|
177
|
+
*
|
|
178
|
+
* @param userId - The user ID for authentication and tracking
|
|
179
|
+
* @param message - The message response from Anthropic
|
|
180
|
+
* @param options - Additional options for tool execution
|
|
181
|
+
* @param modifiers - Modifiers for tool execution
|
|
182
|
+
* @returns Array of tool execution results as JSON strings
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // Handle tool calls from an Anthropic message response
|
|
187
|
+
* const anthropic = new Anthropic({ apiKey: 'your-anthropic-api-key' });
|
|
188
|
+
*
|
|
189
|
+
* const message = await anthropic.messages.create({
|
|
190
|
+
* model: 'claude-3-opus-20240229',
|
|
191
|
+
* max_tokens: 1024,
|
|
192
|
+
* tools: provider.wrapTools(composioTools),
|
|
193
|
+
* messages: [
|
|
194
|
+
* {
|
|
195
|
+
* role: 'user',
|
|
196
|
+
* content: 'Search for information about Composio'
|
|
197
|
+
* }
|
|
198
|
+
* ]
|
|
199
|
+
* });
|
|
200
|
+
*
|
|
201
|
+
* // Process any tool calls in the response
|
|
202
|
+
* const results = await provider.handleToolCalls(
|
|
203
|
+
* 'user123',
|
|
204
|
+
* message,
|
|
205
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* // Use the results to continue the conversation
|
|
209
|
+
* console.log(results);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async handleToolCalls(userId, message, options, modifiers) {
|
|
213
|
+
const outputs = [];
|
|
214
|
+
const toolUseBlocks = [];
|
|
215
|
+
for (const content of message.content) if (typeof content === "object" && content !== null && "type" in content && typeof content.type === "string" && content.type.toString() === "tool_use" && "id" in content && "name" in content && "input" in content) toolUseBlocks.push({
|
|
216
|
+
type: "tool_use",
|
|
217
|
+
id: String(content.id),
|
|
218
|
+
name: String(content.name),
|
|
219
|
+
input: content.input
|
|
220
|
+
});
|
|
221
|
+
for (const toolUse of toolUseBlocks) {
|
|
222
|
+
const toolResult = await this.executeToolCall(userId, toolUse, options, modifiers);
|
|
223
|
+
outputs.push({
|
|
224
|
+
type: "tool_result",
|
|
225
|
+
tool_use_id: toolUse.id,
|
|
226
|
+
content: toolResult,
|
|
227
|
+
cache_control: this.chacheTools ? { type: "ephemeral" } : void 0
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return outputs.length > 0 ? [{
|
|
231
|
+
role: "user",
|
|
232
|
+
content: outputs
|
|
233
|
+
}] : [];
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Transform MCP URL response into Anthropic-specific format.
|
|
237
|
+
* By default, Anthropic uses the standard format (same as default),
|
|
238
|
+
* but this method is here to show providers can customize if needed.
|
|
239
|
+
*
|
|
240
|
+
* @param data - The MCP URL response data
|
|
241
|
+
* @returns Standard MCP server response format
|
|
242
|
+
*/
|
|
243
|
+
wrapMcpServerResponse(data) {
|
|
244
|
+
return data.map((item) => ({
|
|
245
|
+
url: item.url,
|
|
246
|
+
name: item.name,
|
|
247
|
+
type: "url"
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
export { AnthropicProvider };
|
package/package.json
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Non-Agentic Provider for Anthropic in Composio SDK",
|
|
5
|
-
"main": "dist/index.
|
|
6
|
-
"type": "module",
|
|
5
|
+
"main": "dist/index.mjs",
|
|
7
6
|
"publishConfig": {
|
|
8
7
|
"access": "public"
|
|
9
8
|
},
|
|
10
9
|
"exports": {
|
|
11
10
|
".": {
|
|
12
|
-
"import":
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"default": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
24
|
},
|
|
17
25
|
"files": [
|
|
@@ -27,19 +35,19 @@
|
|
|
27
35
|
"license": "ISC",
|
|
28
36
|
"peerDependencies": {
|
|
29
37
|
"@anthropic-ai/sdk": "^0.52.0",
|
|
30
|
-
"@composio/core": "0.
|
|
38
|
+
"@composio/core": "0.5.0",
|
|
31
39
|
"@mastra/mcp": "^0.12.0"
|
|
32
40
|
},
|
|
33
41
|
"devDependencies": {
|
|
34
|
-
"
|
|
42
|
+
"tsdown": "^0.18.4",
|
|
35
43
|
"typescript": "^5.9.2",
|
|
36
44
|
"vitest": "^3.2.4",
|
|
37
|
-
"@composio/core": "0.
|
|
45
|
+
"@composio/core": "0.5.0"
|
|
38
46
|
},
|
|
39
47
|
"scripts": {
|
|
40
48
|
"clean": "git clean -xdf node_modules",
|
|
41
|
-
"build": "
|
|
49
|
+
"build": "tsdown",
|
|
42
50
|
"test": "vitest run"
|
|
43
51
|
},
|
|
44
|
-
"types": "dist/index.d.
|
|
52
|
+
"types": "dist/index.d.mts"
|
|
45
53
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { BaseNonAgenticProvider, Tool, ExecuteToolFnOptions, ExecuteToolModifiers, McpUrlResponse } from '@composio/core';
|
|
2
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
3
|
-
|
|
4
|
-
interface AnthropicTool {
|
|
5
|
-
/**
|
|
6
|
-
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
|
7
|
-
*
|
|
8
|
-
* This defines the shape of the `input` that your tool accepts and that the model
|
|
9
|
-
* will produce.
|
|
10
|
-
*/
|
|
11
|
-
input_schema: InputSchema;
|
|
12
|
-
/**
|
|
13
|
-
* Name of the tool.
|
|
14
|
-
*
|
|
15
|
-
* This is how the tool will be called by the model and in `tool_use` blocks.
|
|
16
|
-
*/
|
|
17
|
-
name: string;
|
|
18
|
-
/**
|
|
19
|
-
* Create a cache control breakpoint at this content block.
|
|
20
|
-
*/
|
|
21
|
-
cache_control?: CacheControlEphemeral | null;
|
|
22
|
-
/**
|
|
23
|
-
* Description of what this tool does.
|
|
24
|
-
*
|
|
25
|
-
* Tool descriptions should be as detailed as possible. The more information that
|
|
26
|
-
* the model has about what the tool is and how to use it, the better it will
|
|
27
|
-
* perform. You can use natural language descriptions to reinforce important
|
|
28
|
-
* aspects of the tool input JSON schema.
|
|
29
|
-
*/
|
|
30
|
-
description?: string;
|
|
31
|
-
type?: 'custom' | null;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
|
35
|
-
*
|
|
36
|
-
* This defines the shape of the `input` that your tool accepts and that the model
|
|
37
|
-
* will produce.
|
|
38
|
-
*/
|
|
39
|
-
interface InputSchema {
|
|
40
|
-
type: 'object';
|
|
41
|
-
properties?: unknown | null;
|
|
42
|
-
[k: string]: unknown;
|
|
43
|
-
}
|
|
44
|
-
interface CacheControlEphemeral {
|
|
45
|
-
type: 'ephemeral';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Anthropic Provider
|
|
50
|
-
*
|
|
51
|
-
* This provider provides a set of tools for interacting with Anthropic's API.
|
|
52
|
-
* It implements the non-agentic provider interface for Anthropic's Claude models.
|
|
53
|
-
*
|
|
54
|
-
* @packageDocumentation
|
|
55
|
-
* @module providers/anthropic
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
type AnthropicMcpServerGetResponse = {
|
|
59
|
-
type: 'url';
|
|
60
|
-
url: string;
|
|
61
|
-
name: string;
|
|
62
|
-
}[];
|
|
63
|
-
/**
|
|
64
|
-
* Collection of Anthropic tools
|
|
65
|
-
*/
|
|
66
|
-
type AnthropicToolCollection = AnthropicTool[];
|
|
67
|
-
/**
|
|
68
|
-
* Type for Anthropic tool use block in message content
|
|
69
|
-
*/
|
|
70
|
-
interface AnthropicToolUseBlock {
|
|
71
|
-
type: 'tool_use';
|
|
72
|
-
id: string;
|
|
73
|
-
name: string;
|
|
74
|
-
input: Record<string, unknown>;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Type for Anthropic message content block
|
|
78
|
-
*/
|
|
79
|
-
type AnthropicContentBlock = {
|
|
80
|
-
type: string;
|
|
81
|
-
[key: string]: unknown;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Anthropic Provider implementation for Composio
|
|
85
|
-
*/
|
|
86
|
-
declare class AnthropicProvider extends BaseNonAgenticProvider<AnthropicToolCollection, AnthropicTool, AnthropicMcpServerGetResponse> {
|
|
87
|
-
readonly name = "anthropic";
|
|
88
|
-
private chacheTools;
|
|
89
|
-
/**
|
|
90
|
-
* Creates a new instance of the AnthropicProvider.
|
|
91
|
-
*
|
|
92
|
-
* @param {Object} [options] - Configuration options for the provider
|
|
93
|
-
* @param {boolean} [options.cacheTools=false] - Whether to cache tools using Anthropic's ephemeral cache
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* // Initialize with default settings (no caching)
|
|
98
|
-
* const provider = new AnthropicProvider();
|
|
99
|
-
*
|
|
100
|
-
* // Initialize with tool caching enabled
|
|
101
|
-
* const providerWithCaching = new AnthropicProvider({
|
|
102
|
-
* cacheTools: true
|
|
103
|
-
* });
|
|
104
|
-
*
|
|
105
|
-
* // Use with Composio
|
|
106
|
-
* const composio = new Composio({
|
|
107
|
-
* apiKey: 'your-api-key',
|
|
108
|
-
* provider: new AnthropicProvider({
|
|
109
|
-
* cacheTools: true
|
|
110
|
-
* })
|
|
111
|
-
* });
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
constructor(options?: {
|
|
115
|
-
cacheTools?: boolean;
|
|
116
|
-
});
|
|
117
|
-
/**
|
|
118
|
-
* Wraps a Composio tool in the Anthropic format.
|
|
119
|
-
*
|
|
120
|
-
* This method transforms a Composio tool definition into the format
|
|
121
|
-
* expected by Anthropic's Claude API for tool use.
|
|
122
|
-
*
|
|
123
|
-
* @param tool - The Composio tool to wrap
|
|
124
|
-
* @returns The wrapped tool in Anthropic format
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* // Wrap a single tool for use with Anthropic
|
|
129
|
-
* const composioTool = {
|
|
130
|
-
* slug: 'SEARCH_TOOL',
|
|
131
|
-
* description: 'Search for information',
|
|
132
|
-
* inputParameters: {
|
|
133
|
-
* type: 'object',
|
|
134
|
-
* properties: {
|
|
135
|
-
* query: { type: 'string' }
|
|
136
|
-
* },
|
|
137
|
-
* required: ['query']
|
|
138
|
-
* }
|
|
139
|
-
* };
|
|
140
|
-
*
|
|
141
|
-
* const anthropicTool = provider.wrapTool(composioTool);
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
wrapTool(tool: Tool): AnthropicTool;
|
|
145
|
-
/**
|
|
146
|
-
* Wraps a list of Composio tools in the Anthropic format.
|
|
147
|
-
*
|
|
148
|
-
* This method transforms multiple Composio tool definitions into the format
|
|
149
|
-
* expected by Anthropic's Claude API for tool use.
|
|
150
|
-
*
|
|
151
|
-
* @param tools - Array of Composio tools to wrap
|
|
152
|
-
* @returns Array of wrapped tools in Anthropic format
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* // Wrap multiple tools for use with Anthropic
|
|
157
|
-
* const composioTools = [
|
|
158
|
-
* {
|
|
159
|
-
* slug: 'SEARCH_TOOL',
|
|
160
|
-
* description: 'Search for information',
|
|
161
|
-
* inputParameters: {
|
|
162
|
-
* type: 'object',
|
|
163
|
-
* properties: {
|
|
164
|
-
* query: { type: 'string' }
|
|
165
|
-
* }
|
|
166
|
-
* }
|
|
167
|
-
* },
|
|
168
|
-
* {
|
|
169
|
-
* slug: 'WEATHER_TOOL',
|
|
170
|
-
* description: 'Get weather information',
|
|
171
|
-
* inputParameters: {
|
|
172
|
-
* type: 'object',
|
|
173
|
-
* properties: {
|
|
174
|
-
* location: { type: 'string' }
|
|
175
|
-
* }
|
|
176
|
-
* }
|
|
177
|
-
* }
|
|
178
|
-
* ];
|
|
179
|
-
*
|
|
180
|
-
* const anthropicTools = provider.wrapTools(composioTools);
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
wrapTools(tools: Tool[]): AnthropicToolCollection;
|
|
184
|
-
/**
|
|
185
|
-
* Executes a tool call from Anthropic's Claude API.
|
|
186
|
-
*
|
|
187
|
-
* This method processes a tool call from Anthropic's Claude API,
|
|
188
|
-
* executes the corresponding Composio tool, and returns the result.
|
|
189
|
-
*
|
|
190
|
-
* @param userId - The user ID for authentication and tracking
|
|
191
|
-
* @param toolUse - The tool use object from Anthropic
|
|
192
|
-
* @param options - Additional options for tool execution
|
|
193
|
-
* @param modifiers - Modifiers for tool execution
|
|
194
|
-
* @returns The result of the tool execution as a JSON string
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* // Execute a tool call from Anthropic
|
|
199
|
-
* const toolUse = {
|
|
200
|
-
* type: 'tool_use',
|
|
201
|
-
* id: 'tu_abc123',
|
|
202
|
-
* name: 'SEARCH_TOOL',
|
|
203
|
-
* input: {
|
|
204
|
-
* query: 'composio documentation'
|
|
205
|
-
* }
|
|
206
|
-
* };
|
|
207
|
-
*
|
|
208
|
-
* const result = await provider.executeToolCall(
|
|
209
|
-
* 'user123',
|
|
210
|
-
* toolUse,
|
|
211
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
212
|
-
* );
|
|
213
|
-
* console.log(JSON.parse(result));
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
executeToolCall(userId: string, toolUse: AnthropicToolUseBlock, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>;
|
|
217
|
-
/**
|
|
218
|
-
* Handles tool calls from Anthropic's message response.
|
|
219
|
-
*
|
|
220
|
-
* This method processes tool calls from an Anthropic message response,
|
|
221
|
-
* extracts the tool use blocks, executes each tool call, and returns the results.
|
|
222
|
-
*
|
|
223
|
-
* @param userId - The user ID for authentication and tracking
|
|
224
|
-
* @param message - The message response from Anthropic
|
|
225
|
-
* @param options - Additional options for tool execution
|
|
226
|
-
* @param modifiers - Modifiers for tool execution
|
|
227
|
-
* @returns Array of tool execution results as JSON strings
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* // Handle tool calls from an Anthropic message response
|
|
232
|
-
* const anthropic = new Anthropic({ apiKey: 'your-anthropic-api-key' });
|
|
233
|
-
*
|
|
234
|
-
* const message = await anthropic.messages.create({
|
|
235
|
-
* model: 'claude-3-opus-20240229',
|
|
236
|
-
* max_tokens: 1024,
|
|
237
|
-
* tools: provider.wrapTools(composioTools),
|
|
238
|
-
* messages: [
|
|
239
|
-
* {
|
|
240
|
-
* role: 'user',
|
|
241
|
-
* content: 'Search for information about Composio'
|
|
242
|
-
* }
|
|
243
|
-
* ]
|
|
244
|
-
* });
|
|
245
|
-
*
|
|
246
|
-
* // Process any tool calls in the response
|
|
247
|
-
* const results = await provider.handleToolCalls(
|
|
248
|
-
* 'user123',
|
|
249
|
-
* message,
|
|
250
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
251
|
-
* );
|
|
252
|
-
*
|
|
253
|
-
* // Use the results to continue the conversation
|
|
254
|
-
* console.log(results);
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
handleToolCalls(userId: string, message: Anthropic.Message, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<Anthropic.Messages.MessageParam[]>;
|
|
258
|
-
/**
|
|
259
|
-
* Transform MCP URL response into Anthropic-specific format.
|
|
260
|
-
* By default, Anthropic uses the standard format (same as default),
|
|
261
|
-
* but this method is here to show providers can customize if needed.
|
|
262
|
-
*
|
|
263
|
-
* @param data - The MCP URL response data
|
|
264
|
-
* @returns Standard MCP server response format
|
|
265
|
-
*/
|
|
266
|
-
wrapMcpServerResponse(data: McpUrlResponse): AnthropicMcpServerGetResponse;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export { type AnthropicContentBlock, type AnthropicMcpServerGetResponse, AnthropicProvider, type AnthropicToolCollection, type AnthropicToolUseBlock };
|