refactor: 重构项目结构,将 tracer 模块提取为独立子包
- 将 tracer 相关代码移动到 tracers.ts 子目录中 - 新增类型定义文件,统一管理命令类型 - 实现上下文管理机制,集中处理 tracer 命令 - 更新构建配置和依赖管理 - 移除旧的根目录文件,保持代码结构清晰
This commit is contained in:
57
tracers.ts/src/types/array-tracer.ts
Normal file
57
tracers.ts/src/types/array-tracer.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { BaseTracerCommand, JsonValue } from './common';
|
||||
|
||||
type BaseArrayTracerCommand = BaseTracerCommand & {
|
||||
type: 'ArrayTracer';
|
||||
};
|
||||
|
||||
type ArrayTracerCreateCommand = BaseArrayTracerCommand & {
|
||||
action: 'create';
|
||||
params: {
|
||||
description: string;
|
||||
array?: JsonValue[];
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerScaleCommand = BaseArrayTracerCommand & {
|
||||
action: 'scale';
|
||||
params: {
|
||||
size: number;
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerPickCommand = BaseArrayTracerCommand & {
|
||||
action: 'pick';
|
||||
params: {
|
||||
index: number;
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerDropCommand = BaseArrayTracerCommand & {
|
||||
action: 'drop';
|
||||
params: {
|
||||
index: number;
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerPatchCommand = BaseArrayTracerCommand & {
|
||||
action: 'patch';
|
||||
params: {
|
||||
index: number;
|
||||
value: JsonValue;
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerUnsetCommand = BaseArrayTracerCommand & {
|
||||
action: 'unset';
|
||||
params: {
|
||||
index: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type ArrayTracerCommand =
|
||||
| ArrayTracerCreateCommand
|
||||
| ArrayTracerScaleCommand
|
||||
| ArrayTracerPickCommand
|
||||
| ArrayTracerDropCommand
|
||||
| ArrayTracerPatchCommand
|
||||
| ArrayTracerUnsetCommand;
|
||||
8
tracers.ts/src/types/command.ts
Normal file
8
tracers.ts/src/types/command.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { ArrayTracerCommand } from './array-tracer';
|
||||
import type { ControlTracerCommand } from './control-tracer';
|
||||
import type { LogTracerCommand } from './log-tracer';
|
||||
|
||||
export type TracerCommand =
|
||||
| ArrayTracerCommand
|
||||
| LogTracerCommand
|
||||
| ControlTracerCommand;
|
||||
16
tracers.ts/src/types/common.ts
Normal file
16
tracers.ts/src/types/common.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export type JsonValue =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| JsonValue[]
|
||||
| { [key: string]: JsonValue };
|
||||
|
||||
export type TracerType = 'ArrayTracer' | 'LogTracer' | 'ControlTracer';
|
||||
|
||||
export type TracerId = ReturnType<typeof crypto.randomUUID>;
|
||||
|
||||
export type BaseTracerCommand = {
|
||||
type: TracerType;
|
||||
tracer: TracerId;
|
||||
};
|
||||
23
tracers.ts/src/types/control-tracer.ts
Normal file
23
tracers.ts/src/types/control-tracer.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { BaseTracerCommand } from './common';
|
||||
|
||||
type BaseControlTracerCommand = BaseTracerCommand & {
|
||||
type: 'ControlTracer';
|
||||
};
|
||||
|
||||
type ControlTracerCreateCommand = BaseControlTracerCommand & {
|
||||
action: 'create';
|
||||
params: {
|
||||
description: string;
|
||||
};
|
||||
};
|
||||
|
||||
type ControlTracerStepCommand = BaseControlTracerCommand & {
|
||||
action: 'step';
|
||||
params: {
|
||||
lines: number[];
|
||||
};
|
||||
};
|
||||
|
||||
export type ControlTracerCommand =
|
||||
| ControlTracerCreateCommand
|
||||
| ControlTracerStepCommand;
|
||||
5
tracers.ts/src/types/index.ts
Normal file
5
tracers.ts/src/types/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './array-tracer';
|
||||
export * from './command';
|
||||
export * from './common';
|
||||
export * from './control-tracer';
|
||||
export * from './log-tracer';
|
||||
21
tracers.ts/src/types/log-tracer.ts
Normal file
21
tracers.ts/src/types/log-tracer.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { BaseTracerCommand } from "./common";
|
||||
|
||||
type BaseLogTracerCommand = BaseTracerCommand & {
|
||||
type: 'LogTracer';
|
||||
};
|
||||
|
||||
type LogTracerCreateCommand = BaseLogTracerCommand & {
|
||||
action: 'create';
|
||||
params: {
|
||||
description: string;
|
||||
};
|
||||
};
|
||||
|
||||
type LogTracerLogCommand = BaseLogTracerCommand & {
|
||||
action: 'log';
|
||||
params: {
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type LogTracerCommand = LogTracerCreateCommand | LogTracerLogCommand;
|
||||
Reference in New Issue
Block a user