@sixb/server 0.1.22 → 0.1.24
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.js +59 -15
- package/dist/index.js.map +7 -7
- package/dist/openapi/components.d.ts +15 -1
- package/dist/openapi/components.d.ts.map +1 -1
- package/dist/routes/model-generations.d.ts +4 -14
- package/dist/routes/model-generations.d.ts.map +1 -1
- package/dist/routes/models.d.ts +3 -0
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/schemas/models.d.ts +43 -3
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/openapi/components.ts +20 -0
- package/src/routes/model-generations.ts +55 -6
- package/src/routes/models.ts +3 -1
- package/src/schemas/models.ts +19 -2
- package/src/server.ts +3 -9
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import { setApiPublicOrigin } from "@sixb/core/internal/runtime";
|
|
|
10
10
|
import { checkPipelineMarkings, warmAppliedMarkings } from "@sixb/core/internal/security";
|
|
11
11
|
import { Elysia, ParseError } from "elysia";
|
|
12
12
|
import { websocket as elysiaWebSocket } from "elysia/ws";
|
|
13
|
-
import { zodToJsonSchema as zodToJsonSchema3 } from "zod-to-json-schema";
|
|
14
13
|
|
|
15
14
|
// src/auth/browser-origin.ts
|
|
16
15
|
class BrowserOriginError extends Error {
|
|
@@ -1451,6 +1450,9 @@ var ModelCatalogSchema = z7.object({
|
|
|
1451
1450
|
audio: z7.object({
|
|
1452
1451
|
speech: z7.array(SpeechModelSchema),
|
|
1453
1452
|
transcription: z7.array(TranscriptionModelSchema)
|
|
1453
|
+
}),
|
|
1454
|
+
capabilities: z7.object({
|
|
1455
|
+
run: z7.boolean()
|
|
1454
1456
|
})
|
|
1455
1457
|
});
|
|
1456
1458
|
var ModelReasoningLevelSchema = z7.enum(MODEL_REASONING_LEVELS);
|
|
@@ -1527,8 +1529,13 @@ var FileGenerationSchema = GenerationResultBase.extend({
|
|
|
1527
1529
|
files: z7.array(FileRefSchema),
|
|
1528
1530
|
warnings: z7.array(z7.string())
|
|
1529
1531
|
});
|
|
1532
|
+
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
1533
|
+
var InlineAudioSchema = z7.object({
|
|
1534
|
+
data: z7.string().min(1).regex(BASE64_PATTERN, "Invalid base64").refine((data) => data.length % 4 === 0, "Invalid base64"),
|
|
1535
|
+
mediaType: z7.string().min(1)
|
|
1536
|
+
});
|
|
1530
1537
|
var TranscriptionBodySchema = GenerationBodyBase.extend({
|
|
1531
|
-
audio: FileRefSchema
|
|
1538
|
+
audio: z7.union([FileRefSchema, InlineAudioSchema])
|
|
1532
1539
|
});
|
|
1533
1540
|
var TranscriptionSchema = GenerationResultBase.extend({
|
|
1534
1541
|
text: z7.string()
|
|
@@ -2191,6 +2198,17 @@ function openApiOverride(except) {
|
|
|
2191
2198
|
return name === undefined ? ignoreOverride2 : { $ref: `#/components/schemas/${name}` };
|
|
2192
2199
|
};
|
|
2193
2200
|
}
|
|
2201
|
+
function openApiJsonSchema(schema) {
|
|
2202
|
+
return zodToJsonSchema(schema, {
|
|
2203
|
+
$refStrategy: "none",
|
|
2204
|
+
target: "openApi3",
|
|
2205
|
+
override: openApiOverride()
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
function jsonRequestBody(schema) {
|
|
2209
|
+
const jsonSchema = openApiJsonSchema(schema);
|
|
2210
|
+
return { required: true, content: { "application/json": { schema: jsonSchema } } };
|
|
2211
|
+
}
|
|
2194
2212
|
var NamedOpenApiSchemas = Object.fromEntries(NAMED.map(([name, schema]) => [
|
|
2195
2213
|
name,
|
|
2196
2214
|
zodToJsonSchema(schema, {
|
|
@@ -10964,6 +10982,27 @@ function generationError(error, set) {
|
|
|
10964
10982
|
}
|
|
10965
10983
|
return handleRouteError(error, set);
|
|
10966
10984
|
}
|
|
10985
|
+
async function readTranscriptionBody(request) {
|
|
10986
|
+
const bytes = await readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES);
|
|
10987
|
+
let json;
|
|
10988
|
+
try {
|
|
10989
|
+
json = JSON.parse(new TextDecoder().decode(bytes));
|
|
10990
|
+
} catch {
|
|
10991
|
+
throw new TypeError("[SixbServer] Transcription request body must be JSON.");
|
|
10992
|
+
}
|
|
10993
|
+
const parsed = TranscriptionBodySchema.safeParse(json);
|
|
10994
|
+
if (!parsed.success) {
|
|
10995
|
+
const [issue] = parsed.error.issues;
|
|
10996
|
+
throw new TypeError(`[SixbServer] Invalid transcription request: ${issue?.path.join(".") || "body"}: ${issue?.message}`);
|
|
10997
|
+
}
|
|
10998
|
+
return parsed.data;
|
|
10999
|
+
}
|
|
11000
|
+
function transcriptionAudio(audio) {
|
|
11001
|
+
if ("data" in audio) {
|
|
11002
|
+
return { data: Buffer.from(audio.data, "base64"), mediaType: audio.mediaType };
|
|
11003
|
+
}
|
|
11004
|
+
return audio;
|
|
11005
|
+
}
|
|
10967
11006
|
var responses = {
|
|
10968
11007
|
400: ErrorResponseSchema,
|
|
10969
11008
|
403: ErrorResponseSchema,
|
|
@@ -11054,12 +11093,17 @@ function registerModelGenerationRoutes(app, host) {
|
|
|
11054
11093
|
response: { 200: FileGenerationSchema, ...responses },
|
|
11055
11094
|
detail: detail("generateSpeech", "Generate speech with a speech model")
|
|
11056
11095
|
}).post("/api/models/audio/transcriptions", async (context) => {
|
|
11057
|
-
const {
|
|
11096
|
+
const { request, set } = context;
|
|
11058
11097
|
try {
|
|
11059
11098
|
const sixb = requireRequestSixb(context);
|
|
11099
|
+
if (!sixb.models.canRun()) {
|
|
11100
|
+
set.status = 403;
|
|
11101
|
+
return { error: "[SixbServer] Transcribing audio requires can.run(project.models)." };
|
|
11102
|
+
}
|
|
11103
|
+
const body = await readTranscriptionBody(request);
|
|
11060
11104
|
const entry = selectBinding(catalog()?.audio?.transcription, "transcription", body.model);
|
|
11061
11105
|
const call = await sixb.models.audio.transcribe({
|
|
11062
|
-
audio: body.audio,
|
|
11106
|
+
audio: transcriptionAudio(body.audio),
|
|
11063
11107
|
model: entry.model,
|
|
11064
11108
|
signal: request.signal
|
|
11065
11109
|
});
|
|
@@ -11068,9 +11112,12 @@ function registerModelGenerationRoutes(app, host) {
|
|
|
11068
11112
|
return generationError(error, set);
|
|
11069
11113
|
}
|
|
11070
11114
|
}, {
|
|
11071
|
-
|
|
11072
|
-
response: { 200: TranscriptionSchema, ...responses },
|
|
11073
|
-
detail:
|
|
11115
|
+
parse: "none",
|
|
11116
|
+
response: { 200: TranscriptionSchema, 413: ErrorResponseSchema, ...responses },
|
|
11117
|
+
detail: {
|
|
11118
|
+
...detail("transcribeAudio", "Transcribe audio with a transcription model"),
|
|
11119
|
+
requestBody: jsonRequestBody(TranscriptionBodySchema)
|
|
11120
|
+
}
|
|
11074
11121
|
});
|
|
11075
11122
|
}
|
|
11076
11123
|
|
|
@@ -11240,7 +11287,7 @@ async function serializeTranscriptionModel(entry, defaultEntry) {
|
|
|
11240
11287
|
};
|
|
11241
11288
|
}
|
|
11242
11289
|
function registerModelRoutes(app, host) {
|
|
11243
|
-
return app.get("/api/models", async () => {
|
|
11290
|
+
return app.get("/api/models", async (context) => {
|
|
11244
11291
|
const models = host.definitions.models;
|
|
11245
11292
|
const language = models?.language;
|
|
11246
11293
|
const image = models?.image;
|
|
@@ -11253,7 +11300,8 @@ function registerModelRoutes(app, host) {
|
|
|
11253
11300
|
audio: {
|
|
11254
11301
|
speech: speech ? await Promise.all(speech.list().map((entry) => serializeSpeechModel(entry, speech.default))) : [],
|
|
11255
11302
|
transcription: transcription ? await Promise.all(transcription.list().map((entry) => serializeTranscriptionModel(entry, transcription.default))) : []
|
|
11256
|
-
}
|
|
11303
|
+
},
|
|
11304
|
+
capabilities: { run: requireRequestSixb(context).models.canRun() }
|
|
11257
11305
|
});
|
|
11258
11306
|
}, {
|
|
11259
11307
|
response: { 200: ModelCatalogSchema },
|
|
@@ -18301,11 +18349,7 @@ function createSixbApi(server) {
|
|
|
18301
18349
|
withCredentials: true
|
|
18302
18350
|
},
|
|
18303
18351
|
mapJsonSchema: {
|
|
18304
|
-
zod:
|
|
18305
|
-
$refStrategy: "none",
|
|
18306
|
-
target: "openApi3",
|
|
18307
|
-
override: openApiOverride()
|
|
18308
|
-
})
|
|
18352
|
+
zod: openApiJsonSchema
|
|
18309
18353
|
}
|
|
18310
18354
|
}));
|
|
18311
18355
|
const authExperience = server.getAuthExperience();
|
|
@@ -18407,4 +18451,4 @@ export {
|
|
|
18407
18451
|
createSixbServer
|
|
18408
18452
|
};
|
|
18409
18453
|
|
|
18410
|
-
//# debugId=
|
|
18454
|
+
//# debugId=0F67BE915C7C3AAC64756E2164756E21
|