@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 145 lines 5.78 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Schema from "effect/Schema";
3 import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
4
5 const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
6
7 const RuntimeTurnState = Schema.Literals(["completed", "failed", "interrupted", "cancelled"]);
8 export type RuntimeTurnState = typeof RuntimeTurnState.Type;
9
10 const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
11 export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
12
13 const TOOL_LIFECYCLE_ITEM_TYPES = [
14 "command_execution",
15 "file_change",
16 "mcp_tool_call",
17 "dynamic_tool_call",
18 "collab_agent_tool_call",
19 "web_search",
20 "image_view",
21 ] as const;
22
23 export const ToolLifecycleItemType = Schema.Literals(TOOL_LIFECYCLE_ITEM_TYPES);
24 export type ToolLifecycleItemType = typeof ToolLifecycleItemType.Type;
25
26 export function isToolLifecycleItemType(value: string): value is ToolLifecycleItemType {
27 return TOOL_LIFECYCLE_ITEM_TYPES.includes(value as ToolLifecycleItemType);
28 }
29
30 export const ThreadTokenUsageSnapshot = Schema.Struct({
31 usedTokens: NonNegativeInt,
32 totalProcessedTokens: Schema.optional(NonNegativeInt),
33 maxTokens: Schema.optional(PositiveInt),
34 inputTokens: Schema.optional(NonNegativeInt),
35 cachedInputTokens: Schema.optional(NonNegativeInt),
36 outputTokens: Schema.optional(NonNegativeInt),
37 reasoningOutputTokens: Schema.optional(NonNegativeInt),
38 lastUsedTokens: Schema.optional(NonNegativeInt),
39 lastInputTokens: Schema.optional(NonNegativeInt),
40 lastCachedInputTokens: Schema.optional(NonNegativeInt),
41 lastOutputTokens: Schema.optional(NonNegativeInt),
42 lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
43 toolUses: Schema.optional(NonNegativeInt),
44 durationMs: Schema.optional(NonNegativeInt),
45 compactsAutomatically: Schema.optional(Schema.Boolean),
46 autoCompactThreshold: Schema.optional(PositiveInt),
47 cost: Schema.optional(
48 Schema.Struct({
49 amount: Schema.Number.check(Schema.isFinite()),
50 currency: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(32)),
51 }),
52 ),
53 });
54 export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
55
56 // Input includes cache reads/writes; output includes the optional reasoningTokens subset.
57 const TurnTokenUsageCommonFields = {
58 usageScope: Schema.Literal("main_agent"),
59 cachedInputTokens: Schema.optional(NonNegativeInt),
60 cacheCreationTokens: Schema.optional(NonNegativeInt),
61 reasoningTokens: Schema.optional(NonNegativeInt),
62 hasSubagents: Schema.Boolean,
63 // Native model ids the provider reported for the main agent's work. Absent means unknown.
64 models: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
65 // The provider ran a local command; its counters describe that result, not model work.
66 localCommand: Schema.optional(Schema.Boolean),
67 // Provider-ledger counts beyond the main agent, such as native subagents and compaction.
68 otherUsage: Schema.optional(
69 Schema.Struct({ inputTokens: NonNegativeInt, outputTokens: NonNegativeInt }),
70 ),
71 };
72 export const TurnTokenUsage = Schema.Union([
73 Schema.Struct({
74 ...TurnTokenUsageCommonFields,
75 usageStatus: Schema.Literal("complete"),
76 inputTokens: NonNegativeInt,
77 outputTokens: NonNegativeInt,
78 }),
79 Schema.Struct({
80 ...TurnTokenUsageCommonFields,
81 usageStatus: Schema.Literals(["partial", "unavailable"]),
82 inputTokens: Schema.optional(NonNegativeInt),
83 outputTokens: Schema.optional(NonNegativeInt),
84 }),
85 ]);
86 export type TurnTokenUsage = typeof TurnTokenUsage.Type;
87
88 export const ToolActivitySurface = Schema.Literals(["browser", "computer"]);
89 export type ToolActivitySurface = typeof ToolActivitySurface.Type;
90
91 export const ToolActivityNativeAppReference = Schema.Union([
92 Schema.TaggedStruct("app-id", {
93 appId: TrimmedNonEmptyStringSchema.check(
94 Schema.isMaxLength(512),
95 Schema.isPattern(/^[A-Za-z0-9._-]+$/u),
96 ),
97 }),
98 Schema.TaggedStruct("display-name", {
99 displayName: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
100 }),
101 ]);
102 export type ToolActivityNativeAppReference = typeof ToolActivityNativeAppReference.Type;
103
104 export const ToolActivityIcon = Schema.Union([
105 Schema.TaggedStruct("website", {
106 pageUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
107 faviconUrl: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
108 faviconUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
109 }),
110 Schema.TaggedStruct("native-app", {
111 app: ToolActivityNativeAppReference,
112 }),
113 Schema.TaggedStruct("themed-logo", {
114 logoUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
115 logoUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
116 }),
117 ]);
118 export type ToolActivityIcon = typeof ToolActivityIcon.Type;
119
120 export const ToolActivitySource = Schema.Struct({
121 key: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(512)),
122 name: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
123 kind: Schema.Literals(["browser", "computer", "integration"]),
124 icon: Schema.optional(ToolActivityIcon),
125 });
126 export type ToolActivitySource = typeof ToolActivitySource.Type;
127
128 const UserInputQuestionOption = Schema.Struct({
129 label: TrimmedNonEmptyStringSchema,
130 description: Schema.String,
131 value: Schema.optional(Schema.String),
132 });
133
134 export const UserInputQuestion = Schema.Struct({
135 id: TrimmedNonEmptyStringSchema,
136 header: TrimmedNonEmptyStringSchema,
137 question: TrimmedNonEmptyStringSchema,
138 options: Schema.Array(UserInputQuestionOption),
139 allowCustomAnswer: Schema.optional(Schema.Boolean),
140 initialAnswer: Schema.optional(Schema.String),
141 multiSelect: Schema.optional(Schema.Boolean).pipe(
142 Schema.withConstructorDefault(Effect.succeed(false)),
143 ),
144 });
145 export type UserInputQuestion = typeof UserInputQuestion.Type;