feat(messaging): run a channel per organisation and deliver only through the owner's

This commit is contained in:
sam committed 2026-10-27 10:38:00 +11:00
1 parent 3ea929cbdc
commit 4f2d0e964a
37 files changed
+1108 -277

No files matched your search

+55 -5
View File
@@ -27,10 +27,12 @@ import {
TagsInputItemText,
} from "@/components/ui/tags-input";
import { api } from "@/lib/api";
import OptionSelect from "@/workflows/OptionSelect.vue";
import { useOrgStore, type Identity } from "@/stores/org";
import { Section } from "@/components/ui/section";
import SecretRefField from "@/settings/SecretRefField.vue";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import { useLiveResource } from "@/stores/session";
import { useLiveResource, useSessionStore } from "@/stores/session";
const KIND = "channel-settings";
@@ -47,6 +49,7 @@ interface ChannelSettings {
rate_limit: { window: string; max_requests: number };
unrestricted_filesystem: boolean;
workspace: string;
agent: string;
}
/** What the messaging service reports about a running channel. */
@@ -63,6 +66,29 @@ const form = computed(() => store.formFor(KIND));
const chat = computed(() => store.draftValue(KIND) as ChannelSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
// The instance's workspace, filesystem, rate limit and bot token are the
// system org's; another org runs its own bot as one of its agents, with its
// token bound as a credential.
const instance = computed(() => useSessionStore().sections?.settings !== false);
const identities = useOrgStore();
const agents = ref<Identity[]>([]);
const agentsError = ref("");
async function loadAgents(): Promise<void> {
agentsError.value = "";
try {
await identities.loadOrg();
const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg);
agents.value = response.agents.filter((agent) => agent.lifecycle === "active");
} catch (cause) {
agentsError.value = String((cause as Error).message || cause);
}
}
const agentOptions = computed(() => {
const current = chat.value?.agent ?? "";
const options = agents.value.map((agent) => ({ value: agent.id, label: agent.display_name }));
return current && !agents.value.some((agent) => agent.id === current) ? [{ value: current, label: `${current} (unknown)`, disabled: true }, ...options] : options;
});
const statuses = ref<ChannelStatus[]>([]);
async function loadStatus() {
try {
@@ -72,7 +98,7 @@ async function loadStatus() {
}
}
useLiveResource(null, () => void loadStatus());
onMounted(() => Promise.all([loadStatus(), store.load()]));
onMounted(() => Promise.all([loadStatus(), store.load(), instance.value ? undefined : loadAgents()]));
// Running state comes only from the messaging service's report; a channel it
// does not mention shows none rather than one guessed from its settings.
@@ -88,7 +114,7 @@ function statusOf(id: string) {
// A channel is set up once its enabling field is filled in, the rule the
// daemon applies when it decides what to start.
const configured = computed(() => ({
telegram: !!chat.value?.telegram.token_ref.key,
telegram: instance.value ? !!chat.value?.telegram.token_ref.key : !!chat.value?.agent,
}));
const opened = reactive({ telegram: false });
const shown = (id: keyof typeof opened) => configured.value[id] || opened[id];
@@ -132,7 +158,23 @@ function setModels(list: string[]) {
</div>
</template>
<FieldGroup v-if="form && shown(channel.id) && channel.id === 'telegram'" class="@container/field-group">
<form.Field v-slot="{ field }" name="telegram.token_ref">
<form.Field v-if="!instance" v-slot="{ field }" name="agent">
<Field orientation="responsive">
<FieldContent><FieldLabel>Runs as</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<OptionSelect
:model-value="field.state.value"
:options="agentOptions"
aria-label="Agent"
placeholder="Choose an agent"
class="w-44"
@update:model-value="field.handleChange"
/>
</div>
<Alert v-if="agentsError" variant="destructive"><AlertDescription>{{ agentsError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></AlertDescription></Alert>
</Field>
</form.Field>
<form.Field v-if="instance" v-slot="{ field }" name="telegram.token_ref">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Bot token</FieldLabel>
@@ -158,10 +200,18 @@ function setModels(list: string[]) {
</TagsInput>
</div>
</Field>
<form.Field v-if="!instance" v-slot="{ field }" name="show_tool_calls">
<Field orientation="responsive">
<FieldContent><FieldLabel>Show tool calls</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" aria-label="Show tool calls" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
<Section title="Chat session defaults">
<Section v-if="instance" title="Chat session defaults">
<FieldGroup v-if="form" class="@container/field-group">
<form.Field v-slot="{ field }" name="workspace">
<Field orientation="responsive">
+1 -2
View File
@@ -41,7 +41,7 @@ const orgSpecs: NavSpec[] = [
},
{
label: "Automation",
paths: ["/org/schedules", "/org/scheduling-policy", "/org/playbooks", "/org/alerts"],
paths: ["/org/schedules", "/org/scheduling-policy", "/org/channels", "/org/playbooks", "/org/alerts"],
},
],
},
@@ -64,7 +64,6 @@ const settings: NavSpec = {
{
label: "Connections & channels",
paths: [
"/settings/channels",
"/settings/tools",
"/settings/extensions",
"/settings/plugins",
+8 -13
View File
@@ -266,6 +266,12 @@ const routes = [
component: () => import("@/schedules/ScheduleRunsPage.vue"),
meta: { label: "Schedule runs", navPath: "/org/schedules", nav: false },
},
{
path: "channels",
name: "org-channels",
component: ChannelsPage,
meta: { label: "Channels", navPath: "/org", description: "Chat channels.", section: "channels" },
},
{
path: "scheduling-policy",
name: "org-scheduling-policy",
@@ -306,19 +312,8 @@ const routes = [
"/settings/schedules": "/org/schedules",
"/settings/playbooks": "/org/playbooks",
"/settings/scheduling-policy": "/org/scheduling-policy",
"/settings/channels": "/org/channels",
}).map(([path, redirect]) => ({ path, redirect, meta: { nav: false } })),
{
path: "/settings/channels",
name: "channels",
component: ChannelsPage,
meta: {
navPath: "/settings",
settings: true,
label: "Channels",
description: "Chat and notification channels.",
section: "channels",
},
},
{
path: "/settings/tools",
name: "settings-tools",
@@ -426,7 +421,7 @@ const routes = [
"/system/models": "/settings/models",
"/system/repos": "/settings/repositories",
"/system/identities": "/org/agents",
"/channels": "/settings/channels",
"/channels": "/org/channels",
"/skills": "/settings/skills",
"/curators": "/settings/curators",
}).map(([path, redirect]) => ({ path, redirect, meta: { nav: false } })),