"use strict";
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionServiceClient = void 0;
const stream_1 = require("stream");
const jsonProtos = require("../../protos/protos.json");
const google_gax_1 = require("google-gax");
/**
 * Client JSON configuration object, loaded from
 * `src/v1/session_service_client_config.json`.
 * This file defines retry strategy and timeouts for all API methods in this library.
 */
const gapicConfig = require("./session_service_client_config.json");
const version = require('../../../package.json').version;
/**
 *  Session service provides APIs for interacting with CES agents.
 * @class
 * @memberof v1
 */
class SessionServiceClient {
    _terminated = false;
    _opts;
    _providedCustomServicePath;
    _gaxModule;
    _gaxGrpc;
    _protos;
    _defaults;
    _universeDomain;
    _servicePath;
    _log = google_gax_1.loggingUtils.log('ces');
    auth;
    descriptors = {
        page: {},
        stream: {},
        longrunning: {},
        batching: {},
    };
    warn;
    innerApiCalls;
    locationsClient;
    pathTemplates;
    sessionServiceStub;
    /**
     * Construct an instance of SessionServiceClient.
     *
     * @param {object} [options] - The configuration object.
     * The options accepted by the constructor are described in detail
     * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
     * The common options are:
     * @param {object} [options.credentials] - Credentials object.
     * @param {string} [options.credentials.client_email]
     * @param {string} [options.credentials.private_key]
     * @param {string} [options.email] - Account email address. Required when
     *     using a .pem or .p12 keyFilename.
     * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
     *     .p12 key downloaded from the Google Developers Console. If you provide
     *     a path to a JSON file, the projectId option below is not necessary.
     *     NOTE: .pem and .p12 require you to specify options.email as well.
     * @param {number} [options.port] - The port on which to connect to
     *     the remote host.
     * @param {string} [options.projectId] - The project ID from the Google
     *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
     *     the environment variable GCLOUD_PROJECT for your project ID. If your
     *     app is running in an environment which supports
     *     {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials},
     *     your project ID will be detected automatically.
     * @param {string} [options.apiEndpoint] - The domain name of the
     *     API remote host.
     * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
     *     Follows the structure of {@link gapicConfig}.
     * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
     *     For more information, please check the
     *     {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
     * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
     *     need to avoid loading the default gRPC version and want to use the fallback
     *     HTTP implementation. Load only fallback version and pass it to the constructor:
     *     ```
     *     const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
     *     const client = new SessionServiceClient({fallback: true}, gax);
     *     ```
     */
    constructor(opts, gaxInstance) {
        // Ensure that options include all the required fields.
        const staticMembers = this.constructor;
        if (opts?.universe_domain &&
            opts?.universeDomain &&
            opts?.universe_domain !== opts?.universeDomain) {
            throw new Error('Please set either universe_domain or universeDomain, but not both.');
        }
        const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
            ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
            : undefined;
        this._universeDomain =
            opts?.universeDomain ??
                opts?.universe_domain ??
                universeDomainEnvVar ??
                'googleapis.com';
        this._servicePath = 'ces.' + this._universeDomain;
        const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath;
        this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint);
        const port = opts?.port || staticMembers.port;
        const clientConfig = opts?.clientConfig ?? {};
        const fallback = opts?.fallback ??
            (typeof window !== 'undefined' && typeof window?.fetch === 'function');
        opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
        // Request numeric enum values if REST transport is used.
        opts.numericEnums = true;
        // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
        if (servicePath !== this._servicePath && !('scopes' in opts)) {
            opts['scopes'] = staticMembers.scopes;
        }
        // Load google-gax module synchronously if needed
        if (!gaxInstance) {
            gaxInstance = require('google-gax');
        }
        // Choose either gRPC or proto-over-HTTP implementation of google-gax.
        this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
        // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
        this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
        // Save options to use in initialize() method.
        this._opts = opts;
        // Save the auth object to the client, for use by other methods.
        this.auth = this._gaxGrpc.auth;
        // Set useJWTAccessWithScope on the auth object.
        this.auth.useJWTAccessWithScope = true;
        // Set defaultServicePath on the auth object.
        this.auth.defaultServicePath = this._servicePath;
        // Set the default scopes in auth client if needed.
        if (servicePath === this._servicePath) {
            this.auth.defaultScopes = staticMembers.scopes;
        }
        this.locationsClient = new this._gaxModule.LocationsClient(this._gaxGrpc, opts);
        // Determine the client header string.
        const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
        if (typeof process === 'object' && 'versions' in process) {
            clientHeader.push(`gl-node/${process.versions.node}`);
        }
        else {
            clientHeader.push(`gl-web/${this._gaxModule.version}`);
        }
        if (!opts.fallback) {
            clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
        }
        else {
            clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
        }
        if (opts.libName && opts.libVersion) {
            clientHeader.push(`${opts.libName}/${opts.libVersion}`);
        }
        // Load the applicable protos.
        this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
        // This API contains "path templates"; forward-slash-separated
        // identifiers to uniquely identify resources within the API.
        // Create useful helper objects for these.
        this.pathTemplates = {
            agentPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/agents/{agent}'),
            appPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}'),
            appVersionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/versions/{version}'),
            changelogPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/changelogs/{changelog}'),
            conversationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/conversations/{conversation}'),
            deploymentPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/deployments/{deployment}'),
            examplePathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/examples/{example}'),
            guardrailPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/guardrails/{guardrail}'),
            omnichannelPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/omnichannels/{omnichannel}'),
            securitySettingsPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/securitySettings'),
            sessionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/sessions/{session}'),
            toolPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/tools/{tool}'),
            toolsetPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/apps/{app}/toolsets/{toolset}'),
        };
        // Some of the methods on this service provide streaming responses.
        // Provide descriptors for these.
        this.descriptors.stream = {
            streamRunSession: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
            bidiRunSession: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
        };
        // Put together the default options sent with requests.
        this._defaults = this._gaxGrpc.constructSettings('google.cloud.ces.v1.SessionService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
        // Set up a dictionary of "inner API calls"; the core implementation
        // of calling the API is handled in `google-gax`, with this code
        // merely providing the destination and request information.
        this.innerApiCalls = {};
        // Add a warn function to the client constructor so it can be easily tested.
        this.warn = this._gaxModule.warn;
    }
    /**
     * Initialize the client.
     * Performs asynchronous operations (such as authentication) and prepares the client.
     * This function will be called automatically when any class method is called for the
     * first time, but if you need to initialize it before calling an actual method,
     * feel free to call initialize() directly.
     *
     * You can await on this method if you want to make sure the client is initialized.
     *
     * @returns {Promise} A promise that resolves to an authenticated service stub.
     */
    initialize() {
        // If the client stub promise is already initialized, return immediately.
        if (this.sessionServiceStub) {
            return this.sessionServiceStub;
        }
        // Put together the "service stub" for
        // google.cloud.ces.v1.SessionService.
        this.sessionServiceStub = this._gaxGrpc.createStub(this._opts.fallback
            ? this._protos.lookupService('google.cloud.ces.v1.SessionService')
            : // eslint-disable-next-line @typescript-eslint/no-explicit-any
                this._protos.google.cloud.ces.v1.SessionService, this._opts, this._providedCustomServicePath);
        // Iterate over each of the methods that the service provides
        // and create an API call method for each.
        const sessionServiceStubMethods = [
            'runSession',
            'streamRunSession',
            'bidiRunSession',
        ];
        for (const methodName of sessionServiceStubMethods) {
            const callPromise = this.sessionServiceStub.then((stub) => (...args) => {
                if (this._terminated) {
                    if (methodName in this.descriptors.stream) {
                        const stream = new stream_1.PassThrough({ objectMode: true });
                        setImmediate(() => {
                            stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.'));
                        });
                        return stream;
                    }
                    return Promise.reject('The client has already been closed.');
                }
                const func = stub[methodName];
                return func.apply(stub, args);
            }, (err) => () => {
                throw err;
            });
            const descriptor = this.descriptors.stream[methodName] || undefined;
            const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
            this.innerApiCalls[methodName] = apiCall;
        }
        return this.sessionServiceStub;
    }
    /**
     * The DNS address for this API service.
     * @deprecated Use the apiEndpoint method of the client instance.
     * @returns {string} The DNS address for this service.
     */
    static get servicePath() {
        if (typeof process === 'object' &&
            typeof process.emitWarning === 'function') {
            process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
        }
        return 'ces.googleapis.com';
    }
    /**
     * The DNS address for this API service - same as servicePath.
     * @deprecated Use the apiEndpoint method of the client instance.
     * @returns {string} The DNS address for this service.
     */
    static get apiEndpoint() {
        if (typeof process === 'object' &&
            typeof process.emitWarning === 'function') {
            process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
        }
        return 'ces.googleapis.com';
    }
    /**
     * The DNS address for this API service.
     * @returns {string} The DNS address for this service.
     */
    get apiEndpoint() {
        return this._servicePath;
    }
    get universeDomain() {
        return this._universeDomain;
    }
    /**
     * The port for this API service.
     * @returns {number} The default port for this service.
     */
    static get port() {
        return 443;
    }
    /**
     * The scopes needed to make gRPC calls for every method defined
     * in this service.
     * @returns {string[]} List of default scopes.
     */
    static get scopes() {
        return [
            'https://www.googleapis.com/auth/ces',
            'https://www.googleapis.com/auth/cloud-platform',
        ];
    }
    /**
     * Return the project ID used by this class.
     * @returns {Promise} A promise that resolves to string containing the project ID.
     */
    getProjectId(callback) {
        if (callback) {
            this.auth.getProjectId(callback);
            return;
        }
        return this.auth.getProjectId();
    }
    runSession(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] =
            this._gaxModule.routingHeader.fromParams({
                'config.session': request.config.session ?? '',
            });
        this.initialize().catch((err) => {
            throw err;
        });
        this._log.info('runSession request %j', request);
        const wrappedCallback = callback
            ? (error, response, options, rawResponse) => {
                this._log.info('runSession response %j', response);
                callback(error, response, options, rawResponse); // We verified callback above.
            }
            : undefined;
        return this.innerApiCalls
            .runSession(request, options, wrappedCallback)
            ?.then(([response, options, rawResponse]) => {
            this._log.info('runSession response %j', response);
            return [response, options, rawResponse];
        })
            .catch((error) => {
            if (error &&
                'statusDetails' in error &&
                error.statusDetails instanceof Array) {
                const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
                error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
            }
            throw error;
        });
    }
    /**
     * Initiates a single-turn interaction with the CES agent. Uses server-side
     * streaming to deliver incremental results and partial responses as they are
     * generated.
     *
     * By default, complete responses (e.g., messages from callbacks or full LLM
     * responses) are sent to the client as soon as they are available. To enable
     * streaming individual text chunks directly from the model, set
     * {@link protos.google.cloud.ces.v1.SessionConfig.enable_text_streaming|enable_text_streaming}
     * to true.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {google.cloud.ces.v1.SessionConfig} request.config
     *   Required. The configuration for the session.
     * @param {number[]} request.inputs
     *   Required. Inputs for the session.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which emits {@link protos.google.cloud.ces.v1.RunSessionResponse|RunSessionResponse} on 'data' event.
     *   Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation }
     *   for more details and examples.
     * @example <caption>include:samples/generated/v1/session_service.stream_run_session.js</caption>
     * region_tag:ces_v1_generated_SessionService_StreamRunSession_async
     */
    streamRunSession(request, options) {
        request = request || {};
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] =
            this._gaxModule.routingHeader.fromParams({
                'config.session': request.config.session ?? '',
            });
        this.initialize().catch((err) => {
            throw err;
        });
        this._log.info('streamRunSession stream %j', options);
        return this.innerApiCalls.streamRunSession(request, options);
    }
    /**
     * Establishes a bidirectional streaming connection with the CES agent.
     * The agent processes continuous multimodal inputs (e.g., text, audio) and
     * generates real-time multimodal output streams.
     *
     * --- Client Request Stream ---
     * The client streams requests in the following order:
     *
     * 1.  Initialization:
     *     The first message must contain
     *     {@link protos.google.cloud.ces.v1.BidiSessionClientMessage.config|SessionConfig}.
     *     For audio sessions, this should also include
     *     {@link protos.google.cloud.ces.v1.SessionConfig.input_audio_config|InputAudioConfig}
     *     and
     *     {@link protos.google.cloud.ces.v1.SessionConfig.output_audio_config|OutputAudioConfig}
     *     to define audio processing and synthesis parameters.
     *
     * 2.  Interaction:
     *     Subsequent messages stream
     *     {@link protos.google.cloud.ces.v1.BidiSessionClientMessage.realtime_input|SessionInput}
     *     containing real-time user input data.
     *
     * 3.  Termination:
     *     The client should half-close the stream when there is no more user
     *     input. It should also half-close upon receiving
     *     {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.end_session|EndSession}
     *     or {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.go_away|GoAway} from
     *     the agent.
     *
     * --- Server Response Stream ---
     * For each interaction turn, the agent streams messages in the following
     * sequence:
     *
     * 1.  Speech Recognition (First N messages):
     *     Contains
     *     {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.recognition_result|RecognitionResult}
     *     representing the concatenated user speech segments captured so far.
     *     This is only populated for audio sessions.
     *
     * 2.  Response (Next M messages):
     *     Contains
     *     {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.session_output|SessionOutput}
     *     delivering the agent's response in various modalities (e.g., text,
     *     audio).
     *
     * 3.  Turn Completion (Final message of the turn):
     *     Contains
     *     {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.session_output|SessionOutput}
     *     with {@link protos.google.cloud.ces.v1.SessionOutput.turn_completed|turn_completed}
     *     set to true. This signals the end of the current turn and includes
     *     {@link protos.google.cloud.ces.v1.SessionOutput.diagnostic_info|DiagnosticInfo}
     *     with execution details.
     *
     * --- Audio Best Practices ---
     * 1.  Streaming:
     *     Stream {@link protos.google.cloud.ces.v1.SessionInput.audio|audio data}
     *     **CONTINUOUSLY**, even during silence. Recommended chunk size: 40-120ms
     *     (balances latency vs. efficiency).
     *
     * 2.  Playback & Interruption:
     *     Play {@link protos.google.cloud.ces.v1.SessionOutput.audio|audio responses} upon
     *     receipt. Stop playback immediately if an
     *     {@link protos.google.cloud.ces.v1.BidiSessionServerMessage.interruption_signal|InterruptionSignal}
     *     is received (e.g., user barge-in or new agent response).
     *
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which is both readable and writable. It accepts objects
     *   representing {@link protos.google.cloud.ces.v1.BidiSessionClientMessage|BidiSessionClientMessage} for write() method, and
     *   will emit objects representing {@link protos.google.cloud.ces.v1.BidiSessionServerMessage|BidiSessionServerMessage} on 'data' event asynchronously.
     *   Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation }
     *   for more details and examples.
     * @example <caption>include:samples/generated/v1/session_service.bidi_run_session.js</caption>
     * region_tag:ces_v1_generated_SessionService_BidiRunSession_async
     */
    bidiRunSession(options) {
        this.initialize().catch((err) => {
            throw err;
        });
        this._log.info('bidiRunSession stream %j', options);
        return this.innerApiCalls.bidiRunSession(null, options);
    }
    /**
     * Gets information about a location.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Resource name for the location.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html | CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing {@link google.cloud.location.Location | Location}.
     *   Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation }
     *   for more details and examples.
     * @example
     * ```
     * const [response] = await client.getLocation(request);
     * ```
     */
    getLocation(request, options, callback) {
        return this.locationsClient.getLocation(request, options, callback);
    }
    /**
     * Lists information about the supported locations for this service. Returns an iterable object.
     *
     * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   The resource that owns the locations collection, if applicable.
     * @param {string} request.filter
     *   The standard list filter.
     * @param {number} request.pageSize
     *   The standard list page size.
     * @param {string} request.pageToken
     *   The standard list page token.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Object}
     *   An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }.
     *   When you iterate the returned iterable, each element will be an object representing
     *   {@link google.cloud.location.Location | Location}. The API will be called under the hood as needed, once per the page,
     *   so you can stop the iteration when you don't need more results.
     *   Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
     *   for more details and examples.
     * @example
     * ```
     * const iterable = client.listLocationsAsync(request);
     * for await (const response of iterable) {
     *   // process response
     * }
     * ```
     */
    listLocationsAsync(request, options) {
        return this.locationsClient.listLocationsAsync(request, options);
    }
    // --------------------
    // -- Path templates --
    // --------------------
    /**
     * Return a fully-qualified agent resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} agent
     * @returns {string} Resource name string.
     */
    agentPath(project, location, app, agent) {
        return this.pathTemplates.agentPathTemplate.render({
            project: project,
            location: location,
            app: app,
            agent: agent,
        });
    }
    /**
     * Parse the project from Agent resource.
     *
     * @param {string} agentName
     *   A fully-qualified path representing Agent resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromAgentName(agentName) {
        return this.pathTemplates.agentPathTemplate.match(agentName).project;
    }
    /**
     * Parse the location from Agent resource.
     *
     * @param {string} agentName
     *   A fully-qualified path representing Agent resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromAgentName(agentName) {
        return this.pathTemplates.agentPathTemplate.match(agentName).location;
    }
    /**
     * Parse the app from Agent resource.
     *
     * @param {string} agentName
     *   A fully-qualified path representing Agent resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromAgentName(agentName) {
        return this.pathTemplates.agentPathTemplate.match(agentName).app;
    }
    /**
     * Parse the agent from Agent resource.
     *
     * @param {string} agentName
     *   A fully-qualified path representing Agent resource.
     * @returns {string} A string representing the agent.
     */
    matchAgentFromAgentName(agentName) {
        return this.pathTemplates.agentPathTemplate.match(agentName).agent;
    }
    /**
     * Return a fully-qualified app resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @returns {string} Resource name string.
     */
    appPath(project, location, app) {
        return this.pathTemplates.appPathTemplate.render({
            project: project,
            location: location,
            app: app,
        });
    }
    /**
     * Parse the project from App resource.
     *
     * @param {string} appName
     *   A fully-qualified path representing App resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromAppName(appName) {
        return this.pathTemplates.appPathTemplate.match(appName).project;
    }
    /**
     * Parse the location from App resource.
     *
     * @param {string} appName
     *   A fully-qualified path representing App resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromAppName(appName) {
        return this.pathTemplates.appPathTemplate.match(appName).location;
    }
    /**
     * Parse the app from App resource.
     *
     * @param {string} appName
     *   A fully-qualified path representing App resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromAppName(appName) {
        return this.pathTemplates.appPathTemplate.match(appName).app;
    }
    /**
     * Return a fully-qualified appVersion resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} version
     * @returns {string} Resource name string.
     */
    appVersionPath(project, location, app, version) {
        return this.pathTemplates.appVersionPathTemplate.render({
            project: project,
            location: location,
            app: app,
            version: version,
        });
    }
    /**
     * Parse the project from AppVersion resource.
     *
     * @param {string} appVersionName
     *   A fully-qualified path representing AppVersion resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromAppVersionName(appVersionName) {
        return this.pathTemplates.appVersionPathTemplate.match(appVersionName)
            .project;
    }
    /**
     * Parse the location from AppVersion resource.
     *
     * @param {string} appVersionName
     *   A fully-qualified path representing AppVersion resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromAppVersionName(appVersionName) {
        return this.pathTemplates.appVersionPathTemplate.match(appVersionName)
            .location;
    }
    /**
     * Parse the app from AppVersion resource.
     *
     * @param {string} appVersionName
     *   A fully-qualified path representing AppVersion resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromAppVersionName(appVersionName) {
        return this.pathTemplates.appVersionPathTemplate.match(appVersionName).app;
    }
    /**
     * Parse the version from AppVersion resource.
     *
     * @param {string} appVersionName
     *   A fully-qualified path representing AppVersion resource.
     * @returns {string} A string representing the version.
     */
    matchVersionFromAppVersionName(appVersionName) {
        return this.pathTemplates.appVersionPathTemplate.match(appVersionName)
            .version;
    }
    /**
     * Return a fully-qualified changelog resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} changelog
     * @returns {string} Resource name string.
     */
    changelogPath(project, location, app, changelog) {
        return this.pathTemplates.changelogPathTemplate.render({
            project: project,
            location: location,
            app: app,
            changelog: changelog,
        });
    }
    /**
     * Parse the project from Changelog resource.
     *
     * @param {string} changelogName
     *   A fully-qualified path representing Changelog resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromChangelogName(changelogName) {
        return this.pathTemplates.changelogPathTemplate.match(changelogName)
            .project;
    }
    /**
     * Parse the location from Changelog resource.
     *
     * @param {string} changelogName
     *   A fully-qualified path representing Changelog resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromChangelogName(changelogName) {
        return this.pathTemplates.changelogPathTemplate.match(changelogName)
            .location;
    }
    /**
     * Parse the app from Changelog resource.
     *
     * @param {string} changelogName
     *   A fully-qualified path representing Changelog resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromChangelogName(changelogName) {
        return this.pathTemplates.changelogPathTemplate.match(changelogName).app;
    }
    /**
     * Parse the changelog from Changelog resource.
     *
     * @param {string} changelogName
     *   A fully-qualified path representing Changelog resource.
     * @returns {string} A string representing the changelog.
     */
    matchChangelogFromChangelogName(changelogName) {
        return this.pathTemplates.changelogPathTemplate.match(changelogName)
            .changelog;
    }
    /**
     * Return a fully-qualified conversation resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} conversation
     * @returns {string} Resource name string.
     */
    conversationPath(project, location, app, conversation) {
        return this.pathTemplates.conversationPathTemplate.render({
            project: project,
            location: location,
            app: app,
            conversation: conversation,
        });
    }
    /**
     * Parse the project from Conversation resource.
     *
     * @param {string} conversationName
     *   A fully-qualified path representing Conversation resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromConversationName(conversationName) {
        return this.pathTemplates.conversationPathTemplate.match(conversationName)
            .project;
    }
    /**
     * Parse the location from Conversation resource.
     *
     * @param {string} conversationName
     *   A fully-qualified path representing Conversation resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromConversationName(conversationName) {
        return this.pathTemplates.conversationPathTemplate.match(conversationName)
            .location;
    }
    /**
     * Parse the app from Conversation resource.
     *
     * @param {string} conversationName
     *   A fully-qualified path representing Conversation resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromConversationName(conversationName) {
        return this.pathTemplates.conversationPathTemplate.match(conversationName)
            .app;
    }
    /**
     * Parse the conversation from Conversation resource.
     *
     * @param {string} conversationName
     *   A fully-qualified path representing Conversation resource.
     * @returns {string} A string representing the conversation.
     */
    matchConversationFromConversationName(conversationName) {
        return this.pathTemplates.conversationPathTemplate.match(conversationName)
            .conversation;
    }
    /**
     * Return a fully-qualified deployment resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} deployment
     * @returns {string} Resource name string.
     */
    deploymentPath(project, location, app, deployment) {
        return this.pathTemplates.deploymentPathTemplate.render({
            project: project,
            location: location,
            app: app,
            deployment: deployment,
        });
    }
    /**
     * Parse the project from Deployment resource.
     *
     * @param {string} deploymentName
     *   A fully-qualified path representing Deployment resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromDeploymentName(deploymentName) {
        return this.pathTemplates.deploymentPathTemplate.match(deploymentName)
            .project;
    }
    /**
     * Parse the location from Deployment resource.
     *
     * @param {string} deploymentName
     *   A fully-qualified path representing Deployment resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromDeploymentName(deploymentName) {
        return this.pathTemplates.deploymentPathTemplate.match(deploymentName)
            .location;
    }
    /**
     * Parse the app from Deployment resource.
     *
     * @param {string} deploymentName
     *   A fully-qualified path representing Deployment resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromDeploymentName(deploymentName) {
        return this.pathTemplates.deploymentPathTemplate.match(deploymentName).app;
    }
    /**
     * Parse the deployment from Deployment resource.
     *
     * @param {string} deploymentName
     *   A fully-qualified path representing Deployment resource.
     * @returns {string} A string representing the deployment.
     */
    matchDeploymentFromDeploymentName(deploymentName) {
        return this.pathTemplates.deploymentPathTemplate.match(deploymentName)
            .deployment;
    }
    /**
     * Return a fully-qualified example resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} example
     * @returns {string} Resource name string.
     */
    examplePath(project, location, app, example) {
        return this.pathTemplates.examplePathTemplate.render({
            project: project,
            location: location,
            app: app,
            example: example,
        });
    }
    /**
     * Parse the project from Example resource.
     *
     * @param {string} exampleName
     *   A fully-qualified path representing Example resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromExampleName(exampleName) {
        return this.pathTemplates.examplePathTemplate.match(exampleName).project;
    }
    /**
     * Parse the location from Example resource.
     *
     * @param {string} exampleName
     *   A fully-qualified path representing Example resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromExampleName(exampleName) {
        return this.pathTemplates.examplePathTemplate.match(exampleName).location;
    }
    /**
     * Parse the app from Example resource.
     *
     * @param {string} exampleName
     *   A fully-qualified path representing Example resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromExampleName(exampleName) {
        return this.pathTemplates.examplePathTemplate.match(exampleName).app;
    }
    /**
     * Parse the example from Example resource.
     *
     * @param {string} exampleName
     *   A fully-qualified path representing Example resource.
     * @returns {string} A string representing the example.
     */
    matchExampleFromExampleName(exampleName) {
        return this.pathTemplates.examplePathTemplate.match(exampleName).example;
    }
    /**
     * Return a fully-qualified guardrail resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} guardrail
     * @returns {string} Resource name string.
     */
    guardrailPath(project, location, app, guardrail) {
        return this.pathTemplates.guardrailPathTemplate.render({
            project: project,
            location: location,
            app: app,
            guardrail: guardrail,
        });
    }
    /**
     * Parse the project from Guardrail resource.
     *
     * @param {string} guardrailName
     *   A fully-qualified path representing Guardrail resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromGuardrailName(guardrailName) {
        return this.pathTemplates.guardrailPathTemplate.match(guardrailName)
            .project;
    }
    /**
     * Parse the location from Guardrail resource.
     *
     * @param {string} guardrailName
     *   A fully-qualified path representing Guardrail resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromGuardrailName(guardrailName) {
        return this.pathTemplates.guardrailPathTemplate.match(guardrailName)
            .location;
    }
    /**
     * Parse the app from Guardrail resource.
     *
     * @param {string} guardrailName
     *   A fully-qualified path representing Guardrail resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromGuardrailName(guardrailName) {
        return this.pathTemplates.guardrailPathTemplate.match(guardrailName).app;
    }
    /**
     * Parse the guardrail from Guardrail resource.
     *
     * @param {string} guardrailName
     *   A fully-qualified path representing Guardrail resource.
     * @returns {string} A string representing the guardrail.
     */
    matchGuardrailFromGuardrailName(guardrailName) {
        return this.pathTemplates.guardrailPathTemplate.match(guardrailName)
            .guardrail;
    }
    /**
     * Return a fully-qualified omnichannel resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} omnichannel
     * @returns {string} Resource name string.
     */
    omnichannelPath(project, location, omnichannel) {
        return this.pathTemplates.omnichannelPathTemplate.render({
            project: project,
            location: location,
            omnichannel: omnichannel,
        });
    }
    /**
     * Parse the project from Omnichannel resource.
     *
     * @param {string} omnichannelName
     *   A fully-qualified path representing Omnichannel resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromOmnichannelName(omnichannelName) {
        return this.pathTemplates.omnichannelPathTemplate.match(omnichannelName)
            .project;
    }
    /**
     * Parse the location from Omnichannel resource.
     *
     * @param {string} omnichannelName
     *   A fully-qualified path representing Omnichannel resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromOmnichannelName(omnichannelName) {
        return this.pathTemplates.omnichannelPathTemplate.match(omnichannelName)
            .location;
    }
    /**
     * Parse the omnichannel from Omnichannel resource.
     *
     * @param {string} omnichannelName
     *   A fully-qualified path representing Omnichannel resource.
     * @returns {string} A string representing the omnichannel.
     */
    matchOmnichannelFromOmnichannelName(omnichannelName) {
        return this.pathTemplates.omnichannelPathTemplate.match(omnichannelName)
            .omnichannel;
    }
    /**
     * Return a fully-qualified securitySettings resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @returns {string} Resource name string.
     */
    securitySettingsPath(project, location) {
        return this.pathTemplates.securitySettingsPathTemplate.render({
            project: project,
            location: location,
        });
    }
    /**
     * Parse the project from SecuritySettings resource.
     *
     * @param {string} securitySettingsName
     *   A fully-qualified path representing SecuritySettings resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromSecuritySettingsName(securitySettingsName) {
        return this.pathTemplates.securitySettingsPathTemplate.match(securitySettingsName).project;
    }
    /**
     * Parse the location from SecuritySettings resource.
     *
     * @param {string} securitySettingsName
     *   A fully-qualified path representing SecuritySettings resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromSecuritySettingsName(securitySettingsName) {
        return this.pathTemplates.securitySettingsPathTemplate.match(securitySettingsName).location;
    }
    /**
     * Return a fully-qualified session resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} session
     * @returns {string} Resource name string.
     */
    sessionPath(project, location, app, session) {
        return this.pathTemplates.sessionPathTemplate.render({
            project: project,
            location: location,
            app: app,
            session: session,
        });
    }
    /**
     * Parse the project from Session resource.
     *
     * @param {string} sessionName
     *   A fully-qualified path representing Session resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromSessionName(sessionName) {
        return this.pathTemplates.sessionPathTemplate.match(sessionName).project;
    }
    /**
     * Parse the location from Session resource.
     *
     * @param {string} sessionName
     *   A fully-qualified path representing Session resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromSessionName(sessionName) {
        return this.pathTemplates.sessionPathTemplate.match(sessionName).location;
    }
    /**
     * Parse the app from Session resource.
     *
     * @param {string} sessionName
     *   A fully-qualified path representing Session resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromSessionName(sessionName) {
        return this.pathTemplates.sessionPathTemplate.match(sessionName).app;
    }
    /**
     * Parse the session from Session resource.
     *
     * @param {string} sessionName
     *   A fully-qualified path representing Session resource.
     * @returns {string} A string representing the session.
     */
    matchSessionFromSessionName(sessionName) {
        return this.pathTemplates.sessionPathTemplate.match(sessionName).session;
    }
    /**
     * Return a fully-qualified tool resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} tool
     * @returns {string} Resource name string.
     */
    toolPath(project, location, app, tool) {
        return this.pathTemplates.toolPathTemplate.render({
            project: project,
            location: location,
            app: app,
            tool: tool,
        });
    }
    /**
     * Parse the project from Tool resource.
     *
     * @param {string} toolName
     *   A fully-qualified path representing Tool resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromToolName(toolName) {
        return this.pathTemplates.toolPathTemplate.match(toolName).project;
    }
    /**
     * Parse the location from Tool resource.
     *
     * @param {string} toolName
     *   A fully-qualified path representing Tool resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromToolName(toolName) {
        return this.pathTemplates.toolPathTemplate.match(toolName).location;
    }
    /**
     * Parse the app from Tool resource.
     *
     * @param {string} toolName
     *   A fully-qualified path representing Tool resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromToolName(toolName) {
        return this.pathTemplates.toolPathTemplate.match(toolName).app;
    }
    /**
     * Parse the tool from Tool resource.
     *
     * @param {string} toolName
     *   A fully-qualified path representing Tool resource.
     * @returns {string} A string representing the tool.
     */
    matchToolFromToolName(toolName) {
        return this.pathTemplates.toolPathTemplate.match(toolName).tool;
    }
    /**
     * Return a fully-qualified toolset resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} app
     * @param {string} toolset
     * @returns {string} Resource name string.
     */
    toolsetPath(project, location, app, toolset) {
        return this.pathTemplates.toolsetPathTemplate.render({
            project: project,
            location: location,
            app: app,
            toolset: toolset,
        });
    }
    /**
     * Parse the project from Toolset resource.
     *
     * @param {string} toolsetName
     *   A fully-qualified path representing Toolset resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromToolsetName(toolsetName) {
        return this.pathTemplates.toolsetPathTemplate.match(toolsetName).project;
    }
    /**
     * Parse the location from Toolset resource.
     *
     * @param {string} toolsetName
     *   A fully-qualified path representing Toolset resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromToolsetName(toolsetName) {
        return this.pathTemplates.toolsetPathTemplate.match(toolsetName).location;
    }
    /**
     * Parse the app from Toolset resource.
     *
     * @param {string} toolsetName
     *   A fully-qualified path representing Toolset resource.
     * @returns {string} A string representing the app.
     */
    matchAppFromToolsetName(toolsetName) {
        return this.pathTemplates.toolsetPathTemplate.match(toolsetName).app;
    }
    /**
     * Parse the toolset from Toolset resource.
     *
     * @param {string} toolsetName
     *   A fully-qualified path representing Toolset resource.
     * @returns {string} A string representing the toolset.
     */
    matchToolsetFromToolsetName(toolsetName) {
        return this.pathTemplates.toolsetPathTemplate.match(toolsetName).toolset;
    }
    /**
     * Terminate the gRPC channel and close the client.
     *
     * The client will no longer be usable and all future behavior is undefined.
     * @returns {Promise} A promise that resolves when the client is closed.
     */
    close() {
        if (this.sessionServiceStub && !this._terminated) {
            return this.sessionServiceStub.then((stub) => {
                this._log.info('ending gRPC channel');
                this._terminated = true;
                stub.close();
                this.locationsClient.close().catch((err) => {
                    throw err;
                });
            });
        }
        return Promise.resolve();
    }
}
exports.SessionServiceClient = SessionServiceClient;
//# sourceMappingURL=session_service_client.js.map