From 32ec1d433dba9435c72a3cef9cdd4c731938a3ca Mon Sep 17 00:00:00 2001 From: David Souther Date: Thu, 6 Jun 2024 07:42:31 -0400 Subject: [PATCH] Better detect and message unknown CLI region (#150) --- cli/src/index.ts | 5 +++-- core/src/engine/bedrock/bedrock.ts | 7 ++++++- extension/src/extension.ts | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cli/src/index.ts b/cli/src/index.ts index 0e4102b..c5d0301 100755 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -40,6 +40,7 @@ export async function main() { loaded.settings ); + const isStdOut = loaded.content.at(-1) == "/dev/stdout"; switch (true) { case args.values["update-db"]: await generator.updateDatabase(); @@ -67,7 +68,7 @@ export async function main() { LOGGER.info(`Starting ${loaded.content.length} requests`); generator.start(); - if (loaded.content.at(-1) == "/dev/stdout") { + if (isStdOut) { loaded.content.splice(-1, 1); const prompt = loaded.context["/dev/stdout"]; const edit = prompt.context.edit; @@ -93,7 +94,7 @@ export async function main() { const errors = generator .errors() .filter((c) => c.content.name != "/dev/stdout"); - if (errors.length > 0) { + if (errors.length > 0 && !isStdOut) { console.error( [ "There were errors when generating responses:", diff --git a/core/src/engine/bedrock/bedrock.ts b/core/src/engine/bedrock/bedrock.ts index c14b854..a42fca1 100644 --- a/core/src/engine/bedrock/bedrock.ts +++ b/core/src/engine/bedrock/bedrock.ts @@ -26,6 +26,7 @@ export interface BedrockDebug extends EngineDebug { }; finish?: string; error?: Error; + region?: string; id: string; } @@ -83,6 +84,7 @@ export const generate: EngineGenerate = ( model, engine: "bedrock", }; + bedrock.config.region().then((region) => (debug.region = region)); const stream = new TransformStream(); const writer = stream.writable.getWriter(); const invokeModelCommand = { @@ -228,7 +230,10 @@ export function formatError(content: Content) { try { const { message } = content.meta!.debug!.error!; const model = content.meta!.debug!.model!; - const region = process.env["AWS_REGION"] ?? makeClient().config.region; + const region = + process.env["AWS_REGION"] ?? + (content.meta?.debug as BedrockDebug | undefined)?.region ?? + "unknown region"; let base = "There was an error calling Bedrock. "; switch (message) { case "The security token included in the request is invalid.": diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 8a10ad3..94c4fbd 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -1,7 +1,7 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import * as vscode from "vscode"; -import path, { basename } from "path"; +import { basename } from "path"; import { generate, type ExtensionEdit } from "./generate.js"; import { LOGGER, resetLogger } from "./settings.js"; import {