|
@@ -0,0 +1,312 @@
|
|
|
|
|
+<script lang="ts">
|
|
|
|
|
+ import { AgentSelectDialog } from '$lib/components/agents/select';
|
|
|
|
|
+ import { Card } from '$lib/components/common/card';
|
|
|
|
|
+ import { Icon } from '$lib/components/common/icon';
|
|
|
|
|
+ import { Button } from '$lib/components/controls/button';
|
|
|
|
|
+ import * as Field from '$lib/components/controls/field';
|
|
|
|
|
+ import { Input } from '$lib/components/controls/input';
|
|
|
|
|
+ import { Spinner } from '$lib/components/controls/spinner';
|
|
|
|
|
+ import { Textarea } from '$lib/components/controls/textarea';
|
|
|
|
|
+ import { ArrayInput } from '$lib/components/forms/array-input';
|
|
|
|
|
+ import { DeploymentForm } from '$lib/components/forms/deployment';
|
|
|
|
|
+ import { IconPicker } from '$lib/components/forms/icon-picker';
|
|
|
|
|
+ import { Optional } from '$lib/components/forms/optional';
|
|
|
|
|
+ import { KBSelectDialog } from '$lib/components/kbs/select';
|
|
|
|
|
+ import { ModelSelectDialog } from '$lib/components/models/select';
|
|
|
|
|
+ import { SkillSelectDialog } from '$lib/components/skills/select';
|
|
|
|
|
+ import { ToolSelectDialog } from '$lib/components/tools/select';
|
|
|
|
|
+ import type { IDRef } from '$lib/types/entities';
|
|
|
|
|
+
|
|
|
|
|
+ import { type AgentFormValue, DEFAULT_AGENT_FORM_VALUE } from './types';
|
|
|
|
|
+
|
|
|
|
|
+ let {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ disabled = false,
|
|
|
|
|
+ submitting = false,
|
|
|
|
|
+ value,
|
|
|
|
|
+ cancelHref,
|
|
|
|
|
+ onsubmit,
|
|
|
|
|
+ }: {
|
|
|
|
|
+ workspaceId: string;
|
|
|
|
|
+ disabled?: boolean;
|
|
|
|
|
+ submitting?: boolean;
|
|
|
|
|
+ value?: AgentFormValue;
|
|
|
|
|
+ cancelHref: string;
|
|
|
|
|
+ onsubmit: (value: AgentFormValue) => void;
|
|
|
|
|
+ } = $props();
|
|
|
|
|
+
|
|
|
|
|
+ const isEdit = $derived(value !== undefined);
|
|
|
|
|
+ let form = $state<AgentFormValue>({ ...DEFAULT_AGENT_FORM_VALUE });
|
|
|
|
|
+ let errors = $state<{
|
|
|
|
|
+ name?: string;
|
|
|
|
|
+ }>({});
|
|
|
|
|
+ let modelSelectionShown = $state(false);
|
|
|
|
|
+ let skillSelectionShown = $state(false);
|
|
|
|
|
+ let toolSelectionShown = $state(false);
|
|
|
|
|
+ let kbSelectionShown = $state(false);
|
|
|
|
|
+ let subagentSelectionShown = $state(false);
|
|
|
|
|
+
|
|
|
|
|
+ const initForm = (value?: AgentFormValue) => {
|
|
|
|
|
+ if (!value) {
|
|
|
|
|
+ form = { ...DEFAULT_AGENT_FORM_VALUE };
|
|
|
|
|
+ } else {
|
|
|
|
|
+ form = {
|
|
|
|
|
+ ...$state.snapshot(value),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $effect(() => initForm(value));
|
|
|
|
|
+
|
|
|
|
|
+ const onModelSelect = (models: IDRef[]): IDRef[] => {
|
|
|
|
|
+ form.model = {
|
|
|
|
|
+ id: models[0].id,
|
|
|
|
|
+ type: models[0].type,
|
|
|
|
|
+ icon: models[0].icon,
|
|
|
|
|
+ name: models[0].name,
|
|
|
|
|
+ };
|
|
|
|
|
+ return models;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const onSkillSelect = (skills: IDRef[]): IDRef[] => {
|
|
|
|
|
+ form.skills = skills;
|
|
|
|
|
+ return skills;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const onToolSelect = (tools: IDRef[]): IDRef[] => {
|
|
|
|
|
+ form.tools = tools;
|
|
|
|
|
+ return tools;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const onKbSelect = (kbs: IDRef[]): IDRef[] => {
|
|
|
|
|
+ form.kbs = kbs;
|
|
|
|
|
+ return kbs;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const onSubagentSelect = (subagents: IDRef[]): IDRef[] => {
|
|
|
|
|
+ form.subagents = subagents;
|
|
|
|
|
+ return subagents;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const handleSubmit = async () => {
|
|
|
|
|
+ onsubmit(form);
|
|
|
|
|
+ };
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+{#snippet panel()}
|
|
|
|
|
+ <div class="flex items-center gap-2">
|
|
|
|
|
+ <Button href={cancelHref} size="sm" variant="outline">Cancel</Button>
|
|
|
|
|
+ <Button disabled={submitting} size="sm" onclick={handleSubmit}>
|
|
|
|
|
+ {#if submitting}
|
|
|
|
|
+ <Spinner />
|
|
|
|
|
+ {/if}
|
|
|
|
|
+ {isEdit ? 'Save Changes' : 'Create'}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+{/snippet}
|
|
|
|
|
+
|
|
|
|
|
+<div class="mx-auto max-w-2xl p-6">
|
|
|
|
|
+ <!-- Page header -->
|
|
|
|
|
+ <div class="mb-4 flex items-center justify-between gap-4">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1 class="text-xl font-semibold text-white/90">
|
|
|
|
|
+ {isEdit ? 'Edit Agent' : 'New Agent'}
|
|
|
|
|
+ </h1>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {@render panel()}
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Basic Information panel (shared) -->
|
|
|
|
|
+ <Card class="mb-4" title="Basic Information">
|
|
|
|
|
+ <div class="mb-4 flex gap-8">
|
|
|
|
|
+ <!-- Icon -->
|
|
|
|
|
+ <div class="shrink-0">
|
|
|
|
|
+ <IconPicker bind:value={form.icon} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <!-- Name -->
|
|
|
|
|
+ <div class="min-w-0 flex-1 space-y-4">
|
|
|
|
|
+ <Field.Set>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label for="name">Name</Field.Label>
|
|
|
|
|
+ <Input id="name" maxlength={64} bind:value={form.name} />
|
|
|
|
|
+ <Field.Error>{errors.name}</Field.Error>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label for="description">Description</Field.Label>
|
|
|
|
|
+ <Textarea
|
|
|
|
|
+ id="description"
|
|
|
|
|
+ placeholder="What does this tool do?"
|
|
|
|
|
+ rows={3}
|
|
|
|
|
+ bind:value={form.description}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Field.Description>
|
|
|
|
|
+ Provide a brief description that can also help AI assistant to understand the agent's
|
|
|
|
|
+ functionality.
|
|
|
|
|
+ </Field.Description>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ </Field.Set>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <Optional title="Tags">
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <ArrayInput {disabled} bind:value={form.tags} />
|
|
|
|
|
+ <Field.Description>
|
|
|
|
|
+ Tags can be used for filtering and searching in the list view.
|
|
|
|
|
+ </Field.Description>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ </Optional>
|
|
|
|
|
+ </Card>
|
|
|
|
|
+
|
|
|
|
|
+ <Card class="mb-4" title="Configuration">
|
|
|
|
|
+ <Field.Set>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label for="systemPrompt">System Prompt / AGENTS.md</Field.Label>
|
|
|
|
|
+ <Textarea
|
|
|
|
|
+ id="systemPrompt"
|
|
|
|
|
+ placeholder="You are a helpful assistant..."
|
|
|
|
|
+ rows={5}
|
|
|
|
|
+ bind:value={form.systemPrompt}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label>Language Model</Field.Label>
|
|
|
|
|
+ <Field.Content>
|
|
|
|
|
+ <div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (modelSelectionShown = true)}>
|
|
|
|
|
+ {#if form.model}
|
|
|
|
|
+ <Icon icon={form.model.icon} size={14} />
|
|
|
|
|
+ <div>{form.model.name}</div>
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ Select model...
|
|
|
|
|
+ {/if}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Field.Content>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label>Skills</Field.Label>
|
|
|
|
|
+ <Field.Content>
|
|
|
|
|
+ <div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
+ {#each form.skills as skill (skill.id)}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (skillSelectionShown = true)}>
|
|
|
|
|
+ <Icon icon={skill.icon} size={14} />
|
|
|
|
|
+ <div>{skill.name}</div>
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (skillSelectionShown = true)}>
|
|
|
|
|
+ Select skills...
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {/each}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Field.Content>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label>Tools</Field.Label>
|
|
|
|
|
+ <Field.Content>
|
|
|
|
|
+ <div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
+ {#each form.tools as tool (tool.id)}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (toolSelectionShown = true)}>
|
|
|
|
|
+ <Icon icon={tool.icon} size={14} />
|
|
|
|
|
+ <div>{tool.name}</div>
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (toolSelectionShown = true)}>
|
|
|
|
|
+ Select tools...
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {/each}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Field.Content>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label>Knowledge Bases</Field.Label>
|
|
|
|
|
+ <Field.Content>
|
|
|
|
|
+ <div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
+ {#each form.kbs as kb (kb.id)}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (kbSelectionShown = true)}>
|
|
|
|
|
+ <Icon icon={kb.icon} size={14} />
|
|
|
|
|
+ <div>{kb.name}</div>
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (kbSelectionShown = true)}>
|
|
|
|
|
+ Select knowledge bases...
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {/each}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Field.Content>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ <Field.Field>
|
|
|
|
|
+ <Field.Label>Subagents</Field.Label>
|
|
|
|
|
+ <Field.Content>
|
|
|
|
|
+ <div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
+ {#each form.subagents as agent (agent.id)}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (subagentSelectionShown = true)}>
|
|
|
|
|
+ <Icon icon={agent.icon} size={14} />
|
|
|
|
|
+ <div>{agent.name}</div>
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ <Button size="sm" variant="outline" onclick={() => (subagentSelectionShown = true)}>
|
|
|
|
|
+ Select subagents...
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ {/each}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Field.Content>
|
|
|
|
|
+ </Field.Field>
|
|
|
|
|
+ </Field.Set>
|
|
|
|
|
+ </Card>
|
|
|
|
|
+
|
|
|
|
|
+ <Card class="mb-4" title="Deployment">
|
|
|
|
|
+ <Optional title="Runtime Settings">
|
|
|
|
|
+ <DeploymentForm
|
|
|
|
|
+ {disabled}
|
|
|
|
|
+ runtimes={[
|
|
|
|
|
+ { value: 'loco-agent', label: 'loco-agents', versions: [] },
|
|
|
|
|
+ { value: 'opencode', label: 'OpenCode', versions: [] },
|
|
|
|
|
+ ]}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:form
|
|
|
|
|
+ />
|
|
|
|
|
+ </Optional>
|
|
|
|
|
+ </Card>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Footer actions -->
|
|
|
|
|
+ <div class="flex justify-end">
|
|
|
|
|
+ {@render panel()}
|
|
|
|
|
+ </div>
|
|
|
|
|
+</div>
|
|
|
|
|
+
|
|
|
|
|
+<ModelSelectDialog
|
|
|
|
|
+ category="language"
|
|
|
|
|
+ multiple={false}
|
|
|
|
|
+ value={form.model ? [form.model] : []}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:open={modelSelectionShown}
|
|
|
|
|
+ onselect={(model) => onModelSelect(model)}
|
|
|
|
|
+/>
|
|
|
|
|
+
|
|
|
|
|
+<SkillSelectDialog
|
|
|
|
|
+ value={form.skills}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:open={skillSelectionShown}
|
|
|
|
|
+ onselect={(skills) => onSkillSelect(skills)}
|
|
|
|
|
+/>
|
|
|
|
|
+
|
|
|
|
|
+<ToolSelectDialog
|
|
|
|
|
+ value={form.tools}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:open={toolSelectionShown}
|
|
|
|
|
+ onselect={(tools) => onToolSelect(tools)}
|
|
|
|
|
+/>
|
|
|
|
|
+
|
|
|
|
|
+<KBSelectDialog
|
|
|
|
|
+ value={form.kbs}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:open={kbSelectionShown}
|
|
|
|
|
+ onselect={(kbs) => onKbSelect(kbs)}
|
|
|
|
|
+/>
|
|
|
|
|
+
|
|
|
|
|
+<AgentSelectDialog
|
|
|
|
|
+ value={form.subagents}
|
|
|
|
|
+ {workspaceId}
|
|
|
|
|
+ bind:open={subagentSelectionShown}
|
|
|
|
|
+ onselect={(agents) => onSubagentSelect(agents)}
|
|
|
|
|
+/>
|