@urun-sh/openai 0.5.4 → 0.5.6
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/{ResponsesClient-BYx3YLGo.d.ts → ResponsesClient-BE3-hx3m.d.ts} +2 -0
- package/dist/{ResponsesClient-Dft3bg3b.d.cts → ResponsesClient-DjZWjlFH.d.cts} +2 -0
- package/dist/chunk-2T2YYBVX.js +1 -0
- package/dist/chunk-3WAJD62J.js +4 -0
- package/dist/{chunk-K23AZPI4.js → chunk-5HKWNK3O.js} +1 -1
- package/dist/chunk-7M6LY6DR.js +2 -0
- package/dist/chunk-BSHT6RZZ.js +1 -0
- package/dist/{chunk-GBBY3PCZ.js → chunk-FP4RSAIE.js} +1 -1
- package/dist/chunk-HR5H6S7L.js +1 -0
- package/dist/chunk-NY23USZF.js +57 -0
- package/dist/chunk-VLRMJRLS.js +6 -0
- package/dist/gemini-live.cjs +2 -2
- package/dist/gemini-live.d.cts +17 -2
- package/dist/gemini-live.d.ts +7 -2
- package/dist/gemini-live.js +1 -1
- package/dist/hosted/bin.cjs +65 -37
- package/dist/hosted/bin.js +3 -3
- package/dist/hosted/index.cjs +46 -19
- package/dist/hosted/index.d.cts +760 -272
- package/dist/hosted/index.d.ts +203 -107
- package/dist/hosted/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/{models-NYMZrklp.d.cts → models-DUdx_Y6X.d.cts} +1 -1
- package/dist/pi-extension/index.cjs +7 -7
- package/dist/pi-extension/index.d.cts +1 -1
- package/dist/pi-extension/index.d.ts +1 -1
- package/dist/pi-extension/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +48 -48
- package/dist/proxy/cli.cjs +54 -40
- package/dist/proxy/cli.js +14 -14
- package/dist/proxy/index.cjs +33 -22
- package/dist/proxy/index.d.cts +546 -4
- package/dist/proxy/index.d.ts +185 -4
- package/dist/proxy/index.js +1 -1
- package/dist/responses-turn-Dr37N3kH.d.ts +486 -0
- package/dist/responses-turn-tNUHq5b0.d.cts +1807 -0
- package/dist/{translator-C9uPKypK.d.ts → translator-BCoRFaTs.d.ts} +1 -1
- package/dist/{translator-CcDBEfvm.d.cts → translator-Bh0Bp_Ie.d.cts} +3 -3
- package/dist/{video-out-D20UuJ8G.d.cts → video-out-CCksIcj8.d.cts} +5 -5
- package/package.json +12 -11
- package/dist/chunk-4MSBS7M6.js +0 -1
- package/dist/chunk-5NXM4IO3.js +0 -2
- package/dist/chunk-CWJRDBDC.js +0 -1
- package/dist/chunk-OI2OY32M.js +0 -1
- package/dist/chunk-RQBD4OAA.js +0 -6
- package/dist/chunk-STFRT5OY.js +0 -1
- package/dist/chunk-VNM4M4P3.js +0 -40
- package/dist/server-DuH_5OD9.d.ts +0 -84
- package/dist/server-wmUnMewW.d.cts +0 -206
- /package/dist/{chunk-YSFSRI3D.js → chunk-5CCJUNH7.js} +0 -0
- /package/dist/{models-NYMZrklp.d.ts → models-DUdx_Y6X.d.ts} +0 -0
- /package/dist/{video-out-CWesbk12.d.ts → video-out-IGQ4YQ-c.d.ts} +0 -0
package/dist/hosted/index.d.ts
CHANGED
|
@@ -1,123 +1,70 @@
|
|
|
1
1
|
import { Server } from 'node:http';
|
|
2
|
+
import * as _prometheus_io_client from '@prometheus-io/client';
|
|
3
|
+
import { Registry } from '@prometheus-io/client';
|
|
4
|
+
import { c as LedgerOutcome, I as InferenceRecord, S as SessionGoneError, P as ProxyClients, M as ModelRouter, i as UsageRowReporter, b as InferenceUsageRecord, e as LedgerWrite, d as LedgerRecorded, L as LedgerFailure } from '../responses-turn-Dr37N3kH.js';
|
|
2
5
|
import { createClientToken } from '@urun-sh/core';
|
|
3
|
-
import { U as UrunResponses } from '../ResponsesClient-
|
|
6
|
+
import { U as UrunResponses } from '../ResponsesClient-BE3-hx3m.js';
|
|
4
7
|
import { b as UrunSessionLike } from '../types-lsVTbNcH.js';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import '../video-out-CWesbk12.js';
|
|
8
|
+
import '../models-DUdx_Y6X.js';
|
|
9
|
+
import '../video-out-IGQ4YQ-c.js';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
data: OpenRouterProviderModel[];
|
|
11
|
-
};
|
|
12
|
-
interface OpenRouterProviderModel {
|
|
13
|
-
schema_version: '2.4';
|
|
14
|
-
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
created: number;
|
|
18
|
-
|
|
19
|
-
quantization: string | null;
|
|
20
|
-
description: string;
|
|
21
|
-
hugging_face_id: string;
|
|
22
|
-
input_modalities: Array<Record<string, unknown>>;
|
|
23
|
-
output_modalities: Array<Record<string, unknown>>;
|
|
24
|
-
}
|
|
11
|
+
declare const METRICS_PORT = 9464;
|
|
25
12
|
|
|
26
|
-
|
|
27
|
-
app_slug: string;
|
|
28
|
-
function_name?: string | null;
|
|
29
|
-
deployment_status?: string | null;
|
|
30
|
-
[k: string]: unknown;
|
|
31
|
-
}
|
|
13
|
+
declare const METRICS_PATH = "/metrics";
|
|
32
14
|
|
|
33
|
-
declare
|
|
34
|
-
}
|
|
15
|
+
declare const OTHER_LABEL = "(other)";
|
|
35
16
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
context_length?: number;
|
|
53
|
-
}
|
|
54
|
-
interface RouterModelList {
|
|
55
|
-
object: 'list';
|
|
56
|
-
data: RouterModelEntry[];
|
|
57
|
-
}
|
|
58
|
-
interface ModelRouterOptions<S> {
|
|
59
|
-
|
|
60
|
-
defaultApp: string | null;
|
|
61
|
-
|
|
62
|
-
fnName: string;
|
|
63
|
-
|
|
64
|
-
openSession: (appSlug: string) => S | Promise<S>;
|
|
65
|
-
|
|
66
|
-
closeSession: (entry: S) => Promise<void>;
|
|
67
|
-
|
|
68
|
-
listApps: (() => Promise<DeployedApp[]>) | null;
|
|
17
|
+
declare const NO_MODEL_LABEL = "(none)";
|
|
18
|
+
|
|
19
|
+
declare const MAX_MODEL_LABELS = 64;
|
|
20
|
+
|
|
21
|
+
declare const MAX_ORG_LABELS = 128;
|
|
22
|
+
|
|
23
|
+
declare function laneOf(path: string): string;
|
|
24
|
+
|
|
25
|
+
declare function statusClassOf(status: number | null): string;
|
|
26
|
+
|
|
27
|
+
declare class BoundedLabel {
|
|
28
|
+
private readonly max;
|
|
29
|
+
private readonly admitted;
|
|
30
|
+
private overflows;
|
|
31
|
+
constructor(max: number);
|
|
69
32
|
|
|
70
|
-
|
|
33
|
+
of(value: string | null, admit?: boolean): string;
|
|
71
34
|
|
|
72
|
-
|
|
35
|
+
get size(): number;
|
|
73
36
|
|
|
74
|
-
|
|
37
|
+
get overflowCount(): number;
|
|
75
38
|
}
|
|
76
39
|
|
|
77
|
-
declare class
|
|
78
|
-
|
|
79
|
-
private readonly
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
private
|
|
86
|
-
|
|
87
|
-
private
|
|
88
|
-
|
|
89
|
-
private
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
handleFor(model: string | undefined): Promise<{
|
|
103
|
-
app: string;
|
|
104
|
-
handle: string;
|
|
105
|
-
}>;
|
|
106
|
-
|
|
107
|
-
sessionForHandle(handle: string): Promise<{
|
|
108
|
-
app: string;
|
|
109
|
-
entry: S;
|
|
110
|
-
}>;
|
|
111
|
-
|
|
112
|
-
evict(app: string, entry: S): Promise<void>;
|
|
113
|
-
|
|
114
|
-
modelList(): Promise<RouterModelList>;
|
|
115
|
-
|
|
116
|
-
openRouterModels(): Promise<OpenRouterProviderDoc>;
|
|
117
|
-
|
|
118
|
-
closeAll(): Promise<void>;
|
|
40
|
+
declare class InferenceMetrics {
|
|
41
|
+
readonly registry: Registry<_prometheus_io_client.RegistryContentType>;
|
|
42
|
+
private readonly modelLabel;
|
|
43
|
+
private readonly orgLabel;
|
|
44
|
+
private readonly requests;
|
|
45
|
+
private readonly duration;
|
|
46
|
+
private readonly ttft;
|
|
47
|
+
private readonly streamErrors;
|
|
48
|
+
private readonly undelivered;
|
|
49
|
+
private readonly ledgerWrites;
|
|
50
|
+
private readonly ledgerQueue;
|
|
51
|
+
private readonly labelCardinality;
|
|
52
|
+
private readonly labelOverflows;
|
|
53
|
+
constructor(options?: {
|
|
54
|
+
defaultMetrics?: boolean;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
observeLedger(outcome: LedgerOutcome): void;
|
|
58
|
+
|
|
59
|
+
observe(record: InferenceRecord): void;
|
|
60
|
+
|
|
61
|
+
scrape(): Promise<string>;
|
|
62
|
+
|
|
63
|
+
get contentType(): string;
|
|
119
64
|
}
|
|
120
65
|
|
|
66
|
+
declare function createMetricsServer(metrics: InferenceMetrics): Server;
|
|
67
|
+
|
|
121
68
|
declare class ProxyAuthError extends Error {
|
|
122
69
|
readonly status: number;
|
|
123
70
|
constructor(message: string, status?: number);
|
|
@@ -174,12 +121,18 @@ interface CatalogConfig {
|
|
|
174
121
|
|
|
175
122
|
type OwnedSession = UrunSessionLike & {
|
|
176
123
|
end: () => Promise<unknown>;
|
|
124
|
+
|
|
125
|
+
detach?: () => void;
|
|
177
126
|
id?: string;
|
|
178
127
|
endsAt?: Date | null;
|
|
179
128
|
onPhase?: (handler: (phase: {
|
|
180
129
|
name: string;
|
|
181
130
|
reason?: string;
|
|
182
131
|
}) => void) => () => void;
|
|
132
|
+
whenLive?: (options?: {
|
|
133
|
+
timeout?: number;
|
|
134
|
+
signal?: AbortSignal;
|
|
135
|
+
}) => Promise<void>;
|
|
183
136
|
};
|
|
184
137
|
|
|
185
138
|
type PoolEntry = {
|
|
@@ -209,6 +162,8 @@ declare class TenantRegistry {
|
|
|
209
162
|
|
|
210
163
|
private readonly tenants;
|
|
211
164
|
constructor(opts: TenantRegistryOptions);
|
|
165
|
+
|
|
166
|
+
private label;
|
|
212
167
|
private build;
|
|
213
168
|
|
|
214
169
|
clientsFor(caller: CallerIdentity): ProxyClients;
|
|
@@ -218,6 +173,109 @@ declare class TenantRegistry {
|
|
|
218
173
|
closeAll(): Promise<void>;
|
|
219
174
|
}
|
|
220
175
|
|
|
176
|
+
declare const MAX_CONVERSATIONS = 512;
|
|
177
|
+
|
|
178
|
+
declare const MAX_CONVERSATION_HANDLES = 1024;
|
|
179
|
+
|
|
180
|
+
declare class ConversationCapacityError extends Error {
|
|
181
|
+
constructor();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface PrivateConversationBackhaul {
|
|
185
|
+
clients: ProxyClients;
|
|
186
|
+
|
|
187
|
+
release(): Promise<void>;
|
|
188
|
+
}
|
|
189
|
+
interface ConversationBackhaulOptions {
|
|
190
|
+
|
|
191
|
+
baseUrl: string;
|
|
192
|
+
|
|
193
|
+
apiUrl: string;
|
|
194
|
+
|
|
195
|
+
catalog: CatalogConfig | null;
|
|
196
|
+
|
|
197
|
+
build?: (caller: CallerIdentity, conversation: {
|
|
198
|
+
id: string;
|
|
199
|
+
subject: string;
|
|
200
|
+
}) => PrivateConversationBackhaul;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
interface PrivateConversationConnection {
|
|
204
|
+
clients: ProxyClients;
|
|
205
|
+
bindResumeHandle(handle: string): void;
|
|
206
|
+
clientsForResume(handle: string): Promise<ProxyClients>;
|
|
207
|
+
|
|
208
|
+
release(): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare class ConversationBackhauls {
|
|
212
|
+
private readonly opts;
|
|
213
|
+
|
|
214
|
+
private readonly byCaller;
|
|
215
|
+
|
|
216
|
+
private readonly byHandle;
|
|
217
|
+
constructor(opts: ConversationBackhaulOptions);
|
|
218
|
+
private build;
|
|
219
|
+
|
|
220
|
+
private attachEntry;
|
|
221
|
+
private get conversationCount();
|
|
222
|
+
|
|
223
|
+
private evictOverflow;
|
|
224
|
+
private dropHandleIndexFor;
|
|
225
|
+
|
|
226
|
+
connectionFor(caller: CallerIdentity): PrivateConversationConnection;
|
|
227
|
+
|
|
228
|
+
detachAll(): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface UsageClientOptions {
|
|
232
|
+
|
|
233
|
+
apiUrl: string;
|
|
234
|
+
|
|
235
|
+
fetchImpl?: typeof fetch;
|
|
236
|
+
|
|
237
|
+
onRejectedRow?: UsageRowReporter;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare class UsageClient {
|
|
241
|
+
private readonly opts;
|
|
242
|
+
private readonly fetchImpl;
|
|
243
|
+
constructor(opts: UsageClientOptions);
|
|
244
|
+
|
|
245
|
+
lookup(apiKey: string, inferenceIds: readonly string[]): Promise<InferenceUsageRecord[]>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
declare const LEDGER_FUNCTION_PATH = "/inference-ledger";
|
|
249
|
+
|
|
250
|
+
declare const LEDGER_WRITE_TIMEOUT_MS = 10000;
|
|
251
|
+
|
|
252
|
+
declare class LedgerDuplicateError extends Error implements LedgerFailure {
|
|
253
|
+
|
|
254
|
+
readonly ledgerFailureReason: 'duplicate' | 'duplicate_foreign';
|
|
255
|
+
constructor(message: string, reason?: 'duplicate' | 'duplicate_foreign');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
declare class LedgerSurfaceError extends Error implements LedgerFailure {
|
|
259
|
+
readonly ledgerFailureReason: "surface";
|
|
260
|
+
constructor(message: string);
|
|
261
|
+
}
|
|
262
|
+
interface LedgerClientOptions {
|
|
263
|
+
|
|
264
|
+
apiUrl: string;
|
|
265
|
+
|
|
266
|
+
fetchImpl?: typeof fetch;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
declare function parseLedgerRecorded(raw: unknown, where: string): LedgerRecorded;
|
|
270
|
+
|
|
271
|
+
declare class LedgerClient {
|
|
272
|
+
private readonly opts;
|
|
273
|
+
private readonly fetchImpl;
|
|
274
|
+
constructor(opts: LedgerClientOptions);
|
|
275
|
+
|
|
276
|
+
write(apiKey: string, entry: LedgerWrite): Promise<LedgerRecorded>;
|
|
277
|
+
}
|
|
278
|
+
|
|
221
279
|
declare const DEFAULT_PORT = 8080;
|
|
222
280
|
|
|
223
281
|
declare const SERVE_FUNCTION = "serve";
|
|
@@ -250,11 +308,49 @@ interface HostedProxyOptions extends HostedConfig {
|
|
|
250
308
|
resolver?: OrgResolver;
|
|
251
309
|
|
|
252
310
|
registry?: TenantRegistry;
|
|
311
|
+
|
|
312
|
+
conversations?: ConversationBackhauls;
|
|
313
|
+
|
|
314
|
+
usageClient?: UsageClient;
|
|
315
|
+
|
|
316
|
+
ledgerClient?: LedgerClient;
|
|
317
|
+
|
|
318
|
+
ledgerLog?: (line: string) => void;
|
|
319
|
+
|
|
320
|
+
requestLog?: (line: string) => void;
|
|
321
|
+
|
|
322
|
+
defaultMetrics?: boolean;
|
|
253
323
|
}
|
|
254
324
|
|
|
255
325
|
declare function createHostedProxy(options: HostedProxyOptions): {
|
|
256
326
|
server: Server;
|
|
327
|
+
|
|
328
|
+
metricsServer: Server;
|
|
329
|
+
metrics: InferenceMetrics;
|
|
330
|
+
|
|
331
|
+
edgeIdentityServer: Server;
|
|
257
332
|
closeAll: () => Promise<void>;
|
|
333
|
+
closeWebSockets: () => Promise<void>;
|
|
258
334
|
};
|
|
259
335
|
|
|
260
|
-
|
|
336
|
+
declare const EDGE_IDENTITY_PORT = 9465;
|
|
337
|
+
|
|
338
|
+
declare const EDGE_KEY_ID_HEADER = "x-urun-key-id";
|
|
339
|
+
|
|
340
|
+
declare const EDGE_KEY_FINGERPRINT_HEADER = "x-urun-key-fingerprint";
|
|
341
|
+
|
|
342
|
+
declare const BUCKET_DOMAIN = "urun-ratelimit-bucket:";
|
|
343
|
+
|
|
344
|
+
declare const TIER_DOMAIN = "urun-ratelimit-tier:";
|
|
345
|
+
|
|
346
|
+
declare const ANONYMOUS_KEY_ID = "anonymous";
|
|
347
|
+
|
|
348
|
+
declare function edgeBucketId(bearerToken: string): string;
|
|
349
|
+
|
|
350
|
+
declare function edgeTierFingerprint(bearerToken: string): string;
|
|
351
|
+
|
|
352
|
+
declare function bearerTokenOf(headerValue: string | undefined): string | null;
|
|
353
|
+
|
|
354
|
+
declare function createEdgeIdentityServer(): Server;
|
|
355
|
+
|
|
356
|
+
export { ANONYMOUS_KEY_ID, BIND_HOST, BUCKET_DOMAIN, BoundedLabel, type CallerIdentity, ControlPlaneUnavailableError, type ConversationBackhaulOptions, ConversationBackhauls, ConversationCapacityError, DEFAULT_PORT, EDGE_IDENTITY_PORT, EDGE_KEY_FINGERPRINT_HEADER, EDGE_KEY_ID_HEADER, type HostedConfig, type HostedProxyOptions, InferenceMetrics, LEDGER_FUNCTION_PATH, LEDGER_WRITE_TIMEOUT_MS, LedgerClient, type LedgerClientOptions, LedgerDuplicateError, LedgerSurfaceError, MAX_CACHED_KEYS, MAX_CONVERSATIONS, MAX_CONVERSATION_HANDLES, MAX_MODEL_LABELS, MAX_ORG_LABELS, MAX_TENANTS, METRICS_PATH, METRICS_PORT, NO_MODEL_LABEL, ORG_BINDING_TTL_MS, OTHER_LABEL, OrgResolver, type OrgResolverOptions, type PrivateConversationBackhaul, type PrivateConversationConnection, ProxyAuthError, READINESS_TIMEOUT_MS, READINESS_TTL_MS, SERVE_FUNCTION, TIER_DOMAIN, TenantRegistry, type TenantRegistryOptions, bearerFrom, bearerTokenOf, createEdgeIdentityServer, createHostedProxy, createMetricsServer, edgeBucketId, edgeTierFingerprint, laneOf, parseLedgerRecorded, resolveHostedConfig, statusClassOf, tenantSubject };
|
package/dist/hosted/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{A as x,B as v,C as m,D as y,E as B,F as H,G as P,H as u,I as G,J as U,K as F,L as X,M as Y,N as b,O as h,P as k,Q as K,R as V,S as j,T as W,U as q,a as r,b as o,c as t,d as E,e as n,f as _,g as a,h as T,i as O,j as i,k as s,l as I,m as p,n as A,o as R,p as S,q as N,r as C,s as D,t as L,u as M,v as d,w as f,x as l,y as c,z as g}from"../chunk-VLRMJRLS.js";import"../chunk-HR5H6S7L.js";import"../chunk-5HKWNK3O.js";import"../chunk-NY23USZF.js";import"../chunk-FP4RSAIE.js";import"../chunk-3WAJD62J.js";import"../chunk-7M6LY6DR.js";import"../chunk-BSHT6RZZ.js";import"../chunk-2T2YYBVX.js";import{c as e}from"../chunk-5CCJUNH7.js";e();export{N as ANONYMOUS_KEY_ID,y as BIND_HOST,R as BUCKET_DOMAIN,O as BoundedLabel,f as ControlPlaneUnavailableError,X as ConversationBackhauls,F as ConversationCapacityError,v as DEFAULT_PORT,I as EDGE_IDENTITY_PORT,A as EDGE_KEY_FINGERPRINT_HEADER,p as EDGE_KEY_ID_HEADER,i as InferenceMetrics,Y as LEDGER_FUNCTION_PATH,b as LEDGER_WRITE_TIMEOUT_MS,V as LedgerClient,h as LedgerDuplicateError,k as LedgerSurfaceError,g as MAX_CACHED_KEYS,G as MAX_CONVERSATIONS,U as MAX_CONVERSATION_HANDLES,n as MAX_MODEL_LABELS,_ as MAX_ORG_LABELS,H as MAX_TENANTS,o as METRICS_PATH,r as METRICS_PORT,E as NO_MODEL_LABEL,c as ORG_BINDING_TTL_MS,t as OTHER_LABEL,x as OrgResolver,d as ProxyAuthError,W as READINESS_TIMEOUT_MS,j as READINESS_TTL_MS,m as SERVE_FUNCTION,S as TIER_DOMAIN,u as TenantRegistry,l as bearerFrom,L as bearerTokenOf,M as createEdgeIdentityServer,q as createHostedProxy,s as createMetricsServer,C as edgeBucketId,D as edgeTierFingerprint,a as laneOf,K as parseLedgerRecorded,B as resolveHostedConfig,T as statusClassOf,P as tenantSubject};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var z=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var ee=(e,t)=>{for(var n in t)h(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of K(t))!Z.call(e,o)&&o!==n&&h(e,o,{get:()=>t[o],enumerable:!(r=Q(t,o))||r.enumerable});return e};var v=(e,t,n)=>(n=e!=null?z(X(e)):{},x(t||!e||!e.__esModule?h(n,"default",{value:e,enumerable:!0}):n,e)),te=e=>x(h({},"__esModule",{value:!0}),e);var le={};ee(le,{RT_VIDEO_OUT_STREAM:()=>w,SUPPORTED_REALTIME_CLIENT_EVENTS:()=>A,SUPPORTED_RESPONSES_EVENTS:()=>T,UrunRealtime:()=>k,UrunResponses:()=>_,VIDEO_OUT_DEFAULT_CODEC:()=>b,VIDEO_OUT_FRAMING:()=>R,VIDEO_OUT_WS_FRAMING:()=>W,consumeVideoOut:()=>q,decodeVideoOutRecord:()=>E,encodeVideoOutRecord:()=>$,isSupportedClientEvent:()=>F,isSupportedResponsesEvent:()=>j,listModels:()=>B,negotiateSessionVideoOutQuic:()=>N,nodeAudioBackend:()=>P,openSessionVideoOutLane:()=>H,toErrorEvent:()=>m,weriftAudioBackend:()=>U});module.exports=te(le);function I(e,t,n,r){let o=e.response??{},i={request_id:n,consumer_id:r,stream:!0,kind:"chat",messages:t};return typeof o.instructions=="string"&&(i.instructions=o.instructions),Array.isArray(o.modalities)&&(i.modalities=o.modalities),typeof o.temperature=="number"&&(i.temperature=o.temperature),typeof o.max_output_tokens=="number"&&(i.max_output_tokens=o.max_output_tokens),o.tools!==void 0&&(i.tools=o.tools),i}function L(e,t,n){let r={request_id:t,consumer_id:n,stream:!!e.stream,kind:"responses",input:e.input};return e.model&&(r.model=e.model),e.tools!==void 0&&(r.tools=e.tools),e.tool_choice!==void 0&&(r.tool_choice=e.tool_choice),typeof e.temperature=="number"&&(r.temperature=e.temperature),typeof e.max_output_tokens=="number"&&(r.max_output_tokens=e.max_output_tokens),typeof e.top_p=="number"&&(r.top_p=e.top_p),Array.isArray(e.stop)&&e.stop.length>0&&(r.stop=e.stop),typeof e.reasoning_effort=="string"&&(r.reasoning_effort=e.reasoning_effort),e.chat_template_kwargs!==void 0&&(r.chat_template_kwargs=e.chat_template_kwargs),r}function m(e){if(e instanceof Error)return{type:"error",error:{type:"urun_error",code:e.name||null,message:e.message}};if(e&&typeof e=="object"&&e.t==="error"){let t=e,n=t.body??{};return{type:"error",error:{type:"urun_error",code:t.code??null,message:n.message??"unknown error"}}}return{type:"error",error:{type:"urun_error",code:null,message:String(e)}}}var ne="llm-resp";async function*S(e,t){let n=`${ne}:${t}`,r=`resp_${t}`;yield{type:"response.created",response:{id:r,status:"in_progress"}};let o=new Map;for await(let i of e.stream(n).messages()){let d=i;if(d.t==="delta"){if(typeof d.delta=="string"&&(yield{type:"response.output_text.delta",item_id:r,delta:d.delta}),typeof d.reasoning=="string"&&(yield{type:"response.reasoning_text.delta",item_id:r,delta:d.reasoning}),Array.isArray(d.tool_calls))for(let u of d.tool_calls){let s=typeof u.index=="number"?u.index:0,a=o.get(s)??{};u.id&&(a.id=u.id),u.function?.name&&(a.name=u.function.name),o.set(s,a),yield{type:"response.function_call_arguments.delta",item_id:`fc_${t}_${s}`,tool_index:s,call_id:a.id,name:a.name,delta:u.function?.arguments??""}}}else if(d.t==="response"){yield{type:"response.completed",response:{id:r,status:"completed",...d.body}};return}else if(d.t==="error"){yield m(d);return}}}var re="llm",g=class{constructor(t){this.session=t;this.sessionTag=t.sessionId??globalThis.crypto.randomUUID()}session;sessionTag;get consumerId(){return this.session.consumerId}write(t){t.session_tag=this.sessionTag,this.session.doc(re).set({requests:{[t.request_id]:{payload:t,consumer_id:t.consumer_id,stream:t.stream}}})}sendResponses(t,n){let r=L(t,n,this.consumerId);return this.write(r),S(this.session,n)}sendResponseCreate(t,n,r){let o=I(t,n,r,this.consumerId);return this.write(o),S(this.session,r)}};var O=class{constructor(t,n){this.backend=t;this.opts=n}backend;opts;source=null;sink=null;outHandlers=new Set;async startOutbound(){return this.source=this.backend.createSource(),this.source.track}appendInputAudio(t){if(!this.source)throw new Error("startOutbound() not called");let n=Buffer.from(t,"base64"),r=Math.floor(n.byteLength/2),o=new Int16Array(r);for(let i=0;i<r;i++)o[i]=n.readInt16LE(i*2);this.source.onData(o)}async startInbound(t){if(t==null)throw new Error('startInbound: no downstream audio track \u2014 the runtime audio producer has not been consumed yet (session.stream("rt-audio-out").track is null)');this.sink=this.backend.createSink(t),this.sink.onframe=n=>{let r=Buffer.from(n.samples.buffer,n.samples.byteOffset,n.samples.byteLength).toString("base64");for(let o of this.outHandlers)o(r)}}onOutputAudio(t){return this.outHandlers.add(t),()=>this.outHandlers.delete(t)}};async function V(e,t,n=1e4){let r=new O(t,{sampleRate:24e3}),o=await r.startOutbound();await e.stream("rt-audio-in").attach(o);let i=await oe(e,n);return await r.startInbound(i),r}function oe(e,t){let n=e.stream("rt-audio-out");return n.track!=null?Promise.resolve(n.track):new Promise((r,o)=>{let i,d=setTimeout(()=>{i?.(),o(new Error(`enableSessionAudio: no downstream audio track within ${t}ms (runtime produced no voice OUT / SFU audio consumer never attached)`))},t),u=s=>{s!=null&&(clearTimeout(d),i?.(),r(s))};i=n.on?.("track",u),n.track!=null&&u(n.track)})}var se=24e3,y=480,ie=111;async function ae(){let e=await import("opusscript"),t=e.default??e;return new t(se,1,2048)}async function U(){let e=await import("werift"),t=await ae();return{createSource:()=>{let n=new e.MediaStreamTrack({kind:"audio"}),r=Math.random()*4294967295>>>0,o=Math.random()*65535&65535,i=Math.random()*4294967295>>>0,d=new Int16Array(0);return{track:n,onData:u=>{let s=new Int16Array(d.length+u.length);s.set(d,0),s.set(u,d.length);let a=0;for(;s.length-a>=y;){let c=s.subarray(a,a+y);a+=y;let l=Buffer.from(c.buffer,c.byteOffset,c.byteLength),Y=t.encode(l,y);o=o+1&65535,i=i+y>>>0;let G=new e.RtpHeader({version:2,payloadType:ie,sequenceNumber:o,timestamp:i,ssrc:r,marker:!1}),J=new e.RtpPacket(G,Y);n.writeRtp(J)}d=s.slice(a)}}},createSink:n=>{let r={onframe:null};return n.onReceiveRtp.subscribe(i=>{let d;try{d=t.decode(i.payload)}catch{return}let u=new Int16Array(d.length/2);for(let s=0;s<u.length;s++)u[s]=d.readInt16LE(s*2);r.onframe?.({samples:u})}),r}}}async function P(){let e=await import("@roamhq/wrtc");return{createSource:()=>{let t=new e.nonstandard.RTCAudioSource;return{track:t.createTrack(),onData:r=>t.onData({samples:r,sampleRate:24e3})}},createSink:t=>{let n={onframe:null},r=new e.nonstandard.RTCAudioSink(t);return r.ondata=o=>{n.onframe?.(o)},n}}}var D=0;function de(){return D+=1,`rt_${Date.now().toString(36)}_${D.toString(36)}`}var k=class{constructor(t,n={}){this.session=t;this.opts=n;this.transport=new g(t)}session;opts;transport;handlers=new Set;conversation=[];active=null;audio=null;currentRequestId=null;async enableAudio(){if(!this.opts.audioBackend)throw new Error("audioBackend required for audio");this.audio=await V(this.session,this.opts.audioBackend),this.audio.onOutputAudio(t=>this.emit({type:"response.audio.delta",delta:t}))}on(t,n){return this.handlers.add(n),()=>this.handlers.delete(n)}emit(t){for(let n of this.handlers)n(t)}send(t){switch(t.type){case"conversation.item.create":{let n=(t.item?.content??[]).map(r=>r.text??"").join("");this.conversation.push({role:t.item?.role??"user",content:n});return}case"response.create":{let n=de();this.currentRequestId=n;let r=this.transport.sendResponseCreate({type:"response.create",response:t.response},this.conversation,n);this.active=(async()=>{try{for await(let o of r)this.emit(o)}catch(o){this.emit(m(o))}})();return}case"input_audio_buffer.append":this.audio?.appendInputAudio(t.audio);return;case"input_audio_buffer.commit":case"input_audio_buffer.clear":return;case"response.cancel":return;default:return}}async drain(){this.active&&await this.active}};var C=0;function ue(){return C+=1,`req_${Date.now().toString(36)}_${C.toString(36)}`}var _=class{transport;constructor(t){this.transport=new g(t)}responses={create:async t=>{let n=ue(),r=this.transport.sendResponses(t,n);return Object.assign((async function*(){yield*r})(),{requestId:n})}}};async function ce(e){let n=await(e.fetchImpl??fetch)(`${e.catalogUrl}/model_catalog?select=model_id,variant,gpu_spec,engine,task,description,size_gb,hf_repo,engine_args,updated_at`,{headers:{apikey:e.anonKey,Authorization:`Bearer ${e.anonKey}`}});if(!n.ok)throw new Error(`model_catalog fetch failed: ${n.status}`);return await n.json()}async function B(e){return{object:"list",data:(await ce(e)).map(n=>({id:`${n.model_id}:${n.variant}`,object:"model",created:0,owned_by:"urun"}))}}var f=require("@urun-sh/core"),w="rt-video-out",R="urun.videoOut.v1",b="h264";function M(e,t){if(!Number.isInteger(e.seq)||e.seq<0)throw new Error(`${t}: header seq must be a non-negative integer (got ${e.seq})`);if(!Number.isInteger(e.ptsUs))throw new Error(`${t}: header ptsUs must be an integer microsecond timestamp (got ${e.ptsUs})`);if(typeof e.codec!="string"||e.codec.length===0)throw new Error(`${t}: header codec must be a non-empty string`);if(typeof e.key!="boolean")throw new Error(`${t}: header key must be a boolean`)}function $(e,t){if(M(e,"encodeVideoOutRecord"),t.byteLength===0)throw new Error("encodeVideoOutRecord: refusing to encode an empty access unit");let n=new TextEncoder().encode(JSON.stringify({v:1,seq:e.seq,ptsUs:e.ptsUs,codec:e.codec,key:e.key}));if(n.byteLength>65535)throw new Error(`encodeVideoOutRecord: header JSON is ${n.byteLength} bytes \u2014 over the u16 length prefix`);let r=new Uint8Array(2+n.byteLength+t.byteLength);return r[0]=n.byteLength&255,r[1]=n.byteLength>>8,r.set(n,2),r.set(t,2+n.byteLength),r}function E(e){if(e.byteLength<2)throw new Error(`decodeVideoOutRecord: truncated record (${e.byteLength} byte(s), no header length)`);let t=e[0]|e[1]<<8;if(e.byteLength<2+t)throw new Error(`decodeVideoOutRecord: truncated record (header says ${t} bytes, ${e.byteLength-2} present)`);let n;try{n=JSON.parse(new TextDecoder().decode(e.subarray(2,2+t)))}catch(d){throw new Error(`decodeVideoOutRecord: header is not valid JSON (${String(d)})`)}let r=n;if(r===null||typeof r!="object"||r.v!==1)throw new Error(`decodeVideoOutRecord: header is not spec v1 (v=${JSON.stringify(r?.v)}) \u2014 a newer producer must be met with a newer consumer, never silently misread`);let o=r;M(o,"decodeVideoOutRecord");let i=e.subarray(2+t);if(i.byteLength===0)throw new Error("decodeVideoOutRecord: empty access unit \u2014 a record with no AU bytes is a producer bug");return{header:o,au:i.slice()}}async function N(e){let t=e.wtDataEndpoint;if(typeof t!="function")throw new Error("negotiateSessionVideoOutQuic: the core session exposes no wtDataEndpoint() \u2014 the \xA75-over-QUIC dial seam (urun-infra#1608 TransportOfferResponse.webtransport, offered with wtData: true) is required for the video OUT lane; there is no WS fallback");let n=await t.call(e),r=n.sessionId??e.sessionId;if(typeof r!="string"||r.length===0)throw new Error("negotiateSessionVideoOutQuic: no session id \u2014 the WT hello requires one and neither the negotiated endpoint nor the core session carries it");return{transport:"webtransport",url:n.url,certHashes:n.certHashes,token:n.token,sessionId:r,stream:w,codec:b,framing:R}}var W="urun.videoOut.v2-ws";function H(e){let t=e.stream(w);if(typeof t.messages!="function")throw new Error(`openSessionVideoOutLane: session.stream('${w}') has no messages() \u2014 the named-DATA stream consume seam (@urun-sh/core SessionStream.messages, contract \xA75) is required for the video OUT lane`);let n=new Set,r=new Set,o=new Set,i=s=>{for(let a of r)a(s)},d=!1,u=async()=>{for await(let s of t.messages()){if(!(s instanceof Uint8Array)){i(new Error(`openSessionVideoOutLane: "${w}" delivered a non-BINARY \xA75 payload (${typeof s}) \u2014 spec v1 records ride BINARY envelopes only`));continue}let a;try{a=E(s)}catch(c){i(c instanceof Error?c:new Error(String(c)));continue}for(let c of n)c(a)}for(let s of o)s()};return{codec:b,onOutputFrame:s=>(n.add(s),d||(d=!0,u().catch(a=>i(a instanceof Error?a:new Error(String(a))))),()=>n.delete(s)),onLaneError:s=>(r.add(s),()=>r.delete(s)),onEnd:s=>(o.add(s),()=>o.delete(s))}}function pe(e){if(e.length%2!==0||/[^0-9a-fA-F]/.test(e))throw new Error(`consumeVideoOut: certHashes entry is not hex sha-256 (${JSON.stringify(e)})`);let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}async function q(e,t,n){let r=n??(typeof globalThis.WebTransport=="function"?(a,c)=>new globalThis.WebTransport(a,c):void 0);if(!r)throw new Error("consumeVideoOut: no WebTransport implementation \u2014 this platform has no globalThis.WebTransport; inject a connect factory (the third argument)");let o=r(e.url,{serverCertificateHashes:e.certHashes.map(a=>({algorithm:"sha-256",value:pe(a)}))});await o.ready;let i=await o.createBidirectionalStream();await i.writable.getWriter().write((0,f.encodeWtControlFrame)({t:"hello",token:e.token,sessionId:e.sessionId}));let d=i.readable.getReader(),u=new f.WtControlDecoder,s=!1;for(;!s;){let{value:a,done:c}=await d.read();if(c)throw new Error("consumeVideoOut: gateway closed the control stream before hello-ack");if(a)for(let l of u.push(a)){if(l.t==="hello-ack"){s=!0;break}throw new Error(`consumeVideoOut: gateway rejected hello (got ${JSON.stringify(l.t)} before hello-ack)`)}}await(0,f.consumeWtDataStreams)(o.incomingUnidirectionalStreams,{onData:(a,c)=>{if(a===e.stream){if(c===f.STREAM_END){t.onEnd?.();return}if(!(c instanceof Uint8Array)){t.onLaneError(new Error(`consumeVideoOut: "${e.stream}" delivered a non-BINARY \xA75 payload (${typeof c}) \u2014 spec v1 records ride BINARY envelopes only`));return}try{t.onFrame(E(c))}catch(l){t.onLaneError(l instanceof Error?l:new Error(String(l)))}}},onLaneError:a=>t.onLaneError(a)})}var A=["session.update","conversation.item.create","response.create","response.cancel","input_audio_buffer.append","input_audio_buffer.commit","input_audio_buffer.clear"],T=["response.created","response.output_text.delta","response.output_item.added","response.function_call_arguments.delta","response.image_generation_call.partial_image","response.completed","error"];function F(e){return A.includes(e)}function j(e){return T.includes(e)}0&&(module.exports={RT_VIDEO_OUT_STREAM,SUPPORTED_REALTIME_CLIENT_EVENTS,SUPPORTED_RESPONSES_EVENTS,UrunRealtime,UrunResponses,VIDEO_OUT_DEFAULT_CODEC,VIDEO_OUT_FRAMING,VIDEO_OUT_WS_FRAMING,consumeVideoOut,decodeVideoOutRecord,encodeVideoOutRecord,isSupportedClientEvent,isSupportedResponsesEvent,listModels,negotiateSessionVideoOutQuic,nodeAudioBackend,openSessionVideoOutLane,toErrorEvent,weriftAudioBackend});
|
|
1
|
+
"use strict";var Q=Object.create;var h=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(e,t)=>{for(var n in t)h(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of X(t))!ee.call(e,o)&&o!==n&&h(e,o,{get:()=>t[o],enumerable:!(r=K(t,o))||r.enumerable});return e};var v=(e,t,n)=>(n=e!=null?Q(Z(e)):{},x(t||!e||!e.__esModule?h(n,"default",{value:e,enumerable:!0}):n,e)),ne=e=>x(h({},"__esModule",{value:!0}),e);var fe={};te(fe,{RT_VIDEO_OUT_STREAM:()=>y,SUPPORTED_REALTIME_CLIENT_EVENTS:()=>A,SUPPORTED_RESPONSES_EVENTS:()=>T,UrunRealtime:()=>_,UrunResponses:()=>k,VIDEO_OUT_DEFAULT_CODEC:()=>b,VIDEO_OUT_FRAMING:()=>R,VIDEO_OUT_WS_FRAMING:()=>H,consumeVideoOut:()=>F,decodeVideoOutRecord:()=>E,encodeVideoOutRecord:()=>N,isSupportedClientEvent:()=>j,isSupportedResponsesEvent:()=>J,listModels:()=>B,negotiateSessionVideoOutQuic:()=>W,nodeAudioBackend:()=>D,openSessionVideoOutLane:()=>q,toErrorEvent:()=>m,weriftAudioBackend:()=>P});module.exports=ne(fe);function I(e,t,n,r){let o=e.response??{},i={request_id:n,consumer_id:r,stream:!0,kind:"chat",messages:t};return typeof o.instructions=="string"&&(i.instructions=o.instructions),Array.isArray(o.modalities)&&(i.modalities=o.modalities),typeof o.temperature=="number"&&(i.temperature=o.temperature),typeof o.max_output_tokens=="number"&&(i.max_output_tokens=o.max_output_tokens),o.tools!==void 0&&(i.tools=o.tools),i}function L(e,t,n){let r={request_id:t,consumer_id:n,stream:!!e.stream,kind:"responses",input:e.input};return e.model&&(r.model=e.model),e.tools!==void 0&&(r.tools=e.tools),e.tool_choice!==void 0&&(r.tool_choice=e.tool_choice),typeof e.temperature=="number"&&(r.temperature=e.temperature),typeof e.max_output_tokens=="number"&&(r.max_output_tokens=e.max_output_tokens),typeof e.top_p=="number"&&(r.top_p=e.top_p),Array.isArray(e.stop)&&e.stop.length>0&&(r.stop=e.stop),typeof e.reasoning_effort=="string"&&(r.reasoning_effort=e.reasoning_effort),e.chat_template_kwargs!==void 0&&(r.chat_template_kwargs=e.chat_template_kwargs),e.response_format!==void 0&&(r.response_format=e.response_format),r}function m(e){if(e instanceof Error)return{type:"error",error:{type:"urun_error",code:e.name||null,message:e.message}};if(e&&typeof e=="object"&&e.t==="error"){let t=e,n=t.body??{},r=n.error,o=r?.message??n.message??`unreadable serve error body: ${JSON.stringify(t.body??null)}`;return{type:"error",error:{type:r?.type??"urun_error",code:t.code??r?.code??null,message:o}}}return{type:"error",error:{type:"urun_error",code:null,message:String(e)}}}var re="llm-resp";async function*S(e,t){let n=`${re}:${t}`,r=`resp_${t}`;yield{type:"response.created",response:{id:r,status:"in_progress"}};let o=new Map;for await(let i of e.stream(n).messages()){let d=i;if(d.t==="delta"){if(typeof d.delta=="string"&&(yield{type:"response.output_text.delta",item_id:r,delta:d.delta}),typeof d.reasoning=="string"&&(yield{type:"response.reasoning_text.delta",item_id:r,delta:d.reasoning}),Array.isArray(d.tool_calls))for(let u of d.tool_calls){let s=typeof u.index=="number"?u.index:0,a=o.get(s)??{};u.id&&(a.id=u.id),u.function?.name&&(a.name=u.function.name),o.set(s,a),yield{type:"response.function_call_arguments.delta",item_id:`fc_${t}_${s}`,tool_index:s,call_id:a.id,name:a.name,delta:u.function?.arguments??""}}}else if(d.t==="response"){yield{type:"response.completed",response:{id:r,status:"completed",...d.body}};return}else if(d.t==="error"){yield m(d);return}}}var oe="llm",g=class{constructor(t){this.session=t;this.sessionTag=t.sessionId??globalThis.crypto.randomUUID()}session;sessionTag;get consumerId(){return this.session.consumerId}write(t){t.session_tag=this.sessionTag,this.session.doc(oe).set({requests:{[t.request_id]:{payload:t,consumer_id:t.consumer_id,stream:t.stream}}})}sendResponses(t,n){let r=L(t,n,this.consumerId);return this.write(r),S(this.session,n)}sendResponseCreate(t,n,r){let o=I(t,n,r,this.consumerId);return this.write(o),S(this.session,r)}};var V="audio",O=class{constructor(t,n){this.backend=t;this.opts=n}backend;opts;source=null;sink=null;outHandlers=new Set;async startOutbound(){return this.source=this.backend.createSource(),this.source.track}appendInputAudio(t){if(!this.source)throw new Error("startOutbound() not called");let n=Buffer.from(t,"base64"),r=Math.floor(n.byteLength/2),o=new Int16Array(r);for(let i=0;i<r;i++)o[i]=n.readInt16LE(i*2);this.source.onData(o)}async startInbound(t){if(t==null)throw new Error('startInbound: no downstream audio track \u2014 the runtime audio producer has not been consumed yet (session.stream("audio").track is null)');this.sink=this.backend.createSink(t),this.sink.onframe=n=>{let r=Buffer.from(n.samples.buffer,n.samples.byteOffset,n.samples.byteLength).toString("base64");for(let o of this.outHandlers)o(r)}}onOutputAudio(t){return this.outHandlers.add(t),()=>this.outHandlers.delete(t)}};async function U(e,t,n=1e4){let r=new O(t,{sampleRate:24e3}),o=await r.startOutbound();await e.stream(V).attach(o);let i=await se(e,n);return await r.startInbound(i),r}function se(e,t){let n=e.stream(V);return n.track!=null?Promise.resolve(n.track):new Promise((r,o)=>{let i,d=setTimeout(()=>{i?.(),o(new Error(`enableSessionAudio: no downstream audio track within ${t}ms (runtime produced no voice OUT / SFU audio consumer never attached)`))},t),u=s=>{s!=null&&(clearTimeout(d),i?.(),r(s))};i=n.on?.("track",u),n.track!=null&&u(n.track)})}var ie=24e3,w=480,ae=111;async function de(){let e=await import("opusscript"),t=e.default??e;return new t(ie,1,2048)}async function P(){let e=await import("werift"),t=await de();return{createSource:()=>{let n=new e.MediaStreamTrack({kind:"audio"}),r=Math.random()*4294967295>>>0,o=Math.random()*65535&65535,i=Math.random()*4294967295>>>0,d=new Int16Array(0);return{track:n,onData:u=>{let s=new Int16Array(d.length+u.length);s.set(d,0),s.set(u,d.length);let a=0;for(;s.length-a>=w;){let c=s.subarray(a,a+w);a+=w;let l=Buffer.from(c.buffer,c.byteOffset,c.byteLength),Y=t.encode(l,w);o=o+1&65535,i=i+w>>>0;let G=new e.RtpHeader({version:2,payloadType:ae,sequenceNumber:o,timestamp:i,ssrc:r,marker:!1}),z=new e.RtpPacket(G,Y);n.writeRtp(z)}d=s.slice(a)}}},createSink:n=>{let r={onframe:null};return n.onReceiveRtp.subscribe(i=>{let d;try{d=t.decode(i.payload)}catch{return}let u=new Int16Array(d.length/2);for(let s=0;s<u.length;s++)u[s]=d.readInt16LE(s*2);r.onframe?.({samples:u})}),r}}}async function D(){let e=await import("@roamhq/wrtc");return{createSource:()=>{let t=new e.nonstandard.RTCAudioSource;return{track:t.createTrack(),onData:r=>t.onData({samples:r,sampleRate:24e3})}},createSink:t=>{let n={onframe:null},r=new e.nonstandard.RTCAudioSink(t);return r.ondata=o=>{n.onframe?.(o)},n}}}var C=0;function ue(){return C+=1,`rt_${Date.now().toString(36)}_${C.toString(36)}`}var _=class{constructor(t,n={}){this.session=t;this.opts=n;this.transport=new g(t)}session;opts;transport;handlers=new Set;conversation=[];active=null;audio=null;currentRequestId=null;async enableAudio(){if(!this.opts.audioBackend)throw new Error("audioBackend required for audio");this.audio=await U(this.session,this.opts.audioBackend),this.audio.onOutputAudio(t=>this.emit({type:"response.audio.delta",delta:t}))}on(t,n){return this.handlers.add(n),()=>this.handlers.delete(n)}emit(t){for(let n of this.handlers)n(t)}send(t){switch(t.type){case"conversation.item.create":{let n=(t.item?.content??[]).map(r=>r.text??"").join("");this.conversation.push({role:t.item?.role??"user",content:n});return}case"response.create":{let n=ue();this.currentRequestId=n;let r=this.transport.sendResponseCreate({type:"response.create",response:t.response},this.conversation,n);this.active=(async()=>{try{for await(let o of r)this.emit(o)}catch(o){this.emit(m(o))}})();return}case"input_audio_buffer.append":this.audio?.appendInputAudio(t.audio);return;case"input_audio_buffer.commit":case"input_audio_buffer.clear":return;case"response.cancel":return;default:return}}async drain(){this.active&&await this.active}};var M=0;function ce(){return M+=1,`req_${Date.now().toString(36)}_${M.toString(36)}`}var k=class{transport;constructor(t){this.transport=new g(t)}responses={create:async t=>{let n=ce(),r=this.transport.sendResponses(t,n);return Object.assign((async function*(){yield*r})(),{requestId:n})}}};async function pe(e){let n=await(e.fetchImpl??fetch)(`${e.catalogUrl}/model_catalog?select=model_id,variant,gpu_spec,engine,task,description,size_gb,hf_repo,engine_args,updated_at`,{headers:{apikey:e.anonKey,Authorization:`Bearer ${e.anonKey}`}});if(!n.ok)throw new Error(`model_catalog fetch failed: ${n.status}`);return await n.json()}async function B(e){return{object:"list",data:(await pe(e)).map(n=>({id:`${n.model_id}:${n.variant}`,object:"model",created:0,owned_by:"urun"}))}}var f=require("@urun-sh/core"),y="rt-video-out",R="urun.videoOut.v1",b="h264";function $(e,t){if(!Number.isInteger(e.seq)||e.seq<0)throw new Error(`${t}: header seq must be a non-negative integer (got ${e.seq})`);if(!Number.isInteger(e.ptsUs))throw new Error(`${t}: header ptsUs must be an integer microsecond timestamp (got ${e.ptsUs})`);if(typeof e.codec!="string"||e.codec.length===0)throw new Error(`${t}: header codec must be a non-empty string`);if(typeof e.key!="boolean")throw new Error(`${t}: header key must be a boolean`)}function N(e,t){if($(e,"encodeVideoOutRecord"),t.byteLength===0)throw new Error("encodeVideoOutRecord: refusing to encode an empty access unit");let n=new TextEncoder().encode(JSON.stringify({v:1,seq:e.seq,ptsUs:e.ptsUs,codec:e.codec,key:e.key}));if(n.byteLength>65535)throw new Error(`encodeVideoOutRecord: header JSON is ${n.byteLength} bytes \u2014 over the u16 length prefix`);let r=new Uint8Array(2+n.byteLength+t.byteLength);return r[0]=n.byteLength&255,r[1]=n.byteLength>>8,r.set(n,2),r.set(t,2+n.byteLength),r}function E(e){if(e.byteLength<2)throw new Error(`decodeVideoOutRecord: truncated record (${e.byteLength} byte(s), no header length)`);let t=e[0]|e[1]<<8;if(e.byteLength<2+t)throw new Error(`decodeVideoOutRecord: truncated record (header says ${t} bytes, ${e.byteLength-2} present)`);let n;try{n=JSON.parse(new TextDecoder().decode(e.subarray(2,2+t)))}catch(d){throw new Error(`decodeVideoOutRecord: header is not valid JSON (${String(d)})`)}let r=n;if(r===null||typeof r!="object"||r.v!==1)throw new Error(`decodeVideoOutRecord: header is not spec v1 (v=${JSON.stringify(r?.v)}) \u2014 a newer producer must be met with a newer consumer, never silently misread`);let o=r;$(o,"decodeVideoOutRecord");let i=e.subarray(2+t);if(i.byteLength===0)throw new Error("decodeVideoOutRecord: empty access unit \u2014 a record with no AU bytes is a producer bug");return{header:o,au:i.slice()}}async function W(e){let t=e.wtDataEndpoint;if(typeof t!="function")throw new Error("negotiateSessionVideoOutQuic: the core session exposes no wtDataEndpoint() \u2014 the \xA75-over-QUIC dial seam (urun-infra#1608 TransportOfferResponse.webtransport, offered with wtData: true) is required for the video OUT lane; there is no WS fallback");let n=await t.call(e),r=n.sessionId??e.sessionId;if(typeof r!="string"||r.length===0)throw new Error("negotiateSessionVideoOutQuic: no session id \u2014 the WT hello requires one and neither the negotiated endpoint nor the core session carries it");return{transport:"webtransport",url:n.url,certHashes:n.certHashes,token:n.token,sessionId:r,stream:y,codec:b,framing:R}}var H="urun.videoOut.v2-ws";function q(e){let t=e.stream(y);if(typeof t.messages!="function")throw new Error(`openSessionVideoOutLane: session.stream('${y}') has no messages() \u2014 the named-DATA stream consume seam (@urun-sh/core SessionStream.messages, contract \xA75) is required for the video OUT lane`);let n=new Set,r=new Set,o=new Set,i=s=>{for(let a of r)a(s)},d=!1,u=async()=>{for await(let s of t.messages()){if(!(s instanceof Uint8Array)){i(new Error(`openSessionVideoOutLane: "${y}" delivered a non-BINARY \xA75 payload (${typeof s}) \u2014 spec v1 records ride BINARY envelopes only`));continue}let a;try{a=E(s)}catch(c){i(c instanceof Error?c:new Error(String(c)));continue}for(let c of n)c(a)}for(let s of o)s()};return{codec:b,onOutputFrame:s=>(n.add(s),d||(d=!0,u().catch(a=>i(a instanceof Error?a:new Error(String(a))))),()=>n.delete(s)),onLaneError:s=>(r.add(s),()=>r.delete(s)),onEnd:s=>(o.add(s),()=>o.delete(s))}}function le(e){if(e.length%2!==0||/[^0-9a-fA-F]/.test(e))throw new Error(`consumeVideoOut: certHashes entry is not hex sha-256 (${JSON.stringify(e)})`);let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}async function F(e,t,n){let r=n??(typeof globalThis.WebTransport=="function"?(a,c)=>new globalThis.WebTransport(a,c):void 0);if(!r)throw new Error("consumeVideoOut: no WebTransport implementation \u2014 this platform has no globalThis.WebTransport; inject a connect factory (the third argument)");let o=r(e.url,{serverCertificateHashes:e.certHashes.map(a=>({algorithm:"sha-256",value:le(a)}))});await o.ready;let i=await o.createBidirectionalStream();await i.writable.getWriter().write((0,f.encodeWtControlFrame)({t:"hello",token:e.token,sessionId:e.sessionId}));let d=i.readable.getReader(),u=new f.WtControlDecoder,s=!1;for(;!s;){let{value:a,done:c}=await d.read();if(c)throw new Error("consumeVideoOut: gateway closed the control stream before hello-ack");if(a)for(let l of u.push(a)){if(l.t==="hello-ack"){s=!0;break}throw new Error(`consumeVideoOut: gateway rejected hello (got ${JSON.stringify(l.t)} before hello-ack)`)}}await(0,f.consumeWtDataStreams)(o.incomingUnidirectionalStreams,{onData:(a,c)=>{if(a===e.stream){if(c===f.STREAM_END){t.onEnd?.();return}if(!(c instanceof Uint8Array)){t.onLaneError(new Error(`consumeVideoOut: "${e.stream}" delivered a non-BINARY \xA75 payload (${typeof c}) \u2014 spec v1 records ride BINARY envelopes only`));return}try{t.onFrame(E(c))}catch(l){t.onLaneError(l instanceof Error?l:new Error(String(l)))}}},onLaneError:a=>t.onLaneError(a)})}var A=["session.update","conversation.item.create","response.create","response.cancel","input_audio_buffer.append","input_audio_buffer.commit","input_audio_buffer.clear"],T=["response.created","response.output_text.delta","response.output_item.added","response.function_call_arguments.delta","response.image_generation_call.partial_image","response.completed","error"];function j(e){return A.includes(e)}function J(e){return T.includes(e)}0&&(module.exports={RT_VIDEO_OUT_STREAM,SUPPORTED_REALTIME_CLIENT_EVENTS,SUPPORTED_RESPONSES_EVENTS,UrunRealtime,UrunResponses,VIDEO_OUT_DEFAULT_CODEC,VIDEO_OUT_FRAMING,VIDEO_OUT_WS_FRAMING,consumeVideoOut,decodeVideoOutRecord,encodeVideoOutRecord,isSupportedClientEvent,isSupportedResponsesEvent,listModels,negotiateSessionVideoOutQuic,nodeAudioBackend,openSessionVideoOutLane,toErrorEvent,weriftAudioBackend});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { b as UrunSessionLike, L as LaneMessage } from './types-lsVTbNcH.cjs';
|
|
2
|
-
import { A as AudioBackend } from './video-out-
|
|
3
|
-
export { b as AudioSink, c as AudioSource, d as RT_VIDEO_OUT_STREAM, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-
|
|
4
|
-
export { U as UrunResponses } from './ResponsesClient-
|
|
5
|
-
export { M as ModelList, a as ModelObject, l as listModels } from './models-
|
|
2
|
+
import { A as AudioBackend } from './video-out-CCksIcj8.cjs';
|
|
3
|
+
export { b as AudioSink, c as AudioSource, d as RT_VIDEO_OUT_STREAM, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-CCksIcj8.cjs';
|
|
4
|
+
export { U as UrunResponses } from './ResponsesClient-DjZWjlFH.cjs';
|
|
5
|
+
export { M as ModelList, a as ModelObject, l as listModels } from './models-DUdx_Y6X.cjs';
|
|
6
6
|
export { RealtimeClientEvent, RealtimeServerEvent } from 'openai/resources/beta/realtime/realtime';
|
|
7
7
|
export { ResponseStreamEvent } from 'openai/resources/responses/responses';
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { b as UrunSessionLike, L as LaneMessage } from './types-lsVTbNcH.js';
|
|
2
|
-
import { A as AudioBackend } from './video-out-
|
|
3
|
-
export { b as AudioSink, c as AudioSource, d as RT_VIDEO_OUT_STREAM, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-
|
|
4
|
-
export { U as UrunResponses } from './ResponsesClient-
|
|
5
|
-
export { M as ModelList, a as ModelObject, l as listModels } from './models-
|
|
2
|
+
import { A as AudioBackend } from './video-out-IGQ4YQ-c.js';
|
|
3
|
+
export { b as AudioSink, c as AudioSource, d as RT_VIDEO_OUT_STREAM, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-IGQ4YQ-c.js';
|
|
4
|
+
export { U as UrunResponses } from './ResponsesClient-BE3-hx3m.js';
|
|
5
|
+
export { M as ModelList, a as ModelObject, l as listModels } from './models-DUdx_Y6X.js';
|
|
6
6
|
export { RealtimeClientEvent, RealtimeServerEvent } from 'openai/resources/beta/realtime/realtime';
|
|
7
7
|
export { ResponseStreamEvent } from 'openai/resources/responses/responses';
|
|
8
8
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as S}from"./chunk-
|
|
1
|
+
import{b as S}from"./chunk-5HKWNK3O.js";import{a as _}from"./chunk-FP4RSAIE.js";import{c as p,g as v,h as f,i as R,j as y,k as O,l as h,m as x,n as g,o as k,p as A,q as T}from"./chunk-BSHT6RZZ.js";import{c as s,e as d}from"./chunk-2T2YYBVX.js";import{c as o}from"./chunk-5CCJUNH7.js";o();o();var u=0;function V(){return u+=1,`rt_${Date.now().toString(36)}_${u.toString(36)}`}var a=class{constructor(e,t={}){this.session=e;this.opts=t;this.transport=new d(e)}session;opts;transport;handlers=new Set;conversation=[];active=null;audio=null;currentRequestId=null;async enableAudio(){if(!this.opts.audioBackend)throw new Error("audioBackend required for audio");this.audio=await p(this.session,this.opts.audioBackend),this.audio.onOutputAudio(e=>this.emit({type:"response.audio.delta",delta:e}))}on(e,t){return this.handlers.add(t),()=>this.handlers.delete(t)}emit(e){for(let t of this.handlers)t(e)}send(e){switch(e.type){case"conversation.item.create":{let t=(e.item?.content??[]).map(n=>n.text??"").join("");this.conversation.push({role:e.item?.role??"user",content:t});return}case"response.create":{let t=V();this.currentRequestId=t;let n=this.transport.sendResponseCreate({type:"response.create",response:e.response},this.conversation,t);this.active=(async()=>{try{for await(let i of n)this.emit(i)}catch(i){this.emit(s(i))}})();return}case"input_audio_buffer.append":this.audio?.appendInputAudio(e.audio);return;case"input_audio_buffer.commit":case"input_audio_buffer.clear":return;case"response.cancel":return;default:return}}async drain(){this.active&&await this.active}};o();var m=["session.update","conversation.item.create","response.create","response.cancel","input_audio_buffer.append","input_audio_buffer.commit","input_audio_buffer.clear"],E=["response.created","response.output_text.delta","response.output_item.added","response.function_call_arguments.delta","response.image_generation_call.partial_image","response.completed","error"];function w(r){return m.includes(r)}function I(r){return E.includes(r)}export{R as RT_VIDEO_OUT_STREAM,m as SUPPORTED_REALTIME_CLIENT_EVENTS,E as SUPPORTED_RESPONSES_EVENTS,a as UrunRealtime,_ as UrunResponses,O as VIDEO_OUT_DEFAULT_CODEC,y as VIDEO_OUT_FRAMING,k as VIDEO_OUT_WS_FRAMING,T as consumeVideoOut,x as decodeVideoOutRecord,h as encodeVideoOutRecord,w as isSupportedClientEvent,I as isSupportedResponsesEvent,S as listModels,g as negotiateSessionVideoOutQuic,f as nodeAudioBackend,A as openSessionVideoOutLane,s as toErrorEvent,v as weriftAudioBackend};
|
|
@@ -23,7 +23,7 @@ interface CatalogRow {
|
|
|
23
23
|
description?: string | null;
|
|
24
24
|
/** Weights size in GB. */
|
|
25
25
|
size_gb?: number | null;
|
|
26
|
-
/** Engine args jsonb — context_length (
|
|
26
|
+
/** Engine args jsonb — the context window lives here: `context_length` (sglang) or `max_model_len` (vLLM). */
|
|
27
27
|
engine_args?: Record<string, unknown> | null;
|
|
28
28
|
/** Last catalog reseed that touched this row (ISO 8601). */
|
|
29
29
|
updated_at?: string | null;
|