|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * g3-prettier-ignore-file |
| 7 | + */ |
| 8 | + |
| 9 | +/* |
| 10 | + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. |
| 11 | + */ |
| 12 | + |
| 13 | +import { GoogleGenAICore } from "../core.js"; |
| 14 | +import { encodeFormQuery, encodeSimple } from "../lib/encodings.js"; |
| 15 | +import { matchStatusCode } from "../lib/http.js"; |
| 16 | +import * as M from "../lib/matchers.js"; |
| 17 | +import { compactMap } from "../lib/primitives.js"; |
| 18 | +import { RequestOptions } from "../lib/sdks.js"; |
| 19 | +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; |
| 20 | +import { pathToFunc } from "../lib/url.js"; |
| 21 | +import { GoogleGenAiError } from "../models/errors/google-gen-ai-error.js"; |
| 22 | +import { |
| 23 | + ConnectionError, |
| 24 | + InvalidRequestError, |
| 25 | + RequestAbortedError, |
| 26 | + RequestTimeoutError, |
| 27 | + UnexpectedClientError, |
| 28 | +} from "../models/errors/http-client-errors.js"; |
| 29 | +import * as operations from "../models/operations/index.js"; |
| 30 | +import { APICall, APIPromise } from "../types/async.js"; |
| 31 | +import { Result } from "../types/fp.js"; |
| 32 | + |
| 33 | +/** |
| 34 | + * List interactions. |
| 35 | + */ |
| 36 | +export function interactionsList( |
| 37 | + client: GoogleGenAICore, |
| 38 | + page_size?: number | undefined, |
| 39 | + page_token?: string | undefined, |
| 40 | + api_version?: string | undefined, |
| 41 | + options?: Omit<RequestOptions, "extra_body">, |
| 42 | +): APIPromise< |
| 43 | + Result< |
| 44 | + operations.ListInteractionsResponse, |
| 45 | + | GoogleGenAiError |
| 46 | + | ConnectionError |
| 47 | + | RequestAbortedError |
| 48 | + | RequestTimeoutError |
| 49 | + | InvalidRequestError |
| 50 | + | UnexpectedClientError |
| 51 | + > |
| 52 | +> { |
| 53 | + return new APIPromise($do( |
| 54 | + client, |
| 55 | + page_size, |
| 56 | + page_token, |
| 57 | + api_version, |
| 58 | + options, |
| 59 | + )); |
| 60 | +} |
| 61 | + |
| 62 | +async function $do( |
| 63 | + client: GoogleGenAICore, |
| 64 | + page_size?: number | undefined, |
| 65 | + page_token?: string | undefined, |
| 66 | + api_version?: string | undefined, |
| 67 | + options?: Omit<RequestOptions, "extra_body">, |
| 68 | +): Promise< |
| 69 | + [ |
| 70 | + Result< |
| 71 | + operations.ListInteractionsResponse, |
| 72 | + | GoogleGenAiError |
| 73 | + | ConnectionError |
| 74 | + | RequestAbortedError |
| 75 | + | RequestTimeoutError |
| 76 | + | InvalidRequestError |
| 77 | + | UnexpectedClientError |
| 78 | + >, |
| 79 | + APICall, |
| 80 | + ] |
| 81 | +> { |
| 82 | + const input: operations.ListInteractionsRequest | undefined = { |
| 83 | + page_size: page_size, |
| 84 | + page_token: page_token, |
| 85 | + api_version: api_version, |
| 86 | + }; |
| 87 | + |
| 88 | + const payload = input; |
| 89 | + const body = null; |
| 90 | + |
| 91 | + const pathParams = { |
| 92 | + api_version: encodeSimple( |
| 93 | + "api_version", |
| 94 | + payload?.api_version ?? client._options.api_version, |
| 95 | + { explode: false, charEncoding: "percent" }, |
| 96 | + ), |
| 97 | + }; |
| 98 | + const path = pathToFunc("/{api_version}/interactions:list")(pathParams); |
| 99 | + |
| 100 | + const query = encodeFormQuery({ |
| 101 | + "page_size": payload?.page_size, |
| 102 | + "page_token": payload?.page_token, |
| 103 | + }); |
| 104 | + |
| 105 | + const headers = new Headers(compactMap({ |
| 106 | + Accept: "application/json", |
| 107 | + })); |
| 108 | + |
| 109 | + const securityInput = await extractSecurity(client._options.security); |
| 110 | + const requestSecurity = resolveGlobalSecurity(securityInput); |
| 111 | + |
| 112 | + const context = { |
| 113 | + options: client._options, |
| 114 | + base_url: options?.server_url ?? client._baseURL ?? "", |
| 115 | + operation_id: "listInteractions", |
| 116 | + o_auth2_scopes: null, |
| 117 | + |
| 118 | + resolved_security: requestSecurity, |
| 119 | + |
| 120 | + security_source: client._options.security, |
| 121 | + retry_config: options?.retries |
| 122 | + || client._options.retry_config |
| 123 | + || { |
| 124 | + strategy: "attempt-count-backoff", |
| 125 | + backoff: { |
| 126 | + initialInterval: 500, |
| 127 | + maxInterval: 8000, |
| 128 | + exponent: 2, |
| 129 | + maxElapsedTime: 30000, |
| 130 | + }, |
| 131 | + retryConnectionErrors: true, |
| 132 | + maxRetries: 4, |
| 133 | + } |
| 134 | + || { strategy: "none" }, |
| 135 | + retry_codes: options?.retry_codes || ["408", "409", "429", "5XX"], |
| 136 | + }; |
| 137 | + |
| 138 | + const requestRes = client._createRequest(context, { |
| 139 | + security: requestSecurity, |
| 140 | + method: "GET", |
| 141 | + baseURL: options?.server_url, |
| 142 | + path: path, |
| 143 | + headers: headers, |
| 144 | + query: query, |
| 145 | + body: body, |
| 146 | + userAgent: client._options.user_agent, |
| 147 | + timeout_ms: options?.timeout_ms || client._options.timeout_ms || -1, |
| 148 | + }, options); |
| 149 | + if (!requestRes.ok) { |
| 150 | + return [requestRes, { status: "invalid" }]; |
| 151 | + } |
| 152 | + const req = requestRes.value; |
| 153 | + |
| 154 | + const doResult = await client._do(req, { |
| 155 | + context, |
| 156 | + isErrorStatusCode: (statusCode: number) => |
| 157 | + matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]), |
| 158 | + retryConfig: context.retry_config, |
| 159 | + retryCodes: context.retry_codes, |
| 160 | + }); |
| 161 | + if (!doResult.ok) { |
| 162 | + return [doResult, { status: "request-error", request: req }]; |
| 163 | + } |
| 164 | + const response = doResult.value; |
| 165 | + |
| 166 | + const [result] = await M.match< |
| 167 | + operations.ListInteractionsResponse, |
| 168 | + | GoogleGenAiError |
| 169 | + | ConnectionError |
| 170 | + | RequestAbortedError |
| 171 | + | RequestTimeoutError |
| 172 | + | InvalidRequestError |
| 173 | + | UnexpectedClientError |
| 174 | + >( |
| 175 | + M.json<operations.ListInteractionsResponse>(200), |
| 176 | + M.fail("4XX"), |
| 177 | + M.fail("5XX"), |
| 178 | + M.json<operations.ListInteractionsResponse>("default"), |
| 179 | + )(response, req); |
| 180 | + if (!result.ok) { |
| 181 | + return [result, { status: "complete", request: req, response }]; |
| 182 | + } |
| 183 | + |
| 184 | + return [result, { status: "complete", request: req, response }]; |
| 185 | +} |
0 commit comments