/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: e248dfd3c2d1 */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GleanCore } from "../core.js"; import { clientAgentsRunStream } from "../funcs/clientAgentsRunStream.js"; import { combineSignals } from "../lib/primitives.js"; import { RequestOptions } from "../lib/sdks.js"; import * as components from "../models/components/index.js"; import { GleanBaseError } from "../models/errors/gleanbaseerror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { unwrapAsync } from "../types/fp.js"; import { useGleanContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type ClientAgentsRunStreamMutationVariables = { request: components.AgentRunCreate; options?: RequestOptions; }; export type ClientAgentsRunStreamMutationData = string; export type ClientAgentsRunStreamMutationError = | errors.ErrorResponse | GleanBaseError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create an agent run and stream the response * * @remarks * Executes an [agent](https://developers.glean.com/agents/agents-api) run and returns the result as a stream of server-sent events (SSE). **Note**: If the agent uses an input form trigger, all form fields (including optional fields) must be included in the `input` object. */ export function useClientAgentsRunStreamMutation( options?: MutationHookOptions< ClientAgentsRunStreamMutationData, ClientAgentsRunStreamMutationError, ClientAgentsRunStreamMutationVariables >, ): UseMutationResult< ClientAgentsRunStreamMutationData, ClientAgentsRunStreamMutationError, ClientAgentsRunStreamMutationVariables > { const client = useGleanContext(); return useMutation({ ...buildClientAgentsRunStreamMutation(client, options), ...options, }); } export function mutationKeyClientAgentsRunStream(): MutationKey { return ["@gleanwork/api-client", "agents", "runStream"]; } export function buildClientAgentsRunStreamMutation( client$: GleanCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: ClientAgentsRunStreamMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyClientAgentsRunStream(), mutationFn: function clientAgentsRunStreamMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(clientAgentsRunStream( client$, request, mergedOptions, )); }, }; }