/opt/canhelp/node_modules/openai/resources/beta/threads/runs
NameSizeModeActions
index.d.mts11690644editdlrm
index.d.mts.map8660644editdlrm
index.d.ts11660644editdlrm
index.d.ts.map8650644editdlrm
index.js5190644editdlrm
index.js.map2250644editdlrm
index.mjs1950644editdlrm
index.mjs.map1940644editdlrm
runs.d.mts333580644editdlrm
runs.d.mts.map101440644editdlrm
runs.d.ts333430644editdlrm
runs.d.ts.map101430644editdlrm
runs.js77020644editdlrm
runs.js.map47950644editdlrm
runs.mjs72290644editdlrm
runs.mjs.map47580644editdlrm
steps.d.mts194550644editdlrm
steps.d.mts.map71090644editdlrm
steps.d.ts194480644editdlrm
steps.d.ts.map71080644editdlrm
steps.js17280644editdlrm
steps.js.map9860644editdlrm
steps.mjs15340644editdlrm
steps.mjs.map9830644editdlrm
Edit: /opt/canhelp/node_modules/openai/resources/beta/threads/runs/runs.mjs (7229B)
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import * as StepsAPI from "./steps.mjs"; import { Steps, } from "./steps.mjs"; import { CursorPage } from "../../../../core/pagination.mjs"; import { buildHeaders } from "../../../../internal/headers.mjs"; import { AssistantStream } from "../../../../lib/AssistantStream.mjs"; import { sleep } from "../../../../internal/utils/sleep.mjs"; import { path } from "../../../../internal/utils/path.mjs"; /** * Build Assistants that can call models and use tools. * * @deprecated The Assistants API is deprecated in favor of the Responses API */ export class Runs extends APIResource { constructor() { super(...arguments); this.steps = new StepsAPI.Steps(this._client); } create(threadID, params, options) { const { include, ...body } = params; return this._client.post(path `/threads/${threadID}/runs`, { query: { include }, body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), stream: params.stream ?? false, __synthesizeEventData: true, }); } /** * Retrieves a run. * * @deprecated The Assistants API is deprecated in favor of the Responses API */ retrieve(runID, params, options) { const { thread_id } = params; return this._client.get(path `/threads/${thread_id}/runs/${runID}`, { ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), }); } /** * Modifies a run. * * @deprecated The Assistants API is deprecated in favor of the Responses API */ update(runID, params, options) { const { thread_id, ...body } = params; return this._client.post(path `/threads/${thread_id}/runs/${runID}`, { body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), }); } /** * Returns a list of runs belonging to a thread. * * @deprecated The Assistants API is deprecated in favor of the Responses API */ list(threadID, query = {}, options) { return this._client.getAPIList(path `/threads/${threadID}/runs`, (CursorPage), { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), }); } /** * Cancels a run that is `in_progress`. * * @deprecated The Assistants API is deprecated in favor of the Responses API */ cancel(runID, params, options) { const { thread_id } = params; return this._client.post(path `/threads/${thread_id}/runs/${runID}/cancel`, { ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), }); } /** * A helper to create a run an poll for a terminal state. More information on Run * lifecycles can be found here: * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps */ async createAndPoll(threadId, body, options) { const run = await this.create(threadId, body, options); return await this.poll(run.id, { thread_id: threadId }, options); } /** * Create a Run stream * * @deprecated use `stream` instead */ createAndStream(threadId, body, options) { return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options); } /** * A helper to poll a run status until it reaches a terminal state. More * information on Run lifecycles can be found here: * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps */ async poll(runId, params, options) { const headers = buildHeaders([ options?.headers, { 'X-Stainless-Poll-Helper': 'true', 'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined, }, ]); while (true) { const { data: run, response } = await this.retrieve(runId, params, { ...options, headers: { ...options?.headers, ...headers }, }).withResponse(); switch (run.status) { //If we are in any sort of intermediate state we poll case 'queued': case 'in_progress': case 'cancelling': let sleepInterval = 5000; if (options?.pollIntervalMs) { sleepInterval = options.pollIntervalMs; } else { const headerInterval = response.headers.get('openai-poll-after-ms'); if (headerInterval) { const headerIntervalMs = parseInt(headerInterval); if (!isNaN(headerIntervalMs)) { sleepInterval = headerIntervalMs; } } } await sleep(sleepInterval); break; //We return the run in any terminal state. case 'requires_action': case 'incomplete': case 'cancelled': case 'completed': case 'failed': case 'expired': return run; } } } /** * Create a Run stream */ stream(threadId, body, options) { return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options); } submitToolOutputs(runID, params, options) { const { thread_id, ...body } = params; return this._client.post(path `/threads/${thread_id}/runs/${runID}/submit_tool_outputs`, { body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), stream: params.stream ?? false, __synthesizeEventData: true, }); } /** * A helper to submit a tool output to a run and poll for a terminal run state. * More information on Run lifecycles can be found here: * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps */ async submitToolOutputsAndPoll(runId, params, options) { const run = await this.submitToolOutputs(runId, params, options); return await this.poll(run.id, params, options); } /** * Submit the tool outputs from a previous run and stream the run to a terminal * state. More information on Run lifecycles can be found here: * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps */ submitToolOutputsStream(runId, params, options) { return AssistantStream.createToolAssistantStream(runId, this._client.beta.threads.runs, params, options); } } Runs.Steps = Steps; //# sourceMappingURL=runs.mjs.map