integrate-sdk 0.7.22 → 0.7.24

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.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Anthropic Claude Integration
3
+ *
4
+ * Helper functions to convert MCP tools to Anthropic Claude API format
5
+ */
6
+ import type { MCPClient } from "../client.js";
7
+ import type { MCPTool } from "../protocol/messages.js";
8
+ import { type AIToolsOptions } from "./utils.js";
9
+ /**
10
+ * Anthropic tool definition
11
+ * Compatible with Anthropic's Claude API
12
+ */
13
+ export interface AnthropicTool {
14
+ name: string;
15
+ description: string;
16
+ input_schema: {
17
+ type: 'object';
18
+ properties?: Record<string, unknown>;
19
+ required?: string[];
20
+ [key: string]: unknown;
21
+ };
22
+ }
23
+ /**
24
+ * Options for converting MCP tools to Anthropic format
25
+ */
26
+ export interface AnthropicToolsOptions extends AIToolsOptions {
27
+ }
28
+ /**
29
+ * Anthropic tool use block from message content
30
+ */
31
+ export interface AnthropicToolUseBlock {
32
+ type: 'tool_use';
33
+ id: string;
34
+ name: string;
35
+ input: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * Anthropic tool result block for responses
39
+ */
40
+ export interface AnthropicToolResultBlock {
41
+ type: 'tool_result';
42
+ tool_use_id: string;
43
+ content: string;
44
+ }
45
+ /**
46
+ * Convert a single MCP tool to Anthropic Claude API format
47
+ *
48
+ * @param mcpTool - The MCP tool definition
49
+ * @param client - The MCP client instance (used for executing the tool)
50
+ * @param options - Optional configuration including provider tokens
51
+ * @returns Anthropic compatible tool definition
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const anthropicTool = convertMCPToolToAnthropic(mcpTool, client);
56
+ * ```
57
+ */
58
+ export declare function convertMCPToolToAnthropic(mcpTool: MCPTool, _client: MCPClient<any>, _options?: AnthropicToolsOptions): AnthropicTool;
59
+ /**
60
+ * Convert all enabled MCP tools to Anthropic Claude API format
61
+ *
62
+ * @param client - The MCP client instance (must be connected)
63
+ * @param options - Optional configuration including provider tokens
64
+ * @returns Array of Anthropic compatible tool definitions
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // Client-side usage
69
+ * const tools = convertMCPToolsToAnthropic(mcpClient);
70
+ *
71
+ * // Server-side with provider tokens
72
+ * const tools = convertMCPToolsToAnthropic(serverClient, {
73
+ * providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
74
+ * });
75
+ * ```
76
+ */
77
+ export declare function convertMCPToolsToAnthropic(client: MCPClient<any>, options?: AnthropicToolsOptions): AnthropicTool[];
78
+ /**
79
+ * Execute a tool call from Anthropic's response
80
+ *
81
+ * @param client - The MCP client instance
82
+ * @param toolUse - The tool use block from Anthropic response
83
+ * @param options - Optional configuration including provider tokens
84
+ * @returns Tool execution result as JSON string
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const result = await executeAnthropicToolCall(client, {
89
+ * type: 'tool_use',
90
+ * id: 'toolu_123',
91
+ * name: 'github_create_issue',
92
+ * input: { owner: 'user', repo: 'repo', title: 'Bug' }
93
+ * }, { providerTokens });
94
+ * ```
95
+ */
96
+ export declare function executeAnthropicToolCall(client: MCPClient<any>, toolUse: AnthropicToolUseBlock, options?: AnthropicToolsOptions): Promise<string>;
97
+ /**
98
+ * Handle all tool calls from Anthropic's message response
99
+ * Executes all tool use blocks and returns tool result blocks
100
+ *
101
+ * @param client - The MCP client instance
102
+ * @param messageContent - Array of content blocks from Anthropic message
103
+ * @param options - Optional configuration including provider tokens
104
+ * @returns Array of tool result blocks ready to send back to Claude
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const response = await anthropic.messages.create({
109
+ * model: 'claude-3-5-sonnet-20241022',
110
+ * max_tokens: 1024,
111
+ * tools,
112
+ * messages: [{ role: 'user', content: 'Create a GitHub issue' }]
113
+ * });
114
+ *
115
+ * // Handle tool calls
116
+ * const toolResults = await handleAnthropicToolCalls(
117
+ * client,
118
+ * response.content,
119
+ * { providerTokens }
120
+ * );
121
+ *
122
+ * // Continue conversation with tool results
123
+ * const finalResponse = await anthropic.messages.create({
124
+ * model: 'claude-3-5-sonnet-20241022',
125
+ * max_tokens: 1024,
126
+ * tools,
127
+ * messages: [
128
+ * { role: 'user', content: 'Create a GitHub issue' },
129
+ * { role: 'assistant', content: response.content },
130
+ * { role: 'user', content: toolResults }
131
+ * ]
132
+ * });
133
+ * ```
134
+ */
135
+ export declare function handleAnthropicToolCalls(client: MCPClient<any>, messageContent: Array<{
136
+ type: string;
137
+ [key: string]: any;
138
+ }>, options?: AnthropicToolsOptions): Promise<AnthropicToolResultBlock[]>;
139
+ /**
140
+ * Get tools in a format compatible with Anthropic Claude API
141
+ *
142
+ * Automatically connects the client if not already connected.
143
+ *
144
+ * **Auto-extraction**: Provider tokens are automatically extracted from request headers
145
+ * or environment variables if not provided in options.
146
+ *
147
+ * @param client - The MCP client instance
148
+ * @param options - Optional configuration including provider tokens for server-side usage
149
+ * @returns Array of tools ready to pass to Claude API
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // Auto-extraction (recommended)
154
+ * import { serverClient } from '@/lib/integrate-server';
155
+ * import { getAnthropicTools, handleAnthropicToolCalls } from 'integrate-sdk';
156
+ * import Anthropic from '@anthropic-ai/sdk';
157
+ *
158
+ * export async function POST(req: Request) {
159
+ * const tools = await getAnthropicTools(serverClient); // Tokens auto-extracted
160
+ *
161
+ * const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
162
+ * const message = await anthropic.messages.create({
163
+ * model: 'claude-3-5-sonnet-20241022',
164
+ * max_tokens: 1024,
165
+ * tools,
166
+ * messages: [{ role: 'user', content: 'Create a GitHub issue' }]
167
+ * });
168
+ *
169
+ * return Response.json(message);
170
+ * }
171
+ * ```
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Manual override
176
+ * const tools = await getAnthropicTools(serverClient, {
177
+ * providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
178
+ * });
179
+ * ```
180
+ */
181
+ export declare function getAnthropicTools(client: MCPClient<any>, options?: AnthropicToolsOptions): Promise<AnthropicTool[]>;
182
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/ai/anthropic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjH;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;CAAI;AAEjE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ,CAAC,EAAE,qBAAqB,GAC/B,aAAa,CAUf;AAED;;;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