GeezerVison is showing github.com — Apply PR #38459: feat(app): project current server state · anomalyco/opencode@070ea24
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/regression/remote-tab-busy.spec.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,5 +105,9 @@ function json(route: Route, body: unknown, status = 200) { | 105 | 105 | } | 106 | 106 |
| 107 | 107 | function sse(route: Route) { | 108 | | - return route.fulfill({ status: 200, contentType: "text/event-stream", body: ": ok\n\n" }) | | 108 | + return route.fulfill({ | | 109 | + status: 200, | | 110 | + contentType: "text/event-stream", | | 111 | + body: `data: ${JSON.stringify({ payload: { id: "evt_mock_connected", type: "server.connected", properties: {} } })}\n\n`, | | 112 | + }) | 109 | 113 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/regression/review-open-file.spec.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -133,7 +133,7 @@ test("opens and searches project files inline", async ({ page }) => { | 133 | 133 | await expect(panel.getByRole("tab", { name: "nested.ts" })).toHaveCount(1) | 134 | 134 | await expect(panel.getByRole("tab", { name: "Open file" })).toHaveAttribute("data-selected", "") | 135 | 135 | await expect(sidebarToggle).toBeDisabled() | 136 | | - await panel.getByRole("tab", { name: /Review/ }).click() | | 136 | + await panel.locator("#session-side-panel-review-tab").click() | 137 | 137 | await expect(sidebarToggle).toBeEnabled() | 138 | 138 | await panel.getByRole("tab", { name: "Open file" }).click() | 139 | 139 | await page.keyboard.press("Control+w") | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/regression/review-state-persistence.spec.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,7 +46,7 @@ test("restores review mode and selected file per session", async ({ page }) => { | 46 | 46 |
| 47 | 47 | async function selectMode(page: Page, current: string, next: string) { | 48 | 48 | await page.getByRole("button", { name: current }).click() | 49 | | - await page.getByRole("option", { name: next }).click() | | 49 | + await page.getByRole("option", { name: next }).dispatchEvent("click") | 50 | 50 | } | 51 | 51 |
| 52 | 52 | async function selectFile(page: Page, file: string) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/utils/mock-server.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,7 +61,12 @@ export async function mockOpenCodeServer(page: Page, config: MockServerConfig) { | 61 | 61 | route, | 62 | 62 | path === "/api/event" | 63 | 63 | ? [{ id: "evt_mock_connected", type: "server.connected", data: {} }, ...(events?.map(currentEvent) ?? [])] | 64 | | - : events, | | 64 | + : [ | | 65 | + ...(path === "/global/event" | | 66 | + ? [{ payload: { id: "evt_mock_connected", type: "server.connected", properties: {} } }] | | 67 | + : []), | | 68 | + ...(events ?? []), | | 69 | + ], | 65 | 70 | config.eventRetry, | 66 | 71 | ) | 67 | 72 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/utils/sse-transport.ts +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -197,6 +197,14 @@ export async function installSseTransport<T>( | 197 | 197 | controller.enqueue( | 198 | 198 | encoder.encode(frame({ id: `evt_mock_connected_${id}`, type: "server.connected", data: {} })), | 199 | 199 | ) | | 200 | + if (url.pathname === "/global/event") | | 201 | + controller.enqueue( | | 202 | + encoder.encode( | | 203 | + frame({ | | 204 | + payload: { id: `evt_mock_connected_${id}`, type: "server.connected", properties: {} }, | | 205 | + }), | | 206 | + ), | | 207 | + ) | 200 | 208 | request.signal.addEventListener( | 201 | 209 | "abort", | 202 | 210 | () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input-v2.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -310,7 +310,7 @@ export function usePromptInputV2Controller(props: PromptInputV2ControllerProps): | 310 | 310 | ) | 311 | 311 | const resources = createMemo(() => | 312 | 312 | Object.values(sync().data.mcp_resource).map((resource) => ({ | 313 | | - id: `resource:${resource.client}:${resource.uri}`, | | 313 | + id: `resource:${resource.server}:${resource.uri}`, | 314 | 314 | kind: "resource" as const, | 315 | 315 | label: `@${resource.name}`, | 316 | 316 | path: resource.uri, | @@ -327,7 +327,7 @@ export function usePromptInputV2Controller(props: PromptInputV2ControllerProps): | 327 | 327 | source: { | 328 | 328 | type: "resource" as const, | 329 | 329 | text: { value: `@${resource.name}`, start: 0, end: resource.name.length + 1 }, | 330 | | - clientName: resource.client, | | 330 | + clientName: resource.server, | 331 | 331 | uri: resource.uri, | 332 | 332 | }, | 333 | 333 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -591,7 +591,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => { | 591 | 591 | type: "resource", | 592 | 592 | name: resource.name, | 593 | 593 | uri: resource.uri, | 594 | | - client: resource.client, | | 594 | + client: resource.server, | 595 | 595 | display: resource.name, | 596 | 596 | description: resource.description, | 597 | 597 | mime: resource.mimeType, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input/submit.test.ts +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ const optimistic: Array<{ | 19 | 19 | }> = [] | 20 | 20 | const optimisticSeeded: boolean[] = [] | 21 | 21 | const storedSessions: Record<string, Array<{ id: string; title?: string }>> = {} | | 22 | +const sessionDirectories: Record<string, string> = {} | 22 | 23 | const promoted: Array<{ directory: string; sessionID: string }> = [] | 23 | 24 | const sentShell: string[] = [] | 24 | 25 | const syncedDirectories: string[] = [] | @@ -89,6 +90,27 @@ const clientFor = (directory: string) => { | 89 | 90 | } | 90 | 91 | } | 91 | 92 |
| | 93 | +const api = { | | 94 | + session: { | | 95 | + async create(input: { location: { directory: string } }) { | | 96 | + await createSessionGate | | 97 | + createdSessions.push(input.location.directory) | | 98 | + const session = { | | 99 | + id: `session-${createdSessions.length}`, | | 100 | + title: `New session ${createdSessions.length}`, | | 101 | + } | | 102 | + sessionDirectories[session.id] = input.location.directory | | 103 | + return session | | 104 | + }, | | 105 | + async shell(input: { sessionID: string }) { | | 106 | + sentShell.push(sessionDirectories[input.sessionID] ?? "/repo/main") | | 107 | + }, | | 108 | + async prompt() {}, | | 109 | + async command() {}, | | 110 | + async interrupt() {}, | | 111 | + }, | | 112 | +} | | 113 | + | 92 | 114 | beforeAll(async () => { | 93 | 115 | const rootClient = clientFor("/repo/main") | 94 | 116 |
| @@ -171,6 +193,7 @@ beforeAll(async () => { | 171 | 193 | const sdk = { | 172 | 194 | scope: "local", | 173 | 195 | directory: "/repo/main", | | 196 | + api, | 174 | 197 | client: rootClient, | 175 | 198 | url: "http://localhost:4096", | 176 | 199 | createClient(opts: any) { | @@ -265,6 +288,7 @@ beforeEach(() => { | 265 | 288 | permissionServer = "server-a" | 266 | 289 | createSessionGate = undefined | 267 | 290 | for (const key of Object.keys(storedSessions)) delete storedSessions[key] | | 291 | + for (const key of Object.keys(sessionDirectories)) delete sessionDirectories[key] | 268 | 292 | }) | 269 | 293 |
| 270 | 294 | describe("prompt submit worktree selection", () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input/submit.ts +65-33Lines changed: 65 additions & 33 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,8 @@ import { setCursorPosition } from "./editor-dom" | 20 | 20 | import { formatServerError } from "@/utils/server-errors" | 21 | 21 | import { ScopedKey } from "@/utils/server-scope" | 22 | 22 | import { createPromptSubmissionState } from "./submission-state" | | 23 | +import { normalizeSessionInfo } from "@/utils/session" | | 24 | +import { Event } from "@opencode-ai/schema/event" | 23 | 25 |
| 24 | 26 | type PendingPrompt = { | 25 | 27 | abort: AbortController | @@ -39,7 +41,7 @@ export type FollowupDraft = { | 39 | 41 | } | 40 | 42 |
| 41 | 43 | type FollowupSendInput = { | 42 | | - client: DirectorySDK["client"] | | 44 | + api: DirectorySDK["api"]["session"] | 43 | 45 | serverSync: ServerSync | 44 | 46 | sync: DirectorySync | 45 | 47 | draft: FollowupDraft | @@ -81,19 +83,21 @@ export async function sendFollowupDraft(input: FollowupSendInput) { | 81 | 83 | return false | 82 | 84 | } | 83 | 85 |
| 84 | | - await input.client.session.command({ | | 86 | + const messageID = Identifier.ascending("message") | | 87 | + await input.api.command({ | 85 | 88 | sessionID: input.draft.sessionID, | | 89 | + id: messageID, | 86 | 90 | command: cmd, | 87 | 91 | arguments: tail.join(" "), | 88 | 92 | agent: input.draft.agent, | 89 | | - model: `${input.draft.model.providerID}/${input.draft.model.modelID}`, | 90 | | - variant: input.draft.variant, | 91 | | - parts: images.map((attachment) => ({ | 92 | | - id: Identifier.ascending("part"), | 93 | | - type: "file" as const, | 94 | | - mime: attachment.mime, | 95 | | - url: attachment.dataUrl, | 96 | | - filename: attachment.filename, | | 93 | + model: { | | 94 | + id: input.draft.model.modelID, | | 95 | + providerID: input.draft.model.providerID, | | 96 | + variant: input.draft.variant, | | 97 | + }, | | 98 | + files: images.map((attachment) => ({ | | 99 | + uri: attachment.dataUrl, | | 100 | + name: attachment.filename, | 97 | 101 | })), | 98 | 102 | }) | 99 | 103 | return true | @@ -152,13 +156,36 @@ export async function sendFollowupDraft(input: FollowupSendInput) { | 152 | 156 | return false | 153 | 157 | } | 154 | 158 |
| 155 | | - await input.client.session.promptAsync({ | | 159 | + await input.api.prompt({ | 156 | 160 | sessionID: input.draft.sessionID, | | 161 | + id: messageID, | 157 | 162 | agent: input.draft.agent, | 158 | 163 | model: input.draft.model, | 159 | | - messageID, | 160 | | - parts: requestParts, | 161 | 164 | variant: input.draft.variant, | | 165 | + text: requestParts.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n"), | | 166 | + files: requestParts.flatMap((part) => { | | 167 | + if (part.type !== "file") return [] | | 168 | + const text = part.source?.text | | 169 | + return [ | | 170 | + { | | 171 | + uri: part.url, | | 172 | + name: part.filename, | | 173 | + mention: text ? { start: text.start, end: text.end, text: text.value } : undefined, | | 174 | + }, | | 175 | + ] | | 176 | + }), | | 177 | + agents: requestParts.flatMap((part) => | | 178 | + part.type === "agent" | | 179 | + ? [ | | 180 | + { | | 181 | + name: part.name, | | 182 | + mention: part.source | | 183 | + ? { start: part.source.start, end: part.source.end, text: part.source.value } | | 184 | + : undefined, | | 185 | + }, | | 186 | + ] | | 187 | + : [], | | 188 | + ), | 162 | 189 | }) | 163 | 190 | return true | 164 | 191 | } catch (err) { | @@ -210,6 +237,7 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 210 | 237 | const pendingKey = (sessionID: string) => ScopedKey.from(sdk().scope, sessionID) | 211 | 238 |
| 212 | 239 | const errorMessage = (err: unknown) => { | | 240 | + if (err && typeof err === "object" && "message" in err && typeof err.message === "string") return err.message | 213 | 241 | if (err && typeof err === "object" && "data" in err) { | 214 | 242 | const data = (err as { data?: { message?: string } }).data | 215 | 243 | if (data?.message) return data.message | @@ -235,9 +263,7 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 235 | 263 | return Promise.resolve() | 236 | 264 | } | 237 | 265 | return sdk() | 238 | | - .client.session.abort({ | 239 | | - sessionID, | 240 | | - }) | | 266 | + .api.session.interrupt({ sessionID }) | 241 | 267 | .catch(() => {}) | 242 | 268 | } | 243 | 269 |
| @@ -364,9 +390,13 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 364 | 390 |
| 365 | 391 | let session = input.info() | 366 | 392 | if (!session && isNewSession) { | 367 | | - const created = await client.session | 368 | | - .create() | 369 | | - .then((x) => x.data ?? undefined) | | 393 | + const created = await sdk() | | 394 | + .api.session.create({ | | 395 | + agent: currentAgent.name, | | 396 | + model: { id: currentModel.id, providerID: currentModel.provider.id, variant }, | | 397 | + location: { directory: sessionDirectory }, | | 398 | + }) | | 399 | + .then(normalizeSessionInfo) | 370 | 400 | .catch((err) => { | 371 | 401 | showToast({ | 372 | 402 | title: language.t("prompt.toast.sessionCreateFailed.title"), | @@ -450,12 +480,14 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 450 | 480 |
| 451 | 481 | if (mode === "shell") { | 452 | 482 | clearInput() | 453 | | - client.session | 454 | | - .shell({ | | 483 | + const eventID = Event.ID.create() | | 484 | + sdk() | | 485 | + .api.session.shell({ | 455 | 486 | sessionID: session.id, | | 487 | + id: eventID, | | 488 | + command: text, | 456 | 489 | agent, | 457 | 490 | model, | 458 | | - command: text, | 459 | 491 | }) | 460 | 492 | .catch((err) => { | 461 | 493 | showToast({ | @@ -473,23 +505,23 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 473 | 505 | const customCommand = sync().data.command.find((c) => c.name === commandName) | 474 | 506 | if (customCommand) { | 475 | 507 | clearInput() | 476 | | - client.session | 477 | | - .command({ | | 508 | + const messageID = Identifier.ascending("message") | | 509 | + serverSync().session.set("session_status", session.id, { type: "busy" }) | | 510 | + sdk() | | 511 | + .api.session.command({ | 478 | 512 | sessionID: session.id, | | 513 | + id: messageID, | 479 | 514 | command: commandName, | 480 | 515 | arguments: args.join(" "), | 481 | 516 | agent, | 482 | | - model: `${model.providerID}/${model.modelID}`, | 483 | | - variant, | 484 | | - parts: images.map((attachment) => ({ | 485 | | - id: Identifier.ascending("part"), | 486 | | - type: "file" as const, | 487 | | - mime: attachment.mime, | 488 | | - url: attachment.dataUrl, | 489 | | - filename: attachment.filename, | | 517 | + model: { id: model.modelID, providerID: model.providerID, variant }, | | 518 | + files: images.map((attachment) => ({ | | 519 | + uri: attachment.dataUrl, | | 520 | + name: attachment.filename, | 490 | 521 | })), | 491 | 522 | }) | 492 | 523 | .catch((err) => { | | 524 | + serverSync().session.set("session_status", session.id, { type: "idle" }) | 493 | 525 | showToast({ | 494 | 526 | title: language.t("prompt.toast.commandSendFailed.title"), | 495 | 527 | description: formatServerError(err, language.t, language.t("common.requestFailed")), | @@ -573,7 +605,7 @@ export function createPromptSubmit(input: PromptSubmitInput) { | 573 | 605 | } | 574 | 606 |
| 575 | 607 | void sendFollowupDraft({ | 576 | | - client, | | 608 | + api: sdk().api.session, | 577 | 609 | sync: sync(), | 578 | 610 | serverSync: serverSync(), | 579 | 611 | draft, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/status-popover-indicator.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ describe("hasNonBlockingServiceIssue", () => { | 26 | 26 | expect(hasNonBlockingServiceIssue({ mcp: ["failed"], lsp: [] })).toBe(true) | 27 | 27 | expect(hasNonBlockingServiceIssue({ mcp: ["needs_auth"], lsp: [] })).toBe(true) | 28 | 28 | expect(hasNonBlockingServiceIssue({ mcp: ["needs_client_registration"], lsp: [] })).toBe(true) | 29 | | - expect(hasNonBlockingServiceIssue({ mcp: ["connected", "disabled"], lsp: [] })).toBe(false) | | 29 | + expect(hasNonBlockingServiceIssue({ mcp: ["connected", "pending", "disabled"], lsp: [] })).toBe(false) | 30 | 30 | }) | 31 | 31 |
| 32 | 32 | test("detects LSP failures that do not block chatting", () => { | |
|