promise.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. import { expect, test } from "bun:test"
  2. import { isSessionNotFoundError, isUnauthorizedError, OpenCode } from "../src/promise/index"
  3. test("exposes every standard HTTP API group", () => {
  4. const client = OpenCode.make({ baseUrl: "http://localhost:3000" })
  5. expect(Object.keys(client)).toEqual([
  6. "health",
  7. "server",
  8. "location",
  9. "agent",
  10. "plugin",
  11. "session",
  12. "message",
  13. "model",
  14. "generate",
  15. "provider",
  16. "integration",
  17. "mcp",
  18. "credential",
  19. "project",
  20. "form",
  21. "permission",
  22. "file",
  23. "command",
  24. "skill",
  25. "event",
  26. "pty",
  27. "shell",
  28. "question",
  29. "reference",
  30. "projectCopy",
  31. "vcs",
  32. "path",
  33. "debug",
  34. ])
  35. expect(Object.keys(client.debug)).toEqual(["location"])
  36. expect(Object.keys(client.debug.location)).toEqual(["list", "evict"])
  37. expect(Object.keys(client.message)).toEqual(["list"])
  38. expect(Object.keys(client.integration)).toEqual(["list", "get", "wellknown", "connect", "oauth", "command"])
  39. expect(Object.keys(client.integration.wellknown)).toEqual(["add"])
  40. expect(Object.keys(client.integration.connect)).toEqual(["key"])
  41. expect(Object.keys(client.integration.oauth)).toEqual(["connect", "status", "complete", "cancel"])
  42. expect(Object.keys(client.integration.command)).toEqual(["connect", "status", "cancel"])
  43. expect(Object.keys(client.file)).toEqual(["read", "list", "find"])
  44. expect(Object.keys(client.vcs)).toEqual(["get", "status", "diff"])
  45. expect(Object.keys(client.pty)).toEqual(["shells", "list", "create", "get", "update", "remove", "connectToken"])
  46. expect(Object.keys(client.shell)).toEqual(["list", "create", "get", "timeout", "output", "remove"])
  47. expect(Object.keys(client.project)).toEqual(["list", "current", "directories"])
  48. })
  49. test("PTY connect token sends the required browser header", async () => {
  50. let request: Request | undefined
  51. const client = OpenCode.make({
  52. baseUrl: "http://localhost:3000",
  53. fetch: async (input, init) => {
  54. request = input instanceof Request ? input : new Request(input, init)
  55. return Response.json({
  56. location: { directory: "/tmp/project", project: { id: "proj_test", directory: "/tmp/project" } },
  57. data: { ticket: "ticket", expires_in: 60 },
  58. })
  59. },
  60. })
  61. const result = await client.pty.connectToken({
  62. ptyID: "pty_test",
  63. location: { directory: "/tmp/project" },
  64. "x-opencode-ticket": "1",
  65. })
  66. expect(result.data.ticket).toBe("ticket")
  67. expect(request?.method).toBe("POST")
  68. expect(request?.headers.get("x-opencode-ticket")).toBe("1")
  69. expect(request?.url).toBe(
  70. "http://localhost:3000/api/pty/pty_test/connect-token?location%5Bdirectory%5D=%2Ftmp%2Fproject",
  71. )
  72. })
  73. test("server.get uses the public HTTP contract", async () => {
  74. let request: Request | undefined
  75. const client = OpenCode.make({
  76. baseUrl: "http://localhost:3000",
  77. fetch: async (input) => {
  78. request = input instanceof Request ? input : new Request(input)
  79. return Response.json({ urls: ["http://192.168.1.10:4096"] })
  80. },
  81. })
  82. expect(await client.server.get()).toEqual({ urls: ["http://192.168.1.10:4096"] })
  83. expect(request?.method).toBe("GET")
  84. expect(request?.url).toBe("http://localhost:3000/api/server")
  85. })
  86. test("experimental wellknown integration add uses the public HTTP contract", async () => {
  87. let request: Request | undefined
  88. const client = OpenCode.make({
  89. baseUrl: "http://localhost:3000",
  90. fetch: async (input, init) => {
  91. request = input instanceof Request ? input : new Request(input, init)
  92. return new Response(null, { status: 204 })
  93. },
  94. })
  95. await client.integration.wellknown.add({
  96. url: "https://example.com",
  97. location: { directory: "/tmp/project" },
  98. })
  99. expect(request?.method).toBe("POST")
  100. expect(request?.url).toBe(
  101. "http://localhost:3000/api/experimental/integration/wellknown?location%5Bdirectory%5D=%2Ftmp%2Fproject",
  102. )
  103. expect(await request?.json()).toEqual({ url: "https://example.com" })
  104. })
  105. test("health.stop sends exact replacement identity", async () => {
  106. let request: Request | undefined
  107. const client = OpenCode.make({
  108. baseUrl: "http://localhost:3000",
  109. fetch: async (input, init) => {
  110. request = input instanceof Request ? input : new Request(input, init)
  111. return Response.json({ accepted: true })
  112. },
  113. })
  114. expect(await client.health.stop({ instanceID: "instance" })).toEqual({ accepted: true })
  115. expect(request?.method).toBe("POST")
  116. expect(request?.url).toBe("http://localhost:3000/api/service/stop")
  117. expect(await request?.json()).toEqual({ instanceID: "instance" })
  118. })
  119. test("MCP resource catalog uses the public HTTP contract", async () => {
  120. let request: Request | undefined
  121. const client = OpenCode.make({
  122. baseUrl: "http://localhost:3000",
  123. fetch: async (input) => {
  124. request = input instanceof Request ? input : new Request(input)
  125. return Response.json({
  126. location: { directory: "/tmp/project", project: { id: "proj_test", directory: "/tmp/project" } },
  127. data: {
  128. resources: [{ server: "docs", name: "Readme", uri: "docs://readme" }],
  129. templates: [{ server: "docs", name: "File", uriTemplate: "docs://{path}" }],
  130. },
  131. })
  132. },
  133. })
  134. const result = await client.mcp.resource.catalog({ location: { directory: "/tmp/project" } })
  135. expect(result.data.resources[0]?.uri).toBe("docs://readme")
  136. expect(request?.method).toBe("GET")
  137. expect(request?.url).toBe("http://localhost:3000/api/mcp/resource?location%5Bdirectory%5D=%2Ftmp%2Fproject")
  138. })
  139. test("file.read returns binary content from the public HTTP contract", async () => {
  140. let request: Request | undefined
  141. const client = OpenCode.make({
  142. baseUrl: "http://localhost:3000",
  143. fetch: async (input) => {
  144. request = input instanceof Request ? input : new Request(input)
  145. return new Response(new Uint8Array([104, 105]))
  146. },
  147. })
  148. const content = await client.file.read({
  149. path: "src/a b#c.ts",
  150. location: { directory: "/tmp/project" },
  151. })
  152. expect(Array.from(content)).toEqual([104, 105])
  153. expect(request?.url).toBe(
  154. "http://localhost:3000/api/fs/read/src/a%20b%23c.ts?location%5Bdirectory%5D=%2Ftmp%2Fproject",
  155. )
  156. })
  157. test("project methods use the public HTTP contract", async () => {
  158. const requests: string[] = []
  159. const client = OpenCode.make({
  160. baseUrl: "http://localhost:3000",
  161. fetch: async (input) => {
  162. const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url
  163. requests.push(url)
  164. if (url.includes("/directories")) return Response.json([])
  165. return Response.json({ id: "proj_test", directory: "/tmp/project" })
  166. },
  167. })
  168. const current = await client.project.current({ location: { workspace: "wrk_test" } })
  169. const directories = await client.project.directories({
  170. projectID: current.id,
  171. location: { directory: current.directory },
  172. })
  173. expect(current).toEqual({ id: "proj_test", directory: "/tmp/project" })
  174. expect(directories).toEqual([])
  175. expect(requests).toEqual([
  176. "http://localhost:3000/api/project/current?location%5Bworkspace%5D=wrk_test",
  177. "http://localhost:3000/api/project/proj_test/directories?location%5Bdirectory%5D=%2Ftmp%2Fproject",
  178. ])
  179. })
  180. test("shell list and remove use the public HTTP contract", async () => {
  181. const requests: Array<{ method: string; url: string }> = []
  182. const shell = {
  183. id: "sh_test",
  184. status: "running",
  185. command: "pwd",
  186. cwd: "/tmp/project",
  187. shell: "/bin/zsh",
  188. file: "/tmp/opencode-shell",
  189. metadata: { sessionID: "ses_test" },
  190. time: { started: 1_717_171_717_000 },
  191. }
  192. const client = OpenCode.make({
  193. baseUrl: "http://localhost:3000",
  194. fetch: async (input, init) => {
  195. const request = input instanceof Request ? input : new Request(input, init)
  196. requests.push({ method: request.method, url: request.url })
  197. if (request.method === "DELETE") return new Response(null, { status: 204 })
  198. return Response.json({
  199. location: { directory: "/tmp/project", project: { id: "proj_test", directory: "/tmp/project" } },
  200. data: [shell],
  201. })
  202. },
  203. })
  204. const result = await client.shell.list({ location: { directory: "/tmp/project" } })
  205. await client.shell.remove({ id: shell.id })
  206. expect(result.data).toEqual([shell])
  207. expect(requests).toEqual([
  208. { method: "GET", url: "http://localhost:3000/api/shell?location%5Bdirectory%5D=%2Ftmp%2Fproject" },
  209. { method: "DELETE", url: "http://localhost:3000/api/shell/sh_test" },
  210. ])
  211. })
  212. test("session.get returns the wire projection", async () => {
  213. const client = OpenCode.make({
  214. baseUrl: "http://localhost:3000",
  215. fetch: async (input) => {
  216. expect(typeof input === "string" ? input : input instanceof URL ? input.href : input.url).toBe(
  217. "http://localhost:3000/api/session/ses_test",
  218. )
  219. return Response.json(session)
  220. },
  221. })
  222. const result = await client.session.get({ sessionID: "ses_test" })
  223. expect(result.time.created).toBe(1_717_171_717_000)
  224. })
  225. test("session instructions methods use the public HTTP contract", async () => {
  226. const requests: Array<{ method: string; url: string; body?: unknown }> = []
  227. const instructions = [{ key: "review-notes", value: { text: "Check the diff", priority: 1 } }]
  228. const client = OpenCode.make({
  229. baseUrl: "http://localhost:3000",
  230. fetch: async (input, init) => {
  231. const request = input instanceof Request ? input : new Request(input, init)
  232. requests.push({
  233. method: request.method,
  234. url: request.url,
  235. body: request.method === "PUT" ? await request.json() : undefined,
  236. })
  237. if (request.method === "GET") return Response.json({ data: instructions })
  238. return new Response(null, { status: 204 })
  239. },
  240. })
  241. const result = await client.session.instructions.entry.list({ sessionID: "ses_test" })
  242. await client.session.instructions.entry.put({
  243. sessionID: "ses_test",
  244. key: "review-notes",
  245. value: instructions[0].value,
  246. })
  247. await client.session.instructions.entry.remove({ sessionID: "ses_test", key: "review-notes" })
  248. expect(result).toEqual(instructions)
  249. expect(requests).toEqual([
  250. {
  251. method: "GET",
  252. url: "http://localhost:3000/api/session/ses_test/instructions/entries",
  253. body: undefined,
  254. },
  255. {
  256. method: "PUT",
  257. url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
  258. body: { value: { text: "Check the diff", priority: 1 } },
  259. },
  260. {
  261. method: "DELETE",
  262. url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
  263. body: undefined,
  264. },
  265. ])
  266. })
  267. test("session.pending.list uses the public HTTP contract", async () => {
  268. const requests: Array<{ method: string; url: string }> = []
  269. const pending = [
  270. {
  271. admittedSeq: 3,
  272. id: "msg_pending",
  273. sessionID: "ses_test",
  274. timeCreated: 1_717_171_717_000,
  275. type: "user",
  276. data: { text: "Fix the failing tests" },
  277. delivery: "steer",
  278. },
  279. ]
  280. const client = OpenCode.make({
  281. baseUrl: "http://localhost:3000",
  282. fetch: async (input, init) => {
  283. const request = input instanceof Request ? input : new Request(input, init)
  284. requests.push({ method: request.method, url: request.url })
  285. return Response.json({ data: pending })
  286. },
  287. })
  288. const result = await client.session.pending.list({ sessionID: "ses_test" })
  289. expect(result).toEqual(pending)
  290. expect(requests).toEqual([{ method: "GET", url: "http://localhost:3000/api/session/ses_test/pending" }])
  291. })
  292. test("event.subscribe exposes the Promise event stream wire projection", async () => {
  293. const client = OpenCode.make({
  294. baseUrl: "http://localhost:3000",
  295. fetch: async () =>
  296. new Response(
  297. `: heartbeat\n\ndata: ${JSON.stringify({ id: "evt_connected", created: 0, type: "server.connected", data: {} })}\n\n` +
  298. `data: ${JSON.stringify(modelSwitchedEvent)}\n\n`,
  299. { headers: { "content-type": "text/event-stream" } },
  300. ),
  301. })
  302. const events = []
  303. for await (const event of client.event.subscribe()) events.push(event)
  304. expect(events).toEqual([{ id: "evt_connected", created: 0, type: "server.connected", data: {} }, modelSwitchedEvent])
  305. expect(events[1]?.type === "session.model.selected" && events[1].created).toBe(1_717_171_717_000)
  306. })
  307. test("event.subscribe terminates on malformed Promise SSE data", async () => {
  308. const client = OpenCode.make({
  309. baseUrl: "http://localhost:3000",
  310. fetch: async () => new Response("data: {not-json}\n\n", { headers: { "content-type": "text/event-stream" } }),
  311. })
  312. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).rejects.toMatchObject({
  313. name: "ClientError",
  314. reason: "MalformedResponse",
  315. })
  316. })
  317. test("event.subscribe accepts a fragmented SSE event below the size limit", async () => {
  318. const event = { id: "evt_large", type: "test.large", data: { output: "x".repeat(12 * 1024 * 1024) } }
  319. const encoded = new TextEncoder().encode(`data: ${JSON.stringify(event)}\n\n`)
  320. const client = OpenCode.make({
  321. baseUrl: "http://localhost:3000",
  322. fetch: async () =>
  323. new Response(
  324. new ReadableStream({
  325. start(controller) {
  326. for (let offset = 0; offset < encoded.length; offset += 64 * 1024) {
  327. controller.enqueue(encoded.slice(offset, offset + 64 * 1024))
  328. }
  329. controller.close()
  330. },
  331. }),
  332. { headers: { "content-type": "text/event-stream" } },
  333. ),
  334. })
  335. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).resolves.toEqual({ done: false, value: event })
  336. })
  337. test("event.subscribe rejects an SSE event above the size limit", async () => {
  338. const client = OpenCode.make({
  339. baseUrl: "http://localhost:3000",
  340. fetch: async () =>
  341. new Response(`data: ${JSON.stringify({ output: "x".repeat(16 * 1024 * 1024) })}`, {
  342. headers: { "content-type": "text/event-stream" },
  343. }),
  344. })
  345. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).rejects.toMatchObject({
  346. name: "ClientError",
  347. reason: "SseEventTooLarge",
  348. })
  349. })
  350. test("session methods use the public HTTP contract", async () => {
  351. const requests: Array<{ url: string; init?: RequestInit }> = []
  352. const client = OpenCode.make({
  353. baseUrl: "http://localhost:3000",
  354. fetch: async (input, init) => {
  355. const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url
  356. requests.push({ url, init })
  357. if (url.includes("/event")) {
  358. return new Response(`data: ${JSON.stringify(modelSwitchedEvent)}\n\n`, {
  359. headers: { "content-type": "text/event-stream" },
  360. })
  361. }
  362. if (url.includes("/log")) {
  363. return new Response(`data: ${JSON.stringify(modelSwitchedEvent)}\n\ndata: ${JSON.stringify(synced)}\n\n`, {
  364. headers: { "content-type": "text/event-stream" },
  365. })
  366. }
  367. if (url.includes("/prompt")) return Response.json(admission)
  368. if (url.includes("/generate")) return Response.json({ data: { text: "A transient answer" } })
  369. if (url.includes("/synthetic")) return Response.json(syntheticAdmission)
  370. if (url.endsWith("/compact")) return Response.json(compactionAdmission)
  371. if (url.includes("/context")) return Response.json({ data: [] })
  372. if (url.includes("/message/")) return Response.json({ data: modelSwitchedMessage })
  373. if (url.endsWith("/api/session/active")) return Response.json({ data: { ses_test: { type: "running" } } })
  374. if (init?.method === "POST" && url.endsWith("/api/session")) return Response.json(session)
  375. if (init?.method === "POST") return new Response(null, { status: 204 })
  376. return Response.json({ data: [session.data], cursor: { next: "next" } })
  377. },
  378. })
  379. const page = await client.session.list({ limit: 10, order: "desc", parentID: null })
  380. const active = await client.session.active()
  381. const created = await client.session.create({ location: { directory: "/tmp/project" } })
  382. await client.session.switchAgent({ sessionID: "ses_test", agent: "build" })
  383. await client.session.switchModel({
  384. sessionID: "ses_test",
  385. model: { id: "claude", providerID: "anthropic" },
  386. })
  387. const admitted = await client.session.prompt({
  388. sessionID: "ses_test",
  389. text: "Hello",
  390. resume: false,
  391. })
  392. const generated = await client.session.generate({ sessionID: "ses_test", prompt: "Summarize this session" })
  393. const synthetic = await client.session.synthetic({
  394. sessionID: "ses_test",
  395. text: "Completed",
  396. delivery: "queue",
  397. resume: false,
  398. })
  399. await client.session.compact({ sessionID: "ses_test" })
  400. await client.session.wait({ sessionID: "ses_test" })
  401. const context = await client.session.context({ sessionID: "ses_test" })
  402. const log = []
  403. for await (const item of client.session.log({ sessionID: "ses_test", after: 0 })) log.push(item)
  404. await client.session.interrupt({ sessionID: "ses_test" })
  405. const message = await client.session.message({ sessionID: "ses_test", messageID: "msg_model" })
  406. expect(page.cursor.next).toBe("next")
  407. expect(active).toEqual({ ses_test: { type: "running" } })
  408. expect(created.id).toBe("ses_test")
  409. expect(admitted.id).toBe("msg_test")
  410. expect(generated.text).toBe("A transient answer")
  411. expect(synthetic).toMatchObject({ type: "synthetic", data: { text: "Completed" }, delivery: "queue" })
  412. expect(context).toEqual([])
  413. expect(log).toEqual([modelSwitchedEvent, synced])
  414. expect(message).toEqual(modelSwitchedMessage)
  415. expect(requests.map((request) => [request.init?.method, request.url])).toEqual([
  416. ["GET", "http://localhost:3000/api/session?limit=10&order=desc&parentID=null"],
  417. ["GET", "http://localhost:3000/api/session/active"],
  418. ["POST", "http://localhost:3000/api/session"],
  419. ["POST", "http://localhost:3000/api/session/ses_test/agent"],
  420. ["POST", "http://localhost:3000/api/session/ses_test/model"],
  421. ["POST", "http://localhost:3000/api/session/ses_test/prompt"],
  422. ["POST", "http://localhost:3000/api/session/ses_test/generate"],
  423. ["POST", "http://localhost:3000/api/session/ses_test/synthetic"],
  424. ["POST", "http://localhost:3000/api/session/ses_test/compact"],
  425. ["POST", "http://localhost:3000/api/session/ses_test/wait"],
  426. ["GET", "http://localhost:3000/api/session/ses_test/context"],
  427. ["GET", "http://localhost:3000/api/experimental/session/ses_test/log?after=0"],
  428. ["POST", "http://localhost:3000/api/session/ses_test/interrupt"],
  429. ["GET", "http://localhost:3000/api/session/ses_test/message/msg_model"],
  430. ])
  431. const body = requests.find((request) => request.url.endsWith("/api/session/ses_test/prompt"))?.init?.body
  432. if (typeof body !== "string") throw new Error("Expected JSON request body")
  433. expect(JSON.parse(body)).toEqual({
  434. text: "Hello",
  435. resume: false,
  436. })
  437. const syntheticBody = requests.find((request) => request.url.endsWith("/synthetic"))?.init?.body
  438. if (typeof syntheticBody !== "string") throw new Error("Expected JSON synthetic request body")
  439. expect(JSON.parse(syntheticBody)).toEqual({
  440. text: "Completed",
  441. delivery: "queue",
  442. resume: false,
  443. })
  444. })
  445. test("middleware errors remain declared client errors", async () => {
  446. const client = OpenCode.make({
  447. baseUrl: "http://localhost:3000",
  448. fetch: async () =>
  449. Response.json({ _tag: "UnauthorizedError", message: "Authentication required" }, { status: 401 }),
  450. })
  451. try {
  452. await client.session.create({})
  453. throw new Error("Expected request to fail")
  454. } catch (error) {
  455. expect(isUnauthorizedError(error)).toBe(true)
  456. }
  457. })
  458. test("session.log decodes SessionNotFoundError", async () => {
  459. const client = OpenCode.make({
  460. baseUrl: "http://localhost:3000",
  461. fetch: async () =>
  462. Response.json(
  463. { _tag: "SessionNotFoundError", sessionID: "ses_missing", message: "Session not found" },
  464. { status: 404 },
  465. ),
  466. })
  467. try {
  468. await client.session.log({ sessionID: "ses_missing" })[Symbol.asyncIterator]().next()
  469. throw new Error("Expected request to fail")
  470. } catch (error) {
  471. expect(isSessionNotFoundError(error)).toBe(true)
  472. }
  473. })
  474. const session = {
  475. data: {
  476. id: "ses_test",
  477. projectID: "project",
  478. cost: 0,
  479. tokens: {
  480. input: 1,
  481. output: 2,
  482. reasoning: 3,
  483. cache: { read: 4, write: 5 },
  484. },
  485. time: {
  486. created: 1_717_171_717_000,
  487. updated: 1_717_171_717_000,
  488. },
  489. title: "Test",
  490. location: { directory: "/tmp/project" },
  491. },
  492. }
  493. const admission = {
  494. data: {
  495. admittedSeq: 0,
  496. id: "msg_test",
  497. sessionID: "ses_test",
  498. type: "user",
  499. data: { text: "Hello" },
  500. delivery: "steer",
  501. timeCreated: 1_717_171_717_000,
  502. },
  503. }
  504. const syntheticAdmission = {
  505. data: {
  506. admittedSeq: 1,
  507. id: "msg_synthetic",
  508. sessionID: "ses_test",
  509. type: "synthetic",
  510. data: { text: "Completed" },
  511. delivery: "queue",
  512. timeCreated: 1_717_171_717_000,
  513. },
  514. }
  515. const compactionAdmission = {
  516. data: {
  517. type: "compaction",
  518. admittedSeq: 1,
  519. id: "msg_compaction",
  520. sessionID: "ses_test",
  521. timeCreated: 1_717_171_717_000,
  522. },
  523. }
  524. const modelSwitchedMessage = {
  525. id: "msg_model",
  526. type: "model-switched",
  527. time: { created: 1_717_171_717_000 },
  528. model: { id: "claude", providerID: "anthropic" },
  529. }
  530. const synced = { type: "log.synced", aggregateID: "ses_test", seq: 1 }
  531. const modelSwitchedEvent = {
  532. id: "evt_model",
  533. created: 1_717_171_717_000,
  534. type: "session.model.selected",
  535. durable: { aggregateID: "ses_test", seq: 1, version: 1 },
  536. data: {
  537. sessionID: "ses_test",
  538. model: { id: "claude", providerID: "anthropic" },
  539. },
  540. }