assistant-cloud
Version:
Cloud integration for assistant-ui
37 lines (36 loc) • 1.57 kB
JavaScript
import { readCloudNumber, readCloudRecord } from "./cloudResponse.js";
// src/AssistantCloudThreadRuns.ts
/**
* Run leases on thread messages. A lease is opened with `open_run` when its
* message is created, belongs to that message alone, and runs until its
* holder ends it; the server never expires one. The holder heartbeats on the
* server's `heartbeat_interval_ms`, and listed messages report how long ago
* the last beat was, so readers can tell a run whose tab went away. Writes as
* the holder go through `threads.messages` with the `lease_id`.
*/
var AssistantCloudThreadRuns = class {
cloud;
constructor(cloud) {
this.cloud = cloud;
}
/**
* Records a beat of a running lease. 409 `run_ended` after it ended, 404
* for a lease the server does not know.
*/
async heartbeat(threadId, leaseId) {
const response = readCloudRecord(await this.cloud.makeRequest(`/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(leaseId)}/heartbeat`, { method: "POST" }), "run heartbeat response");
return { heartbeat_interval_ms: readCloudNumber(response.heartbeat_interval_ms, "heartbeat_interval_ms") };
}
/**
* Ends a run without a content write; ending an ended run again succeeds
* and keeps the first reason. 404 for a lease the server does not know.
*/
async end(threadId, leaseId, body = {}) {
await this.cloud.makeRequest(`/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(leaseId)}/end`, {
method: "POST",
body
});
}
};
export { AssistantCloudThreadRuns };
//# sourceMappingURL=AssistantCloudThreadRuns.js.map