@open-mercato/channel-discord 0.7.1-develop.7152.1.a69e92f9c9 → 0.7.1-develop.7153.1.7145d295e6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -154,6 +154,7 @@ function DiscordAiAutoReplyPage({ params }) {
154
154
  CrudForm,
155
155
  {
156
156
  title: t("channel_discord.aiAutoReply.page.title", "Discord AI auto-reply"),
157
+ titleHeadingLevel: 1,
157
158
  backHref: CHANNELS_LIST_HREF,
158
159
  cancelHref: CHANNELS_LIST_HREF,
159
160
  fields,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../../src/modules/channel_discord/backend/channel_discord/channels/%5Bid%5D/ai-auto-reply/page.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudField } from '@open-mercato/ui/backend/CrudForm'\nimport { ErrorMessage, LoadingMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { updateCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\n\ntype EligibleAgent = {\n id: string\n label: string\n description: string\n requiredFeatures: string[]\n /** Whether the auto-reply principal holds the agent's `requiredFeatures`. */\n invocable: boolean\n missingFeatures: string[]\n}\n\ntype AiAutoReplySettings = {\n channelId: string\n displayName: string\n updatedAt: string | null\n aiAutoReplyEnabled: boolean\n aiAgentId: string | null\n aiAutoReplyLastError: string | null\n aiAutoReplyLastErrorAt: string | null\n defaultAgentId: string\n aiAvailable: boolean\n agents: EligibleAgent[]\n}\n\ntype FormValues = {\n id: string\n updatedAt: string | null\n aiAutoReplyEnabled: boolean\n aiAgentId: string\n}\n\nconst CHANNELS_LIST_HREF = '/backend/communication_channels/channels'\n\n/**\n * Per-channel AI auto-reply settings (issue #4778) \u2014 the surface that writes\n * `aiAutoReplyEnabled` / `aiAgentId`, the two keys the subscriber reads.\n *\n * It is a `CrudForm` rather than a hand-rolled form so the save inherits the\n * platform's contract for free: zod validation with field-level errors, and the\n * optimistic-lock header auto-derived from `initialValues.updatedAt`, so a save\n * from a tab opened before someone else touched the channel surfaces the shared\n * conflict bar instead of overwriting them.\n */\nexport default function DiscordAiAutoReplyPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const channelId = params?.id ?? ''\n\n const [settings, setSettings] = React.useState<AiAutoReplySettings | null>(null)\n const [isLoading, setIsLoading] = React.useState(true)\n const [errorMessage, setErrorMessage] = React.useState<string | null>(null)\n const [notFound, setNotFound] = React.useState(false)\n\n const load = React.useCallback(async () => {\n if (!channelId) {\n setIsLoading(false)\n setErrorMessage(t('channel_discord.aiAutoReply.errors.missingChannelId', 'No channel selected.'))\n return\n }\n setIsLoading(true)\n setErrorMessage(null)\n setNotFound(false)\n const response = await apiCall<AiAutoReplySettings>(\n `/api/channel_discord/channels/${encodeURIComponent(channelId)}/ai-auto-reply`,\n ).catch(() => null)\n if (!response || !response.ok) {\n const status = (response as { status?: number } | null)?.status\n if (status === 404) {\n setNotFound(true)\n } else {\n const body = response?.result as { error?: string } | undefined\n setErrorMessage(\n body?.error ?? t('channel_discord.aiAutoReply.errors.load', 'Failed to load AI auto-reply settings'),\n )\n }\n setSettings(null)\n } else {\n setSettings(response.result ?? null)\n }\n setIsLoading(false)\n }, [channelId, t])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const fields = React.useMemo<CrudField[]>(() => {\n // An agent the auto-reply principal cannot invoke stays in the list \u2014 hiding\n // it would leave the operator wondering where an agent they can see elsewhere\n // went \u2014 but it says what it needs, so the requirement is visible before the\n // save rather than only in the 400 that follows.\n const agentOptions = (settings?.agents ?? []).map((agent) => ({\n value: agent.id,\n label: agent.invocable\n ? agent.label\n : t(\n 'channel_discord.aiAutoReply.fields.agentMissingFeatures',\n '{label} \u2014 needs {features}',\n { label: agent.label, features: agent.missingFeatures.join(', ') },\n ),\n }))\n return [\n {\n id: 'aiAutoReplyEnabled',\n type: 'checkbox',\n label: t('channel_discord.aiAutoReply.fields.enabled', 'Answer inbound Discord messages with AI'),\n description: t(\n 'channel_discord.aiAutoReply.fields.enabledHelp',\n 'Off by default. When on, straightforward messages are answered automatically; anything sensitive, low-confidence or suspicious is proposed for a human to approve instead.',\n ),\n disabled: !settings?.aiAvailable,\n },\n {\n id: 'aiAgentId',\n type: 'select',\n label: t('channel_discord.aiAutoReply.fields.agent', 'Agent'),\n description: t(\n 'channel_discord.aiAutoReply.fields.agentHelp',\n 'Only agents that produce structured output can answer a channel. Grant the tenant channel-bot user the agent\u2019s required features before choosing an agent from another module.',\n ),\n options: agentOptions,\n required: true,\n visibleWhen: { field: 'aiAutoReplyEnabled', equals: true },\n },\n ]\n }, [settings, t])\n\n const initialValues = React.useMemo<Partial<FormValues>>(() => {\n if (!settings) return {}\n // Default to an agent the principal can actually invoke, so the form does not\n // pre-select a choice the save will reject.\n const invocable = settings.agents.filter((agent) => agent.invocable)\n const fallbackAgentId = invocable.some((agent) => agent.id === settings.defaultAgentId)\n ? settings.defaultAgentId\n : (invocable[0]?.id ?? settings.agents[0]?.id ?? '')\n return {\n id: settings.channelId,\n updatedAt: settings.updatedAt,\n aiAutoReplyEnabled: settings.aiAutoReplyEnabled,\n aiAgentId: settings.aiAgentId ?? fallbackAgentId,\n }\n }, [settings])\n\n const onSubmit = React.useCallback(\n async (values: FormValues) => {\n const enabled = Boolean(values.aiAutoReplyEnabled)\n const agentId = (values.aiAgentId ?? '').trim()\n if (enabled && !agentId) {\n throw createCrudFormError(\n t('channel_discord.aiAutoReply.errors.agentRequired', 'Choose the agent that should answer this channel'),\n { aiAgentId: t('channel_discord.aiAutoReply.errors.agentRequired', 'Choose the agent that should answer this channel') },\n )\n }\n // The route enforces this too \u2014 it has to, since a role can change between\n // the load and the save. Checking here as well turns the common case into an\n // inline field error instead of a round trip.\n const chosen = settings?.agents.find((agent) => agent.id === agentId)\n if (enabled && chosen && !chosen.invocable) {\n const message = t(\n 'channel_discord.aiAutoReply.errors.agentFeaturesMissing',\n 'The channel-bot user is missing the features this agent needs: {features}. Grant them first, or pick another agent.',\n { features: chosen.missingFeatures.join(', ') },\n )\n throw createCrudFormError(message, { aiAgentId: message })\n }\n // Deliberately unguarded: a 409 from the optimistic-lock check has to reach\n // CrudForm, which renders it on the shared conflict bar. Catching it here\n // would surface the same bar and then let the form believe the save\n // succeeded.\n await updateCrud(\n `channel_discord/channels/${encodeURIComponent(channelId)}/ai-auto-reply`,\n {\n aiAutoReplyEnabled: enabled,\n aiAgentId: enabled ? agentId : undefined,\n },\n {\n errorMessage: t(\n 'channel_discord.aiAutoReply.errors.save',\n 'Failed to save AI auto-reply settings',\n ),\n },\n )\n flash(t('channel_discord.aiAutoReply.saved', 'AI auto-reply settings saved.'), 'success')\n await load()\n },\n [channelId, load, settings, t],\n )\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('channel_discord.aiAutoReply.loading', 'Loading AI auto-reply settings...')} />\n </PageBody>\n </Page>\n )\n }\n\n if (notFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('channel_discord.aiAutoReply.notFound', 'Discord channel not found')}\n backHref={CHANNELS_LIST_HREF}\n />\n </PageBody>\n </Page>\n )\n }\n\n if (errorMessage || !settings) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage\n label={\n errorMessage\n ?? t('channel_discord.aiAutoReply.errors.load', 'Failed to load AI auto-reply settings')\n }\n />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm<FormValues>\n title={t('channel_discord.aiAutoReply.page.title', 'Discord AI auto-reply')}\n backHref={CHANNELS_LIST_HREF}\n cancelHref={CHANNELS_LIST_HREF}\n fields={fields}\n initialValues={initialValues}\n onSubmit={onSubmit}\n submitLabel={t('channel_discord.aiAutoReply.save', 'Save')}\n contentHeader={\n <div className=\"mb-4 space-y-2 text-sm text-muted-foreground\">\n <p>\n {t(\n 'channel_discord.aiAutoReply.intro',\n 'Choose whether this Discord channel may answer on its own, and which agent drafts the reply.',\n )}{' '}\n <span className=\"font-medium text-foreground\">{settings.displayName}</span>\n </p>\n {settings.aiAvailable ? null : (\n <p>\n {t(\n 'channel_discord.aiAutoReply.unavailable',\n 'The AI assistant module is not installed in this deployment, so auto-reply cannot be enabled. The channel keeps working as a normal inbox.',\n )}\n </p>\n )}\n {settings.aiAutoReplyLastError ? (\n // An armed channel whose runtime call keeps being refused is the\n // dormancy failure wearing a green tag. It is reported here, on the\n // surface that armed it, rather than only in a subscriber log line.\n <p className=\"rounded-md border border-status-error-border bg-status-error-bg p-3 text-status-error-text\">\n {t(\n 'channel_discord.aiAutoReply.lastError',\n 'The last auto-reply attempt on this channel produced nothing: {reason}',\n { reason: settings.aiAutoReplyLastError },\n )}\n {settings.aiAutoReplyLastErrorAt ? (\n <span className=\"ml-1\">\n {t('channel_discord.aiAutoReply.lastErrorAt', '(first seen {at})', {\n at: new Date(settings.aiAutoReplyLastErrorAt).toLocaleString(),\n })}\n </span>\n ) : null}\n </p>\n ) : null}\n </div>\n }\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
- "mappings": ";AA0MU,cA+CI,YA/CJ;AAxMV,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgC;AACzC,SAAS,cAAc,gBAAgB,2BAA2B;AAClE,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AAgCpC,MAAM,qBAAqB;AAYZ,SAAR,uBAAwC,EAAE,OAAO,GAAiC;AACvF,QAAM,IAAI,KAAK;AACf,QAAM,YAAY,QAAQ,MAAM;AAEhC,QAAM,CAAC,UAAU,WAAW,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E,oCAAoC,MAAM;AAAA,MACzD,eACE,qBAAC,SAAI,WAAU,gDACb;AAAA,6BAAC,OACE;AAAA;AAAA,YACC;AAAA,YACA;AAAA,UACF;AAAA,UAAG;AAAA,UACH,oBAAC,UAAK,WAAU,+BAA+B,mBAAS,aAAY;AAAA,WACtE;AAAA,QACC,SAAS,cAAc,OACtB,oBAAC,OACE;AAAA,UACC;AAAA,UACA;AAAA,QACF,GACF;AAAA,QAED,SAAS;AAAA;AAAA;AAAA;AAAA,UAIR,qBAAC,OAAE,WAAU,8FACV;AAAA;AAAA,cACC;AAAA,cACA;AAAA,cACA,EAAE,QAAQ,SAAS,qBAAqB;AAAA,YAC1C;AAAA,YACC,SAAS,yBACR,oBAAC,UAAK,WAAU,QACb,YAAE,2CAA2C,qBAAqB;AAAA,cACjE,IAAI,IAAI,KAAK,SAAS,sBAAsB,EAAE,eAAe;AAAA,YAC/D,CAAC,GACH,IACE;AAAA,aACN;AAAA,YACE;AAAA,SACN;AAAA;AAAA,EAEJ,GACF,GACF;AAEJ;",
4
+ "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudField } from '@open-mercato/ui/backend/CrudForm'\nimport { ErrorMessage, LoadingMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { updateCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\n\ntype EligibleAgent = {\n id: string\n label: string\n description: string\n requiredFeatures: string[]\n /** Whether the auto-reply principal holds the agent's `requiredFeatures`. */\n invocable: boolean\n missingFeatures: string[]\n}\n\ntype AiAutoReplySettings = {\n channelId: string\n displayName: string\n updatedAt: string | null\n aiAutoReplyEnabled: boolean\n aiAgentId: string | null\n aiAutoReplyLastError: string | null\n aiAutoReplyLastErrorAt: string | null\n defaultAgentId: string\n aiAvailable: boolean\n agents: EligibleAgent[]\n}\n\ntype FormValues = {\n id: string\n updatedAt: string | null\n aiAutoReplyEnabled: boolean\n aiAgentId: string\n}\n\nconst CHANNELS_LIST_HREF = '/backend/communication_channels/channels'\n\n/**\n * Per-channel AI auto-reply settings (issue #4778) \u2014 the surface that writes\n * `aiAutoReplyEnabled` / `aiAgentId`, the two keys the subscriber reads.\n *\n * It is a `CrudForm` rather than a hand-rolled form so the save inherits the\n * platform's contract for free: zod validation with field-level errors, and the\n * optimistic-lock header auto-derived from `initialValues.updatedAt`, so a save\n * from a tab opened before someone else touched the channel surfaces the shared\n * conflict bar instead of overwriting them.\n */\nexport default function DiscordAiAutoReplyPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const channelId = params?.id ?? ''\n\n const [settings, setSettings] = React.useState<AiAutoReplySettings | null>(null)\n const [isLoading, setIsLoading] = React.useState(true)\n const [errorMessage, setErrorMessage] = React.useState<string | null>(null)\n const [notFound, setNotFound] = React.useState(false)\n\n const load = React.useCallback(async () => {\n if (!channelId) {\n setIsLoading(false)\n setErrorMessage(t('channel_discord.aiAutoReply.errors.missingChannelId', 'No channel selected.'))\n return\n }\n setIsLoading(true)\n setErrorMessage(null)\n setNotFound(false)\n const response = await apiCall<AiAutoReplySettings>(\n `/api/channel_discord/channels/${encodeURIComponent(channelId)}/ai-auto-reply`,\n ).catch(() => null)\n if (!response || !response.ok) {\n const status = (response as { status?: number } | null)?.status\n if (status === 404) {\n setNotFound(true)\n } else {\n const body = response?.result as { error?: string } | undefined\n setErrorMessage(\n body?.error ?? t('channel_discord.aiAutoReply.errors.load', 'Failed to load AI auto-reply settings'),\n )\n }\n setSettings(null)\n } else {\n setSettings(response.result ?? null)\n }\n setIsLoading(false)\n }, [channelId, t])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const fields = React.useMemo<CrudField[]>(() => {\n // An agent the auto-reply principal cannot invoke stays in the list \u2014 hiding\n // it would leave the operator wondering where an agent they can see elsewhere\n // went \u2014 but it says what it needs, so the requirement is visible before the\n // save rather than only in the 400 that follows.\n const agentOptions = (settings?.agents ?? []).map((agent) => ({\n value: agent.id,\n label: agent.invocable\n ? agent.label\n : t(\n 'channel_discord.aiAutoReply.fields.agentMissingFeatures',\n '{label} \u2014 needs {features}',\n { label: agent.label, features: agent.missingFeatures.join(', ') },\n ),\n }))\n return [\n {\n id: 'aiAutoReplyEnabled',\n type: 'checkbox',\n label: t('channel_discord.aiAutoReply.fields.enabled', 'Answer inbound Discord messages with AI'),\n description: t(\n 'channel_discord.aiAutoReply.fields.enabledHelp',\n 'Off by default. When on, straightforward messages are answered automatically; anything sensitive, low-confidence or suspicious is proposed for a human to approve instead.',\n ),\n disabled: !settings?.aiAvailable,\n },\n {\n id: 'aiAgentId',\n type: 'select',\n label: t('channel_discord.aiAutoReply.fields.agent', 'Agent'),\n description: t(\n 'channel_discord.aiAutoReply.fields.agentHelp',\n 'Only agents that produce structured output can answer a channel. Grant the tenant channel-bot user the agent\u2019s required features before choosing an agent from another module.',\n ),\n options: agentOptions,\n required: true,\n visibleWhen: { field: 'aiAutoReplyEnabled', equals: true },\n },\n ]\n }, [settings, t])\n\n const initialValues = React.useMemo<Partial<FormValues>>(() => {\n if (!settings) return {}\n // Default to an agent the principal can actually invoke, so the form does not\n // pre-select a choice the save will reject.\n const invocable = settings.agents.filter((agent) => agent.invocable)\n const fallbackAgentId = invocable.some((agent) => agent.id === settings.defaultAgentId)\n ? settings.defaultAgentId\n : (invocable[0]?.id ?? settings.agents[0]?.id ?? '')\n return {\n id: settings.channelId,\n updatedAt: settings.updatedAt,\n aiAutoReplyEnabled: settings.aiAutoReplyEnabled,\n aiAgentId: settings.aiAgentId ?? fallbackAgentId,\n }\n }, [settings])\n\n const onSubmit = React.useCallback(\n async (values: FormValues) => {\n const enabled = Boolean(values.aiAutoReplyEnabled)\n const agentId = (values.aiAgentId ?? '').trim()\n if (enabled && !agentId) {\n throw createCrudFormError(\n t('channel_discord.aiAutoReply.errors.agentRequired', 'Choose the agent that should answer this channel'),\n { aiAgentId: t('channel_discord.aiAutoReply.errors.agentRequired', 'Choose the agent that should answer this channel') },\n )\n }\n // The route enforces this too \u2014 it has to, since a role can change between\n // the load and the save. Checking here as well turns the common case into an\n // inline field error instead of a round trip.\n const chosen = settings?.agents.find((agent) => agent.id === agentId)\n if (enabled && chosen && !chosen.invocable) {\n const message = t(\n 'channel_discord.aiAutoReply.errors.agentFeaturesMissing',\n 'The channel-bot user is missing the features this agent needs: {features}. Grant them first, or pick another agent.',\n { features: chosen.missingFeatures.join(', ') },\n )\n throw createCrudFormError(message, { aiAgentId: message })\n }\n // Deliberately unguarded: a 409 from the optimistic-lock check has to reach\n // CrudForm, which renders it on the shared conflict bar. Catching it here\n // would surface the same bar and then let the form believe the save\n // succeeded.\n await updateCrud(\n `channel_discord/channels/${encodeURIComponent(channelId)}/ai-auto-reply`,\n {\n aiAutoReplyEnabled: enabled,\n aiAgentId: enabled ? agentId : undefined,\n },\n {\n errorMessage: t(\n 'channel_discord.aiAutoReply.errors.save',\n 'Failed to save AI auto-reply settings',\n ),\n },\n )\n flash(t('channel_discord.aiAutoReply.saved', 'AI auto-reply settings saved.'), 'success')\n await load()\n },\n [channelId, load, settings, t],\n )\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('channel_discord.aiAutoReply.loading', 'Loading AI auto-reply settings...')} />\n </PageBody>\n </Page>\n )\n }\n\n if (notFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('channel_discord.aiAutoReply.notFound', 'Discord channel not found')}\n backHref={CHANNELS_LIST_HREF}\n />\n </PageBody>\n </Page>\n )\n }\n\n if (errorMessage || !settings) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage\n label={\n errorMessage\n ?? t('channel_discord.aiAutoReply.errors.load', 'Failed to load AI auto-reply settings')\n }\n />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm<FormValues>\n title={t('channel_discord.aiAutoReply.page.title', 'Discord AI auto-reply')}\n titleHeadingLevel={1}\n backHref={CHANNELS_LIST_HREF}\n cancelHref={CHANNELS_LIST_HREF}\n fields={fields}\n initialValues={initialValues}\n onSubmit={onSubmit}\n submitLabel={t('channel_discord.aiAutoReply.save', 'Save')}\n contentHeader={\n <div className=\"mb-4 space-y-2 text-sm text-muted-foreground\">\n <p>\n {t(\n 'channel_discord.aiAutoReply.intro',\n 'Choose whether this Discord channel may answer on its own, and which agent drafts the reply.',\n )}{' '}\n <span className=\"font-medium text-foreground\">{settings.displayName}</span>\n </p>\n {settings.aiAvailable ? null : (\n <p>\n {t(\n 'channel_discord.aiAutoReply.unavailable',\n 'The AI assistant module is not installed in this deployment, so auto-reply cannot be enabled. The channel keeps working as a normal inbox.',\n )}\n </p>\n )}\n {settings.aiAutoReplyLastError ? (\n // An armed channel whose runtime call keeps being refused is the\n // dormancy failure wearing a green tag. It is reported here, on the\n // surface that armed it, rather than only in a subscriber log line.\n <p className=\"rounded-md border border-status-error-border bg-status-error-bg p-3 text-status-error-text\">\n {t(\n 'channel_discord.aiAutoReply.lastError',\n 'The last auto-reply attempt on this channel produced nothing: {reason}',\n { reason: settings.aiAutoReplyLastError },\n )}\n {settings.aiAutoReplyLastErrorAt ? (\n <span className=\"ml-1\">\n {t('channel_discord.aiAutoReply.lastErrorAt', '(first seen {at})', {\n at: new Date(settings.aiAutoReplyLastErrorAt).toLocaleString(),\n })}\n </span>\n ) : null}\n </p>\n ) : null}\n </div>\n }\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
+ "mappings": ";AA0MU,cAgDI,YAhDJ;AAxMV,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgC;AACzC,SAAS,cAAc,gBAAgB,2BAA2B;AAClE,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,kBA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ACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,0CAA0C,uBAAuB;AAAA,MAC1E,mBAAmB;AAAA,MACnB,UAAU;AAAA,MACV,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,EAAE,oCAAoC,MAAM;AAAA,MACzD,eACE,qBAAC,SAAI,WAAU,gDACb;AAAA,6BAAC,OACE;AAAA;AAAA,YACC;AAAA,YACA;AAAA,UACF;AAAA,UAAG;AAAA,UACH,oBAAC,UAAK,WAAU,+BAA+B,mBAAS,aAAY;AAAA,WACtE;AAAA,QACC,SAAS,cAAc,OACtB,oBAAC,OACE;AAAA,UACC;AAAA,UACA;AAAA,QACF,GACF;AAAA,QAED,SAAS;AAAA;AAAA;AAAA;AAAA,UAIR,qBAAC,OAAE,WAAU,8FACV;AAAA;AAAA,cACC;AAAA,cACA;AAAA,cACA,EAAE,QAAQ,SAAS,qBAAqB;AAAA,YAC1C;AAAA,YACC,SAAS,yBACR,oBAAC,UAAK,WAAU,QACb,YAAE,2CAA2C,qBAAqB;AAAA,cACjE,IAAI,IAAI,KAAK,SAAS,sBAAsB,EAAE,eAAe;AAAA,YAC/D,CAAC,GACH,IACE;AAAA,aACN;AAAA,YACE;AAAA,SACN;AAAA;AAAA,EAEJ,GACF,GACF;AAEJ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/channel-discord",
3
- "version": "0.7.1-develop.7152.1.a69e92f9c9",
3
+ "version": "0.7.1-develop.7153.1.7145d295e6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,14 +62,14 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@open-mercato/core": "0.7.1-develop.7152.1.a69e92f9c9",
66
- "@open-mercato/queue": "0.7.1-develop.7152.1.a69e92f9c9",
67
- "@open-mercato/ui": "0.7.1-develop.7152.1.a69e92f9c9"
65
+ "@open-mercato/core": "0.7.1-develop.7153.1.7145d295e6",
66
+ "@open-mercato/queue": "0.7.1-develop.7153.1.7145d295e6",
67
+ "@open-mercato/ui": "0.7.1-develop.7153.1.7145d295e6"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@mikro-orm/postgresql": "^7.0.14",
71
- "@open-mercato/ai-assistant": "0.7.1-develop.7152.1.a69e92f9c9",
72
- "@open-mercato/shared": "0.7.1-develop.7152.1.a69e92f9c9",
71
+ "@open-mercato/ai-assistant": "0.7.1-develop.7153.1.7145d295e6",
72
+ "@open-mercato/shared": "0.7.1-develop.7153.1.7145d295e6",
73
73
  "react": "^19.0.0",
74
74
  "react-dom": "^19.0.0"
75
75
  },
@@ -79,8 +79,8 @@
79
79
  }
80
80
  },
81
81
  "devDependencies": {
82
- "@open-mercato/ai-assistant": "0.7.1-develop.7152.1.a69e92f9c9",
83
- "@open-mercato/shared": "0.7.1-develop.7152.1.a69e92f9c9",
82
+ "@open-mercato/ai-assistant": "0.7.1-develop.7153.1.7145d295e6",
83
+ "@open-mercato/shared": "0.7.1-develop.7153.1.7145d295e6",
84
84
  "@types/jest": "^30.0.0",
85
85
  "@types/react": "^19.2.17",
86
86
  "@types/react-dom": "^19.2.3",
@@ -239,6 +239,7 @@ export default function DiscordAiAutoReplyPage({ params }: { params?: { id?: str
239
239
  <PageBody>
240
240
  <CrudForm<FormValues>
241
241
  title={t('channel_discord.aiAutoReply.page.title', 'Discord AI auto-reply')}
242
+ titleHeadingLevel={1}
242
243
  backHref={CHANNELS_LIST_HREF}
243
244
  cancelHref={CHANNELS_LIST_HREF}
244
245
  fields={fields}