@ohm_studio/sdk-core 0.7.0 → 0.9.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/dist/client.d.ts +72 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +369 -50
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +33 -27
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +19 -1
- package/dist/errors.js.map +1 -1
- package/dist/types.d.ts +138 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiDetail, ApiSummary, AudioExtractInput, AudioExtractResult, AudioTranscribeInput, AudioTranscribeResult, CreateAudioJobInput, CreateAudioJobResult, ExtractInput, ExtractResult, GetApiOptions, InsightsInput, InsightsResult, JobDetail, ListApisOptions, OHMClientOptions, OHMInit, PollJobOptions, RequestOptions, SearchInvocationsByPatientOptions, SearchInvocationsByPatientResult, StreamChunk, SummarizeInput, SummarizeResult, UploadProgressEvent, UsageEvent } from "./types";
|
|
1
|
+
import type { ApiDetail, ApiSummary, AudioExtractInput, AudioExtractResult, AudioTranscribeInput, AudioTranscribeResult, BulkExtractOptions, BulkResult, ClientHooks, CreateAudioJobInput, CreateAudioJobResult, ExtractInput, ExtractResult, GetApiOptions, InsightsInput, InsightsResult, JobDetail, ListApisOptions, OHMClientOptions, OHMInit, PollJobOptions, RequestOptions, SearchInvocationsByPatientOptions, SearchInvocationsByPatientResult, StreamChunk, SummarizeInput, SummarizeResult, UploadProgressEvent, UsageEvent } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Platform-agnostic core client. Subclasses (sdk-js, sdk-react-native)
|
|
4
4
|
* supply the platform-specific multipart/audio adapter via the `attachAudio`
|
|
@@ -9,12 +9,47 @@ export declare abstract class OHMCoreClient {
|
|
|
9
9
|
protected readonly apiKey?: string;
|
|
10
10
|
protected readonly jwt?: string;
|
|
11
11
|
protected readonly timeoutMs: number;
|
|
12
|
+
protected readonly totalTimeoutMs?: number;
|
|
12
13
|
protected readonly maxRetries: number;
|
|
13
14
|
protected readonly fetchImpl: typeof fetch;
|
|
14
15
|
protected readonly onUsage?: (e: UsageEvent) => void;
|
|
16
|
+
protected readonly hooks?: ClientHooks;
|
|
17
|
+
protected readonly disableAutoIdempotency: boolean;
|
|
18
|
+
protected readonly userAgent: string;
|
|
15
19
|
protected readonly _mock: boolean;
|
|
16
20
|
protected readonly _mockResponses?: OHMClientOptions["mockResponses"];
|
|
21
|
+
/** Cached options for `withOverrides`. */
|
|
22
|
+
private readonly _opts;
|
|
23
|
+
/** SDK version stamped on `X-OHM-Client` + `User-Agent`. */
|
|
24
|
+
protected static readonly SDK_VERSION = "0.8.0";
|
|
17
25
|
constructor(init: OHMInit);
|
|
26
|
+
/**
|
|
27
|
+
* Returns the SDK version string. Useful when forwarding the SDK
|
|
28
|
+
* version to your own telemetry pipeline.
|
|
29
|
+
*/
|
|
30
|
+
static getVersion(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a new client with overridden options for one call. The
|
|
33
|
+
* underlying auth + base URL are inherited; you typically only
|
|
34
|
+
* override `timeoutMs` / `maxRetries` / `totalTimeoutMs` for a
|
|
35
|
+
* single known-slow call.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const slow = ohm.withOverrides({ timeoutMs: 5 * 60_000 });
|
|
39
|
+
* await slow.audio.extract({ apiSlug, file: bigAudio });
|
|
40
|
+
*/
|
|
41
|
+
withOverrides(overrides: Partial<OHMClientOptions>): this;
|
|
42
|
+
/**
|
|
43
|
+
* Establish a TCP/TLS connection to the API ahead of the first real
|
|
44
|
+
* call. Drops cold-start latency from ~500 ms to ~150 ms on real-world
|
|
45
|
+
* mobile networks. Safe to call multiple times; no-op in mock mode.
|
|
46
|
+
*
|
|
47
|
+
* const ohm = new OHM({ apiKey });
|
|
48
|
+
* void ohm.warmUp(); // fire-and-forget at app boot
|
|
49
|
+
* // ...
|
|
50
|
+
* await ohm.extract({ ... }); // already-warm connection
|
|
51
|
+
*/
|
|
52
|
+
warmUp(): Promise<void>;
|
|
18
53
|
/**
|
|
19
54
|
* Audio surface — speech-to-text and audio-to-structured-JSON.
|
|
20
55
|
* Subclasses fill in the platform-specific multipart adapter (browser
|
|
@@ -65,7 +100,7 @@ export declare abstract class OHMCoreClient {
|
|
|
65
100
|
* step finishes. Backend uses Server-Sent Events.
|
|
66
101
|
*
|
|
67
102
|
* @example
|
|
68
|
-
* const stream = ohm.audio.
|
|
103
|
+
* const stream = ohm.audio.extractStream({ apiSlug, file });
|
|
69
104
|
* for await (const chunk of stream) {
|
|
70
105
|
* if (chunk.type === "transcript") setT(chunk.transcript);
|
|
71
106
|
* if (chunk.type === "data") setData(chunk.data);
|
|
@@ -160,6 +195,29 @@ export declare abstract class OHMCoreClient {
|
|
|
160
195
|
* }
|
|
161
196
|
*/
|
|
162
197
|
extract<T = Record<string, unknown>>(input: ExtractInput): Promise<ExtractResult<T>>;
|
|
198
|
+
/**
|
|
199
|
+
* Bulk-extract a batch of text inputs concurrently. Partial failures
|
|
200
|
+
* do NOT fail the batch — each input gets a discriminated-union
|
|
201
|
+
* result (`{ ok: true, data }` or `{ ok: false, error, input }`).
|
|
202
|
+
*
|
|
203
|
+
* Use when replaying historical transcripts, batch-tagging lab
|
|
204
|
+
* reports, or anywhere "10 000 of these need to extract this week".
|
|
205
|
+
*
|
|
206
|
+
* Default concurrency is 4 — enough to amortise network round-trips
|
|
207
|
+
* without blowing the per-key rate limit. Pass a higher cap when you
|
|
208
|
+
* know your key's quota is generous.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* const results = await ohm.extractBulk(transcripts.map(t => ({
|
|
212
|
+
* apiSlug: "opd-clinic",
|
|
213
|
+
* text: t,
|
|
214
|
+
* })), {
|
|
215
|
+
* concurrency: 8,
|
|
216
|
+
* onProgress: (done, total) => console.log(`${done}/${total}`),
|
|
217
|
+
* });
|
|
218
|
+
* const errored = results.filter(r => !r.ok);
|
|
219
|
+
*/
|
|
220
|
+
extractBulk<T = Record<string, unknown>>(inputs: ExtractInput[], options?: BulkExtractOptions): Promise<BulkResult<T>[]>;
|
|
163
221
|
/**
|
|
164
222
|
* One-line convenience: pass a transcript, get back the data field.
|
|
165
223
|
* Equivalent to `(await ohm.extract({ apiSlug, text })).data` — the most
|
|
@@ -264,16 +322,25 @@ export declare abstract class OHMCoreClient {
|
|
|
264
322
|
searchByPatient: (options: SearchInvocationsByPatientOptions) => Promise<SearchInvocationsByPatientResult>;
|
|
265
323
|
};
|
|
266
324
|
protected requestJson<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
325
|
+
/**
|
|
326
|
+
* Pre-upload size guard. Throws OHMValidationError BEFORE the
|
|
327
|
+
* multipart request fires so the customer doesn't burn upload time
|
|
328
|
+
* on a multi-GB mis-attached file. Best-effort — file shape varies
|
|
329
|
+
* across web (Blob/File), node (Buffer/Stream), and React-Native; we
|
|
330
|
+
* read whatever size hint is reachable and skip the check when none
|
|
331
|
+
* is. Server-side will reject oversize uploads regardless.
|
|
332
|
+
*/
|
|
333
|
+
protected assertFileSize(file: any): void;
|
|
267
334
|
protected abstract runMultipart<T>(opts: {
|
|
268
335
|
path: string;
|
|
269
336
|
file: any;
|
|
270
337
|
fields?: Record<string, string>;
|
|
271
338
|
signal?: AbortSignal;
|
|
272
|
-
idempotencyKey?: string;
|
|
339
|
+
idempotencyKey?: string | null;
|
|
273
340
|
onProgress?: (event: UploadProgressEvent) => void;
|
|
274
341
|
}): Promise<T>;
|
|
275
342
|
/**
|
|
276
|
-
* Default SSE-based streaming for audio.
|
|
343
|
+
* Default SSE-based streaming for audio.extractStream. Subclasses
|
|
277
344
|
* override `runMultipart` to construct the FormData body for their
|
|
278
345
|
* platform; this method reuses that body and parses an SSE event stream
|
|
279
346
|
* off the response.
|
|
@@ -289,7 +356,7 @@ export declare abstract class OHMCoreClient {
|
|
|
289
356
|
file: any;
|
|
290
357
|
fields?: Record<string, string>;
|
|
291
358
|
signal?: AbortSignal;
|
|
292
|
-
idempotencyKey?: string;
|
|
359
|
+
idempotencyKey?: string | null;
|
|
293
360
|
}): AsyncGenerator<StreamChunk<T>>;
|
|
294
361
|
/**
|
|
295
362
|
* Builds a `FormData` (web/Node) or RN-shaped FormData. Subclasses
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACd,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,cAAc,EACd,iCAAiC,EACjC,gCAAgC,EAChC,WAAW,EACX,cAAc,EACd,eAAe,EAEf,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACd,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,cAAc,EACd,iCAAiC,EACjC,gCAAgC,EAChC,WAAW,EACX,cAAc,EACd,eAAe,EAEf,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;AAqDjB;;;;GAIG;AACH,8BAAsB,aAAa;IACjC,SAAS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