@meetopenbot/claude-code 0.1.7 → 0.1.8

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 +98 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // cloud-mode.ts
2
+ var isCloudMode = () => process.env.OPENBOT_CLOUD_MODE === "1";
3
+ var defaultAuthMode = () => isCloudMode() ? "credits" : "byok";
4
+
1
5
  // runtime.ts
2
6
  import { execSync } from "node:child_process";
3
7
  import { existsSync as existsSync2, readlinkSync as readlinkSync2, statSync as statSync2 } from "node:fs";
@@ -19365,6 +19369,22 @@ function uiWidget(args) {
19365
19369
  };
19366
19370
  }
19367
19371
 
19372
+ // credits-auth.ts
19373
+ var INTEGRATIONS_TOKEN_HEADER = "x-openbot-integrations-token";
19374
+ 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}`
19381
+ };
19382
+ if (!process.env.ANTHROPIC_API_KEY?.trim()) {
19383
+ env.ANTHROPIC_API_KEY = "openbot-credits";
19384
+ }
19385
+ return env;
19386
+ };
19387
+
19368
19388
  // runtime.ts
19369
19389
  var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
19370
19390
  var readPersistedSessionId = (state) => {
@@ -19400,6 +19420,16 @@ var isAuthErrorMessage = (message) => {
19400
19420
  const lower = message.toLowerCase();
19401
19421
  return AUTH_ERROR_PATTERNS.some((p) => lower.includes(p));
19402
19422
  };
19423
+ var isCreditsErrorMessage = (message) => {
19424
+ const lower = message.toLowerCase();
19425
+ return lower.includes("insufficient_credits") || lower.includes("insufficient credits") || lower.includes("402");
19426
+ };
19427
+ var buildSdkEnv = (authMode) => {
19428
+ if (authMode !== "credits") return void 0;
19429
+ const creditsEnv = buildCreditsAnthropicEnv();
19430
+ if (!creditsEnv) return void 0;
19431
+ return { ...process.env, ...creditsEnv };
19432
+ };
19403
19433
  var buildApiKeyWidget = (agentId, threadId, reason) => uiWidget({
19404
19434
  agentId,
19405
19435
  threadId,
@@ -19638,7 +19668,8 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19638
19668
  cwd,
19639
19669
  executablePath: executablePathOverride,
19640
19670
  allowedTools,
19641
- storage
19671
+ storage,
19672
+ authMode = defaultAuthMode()
19642
19673
  } = options;
19643
19674
  const executablePath = executablePathOverride || findClaudeExecutable();
19644
19675
  builder.on("agent:invoke", async function* (event, context) {
@@ -19655,6 +19686,7 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19655
19686
  executablePath,
19656
19687
  workingDir
19657
19688
  };
19689
+ const sdkEnv = buildSdkEnv(authMode);
19658
19690
  const sdkOptions = {
19659
19691
  model,
19660
19692
  permissionMode,
@@ -19665,7 +19697,8 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19665
19697
  ...resumeId ? { resume: resumeId } : {},
19666
19698
  ...workingDir ? { cwd: workingDir } : {},
19667
19699
  ...executablePath ? { pathToClaudeCodeExecutable: executablePath } : {},
19668
- ...allowedTools ? { allowedTools } : {}
19700
+ ...allowedTools ? { allowedTools } : {},
19701
+ ...sdkEnv ? { env: sdkEnv } : {}
19669
19702
  };
19670
19703
  try {
19671
19704
  let lastSessionId = resumeId;
@@ -19679,12 +19712,20 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19679
19712
  }
19680
19713
  if (!authWidgetYielded && message.type === "assistant" && (message.error === "authentication_failed" || message.error === "oauth_org_not_allowed")) {
19681
19714
  authWidgetYielded = true;
19682
- yield buildApiKeyWidget(context.state.agentId, threadId, message.error);
19683
- yield agentOutput({
19684
- agentId: context.state.agentId,
19685
- threadId,
19686
- content: "Claude needs an API key to continue. Please provide ANTHROPIC_API_KEY as a variable from the workspace settings or inside the widget above."
19687
- });
19715
+ if (authMode === "credits") {
19716
+ yield agentOutput({
19717
+ agentId: context.state.agentId,
19718
+ threadId,
19719
+ content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19720
+ });
19721
+ } else {
19722
+ yield buildApiKeyWidget(context.state.agentId, threadId, message.error);
19723
+ yield agentOutput({
19724
+ agentId: context.state.agentId,
19725
+ threadId,
19726
+ content: "Claude needs an API key to continue. Please provide ANTHROPIC_API_KEY as a variable from the workspace settings or inside the widget above."
19727
+ });
19728
+ }
19688
19729
  return;
19689
19730
  }
19690
19731
  if (message.type === "assistant") {
@@ -19781,9 +19822,25 @@ var claudeCodeRuntime = (options = {}) => (builder) => {
19781
19822
  if (message.type === "result" && message.subtype !== "success") {
19782
19823
  const subtype = message.subtype;
19783
19824
  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;
19832
+ }
19784
19833
  if (!authWidgetYielded && (isAuthErrorMessage(subtype) || isAuthErrorMessage(resultText))) {
19785
19834
  authWidgetYielded = true;
19786
- yield buildApiKeyWidget(context.state.agentId, threadId, subtype);
19835
+ if (authMode === "credits") {
19836
+ yield agentOutput({
19837
+ agentId: context.state.agentId,
19838
+ threadId,
19839
+ content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19840
+ });
19841
+ } else {
19842
+ yield buildApiKeyWidget(context.state.agentId, threadId, subtype);
19843
+ }
19787
19844
  return;
19788
19845
  }
19789
19846
  const details = formatResultError(message);
@@ -19800,8 +19857,24 @@ ${details}` : `[claude-code] run ended with error: ${subtype}`
19800
19857
  }
19801
19858
  } catch (error) {
19802
19859
  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;
19867
+ }
19803
19868
  if (isAuthErrorMessage(errorMessage)) {
19804
- yield buildApiKeyWidget(context.state.agentId, threadId, errorMessage);
19869
+ if (authMode === "credits") {
19870
+ yield agentOutput({
19871
+ agentId: context.state.agentId,
19872
+ threadId,
19873
+ content: "Claude could not authenticate via OpenBot Credits. Check your workspace credit balance in settings, or switch this agent to BYOK mode."
19874
+ });
19875
+ } else {
19876
+ yield buildApiKeyWidget(context.state.agentId, threadId, errorMessage);
19877
+ }
19805
19878
  return;
19806
19879
  }
19807
19880
  yield agentOutput({
@@ -19861,6 +19934,12 @@ Your goal is to help the user with their coding tasks.
19861
19934
  `;
19862
19935
 
19863
19936
  // index.ts
19937
+ var resolveAuthMode = (config) => {
19938
+ if (config.authMode === "byok" || config.authMode === "credits") {
19939
+ return config.authMode;
19940
+ }
19941
+ return defaultAuthMode();
19942
+ };
19864
19943
  var claudeCodePlugin = {
19865
19944
  id: "claude-code",
19866
19945
  name: "Claude Code",
@@ -19868,6 +19947,14 @@ var claudeCodePlugin = {
19868
19947
  configSchema: {
19869
19948
  type: "object",
19870
19949
  properties: {
19950
+ ...isCloudMode() ? {
19951
+ authMode: {
19952
+ type: "string",
19953
+ description: "Credits \u2014 use your workspace credit balance via OpenBot. BYOK \u2014 bring your own Anthropic API key.",
19954
+ enum: ["credits", "byok"],
19955
+ default: "credits"
19956
+ }
19957
+ } : {},
19871
19958
  model: {
19872
19959
  type: "string",
19873
19960
  description: "Claude model alias or full id (e.g. sonnet, opus, claude-opus-4-5).",
@@ -19893,6 +19980,7 @@ var claudeCodePlugin = {
19893
19980
  model,
19894
19981
  permissionMode,
19895
19982
  executablePath,
19983
+ authMode: resolveAuthMode(config),
19896
19984
  system: agentDetails.instructions || CLAUDE_CODE_SYSTEM_PROMPT,
19897
19985
  storage
19898
19986
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/claude-code",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "Claude Code plugin for OpenBot",
6
6
  "main": "./dist/index.js",