@jsm-mit/sultana-core-motoko-package 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { AdminActor } from "./actors/admin-actor.js";
2
- export { VideoUploadClient, uploadVideoToWorkers } from "./video-upload-client.js";
3
- export type { VideoUploadStage, VideoUploadProgress, VideoUploadOptions, VideoUploadAcceptance, VideoUploadResult, } from "./video-upload-client.js";
2
+ export { VideoUploadClient, uploadVideoToWorkers, getSalonAssetsWithStatus } from "./video-upload-client.js";
3
+ export type { SalonAssetWithStatus } from "./video-upload-client.js";
4
+ export type { VideoUploadStage, VideoUploadProgress, VideoUploadOptions, VideoUploadAcceptance, VideoUploadResult, VideoTranscodeCheck, } from "./video-upload-client.js";
4
5
  export type { ActionQuotaRole, CallActivityStats } from "./actors/admin-actor.js";
5
6
  export { BulkActor } from "./actors/bulk-actor.js";
6
7
  export { AppointmentsActor } from "./actors/appointments-actor.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACnF,YAAY,EACR,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AA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yB,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1G,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAClH,YAAY,EACR,KAAK,EACL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,GAClB,MAAM,gEAAgE,CAAC;AACxE,YAAY,EACR,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,4BAA4B,EAC5B,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACzB,MAAM,gEAAgE,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { AdminActor } from "./actors/admin-actor.js";
2
- export { VideoUploadClient, uploadVideoToWorkers } from "./video-upload-client.js";
2
+ export { VideoUploadClient, uploadVideoToWorkers, getSalonAssetsWithStatus } from "./video-upload-client.js";
3
3
  export { BulkActor } from "./actors/bulk-actor.js";
4
4
  export { AppointmentsActor } from "./actors/appointments-actor.js";
5
5
  export { AssetsActor } from "./actors/assets-actor.js";
@@ -1,4 +1,6 @@
1
1
  import { type Identity } from "@icp-sdk/core/agent";
2
+ import type { SalonAsset } from "../declarations/sultana-core-motoko/sultana-core-motoko.did.js";
3
+ import type { AssetsActor } from "./actors/assets-actor.js";
2
4
  /**
3
5
  * Front-facing video upload flow (see TODO_ASSETS.md "Wideo — upload"):
4
6
  *
@@ -69,6 +71,33 @@ export interface VideoUploadResult {
69
71
  /** One entry per worker that was tried and failed before the accepting one. */
70
72
  failedAttempts: string[];
71
73
  }
74
+ /** One-shot verdict about a video upload's transcoding state (see checkVideoStatus). */
75
+ export type VideoTranscodeCheck = {
76
+ state: "stored";
77
+ sizeBytes: number;
78
+ } | {
79
+ state: "processing";
80
+ workerUrl: string;
81
+ } | {
82
+ state: "failed";
83
+ message: string;
84
+ workerUrl: string;
85
+ } | {
86
+ state: "unknown";
87
+ };
88
+ /** A library entry, enriched with a live transcode verdict when it is #Pending. */
89
+ export type SalonAssetWithStatus = SalonAsset & {
90
+ /** Present only on #Pending entries (see getSalonAssetsWithStatus). */
91
+ transcodeCheck?: VideoTranscodeCheck;
92
+ };
93
+ /**
94
+ * getSalonAssets + a live one-shot transcode verdict for every #Pending entry — the library
95
+ * fetch a UI actually wants: Ready/Failed entries come as-is, Pending ones say whether the
96
+ * worker is still on it ("processing"), already delivered ("stored" — registration in
97
+ * flight), reported a failure, or lost its context ("unknown" — the sweep will flip the
98
+ * entry to #Failed within ~25h). The worker list is fetched once for all checks.
99
+ */
100
+ export declare function getSalonAssetsWithStatus(assetsActor: AssetsActor, videoClient: VideoUploadClient, salonId: string): Promise<SalonAssetWithStatus[]>;
72
101
  /**
73
102
  * Uploads the source to the first worker in `uploadUrls` that accepts it, restarting from
74
103
  * chunk 0 on each failover. Exported separately from the client so the failover behavior is
@@ -99,6 +128,23 @@ export declare class VideoUploadClient {
99
128
  /** startVideoUpload + waitForVideo: resolves only when the transcoded result is stored
100
129
  * on the asset canister and registered #Ready in the salon's library. */
101
130
  uploadVideo(salonId: string, bytes: Uint8Array, options?: VideoUploadOptions): Promise<VideoUploadResult>;
131
+ /** The upload-endpoint URLs currently configured on the asset canister (get_workers). */
132
+ getWorkerUrls(): Promise<string[]>;
133
+ /**
134
+ * One-shot, non-blocking check of a video upload's transcoding state — for UIs that show
135
+ * a #Pending library entry and want to tell "still working" from "context lost". Sources,
136
+ * in order of authority:
137
+ * 1. the asset canister's get_asset_info — result already stored ("stored");
138
+ * 2. the transcode-status endpoints of the given workers (or, by default, every worker
139
+ * configured on the canister — the library entry does not record which one took the
140
+ * upload): "processing"/"done" → processing, "error"/"rejected" → failed with reason;
141
+ * 3. nobody knows the id → "unknown": for a Pending entry that means the worker lost its
142
+ * context (crash/restart) — the canister's stale-reservation sweep will flip the entry
143
+ * to #Failed within ~25h, or the owner can delete it right away. (Worker statuses are
144
+ * in-memory with a 1h TTL, so "unknown" can also mean "finished over an hour ago" —
145
+ * but then the entry would no longer be Pending.)
146
+ */
147
+ checkVideoStatus(assetId: string, workerUrls?: string[]): Promise<VideoTranscodeCheck>;
102
148
  /**
103
149
  * Waits for an accepted upload to finish transcoding, by polling the asset canister's
104
150
  * metadata (the durable source of truth — survives dropped connections and page reloads)
@@ -1 +1 @@
1
- {"version":3,"file":"video-upload-client.d.ts","sourceRoot":"","sources":["../src/video-upload-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI1F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC;AAExE,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,gBAAgB,CAAC;IACxB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IAC/B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8FAA8F;IAC9F,mBAA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TES = 10 * 1024 * 1024;
4
4
  const DEFAULT_PROCESSING_TIMEOUT_MS = 10 * 60 * 1000;
5
5
  const DEFAULT_POLL_INTERVAL_MS = 5 * 1000;
6
+ /**
7
+ * getSalonAssets + a live one-shot transcode verdict for every #Pending entry — the library
8
+ * fetch a UI actually wants: Ready/Failed entries come as-is, Pending ones say whether the
9
+ * worker is still on it ("processing"), already delivered ("stored" — registration in
10
+ * flight), reported a failure, or lost its context ("unknown" — the sweep will flip the
11
+ * entry to #Failed within ~25h). The worker list is fetched once for all checks.
12
+ */
13
+ export async function getSalonAssetsWithStatus(assetsActor, videoClient, salonId) {
14
+ const library = await assetsActor.getSalonAssetsAsyncUnsafe(salonId);
15
+ const pending = library.filter(asset => "Pending" in asset.status);
16
+ if (pending.length === 0)
17
+ return library;
18
+ const workerUrls = await videoClient.getWorkerUrls();
19
+ const checks = new Map();
20
+ await Promise.all(pending.map(async (asset) => {
21
+ checks.set(asset.assetId, await videoClient.checkVideoStatus(asset.assetId, workerUrls));
22
+ }));
23
+ return library.map(asset => checks.has(asset.assetId) ? { ...asset, transcodeCheck: checks.get(asset.assetId) } : asset);
24
+ }
6
25
  class WorkerHttpError extends Error {
7
26
  status;
8
27
  constructor(status, message) {
@@ -159,6 +178,53 @@ export class VideoUploadClient {
159
178
  failedAttempts: acceptance.failedAttempts,
160
179
  };
161
180
  }
181
+ /** The upload-endpoint URLs currently configured on the asset canister (get_workers). */
182
+ async getWorkerUrls() {
183
+ return (await this.actor.get_workers()).map(worker => worker.url);
184
+ }
185
+ /**
186
+ * One-shot, non-blocking check of a video upload's transcoding state — for UIs that show
187
+ * a #Pending library entry and want to tell "still working" from "context lost". Sources,
188
+ * in order of authority:
189
+ * 1. the asset canister's get_asset_info — result already stored ("stored");
190
+ * 2. the transcode-status endpoints of the given workers (or, by default, every worker
191
+ * configured on the canister — the library entry does not record which one took the
192
+ * upload): "processing"/"done" → processing, "error"/"rejected" → failed with reason;
193
+ * 3. nobody knows the id → "unknown": for a Pending entry that means the worker lost its
194
+ * context (crash/restart) — the canister's stale-reservation sweep will flip the entry
195
+ * to #Failed within ~25h, or the owner can delete it right away. (Worker statuses are
196
+ * in-memory with a 1h TTL, so "unknown" can also mean "finished over an hour ago" —
197
+ * but then the entry would no longer be Pending.)
198
+ */
199
+ async checkVideoStatus(assetId, workerUrls) {
200
+ const info = await this.actor.get_asset_info(assetId);
201
+ if (info.length > 0)
202
+ return { state: "stored", sizeBytes: Number(info[0].totalSize) };
203
+ const urls = workerUrls ?? (await this.actor.get_workers()).map(w => w.url);
204
+ for (const workerUrl of urls) {
205
+ const statusUrl = statusUrlFor(workerUrl, assetId);
206
+ if (!statusUrl)
207
+ continue;
208
+ try {
209
+ const response = await fetch(statusUrl);
210
+ if (!response.ok)
211
+ continue;
212
+ const status = (await response.json());
213
+ if (status.status === "processing" || status.status === "done") {
214
+ // "done" with no stored bytes yet = the canister upload/registration is in
215
+ // flight — from the caller's perspective that is still processing.
216
+ return { state: "processing", workerUrl };
217
+ }
218
+ if (status.status === "error" || status.status === "rejected") {
219
+ return { state: "failed", message: status.message ?? status.status, workerUrl };
220
+ }
221
+ }
222
+ catch {
223
+ // worker unreachable — try the next one
224
+ }
225
+ }
226
+ return { state: "unknown" };
227
+ }
162
228
  /**
163
229
  * Waits for an accepted upload to finish transcoding, by polling the asset canister's
164
230
  * metadata (the durable source of truth — survives dropped connections and page reloads)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/sultana-core-motoko-package",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "A TypeScript library for interacting with the Sultana Core Motoko actor on the Internet Computer (IC) platform.",
5
5
  "homepage": "https://github.com/JSM-Sultana/sultana-core-motoko-package#readme",
6
6
  "bugs": {