promise.test.ts 21 KB

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