mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-13 17:22:37 +02:00
autosubmit mocked tool responses in editor
This commit is contained in:
parent
17d119f105
commit
4db69aea24
5 changed files with 51 additions and 19 deletions
|
|
@ -186,6 +186,7 @@ export const WorkflowTool = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
mockInPlayground: z.boolean().default(false).optional(),
|
mockInPlayground: z.boolean().default(false).optional(),
|
||||||
|
autoSubmitMockedResponse: z.boolean().default(false).optional(),
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
type: z.literal('object'),
|
type: z.literal('object'),
|
||||||
properties: z.record(z.object({
|
properties: z.record(z.object({
|
||||||
|
|
@ -216,6 +217,7 @@ export const AgenticAPIPrompt = WorkflowPrompt;
|
||||||
|
|
||||||
export const AgenticAPITool = WorkflowTool.omit({
|
export const AgenticAPITool = WorkflowTool.omit({
|
||||||
mockInPlayground: true,
|
mockInPlayground: true,
|
||||||
|
autoSubmitMockedResponse: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Workflow = z.object({
|
export const Workflow = z.object({
|
||||||
|
|
@ -433,7 +435,7 @@ export function convertWorkflowToAgenticAPI(workflow: z.infer<typeof Workflow>):
|
||||||
controlType: agent.controlType,
|
controlType: agent.controlType,
|
||||||
})),
|
})),
|
||||||
tools: workflow.tools.map(tool => {
|
tools: workflow.tools.map(tool => {
|
||||||
const { mockInPlayground, ...rest } = tool;
|
const { mockInPlayground, autoSubmitMockedResponse, ...rest } = tool;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,7 @@ export async function getAgenticApiResponse(
|
||||||
rawAPIResponse: unknown,
|
rawAPIResponse: unknown,
|
||||||
}> {
|
}> {
|
||||||
// call agentic api
|
// call agentic api
|
||||||
|
console.log(`agentic request`, JSON.stringify(request, null, 2));
|
||||||
const response = await fetch(process.env.AGENTIC_API_URL + '/chat', {
|
const response = await fetch(process.env.AGENTIC_API_URL + '/chat', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(request),
|
body: JSON.stringify(request),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
import { Button, Spinner, Textarea } from "@nextui-org/react";
|
import { Button, Spinner, Textarea } from "@nextui-org/react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { GetInformationToolResult, WebpageCrawlResponse, Workflow, WorkflowTool } from "@/app/lib/types";
|
import { GetInformationToolResult, WebpageCrawlResponse, Workflow, WorkflowTool } from "@/app/lib/types";
|
||||||
import { executeClientTool, getInformationTool, scrapeWebpage, suggestToolResponse } from "@/app/actions";
|
import { executeClientTool, getInformationTool, scrapeWebpage, suggestToolResponse } from "@/app/actions";
|
||||||
|
|
@ -201,6 +201,7 @@ function ToolCall({
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
sender={sender}
|
sender={sender}
|
||||||
|
autoSubmit={matchingWorkflowTool?.autoSubmitMockedResponse}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -504,6 +505,7 @@ function MockToolCall({
|
||||||
projectId,
|
projectId,
|
||||||
messages,
|
messages,
|
||||||
sender,
|
sender,
|
||||||
|
autoSubmit = false,
|
||||||
}: {
|
}: {
|
||||||
toolCall: z.infer<typeof apiV1.AssistantMessageWithToolCalls>['tool_calls'][number];
|
toolCall: z.infer<typeof apiV1.AssistantMessageWithToolCalls>['tool_calls'][number];
|
||||||
result: z.infer<typeof apiV1.ToolMessage> | undefined;
|
result: z.infer<typeof apiV1.ToolMessage> | undefined;
|
||||||
|
|
@ -511,11 +513,30 @@ function MockToolCall({
|
||||||
projectId: string;
|
projectId: string;
|
||||||
messages: z.infer<typeof apiV1.ChatMessage>[];
|
messages: z.infer<typeof apiV1.ChatMessage>[];
|
||||||
sender: string | null | undefined;
|
sender: string | null | undefined;
|
||||||
|
autoSubmit?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const [result, setResult] = useState<z.infer<typeof apiV1.ToolMessage> | undefined>(availableResult);
|
const [result, setResult] = useState<z.infer<typeof apiV1.ToolMessage> | undefined>(availableResult);
|
||||||
const [response, setResponse] = useState('');
|
const [response, setResponse] = useState('');
|
||||||
const [generatingResponse, setGeneratingResponse] = useState(false);
|
const [generatingResponse, setGeneratingResponse] = useState(false);
|
||||||
|
|
||||||
|
const handleSubmit = useCallback(() => {
|
||||||
|
let parsed;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(response);
|
||||||
|
} catch (e) {
|
||||||
|
alert('Invalid JSON');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result: z.infer<typeof apiV1.ToolMessage> = {
|
||||||
|
role: 'tool',
|
||||||
|
tool_call_id: toolCall.id,
|
||||||
|
tool_name: toolCall.function.name,
|
||||||
|
content: JSON.stringify(parsed),
|
||||||
|
};
|
||||||
|
setResult(result);
|
||||||
|
handleResult(result);
|
||||||
|
}, [toolCall.id, toolCall.function.name, handleResult, response]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (result) {
|
if (result) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -549,23 +570,18 @@ function MockToolCall({
|
||||||
};
|
};
|
||||||
}, [result, response, toolCall.id, projectId, messages]);
|
}, [result, response, toolCall.id, projectId, messages]);
|
||||||
|
|
||||||
function handleSubmit() {
|
// auto submit if autoSubmitMockedResponse is true
|
||||||
let parsed;
|
useEffect(() => {
|
||||||
try {
|
if (!autoSubmit) {
|
||||||
parsed = JSON.parse(response);
|
|
||||||
} catch (e) {
|
|
||||||
alert('Invalid JSON');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result: z.infer<typeof apiV1.ToolMessage> = {
|
if (result) {
|
||||||
role: 'tool',
|
return;
|
||||||
tool_call_id: toolCall.id,
|
|
||||||
tool_name: toolCall.function.name,
|
|
||||||
content: JSON.stringify(parsed),
|
|
||||||
};
|
|
||||||
setResult(result);
|
|
||||||
handleResult(result);
|
|
||||||
}
|
}
|
||||||
|
if (response) {
|
||||||
|
handleSubmit();
|
||||||
|
}
|
||||||
|
}, [autoSubmit, response, handleSubmit, result]);
|
||||||
|
|
||||||
return <div className="flex flex-col gap-1">
|
return <div className="flex flex-col gap-1">
|
||||||
{sender && <div className='text-gray-500 text-sm ml-3'>{sender}</div>}
|
{sender && <div className='text-gray-500 text-sm ml-3'>{sender}</div>}
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ export function ToolConfig({
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
key="mockInPlayground"
|
||||||
size="sm"
|
size="sm"
|
||||||
isSelected={tool.mockInPlayground ?? false}
|
isSelected={tool.mockInPlayground ?? false}
|
||||||
onValueChange={(value) => handleUpdate({
|
onValueChange={(value) => handleUpdate({
|
||||||
|
|
@ -235,6 +236,17 @@ export function ToolConfig({
|
||||||
>
|
>
|
||||||
Mock tool in Playground
|
Mock tool in Playground
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
|
{tool.mockInPlayground && <Checkbox
|
||||||
|
key="autoSubmitMockedResponse"
|
||||||
|
size="sm"
|
||||||
|
isSelected={tool.autoSubmitMockedResponse ?? false}
|
||||||
|
onValueChange={(value) => handleUpdate({
|
||||||
|
...tool,
|
||||||
|
autoSubmitMockedResponse: value
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
Auto-submit mocked response
|
||||||
|
</Checkbox>}
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,7 @@ function reducer(state: State, action: Action): State {
|
||||||
description: "",
|
description: "",
|
||||||
parameters: undefined,
|
parameters: undefined,
|
||||||
mockInPlayground: true,
|
mockInPlayground: true,
|
||||||
|
autoSubmitMockedResponse: true,
|
||||||
...action.tool
|
...action.tool
|
||||||
});
|
});
|
||||||
draft.selection = {
|
draft.selection = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue