@metorial/anthropic 2.0.0 → 3.0.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/README.md +24 -27
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -13
- package/dist/index.d.ts +3 -13
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -30,37 +30,34 @@ let anthropic = new OpenAI({
|
|
|
30
30
|
baseURL: 'https://api.anthropic.com/v1'
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
await metorial.
|
|
34
|
-
metorialAnthropic,
|
|
33
|
+
let session = await metorial.connect({
|
|
34
|
+
adapter: metorialAnthropic(),
|
|
35
|
+
providers: [{ providerDeploymentId: 'your-provider-deployment-id' }]
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
let messages = [
|
|
35
39
|
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
role: 'user',
|
|
42
|
-
content:
|
|
43
|
-
'Summarize the README.md file of the metorial/websocket-explorer repository on GitHub?'
|
|
44
|
-
}
|
|
45
|
-
];
|
|
40
|
+
role: 'user',
|
|
41
|
+
content:
|
|
42
|
+
'Summarize the README.md file of the metorial/websocket-explorer repository on GitHub?'
|
|
43
|
+
}
|
|
44
|
+
];
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
let response = await anthropic.chat.completions.create({
|
|
47
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
48
|
+
messages,
|
|
49
|
+
tools: session.tools()
|
|
50
|
+
});
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
let choice = response.choices[0]!;
|
|
53
|
+
let toolCalls = choice.message.tool_calls;
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
);
|
|
55
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
56
|
+
let toolResponses = await session.callTools(toolCalls);
|
|
57
|
+
console.log('Tool responses:', toolResponses);
|
|
58
|
+
} else {
|
|
59
|
+
console.log(choice.message.content);
|
|
60
|
+
}
|
|
64
61
|
```
|
|
65
62
|
|
|
66
63
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var mcpSdkUtils = require('@metorial/mcp-sdk-utils');
|
|
4
4
|
|
|
5
5
|
// src/metorialAnthropic.ts
|
|
6
|
-
var metorialAnthropic = mcpSdkUtils.createMcpSdk(
|
|
7
|
-
tools: tools.getTools().map(
|
|
6
|
+
var metorialAnthropic = mcpSdkUtils.createMcpSdk(async ({ tools }) => ({
|
|
7
|
+
tools: () => tools.getTools().map(
|
|
8
8
|
(t) => {
|
|
9
9
|
var _a;
|
|
10
10
|
return {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/metorialAnthropic.ts"],"names":[],"mappings":";AAMA,SAAS,oBAAoB;AAEtB,IAAI,oBAAoB,aAAa,
|
|
1
|
+
{"version":3,"sources":["../src/metorialAnthropic.ts"],"names":[],"mappings":";AAMA,SAAS,oBAAoB;AAEtB,IAAI,oBAAoB,aAAa,OAAO,EAAE,MAAM,OAAO;AAAA,EAChE,OAAO,MAAM,MAAM,SAAS,EAAE;AAAA,IAC5B,OAAE;AAVN;AAWO;AAAA,QACC,MAAM,EAAE;AAAA,QACR,cAAa,OAAE,gBAAF,YAAiB;AAAA,QAC9B,cAAc,EAAE,gBAAgB,aAAa;AAAA,MAC/C;AAAA;AAAA,EACJ;AAAA,EAEA,WAAW,OAAO,WAAkD;AAAA,IAClE,MAAM;AAAA,IACN,SAAS,MAAM,QAAQ;AAAA,MACrB,MAAM,IAAI,OAAM,SAAQ;AACtB,YAAI,OAAO,MAAM,QAAQ,KAAK,IAAI;AAClC,YAAI,CAAC,MAAM;AACT,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,2BAA2B,KAAK,IAAI;AAAA,UAC/C;AAAA,QACF;AAEA,YAAI,OAAY,CAAC;AAEjB,YAAI;AACF,cAAI,OAAO,KAAK,SAAS,UAAU;AACjC,mBAAO,KAAK,MAAM,KAAK,KAAK;AAAA,UAC9B,OAAO;AACL,mBAAO,KAAK;AAAA,UACd;AAAA,QACF,SAAS,GAAQ;AACf,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,gDAAgD,EAAE,OAAO;AAAA,UACpE;AAAA,QACF;AAEA,YAAI;AACF,cAAI,SAAS,MAAM,KAAK,KAAK,IAAI;AAEjC,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,KAAK,UAAU,MAAM;AAAA,UAChC;AAAA,QACF,SAAS,GAAQ;AACf,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,6BAA6B,EAAE,OAAO;AAAA,UACjD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,EAAE","sourcesContent":["import {\n MessageParam,\n ToolResultBlockParam,\n ToolUnion,\n ToolUseBlock\n} from '@anthropic-ai/sdk/resources/messages';\nimport { createMcpSdk } from '@metorial/mcp-sdk-utils';\n\nexport let metorialAnthropic = createMcpSdk(async ({ tools }) => ({\n tools: () => tools.getTools().map(\n t =>\n ({\n name: t.id,\n description: t.description ?? undefined,\n input_schema: t.getParametersAs('json-schema') as any\n }) satisfies ToolUnion\n ) as ToolUnion[],\n\n callTools: async (calls: ToolUseBlock[]): Promise<MessageParam> => ({\n role: 'user',\n content: await Promise.all(\n calls.map(async call => {\n let tool = tools.getTool(call.name);\n if (!tool) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Tool with name \"${call.name}\" not found.`\n } satisfies ToolResultBlockParam;\n }\n\n let data: any = {};\n\n try {\n if (typeof call.input == 'string') {\n data = JSON.parse(call.input);\n } else {\n data = call.input;\n }\n } catch (e: any) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Invalid JSON in tool call arguments: ${e.message}`\n } satisfies ToolResultBlockParam;\n }\n\n try {\n let result = await tool.call(data);\n\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: JSON.stringify(result)\n } satisfies ToolResultBlockParam;\n } catch (e: any) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Tool call failed: ${e.message}`\n } satisfies ToolResultBlockParam;\n }\n })\n )\n })\n}));\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import * as _metorial_mcp_session from '@metorial/mcp-session';
|
|
2
1
|
import * as _metorial_mcp_sdk_utils from '@metorial/mcp-sdk-utils';
|
|
3
2
|
import { ToolUnion, ToolUseBlock, MessageParam } from '@anthropic-ai/sdk/resources/messages';
|
|
4
3
|
|
|
5
|
-
declare let metorialAnthropic: (
|
|
6
|
-
tools: ToolUnion[];
|
|
4
|
+
declare let metorialAnthropic: () => _metorial_mcp_sdk_utils.MetorialAdapter<{
|
|
5
|
+
tools: () => ToolUnion[];
|
|
7
6
|
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
8
|
-
}
|
|
9
|
-
ofSession: (session: _metorial_mcp_sdk_utils.McpSessionLike, input: void) => Promise<{
|
|
10
|
-
tools: ToolUnion[];
|
|
11
|
-
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
12
|
-
}>;
|
|
13
|
-
ofSdk: (sdk: _metorial_mcp_sdk_utils.McpSDK, init: _metorial_mcp_session.MetorialMcpSessionInit, input: void) => Promise<{
|
|
14
|
-
tools: ToolUnion[];
|
|
15
|
-
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
16
|
-
}>;
|
|
17
|
-
};
|
|
7
|
+
}>;
|
|
18
8
|
|
|
19
9
|
export { metorialAnthropic };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import * as _metorial_mcp_session from '@metorial/mcp-session';
|
|
2
1
|
import * as _metorial_mcp_sdk_utils from '@metorial/mcp-sdk-utils';
|
|
3
2
|
import { ToolUnion, ToolUseBlock, MessageParam } from '@anthropic-ai/sdk/resources/messages';
|
|
4
3
|
|
|
5
|
-
declare let metorialAnthropic: (
|
|
6
|
-
tools: ToolUnion[];
|
|
4
|
+
declare let metorialAnthropic: () => _metorial_mcp_sdk_utils.MetorialAdapter<{
|
|
5
|
+
tools: () => ToolUnion[];
|
|
7
6
|
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
8
|
-
}
|
|
9
|
-
ofSession: (session: _metorial_mcp_sdk_utils.McpSessionLike, input: void) => Promise<{
|
|
10
|
-
tools: ToolUnion[];
|
|
11
|
-
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
12
|
-
}>;
|
|
13
|
-
ofSdk: (sdk: _metorial_mcp_sdk_utils.McpSDK, init: _metorial_mcp_session.MetorialMcpSessionInit, input: void) => Promise<{
|
|
14
|
-
tools: ToolUnion[];
|
|
15
|
-
callTools: (calls: ToolUseBlock[]) => Promise<MessageParam>;
|
|
16
|
-
}>;
|
|
17
|
-
};
|
|
7
|
+
}>;
|
|
18
8
|
|
|
19
9
|
export { metorialAnthropic };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createMcpSdk } from '@metorial/mcp-sdk-utils';
|
|
2
2
|
|
|
3
3
|
// src/metorialAnthropic.ts
|
|
4
|
-
var metorialAnthropic = createMcpSdk(
|
|
5
|
-
tools: tools.getTools().map(
|
|
4
|
+
var metorialAnthropic = createMcpSdk(async ({ tools }) => ({
|
|
5
|
+
tools: () => tools.getTools().map(
|
|
6
6
|
(t) => {
|
|
7
7
|
var _a;
|
|
8
8
|
return {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/metorialAnthropic.ts"],"names":[],"mappings":";AAMA,SAAS,oBAAoB;AAEtB,IAAI,oBAAoB,aAAa,
|
|
1
|
+
{"version":3,"sources":["../src/metorialAnthropic.ts"],"names":[],"mappings":";AAMA,SAAS,oBAAoB;AAEtB,IAAI,oBAAoB,aAAa,OAAO,EAAE,MAAM,OAAO;AAAA,EAChE,OAAO,MAAM,MAAM,SAAS,EAAE;AAAA,IAC5B,OAAE;AAVN;AAWO;AAAA,QACC,MAAM,EAAE;AAAA,QACR,cAAa,OAAE,gBAAF,YAAiB;AAAA,QAC9B,cAAc,EAAE,gBAAgB,aAAa;AAAA,MAC/C;AAAA;AAAA,EACJ;AAAA,EAEA,WAAW,OAAO,WAAkD;AAAA,IAClE,MAAM;AAAA,IACN,SAAS,MAAM,QAAQ;AAAA,MACrB,MAAM,IAAI,OAAM,SAAQ;AACtB,YAAI,OAAO,MAAM,QAAQ,KAAK,IAAI;AAClC,YAAI,CAAC,MAAM;AACT,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,2BAA2B,KAAK,IAAI;AAAA,UAC/C;AAAA,QACF;AAEA,YAAI,OAAY,CAAC;AAEjB,YAAI;AACF,cAAI,OAAO,KAAK,SAAS,UAAU;AACjC,mBAAO,KAAK,MAAM,KAAK,KAAK;AAAA,UAC9B,OAAO;AACL,mBAAO,KAAK;AAAA,UACd;AAAA,QACF,SAAS,GAAQ;AACf,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,gDAAgD,EAAE,OAAO;AAAA,UACpE;AAAA,QACF;AAEA,YAAI;AACF,cAAI,SAAS,MAAM,KAAK,KAAK,IAAI;AAEjC,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,KAAK,UAAU,MAAM;AAAA,UAChC;AAAA,QACF,SAAS,GAAQ;AACf,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa,KAAK;AAAA,YAClB,SAAS,6BAA6B,EAAE,OAAO;AAAA,UACjD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,EAAE","sourcesContent":["import {\n MessageParam,\n ToolResultBlockParam,\n ToolUnion,\n ToolUseBlock\n} from '@anthropic-ai/sdk/resources/messages';\nimport { createMcpSdk } from '@metorial/mcp-sdk-utils';\n\nexport let metorialAnthropic = createMcpSdk(async ({ tools }) => ({\n tools: () => tools.getTools().map(\n t =>\n ({\n name: t.id,\n description: t.description ?? undefined,\n input_schema: t.getParametersAs('json-schema') as any\n }) satisfies ToolUnion\n ) as ToolUnion[],\n\n callTools: async (calls: ToolUseBlock[]): Promise<MessageParam> => ({\n role: 'user',\n content: await Promise.all(\n calls.map(async call => {\n let tool = tools.getTool(call.name);\n if (!tool) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Tool with name \"${call.name}\" not found.`\n } satisfies ToolResultBlockParam;\n }\n\n let data: any = {};\n\n try {\n if (typeof call.input == 'string') {\n data = JSON.parse(call.input);\n } else {\n data = call.input;\n }\n } catch (e: any) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Invalid JSON in tool call arguments: ${e.message}`\n } satisfies ToolResultBlockParam;\n }\n\n try {\n let result = await tool.call(data);\n\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: JSON.stringify(result)\n } satisfies ToolResultBlockParam;\n } catch (e: any) {\n return {\n type: 'tool_result',\n tool_use_id: call.id,\n content: `[ERROR] Tool call failed: ${e.message}`\n } satisfies ToolResultBlockParam;\n }\n })\n )\n })\n}));\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metorial/anthropic",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"author": "Metorial Inc.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.cjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"module": "dist/index.js",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/metorial/metorial-node"
|
|
13
|
+
},
|
|
10
14
|
"exports": {
|
|
11
15
|
".": {
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
@@ -25,10 +29,10 @@
|
|
|
25
29
|
"dist"
|
|
26
30
|
],
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@metorial/core": "^
|
|
29
|
-
"@metorial/mcp-sdk-utils": "^
|
|
30
|
-
"@metorial/mcp-session": "^
|
|
31
|
-
"@metorial/openai-compatible": "^
|
|
32
|
+
"@metorial/core": "^3.0.0",
|
|
33
|
+
"@metorial/mcp-sdk-utils": "^3.0.0",
|
|
34
|
+
"@metorial/mcp-session": "^3.0.0",
|
|
35
|
+
"@metorial/openai-compatible": "^3.0.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
38
|
"@anthropic-ai/sdk": "*"
|