Skip to content

Commit e55fcdf

Browse files
committed
feat(session): add ts_before and breakpoint params to Session.messages API
Add optional parameters to Session.messages() for loading older messages: - ts_before: filter to messages created before this timestamp - breakpoint: stop at first compaction summary when true This is a foundational API enhancement that enables clients to implement pagination and history loading without breaking existing functionality.
1 parent e8746dd commit e55fcdf

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/opencode/src/server/routes/session.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,17 @@ export const SessionRoutes = lazy(() =>
567567
"query",
568568
z.object({
569569
limit: z.coerce.number().optional(),
570+
ts_before: z.coerce.number().optional(),
571+
breakpoint: z.coerce.boolean().optional(),
570572
}),
571573
),
572574
async (c) => {
573575
const query = c.req.valid("query")
574576
const messages = await Session.messages({
575577
sessionID: c.req.valid("param").sessionID,
576578
limit: query.limit,
579+
ts_before: query.ts_before,
580+
breakpoint: query.breakpoint,
577581
})
578582
return c.json(messages)
579583
},

packages/opencode/src/session/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,16 @@ export namespace Session {
293293
z.object({
294294
sessionID: Identifier.schema("session"),
295295
limit: z.number().optional(),
296+
ts_before: z.number().optional(),
297+
breakpoint: z.boolean().optional(),
296298
}),
297299
async (input) => {
298300
const result = [] as MessageV2.WithParts[]
299301
for await (const msg of MessageV2.stream(input.sessionID)) {
302+
if (input.ts_before && msg.info.time.created >= input.ts_before) continue
300303
if (input.limit && result.length >= input.limit) break
301304
result.push(msg)
305+
if (input.ts_before && input.breakpoint && msg.parts.some((p) => p.type === "compaction")) break
302306
}
303307
result.reverse()
304308
return result

0 commit comments

Comments
 (0)