@allternit/gizzi-code 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/bin/gizzi +4 -0
  2. package/bin/gizzi-ink +5 -0
  3. package/package.json +137 -31
  4. package/src/Tool.ts +26 -0
  5. package/src/bootstrap/state.ts +165 -322
  6. package/src/commands.ts +209 -0
  7. package/src/context/QueuedMessageContext.tsx +63 -0
  8. package/src/context/fpsMetrics.tsx +30 -0
  9. package/src/context/mailbox.tsx +38 -0
  10. package/src/context/modalContext.tsx +58 -0
  11. package/src/context/notifications.tsx +240 -0
  12. package/src/context/overlayContext.tsx +151 -0
  13. package/src/context/promptOverlayContext.tsx +125 -0
  14. package/src/context/stats.tsx +220 -0
  15. package/src/context/voice.tsx +88 -0
  16. package/src/hooks/useCanUseTool.ts +11 -0
  17. package/src/hooks/useExitOnCtrlCD.ts +40 -187
  18. package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
  19. package/src/hooks/useKeybinding.ts +68 -209
  20. package/src/hooks/useTerminalSize.ts +31 -99
  21. package/src/hooks.ts +37 -0
  22. package/src/ink.ts +204 -0
  23. package/src/main.ts +7 -0
  24. package/src/types/command.ts +216 -0
  25. package/src/types/connectorText.ts +39 -0
  26. package/src/types/fileSuggestion.ts +15 -0
  27. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
  28. package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
  29. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
  30. package/src/types/generated/google/protobuf/timestamp.ts +187 -0
  31. package/src/types/hooks.ts +319 -0
  32. package/src/types/ids.ts +44 -0
  33. package/src/types/logs.ts +331 -0
  34. package/src/types/merged/index.ts +5 -0
  35. package/src/types/merged/message.ts +552 -0
  36. package/src/types/message.ts +927 -186
  37. package/src/types/messageQueueTypes.ts +21 -0
  38. package/src/types/notebook.ts +72 -0
  39. package/src/types/permissions.ts +447 -0
  40. package/src/types/plugin.ts +363 -0
  41. package/src/types/statusLine.ts +15 -0
  42. package/src/types/textInputTypes.ts +387 -0
  43. package/src/types/tools.ts +149 -0
  44. package/src/types/utils.ts +20 -0
  45. package/src/utils/advisor.ts +12 -0
  46. package/src/utils/api.ts +29 -0
  47. package/src/utils/array.ts +7 -0
  48. package/src/utils/attachments.ts +60 -0
  49. package/src/utils/auth.ts +3 -0
  50. package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
  51. package/src/utils/claudeInChrome/common.ts +12 -0
  52. package/src/utils/claudeInChrome/mcpServer.ts +15 -0
  53. package/src/utils/computerUse/common.ts +19 -0
  54. package/src/utils/computerUse/mcpServer.ts +15 -0
  55. package/src/utils/config.ts +35 -0
  56. package/src/utils/context.ts +19 -0
  57. package/src/utils/cwd.ts +3 -0
  58. package/src/utils/debug.ts +3 -0
  59. package/src/utils/earlyInput.ts +7 -0
  60. package/src/utils/effort.ts +13 -0
  61. package/src/utils/embeddedTools.ts +12 -0
  62. package/src/utils/envUtils.ts +3 -0
  63. package/src/utils/errors.ts +3 -0
  64. package/src/utils/execFileNoThrow.ts +24 -0
  65. package/src/utils/feature-flags.ts +112 -0
  66. package/src/utils/file.ts +3 -0
  67. package/src/utils/fileHistory.ts +17 -0
  68. package/src/utils/fingerprint.ts +7 -0
  69. package/src/utils/format.ts +75 -305
  70. package/src/utils/frontmatterParser.ts +33 -0
  71. package/src/utils/fsOperations.ts +31 -0
  72. package/src/utils/fullscreen.ts +40 -350
  73. package/src/utils/git.ts +15 -0
  74. package/src/utils/imageResizer.ts +30 -0
  75. package/src/utils/lazySchema.ts +9 -0
  76. package/src/utils/log.ts +3 -0
  77. package/src/utils/markdownConfigLoader.ts +12 -0
  78. package/src/utils/messages.ts +13 -0
  79. package/src/utils/migration.ts +137 -0
  80. package/src/utils/model/providers.ts +15 -0
  81. package/src/utils/path.ts +3 -0
  82. package/src/utils/permissions/PermissionResult.ts +14 -0
  83. package/src/utils/permissions/autoModeState.ts +12 -0
  84. package/src/utils/permissions/filesystem.ts +12 -0
  85. package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
  86. package/src/utils/plugins/schemas.ts +25 -0
  87. package/src/utils/process.ts +16 -0
  88. package/src/utils/sandbox/sandbox-adapter.ts +19 -0
  89. package/src/utils/sessionStorage.ts +238 -472
  90. package/src/utils/settings/constants.ts +10 -0
  91. package/src/utils/settings/settings.ts +19 -0
  92. package/src/utils/settings/types.ts +18 -0
  93. package/src/utils/shell/shellToolUtils.ts +9 -0
  94. package/src/utils/sinks.ts +11 -0
  95. package/src/utils/sleep.ts +7 -0
  96. package/src/utils/sliceAnsi.ts +7 -0
  97. package/src/utils/slowOperations.ts +3 -0
  98. package/src/utils/startupProfiler.ts +11 -0
  99. package/src/utils/stringUtils.ts +106 -0
  100. package/src/utils/systemPromptType.ts +9 -0
  101. package/src/utils/teleport/api.ts +15 -0
  102. package/src/utils/textHighlighting.ts +16 -0
  103. package/src/utils/theme.ts +17 -0
  104. package/src/utils/thinking.ts +58 -0
  105. package/src/utils/tokens.ts +11 -0
  106. package/src/utils/toolResultStorage.ts +17 -0
  107. package/src/utils/worktreeModeEnabled.ts +7 -0
  108. package/WORKSPACE_INTEGRATION.md +0 -290
  109. package/chat-sessions/sessions-index.json +0 -98
  110. package/package.json.original +0 -31
  111. package/package.json.publish +0 -47
  112. package/src/bootstrap/state.d.ts +0 -169
  113. package/src/bootstrap/state.js +0 -261
  114. package/src/context/pack-builder.d.ts +0 -24
  115. package/src/context/pack-builder.js +0 -281
  116. package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
  117. package/src/hooks/useExitOnCtrlCD.js +0 -130
  118. package/src/hooks/useKeybinding.d.ts +0 -89
  119. package/src/hooks/useKeybinding.js +0 -163
  120. package/src/hooks/useTerminalSize.d.ts +0 -41
  121. package/src/hooks/useTerminalSize.js +0 -90
  122. package/src/index.d.ts +0 -23
  123. package/src/index.js +0 -24
  124. package/src/runtime/brand/brand.d.ts +0 -488
  125. package/src/runtime/brand/brand.js +0 -464
  126. package/src/runtime/brand/brand.ts +0 -667
  127. package/src/runtime/services/tokenEstimation.d.ts +0 -187
  128. package/src/runtime/services/tokenEstimation.js +0 -423
  129. package/src/runtime/services/tokenEstimation.ts +0 -547
  130. package/src/runtime/tools/Tool.d.ts +0 -239
  131. package/src/runtime/tools/Tool.js +0 -285
  132. package/src/runtime/tools/Tool.ts +0 -524
  133. package/src/scheduler/TaskScheduler.d.ts +0 -98
  134. package/src/scheduler/TaskScheduler.js +0 -201
  135. package/src/scheduler/TaskScheduler.ts +0 -259
  136. package/src/state/AppStateStore.d.ts +0 -347
  137. package/src/state/AppStateStore.js +0 -439
  138. package/src/state/AppStateStore.ts +0 -658
  139. package/src/state/WorkspaceStateStore.d.ts +0 -43
  140. package/src/state/WorkspaceStateStore.js +0 -224
  141. package/src/state/WorkspaceStateStore.ts +0 -297
  142. package/src/types/message.d.ts +0 -190
  143. package/src/types/message.js +0 -77
  144. package/src/utils/format.d.ts +0 -126
  145. package/src/utils/format.js +0 -230
  146. package/src/utils/fullscreen.d.ts +0 -161
  147. package/src/utils/fullscreen.js +0 -277
  148. package/src/utils/sessionStorage.d.ts +0 -210
  149. package/src/utils/sessionStorage.js +0 -435
  150. package/src/watcher/WorkspaceWatcher.d.ts +0 -70
  151. package/src/watcher/WorkspaceWatcher.js +0 -191
  152. package/src/watcher/WorkspaceWatcher.ts +0 -251
  153. package/src/workspace/loader.d.ts +0 -30
  154. package/src/workspace/loader.js +0 -117
  155. package/src/workspace/types.d.ts +0 -91
  156. package/src/workspace/types.js +0 -7
  157. package/threads/thread_1775361175022.json +0 -9
  158. package/tsconfig.json +0 -14
@@ -0,0 +1,552 @@
1
+ /**
2
+ * Merged Message Types
3
+ *
4
+ * Combines Gizzi's Part-based system with Claude's ContentBlock richness.
5
+ *
6
+ * Philosophy:
7
+ * - Use Gizzi's database-friendly structure (PartBase with IDs)
8
+ * - Add Claude's content types (thinking, redacted_thinking, image)
9
+ * - Maintain Zod validation for runtime safety
10
+ * - Provide adapters for both Claude and Gizzi APIs
11
+ */
12
+
13
+ import z from "zod/v4"
14
+ import { BusEvent } from "@/shared/bus/bus-event"
15
+
16
+ // ============================================================================
17
+ // Base Types (from Gizzi)
18
+ // ============================================================================
19
+
20
+ export const PartBase = z.object({
21
+ id: z.string(),
22
+ sessionID: z.string(),
23
+ messageID: z.string(),
24
+ })
25
+
26
+ export const MessageRole = z.enum(["user", "assistant", "system"])
27
+ export type MessageRole = z.infer<typeof MessageRole>
28
+
29
+ // ============================================================================
30
+ // Content Types (merged from both systems)
31
+ // ============================================================================
32
+
33
+ // Text - Both systems have this
34
+ export const TextPart = PartBase.extend({
35
+ type: z.literal("text"),
36
+ text: z.string(),
37
+ synthetic: z.boolean().optional(),
38
+ ignored: z.boolean().optional(),
39
+ time: z
40
+ .object({
41
+ start: z.number(),
42
+ end: z.number().optional(),
43
+ })
44
+ .optional(),
45
+ metadata: z.record(z.string(), z.any()).optional(),
46
+ })
47
+ export type TextPart = z.infer<typeof TextPart>
48
+
49
+ // Reasoning - Both systems have this
50
+ export const ReasoningPart = PartBase.extend({
51
+ type: z.literal("reasoning"),
52
+ text: z.string(),
53
+ signature: z.string().optional(), // From Claude
54
+ metadata: z.record(z.string(), z.any()).optional(),
55
+ time: z.object({
56
+ start: z.number(),
57
+ end: z.number().optional(),
58
+ }),
59
+ })
60
+ export type ReasoningPart = z.infer<typeof ReasoningPart>
61
+
62
+ // Thinking (Claude's extended reasoning with signature)
63
+ export const ThinkingPart = PartBase.extend({
64
+ type: z.literal("thinking"),
65
+ thinking: z.string(),
66
+ signature: z.string().optional(),
67
+ })
68
+ export type ThinkingPart = z.infer<typeof ThinkingPart>
69
+
70
+ // Redacted Thinking (Claude - for sensitive reasoning)
71
+ export const RedactedThinkingPart = PartBase.extend({
72
+ type: z.literal("redacted_thinking"),
73
+ data: z.string(),
74
+ })
75
+ export type RedactedThinkingPart = z.infer<typeof RedactedThinkingPart>
76
+
77
+ // Tool Use (Claude style)
78
+ export const ToolUsePart = PartBase.extend({
79
+ type: z.literal("tool_use"),
80
+ toolUseId: z.string(),
81
+ name: z.string(),
82
+ input: z.record(z.string(), z.any()),
83
+ })
84
+ export type ToolUsePart = z.infer<typeof ToolUsePart>
85
+
86
+ // Tool Result (Claude style)
87
+ export const ToolResultPart = PartBase.extend({
88
+ type: z.literal("tool_result"),
89
+ toolUseId: z.string(),
90
+ content: z.union([z.string(), z.array(z.record(z.string(), z.any()))]),
91
+ isError: z.boolean().optional(),
92
+ })
93
+ export type ToolResultPart = z.infer<typeof ToolResultPart>
94
+
95
+ // Tool (Gizzi style with state machine)
96
+ export const ToolStatePending = z.object({
97
+ status: z.literal("pending"),
98
+ input: z.record(z.string(), z.any()),
99
+ raw: z.string(),
100
+ })
101
+
102
+ export const ToolStateRunning = z.object({
103
+ status: z.literal("running"),
104
+ input: z.record(z.string(), z.any()),
105
+ title: z.string().optional(),
106
+ metadata: z.record(z.string(), z.any()).optional(),
107
+ time: z.object({ start: z.number() }),
108
+ })
109
+
110
+ export const ToolStateCompleted = z.object({
111
+ status: z.literal("completed"),
112
+ input: z.record(z.string(), z.any()),
113
+ output: z.string(),
114
+ title: z.string(),
115
+ metadata: z.record(z.string(), z.any()),
116
+ time: z.object({
117
+ start: z.number(),
118
+ end: z.number(),
119
+ compacted: z.number().optional(),
120
+ }),
121
+ })
122
+
123
+ export const ToolStateError = z.object({
124
+ status: z.literal("error"),
125
+ input: z.record(z.string(), z.any()),
126
+ error: z.string(),
127
+ metadata: z.record(z.string(), z.any()).optional(),
128
+ time: z.object({ start: z.number(), end: z.number() }),
129
+ })
130
+
131
+ export const ToolState = z.discriminatedUnion("status", [
132
+ ToolStatePending,
133
+ ToolStateRunning,
134
+ ToolStateCompleted,
135
+ ToolStateError,
136
+ ])
137
+ export type ToolState = z.infer<typeof ToolState>
138
+
139
+ export const ToolPart = PartBase.extend({
140
+ type: z.literal("tool"),
141
+ callID: z.string(),
142
+ tool: z.string(),
143
+ state: ToolState,
144
+ metadata: z.record(z.string(), z.any()).optional(),
145
+ })
146
+ export type ToolPart = z.infer<typeof ToolPart>
147
+
148
+ // Image (Claude)
149
+ export const ImagePart = PartBase.extend({
150
+ type: z.literal("image"),
151
+ source: z.discriminatedUnion("type", [
152
+ z.object({
153
+ type: z.literal("base64"),
154
+ media_type: z.string(),
155
+ data: z.string(),
156
+ }),
157
+ z.object({
158
+ type: z.literal("url"),
159
+ url: z.string(),
160
+ }),
161
+ ]),
162
+ })
163
+ export type ImagePart = z.infer<typeof ImagePart>
164
+
165
+ // File (Gizzi)
166
+ export const FilePartSource = z.discriminatedUnion("type", [
167
+ z.object({
168
+ type: z.literal("file"),
169
+ path: z.string(),
170
+ text: z.object({
171
+ value: z.string(),
172
+ start: z.number(),
173
+ end: z.number(),
174
+ }),
175
+ }),
176
+ z.object({
177
+ type: z.literal("symbol"),
178
+ path: z.string(),
179
+ range: z.any(), // LSP.Range
180
+ name: z.string(),
181
+ kind: z.number(),
182
+ text: z.object({
183
+ value: z.string(),
184
+ start: z.number(),
185
+ end: z.number(),
186
+ }),
187
+ }),
188
+ z.object({
189
+ type: z.literal("resource"),
190
+ clientName: z.string(),
191
+ uri: z.string(),
192
+ text: z.object({
193
+ value: z.string(),
194
+ start: z.number(),
195
+ end: z.number(),
196
+ }),
197
+ }),
198
+ ])
199
+
200
+ export const FilePart = PartBase.extend({
201
+ type: z.literal("file"),
202
+ mime: z.string(),
203
+ filename: z.string().optional(),
204
+ url: z.string(),
205
+ source: FilePartSource.optional(),
206
+ })
207
+ export type FilePart = z.infer<typeof FilePart>
208
+
209
+ // Agent (Gizzi)
210
+ export const AgentPart = PartBase.extend({
211
+ type: z.literal("agent"),
212
+ name: z.string(),
213
+ source: z
214
+ .object({
215
+ value: z.string(),
216
+ start: z.number(),
217
+ end: z.number(),
218
+ })
219
+ .optional(),
220
+ })
221
+ export type AgentPart = z.infer<typeof AgentPart>
222
+
223
+ // Step tracking (Gizzi)
224
+ export const StepStartPart = PartBase.extend({
225
+ type: z.literal("step-start"),
226
+ snapshot: z.string().optional(),
227
+ })
228
+ export type StepStartPart = z.infer<typeof StepStartPart>
229
+
230
+ export const StepFinishPart = PartBase.extend({
231
+ type: z.literal("step-finish"),
232
+ reason: z.string().optional().default("unknown"),
233
+ snapshot: z.string().optional(),
234
+ cost: z.number(),
235
+ tokens: z.object({
236
+ total: z.number().optional(),
237
+ input: z.number(),
238
+ output: z.number(),
239
+ reasoning: z.number(),
240
+ cache: z.object({ read: z.number(), write: z.number() }),
241
+ }),
242
+ })
243
+ export type StepFinishPart = z.infer<typeof StepFinishPart>
244
+
245
+ // Compaction (Gizzi)
246
+ export const CompactionPart = PartBase.extend({
247
+ type: z.literal("compaction"),
248
+ auto: z.boolean(),
249
+ })
250
+ export type CompactionPart = z.infer<typeof CompactionPart>
251
+
252
+ // Subtask (Gizzi)
253
+ export const SubtaskPart = PartBase.extend({
254
+ type: z.literal("subtask"),
255
+ prompt: z.string(),
256
+ description: z.string(),
257
+ agent: z.string(),
258
+ model: z
259
+ .object({
260
+ providerID: z.string(),
261
+ modelID: z.string(),
262
+ })
263
+ .optional(),
264
+ command: z.string().optional(),
265
+ })
266
+ export type SubtaskPart = z.infer<typeof SubtaskPart>
267
+
268
+ // Retry (Gizzi)
269
+ export const RetryPart = PartBase.extend({
270
+ type: z.literal("retry"),
271
+ attempt: z.number(),
272
+ error: z.any(), // APIError schema
273
+ time: z.object({ created: z.number() }),
274
+ })
275
+ export type RetryPart = z.infer<typeof RetryPart>
276
+
277
+ // Snapshot (Gizzi)
278
+ export const SnapshotPart = PartBase.extend({
279
+ type: z.literal("snapshot"),
280
+ snapshot: z.string(),
281
+ })
282
+ export type SnapshotPart = z.infer<typeof SnapshotPart>
283
+
284
+ // Patch (Gizzi)
285
+ export const PatchPart = PartBase.extend({
286
+ type: z.literal("patch"),
287
+ hash: z.string(),
288
+ files: z.string().array(),
289
+ })
290
+ export type PatchPart = z.infer<typeof PatchPart>
291
+
292
+ // ============================================================================
293
+ // Unified Part Union
294
+ // ============================================================================
295
+
296
+ export const Part = z.discriminatedUnion("type", [
297
+ // Text content
298
+ TextPart,
299
+
300
+ // Reasoning/thinking
301
+ ReasoningPart,
302
+ ThinkingPart,
303
+ RedactedThinkingPart,
304
+
305
+ // Tool interactions
306
+ ToolUsePart,
307
+ ToolResultPart,
308
+ ToolPart,
309
+
310
+ // Media
311
+ ImagePart,
312
+ FilePart,
313
+
314
+ // Agent/system
315
+ AgentPart,
316
+
317
+ // Execution tracking
318
+ StepStartPart,
319
+ StepFinishPart,
320
+ SubtaskPart,
321
+ RetryPart,
322
+
323
+ // State management
324
+ CompactionPart,
325
+ SnapshotPart,
326
+ PatchPart,
327
+ ])
328
+ export type Part = z.infer<typeof Part>
329
+
330
+ // ============================================================================
331
+ // Message Types
332
+ // ============================================================================
333
+
334
+ export const MessageBase = z.object({
335
+ id: z.string(),
336
+ sessionID: z.string(),
337
+ })
338
+
339
+ export const UserMessage = MessageBase.extend({
340
+ role: z.literal("user"),
341
+ time: z.object({
342
+ created: z.number(),
343
+ }),
344
+ format: z
345
+ .discriminatedUnion("type", [
346
+ z.object({ type: z.literal("text") }),
347
+ z.object({ type: z.literal("json_schema"), schema: z.record(z.string(), z.any()), retryCount: z.number().default(2) }),
348
+ ])
349
+ .optional(),
350
+ summary: z
351
+ .object({
352
+ title: z.string().optional(),
353
+ body: z.string().optional(),
354
+ diffs: z.any().array(), // Snapshot.FileDiff
355
+ })
356
+ .optional(),
357
+ agent: z.string(),
358
+ model: z.object({
359
+ providerID: z.string(),
360
+ modelID: z.string(),
361
+ }),
362
+ system: z.string().optional(),
363
+ tools: z.record(z.string(), z.boolean()).optional(),
364
+ variant: z.string().optional(),
365
+ })
366
+ export type UserMessage = z.infer<typeof UserMessage>
367
+
368
+ export const AssistantMessage = MessageBase.extend({
369
+ role: z.literal("assistant"),
370
+ time: z.object({
371
+ created: z.number(),
372
+ completed: z.number().optional(),
373
+ }),
374
+ error: z
375
+ .object({
376
+ name: z.string(),
377
+ message: z.string(),
378
+ data: z.any().optional(),
379
+ retries: z.number().optional(),
380
+ statusCode: z.number().optional(),
381
+ isRetryable: z.boolean().optional(),
382
+ providerID: z.string().optional(),
383
+ })
384
+ .optional(),
385
+ parentID: z.string(),
386
+ modelID: z.string(),
387
+ providerID: z.string(),
388
+ mode: z.string(),
389
+ agent: z.string(),
390
+ path: z.object({
391
+ cwd: z.string(),
392
+ root: z.string(),
393
+ }),
394
+ summary: z.boolean().optional(),
395
+ cost: z.number(),
396
+ tokens: z.object({
397
+ total: z.number().optional(),
398
+ input: z.number(),
399
+ output: z.number(),
400
+ reasoning: z.number(),
401
+ cache: z.object({ read: z.number(), write: z.number() }),
402
+ }),
403
+ structured: z.any().optional(),
404
+ variant: z.string().optional(),
405
+ finish: z.string().optional(),
406
+ })
407
+ export type AssistantMessage = z.infer<typeof AssistantMessage>
408
+
409
+ export const Message = z.discriminatedUnion("role", [UserMessage, AssistantMessage])
410
+ export type Message = z.infer<typeof Message>
411
+
412
+ // ============================================================================
413
+ // Events
414
+ // ============================================================================
415
+
416
+ export const MessageEvent = {
417
+ Updated: BusEvent.define(
418
+ "message.updated",
419
+ z.object({
420
+ info: Message,
421
+ }),
422
+ ),
423
+ PartUpdated: BusEvent.define(
424
+ "message.part.updated",
425
+ z.object({
426
+ part: Part,
427
+ }),
428
+ ),
429
+ PartDelta: BusEvent.define(
430
+ "message.part.delta",
431
+ z.object({
432
+ partID: z.string(),
433
+ delta: z.record(z.string(), z.any()),
434
+ }),
435
+ ),
436
+ }
437
+
438
+ // ============================================================================
439
+ // Adapter Functions (for interoperability)
440
+ // ============================================================================
441
+
442
+ /**
443
+ * Convert Claude ContentBlock to merged Part
444
+ */
445
+ export function fromClaudeContentBlock(
446
+ block: any,
447
+ base: { id: string; sessionID: string; messageID: string }
448
+ ): Part | null {
449
+ switch (block.type) {
450
+ case "text":
451
+ return TextPart.parse({ ...base, type: "text", text: block.text })
452
+ case "thinking":
453
+ return ThinkingPart.parse({
454
+ ...base,
455
+ type: "thinking",
456
+ thinking: block.thinking,
457
+ signature: block.signature,
458
+ })
459
+ case "redacted_thinking":
460
+ return RedactedThinkingPart.parse({
461
+ ...base,
462
+ type: "redacted_thinking",
463
+ data: block.data,
464
+ })
465
+ case "tool_use":
466
+ return ToolUsePart.parse({
467
+ ...base,
468
+ type: "tool_use",
469
+ toolUseId: block.id || block.toolUseId,
470
+ name: block.name,
471
+ input: block.input,
472
+ })
473
+ case "tool_result":
474
+ return ToolResultPart.parse({
475
+ ...base,
476
+ type: "tool_result",
477
+ toolUseId: block.tool_use_id,
478
+ content: block.content,
479
+ isError: block.is_error,
480
+ })
481
+ case "image":
482
+ return ImagePart.parse({
483
+ ...base,
484
+ type: "image",
485
+ source: block.source,
486
+ })
487
+ default:
488
+ return null
489
+ }
490
+ }
491
+
492
+ /**
493
+ * Convert Gizzi Part to Claude ContentBlock
494
+ */
495
+ export function toClaudeContentBlock(part: Part): any {
496
+ switch (part.type) {
497
+ case "text":
498
+ return { type: "text", text: part.text }
499
+ case "thinking":
500
+ return {
501
+ type: "thinking",
502
+ thinking: part.thinking,
503
+ signature: part.signature,
504
+ }
505
+ case "redacted_thinking":
506
+ return { type: "redacted_thinking", data: part.data }
507
+ case "tool_use":
508
+ return {
509
+ type: "tool_use",
510
+ id: part.toolUseId,
511
+ name: part.name,
512
+ input: part.input,
513
+ }
514
+ case "tool_result":
515
+ return {
516
+ type: "tool_result",
517
+ tool_use_id: part.toolUseId,
518
+ content: part.content,
519
+ is_error: part.isError,
520
+ }
521
+ case "image":
522
+ return { type: "image", source: part.source }
523
+ case "tool":
524
+ // Convert ToolPart to tool_result
525
+ if (part.state.status === "completed") {
526
+ return {
527
+ type: "tool_result",
528
+ tool_use_id: part.callID,
529
+ content: part.state.output,
530
+ }
531
+ }
532
+ return null
533
+ default:
534
+ return null
535
+ }
536
+ }
537
+
538
+ /**
539
+ * Type guards
540
+ */
541
+ export const PartGuards = {
542
+ isText: (p: Part): p is TextPart => p.type === "text",
543
+ isThinking: (p: Part): p is ThinkingPart => p.type === "thinking",
544
+ isRedactedThinking: (p: Part): p is RedactedThinkingPart =>
545
+ p.type === "redacted_thinking",
546
+ isToolUse: (p: Part): p is ToolUsePart => p.type === "tool_use",
547
+ isToolResult: (p: Part): p is ToolResultPart => p.type === "tool_result",
548
+ isTool: (p: Part): p is ToolPart => p.type === "tool",
549
+ isImage: (p: Part): p is ImagePart => p.type === "image",
550
+ isFile: (p: Part): p is FilePart => p.type === "file",
551
+ isReasoning: (p: Part): p is ReasoningPart => p.type === "reasoning",
552
+ }