|
| 1 | +/* |
| 2 | + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. |
| 3 | + */ |
| 4 | + |
| 5 | +import { AgentControlSDKCore } from "../core.js"; |
| 6 | +import * as M from "../lib/matchers.js"; |
| 7 | +import { compactMap } from "../lib/primitives.js"; |
| 8 | +import { RequestOptions } from "../lib/sdks.js"; |
| 9 | +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; |
| 10 | +import { pathToFunc } from "../lib/url.js"; |
| 11 | +import { AgentControlSDKError } from "../models/errors/agent-control-sdk-error.js"; |
| 12 | +import { |
| 13 | + ConnectionError, |
| 14 | + InvalidRequestError, |
| 15 | + RequestAbortedError, |
| 16 | + RequestTimeoutError, |
| 17 | + UnexpectedClientError, |
| 18 | +} from "../models/errors/http-client-errors.js"; |
| 19 | +import { ResponseValidationError } from "../models/errors/response-validation-error.js"; |
| 20 | +import { SDKValidationError } from "../models/errors/sdk-validation-error.js"; |
| 21 | +import * as models from "../models/index.js"; |
| 22 | +import { APICall, APIPromise } from "../types/async.js"; |
| 23 | +import { Result } from "../types/fp.js"; |
| 24 | + |
| 25 | +/** |
| 26 | + * Get control definition JSON schema |
| 27 | + * |
| 28 | + * @remarks |
| 29 | + * Return the canonical JSON schema for ControlDefinition. |
| 30 | + */ |
| 31 | +export function controlsGetSchema( |
| 32 | + client: AgentControlSDKCore, |
| 33 | + options?: RequestOptions, |
| 34 | +): APIPromise< |
| 35 | + Result< |
| 36 | + models.GetControlSchemaResponse, |
| 37 | + | AgentControlSDKError |
| 38 | + | ResponseValidationError |
| 39 | + | ConnectionError |
| 40 | + | RequestAbortedError |
| 41 | + | RequestTimeoutError |
| 42 | + | InvalidRequestError |
| 43 | + | UnexpectedClientError |
| 44 | + | SDKValidationError |
| 45 | + > |
| 46 | +> { |
| 47 | + return new APIPromise($do( |
| 48 | + client, |
| 49 | + options, |
| 50 | + )); |
| 51 | +} |
| 52 | + |
| 53 | +async function $do( |
| 54 | + client: AgentControlSDKCore, |
| 55 | + options?: RequestOptions, |
| 56 | +): Promise< |
| 57 | + [ |
| 58 | + Result< |
| 59 | + models.GetControlSchemaResponse, |
| 60 | + | AgentControlSDKError |
| 61 | + | ResponseValidationError |
| 62 | + | ConnectionError |
| 63 | + | RequestAbortedError |
| 64 | + | RequestTimeoutError |
| 65 | + | InvalidRequestError |
| 66 | + | UnexpectedClientError |
| 67 | + | SDKValidationError |
| 68 | + >, |
| 69 | + APICall, |
| 70 | + ] |
| 71 | +> { |
| 72 | + const path = pathToFunc("/api/v1/controls/schema")(); |
| 73 | + |
| 74 | + const headers = new Headers(compactMap({ |
| 75 | + Accept: "application/json", |
| 76 | + })); |
| 77 | + |
| 78 | + const secConfig = await extractSecurity(client._options.apiKeyHeader); |
| 79 | + const securityInput = secConfig == null ? {} : { apiKeyHeader: secConfig }; |
| 80 | + const requestSecurity = resolveGlobalSecurity(securityInput); |
| 81 | + |
| 82 | + const context = { |
| 83 | + options: client._options, |
| 84 | + baseURL: options?.serverURL ?? client._baseURL ?? "", |
| 85 | + operationID: "get_control_schema_api_v1_controls_schema_get", |
| 86 | + oAuth2Scopes: null, |
| 87 | + |
| 88 | + resolvedSecurity: requestSecurity, |
| 89 | + |
| 90 | + securitySource: client._options.apiKeyHeader, |
| 91 | + retryConfig: options?.retries |
| 92 | + || client._options.retryConfig |
| 93 | + || { strategy: "none" }, |
| 94 | + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], |
| 95 | + }; |
| 96 | + |
| 97 | + const requestRes = client._createRequest(context, { |
| 98 | + security: requestSecurity, |
| 99 | + method: "GET", |
| 100 | + baseURL: options?.serverURL, |
| 101 | + path: path, |
| 102 | + headers: headers, |
| 103 | + userAgent: client._options.userAgent, |
| 104 | + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, |
| 105 | + }, options); |
| 106 | + if (!requestRes.ok) { |
| 107 | + return [requestRes, { status: "invalid" }]; |
| 108 | + } |
| 109 | + const req = requestRes.value; |
| 110 | + |
| 111 | + const doResult = await client._do(req, { |
| 112 | + context, |
| 113 | + errorCodes: ["4XX", "5XX"], |
| 114 | + retryConfig: context.retryConfig, |
| 115 | + retryCodes: context.retryCodes, |
| 116 | + }); |
| 117 | + if (!doResult.ok) { |
| 118 | + return [doResult, { status: "request-error", request: req }]; |
| 119 | + } |
| 120 | + const response = doResult.value; |
| 121 | + |
| 122 | + const [result] = await M.match< |
| 123 | + models.GetControlSchemaResponse, |
| 124 | + | AgentControlSDKError |
| 125 | + | ResponseValidationError |
| 126 | + | ConnectionError |
| 127 | + | RequestAbortedError |
| 128 | + | RequestTimeoutError |
| 129 | + | InvalidRequestError |
| 130 | + | UnexpectedClientError |
| 131 | + | SDKValidationError |
| 132 | + >( |
| 133 | + M.json(200, models.GetControlSchemaResponse$inboundSchema), |
| 134 | + M.fail("4XX"), |
| 135 | + M.fail("5XX"), |
| 136 | + )(response, req); |
| 137 | + if (!result.ok) { |
| 138 | + return [result, { status: "complete", request: req, response }]; |
| 139 | + } |
| 140 | + |
| 141 | + return [result, { status: "complete", request: req, response }]; |
| 142 | +} |
0 commit comments