Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/opencode/script/seed-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const seed = async () => {
const { Instance } = await import("../src/project/instance")
const { InstanceBootstrap } = await import("../src/project/bootstrap")
const { Session } = await import("../src/session")
const { Identifier } = await import("../src/id/id")
const { MessageID } = await import("../src/session/schema")
const { MessageID, PartID } = await import("../src/session/schema")
const { Project } = await import("../src/project/project")

await Instance.provide({
Expand All @@ -21,7 +20,7 @@ const seed = async () => {
fn: async () => {
const session = await Session.create({ title })
const messageID = MessageID.ascending()
const partID = Identifier.descending("part")
const partID = PartID.ascending()
const message = {
id: messageID,
sessionID: session.id,
Expand Down
5 changes: 2 additions & 3 deletions packages/opencode/src/cli/cmd/debug/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Agent } from "../../../agent/agent"
import { Provider } from "../../../provider/provider"
import { Session } from "../../../session"
import type { MessageV2 } from "../../../session/message-v2"
import { Identifier } from "../../../id/id"
import { MessageID } from "../../../session/schema"
import { MessageID, PartID } from "../../../session/schema"
import { ToolRegistry } from "../../../tool/registry"
import { Instance } from "../../../project/instance"
import { PermissionNext } from "../../../permission/next"
Expand Down Expand Up @@ -151,7 +150,7 @@ async function createToolContext(agent: Agent.Info) {
return {
sessionID: session.id,
messageID,
callID: Identifier.ascending("part"),
callID: PartID.ascending(),
agent: agent.name,
abort: new AbortController().signal,
messages: [],
Expand Down
9 changes: 4 additions & 5 deletions packages/opencode/src/cli/cmd/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { Instance } from "@/project/instance"
import { bootstrap } from "../bootstrap"
import { Session } from "../../session"
import type { SessionID } from "../../session/schema"
import { Identifier } from "../../id/id"
import { MessageID } from "../../session/schema"
import { MessageID, PartID } from "../../session/schema"
import { Provider } from "../../provider/provider"
import { Bus } from "../../bus"
import { MessageV2 } from "../../session/message-v2"
Expand Down Expand Up @@ -945,13 +944,13 @@ export const GithubRunCommand = cmd({
// agent is omitted - server will use default_agent from config or fall back to "build"
parts: [
{
id: Identifier.ascending("part"),
id: PartID.ascending(),
type: "text",
text: message,
},
...files.flatMap((f) => [
{
id: Identifier.ascending("part"),
id: PartID.ascending(),
type: "file" as const,
mime: f.mime,
url: `data:${f.mime};base64,${f.content}`,
Expand Down Expand Up @@ -999,7 +998,7 @@ export const GithubRunCommand = cmd({
tools: { "*": false }, // Disable all tools to force text response
parts: [
{
id: Identifier.ascending("part"),
id: PartID.ascending(),
type: "text",
text: "Summarize the actions (tool calls & reasoning) you did for the user in 1-2 sentences.",
},
Expand Down
10 changes: 7 additions & 3 deletions packages/opencode/src/cli/cmd/import.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Argv } from "yargs"
import type { Session as SDKSession, Message, Part } from "@opencode-ai/sdk/v2"
import { Session } from "../../session"
import { SessionID, MessageID } from "../../session/schema"
import { SessionID, MessageID, PartID } from "../../session/schema"
import { WorkspaceID } from "../../control-plane/schema"
import { cmd } from "./cmd"
import { bootstrap } from "../bootstrap"
Expand Down Expand Up @@ -161,7 +161,11 @@ export const ImportCommand = cmd({
workspaceID: exportData.info.workspaceID ? WorkspaceID.make(exportData.info.workspaceID) : undefined,
projectID: Instance.project.id,
revert: exportData.info.revert
? { ...exportData.info.revert, messageID: MessageID.make(exportData.info.revert.messageID) }
? {
...exportData.info.revert,
messageID: MessageID.make(exportData.info.revert.messageID),
partID: exportData.info.revert.partID ? PartID.make(exportData.info.revert.partID) : undefined,
}
: undefined,
})
Database.use((db) =>
Expand Down Expand Up @@ -193,7 +197,7 @@ export const ImportCommand = cmd({
db
.insert(PartTable)
.values({
id: part.id,
id: PartID.make(part.id),
message_id: MessageID.make(msg.info.id),
session_id: row.id,
data: partData,
Expand Down
9 changes: 4 additions & 5 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { EmptyBorder } from "@tui/component/border"
import { useSDK } from "@tui/context/sdk"
import { useRoute } from "@tui/context/route"
import { useSync } from "@tui/context/sync"
import { Identifier } from "@/id/id"
import { MessageID } from "@/session/schema"
import { MessageID, PartID } from "@/session/schema"
import { createStore, produce } from "solid-js/store"
import { useKeybind } from "@tui/context/keybind"
import { usePromptHistory, type PromptInfo } from "./history"
Expand Down Expand Up @@ -625,7 +624,7 @@ export function Prompt(props: PromptProps) {
parts: nonTextParts
.filter((x) => x.type === "file")
.map((x) => ({
id: Identifier.ascending("part"),
id: PartID.ascending(),
...x,
})),
})
Expand All @@ -640,12 +639,12 @@ export function Prompt(props: PromptProps) {
variant,
parts: [
{
id: Identifier.ascending("part"),
id: PartID.ascending(),
type: "text",
text: inputText,
},
...nonTextParts.map((x) => ({
id: Identifier.ascending("part"),
id: PartID.ascending(),
...x,
})),
],
Expand Down
6 changes: 3 additions & 3 deletions packages/opencode/src/server/routes/session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hono } from "hono"
import { stream } from "hono/streaming"
import { describeRoute, validator, resolver } from "hono-openapi"
import { SessionID, MessageID } from "@/session/schema"
import { SessionID, MessageID, PartID } from "@/session/schema"
import z from "zod"
import { Session } from "../../session"
import { MessageV2 } from "../../session/message-v2"
Expand Down Expand Up @@ -677,7 +677,7 @@ export const SessionRoutes = lazy(() =>
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: z.string(),
partID: PartID.zod,
}),
),
async (c) => {
Expand Down Expand Up @@ -712,7 +712,7 @@ export const SessionRoutes = lazy(() =>
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: z.string(),
partID: PartID.zod,
}),
),
validator("json", MessageV2.Part),
Expand Down
9 changes: 4 additions & 5 deletions packages/opencode/src/session/compaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BusEvent } from "@/bus/bus-event"
import { Bus } from "@/bus"
import { Session } from "."
import { Identifier } from "../id/id"
import { SessionID, MessageID } from "./schema"
import { SessionID, MessageID, PartID } from "./schema"
import { Instance } from "../project/instance"
import { Provider } from "../provider/provider"
import { MessageV2 } from "./message-v2"
Expand Down Expand Up @@ -256,7 +255,7 @@ When constructing the summary, try to stick to this template:
: part
await Session.updatePart({
...replayPart,
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: replayMsg.id,
sessionID: input.sessionID,
})
Expand All @@ -276,7 +275,7 @@ When constructing the summary, try to stick to this template:
: "") +
"Continue if you have next steps, or stop and ask for clarification if you are unsure how to proceed."
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: continueMsg.id,
sessionID: input.sessionID,
type: "text",
Expand Down Expand Up @@ -317,7 +316,7 @@ When constructing the summary, try to stick to this template:
},
})
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: msg.id,
sessionID: msg.sessionID,
type: "compaction",
Expand Down
11 changes: 5 additions & 6 deletions packages/opencode/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import z from "zod"
import { type ProviderMetadata } from "ai"
import { Config } from "../config/config"
import { Flag } from "../flag/flag"
import { Identifier } from "../id/id"
import { Installation } from "../installation"

import { Database, NotFoundError, eq, and, or, gte, isNull, desc, like, inArray, lt } from "../storage/db"
Expand All @@ -25,7 +24,7 @@ import { Snapshot } from "@/snapshot"
import { WorkspaceContext } from "../control-plane/workspace-context"
import { ProjectID } from "../project/schema"
import { WorkspaceID } from "../control-plane/schema"
import { SessionID, MessageID } from "./schema"
import { SessionID, MessageID, PartID } from "./schema"

import type { Provider } from "@/provider/provider"
import { PermissionNext } from "@/permission/next"
Expand Down Expand Up @@ -152,7 +151,7 @@ export namespace Session {
revert: z
.object({
messageID: MessageID.zod,
partID: z.string().optional(),
partID: PartID.zod.optional(),
snapshot: z.string().optional(),
diff: z.string().optional(),
})
Expand Down Expand Up @@ -269,7 +268,7 @@ export namespace Session {
for (const part of msg.parts) {
await updatePart({
...part,
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: cloned.id,
sessionID: session.id,
})
Expand Down Expand Up @@ -731,7 +730,7 @@ export namespace Session {
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: Identifier.schema("part"),
partID: PartID.zod,
}),
async (input) => {
Database.use((db) => {
Expand Down Expand Up @@ -779,7 +778,7 @@ export namespace Session {
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: z.string(),
partID: PartID.zod,
field: z.string(),
delta: z.string(),
}),
Expand Down
8 changes: 4 additions & 4 deletions packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BusEvent } from "@/bus/bus-event"
import { SessionID, MessageID } from "./schema"
import { SessionID, MessageID, PartID } from "./schema"
import z from "zod"
import { NamedError } from "@opencode-ai/util/error"
import { APICallError, convertToModelMessages, LoadAPIKeyError, type ModelMessage, type UIMessage } from "ai"
Expand Down Expand Up @@ -78,7 +78,7 @@ export namespace MessageV2 {
export type OutputFormat = z.infer<typeof Format>

const PartBase = z.object({
id: z.string(),
id: PartID.zod,
sessionID: SessionID.zod,
messageID: MessageID.zod,
})
Expand Down Expand Up @@ -472,7 +472,7 @@ export namespace MessageV2 {
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: z.string(),
partID: PartID.zod,
field: z.string(),
delta: z.string(),
}),
Expand All @@ -482,7 +482,7 @@ export namespace MessageV2 {
z.object({
sessionID: SessionID.zod,
messageID: MessageID.zod,
partID: z.string(),
partID: PartID.zod,
}),
),
}
Expand Down
16 changes: 8 additions & 8 deletions packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MessageV2 } from "./message-v2"
import { Log } from "@/util/log"
import { Identifier } from "@/id/id"
import { Session } from "."
import { Agent } from "@/agent/agent"
import { Snapshot } from "@/snapshot"
Expand All @@ -15,6 +14,7 @@ import { Config } from "@/config/config"
import { SessionCompaction } from "./compaction"
import { PermissionNext } from "@/permission/next"
import { Question } from "@/question"
import { PartID } from "./schema"
import type { SessionID, MessageID } from "./schema"

export namespace SessionProcessor {
Expand Down Expand Up @@ -65,7 +65,7 @@ export namespace SessionProcessor {
continue
}
const reasoningPart = {
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.assistantMessage.sessionID,
type: "reasoning" as const,
Expand Down Expand Up @@ -111,7 +111,7 @@ export namespace SessionProcessor {

case "tool-input-start":
const part = await Session.updatePart({
id: toolcalls[value.id]?.id ?? Identifier.ascending("part"),
id: toolcalls[value.id]?.id ?? PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.assistantMessage.sessionID,
type: "tool",
Expand Down Expand Up @@ -234,7 +234,7 @@ export namespace SessionProcessor {
case "start-step":
snapshot = await Snapshot.track()
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.sessionID,
snapshot,
Expand All @@ -252,7 +252,7 @@ export namespace SessionProcessor {
input.assistantMessage.cost += usage.cost
input.assistantMessage.tokens = usage.tokens
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
reason: value.finishReason,
snapshot: await Snapshot.track(),
messageID: input.assistantMessage.id,
Expand All @@ -266,7 +266,7 @@ export namespace SessionProcessor {
const patch = await Snapshot.patch(snapshot)
if (patch.files.length) {
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.sessionID,
type: "patch",
Expand All @@ -290,7 +290,7 @@ export namespace SessionProcessor {

case "text-start":
currentText = {
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.assistantMessage.sessionID,
type: "text",
Expand Down Expand Up @@ -389,7 +389,7 @@ export namespace SessionProcessor {
const patch = await Snapshot.patch(snapshot)
if (patch.files.length) {
await Session.updatePart({
id: Identifier.ascending("part"),
id: PartID.ascending(),
messageID: input.assistantMessage.id,
sessionID: input.sessionID,
type: "patch",
Expand Down
Loading
Loading