fix: update AIOStream schema export and enhance AIOStreamsStreamParser with validation

This commit is contained in:
Viren070
2025-06-09 15:36:21 +01:00
parent f8b08b3093
commit edc310fe5f
2 changed files with 14 additions and 4 deletions
+3 -3
View File
@@ -641,7 +641,7 @@ export const ParsedStreamSchema = z.object({
export type ParsedStream = z.infer<typeof ParsedStreamSchema>;
const AIOStreamSchema = StreamSchema.extend({
export const AIOStream = StreamSchema.extend({
streamData: z.object({
error: z
.object({
@@ -687,10 +687,10 @@ const AIOStreamSchema = StreamSchema.extend({
}),
});
export type AIOStream = z.infer<typeof AIOStreamSchema>;
export type AIOStream = z.infer<typeof AIOStream>;
const AIOStreamResponseSchema = z.object({
streams: z.array(AIOStreamSchema),
streams: z.array(AIOStream),
});
export type AIOStreamResponse = z.infer<typeof AIOStreamResponseSchema>;
+11 -1
View File
@@ -7,12 +7,22 @@ import {
AIOStream,
} from '../db';
import { Preset, baseOptions } from './preset';
import { Env, RESOURCES } from '../utils';
import { Env, formatZodError, RESOURCES } from '../utils';
import { StreamParser } from '../parser';
import { createLogger } from '../utils';
const logger = createLogger('parser');
class AIOStreamsStreamParser extends StreamParser {
override parse(stream: Stream): ParsedStream {
const aioStream = stream as AIOStream;
const parsed = AIOStream.safeParse(aioStream);
if (!parsed.success) {
logger.error(
`Stream from AIOStream was not detected as a valid stream: ${formatZodError(parsed.error)}`
);
throw new Error('Invalid stream');
}
return {
addon: {
...this.addon,