mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-11 08:16:03 +00:00
feat(platform): show deployment outbound IPs on adapter config forms
Cloud/NAT deployments couldn't complete WeCom-family / Official Account / QQ Official setup because the trusted-IP (IP whitelist) value — the server's egress IPs — was nowhere visible in LangBot. - config.yaml: new system.outbound_ips list (env: SYSTEM__OUTBOUND_IPS, comma-separated), exposed via GET /api/v1/system/info - dynamic form: generic __system.*-named display-only fields resolved from systemContext (same namespace as show_if), one read-only row per value with a copy button, excluded from form state and emitted values; hidden entirely when the deployment provides no IPs - manifests: trusted-IP display field for wecom, wecomcs, wecombot, officialaccount, qqofficial Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import { IDynamicFormItemSchema } from '@/app/infra/entities/form/dynamic';
|
||||
import { UUID } from 'uuidjs';
|
||||
import DynamicFormComponent from '@/app/home/components/dynamic-form/DynamicFormComponent';
|
||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
||||
import { systemInfo } from '@/app/infra/http';
|
||||
import { Bot } from '@/app/infra/entities/api';
|
||||
import { getAdapterDocUrl } from '@/app/infra/entities/adapter-docs';
|
||||
import { ExternalLink } from 'lucide-react';
|
||||
@@ -621,6 +622,7 @@ export default function BotForm({
|
||||
extra_webhook_url: extraWebhookUrl,
|
||||
bot_uuid: initBotId || '',
|
||||
adapter_config: form.getValues('adapter_config') || {},
|
||||
outbound_ips: systemInfo.outbound_ips,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { IDynamicFormItemSchema } from '@/app/infra/entities/form/dynamic';
|
||||
import {
|
||||
IDynamicFormItemSchema,
|
||||
SYSTEM_FIELD_PREFIX,
|
||||
} from '@/app/infra/entities/form/dynamic';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
@@ -44,8 +47,8 @@ function resolveShowIfValue(
|
||||
externalDependentValues?: Record<string, unknown>,
|
||||
systemContext?: Record<string, unknown>,
|
||||
): unknown {
|
||||
if (field.startsWith('__system.')) {
|
||||
const key = field.slice('__system.'.length);
|
||||
if (field.startsWith(SYSTEM_FIELD_PREFIX)) {
|
||||
const key = field.slice(SYSTEM_FIELD_PREFIX.length);
|
||||
return systemContext?.[key];
|
||||
}
|
||||
if (watchedValues[field] !== undefined) {
|
||||
@@ -198,6 +201,66 @@ function WebhookUrlField({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display-only component for `__system.*` fields (e.g. the deployment's
|
||||
* outbound IPs that the operator must add to a platform's trusted-IP list).
|
||||
* Renders one read-only row per value, each with a copy button. Rendered
|
||||
* outside of react-hook-form binding since the values come from
|
||||
* systemContext, not user input.
|
||||
*/
|
||||
function SystemInfoField({
|
||||
label,
|
||||
description,
|
||||
values,
|
||||
}: {
|
||||
label: string;
|
||||
description?: string;
|
||||
values: string[];
|
||||
}) {
|
||||
const [copiedIndex, setCopiedIndex] = useState<number | null>(null);
|
||||
|
||||
const handleCopy = (text: string, index: number) => {
|
||||
copyToClipboard(text).catch(() => {});
|
||||
setCopiedIndex(index);
|
||||
setTimeout(() => setCopiedIndex(null), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<FormItem className="min-w-0">
|
||||
<FormLabel className="break-words">{label}</FormLabel>
|
||||
<div className="space-y-2">
|
||||
{values.map((value, index) => (
|
||||
<div key={index} className="flex min-w-0 items-center gap-2">
|
||||
<Input
|
||||
value={value}
|
||||
readOnly
|
||||
className="min-w-0 flex-1 bg-muted"
|
||||
onClick={(e) => (e.target as HTMLInputElement).select()}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handleCopy(value, index)}
|
||||
>
|
||||
{copiedIndex === index ? (
|
||||
<Check className="h-4 w-4 text-green-600" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{description && (
|
||||
<p className="text-sm break-words text-muted-foreground">
|
||||
{description}
|
||||
</p>
|
||||
)}
|
||||
</FormItem>
|
||||
);
|
||||
}
|
||||
|
||||
// Hover-only Radix tooltips never open on touch devices (no pointer hover),
|
||||
// so the ``disabled_tooltip`` explaining why a field is locked was invisible on
|
||||
// mobile. This wrapper makes the info icon also toggle the tooltip on tap while
|
||||
@@ -290,15 +353,17 @@ export default function DynamicFormComponent({
|
||||
return value;
|
||||
};
|
||||
|
||||
// Filter out display-only field types (e.g. webhook-url, embed-code) that should not
|
||||
// participate in form state, validation, or value emission.
|
||||
// Filter out display-only fields (webhook-url/embed-code/qr-code-login types
|
||||
// and `__system.*`-named fields) that should not participate in form state,
|
||||
// validation, or value emission.
|
||||
const editableItems = useMemo(
|
||||
() =>
|
||||
itemConfigList.filter(
|
||||
(item) =>
|
||||
item.type !== 'webhook-url' &&
|
||||
item.type !== 'embed-code' &&
|
||||
item.type !== 'qr-code-login',
|
||||
item.type !== 'qr-code-login' &&
|
||||
!item.name.startsWith(SYSTEM_FIELD_PREFIX),
|
||||
),
|
||||
[itemConfigList],
|
||||
);
|
||||
@@ -583,6 +648,31 @@ export default function DynamicFormComponent({
|
||||
<DisabledTooltipIcon text={disabledTooltip} />
|
||||
) : null;
|
||||
|
||||
// `__system.*` fields are display-only; their value is resolved
|
||||
// from systemContext (same namespace as show_if), not user input.
|
||||
// Hidden entirely when the deployment doesn't provide the value.
|
||||
if (config.name.startsWith(SYSTEM_FIELD_PREFIX)) {
|
||||
const rawValue =
|
||||
systemContext?.[config.name.slice(SYSTEM_FIELD_PREFIX.length)];
|
||||
const values = (Array.isArray(rawValue) ? rawValue : [rawValue])
|
||||
.filter((v) => v !== undefined && v !== null && v !== '')
|
||||
.map(String);
|
||||
if (values.length === 0) return null;
|
||||
|
||||
return (
|
||||
<SystemInfoField
|
||||
key={config.id}
|
||||
label={extractI18nObject(config.label)}
|
||||
description={
|
||||
config.description
|
||||
? extractI18nObject(config.description)
|
||||
: undefined
|
||||
}
|
||||
values={values}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// Webhook URL fields are display-only; render outside of form binding
|
||||
if (config.type === 'webhook-url') {
|
||||
const webhookUrl = (systemContext?.webhook_url as string) || '';
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
DynamicFormItemType,
|
||||
IDynamicFormItemOption,
|
||||
IShowIfCondition,
|
||||
SYSTEM_FIELD_PREFIX,
|
||||
} from '@/app/infra/entities/form/dynamic';
|
||||
import { I18nObject } from '@/app/infra/entities/common';
|
||||
|
||||
@@ -50,6 +51,11 @@ export function getDefaultValues(
|
||||
): Record<string, any> {
|
||||
return itemConfigList.reduce(
|
||||
(acc, item) => {
|
||||
// `__system.*` fields are display-only (resolved from systemContext);
|
||||
// their placeholder defaults must not leak into the config values.
|
||||
if (item.name.startsWith(SYSTEM_FIELD_PREFIX)) {
|
||||
return acc;
|
||||
}
|
||||
acc[item.name] = item.default;
|
||||
return acc;
|
||||
},
|
||||
|
||||
@@ -348,6 +348,10 @@ export interface ApiRespSystemInfo {
|
||||
allow_modify_login_info: boolean;
|
||||
disable_models_service: boolean;
|
||||
limitation: SystemLimitation;
|
||||
/** Public outbound IPs of the deployment (``system.outbound_ips`` in
|
||||
* config.yaml). Shown on adapter config forms whose platform requires
|
||||
* trusted-IP / IP-whitelist settings. Empty = not configured. */
|
||||
outbound_ips: string[];
|
||||
wizard_status: string; // 'none' | 'skipped' | 'completed'
|
||||
wizard_progress: WizardProgress | null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { I18nObject } from '@/app/infra/entities/common';
|
||||
|
||||
/** Namespace prefix shared by ``show_if.field`` references and display-only
|
||||
* form item names whose value is resolved from the caller-supplied
|
||||
* ``DynamicFormComponent.systemContext``. */
|
||||
export const SYSTEM_FIELD_PREFIX = '__system.';
|
||||
|
||||
export interface IShowIfCondition {
|
||||
field: string;
|
||||
operator: 'eq' | 'neq' | 'in';
|
||||
@@ -11,6 +16,12 @@ export interface IDynamicFormItemSchema {
|
||||
id: string;
|
||||
default: string | number | boolean | Array<unknown>;
|
||||
label: I18nObject;
|
||||
/** Form value key. Names prefixed with ``__system.`` denote display-only
|
||||
* fields whose value is resolved from
|
||||
* ``DynamicFormComponent.systemContext`` (e.g. ``__system.outbound_ips``
|
||||
* → ``systemContext.outbound_ips``) — same namespace as ``show_if``.
|
||||
* Such fields are rendered read-only with copy buttons, excluded from
|
||||
* form state/validation/emission, and hidden when the value is empty. */
|
||||
name: string;
|
||||
required: boolean;
|
||||
type: DynamicFormItemType;
|
||||
|
||||
@@ -16,6 +16,7 @@ export const systemInfo: ApiRespSystemInfo = {
|
||||
max_pipelines: -1,
|
||||
max_extensions: -1,
|
||||
},
|
||||
outbound_ips: [],
|
||||
wizard_status: 'none',
|
||||
wizard_progress: null,
|
||||
};
|
||||
|
||||
@@ -939,6 +939,7 @@ function StepBotConfig({
|
||||
is_wizard: true,
|
||||
webhook_url: webhookUrl,
|
||||
extra_webhook_url: extraWebhookUrl,
|
||||
outbound_ips: systemInfo.outbound_ips,
|
||||
}}
|
||||
/>
|
||||
</CardContent>
|
||||
|
||||
Reference in New Issue
Block a user