@inferencesh/app 0.1.15 → 0.2.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.js +4 -11
- package/dist/stream.d.ts +11 -4
- package/dist/stream.js +19 -40
- package/dist/types.d.ts +2 -2
- package/dist/zod-walk.d.ts +9 -0
- package/dist/zod-walk.js +40 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { File } from "./file.js";
|
|
|
2
2
|
export type { FileOptions, FileData } from "./file.js";
|
|
3
3
|
export { createFileSchema, isFileSchema, FILE_SCHEMA_MARKER } from "./schema.js";
|
|
4
4
|
export type { Socket, Frame } from "./socket.js";
|
|
5
|
-
export { createStreamSchema, media, pcm16, Live, liveFields, binaryField, STREAM_SCHEMA_MARKER, CLEAR_KEY, BINARY_SCHEMA_MARKER, } from "./stream.js";
|
|
5
|
+
export { createStreamSchema, media, pcm16, Live, liveFields, binaryField, STREAM_SCHEMA_MARKER, CLEAR_KEY, ERROR_KEY, BINARY_SCHEMA_MARKER, } from "./stream.js";
|
|
6
6
|
export type { Update } from "./stream.js";
|
|
7
7
|
export { StorageDir, ensureDir } from "./storage.js";
|
|
8
8
|
export type { StorageDirValue } from "./storage.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { File } from "./file.js";
|
|
3
3
|
// Zod schema utilities
|
|
4
4
|
export { createFileSchema, isFileSchema, FILE_SCHEMA_MARKER } from "./schema.js";
|
|
5
|
-
export { createStreamSchema, media, pcm16, Live, liveFields, binaryField, STREAM_SCHEMA_MARKER, CLEAR_KEY, BINARY_SCHEMA_MARKER, } from "./stream.js";
|
|
5
|
+
export { createStreamSchema, media, pcm16, Live, liveFields, binaryField, STREAM_SCHEMA_MARKER, CLEAR_KEY, ERROR_KEY, BINARY_SCHEMA_MARKER, } from "./stream.js";
|
|
6
6
|
// Storage directories
|
|
7
7
|
export { StorageDir, ensureDir } from "./storage.js";
|
|
8
8
|
// Download utility
|
package/dist/schema.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare const FILE_SCHEMA_MARKER: unique symbol;
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function createFileSchema(z: any): any;
|
|
30
30
|
/**
|
|
31
|
-
* Check if a Zod schema is a file schema (created by createFileSchema)
|
|
31
|
+
* Check if a Zod schema is a file schema (created by createFileSchema),
|
|
32
|
+
* through any wrapper (optional, default, nullable, ...) in zod v3 or v4.
|
|
32
33
|
*/
|
|
33
34
|
export declare function isFileSchema(schema: any): boolean;
|
package/dist/schema.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Generates JSON Schema with format: "file"
|
|
8
8
|
*/
|
|
9
9
|
import { File } from "./file.js";
|
|
10
|
+
import { findMarker } from "./zod-walk.js";
|
|
10
11
|
// We don't import zod directly to avoid version conflicts.
|
|
11
12
|
// Instead, apps provide their own zod and we work with the schema structure.
|
|
12
13
|
/**
|
|
@@ -36,17 +37,9 @@ export function createFileSchema(z) {
|
|
|
36
37
|
return schema;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
|
-
* Check if a Zod schema is a file schema (created by createFileSchema)
|
|
40
|
+
* Check if a Zod schema is a file schema (created by createFileSchema),
|
|
41
|
+
* through any wrapper (optional, default, nullable, ...) in zod v3 or v4.
|
|
40
42
|
*/
|
|
41
43
|
export function isFileSchema(schema) {
|
|
42
|
-
|
|
43
|
-
return false;
|
|
44
|
-
// Check for our marker
|
|
45
|
-
if (schema._def && schema._def[FILE_SCHEMA_MARKER])
|
|
46
|
-
return true;
|
|
47
|
-
// Check inner type for transforms/effects
|
|
48
|
-
if (schema._def?.typeName === "ZodEffects" && schema._def.schema) {
|
|
49
|
-
return isFileSchema(schema._def.schema);
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
44
|
+
return findMarker(schema, FILE_SCHEMA_MARKER) === true;
|
|
52
45
|
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -51,11 +51,13 @@ import type { Socket } from "./socket.js";
|
|
|
51
51
|
* The kernel's zodToJsonSchema reads this and emits `format: "stream"`.
|
|
52
52
|
*/
|
|
53
53
|
export declare const STREAM_SCHEMA_MARKER: unique symbol;
|
|
54
|
+
/** `{"$clear": "audio"}`: drop what has been buffered of a live output field. */
|
|
55
|
+
export declare const CLEAR_KEY = "$clear";
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
+
* `{"$error": {"field": ..., "message": ...}}`: a refused frame, or anything
|
|
58
|
+
* else the caller should be told went wrong. The stream goes on.
|
|
57
59
|
*/
|
|
58
|
-
export declare const
|
|
60
|
+
export declare const ERROR_KEY = "$error";
|
|
59
61
|
/**
|
|
60
62
|
* Marks a binary item schema. The value on `_def` is the content type.
|
|
61
63
|
* The kernel's zodToJsonSchema reads this and emits
|
|
@@ -117,7 +119,7 @@ export declare function binaryField(objectSchema: any): string | null;
|
|
|
117
119
|
* ```
|
|
118
120
|
*
|
|
119
121
|
* A frame that does not fit the input schema is answered with
|
|
120
|
-
* `{"error": {"field": ..., "message": ...}}` and skipped; the stream goes on.
|
|
122
|
+
* `{"$error": {"field": ..., "message": ...}}` and skipped; the stream goes on.
|
|
121
123
|
*
|
|
122
124
|
* The function may instead be an async generator (`async *talk(inputData, socket)`):
|
|
123
125
|
* each yield is a cumulative snapshot of the task's output, sent as a task update
|
|
@@ -139,6 +141,11 @@ export declare class Live {
|
|
|
139
141
|
private frames;
|
|
140
142
|
private read;
|
|
141
143
|
private refuse;
|
|
144
|
+
/**
|
|
145
|
+
* Tell the caller something went wrong without ending the stream: a
|
|
146
|
+
* provider error, or why the session is about to end.
|
|
147
|
+
*/
|
|
148
|
+
error(message: string, field?: string | null): Promise<void>;
|
|
142
149
|
/**
|
|
143
150
|
* Send items of live output fields, or new values of ordinary ones.
|
|
144
151
|
*
|
package/dist/stream.js
CHANGED
|
@@ -45,16 +45,23 @@
|
|
|
45
45
|
* Zod is never imported: the app's own zod (v3 or v4) is passed in, and the
|
|
46
46
|
* schemas are read by duck-typing `_def`, the same way the kernel does.
|
|
47
47
|
*/
|
|
48
|
+
import { findMarker } from "./zod-walk.js";
|
|
48
49
|
/**
|
|
49
50
|
* Marks a live field's schema. The value on `_def` is the item schema.
|
|
50
51
|
* The kernel's zodToJsonSchema reads this and emits `format: "stream"`.
|
|
51
52
|
*/
|
|
52
53
|
export const STREAM_SCHEMA_MARKER = Symbol.for("inferencesh.streamSchema");
|
|
54
|
+
// Control frames. Reserved keys start with `$`, which no field name can, so a
|
|
55
|
+
// control frame is never mistaken for an output field. sdk-js
|
|
56
|
+
// (src/live/protocol.ts) and sdk-py (inferencesh/models/stream.py) mirror
|
|
57
|
+
// these; change all three together.
|
|
58
|
+
/** `{"$clear": "audio"}`: drop what has been buffered of a live output field. */
|
|
59
|
+
export const CLEAR_KEY = "$clear";
|
|
53
60
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
61
|
+
* `{"$error": {"field": ..., "message": ...}}`: a refused frame, or anything
|
|
62
|
+
* else the caller should be told went wrong. The stream goes on.
|
|
56
63
|
*/
|
|
57
|
-
export const
|
|
64
|
+
export const ERROR_KEY = "$error";
|
|
58
65
|
/**
|
|
59
66
|
* Marks a binary item schema. The value on `_def` is the content type.
|
|
60
67
|
* The kernel's zodToJsonSchema reads this and emits
|
|
@@ -95,41 +102,6 @@ export function pcm16(z, rate = 16000, channels = 1) {
|
|
|
95
102
|
return media(z, `audio/pcm;format=s16le;rate=${rate};channels=${channels}`);
|
|
96
103
|
}
|
|
97
104
|
// --- schema walking (zod v3 and v4 `_def` shapes) ---------------------------
|
|
98
|
-
/** Inner schemas of a wrapper def, in the order worth checking. */
|
|
99
|
-
function innerSchemas(def) {
|
|
100
|
-
const out = [];
|
|
101
|
-
// v3 + v4: optional / default / nullable / catch / readonly
|
|
102
|
-
if (def.innerType)
|
|
103
|
-
out.push(def.innerType);
|
|
104
|
-
// v3: effects (preprocess / transform / refine), v4: some wrappers
|
|
105
|
-
if (def.schema)
|
|
106
|
-
out.push(def.schema);
|
|
107
|
-
if (def.inner)
|
|
108
|
-
out.push(def.inner);
|
|
109
|
-
// v4: pipe (preprocess, transform) — in, then out
|
|
110
|
-
if (def.in)
|
|
111
|
-
out.push(def.in);
|
|
112
|
-
if (def.out)
|
|
113
|
-
out.push(def.out);
|
|
114
|
-
return out;
|
|
115
|
-
}
|
|
116
|
-
/** The marker's value on the schema or any schema it wraps, or undefined. */
|
|
117
|
-
function findMarker(schema, marker, seen = new Set()) {
|
|
118
|
-
if (!schema || typeof schema !== "object" || seen.has(schema))
|
|
119
|
-
return undefined;
|
|
120
|
-
seen.add(schema);
|
|
121
|
-
const def = schema._def;
|
|
122
|
-
if (!def || typeof def !== "object")
|
|
123
|
-
return undefined;
|
|
124
|
-
if (Object.prototype.hasOwnProperty.call(def, marker))
|
|
125
|
-
return def[marker];
|
|
126
|
-
for (const inner of innerSchemas(def)) {
|
|
127
|
-
const found = findMarker(inner, marker, seen);
|
|
128
|
-
if (found !== undefined)
|
|
129
|
-
return found;
|
|
130
|
-
}
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
105
|
/** The fields of a zod object schema. v3: `_def.shape()`, v4: `_def.shape`. */
|
|
134
106
|
function shapeOf(objectSchema) {
|
|
135
107
|
const def = objectSchema?._def;
|
|
@@ -203,7 +175,7 @@ function firstIssue(result) {
|
|
|
203
175
|
* ```
|
|
204
176
|
*
|
|
205
177
|
* A frame that does not fit the input schema is answered with
|
|
206
|
-
* `{"error": {"field": ..., "message": ...}}` and skipped; the stream goes on.
|
|
178
|
+
* `{"$error": {"field": ..., "message": ...}}` and skipped; the stream goes on.
|
|
207
179
|
*
|
|
208
180
|
* The function may instead be an async generator (`async *talk(inputData, socket)`):
|
|
209
181
|
* each yield is a cumulative snapshot of the task's output, sent as a task update
|
|
@@ -299,7 +271,14 @@ export class Live {
|
|
|
299
271
|
return updates;
|
|
300
272
|
}
|
|
301
273
|
async refuse(field, message) {
|
|
302
|
-
await this.
|
|
274
|
+
await this.error(message, field);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Tell the caller something went wrong without ending the stream: a
|
|
278
|
+
* provider error, or why the session is about to end.
|
|
279
|
+
*/
|
|
280
|
+
async error(message, field = null) {
|
|
281
|
+
await this.socket.send({ [ERROR_KEY]: { field, message } });
|
|
303
282
|
}
|
|
304
283
|
/**
|
|
305
284
|
* Send items of live output fields, or new values of ordinary ones.
|
package/dist/types.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface OutputMeta {
|
|
|
44
44
|
/**
|
|
45
45
|
* MetaItemType is the type discriminator for MetaItem
|
|
46
46
|
*/
|
|
47
|
-
export type MetaItemType =
|
|
47
|
+
export type MetaItemType = "text" | "image" | "video" | "audio" | "raw";
|
|
48
48
|
export declare const MetaItemTypeText: MetaItemType;
|
|
49
49
|
export declare const MetaItemTypeImage: MetaItemType;
|
|
50
50
|
export declare const MetaItemTypeVideo: MetaItemType;
|
|
@@ -53,7 +53,7 @@ export declare const MetaItemTypeRaw: MetaItemType;
|
|
|
53
53
|
/**
|
|
54
54
|
* VideoResolution represents standard video resolution presets
|
|
55
55
|
*/
|
|
56
|
-
export type VideoResolution =
|
|
56
|
+
export type VideoResolution = "480p" | "720p" | "1080p" | "1440p" | "4k";
|
|
57
57
|
export declare const VideoRes480P: VideoResolution;
|
|
58
58
|
export declare const VideoRes720P: VideoResolution;
|
|
59
59
|
export declare const VideoRes1080P: VideoResolution;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walking a zod schema through its wrappers, the same way for zod v3 and v4:
|
|
3
|
+
* the app's own zod is passed in and never imported here, so schemas are read
|
|
4
|
+
* by duck-typing `_def`, as the kernel does.
|
|
5
|
+
*/
|
|
6
|
+
/** The schemas a wrapper (optional, default, nullable, effects, pipe, ...) wraps. */
|
|
7
|
+
export declare function innerSchemas(def: any): any[];
|
|
8
|
+
/** The value of a marker on a schema's `_def`, looking through its wrappers. */
|
|
9
|
+
export declare function findMarker(schema: any, marker: symbol, seen?: Set<any>): unknown;
|
package/dist/zod-walk.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walking a zod schema through its wrappers, the same way for zod v3 and v4:
|
|
3
|
+
* the app's own zod is passed in and never imported here, so schemas are read
|
|
4
|
+
* by duck-typing `_def`, as the kernel does.
|
|
5
|
+
*/
|
|
6
|
+
/** The schemas a wrapper (optional, default, nullable, effects, pipe, ...) wraps. */
|
|
7
|
+
export function innerSchemas(def) {
|
|
8
|
+
const out = [];
|
|
9
|
+
// v3 + v4: optional / default / nullable / catch / readonly
|
|
10
|
+
if (def.innerType)
|
|
11
|
+
out.push(def.innerType);
|
|
12
|
+
// v3: effects (preprocess / transform / refine), v4: some wrappers
|
|
13
|
+
if (def.schema)
|
|
14
|
+
out.push(def.schema);
|
|
15
|
+
if (def.inner)
|
|
16
|
+
out.push(def.inner);
|
|
17
|
+
// v4: pipe (preprocess, transform) — in, then out
|
|
18
|
+
if (def.in)
|
|
19
|
+
out.push(def.in);
|
|
20
|
+
if (def.out)
|
|
21
|
+
out.push(def.out);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/** The value of a marker on a schema's `_def`, looking through its wrappers. */
|
|
25
|
+
export function findMarker(schema, marker, seen = new Set()) {
|
|
26
|
+
if (!schema || typeof schema !== "object" || seen.has(schema))
|
|
27
|
+
return undefined;
|
|
28
|
+
seen.add(schema);
|
|
29
|
+
const def = schema._def;
|
|
30
|
+
if (!def || typeof def !== "object")
|
|
31
|
+
return undefined;
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(def, marker))
|
|
33
|
+
return def[marker];
|
|
34
|
+
for (const inner of innerSchemas(def)) {
|
|
35
|
+
const found = findMarker(inner, marker, seen);
|
|
36
|
+
if (found !== undefined)
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
package/package.json
CHANGED