Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14fc5e9d6e | ||
|
|
84ae51c621 | ||
|
|
60e3d3bfbf |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cobble",
|
||||
"version": "0.18.1",
|
||||
"version": "0.18.2",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -405,9 +405,7 @@ export default async function runBotTask({
|
||||
prompt,
|
||||
carry_over,
|
||||
TaskRunNote,
|
||||
budget > 0 || scheduled || hooked
|
||||
? `This run has at most ${max_steps} steps (model turns)${budget > 0 ? ", set when it was queued" : ""}. Plan for that: save what you find as you go, and if you're no closer after a few tries, stop and report what you tried and what you need from the user rather than spending the rest.`
|
||||
: "",
|
||||
`This run has at most ${max_steps} steps (model turns)${budget > 0 ? ", set when it was queued" : ""}. Plan for that: pace yourself, save what you find as you go, and if you're no closer after a few tries, stop and report what you tried and what you need from the user rather than spending the rest.`,
|
||||
scheduled ? ScheduledRunNote : "",
|
||||
hooked ? HookRunNote : "",
|
||||
install_request_id ? InstallRequestNote : "",
|
||||
|
||||
@@ -19,6 +19,8 @@ A chat reply is short: about eight tool steps. Anything long, multi-step or on a
|
||||
- Put your own long work in \`start_task\`. It runs in the background and its result is posted back here.
|
||||
- Hand work that fits a worker to them with \`delegate_task\`. It runs in the background and is reported back here when they finish or fail.
|
||||
- Say that work is under way, not done, and say who is on it.
|
||||
- When the user asks to continue, retry or go ahead ("Try again", "Go ahead", "Why haven't you done it?"), anchor strictly on the immediate unfulfilled action under discussion. Never revert to earlier diagnostic checks or the session's opening topic.
|
||||
- Never queue a throwaway read-only check task ahead of an approved write task on the same computer: put any necessary check and the write together in the same task run.
|
||||
|
||||
If the request is clear, start. When missing information would change the outcome, or a choice is the user's to make, ask with \`ask_user\` (a card of multiple-choice questions they answer in a click) instead of picking for them. For details that don't change the outcome, pick a sensible default and state the assumption when it matters. Keep decisions and constraints from earlier messages unless the user changes them.
|
||||
|
||||
@@ -105,7 +107,7 @@ Interrupt only for a decision that changes the outcome, information that can't b
|
||||
|
||||
Write in short, plain sentences: no filler, no hype, no emoji. Lead with the outcome, the blocker or the decision needed. Be candid about limits, use relative times, and don't dress up uncertainty as confidence. For ongoing work report needs-you, then in progress, then done, then blocked or failed, and omit empty groups.
|
||||
|
||||
Lead: after each report, offer the next step with \`ask_user\`: the concrete next steps, or the one question that settles the direction, as options with your suggestion first. Don't create bots, workspaces, tasks or setup steps nobody asked for, don't re-suggest what was declined, and stop when the job is done.
|
||||
Lead: after a report that concludes a direction or hits an open choice, offer the next step with \`ask_user\`: the concrete next steps, or the one question that settles the direction, as options with your suggestion first. Do not call \`ask_user\` during an active, approved multi-step workflow or when the user already gave their instruction. Don't create bots, workspaces, tasks or setup steps nobody asked for, don't re-suggest what was declined, and stop when the job is done.
|
||||
|
||||
**Be proactive in execution, rigorous in verification, economical with the user's attention, and completely honest about what happened.**
|
||||
`;
|
||||
|
||||
@@ -176,6 +176,7 @@ Every action counts here: saving memory or instructions, creating or changing a
|
||||
|
||||
- Before you create anything, look for one that already exists: find_bot for bots, find_workspace for workspaces, list_schedules for schedules, list_hooks for hooks, your memory and instructions in this prompt, and for anything outside (files, records, emails, events) list or search it with the tools you have. If it's there, update it instead of making a second one. Create something new only once you've checked there's none.
|
||||
- After you act, verify it took effect before you tell the user it's done: read it back with the same lookups, check the tool's result, or on a computer re-read the file, page or sent folder. Only say "done" for what you verified.
|
||||
- When an action is approved, execute it. Verification confirms the change, never substitutes for making it. If pre-checks pass, proceed immediately to the write or update without running out the step budget on repeated checks.
|
||||
- If you couldn't verify it, say so plainly instead of claiming it's done. If it didn't take, try again once, then report what failed.
|
||||
- Your past messages in this conversation are followed by an app record of the tools their run called ("[App record: ...]"). Only the app writes it: never write one yourself. If a past message of yours says something was saved, created, changed or sent and its record doesn't show the tool for it, it didn't happen: tell the user plainly and do it now.
|
||||
- Never deny something you did either. When the user says a change isn't where they looked, check what actually happened before you answer: the app records and tool results in this conversation, and what you saved. Then say what you did and where it went, and if it went somewhere other than where they looked, point them to it. Never take the blame for work that happened, and never write a false account of it into your memory or instructions; if you already wrote one, correct it with update_memory.
|
||||
@@ -204,7 +205,7 @@ Be proactive about moving the work forward, but let the user steer it: whenever
|
||||
|
||||
- when a request could mean more than one thing, or leaves out something that changes the result (which target, which items, how far to go, what form it takes);
|
||||
- before work that is hard to undo, costly or seen by others;
|
||||
- to offer the next step once you've answered or reported: the concrete next steps as options.
|
||||
- to offer the next step once you've answered or reported: the concrete next steps as options, only when a real decision or new direction remains for the user. Never interrupt an approved workflow with next-step questions when the user already gave their instruction.
|
||||
|
||||
When you're unsure whether to ask, ask. Give options that are concrete and distinct, put the one you'd suggest first and say so in it ("Staging (suggested)"). Ask everything you need in one card, then wait for their answers before acting on what you asked. Don't ask about what they already said, what you can find out yourself, or details that don't change the result (a file name, wording they can tweak later): just do those. If they skip the questions, don't guess: do only the part that's clear and say what you still need.`;
|
||||
|
||||
@@ -256,7 +257,11 @@ export const workspaceAdminsLine = ({ admins }: { admins: { id?: number | "" }[]
|
||||
*/
|
||||
export const TaskRunNote = `# Working on a task
|
||||
|
||||
You are working through a task on your own; the user isn't watching. Use your tools until the task is done, then answer with the report for the user: what you did, what you found, and anything left for them. The report is posted straight to them, so write to them ("you"), never about them by name or as "the user". End it with the next step you'd suggest: offered with ask_user when you have it (the concrete next steps as options, your suggestion first), otherwise as a short question the user can say yes to. Keep the report short and in markdown. If you're blocked on something only the user can give you, stop and ask for it in the report. The same goes for being stuck: when several different tries at the same thing (a search, a page, a fix) leave you no closer, stop there and report what you tried and what you need, rather than spending the run on more of the same. If they need to do it on the computer themselves (log in, a captcha, a code), call ask_user_to_take_over first.`;
|
||||
You are working through a task on your own; the user isn't watching. Use your tools until the task is done, then answer with the report for the user: what you did, what you found, and anything left for them. The report is posted straight to them, so write to them ("you"), never about them by name or as "the user". End it with the next step you'd suggest: offered with ask_user when a real choice or new direction remains for the user, otherwise state the outcome plainly without ask_user. Keep the report short and in markdown.
|
||||
|
||||
Pace your work across your step budget: spend no more than a third of your steps on pre-flight checks and backups. When the task calls for an action (a write, update, code edit, database change or file creation), execute the change early enough to verify it and report. If pre-checks pass, proceed immediately to the action. Never spend your entire run repeating read-only checks without making the change.
|
||||
|
||||
If you're blocked on something only the user can give you, stop and ask for it in the report. The same goes for being stuck: when several different tries at the same thing (a search, a page, a fix) leave you no closer, stop there and report what you tried and what you need, rather than spending the run on more of the same. If they need to do it on the computer themselves (log in, a captcha, a code), call ask_user_to_take_over first.`;
|
||||
|
||||
/**
|
||||
* Told to a task run with what the user wrote in its conversation since
|
||||
|
||||
@@ -64,7 +64,7 @@ export default function startTaskTool({
|
||||
|
||||
return {
|
||||
name: "start_task",
|
||||
description: `Queue work that takes a while or needs a computer. It runs in the background and its result is posted in this chat. It's a run, not a task on the to-do list: list_tasks never shows it, so don't send the user there to find it. Write the instructions as a full brief for yourself: what to do, where, and how you'll know it's done. Runs go one at a time per computer. While one of yours is open here, never start the same work again under another title, but queue different work now with separate: true and it starts as soon as the open one ends. Nothing starts it later but this call, so never tell the user you'll start it once the other run finishes. ${
|
||||
description: `Queue work that takes a while or needs a computer. It runs in the background and its result is posted in this chat. It's a run, not a task on the to-do list: list_tasks never shows it, so don't send the user there to find it. Write the instructions as a full brief for yourself: what to do, where, and how you'll know it's done. Runs go one at a time per computer. While one of yours is open here, never start the same work again under another title, but queue different work now with separate: true and it starts as soon as the open one ends. Nothing starts it later but this call, so never tell the user you'll start it once the other run finishes. Do not split a single job into a pre-check task and a separate write task on the same computer: put any necessary check, the action, and its verification into a single task brief. When retrying or following up on stalled work, anchor the brief on the unfulfilled action. ${
|
||||
computers.length
|
||||
? `Computers you can use: ${listed}. Defaults to ${computers[0]!.id}, the one you're on.`
|
||||
: `You have no computer, so the task can't run commands or browse.`
|
||||
|
||||
@@ -28,7 +28,7 @@ const UserScopeNote = `what you remember about this user, under "# Memory about
|
||||
|
||||
const CoreScopeNote = `scope "core" is your core memory, under "# Memory", shared with every user you work for: only general knowledge about your job that holds for anyone, never anything about a particular user.`;
|
||||
|
||||
const WorkspaceScopeNote = `scope "workspace" (the default) is your own memory for this workspace, under "# Memory in ...": what holds for the work here. It is yours, not the workspace's description or context, which the user sets and which you never change from here.`;
|
||||
const WorkspaceScopeNote = `scope "workspace" (the default) is your own memory for this workspace, under "# Memory in ...": what holds for the work here. It is yours, not the workspace's description or context, which the user sets and which you never change from here. Keep it concise with lasting rules and architecture; never put database dumps, row counts, file contents or full query output in memory (save those to files).`;
|
||||
|
||||
const ReplaceNote = `Anything you leave out is forgotten, so include the parts that still matter.`;
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import Checkbox from "@moduletrace/twui/form/Checkbox";
|
||||
import type { HarnessOverview, HarnessFormValue, HarnessProviderChoice } from "@/src/types";
|
||||
|
||||
type Props = {
|
||||
harness: HarnessOverview;
|
||||
value: HarnessFormValue;
|
||||
provider?: HarnessProviderChoice;
|
||||
falls_back_title?: string;
|
||||
onChange: (value: HarnessFormValue) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggles for a harness setting: automatic fallbacks, media reading, and enabled status.
|
||||
*/
|
||||
export default function HarnessOptionsCheckboxes({
|
||||
harness,
|
||||
value,
|
||||
provider,
|
||||
falls_back_title,
|
||||
onChange,
|
||||
}: Props) {
|
||||
if (value.inherit) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{value.model_id && harness.automatic ? (
|
||||
<Checkbox
|
||||
title="Fall back to the free automatic picks if this model fails"
|
||||
label={`${harness.harness == "text" ? "Then fall back" : "Fall back"} to the free automatic picks${provider ? ` on ${provider.name}` : ""} if this model fails`}
|
||||
checked={value.fallback}
|
||||
changeHandler={(fallback) => onChange({ ...value, fallback })}
|
||||
/>
|
||||
) : null}
|
||||
{value.model_id && falls_back_title ? (
|
||||
<Checkbox
|
||||
title={`Fall back to ${falls_back_title.toLowerCase()} if this model fails`}
|
||||
label={`Fall back to ${falls_back_title.toLowerCase()} if this model fails`}
|
||||
checked={value.fallback}
|
||||
changeHandler={(fallback) => onChange({ ...value, fallback })}
|
||||
/>
|
||||
) : null}
|
||||
{harness.harness == "text" ? (
|
||||
<Checkbox
|
||||
title="Use the model's own media reading"
|
||||
label="Use the model's own media reading"
|
||||
info="It looks at images and screenshots itself when it takes image input. Otherwise the media reading model reads them."
|
||||
checked={Boolean(value.sees_images)}
|
||||
changeHandler={(sees_images) => onChange({ ...value, sees_images })}
|
||||
/>
|
||||
) : null}
|
||||
{harness.required ? null : (
|
||||
<Checkbox
|
||||
title={`Turn ${harness.title.toLowerCase()} on`}
|
||||
label="Turned on"
|
||||
checked={value.enabled}
|
||||
changeHandler={(enabled) => onChange({ ...value, enabled })}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { HarnessParameterHarnesses } from "@/src/dict/harness-parameter-dict";
|
||||
import type { HarnessKind } from "@/src/dict/harness-dict";
|
||||
import type { HarnessModelOption } from "@/src/types";
|
||||
import HarnessParameterModal from "./harness-parameter-modal";
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
harness: HarnessKind;
|
||||
inherit?: boolean;
|
||||
model?: HarnessModelOption | null;
|
||||
params?: Record<string, number | string>;
|
||||
onChange: (params: Record<string, number | string>) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parameter modal trigger for harnesses supporting generation settings.
|
||||
*/
|
||||
export default function HarnessParamsButton({
|
||||
id,
|
||||
harness,
|
||||
inherit,
|
||||
model,
|
||||
params,
|
||||
onChange,
|
||||
}: Props) {
|
||||
const is_supported = HarnessParameterHarnesses.includes(
|
||||
harness as (typeof HarnessParameterHarnesses)[number],
|
||||
);
|
||||
|
||||
if (inherit || !is_supported || !model) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<HarnessParameterModal
|
||||
id={id}
|
||||
harness={harness}
|
||||
model={model}
|
||||
params={params}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import Checkbox from "@moduletrace/twui/form/Checkbox";
|
||||
import { harnessFallbackTitle } from "@/src/dict/harness-dict";
|
||||
import { HarnessParameterHarnesses } from "@/src/dict/harness-parameter-dict";
|
||||
import type { HarnessFormValue, HarnessOverview } from "@/src/types";
|
||||
import SettingsGroup from "../../(partials)/settings-group";
|
||||
import harnessDefaultName from "../(utils)/harness-default-name";
|
||||
import nextHarnessProviderValue from "../(utils)/next-harness-provider-value";
|
||||
import HarnessCurrentModel from "./harness-current-model";
|
||||
import HarnessFallbackModels from "./harness-fallback-models";
|
||||
import HarnessModelSelect from "./harness-model-select";
|
||||
import HarnessParameterModal from "./harness-parameter-modal";
|
||||
import HarnessOptionsCheckboxes from "./harness-options-checkboxes";
|
||||
import HarnessParamsButton from "./harness-params-button";
|
||||
import HarnessProviderSelect from "./harness-provider-select";
|
||||
import HarnessVoicePreview from "./harness-voice-preview";
|
||||
import HarnessVoiceSelect from "./harness-voice-select";
|
||||
import HarnessTextFallbacks from "./harness-text-fallbacks";
|
||||
import HarnessVoiceControls from "./harness-voice-controls";
|
||||
|
||||
type Props = {
|
||||
harness: HarnessOverview;
|
||||
@@ -18,11 +18,8 @@ type Props = {
|
||||
};
|
||||
|
||||
/**
|
||||
* One harness: its provider, then its model (narrowed to that provider),
|
||||
* the text harness's fallback models (any provider), whether it falls back to the automatic picks (for a harness that has
|
||||
* them), whether it's on, and its voice for speech, with a sample to hear
|
||||
* it before saving. On a bot's page the provider select can also use the
|
||||
* default, which hides the rest.
|
||||
* One harness: its provider, its model, text fallback models,
|
||||
* automatic fallback options, and voice controls for speech.
|
||||
*/
|
||||
export default function HarnessSettingGroup({ harness, value, onChange }: Props) {
|
||||
const id = `harness-${harness.harness}`;
|
||||
@@ -31,25 +28,12 @@ export default function HarnessSettingGroup({ harness, value, onChange }: Props)
|
||||
? harness.models.filter((model) => model.provider_id == value.provider_id)
|
||||
: harness.models;
|
||||
const picked = models.find((model) => model.id == value.model_id);
|
||||
const voices = (picked || harness.current)?.voices;
|
||||
/**
|
||||
* The model the settings are for: the pick, else the one it runs on now.
|
||||
*/
|
||||
const params_model = picked || harness.current;
|
||||
const shows_params =
|
||||
!value.inherit &&
|
||||
HarnessParameterHarnesses.includes(
|
||||
harness.harness as (typeof HarnessParameterHarnesses)[number],
|
||||
);
|
||||
const on_bot_page = harness.default !== undefined;
|
||||
const falls_back_title = harnessFallbackTitle({ harness: harness.harness });
|
||||
const default_name = harness.default?.enabled === false
|
||||
? "turned off"
|
||||
: harness.default?.current
|
||||
? `${harness.default.current.name} on ${harness.default.current.provider_name}`
|
||||
: falls_back_title
|
||||
? `same as ${falls_back_title.toLowerCase()}`
|
||||
: "not available";
|
||||
const default_name = harnessDefaultName({
|
||||
harness_default: harness.default,
|
||||
falls_back_title,
|
||||
});
|
||||
|
||||
return (
|
||||
<SettingsGroup title={harness.title} description={harness.description}>
|
||||
@@ -60,15 +44,13 @@ export default function HarnessSettingGroup({ harness, value, onChange }: Props)
|
||||
inherit={value.inherit}
|
||||
inherit_title={on_bot_page ? `Same as the default (now ${default_name})` : undefined}
|
||||
onChange={(next) =>
|
||||
onChange({
|
||||
...value,
|
||||
...next,
|
||||
model_id:
|
||||
next.provider_id && picked?.provider_id != next.provider_id
|
||||
? null
|
||||
: value.model_id,
|
||||
voice: undefined,
|
||||
})
|
||||
onChange(
|
||||
nextHarnessProviderValue({
|
||||
value,
|
||||
next,
|
||||
picked_provider_id: picked?.provider_id,
|
||||
}),
|
||||
)
|
||||
}
|
||||
/>
|
||||
{value.inherit ? null : (
|
||||
@@ -83,73 +65,34 @@ export default function HarnessSettingGroup({ harness, value, onChange }: Props)
|
||||
onChange={(model_id) => onChange({ ...value, model_id, voice: undefined })}
|
||||
/>
|
||||
)}
|
||||
{!value.inherit && value.model_id && harness.harness == "text" ? (
|
||||
<HarnessFallbackModels
|
||||
<HarnessTextFallbacks id={id} harness={harness} value={value} onChange={onChange} />
|
||||
<HarnessCurrentModel
|
||||
harness={value.inherit && harness.default ? { ...harness, ...harness.default } : harness}
|
||||
/>
|
||||
<HarnessOptionsCheckboxes
|
||||
harness={harness}
|
||||
value={value}
|
||||
provider={provider}
|
||||
falls_back_title={falls_back_title}
|
||||
onChange={onChange}
|
||||
/>
|
||||
<HarnessParamsButton
|
||||
id={id}
|
||||
harness={harness.harness}
|
||||
inherit={value.inherit}
|
||||
model={picked || harness.current}
|
||||
params={value.params}
|
||||
onChange={(params) => onChange({ ...value, params })}
|
||||
/>
|
||||
{!value.inherit && harness.harness == "speech" ? (
|
||||
<HarnessVoiceControls
|
||||
id={id}
|
||||
models={harness.models}
|
||||
model_id={value.model_id}
|
||||
fallback_model_ids={value.fallback_model_ids || []}
|
||||
onChange={(fallback_model_ids) => onChange({ ...value, fallback_model_ids })}
|
||||
/>
|
||||
) : null}
|
||||
{value.inherit && harness.default ? (
|
||||
<HarnessCurrentModel harness={{ ...harness, ...harness.default }} />
|
||||
) : (
|
||||
<HarnessCurrentModel harness={harness} />
|
||||
)}
|
||||
{!value.inherit && value.model_id && harness.automatic ? (
|
||||
<Checkbox
|
||||
title="Fall back to the free automatic picks if this model fails"
|
||||
label={`${harness.harness == "text" ? "Then fall back" : "Fall back"} to the free automatic picks${provider ? ` on ${provider.name}` : ""} if this model fails`}
|
||||
checked={value.fallback}
|
||||
changeHandler={(fallback) => onChange({ ...value, fallback })}
|
||||
/>
|
||||
) : null}
|
||||
{!value.inherit && value.model_id && falls_back_title ? (
|
||||
<Checkbox
|
||||
title={`Fall back to ${falls_back_title.toLowerCase()} if this model fails`}
|
||||
label={`Fall back to ${falls_back_title.toLowerCase()} if this model fails`}
|
||||
checked={value.fallback}
|
||||
changeHandler={(fallback) => onChange({ ...value, fallback })}
|
||||
/>
|
||||
) : null}
|
||||
{!value.inherit && harness.harness == "text" ? (
|
||||
<Checkbox
|
||||
title="Use the model's own media reading"
|
||||
label="Use the model's own media reading"
|
||||
info="It looks at images and screenshots itself when it takes image input. Otherwise the media reading model reads them."
|
||||
checked={Boolean(value.sees_images)}
|
||||
changeHandler={(sees_images) => onChange({ ...value, sees_images })}
|
||||
/>
|
||||
) : null}
|
||||
{shows_params && params_model ? (
|
||||
<HarnessParameterModal
|
||||
id={id}
|
||||
harness={harness.harness}
|
||||
model={params_model}
|
||||
params={value.params}
|
||||
onChange={(params) => onChange({ ...value, params })}
|
||||
/>
|
||||
) : null}
|
||||
{!value.inherit && harness.harness == "speech" && voices?.length ? (
|
||||
<HarnessVoiceSelect
|
||||
id={`${id}-voice`}
|
||||
voices={voices}
|
||||
voices={(picked || harness.current)?.voices}
|
||||
voice={value.voice}
|
||||
onChange={(voice) => onChange({ ...value, voice: voice || undefined })}
|
||||
model_id={picked?.id}
|
||||
onChange={(voice) => onChange({ ...value, voice })}
|
||||
/>
|
||||
) : null}
|
||||
{!value.inherit && harness.harness == "speech" && picked ? (
|
||||
<HarnessVoicePreview model_id={picked.id} voice={value.voice} />
|
||||
) : null}
|
||||
{value.inherit || harness.required ? null : (
|
||||
<Checkbox
|
||||
title={`Turn ${harness.title.toLowerCase()} on`}
|
||||
label="Turned on"
|
||||
checked={value.enabled}
|
||||
changeHandler={(enabled) => onChange({ ...value, enabled })}
|
||||
/>
|
||||
)}
|
||||
</SettingsGroup>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { HarnessOverview, HarnessFormValue } from "@/src/types";
|
||||
import HarnessFallbackModels from "./harness-fallback-models";
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
harness: HarnessOverview;
|
||||
value: HarnessFormValue;
|
||||
onChange: (value: HarnessFormValue) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Text harness fallback models list, shown when a text model is selected.
|
||||
*/
|
||||
export default function HarnessTextFallbacks({ id, harness, value, onChange }: Props) {
|
||||
if (value.inherit || !value.model_id || harness.harness != "text") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<HarnessFallbackModels
|
||||
id={id}
|
||||
models={harness.models}
|
||||
model_id={value.model_id}
|
||||
fallback_model_ids={value.fallback_model_ids || []}
|
||||
onChange={(fallback_model_ids) => onChange({ ...value, fallback_model_ids })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import HarnessVoiceSelect from "./harness-voice-select";
|
||||
import HarnessVoicePreview from "./harness-voice-preview";
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
voices?: string[];
|
||||
voice?: string;
|
||||
model_id?: number | null;
|
||||
onChange: (voice?: string) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Voice selection and audio sample preview for the speech harness.
|
||||
*/
|
||||
export default function HarnessVoiceControls({
|
||||
id,
|
||||
voices,
|
||||
voice,
|
||||
model_id,
|
||||
onChange,
|
||||
}: Props) {
|
||||
return (
|
||||
<>
|
||||
{voices?.length ? (
|
||||
<HarnessVoiceSelect
|
||||
id={`${id}-voice`}
|
||||
voices={voices}
|
||||
voice={voice}
|
||||
onChange={(picked) => onChange(picked || undefined)}
|
||||
/>
|
||||
) : null}
|
||||
{model_id ? (
|
||||
<HarnessVoicePreview model_id={model_id} voice={voice} />
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import harnessDefaultName from "./harness-default-name";
|
||||
|
||||
describe("harnessDefaultName", () => {
|
||||
test("returns 'turned off' when default is disabled", () => {
|
||||
expect(
|
||||
harnessDefaultName({
|
||||
harness_default: { enabled: false },
|
||||
}),
|
||||
).toBe("turned off");
|
||||
});
|
||||
|
||||
test("returns model and provider name when current model exists", () => {
|
||||
expect(
|
||||
harnessDefaultName({
|
||||
harness_default: {
|
||||
enabled: true,
|
||||
current: {
|
||||
name: "Claude 3.5 Sonnet",
|
||||
provider_name: "Anthropic",
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
).toBe("Claude 3.5 Sonnet on Anthropic");
|
||||
});
|
||||
|
||||
test("returns fallback title in lower case when no current model", () => {
|
||||
expect(
|
||||
harnessDefaultName({
|
||||
falls_back_title: "Text",
|
||||
}),
|
||||
).toBe("same as text");
|
||||
});
|
||||
|
||||
test("returns 'not available' when nothing is specified", () => {
|
||||
expect(harnessDefaultName({})).toBe("not available");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
type Params = {
|
||||
/**
|
||||
* Default configuration for this harness when inherited.
|
||||
*/
|
||||
harness_default?: {
|
||||
enabled?: boolean;
|
||||
current?: { name: string; provider_name: string } | null;
|
||||
};
|
||||
/**
|
||||
* Fallback title for harnesses that fall back to another harness.
|
||||
*/
|
||||
falls_back_title?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes a human-readable description of the default model setting
|
||||
* for a harness when a bot or workspace inherits its configuration.
|
||||
*/
|
||||
export default function harnessDefaultName({
|
||||
harness_default,
|
||||
falls_back_title,
|
||||
}: Params): string {
|
||||
// If the default is explicitly disabled
|
||||
if (harness_default?.enabled === false) {
|
||||
return "turned off";
|
||||
}
|
||||
|
||||
// If a default model is active
|
||||
if (harness_default?.current) {
|
||||
return `${harness_default.current.name} on ${harness_default.current.provider_name}`;
|
||||
}
|
||||
|
||||
// If it falls back to another harness (e.g. media reading falls back to text)
|
||||
if (falls_back_title) {
|
||||
return `same as ${falls_back_title.toLowerCase()}`;
|
||||
}
|
||||
|
||||
return "not available";
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import nextHarnessProviderValue from "./next-harness-provider-value";
|
||||
import type { HarnessFormValue } from "@/src/types";
|
||||
|
||||
const base_value: HarnessFormValue = {
|
||||
model_id: 10,
|
||||
provider_id: 1,
|
||||
fallback_model_ids: [11, 12],
|
||||
fallback: true,
|
||||
enabled: true,
|
||||
voice: "george",
|
||||
inherit: false,
|
||||
};
|
||||
|
||||
describe("nextHarnessProviderValue", () => {
|
||||
test("resets fallback models and clears model when changing to another provider", () => {
|
||||
const result = nextHarnessProviderValue({
|
||||
value: base_value,
|
||||
next: { provider_id: 2, inherit: false },
|
||||
picked_provider_id: 1,
|
||||
});
|
||||
|
||||
// Model 10 belonged to provider 1, so changing to provider 2 should clear model_id
|
||||
expect(result.model_id).toBeNull();
|
||||
// Fallback models must be reset to empty array
|
||||
expect(result.fallback_model_ids).toEqual([]);
|
||||
// Provider must update to 2
|
||||
expect(result.provider_id).toBe(2);
|
||||
// Voice is cleared
|
||||
expect(result.voice).toBeUndefined();
|
||||
});
|
||||
|
||||
test("resets fallback models when changing to any provider while keeping model if valid", () => {
|
||||
const result = nextHarnessProviderValue({
|
||||
value: base_value,
|
||||
next: { provider_id: null, inherit: false },
|
||||
picked_provider_id: 1,
|
||||
});
|
||||
|
||||
// In 'any provider', model 10 is still available
|
||||
expect(result.model_id).toBe(10);
|
||||
// Fallback models must be reset on provider change
|
||||
expect(result.fallback_model_ids).toEqual([]);
|
||||
expect(result.provider_id).toBeNull();
|
||||
});
|
||||
|
||||
test("resets fallback models when changing from any provider to a specific provider", () => {
|
||||
const from_any: HarnessFormValue = {
|
||||
...base_value,
|
||||
provider_id: null,
|
||||
fallback_model_ids: [15, 16],
|
||||
};
|
||||
|
||||
const result = nextHarnessProviderValue({
|
||||
value: from_any,
|
||||
next: { provider_id: 1, inherit: false },
|
||||
picked_provider_id: 1,
|
||||
});
|
||||
|
||||
// Model 10 belongs to provider 1, so model_id is kept
|
||||
expect(result.model_id).toBe(10);
|
||||
// Fallback models must be reset
|
||||
expect(result.fallback_model_ids).toEqual([]);
|
||||
expect(result.provider_id).toBe(1);
|
||||
});
|
||||
|
||||
test("resets fallback models when switching to inherit mode", () => {
|
||||
const result = nextHarnessProviderValue({
|
||||
value: base_value,
|
||||
next: { provider_id: null, inherit: true },
|
||||
picked_provider_id: 1,
|
||||
});
|
||||
|
||||
expect(result.inherit).toBe(true);
|
||||
expect(result.fallback_model_ids).toEqual([]);
|
||||
});
|
||||
|
||||
test("keeps fallback models when provider selection has not changed", () => {
|
||||
const result = nextHarnessProviderValue({
|
||||
value: base_value,
|
||||
next: { provider_id: 1, inherit: false },
|
||||
picked_provider_id: 1,
|
||||
});
|
||||
|
||||
expect(result.model_id).toBe(10);
|
||||
expect(result.fallback_model_ids).toEqual([11, 12]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { HarnessFormValue } from "@/src/types";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* The current harness form state before the provider selection change.
|
||||
*/
|
||||
value: HarnessFormValue;
|
||||
/**
|
||||
* The new provider id and inherit state selected by the user.
|
||||
*/
|
||||
next: { provider_id: number | null; inherit: boolean };
|
||||
/**
|
||||
* The provider id of the currently picked model, if any.
|
||||
*/
|
||||
picked_provider_id?: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the next harness form value when the model provider changes.
|
||||
*
|
||||
* When the provider changes (including switching between specific providers,
|
||||
* 'any provider', or inherit mode), fallback models are reset to empty to avoid
|
||||
* retaining fallback models from the previous provider configuration.
|
||||
*
|
||||
* The selected model is also cleared if a specific provider is chosen and the
|
||||
* currently picked model does not belong to that provider.
|
||||
*/
|
||||
export default function nextHarnessProviderValue({
|
||||
value,
|
||||
next,
|
||||
picked_provider_id,
|
||||
}: Params): HarnessFormValue {
|
||||
// Detect whether the provider selection or inherit mode actually changed
|
||||
const provider_changed =
|
||||
next.provider_id != value.provider_id ||
|
||||
Boolean(next.inherit) != Boolean(value.inherit);
|
||||
|
||||
// If a specific provider was selected and the picked model does not belong to it, clear the model
|
||||
const should_clear_model = Boolean(
|
||||
next.provider_id && picked_provider_id != next.provider_id,
|
||||
);
|
||||
|
||||
return {
|
||||
...value,
|
||||
...next,
|
||||
// Reset the model if it is invalid under the newly selected provider
|
||||
model_id: should_clear_model ? null : value.model_id,
|
||||
// Reset fallback models when the provider changes
|
||||
fallback_model_ids: provider_changed ? [] : (value.fallback_model_ids || []),
|
||||
// Voice is cleared on provider change as voices are provider/model-specific
|
||||
voice: undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user