@riotprompt/execution-anthropic 0.0.2 → 0.0.4
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/package.json +14 -6
- package/dist/index.cjs +0 -83
- package/dist/index.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riotprompt/execution-anthropic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Anthropic Claude provider for execution interface",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
7
|
-
"module": "./dist/index.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
8
7
|
"types": "./dist/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
10
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
11
|
+
"import": "./dist/index.js"
|
|
14
12
|
}
|
|
15
13
|
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=24.0.0"
|
|
16
|
+
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"clean": "rm -rf dist",
|
|
18
19
|
"build": "vite build",
|
|
19
|
-
"test": "vitest run",
|
|
20
|
+
"test": "vitest run --coverage",
|
|
21
|
+
"test:coverage": "vitest run --coverage",
|
|
20
22
|
"lint": "eslint src",
|
|
23
|
+
"precommit": "npm run lint && npm run test",
|
|
21
24
|
"prepublishOnly": "npm run clean && npm run build"
|
|
22
25
|
},
|
|
23
26
|
"keywords": [
|
|
@@ -29,6 +32,10 @@
|
|
|
29
32
|
],
|
|
30
33
|
"author": "Tim O'Brien <tobrien@discursive.com>",
|
|
31
34
|
"license": "Apache-2.0",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/kjerneverk/execution-anthropic"
|
|
38
|
+
},
|
|
32
39
|
"dependencies": {
|
|
33
40
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
34
41
|
},
|
|
@@ -36,6 +43,7 @@
|
|
|
36
43
|
"@types/node": "^25.0.6",
|
|
37
44
|
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
|
38
45
|
"@typescript-eslint/parser": "^8.33.1",
|
|
46
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
39
47
|
"eslint": "^9.28.0",
|
|
40
48
|
"globals": "^16.2.0",
|
|
41
49
|
"typescript": "^5.8.3",
|
package/dist/index.cjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const Anthropic = require("@anthropic-ai/sdk");
|
|
4
|
-
class AnthropicProvider {
|
|
5
|
-
name = "anthropic";
|
|
6
|
-
/**
|
|
7
|
-
* Check if this provider supports a given model
|
|
8
|
-
*/
|
|
9
|
-
supportsModel(model) {
|
|
10
|
-
if (!model) return false;
|
|
11
|
-
return model.startsWith("claude");
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Execute a request against Anthropic
|
|
15
|
-
*/
|
|
16
|
-
async execute(request, options = {}) {
|
|
17
|
-
const apiKey = options.apiKey || process.env.ANTHROPIC_API_KEY;
|
|
18
|
-
if (!apiKey) throw new Error("Anthropic API key is required");
|
|
19
|
-
const client = new Anthropic({ apiKey });
|
|
20
|
-
const model = options.model || request.model || "claude-3-opus-20240229";
|
|
21
|
-
let systemPrompt = "";
|
|
22
|
-
const messages = [];
|
|
23
|
-
for (const msg of request.messages) {
|
|
24
|
-
if (msg.role === "system" || msg.role === "developer") {
|
|
25
|
-
systemPrompt += (typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)) + "\n\n";
|
|
26
|
-
} else {
|
|
27
|
-
messages.push({
|
|
28
|
-
role: msg.role,
|
|
29
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const response = await client.messages.create({
|
|
34
|
-
model,
|
|
35
|
-
system: systemPrompt.trim() || void 0,
|
|
36
|
-
messages,
|
|
37
|
-
max_tokens: options.maxTokens || 4096,
|
|
38
|
-
temperature: options.temperature,
|
|
39
|
-
...request.responseFormat?.type === "json_schema" ? {
|
|
40
|
-
tools: [
|
|
41
|
-
{
|
|
42
|
-
name: request.responseFormat.json_schema.name,
|
|
43
|
-
description: request.responseFormat.json_schema.description || "Output data in this structured format",
|
|
44
|
-
input_schema: request.responseFormat.json_schema.schema
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
tool_choice: {
|
|
48
|
-
type: "tool",
|
|
49
|
-
name: request.responseFormat.json_schema.name
|
|
50
|
-
}
|
|
51
|
-
} : {}
|
|
52
|
-
});
|
|
53
|
-
let text = "";
|
|
54
|
-
if (request.responseFormat?.type === "json_schema") {
|
|
55
|
-
const toolUseBlock = response.content.find(
|
|
56
|
-
(block) => block.type === "tool_use"
|
|
57
|
-
);
|
|
58
|
-
if (toolUseBlock && toolUseBlock.type === "tool_use") {
|
|
59
|
-
text = JSON.stringify(toolUseBlock.input, null, 2);
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
const contentBlock = response.content[0];
|
|
63
|
-
text = contentBlock.type === "text" ? contentBlock.text : "";
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
content: text,
|
|
67
|
-
model: response.model,
|
|
68
|
-
usage: {
|
|
69
|
-
inputTokens: response.usage.input_tokens,
|
|
70
|
-
outputTokens: response.usage.output_tokens
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function createAnthropicProvider() {
|
|
76
|
-
return new AnthropicProvider();
|
|
77
|
-
}
|
|
78
|
-
const VERSION = "0.0.1";
|
|
79
|
-
exports.AnthropicProvider = AnthropicProvider;
|
|
80
|
-
exports.VERSION = VERSION;
|
|
81
|
-
exports.createAnthropicProvider = createAnthropicProvider;
|
|
82
|
-
exports.default = AnthropicProvider;
|
|
83
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["/**\n * Execution Anthropic Package\n *\n * Anthropic provider implementation for LLM execution.\n *\n * @packageDocumentation\n */\n\nimport Anthropic from '@anthropic-ai/sdk';\n\n// ===== INLINE TYPES (from 'execution' package) =====\n\nexport type Model = string;\n\nexport interface Message {\n role: 'user' | 'assistant' | 'system' | 'developer' | 'tool';\n content: string | string[] | null;\n name?: string;\n}\n\nexport interface Request {\n messages: Message[];\n model: Model;\n responseFormat?: any;\n validator?: any;\n addMessage(message: Message): void;\n}\n\nexport interface ProviderResponse {\n content: string;\n model: string;\n usage?: {\n inputTokens: number;\n outputTokens: number;\n };\n toolCalls?: Array<{\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n }>;\n}\n\nexport interface ExecutionOptions {\n apiKey?: string;\n model?: string;\n temperature?: number;\n maxTokens?: number;\n timeout?: number;\n retries?: number;\n}\n\nexport interface Provider {\n readonly name: string;\n execute(request: Request, options?: ExecutionOptions): Promise<ProviderResponse>;\n supportsModel?(model: Model): boolean;\n}\n\n/**\n * Anthropic Provider implementation\n */\nexport class AnthropicProvider implements Provider {\n readonly name = 'anthropic';\n\n /**\n * Check if this provider supports a given model\n */\n supportsModel(model: Model): boolean {\n if (!model) return false;\n return model.startsWith('claude');\n }\n\n /**\n * Execute a request against Anthropic\n */\n async execute(\n request: Request,\n options: ExecutionOptions = {}\n ): Promise<ProviderResponse> {\n const apiKey = options.apiKey || process.env.ANTHROPIC_API_KEY;\n if (!apiKey) throw new Error('Anthropic API key is required');\n\n const client = new Anthropic({ apiKey });\n\n const model = options.model || request.model || 'claude-3-opus-20240229';\n\n // Anthropic separates system prompt from messages\n let systemPrompt = '';\n const messages: Anthropic.MessageParam[] = [];\n\n for (const msg of request.messages) {\n if (msg.role === 'system' || msg.role === 'developer') {\n systemPrompt +=\n (typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content)) + '\\n\\n';\n } else {\n messages.push({\n role: msg.role as 'user' | 'assistant',\n content:\n typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content),\n });\n }\n }\n\n const response = await client.messages.create({\n model: model,\n system: systemPrompt.trim() || undefined,\n messages: messages,\n max_tokens: options.maxTokens || 4096,\n temperature: options.temperature,\n ...(request.responseFormat?.type === 'json_schema'\n ? {\n tools: [\n {\n name: request.responseFormat.json_schema.name,\n description:\n request.responseFormat.json_schema.description ||\n 'Output data in this structured format',\n input_schema:\n request.responseFormat.json_schema.schema,\n },\n ],\n tool_choice: {\n type: 'tool' as const,\n name: request.responseFormat.json_schema.name,\n },\n }\n : {}),\n });\n\n // Handle ContentBlock\n let text = '';\n\n if (request.responseFormat?.type === 'json_schema') {\n const toolUseBlock = response.content.find(\n (block) => block.type === 'tool_use'\n );\n if (toolUseBlock && toolUseBlock.type === 'tool_use') {\n text = JSON.stringify(toolUseBlock.input, null, 2);\n }\n } else {\n const contentBlock = response.content[0];\n text = contentBlock.type === 'text' ? contentBlock.text : '';\n }\n\n return {\n content: text,\n model: response.model,\n usage: {\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n },\n };\n }\n}\n\n/**\n * Create a new Anthropic provider instance\n */\nexport function createAnthropicProvider(): AnthropicProvider {\n return new AnthropicProvider();\n}\n\n/**\n * Package version\n */\nexport const VERSION = '0.0.1';\n\nexport default AnthropicProvider;\n"],"names":[],"mappings":";;;AA+DO,MAAM,kBAAsC;AAAA,EACtC,OAAO;AAAA;AAAA;AAAA;AAAA,EAKhB,cAAc,OAAuB;AACjC,QAAI,CAAC,MAAO,QAAO;AACnB,WAAO,MAAM,WAAW,QAAQ;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA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