Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/opencode/src/server/routes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,17 @@ export const SessionRoutes = lazy(() =>
"query",
z.object({
limit: z.coerce.number().optional(),
ts_before: z.coerce.number().optional(),
breakpoint: z.coerce.boolean().optional(),
}),
),
async (c) => {
const query = c.req.valid("query")
const messages = await Session.messages({
sessionID: c.req.valid("param").sessionID,
limit: query.limit,
ts_before: query.ts_before,
breakpoint: query.breakpoint,
})
return c.json(messages)
},
Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,16 @@ export namespace Session {
z.object({
sessionID: Identifier.schema("session"),
limit: z.number().optional(),
ts_before: z.number().optional(),
breakpoint: z.boolean().optional(),
}),
async (input) => {
const result = [] as MessageV2.WithParts[]
for await (const msg of MessageV2.stream(input.sessionID)) {
if (input.ts_before && msg.info.time.created >= input.ts_before) continue
if (input.limit && result.length >= input.limit) break
result.push(msg)
if (input.ts_before && input.breakpoint && msg.parts.some((p) => p.type === "compaction")) break
}
result.reverse()
return result
Expand Down
9 changes: 1 addition & 8 deletions packages/sdk/js/src/v2/gen/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,10 @@ export const createClient = (config: Config = {}): Client => {
case "arrayBuffer":
case "blob":
case "formData":
case "json":
case "text":
data = await response[parseAs]()
break
case "json": {
// Some servers return 200 with no Content-Length and empty body.
// response.json() would throw; read as text and parse if non-empty.
const text = await response.text()
data = text ? JSON.parse(text) : {}
break
}
case "stream":
return opts.responseStyle === "data"
? response.body
Expand Down Expand Up @@ -250,7 +244,6 @@ export const createClient = (config: Config = {}): Client => {
}
return request
},
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
url,
})
}
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/js/src/v2/gen/core/serverSentEvents.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ export const createSseClient = <TData = unknown>({
const { done, value } = await reader.read()
if (done) break
buffer += value
// Normalize line endings: CRLF -> LF, then CR -> LF
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n")

const chunks = buffer.split("\n\n")
buffer = chunks.pop() ?? ""
Expand Down
227 changes: 71 additions & 156 deletions packages/sdk/js/src/v2/gen/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
AppLogErrors,
AppLogResponses,
AppSkillsResponses,
Auth as Auth3,
Auth as Auth2,
AuthSetErrors,
AuthSetResponses,
CommandListResponses,
Expand Down Expand Up @@ -731,10 +731,7 @@ export class Resource extends HeyApiClient {
}

export class Experimental extends HeyApiClient {
private _resource?: Resource
get resource(): Resource {
return (this._resource ??= new Resource({ client: this.client }))
}
resource = new Resource({ client: this.client })
}

export class Session extends HeyApiClient {
Expand Down Expand Up @@ -1244,6 +1241,8 @@ export class Session extends HeyApiClient {
sessionID: string
directory?: string
limit?: number
ts_before?: number
breakpoint?: boolean
},
options?: Options<never, ThrowOnError>,
) {
Expand All @@ -1255,6 +1254,8 @@ export class Session extends HeyApiClient {
{ in: "path", key: "sessionID" },
{ in: "query", key: "directory" },
{ in: "query", key: "limit" },
{ in: "query", key: "ts_before" },
{ in: "query", key: "breakpoint" },
],
},
],
Expand Down Expand Up @@ -1967,10 +1968,7 @@ export class Provider extends HeyApiClient {
})
}

private _oauth?: Oauth
get oauth(): Oauth {
return (this._oauth ??= new Oauth({ client: this.client }))
}
oauth = new Oauth({ client: this.client })
}

export class Find extends HeyApiClient {
Expand Down Expand Up @@ -2281,6 +2279,43 @@ export class Auth extends HeyApiClient {
},
)
}

/**
* Set auth credentials
*
* Set authentication credentials
*/
public set<ThrowOnError extends boolean = false>(
parameters: {
providerID: string
directory?: string
auth?: Auth2
},
options?: Options<never, ThrowOnError>,
) {
const params = buildClientParams(
[parameters],
[
{
args: [
{ in: "path", key: "providerID" },
{ in: "query", key: "directory" },
{ key: "auth", map: "body" },
],
},
],
)
return (options?.client ?? this.client).put<AuthSetResponses, AuthSetErrors, ThrowOnError>({
url: "/auth/{providerID}",
...options,
...params,
headers: {
"Content-Type": "application/json",
...options?.headers,
...params.headers,
},
})
}
}

export class Mcp extends HeyApiClient {
Expand Down Expand Up @@ -2396,10 +2431,7 @@ export class Mcp extends HeyApiClient {
})
}

private _auth?: Auth
get auth(): Auth {
return (this._auth ??= new Auth({ client: this.client }))
}
auth = new Auth({ client: this.client })
}

export class Control extends HeyApiClient {
Expand Down Expand Up @@ -2734,10 +2766,7 @@ export class Tui extends HeyApiClient {
})
}

private _control?: Control
get control(): Control {
return (this._control ??= new Control({ client: this.client }))
}
control = new Control({ client: this.client })
}

export class Instance extends HeyApiClient {
Expand Down Expand Up @@ -2949,45 +2978,6 @@ export class Formatter extends HeyApiClient {
}
}

export class Auth2 extends HeyApiClient {
/**
* Set auth credentials
*
* Set authentication credentials
*/
public set<ThrowOnError extends boolean = false>(
parameters: {
providerID: string
directory?: string
auth?: Auth3
},
options?: Options<never, ThrowOnError>,
) {
const params = buildClientParams(
[parameters],
[
{
args: [
{ in: "path", key: "providerID" },
{ in: "query", key: "directory" },
{ key: "auth", map: "body" },
],
},
],
)
return (options?.client ?? this.client).put<AuthSetResponses, AuthSetErrors, ThrowOnError>({
url: "/auth/{providerID}",
...options,
...params,
headers: {
"Content-Type": "application/json",
...options?.headers,
...params.headers,
},
})
}
}

export class Event extends HeyApiClient {
/**
* Subscribe to events
Expand Down Expand Up @@ -3017,128 +3007,53 @@ export class OpencodeClient extends HeyApiClient {
OpencodeClient.__registry.set(this, args?.key)
}

private _global?: Global
get global(): Global {
return (this._global ??= new Global({ client: this.client }))
}
global = new Global({ client: this.client })

private _project?: Project
get project(): Project {
return (this._project ??= new Project({ client: this.client }))
}
project = new Project({ client: this.client })

private _pty?: Pty
get pty(): Pty {
return (this._pty ??= new Pty({ client: this.client }))
}
pty = new Pty({ client: this.client })

private _config?: Config
get config(): Config {
return (this._config ??= new Config({ client: this.client }))
}
config = new Config({ client: this.client })

private _tool?: Tool
get tool(): Tool {
return (this._tool ??= new Tool({ client: this.client }))
}
tool = new Tool({ client: this.client })

private _worktree?: Worktree
get worktree(): Worktree {
return (this._worktree ??= new Worktree({ client: this.client }))
}
worktree = new Worktree({ client: this.client })

private _experimental?: Experimental
get experimental(): Experimental {
return (this._experimental ??= new Experimental({ client: this.client }))
}
experimental = new Experimental({ client: this.client })

private _session?: Session
get session(): Session {
return (this._session ??= new Session({ client: this.client }))
}
session = new Session({ client: this.client })

private _part?: Part
get part(): Part {
return (this._part ??= new Part({ client: this.client }))
}
part = new Part({ client: this.client })

private _permission?: Permission
get permission(): Permission {
return (this._permission ??= new Permission({ client: this.client }))
}
permission = new Permission({ client: this.client })

private _question?: Question
get question(): Question {
return (this._question ??= new Question({ client: this.client }))
}
question = new Question({ client: this.client })

private _provider?: Provider
get provider(): Provider {
return (this._provider ??= new Provider({ client: this.client }))
}
provider = new Provider({ client: this.client })

private _find?: Find
get find(): Find {
return (this._find ??= new Find({ client: this.client }))
}
find = new Find({ client: this.client })

private _file?: File
get file(): File {
return (this._file ??= new File({ client: this.client }))
}
file = new File({ client: this.client })

private _mcp?: Mcp
get mcp(): Mcp {
return (this._mcp ??= new Mcp({ client: this.client }))
}
mcp = new Mcp({ client: this.client })

private _tui?: Tui
get tui(): Tui {
return (this._tui ??= new Tui({ client: this.client }))
}
tui = new Tui({ client: this.client })

private _instance?: Instance
get instance(): Instance {
return (this._instance ??= new Instance({ client: this.client }))
}
instance = new Instance({ client: this.client })

private _path?: Path
get path(): Path {
return (this._path ??= new Path({ client: this.client }))
}
path = new Path({ client: this.client })

private _vcs?: Vcs
get vcs(): Vcs {
return (this._vcs ??= new Vcs({ client: this.client }))
}
vcs = new Vcs({ client: this.client })

private _command?: Command
get command(): Command {
return (this._command ??= new Command({ client: this.client }))
}
command = new Command({ client: this.client })

private _app?: App
get app(): App {
return (this._app ??= new App({ client: this.client }))
}
app = new App({ client: this.client })

private _lsp?: Lsp
get lsp(): Lsp {
return (this._lsp ??= new Lsp({ client: this.client }))
}
lsp = new Lsp({ client: this.client })

private _formatter?: Formatter
get formatter(): Formatter {
return (this._formatter ??= new Formatter({ client: this.client }))
}
formatter = new Formatter({ client: this.client })

private _auth?: Auth2
get auth(): Auth2 {
return (this._auth ??= new Auth2({ client: this.client }))
}
auth = new Auth({ client: this.client })

private _event?: Event
get event(): Event {
return (this._event ??= new Event({ client: this.client }))
}
event = new Event({ client: this.client })
}
2 changes: 2 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,8 @@ export type SessionMessagesData = {
query?: {
directory?: string
limit?: number
ts_before?: number
breakpoint?: boolean
}
url: "/session/{sessionID}/message"
}
Expand Down
Loading