@nymbalhq/adapter-anthropic 1.0.0 → 1.2.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.d.ts +11 -3
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { Logger, AiAdapter, AdapterContext } from '@nymbalhq/types';
|
|
1
|
+
import { Logger, AiAdapter, AdapterContext, AdapterSetting } from '@nymbalhq/types';
|
|
2
2
|
|
|
3
3
|
interface AnthropicAiAdapterConfig {
|
|
4
4
|
apiKey: string;
|
|
5
5
|
model?: string;
|
|
6
|
+
/** Where the Messages API is; Anthropic's own when omitted (a stand-in for tests). */
|
|
7
|
+
baseUrl?: string;
|
|
6
8
|
logger: Logger;
|
|
7
9
|
}
|
|
8
10
|
declare function createAnthropicAiAdapter(config: AnthropicAiAdapterConfig): AiAdapter;
|
|
9
11
|
|
|
10
|
-
/** The
|
|
12
|
+
/** The fields the admin's Settings may fill when the config (and, for the key, ANTHROPIC_API_KEY) leaves them unset. */
|
|
13
|
+
declare const settings: AdapterSetting[];
|
|
14
|
+
/**
|
|
15
|
+
* The kernel's entry: `ai: { provider: 'anthropic', config: { apiKey?, model?, baseUrl? } }`, the key falling back to
|
|
16
|
+
* ANTHROPIC_API_KEY.
|
|
17
|
+
*/
|
|
11
18
|
declare function createAdapter(ctx: AdapterContext): AiAdapter;
|
|
12
19
|
|
|
13
|
-
export {
|
|
20
|
+
export { createAdapter, createAnthropicAiAdapter, settings };
|
|
21
|
+
export type { AnthropicAiAdapterConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ConfigError
|
|
4
|
+
} from "@nymbalhq/types";
|
|
3
5
|
|
|
4
6
|
// src/anthropic-adapter.ts
|
|
5
7
|
import Anthropic from "@anthropic-ai/sdk";
|
|
6
8
|
import { AdapterError } from "@nymbalhq/types";
|
|
7
9
|
function createAnthropicAiAdapter(config) {
|
|
8
10
|
const model = config.model ?? "claude-sonnet-4-6";
|
|
9
|
-
const client = new Anthropic({
|
|
11
|
+
const client = new Anthropic({
|
|
12
|
+
apiKey: config.apiKey,
|
|
13
|
+
...config.baseUrl !== void 0 && { baseURL: config.baseUrl }
|
|
14
|
+
});
|
|
10
15
|
return {
|
|
11
16
|
kind: "ai",
|
|
12
17
|
providerName: "anthropic",
|
|
@@ -41,6 +46,10 @@ function createAnthropicAiAdapter(config) {
|
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
// src/index.ts
|
|
49
|
+
var settings = [
|
|
50
|
+
{ path: "apiKey", label: "API key", secret: true, env: "ANTHROPIC_API_KEY" },
|
|
51
|
+
{ path: "baseUrl", label: "API base URL", secret: false }
|
|
52
|
+
];
|
|
44
53
|
function createAdapter(ctx) {
|
|
45
54
|
if (ctx.slot !== "ai") {
|
|
46
55
|
throw new ConfigError(`@nymbalhq/adapter-anthropic serves ai, not ${ctx.slot}`, {
|
|
@@ -50,14 +59,17 @@ function createAdapter(ctx) {
|
|
|
50
59
|
}
|
|
51
60
|
const apiKey = ctx.config["apiKey"];
|
|
52
61
|
const model = ctx.config["model"];
|
|
62
|
+
const baseUrl = ctx.config["baseUrl"];
|
|
53
63
|
return createAnthropicAiAdapter({
|
|
54
64
|
apiKey: typeof apiKey === "string" && apiKey !== "" ? apiKey : ctx.env["ANTHROPIC_API_KEY"] ?? "",
|
|
55
65
|
...typeof model === "string" && { model },
|
|
66
|
+
...typeof baseUrl === "string" && baseUrl !== "" && { baseUrl },
|
|
56
67
|
logger: ctx.logger
|
|
57
68
|
});
|
|
58
69
|
}
|
|
59
70
|
export {
|
|
60
71
|
createAdapter,
|
|
61
|
-
createAnthropicAiAdapter
|
|
72
|
+
createAnthropicAiAdapter,
|
|
73
|
+
settings
|
|
62
74
|
};
|
|
63
75
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/anthropic-adapter.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/anthropic-adapter.ts"],"sourcesContent":["import {\n ConfigError,\n type AdapterContext,\n type AdapterSetting,\n type AiAdapter,\n} from '@nymbalhq/types'\nimport { createAnthropicAiAdapter, type AnthropicAiAdapterConfig } from './anthropic-adapter.js'\n\nexport { createAnthropicAiAdapter, type AnthropicAiAdapterConfig }\n\n/** The fields the admin's Settings may fill when the config (and, for the key, ANTHROPIC_API_KEY) leaves them unset. */\nexport const settings: AdapterSetting[] = [\n { path: 'apiKey', label: 'API key', secret: true, env: 'ANTHROPIC_API_KEY' },\n { path: 'baseUrl', label: 'API base URL', secret: false },\n]\n\n/**\n * The kernel's entry: `ai: { provider: 'anthropic', config: { apiKey?, model?, baseUrl? } }`, the key falling back to\n * ANTHROPIC_API_KEY.\n */\nexport function createAdapter(ctx: AdapterContext): AiAdapter {\n if (ctx.slot !== 'ai') {\n throw new ConfigError(`@nymbalhq/adapter-anthropic serves ai, not ${ctx.slot}`, {\n code: 'adapter.wrong_slot',\n context: { slot: ctx.slot },\n })\n }\n const apiKey = ctx.config['apiKey']\n const model = ctx.config['model']\n const baseUrl = ctx.config['baseUrl']\n return createAnthropicAiAdapter({\n apiKey:\n typeof apiKey === 'string' && apiKey !== '' ? apiKey : (ctx.env['ANTHROPIC_API_KEY'] ?? ''),\n ...(typeof model === 'string' && { model }),\n ...(typeof baseUrl === 'string' && baseUrl !== '' && { baseUrl }),\n logger: ctx.logger,\n })\n}\n","import Anthropic from '@anthropic-ai/sdk'\nimport type { AiAdapter, Logger } from '@nymbalhq/types'\nimport { AdapterError } from '@nymbalhq/types'\n\nexport interface AnthropicAiAdapterConfig {\n apiKey: string\n model?: string\n /** Where the Messages API is; Anthropic's own when omitted (a stand-in for tests). */\n baseUrl?: string\n logger: Logger\n}\n\nexport function createAnthropicAiAdapter(config: AnthropicAiAdapterConfig): AiAdapter {\n const model = config.model ?? 'claude-sonnet-4-6'\n const client = new Anthropic({\n apiKey: config.apiKey,\n ...(config.baseUrl !== undefined && { baseURL: config.baseUrl }),\n })\n\n return {\n kind: 'ai',\n providerName: 'anthropic',\n capabilities: () => ['complete'],\n producesEvents: [],\n consumesEvents: [],\n async initialize() {\n // no-op: the client is constructed above\n },\n async healthCheck() {\n return { status: 'healthy', detail: `Anthropic AI adapter using model ${model}` }\n },\n\n async embed() {\n throw new AdapterError(\n 'not_configured',\n 'Embedding not yet supported by the Anthropic adapter',\n )\n },\n\n async complete(prompt, opts) {\n const maxTokens = opts?.maxTokens ?? 1024\n const message = await client.messages.create({\n model,\n max_tokens: maxTokens,\n messages: [{ role: 'user', content: prompt }],\n })\n const block = message.content[0]\n if (!block || block.type !== 'text') {\n throw new AdapterError('unexpected_response', 'Anthropic returned no text content')\n }\n return block.text\n },\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAIK;;;ACLP,OAAO,eAAe;AAEtB,SAAS,oBAAoB;AAUtB,SAAS,yBAAyB,QAA6C;AACpF,QAAM,QAAQ,OAAO,SAAS;AAC9B,QAAM,SAAS,IAAI,UAAU;AAAA,IAC3B,QAAQ,OAAO;AAAA,IACf,GAAI,OAAO,YAAY,UAAa,EAAE,SAAS,OAAO,QAAQ;AAAA,EAChE,CAAC;AAED,SAAO;AAAA,IACL,MAAM;AAAA,IACN,cAAc;AAAA,IACd,cAAc,MAAM,CAAC,UAAU;AAAA,IAC/B,gBAAgB,CAAC;AAAA,IACjB,gBAAgB,CAAC;AAAA,IACjB,MAAM,aAAa;AAAA,IAEnB;AAAA,IACA,MAAM,cAAc;AAClB,aAAO,EAAE,QAAQ,WAAW,QAAQ,oCAAoC,KAAK,GAAG;AAAA,IAClF;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAM,IAAI;AAAA,QACR;AAAA,QACA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ymbalhq/adapter-anthropic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Anthropic AI for Nymbal: the `anthropic` ai provider",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,20 +27,21 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@nymbalhq/types": "1.
|
|
30
|
+
"@nymbalhq/types": "1.2.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@anthropic-ai/sdk": "^0.39.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
38
|
+
"tsup": "^9.0.0",
|
|
39
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
39
40
|
"vitest": "^3.0.0"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsup",
|
|
43
44
|
"dev": "tsup --watch",
|
|
44
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit --rootDir ../.."
|
|
45
46
|
}
|
|
46
47
|
}
|