@nymbalhq/adapter-anthropic 0.0.0-stage → 1.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/dist/index.d.ts +13 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Logger, AiAdapter, AdapterContext } from '@nymbalhq/types';
|
|
2
|
+
|
|
3
|
+
interface AnthropicAiAdapterConfig {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
}
|
|
8
|
+
declare function createAnthropicAiAdapter(config: AnthropicAiAdapterConfig): AiAdapter;
|
|
9
|
+
|
|
10
|
+
/** The kernel's entry: `ai: { provider: 'anthropic', config: { apiKey?, model? } }`, the key falling back to ANTHROPIC_API_KEY. */
|
|
11
|
+
declare function createAdapter(ctx: AdapterContext): AiAdapter;
|
|
12
|
+
|
|
13
|
+
export { type AnthropicAiAdapterConfig, createAdapter, createAnthropicAiAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { ConfigError } from "@nymbalhq/types";
|
|
3
|
+
|
|
4
|
+
// src/anthropic-adapter.ts
|
|
5
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
6
|
+
import { AdapterError } from "@nymbalhq/types";
|
|
7
|
+
function createAnthropicAiAdapter(config) {
|
|
8
|
+
const model = config.model ?? "claude-sonnet-4-6";
|
|
9
|
+
const client = new Anthropic({ apiKey: config.apiKey });
|
|
10
|
+
return {
|
|
11
|
+
kind: "ai",
|
|
12
|
+
providerName: "anthropic",
|
|
13
|
+
capabilities: () => ["complete"],
|
|
14
|
+
producesEvents: [],
|
|
15
|
+
consumesEvents: [],
|
|
16
|
+
async initialize() {
|
|
17
|
+
},
|
|
18
|
+
async healthCheck() {
|
|
19
|
+
return { status: "healthy", detail: `Anthropic AI adapter using model ${model}` };
|
|
20
|
+
},
|
|
21
|
+
async embed() {
|
|
22
|
+
throw new AdapterError(
|
|
23
|
+
"not_configured",
|
|
24
|
+
"Embedding not yet supported by the Anthropic adapter"
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
async complete(prompt, opts) {
|
|
28
|
+
const maxTokens = opts?.maxTokens ?? 1024;
|
|
29
|
+
const message = await client.messages.create({
|
|
30
|
+
model,
|
|
31
|
+
max_tokens: maxTokens,
|
|
32
|
+
messages: [{ role: "user", content: prompt }]
|
|
33
|
+
});
|
|
34
|
+
const block = message.content[0];
|
|
35
|
+
if (!block || block.type !== "text") {
|
|
36
|
+
throw new AdapterError("unexpected_response", "Anthropic returned no text content");
|
|
37
|
+
}
|
|
38
|
+
return block.text;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/index.ts
|
|
44
|
+
function createAdapter(ctx) {
|
|
45
|
+
if (ctx.slot !== "ai") {
|
|
46
|
+
throw new ConfigError(`@nymbalhq/adapter-anthropic serves ai, not ${ctx.slot}`, {
|
|
47
|
+
code: "adapter.wrong_slot",
|
|
48
|
+
context: { slot: ctx.slot }
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const apiKey = ctx.config["apiKey"];
|
|
52
|
+
const model = ctx.config["model"];
|
|
53
|
+
return createAnthropicAiAdapter({
|
|
54
|
+
apiKey: typeof apiKey === "string" && apiKey !== "" ? apiKey : ctx.env["ANTHROPIC_API_KEY"] ?? "",
|
|
55
|
+
...typeof model === "string" && { model },
|
|
56
|
+
logger: ctx.logger
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
createAdapter,
|
|
61
|
+
createAnthropicAiAdapter
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/anthropic-adapter.ts"],"sourcesContent":["import { ConfigError, type AdapterContext, type AiAdapter } from '@nymbalhq/types'\nimport { createAnthropicAiAdapter, type AnthropicAiAdapterConfig } from './anthropic-adapter.js'\n\nexport { createAnthropicAiAdapter, type AnthropicAiAdapterConfig }\n\n/** The kernel's entry: `ai: { provider: 'anthropic', config: { apiKey?, model? } }`, the key falling back to ANTHROPIC_API_KEY. */\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 return createAnthropicAiAdapter({\n apiKey:\n typeof apiKey === 'string' && apiKey !== '' ? apiKey : (ctx.env['ANTHROPIC_API_KEY'] ?? ''),\n ...(typeof model === 'string' && { model }),\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 logger: Logger\n}\n\nexport function createAnthropicAiAdapter(config: AnthropicAiAdapterConfig): AiAdapter {\n const model = config.model ?? 'claude-sonnet-4-6'\n const client = new Anthropic({ apiKey: config.apiKey })\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,SAAS,mBAAwD;;;ACAjE,OAAO,eAAe;AAEtB,SAAS,oBAAoB;AAQtB,SAAS,yBAAyB,QAA6C;AACpF,QAAM,QAAQ,OAAO,SAAS;AAC9B,QAAM,SAAS,IAAI,UAAU,EAAE,QAAQ,OAAO,OAAO,CAAC;AAEtD,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;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,SAAS,QAAQ,MAAM;AAC3B,YAAM,YAAY,MAAM,aAAa;AACrC,YAAM,UAAU,MAAM,OAAO,SAAS,OAAO;AAAA,QAC3C;AAAA,QACA,YAAY;AAAA,QACZ,UAAU,CAAC,EAAE,MAAM,QAAQ,SAAS,OAAO,CAAC;AAAA,MAC9C,CAAC;AACD,YAAM,QAAQ,QAAQ,QAAQ,CAAC;AAC/B,UAAI,CAAC,SAAS,MAAM,SAAS,QAAQ;AACnC,cAAM,IAAI,aAAa,uBAAuB,oCAAoC;AAAA,MACpF;AACA,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AACF;;;AD1CO,SAAS,cAAc,KAAgC;AAC5D,MAAI,IAAI,SAAS,MAAM;AACrB,UAAM,IAAI,YAAY,8CAA8C,IAAI,IAAI,IAAI;AAAA,MAC9E,MAAM;AAAA,MACN,SAAS,EAAE,MAAM,IAAI,KAAK;AAAA,IAC5B,CAAC;AAAA,EACH;AACA,QAAM,SAAS,IAAI,OAAO,QAAQ;AAClC,QAAM,QAAQ,IAAI,OAAO,OAAO;AAChC,SAAO,yBAAyB;AAAA,IAC9B,QACE,OAAO,WAAW,YAAY,WAAW,KAAK,SAAU,IAAI,IAAI,mBAAmB,KAAK;AAAA,IAC1F,GAAI,OAAO,UAAU,YAAY,EAAE,MAAM;AAAA,IACzC,QAAQ,IAAI;AAAA,EACd,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymbalhq/adapter-anthropic",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Anthropic AI for Nymbal: the `anthropic` ai provider",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nymbalhq/nymbal.git",
|
|
9
|
+
"directory": "packages/adapter-anthropic"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@nymbalhq/types": "1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@anthropic-ai/sdk": "^0.39.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@anthropic-ai/sdk": "^0.39.0",
|
|
37
|
+
"tsup": "^8.3.5",
|
|
38
|
+
"typescript": "^5.6.3",
|
|
39
|
+
"vitest": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
45
|
+
}
|
|
6
46
|
}
|
package/README.md
DELETED