moi-computer 0.13.1-next.4 → 0.14.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/bin/moi.mjs +10 -6
- package/dist/{chunk-k32585ne.js → chunk-828s864r.js} +61 -61
- package/dist/chunk-9ffaaaw3.css +1 -0
- package/dist/chunk-gh11h6dc.js +2 -0
- package/dist/chunk-hhgsmxsq.js +1 -0
- package/dist/chunk-ht9zmff2.js +5 -0
- package/dist/{chunk-0t8m1ehd.js → chunk-jqa4c92z.js} +2 -2
- package/dist/{chunk-qtkv7hp8.js → chunk-kkhswjz8.js} +2 -2
- package/dist/{chunk-wjbejzek.js → chunk-nqh3kx2x.js} +1 -1
- package/dist/chunk-rb2vsqvb.js +1 -0
- package/dist/{chunk-c8g5x288.js → chunk-t22yw8s6.js} +1 -1
- package/dist/chunk-yv6n9e3z.js +72 -0
- package/dist/dot-2bdkpg3k.png +0 -0
- package/dist/duet-3ab8xyzd.png +0 -0
- package/dist/grok-bot-yv07qj9f.png +0 -0
- package/dist/index.html +1 -1
- package/dist/instinct-ypmq6t0w.png +0 -0
- package/dist/muse-qr7zwsvf.png +0 -0
- package/package.json +39 -40
- package/runtime/applets/chunk-bzxakh65.js +2 -0
- package/runtime/applets/chunk-qhjskz2m.js +2 -0
- package/runtime/applets/collab.js +1 -0
- package/runtime/applets/moi.js +1 -0
- package/runtime/applets/rpc.js +2 -0
- package/runtime/assets/shadcn.css +629 -0
- package/runtime/assets/tw-animate.css +1 -0
- package/runtime/build-worker-entry.js +2 -0
- package/runtime/chunk-00rk365r.js +83 -0
- package/runtime/chunk-4wj1jzhr.js +3 -0
- package/runtime/chunk-5egvk1rz.js +3 -0
- package/runtime/chunk-7c0zbz74.js +3 -0
- package/runtime/chunk-8fvgvm56.js +2 -0
- package/runtime/chunk-c3qyet60.js +128 -0
- package/runtime/chunk-ewc55jga.js +32623 -0
- package/runtime/chunk-gbkjshyt.js +26 -0
- package/runtime/chunk-ggphq7nk.js +66 -0
- package/runtime/chunk-h2bwhk81.js +3 -0
- package/runtime/chunk-hjzfk1cr.js +3 -0
- package/runtime/chunk-j0nd7kw0.js +52 -0
- package/runtime/chunk-jb63ns1z.js +2 -0
- package/runtime/chunk-k049dtaq.js +3 -0
- package/runtime/chunk-kjp60rqs.js +3 -0
- package/runtime/chunk-q06m17nb.js +3 -0
- package/runtime/chunk-r5s8rm8n.js +3 -0
- package/runtime/chunk-sdyqhxe1.js +10 -0
- package/runtime/chunk-w1fx9tsc.js +3 -0
- package/runtime/chunk-w6ksnv8y.js +2 -0
- package/runtime/chunk-wvarpvem.js +78 -0
- package/runtime/chunk-zm7k0v1c.js +3 -0
- package/runtime/chunk-zwvtkb81.js +139 -0
- package/runtime/cli.js +246 -0
- package/runtime/functions-worker.js +2 -0
- package/runtime/gateway-client.js +2 -0
- package/runtime/third-party-notices.txt +6830 -0
- package/runtime/worker.js +2 -0
- package/runtime/xdg-open +1267 -0
- package/bunfig.toml +0 -7
- package/client/AGENTS.md +0 -40
- package/client/api/app-config.ts +0 -58
- package/client/api/http.ts +0 -44
- package/client/api/query-client.ts +0 -5
- package/client/api/query-options.ts +0 -6
- package/client/api/workspace-keys.ts +0 -18
- package/client/app/app-provider.tsx +0 -39
- package/client/app/app-router.tsx +0 -57
- package/client/app/routes/home-route.tsx +0 -27
- package/client/app/routes/onboarding-route.tsx +0 -11
- package/client/app/routes/settings-route.tsx +0 -10
- package/client/app/routes/workspace-registration.tsx +0 -68
- package/client/app/routes/workspace-route.tsx +0 -127
- package/client/app/shell/sidebar-layout.tsx +0 -247
- package/client/assets/claude.svg +0 -3
- package/client/assets/favicon.png +0 -0
- package/client/assets/floppy-disk.webp +0 -0
- package/client/assets/hermes.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/airtable.png +0 -0
- package/client/assets/mcp/apollo.png +0 -0
- package/client/assets/mcp/asana.png +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +0 -33
- package/client/assets/mcp/clickup.png +0 -0
- package/client/assets/mcp/cloudflare.png +0 -0
- package/client/assets/mcp/context7.png +0 -0
- package/client/assets/mcp/datadog.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/dropbox.png +0 -0
- package/client/assets/mcp/elevenlabs.png +0 -0
- package/client/assets/mcp/exa.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/gmail.png +0 -0
- package/client/assets/mcp/googlecalendar.png +0 -0
- package/client/assets/mcp/googledrive.png +0 -0
- package/client/assets/mcp/grafana.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/paper.png +0 -0
- package/client/assets/mcp/paypal.png +0 -0
- package/client/assets/mcp/perplexity.png +0 -0
- package/client/assets/mcp/postgresql.png +0 -0
- package/client/assets/mcp/posthog.png +0 -0
- package/client/assets/mcp/puppeteer.png +0 -0
- package/client/assets/mcp/railway.png +0 -0
- package/client/assets/mcp/redis.png +0 -0
- package/client/assets/mcp/salesforce.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/assets/moi-logo.svg +0 -11
- package/client/assets/openai.svg +0 -1
- package/client/assets/openclaw.svg +0 -22
- package/client/assets.d.ts +0 -14
- package/client/components/shared/agent-blobatar.tsx +0 -93
- package/client/components/shared/bottom-panel.tsx +0 -65
- package/client/components/shared/composer.tsx +0 -125
- package/client/components/shared/led-logo.tsx +0 -181
- package/client/components/shared/panel-header.tsx +0 -16
- package/client/components/shared/reorderable-list.tsx +0 -204
- package/client/components/shared/screen-shell.tsx +0 -23
- package/client/components/shared/ultrafast-icon.tsx +0 -61
- package/client/components/shared/workspace-icon.tsx +0 -83
- package/client/components/ui/alert-dialog.tsx +0 -1
- package/client/components/ui/button.tsx +0 -1
- package/client/components/ui/checkbox.tsx +0 -1
- package/client/components/ui/collapsible.tsx +0 -1
- package/client/components/ui/dialog.tsx +0 -1
- package/client/components/ui/dropdown-menu.tsx +0 -1
- package/client/components/ui/hover-card.tsx +0 -1
- package/client/components/ui/inline-input.tsx +0 -84
- package/client/components/ui/input.tsx +0 -1
- package/client/components/ui/popover.tsx +0 -1
- package/client/components/ui/resizable.tsx +0 -1
- package/client/components/ui/skeleton.tsx +0 -1
- package/client/components/ui/slider.tsx +0 -1
- package/client/components/ui/spinner.tsx +0 -1
- package/client/components/ui/switch.tsx +0 -1
- package/client/components/ui/tabs.tsx +0 -1
- package/client/components/ui/textarea.tsx +0 -1
- package/client/components/ui/toast.tsx +0 -220
- package/client/components/ui/tooltip.tsx +0 -1
- package/client/dev/index.html +0 -43
- package/client/dev/index.ts +0 -15
- package/client/externalize-react.ts +0 -41
- package/client/features/account/account-menu.tsx +0 -96
- package/client/features/account/account-provider.tsx +0 -93
- package/client/features/account/account-test-utils.tsx +0 -310
- package/client/features/account/api.ts +0 -67
- package/client/features/account/profile-actions.ts +0 -29
- package/client/features/app-settings/api.ts +0 -33
- package/client/features/app-settings/avatar-upload.tsx +0 -62
- package/client/features/app-settings/general-settings.tsx +0 -39
- package/client/features/app-settings/profile-settings.tsx +0 -105
- package/client/features/app-settings/settings-page.tsx +0 -45
- package/client/features/app-settings/settings-section.tsx +0 -26
- package/client/features/applets/api.ts +0 -38
- package/client/features/applets/applet-cache.ts +0 -95
- package/client/features/applets/applet-container.tsx +0 -33
- package/client/features/applets/applet-log.ts +0 -81
- package/client/features/applets/applet-runtime.ts +0 -325
- package/client/features/applets/applet-styles.ts +0 -81
- package/client/features/applets/applet-thumbnail.ts +0 -294
- package/client/features/applets/use-applet.ts +0 -210
- package/client/features/applets/widget-error-boundary.tsx +0 -62
- package/client/features/applets/widget-shell.tsx +0 -56
- package/client/features/chat/applet-chat-intents.ts +0 -173
- package/client/features/chat/chat-panel.tsx +0 -326
- package/client/features/chat/chat-popup.tsx +0 -175
- package/client/features/chat/chat-send.ts +0 -259
- package/client/features/chat/chat-store.ts +0 -328
- package/client/features/chat/composer/attachments/attachment-chip.tsx +0 -99
- package/client/features/chat/composer/attachments/draft-attachments.ts +0 -185
- package/client/features/chat/composer/attachments/drawing-attachment-chip.tsx +0 -37
- package/client/features/chat/composer/attachments/file-attachment-chip.tsx +0 -22
- package/client/features/chat/composer/attachments/text-attachment-chip.tsx +0 -11
- package/client/features/chat/composer/attachments/types.ts +0 -25
- package/client/features/chat/composer/attachments/uploads.ts +0 -26
- package/client/features/chat/composer/banners/composer-banner.tsx +0 -16
- package/client/features/chat/composer/banners/error-banner.tsx +0 -36
- package/client/features/chat/composer/banners/skill-update-banner.tsx +0 -93
- package/client/features/chat/composer/chat-composer.tsx +0 -290
- package/client/features/chat/composer/model-order.ts +0 -110
- package/client/features/chat/composer/model-picker.tsx +0 -408
- package/client/features/chat/composer/use-workspace-composer-state.tsx +0 -69
- package/client/features/chat/composer/use-workspace-skill-updates.ts +0 -160
- package/client/features/chat/connection/chat-connection.ts +0 -64
- package/client/features/chat/connection/chat-frames.ts +0 -153
- package/client/features/chat/messages/chat-empty-state.tsx +0 -294
- package/client/features/chat/messages/chat-prompt-bubbles.tsx +0 -72
- package/client/features/chat/messages/fork-history.ts +0 -14
- package/client/features/chat/messages/group-turns.ts +0 -74
- package/client/features/chat/messages/interleave-notices.ts +0 -80
- package/client/features/chat/messages/markdown-content.tsx +0 -89
- package/client/features/chat/messages/preview-turn.ts +0 -37
- package/client/features/chat/messages/shimmer-text.tsx +0 -20
- package/client/features/chat/messages/tool-group/code-block.tsx +0 -41
- package/client/features/chat/messages/tool-group/collapse.tsx +0 -28
- package/client/features/chat/messages/tool-group/detect.ts +0 -93
- package/client/features/chat/messages/tool-group/fixtures.ts +0 -309
- package/client/features/chat/messages/tool-group/format/claude.ts +0 -49
- package/client/features/chat/messages/tool-group/format/codex.ts +0 -130
- package/client/features/chat/messages/tool-group/format/hermes.ts +0 -69
- package/client/features/chat/messages/tool-group/format/index.ts +0 -34
- package/client/features/chat/messages/tool-group/format/mcp.ts +0 -68
- package/client/features/chat/messages/tool-group/format/openclaw.ts +0 -120
- package/client/features/chat/messages/tool-group/format/shared.ts +0 -49
- package/client/features/chat/messages/tool-group/format/shell.ts +0 -162
- package/client/features/chat/messages/tool-group/index.ts +0 -9
- package/client/features/chat/messages/tool-group/read-image-preview.tsx +0 -46
- package/client/features/chat/messages/tool-group/subagent-card.tsx +0 -138
- package/client/features/chat/messages/tool-group/timeline-row.tsx +0 -159
- package/client/features/chat/messages/tool-group/tool-call-group.tsx +0 -279
- package/client/features/chat/messages/tool-group/tool-output.tsx +0 -125
- package/client/features/chat/messages/turn-view.tsx +0 -270
- package/client/features/chat/messages/use-stick-to-bottom.ts +0 -96
- package/client/features/chat/messages/user-message-bubble.tsx +0 -63
- package/client/features/chat/sessions/api.ts +0 -193
- package/client/features/chat/sessions/chat-selector.tsx +0 -399
- package/client/features/chat/sessions/session-view.ts +0 -53
- package/client/features/chat/sessions/use-selected-session.ts +0 -171
- package/client/features/chat/use-chat.ts +0 -229
- package/client/features/collab/applet-api.ts +0 -35
- package/client/features/collab/components/cursors.tsx +0 -241
- package/client/features/collab/components/presence-avatars.tsx +0 -74
- package/client/features/collab/components/presence-frame.tsx +0 -122
- package/client/features/collab/components/presence-group.tsx +0 -31
- package/client/features/collab/components/presence-helpers.ts +0 -50
- package/client/features/collab/components/user-avatar-group.tsx +0 -35
- package/client/features/collab/components/user-avatar.tsx +0 -65
- package/client/features/collab/components/user.tsx +0 -69
- package/client/features/collab/host-state.ts +0 -160
- package/client/features/collab/index.ts +0 -5
- package/client/features/collab/local-user.ts +0 -46
- package/client/features/collab/members/api.ts +0 -17
- package/client/features/collab/members/hooks.ts +0 -97
- package/client/features/collab/members/store.ts +0 -148
- package/client/features/collab/members/types.ts +0 -55
- package/client/features/collab/presence/client.ts +0 -242
- package/client/features/collab/presence/hooks.tsx +0 -160
- package/client/features/collab/presence/presence-publisher.ts +0 -30
- package/client/features/collab/presence/presence-target.ts +0 -8
- package/client/features/collab/presence/provider.tsx +0 -74
- package/client/features/collab/presence/store.ts +0 -156
- package/client/features/collab/presence/users.ts +0 -87
- package/client/features/collab/proxy-user.ts +0 -28
- package/client/features/collab/sharing/agent-invite.tsx +0 -30
- package/client/features/collab/sharing/workspace-members.tsx +0 -269
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +0 -179
- package/client/features/collab/testing/component-fixtures.tsx +0 -54
- package/client/features/collab/testing/fake-engine.ts +0 -120
- package/client/features/connectors/api.ts +0 -25
- package/client/features/connectors/icon-mcp.tsx +0 -21
- package/client/features/connectors/mcp-icons.ts +0 -183
- package/client/features/connectors/mcp-server-cards.tsx +0 -105
- package/client/features/connectors/read-connectors.ts +0 -35
- package/client/features/demo/demo-dialog.tsx +0 -194
- package/client/features/dev/blobatar-shapes-page.tsx +0 -344
- package/client/features/dev/chat-states-fixtures.ts +0 -755
- package/client/features/dev/chat-states-page.tsx +0 -476
- package/client/features/dev/collab/collab-page.tsx +0 -24
- package/client/features/dev/collab/collab-playground.tsx +0 -614
- package/client/features/dev/collab/local-user-settings.tsx +0 -120
- package/client/features/dev/collab/playground-room.ts +0 -33
- package/client/features/dev/dev-index-page.tsx +0 -83
- package/client/features/dev/dev-routes.tsx +0 -43
- package/client/features/dev/harness-debug-page.tsx +0 -607
- package/client/features/dev/onboarding-preview-page.tsx +0 -76
- package/client/features/dev/texture-lab-page.tsx +0 -149
- package/client/features/dev/tool-calls-page.tsx +0 -79
- package/client/features/dev/ui-components/ui-component-previews.tsx +0 -855
- package/client/features/dev/ui-components/ui-components-page.tsx +0 -60
- package/client/features/dev/workspace-setup-mocks.ts +0 -103
- package/client/features/dev/workspace-setup-page.tsx +0 -11
- package/client/features/dev/workspace-setup-preview.tsx +0 -249
- package/client/features/drawings/capture-element.ts +0 -57
- package/client/features/drawings/drawing-layer.tsx +0 -49
- package/client/features/drawings/drawing-toolbar.tsx +0 -95
- package/client/features/drawings/use-chat-annotation.ts +0 -228
- package/client/features/drawings/use-drawing-layer.ts +0 -756
- package/client/features/drawings/use-view-sketch.ts +0 -154
- package/client/features/harness/api.ts +0 -69
- package/client/features/harness/device-login-steps.tsx +0 -103
- package/client/features/harness/harness-login-panel.tsx +0 -232
- package/client/features/harness/harness-presentation.ts +0 -15
- package/client/features/harness/harness-selector.tsx +0 -119
- package/client/features/harness/use-harness-login.ts +0 -77
- package/client/features/home/api.ts +0 -135
- package/client/features/home/home-logo.tsx +0 -344
- package/client/features/home/home-page.tsx +0 -305
- package/client/features/home/shared-workspaces.tsx +0 -70
- package/client/features/home/workspace-invitations.tsx +0 -101
- package/client/features/home/workspace-preview.tsx +0 -213
- package/client/features/identity/host-api.ts +0 -35
- package/client/features/identity/store.ts +0 -26
- package/client/features/identity/types.ts +0 -41
- package/client/features/identity/use-identity.ts +0 -6
- package/client/features/onboarding/agent-setup-step.tsx +0 -57
- package/client/features/onboarding/api.ts +0 -42
- package/client/features/onboarding/onboarding-idea-disk.tsx +0 -129
- package/client/features/onboarding/onboarding-page.tsx +0 -33
- package/client/features/onboarding/onboarding-screen.tsx +0 -20
- package/client/features/onboarding/onboarding-status.tsx +0 -24
- package/client/features/onboarding/workspace-setup-step.tsx +0 -239
- package/client/features/overview/api.ts +0 -28
- package/client/features/overview/default/registry.tsx +0 -34
- package/client/features/overview/default/views-widget.tsx +0 -246
- package/client/features/overview/grid.ts +0 -77
- package/client/features/overview/hidden-panel.tsx +0 -111
- package/client/features/overview/overview.tsx +0 -299
- package/client/features/overview/use-grid-reconcile.ts +0 -94
- package/client/features/overview/widget-canvas.tsx +0 -166
- package/client/features/overview/widget-frame.tsx +0 -77
- package/client/features/overview/workspace-name.tsx +0 -55
- package/client/features/scratchpad/scratch-session.ts +0 -71
- package/client/features/scratchpad/scratchpad-controls.tsx +0 -516
- package/client/features/scratchpad/scratchpad.tsx +0 -360
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +0 -133
- package/client/features/update/api.ts +0 -35
- package/client/features/update/update-control.tsx +0 -102
- package/client/features/views/api.ts +0 -188
- package/client/features/views/pending-view-screen.tsx +0 -303
- package/client/features/views/use-view-actions.ts +0 -119
- package/client/features/views/use-view-drafts.ts +0 -88
- package/client/features/views/view-manager.tsx +0 -293
- package/client/features/views/view-presentation.ts +0 -12
- package/client/features/views/view-residency.ts +0 -77
- package/client/features/views/view-submission.ts +0 -56
- package/client/features/workspace/add/api.ts +0 -61
- package/client/features/workspace/add/create-workspace-dialog.tsx +0 -230
- package/client/features/workspace/add/import-workspace-dialog.tsx +0 -81
- package/client/features/workspace/add/use-workspace-import.ts +0 -61
- package/client/features/workspace/add/workspace-agent-options.ts +0 -53
- package/client/features/workspace/add/workspace-agent-selector.tsx +0 -96
- package/client/features/workspace/add/workspace-dialog-content.tsx +0 -22
- package/client/features/workspace/api.ts +0 -180
- package/client/features/workspace/harness-transition.ts +0 -81
- package/client/features/workspace/moi-context.ts +0 -129
- package/client/features/workspace/remote.ts +0 -34
- package/client/features/workspace/settings/api.ts +0 -112
- package/client/features/workspace/settings/connectors-settings.tsx +0 -110
- package/client/features/workspace/settings/environment-settings.tsx +0 -149
- package/client/features/workspace/settings/general-settings.tsx +0 -180
- package/client/features/workspace/settings/icon-picker-options.ts +0 -30
- package/client/features/workspace/settings/settings-layout.tsx +0 -53
- package/client/features/workspace/settings/use-env-vars.ts +0 -20
- package/client/features/workspace/settings/workspace-icon-picker.tsx +0 -318
- package/client/features/workspace/settings/workspace-settings-dialog.tsx +0 -65
- package/client/features/workspace/setup/workspace-login-state.tsx +0 -56
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -142
- package/client/features/workspace/setup/workspace-setup.tsx +0 -98
- package/client/features/workspace/setup/workspace-welcome-state.tsx +0 -81
- package/client/features/workspace/tab-resolution.ts +0 -32
- package/client/features/workspace/theme-panel.tsx +0 -191
- package/client/features/workspace/unavailable-page.tsx +0 -21
- package/client/features/workspace/use-fits-split-layout.ts +0 -69
- package/client/features/workspace/use-workspace-navigation.ts +0 -265
- package/client/features/workspace/use-workspace-socket.ts +0 -51
- package/client/features/workspace/workspace-content.tsx +0 -597
- package/client/features/workspace/workspace-context.tsx +0 -21
- package/client/features/workspace/workspace-frame.tsx +0 -64
- package/client/features/workspace/workspace-identity.tsx +0 -40
- package/client/features/workspace/workspace-layout-context.tsx +0 -156
- package/client/features/workspace/workspace-menu.tsx +0 -67
- package/client/features/workspace/workspace-pane.tsx +0 -22
- package/client/features/workspace/workspace-pending-screen.tsx +0 -26
- package/client/features/workspace/workspace-preferences.ts +0 -91
- package/client/features/workspace/workspace-presentation.tsx +0 -35
- package/client/features/workspace/workspace-screen.tsx +0 -28
- package/client/features/workspace/workspace-split-layout.tsx +0 -116
- package/client/features/workspace/workspace-state.ts +0 -206
- package/client/features/workspace/workspace-tabs.tsx +0 -233
- package/client/features/workspace/workspace-test-utils.ts +0 -23
- package/client/global.d.ts +0 -5
- package/client/index.css +0 -247
- package/client/index.html +0 -81
- package/client/index.tsx +0 -45
- package/client/lib/agent-availability.ts +0 -14
- package/client/lib/browser-tab-id.ts +0 -4
- package/client/lib/cn.ts +0 -6
- package/client/lib/flags.ts +0 -11
- package/client/lib/identity-icon-registry.ts +0 -150
- package/client/lib/rate-limit.ts +0 -77
- package/client/lib/use-latest-ref.ts +0 -11
- package/client/lib/user-display-name.ts +0 -6
- package/client/lib/ws-url.ts +0 -10
- package/client/main.tsx +0 -43
- package/client/runtime/app-context.ts +0 -20
- package/client/runtime/app-events.ts +0 -75
- package/client/runtime/hmr-watchdog.ts +0 -39
- package/client/runtime/reconnecting-socket.ts +0 -115
- package/client/runtime/use-client-events.ts +0 -69
- package/client/runtime/workspace-theme.ts +0 -175
- package/client/store/ui.ts +0 -94
- package/client/store/workspace-session.ts +0 -30
- package/client/structured-clone-shim.ts +0 -14
- package/client/tailwind-config.ts +0 -43
- package/dist/chunk-851bx8ss.js +0 -72
- package/dist/chunk-cty37f3v.js +0 -1
- package/dist/chunk-dy6f6h3e.js +0 -5
- package/dist/chunk-j6928pwm.js +0 -1
- package/dist/chunk-kffcah9w.css +0 -1
- package/dist/chunk-rh58dc0y.js +0 -2
- package/lib/applet-selector.ts +0 -24
- package/lib/attachment-note.ts +0 -66
- package/lib/chat-title.ts +0 -11
- package/lib/collab/colors.ts +0 -30
- package/lib/collab/protocol.ts +0 -84
- package/lib/collab/types.ts +0 -52
- package/lib/default-widgets.ts +0 -32
- package/lib/events.ts +0 -61
- package/lib/format.ts +0 -348
- package/lib/harness-instructions.ts +0 -30
- package/lib/harness-types.ts +0 -13
- package/lib/identity-icons.ts +0 -73
- package/lib/ids.ts +0 -33
- package/lib/message-attachments.ts +0 -40
- package/lib/moi-attachments.ts +0 -204
- package/lib/moi-context.ts +0 -305
- package/lib/navigation.ts +0 -65
- package/lib/onboarding.ts +0 -41
- package/lib/scratchpad-skew.ts +0 -64
- package/lib/session-drafts.ts +0 -10
- package/lib/speed-mode.ts +0 -5
- package/lib/system-messages.ts +0 -241
- package/lib/themes.ts +0 -241
- package/lib/types.ts +0 -776
- package/lib/update.ts +0 -2
- package/lib/view-build-directives.ts +0 -11
- package/lib/workspace-config.ts +0 -48
- package/lib/workspace-icon.ts +0 -20
- package/lib/workspace-layout.ts +0 -15
- package/lib/workspace-name.ts +0 -17
- package/lib/workspace-tabs.ts +0 -29
- package/server/AGENTS.md +0 -17
- package/server/README.md +0 -123
- package/server/agent-caller.ts +0 -16
- package/server/agent-launcher.ts +0 -27
- package/server/api/harnesses.ts +0 -79
- package/server/api/index.ts +0 -1351
- package/server/api/onboarding.ts +0 -46
- package/server/app-config.ts +0 -264
- package/server/app-settings.ts +0 -69
- package/server/applets/api-base.ts +0 -4
- package/server/applets/applet-css.ts +0 -55
- package/server/applets/build-applet.ts +0 -475
- package/server/applets/build-worker.ts +0 -179
- package/server/applets/bundle-queue.ts +0 -19
- package/server/applets/config.ts +0 -226
- package/server/applets/declarations.ts +0 -45
- package/server/applets/dependencies.ts +0 -206
- package/server/applets/functions-worker.ts +0 -121
- package/server/applets/functions.ts +0 -392
- package/server/applets/index.ts +0 -504
- package/server/applets/log.ts +0 -149
- package/server/applets/runtime/collab.ts +0 -94
- package/server/applets/runtime/moi.ts +0 -35
- package/server/applets/runtime/rpc.ts +0 -15
- package/server/applets/thumbnails.ts +0 -200
- package/server/applets/typecheck.ts +0 -100
- package/server/applets/ui-components.ts +0 -241
- package/server/applets/view-source.ts +0 -73
- package/server/applets/views.ts +0 -323
- package/server/applets/widgets.ts +0 -181
- package/server/cli/applet-selector.ts +0 -19
- package/server/cli/args.ts +0 -5
- package/server/cli/colors.ts +0 -20
- package/server/cli/commands/bundle.ts +0 -119
- package/server/cli/commands/call-server-fn.ts +0 -42
- package/server/cli/commands/check.ts +0 -53
- package/server/cli/commands/config.ts +0 -120
- package/server/cli/commands/debug.ts +0 -119
- package/server/cli/commands/env.ts +0 -162
- package/server/cli/commands/hermes.ts +0 -149
- package/server/cli/commands/init.ts +0 -323
- package/server/cli/commands/navigate.ts +0 -35
- package/server/cli/commands/openclaw.ts +0 -168
- package/server/cli/commands/refresh.ts +0 -45
- package/server/cli/commands/remote.ts +0 -330
- package/server/cli/commands/scratch.ts +0 -496
- package/server/cli/commands/service.ts +0 -298
- package/server/cli/commands/skill.ts +0 -121
- package/server/cli/commands/start.ts +0 -112
- package/server/cli/commands/status.ts +0 -80
- package/server/cli/commands/tabs.ts +0 -36
- package/server/cli/commands/theme.ts +0 -192
- package/server/cli/commands/ui-components.ts +0 -15
- package/server/cli/commands/update.ts +0 -192
- package/server/cli/commands/version.ts +0 -9
- package/server/cli/commands/views.ts +0 -87
- package/server/cli/control.ts +0 -120
- package/server/cli/env.ts +0 -259
- package/server/cli/index.ts +0 -175
- package/server/cli/pc.ts +0 -20
- package/server/cli/provider.ts +0 -25
- package/server/cli/remote-command.ts +0 -77
- package/server/cli/remote-control.ts +0 -73
- package/server/cli/remote-operations.ts +0 -247
- package/server/cli/server-version.ts +0 -16
- package/server/cli/server.ts +0 -93
- package/server/cli/ui-components.ts +0 -294
- package/server/cli/ui.ts +0 -52
- package/server/cli.ts +0 -3
- package/server/collab/cloudflare-access.ts +0 -78
- package/server/collab/config.ts +0 -13
- package/server/collab/manager.ts +0 -413
- package/server/collab/service.ts +0 -136
- package/server/collab/skill/index.ts +0 -7
- package/server/collab/worker-messages.ts +0 -10
- package/server/collab/worker.ts +0 -52
- package/server/constants.ts +0 -13
- package/server/control-client.ts +0 -124
- package/server/control.ts +0 -572
- package/server/data-dir.ts +0 -22
- package/server/debug.ts +0 -10
- package/server/events.ts +0 -25
- package/server/harness/README.md +0 -381
- package/server/harness/acp/NOTES.md +0 -426
- package/server/harness/acp/adapter.ts +0 -206
- package/server/harness/acp/archived.ts +0 -88
- package/server/harness/acp/client.ts +0 -329
- package/server/harness/acp/discovery.ts +0 -127
- package/server/harness/acp/model-state.ts +0 -57
- package/server/harness/acp/run-durations.ts +0 -68
- package/server/harness/acp/session.ts +0 -786
- package/server/harness/acp/wire.ts +0 -132
- package/server/harness/auth.ts +0 -272
- package/server/harness/claude-code/NOTES.md +0 -651
- package/server/harness/claude-code/adapter.ts +0 -876
- package/server/harness/claude-code/auth.ts +0 -178
- package/server/harness/claude-code/cli.ts +0 -42
- package/server/harness/claude-code/git-worktree.ts +0 -35
- package/server/harness/claude-code/index.ts +0 -171
- package/server/harness/claude-code/mcp.ts +0 -152
- package/server/harness/claude-code/models.ts +0 -102
- package/server/harness/claude-code/permissions.ts +0 -34
- package/server/harness/claude-code/run-action.ts +0 -123
- package/server/harness/claude-code/session-title.ts +0 -104
- package/server/harness/claude-code/session.ts +0 -969
- package/server/harness/claude-code/sessions.ts +0 -153
- package/server/harness/codex/NOTES.md +0 -259
- package/server/harness/codex/adapter.ts +0 -633
- package/server/harness/codex/auth.ts +0 -140
- package/server/harness/codex/client.ts +0 -439
- package/server/harness/codex/connectors.ts +0 -92
- package/server/harness/codex/discovery.ts +0 -106
- package/server/harness/codex/index.ts +0 -107
- package/server/harness/codex/pagination.ts +0 -27
- package/server/harness/codex/permissions.ts +0 -80
- package/server/harness/codex/probe.ts +0 -183
- package/server/harness/codex/run-action.ts +0 -93
- package/server/harness/codex/session-title.ts +0 -147
- package/server/harness/codex/session.ts +0 -1196
- package/server/harness/codex/status.ts +0 -31
- package/server/harness/codex/thread-list.ts +0 -78
- package/server/harness/codex/transport.ts +0 -191
- package/server/harness/command.ts +0 -45
- package/server/harness/debug.ts +0 -57
- package/server/harness/detect.ts +0 -164
- package/server/harness/executable.ts +0 -125
- package/server/harness/fork.ts +0 -14
- package/server/harness/hermes/NOTES.md +0 -833
- package/server/harness/hermes/discovery.ts +0 -175
- package/server/harness/hermes/index.ts +0 -167
- package/server/harness/hermes/models.ts +0 -99
- package/server/harness/install.ts +0 -49
- package/server/harness/openclaw/NOTES.md +0 -749
- package/server/harness/openclaw/adapter.ts +0 -336
- package/server/harness/openclaw/compat.ts +0 -95
- package/server/harness/openclaw/cron-view.ts +0 -78
- package/server/harness/openclaw/discovery.ts +0 -456
- package/server/harness/openclaw/gateway.ts +0 -467
- package/server/harness/openclaw/index.ts +0 -125
- package/server/harness/openclaw/session.ts +0 -1512
- package/server/harness/openclaw/strip.ts +0 -184
- package/server/harness/openclaw/thinking.ts +0 -150
- package/server/harness/registry.ts +0 -39
- package/server/harness/run-action.ts +0 -85
- package/server/harness/session-title.ts +0 -59
- package/server/harness/shell-path.ts +0 -89
- package/server/harness/types.ts +0 -170
- package/server/navigation-relay.ts +0 -110
- package/server/onboarding/brief.ts +0 -29
- package/server/onboarding/ideas.ts +0 -48
- package/server/onboarding/jobs.ts +0 -291
- package/server/open-browser.ts +0 -7
- package/server/operations/commands.ts +0 -46
- package/server/operations/files.ts +0 -148
- package/server/operations/server.ts +0 -206
- package/server/remote/agent.ts +0 -103
- package/server/remote/broker-client.ts +0 -76
- package/server/remote/broker.ts +0 -81
- package/server/remote/client.ts +0 -725
- package/server/remote/errors.ts +0 -2
- package/server/remote/routes.ts +0 -121
- package/server/remote/workspace.ts +0 -34
- package/server/scratchpad/assets.ts +0 -258
- package/server/scratchpad/document.ts +0 -312
- package/server/scratchpad/executor.ts +0 -499
- package/server/scratchpad/relay.ts +0 -44
- package/server/scratchpad/shape-defaults.ts +0 -82
- package/server/server-cwd.ts +0 -23
- package/server/service.ts +0 -800
- package/server/sessions/archive.ts +0 -23
- package/server/sessions/attachment-message.ts +0 -95
- package/server/sessions/config.ts +0 -45
- package/server/sessions/lifecycle.ts +0 -19
- package/server/sessions/pending-views.ts +0 -158
- package/server/sessions/selected.ts +0 -113
- package/server/sessions/send-message.ts +0 -102
- package/server/sessions/store.ts +0 -54
- package/server/sessions/view-sessions.ts +0 -192
- package/server/skills/locations.ts +0 -82
- package/server/skills/lock.ts +0 -29
- package/server/skills/template.ts +0 -94
- package/server/skills/update.ts +0 -94
- package/server/skills/version.ts +0 -129
- package/server/skills/workspace.ts +0 -121
- package/server/state.ts +0 -40
- package/server/static.ts +0 -25
- package/server/status.ts +0 -110
- package/server/tldraw-package.d.ts +0 -4
- package/server/update.ts +0 -429
- package/server/uploads.ts +0 -290
- package/server/vendor.ts +0 -63
- package/server/version.ts +0 -41
- package/server/web.ts +0 -350
- package/server/workspace-state/file.ts +0 -181
- package/server/workspace-state/index.ts +0 -169
- package/server/workspace-state/lock.ts +0 -42
- package/server/workspace-state/types.ts +0 -16
- package/server/workspaces/api.ts +0 -24
- package/server/workspaces/change-harness.ts +0 -77
- package/server/workspaces/config.ts +0 -42
- package/server/workspaces/env-apply.ts +0 -20
- package/server/workspaces/env.ts +0 -424
- package/server/workspaces/harness-transition.ts +0 -29
- package/server/workspaces/icon.ts +0 -13
- package/server/workspaces/import.ts +0 -74
- package/server/workspaces/init.ts +0 -74
- package/server/workspaces/layout.ts +0 -190
- package/server/workspaces/preview.ts +0 -72
- package/server/workspaces/registry.ts +0 -330
- package/server/workspaces/required-env.ts +0 -19
- package/server/workspaces/scaffold.ts +0 -189
- package/server/workspaces/shared.ts +0 -74
- package/server/workspaces/tabs.ts +0 -35
- package/server/workspaces/theme.ts +0 -58
- package/tsconfig.json +0 -20
|
@@ -1,1196 +0,0 @@
|
|
|
1
|
-
import type { SpeedMode } from '@/lib/types'
|
|
2
|
-
import type { MessageAttachment } from '@/lib/types'
|
|
3
|
-
import { attachmentLabel } from '@/lib/moi-attachments'
|
|
4
|
-
// Live state per (workspaceId, sessionId): display history, native lifecycle,
|
|
5
|
-
// and previews. client.ts owns the shared workspace process;
|
|
6
|
-
// Codex owns durable history. See NOTES.md for ordering and recovery rules.
|
|
7
|
-
import {
|
|
8
|
-
prepareAttachmentMessage,
|
|
9
|
-
type PreparedAttachmentMessage
|
|
10
|
-
} from '../../sessions/attachment-message'
|
|
11
|
-
import { buildSessionTitleSource } from '../session-title'
|
|
12
|
-
import {
|
|
13
|
-
type MoiContext,
|
|
14
|
-
appendMoiContext,
|
|
15
|
-
renderMoiContext,
|
|
16
|
-
renderMoiContextBody
|
|
17
|
-
} from '@/lib/moi-context'
|
|
18
|
-
import { type SubagentRecord, type Turn, applyEvent, emptyViewState } from '@/lib/format'
|
|
19
|
-
import type { SessionActivity, StreamEvent, ViewState } from '@/lib/types'
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
type CodexThread,
|
|
23
|
-
type CodexThreadItem,
|
|
24
|
-
type CodexTokenUsage,
|
|
25
|
-
type CodexTurn,
|
|
26
|
-
type SubagentReplay,
|
|
27
|
-
codexServiceTierForSpeedMode,
|
|
28
|
-
codexItemToNotice,
|
|
29
|
-
codexItemToTurn,
|
|
30
|
-
codexThreadToEvents,
|
|
31
|
-
withCodexTurnDuration
|
|
32
|
-
} from './adapter'
|
|
33
|
-
import {
|
|
34
|
-
type CodexClient,
|
|
35
|
-
getCodexClient,
|
|
36
|
-
getCodexModelCatalog,
|
|
37
|
-
interruptCodexTurn,
|
|
38
|
-
readSubagentRecords
|
|
39
|
-
} from './client'
|
|
40
|
-
import { CodexRpcError } from './transport'
|
|
41
|
-
import {
|
|
42
|
-
CODEX_LOCAL_CONTROL_CONTEXT,
|
|
43
|
-
CODEX_LOCAL_CONTROL_FALLBACK,
|
|
44
|
-
CODEX_THREAD_ACCESS,
|
|
45
|
-
CODEX_TURN_ACCESS
|
|
46
|
-
} from './permissions'
|
|
47
|
-
import { generateCodexSessionTitle, renameCodexSessionIfUnchanged } from './session-title'
|
|
48
|
-
import { harnessStore } from '../auth'
|
|
49
|
-
import { debug } from '../../debug'
|
|
50
|
-
import { broadcast } from '../../state'
|
|
51
|
-
import { hasSessionConfig, saveSessionConfig } from '../../sessions/config'
|
|
52
|
-
import { renameSessionReferences } from '../../sessions/lifecycle'
|
|
53
|
-
|
|
54
|
-
type CodexUserInputItem = { type: 'text'; text: string } | { type: 'image'; url: string }
|
|
55
|
-
|
|
56
|
-
// A child agent thread nested under this session (Codex multi-agent): the
|
|
57
|
-
// child's items stream on the same connection under its own threadId, and we
|
|
58
|
-
// fold them into a SubagentRecord on the parent's `subagent_activity` card.
|
|
59
|
-
type ChildThread = {
|
|
60
|
-
toolCallId: string // the parent card carrying the nested transcript
|
|
61
|
-
record: SubagentRecord
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
type SessionRecord = {
|
|
65
|
-
client: CodexClient
|
|
66
|
-
lastTouched: number
|
|
67
|
-
workspaceId: string
|
|
68
|
-
workspacePath: string
|
|
69
|
-
sessionId: string // real Codex thread id once known (rekeyed on rename)
|
|
70
|
-
view: ViewState
|
|
71
|
-
activeTurnId: string | null
|
|
72
|
-
processing: boolean
|
|
73
|
-
waiting: boolean
|
|
74
|
-
activity: SessionActivity
|
|
75
|
-
model?: string
|
|
76
|
-
// Live token streaming opt-in from the latest chat frame. Codex always
|
|
77
|
-
// streams deltas; this gates whether we forward them as preview frames.
|
|
78
|
-
stream: boolean
|
|
79
|
-
// Cumulative preview text per item id (agentMessage / reasoning summary).
|
|
80
|
-
previews: Map<string, { kind: 'text' | 'reasoning'; text: string }>
|
|
81
|
-
// Usage from `thread/tokenUsage/updated`, folded into the last assistant
|
|
82
|
-
// turn when the turn completes.
|
|
83
|
-
lastUsage: CodexTokenUsage | null
|
|
84
|
-
usageTurnId: string | null
|
|
85
|
-
completedTurns: Set<string>
|
|
86
|
-
bufferedNotifications: [string, Record<string, unknown>][] | null
|
|
87
|
-
previewTimer: Timer | null
|
|
88
|
-
dirtyPreviews: Set<string>
|
|
89
|
-
commandOutput: Map<string, string>
|
|
90
|
-
commandOutputTimer: Timer | null
|
|
91
|
-
// Child agent threads keyed by their thread id (see ChildThread).
|
|
92
|
-
children: Map<string, ChildThread>
|
|
93
|
-
refreshSessionsOnTurnComplete: boolean
|
|
94
|
-
sessionTitleSource: string | undefined
|
|
95
|
-
sessionTitleAbort: AbortController | null
|
|
96
|
-
unsubscribe?: () => void
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const sessions = new Map<string, SessionRecord>() // key: `${workspaceId}:${sessionId}`
|
|
100
|
-
// `${workspaceId}:${tempId}` -> native thread id after session:renamed.
|
|
101
|
-
const aliases = new Map<string, string>()
|
|
102
|
-
const resumes = new Map<string, Promise<SessionRecord>>()
|
|
103
|
-
type SendLane = { tail: Promise<void>; generation: number }
|
|
104
|
-
const sendLanes = new Map<string, SendLane>()
|
|
105
|
-
const SESSION_IDLE_TTL_MS = 30 * 60_000
|
|
106
|
-
|
|
107
|
-
// The provider keeps durable history. Release transcript copies and listeners
|
|
108
|
-
// from chats that nobody has used recently; opening one subscribes again.
|
|
109
|
-
const evictionTimer = setInterval(() => {
|
|
110
|
-
const cutoff = Date.now() - SESSION_IDLE_TTL_MS
|
|
111
|
-
for (const [key, rec] of sessions) {
|
|
112
|
-
if (
|
|
113
|
-
rec.lastTouched > cutoff ||
|
|
114
|
-
rec.processing ||
|
|
115
|
-
rec.bufferedNotifications ||
|
|
116
|
-
rec.sessionTitleAbort
|
|
117
|
-
)
|
|
118
|
-
continue
|
|
119
|
-
rec.unsubscribe?.()
|
|
120
|
-
clearPreviews(rec)
|
|
121
|
-
sessions.delete(key)
|
|
122
|
-
const lane = sendLanes.get(key)
|
|
123
|
-
for (const [laneKey, candidate] of sendLanes) {
|
|
124
|
-
if (candidate === lane) sendLanes.delete(laneKey)
|
|
125
|
-
}
|
|
126
|
-
for (const [alias, sessionId] of aliases) {
|
|
127
|
-
if (recKey(rec.workspaceId, sessionId) === key && alias.startsWith(`${rec.workspaceId}:`))
|
|
128
|
-
aliases.delete(alias)
|
|
129
|
-
}
|
|
130
|
-
void rec.client.rpc('thread/unsubscribe', { threadId: rec.sessionId }).catch(() => {})
|
|
131
|
-
}
|
|
132
|
-
}, 60_000)
|
|
133
|
-
evictionTimer.unref()
|
|
134
|
-
|
|
135
|
-
function sendLane(workspaceId: string, sessionId: string): SendLane {
|
|
136
|
-
const key = liveKey(workspaceId, sessionId)
|
|
137
|
-
let lane = sendLanes.get(key)
|
|
138
|
-
if (!lane) {
|
|
139
|
-
lane = { tail: Promise.resolve(), generation: 0 }
|
|
140
|
-
sendLanes.set(key, lane)
|
|
141
|
-
}
|
|
142
|
-
return lane
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function recKey(workspaceId: string, sessionId: string): string {
|
|
146
|
-
return `${workspaceId}:${sessionId}`
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function liveKey(workspaceId: string, sessionId: string): string {
|
|
150
|
-
const direct = recKey(workspaceId, sessionId)
|
|
151
|
-
if (sessions.has(direct)) return direct
|
|
152
|
-
const real = aliases.get(direct)
|
|
153
|
-
return real ? recKey(workspaceId, real) : direct
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export type CodexActiveSession = {
|
|
157
|
-
workspaceId: string
|
|
158
|
-
workspacePath: string
|
|
159
|
-
sessionId: string
|
|
160
|
-
activity: SessionActivity
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function getCodexActiveSessions(): CodexActiveSession[] {
|
|
164
|
-
const out: CodexActiveSession[] = []
|
|
165
|
-
for (const s of sessions.values()) {
|
|
166
|
-
if (s.processing) {
|
|
167
|
-
out.push({
|
|
168
|
-
workspaceId: s.workspaceId,
|
|
169
|
-
workspacePath: s.workspacePath,
|
|
170
|
-
sessionId: s.sessionId,
|
|
171
|
-
activity: sessionActivity(s)
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return out
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// The workspace connector panel has no selected-chat parameter. Use the most
|
|
179
|
-
// recently observed loaded chat to obtain runtime health instead of auth alone.
|
|
180
|
-
export function getLatestCodexSessionId(workspaceId: string): string | undefined {
|
|
181
|
-
let latest: SessionRecord | undefined
|
|
182
|
-
for (const rec of sessions.values()) {
|
|
183
|
-
if (
|
|
184
|
-
rec.workspaceId === workspaceId &&
|
|
185
|
-
!rec.bufferedNotifications &&
|
|
186
|
-
(!latest || rec.lastTouched >= latest.lastTouched)
|
|
187
|
-
)
|
|
188
|
-
latest = rec
|
|
189
|
-
}
|
|
190
|
-
return latest?.sessionId
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function setProcessing(rec: SessionRecord, processing: boolean, turnId: string | null) {
|
|
194
|
-
rec.activeTurnId = turnId
|
|
195
|
-
rec.processing = processing
|
|
196
|
-
if (!processing) rec.waiting = false
|
|
197
|
-
publishActivity(rec)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function sessionActivity(rec: SessionRecord): SessionActivity {
|
|
201
|
-
return rec.waiting ? 'requires-action' : rec.processing ? 'running' : 'idle'
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function publishActivity(rec: SessionRecord) {
|
|
205
|
-
const activity = sessionActivity(rec)
|
|
206
|
-
if (rec.activity === activity) return
|
|
207
|
-
rec.activity = activity
|
|
208
|
-
broadcast(rec.workspaceId, {
|
|
209
|
-
type: 'session:status',
|
|
210
|
-
sessionId: rec.sessionId,
|
|
211
|
-
activity
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function waitingOnInput(status: CodexThread['status']): boolean {
|
|
216
|
-
return (
|
|
217
|
-
status?.type === 'active' &&
|
|
218
|
-
Boolean(
|
|
219
|
-
status.activeFlags?.some(
|
|
220
|
-
flag => flag === 'waitingOnApproval' || flag === 'waitingOnUserInput'
|
|
221
|
-
)
|
|
222
|
-
)
|
|
223
|
-
)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function releaseSession(rec: SessionRecord, reason: string) {
|
|
227
|
-
flushCommandOutput(rec)
|
|
228
|
-
clearPreviews(rec)
|
|
229
|
-
settleTools(rec, reason)
|
|
230
|
-
setProcessing(rec, false, null)
|
|
231
|
-
rec.sessionTitleAbort?.abort()
|
|
232
|
-
rec.sessionTitleAbort = null
|
|
233
|
-
rec.unsubscribe?.()
|
|
234
|
-
const key = recKey(rec.workspaceId, rec.sessionId)
|
|
235
|
-
if (sessions.get(key) === rec) sessions.delete(key)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function emitTurnEvent(rec: SessionRecord, ev: StreamEvent) {
|
|
239
|
-
rec.view = applyEvent(rec.view, ev)
|
|
240
|
-
broadcast(rec.workspaceId, { ...ev, sessionId: rec.sessionId })
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function ingestItem(rec: SessionRecord, item: CodexThreadItem) {
|
|
244
|
-
const turn = codexItemToTurn(item, rec.sessionId)
|
|
245
|
-
if (turn) {
|
|
246
|
-
turn.timestamp =
|
|
247
|
-
rec.view.turns.find(existing => existing.id === turn.id)?.timestamp ??
|
|
248
|
-
new Date().toISOString()
|
|
249
|
-
// subAgentActivity announces a child agent thread: register it so its
|
|
250
|
-
// item stream (arriving under `agentThreadId`) nests into this card's
|
|
251
|
-
// SubagentRecord, CC-style.
|
|
252
|
-
if (item.type === 'subAgentActivity' && item.agentThreadId) {
|
|
253
|
-
const existing = rec.children.get(item.agentThreadId)
|
|
254
|
-
const child: ChildThread = existing ?? {
|
|
255
|
-
toolCallId: item.id,
|
|
256
|
-
record: {
|
|
257
|
-
taskId: item.agentThreadId,
|
|
258
|
-
description: item.agentPath?.split('/').pop() || 'sub-agent',
|
|
259
|
-
progress: [],
|
|
260
|
-
status: 'running',
|
|
261
|
-
transcript: []
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (item.kind === 'completed' || item.kind === 'closed') child.record.status = 'completed'
|
|
265
|
-
if (item.kind === 'failed') child.record.status = 'failed'
|
|
266
|
-
rec.children.set(item.agentThreadId, child)
|
|
267
|
-
attachSubagent(turn, child.record)
|
|
268
|
-
}
|
|
269
|
-
emitTurnEvent(rec, { kind: 'turn', turn })
|
|
270
|
-
return
|
|
271
|
-
}
|
|
272
|
-
const notice = codexItemToNotice(item, rec.sessionId)
|
|
273
|
-
if (notice) emitTurnEvent(rec, { kind: 'notice', notice })
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Fold the child's SubagentRecord into the tool-call part of its parent card.
|
|
277
|
-
function attachSubagent(turn: Turn, record: SubagentRecord) {
|
|
278
|
-
const part = turn.parts.find(p => p.type === 'tool-call')
|
|
279
|
-
if (part?.type === 'tool-call') part.call.subagent = record
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// A child-thread notification: upsert the child's items into its
|
|
283
|
-
// SubagentRecord transcript and re-emit the parent card so the nested lane
|
|
284
|
-
// updates live.
|
|
285
|
-
function handleChildNotification(
|
|
286
|
-
rec: SessionRecord,
|
|
287
|
-
child: ChildThread,
|
|
288
|
-
childThreadId: string,
|
|
289
|
-
method: string,
|
|
290
|
-
params: Record<string, unknown>
|
|
291
|
-
) {
|
|
292
|
-
if (method === 'item/started' || method === 'item/completed') {
|
|
293
|
-
const item = params.item as CodexThreadItem | undefined
|
|
294
|
-
if (!item) return
|
|
295
|
-
// The child's own `subAgentActivity` (its send-back to the parent) would
|
|
296
|
-
// render as a cryptic nested agent card — skip it, matching the replay
|
|
297
|
-
// path (childThreadToSubagentRecord).
|
|
298
|
-
if (item.type === 'subAgentActivity') return
|
|
299
|
-
const turn = codexItemToTurn(item, childThreadId)
|
|
300
|
-
if (!turn) return
|
|
301
|
-
const idx = child.record.transcript.findIndex(t => t.id === turn.id)
|
|
302
|
-
if (idx >= 0) child.record.transcript[idx] = turn
|
|
303
|
-
else child.record.transcript.push(turn)
|
|
304
|
-
// Progress: keep the latest assistant text as the "what it's doing" line.
|
|
305
|
-
if (method === 'item/completed' && item.type === 'agentMessage' && item.text) {
|
|
306
|
-
child.record.progress = [item.text.slice(0, 200)]
|
|
307
|
-
}
|
|
308
|
-
} else if (method === 'thread/tokenUsage/updated') {
|
|
309
|
-
const usage = (params.tokenUsage ?? null) as CodexTokenUsage | null
|
|
310
|
-
if (usage?.total?.totalTokens !== undefined) {
|
|
311
|
-
child.record.usage = { ...child.record.usage, totalTokens: usage.total.totalTokens }
|
|
312
|
-
}
|
|
313
|
-
} else if (method === 'turn/completed') {
|
|
314
|
-
const turn = params.turn as CodexTurn | undefined
|
|
315
|
-
if (turn?.status === 'failed') child.record.status = 'failed'
|
|
316
|
-
else if (child.record.status === 'running') child.record.status = 'completed'
|
|
317
|
-
} else {
|
|
318
|
-
return
|
|
319
|
-
}
|
|
320
|
-
// Re-emit the parent card so the nested transcript renders live.
|
|
321
|
-
const owner = rec.view.turns.find(t =>
|
|
322
|
-
t.parts.some(p => p.type === 'tool-call' && p.call.toolCallId === child.toolCallId)
|
|
323
|
-
)
|
|
324
|
-
if (owner) {
|
|
325
|
-
attachSubagent(owner, child.record)
|
|
326
|
-
emitTurnEvent(rec, { kind: 'turn', turn: owner })
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function forwardPreview(
|
|
331
|
-
rec: SessionRecord,
|
|
332
|
-
itemId: string,
|
|
333
|
-
kind: 'text' | 'reasoning',
|
|
334
|
-
delta: string
|
|
335
|
-
) {
|
|
336
|
-
if (!rec.stream) return
|
|
337
|
-
const entry = rec.previews.get(itemId) ?? { kind, text: '' }
|
|
338
|
-
entry.text += delta
|
|
339
|
-
rec.previews.set(itemId, entry)
|
|
340
|
-
rec.dirtyPreviews.add(itemId)
|
|
341
|
-
// Coalesce tokens to reduce repeated cumulative payloads and client updates.
|
|
342
|
-
rec.previewTimer ??= setTimeout(() => flushPreviews(rec), 40)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function flushPreviews(rec: SessionRecord) {
|
|
346
|
-
if (rec.previewTimer) clearTimeout(rec.previewTimer)
|
|
347
|
-
rec.previewTimer = null
|
|
348
|
-
for (const itemId of rec.dirtyPreviews) {
|
|
349
|
-
const entry = rec.previews.get(itemId)
|
|
350
|
-
if (!entry) continue
|
|
351
|
-
broadcast(rec.workspaceId, {
|
|
352
|
-
type: 'session:preview',
|
|
353
|
-
sessionId: rec.sessionId,
|
|
354
|
-
messageId: itemId,
|
|
355
|
-
parentToolUseId: null,
|
|
356
|
-
blocks: [{ index: 0, kind: entry.kind, text: entry.text }]
|
|
357
|
-
})
|
|
358
|
-
}
|
|
359
|
-
rec.dirtyPreviews.clear()
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function clearPreviews(rec: SessionRecord) {
|
|
363
|
-
if (rec.previewTimer) clearTimeout(rec.previewTimer)
|
|
364
|
-
rec.previewTimer = null
|
|
365
|
-
rec.dirtyPreviews.clear()
|
|
366
|
-
rec.previews.clear()
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const LIVE_OUTPUT_LIMIT = 64 * 1024
|
|
370
|
-
|
|
371
|
-
function flushCommandOutput(rec: SessionRecord) {
|
|
372
|
-
if (rec.commandOutputTimer) clearTimeout(rec.commandOutputTimer)
|
|
373
|
-
rec.commandOutputTimer = null
|
|
374
|
-
for (const [itemId, delta] of rec.commandOutput) {
|
|
375
|
-
const owner = rec.view.turns.find(turn =>
|
|
376
|
-
turn.parts.some(
|
|
377
|
-
part =>
|
|
378
|
-
part.type === 'tool-call' &&
|
|
379
|
-
part.call.toolCallId === itemId &&
|
|
380
|
-
part.call.name === 'exec' &&
|
|
381
|
-
part.call.state === 'running'
|
|
382
|
-
)
|
|
383
|
-
)
|
|
384
|
-
if (!owner) continue
|
|
385
|
-
const parts = owner.parts.map(part => {
|
|
386
|
-
if (
|
|
387
|
-
part.type !== 'tool-call' ||
|
|
388
|
-
part.call.toolCallId !== itemId ||
|
|
389
|
-
part.call.state !== 'running'
|
|
390
|
-
)
|
|
391
|
-
return part
|
|
392
|
-
const output = `${typeof part.call.output === 'string' ? part.call.output : ''}${delta}`
|
|
393
|
-
return {
|
|
394
|
-
...part,
|
|
395
|
-
call: {
|
|
396
|
-
...part.call,
|
|
397
|
-
output:
|
|
398
|
-
output.length > LIVE_OUTPUT_LIMIT
|
|
399
|
-
? `[Earlier live output omitted]\n${output.slice(-LIVE_OUTPUT_LIMIT)}`
|
|
400
|
-
: output
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
})
|
|
404
|
-
emitTurnEvent(rec, { kind: 'turn', turn: { ...owner, parts } })
|
|
405
|
-
}
|
|
406
|
-
rec.commandOutput.clear()
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function clearCommandOutput(rec: SessionRecord) {
|
|
410
|
-
if (rec.commandOutputTimer) clearTimeout(rec.commandOutputTimer)
|
|
411
|
-
rec.commandOutputTimer = null
|
|
412
|
-
rec.commandOutput.clear()
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
function settleTools(rec: SessionRecord, reason: string) {
|
|
416
|
-
for (const turn of rec.view.turns) {
|
|
417
|
-
let changed = false
|
|
418
|
-
const parts = turn.parts.map(part => {
|
|
419
|
-
if (
|
|
420
|
-
part.type !== 'tool-call' ||
|
|
421
|
-
!['running', 'pending', 'approval-pending'].includes(part.call.state)
|
|
422
|
-
)
|
|
423
|
-
return part
|
|
424
|
-
changed = true
|
|
425
|
-
return { ...part, call: { ...part.call, state: 'error' as const, errorText: reason } }
|
|
426
|
-
})
|
|
427
|
-
if (changed) emitTurnEvent(rec, { kind: 'turn', turn: { ...turn, parts } })
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Fold native completion metadata into the newest assistant turn so replay and
|
|
432
|
-
// live rendering use the same display shape. Re-emits that turn (upsert-by-id).
|
|
433
|
-
function applyCompletionMeta(
|
|
434
|
-
rec: SessionRecord,
|
|
435
|
-
turnId: string | undefined,
|
|
436
|
-
durationMs: number | null | undefined
|
|
437
|
-
) {
|
|
438
|
-
const last = rec.usageTurnId === turnId ? rec.lastUsage?.last : undefined
|
|
439
|
-
for (let i = rec.view.turns.length - 1; i >= 0; i--) {
|
|
440
|
-
const t = rec.view.turns[i]
|
|
441
|
-
if (t.role === 'user' && t.origin.kind === 'user-input') return
|
|
442
|
-
if (t.role !== 'assistant') continue
|
|
443
|
-
let updated = withCodexTurnDuration(t, durationMs)
|
|
444
|
-
if (last) {
|
|
445
|
-
updated = {
|
|
446
|
-
...updated,
|
|
447
|
-
meta: {
|
|
448
|
-
...updated.meta,
|
|
449
|
-
usage: {
|
|
450
|
-
inputTokens: last.inputTokens,
|
|
451
|
-
outputTokens: last.outputTokens,
|
|
452
|
-
totalTokens: last.totalTokens
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (updated === t) return
|
|
458
|
-
emitTurnEvent(rec, { kind: 'turn', turn: updated })
|
|
459
|
-
return
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// A failed send may reflect an external logout. Refresh the cached banner now.
|
|
464
|
-
function refreshAvailability(workspaceId: string, workspacePath: string) {
|
|
465
|
-
void harnessStore.refresh({ id: workspaceId, path: workspacePath, harness: 'codex' })
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function handleNotification(rec: SessionRecord, method: string, params: Record<string, unknown>) {
|
|
469
|
-
if (method === '__exit') {
|
|
470
|
-
// The app-server died (crash or env-change restart). Drop the record so
|
|
471
|
-
// the next message re-resumes against a fresh process.
|
|
472
|
-
if (rec.processing)
|
|
473
|
-
broadcast(rec.workspaceId, {
|
|
474
|
-
kind: 'error',
|
|
475
|
-
sessionId: rec.sessionId,
|
|
476
|
-
content:
|
|
477
|
-
typeof params.message === 'string'
|
|
478
|
-
? params.message
|
|
479
|
-
: 'ChatGPT disconnected. Send another message to resume this chat.'
|
|
480
|
-
})
|
|
481
|
-
releaseSession(rec, 'ChatGPT disconnected before this tool returned a result')
|
|
482
|
-
return
|
|
483
|
-
}
|
|
484
|
-
if (rec.bufferedNotifications) {
|
|
485
|
-
rec.bufferedNotifications.push([method, params])
|
|
486
|
-
return
|
|
487
|
-
}
|
|
488
|
-
const mcpFailure = method === 'mcpServer/startupStatus/updated' && params.status === 'failed'
|
|
489
|
-
if (
|
|
490
|
-
(method === 'warning' || method === 'configWarning' || mcpFailure) &&
|
|
491
|
-
(params.threadId == null || params.threadId === rec.sessionId)
|
|
492
|
-
) {
|
|
493
|
-
const message = mcpFailure
|
|
494
|
-
? `MCP ${String(params.name ?? 'server')} failed to start${typeof params.error === 'string' ? `: ${params.error}` : ''}`
|
|
495
|
-
: method === 'warning'
|
|
496
|
-
? params.message
|
|
497
|
-
: params.summary
|
|
498
|
-
if (typeof message === 'string')
|
|
499
|
-
emitTurnEvent(rec, {
|
|
500
|
-
kind: 'notice',
|
|
501
|
-
notice: {
|
|
502
|
-
id: `codex:${rec.sessionId}:warning:${message}`,
|
|
503
|
-
kind: 'warning',
|
|
504
|
-
at: new Date().toISOString(),
|
|
505
|
-
message
|
|
506
|
-
}
|
|
507
|
-
})
|
|
508
|
-
return
|
|
509
|
-
}
|
|
510
|
-
// Child agent threads stream on the same connection under their own ids —
|
|
511
|
-
// route them into the parent's SubagentRecord.
|
|
512
|
-
if (typeof params.threadId === 'string' && params.threadId !== rec.sessionId) {
|
|
513
|
-
const child = rec.children.get(params.threadId)
|
|
514
|
-
if (child) handleChildNotification(rec, child, params.threadId, method, params)
|
|
515
|
-
return
|
|
516
|
-
}
|
|
517
|
-
if (params.threadId !== rec.sessionId) return
|
|
518
|
-
rec.lastTouched = Date.now()
|
|
519
|
-
|
|
520
|
-
switch (method) {
|
|
521
|
-
case 'model/rerouted': {
|
|
522
|
-
if (typeof params.toModel !== 'string') return
|
|
523
|
-
rec.model = params.toModel
|
|
524
|
-
emitTurnEvent(rec, {
|
|
525
|
-
kind: 'notice',
|
|
526
|
-
notice: {
|
|
527
|
-
id: `codex:${rec.sessionId}:model:${String(params.turnId)}`,
|
|
528
|
-
kind: 'model-change',
|
|
529
|
-
at: new Date().toISOString(),
|
|
530
|
-
model: params.toModel,
|
|
531
|
-
...(typeof params.fromModel === 'string' ? { prev: params.fromModel } : {})
|
|
532
|
-
}
|
|
533
|
-
})
|
|
534
|
-
return
|
|
535
|
-
}
|
|
536
|
-
case 'turn/plan/updated': {
|
|
537
|
-
if (!Array.isArray(params.plan) || typeof params.turnId !== 'string') return
|
|
538
|
-
const steps = params.plan.flatMap((step: unknown) => {
|
|
539
|
-
if (!step || typeof step !== 'object' || !('step' in step) || typeof step.step !== 'string')
|
|
540
|
-
return []
|
|
541
|
-
const status = 'status' in step ? step.status : undefined
|
|
542
|
-
return [
|
|
543
|
-
`${status === 'completed' ? '[x]' : status === 'inProgress' ? '[→]' : '[ ]'} ${step.step}`
|
|
544
|
-
]
|
|
545
|
-
})
|
|
546
|
-
ingestItem(rec, {
|
|
547
|
-
type: 'plan',
|
|
548
|
-
id: `${params.turnId}:plan`,
|
|
549
|
-
text: [typeof params.explanation === 'string' ? params.explanation : '', ...steps]
|
|
550
|
-
.filter(Boolean)
|
|
551
|
-
.join('\n')
|
|
552
|
-
})
|
|
553
|
-
return
|
|
554
|
-
}
|
|
555
|
-
case 'item/started':
|
|
556
|
-
case 'item/completed': {
|
|
557
|
-
const item = params.item as CodexThreadItem | undefined
|
|
558
|
-
if (!item) return
|
|
559
|
-
if (method === 'item/completed') {
|
|
560
|
-
rec.commandOutput.delete(item.id)
|
|
561
|
-
rec.previews.delete(item.id)
|
|
562
|
-
rec.dirtyPreviews.delete(item.id)
|
|
563
|
-
}
|
|
564
|
-
ingestItem(rec, item)
|
|
565
|
-
return
|
|
566
|
-
}
|
|
567
|
-
case 'item/commandExecution/outputDelta': {
|
|
568
|
-
if (typeof params.itemId !== 'string' || typeof params.delta !== 'string') return
|
|
569
|
-
const output = (rec.commandOutput.get(params.itemId) ?? '') + params.delta
|
|
570
|
-
rec.commandOutput.set(
|
|
571
|
-
params.itemId,
|
|
572
|
-
output.length > LIVE_OUTPUT_LIMIT
|
|
573
|
-
? `[Earlier live output omitted]\n${output.slice(-LIVE_OUTPUT_LIMIT)}`
|
|
574
|
-
: output
|
|
575
|
-
)
|
|
576
|
-
rec.commandOutputTimer ??= setTimeout(() => flushCommandOutput(rec), 40)
|
|
577
|
-
return
|
|
578
|
-
}
|
|
579
|
-
case 'item/agentMessage/delta': {
|
|
580
|
-
forwardPreview(rec, params.itemId as string, 'text', String(params.delta ?? ''))
|
|
581
|
-
return
|
|
582
|
-
}
|
|
583
|
-
case 'item/reasoning/summaryTextDelta': {
|
|
584
|
-
forwardPreview(rec, params.itemId as string, 'reasoning', String(params.delta ?? ''))
|
|
585
|
-
return
|
|
586
|
-
}
|
|
587
|
-
case 'item/reasoning/summaryPartAdded': {
|
|
588
|
-
// Match replay's summary separator without adding a leading blank line.
|
|
589
|
-
if (rec.previews.has(params.itemId as string)) {
|
|
590
|
-
forwardPreview(rec, params.itemId as string, 'reasoning', '\n')
|
|
591
|
-
}
|
|
592
|
-
return
|
|
593
|
-
}
|
|
594
|
-
case 'thread/tokenUsage/updated': {
|
|
595
|
-
rec.lastUsage = (params.tokenUsage ?? null) as CodexTokenUsage | null
|
|
596
|
-
rec.usageTurnId = typeof params.turnId === 'string' ? params.turnId : rec.activeTurnId
|
|
597
|
-
return
|
|
598
|
-
}
|
|
599
|
-
case 'turn/started': {
|
|
600
|
-
const turn = params.turn as CodexTurn | undefined
|
|
601
|
-
if (turn?.id && rec.completedTurns.has(turn.id)) return
|
|
602
|
-
if (rec.activeTurnId !== turn?.id) {
|
|
603
|
-
rec.lastUsage = null
|
|
604
|
-
rec.usageTurnId = null
|
|
605
|
-
}
|
|
606
|
-
setProcessing(rec, true, turn?.id ?? rec.activeTurnId)
|
|
607
|
-
return
|
|
608
|
-
}
|
|
609
|
-
case 'turn/completed': {
|
|
610
|
-
const turn = params.turn as CodexTurn | undefined
|
|
611
|
-
if (turn?.id && rec.completedTurns.has(turn.id)) return
|
|
612
|
-
if (turn?.id) {
|
|
613
|
-
rec.completedTurns.add(turn.id)
|
|
614
|
-
if (rec.completedTurns.size > 64)
|
|
615
|
-
rec.completedTurns.delete(rec.completedTurns.values().next().value!)
|
|
616
|
-
}
|
|
617
|
-
// A delayed completion from an older turn must not stop a newer one.
|
|
618
|
-
if (rec.activeTurnId && turn?.id && rec.activeTurnId !== turn.id) return
|
|
619
|
-
flushCommandOutput(rec)
|
|
620
|
-
for (const item of turn?.items ?? []) ingestItem(rec, item)
|
|
621
|
-
settleTools(
|
|
622
|
-
rec,
|
|
623
|
-
turn?.status === 'interrupted'
|
|
624
|
-
? 'Stopped'
|
|
625
|
-
: 'ChatGPT ended the turn before this tool returned a result'
|
|
626
|
-
)
|
|
627
|
-
clearPreviews(rec)
|
|
628
|
-
applyCompletionMeta(rec, turn?.id, turn?.durationMs)
|
|
629
|
-
setProcessing(rec, false, null)
|
|
630
|
-
if (rec.refreshSessionsOnTurnComplete) {
|
|
631
|
-
rec.refreshSessionsOnTurnComplete = false
|
|
632
|
-
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
633
|
-
}
|
|
634
|
-
if (turn?.status === 'failed' && turn.error?.message) {
|
|
635
|
-
broadcast(rec.workspaceId, {
|
|
636
|
-
kind: 'error',
|
|
637
|
-
sessionId: rec.sessionId,
|
|
638
|
-
content: turn.error.message
|
|
639
|
-
})
|
|
640
|
-
refreshAvailability(rec.workspaceId, rec.workspacePath)
|
|
641
|
-
}
|
|
642
|
-
// An externally-interrupted turn otherwise ends silently, identical to a
|
|
643
|
-
// clean completion — surface the stop so the client can render it.
|
|
644
|
-
if (turn?.status === 'interrupted') {
|
|
645
|
-
broadcast(rec.workspaceId, { kind: 'stopped', sessionId: rec.sessionId })
|
|
646
|
-
}
|
|
647
|
-
return
|
|
648
|
-
}
|
|
649
|
-
case 'error': {
|
|
650
|
-
const err = params.error as { message?: string } | undefined
|
|
651
|
-
const message = err?.message ?? (typeof params.message === 'string' ? params.message : '')
|
|
652
|
-
if (params.willRetry === true) {
|
|
653
|
-
// The provider still owns a running turn and will retry it. Do not
|
|
654
|
-
// expose a Retry button that would submit the user's message again.
|
|
655
|
-
emitTurnEvent(rec, {
|
|
656
|
-
kind: 'notice',
|
|
657
|
-
notice: {
|
|
658
|
-
id: `codex:${rec.sessionId}:retry:${String(params.turnId ?? rec.activeTurnId)}`,
|
|
659
|
-
kind: 'api-retry',
|
|
660
|
-
at: new Date().toISOString(),
|
|
661
|
-
error: message
|
|
662
|
-
}
|
|
663
|
-
})
|
|
664
|
-
return
|
|
665
|
-
}
|
|
666
|
-
if (params.turnId && rec.activeTurnId && params.turnId !== rec.activeTurnId) return
|
|
667
|
-
if (message) {
|
|
668
|
-
broadcast(rec.workspaceId, { kind: 'error', sessionId: rec.sessionId, content: message })
|
|
669
|
-
refreshAvailability(rec.workspaceId, rec.workspacePath)
|
|
670
|
-
}
|
|
671
|
-
// A top-level error without a following turn/completed would otherwise
|
|
672
|
-
// leave the session busy forever — the error is terminal for the turn.
|
|
673
|
-
setProcessing(rec, false, null)
|
|
674
|
-
clearPreviews(rec)
|
|
675
|
-
flushCommandOutput(rec)
|
|
676
|
-
settleTools(rec, message || 'ChatGPT ended the turn before this tool returned a result')
|
|
677
|
-
return
|
|
678
|
-
}
|
|
679
|
-
case 'thread/status/changed': {
|
|
680
|
-
const status = params.status as CodexThread['status']
|
|
681
|
-
rec.waiting = waitingOnInput(status)
|
|
682
|
-
if (status?.type === 'active') setProcessing(rec, true, rec.activeTurnId)
|
|
683
|
-
else if (status?.type === 'notLoaded') {
|
|
684
|
-
releaseSession(rec, 'ChatGPT unloaded this chat')
|
|
685
|
-
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
686
|
-
} else if (status?.type === 'idle' || status?.type === 'systemError') {
|
|
687
|
-
flushCommandOutput(rec)
|
|
688
|
-
setProcessing(rec, false, null)
|
|
689
|
-
clearPreviews(rec)
|
|
690
|
-
}
|
|
691
|
-
return
|
|
692
|
-
}
|
|
693
|
-
case 'thread/closed':
|
|
694
|
-
case 'thread/archived':
|
|
695
|
-
case 'thread/deleted': {
|
|
696
|
-
releaseSession(rec, 'ChatGPT closed this chat')
|
|
697
|
-
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
698
|
-
return
|
|
699
|
-
}
|
|
700
|
-
case 'thread/unarchived':
|
|
701
|
-
case 'thread/name/updated': {
|
|
702
|
-
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
703
|
-
return
|
|
704
|
-
}
|
|
705
|
-
// Reuse the notice id so completion updates the hook's started row.
|
|
706
|
-
case 'hook/started':
|
|
707
|
-
case 'hook/completed': {
|
|
708
|
-
const run = params.run as
|
|
709
|
-
| {
|
|
710
|
-
id?: string
|
|
711
|
-
eventName?: string
|
|
712
|
-
status?: string
|
|
713
|
-
entries?: { kind?: string; text?: string }[]
|
|
714
|
-
}
|
|
715
|
-
| undefined
|
|
716
|
-
if (!run?.id) return
|
|
717
|
-
const output = (run.entries ?? [])
|
|
718
|
-
.map(e => e.text)
|
|
719
|
-
.filter(Boolean)
|
|
720
|
-
.join('\n')
|
|
721
|
-
emitTurnEvent(rec, {
|
|
722
|
-
kind: 'notice',
|
|
723
|
-
notice: {
|
|
724
|
-
id: `codex:${rec.sessionId}:hook:${run.id}`,
|
|
725
|
-
kind: 'hook',
|
|
726
|
-
at: new Date().toISOString(),
|
|
727
|
-
hookId: run.id,
|
|
728
|
-
hookName: run.eventName ?? 'hook',
|
|
729
|
-
event: run.eventName ?? '',
|
|
730
|
-
status: method === 'hook/started' ? 'started' : 'response',
|
|
731
|
-
...(output ? { output } : {}),
|
|
732
|
-
...(method === 'hook/completed'
|
|
733
|
-
? { outcome: run.status === 'failed' ? ('error' as const) : ('success' as const) }
|
|
734
|
-
: {})
|
|
735
|
-
}
|
|
736
|
-
})
|
|
737
|
-
return
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
function isCurrentCodexSession(rec: SessionRecord, abort: AbortController): boolean {
|
|
743
|
-
return !abort.signal.aborted && sessions.get(recKey(rec.workspaceId, rec.sessionId)) === rec
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
function startCodexSessionTitleJob(rec: SessionRecord, client: CodexClient) {
|
|
747
|
-
if (!rec.sessionTitleSource) return
|
|
748
|
-
const source = rec.sessionTitleSource
|
|
749
|
-
rec.sessionTitleSource = undefined
|
|
750
|
-
const abort = new AbortController()
|
|
751
|
-
rec.sessionTitleAbort = abort
|
|
752
|
-
|
|
753
|
-
void (async () => {
|
|
754
|
-
try {
|
|
755
|
-
const title = await generateCodexSessionTitle({
|
|
756
|
-
source,
|
|
757
|
-
abortController: abort
|
|
758
|
-
})
|
|
759
|
-
if (!title || !isCurrentCodexSession(rec, abort)) return
|
|
760
|
-
|
|
761
|
-
const renamed = await renameCodexSessionIfUnchanged({
|
|
762
|
-
client,
|
|
763
|
-
threadId: rec.sessionId,
|
|
764
|
-
title,
|
|
765
|
-
isCurrent: () => isCurrentCodexSession(rec, abort)
|
|
766
|
-
})
|
|
767
|
-
if (!renamed || !isCurrentCodexSession(rec, abort)) return
|
|
768
|
-
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
769
|
-
debug(
|
|
770
|
-
`codex session title ws=${rec.workspaceId} thread=${rec.sessionId} title=${JSON.stringify(title)}`
|
|
771
|
-
)
|
|
772
|
-
} catch (err) {
|
|
773
|
-
debug(
|
|
774
|
-
`codex session title failed ws=${rec.workspaceId} thread=${rec.sessionId}: ${err instanceof Error ? err.message : String(err)}`
|
|
775
|
-
)
|
|
776
|
-
} finally {
|
|
777
|
-
if (rec.sessionTitleAbort === abort) rec.sessionTitleAbort = null
|
|
778
|
-
}
|
|
779
|
-
})()
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
function createRecord(input: {
|
|
783
|
-
workspaceId: string
|
|
784
|
-
workspacePath: string
|
|
785
|
-
sessionId: string
|
|
786
|
-
client: CodexClient
|
|
787
|
-
refreshSessionsOnTurnComplete?: boolean
|
|
788
|
-
sessionTitleSource?: string
|
|
789
|
-
}): SessionRecord {
|
|
790
|
-
const rec: SessionRecord = {
|
|
791
|
-
client: input.client,
|
|
792
|
-
lastTouched: Date.now(),
|
|
793
|
-
workspaceId: input.workspaceId,
|
|
794
|
-
workspacePath: input.workspacePath,
|
|
795
|
-
sessionId: input.sessionId,
|
|
796
|
-
view: emptyViewState(),
|
|
797
|
-
activeTurnId: null,
|
|
798
|
-
processing: false,
|
|
799
|
-
waiting: false,
|
|
800
|
-
activity: 'idle',
|
|
801
|
-
stream: false,
|
|
802
|
-
previews: new Map(),
|
|
803
|
-
children: new Map(),
|
|
804
|
-
lastUsage: null,
|
|
805
|
-
usageTurnId: null,
|
|
806
|
-
completedTurns: new Set(),
|
|
807
|
-
bufferedNotifications: null,
|
|
808
|
-
previewTimer: null,
|
|
809
|
-
dirtyPreviews: new Set(),
|
|
810
|
-
commandOutput: new Map(),
|
|
811
|
-
commandOutputTimer: null,
|
|
812
|
-
refreshSessionsOnTurnComplete: input.refreshSessionsOnTurnComplete === true,
|
|
813
|
-
sessionTitleSource: input.sessionTitleSource,
|
|
814
|
-
sessionTitleAbort: null
|
|
815
|
-
}
|
|
816
|
-
rec.unsubscribe = input.client.onNotification((method, params) =>
|
|
817
|
-
handleNotification(rec, method, params)
|
|
818
|
-
)
|
|
819
|
-
sessions.set(recKey(rec.workspaceId, rec.sessionId), rec)
|
|
820
|
-
return rec
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// Seed a record's view from a resumed thread payload (turns included).
|
|
824
|
-
function seedFromThread(
|
|
825
|
-
rec: SessionRecord,
|
|
826
|
-
thread: CodexThread,
|
|
827
|
-
subagents?: Map<string, SubagentReplay>
|
|
828
|
-
) {
|
|
829
|
-
let view = emptyViewState()
|
|
830
|
-
for (const ev of codexThreadToEvents(thread, subagents)) view = applyEvent(view, ev)
|
|
831
|
-
for (const notice of rec.view.notices) view = applyEvent(view, { kind: 'notice', notice })
|
|
832
|
-
rec.view = view
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
type ResumeInput = { workspaceId: string; workspacePath: string; sessionId: string }
|
|
836
|
-
|
|
837
|
-
async function resumeSession(input: ResumeInput): Promise<SessionRecord> {
|
|
838
|
-
const key = liveKey(input.workspaceId, input.sessionId)
|
|
839
|
-
const pending = resumes.get(key)
|
|
840
|
-
if (pending) return pending
|
|
841
|
-
const existing = sessions.get(key)
|
|
842
|
-
if (existing) return existing
|
|
843
|
-
const loading = (async () => {
|
|
844
|
-
const client = await getCodexClient(input.workspacePath)
|
|
845
|
-
// Subscribe before resuming. Live frames may arrive before the RPC reply,
|
|
846
|
-
// or while child transcripts are loading; replay them after the snapshot.
|
|
847
|
-
const rec = createRecord({ ...input, client })
|
|
848
|
-
rec.bufferedNotifications = []
|
|
849
|
-
try {
|
|
850
|
-
const resumed = await client.rpc<{ thread: CodexThread; model?: string }>('thread/resume', {
|
|
851
|
-
threadId: input.sessionId,
|
|
852
|
-
...CODEX_THREAD_ACCESS
|
|
853
|
-
})
|
|
854
|
-
const subagents = await readSubagentRecords(client, resumed.thread)
|
|
855
|
-
rec.model = resumed.model
|
|
856
|
-
if (!client.isAlive()) throw new Error('ChatGPT disconnected while resuming this chat')
|
|
857
|
-
for (const [childId, sub] of subagents) rec.children.set(childId, sub)
|
|
858
|
-
seedFromThread(rec, resumed.thread, subagents)
|
|
859
|
-
const active = resumed.thread.turns?.findLast(turn => turn.status === 'inProgress')
|
|
860
|
-
rec.waiting = waitingOnInput(resumed.thread.status)
|
|
861
|
-
setProcessing(
|
|
862
|
-
rec,
|
|
863
|
-
Boolean(active) || resumed.thread.status?.type === 'active',
|
|
864
|
-
active?.id ?? null
|
|
865
|
-
)
|
|
866
|
-
const buffered = rec.bufferedNotifications
|
|
867
|
-
rec.bufferedNotifications = null
|
|
868
|
-
for (const [method, params] of buffered) handleNotification(rec, method, params)
|
|
869
|
-
if (sessions.get(key) !== rec) throw new Error('ChatGPT closed this chat while resuming it')
|
|
870
|
-
return rec
|
|
871
|
-
} catch (error) {
|
|
872
|
-
clearPreviews(rec)
|
|
873
|
-
clearCommandOutput(rec)
|
|
874
|
-
rec.unsubscribe?.()
|
|
875
|
-
if (sessions.get(key) === rec) sessions.delete(key)
|
|
876
|
-
throw error
|
|
877
|
-
}
|
|
878
|
-
})()
|
|
879
|
-
resumes.set(key, loading)
|
|
880
|
-
try {
|
|
881
|
-
return await loading
|
|
882
|
-
} finally {
|
|
883
|
-
if (resumes.get(key) === loading) resumes.delete(key)
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
function buildUserInput(message: PreparedAttachmentMessage): CodexUserInputItem[] {
|
|
888
|
-
const images = message.attachments.filter(
|
|
889
|
-
attachment => attachment.type === 'image' && 'data' in attachment
|
|
890
|
-
)
|
|
891
|
-
const input: CodexUserInputItem[] = images.map(image => ({
|
|
892
|
-
type: 'image',
|
|
893
|
-
url: `data:${image.mediaType};base64,${image.data.toString('base64')}`
|
|
894
|
-
}))
|
|
895
|
-
if (message.text) input.push({ type: 'text', text: message.text })
|
|
896
|
-
return input
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
type CodexSendInput = {
|
|
900
|
-
workspaceId: string
|
|
901
|
-
workspacePath: string
|
|
902
|
-
sessionId: string
|
|
903
|
-
isNew: boolean
|
|
904
|
-
content: string
|
|
905
|
-
attachments?: MessageAttachment[]
|
|
906
|
-
optimisticId?: string
|
|
907
|
-
model?: string
|
|
908
|
-
effort?: string
|
|
909
|
-
speedMode?: SpeedMode
|
|
910
|
-
stream?: boolean
|
|
911
|
-
// Rendered through native additionalContext or the legacy text envelope.
|
|
912
|
-
context?: MoiContext
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
export function sendCodexMessage(input: CodexSendInput): Promise<void> {
|
|
916
|
-
const lane = sendLane(input.workspaceId, input.sessionId)
|
|
917
|
-
const generation = lane.generation
|
|
918
|
-
const sent = lane.tail.then(async () => {
|
|
919
|
-
if (lane.generation !== generation) return
|
|
920
|
-
await sendMessage(input, lane, generation)
|
|
921
|
-
})
|
|
922
|
-
// Serialise acceptance, not entire model turns. A second send can steer as
|
|
923
|
-
// soon as the first start is acknowledged, and failures never poison a lane.
|
|
924
|
-
lane.tail = sent.catch(() => {})
|
|
925
|
-
return sent
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
async function sendMessage(
|
|
929
|
-
input: CodexSendInput,
|
|
930
|
-
lane: SendLane,
|
|
931
|
-
generation: number
|
|
932
|
-
): Promise<void> {
|
|
933
|
-
const prepared = prepareAttachmentMessage(input.workspaceId, input.content, input.attachments)
|
|
934
|
-
if (!prepared.text) return
|
|
935
|
-
const sessionTitleSource = input.isNew
|
|
936
|
-
? buildSessionTitleSource(input.content, prepared.attachments.map(attachmentLabel))
|
|
937
|
-
: undefined
|
|
938
|
-
const userInput = buildUserInput(prepared)
|
|
939
|
-
const { parts } = prepared
|
|
940
|
-
const serviceTier = codexServiceTierForSpeedMode(input.speedMode)
|
|
941
|
-
|
|
942
|
-
let rec: SessionRecord
|
|
943
|
-
try {
|
|
944
|
-
const existing = sessions.get(liveKey(input.workspaceId, input.sessionId))
|
|
945
|
-
if (existing && !existing.bufferedNotifications) rec = existing
|
|
946
|
-
else if (input.isNew && !aliases.has(recKey(input.workspaceId, input.sessionId))) {
|
|
947
|
-
const client = await getCodexClient(input.workspacePath)
|
|
948
|
-
const started = await client.rpc<{ thread: CodexThread; model?: string }>('thread/start', {
|
|
949
|
-
cwd: input.workspacePath,
|
|
950
|
-
...CODEX_THREAD_ACCESS,
|
|
951
|
-
...(input.model ? { model: input.model } : {}),
|
|
952
|
-
serviceTier
|
|
953
|
-
})
|
|
954
|
-
const realId = started.thread.id
|
|
955
|
-
if (realId !== input.sessionId) {
|
|
956
|
-
aliases.set(recKey(input.workspaceId, input.sessionId), realId)
|
|
957
|
-
sendLanes.set(recKey(input.workspaceId, realId), lane)
|
|
958
|
-
await renameSessionReferences(
|
|
959
|
-
{ id: input.workspaceId, path: input.workspacePath },
|
|
960
|
-
input.sessionId,
|
|
961
|
-
realId
|
|
962
|
-
)
|
|
963
|
-
}
|
|
964
|
-
rec = createRecord({
|
|
965
|
-
workspaceId: input.workspaceId,
|
|
966
|
-
workspacePath: input.workspacePath,
|
|
967
|
-
sessionId: realId,
|
|
968
|
-
client,
|
|
969
|
-
refreshSessionsOnTurnComplete: true,
|
|
970
|
-
sessionTitleSource
|
|
971
|
-
})
|
|
972
|
-
rec.model = started.model ?? input.model
|
|
973
|
-
if (
|
|
974
|
-
(input.model || input.effort || input.speedMode !== undefined) &&
|
|
975
|
-
!(await hasSessionConfig({ id: input.workspaceId, path: input.workspacePath }, realId))
|
|
976
|
-
) {
|
|
977
|
-
await saveSessionConfig({ id: input.workspaceId, path: input.workspacePath }, realId, {
|
|
978
|
-
model: input.model,
|
|
979
|
-
effort: input.effort,
|
|
980
|
-
speedMode: input.speedMode
|
|
981
|
-
})
|
|
982
|
-
}
|
|
983
|
-
} else {
|
|
984
|
-
rec = await resumeSession({
|
|
985
|
-
...input,
|
|
986
|
-
sessionId: aliases.get(recKey(input.workspaceId, input.sessionId)) ?? input.sessionId
|
|
987
|
-
})
|
|
988
|
-
}
|
|
989
|
-
} catch (err) {
|
|
990
|
-
// No session record exists to run setProcessing through — clear the
|
|
991
|
-
// client's optimistic spinner explicitly or it sticks until reconnect.
|
|
992
|
-
broadcast(input.workspaceId, {
|
|
993
|
-
type: 'session:status',
|
|
994
|
-
sessionId: input.sessionId,
|
|
995
|
-
activity: 'idle'
|
|
996
|
-
})
|
|
997
|
-
broadcast(input.workspaceId, {
|
|
998
|
-
kind: 'error',
|
|
999
|
-
sessionId: input.sessionId,
|
|
1000
|
-
content: err instanceof Error ? err.message : 'failed to start codex session'
|
|
1001
|
-
})
|
|
1002
|
-
refreshAvailability(input.workspaceId, input.workspacePath)
|
|
1003
|
-
throw err
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
if (lane.generation !== generation) return
|
|
1007
|
-
rec.lastTouched = Date.now()
|
|
1008
|
-
rec.stream = input.stream === true
|
|
1009
|
-
if (!rec.stream) clearPreviews(rec)
|
|
1010
|
-
|
|
1011
|
-
if (userInput.some(item => item.type === 'image')) {
|
|
1012
|
-
try {
|
|
1013
|
-
// Steering keeps the running turn's model, regardless of picker changes.
|
|
1014
|
-
const models = await getCodexModelCatalog(input.workspacePath)
|
|
1015
|
-
const modelId = rec.activeTurnId ? rec.model : (input.model ?? rec.model)
|
|
1016
|
-
const model = models.find(model => model.model === modelId || model.id === modelId)
|
|
1017
|
-
if (model?.inputModalities && !model.inputModalities.includes('image')) {
|
|
1018
|
-
throw new Error(
|
|
1019
|
-
`${model.displayName} does not accept images. Choose a model that supports images.`
|
|
1020
|
-
)
|
|
1021
|
-
}
|
|
1022
|
-
} catch (error) {
|
|
1023
|
-
broadcast(rec.workspaceId, {
|
|
1024
|
-
kind: 'error',
|
|
1025
|
-
sessionId: rec.sessionId,
|
|
1026
|
-
content: error instanceof Error ? error.message : 'Could not check image support',
|
|
1027
|
-
terminal: !rec.activeTurnId
|
|
1028
|
-
})
|
|
1029
|
-
if (!rec.activeTurnId) setProcessing(rec, false, null)
|
|
1030
|
-
throw error
|
|
1031
|
-
}
|
|
1032
|
-
if (lane.generation !== generation) return
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
// Broadcast the user's bubble immediately so every connected tab shows it;
|
|
1036
|
-
// the Codex echo (`userMessage` item) reuses this id via `clientId` and
|
|
1037
|
-
// upserts in place.
|
|
1038
|
-
const turnId = input.optimisticId ?? crypto.randomUUID()
|
|
1039
|
-
emitTurnEvent(rec, {
|
|
1040
|
-
kind: 'turn',
|
|
1041
|
-
turn: {
|
|
1042
|
-
id: turnId,
|
|
1043
|
-
role: 'user',
|
|
1044
|
-
origin: { kind: 'user-input' },
|
|
1045
|
-
parts,
|
|
1046
|
-
timestamp: new Date().toISOString()
|
|
1047
|
-
}
|
|
1048
|
-
})
|
|
1049
|
-
|
|
1050
|
-
setProcessing(rec, true, rec.activeTurnId)
|
|
1051
|
-
try {
|
|
1052
|
-
const client = rec.client
|
|
1053
|
-
// Native context keys become tags, so pass unwrapped bodies. The fallback
|
|
1054
|
-
// envelope is stripped from user echoes by adapter.ts.
|
|
1055
|
-
const additionalContext = client.supportsAdditionalContext
|
|
1056
|
-
? {
|
|
1057
|
-
...CODEX_LOCAL_CONTROL_CONTEXT,
|
|
1058
|
-
...(input.context
|
|
1059
|
-
? { 'moi-context': { value: renderMoiContextBody(input.context), kind: 'application' } }
|
|
1060
|
-
: {})
|
|
1061
|
-
}
|
|
1062
|
-
: undefined
|
|
1063
|
-
if (!additionalContext) {
|
|
1064
|
-
const envelope = [
|
|
1065
|
-
CODEX_LOCAL_CONTROL_FALLBACK,
|
|
1066
|
-
...(input.context ? [renderMoiContext(input.context)] : [])
|
|
1067
|
-
].join('\n\n')
|
|
1068
|
-
const last = userInput[userInput.length - 1]
|
|
1069
|
-
if (last?.type === 'text') last.text = appendMoiContext(last.text, envelope)
|
|
1070
|
-
else userInput.push({ type: 'text', text: envelope })
|
|
1071
|
-
}
|
|
1072
|
-
const turnParams = {
|
|
1073
|
-
threadId: rec.sessionId,
|
|
1074
|
-
clientUserMessageId: turnId,
|
|
1075
|
-
input: userInput,
|
|
1076
|
-
...CODEX_TURN_ACCESS,
|
|
1077
|
-
...(additionalContext ? { additionalContext } : {}),
|
|
1078
|
-
// Request visible reasoning summaries instead of relying on CLI defaults.
|
|
1079
|
-
summary: 'detailed',
|
|
1080
|
-
...(input.model ? { model: input.model } : {}),
|
|
1081
|
-
...(input.effort ? { effort: input.effort } : {}),
|
|
1082
|
-
serviceTier
|
|
1083
|
-
}
|
|
1084
|
-
if (rec.activeTurnId) {
|
|
1085
|
-
try {
|
|
1086
|
-
await client.rpc('turn/steer', {
|
|
1087
|
-
threadId: rec.sessionId,
|
|
1088
|
-
clientUserMessageId: turnId,
|
|
1089
|
-
input: userInput,
|
|
1090
|
-
...(additionalContext ? { additionalContext } : {}),
|
|
1091
|
-
expectedTurnId: rec.activeTurnId
|
|
1092
|
-
})
|
|
1093
|
-
} catch (error) {
|
|
1094
|
-
// Only a definitive no-active-turn rejection makes a fresh start safe.
|
|
1095
|
-
// Timeouts, auth failures and turn-id mismatches may have accepted the
|
|
1096
|
-
// input already, or refer to another active turn.
|
|
1097
|
-
if (
|
|
1098
|
-
!(error instanceof CodexRpcError) ||
|
|
1099
|
-
!/no active turn|not running|no turn in progress/i.test(error.message)
|
|
1100
|
-
)
|
|
1101
|
-
throw error
|
|
1102
|
-
if (lane.generation !== generation) return
|
|
1103
|
-
setProcessing(rec, true, null)
|
|
1104
|
-
rec.model = input.model ?? rec.model
|
|
1105
|
-
const res = await client.rpc<{ turn: CodexTurn }>('turn/start', turnParams)
|
|
1106
|
-
acceptStartedTurn(rec, res.turn)
|
|
1107
|
-
}
|
|
1108
|
-
} else {
|
|
1109
|
-
rec.model = input.model ?? rec.model
|
|
1110
|
-
const res = await client.rpc<{ turn: CodexTurn }>('turn/start', turnParams)
|
|
1111
|
-
acceptStartedTurn(rec, res.turn)
|
|
1112
|
-
}
|
|
1113
|
-
if (lane.generation !== generation && rec.activeTurnId) {
|
|
1114
|
-
await interruptCodexTurn(client, rec.sessionId, rec.activeTurnId)
|
|
1115
|
-
}
|
|
1116
|
-
if (input.isNew && lane.generation === generation) startCodexSessionTitleJob(rec, client)
|
|
1117
|
-
debug(`codex send ws=${rec.workspaceId} thread=${rec.sessionId} turn=${rec.activeTurnId}`)
|
|
1118
|
-
} catch (err) {
|
|
1119
|
-
// A failed steer does not terminate the turn it was trying to modify.
|
|
1120
|
-
// Likewise, a timed-out start can still produce authoritative lifecycle
|
|
1121
|
-
// notifications later. Keep a known active turn stoppable.
|
|
1122
|
-
if (!rec.activeTurnId) setProcessing(rec, false, null)
|
|
1123
|
-
broadcast(rec.workspaceId, {
|
|
1124
|
-
kind: 'error',
|
|
1125
|
-
sessionId: rec.sessionId,
|
|
1126
|
-
content: err instanceof Error ? err.message : 'send failed',
|
|
1127
|
-
terminal: !rec.activeTurnId
|
|
1128
|
-
})
|
|
1129
|
-
refreshAvailability(rec.workspaceId, rec.workspacePath)
|
|
1130
|
-
throw err
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
function acceptStartedTurn(rec: SessionRecord, turn: CodexTurn) {
|
|
1135
|
-
if (rec.completedTurns.has(turn.id)) return
|
|
1136
|
-
if (turn.status === 'inProgress') setProcessing(rec, true, turn.id)
|
|
1137
|
-
else handleNotification(rec, 'turn/completed', { threadId: rec.sessionId, turn })
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
export async function interruptCodexRun(input: {
|
|
1141
|
-
workspaceId: string
|
|
1142
|
-
sessionId: string
|
|
1143
|
-
}): Promise<void> {
|
|
1144
|
-
const lane = sendLane(input.workspaceId, input.sessionId)
|
|
1145
|
-
lane.generation++ // cancels queued sends, including a start still initializing
|
|
1146
|
-
const rec = sessions.get(liveKey(input.workspaceId, input.sessionId))
|
|
1147
|
-
if (!rec?.activeTurnId) {
|
|
1148
|
-
broadcast(input.workspaceId, { kind: 'stopped', sessionId: rec?.sessionId ?? input.sessionId })
|
|
1149
|
-
if (rec) setProcessing(rec, false, null)
|
|
1150
|
-
else
|
|
1151
|
-
broadcast(input.workspaceId, {
|
|
1152
|
-
type: 'session:status',
|
|
1153
|
-
sessionId: input.sessionId,
|
|
1154
|
-
activity: 'idle'
|
|
1155
|
-
})
|
|
1156
|
-
return
|
|
1157
|
-
}
|
|
1158
|
-
try {
|
|
1159
|
-
await interruptCodexTurn(rec.client, rec.sessionId, rec.activeTurnId)
|
|
1160
|
-
// turn/completed is authoritative. In particular, don't emit a second
|
|
1161
|
-
// stopped frame or claim idle while the command is still shutting down.
|
|
1162
|
-
} catch (err) {
|
|
1163
|
-
broadcast(rec.workspaceId, {
|
|
1164
|
-
kind: 'error',
|
|
1165
|
-
sessionId: rec.sessionId,
|
|
1166
|
-
content: err instanceof Error ? err.message : 'Interrupt failed',
|
|
1167
|
-
terminal: !rec.activeTurnId
|
|
1168
|
-
})
|
|
1169
|
-
throw err
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
export function viewAsEvents(rec: SessionRecord): StreamEvent[] {
|
|
1174
|
-
const evs: StreamEvent[] = []
|
|
1175
|
-
for (const turn of rec.view.turns) evs.push({ kind: 'turn', turn })
|
|
1176
|
-
for (const notice of rec.view.notices) evs.push({ kind: 'notice', notice })
|
|
1177
|
-
return evs
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
// Serve the live display copy so REST and WebSocket events stay consistent.
|
|
1181
|
-
export function getLiveCodexEvents(workspaceId: string, sessionId: string): StreamEvent[] | null {
|
|
1182
|
-
const rec = sessions.get(liveKey(workspaceId, sessionId))
|
|
1183
|
-
if (rec) rec.lastTouched = Date.now()
|
|
1184
|
-
return rec && !rec.bufferedNotifications ? viewAsEvents(rec) : null
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
// Cold-load: resume the thread (also subscribing it on our connection) and
|
|
1188
|
-
// return its events, so subsequent WS frames upsert into the same view.
|
|
1189
|
-
export async function ensureCodexSessionLive(input: {
|
|
1190
|
-
workspaceId: string
|
|
1191
|
-
workspacePath: string
|
|
1192
|
-
sessionId: string
|
|
1193
|
-
}): Promise<StreamEvent[]> {
|
|
1194
|
-
const rec = await resumeSession(input)
|
|
1195
|
-
return viewAsEvents(rec)
|
|
1196
|
-
}
|