UNPKG

assistant-cloud

Version:

Cloud integration for assistant-ui

52 lines (51 loc) 2.2 kB
import { readCloudArray, readCloudBoolean, readCloudNullableString, readCloudRecord, readCloudString, readCloudTimestamp } from "./cloudResponse.js"; import { AssistantCloudThreadMessages } from "./AssistantCloudThreadMessages.js"; //#region src/AssistantCloudThreads.ts const decodeCloudThread = (value, field) => { const thread = readCloudRecord(value, field); return { title: readCloudNullableString(thread.title, `${field}.title`) ?? "", last_message_at: readCloudTimestamp(thread.last_message_at, `${field}.last_message_at`), metadata: thread.metadata, external_id: readCloudNullableString(thread.external_id, `${field}.external_id`), id: readCloudString(thread.id, `${field}.id`), project_id: readCloudString(thread.project_id, `${field}.project_id`), created_at: readCloudTimestamp(thread.created_at, `${field}.created_at`), updated_at: readCloudTimestamp(thread.updated_at, `${field}.updated_at`), workspace_id: readCloudString(thread.workspace_id, `${field}.workspace_id`), is_archived: readCloudBoolean(thread.is_archived, `${field}.is_archived`) }; }; var AssistantCloudThreads = class { messages; cloud; constructor(cloud) { this.cloud = cloud; this.messages = new AssistantCloudThreadMessages(cloud); } async list(query) { return { threads: readCloudArray(readCloudRecord(await this.cloud.makeRequest("/threads", { query }), "thread list response").threads, "threads").map((thread, index) => decodeCloudThread(thread, `threads[${index}]`)) }; } async get(threadId) { const response = readCloudRecord(await this.cloud.makeRequest(`/threads/${encodeURIComponent(threadId)}`), "thread response"); return decodeCloudThread(response.thread, "thread"); } async create(body) { return this.cloud.makeRequest("/threads", { method: "POST", body }); } async update(threadId, body) { return this.cloud.makeRequest(`/threads/${encodeURIComponent(threadId)}`, { method: "PUT", body }); } async delete(threadId) { return this.cloud.makeRequest(`/threads/${encodeURIComponent(threadId)}`, { method: "DELETE" }); } }; //#endregion export { AssistantCloudThreads, decodeCloudThread }; //# sourceMappingURL=AssistantCloudThreads.js.map