opencode-crs-bedrock 1.0.4 → 1.0.6

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/index.ts +34 -4
  2. package/package.json +2 -1
package/index.ts CHANGED
@@ -434,8 +434,37 @@ class SSETransformState {
434
434
  controller: TransformStreamDefaultController<string>
435
435
  ): void {
436
436
  for (const [blockIndex, pending] of this.pendingToolBlocks) {
437
- const inferredName =
438
- inferToolName(pending.inputBuffer, this.toolSchemas) || "unknown";
437
+ const inferredName = inferToolName(pending.inputBuffer, this.toolSchemas);
438
+
439
+ // If we couldn't infer a tool name, emit a helpful text block instead of a broken tool_use
440
+ if (!inferredName) {
441
+ debugLog(
442
+ "Could not infer tool name for block",
443
+ blockIndex,
444
+ "- converting to text with available tools list"
445
+ );
446
+
447
+ const availableTools = Array.from(this.toolSchemas.keys()).join(", ");
448
+ const helpText = `Tool inference failed. The model attempted to call a tool but the tool name could not be determined from the input parameters. Available tools: ${availableTools}. Please specify which tool you want to use.`;
449
+
450
+ // Emit as a text block instead of a tool_use
451
+ emitSSEEvent(controller, "content_block_start", {
452
+ type: "content_block_start",
453
+ index: blockIndex,
454
+ content_block: {
455
+ type: "text",
456
+ text: helpText,
457
+ },
458
+ });
459
+
460
+ emitSSEEvent(controller, "content_block_stop", {
461
+ type: "content_block_stop",
462
+ index: blockIndex,
463
+ });
464
+
465
+ continue;
466
+ }
467
+
439
468
  debugLog(
440
469
  "Flushing pending tool block",
441
470
  blockIndex,
@@ -1041,10 +1070,11 @@ export const CRSAuthPlugin: Plugin = async ({ client }: PluginContext) => {
1041
1070
  debugLog("CRS auth loader called");
1042
1071
 
1043
1072
  const auth = await getAuth();
1044
- const apiKey = auth.apiKey as string | undefined;
1073
+ // OpenCode stores API keys as 'key' field when type is 'api'
1074
+ const apiKey = (auth.key || auth.apiKey) as string | undefined;
1045
1075
  const baseURL = (auth.baseURL as string | undefined) || process.env.ANTHROPIC_BASE_URL || "https://crs.tonob.net/api";
1046
1076
 
1047
- debugLog("Auth details:", { hasApiKey: !!apiKey, baseURL });
1077
+ debugLog("Auth details:", { hasApiKey: !!apiKey, baseURL, authKeys: Object.keys(auth) });
1048
1078
 
1049
1079
  if (!apiKey) {
1050
1080
  debugLog("No API key found, returning baseURL only");
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "opencode-crs-bedrock",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "OpenCode plugin for FeedMob CRS proxy to AWS Bedrock Anthropic models",
5
5
  "type": "module",
6
+ "main": "index.ts",
6
7
  "module": "index.ts",
7
8
  "files": [
8
9
  "index.ts"