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(desktop): optimistic prompt submit · toastdriven/opencode@b420958

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/desktop/src
    • components
      • prompt-input.tsx
    • context
      • sync.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/desktop/src/components/prompt-input.tsx
+20-5Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,28 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
709709
}
710710
}
711711

712+
const model = {
713+
modelID: local.model.current()!.id,
714+
providerID: local.model.current()!.provider.id,
715+
}
716+
const agent = local.agent.current()!.name
717+
718+
sync.session.addOptimisticMessage({
719+
sessionID: existing.id,
720+
text,
721+
parts: [
722+
{ type: "text", text } as import("@opencode-ai/sdk/v2/client").Part,
723+
...(fileAttachmentParts as import("@opencode-ai/sdk/v2/client").Part[]),
724+
...(imageAttachmentParts as import("@opencode-ai/sdk/v2/client").Part[]),
725+
],
726+
agent,
727+
model,
728+
})
729+
712730
sdk.client.session.prompt({
713731
sessionID: existing.id,
714-
agent: local.agent.current()!.name,
715-
model: {
716-
modelID: local.model.current()!.id,
717-
providerID: local.model.current()!.provider.id,
718-
},
732+
agent,
733+
model,
719734
parts: [
720735
{
721736
type: "text",
Collapse file

‎packages/desktop/src/context/sync.tsx‎

Copy file name to clipboardExpand all lines: packages/desktop/src/context/sync.tsx
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Binary } from "@opencode-ai/util/binary"
44
import { createSimpleContext } from "@opencode-ai/ui/context"
55
import { useGlobalSync } from "./global-sync"
66
import { useSDK } from "./sdk"
7+
import type { Message, Part } from "@opencode-ai/sdk/v2/client"
78

89
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
910
name: "Sync",
@@ -30,6 +31,40 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
3031
if (match.found) return store.session[match.index]
3132
return undefined
3233
},
34+
addOptimisticMessage(input: {
35+
sessionID: string
36+
text: string
37+
parts: Part[]
38+
agent: string
39+
model: { providerID: string; modelID: string }
40+
}) {
41+
const messageID = crypto.randomUUID()
42+
const message: Message = {
43+
id: messageID,
44+
sessionID: input.sessionID,
45+
role: "user",
46+
time: { created: Date.now() },
47+
agent: input.agent,
48+
model: input.model,
49+
}
50+
setStore(
51+
produce((draft) => {
52+
const messages = draft.message[input.sessionID]
53+
if (!messages) {
54+
draft.message[input.sessionID] = [message]
55+
} else {
56+
const result = Binary.search(messages, messageID, (m) => m.id)
57+
messages.splice(result.index, 0, message)
58+
}
59+
draft.part[messageID] = input.parts.map((part, i) => ({
60+
...part,
61+
id: `${messageID}-${i}`,
62+
sessionID: input.sessionID,
63+
messageID,
64+
}))
65+
}),
66+
)
67+
},
3368
async sync(sessionID: string, _isRetry = false) {
3469
const [session, messages, todo, diff] = await Promise.all([
3570
sdk.client.session.get({ sessionID }, { throwOnError: true }),

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.