mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-17 12:34:20 +01:00
chore: format files
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { z } from 'zod'
|
||||
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"]),
|
||||
}),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { z } from 'zod'
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { z } from 'zod'
|
||||
import { TextContentSchema } from './TextContentSchema'
|
||||
import { ImageContentSchema } from './ImageContentSchema'
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
||||
export type ToolResultContent = z.infer<typeof ToolResultContentSchema>
|
||||
export type ToolResultContent = z.infer<typeof ToolResultContentSchema>;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { z } from 'zod'
|
||||
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()),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { z } from 'zod'
|
||||
import { AssistantMessageSchema } from '../message/AssistantMessageSchema'
|
||||
import { BaseEntrySchema } from './BaseEntrySchema'
|
||||
import { z } from "zod";
|
||||
import { AssistantMessageSchema } from "../message/AssistantMessageSchema";
|
||||
import { BaseEntrySchema } from "./BaseEntrySchema";
|
||||
|
||||
export const AssistantEntrySchema = BaseEntrySchema.extend({
|
||||
// discriminator
|
||||
type: z.literal('assistant'),
|
||||
type: z.literal("assistant"),
|
||||
|
||||
// required
|
||||
message: AssistantMessageSchema,
|
||||
@@ -12,4 +12,4 @@ export const AssistantEntrySchema = BaseEntrySchema.extend({
|
||||
// optional
|
||||
requestId: z.string().optional(),
|
||||
isApiErrorMessage: z.boolean().optional(),
|
||||
}).strict()
|
||||
}).strict();
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import { z } from 'zod'
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { z } from 'zod'
|
||||
import { BaseEntrySchema } from './BaseEntrySchema'
|
||||
import { z } from "zod";
|
||||
import { BaseEntrySchema } from "./BaseEntrySchema";
|
||||
|
||||
export const SystemEntrySchema = BaseEntrySchema.extend({
|
||||
// discriminator
|
||||
type: z.literal('system'),
|
||||
type: z.literal("system"),
|
||||
|
||||
// required
|
||||
content: z.string(),
|
||||
toolUseID: z.string(),
|
||||
level: z.enum(['info']),
|
||||
}).strict()
|
||||
level: z.enum(["info"]),
|
||||
}).strict();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
import { UserMessageSchema } from '../message/UserMessageSchema'
|
||||
import { BaseEntrySchema } from './BaseEntrySchema'
|
||||
import { z } from "zod";
|
||||
import { UserMessageSchema } from "../message/UserMessageSchema";
|
||||
import { BaseEntrySchema } from "./BaseEntrySchema";
|
||||
|
||||
export const UserEntrySchema = BaseEntrySchema.extend({
|
||||
// discriminator
|
||||
type: z.literal('user'),
|
||||
type: z.literal("user"),
|
||||
|
||||
// required
|
||||
message: UserMessageSchema,
|
||||
}).strict()
|
||||
}).strict();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { UserEntrySchema } from './entry/UserEntrySchema'
|
||||
import { AssistantEntrySchema } from './entry/AssistantEntrySchema'
|
||||
import { SummaryEntrySchema } from './entry/SummaryEntrySchema'
|
||||
import { SystemEntrySchema } from './entry/SystemEntrySchema'
|
||||
import { z } from "zod";
|
||||
import { AssistantEntrySchema } from "./entry/AssistantEntrySchema";
|
||||
import { SummaryEntrySchema } from "./entry/SummaryEntrySchema";
|
||||
import { SystemEntrySchema } from "./entry/SystemEntrySchema";
|
||||
import { UserEntrySchema } from "./entry/UserEntrySchema";
|
||||
|
||||
export const ConversationSchema = z.union([
|
||||
UserEntrySchema,
|
||||
AssistantEntrySchema,
|
||||
SummaryEntrySchema,
|
||||
SystemEntrySchema,
|
||||
])
|
||||
]);
|
||||
|
||||
export type Conversation = z.infer<typeof ConversationSchema>
|
||||
export type Conversation = z.infer<typeof ConversationSchema>;
|
||||
|
||||
@@ -1,38 +1,46 @@
|
||||
import { z } from 'zod'
|
||||
import { ThinkingContentSchema } from '../content/ThinkingContentSchema'
|
||||
import { TextContentSchema } from '../content/TextContentSchema'
|
||||
import { ToolUseContentSchema } from '../content/ToolUseContentSchema'
|
||||
import { ToolResultContentSchema } from '../content/ToolResultContentSchema'
|
||||
import { z } from "zod";
|
||||
import { TextContentSchema } from "../content/TextContentSchema";
|
||||
import { ThinkingContentSchema } from "../content/ThinkingContentSchema";
|
||||
import { ToolResultContentSchema } from "../content/ToolResultContentSchema";
|
||||
import { ToolUseContentSchema } from "../content/ToolUseContentSchema";
|
||||
|
||||
const AssistantMessageContentSchema = z.union([
|
||||
ThinkingContentSchema,
|
||||
TextContentSchema,
|
||||
ToolUseContentSchema,
|
||||
ToolResultContentSchema,
|
||||
])
|
||||
]);
|
||||
|
||||
export type AssistantMessageContent = z.infer<typeof AssistantMessageContentSchema>
|
||||
export type AssistantMessageContent = z.infer<
|
||||
typeof AssistantMessageContentSchema
|
||||
>;
|
||||
|
||||
export const AssistantMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
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(),
|
||||
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();
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
import { z } from 'zod'
|
||||
import { ToolResultContentSchema } from '../content/ToolResultContentSchema'
|
||||
import { TextContentSchema } from '../content/TextContentSchema'
|
||||
import { ImageContentSchema } from '../content/ImageContentSchema'
|
||||
|
||||
import { z } from "zod";
|
||||
import { ImageContentSchema } from "../content/ImageContentSchema";
|
||||
import { TextContentSchema } from "../content/TextContentSchema";
|
||||
import { ToolResultContentSchema } from "../content/ToolResultContentSchema";
|
||||
|
||||
const UserMessageContentSchema = z.union([
|
||||
z.string(),
|
||||
TextContentSchema,
|
||||
ToolResultContentSchema,
|
||||
ImageContentSchema
|
||||
])
|
||||
ImageContentSchema,
|
||||
]);
|
||||
|
||||
export type UserMessageContent = z.infer<typeof UserMessageContentSchema>
|
||||
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([
|
||||
export const UserMessageSchema = z
|
||||
.object({
|
||||
role: z.literal("user"),
|
||||
content: z.union([
|
||||
z.string(),
|
||||
UserMessageContentSchema
|
||||
]))
|
||||
]),
|
||||
}).strict()
|
||||
z.array(z.union([z.string(), UserMessageContentSchema])),
|
||||
]),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,59 +1,71 @@
|
||||
import { z } from 'zod'
|
||||
import { StructuredPatchSchema } from './StructuredPatchSchema'
|
||||
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(),
|
||||
})
|
||||
.strict(),
|
||||
|
||||
// create
|
||||
z.object({
|
||||
type: z.literal('create'),
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
structuredPatch: z.array(StructuredPatchSchema)
|
||||
}).strict(),
|
||||
|
||||
// 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(),
|
||||
|
||||
// search?
|
||||
z.object({
|
||||
filenames: z.array(z.string()),
|
||||
durationMs: z.number(),
|
||||
numFiles: z.number(),
|
||||
truncated: z.boolean(),
|
||||
}).strict(),
|
||||
|
||||
// text
|
||||
z.object({
|
||||
type: z.literal('text'),
|
||||
file: z.object({
|
||||
z
|
||||
.object({
|
||||
type: z.literal("create"),
|
||||
filePath: z.string(),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
startLine: z.number(),
|
||||
totalLines: z.number(),
|
||||
structuredPatch: z.array(StructuredPatchSchema),
|
||||
})
|
||||
}).strict(),
|
||||
.strict(),
|
||||
|
||||
// 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(),
|
||||
|
||||
// search?
|
||||
z
|
||||
.object({
|
||||
filenames: z.array(z.string()),
|
||||
durationMs: z.number(),
|
||||
numFiles: z.number(),
|
||||
truncated: z.boolean(),
|
||||
})
|
||||
.strict(),
|
||||
|
||||
// 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()),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
}).strict(),
|
||||
])
|
||||
z
|
||||
.object({
|
||||
mode: z.literal("content"),
|
||||
numFiles: z.number(),
|
||||
filenames: z.array(z.string()),
|
||||
content: z.string(),
|
||||
numLines: z.number(),
|
||||
})
|
||||
.strict(),
|
||||
]);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
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()),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
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(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { TodoToolResultSchema } from "./TodoSchema";
|
||||
import { CommonToolResultSchema } from "./CommonToolSchema";
|
||||
import { TodoToolResultSchema } from "./TodoSchema";
|
||||
|
||||
export const ToolUseResultSchema = z.union([
|
||||
z.string(),
|
||||
|
||||
Reference in New Issue
Block a user