mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2025-12-24 08:44:21 +01:00
chore: remove strict() from zod
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ImageContentSchema = z
|
||||
.object({
|
||||
type: z.literal("image"),
|
||||
source: z.object({
|
||||
type: z.literal("base64"),
|
||||
data: z.string(),
|
||||
media_type: z.enum(["image/png"]),
|
||||
}),
|
||||
})
|
||||
.strict();
|
||||
export const ImageContentSchema = z.object({
|
||||
type: z.literal("image"),
|
||||
source: z.object({
|
||||
type: z.literal("base64"),
|
||||
data: z.string(),
|
||||
media_type: z.enum(["image/png"]),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const TextContentSchema = z
|
||||
.object({
|
||||
type: z.literal("text"),
|
||||
text: z.string(),
|
||||
})
|
||||
.strict();
|
||||
export const TextContentSchema = z.object({
|
||||
type: z.literal("text"),
|
||||
text: z.string(),
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ThinkingContentSchema = z
|
||||
.object({
|
||||
type: z.literal("thinking"),
|
||||
thinking: z.string(),
|
||||
signature: z.string().optional(),
|
||||
})
|
||||
.strict();
|
||||
export const ThinkingContentSchema = z.object({
|
||||
type: z.literal("thinking"),
|
||||
thinking: z.string(),
|
||||
signature: z.string().optional(),
|
||||
});
|
||||
|
||||
@@ -2,16 +2,14 @@ import { z } from "zod";
|
||||
import { ImageContentSchema } from "./ImageContentSchema";
|
||||
import { TextContentSchema } from "./TextContentSchema";
|
||||
|
||||
export const ToolResultContentSchema = z
|
||||
.object({
|
||||
type: z.literal("tool_result"),
|
||||
tool_use_id: z.string(),
|
||||
content: z.union([
|
||||
z.string(),
|
||||
z.array(z.union([TextContentSchema, ImageContentSchema])),
|
||||
]),
|
||||
is_error: z.boolean().optional(),
|
||||
})
|
||||
.strict();
|
||||
export const ToolResultContentSchema = z.object({
|
||||
type: z.literal("tool_result"),
|
||||
tool_use_id: z.string(),
|
||||
content: z.union([
|
||||
z.string(),
|
||||
z.array(z.union([TextContentSchema, ImageContentSchema])),
|
||||
]),
|
||||
is_error: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type ToolResultContent = z.infer<typeof ToolResultContentSchema>;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ToolUseContentSchema = z
|
||||
.object({
|
||||
type: z.literal("tool_use"),
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
input: z.record(z.string(), z.unknown()),
|
||||
})
|
||||
.strict();
|
||||
export const ToolUseContentSchema = z.object({
|
||||
type: z.literal("tool_use"),
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
input: z.record(z.string(), z.unknown()),
|
||||
});
|
||||
|
||||
@@ -12,4 +12,4 @@ export const AssistantEntrySchema = BaseEntrySchema.extend({
|
||||
// optional
|
||||
requestId: z.string().optional(),
|
||||
isApiErrorMessage: z.boolean().optional(),
|
||||
}).strict();
|
||||
});
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const BaseEntrySchema = z
|
||||
.object({
|
||||
// required
|
||||
isSidechain: z.boolean(),
|
||||
userType: z.enum(["external"]),
|
||||
cwd: z.string(),
|
||||
sessionId: z.string(),
|
||||
version: z.string(),
|
||||
uuid: z.uuid(),
|
||||
timestamp: z.string(),
|
||||
export const BaseEntrySchema = z.object({
|
||||
// required
|
||||
isSidechain: z.boolean(),
|
||||
userType: z.enum(["external"]),
|
||||
cwd: z.string(),
|
||||
sessionId: z.string(),
|
||||
version: z.string(),
|
||||
uuid: z.uuid(),
|
||||
timestamp: z.string(),
|
||||
|
||||
// nullable
|
||||
parentUuid: z.uuid().nullable(),
|
||||
// nullable
|
||||
parentUuid: z.uuid().nullable(),
|
||||
|
||||
// optional
|
||||
isMeta: z.boolean().optional(),
|
||||
toolUseResult: z.unknown().optional(), // スキーマがツールごとに異なりすぎるし利用もしなそうなので unknown
|
||||
gitBranch: z.string().optional(),
|
||||
isCompactSummary: z.boolean().optional(),
|
||||
})
|
||||
.strict();
|
||||
// optional
|
||||
isMeta: z.boolean().optional(),
|
||||
toolUseResult: z.unknown().optional(), // スキーマがツールごとに異なりすぎるし利用もしなそうなので unknown
|
||||
gitBranch: z.string().optional(),
|
||||
isCompactSummary: z.boolean().optional(),
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const SummaryEntrySchema = z
|
||||
.object({
|
||||
type: z.literal("summary"),
|
||||
summary: z.string(),
|
||||
leafUuid: z.string().uuid(),
|
||||
})
|
||||
.strict();
|
||||
export const SummaryEntrySchema = z.object({
|
||||
type: z.literal("summary"),
|
||||
summary: z.string(),
|
||||
leafUuid: z.string().uuid(),
|
||||
});
|
||||
|
||||
@@ -9,4 +9,4 @@ export const SystemEntrySchema = BaseEntrySchema.extend({
|
||||
content: z.string(),
|
||||
toolUseID: z.string(),
|
||||
level: z.enum(["info"]),
|
||||
}).strict();
|
||||
});
|
||||
|
||||
@@ -8,4 +8,4 @@ export const UserEntrySchema = BaseEntrySchema.extend({
|
||||
|
||||
// required
|
||||
message: UserMessageSchema,
|
||||
}).strict();
|
||||
});
|
||||
|
||||
@@ -15,33 +15,31 @@ export type AssistantMessageContent = z.infer<
|
||||
typeof AssistantMessageContentSchema
|
||||
>;
|
||||
|
||||
export const AssistantMessageSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
container: z.null().optional(),
|
||||
type: z.literal("message"),
|
||||
role: z.literal("assistant"),
|
||||
model: z.string(),
|
||||
content: z.array(AssistantMessageContentSchema),
|
||||
stop_reason: z.string().nullable(),
|
||||
stop_sequence: z.string().nullable(),
|
||||
usage: z.object({
|
||||
input_tokens: z.number(),
|
||||
cache_creation_input_tokens: z.number().optional(),
|
||||
cache_read_input_tokens: z.number().optional(),
|
||||
cache_creation: z
|
||||
.object({
|
||||
ephemeral_5m_input_tokens: z.number(),
|
||||
ephemeral_1h_input_tokens: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
output_tokens: z.number(),
|
||||
service_tier: z.string().nullable().optional(),
|
||||
server_tool_use: z
|
||||
.object({
|
||||
web_search_requests: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
.strict();
|
||||
export const AssistantMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
container: z.null().optional(),
|
||||
type: z.literal("message"),
|
||||
role: z.literal("assistant"),
|
||||
model: z.string(),
|
||||
content: z.array(AssistantMessageContentSchema),
|
||||
stop_reason: z.string().nullable(),
|
||||
stop_sequence: z.string().nullable(),
|
||||
usage: z.object({
|
||||
input_tokens: z.number(),
|
||||
cache_creation_input_tokens: z.number().optional(),
|
||||
cache_read_input_tokens: z.number().optional(),
|
||||
cache_creation: z
|
||||
.object({
|
||||
ephemeral_5m_input_tokens: z.number(),
|
||||
ephemeral_1h_input_tokens: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
output_tokens: z.number(),
|
||||
service_tier: z.string().nullable().optional(),
|
||||
server_tool_use: z
|
||||
.object({
|
||||
web_search_requests: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -12,12 +12,10 @@ const UserMessageContentSchema = z.union([
|
||||
|
||||
export type UserMessageContent = z.infer<typeof UserMessageContentSchema>;
|
||||
|
||||
export const UserMessageSchema = z
|
||||
.object({
|
||||
role: z.literal("user"),
|
||||
content: z.union([
|
||||
z.string(),
|
||||
z.array(z.union([z.string(), UserMessageContentSchema])),
|
||||
]),
|
||||
})
|
||||
.strict();
|
||||
export const UserMessageSchema = z.object({
|
||||
role: z.literal("user"),
|
||||
content: z.union([
|
||||
z.string(),
|
||||
z.array(z.union([z.string(), UserMessageContentSchema])),
|
||||
]),
|
||||
});
|
||||
|
||||
@@ -2,70 +2,58 @@ import { z } from "zod";
|
||||
import { StructuredPatchSchema } from "./StructuredPatchSchema";
|
||||
|
||||
export const CommonToolResultSchema = z.union([
|
||||
z
|
||||
.object({
|
||||
stdout: z.string(),
|
||||
stderr: z.string(),
|
||||
interrupted: z.boolean(),
|
||||
isImage: z.boolean(),
|
||||
})
|
||||
.strict(),
|
||||
z.object({
|
||||
stdout: z.string(),
|
||||
stderr: z.string(),
|
||||
interrupted: z.boolean(),
|
||||
isImage: z.boolean(),
|
||||
}),
|
||||
|
||||
// create
|
||||
z
|
||||
.object({
|
||||
type: z.literal("create"),
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
structuredPatch: z.array(StructuredPatchSchema),
|
||||
})
|
||||
.strict(),
|
||||
z.object({
|
||||
type: z.literal("create"),
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
structuredPatch: z.array(StructuredPatchSchema),
|
||||
}),
|
||||
|
||||
// update
|
||||
z
|
||||
.object({
|
||||
filePath: z.string(),
|
||||
oldString: z.string(),
|
||||
newString: z.string(),
|
||||
originalFile: z.string(),
|
||||
userModified: z.boolean(),
|
||||
replaceAll: z.boolean(),
|
||||
structuredPatch: z.array(StructuredPatchSchema),
|
||||
})
|
||||
.strict(),
|
||||
z.object({
|
||||
filePath: z.string(),
|
||||
oldString: z.string(),
|
||||
newString: z.string(),
|
||||
originalFile: z.string(),
|
||||
userModified: z.boolean(),
|
||||
replaceAll: z.boolean(),
|
||||
structuredPatch: z.array(StructuredPatchSchema),
|
||||
}),
|
||||
|
||||
// search?
|
||||
z
|
||||
.object({
|
||||
filenames: z.array(z.string()),
|
||||
durationMs: z.number(),
|
||||
numFiles: z.number(),
|
||||
truncated: z.boolean(),
|
||||
})
|
||||
.strict(),
|
||||
z.object({
|
||||
filenames: z.array(z.string()),
|
||||
durationMs: z.number(),
|
||||
numFiles: z.number(),
|
||||
truncated: z.boolean(),
|
||||
}),
|
||||
|
||||
// text
|
||||
z
|
||||
.object({
|
||||
type: z.literal("text"),
|
||||
file: z.object({
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
startLine: z.number(),
|
||||
totalLines: z.number(),
|
||||
}),
|
||||
})
|
||||
.strict(),
|
||||
|
||||
// content
|
||||
z
|
||||
.object({
|
||||
mode: z.literal("content"),
|
||||
numFiles: z.number(),
|
||||
filenames: z.array(z.string()),
|
||||
z.object({
|
||||
type: z.literal("text"),
|
||||
file: z.object({
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
})
|
||||
.strict(),
|
||||
startLine: z.number(),
|
||||
totalLines: z.number(),
|
||||
}),
|
||||
}),
|
||||
|
||||
// content
|
||||
z.object({
|
||||
mode: z.literal("content"),
|
||||
numFiles: z.number(),
|
||||
filenames: z.array(z.string()),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const StructuredPatchSchema = z
|
||||
.object({
|
||||
oldStart: z.number(),
|
||||
oldLines: z.number(),
|
||||
newStart: z.number(),
|
||||
newLines: z.number(),
|
||||
lines: z.array(z.string()),
|
||||
})
|
||||
.strict();
|
||||
export const StructuredPatchSchema = z.object({
|
||||
oldStart: z.number(),
|
||||
oldLines: z.number(),
|
||||
newStart: z.number(),
|
||||
newLines: z.number(),
|
||||
lines: z.array(z.string()),
|
||||
});
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import z from "zod";
|
||||
|
||||
const TodoSchema = z
|
||||
.object({
|
||||
content: z.string(),
|
||||
status: z.enum(["pending", "in_progress", "completed"]),
|
||||
priority: z.enum(["low", "medium", "high"]),
|
||||
id: z.string(),
|
||||
})
|
||||
.strict();
|
||||
const TodoSchema = z.object({
|
||||
content: z.string(),
|
||||
status: z.enum(["pending", "in_progress", "completed"]),
|
||||
priority: z.enum(["low", "medium", "high"]),
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export const TodoToolResultSchema = z
|
||||
.object({
|
||||
oldTodos: z.array(TodoSchema).optional(),
|
||||
newTodos: z.array(TodoSchema).optional(),
|
||||
})
|
||||
.strict();
|
||||
export const TodoToolResultSchema = z.object({
|
||||
oldTodos: z.array(TodoSchema).optional(),
|
||||
newTodos: z.array(TodoSchema).optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user