import { createNimiError } from '../errors.js';
import { ReasonCode } from '../../types/index.js';
import { isRuntimeMethodAllowlisted, RuntimeMethodIds, } from '../method-ids.js';
import { createTauriIpcTransport } from '../transports/tauri-ipc.js';
import { RuntimeStreamMethodCodecs, RuntimeUnaryMethodCodecs, } from './method-codecs.js';
import { CancelCompanionParticipationRequest, CancelCompanionParticipationResponse, GetAvatarDebugReplayRequest, GetAvatarDebugReplayResponse, GetAvatarDebugSnapshotRequest, GetAvatarDebugSnapshotResponse, GetCompanionParticipationProjectionRequest, GetCompanionParticipationProjectionResponse, GetConversationAnchorSnapshotRequest, GetConversationAnchorSnapshotResponse, GetPublicChatSessionSnapshotRequest, GetPublicChatSessionSnapshotResponse, ListAvatarDebugProbeResultsRequest, ListAvatarDebugProbeResultsResponse, OpenConversationAnchorRequest, OpenConversationAnchorResponse, OpenCompanionParticipationReplayRequest, OpenCompanionParticipationReplayResponse, RegisterAvatarLiveInstanceBindingRequest, RegisterAvatarLiveInstanceBindingResponse, ResolveAvatarLiveInstanceBindingRequest, ResolveAvatarLiveInstanceBindingResponse, RequestAvatarDebugProbeRequest, RequestAvatarDebugProbeResponse, RequestCompanionParticipationRequest, RequestCompanionParticipationResponse, } from '../generated/runtime/v1/agent_service.js';
import { ExecuteDelegatedCapabilityRequest, ExecuteDelegatedCapabilityResponse, GetDelegatedControlSurfaceSnapshotRequest, GetDelegatedControlSurfaceSnapshotResponse, GetDelegatedReplayTraceRequest, GetDelegatedReplayTraceResponse, ListDelegatedApprovalRequestsRequest, ListDelegatedApprovalRequestsResponse, ListDelegatedDiagnosticsRequest, ListDelegatedDiagnosticsResponse, ListDelegatedProviderProfilesRequest, ListDelegatedProviderProfilesResponse, SetDelegatedProviderStateRequest, SetDelegatedProviderStateResponse, SubmitDelegatedApprovalDecisionRequest, SubmitDelegatedApprovalDecisionResponse, UpsertDelegatedProviderProfileRequest, UpsertDelegatedProviderProfileResponse, } from '../generated/runtime/v1/delegated_control.js';
import { CreateRealmGroupMessageCandidateRequest, CreateRealmGroupMessageCandidateResponse, GetRealmGroupMessageCandidateEvidenceRequest, GetRealmGroupMessageCandidateEvidenceResponse, } from '../generated/runtime/v1/agent_group_message_candidate.js';
import { decodeStreamEvent, decodeUnaryResponse, encodeRequest, } from './client-codec.js';
import { ensureAppId, normalizeRequestForMethod, } from './client-validation.js';
import { toStreamCall, toUnaryCall, } from './client-auth.js';
let nodeGrpcTransportModulePromise = null;
function loadNodeGrpcTransportModule() {
    if (!nodeGrpcTransportModulePromise) {
        const dynamicImport = new Function('specifier', 'return import(specifier)');
        nodeGrpcTransportModulePromise = dynamicImport('../transports/node-grpc.js');
    }
    return nodeGrpcTransportModulePromise;
}
function createDeferredNodeGrpcTransport(config) {
    let transportPromise = null;
    const ensureTransport = async () => {
        if (!transportPromise) {
            transportPromise = loadNodeGrpcTransportModule()
                .then((module) => module.createNodeGrpcTransport(config));
        }
        return transportPromise;
    };
    return {
        invokeUnary: async (input) => (await ensureTransport()).invokeUnary(input),
        openStream: async (input) => (await ensureTransport()).openStream(input),
        closeStream: async (input) => (await ensureTransport()).closeStream(input),
        destroy: async () => {
            if (!transportPromise) {
                return;
            }
            const transport = await transportPromise;
            await transport.destroy();
        },
    };
}
function createTransport(config) {
    if (config.transport.type === 'tauri-ipc') {
        return createTauriIpcTransport(config.transport);
    }
    return createDeferredNodeGrpcTransport(config.transport);
}
export function createRuntimeClient(input) {
    const config = {
        ...input,
        appId: ensureAppId(input.appId),
    };
    const transport = createTransport(config);
    const getUnaryCodec = (methodId) => RuntimeUnaryMethodCodecs[methodId];
    const getStreamCodec = (methodId) => RuntimeStreamMethodCodecs[methodId];
    const unary = (methodId) => async (request, options) => {
        if (!isRuntimeMethodAllowlisted(methodId)) {
            throw createNimiError({
                message: `${methodId} is not admitted by runtime-method-groups`,
                reasonCode: ReasonCode.SDK_RUNTIME_METHOD_UNAVAILABLE,
                actionHint: 'wait_for_runtime_method_group_admission',
                source: 'sdk',
                details: { methodId },
            });
        }
        const codec = getUnaryCodec(methodId);
        if (!codec) {
            throw createNimiError({
                message: `missing unary codec for ${methodId}`,
                reasonCode: ReasonCode.SDK_RUNTIME_CODEC_MISSING,
                actionHint: 'regenerate_proto_and_update_codec_map',
                source: 'sdk',
            });
        }
        const normalizedRequest = normalizeRequestForMethod(methodId, request, options);
        const wireRequest = encodeRequest(methodId, codec, normalizedRequest);
        const call = await toUnaryCall(config, methodId, wireRequest, normalizedRequest, options);
        const wireResponse = await transport.invokeUnary(call);
        return decodeUnaryResponse(methodId, codec, wireResponse);
    };
    const customUnary = (methodId, codec) => async (request, options) => {
        if (!isRuntimeMethodAllowlisted(methodId)) {
            throw createNimiError({
                message: `${methodId} is not admitted by runtime-method-groups`,
                reasonCode: ReasonCode.SDK_RUNTIME_METHOD_UNAVAILABLE,
                actionHint: 'wait_for_runtime_method_group_admission',
                source: 'sdk',
                details: { methodId },
            });
        }
        const normalizedRequest = normalizeRequestForMethod(methodId, request, options);
        const wireRequest = encodeRequest(methodId, codec, normalizedRequest);
        const call = await toUnaryCall(config, methodId, wireRequest, normalizedRequest, options);
        const wireResponse = await transport.invokeUnary(call);
        return decodeUnaryResponse(methodId, codec, wireResponse);
    };
    const stream = (methodId) => async (request, options) => {
        if (!isRuntimeMethodAllowlisted(methodId)) {
            throw createNimiError({
                message: `${methodId} is not admitted by runtime-method-groups`,
                reasonCode: ReasonCode.SDK_RUNTIME_METHOD_UNAVAILABLE,
                actionHint: 'wait_for_runtime_method_group_admission',
                source: 'sdk',
                details: { methodId },
            });
        }
        const codec = getStreamCodec(methodId);
        if (!codec) {
            throw createNimiError({
                message: `missing stream codec for ${methodId}`,
                reasonCode: ReasonCode.SDK_RUNTIME_CODEC_MISSING,
                actionHint: 'regenerate_proto_and_update_codec_map',
                source: 'sdk',
            });
        }
        const normalizedRequest = normalizeRequestForMethod(methodId, request, options);
        const wireRequest = encodeRequest(methodId, codec, normalizedRequest);
        const call = await toStreamCall(config, methodId, wireRequest, normalizedRequest, options);
        const wireStream = await transport.openStream(call);
        return {
            async *[Symbol.asyncIterator]() {
                for await (const eventBytes of wireStream) {
                    yield decodeStreamEvent(methodId, codec, eventBytes);
                }
            },
        };
    };
    return {
        appId: config.appId,
        transport: config.transport,
        auth: {
            registerApp: unary(RuntimeMethodIds.auth.registerApp),
            openSession: unary(RuntimeMethodIds.auth.openSession),
            refreshSession: unary(RuntimeMethodIds.auth.refreshSession),
            revokeSession: unary(RuntimeMethodIds.auth.revokeSession),
            registerExternalPrincipal: unary(RuntimeMethodIds.auth.registerExternalPrincipal),
            openExternalPrincipalSession: unary(RuntimeMethodIds.auth.openExternalPrincipalSession),
            revokeExternalPrincipalSession: unary(RuntimeMethodIds.auth.revokeExternalPrincipalSession),
        },
        appAuth: {
            authorizeExternalPrincipal: unary(RuntimeMethodIds.appAuth.authorizeExternalPrincipal),
            validateToken: unary(RuntimeMethodIds.appAuth.validateToken),
            revokeToken: unary(RuntimeMethodIds.appAuth.revokeToken),
            issueDelegatedToken: unary(RuntimeMethodIds.appAuth.issueDelegatedToken),
            listTokenChain: unary(RuntimeMethodIds.appAuth.listTokenChain),
        },
        account: {
            getAccountSessionStatus: unary(RuntimeMethodIds.account.getAccountSessionStatus),
            subscribeAccountSessionEvents: stream(RuntimeMethodIds.account.subscribeAccountSessionEvents),
            beginLogin: unary(RuntimeMethodIds.account.beginLogin),
            completeLogin: unary(RuntimeMethodIds.account.completeLogin),
            getAccessToken: unary(RuntimeMethodIds.account.getAccessToken),
            refreshAccountSession: unary(RuntimeMethodIds.account.refreshAccountSession),
            logout: unary(RuntimeMethodIds.account.logout),
            switchAccount: unary(RuntimeMethodIds.account.switchAccount),
            issueScopedAppBinding: unary(RuntimeMethodIds.account.issueScopedAppBinding),
            revokeScopedAppBinding: unary(RuntimeMethodIds.account.revokeScopedAppBinding),
            issueWorkspaceBinding: unary(RuntimeMethodIds.account.issueWorkspaceBinding),
            revokeWorkspaceBinding: unary(RuntimeMethodIds.account.revokeWorkspaceBinding),
        },
        ai: {
            executeScenario: unary(RuntimeMethodIds.ai.executeScenario),
            streamScenario: stream(RuntimeMethodIds.ai.streamScenario),
            submitScenarioJob: unary(RuntimeMethodIds.ai.submitScenarioJob),
            getScenarioJob: unary(RuntimeMethodIds.ai.getScenarioJob),
            cancelScenarioJob: unary(RuntimeMethodIds.ai.cancelScenarioJob),
            subscribeScenarioJobEvents: stream(RuntimeMethodIds.ai.subscribeScenarioJobEvents),
            getScenarioArtifacts: unary(RuntimeMethodIds.ai.getScenarioArtifacts),
            listScenarioProfiles: unary(RuntimeMethodIds.ai.listScenarioProfiles),
            getVoiceAsset: unary(RuntimeMethodIds.ai.getVoiceAsset),
            listVoiceAssets: unary(RuntimeMethodIds.ai.listVoiceAssets),
            deleteVoiceAsset: unary(RuntimeMethodIds.ai.deleteVoiceAsset),
            listPresetVoices: unary(RuntimeMethodIds.ai.listPresetVoices),
            openRealtimeSession: unary(RuntimeMethodIds.aiRealtime.openRealtimeSession),
            appendRealtimeInput: unary(RuntimeMethodIds.aiRealtime.appendRealtimeInput),
            readRealtimeEvents: stream(RuntimeMethodIds.aiRealtime.readRealtimeEvents),
            closeRealtimeSession: unary(RuntimeMethodIds.aiRealtime.closeRealtimeSession),
            peekScheduling: unary(RuntimeMethodIds.ai.peekScheduling),
        },
        workflow: {
            submit: unary(RuntimeMethodIds.workflow.submit),
            get: unary(RuntimeMethodIds.workflow.get),
            cancel: unary(RuntimeMethodIds.workflow.cancel),
            subscribeEvents: stream(RuntimeMethodIds.workflow.subscribeEvents),
        },
        model: {
            list: unary(RuntimeMethodIds.model.list),
            pull: unary(RuntimeMethodIds.model.pull),
            remove: unary(RuntimeMethodIds.model.remove),
            checkHealth: unary(RuntimeMethodIds.model.checkHealth),
        },
        local: {
            listLocalAssets: unary(RuntimeMethodIds.local.listLocalAssets),
            listVerifiedAssets: unary(RuntimeMethodIds.local.listVerifiedAssets),
            searchCatalogModels: unary(RuntimeMethodIds.local.searchCatalogModels),
            resolveModelInstallPlan: unary(RuntimeMethodIds.local.resolveModelInstallPlan),
            installVerifiedAsset: unary(RuntimeMethodIds.local.installVerifiedAsset),
            importLocalAsset: unary(RuntimeMethodIds.local.importLocalAsset),
            importLocalAssetFile: unary(RuntimeMethodIds.local.importLocalAssetFile),
            scanUnregisteredAssets: unary(RuntimeMethodIds.local.scanUnregisteredAssets),
            scaffoldOrphanAsset: unary(RuntimeMethodIds.local.scaffoldOrphanAsset),
            removeLocalAsset: unary(RuntimeMethodIds.local.removeLocalAsset),
            startLocalAsset: unary(RuntimeMethodIds.local.startLocalAsset),
            stopLocalAsset: unary(RuntimeMethodIds.local.stopLocalAsset),
            checkLocalAssetHealth: unary(RuntimeMethodIds.local.checkLocalAssetHealth),
            warmLocalAsset: unary(RuntimeMethodIds.local.warmLocalAsset),
            listLocalTransfers: unary(RuntimeMethodIds.local.listLocalTransfers),
            pauseLocalTransfer: unary(RuntimeMethodIds.local.pauseLocalTransfer),
            resumeLocalTransfer: unary(RuntimeMethodIds.local.resumeLocalTransfer),
            cancelLocalTransfer: unary(RuntimeMethodIds.local.cancelLocalTransfer),
            watchLocalTransfers: stream(RuntimeMethodIds.local.watchLocalTransfers),
            resolveLocalEnvironmentPlan: unary(RuntimeMethodIds.local.resolveLocalEnvironmentPlan),
            listLocalEnvironmentSelectedSources: unary(RuntimeMethodIds.local.listLocalEnvironmentSelectedSources),
            listLocalEnvironmentDependencyJobs: unary(RuntimeMethodIds.local.listLocalEnvironmentDependencyJobs),
            resolveLocalEnvironmentActivationGate: unary(RuntimeMethodIds.local.resolveLocalEnvironmentActivationGate),
            mintRuntimeBaselineReadiness: unary(RuntimeMethodIds.local.mintRuntimeBaselineReadiness),
            resolveRuntimeBaselineReadiness: unary(RuntimeMethodIds.local.resolveRuntimeBaselineReadiness),
            mintFirstRunExecutionEvidence: unary(RuntimeMethodIds.local.mintFirstRunExecutionEvidence),
            resolveFirstRunExecutionEvidence: unary(RuntimeMethodIds.local.resolveFirstRunExecutionEvidence),
            startLocalEnvironmentDependencyJob: unary(RuntimeMethodIds.local.startLocalEnvironmentDependencyJob),
            cancelLocalEnvironmentDependencyJob: unary(RuntimeMethodIds.local.cancelLocalEnvironmentDependencyJob),
            retryLocalEnvironmentDependencyJob: unary(RuntimeMethodIds.local.retryLocalEnvironmentDependencyJob),
            repairLocalEnvironmentDependency: unary(RuntimeMethodIds.local.repairLocalEnvironmentDependency),
            resolveLocalStateReconciliation: unary(RuntimeMethodIds.local.resolveLocalStateReconciliation),
            executeLocalStateCutover: unary(RuntimeMethodIds.local.executeLocalStateCutover),
            collectDeviceProfile: unary(RuntimeMethodIds.local.collectDeviceProfile),
            resolveProfile: unary(RuntimeMethodIds.local.resolveProfile),
            applyProfile: unary(RuntimeMethodIds.local.applyProfile),
            listLocalServices: unary(RuntimeMethodIds.local.listLocalServices),
            installLocalService: unary(RuntimeMethodIds.local.installLocalService),
            startLocalService: unary(RuntimeMethodIds.local.startLocalService),
            stopLocalService: unary(RuntimeMethodIds.local.stopLocalService),
            checkLocalServiceHealth: unary(RuntimeMethodIds.local.checkLocalServiceHealth),
            removeLocalService: unary(RuntimeMethodIds.local.removeLocalService),
            listNodeCatalog: unary(RuntimeMethodIds.local.listNodeCatalog),
            listLocalAudits: unary(RuntimeMethodIds.local.listLocalAudits),
            appendInferenceAudit: unary(RuntimeMethodIds.local.appendInferenceAudit),
            appendRuntimeAudit: unary(RuntimeMethodIds.local.appendRuntimeAudit),
            listEngines: unary(RuntimeMethodIds.local.listEngines),
            ensureEngine: unary(RuntimeMethodIds.local.ensureEngine),
            startEngine: unary(RuntimeMethodIds.local.startEngine),
            stopEngine: unary(RuntimeMethodIds.local.stopEngine),
            getEngineStatus: unary(RuntimeMethodIds.local.getEngineStatus),
        },
        connector: {
            createConnector: unary(RuntimeMethodIds.connector.createConnector),
            getConnector: unary(RuntimeMethodIds.connector.getConnector),
            listConnectors: unary(RuntimeMethodIds.connector.listConnectors),
            updateConnector: unary(RuntimeMethodIds.connector.updateConnector),
            deleteConnector: unary(RuntimeMethodIds.connector.deleteConnector),
            testConnector: unary(RuntimeMethodIds.connector.testConnector),
            listConnectorModels: unary(RuntimeMethodIds.connector.listConnectorModels),
            listProviderCatalog: unary(RuntimeMethodIds.connector.listProviderCatalog),
            listModelCatalogProviders: unary(RuntimeMethodIds.connector.listModelCatalogProviders),
            listCatalogProviderModels: unary(RuntimeMethodIds.connector.listCatalogProviderModels),
            getCatalogModelDetail: unary(RuntimeMethodIds.connector.getCatalogModelDetail),
            upsertModelCatalogProvider: unary(RuntimeMethodIds.connector.upsertModelCatalogProvider),
            deleteModelCatalogProvider: unary(RuntimeMethodIds.connector.deleteModelCatalogProvider),
            upsertCatalogModelOverlay: unary(RuntimeMethodIds.connector.upsertCatalogModelOverlay),
            deleteCatalogModelOverlay: unary(RuntimeMethodIds.connector.deleteCatalogModelOverlay),
        },
        knowledge: {
            createKnowledgeBank: unary(RuntimeMethodIds.knowledge.createKnowledgeBank),
            getKnowledgeBank: unary(RuntimeMethodIds.knowledge.getKnowledgeBank),
            listKnowledgeBanks: unary(RuntimeMethodIds.knowledge.listKnowledgeBanks),
            deleteKnowledgeBank: unary(RuntimeMethodIds.knowledge.deleteKnowledgeBank),
            putPage: unary(RuntimeMethodIds.knowledge.putPage),
            getPage: unary(RuntimeMethodIds.knowledge.getPage),
            listPages: unary(RuntimeMethodIds.knowledge.listPages),
            deletePage: unary(RuntimeMethodIds.knowledge.deletePage),
            searchKeyword: unary(RuntimeMethodIds.knowledge.searchKeyword),
            searchHybrid: unary(RuntimeMethodIds.knowledge.searchHybrid),
            addLink: unary(RuntimeMethodIds.knowledge.addLink),
            removeLink: unary(RuntimeMethodIds.knowledge.removeLink),
            listLinks: unary(RuntimeMethodIds.knowledge.listLinks),
            listBacklinks: unary(RuntimeMethodIds.knowledge.listBacklinks),
            traverseGraph: unary(RuntimeMethodIds.knowledge.traverseGraph),
            ingestDocument: unary(RuntimeMethodIds.knowledge.ingestDocument),
            getIngestTask: unary(RuntimeMethodIds.knowledge.getIngestTask),
        },
        memory: {
            createBank: unary(RuntimeMethodIds.memory.createBank),
            getBank: unary(RuntimeMethodIds.memory.getBank),
            listBanks: unary(RuntimeMethodIds.memory.listBanks),
            deleteBank: unary(RuntimeMethodIds.memory.deleteBank),
            retain: unary(RuntimeMethodIds.memory.retain),
            recall: unary(RuntimeMethodIds.memory.recall),
            history: unary(RuntimeMethodIds.memory.history),
            deleteMemory: unary(RuntimeMethodIds.memory.deleteMemory),
            subscribeEvents: stream(RuntimeMethodIds.memory.subscribeEvents),
        },
        agent: {
            initializeAgent: unary(RuntimeMethodIds.agent.initializeAgent),
            terminateAgent: unary(RuntimeMethodIds.agent.terminateAgent),
            getAgent: unary(RuntimeMethodIds.agent.getAgent),
            listAgents: unary(RuntimeMethodIds.agent.listAgents),
            openConversationAnchor: customUnary(RuntimeMethodIds.agent.openConversationAnchor, {
                requestType: OpenConversationAnchorRequest,
                responseType: OpenConversationAnchorResponse,
            }),
            getConversationAnchorSnapshot: customUnary(RuntimeMethodIds.agent.getConversationAnchorSnapshot, {
                requestType: GetConversationAnchorSnapshotRequest,
                responseType: GetConversationAnchorSnapshotResponse,
            }),
            registerAvatarLiveInstanceBinding: customUnary(RuntimeMethodIds.agent.registerAvatarLiveInstanceBinding, {
                requestType: RegisterAvatarLiveInstanceBindingRequest,
                responseType: RegisterAvatarLiveInstanceBindingResponse,
            }),
            resolveAvatarLiveInstanceBinding: customUnary(RuntimeMethodIds.agent.resolveAvatarLiveInstanceBinding, {
                requestType: ResolveAvatarLiveInstanceBindingRequest,
                responseType: ResolveAvatarLiveInstanceBindingResponse,
            }),
            getPublicChatSessionSnapshot: customUnary(RuntimeMethodIds.agent.getPublicChatSessionSnapshot, {
                requestType: GetPublicChatSessionSnapshotRequest,
                responseType: GetPublicChatSessionSnapshotResponse,
            }),
            getCompanionParticipationProjection: customUnary(RuntimeMethodIds.agent.getCompanionParticipationProjection, {
                requestType: GetCompanionParticipationProjectionRequest,
                responseType: GetCompanionParticipationProjectionResponse,
            }),
            requestCompanionParticipation: customUnary(RuntimeMethodIds.agent.requestCompanionParticipation, {
                requestType: RequestCompanionParticipationRequest,
                responseType: RequestCompanionParticipationResponse,
            }),
            cancelCompanionParticipation: customUnary(RuntimeMethodIds.agent.cancelCompanionParticipation, {
                requestType: CancelCompanionParticipationRequest,
                responseType: CancelCompanionParticipationResponse,
            }),
            openCompanionParticipationReplay: customUnary(RuntimeMethodIds.agent.openCompanionParticipationReplay, {
                requestType: OpenCompanionParticipationReplayRequest,
                responseType: OpenCompanionParticipationReplayResponse,
            }),
            createRealmGroupMessageCandidate: customUnary(RuntimeMethodIds.agent.createRealmGroupMessageCandidate, {
                requestType: CreateRealmGroupMessageCandidateRequest,
                responseType: CreateRealmGroupMessageCandidateResponse,
            }),
            getRealmGroupMessageCandidateEvidence: customUnary(RuntimeMethodIds.agent.getRealmGroupMessageCandidateEvidence, {
                requestType: GetRealmGroupMessageCandidateEvidenceRequest,
                responseType: GetRealmGroupMessageCandidateEvidenceResponse,
            }),
            getAvatarDebugSnapshot: customUnary(RuntimeMethodIds.agent.getAvatarDebugSnapshot, {
                requestType: GetAvatarDebugSnapshotRequest,
                responseType: GetAvatarDebugSnapshotResponse,
            }),
            requestAvatarDebugProbe: customUnary(RuntimeMethodIds.agent.requestAvatarDebugProbe, {
                requestType: RequestAvatarDebugProbeRequest,
                responseType: RequestAvatarDebugProbeResponse,
            }),
            listAvatarDebugProbeResults: customUnary(RuntimeMethodIds.agent.listAvatarDebugProbeResults, {
                requestType: ListAvatarDebugProbeResultsRequest,
                responseType: ListAvatarDebugProbeResultsResponse,
            }),
            getAvatarDebugReplay: customUnary(RuntimeMethodIds.agent.getAvatarDebugReplay, {
                requestType: GetAvatarDebugReplayRequest,
                responseType: GetAvatarDebugReplayResponse,
            }),
            listDelegatedProviderProfiles: customUnary(RuntimeMethodIds.agent.listDelegatedProviderProfiles, {
                requestType: ListDelegatedProviderProfilesRequest,
                responseType: ListDelegatedProviderProfilesResponse,
            }),
            upsertDelegatedProviderProfile: customUnary(RuntimeMethodIds.agent.upsertDelegatedProviderProfile, {
                requestType: UpsertDelegatedProviderProfileRequest,
                responseType: UpsertDelegatedProviderProfileResponse,
            }),
            setDelegatedProviderState: customUnary(RuntimeMethodIds.agent.setDelegatedProviderState, {
                requestType: SetDelegatedProviderStateRequest,
                responseType: SetDelegatedProviderStateResponse,
            }),
            listDelegatedApprovalRequests: customUnary(RuntimeMethodIds.agent.listDelegatedApprovalRequests, {
                requestType: ListDelegatedApprovalRequestsRequest,
                responseType: ListDelegatedApprovalRequestsResponse,
            }),
            submitDelegatedApprovalDecision: customUnary(RuntimeMethodIds.agent.submitDelegatedApprovalDecision, {
                requestType: SubmitDelegatedApprovalDecisionRequest,
                responseType: SubmitDelegatedApprovalDecisionResponse,
            }),
            listDelegatedDiagnostics: customUnary(RuntimeMethodIds.agent.listDelegatedDiagnostics, {
                requestType: ListDelegatedDiagnosticsRequest,
                responseType: ListDelegatedDiagnosticsResponse,
            }),
            getDelegatedReplayTrace: customUnary(RuntimeMethodIds.agent.getDelegatedReplayTrace, {
                requestType: GetDelegatedReplayTraceRequest,
                responseType: GetDelegatedReplayTraceResponse,
            }),
            getDelegatedControlSurfaceSnapshot: customUnary(RuntimeMethodIds.agent.getDelegatedControlSurfaceSnapshot, {
                requestType: GetDelegatedControlSurfaceSnapshotRequest,
                responseType: GetDelegatedControlSurfaceSnapshotResponse,
            }),
            executeDelegatedCapability: customUnary(RuntimeMethodIds.agent.executeDelegatedCapability, {
                requestType: ExecuteDelegatedCapabilityRequest,
                responseType: ExecuteDelegatedCapabilityResponse,
            }),
            getAgentState: unary(RuntimeMethodIds.agent.getAgentState),
            updateAgentState: unary(RuntimeMethodIds.agent.updateAgentState),
            setPresentationProfile: unary(RuntimeMethodIds.agent.setPresentationProfile),
            enableAutonomy: unary(RuntimeMethodIds.agent.enableAutonomy),
            disableAutonomy: unary(RuntimeMethodIds.agent.disableAutonomy),
            setAutonomyConfig: unary(RuntimeMethodIds.agent.setAutonomyConfig),
            listPendingHooks: unary(RuntimeMethodIds.agent.listPendingHooks),
            cancelHook: unary(RuntimeMethodIds.agent.cancelHook),
            queryMemory: unary(RuntimeMethodIds.agent.queryMemory),
            writeMemory: unary(RuntimeMethodIds.agent.writeMemory),
            subscribeEvents: stream(RuntimeMethodIds.agent.subscribeEvents),
        },
        app: {
            sendAppMessage: unary(RuntimeMethodIds.app.sendAppMessage),
            subscribeAppMessages: stream(RuntimeMethodIds.app.subscribeAppMessages),
            installApp: unary(RuntimeMethodIds.app.installApp),
            uninstallApp: unary(RuntimeMethodIds.app.uninstallApp),
            getAppInstallJob: unary(RuntimeMethodIds.app.getAppInstallJob),
            listAppInstallJobs: unary(RuntimeMethodIds.app.listAppInstallJobs),
            watchAppInstallJobEvents: stream(RuntimeMethodIds.app.watchAppInstallJobEvents),
            updateApp: unary(RuntimeMethodIds.app.updateApp),
            healthRepairApp: unary(RuntimeMethodIds.app.healthRepairApp),
            openApp: unary(RuntimeMethodIds.app.openApp),
        },
        artifact: {
            readArtifactBytes: unary(RuntimeMethodIds.artifact.readArtifactBytes),
        },
        audit: {
            listAuditEvents: unary(RuntimeMethodIds.audit.listAuditEvents),
            exportAuditEvents: stream(RuntimeMethodIds.audit.exportAuditEvents),
            listUsageStats: unary(RuntimeMethodIds.audit.listUsageStats),
            getRuntimeHealth: unary(RuntimeMethodIds.audit.getRuntimeHealth),
            listAIProviderHealth: unary(RuntimeMethodIds.audit.listAIProviderHealth),
            subscribeAIProviderHealthEvents: stream(RuntimeMethodIds.audit.subscribeAIProviderHealthEvents),
            subscribeRuntimeHealthEvents: stream(RuntimeMethodIds.audit.subscribeRuntimeHealthEvents),
        },
        closeStream: async (streamId) => {
            await transport.closeStream({ streamId });
        },
        close: async () => {
            await transport.destroy();
        },
    };
}
//# sourceMappingURL=client.js.map