export function listBuiltinCapabilities(surface, account, rawCapabilities) {
    const supports = (capability) => rawCapabilities.includes(capability);
    return [
        {
            id: 'ingress',
            surface,
            label: 'Inbound messages',
            scope: 'surface',
            supported: supports('ingress'),
            detail: supports('ingress') ? 'Surface can accept inbound traffic into the runtime.' : 'Inbound traffic is not supported.',
            metadata: {},
        },
        {
            id: 'egress',
            surface,
            label: 'Outbound delivery',
            scope: 'delivery',
            supported: supports('egress'),
            detail: supports('egress') ? 'Surface can deliver replies and automation output.' : 'Outbound delivery is not supported.',
            metadata: {},
        },
        {
            id: 'threaded_reply',
            surface,
            label: 'Thread-aware replies',
            scope: 'interaction',
            supported: supports('threaded_reply'),
            detail: supports('threaded_reply') ? 'Replies can preserve thread context.' : 'Replies are not thread-aware.',
            metadata: {},
        },
        {
            id: 'interactive_actions',
            surface,
            label: 'Interactive actions',
            scope: 'interaction',
            supported: supports('interactive_actions'),
            detail: supports('interactive_actions') ? 'Surface supports button or interaction callbacks.' : 'Interactive callbacks are not available.',
            metadata: {},
        },
        {
            id: 'session_binding',
            surface,
            label: 'Session binding',
            scope: 'surface',
            supported: supports('session_binding'),
            detail: supports('session_binding') ? 'Routes can be bound to shared runtime sessions.' : 'Session binding is not supported on this surface.',
            metadata: {},
        },
        {
            id: 'account_posture',
            surface,
            label: 'Account posture',
            scope: 'accounts',
            supported: true,
            detail: `Account state: ${account.state}; auth posture: ${account.authState}.`,
            metadata: {
                accountId: account.accountId,
                configured: account.configured,
                linked: account.linked,
            },
        },
        {
            id: 'directory',
            surface,
            label: 'Directory lookup',
            scope: 'directory',
            supported: true,
            detail: 'Directory and group/member projections are available through the channel runtime.',
            metadata: {},
        },
        {
            id: 'tooling',
            surface,
            label: 'Channel tool bridge',
            scope: 'tooling',
            supported: true,
            detail: 'Channel-owned tools and operator actions can be executed through the shared channel tool bridge.',
            metadata: {},
        },
        {
            id: 'account_lifecycle',
            surface,
            label: 'Account lifecycle',
            scope: 'accounts',
            supported: supports('account_lifecycle'),
            detail: supports('account_lifecycle')
                ? 'Surface exposes account lifecycle commands through the channel runtime.'
                : 'Account lifecycle commands are not available.',
            metadata: {},
        },
        {
            id: 'target_resolution',
            surface,
            label: 'Target resolution',
            scope: 'directory',
            supported: supports('target_resolution'),
            detail: supports('target_resolution')
                ? 'Surface can resolve channel-specific target inputs into structured destinations.'
                : 'Target resolution is not available.',
            metadata: {},
        },
        {
            id: 'agent_tools',
            surface,
            label: 'Direct agent tools',
            scope: 'tooling',
            supported: supports('agent_tools'),
            detail: supports('agent_tools')
                ? 'Surface contributes direct tool entries to agent runtimes when the channel registry is active.'
                : 'Direct channel-owned agent tools are not available.',
            metadata: {},
        },
    ];
}
export function listBuiltinOperatorActions(surface) {
    return [
        {
            id: 'inspect-account',
            surface,
            label: 'Inspect account',
            description: 'Return the current channel-account posture and safe secret-source summary.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
            },
            metadata: {},
        },
        {
            id: 'inspect-status',
            surface,
            label: 'Inspect status',
            description: 'Return the current surface status snapshot.',
            dangerous: false,
            metadata: {},
        },
        {
            id: 'setup-schema',
            surface,
            label: 'Get setup schema',
            description: 'Return the versioned setup contract, secret targets, and external steps for this surface.',
            dangerous: false,
            metadata: {},
        },
        {
            id: 'doctor',
            surface,
            label: 'Run doctor',
            description: 'Return doctor checks and repair actions for this surface.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
            },
            metadata: {},
        },
        {
            id: 'repair-actions',
            surface,
            label: 'List repair actions',
            description: 'Return repair actions for this surface.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
            },
            metadata: {},
        },
        {
            id: 'lifecycle-state',
            surface,
            label: 'Get lifecycle state',
            description: 'Return lifecycle migration posture for this surface.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
            },
            metadata: {},
        },
        {
            id: 'migrate-lifecycle',
            surface,
            label: 'Apply lifecycle migration',
            description: 'Apply lifecycle migrations for this surface.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
            },
            metadata: {},
        },
        {
            id: 'list-directory',
            surface,
            label: 'List directory',
            description: 'Search or scope the route-backed channel directory.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    query: { type: 'string' },
                    scope: { type: 'string' },
                    groupId: { type: 'string' },
                    limit: { type: 'number' },
                },
            },
            metadata: {},
        },
        {
            id: 'list-capabilities',
            surface,
            label: 'List capabilities',
            description: 'Return the current channel capability descriptors.',
            dangerous: false,
            metadata: {},
        },
        {
            id: 'account-action',
            surface,
            label: 'Run account lifecycle action',
            description: 'Execute a safe channel-account lifecycle action such as inspect, retest, start, stop, login, or logout.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                    action: { type: 'string' },
                },
                required: ['action'],
            },
            metadata: {},
        },
        {
            id: 'resolve-target',
            surface,
            label: 'Resolve target',
            description: 'Resolve a channel-specific target like #channel, @user, a thread id, or a route-backed destination.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    target: { type: 'string' },
                    input: { type: 'string' },
                    preferredKind: { type: 'string' },
                    threadId: { type: 'string' },
                    accountId: { type: 'string' },
                    createIfMissing: { type: 'boolean' },
                    live: { type: 'boolean' },
                },
            },
            metadata: {},
        },
        {
            id: 'authorize-actor-action',
            surface,
            label: 'Authorize actor action',
            description: 'Check whether a channel actor can run a channel action against an account or target.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    actorId: { type: 'string' },
                    actionId: { type: 'string' },
                    accountId: { type: 'string' },
                    target: { type: 'string' },
                },
                required: ['actionId'],
            },
            metadata: {},
        },
        {
            id: 'resolve-allowlist',
            surface,
            label: 'Resolve allowlist entries',
            description: 'Resolve allowlist candidates into stable user, channel, or group identifiers.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    add: { type: 'array', items: { type: 'string' } },
                    remove: { type: 'array', items: { type: 'string' } },
                    kind: { type: 'string' },
                },
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: 'edit-allowlist',
            surface,
            label: 'Edit allowlist',
            description: 'Apply allowlist additions or removals at the surface or scoped group/channel level.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    add: { type: 'array', items: { type: 'string' } },
                    remove: { type: 'array', items: { type: 'string' } },
                    kind: { type: 'string' },
                    groupId: { type: 'string' },
                    channelId: { type: 'string' },
                    workspaceId: { type: 'string' },
                },
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: 'provider-api',
            surface,
            label: 'Run provider-native API operation',
            description: 'Run provider-native operations such as OAuth URL generation, live directory lookup, Discord command registration, or ntfy polling.',
            dangerous: false,
            inputSchema: {
                type: 'object',
                properties: {
                    operation: { type: 'string' },
                    query: { type: 'string' },
                    scope: { type: 'string' },
                    limit: { type: 'number' },
                    clientId: { type: 'string' },
                    redirectUri: { type: 'string' },
                    guildId: { type: 'string' },
                    topic: { type: 'string' },
                    since: { type: 'string' },
                },
                required: ['operation'],
                additionalProperties: true,
            },
            metadata: {},
        },
    ];
}
export function listBuiltinTools(surface) {
    return [
        {
            id: `${surface}:account`,
            surface,
            name: `${surface}_account`,
            description: `Inspect account posture for the ${surface} surface.`,
            actionIds: ['inspect-account'],
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:status`,
            surface,
            name: `${surface}_status`,
            description: `Inspect status for the ${surface} surface.`,
            actionIds: ['inspect-status'],
            inputSchema: {
                type: 'object',
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:setup_schema`,
            surface,
            name: `${surface}_setup_schema`,
            description: `Return the setup contract for the ${surface} surface.`,
            actionIds: ['setup-schema'],
            inputSchema: {
                type: 'object',
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:doctor`,
            surface,
            name: `${surface}_doctor`,
            description: `Run doctor checks for the ${surface} surface.`,
            actionIds: ['doctor'],
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:lifecycle`,
            surface,
            name: `${surface}_lifecycle`,
            description: `Return lifecycle migration posture for the ${surface} surface.`,
            actionIds: ['lifecycle-state'],
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                },
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:allowlist_resolve`,
            surface,
            name: `${surface}_allowlist_resolve`,
            description: `Resolve allowlist candidates for the ${surface} surface.`,
            actionIds: ['resolve-allowlist'],
            inputSchema: {
                type: 'object',
                properties: {
                    add: { type: 'array', items: { type: 'string' } },
                    remove: { type: 'array', items: { type: 'string' } },
                    kind: { type: 'string' },
                },
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: `${surface}:allowlist_edit`,
            surface,
            name: `${surface}_allowlist_edit`,
            description: `Edit allowlists for the ${surface} surface.`,
            actionIds: ['edit-allowlist'],
            inputSchema: {
                type: 'object',
                properties: {
                    add: { type: 'array', items: { type: 'string' } },
                    remove: { type: 'array', items: { type: 'string' } },
                    kind: { type: 'string' },
                    groupId: { type: 'string' },
                    channelId: { type: 'string' },
                    workspaceId: { type: 'string' },
                },
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: `${surface}:directory`,
            surface,
            name: `${surface}_directory`,
            description: `Query the ${surface} channel directory and group membership view.`,
            actionIds: ['list-directory'],
            inputSchema: {
                type: 'object',
                properties: {
                    query: { type: 'string' },
                    scope: { type: 'string' },
                    groupId: { type: 'string' },
                    limit: { type: 'number' },
                },
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:capabilities`,
            surface,
            name: `${surface}_capabilities`,
            description: `List capability descriptors for the ${surface} surface.`,
            actionIds: ['list-capabilities'],
            inputSchema: {
                type: 'object',
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:account_action`,
            surface,
            name: `${surface}_account_action`,
            description: `Run a safe account lifecycle action for the ${surface} surface.`,
            actionIds: ['account-action'],
            inputSchema: {
                type: 'object',
                properties: {
                    accountId: { type: 'string' },
                    action: { type: 'string' },
                },
                required: ['action'],
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: `${surface}:target`,
            surface,
            name: `${surface}_target`,
            description: `Resolve a ${surface} target into a structured channel destination.`,
            actionIds: ['resolve-target'],
            inputSchema: {
                type: 'object',
                properties: {
                    target: { type: 'string' },
                    input: { type: 'string' },
                    preferredKind: { type: 'string' },
                    threadId: { type: 'string' },
                    accountId: { type: 'string' },
                    createIfMissing: { type: 'boolean' },
                    live: { type: 'boolean' },
                },
                required: ['target'],
                additionalProperties: false,
            },
            metadata: {},
        },
        {
            id: `${surface}:authorize`,
            surface,
            name: `${surface}_authorize`,
            description: `Check whether a channel actor can run an action on the ${surface} surface.`,
            actionIds: ['authorize-actor-action'],
            inputSchema: {
                type: 'object',
                properties: {
                    actorId: { type: 'string' },
                    actionId: { type: 'string' },
                    accountId: { type: 'string' },
                    target: { type: 'string' },
                },
                required: ['actionId'],
                additionalProperties: true,
            },
            metadata: {},
        },
        {
            id: `${surface}:provider`,
            surface,
            name: `${surface}_provider`,
            description: `Run provider-native operations for the ${surface} surface.`,
            actionIds: ['provider-api'],
            inputSchema: {
                type: 'object',
                properties: {
                    operation: { type: 'string' },
                    query: { type: 'string' },
                    scope: { type: 'string' },
                    limit: { type: 'number' },
                    clientId: { type: 'string' },
                    redirectUri: { type: 'string' },
                    guildId: { type: 'string' },
                    topic: { type: 'string' },
                    since: { type: 'string' },
                },
                required: ['operation'],
                additionalProperties: true,
            },
            metadata: {},
        },
    ];
}
