fix(coding-agent): lazy-init OpenAI client to avoid top-level throw
This commit is contained in:
@@ -26,22 +26,15 @@ createApp(App).mount();
|
|||||||
|
|
||||||
```vue
|
```vue
|
||||||
<!-- src/App.vue -->
|
<!-- src/App.vue -->
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { shallowRef, defineComponent } from "vue";
|
import { shallowRef } from "vue";
|
||||||
import { Box, Text, useInput } from "@vue-tui/runtime";
|
import { Box, Text, useInput } from "@vue-tui/runtime";
|
||||||
|
|
||||||
export default defineComponent({
|
const count = shallowRef(0);
|
||||||
components: { Box, Text },
|
|
||||||
setup() {
|
|
||||||
const count = shallowRef(0);
|
|
||||||
|
|
||||||
useInput((input) => {
|
useInput((input) => {
|
||||||
if (input === "+") count.value++;
|
if (input === "+") count.value++;
|
||||||
if (input === "-") count.value--;
|
if (input === "-") count.value--;
|
||||||
});
|
|
||||||
|
|
||||||
return { count };
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,16 @@ export interface AgentOptions {
|
|||||||
requestApproval: (command: string) => Promise<boolean>;
|
requestApproval: (command: string) => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new OpenAI({
|
let client: OpenAI | undefined;
|
||||||
apiKey: process.env["DEEPSEEK_API_KEY"],
|
function getClient(): OpenAI {
|
||||||
baseURL: "https://api.deepseek.com",
|
if (!client) {
|
||||||
});
|
client = new OpenAI({
|
||||||
|
apiKey: process.env["DEEPSEEK_API_KEY"],
|
||||||
|
baseURL: "https://api.deepseek.com",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
const BASH_TOOL = {
|
const BASH_TOOL = {
|
||||||
type: "function" as const,
|
type: "function" as const,
|
||||||
@@ -83,7 +89,7 @@ export async function runAgentLoop(
|
|||||||
messages = [...messages, { role: "user", content: userMessage }];
|
messages = [...messages, { role: "user", content: userMessage }];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const stream = await client.chat.completions.create({
|
const stream = await getClient().chat.completions.create({
|
||||||
model: "deepseek-v4-pro",
|
model: "deepseek-v4-pro",
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "system", content: SYSTEM_PROMPT },
|
{ role: "system", content: SYSTEM_PROMPT },
|
||||||
|
|||||||
Reference in New Issue
Block a user