GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(app): project current server state (#38459) · Ichinose-Kazuki/opencode@f113c18

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app
    • e2e
      • regression
        • remote-tab-busy.spec.ts
        • review-open-file.spec.ts
        • review-state-persistence.spec.ts
      • utils
        • mock-server.ts
        • sse-transport.ts
    • src
      • components
        • prompt-input-v2.tsx
        • prompt-input.tsx
        • prompt-input
          • submit.test.ts
          • submit.ts
        • status-popover-indicator.test.ts
        • status-popover-indicator.ts
      • context
        • directory-sync.ts
        • global-sync
          • bootstrap.test.ts
          • bootstrap.ts
          • child-store.ts
          • event-reducer.test.ts
          • event-reducer.ts
          • mcp.test.ts
          • mcp.ts
          • session-cache.test.ts
          • session-cache.ts
          • session-load.ts
          • types.ts
          • utils.test.ts
          • utils.ts
        • server-session-v2-reducer.test.ts
        • server-session-v2-reducer.ts
        • server-session.test.ts
        • server-session.ts
        • server-sync.test.ts
        • server-sync.tsx
      • pages
        • session.tsx
      • utils
        • server-compat.test.ts
        • server-compat.ts
        • session-message.test.ts
        • session-message.ts
        • session.test.ts
        • session.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/e2e/regression/remote-tab-busy.spec.ts‎

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 numberDiff line numberDiff line change
@@ -105,5 +105,9 @@ function json(route: Route, body: unknown, status = 200) {
105105
}
106106

107107
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+
})
109113
}
Collapse file

‎packages/app/e2e/regression/review-open-file.spec.ts‎

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 numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test("opens and searches project files inline", async ({ page }) => {
133133
await expect(panel.getByRole("tab", { name: "nested.ts" })).toHaveCount(1)
134134
await expect(panel.getByRole("tab", { name: "Open file" })).toHaveAttribute("data-selected", "")
135135
await expect(sidebarToggle).toBeDisabled()
136-
await panel.getByRole("tab", { name: /Review/ }).click()
136+
await panel.locator("#session-side-panel-review-tab").click()
137137
await expect(sidebarToggle).toBeEnabled()
138138
await panel.getByRole("tab", { name: "Open file" }).click()
139139
await page.keyboard.press("Control+w")
Collapse file

‎packages/app/e2e/regression/review-state-persistence.spec.ts‎

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 numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test("restores review mode and selected file per session", async ({ page }) => {
4646

4747
async function selectMode(page: Page, current: string, next: string) {
4848
await page.getByRole("button", { name: current }).click()
49-
await page.getByRole("option", { name: next }).click()
49+
await page.getByRole("option", { name: next }).dispatchEvent("click")
5050
}
5151

5252
async function selectFile(page: Page, file: string) {
Collapse file

‎packages/app/e2e/utils/mock-server.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/utils/mock-server.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export async function mockOpenCodeServer(page: Page, config: MockServerConfig) {
6161
route,
6262
path === "/api/event"
6363
? [{ 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+
],
6570
config.eventRetry,
6671
)
6772
}
Collapse file

‎packages/app/e2e/utils/sse-transport.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/utils/sse-transport.ts
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ export async function installSseTransport<T>(
197197
controller.enqueue(
198198
encoder.encode(frame({ id: `evt_mock_connected_${id}`, type: "server.connected", data: {} })),
199199
)
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+
)
200208
request.signal.addEventListener(
201209
"abort",
202210
() => {
Collapse file

‎packages/app/src/components/prompt-input-v2.tsx‎

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 numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export function usePromptInputV2Controller(props: PromptInputV2ControllerProps):
310310
)
311311
const resources = createMemo(() =>
312312
Object.values(sync().data.mcp_resource).map((resource) => ({
313-
id: `resource:${resource.client}:${resource.uri}`,
313+
id: `resource:${resource.server}:${resource.uri}`,
314314
kind: "resource" as const,
315315
label: `@${resource.name}`,
316316
path: resource.uri,
@@ -327,7 +327,7 @@ export function usePromptInputV2Controller(props: PromptInputV2ControllerProps):
327327
source: {
328328
type: "resource" as const,
329329
text: { value: `@${resource.name}`, start: 0, end: resource.name.length + 1 },
330-
clientName: resource.client,
330+
clientName: resource.server,
331331
uri: resource.uri,
332332
},
333333
},
Collapse file

‎packages/app/src/components/prompt-input.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/components/prompt-input.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
591591
type: "resource",
592592
name: resource.name,
593593
uri: resource.uri,
594-
client: resource.client,
594+
client: resource.server,
595595
display: resource.name,
596596
description: resource.description,
597597
mime: resource.mimeType,
Collapse file

‎packages/app/src/components/prompt-input/submit.test.ts‎

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 numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const optimistic: Array<{
1919
}> = []
2020
const optimisticSeeded: boolean[] = []
2121
const storedSessions: Record<string, Array<{ id: string; title?: string }>> = {}
22+
const sessionDirectories: Record<string, string> = {}
2223
const promoted: Array<{ directory: string; sessionID: string }> = []
2324
const sentShell: string[] = []
2425
const syncedDirectories: string[] = []
@@ -89,6 +90,27 @@ const clientFor = (directory: string) => {
8990
}
9091
}
9192

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+
92114
beforeAll(async () => {
93115
const rootClient = clientFor("/repo/main")
94116

@@ -171,6 +193,7 @@ beforeAll(async () => {
171193
const sdk = {
172194
scope: "local",
173195
directory: "/repo/main",
196+
api,
174197
client: rootClient,
175198
url: "http://localhost:4096",
176199
createClient(opts: any) {
@@ -265,6 +288,7 @@ beforeEach(() => {
265288
permissionServer = "server-a"
266289
createSessionGate = undefined
267290
for (const key of Object.keys(storedSessions)) delete storedSessions[key]
291+
for (const key of Object.keys(sessionDirectories)) delete sessionDirectories[key]
268292
})
269293

270294
describe("prompt submit worktree selection", () => {
Collapse file

‎packages/app/src/components/prompt-input/submit.ts‎

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 numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { setCursorPosition } from "./editor-dom"
2020
import { formatServerError } from "@/utils/server-errors"
2121
import { ScopedKey } from "@/utils/server-scope"
2222
import { createPromptSubmissionState } from "./submission-state"
23+
import { normalizeSessionInfo } from "@/utils/session"
24+
import { Event } from "@opencode-ai/schema/event"
2325

2426
type PendingPrompt = {
2527
abort: AbortController
@@ -39,7 +41,7 @@ export type FollowupDraft = {
3941
}
4042

4143
type FollowupSendInput = {
42-
client: DirectorySDK["client"]
44+
api: DirectorySDK["api"]["session"]
4345
serverSync: ServerSync
4446
sync: DirectorySync
4547
draft: FollowupDraft
@@ -81,19 +83,21 @@ export async function sendFollowupDraft(input: FollowupSendInput) {
8183
return false
8284
}
8385

84-
await input.client.session.command({
86+
const messageID = Identifier.ascending("message")
87+
await input.api.command({
8588
sessionID: input.draft.sessionID,
89+
id: messageID,
8690
command: cmd,
8791
arguments: tail.join(" "),
8892
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,
97101
})),
98102
})
99103
return true
@@ -152,13 +156,36 @@ export async function sendFollowupDraft(input: FollowupSendInput) {
152156
return false
153157
}
154158

155-
await input.client.session.promptAsync({
159+
await input.api.prompt({
156160
sessionID: input.draft.sessionID,
161+
id: messageID,
157162
agent: input.draft.agent,
158163
model: input.draft.model,
159-
messageID,
160-
parts: requestParts,
161164
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+
),
162189
})
163190
return true
164191
} catch (err) {
@@ -210,6 +237,7 @@ export function createPromptSubmit(input: PromptSubmitInput) {
210237
const pendingKey = (sessionID: string) => ScopedKey.from(sdk().scope, sessionID)
211238

212239
const errorMessage = (err: unknown) => {
240+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") return err.message
213241
if (err && typeof err === "object" && "data" in err) {
214242
const data = (err as { data?: { message?: string } }).data
215243
if (data?.message) return data.message
@@ -235,9 +263,7 @@ export function createPromptSubmit(input: PromptSubmitInput) {
235263
return Promise.resolve()
236264
}
237265
return sdk()
238-
.client.session.abort({
239-
sessionID,
240-
})
266+
.api.session.interrupt({ sessionID })
241267
.catch(() => {})
242268
}
243269

@@ -364,9 +390,13 @@ export function createPromptSubmit(input: PromptSubmitInput) {
364390

365391
let session = input.info()
366392
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)
370400
.catch((err) => {
371401
showToast({
372402
title: language.t("prompt.toast.sessionCreateFailed.title"),
@@ -450,12 +480,14 @@ export function createPromptSubmit(input: PromptSubmitInput) {
450480

451481
if (mode === "shell") {
452482
clearInput()
453-
client.session
454-
.shell({
483+
const eventID = Event.ID.create()
484+
sdk()
485+
.api.session.shell({
455486
sessionID: session.id,
487+
id: eventID,
488+
command: text,
456489
agent,
457490
model,
458-
command: text,
459491
})
460492
.catch((err) => {
461493
showToast({
@@ -473,23 +505,23 @@ export function createPromptSubmit(input: PromptSubmitInput) {
473505
const customCommand = sync().data.command.find((c) => c.name === commandName)
474506
if (customCommand) {
475507
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({
478512
sessionID: session.id,
513+
id: messageID,
479514
command: commandName,
480515
arguments: args.join(" "),
481516
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,
490521
})),
491522
})
492523
.catch((err) => {
524+
serverSync().session.set("session_status", session.id, { type: "idle" })
493525
showToast({
494526
title: language.t("prompt.toast.commandSendFailed.title"),
495527
description: formatServerError(err, language.t, language.t("common.requestFailed")),
@@ -573,7 +605,7 @@ export function createPromptSubmit(input: PromptSubmitInput) {
573605
}
574606

575607
void sendFollowupDraft({
576-
client,
608+
api: sdk().api.session,
577609
sync: sync(),
578610
serverSync: serverSync(),
579611
draft,
Collapse file

‎packages/app/src/components/status-popover-indicator.test.ts‎

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 numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("hasNonBlockingServiceIssue", () => {
2626
expect(hasNonBlockingServiceIssue({ mcp: ["failed"], lsp: [] })).toBe(true)
2727
expect(hasNonBlockingServiceIssue({ mcp: ["needs_auth"], lsp: [] })).toBe(true)
2828
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)
3030
})
3131

3232
test("detects LSP failures that do not block chatting", () => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.