@nextclaw/nextclaw-narp-runtime-claude-code-sdk 0.2.3 → 0.2.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-narp-runtime-wrapper.service.d.ts","names":[],"sources":["../../src/services/claude-code-narp-runtime-wrapper.service.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"claude-code-narp-runtime-wrapper.service.d.ts","names":[],"sources":["../../src/services/claude-code-narp-runtime-wrapper.service.ts"],"mappings":";;;;;KAaY,4BAAA,IACV,MAAA,EAAQ,kCAAA,KACL,eAAA;AAAA,cAEQ,4BAAA;EAAA,iBAEQ,aAAA;cAAA,aAAA,GAAe,4BAAA;EAKlC,KAAA;EAOA,uBAAA,GACE,OAAA,EAAS,8BAAA,KACR,eAAA;EAEH,kBAAA,GACE,OAAA,EAAS,8BAAA,KACR,kCAAA;AAAA"}
|
|
@@ -2,6 +2,7 @@ import { NarpStdioRuntimeWrapper } from "@nextclaw/nextclaw-narp-stdio-runtime-w
|
|
|
2
2
|
import { ClaudeCodeSdkNcpAgentRuntime } from "@nextclaw/nextclaw-ncp-runtime-claude-code-sdk";
|
|
3
3
|
//#region src/services/claude-code-narp-runtime-wrapper.service.ts
|
|
4
4
|
const NARP_API_MODE_HEADER = "x-nextclaw-narp-api-mode";
|
|
5
|
+
const RUNTIME_DEFAULT_MODEL_VALUE = "__nextclaw_runtime_default__";
|
|
5
6
|
var ClaudeCodeNarpRuntimeWrapper = class {
|
|
6
7
|
constructor(createRuntime = (config) => new ClaudeCodeSdkNcpAgentRuntime(config)) {
|
|
7
8
|
this.createRuntime = createRuntime;
|
|
@@ -14,10 +15,11 @@ var ClaudeCodeNarpRuntimeWrapper = class {
|
|
|
14
15
|
};
|
|
15
16
|
createClaudeCodeRuntime = (context) => this.createRuntime(this.buildRuntimeConfig(context));
|
|
16
17
|
buildRuntimeConfig = (context) => {
|
|
17
|
-
const { cwd, modelId, promptMeta, sessionId } = context;
|
|
18
|
+
const { cwd, modelId, promptMeta, sessionId, setSessionMetadata } = context;
|
|
18
19
|
const providerRoute = promptMeta.providerRoute;
|
|
19
20
|
const sessionMetadata = promptMeta.sessionMetadata ?? {};
|
|
20
|
-
const
|
|
21
|
+
const requestedModelRoute = readString(sessionMetadata.preferred_model) ?? readString(sessionMetadata.preferredModel) ?? readString(sessionMetadata.model) ?? readString(modelId);
|
|
22
|
+
const useClaudeRuntimeDefaults = !providerRoute && (!requestedModelRoute || requestedModelRoute === RUNTIME_DEFAULT_MODEL_VALUE);
|
|
21
23
|
const apiKey = useClaudeRuntimeDefaults ? "" : readString(providerRoute?.apiKey) ?? readString(process.env.NEXTCLAW_API_KEY) ?? readString(process.env.ANTHROPIC_API_KEY) ?? "";
|
|
22
24
|
const apiBase = useClaudeRuntimeDefaults ? void 0 : resolveClaudeCompatibleApiBase(readString(providerRoute?.apiBase) ?? readString(process.env.NEXTCLAW_API_BASE) ?? readString(process.env.ANTHROPIC_BASE_URL) ?? readString(process.env.ANTHROPIC_API_URL), shouldUseAnthropicGateway(providerRoute?.headers));
|
|
23
25
|
const authToken = useClaudeRuntimeDefaults ? void 0 : readString(process.env.ANTHROPIC_AUTH_TOKEN) ?? readString(process.env.CLAUDE_CODE_OAUTH_TOKEN) ?? resolveClaudeCompatibleAuthToken({
|
|
@@ -35,6 +37,7 @@ var ClaudeCodeNarpRuntimeWrapper = class {
|
|
|
35
37
|
workingDirectory: cwd,
|
|
36
38
|
sessionRuntimeId: readString(sessionMetadata.claude_session_id) ?? null,
|
|
37
39
|
sessionMetadata,
|
|
40
|
+
setSessionMetadata,
|
|
38
41
|
baseQueryOptions: {
|
|
39
42
|
permissionMode: "bypassPermissions",
|
|
40
43
|
includePartialMessages: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-narp-runtime-wrapper.service.js","names":[],"sources":["../../src/services/claude-code-narp-runtime-wrapper.service.ts"],"sourcesContent":["import type { NcpAgentRuntime } from \"@nextclaw/ncp\";\nimport {\n NarpStdioRuntimeWrapper,\n type NarpStdioRuntimeWrapperContext,\n} from \"@nextclaw/nextclaw-narp-stdio-runtime-wrapper\";\nimport {\n ClaudeCodeSdkNcpAgentRuntime,\n type ClaudeCodeSdkNcpAgentRuntimeConfig,\n} from \"@nextclaw/nextclaw-ncp-runtime-claude-code-sdk\";\n\nconst NARP_API_MODE_HEADER = \"x-nextclaw-narp-api-mode\";\n\nexport type ClaudeCodeNarpRuntimeFactory = (\n config: ClaudeCodeSdkNcpAgentRuntimeConfig,\n) => NcpAgentRuntime;\n\nexport class ClaudeCodeNarpRuntimeWrapper {\n constructor(\n private readonly createRuntime: ClaudeCodeNarpRuntimeFactory = (\n config,\n ) => new ClaudeCodeSdkNcpAgentRuntime(config),\n ) {}\n\n start = (): void => {\n new NarpStdioRuntimeWrapper({\n agentName: \"NextClaw Claude Code NARP\",\n createRuntime: (context) => this.createClaudeCodeRuntime(context),\n }).start();\n };\n\n createClaudeCodeRuntime = (\n context: NarpStdioRuntimeWrapperContext,\n ): NcpAgentRuntime => this.createRuntime(this.buildRuntimeConfig(context));\n\n buildRuntimeConfig = (\n context: NarpStdioRuntimeWrapperContext,\n ): ClaudeCodeSdkNcpAgentRuntimeConfig => {\n const { cwd, modelId, promptMeta, sessionId } = context;\n const providerRoute = promptMeta.providerRoute;\n const sessionMetadata = promptMeta.sessionMetadata ?? {};\n const useClaudeRuntimeDefaults
|
|
1
|
+
{"version":3,"file":"claude-code-narp-runtime-wrapper.service.js","names":[],"sources":["../../src/services/claude-code-narp-runtime-wrapper.service.ts"],"sourcesContent":["import type { NcpAgentRuntime } from \"@nextclaw/ncp\";\nimport {\n NarpStdioRuntimeWrapper,\n type NarpStdioRuntimeWrapperContext,\n} from \"@nextclaw/nextclaw-narp-stdio-runtime-wrapper\";\nimport {\n ClaudeCodeSdkNcpAgentRuntime,\n type ClaudeCodeSdkNcpAgentRuntimeConfig,\n} from \"@nextclaw/nextclaw-ncp-runtime-claude-code-sdk\";\n\nconst NARP_API_MODE_HEADER = \"x-nextclaw-narp-api-mode\";\nconst RUNTIME_DEFAULT_MODEL_VALUE = \"__nextclaw_runtime_default__\";\n\nexport type ClaudeCodeNarpRuntimeFactory = (\n config: ClaudeCodeSdkNcpAgentRuntimeConfig,\n) => NcpAgentRuntime;\n\nexport class ClaudeCodeNarpRuntimeWrapper {\n constructor(\n private readonly createRuntime: ClaudeCodeNarpRuntimeFactory = (\n config,\n ) => new ClaudeCodeSdkNcpAgentRuntime(config),\n ) {}\n\n start = (): void => {\n new NarpStdioRuntimeWrapper({\n agentName: \"NextClaw Claude Code NARP\",\n createRuntime: (context) => this.createClaudeCodeRuntime(context),\n }).start();\n };\n\n createClaudeCodeRuntime = (\n context: NarpStdioRuntimeWrapperContext,\n ): NcpAgentRuntime => this.createRuntime(this.buildRuntimeConfig(context));\n\n buildRuntimeConfig = (\n context: NarpStdioRuntimeWrapperContext,\n ): ClaudeCodeSdkNcpAgentRuntimeConfig => {\n const { cwd, modelId, promptMeta, sessionId, setSessionMetadata } = context;\n const providerRoute = promptMeta.providerRoute;\n const sessionMetadata = promptMeta.sessionMetadata ?? {};\n const requestedModelRoute =\n readString(sessionMetadata.preferred_model) ??\n readString(sessionMetadata.preferredModel) ??\n readString(sessionMetadata.model) ??\n readString(modelId);\n const useClaudeRuntimeDefaults =\n !providerRoute && (!requestedModelRoute || requestedModelRoute === RUNTIME_DEFAULT_MODEL_VALUE);\n const apiKey = useClaudeRuntimeDefaults\n ? \"\"\n : readString(providerRoute?.apiKey) ??\n readString(process.env.NEXTCLAW_API_KEY) ??\n readString(process.env.ANTHROPIC_API_KEY) ??\n \"\";\n const apiBase = useClaudeRuntimeDefaults\n ? undefined\n : resolveClaudeCompatibleApiBase(\n readString(providerRoute?.apiBase) ??\n readString(process.env.NEXTCLAW_API_BASE) ??\n readString(process.env.ANTHROPIC_BASE_URL) ??\n readString(process.env.ANTHROPIC_API_URL),\n shouldUseAnthropicGateway(providerRoute?.headers),\n );\n const authToken = useClaudeRuntimeDefaults\n ? undefined\n : readString(process.env.ANTHROPIC_AUTH_TOKEN) ??\n readString(process.env.CLAUDE_CODE_OAUTH_TOKEN) ??\n resolveClaudeCompatibleAuthToken({ apiBase, apiKey });\n const model = useClaudeRuntimeDefaults\n ? undefined\n : readString(providerRoute?.model) ??\n readString(modelId) ??\n readString(process.env.NEXTCLAW_MODEL) ??\n readString(process.env.ANTHROPIC_MODEL);\n return {\n sessionId,\n apiKey,\n ...(useClaudeRuntimeDefaults ? { useClaudeRuntimeDefaults: true } : {}),\n authToken,\n apiBase,\n model,\n workingDirectory: cwd,\n sessionRuntimeId: readString(sessionMetadata.claude_session_id) ?? null,\n sessionMetadata,\n setSessionMetadata,\n baseQueryOptions: {\n permissionMode: \"bypassPermissions\",\n includePartialMessages: true,\n ...(useClaudeRuntimeDefaults\n ? { settingSources: [\"user\", \"project\", \"local\"] }\n : {}),\n },\n ...(apiBase && shouldUseAnthropicGateway(providerRoute?.headers)\n ? {\n anthropicGateway: {\n upstreamApiBase: apiBase,\n upstreamApiKey: apiKey,\n },\n }\n : {}),\n };\n };\n}\n\nfunction readApiMode(headers: Record<string, string> | undefined): string | undefined {\n for (const [key, value] of Object.entries(headers ?? {})) {\n if (key.toLowerCase() === NARP_API_MODE_HEADER) {\n return readString(value)?.toLowerCase();\n }\n }\n return undefined;\n}\n\nfunction readString(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizeApiBase(value: string | undefined): string | undefined {\n return readString(value)?.replace(/\\/+$/, \"\");\n}\n\nfunction resolveClaudeCompatibleApiBase(\n value: string | undefined,\n shouldPreserveOpenAiBase = false,\n): string | undefined {\n const apiBase = normalizeApiBase(value);\n if (!apiBase || shouldPreserveOpenAiBase || !isMiniMaxApiBase(apiBase)) {\n return apiBase;\n }\n if (apiBase.endsWith(\"/anthropic\")) {\n return apiBase;\n }\n return `${apiBase.replace(/\\/v1$/i, \"\")}/anthropic`;\n}\n\nfunction resolveClaudeCompatibleAuthToken(params: {\n apiBase?: string;\n apiKey: string;\n}): string | undefined {\n return params.apiBase && isMiniMaxApiBase(params.apiBase)\n ? readString(params.apiKey)\n : undefined;\n}\n\nfunction isMiniMaxApiBase(apiBase: string): boolean {\n try {\n const host = new URL(apiBase).hostname.toLowerCase();\n return host === \"api.minimaxi.com\" || host.endsWith(\".minimaxi.com\");\n } catch {\n return apiBase.toLowerCase().includes(\"api.minimaxi.com\");\n }\n}\n\nfunction shouldUseAnthropicGateway(headers: Record<string, string> | undefined): boolean {\n return readApiMode(headers) === \"chat_completions\";\n}\n"],"mappings":";;;AAUA,MAAM,uBAAuB;AAC7B,MAAM,8BAA8B;AAMpC,IAAa,+BAAb,MAA0C;CACxC,YACE,iBACE,WACG,IAAI,6BAA6B,OAAO,EAC7C;AAHiB,OAAA,gBAAA;;CAKnB,cAAoB;AAClB,MAAI,wBAAwB;GAC1B,WAAW;GACX,gBAAgB,YAAY,KAAK,wBAAwB,QAAQ;GAClE,CAAC,CAAC,OAAO;;CAGZ,2BACE,YACoB,KAAK,cAAc,KAAK,mBAAmB,QAAQ,CAAC;CAE1E,sBACE,YACuC;EACvC,MAAM,EAAE,KAAK,SAAS,YAAY,WAAW,uBAAuB;EACpE,MAAM,gBAAgB,WAAW;EACjC,MAAM,kBAAkB,WAAW,mBAAmB,EAAE;EACxD,MAAM,sBACJ,WAAW,gBAAgB,gBAAgB,IAC3C,WAAW,gBAAgB,eAAe,IAC1C,WAAW,gBAAgB,MAAM,IACjC,WAAW,QAAQ;EACrB,MAAM,2BACJ,CAAC,kBAAkB,CAAC,uBAAuB,wBAAwB;EACrE,MAAM,SAAS,2BACX,KACA,WAAW,eAAe,OAAO,IACjC,WAAW,QAAQ,IAAI,iBAAiB,IACxC,WAAW,QAAQ,IAAI,kBAAkB,IACzC;EACJ,MAAM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G;;AAG/C,SAAS,+BACP,OACA,2BAA2B,OACP;CACpB,MAAM,UAAU,iBAAiB,MAAM;AACvC,KAAI,CAAC,WAAW,4BAA4B,CAAC,iBAAiB,QAAQ,CACpE,QAAO;AAET,KAAI,QAAQ,SAAS,aAAa,CAChC,QAAO;AAET,QAAO,GAAG,QAAQ,QAAQ,UAAU,GAAG,CAAC;;AAG1C,SAAS,iCAAiC,QAGnB;AACrB,QAAO,OAAO,WAAW,iBAAiB,OAAO,QAAQ,GACrD,WAAW,OAAO,OAAO,GACzB,KAAA;;AAGN,SAAS,iBAAiB,SAA0B;AAClD,KAAI;EACF,MAAM,OAAO,IAAI,IAAI,QAAQ,CAAC,SAAS,aAAa;AACpD,SAAO,SAAS,sBAAsB,KAAK,SAAS,gBAAgB;SAC9D;AACN,SAAO,QAAQ,aAAa,CAAC,SAAS,mBAAmB;;;AAI7D,SAAS,0BAA0B,SAAsD;AACvF,QAAO,YAAY,QAAQ,KAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/nextclaw-narp-runtime-claude-code-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NARP stdio launcher for the NextClaw Claude Code SDK runtime.",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@nextclaw/ncp": "0.7.3",
|
|
23
|
-
"@nextclaw/nextclaw-narp-stdio-runtime-wrapper": "0.3.
|
|
24
|
-
"@nextclaw/nextclaw-ncp-runtime-claude-code-sdk": "0.2.
|
|
23
|
+
"@nextclaw/nextclaw-narp-stdio-runtime-wrapper": "0.3.4",
|
|
24
|
+
"@nextclaw/nextclaw-ncp-runtime-claude-code-sdk": "0.2.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^20.17.6",
|