@meetopenbot/claude-code 0.1.8 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/index.js +81 -32
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19371,18 +19371,25 @@ function uiWidget(args) {
19371
19371
 
19372
19372
  // credits-auth.ts
19373
19373
  var INTEGRATIONS_TOKEN_HEADER = "x-openbot-integrations-token";
19374
+ var CREDITS_API_KEY_PLACEHOLDER = "openbot-credits";
19375
+ var resolveCreditsAuthConfig = () => {
19376
+ const baseUrl = process.env.OPENBOT_INTEGRATIONS_BASE_URL?.trim();
19377
+ const token = process.env.OPENBOT_INTEGRATIONS_TOKEN?.trim();
19378
+ if (!baseUrl || !token) return void 0;
19379
+ return { baseUrl: baseUrl.replace(/\/$/, ""), token };
19380
+ };
19374
19381
  var buildCreditsAnthropicEnv = () => {
19375
- const integrationsBaseUrl = process.env.OPENBOT_INTEGRATIONS_BASE_URL?.trim();
19376
- const integrationsToken = process.env.OPENBOT_INTEGRATIONS_TOKEN?.trim();
19377
- if (!integrationsBaseUrl || !integrationsToken) return void 0;
19378
- const env = {
19379
- ANTHROPIC_BASE_URL: `${integrationsBaseUrl.replace(/\/$/, "")}/anthropic/v1`,
19380
- ANTHROPIC_CUSTOM_HEADERS: `${INTEGRATIONS_TOKEN_HEADER}: ${integrationsToken}`
19382
+ const config = resolveCreditsAuthConfig();
19383
+ if (!config) return void 0;
19384
+ const apiKey = config.token || CREDITS_API_KEY_PLACEHOLDER;
19385
+ return {
19386
+ ANTHROPIC_BASE_URL: `${config.baseUrl}/anthropic/v1`,
19387
+ ANTHROPIC_CUSTOM_HEADERS: `${INTEGRATIONS_TOKEN_HEADER}: ${config.token}`,
19388
+ ANTHROPIC_API_KEY: apiKey,
19389
+ // Prevent the CLI from preferring stored OAuth over gateway routing.
19390
+ CLAUDE_CODE_OAUTH_TOKEN: "",
19391
+ ANTHROPIC_AUTH_TOKEN: ""
19381
19392
  };
19382
- if (!process.env.ANTHROPIC_API_KEY?.trim()) {
19383
- env.ANTHROPIC_API_KEY = "openbot-credits";
19384
- }
19385
- return env;
19386
19393
  };
19387
19394
 
19388
19395
  // runtime.ts
@@ -19424,12 +19431,27 @@ var isCreditsErrorMessage = (message) => {
19424
19431
  const lower = message.toLowerCase();
19425
19432
  return lower.includes("insufficient_credits") || lower.includes("insufficient credits") || lower.includes("402");
19426
19433
  };
19434
+ var isIntegrationsProviderError = (message) => {
19435
+ const lower = message.toLowerCase();
19436
+ return lower.includes("provider api key not configured") || lower.includes("503") && lower.includes("provider");
19437
+ };
19438
+ var CREDITS_NOT_CONFIGURED_MESSAGE = "OpenBot Credits is not configured on this runtime. The cloud host must set OPENBOT_INTEGRATIONS_BASE_URL and OPENBOT_INTEGRATIONS_TOKEN (try redeploying the workspace).";
19439
+ var CREDITS_PROVIDER_UNAVAILABLE_MESSAGE = "OpenBot Credits could not reach Anthropic \u2014 the platform provider API key is not configured yet. Try again later or switch this agent to BYOK mode.";
19440
+ var CREDITS_AUTH_FAILED_MESSAGE = "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode.";
19427
19441
  var buildSdkEnv = (authMode) => {
19428
19442
  if (authMode !== "credits") return void 0;
19429
19443
  const creditsEnv = buildCreditsAnthropicEnv();
19430
19444
  if (!creditsEnv) return void 0;
19431
19445
  return { ...process.env, ...creditsEnv };
19432
19446
  };
19447
+ var creditsErrorMessage = (message) => {
19448
+ if (isIntegrationsProviderError(message)) return CREDITS_PROVIDER_UNAVAILABLE_MESSAGE;
19449
+ if (isCreditsErrorMessage(message)) {
19450
+ return "Insufficient workspace credits. Add credits in workspace settings or switch this agent to BYOK mode.";
19451
+ }
19452
+ if (isAuthErrorMessage(message)) return CREDITS_AUTH_FAILED_MESSAGE;
19453
+ return void 0;
19454
+ };
19433
19455
  var buildApiKeyWidget = (agentId, threadId, reason) => uiWidget({
19434
19456
  agentId,
19435
19457
  threadId,
@@ -19687,6 +19709,14 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19687
19709
  workingDir
19688
19710
  };
19689
19711
  const sdkEnv = buildSdkEnv(authMode);
19712
+ if (authMode === "credits" && !resolveCreditsAuthConfig()) {
19713
+ yield agentOutput({
19714
+ agentId: context.state.agentId,
19715
+ threadId,
19716
+ content: CREDITS_NOT_CONFIGURED_MESSAGE
19717
+ });
19718
+ return;
19719
+ }
19690
19720
  const sdkOptions = {
19691
19721
  model,
19692
19722
  permissionMode,
@@ -19703,6 +19733,7 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19703
19733
  try {
19704
19734
  let lastSessionId = resumeId;
19705
19735
  let authWidgetYielded = false;
19736
+ let creditsFailureYielded = false;
19706
19737
  const emittedToolCallIds = /* @__PURE__ */ new Set();
19707
19738
  const emittedToolResultIds = /* @__PURE__ */ new Set();
19708
19739
  const toolTitleByUseId = /* @__PURE__ */ new Map();
@@ -19716,7 +19747,7 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19716
19747
  yield agentOutput({
19717
19748
  agentId: context.state.agentId,
19718
19749
  threadId,
19719
- content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19750
+ content: creditsErrorMessage(message.error) ?? CREDITS_AUTH_FAILED_MESSAGE
19720
19751
  });
19721
19752
  } else {
19722
19753
  yield buildApiKeyWidget(context.state.agentId, threadId, message.error);
@@ -19778,11 +19809,20 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19778
19809
  if (textParts.length > 0) {
19779
19810
  const joined = textParts.join("\n");
19780
19811
  if (joined.length > 0) {
19781
- yield agentOutput({
19782
- agentId: context.state.agentId,
19783
- threadId,
19784
- content: joined
19785
- });
19812
+ if (authMode === "credits" && !creditsFailureYielded && isIntegrationsProviderError(joined)) {
19813
+ creditsFailureYielded = true;
19814
+ yield agentOutput({
19815
+ agentId: context.state.agentId,
19816
+ threadId,
19817
+ content: CREDITS_PROVIDER_UNAVAILABLE_MESSAGE
19818
+ });
19819
+ } else {
19820
+ yield agentOutput({
19821
+ agentId: context.state.agentId,
19822
+ threadId,
19823
+ content: joined
19824
+ });
19825
+ }
19786
19826
  }
19787
19827
  }
19788
19828
  }
@@ -19822,13 +19862,19 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19822
19862
  if (message.type === "result" && message.subtype !== "success") {
19823
19863
  const subtype = message.subtype;
19824
19864
  const resultText = "result" in message && typeof message.result === "string" ? message.result : "";
19825
- if (authMode === "credits" && (isCreditsErrorMessage(subtype) || isCreditsErrorMessage(resultText))) {
19826
- yield agentOutput({
19827
- agentId: context.state.agentId,
19828
- threadId,
19829
- content: "Insufficient workspace credits. Add credits in workspace settings or switch this agent to BYOK mode."
19830
- });
19831
- return;
19865
+ const errorText = resultText || subtype;
19866
+ if (authMode === "credits") {
19867
+ const creditsMessage = creditsErrorMessage(errorText);
19868
+ if (creditsMessage && !creditsFailureYielded) {
19869
+ creditsFailureYielded = true;
19870
+ yield agentOutput({
19871
+ agentId: context.state.agentId,
19872
+ threadId,
19873
+ content: creditsMessage
19874
+ });
19875
+ return;
19876
+ }
19877
+ if (creditsFailureYielded) return;
19832
19878
  }
19833
19879
  if (!authWidgetYielded && (isAuthErrorMessage(subtype) || isAuthErrorMessage(resultText))) {
19834
19880
  authWidgetYielded = true;
@@ -19836,7 +19882,7 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19836
19882
  yield agentOutput({
19837
19883
  agentId: context.state.agentId,
19838
19884
  threadId,
19839
- content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19885
+ content: creditsErrorMessage(resultText || subtype) ?? CREDITS_AUTH_FAILED_MESSAGE
19840
19886
  });
19841
19887
  } else {
19842
19888
  yield buildApiKeyWidget(context.state.agentId, threadId, subtype);
@@ -19857,20 +19903,23 @@ ${details}` : `[claude-code] run ended with error: ${subtype}`
19857
19903
  }
19858
19904
  } catch (error) {
19859
19905
  const errorMessage = formatClaudeCodeError(error, launchContext, stderrChunks);
19860
- if (authMode === "credits" && isCreditsErrorMessage(errorMessage)) {
19861
- yield agentOutput({
19862
- agentId: context.state.agentId,
19863
- threadId,
19864
- content: "Insufficient workspace credits. Add credits in workspace settings or switch this agent to BYOK mode."
19865
- });
19866
- return;
19906
+ if (authMode === "credits") {
19907
+ const creditsMessage = creditsErrorMessage(errorMessage);
19908
+ if (creditsMessage) {
19909
+ yield agentOutput({
19910
+ agentId: context.state.agentId,
19911
+ threadId,
19912
+ content: creditsMessage
19913
+ });
19914
+ return;
19915
+ }
19867
19916
  }
19868
19917
  if (isAuthErrorMessage(errorMessage)) {
19869
19918
  if (authMode === "credits") {
19870
19919
  yield agentOutput({
19871
19920
  agentId: context.state.agentId,
19872
19921
  threadId,
19873
- content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19922
+ content: creditsErrorMessage(errorMessage) ?? CREDITS_AUTH_FAILED_MESSAGE
19874
19923
  });
19875
19924
  } else {
19876
19925
  yield buildApiKeyWidget(context.state.agentId, threadId, errorMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/claude-code",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Claude Code plugin for OpenBot",
6
6
  "main": "./dist/index.js",