promise.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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(["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. admittedSeq: 3,
  277. id: "msg_pending",
  278. sessionID: "ses_test",
  279. timeCreated: 1_717_171_717_000,
  280. type: "user",
  281. data: { text: "Fix the failing tests" },
  282. delivery: "steer",
  283. },
  284. ]
  285. const client = OpenCode.make({
  286. baseUrl: "http://localhost:3000",
  287. fetch: async (input, init) => {
  288. const request = input instanceof Request ? input : new Request(input, init)
  289. requests.push({ method: request.method, url: request.url })
  290. return Response.json({ data: pending })
  291. },
  292. })
  293. const result = await client.session.pending.list({ sessionID: "ses_test" })
  294. expect(result).toEqual(pending)
  295. expect(requests).toEqual([{ method: "GET", url: "http://localhost:3000/api/session/ses_test/pending" }])
  296. })
  297. test("event.subscribe exposes the Promise event stream wire projection", async () => {
  298. const client = OpenCode.make({
  299. baseUrl: "http://localhost:3000",
  300. fetch: async () =>
  301. new Response(
  302. `: heartbeat\n\ndata: ${JSON.stringify({ id: "evt_connected", created: 0, type: "server.connected", data: {} })}\n\n` +
  303. `data: ${JSON.stringify(modelSwitchedEvent)}\n\n`,
  304. { headers: { "content-type": "text/event-stream" } },
  305. ),
  306. })
  307. const events = []
  308. for await (const event of client.event.subscribe()) events.push(event)
  309. expect(events).toEqual([{ id: "evt_connected", created: 0, type: "server.connected", data: {} }, modelSwitchedEvent])
  310. expect(events[1]?.type === "session.model.selected" && events[1].created).toBe(1_717_171_717_000)
  311. })
  312. test("event.subscribe terminates on malformed Promise SSE data", async () => {
  313. const client = OpenCode.make({
  314. baseUrl: "http://localhost:3000",
  315. fetch: async () => new Response("data: {not-json}\n\n", { headers: { "content-type": "text/event-stream" } }),
  316. })
  317. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).rejects.toMatchObject({
  318. name: "ClientError",
  319. reason: "MalformedResponse",
  320. })
  321. })
  322. test("event.subscribe accepts a fragmented SSE event below the size limit", async () => {
  323. const event = { id: "evt_large", type: "test.large", data: { output: "x".repeat(12 * 1024 * 1024) } }
  324. const encoded = new TextEncoder().encode(`data: ${JSON.stringify(event)}\n\n`)
  325. const client = OpenCode.make({
  326. baseUrl: "http://localhost:3000",
  327. fetch: async () =>
  328. new Response(
  329. new ReadableStream({
  330. start(controller) {
  331. for (let offset = 0; offset < encoded.length; offset += 64 * 1024) {
  332. controller.enqueue(encoded.slice(offset, offset + 64 * 1024))
  333. }
  334. controller.close()
  335. },
  336. }),
  337. { headers: { "content-type": "text/event-stream" } },
  338. ),
  339. })
  340. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).resolves.toEqual({ done: false, value: event })
  341. })
  342. test("event.subscribe rejects an SSE event above the size limit", async () => {
  343. const client = OpenCode.make({
  344. baseUrl: "http://localhost:3000",
  345. fetch: async () =>
  346. new Response(`data: ${JSON.stringify({ output: "x".repeat(16 * 1024 * 1024) })}`, {
  347. headers: { "content-type": "text/event-stream" },
  348. }),
  349. })
  350. await expect(client.event.subscribe()[Symbol.asyncIterator]().next()).rejects.toMatchObject({
  351. name: "ClientError",
  352. reason: "SseEventTooLarge",
  353. })
  354. })
  355. test("session methods use the public HTTP contract", async () => {
  356. const requests: Array<{ url: string; init?: RequestInit }> = []
  357. const client = OpenCode.make({
  358. baseUrl: "http://localhost:3000",
  359. fetch: async (input, init) => {
  360. const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url
  361. requests.push({ url, init })
  362. if (url.includes("/event")) {
  363. return new Response(`data: ${JSON.stringify(modelSwitchedEvent)}\n\n`, {
  364. headers: { "content-type": "text/event-stream" },
  365. })
  366. }
  367. if (url.includes("/log")) {
  368. return new Response(`data: ${JSON.stringify(modelSwitchedEvent)}\n\ndata: ${JSON.stringify(synced)}\n\n`, {
  369. headers: { "content-type": "text/event-stream" },
  370. })
  371. }
  372. if (url.includes("/prompt")) return Response.json(admission)
  373. if (url.includes("/generate")) return Response.json({ data: { text: "A transient answer" } })
  374. if (url.includes("/synthetic")) return Response.json(syntheticAdmission)
  375. if (url.endsWith("/compact")) return Response.json(compactionAdmission)
  376. if (url.includes("/context")) return Response.json({ data: [] })
  377. if (url.includes("/message/")) return Response.json({ data: modelSwitchedMessage })
  378. if (url.endsWith("/api/session/active")) return Response.json({ data: { ses_test: { type: "running" } } })
  379. if (init?.method === "POST" && url.endsWith("/api/session")) return Response.json(session)
  380. if (init?.method === "POST") return new Response(null, { status: 204 })
  381. return Response.json({ data: [session.data], cursor: { next: "next" } })
  382. },
  383. })
  384. const page = await client.session.list({ limit: 10, order: "desc", parentID: null })
  385. const active = await client.session.active()
  386. const created = await client.session.create({ location: { directory: "/tmp/project" } })
  387. await client.session.switchAgent({ sessionID: "ses_test", agent: "build" })
  388. await client.session.switchModel({
  389. sessionID: "ses_test",
  390. model: { id: "claude", providerID: "anthropic" },
  391. })
  392. const admitted = await client.session.prompt({
  393. sessionID: "ses_test",
  394. text: "Hello",
  395. resume: false,
  396. })
  397. const generated = await client.session.generate({ sessionID: "ses_test", prompt: "Summarize this session" })
  398. const synthetic = await client.session.synthetic({
  399. sessionID: "ses_test",
  400. text: "Completed",
  401. delivery: "queue",
  402. resume: false,
  403. })
  404. await client.session.compact({ sessionID: "ses_test" })
  405. await client.session.wait({ sessionID: "ses_test" })
  406. const context = await client.session.context({ sessionID: "ses_test" })
  407. const log = []
  408. for await (const item of client.session.log({ sessionID: "ses_test", after: 0 })) log.push(item)
  409. await client.session.interrupt({ sessionID: "ses_test" })
  410. const message = await client.session.message({ sessionID: "ses_test", messageID: "msg_model" })
  411. expect(page.cursor.next).toBe("next")
  412. expect(active).toEqual({ ses_test: { type: "running" } })
  413. expect(created.id).toBe("ses_test")
  414. expect(admitted.id).toBe("msg_test")
  415. expect(generated.text).toBe("A transient answer")
  416. expect(synthetic).toMatchObject({ type: "synthetic", data: { text: "Completed" }, delivery: "queue" })
  417. expect(context).toEqual([])
  418. expect(log).toEqual([modelSwitchedEvent, synced])
  419. expect(message).toEqual(modelSwitchedMessage)
  420. expect(requests.map((request) => [request.init?.method, request.url])).toEqual([
  421. ["GET", "http://localhost:3000/api/session?limit=10&order=desc&parentID=null"],
  422. ["GET", "http://localhost:3000/api/session/active"],
  423. ["POST", "http://localhost:3000/api/session"],
  424. ["POST", "http://localhost:3000/api/session/ses_test/agent"],
  425. ["POST", "http://localhost:3000/api/session/ses_test/model"],
  426. ["POST", "http://localhost:3000/api/session/ses_test/prompt"],
  427. ["POST", "http://localhost:3000/api/session/ses_test/generate"],
  428. ["POST", "http://localhost:3000/api/session/ses_test/synthetic"],
  429. ["POST", "http://localhost:3000/api/session/ses_test/compact"],
  430. ["POST", "http://localhost:3000/api/session/ses_test/wait"],
  431. ["GET", "http://localhost:3000/api/session/ses_test/context"],
  432. ["GET", "http://localhost:3000/api/experimental/session/ses_test/log?after=0"],
  433. ["POST", "http://localhost:3000/api/session/ses_test/interrupt"],
  434. ["GET", "http://localhost:3000/api/session/ses_test/message/msg_model"],
  435. ])
  436. const body = requests.find((request) => request.url.endsWith("/api/session/ses_test/prompt"))?.init?.body
  437. if (typeof body !== "string") throw new Error("Expected JSON request body")
  438. expect(JSON.parse(body)).toEqual({
  439. text: "Hello",
  440. resume: false,
  441. })
  442. const syntheticBody = requests.find((request) => request.url.endsWith("/synthetic"))?.init?.body
  443. if (typeof syntheticBody !== "string") throw new Error("Expected JSON synthetic request body")
  444. expect(JSON.parse(syntheticBody)).toEqual({
  445. text: "Completed",
  446. delivery: "queue",
  447. resume: false,
  448. })
  449. })
  450. test("middleware errors remain declared client errors", async () => {
  451. const client = OpenCode.make({
  452. baseUrl: "http://localhost:3000",
  453. fetch: async () =>
  454. Response.json({ _tag: "UnauthorizedError", message: "Authentication required" }, { status: 401 }),
  455. })
  456. try {
  457. await client.session.create({})
  458. throw new Error("Expected request to fail")
  459. } catch (error) {
  460. expect(isUnauthorizedError(error)).toBe(true)
  461. }
  462. })
  463. test("session.log decodes SessionNotFoundError", async () => {
  464. const client = OpenCode.make({
  465. baseUrl: "http://localhost:3000",
  466. fetch: async () =>
  467. Response.json(
  468. { _tag: "SessionNotFoundError", sessionID: "ses_missing", message: "Session not found" },
  469. { status: 404 },
  470. ),
  471. })
  472. try {
  473. await client.session.log({ sessionID: "ses_missing" })[Symbol.asyncIterator]().next()
  474. throw new Error("Expected request to fail")
  475. } catch (error) {
  476. expect(isSessionNotFoundError(error)).toBe(true)
  477. }
  478. })
  479. const session = {
  480. data: {
  481. id: "ses_test",
  482. projectID: "project",
  483. cost: 0,
  484. tokens: {
  485. input: 1,
  486. output: 2,
  487. reasoning: 3,
  488. cache: { read: 4, write: 5 },
  489. },
  490. time: {
  491. created: 1_717_171_717_000,
  492. updated: 1_717_171_717_000,
  493. },
  494. title: "Test",
  495. location: { directory: "/tmp/project" },
  496. },
  497. }
  498. const admission = {
  499. data: {
  500. admittedSeq: 0,
  501. id: "msg_test",
  502. sessionID: "ses_test",
  503. type: "user",
  504. data: { text: "Hello" },
  505. delivery: "steer",
  506. timeCreated: 1_717_171_717_000,
  507. },
  508. }
  509. const syntheticAdmission = {
  510. data: {
  511. admittedSeq: 1,
  512. id: "msg_synthetic",
  513. sessionID: "ses_test",
  514. type: "synthetic",
  515. data: { text: "Completed" },
  516. delivery: "queue",
  517. timeCreated: 1_717_171_717_000,
  518. },
  519. }
  520. const compactionAdmission = {
  521. data: {
  522. type: "compaction",
  523. admittedSeq: 1,
  524. id: "msg_compaction",
  525. sessionID: "ses_test",
  526. timeCreated: 1_717_171_717_000,
  527. },
  528. }
  529. const modelSwitchedMessage = {
  530. id: "msg_model",
  531. type: "model-switched",
  532. time: { created: 1_717_171_717_000 },
  533. model: { id: "claude", providerID: "anthropic" },
  534. }
  535. const synced = { type: "log.synced", aggregateID: "ses_test", seq: 1 }
  536. const modelSwitchedEvent = {
  537. id: "evt_model",
  538. created: 1_717_171_717_000,
  539. type: "session.model.selected",
  540. durable: { aggregateID: "ses_test", seq: 1, version: 1 },
  541. data: {
  542. sessionID: "ses_test",
  543. model: { id: "claude", providerID: "anthropic" },
  544. },
  545. }