@hostr/upload 0.2.0 → 0.4.0

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/README.md CHANGED
@@ -75,6 +75,11 @@ upload.start();
75
75
  const { etag, sha256 } = await upload.done;
76
76
  ```
77
77
 
78
+ `createUploadSession` also takes `audio` (`'asmr'` or the knobs) and, from
79
+ 0.3.0, `captions` — `{ language?: 'auto' | bcp47, translate?: string[], context?: string }`
80
+ — which has hostr transcribe and translate the video once its audio exists
81
+ (the account must have captions enabled; see the captions guide).
82
+
78
83
  `infra/scripts/test-upload.mjs` is the canonical example — it drives the SDK
79
84
  through a kill/resume cycle and a corrupted-part self-heal against a real API
80
85
  and real R2.
@@ -29,6 +29,12 @@ export type CreateResult = {
29
29
  expectedParts: number;
30
30
  key: string;
31
31
  };
32
+ /** `createUploadSession`'s result: the API's response plus the `endpoint` it
33
+ * was minted against, because the token is only valid there and the client
34
+ * must take the endpoint from this response, not from its own config. */
35
+ export type UploadSession = CreateResult & {
36
+ endpoint: string;
37
+ };
32
38
  export type CompleteResult = {
33
39
  status: string;
34
40
  etag?: string;
@@ -63,6 +69,21 @@ export type UploadAudioOptions = 'asmr' | {
63
69
  truePeakDbtp?: number;
64
70
  kbps?: number;
65
71
  };
72
+ /**
73
+ * Per-asset captions for `POST /v1/uploads`: hostr transcribes the audio as
74
+ * soon as it exists, attaches it as a `<Language> (auto)` subtitle track, and
75
+ * translates it into each `translate` language as `(auto-translated)` tracks.
76
+ * Needs captions enabled on the account (the request is refused with
77
+ * `403 captions_not_enabled` otherwise). Watch for `captions.ready` per track.
78
+ */
79
+ export type UploadCaptionsOptions = {
80
+ /** `'auto'` (the default) to detect, or the BCP 47 tag the speech is in. */
81
+ language?: string;
82
+ /** Target BCP 47 tags, at most 10. A target in the spoken language is dropped. */
83
+ translate?: string[];
84
+ /** Up to 1000 characters of context for the transcriber: creator, title, terms. */
85
+ context?: string;
86
+ };
66
87
  export declare function createUploadSession(opts: {
67
88
  endpoint: string;
68
89
  apiKey: string;
@@ -71,8 +92,11 @@ export declare function createUploadSession(opts: {
71
92
  size: number;
72
93
  partSize?: number;
73
94
  tokenTtlSec?: number;
95
+ /** Allow Hostr to finalize validated parts without a client callback. */
96
+ autoComplete?: boolean;
74
97
  audio?: UploadAudioOptions;
75
- }, fetchFn?: typeof fetch): Promise<CreateResult>;
98
+ captions?: UploadCaptionsOptions;
99
+ }, fetchFn?: typeof fetch): Promise<UploadSession>;
76
100
  export declare function mintUploadToken(opts: {
77
101
  endpoint: string;
78
102
  apiKey: string;
package/dist/browser.js CHANGED
@@ -97,7 +97,8 @@ var HostrApi = class {
97
97
  };
98
98
  async function createUploadSession(opts, fetchFn = fetch) {
99
99
  const { endpoint, apiKey, ...body } = opts;
100
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
100
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
101
+ return { ...created, endpoint };
101
102
  }
102
103
  function mintUploadToken(opts, fetchFn = fetch) {
103
104
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type * from './core/types.js';
2
2
  export { ApiError, NetworkError, HostrApi, createUploadSession, mintUploadToken, } from './api/client.js';
3
- export type { RemotePart, RemoteUpload, CreateResult, CompleteResult, UploadAudioOptions } from './api/client.js';
3
+ export type { RemotePart, RemoteUpload, CreateResult, UploadSession, CompleteResult, UploadAudioOptions, UploadCaptionsOptions } from './api/client.js';
4
4
  export { storageKey, loadSession, saveSession, clearSession, partSizeOf, memoryStore, } from './core/session.js';
5
5
  export type { SessionStatus, SessionRecord } from './core/session.js';
6
6
  export { classifyPut, classifyApi, backoffMs, RETRY_BUDGET } from './core/retry.js';
package/dist/index.js CHANGED
@@ -71,7 +71,8 @@ var HostrApi = class {
71
71
  };
72
72
  async function createUploadSession(opts, fetchFn = fetch) {
73
73
  const { endpoint, apiKey, ...body } = opts;
74
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
74
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
75
+ return { ...created, endpoint };
75
76
  }
76
77
  function mintUploadToken(opts, fetchFn = fetch) {
77
78
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
package/dist/node.js CHANGED
@@ -102,7 +102,8 @@ var HostrApi = class {
102
102
  };
103
103
  async function createUploadSession(opts, fetchFn = fetch) {
104
104
  const { endpoint, apiKey, ...body } = opts;
105
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
105
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
106
+ return { ...created, endpoint };
106
107
  }
107
108
  function mintUploadToken(opts, fetchFn = fetch) {
108
109
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostr/upload",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,