moi-computer 0.3.0-next.2 → 0.3.0
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.
- package/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/http.ts +1 -1
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/AppRouter.tsx +14 -5
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/routes/WorkspaceRoute.tsx +8 -2
- package/client/app/shell/SidebarLayout.tsx +10 -5
- package/client/assets/openai.svg +3 -0
- package/client/components/shared/BottomPanel.tsx +2 -2
- package/client/components/ui/button.tsx +3 -2
- package/client/components/ui/input.tsx +1 -1
- package/client/features/applets/AppletMount.tsx +44 -0
- package/client/features/applets/WidgetShell.tsx +4 -1
- package/client/features/applets/applet-cache.ts +8 -0
- package/client/features/applets/applet-styles.ts +61 -0
- package/client/features/chat/ChatComposer.tsx +2 -2
- package/client/features/chat/ChatPanel.tsx +8 -25
- package/client/features/chat/ChatPopup.tsx +3 -3
- package/client/features/chat/{ThreadSelector.tsx → ChatSelector.tsx} +4 -4
- package/client/features/chat/TurnView.tsx +8 -9
- package/client/features/chat/api.ts +1 -1
- package/client/features/chat/chat-send.ts +57 -0
- package/client/features/chat/tool-group/ToolCallGroup.tsx +2 -1
- package/client/features/chat/tool-group/format.ts +117 -0
- package/client/features/chat/useChat.ts +10 -34
- package/client/features/connectors/McpMenu.tsx +4 -21
- package/client/features/dev/DevRoutes.tsx +18 -0
- package/client/features/dev/HarnessDebugPage.tsx +468 -0
- package/client/{components/playground → features/dev}/PlaygroundPage.tsx +1 -1
- package/client/features/home/CreateWorkspaceDialog.tsx +64 -158
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
- package/client/features/home/HomeLogo.tsx +344 -0
- package/client/features/home/HomePage.tsx +15 -21
- package/client/features/home/WorkspacePreview.tsx +12 -5
- package/client/features/home/api.ts +11 -3
- package/client/features/home/workspace-presentation.tsx +4 -4
- package/client/features/settings/GeneralSettings.tsx +3 -3
- package/client/features/settings/IconPicker.tsx +4 -3
- package/client/features/settings/icon-picker-options.ts +0 -131
- package/client/features/views/ViewBuilderTab.tsx +153 -0
- package/client/features/views/api.ts +124 -0
- package/client/features/views/useViewBuilderActions.ts +72 -0
- package/client/features/widgets/WidgetGrid.tsx +36 -20
- package/client/features/widgets/Widgets.tsx +140 -90
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -9
- package/client/features/workspace/WorkspaceScreen.tsx +179 -40
- package/client/features/workspace/WorkspaceTabs.tsx +4 -4
- package/client/index.css +0 -35
- package/client/index.html +1 -1
- package/client/lib/app-icon-registry.ts +145 -0
- package/client/runtime/useWorkspaceEvents.ts +3 -1
- package/client/theme.css +1 -1
- package/dist/chunk-4vf1t6v1.js +10 -0
- package/dist/chunk-4z52b2av.css +1 -0
- package/dist/chunk-6c8cwpzc.js +1 -0
- package/dist/chunk-b4b276wx.js +15 -0
- package/dist/{chunk-c4j722at.js → chunk-cs8vbert.js} +2 -2
- package/dist/chunk-fjksw6xf.js +1 -0
- package/dist/chunk-kxmvv1ax.js +48 -0
- package/dist/{chunk-p68fnz3q.js → chunk-vkvb3hjm.js} +1 -1
- package/dist/chunk-y82s1jxm.js +61 -0
- package/dist/chunk-zpxrb1ce.js +2 -0
- package/dist/index.html +2 -2
- package/dist/openai-h13pza4b.svg +3 -0
- package/lib/format.ts +2 -2
- package/lib/types.ts +38 -2
- package/lib/view-builder-meta.ts +35 -0
- package/lib/workspace-layout.ts +14 -0
- package/package.json +2 -1
- package/server/AGENTS.md +3 -3
- package/server/api.ts +165 -51
- package/server/applets.ts +1 -1
- package/server/bundle-queue.ts +19 -0
- package/server/bundler/applet-css.ts +50 -0
- package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
- package/server/cli.ts +79 -2
- package/server/control.ts +106 -8
- package/server/env-apply.ts +2 -2
- package/server/harness/README.md +228 -0
- package/server/harness/claude-code/NOTES.md +578 -0
- package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
- package/server/harness/claude-code/index.ts +124 -0
- package/server/{mcp.ts → harness/claude-code/mcp.ts} +1 -1
- package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
- package/server/harness/claude-code/sessions.ts +42 -0
- package/server/harness/codex/NOTES.md +326 -0
- package/server/harness/codex/adapter.ts +414 -0
- package/server/harness/codex/client.ts +343 -0
- package/server/harness/codex/index.ts +68 -0
- package/server/harness/codex/probe.ts +186 -0
- package/server/harness/codex/session.ts +617 -0
- package/server/harness/debug.ts +57 -0
- package/server/harness/openclaw/NOTES.md +316 -0
- package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
- package/server/harness/openclaw/index.ts +93 -0
- package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
- package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
- package/server/harness/registry.ts +36 -0
- package/server/harness/types.ts +87 -0
- package/server/layout.ts +6 -12
- package/server/moi-scaffold.ts +1 -1
- package/server/registry.ts +14 -52
- package/server/state.ts +5 -38
- package/server/status.ts +7 -46
- package/server/vendor.ts +1 -1
- package/server/view-builders.ts +428 -0
- package/server/views.ts +0 -0
- package/server/web.ts +18 -40
- package/server/workspace-init.ts +6 -6
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
- package/client/assets/hermes-nous.png +0 -0
- package/client/hooks/useScrollFade.ts +0 -38
- package/dist/chunk-23cgr1tz.css +0 -1
- package/dist/chunk-3hy3qy6d.js +0 -10
- package/dist/chunk-dyfaffyz.js +0 -119
- package/dist/chunk-kpe40hm8.js +0 -1
- package/dist/chunk-ty6dvda0.js +0 -1
- package/dist/hermes-nous-pznd63x9.png +0 -0
- /package/client/{components/playground → features/dev}/PixelPainter.tsx +0 -0
- /package/client/{components/playground → features/dev}/ToolCallsPage.tsx +0 -0
- /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
- /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
- /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// Map Codex app-server shapes into our agent-agnostic display format.
|
|
2
|
+
//
|
|
3
|
+
// Codex emits semantic ThreadItems (a command, a patch, an MCP call) with
|
|
4
|
+
// their own lifecycle (`item/started` → `item/completed`), not raw
|
|
5
|
+
// tool_use/tool_result pairs. Each item becomes one Turn: `userMessage` a
|
|
6
|
+
// user turn, everything else an assistant turn; tool-shaped items carry a
|
|
7
|
+
// single `tool-call` part whose state tracks the item's `status`.
|
|
8
|
+
//
|
|
9
|
+
// Type shapes are hand-written against `codex app-server generate-ts`
|
|
10
|
+
// (CLI 0.144.5) and read defensively — see ./NOTES.md.
|
|
11
|
+
import type { Part, StreamEvent, SystemNotice, ToolCall, ToolState, Turn } from '@/lib/format'
|
|
12
|
+
import type { Model, SessionInfo } from '@/lib/types'
|
|
13
|
+
|
|
14
|
+
// ---- protocol shapes (subset we consume) ------------------------------------
|
|
15
|
+
|
|
16
|
+
export type CodexUserInput =
|
|
17
|
+
| { type: 'text'; text: string }
|
|
18
|
+
| { type: 'image'; url: string }
|
|
19
|
+
| { type: 'localImage'; path: string }
|
|
20
|
+
|
|
21
|
+
export type CodexThreadItem = {
|
|
22
|
+
type: string
|
|
23
|
+
id: string
|
|
24
|
+
// userMessage
|
|
25
|
+
clientId?: string | null
|
|
26
|
+
content?: CodexUserInput[]
|
|
27
|
+
// agentMessage / plan
|
|
28
|
+
text?: string
|
|
29
|
+
phase?: string | null
|
|
30
|
+
// reasoning
|
|
31
|
+
summary?: string[]
|
|
32
|
+
// commandExecution
|
|
33
|
+
command?: string
|
|
34
|
+
cwd?: string
|
|
35
|
+
status?: string
|
|
36
|
+
aggregatedOutput?: string | null
|
|
37
|
+
exitCode?: number | null
|
|
38
|
+
durationMs?: number | null
|
|
39
|
+
// Codex's own parse of what the command does (read/listFiles/search/
|
|
40
|
+
// unknown) — one entry per piped command. Drives CC-style semantic labels.
|
|
41
|
+
commandActions?: {
|
|
42
|
+
type?: string
|
|
43
|
+
command?: string
|
|
44
|
+
name?: string
|
|
45
|
+
path?: string
|
|
46
|
+
query?: string | null
|
|
47
|
+
}[]
|
|
48
|
+
// fileChange
|
|
49
|
+
changes?: { path: string; kind?: { type?: string }; diff?: string }[]
|
|
50
|
+
// mcpToolCall
|
|
51
|
+
server?: string
|
|
52
|
+
tool?: string
|
|
53
|
+
arguments?: unknown
|
|
54
|
+
result?: { content?: unknown[]; structuredContent?: unknown } | null
|
|
55
|
+
error?: { message?: string } | null
|
|
56
|
+
// webSearch
|
|
57
|
+
query?: string
|
|
58
|
+
action?: { query?: string | null; queries?: (string | null)[] | null } | null
|
|
59
|
+
// imageGeneration
|
|
60
|
+
revisedPrompt?: string | null
|
|
61
|
+
// collabAgentToolCall (tool reused from mcpToolCall above)
|
|
62
|
+
prompt?: string | null
|
|
63
|
+
senderThreadId?: string
|
|
64
|
+
receiverThreadIds?: string[]
|
|
65
|
+
// subAgentActivity
|
|
66
|
+
kind?: string
|
|
67
|
+
agentThreadId?: string
|
|
68
|
+
agentPath?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type CodexTurn = {
|
|
72
|
+
id: string
|
|
73
|
+
items: CodexThreadItem[]
|
|
74
|
+
status: string
|
|
75
|
+
error?: { message?: string; codexErrorInfo?: unknown } | null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type CodexThread = {
|
|
79
|
+
id: string
|
|
80
|
+
preview?: string
|
|
81
|
+
cwd?: string
|
|
82
|
+
createdAt?: number
|
|
83
|
+
updatedAt?: number
|
|
84
|
+
name?: string | null
|
|
85
|
+
turns?: CodexTurn[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type CodexTokenUsage = {
|
|
89
|
+
total?: { totalTokens?: number; inputTokens?: number; outputTokens?: number }
|
|
90
|
+
last?: { totalTokens?: number; inputTokens?: number; outputTokens?: number }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type CodexModel = {
|
|
94
|
+
id: string
|
|
95
|
+
model: string
|
|
96
|
+
displayName: string
|
|
97
|
+
description?: string
|
|
98
|
+
hidden?: boolean
|
|
99
|
+
supportedReasoningEfforts?: { reasoningEffort: string; description?: string }[]
|
|
100
|
+
defaultReasoningEffort?: string
|
|
101
|
+
isDefault?: boolean
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---- discovery mappings ------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
export function codexThreadToSessionInfo(t: CodexThread): SessionInfo {
|
|
107
|
+
return {
|
|
108
|
+
sessionId: t.id,
|
|
109
|
+
summary: t.name?.trim() || t.preview?.trim() || '',
|
|
110
|
+
// Codex timestamps are unix seconds; SessionInfo wants millis.
|
|
111
|
+
lastModified: (t.updatedAt ?? t.createdAt ?? 0) * 1000,
|
|
112
|
+
cwd: t.cwd
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function codexModelToModel(m: CodexModel): Model {
|
|
117
|
+
const efforts = (m.supportedReasoningEfforts ?? []).map(e => e.reasoningEffort)
|
|
118
|
+
return {
|
|
119
|
+
value: m.id,
|
|
120
|
+
resolvedModel: m.model,
|
|
121
|
+
displayName: m.displayName,
|
|
122
|
+
// Our Model.description is a " · "-joined "<headline> · <tagline>" blurb
|
|
123
|
+
// (the picker renders the first segment as the row label), so lead with
|
|
124
|
+
// the display name and let Codex's one-liner be the tagline.
|
|
125
|
+
...(m.description
|
|
126
|
+
? { description: `${m.displayName} · ${m.description}` }
|
|
127
|
+
: { description: m.displayName }),
|
|
128
|
+
supportsEffort: efforts.length > 0,
|
|
129
|
+
...(efforts.length > 0 ? { supportedEffortLevels: efforts } : {})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ---- item → turn -------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
function statusToToolState(status: string | undefined): ToolState {
|
|
136
|
+
switch (status) {
|
|
137
|
+
case 'inProgress':
|
|
138
|
+
return 'running'
|
|
139
|
+
case 'completed':
|
|
140
|
+
return 'success'
|
|
141
|
+
case 'failed':
|
|
142
|
+
return 'error'
|
|
143
|
+
case 'declined':
|
|
144
|
+
return 'approval-denied'
|
|
145
|
+
default:
|
|
146
|
+
return 'pending'
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function userInputToParts(content: CodexUserInput[] | undefined): Part[] {
|
|
151
|
+
const parts: Part[] = []
|
|
152
|
+
for (const c of content ?? []) {
|
|
153
|
+
if (c.type === 'text' && c.text) parts.push({ type: 'text', text: c.text })
|
|
154
|
+
else if (c.type === 'image' && c.url)
|
|
155
|
+
parts.push({ type: 'file', mediaType: 'image/*', url: c.url })
|
|
156
|
+
else if (c.type === 'localImage' && c.path)
|
|
157
|
+
parts.push({ type: 'text', text: `[image: ${c.path}]` })
|
|
158
|
+
}
|
|
159
|
+
return parts
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Flatten an MCP result's content blocks into a readable string (same
|
|
163
|
+
// approach as the OpenClaw adapter — text blocks joined, others tagged).
|
|
164
|
+
function flattenMcpResult(result: CodexThreadItem['result']): string {
|
|
165
|
+
if (!result) return ''
|
|
166
|
+
if (result.structuredContent !== undefined && result.structuredContent !== null) {
|
|
167
|
+
return JSON.stringify(result.structuredContent, null, 2)
|
|
168
|
+
}
|
|
169
|
+
const blocks = Array.isArray(result.content) ? result.content : []
|
|
170
|
+
return blocks
|
|
171
|
+
.map(b => {
|
|
172
|
+
if (b && typeof b === 'object' && (b as { type?: string }).type === 'text') {
|
|
173
|
+
const t = (b as { text?: unknown }).text
|
|
174
|
+
return typeof t === 'string' ? t : ''
|
|
175
|
+
}
|
|
176
|
+
return b && typeof b === 'object' ? `[${(b as { type?: string }).type ?? 'block'}]` : ''
|
|
177
|
+
})
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.join('\n')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function itemToToolCall(item: CodexThreadItem): ToolCall | null {
|
|
183
|
+
switch (item.type) {
|
|
184
|
+
case 'commandExecution': {
|
|
185
|
+
const call: ToolCall = {
|
|
186
|
+
toolCallId: item.id,
|
|
187
|
+
name: 'exec',
|
|
188
|
+
caller: 'model',
|
|
189
|
+
provider: 'codex',
|
|
190
|
+
state: statusToToolState(item.status),
|
|
191
|
+
input: {
|
|
192
|
+
command: item.command,
|
|
193
|
+
cwd: item.cwd,
|
|
194
|
+
...(item.commandActions?.length ? { commandActions: item.commandActions } : {})
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (item.aggregatedOutput) {
|
|
198
|
+
if (call.state === 'error') call.errorText = item.aggregatedOutput
|
|
199
|
+
else call.output = item.aggregatedOutput
|
|
200
|
+
}
|
|
201
|
+
if (typeof item.exitCode === 'number' || typeof item.durationMs === 'number') {
|
|
202
|
+
call.sidecar = { exitCode: item.exitCode, durationMs: item.durationMs }
|
|
203
|
+
}
|
|
204
|
+
return call
|
|
205
|
+
}
|
|
206
|
+
case 'fileChange': {
|
|
207
|
+
return {
|
|
208
|
+
toolCallId: item.id,
|
|
209
|
+
name: 'apply_patch',
|
|
210
|
+
caller: 'model',
|
|
211
|
+
provider: 'codex',
|
|
212
|
+
state: statusToToolState(item.status),
|
|
213
|
+
input: {
|
|
214
|
+
changes: (item.changes ?? []).map(c => ({
|
|
215
|
+
path: c.path,
|
|
216
|
+
kind: c.kind?.type,
|
|
217
|
+
diff: c.diff
|
|
218
|
+
}))
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
case 'mcpToolCall': {
|
|
223
|
+
const call: ToolCall = {
|
|
224
|
+
toolCallId: item.id,
|
|
225
|
+
name: item.tool ?? 'mcp',
|
|
226
|
+
caller: 'model',
|
|
227
|
+
provider: 'codex',
|
|
228
|
+
mcpServer: item.server,
|
|
229
|
+
state: statusToToolState(item.status),
|
|
230
|
+
input: item.arguments
|
|
231
|
+
}
|
|
232
|
+
const output = flattenMcpResult(item.result)
|
|
233
|
+
if (item.error?.message) {
|
|
234
|
+
call.state = 'error'
|
|
235
|
+
call.errorText = item.error.message
|
|
236
|
+
} else if (output) {
|
|
237
|
+
call.output = output
|
|
238
|
+
}
|
|
239
|
+
return call
|
|
240
|
+
}
|
|
241
|
+
case 'webSearch': {
|
|
242
|
+
// A single item can fan out into several queries (`action.queries`).
|
|
243
|
+
const queries = (item.action?.queries ?? []).filter(
|
|
244
|
+
(q): q is string => typeof q === 'string' && q.length > 0
|
|
245
|
+
)
|
|
246
|
+
return {
|
|
247
|
+
toolCallId: item.id,
|
|
248
|
+
name: 'web_search',
|
|
249
|
+
caller: 'model',
|
|
250
|
+
provider: 'codex',
|
|
251
|
+
// webSearch items have no lifecycle status; they appear when done.
|
|
252
|
+
state: 'success',
|
|
253
|
+
input: { query: item.query, ...(queries.length ? { queries } : {}) }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
case 'plan': {
|
|
257
|
+
return {
|
|
258
|
+
toolCallId: item.id,
|
|
259
|
+
name: 'update_plan',
|
|
260
|
+
caller: 'model',
|
|
261
|
+
provider: 'codex',
|
|
262
|
+
state: 'success',
|
|
263
|
+
input: { plan: item.text }
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Codex multi-agent: the parent's collab tool invocations (spawn / send /
|
|
267
|
+
// wait / close). The child agent runs as its OWN thread whose items
|
|
268
|
+
// stream on the same connection under `agentThreadId` — nesting that
|
|
269
|
+
// transcript into a SubagentRecord is future work; for now the card makes
|
|
270
|
+
// the spawn/wait visible instead of silently dropping it.
|
|
271
|
+
case 'collabAgentToolCall': {
|
|
272
|
+
return {
|
|
273
|
+
toolCallId: item.id,
|
|
274
|
+
name: 'subagent',
|
|
275
|
+
caller: 'subagent',
|
|
276
|
+
provider: 'codex',
|
|
277
|
+
state: statusToToolState(item.status),
|
|
278
|
+
input: {
|
|
279
|
+
action: item.tool,
|
|
280
|
+
...(item.prompt ? { prompt: item.prompt } : {}),
|
|
281
|
+
...(item.receiverThreadIds?.length ? { agents: item.receiverThreadIds } : {})
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
case 'subAgentActivity': {
|
|
286
|
+
// The card that carries the child agent's nested transcript: the
|
|
287
|
+
// session layer correlates the child thread (`agentThreadId`) and
|
|
288
|
+
// attaches a SubagentRecord to this call (see session.ts).
|
|
289
|
+
return {
|
|
290
|
+
toolCallId: item.id,
|
|
291
|
+
name: 'subagent_activity',
|
|
292
|
+
caller: 'subagent',
|
|
293
|
+
provider: 'codex',
|
|
294
|
+
state: 'success',
|
|
295
|
+
input: { kind: item.kind, agentThreadId: item.agentThreadId, agentPath: item.agentPath }
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
case 'enteredReviewMode':
|
|
299
|
+
case 'exitedReviewMode': {
|
|
300
|
+
return {
|
|
301
|
+
toolCallId: item.id,
|
|
302
|
+
name: 'review',
|
|
303
|
+
caller: 'model',
|
|
304
|
+
provider: 'codex',
|
|
305
|
+
state: 'success',
|
|
306
|
+
input: {
|
|
307
|
+
phase: item.type === 'enteredReviewMode' ? 'entered' : 'exited',
|
|
308
|
+
review: item.text ?? (item as { review?: string }).review
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
case 'imageView': {
|
|
313
|
+
return {
|
|
314
|
+
toolCallId: item.id,
|
|
315
|
+
name: 'view_image',
|
|
316
|
+
caller: 'model',
|
|
317
|
+
provider: 'codex',
|
|
318
|
+
state: 'success',
|
|
319
|
+
input: { path: (item as { path?: string }).path }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
case 'imageGeneration': {
|
|
323
|
+
// `revisedPrompt` is the model's final prompt; the item also carries
|
|
324
|
+
// `result` — the ENTIRE generated image as base64 (megabytes). Never
|
|
325
|
+
// fold that into the turn: it would ride every broadcast/replay.
|
|
326
|
+
return {
|
|
327
|
+
toolCallId: item.id,
|
|
328
|
+
name: 'generate_image',
|
|
329
|
+
caller: 'model',
|
|
330
|
+
provider: 'codex',
|
|
331
|
+
state: statusToToolState(item.status),
|
|
332
|
+
input: { ...(item.revisedPrompt ? { prompt: item.revisedPrompt } : {}) }
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
default:
|
|
336
|
+
return null
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Build a Turn from one Codex ThreadItem, or null for item kinds we don't
|
|
341
|
+
// render (contextCompaction becomes a notice — see itemToNotice).
|
|
342
|
+
export function codexItemToTurn(item: CodexThreadItem, threadId: string): Turn | null {
|
|
343
|
+
const turnId = `codex:${threadId}:${item.id}`
|
|
344
|
+
if (item.type === 'userMessage') {
|
|
345
|
+
const parts = userInputToParts(item.content)
|
|
346
|
+
if (parts.length === 0) return null
|
|
347
|
+
return {
|
|
348
|
+
// The echo carries our optimistic id back as `clientId` — reusing it
|
|
349
|
+
// upserts the sender's optimistic bubble in place of a duplicate.
|
|
350
|
+
id: item.clientId || turnId,
|
|
351
|
+
role: 'user',
|
|
352
|
+
origin: { kind: 'user-input' },
|
|
353
|
+
parts
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (item.type === 'agentMessage') {
|
|
357
|
+
if (!item.text) return null
|
|
358
|
+
return {
|
|
359
|
+
id: turnId,
|
|
360
|
+
role: 'assistant',
|
|
361
|
+
origin: { kind: 'user-input' },
|
|
362
|
+
parts: [{ type: 'text', text: item.text }],
|
|
363
|
+
// The item id keys the live token preview; reporting it as the
|
|
364
|
+
// apiMessageId lets the client clear that preview when the turn lands.
|
|
365
|
+
meta: { apiMessageId: item.id }
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (item.type === 'reasoning') {
|
|
369
|
+
const text = (item.summary ?? []).filter(Boolean).join('\n\n')
|
|
370
|
+
if (!text) return null
|
|
371
|
+
return {
|
|
372
|
+
id: turnId,
|
|
373
|
+
role: 'assistant',
|
|
374
|
+
origin: { kind: 'user-input' },
|
|
375
|
+
parts: [{ type: 'reasoning', text }],
|
|
376
|
+
meta: { apiMessageId: item.id }
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const call = itemToToolCall(item)
|
|
380
|
+
if (!call) return null
|
|
381
|
+
return {
|
|
382
|
+
id: turnId,
|
|
383
|
+
role: 'assistant',
|
|
384
|
+
origin: { kind: 'user-input' },
|
|
385
|
+
parts: [{ type: 'tool-call', call }]
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function codexItemToNotice(item: CodexThreadItem, threadId: string): SystemNotice | null {
|
|
390
|
+
if (item.type !== 'contextCompaction') return null
|
|
391
|
+
return {
|
|
392
|
+
id: `codex:${threadId}:${item.id}`,
|
|
393
|
+
kind: 'compact',
|
|
394
|
+
at: new Date().toISOString()
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Static replay path: map a `thread/read`/`thread/resume` payload (turns
|
|
399
|
+
// included) onto StreamEvents for the REST events endpoint.
|
|
400
|
+
export function codexThreadToEvents(thread: CodexThread): StreamEvent[] {
|
|
401
|
+
const events: StreamEvent[] = []
|
|
402
|
+
for (const turn of thread.turns ?? []) {
|
|
403
|
+
for (const item of turn.items ?? []) {
|
|
404
|
+
const t = codexItemToTurn(item, thread.id)
|
|
405
|
+
if (t) {
|
|
406
|
+
events.push({ kind: 'turn', turn: t })
|
|
407
|
+
continue
|
|
408
|
+
}
|
|
409
|
+
const n = codexItemToNotice(item, thread.id)
|
|
410
|
+
if (n) events.push({ kind: 'notice', notice: n })
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return events
|
|
414
|
+
}
|