mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
fix: update AIOStream schema export and enhance AIOStreamsStreamParser with validation
This commit is contained in:
@@ -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>;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user