fix: correct handling of claude response
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -133,3 +133,4 @@ dist
|
||||
|
||||
.DS_Store
|
||||
.vercel
|
||||
.env*.local
|
||||
|
||||
@@ -37,6 +37,7 @@ export const Content = () => {
|
||||
try {
|
||||
downloadJson(consumer, 'consumer.json');
|
||||
} catch (err) {
|
||||
console.error('Failed to download consumer data', err);
|
||||
showToast('Failed to download consumer data');
|
||||
}
|
||||
};
|
||||
@@ -46,6 +47,7 @@ export const Content = () => {
|
||||
try {
|
||||
downloadJson(purchasesResult, 'purchases.json');
|
||||
} catch (err) {
|
||||
console.error('Failed to download purchase history', err);
|
||||
showToast('Failed to download purchase history');
|
||||
}
|
||||
};
|
||||
@@ -69,6 +71,7 @@ export const Content = () => {
|
||||
setConsumer(data.consumer);
|
||||
setEditedConsumer(JSON.stringify(data.consumer, null, 2));
|
||||
} catch (err) {
|
||||
console.error('Something went wrong', err);
|
||||
if (axios.isAxiosError(err)) {
|
||||
const errorMessage = err.response?.data?.error || err.message;
|
||||
showToast(errorMessage);
|
||||
@@ -119,6 +122,7 @@ export const Content = () => {
|
||||
|
||||
setPurchasesResult(data);
|
||||
} catch (err) {
|
||||
console.error('Something went wrong', err);
|
||||
if (axios.isAxiosError(err)) {
|
||||
const errorMessage = err.response?.data?.error || err.message;
|
||||
showToast(errorMessage);
|
||||
|
||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -2,4 +2,4 @@
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
||||
@@ -11,6 +11,13 @@ export interface BaseTool {
|
||||
};
|
||||
}
|
||||
|
||||
export type ToolUseBlock = {
|
||||
type: 'tool_use';
|
||||
id: string;
|
||||
name: string;
|
||||
input: Record<string, any>;
|
||||
};
|
||||
|
||||
export async function makeRequest<T extends BaseTool>(prompt: string, tool: T) {
|
||||
if (!process.env.ANTHROPIC_API_KEY) {
|
||||
throw Error('No Anthropic API key found.');
|
||||
@@ -20,7 +27,7 @@ export async function makeRequest<T extends BaseTool>(prompt: string, tool: T) {
|
||||
|
||||
try {
|
||||
const response = await client.messages.create({
|
||||
model: 'claude-sonnet-4-20250514',
|
||||
model: 'claude-sonnet-4-0',
|
||||
max_tokens: 8192,
|
||||
temperature: 1,
|
||||
tools: [tool],
|
||||
@@ -35,13 +42,17 @@ export async function makeRequest<T extends BaseTool>(prompt: string, tool: T) {
|
||||
throw Error(JSON.stringify(response));
|
||||
}
|
||||
|
||||
const content = response.content as [
|
||||
{ type: string; text: string },
|
||||
{ type: string; input: object }
|
||||
];
|
||||
const content = response.content;
|
||||
|
||||
return content[1].input;
|
||||
const toolUse = content.find((block): block is ToolUseBlock => block.type === 'tool_use');
|
||||
|
||||
if (!toolUse) {
|
||||
throw new Error('No tool_use block found in response');
|
||||
}
|
||||
|
||||
return toolUse.input;
|
||||
} catch (error) {
|
||||
console.error('Error making request:', error);
|
||||
throw Error('Anthropic client error.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user