@azure/openai-assistants
Version:
An isomorphic client library for Azure OpenAI Assistants.
1 lines • 144 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/logger.ts","../src/rest/assistantsClient.ts","../src/api/AssistantsContext.ts","../src/api/util.ts","../src/models/helpers.ts","../src/api/operations.ts","../src/api/policies/nonAzure.ts","../src/assistantsClient.ts","../src/OpenAIKeyCredential.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"openai-assistants\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\n\nimport { ClientOptions, getClient } from \"@azure-rest/core-client\";\nimport { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { logger } from \"../logger.js\";\nimport { AssistantsContext } from \"./clientDefinitions.js\";\n\n/**\n * Initialize a new instance of `AssistantsContext`\n * @param endpoint - An OpenAI endpoint supporting assistants functionality.\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credentials: TokenCredential | KeyCredential,\n options: ClientOptions = {}\n): AssistantsContext {\n const baseUrl = options.baseUrl ?? `${endpoint}/openai`;\n options.apiVersion = options.apiVersion ?? \"2024-02-15-preview\";\n const userAgentInfo = `azsdk-js-openai-assistants-rest/1.0.0-beta.6`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://cognitiveservices.azure.com/.default\"],\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"api-key\",\n },\n };\n return getClient(baseUrl, credentials, options) as AssistantsContext;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\n\nimport { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport { ClientOptions } from \"@azure-rest/core-client\";\nimport { AssistantsContext } from \"../rest/index.js\";\nimport getClient from \"../rest/index.js\";\n\n/** The details used to create a assistant client **/\nexport interface AssistantsClientOptions extends ClientOptions {}\n\nexport { AssistantsContext } from \"../rest/index.js\";\n\n/** Azure OpenAI APIs for Assistants. */\nexport function createAssistants(\n endpoint: string,\n credential: KeyCredential | TokenCredential,\n options: AssistantsClientOptions = {}\n): AssistantsContext {\n const clientContext = getClient(endpoint, credential, options);\n return clientContext;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\nexport type SnakeCaseKeys<T> = {\n [K in keyof T as SnakeCase<K & string>]: MapSnakeCaseKeysOverCollections<T[K]>;\n};\ntype CamelCase<S extends string> = S extends `${infer P1}_${infer P2}`\n ? `${Lowercase<P1>}${Capitalize<CamelCase<P2>>}`\n : Lowercase<S>;\ntype SnakeCase<S extends string> = S extends `${infer T}${infer U}`\n ? `${T extends Capitalize<T> ? \"_\" : \"\"}${Lowercase<T>}${SnakeCase<U>}`\n : S;\ntype MapCamelCaseKeysOverCollections<T> = T extends Array<infer X>\n ? Array<MapCamelCaseKeysOverCollections<X>>\n : CamelCaseKeys<T>;\ntype MapSnakeCaseKeysOverCollections<T> = T extends Array<infer X>\n ? Array<MapSnakeCaseKeysOverCollections<X>>\n : // : T extends (infer X | infer Y)\n // ? MapSnakeCaseKeysOverCollections<X> | MapSnakeCaseKeysOverCollections<Y>\n SnakeCaseKeys<T>;\ntype CamelCaseKeys<T> = {\n [K in keyof T as CamelCase<K & string>]: MapCamelCaseKeysOverCollections<T[K]>;\n};\n\nexport function wrapError<T>(f: () => T, message: string): T {\n try {\n const result = f();\n return result;\n } catch (cause) {\n throw new Error(`${message}: ${cause}`);\n }\n}\n\n/**\n * Rename keys to camel case.\n * @param obj - The object to rename keys to camel case\n * @returns The object with keys renamed to camel case\n */\nexport function renameKeysToCamelCase(obj: Record<string, any>): Record<string, any> {\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n const newKey = tocamelCase(key);\n if (newKey !== key) {\n delete obj[key];\n }\n obj[newKey] =\n typeof value === \"object\"\n ? Array.isArray(value)\n ? value.map((v) => renameKeysToCamelCase(v))\n : renameKeysToCamelCase(value)\n : value;\n }\n\n return obj;\n}\n\nexport function camelCaseKeys<O extends Record<string, any>>(obj: O): CamelCaseKeys<O> {\n if (typeof obj !== \"object\" || !obj) return obj;\n if (Array.isArray(obj)) {\n return obj.map((v) =>\n camelCaseKeys<O extends Array<infer X> ? (X extends Record<string, any> ? X : never) : never>(\n v\n )\n ) as CamelCaseKeys<O>;\n } else {\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n const newKey = tocamelCase(key);\n if (newKey !== key) {\n delete obj[key];\n }\n (obj[newKey] as Record<string, any>) =\n typeof obj[newKey] === \"object\" ? camelCaseKeys(value) : value;\n }\n return obj;\n }\n}\n\nexport function snakeCaseKeys<O extends Record<string, any>>(obj: O): SnakeCaseKeys<O> {\n if (typeof obj !== \"object\" || !obj) return obj;\n if (Array.isArray(obj)) {\n return obj.map((v) =>\n snakeCaseKeys<O extends Array<infer X> ? (X extends Record<string, any> ? X : never) : never>(\n v\n )\n ) as SnakeCaseKeys<O>;\n } else {\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n const newKey = toSnakeCase(key);\n if (newKey !== key) {\n delete obj[key];\n }\n (obj[newKey] as Record<string, any>) =\n typeof obj[newKey] === \"object\" ? snakeCaseKeys(value) : value;\n }\n return obj;\n }\n}\n\nfunction tocamelCase<P extends string>(str: P): CamelCase<P> {\n return str\n .toLowerCase()\n .replace(/([_][a-z])/g, (group) => group.toUpperCase().replace(\"_\", \"\")) as CamelCase<P>;\n}\n\nfunction toSnakeCase<P extends string>(str: P): SnakeCase<P> {\n return str\n .replace(/([A-Z])/g, (group) => `_${group.toLowerCase()}`)\n .replace(/^_/, \"\") as SnakeCase<P>;\n}\n\nexport function unixToDate(unix: number): Date {\n return new Date(unix * 1000);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\nimport {\n CodeInterpreterToolCallDetailsOutput,\n RequiredToolCallOutput,\n ToolCallOutput,\n} from \"../rest/outputModels.js\";\nimport { CodeInterpreterToolCallDetails, RequiredToolCall, ToolCall } from \"./models.js\";\nimport { camelCaseKeys } from \"../api/util.js\";\n\nexport function parseRequiredToolCallOutput(\n requiredToolCallOutput: RequiredToolCallOutput\n): RequiredToolCall {\n return {\n type: \"function\",\n id: requiredToolCallOutput.id,\n function: requiredToolCallOutput.function,\n } as RequiredToolCall;\n}\n\nexport function parseToolCallOutput(toolCallOutput: ToolCallOutput): ToolCall {\n const { id, type } = toolCallOutput;\n switch (type) {\n case \"function\":\n return { type, id, function: toolCallOutput.function };\n case \"retrieval\":\n return { type, id, retrieval: toolCallOutput.retrieval };\n case \"code_interpreter\":\n return {\n type,\n id,\n codeInterpreter: parseCodeInterpreterToolCallDetailsOutput(toolCallOutput.code_interpreter),\n };\n default:\n throw new Error(`Unknown tool call type: ${type}`);\n }\n}\n\nfunction parseCodeInterpreterToolCallDetailsOutput(\n codeInterpreterToolCallDetailsOutput: CodeInterpreterToolCallDetailsOutput\n): CodeInterpreterToolCallDetails {\n const { ...rest } = codeInterpreterToolCallDetailsOutput;\n return { ...camelCaseKeys(rest) };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * THIS IS AN AUTO-GENERATED FILE - DO NOT EDIT!\n *\n * Any changes you make here may be lost.\n *\n * If you need to make changes, please do so in the original source file, \\{project-root\\}/sources/custom\n */\n\nimport {\n StreamableMethod,\n createRestError,\n operationOptionsToRequestParameters,\n} from \"@azure-rest/core-client\";\nimport { createFile } from \"@azure/core-rest-pipeline\";\nimport { parseToolCallOutput, parseRequiredToolCallOutput } from \"../models/helpers.js\";\nimport {\n Assistant,\n AssistantFile,\n CreateThreadOptions,\n FilePurpose,\n GetMessageOptions,\n InputFile,\n ListAssistantFilesOptions,\n ListAssistantsOptions,\n ListMessageFilesOptions,\n ListMessagesOptions,\n ListRunStepsOptions,\n ListRunsOptions,\n MessageFile,\n RunStep,\n RunStepDetails,\n ToolCall,\n UploadFileOptions,\n} from \"../models/index.js\";\nimport {\n AssistantCreationOptions,\n AssistantDeletionStatus,\n AssistantFileDeletionStatus,\n AssistantThread,\n CreateAndRunThreadOptions,\n CreateRunOptions,\n FileDeletionStatus,\n FileListResponse,\n ListResponseOf,\n MessageContent,\n MessageRole,\n ThreadDeletionStatus,\n ThreadMessage,\n ThreadRun,\n ToolOutput,\n UpdateAssistantOptions,\n} from \"../models/models.js\";\nimport {\n CancelRunOptions,\n CreateAssistantFileOptions,\n CreateAssistantOptions,\n CreateMessageOptions,\n CreateRunRequestOptions,\n CreateThreadAndRunOptions,\n DeleteAssistantFileOptions,\n DeleteAssistantOptions,\n DeleteFileOptions,\n DeleteThreadOptions,\n GetAssistantFileOptions,\n GetAssistantOptions,\n GetFileOptions,\n GetMessageFileOptions,\n GetRunOptions,\n GetRunStepOptions,\n GetThreadOptions,\n ListFilesOptions,\n SubmitToolOutputsToRunOptions,\n UpdateAssistantRequestOptions,\n UpdateMessageOptions,\n UpdateRunOptions,\n UpdateThreadOptions,\n} from \"../models/options.js\";\nimport {\n AssistantThreadCreationOptions,\n CancelRun200Response,\n AssistantsContext as Client,\n CreateAssistant200Response,\n CreateAssistantFile200Response,\n CreateMessage200Response,\n CreateRun200Response,\n CreateThread200Response,\n CreateThreadAndRun200Response,\n DeleteAssistant200Response,\n DeleteAssistantFile200Response,\n DeleteFile200Response,\n DeleteThread200Response,\n GetAssistant200Response,\n GetAssistantFile200Response,\n GetFile200Response,\n GetMessage200Response,\n GetMessageFile200Response,\n GetRun200Response,\n GetRunStep200Response,\n GetThread200Response,\n ListAssistantFiles200Response,\n ListAssistants200Response,\n ListFiles200Response,\n ListMessageFiles200Response,\n ListMessages200Response,\n ListRuns200Response,\n RunStepDetailsOutput,\n RunStepOutput,\n SubmitToolOutputsToRun200Response,\n UpdateAssistant200Response,\n UpdateMessage200Response,\n UpdateRun200Response,\n UpdateThread200Response,\n UploadFile200Response,\n} from \"../rest/index.js\";\nimport { MessageContentOutput } from \"../rest/outputModels.js\";\nimport { ListRunSteps200Response } from \"../rest/responses.js\";\nimport { camelCaseKeys, unixToDate } from \"./util.js\";\n\nexport function _createAssistantSend(\n context: Client,\n body: AssistantCreationOptions,\n options: CreateAssistantOptions = { requestOptions: {} }\n): StreamableMethod<CreateAssistant200Response> {\n return context.path(\"/assistants\").post({\n ...operationOptionsToRequestParameters(options),\n body: {\n model: body[\"model\"],\n name: body[\"name\"],\n description: body[\"description\"],\n instructions: body[\"instructions\"],\n tools: body[\"tools\"],\n file_ids: body[\"fileIds\"],\n metadata: body[\"metadata\"],\n },\n });\n}\n\nexport async function _createAssistantDeserialize(\n result: CreateAssistant200Response\n): Promise<Assistant> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n name: result.body[\"name\"],\n description: result.body[\"description\"],\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Creates a new assistant. */\nexport async function createAssistant(\n context: Client,\n body: AssistantCreationOptions,\n options: CreateAssistantOptions = { requestOptions: {} }\n): Promise<Assistant> {\n const result = await _createAssistantSend(context, body, options);\n return _createAssistantDeserialize(result);\n}\n\nexport function _listAssistantsSend(\n context: Client,\n options: ListAssistantsOptions = { requestOptions: {} }\n): StreamableMethod<ListAssistants200Response> {\n return context.path(\"/assistants\").get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _getAssistantSend(\n context: Client,\n assistantId: string,\n options: GetAssistantOptions = { requestOptions: {} }\n): StreamableMethod<GetAssistant200Response> {\n return context\n .path(\"/assistants/{assistantId}\", assistantId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _getAssistantDeserialize(\n result: GetAssistant200Response\n): Promise<Assistant> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n name: result.body[\"name\"],\n description: result.body[\"description\"],\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Retrieves an existing assistant. */\nexport async function getAssistant(\n context: Client,\n assistantId: string,\n options: GetAssistantOptions = { requestOptions: {} }\n): Promise<Assistant> {\n const result = await _getAssistantSend(context, assistantId, options);\n return _getAssistantDeserialize(result);\n}\n\nexport function _updateAssistantSend(\n context: Client,\n assistantId: string,\n body: UpdateAssistantOptions,\n options: UpdateAssistantRequestOptions = { requestOptions: {} }\n): StreamableMethod<UpdateAssistant200Response> {\n return context.path(\"/assistants/{assistantId}\", assistantId).post({\n ...operationOptionsToRequestParameters(options),\n body: {\n model: body[\"model\"],\n name: body[\"name\"],\n description: body[\"description\"],\n instructions: body[\"instructions\"],\n tools: body[\"tools\"],\n file_ids: body[\"fileIds\"],\n metadata: body[\"metadata\"],\n },\n });\n}\n\nexport async function _updateAssistantDeserialize(\n result: UpdateAssistant200Response\n): Promise<Assistant> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n name: result.body[\"name\"],\n description: result.body[\"description\"],\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Modifies an existing assistant. */\nexport async function updateAssistant(\n context: Client,\n assistantId: string,\n body: UpdateAssistantOptions,\n options: UpdateAssistantRequestOptions = { requestOptions: {} }\n): Promise<Assistant> {\n const result = await _updateAssistantSend(context, assistantId, body, options);\n return _updateAssistantDeserialize(result);\n}\n\nexport function _deleteAssistantSend(\n context: Client,\n assistantId: string,\n options: DeleteAssistantOptions = { requestOptions: {} }\n): StreamableMethod<DeleteAssistant200Response> {\n return context\n .path(\"/assistants/{assistantId}\", assistantId)\n .delete({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _deleteAssistantDeserialize(\n result: DeleteAssistant200Response\n): Promise<AssistantDeletionStatus> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n deleted: result.body[\"deleted\"],\n };\n}\n\n/** Deletes an assistant. */\nexport async function deleteAssistant(\n context: Client,\n assistantId: string,\n options: DeleteAssistantOptions = { requestOptions: {} }\n): Promise<AssistantDeletionStatus> {\n const result = await _deleteAssistantSend(context, assistantId, options);\n return _deleteAssistantDeserialize(result);\n}\n\nexport function _createAssistantFileSend(\n context: Client,\n assistantId: string,\n fileId: string,\n options: CreateAssistantFileOptions = { requestOptions: {} }\n): StreamableMethod<CreateAssistantFile200Response> {\n return context.path(\"/assistants/{assistantId}/files\", assistantId).post({\n ...operationOptionsToRequestParameters(options),\n body: { file_id: fileId },\n });\n}\n\nexport async function _createAssistantFileDeserialize(\n result: CreateAssistantFile200Response\n): Promise<AssistantFile> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n assistantId: result.body[\"assistant_id\"],\n };\n}\n\n/** Attaches a previously uploaded file to an assistant for use by tools that can read files. */\nexport async function createAssistantFile(\n context: Client,\n assistantId: string,\n fileId: string,\n options: CreateAssistantFileOptions = { requestOptions: {} }\n): Promise<AssistantFile> {\n const result = await _createAssistantFileSend(context, assistantId, fileId, options);\n return _createAssistantFileDeserialize(result);\n}\n\nexport function _listAssistantFilesSend(\n context: Client,\n assistantId: string,\n options: ListAssistantFilesOptions = { requestOptions: {} }\n): StreamableMethod<ListAssistantFiles200Response> {\n return context.path(\"/assistants/{assistantId}/files\", assistantId).get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _getAssistantFileSend(\n context: Client,\n assistantId: string,\n fileId: string,\n options: GetAssistantFileOptions = { requestOptions: {} }\n): StreamableMethod<GetAssistantFile200Response> {\n return context\n .path(\"/assistants/{assistantId}/files/{fileId}\", assistantId, fileId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _getAssistantFileDeserialize(\n result: GetAssistantFile200Response\n): Promise<AssistantFile> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n assistantId: result.body[\"assistant_id\"],\n };\n}\n\n/** Retrieves a file attached to an assistant. */\nexport async function getAssistantFile(\n context: Client,\n assistantId: string,\n fileId: string,\n options: GetAssistantFileOptions = { requestOptions: {} }\n): Promise<AssistantFile> {\n const result = await _getAssistantFileSend(context, assistantId, fileId, options);\n return _getAssistantFileDeserialize(result);\n}\n\nexport function _deleteAssistantFileSend(\n context: Client,\n assistantId: string,\n fileId: string,\n options: DeleteAssistantFileOptions = { requestOptions: {} }\n): StreamableMethod<DeleteAssistantFile200Response> {\n return context\n .path(\"/assistants/{assistantId}/files/{fileId}\", assistantId, fileId)\n .delete({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _deleteAssistantFileDeserialize(\n result: DeleteAssistantFile200Response\n): Promise<AssistantFileDeletionStatus> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n deleted: result.body[\"deleted\"],\n };\n}\n\n/**\n * Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read\n * files.\n */\nexport async function deleteAssistantFile(\n context: Client,\n assistantId: string,\n fileId: string,\n options: DeleteAssistantFileOptions = { requestOptions: {} }\n): Promise<AssistantFileDeletionStatus> {\n const result = await _deleteAssistantFileSend(context, assistantId, fileId, options);\n return _deleteAssistantFileDeserialize(result);\n}\n\nexport async function _createThreadDeserialize(\n result: CreateThread200Response\n): Promise<AssistantThread> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Creates a new thread. Threads contain messages and can be run by assistants. */\nexport async function createThread(\n context: Client,\n body: AssistantThreadCreationOptions,\n options: CreateThreadOptions = { requestOptions: {} }\n): Promise<AssistantThread> {\n const result = await _createThreadSend(context, body, options);\n return _createThreadDeserialize(result);\n}\n\nexport function _getThreadSend(\n context: Client,\n threadId: string,\n options: GetThreadOptions = { requestOptions: {} }\n): StreamableMethod<GetThread200Response> {\n return context\n .path(\"/threads/{threadId}\", threadId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _getThreadDeserialize(\n result: GetThread200Response\n): Promise<AssistantThread> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Gets information about an existing thread. */\nexport async function getThread(\n context: Client,\n threadId: string,\n options: GetThreadOptions = { requestOptions: {} }\n): Promise<AssistantThread> {\n const result = await _getThreadSend(context, threadId, options);\n return _getThreadDeserialize(result);\n}\n\nexport function _updateThreadSend(\n context: Client,\n threadId: string,\n options: UpdateThreadOptions = { requestOptions: {} }\n): StreamableMethod<UpdateThread200Response> {\n return context.path(\"/threads/{threadId}\", threadId).post({\n ...operationOptionsToRequestParameters(options),\n body: { metadata: options?.metadata },\n });\n}\n\nexport async function _updateThreadDeserialize(\n result: UpdateThread200Response\n): Promise<AssistantThread> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Modifies an existing thread. */\nexport async function updateThread(\n context: Client,\n threadId: string,\n options: UpdateThreadOptions = { requestOptions: {} }\n): Promise<AssistantThread> {\n const result = await _updateThreadSend(context, threadId, options);\n return _updateThreadDeserialize(result);\n}\n\nexport function _deleteThreadSend(\n context: Client,\n threadId: string,\n options: DeleteThreadOptions = { requestOptions: {} }\n): StreamableMethod<DeleteThread200Response> {\n return context\n .path(\"/threads/{threadId}\", threadId)\n .delete({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _deleteThreadDeserialize(\n result: DeleteThread200Response\n): Promise<ThreadDeletionStatus> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n deleted: result.body[\"deleted\"],\n };\n}\n\n/** Deletes an existing thread. */\nexport async function deleteThread(\n context: Client,\n threadId: string,\n options: DeleteThreadOptions = { requestOptions: {} }\n): Promise<ThreadDeletionStatus> {\n const result = await _deleteThreadSend(context, threadId, options);\n return _deleteThreadDeserialize(result);\n}\n\nexport function _createMessageSend(\n context: Client,\n threadId: string,\n role: MessageRole,\n content: string,\n options: CreateMessageOptions = { requestOptions: {} }\n): StreamableMethod<CreateMessage200Response> {\n return context.path(\"/threads/{threadId}/messages\", threadId).post({\n ...operationOptionsToRequestParameters(options),\n body: {\n role: role,\n content: content,\n file_ids: options?.fileIds,\n metadata: options?.metadata,\n },\n });\n}\n\n/** Creates a new message on a specified thread. */\nexport async function createMessage(\n context: Client,\n threadId: string,\n role: MessageRole,\n content: string,\n options: CreateMessageOptions = { requestOptions: {} }\n): Promise<ThreadMessage> {\n const result = await _createMessageSend(context, threadId, role, content, options);\n return _createMessageDeserialize(result);\n}\n\nexport function _listMessagesSend(\n context: Client,\n threadId: string,\n options: ListMessagesOptions = { requestOptions: {} }\n): StreamableMethod<ListMessages200Response> {\n return context.path(\"/threads/{threadId}/messages\", threadId).get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _updateMessageSend(\n context: Client,\n threadId: string,\n messageId: string,\n options: UpdateMessageOptions = { requestOptions: {} }\n): StreamableMethod<UpdateMessage200Response> {\n return context.path(\"/threads/{threadId}/messages/{messageId}\", threadId, messageId).post({\n ...operationOptionsToRequestParameters(options),\n body: { metadata: options?.metadata },\n });\n}\n\n/** Modifies an existing message on an existing thread. */\nexport async function updateMessage(\n context: Client,\n threadId: string,\n messageId: string,\n options: UpdateMessageOptions = { requestOptions: {} }\n): Promise<ThreadMessage> {\n const result = await _updateMessageSend(context, threadId, messageId, options);\n return _updateMessageDeserialize(result);\n}\n\nexport function _listMessageFilesSend(\n context: Client,\n threadId: string,\n messageId: string,\n options: ListMessageFilesOptions = { requestOptions: {} }\n): StreamableMethod<ListMessageFiles200Response> {\n return context.path(\"/threads/{threadId}/messages/{messageId}/files\", threadId, messageId).get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _getMessageFileSend(\n context: Client,\n threadId: string,\n messageId: string,\n fileId: string,\n options: GetMessageFileOptions = { requestOptions: {} }\n): StreamableMethod<GetMessageFile200Response> {\n return context\n .path(\"/threads/{threadId}/messages/{messageId}/files/{fileId}\", threadId, messageId, fileId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _getMessageFileDeserialize(\n result: GetMessageFile200Response\n): Promise<MessageFile> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n messageId: result.body[\"message_id\"],\n };\n}\n\n/** Gets information about a file attachment to a message within a thread. */\nexport async function getMessageFile(\n context: Client,\n threadId: string,\n messageId: string,\n fileId: string,\n options: GetMessageFileOptions = { requestOptions: {} }\n): Promise<MessageFile> {\n const result = await _getMessageFileSend(context, threadId, messageId, fileId, options);\n return _getMessageFileDeserialize(result);\n}\n\nexport function _createRunSend(\n context: Client,\n threadId: string,\n createRunOptions: CreateRunOptions,\n options: CreateRunRequestOptions = { requestOptions: {} }\n): StreamableMethod<CreateRun200Response> {\n return context.path(\"/threads/{threadId}/runs\", threadId).post({\n ...operationOptionsToRequestParameters(options),\n body: {\n assistant_id: createRunOptions[\"assistantId\"],\n model: createRunOptions[\"model\"],\n instructions: createRunOptions[\"instructions\"],\n additional_instructions: createRunOptions[\"additionalInstructions\"],\n tools: createRunOptions[\"tools\"],\n metadata: createRunOptions[\"metadata\"],\n },\n });\n}\n\n/** Creates a new run for an assistant thread. */\nexport async function createRun(\n context: Client,\n threadId: string,\n createRunOptions: CreateRunOptions,\n options: CreateRunRequestOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _createRunSend(context, threadId, createRunOptions, options);\n return _createRunDeserialize(result);\n}\n\nexport function _listRunsSend(\n context: Client,\n threadId: string,\n options: ListRunsOptions = { requestOptions: {} }\n): StreamableMethod<ListRuns200Response> {\n return context.path(\"/threads/{threadId}/runs\", threadId).get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _getRunSend(\n context: Client,\n threadId: string,\n runId: string,\n options: GetRunOptions = { requestOptions: {} }\n): StreamableMethod<GetRun200Response> {\n return context\n .path(\"/threads/{threadId}/runs/{runId}\", threadId, runId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\n/** Gets an existing run from an existing thread. */\nexport async function getRun(\n context: Client,\n threadId: string,\n runId: string,\n options: GetRunOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _getRunSend(context, threadId, runId, options);\n return _getRunDeserialize(result);\n}\n\nexport function _updateRunSend(\n context: Client,\n threadId: string,\n runId: string,\n options: UpdateRunOptions = { requestOptions: {} }\n): StreamableMethod<UpdateRun200Response> {\n return context.path(\"/threads/{threadId}/runs/{runId}\", threadId, runId).post({\n ...operationOptionsToRequestParameters(options),\n body: { metadata: options?.metadata },\n });\n}\n\nexport async function _updateRunDeserialize(result: UpdateRun200Response): Promise<ThreadRun> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n threadId: result.body[\"thread_id\"],\n assistantId: result.body[\"assistant_id\"],\n status: result.body[\"status\"],\n requiredAction: result.body.required_action,\n lastError: result.body.last_error,\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n expiresAt:\n result.body[\"expires_at\"] === null ? null : unixToDate(Number(result.body[\"expires_at\"])),\n startedAt:\n result.body[\"started_at\"] === null ? null : unixToDate(Number(result.body[\"started_at\"])),\n completedAt:\n result.body[\"completed_at\"] === null ? null : unixToDate(Number(result.body[\"completed_at\"])),\n cancelledAt:\n result.body[\"cancelled_at\"] === null ? null : unixToDate(Number(result.body[\"cancelled_at\"])),\n failedAt:\n result.body[\"failed_at\"] === null ? null : unixToDate(Number(result.body[\"failed_at\"])),\n metadata: result.body[\"metadata\"],\n };\n}\n\n/** Modifies an existing thread run. */\nexport async function updateRun(\n context: Client,\n threadId: string,\n runId: string,\n options: UpdateRunOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _updateRunSend(context, threadId, runId, options);\n return _updateRunDeserialize(result);\n}\n\nexport function _submitToolOutputsToRunSend(\n context: Client,\n threadId: string,\n runId: string,\n toolOutputs: ToolOutput[],\n options: SubmitToolOutputsToRunOptions = { requestOptions: {} }\n): StreamableMethod<SubmitToolOutputsToRun200Response> {\n return context\n .path(\"/threads/{threadId}/runs/{runId}/submit_tool_outputs\", threadId, runId)\n .post({\n ...operationOptionsToRequestParameters(options),\n body: {\n tool_outputs: toolOutputs.map((p) => ({\n tool_call_id: p[\"toolCallId\"],\n output: p[\"output\"],\n })),\n },\n });\n}\n\n/** Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. */\nexport async function submitToolOutputsToRun(\n context: Client,\n threadId: string,\n runId: string,\n toolOutputs: ToolOutput[],\n options: SubmitToolOutputsToRunOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _submitToolOutputsToRunSend(context, threadId, runId, toolOutputs, options);\n return _submitToolOutputsToRunDeserialize(result);\n}\n\nexport function _cancelRunSend(\n context: Client,\n threadId: string,\n runId: string,\n options: CancelRunOptions = { requestOptions: {} }\n): StreamableMethod<CancelRun200Response> {\n return context\n .path(\"/threads/{threadId}/runs/{runId}/cancel\", threadId, runId)\n .post({ ...operationOptionsToRequestParameters(options) });\n}\n\n/** Cancels a run of an in progress thread. */\nexport async function cancelRun(\n context: Client,\n threadId: string,\n runId: string,\n options: CancelRunOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _cancelRunSend(context, threadId, runId, options);\n return _cancelRunDeserialize(result);\n}\n\n/** Creates a new assistant thread and immediately starts a run using that new thread. */\nexport async function createThreadAndRun(\n context: Client,\n body: CreateAndRunThreadOptions,\n options: CreateThreadAndRunOptions = { requestOptions: {} }\n): Promise<ThreadRun> {\n const result = await _createThreadAndRunSend(context, body, options);\n return _createThreadAndRunDeserialize(result);\n}\n\nexport function _getRunStepSend(\n context: Client,\n threadId: string,\n runId: string,\n stepId: string,\n options: GetRunStepOptions = { requestOptions: {} }\n): StreamableMethod<GetRunStep200Response> {\n return context\n .path(\"/threads/{threadId}/runs/{runId}/steps/{stepId}\", threadId, runId, stepId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\n/** Gets a single run step from a thread run. */\nexport async function getRunStep(\n context: Client,\n threadId: string,\n runId: string,\n stepId: string,\n options: GetRunStepOptions = { requestOptions: {} }\n): Promise<RunStep> {\n const result = await _getRunStepSend(context, threadId, runId, stepId, options);\n return _getRunStepDeserialize(result);\n}\n\nexport function _listRunStepsSend(\n context: Client,\n threadId: string,\n runId: string,\n options: ListRunStepsOptions = { requestOptions: {} }\n): StreamableMethod<ListRunSteps200Response> {\n return context.path(\"/threads/{threadId}/runs/{runId}/steps\", threadId, runId).get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: {\n limit: options?.limit,\n order: options?.order,\n after: options?.after,\n before: options?.before,\n },\n });\n}\n\nexport function _listFilesSend(\n context: Client,\n options: ListFilesOptions = { requestOptions: {} }\n): StreamableMethod<ListFiles200Response> {\n return context.path(\"/files\").get({\n ...operationOptionsToRequestParameters(options),\n queryParameters: { purpose: options?.purpose },\n });\n}\n\nexport async function _listFilesDeserialize(\n result: ListFiles200Response\n): Promise<FileListResponse> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n data: result.body[\"data\"].map((p) => ({\n id: p[\"id\"],\n bytes: p[\"bytes\"],\n filename: p[\"filename\"],\n createdAt: unixToDate(p[\"created_at\"]),\n purpose: p[\"purpose\"],\n })),\n };\n}\n\n/** Gets a list of previously uploaded files. */\nexport async function listFiles(\n context: Client,\n options: ListFilesOptions = { requestOptions: {} }\n): Promise<FileListResponse> {\n const result = await _listFilesSend(context, options);\n return _listFilesDeserialize(result);\n}\n\n/** Uploads a file for use by other operations. */\nexport async function uploadFile(\n context: Client,\n file: Uint8Array,\n purpose: FilePurpose,\n options: UploadFileOptions = { requestOptions: {} }\n): Promise<InputFile> {\n const result = await _uploadFileSend(context, file, purpose, options);\n return _uploadFileDeserialize(result);\n}\n\nexport function _deleteFileSend(\n context: Client,\n fileId: string,\n options: DeleteFileOptions = { requestOptions: {} }\n): StreamableMethod<DeleteFile200Response> {\n return context\n .path(\"/files/{fileId}\", fileId)\n .delete({ ...operationOptionsToRequestParameters(options) });\n}\n\nexport async function _deleteFileDeserialize(\n result: DeleteFile200Response\n): Promise<FileDeletionStatus> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n deleted: result.body[\"deleted\"],\n };\n}\n\n/** Delete a previously uploaded file. */\nexport async function deleteFile(\n context: Client,\n fileId: string,\n options: DeleteFileOptions = { requestOptions: {} }\n): Promise<FileDeletionStatus> {\n const result = await _deleteFileSend(context, fileId, options);\n return _deleteFileDeserialize(result);\n}\n\nexport function _getFileSend(\n context: Client,\n fileId: string,\n options: GetFileOptions = { requestOptions: {} }\n): StreamableMethod<GetFile200Response> {\n return context\n .path(\"/files/{fileId}\", fileId)\n .get({ ...operationOptionsToRequestParameters(options) });\n}\n\n/** Returns information about a specific file. Does not retrieve file content. */\nexport async function getFile(\n context: Client,\n fileId: string,\n options: GetFileOptions = { requestOptions: {} }\n): Promise<InputFile> {\n const result = await _getFileSend(context, fileId, options);\n return _getFileDeserialize(result);\n}\n\nexport async function _createRunDeserialize(result: CreateRun200Response): Promise<ThreadRun> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n const {\n required_action,\n last_error,\n created_at,\n expires_at,\n started_at,\n completed_at,\n cancelled_at,\n failed_at,\n ...rest\n } = result.body;\n return {\n ...camelCaseKeys(rest),\n requiredAction: !required_action\n ? undefined\n : {\n type: required_action?.[\"type\"],\n submitToolOutputs: !required_action?.submit_tool_outputs?.[\"tool_calls\"]\n ? undefined\n : {\n toolCalls: required_action?.submit_tool_outputs?.tool_calls?.map(\n parseRequiredToolCallOutput\n ),\n },\n },\n lastError: !last_error\n ? undefined\n : {\n code: last_error?.[\"code\"],\n message: last_error?.[\"message\"],\n },\n createdAt: unixToDate(created_at),\n expiresAt: expires_at === null ? null : unixToDate(Number(expires_at)),\n startedAt: started_at === null ? null : unixToDate(Number(started_at)),\n completedAt: completed_at === null ? null : unixToDate(Number(completed_at)),\n cancelledAt: cancelled_at === null ? null : unixToDate(Number(cancelled_at)),\n failedAt: failed_at === null ? null : unixToDate(Number(failed_at)),\n };\n}\n\nexport async function _listRunsDeserialize(\n result: ListRuns200Response\n): Promise<ListResponseOf<ThreadRun>> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n data: result.body[\"data\"].map(\n (p) =>\n ({\n id: p[\"id\"],\n threadId: p[\"thread_id\"],\n assistantId: p[\"assistant_id\"],\n status: p[\"status\"],\n requiredAction: !p.required_action ? undefined : { type: p.required_action?.[\"type\"] },\n lastError: !p.last_error\n ? undefined\n : { code: p.last_error?.[\"code\"], message: p.last_error?.[\"message\"] },\n model: p[\"model\"],\n instructions: p[\"instructions\"],\n tools: p[\"tools\"],\n fileIds: p[\"file_ids\"],\n metadata: p[\"metadata\"],\n createdAt: unixToDate(p[\"created_at\"]),\n expiresAt: p[\"expires_at\"] === null ? null : unixToDate(Number(p[\"expires_at\"])),\n startedAt: p[\"started_at\"] === null ? null : unixToDate(Number(p[\"started_at\"])),\n completedAt: p[\"completed_at\"] === null ? null : unixToDate(Number(p[\"completed_at\"])),\n cancelledAt: p[\"cancelled_at\"] === null ? null : unixToDate(Number(p[\"cancelled_at\"])),\n failedAt: p[\"failed_at\"] === null ? null : unixToDate(Number(p[\"failed_at\"])),\n } as ThreadRun)\n ),\n firstId: result.body[\"first_id\"],\n lastId: result.body[\"last_id\"],\n hasMore: result.body[\"has_more\"],\n };\n}\n\nexport function _createThreadAndRunSend(\n context: Client,\n body: CreateAndRunThreadOptions,\n options: CreateThreadAndRunOptions = { requestOptions: {} }\n): StreamableMethod<CreateThreadAndRun200Response> {\n return context.path(\"/threads/runs\").post({\n ...operationOptionsToRequestParameters(options),\n body: {\n assistant_id: body[\"assistantId\"],\n thread: !body.thread\n ? undefined\n : {\n messages: !body.thread?.[\"messages\"]\n ? body.thread?.[\"messages\"]\n : body.thread?.[\"messages\"].map((p) => ({\n role: p[\"role\"],\n content: p[\"content\"],\n })),\n metadata: body.thread?.[\"metadata\"],\n },\n model: body[\"model\"],\n instructions: body[\"instructions\"],\n tools: body[\"tools\"],\n metadata: body[\"metadata\"],\n },\n });\n}\n\n/** Returns a list of runs associated with an assistant thread. */\nexport async function listRuns(\n context: Client,\n threadId: string,\n options: ListRunsOptions = { requestOptions: {} }\n): Promise<ListResponseOf<ThreadRun>> {\n const result = await _listRunsSend(context, threadId, options);\n return _listRunsDeserialize(result);\n}\n\nexport async function _getRunDeserialize(result: GetRun200Response): Promise<ThreadRun> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n threadId: result.body[\"thread_id\"],\n assistantId: result.body[\"assistant_id\"],\n status: result.body[\"status\"],\n requiredAction: !result.body.required_action\n ? undefined\n : {\n type: result.body.required_action?.[\"type\"],\n submitToolOutputs: !result.body.required_action?.submit_tool_outputs?.[\"tool_calls\"]\n ? undefined\n : {\n toolCalls: result.body.required_action?.submit_tool_outputs?.tool_calls?.map(\n parseRequiredToolCallOutput\n ),\n },\n },\n lastError: !result.body.last_error\n ? undefined\n : {\n code: result.body.last_error?.[\"code\"],\n message: result.body.last_error?.[\"message\"],\n },\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n expiresAt:\n result.body[\"expires_at\"] === null ? null : unixToDate(Number(result.body[\"expires_at\"])),\n startedAt:\n result.body[\"started_at\"] === null ? null : unixToDate(Number(result.body[\"started_at\"])),\n completedAt:\n result.body[\"completed_at\"] === null ? null : unixToDate(Number(result.body[\"completed_at\"])),\n cancelledAt:\n result.body[\"cancelled_at\"] === null ? null : unixToDate(Number(result.body[\"cancelled_at\"])),\n failedAt:\n result.body[\"failed_at\"] === null ? null : unixToDate(Number(result.body[\"failed_at\"])),\n };\n}\n\nexport async function _submitToolOutputsToRunDeserialize(\n result: SubmitToolOutputsToRun200Response\n): Promise<ThreadRun> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n threadId: result.body[\"thread_id\"],\n assistantId: result.body[\"assistant_id\"],\n status: result.body[\"status\"],\n requiredAction: !result.body.required_action\n ? undefined\n : {\n type: result.body.required_action?.[\"type\"],\n submitToolOutputs: !result.body.required_action?.submit_tool_outputs?.[\"tool_calls\"]\n ? undefined\n : {\n toolCalls: result.body.required_action?.submit_tool_outputs?.tool_calls?.map(\n parseRequiredToolCallOutput\n ),\n },\n },\n lastError: !result.body.last_error\n ? undefined\n : {\n code: result.body.last_error?.[\"code\"],\n message: result.body.last_error?.[\"message\"],\n },\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n createdAt: unixToDate(result.body[\"created_at\"]),\n expiresAt:\n result.body[\"expires_at\"] === null ? null : unixToDate(Number(result.body[\"expires_at\"])),\n startedAt:\n result.body[\"started_at\"] === null ? null : unixToDate(Number(result.body[\"started_at\"])),\n completedAt:\n result.body[\"completed_at\"] === null ? null : unixToDate(Number(result.body[\"completed_at\"])),\n cancelledAt:\n result.body[\"cancelled_at\"] === null ? null : unixToDate(Number(result.body[\"cancelled_at\"])),\n failedAt:\n result.body[\"failed_at\"] === null ? null : unixToDate(Number(result.body[\"failed_at\"])),\n };\n}\n\nexport async function _createThreadAndRunDeserialize(\n result: CreateThreadAndRun200Response\n): Promise<ThreadRun> {\n if (result.status !== \"200\") {\n throw createRestError(result);\n }\n\n return {\n id: result.body[\"id\"],\n threadId: result.body[\"thread_id\"],\n assistantId: result.body[\"assistant_id\"],\n status: result.body[\"status\"],\n requiredAction: !result.body.required_action\n ? undefined\n : {\n type: result.body.required_action?.[\"type\"],\n submitToolOutputs: !result.body.required_action?.submit_tool_outputs?.[\"tool_calls\"]\n ? undefined\n : {\n toolCalls: result.body.required_action?.submit_tool_outputs?.tool_calls?.map(\n parseRequiredToolCallOutput\n ),\n },\n },\n lastError: !result.body.last_error\n ? undefined\n : {\n code: result.body.last_error?.[\"code\"],\n message: result.body.last_error?.[\"message\"],\n },\n model: result.body[\"model\"],\n instructions: result.body[\"instructions\"],\n tools: result.body[\"tools\"],\n fileIds: result.body[\"file_ids\"],\n metadata: result.body[\"metadata\"],\n createdAt: unixToDate(result.body[\"cre