mayura 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/README.md +2 -0
  2. package/docs/README.md +17 -5
  3. package/docs/cli/init.md +15 -3
  4. package/docs/guides/choosing-a-starter.md +80 -0
  5. package/docs/guides/framework-starters.md +5 -1
  6. package/docs/guides/hono.md +94 -0
  7. package/docs/guides/nextjs.md +94 -0
  8. package/docs/guides/nuxt.md +94 -0
  9. package/docs/guides/rag-deployment.md +48 -0
  10. package/docs/guides/rag-modal-pinecone-starter.md +63 -0
  11. package/docs/guides/rag-production.md +34 -15
  12. package/docs/guides/rag-quickstart.md +119 -0
  13. package/docs/guides/rag.md +11 -1
  14. package/docs/guides/react-router.md +94 -0
  15. package/docs/guides/release-readiness.md +76 -39
  16. package/docs/guides/sveltekit.md +94 -0
  17. package/docs/guides/tanstack-start.md +94 -0
  18. package/docs/integrations/reranker-cohere.md +1 -0
  19. package/docs/integrations/reranker-jina.md +1 -0
  20. package/docs/integrations/reranker-voyage.md +1 -0
  21. package/docs/integrations/vector-chroma.md +1 -0
  22. package/docs/integrations/vector-libsql.md +1 -0
  23. package/docs/integrations/vector-pgvector.md +1 -0
  24. package/docs/integrations/vector-pinecone.md +4 -1
  25. package/docs/integrations/vector-qdrant.md +1 -0
  26. package/docs/integrations/vector-weaviate.md +1 -0
  27. package/docs/introduction.md +5 -0
  28. package/docs/project/whats-new.md +70 -2
  29. package/docs/quickstart.md +5 -3
  30. package/lib/adapter-code-docker/image/Dockerfile +1 -1
  31. package/lib/adapter-code-docker/package.json +1 -1
  32. package/lib/adapter-code-quickjs/package.json +1 -1
  33. package/lib/adapter-mcp/package.json +1 -1
  34. package/lib/ag-ui/package.json +1 -1
  35. package/lib/artifacts/package.json +1 -1
  36. package/lib/auth/package.json +1 -1
  37. package/lib/authz/package.json +1 -1
  38. package/lib/browser/package.json +1 -1
  39. package/lib/cli/dist/index.d.ts +1 -1
  40. package/lib/cli/dist/index.d.ts.map +1 -1
  41. package/lib/cli/dist/index.js +63 -20
  42. package/lib/cli/dist/index.js.map +1 -1
  43. package/lib/cli/dist/interactive.js +2 -2
  44. package/lib/cli/dist/interactive.js.map +1 -1
  45. package/lib/cli/package.json +1 -1
  46. package/lib/cli/src/index.ts +51 -12
  47. package/lib/cli/src/interactive.ts +2 -2
  48. package/lib/cli/starter-assets/manifest.json +1 -0
  49. package/lib/cli/starters/hono/package.json +2 -2
  50. package/lib/cli/starters/rag-modal-pinecone/README.md +60 -0
  51. package/lib/cli/starters/rag-modal-pinecone/dot-env.example +23 -0
  52. package/lib/cli/starters/{event-automation → rag-modal-pinecone}/dot-gitignore +2 -4
  53. package/lib/cli/starters/rag-modal-pinecone/fixtures/on-call.md +4 -0
  54. package/lib/cli/starters/rag-modal-pinecone/mayura.project.json +13 -0
  55. package/lib/cli/starters/rag-modal-pinecone/modal-app.py +110 -0
  56. package/lib/cli/starters/rag-modal-pinecone/package.json +28 -0
  57. package/lib/cli/starters/rag-modal-pinecone/src/application.ts +148 -0
  58. package/lib/cli/starters/rag-modal-pinecone/src/cli.ts +78 -0
  59. package/lib/cli/starters/rag-modal-pinecone/src/hosted.ts +137 -0
  60. package/lib/cli/starters/rag-modal-pinecone/test/modal_worker_test.py +53 -0
  61. package/lib/cli/starters/rag-modal-pinecone/test/pipeline.test.ts +137 -0
  62. package/lib/cli/starters/{cli-agent → rag-modal-pinecone}/tsconfig.json +0 -1
  63. package/lib/client/package.json +1 -1
  64. package/lib/client-react/package.json +1 -1
  65. package/lib/code-mode/package.json +1 -1
  66. package/lib/code-mode-workflows/package.json +1 -1
  67. package/lib/context/package.json +1 -1
  68. package/lib/core/package.json +1 -1
  69. package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
  70. package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
  71. package/lib/exporter-otlp/dist/signals.js +2 -2
  72. package/lib/exporter-otlp/dist/signals.js.map +1 -1
  73. package/lib/exporter-otlp/package.json +1 -1
  74. package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
  75. package/lib/exporter-otlp/src/signals.ts +2 -2
  76. package/lib/files/package.json +1 -1
  77. package/lib/guardrails/package.json +1 -1
  78. package/lib/helpers/package.json +1 -1
  79. package/lib/keys/package.json +1 -1
  80. package/lib/memory/package.json +1 -1
  81. package/lib/memory-remote/package.json +1 -1
  82. package/lib/observability/package.json +1 -1
  83. package/lib/provider-anthropic/package.json +1 -1
  84. package/lib/provider-openai/package.json +1 -1
  85. package/lib/rag/package.json +1 -1
  86. package/lib/runtime/package.json +1 -1
  87. package/lib/sandbox/package.json +1 -1
  88. package/lib/sdk/package.json +1 -1
  89. package/lib/server/package.json +1 -1
  90. package/lib/server-node/package.json +1 -1
  91. package/lib/skills/package.json +1 -1
  92. package/lib/storage/package.json +1 -1
  93. package/lib/storage-contracts/package.json +1 -1
  94. package/lib/storage-postgres/package.json +1 -1
  95. package/lib/storage-sql/package.json +1 -1
  96. package/lib/storage-sqlite/package.json +1 -1
  97. package/lib/terminal/package.json +1 -1
  98. package/lib/testing/package.json +1 -1
  99. package/lib/threads/package.json +1 -1
  100. package/lib/tools/package.json +1 -1
  101. package/lib/voice/package.json +1 -1
  102. package/lib/workflows/package.json +1 -1
  103. package/lib/workstream/package.json +1 -1
  104. package/llms-full.txt +1362 -289
  105. package/llms.txt +17 -4
  106. package/package.json +4 -4
  107. package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +0 -13
  108. package/lib/cli/starters/cli-agent/dot-gitignore +0 -10
  109. package/lib/cli/starters/event-automation/dot-dockerignore +0 -7
  110. package/lib/cli/starters/event-automation/dot-github/workflows/ci.yml +0 -13
  111. package/lib/cli/starters/event-automation/src/model.ts +0 -40
  112. package/lib/cli/starters/event-automation/tsconfig.json +0 -20
  113. package/lib/cli/starters/nextjs/Dockerfile +0 -12
  114. package/lib/cli/starters/nextjs/compose.yaml +0 -19
  115. package/lib/cli/starters/nextjs/dot-dockerignore +0 -11
  116. package/lib/cli/starters/nextjs/dot-env.example +0 -7
  117. package/lib/cli/starters/nextjs/scripts/setup.mjs +0 -9
  118. package/lib/cli/starters/nextjs/server/application.mjs +0 -74
  119. package/lib/cli/starters/nextjs/server/auth.mjs +0 -24
  120. package/lib/cli/starters/nextjs/server/worker.mjs +0 -11
  121. package/lib/cli/starters/nextjs/server/workflows.mjs +0 -23
  122. package/lib/cli/starters/nextjs/src/ChatApp.jsx +0 -57
  123. package/lib/cli/starters/nextjs/src/Notebook.jsx +0 -25
  124. package/lib/cli/starters/nextjs/src/components/mayura/approval.tsx +0 -142
  125. package/lib/cli/starters/nextjs/src/components/mayura/thread-history.tsx +0 -142
  126. package/lib/cli/starters/nextjs/src/components/mayura/thread-list.tsx +0 -9
  127. package/lib/cli/starters/nextjs/src/components/mayura/ui.css +0 -14
  128. package/lib/cli/starters/nextjs/src/connect.js +0 -21
  129. package/lib/cli/starters/nextjs/src/session.js +0 -138
  130. package/lib/cli/starters/nextjs/src/style.css +0 -11
  131. package/lib/cli/starters/nextjs/test/server.test.mjs +0 -95
  132. package/lib/cli/starters/nextjs/test/session.test.mjs +0 -16
  133. package/lib/cli/starters/nuxt/compose.yaml +0 -19
  134. package/lib/cli/starters/nuxt/dot-dockerignore +0 -11
  135. package/lib/cli/starters/nuxt/dot-env.example +0 -7
  136. package/lib/cli/starters/nuxt/dot-gitignore +0 -14
  137. package/lib/cli/starters/nuxt/scripts/setup.mjs +0 -9
  138. package/lib/cli/starters/nuxt/server/application.mjs +0 -74
  139. package/lib/cli/starters/nuxt/server/auth.mjs +0 -24
  140. package/lib/cli/starters/nuxt/server/worker.mjs +0 -11
  141. package/lib/cli/starters/nuxt/server/workflows.mjs +0 -23
  142. package/lib/cli/starters/nuxt/src/connect.js +0 -21
  143. package/lib/cli/starters/nuxt/src/session.js +0 -138
  144. package/lib/cli/starters/nuxt/src/style.css +0 -11
  145. package/lib/cli/starters/nuxt/test/server.test.mjs +0 -95
  146. package/lib/cli/starters/nuxt/test/session.test.mjs +0 -16
  147. package/lib/cli/starters/react-router/Dockerfile +0 -12
  148. package/lib/cli/starters/react-router/compose.yaml +0 -19
  149. package/lib/cli/starters/react-router/dot-dockerignore +0 -11
  150. package/lib/cli/starters/react-router/dot-env.example +0 -7
  151. package/lib/cli/starters/react-router/dot-gitignore +0 -14
  152. package/lib/cli/starters/react-router/scripts/setup.mjs +0 -9
  153. package/lib/cli/starters/react-router/server/application.mjs +0 -74
  154. package/lib/cli/starters/react-router/server/auth.mjs +0 -24
  155. package/lib/cli/starters/react-router/server/worker.mjs +0 -11
  156. package/lib/cli/starters/react-router/server/workflows.mjs +0 -23
  157. package/lib/cli/starters/react-router/src/ChatApp.jsx +0 -57
  158. package/lib/cli/starters/react-router/src/Notebook.jsx +0 -25
  159. package/lib/cli/starters/react-router/src/components/mayura/approval.tsx +0 -142
  160. package/lib/cli/starters/react-router/src/components/mayura/thread-history.tsx +0 -142
  161. package/lib/cli/starters/react-router/src/components/mayura/thread-list.tsx +0 -9
  162. package/lib/cli/starters/react-router/src/components/mayura/ui.css +0 -14
  163. package/lib/cli/starters/react-router/src/connect.js +0 -21
  164. package/lib/cli/starters/react-router/src/session.js +0 -138
  165. package/lib/cli/starters/react-router/src/style.css +0 -11
  166. package/lib/cli/starters/react-router/src/vite-env.d.ts +0 -1
  167. package/lib/cli/starters/react-router/test/server.test.mjs +0 -95
  168. package/lib/cli/starters/react-router/test/session.test.mjs +0 -16
  169. package/lib/cli/starters/research-team/dot-dockerignore +0 -7
  170. package/lib/cli/starters/research-team/dot-github/workflows/ci.yml +0 -13
  171. package/lib/cli/starters/research-team/dot-gitignore +0 -10
  172. package/lib/cli/starters/research-team/src/model.ts +0 -40
  173. package/lib/cli/starters/research-team/tsconfig.json +0 -20
  174. package/lib/cli/starters/support-agent/dot-dockerignore +0 -7
  175. package/lib/cli/starters/support-agent/dot-github/workflows/ci.yml +0 -13
  176. package/lib/cli/starters/support-agent/dot-gitignore +0 -10
  177. package/lib/cli/starters/support-agent/src/model.ts +0 -40
  178. package/lib/cli/starters/support-agent/tsconfig.json +0 -20
  179. package/lib/cli/starters/sveltekit/Dockerfile +0 -12
  180. package/lib/cli/starters/sveltekit/compose.yaml +0 -19
  181. package/lib/cli/starters/sveltekit/dot-dockerignore +0 -11
  182. package/lib/cli/starters/sveltekit/dot-env.example +0 -7
  183. package/lib/cli/starters/sveltekit/dot-gitignore +0 -14
  184. package/lib/cli/starters/sveltekit/scripts/setup.mjs +0 -9
  185. package/lib/cli/starters/sveltekit/server/application.mjs +0 -74
  186. package/lib/cli/starters/sveltekit/server/auth.mjs +0 -24
  187. package/lib/cli/starters/sveltekit/server/worker.mjs +0 -11
  188. package/lib/cli/starters/sveltekit/server/workflows.mjs +0 -23
  189. package/lib/cli/starters/sveltekit/src/connect.js +0 -21
  190. package/lib/cli/starters/sveltekit/src/session.js +0 -138
  191. package/lib/cli/starters/sveltekit/src/style.css +0 -11
  192. package/lib/cli/starters/sveltekit/src/view.js +0 -49
  193. package/lib/cli/starters/sveltekit/test/server.test.mjs +0 -95
  194. package/lib/cli/starters/sveltekit/test/session.test.mjs +0 -16
  195. package/lib/cli/starters/tanstack-start/Dockerfile +0 -12
  196. package/lib/cli/starters/tanstack-start/compose.yaml +0 -19
  197. package/lib/cli/starters/tanstack-start/dot-dockerignore +0 -11
  198. package/lib/cli/starters/tanstack-start/dot-env.example +0 -7
  199. package/lib/cli/starters/tanstack-start/dot-gitignore +0 -14
  200. package/lib/cli/starters/tanstack-start/scripts/setup.mjs +0 -9
  201. package/lib/cli/starters/tanstack-start/server/application.mjs +0 -74
  202. package/lib/cli/starters/tanstack-start/server/auth.mjs +0 -24
  203. package/lib/cli/starters/tanstack-start/server/worker.mjs +0 -11
  204. package/lib/cli/starters/tanstack-start/server/workflows.mjs +0 -23
  205. package/lib/cli/starters/tanstack-start/src/ChatApp.jsx +0 -57
  206. package/lib/cli/starters/tanstack-start/src/Notebook.jsx +0 -25
  207. package/lib/cli/starters/tanstack-start/src/components/mayura/approval.tsx +0 -142
  208. package/lib/cli/starters/tanstack-start/src/components/mayura/thread-history.tsx +0 -142
  209. package/lib/cli/starters/tanstack-start/src/components/mayura/thread-list.tsx +0 -9
  210. package/lib/cli/starters/tanstack-start/src/components/mayura/ui.css +0 -14
  211. package/lib/cli/starters/tanstack-start/src/connect.js +0 -21
  212. package/lib/cli/starters/tanstack-start/src/session.js +0 -138
  213. package/lib/cli/starters/tanstack-start/src/style.css +0 -11
  214. package/lib/cli/starters/tanstack-start/test/server.test.mjs +0 -95
  215. package/lib/cli/starters/tanstack-start/test/session.test.mjs +0 -16
  216. /package/lib/cli/{starters/hono/src/components/mayura/ui.css → starter-assets/011cacc77ada0de5b447674e9fc4374a247b9a46eb169722b12649753f24188f} +0 -0
  217. /package/lib/cli/{starters/hono/test/server.test.mjs → starter-assets/0c825d6a776673ec6274cfc29cd45b1a8c56dcb880c291a91075c77e1ef1e4f3} +0 -0
  218. /package/lib/cli/{starters/hono/server/auth.mjs → starter-assets/0dd570bfacc357d23be3340250090b9a4c6193a49cdd02e9b6789e7bee8433dd} +0 -0
  219. /package/lib/cli/{starters/hono/src/components/mayura/approval.tsx → starter-assets/11292bd14cdaf27a8f8317ba4ab768d706a726b2e26474b599f3db116674b4b3} +0 -0
  220. /package/lib/cli/{starters/nextjs/dot-gitignore → starter-assets/1873b02e070347f9a449e07084242982fa6af412c45aa764985d553975b64589} +0 -0
  221. /package/lib/cli/{starters/hono/src/style.css → starter-assets/2f3869e6d69134e43be713c4590bfe48896a5c54ece6ffc1a4f204cfcfe54218} +0 -0
  222. /package/lib/cli/{starters/hono/server/worker.mjs → starter-assets/350d77757f548369beff29d658cf1620752d4e23b4b732d99a1b403ca043137f} +0 -0
  223. /package/lib/cli/{starters/approval-workflow/src/model.ts → starter-assets/37294d24c04b71eaf6d6f0bd52fd4c1cc7a5d3cb63da9c7920ed1d44276da9cb} +0 -0
  224. /package/lib/cli/{starters/approval-workflow/tsconfig.json → starter-assets/4387d6537dd5924ae62326aa3d7d8cbad1e5abd930aecc9daa6fab1ac2f6ef24} +0 -0
  225. /package/lib/cli/{starters/hono/dot-dockerignore → starter-assets/4434be031b58cc6ee680b2860b2ad1fe4089af7ee866c13223dfb621dd042ff1} +0 -0
  226. /package/lib/cli/{starters/hono/src/ChatApp.jsx → starter-assets/46e199317648a076243d6c8e7ffedc48785a6ffc0f203b88c7c4a9479b34c5b9} +0 -0
  227. /package/lib/cli/{starters/hono/src/components/mayura/thread-history.tsx → starter-assets/4741fccbca2e0d2fc6f61d11af3cf7bcc5f0238b67bb46282287207abdc6c536} +0 -0
  228. /package/lib/cli/{starters/approval-workflow/dot-dockerignore → starter-assets/4be664708b0120da5d2b73c5a27968093da06b8728f88f2bda2a1ccbf40f6891} +0 -0
  229. /package/lib/cli/{starters/hono/server/workflows.mjs → starter-assets/4d11f729672df54969a851494877a3c5aee24bb8f8c68eacaaa22e715bf5ed69} +0 -0
  230. /package/lib/cli/{starters/hono/dot-env.example → starter-assets/4f141323062660c4dc5b563300d57bb4cdbdc7fe9bfba96e43d9c64bb274474e} +0 -0
  231. /package/lib/cli/{starters/hono/Dockerfile → starter-assets/5471b74c46258d1edb00eb8f60f4219c389a252f7e224f2692f8f3e71ae43e3e} +0 -0
  232. /package/lib/cli/{starters/hono/scripts/setup.mjs → starter-assets/56e2d6db9fe4b0449c979acd06947a5b776bcc645184b54b8d3654a48bd12c38} +0 -0
  233. /package/lib/cli/{starters/hono/src/Notebook.jsx → starter-assets/6138d1e2ca4469daf4f5545d140943f6e23b0c37f865051b266ec99695cf181a} +0 -0
  234. /package/lib/cli/{starters/hono/src/vite-env.d.ts → starter-assets/65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5} +0 -0
  235. /package/lib/cli/{starters/hono/server/application.mjs → starter-assets/757f43c27415654049ecf01b67d560c83d788108d1aebcf1f16a86d956bd7fb6} +0 -0
  236. /package/lib/cli/{starters/hono/src/components/mayura/thread-list.tsx → starter-assets/97601d0bf331df7bbde88f7ee269610bc8a1239f8eeb58fded6416e588a5b7dd} +0 -0
  237. /package/lib/cli/{starters/approval-workflow/dot-github/workflows/ci.yml → starter-assets/aa4182c76778ba2194ecbfde9a960c20181534fd1ab484df126278dbc6eb0186} +0 -0
  238. /package/lib/cli/{starters/hono/src/session.js → starter-assets/abcc6ebd29ba47a079befb6568054dec8f43d4c729187e4a3610af39789e77be} +0 -0
  239. /package/lib/cli/{starters/hono/compose.yaml → starter-assets/cc1df6f5ce0eebffc567ecea1d599eba97cd1b94ab01551085c0eb87a28e3a6c} +0 -0
  240. /package/lib/cli/{starters/hono/src/connect.js → starter-assets/cd3ddb959b277e7d495cc020a6f8146acfbcc9d05ececa3809e8aafcf84504d9} +0 -0
  241. /package/lib/cli/{starters/hono/test/session.test.mjs → starter-assets/dfe75fd07538427d80ba76767e037e929664c80ff5a41b7544496a789181bb73} +0 -0
  242. /package/lib/cli/{starters/approval-workflow/dot-gitignore → starter-assets/f3ef7285253ec9668732f535306beee602e91cb6e20f83d4799b3323399ce569} +0 -0
  243. /package/lib/cli/{starters/nuxt/src/view.js → starter-assets/ff840fe960683d377e78f731b5d4318adf6050384791fa20e4948d34192aa35d} +0 -0
@@ -1,95 +0,0 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { createHash } from 'node:crypto';
4
- import { createSqliteStore } from 'mayura/storage-sqlite';
5
- import { createClient } from 'mayura/client';
6
- import { scriptedModel } from 'mayura/testing';
7
- import { createApplication } from '../server/application.mjs';
8
-
9
- const origin = 'http://localhost:3000'; const tokenA = 'a'.repeat(64); const tokenB = 'b'.repeat(64);
10
- const scope = principal => JSON.stringify([principal, 'fixture', 'notes']);
11
- async function fixture(modelOverride) {
12
- const store = createSqliteStore({ filename: ':memory:' });
13
- const sessions = [tokenA, tokenB].map((token, index) => ({ tokenSha256: createHash('sha256').update(token).digest('hex'), principalId: index ? 'bob' : 'alice', expiresAtMs: Date.now() + 3600000 }));
14
- const app = await createApplication({ store, publicOrigin: origin, projectId: 'fixture', sessions, ...(modelOverride ? { modelOverride } : {}) });
15
- const client = token => createClient({ baseUrl: origin, token: () => token, fetch: (input, init) => { const request = new Request(input, init); const url = new URL(request.url); url.pathname = `/api/mayura${url.pathname}`; return app.fetch(new Request(url, request)); } });
16
- return { app, store, alice: client(tokenA), bob: client(tokenB), unauthenticated: client('c'.repeat(64)) };
17
- }
18
- const reply = { '~standard': { version: 1, validate: value => value && typeof value.reply === 'string' ? { value } : { issues: ['Expected reply.'] } } };
19
- async function pending(client, threadId, key = 'turn-1') {
20
- const run = await client.submit('notebook.assistant', { message: 'Remember the release notes.' }, { threadId, idempotencyKey: key });
21
- const snapshot = await run.inspect(); assert.equal(snapshot.status, 'waiting'); assert.ok(snapshot.approval); return { run, approval: snapshot.approval };
22
- }
23
-
24
- test('verified identity owns its thread; unauthenticated and cross-principal access fail', async () => {
25
- const f = await fixture(); try {
26
- await assert.rejects(f.unauthenticated.session());
27
- assert.deepEqual((await f.alice.session()).scope, { principalId: 'alice', projectId: 'fixture' });
28
- const thread = await f.alice.createThread({ id: 'thread-a', agentId: 'notebook.assistant' });
29
- await assert.rejects(f.bob.thread(thread.id)); assert.equal((await f.bob.threads()).threads.length, 0);
30
- const forged = await f.app.fetch(new Request(`${origin}/api/mayura/v1/threads`, { method: 'POST', headers: { authorization: `Bearer ${tokenA}`, 'content-type': 'application/json' }, body: JSON.stringify({ id: 'forged', scope: { principalId: 'bob', projectId: 'fixture' } }) }));
31
- assert.equal(forged.status, 400);
32
- } finally { await f.app.close(); }
33
- });
34
-
35
- test('a captured approval writes once, records the resumed run once, and queues a durable workflow', async () => {
36
- const f = await fixture(); try {
37
- const thread = await f.alice.createThread({ id: 'approved', agentId: 'notebook.assistant' }); const { run, approval } = await pending(f.alice, thread.id);
38
- const noteId = `${run.id}:${approval.callId}`; assert.equal(await f.store.read(scope('alice'), noteId), undefined);
39
- await assert.rejects(f.bob.run(run.id).approve({ callId: approval.callId, digest: approval.digest, decision: 'approved' }));
40
- await assert.rejects(run.approve({ callId: approval.callId, digest: '0'.repeat(64), decision: 'approved' }));
41
- await run.approve({ callId: approval.callId, digest: approval.digest, decision: 'approved' });
42
- assert.equal((await run.result(reply)).status, 'succeeded'); assert.ok(await f.store.read(scope('alice'), noteId));
43
- await run.approve({ callId: approval.callId, digest: approval.digest, decision: 'approved' }).catch(() => {}); // Idempotent receipt or conflict; never another write.
44
- await f.app.runOnce();
45
- const entries = await f.alice.threadEntries(thread.id); assert.deepEqual(entries.filter(entry => entry.kind === 'run' && entry.runId === run.id).map(entry => entry.status), ['running', 'succeeded']);
46
- assert.equal(entries.filter(entry => entry.kind === 'assistant').length, 1);
47
- assert.ok(await f.store.read(JSON.stringify(['alice', 'fixture', 'note-index']), noteId));
48
- } finally { await f.app.close(); }
49
- });
50
-
51
- test('rejection and cancellation leave no note write', async () => {
52
- for (const decision of ['rejected', 'cancelled']) {
53
- const f = await fixture(); try {
54
- const thread = await f.alice.createThread({ id: decision, agentId: 'notebook.assistant' }); const { run, approval } = await pending(f.alice, thread.id);
55
- if (decision === 'cancelled') await run.cancel(); else await run.approve({ callId: approval.callId, digest: approval.digest, decision });
56
- assert.equal(await f.store.read(scope('alice'), `${run.id}:${approval.callId}`), undefined);
57
- } finally { await f.app.close(); }
58
- }
59
- });
60
-
61
- test('a scripted unregistered tool is denied before it can write', async () => {
62
- const model = scriptedModel([{ type: 'tool_calls', calls: [{ id: 'wrong-tool', toolId: 'secrets.export', input: {} }], usage: { costMicros: 0 } }]);
63
- const f = await fixture(model); try {
64
- const thread = await f.alice.createThread({ id: 'hostile', agentId: 'notebook.assistant' });
65
- const run = await f.alice.submit('notebook.assistant', { message: 'hello' }, { threadId: thread.id, idempotencyKey: 'hostile-1' });
66
- assert.notEqual((await run.result(reply)).status, 'succeeded');
67
- const entries = await f.alice.threadEntries(thread.id); assert.equal(entries.filter(entry => entry.kind === 'tool_result' && entry.result?.saved === true).length, 0);
68
- } finally { await f.app.close(); }
69
- });
70
-
71
- test('aborted browser requests and same-key replays cannot produce a second run', async () => {
72
- const f = await fixture(); try {
73
- const controller = new AbortController(); controller.abort(); await assert.rejects(f.alice.threads({ signal: controller.signal }));
74
- const thread = await f.alice.createThread({ id: 'replay', agentId: 'notebook.assistant' });
75
- const one = await pending(f.alice, thread.id); const two = await f.alice.submit('notebook.assistant', { message: 'Remember the release notes.' }, { threadId: thread.id, idempotencyKey: 'turn-1' });
76
- assert.equal(two.id, one.run.id);
77
- } finally { await f.app.close(); }
78
- });
79
-
80
- test('the next thread turn receives the prior completed conversation history', async () => {
81
- const histories = []; const model = { id: 'history.fixture', maxCostMicros: 0, capabilities: { tools: true, structuredOutput: true, history: true },
82
- async generate(request) {
83
- histories.push(request.history ?? []);
84
- if (request.messages.some(message => message.role === 'tool')) return { type: 'final', output: { reply: 'Done.' }, usage: { costMicros: 0 } };
85
- return { type: 'tool_calls', calls: [{ id: crypto.randomUUID(), toolId: 'notes.save', input: { text: 'History note.' } }], usage: { costMicros: 0 } };
86
- } };
87
- const f = await fixture(model); try {
88
- const thread = await f.alice.createThread({ id: 'history', agentId: 'notebook.assistant' }); const first = await pending(f.alice, thread.id);
89
- await first.run.approve({ callId: first.approval.callId, digest: first.approval.digest, decision: 'approved' });
90
- assert.equal((await first.run.result(reply)).status, 'succeeded');
91
- const second = await pending(f.alice, thread.id, 'turn-2');
92
- assert(histories.at(-1).some(message => message.role === 'assistant' && 'output' in message));
93
- await second.run.approve({ callId: second.approval.callId, digest: second.approval.digest, decision: 'rejected' });
94
- } finally { await f.app.close(); }
95
- });
@@ -1,16 +0,0 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { createChatSession } from '../src/session.js';
4
- const threadId = 'thread-one';
5
- const thread = Object.freeze({ id: threadId, agentId: 'notebook.assistant', title: 'Notebook', metadata: Object.freeze({}), status: 'active', createdAt: '2026-10-20T00:00:00.000Z', updatedAt: '2026-10-20T00:00:00.000Z', lastSequence: 0, entryCount: 0, activeTurnId: null, version: 1 });
6
- const storage = () => { let value; return { getItem: () => value, setItem: (_key, next) => { value = next; } }; };
7
- test('render-independent session creation does no work; an ambiguous submission retains its exact key', async () => {
8
- const calls = []; const client = { updateThread: async () => thread, archiveThread: async () => thread, restoreThread: async () => thread, deleteThread: async () => ({ removed: 0 }), createThread: async () => thread, thread: async () => thread, threadEntries: async () => [], submit: async (_agentId, input, options) => { calls.push({ input, key: options.idempotencyKey }); throw new Error('Lost response.'); } };
9
- const session = createChatSession({ client, storage: storage(), storageKey: 'fixture' });
10
- try { assert.equal(calls.length, 0); await session.open(); await assert.rejects(session.send('hello')); await assert.rejects(session.retrySubmission()); assert.equal(calls.length, 2); assert.deepEqual(calls[0], calls[1]); assert.equal(session.getSnapshot().hasPending, true); }
11
- finally { session.dispose(); }
12
- });
13
- test('disposal does not resubmit or cancel a remote write', async () => {
14
- let submissions = 0; const client = { updateThread: async () => thread, archiveThread: async () => thread, restoreThread: async () => thread, deleteThread: async () => ({ removed: 0 }), createThread: async () => thread, thread: async () => thread, threadEntries: async () => [], submit: async () => { submissions++; throw new Error('Unconfirmed.'); } };
15
- const session = createChatSession({ client, storage: storage(), storageKey: 'fixture' }); await session.open(); await assert.rejects(session.send('hello')); session.dispose(); assert.equal(submissions, 1); await assert.rejects(session.retrySubmission()); assert.equal(submissions, 1);
16
- });