mayura 1.2.0 → 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.
- package/README.md +2 -0
- package/docs/README.md +17 -4
- package/docs/cli/init.md +15 -3
- package/docs/concepts/workflows.md +60 -1
- package/docs/guides/choosing-a-starter.md +80 -0
- package/docs/guides/durable-workflows.md +1 -1
- package/docs/guides/framework-starters.md +5 -1
- package/docs/guides/hono.md +94 -0
- package/docs/guides/nextjs.md +94 -0
- package/docs/guides/nuxt.md +94 -0
- package/docs/guides/rag-deployment.md +48 -0
- package/docs/guides/rag-modal-pinecone-starter.md +63 -0
- package/docs/guides/rag-production.md +48 -0
- package/docs/guides/rag-quickstart.md +119 -0
- package/docs/guides/rag.md +23 -3
- package/docs/guides/react-router.md +94 -0
- package/docs/guides/release-readiness.md +78 -55
- package/docs/guides/sveltekit.md +94 -0
- package/docs/guides/tanstack-start.md +94 -0
- package/docs/guides/workflow-composition.md +1 -1
- package/docs/integrations/reranker-cohere.md +1 -0
- package/docs/integrations/reranker-jina.md +1 -0
- package/docs/integrations/reranker-voyage.md +1 -0
- package/docs/integrations/vector-chroma.md +1 -0
- package/docs/integrations/vector-libsql.md +1 -0
- package/docs/integrations/vector-pgvector.md +1 -0
- package/docs/integrations/vector-pinecone.md +4 -1
- package/docs/integrations/vector-qdrant.md +1 -0
- package/docs/integrations/vector-weaviate.md +1 -0
- package/docs/introduction.md +5 -0
- package/docs/project/whats-new.md +70 -2
- package/docs/quickstart.md +5 -3
- package/lib/adapter-code-docker/image/Dockerfile +1 -1
- package/lib/adapter-code-docker/package.json +1 -1
- package/lib/adapter-code-quickjs/package.json +1 -1
- package/lib/adapter-mcp/package.json +1 -1
- package/lib/ag-ui/package.json +1 -1
- package/lib/artifacts/package.json +1 -1
- package/lib/auth/package.json +1 -1
- package/lib/authz/package.json +1 -1
- package/lib/browser/package.json +1 -1
- package/lib/cli/dist/index.d.ts +1 -1
- package/lib/cli/dist/index.d.ts.map +1 -1
- package/lib/cli/dist/index.js +63 -20
- package/lib/cli/dist/index.js.map +1 -1
- package/lib/cli/dist/interactive.js +2 -2
- package/lib/cli/dist/interactive.js.map +1 -1
- package/lib/cli/dist/operations.d.ts +1 -0
- package/lib/cli/dist/operations.d.ts.map +1 -1
- package/lib/cli/dist/operations.js +13 -5
- package/lib/cli/dist/operations.js.map +1 -1
- package/lib/cli/package.json +1 -1
- package/lib/cli/src/index.ts +51 -12
- package/lib/cli/src/interactive.ts +2 -2
- package/lib/cli/src/operations.ts +9 -5
- package/lib/cli/starter-assets/manifest.json +1 -0
- package/lib/cli/starters/hono/package.json +2 -2
- package/lib/cli/starters/rag-modal-pinecone/README.md +60 -0
- package/lib/cli/starters/rag-modal-pinecone/dot-env.example +23 -0
- package/lib/cli/starters/{event-automation → rag-modal-pinecone}/dot-gitignore +2 -4
- package/lib/cli/starters/rag-modal-pinecone/fixtures/on-call.md +4 -0
- package/lib/cli/starters/rag-modal-pinecone/mayura.project.json +13 -0
- package/lib/cli/starters/rag-modal-pinecone/modal-app.py +110 -0
- package/lib/cli/starters/rag-modal-pinecone/package.json +28 -0
- package/lib/cli/starters/rag-modal-pinecone/src/application.ts +148 -0
- package/lib/cli/starters/rag-modal-pinecone/src/cli.ts +78 -0
- package/lib/cli/starters/rag-modal-pinecone/src/hosted.ts +137 -0
- package/lib/cli/starters/rag-modal-pinecone/test/modal_worker_test.py +53 -0
- package/lib/cli/starters/rag-modal-pinecone/test/pipeline.test.ts +137 -0
- package/lib/cli/starters/{cli-agent → rag-modal-pinecone}/tsconfig.json +0 -1
- package/lib/client/dist/index.d.ts.map +1 -1
- package/lib/client/dist/index.js +12 -4
- package/lib/client/dist/index.js.map +1 -1
- package/lib/client/dist/workflow-limits.d.ts +6 -0
- package/lib/client/dist/workflow-limits.d.ts.map +1 -0
- package/lib/client/dist/workflow-limits.js +15 -0
- package/lib/client/dist/workflow-limits.js.map +1 -0
- package/lib/client/dist/workflows.d.ts +3 -0
- package/lib/client/dist/workflows.d.ts.map +1 -1
- package/lib/client/dist/workflows.js +15 -7
- package/lib/client/dist/workflows.js.map +1 -1
- package/lib/client/package.json +1 -1
- package/lib/client/src/index.ts +7 -4
- package/lib/client/src/workflow-limits.ts +12 -0
- package/lib/client/src/workflows.ts +12 -6
- package/lib/client-react/package.json +1 -1
- package/lib/code-mode/package.json +1 -1
- package/lib/code-mode-workflows/package.json +1 -1
- package/lib/context/package.json +1 -1
- package/lib/core/dist/host.d.ts +1 -0
- package/lib/core/dist/host.d.ts.map +1 -1
- package/lib/core/dist/host.js +1 -0
- package/lib/core/dist/host.js.map +1 -1
- package/lib/core/dist/index.d.ts +1 -0
- package/lib/core/dist/index.d.ts.map +1 -1
- package/lib/core/dist/index.js +1 -0
- package/lib/core/dist/index.js.map +1 -1
- package/lib/core/dist/workflow-environment.d.ts +9 -0
- package/lib/core/dist/workflow-environment.d.ts.map +1 -0
- package/lib/core/dist/workflow-environment.js +15 -0
- package/lib/core/dist/workflow-environment.js.map +1 -0
- package/lib/core/dist/workflow-limits.d.ts +7 -0
- package/lib/core/dist/workflow-limits.d.ts.map +1 -0
- package/lib/core/dist/workflow-limits.js +17 -0
- package/lib/core/dist/workflow-limits.js.map +1 -0
- package/lib/core/package.json +1 -1
- package/lib/core/src/host.ts +1 -0
- package/lib/core/src/index.ts +1 -0
- package/lib/core/src/workflow-environment.ts +15 -0
- package/lib/core/src/workflow-limits.ts +16 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
- package/lib/exporter-otlp/dist/signals.js +2 -2
- package/lib/exporter-otlp/dist/signals.js.map +1 -1
- package/lib/exporter-otlp/package.json +1 -1
- package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
- package/lib/exporter-otlp/src/signals.ts +2 -2
- package/lib/files/package.json +1 -1
- package/lib/guardrails/package.json +1 -1
- package/lib/helpers/package.json +1 -1
- package/lib/keys/package.json +1 -1
- package/lib/memory/package.json +1 -1
- package/lib/memory-remote/package.json +1 -1
- package/lib/observability/package.json +1 -1
- package/lib/provider-anthropic/package.json +1 -1
- package/lib/provider-openai/package.json +1 -1
- package/lib/rag/dist/bm25.d.ts +13 -0
- package/lib/rag/dist/bm25.d.ts.map +1 -0
- package/lib/rag/dist/bm25.js +76 -0
- package/lib/rag/dist/bm25.js.map +1 -0
- package/lib/rag/dist/document-lexical.d.ts +7 -0
- package/lib/rag/dist/document-lexical.d.ts.map +1 -0
- package/lib/rag/dist/document-lexical.js +33 -0
- package/lib/rag/dist/document-lexical.js.map +1 -0
- package/lib/rag/dist/evidence-window.d.ts +15 -0
- package/lib/rag/dist/evidence-window.d.ts.map +1 -0
- package/lib/rag/dist/evidence-window.js +52 -0
- package/lib/rag/dist/evidence-window.js.map +1 -0
- package/lib/rag/dist/retrieval.d.ts +6 -0
- package/lib/rag/dist/retrieval.d.ts.map +1 -1
- package/lib/rag/dist/retrieval.js +60 -6
- package/lib/rag/dist/retrieval.js.map +1 -1
- package/lib/rag/dist/vectors.d.ts +8 -0
- package/lib/rag/dist/vectors.d.ts.map +1 -1
- package/lib/rag/dist/vectors.js +121 -4
- package/lib/rag/dist/vectors.js.map +1 -1
- package/lib/rag/package.json +1 -1
- package/lib/rag/src/bm25.ts +35 -0
- package/lib/rag/src/document-lexical.ts +17 -0
- package/lib/rag/src/evidence-window.ts +41 -0
- package/lib/rag/src/retrieval.ts +56 -7
- package/lib/rag/src/vectors.ts +62 -4
- package/lib/runtime/package.json +1 -1
- package/lib/sandbox/package.json +1 -1
- package/lib/sdk/package.json +1 -1
- package/lib/server/dist/index.d.ts +2 -0
- package/lib/server/dist/index.d.ts.map +1 -1
- package/lib/server/dist/index.js +12 -4
- package/lib/server/dist/index.js.map +1 -1
- package/lib/server/dist/inspector-bundle.d.ts +1 -1
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
- package/lib/server/dist/inspector-bundle.js +4 -4
- package/lib/server/dist/inspector-bundle.js.map +1 -1
- package/lib/server/package.json +1 -1
- package/lib/server/src/index.ts +9 -4
- package/lib/server/src/inspector-bundle.ts +4 -4
- package/lib/server-node/package.json +1 -1
- package/lib/skills/package.json +1 -1
- package/lib/storage/package.json +1 -1
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts +2 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format2.d.ts +2 -0
- package/lib/storage-contracts/dist/workflow-format2.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format2.js +8 -7
- package/lib/storage-contracts/dist/workflow-format2.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format3.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format3.js +9 -7
- package/lib/storage-contracts/dist/workflow-format3.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format4.d.ts +2 -0
- package/lib/storage-contracts/dist/workflow-format4.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format4.js +9 -8
- package/lib/storage-contracts/dist/workflow-format4.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.d.ts +4 -0
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.js +9 -8
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts +2 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-graph-contracts.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts +2 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-tree-contracts.js +5 -3
- package/lib/storage-contracts/dist/workflow-tree-contracts.js.map +1 -1
- package/lib/storage-contracts/package.json +1 -1
- package/lib/storage-contracts/src/scheduled-workflow-contracts.ts +2 -0
- package/lib/storage-contracts/src/workflow-format2.ts +10 -7
- package/lib/storage-contracts/src/workflow-format3.ts +9 -7
- package/lib/storage-contracts/src/workflow-format4.ts +11 -8
- package/lib/storage-contracts/src/workflow-format5.ts +13 -8
- package/lib/storage-contracts/src/workflow-graph-contracts.ts +2 -0
- package/lib/storage-contracts/src/workflow-tree-contracts.ts +7 -3
- package/lib/storage-postgres/package.json +1 -1
- package/lib/storage-sql/dist/scheduled-database.js +1 -1
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-database.js +37 -1
- package/lib/storage-sql/dist/workflow-tree-database.js.map +1 -1
- package/lib/storage-sql/package.json +1 -1
- package/lib/storage-sql/src/scheduled-database.ts +1 -1
- package/lib/storage-sql/src/workflow-tree-database.ts +15 -1
- package/lib/storage-sqlite/package.json +1 -1
- package/lib/terminal/package.json +1 -1
- package/lib/testing/package.json +1 -1
- package/lib/threads/package.json +1 -1
- package/lib/tools/package.json +1 -1
- package/lib/voice/package.json +1 -1
- package/lib/workflows/dist/children-definition.d.ts +5 -1
- package/lib/workflows/dist/children-definition.d.ts.map +1 -1
- package/lib/workflows/dist/children-definition.js +6 -2
- package/lib/workflows/dist/children-definition.js.map +1 -1
- package/lib/workflows/dist/children-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/children-runtime.js +4 -3
- package/lib/workflows/dist/children-runtime.js.map +1 -1
- package/lib/workflows/dist/definition.d.ts +4 -0
- package/lib/workflows/dist/definition.d.ts.map +1 -1
- package/lib/workflows/dist/definition.js +6 -3
- package/lib/workflows/dist/definition.js.map +1 -1
- package/lib/workflows/dist/graph-definition.d.ts +5 -1
- package/lib/workflows/dist/graph-definition.d.ts.map +1 -1
- package/lib/workflows/dist/graph-definition.js +8 -4
- package/lib/workflows/dist/graph-definition.js.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.d.ts +5 -1
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.js +5 -2
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.js +4 -5
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
- package/lib/workflows/dist/node-batches.d.ts +9 -0
- package/lib/workflows/dist/node-batches.d.ts.map +1 -0
- package/lib/workflows/dist/node-batches.js +19 -0
- package/lib/workflows/dist/node-batches.js.map +1 -0
- package/lib/workflows/dist/operator-transports.d.ts +1 -0
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
- package/lib/workflows/dist/operator-transports.js +1 -0
- package/lib/workflows/dist/operator-transports.js.map +1 -1
- package/lib/workflows/dist/runtime.d.ts.map +1 -1
- package/lib/workflows/dist/runtime.js +6 -7
- package/lib/workflows/dist/runtime.js.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.js +3 -2
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
- package/lib/workflows/dist/scheduled.d.ts.map +1 -1
- package/lib/workflows/dist/scheduled.js +2 -1
- package/lib/workflows/dist/scheduled.js.map +1 -1
- package/lib/workflows/package.json +1 -1
- package/lib/workflows/src/children-definition.ts +10 -3
- package/lib/workflows/src/children-runtime.ts +3 -2
- package/lib/workflows/src/definition.ts +9 -2
- package/lib/workflows/src/graph-definition.ts +10 -3
- package/lib/workflows/src/lifecycle-definition.ts +10 -3
- package/lib/workflows/src/lifecycle-runtime.ts +4 -4
- package/lib/workflows/src/node-batches.ts +21 -0
- package/lib/workflows/src/operator-transports.ts +3 -1
- package/lib/workflows/src/runtime.ts +6 -6
- package/lib/workflows/src/scheduled-helpers.ts +3 -2
- package/lib/workflows/src/scheduled.ts +2 -1
- package/lib/workstream/package.json +1 -1
- package/llms-full.txt +1442 -281
- package/llms.txt +17 -3
- package/package.json +4 -4
- package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +0 -13
- package/lib/cli/starters/cli-agent/dot-gitignore +0 -10
- package/lib/cli/starters/event-automation/dot-dockerignore +0 -7
- package/lib/cli/starters/event-automation/dot-github/workflows/ci.yml +0 -13
- package/lib/cli/starters/event-automation/src/model.ts +0 -40
- package/lib/cli/starters/event-automation/tsconfig.json +0 -20
- package/lib/cli/starters/nextjs/Dockerfile +0 -12
- package/lib/cli/starters/nextjs/compose.yaml +0 -19
- package/lib/cli/starters/nextjs/dot-dockerignore +0 -11
- package/lib/cli/starters/nextjs/dot-env.example +0 -7
- package/lib/cli/starters/nextjs/scripts/setup.mjs +0 -9
- package/lib/cli/starters/nextjs/server/application.mjs +0 -74
- package/lib/cli/starters/nextjs/server/auth.mjs +0 -24
- package/lib/cli/starters/nextjs/server/worker.mjs +0 -11
- package/lib/cli/starters/nextjs/server/workflows.mjs +0 -23
- package/lib/cli/starters/nextjs/src/ChatApp.jsx +0 -57
- package/lib/cli/starters/nextjs/src/Notebook.jsx +0 -25
- package/lib/cli/starters/nextjs/src/components/mayura/approval.tsx +0 -142
- package/lib/cli/starters/nextjs/src/components/mayura/thread-history.tsx +0 -142
- package/lib/cli/starters/nextjs/src/components/mayura/thread-list.tsx +0 -9
- package/lib/cli/starters/nextjs/src/components/mayura/ui.css +0 -14
- package/lib/cli/starters/nextjs/src/connect.js +0 -21
- package/lib/cli/starters/nextjs/src/session.js +0 -138
- package/lib/cli/starters/nextjs/src/style.css +0 -11
- package/lib/cli/starters/nextjs/test/server.test.mjs +0 -95
- package/lib/cli/starters/nextjs/test/session.test.mjs +0 -16
- package/lib/cli/starters/nuxt/compose.yaml +0 -19
- package/lib/cli/starters/nuxt/dot-dockerignore +0 -11
- package/lib/cli/starters/nuxt/dot-env.example +0 -7
- package/lib/cli/starters/nuxt/dot-gitignore +0 -14
- package/lib/cli/starters/nuxt/scripts/setup.mjs +0 -9
- package/lib/cli/starters/nuxt/server/application.mjs +0 -74
- package/lib/cli/starters/nuxt/server/auth.mjs +0 -24
- package/lib/cli/starters/nuxt/server/worker.mjs +0 -11
- package/lib/cli/starters/nuxt/server/workflows.mjs +0 -23
- package/lib/cli/starters/nuxt/src/connect.js +0 -21
- package/lib/cli/starters/nuxt/src/session.js +0 -138
- package/lib/cli/starters/nuxt/src/style.css +0 -11
- package/lib/cli/starters/nuxt/test/server.test.mjs +0 -95
- package/lib/cli/starters/nuxt/test/session.test.mjs +0 -16
- package/lib/cli/starters/react-router/Dockerfile +0 -12
- package/lib/cli/starters/react-router/compose.yaml +0 -19
- package/lib/cli/starters/react-router/dot-dockerignore +0 -11
- package/lib/cli/starters/react-router/dot-env.example +0 -7
- package/lib/cli/starters/react-router/dot-gitignore +0 -14
- package/lib/cli/starters/react-router/scripts/setup.mjs +0 -9
- package/lib/cli/starters/react-router/server/application.mjs +0 -74
- package/lib/cli/starters/react-router/server/auth.mjs +0 -24
- package/lib/cli/starters/react-router/server/worker.mjs +0 -11
- package/lib/cli/starters/react-router/server/workflows.mjs +0 -23
- package/lib/cli/starters/react-router/src/ChatApp.jsx +0 -57
- package/lib/cli/starters/react-router/src/Notebook.jsx +0 -25
- package/lib/cli/starters/react-router/src/components/mayura/approval.tsx +0 -142
- package/lib/cli/starters/react-router/src/components/mayura/thread-history.tsx +0 -142
- package/lib/cli/starters/react-router/src/components/mayura/thread-list.tsx +0 -9
- package/lib/cli/starters/react-router/src/components/mayura/ui.css +0 -14
- package/lib/cli/starters/react-router/src/connect.js +0 -21
- package/lib/cli/starters/react-router/src/session.js +0 -138
- package/lib/cli/starters/react-router/src/style.css +0 -11
- package/lib/cli/starters/react-router/src/vite-env.d.ts +0 -1
- package/lib/cli/starters/react-router/test/server.test.mjs +0 -95
- package/lib/cli/starters/react-router/test/session.test.mjs +0 -16
- package/lib/cli/starters/research-team/dot-dockerignore +0 -7
- package/lib/cli/starters/research-team/dot-github/workflows/ci.yml +0 -13
- package/lib/cli/starters/research-team/dot-gitignore +0 -10
- package/lib/cli/starters/research-team/src/model.ts +0 -40
- package/lib/cli/starters/research-team/tsconfig.json +0 -20
- package/lib/cli/starters/support-agent/dot-dockerignore +0 -7
- package/lib/cli/starters/support-agent/dot-github/workflows/ci.yml +0 -13
- package/lib/cli/starters/support-agent/dot-gitignore +0 -10
- package/lib/cli/starters/support-agent/src/model.ts +0 -40
- package/lib/cli/starters/support-agent/tsconfig.json +0 -20
- package/lib/cli/starters/sveltekit/Dockerfile +0 -12
- package/lib/cli/starters/sveltekit/compose.yaml +0 -19
- package/lib/cli/starters/sveltekit/dot-dockerignore +0 -11
- package/lib/cli/starters/sveltekit/dot-env.example +0 -7
- package/lib/cli/starters/sveltekit/dot-gitignore +0 -14
- package/lib/cli/starters/sveltekit/scripts/setup.mjs +0 -9
- package/lib/cli/starters/sveltekit/server/application.mjs +0 -74
- package/lib/cli/starters/sveltekit/server/auth.mjs +0 -24
- package/lib/cli/starters/sveltekit/server/worker.mjs +0 -11
- package/lib/cli/starters/sveltekit/server/workflows.mjs +0 -23
- package/lib/cli/starters/sveltekit/src/connect.js +0 -21
- package/lib/cli/starters/sveltekit/src/session.js +0 -138
- package/lib/cli/starters/sveltekit/src/style.css +0 -11
- package/lib/cli/starters/sveltekit/src/view.js +0 -49
- package/lib/cli/starters/sveltekit/test/server.test.mjs +0 -95
- package/lib/cli/starters/sveltekit/test/session.test.mjs +0 -16
- package/lib/cli/starters/tanstack-start/Dockerfile +0 -12
- package/lib/cli/starters/tanstack-start/compose.yaml +0 -19
- package/lib/cli/starters/tanstack-start/dot-dockerignore +0 -11
- package/lib/cli/starters/tanstack-start/dot-env.example +0 -7
- package/lib/cli/starters/tanstack-start/dot-gitignore +0 -14
- package/lib/cli/starters/tanstack-start/scripts/setup.mjs +0 -9
- package/lib/cli/starters/tanstack-start/server/application.mjs +0 -74
- package/lib/cli/starters/tanstack-start/server/auth.mjs +0 -24
- package/lib/cli/starters/tanstack-start/server/worker.mjs +0 -11
- package/lib/cli/starters/tanstack-start/server/workflows.mjs +0 -23
- package/lib/cli/starters/tanstack-start/src/ChatApp.jsx +0 -57
- package/lib/cli/starters/tanstack-start/src/Notebook.jsx +0 -25
- package/lib/cli/starters/tanstack-start/src/components/mayura/approval.tsx +0 -142
- package/lib/cli/starters/tanstack-start/src/components/mayura/thread-history.tsx +0 -142
- package/lib/cli/starters/tanstack-start/src/components/mayura/thread-list.tsx +0 -9
- package/lib/cli/starters/tanstack-start/src/components/mayura/ui.css +0 -14
- package/lib/cli/starters/tanstack-start/src/connect.js +0 -21
- package/lib/cli/starters/tanstack-start/src/session.js +0 -138
- package/lib/cli/starters/tanstack-start/src/style.css +0 -11
- package/lib/cli/starters/tanstack-start/test/server.test.mjs +0 -95
- package/lib/cli/starters/tanstack-start/test/session.test.mjs +0 -16
- /package/lib/cli/{starters/hono/src/components/mayura/ui.css → starter-assets/011cacc77ada0de5b447674e9fc4374a247b9a46eb169722b12649753f24188f} +0 -0
- /package/lib/cli/{starters/hono/test/server.test.mjs → starter-assets/0c825d6a776673ec6274cfc29cd45b1a8c56dcb880c291a91075c77e1ef1e4f3} +0 -0
- /package/lib/cli/{starters/hono/server/auth.mjs → starter-assets/0dd570bfacc357d23be3340250090b9a4c6193a49cdd02e9b6789e7bee8433dd} +0 -0
- /package/lib/cli/{starters/hono/src/components/mayura/approval.tsx → starter-assets/11292bd14cdaf27a8f8317ba4ab768d706a726b2e26474b599f3db116674b4b3} +0 -0
- /package/lib/cli/{starters/nextjs/dot-gitignore → starter-assets/1873b02e070347f9a449e07084242982fa6af412c45aa764985d553975b64589} +0 -0
- /package/lib/cli/{starters/hono/src/style.css → starter-assets/2f3869e6d69134e43be713c4590bfe48896a5c54ece6ffc1a4f204cfcfe54218} +0 -0
- /package/lib/cli/{starters/hono/server/worker.mjs → starter-assets/350d77757f548369beff29d658cf1620752d4e23b4b732d99a1b403ca043137f} +0 -0
- /package/lib/cli/{starters/approval-workflow/src/model.ts → starter-assets/37294d24c04b71eaf6d6f0bd52fd4c1cc7a5d3cb63da9c7920ed1d44276da9cb} +0 -0
- /package/lib/cli/{starters/approval-workflow/tsconfig.json → starter-assets/4387d6537dd5924ae62326aa3d7d8cbad1e5abd930aecc9daa6fab1ac2f6ef24} +0 -0
- /package/lib/cli/{starters/hono/dot-dockerignore → starter-assets/4434be031b58cc6ee680b2860b2ad1fe4089af7ee866c13223dfb621dd042ff1} +0 -0
- /package/lib/cli/{starters/hono/src/ChatApp.jsx → starter-assets/46e199317648a076243d6c8e7ffedc48785a6ffc0f203b88c7c4a9479b34c5b9} +0 -0
- /package/lib/cli/{starters/hono/src/components/mayura/thread-history.tsx → starter-assets/4741fccbca2e0d2fc6f61d11af3cf7bcc5f0238b67bb46282287207abdc6c536} +0 -0
- /package/lib/cli/{starters/approval-workflow/dot-dockerignore → starter-assets/4be664708b0120da5d2b73c5a27968093da06b8728f88f2bda2a1ccbf40f6891} +0 -0
- /package/lib/cli/{starters/hono/server/workflows.mjs → starter-assets/4d11f729672df54969a851494877a3c5aee24bb8f8c68eacaaa22e715bf5ed69} +0 -0
- /package/lib/cli/{starters/hono/dot-env.example → starter-assets/4f141323062660c4dc5b563300d57bb4cdbdc7fe9bfba96e43d9c64bb274474e} +0 -0
- /package/lib/cli/{starters/hono/Dockerfile → starter-assets/5471b74c46258d1edb00eb8f60f4219c389a252f7e224f2692f8f3e71ae43e3e} +0 -0
- /package/lib/cli/{starters/hono/scripts/setup.mjs → starter-assets/56e2d6db9fe4b0449c979acd06947a5b776bcc645184b54b8d3654a48bd12c38} +0 -0
- /package/lib/cli/{starters/hono/src/Notebook.jsx → starter-assets/6138d1e2ca4469daf4f5545d140943f6e23b0c37f865051b266ec99695cf181a} +0 -0
- /package/lib/cli/{starters/hono/src/vite-env.d.ts → starter-assets/65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5} +0 -0
- /package/lib/cli/{starters/hono/server/application.mjs → starter-assets/757f43c27415654049ecf01b67d560c83d788108d1aebcf1f16a86d956bd7fb6} +0 -0
- /package/lib/cli/{starters/hono/src/components/mayura/thread-list.tsx → starter-assets/97601d0bf331df7bbde88f7ee269610bc8a1239f8eeb58fded6416e588a5b7dd} +0 -0
- /package/lib/cli/{starters/approval-workflow/dot-github/workflows/ci.yml → starter-assets/aa4182c76778ba2194ecbfde9a960c20181534fd1ab484df126278dbc6eb0186} +0 -0
- /package/lib/cli/{starters/hono/src/session.js → starter-assets/abcc6ebd29ba47a079befb6568054dec8f43d4c729187e4a3610af39789e77be} +0 -0
- /package/lib/cli/{starters/hono/compose.yaml → starter-assets/cc1df6f5ce0eebffc567ecea1d599eba97cd1b94ab01551085c0eb87a28e3a6c} +0 -0
- /package/lib/cli/{starters/hono/src/connect.js → starter-assets/cd3ddb959b277e7d495cc020a6f8146acfbcc9d05ececa3809e8aafcf84504d9} +0 -0
- /package/lib/cli/{starters/hono/test/session.test.mjs → starter-assets/dfe75fd07538427d80ba76767e037e929664c80ff5a41b7544496a789181bb73} +0 -0
- /package/lib/cli/{starters/approval-workflow/dot-gitignore → starter-assets/f3ef7285253ec9668732f535306beee602e91cb6e20f83d4799b3323399ce569} +0 -0
- /package/lib/cli/{starters/nuxt/src/view.js → starter-assets/ff840fe960683d377e78f731b5d4318adf6050384791fa20e4948d34192aa35d} +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { sha256Hex } from 'mayura/core/host';
|
|
2
|
-
|
|
3
|
-
export const agentId = 'notebook.assistant';
|
|
4
|
-
export const capabilities = Object.freeze(['runs:read', 'runs:submit', 'runs:cancel', 'runs:approve', 'threads:read', 'threads:write']);
|
|
5
|
-
/** Snapshot a bounded host-owned identity directory. Browser claims never set scope or capabilities. */
|
|
6
|
-
export function identityDirectory(projectId, sessions) {
|
|
7
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(projectId) || !Array.isArray(sessions) || !sessions.length || sessions.length > 32) throw new Error('Invalid identity configuration.');
|
|
8
|
-
const seen = new Set();
|
|
9
|
-
const entries = sessions.map(item => {
|
|
10
|
-
if (!item || Object.keys(item).some(key => !['tokenSha256', 'principalId', 'expiresAtMs'].includes(key))
|
|
11
|
-
|| !/^[a-f0-9]{64}$/u.test(item.tokenSha256) || seen.has(item.tokenSha256)
|
|
12
|
-
|| typeof item.principalId !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(item.principalId)
|
|
13
|
-
|| !Number.isSafeInteger(item.expiresAtMs) || item.expiresAtMs < 1) throw new Error('Invalid identity configuration.');
|
|
14
|
-
seen.add(item.tokenSha256);
|
|
15
|
-
return Object.freeze({ ...item, scope: Object.freeze({ principalId: item.principalId, projectId }) });
|
|
16
|
-
});
|
|
17
|
-
const scopes = [...new Map(entries.map(item => [item.principalId, item.scope])).values()];
|
|
18
|
-
return Object.freeze({ scopes: Object.freeze(scopes), authenticate: async ({ token, signal }) => {
|
|
19
|
-
if (signal.aborted || typeof token !== 'string' || !/^[a-f0-9]{64}$/u.test(token)) return null;
|
|
20
|
-
const digest = await sha256Hex(token); if (signal.aborted) return null;
|
|
21
|
-
const entry = entries.find(item => item.tokenSha256 === digest);
|
|
22
|
-
return entry && entry.expiresAtMs > Date.now() ? { scope: entry.scope, agentIds: [agentId], capabilities, expiresAtMs: entry.expiresAtMs } : null;
|
|
23
|
-
} });
|
|
24
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { application } from './node.mjs';
|
|
2
|
-
// A separate bounded worker process; runOnce is also available to a trusted scheduler. No public cron endpoint.
|
|
3
|
-
const app = await application(); let stopping = false; let timer; let active;
|
|
4
|
-
async function cycle() {
|
|
5
|
-
try { await app.runOnce(); } catch { console.error('Notebook background work needs attention.'); }
|
|
6
|
-
finally { if (!stopping) timer = setTimeout(() => { active = cycle(); }, 1000); }
|
|
7
|
-
}
|
|
8
|
-
async function stop() { if (stopping) return; stopping = true; clearTimeout(timer); await active; await app.close(); }
|
|
9
|
-
process.once('SIGINT', () => void stop()); process.once('SIGTERM', () => void stop());
|
|
10
|
-
console.log(JSON.stringify({ event: 'worker-started' }));
|
|
11
|
-
active = cycle();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineTool, z } from 'mayura';
|
|
2
|
-
import { createWorkflowLeadership, createWorkflowWorker } from 'mayura/workflows';
|
|
3
|
-
import { defineWorkflowLifecycle, createWorkflowLifecycleHost } from 'mayura/workflows/lifecycle';
|
|
4
|
-
|
|
5
|
-
/** Durable no-network indexing fixture; replace its effect with an idempotent integration before production use. */
|
|
6
|
-
export function workflowServices(store, scope) {
|
|
7
|
-
const input = z.object({ noteId: z.string().min(1).max(256) }).strict();
|
|
8
|
-
const index = defineTool({ id: 'notes.index', version: '1', description: 'Index an approved local note.', input,
|
|
9
|
-
output: z.object({ indexed: z.literal(true) }).strict(), effects: 'write', capabilities: ['notes:index'], costMicros: 0,
|
|
10
|
-
execute: async ({ noteId }, context) => {
|
|
11
|
-
context.signal.throwIfAborted();
|
|
12
|
-
if (context.scope.principalId !== scope.principalId || context.scope.projectId !== scope.projectId) throw new Error('Scope refused.');
|
|
13
|
-
await store.create({ scope: JSON.stringify([scope.principalId, scope.projectId, 'note-index']), id: noteId, idempotencyKey: noteId,
|
|
14
|
-
definitionHash: 'notebook-index-v1', state: { indexed: true }, events: [{ type: 'note.indexed', data: { noteId } }] });
|
|
15
|
-
return { indexed: true };
|
|
16
|
-
} });
|
|
17
|
-
const definition = defineWorkflowLifecycle({ id: 'notes.follow-up', version: '1', input, output: z.object({ indexed: z.literal(true) }).strict(),
|
|
18
|
-
nodes: [{ kind: 'tool', id: 'index', tool: index, input: { kind: 'input', path: [] } }], result: { kind: 'step', stepId: 'index', path: [] } });
|
|
19
|
-
const host = createWorkflowLifecycleHost({ store, scope, definitions: [definition], policyVersion: '1', maxCostMicros: 0,
|
|
20
|
-
permissions: { allow: ['tool:notes.index', 'notes:index', 'effect:write'] }, intervalMs: 1000, maxPagesPerCycle: 1, pageLimit: 10 });
|
|
21
|
-
const worker = createWorkflowWorker({ units: [host], leadership: createWorkflowLeadership({ store, scope, role: 'notebook-worker', holderId: crypto.randomUUID() }) });
|
|
22
|
-
return Object.freeze({ definition, host, worker });
|
|
23
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ClientError, createClient } from 'mayura/client';
|
|
2
|
-
import { createChatSession } from './session.js';
|
|
3
|
-
|
|
4
|
-
/** Called only after an explicit login. The credential lives in this session closure, never browser storage. */
|
|
5
|
-
export async function connectNotebook(token, origin = location.origin) {
|
|
6
|
-
if (typeof token !== 'string' || !/^[a-f0-9]{64}$/u.test(token)) throw new ClientError('INVALID_CREDENTIAL');
|
|
7
|
-
const transport = globalThis.fetch.bind(globalThis);
|
|
8
|
-
const client = createClient({ baseUrl: origin, token: () => token, requestTimeoutMs: 45000,
|
|
9
|
-
fetch: (input, init) => {
|
|
10
|
-
const request = new Request(input, init); const url = new URL(request.url);
|
|
11
|
-
if (url.origin !== origin || !url.pathname.startsWith('/v1/')) throw new ClientError('INVALID_DESTINATION');
|
|
12
|
-
url.pathname = `/api/mayura${url.pathname}`;
|
|
13
|
-
return transport(new Request(url, request));
|
|
14
|
-
} });
|
|
15
|
-
// Verify the credential before creating any thread or restoring a selection.
|
|
16
|
-
await client.session();
|
|
17
|
-
const digest = [...new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(token)))].map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
18
|
-
let storage; try { storage = sessionStorage; } catch { /* Optional reload recovery. */ }
|
|
19
|
-
const session = createChatSession({ client, storage, storageKey: `mayura.notebook.${digest}` });
|
|
20
|
-
return { session, client };
|
|
21
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { ClientError } from 'mayura/client';
|
|
2
|
-
import { createHeadlessRunStore, createHeadlessThreadStore, createRunApprovalController } from 'mayura/client/headless';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const id = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
6
|
-
const reply = { '~standard': { version: 1, validate: value => value && typeof value.reply === 'string' ? { value } : { issues: [{ message: 'Expected a reply.' }] } } };
|
|
7
|
-
const terminal = status => ['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown'].includes(status);
|
|
8
|
-
|
|
9
|
-
/** App-owned wiring: only ids and the bounded in-flight message/retry key are saved locally, never credentials. */
|
|
10
|
-
export function createChatSession({ client, storage, storageKey }) {
|
|
11
|
-
const key = storageKey;
|
|
12
|
-
let selected = {};
|
|
13
|
-
try {
|
|
14
|
-
const raw = storage?.getItem(key);
|
|
15
|
-
if (raw && raw.length <= 16_384) {
|
|
16
|
-
const value = JSON.parse(raw);
|
|
17
|
-
if (value && typeof value.threadId === 'string' && id.test(value.threadId)
|
|
18
|
-
&& (value.creating === undefined || typeof value.creating === 'boolean')
|
|
19
|
-
&& (value.runId === undefined || /^[a-f0-9-]{36}$/.test(value.runId))
|
|
20
|
-
&& (value.message === undefined || (typeof value.message === 'string' && value.message.length <= 2_000))
|
|
21
|
-
&& (value.pending === undefined || (typeof value.pending.message === 'string' && value.pending.message.length <= 2_000 && /^[a-f0-9-]{36}$/.test(value.pending.key)))) selected = value;
|
|
22
|
-
}
|
|
23
|
-
} catch { /* Storage can be disabled; this tab still works without reload recovery. */ }
|
|
24
|
-
let disposed = false; let working = false; let generation = 0; let detachRun = () => {};
|
|
25
|
-
let state = Object.freeze({ phase: 'idle', busy: false, threadStore: null, runStore: null, approval: null, message: selected.message ?? null,
|
|
26
|
-
threadId: selected.threadId ?? null, runId: selected.runId ?? null, hasPending: Boolean(selected.pending), errorCode: null });
|
|
27
|
-
const listeners = new Set(); const lifetime = new AbortController();
|
|
28
|
-
const publish = change => {
|
|
29
|
-
if (disposed) return;
|
|
30
|
-
state = Object.freeze({ ...state, ...change });
|
|
31
|
-
for (const listener of [...listeners]) { try { listener(); } catch { /* UI listeners cannot break transport work. */ } }
|
|
32
|
-
};
|
|
33
|
-
const save = () => { try { storage?.setItem(key, JSON.stringify(selected)); } catch { /* In-memory fallback. */ } };
|
|
34
|
-
const failure = error => { if (!disposed) publish({ phase: 'error', errorCode: error instanceof ClientError ? error.code : 'CHAT_FAILED' }); };
|
|
35
|
-
const perform = async work => {
|
|
36
|
-
if (disposed) throw new ClientError('VIEW_DISPOSED'); if (working) throw new ClientError('VIEW_BUSY'); working = true; publish({ busy: true });
|
|
37
|
-
try { return await work(); } catch (error) { failure(error); throw error; } finally { working = false; publish({ busy: false }); }
|
|
38
|
-
};
|
|
39
|
-
const latestHistory = async () => {
|
|
40
|
-
const thread = await client.thread(selected.threadId, { signal: lifetime.signal });
|
|
41
|
-
return state.threadStore.refresh({ before: thread.lastSequence + 1, signal: lifetime.signal });
|
|
42
|
-
};
|
|
43
|
-
const dropRun = () => {
|
|
44
|
-
generation++; detachRun(); detachRun = () => {}; state.runStore?.dispose(); state.approval?.dispose();
|
|
45
|
-
publish({ runStore: null, approval: null });
|
|
46
|
-
};
|
|
47
|
-
const attach = run => {
|
|
48
|
-
dropRun(); const current = generation; const runStore = createHeadlessRunStore({ run });
|
|
49
|
-
let captured = null;
|
|
50
|
-
detachRun = runStore.subscribe(() => {
|
|
51
|
-
const snapshot = runStore.getSnapshot().snapshot;
|
|
52
|
-
if (disposed || current !== generation || !snapshot?.approval || snapshot.status !== 'waiting') return;
|
|
53
|
-
const capture = `${snapshot.approval.callId}:${snapshot.approval.digest}`;
|
|
54
|
-
if (capture !== captured) {
|
|
55
|
-
captured = capture; state.approval?.dispose(); publish({ approval: createRunApprovalController({ run, approval: snapshot.approval }) });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
publish({ runStore, runId: run.id, phase: 'active', errorCode: null });
|
|
59
|
-
// Reading first recovers an already waiting/completed run. Observation then follows pauses/resumes without making decisions.
|
|
60
|
-
void (async () => {
|
|
61
|
-
try {
|
|
62
|
-
await runStore.refresh({ signal: lifetime.signal });
|
|
63
|
-
if (!terminal(runStore.getSnapshot().snapshot?.status)) await runStore.observe({ signal: lifetime.signal });
|
|
64
|
-
if (disposed || current !== generation) return;
|
|
65
|
-
const outcome = await run.result(reply, { signal: lifetime.signal });
|
|
66
|
-
if (!outcome) throw new ClientError('RUN_STILL_ACTIVE');
|
|
67
|
-
await latestHistory(); if (disposed || current !== generation) return;
|
|
68
|
-
selected = { threadId: selected.threadId }; save();
|
|
69
|
-
publish({ phase: 'ready', runId: null, message: null, hasPending: false, errorCode: null });
|
|
70
|
-
} catch (error) { if (!disposed && current === generation) failure(error); }
|
|
71
|
-
})();
|
|
72
|
-
};
|
|
73
|
-
const submitPending = async () => {
|
|
74
|
-
const pending = selected.pending; if (!pending) throw new ClientError('INVALID_REQUEST');
|
|
75
|
-
publish({ phase: 'submitting', hasPending: true, message: pending.message, errorCode: null });
|
|
76
|
-
const run = await state.threadStore.submit('notebook.assistant', { message: pending.message }, { idempotencyKey: pending.key, signal: lifetime.signal });
|
|
77
|
-
if (disposed) return;
|
|
78
|
-
selected = { threadId: selected.threadId, runId: run.id, message: pending.message }; save(); publish({ hasPending: false }); attach(run);
|
|
79
|
-
};
|
|
80
|
-
const openWork = async () => {
|
|
81
|
-
publish({ phase: 'opening', errorCode: null });
|
|
82
|
-
if (!selected.threadId || selected.creating) {
|
|
83
|
-
selected = { threadId: selected.threadId ?? crypto.randomUUID(), creating: true }; save();
|
|
84
|
-
const thread = await client.createThread({ id: selected.threadId, agentId: 'notebook.assistant', title: 'My notes' }, { signal: lifetime.signal });
|
|
85
|
-
selected = { threadId: thread.id }; save();
|
|
86
|
-
}
|
|
87
|
-
if (disposed) return;
|
|
88
|
-
state.threadStore?.dispose(); const threadStore = createHeadlessThreadStore({ client, threadId: selected.threadId, maxEntries: 40 });
|
|
89
|
-
publish({ threadStore, threadId: selected.threadId }); await latestHistory();
|
|
90
|
-
if (selected.runId) attach(client.run(selected.runId));
|
|
91
|
-
else publish({ phase: 'ready', hasPending: Boolean(selected.pending), message: selected.pending?.message ?? null });
|
|
92
|
-
};
|
|
93
|
-
const open = () => perform(openWork);
|
|
94
|
-
return Object.freeze({
|
|
95
|
-
getSnapshot: () => state,
|
|
96
|
-
subscribe: listener => { listeners.add(listener); return () => listeners.delete(listener); },
|
|
97
|
-
open,
|
|
98
|
-
send: message => perform(async () => {
|
|
99
|
-
if (state.phase !== 'ready' || selected.runId || selected.pending) throw new ClientError('VIEW_BUSY');
|
|
100
|
-
if (typeof message !== 'string' || !message.trim() || message.trim().length > 2_000) throw new ClientError('INVALID_REQUEST');
|
|
101
|
-
// Save before the POST. An ambiguous response can be retried explicitly with the exact same key and message.
|
|
102
|
-
selected = { threadId: selected.threadId, pending: { key: crypto.randomUUID(), message: message.trim() } }; save(); await submitPending();
|
|
103
|
-
}),
|
|
104
|
-
retrySubmission: () => perform(submitPending),
|
|
105
|
-
selectThread: threadId => perform(async () => {
|
|
106
|
-
if (!id.test(threadId) || selected.runId || selected.pending || state.busy && state.phase !== 'ready') throw new ClientError('VIEW_BUSY');
|
|
107
|
-
dropRun(); state.threadStore?.dispose(); selected = { threadId }; save();
|
|
108
|
-
const threadStore = createHeadlessThreadStore({ client, threadId, maxEntries: 40 });
|
|
109
|
-
publish({ threadStore, threadId, runId: null, message: null, phase: 'opening', errorCode: null }); await latestHistory(); publish({ phase: 'ready' });
|
|
110
|
-
}),
|
|
111
|
-
reconnect: () => perform(async () => {
|
|
112
|
-
if (selected.creating) { await openWork(); return; }
|
|
113
|
-
if (!selected.runId) { await latestHistory(); publish({ phase: 'ready', errorCode: null }); return; }
|
|
114
|
-
attach(client.run(selected.runId));
|
|
115
|
-
}),
|
|
116
|
-
cancel: () => perform(async () => { if (!selected.runId) throw new ClientError('INVALID_REQUEST'); await client.run(selected.runId).cancel({ signal: lifetime.signal }); }),
|
|
117
|
-
refreshHistory: page => perform(async () => { await state.threadStore.refresh({ ...page, signal: lifetime.signal }); }),
|
|
118
|
-
forgetMissing: () => {
|
|
119
|
-
if (disposed) return Promise.reject(new ClientError('VIEW_DISPOSED'));
|
|
120
|
-
if (working || !['THREAD_NOT_FOUND', 'RUN_NOT_FOUND'].includes(state.errorCode)) return Promise.reject(new ClientError('VIEW_BUSY'));
|
|
121
|
-
// This drops only browser selection after a confirmed not-found response, not server history or running work.
|
|
122
|
-
dropRun(); state.threadStore?.dispose(); selected = {}; save(); publish({ phase: 'opening', threadStore: null, threadId: null, runId: null, message: null, hasPending: false });
|
|
123
|
-
return open();
|
|
124
|
-
},
|
|
125
|
-
newThread: () => perform(async () => {
|
|
126
|
-
if (selected.runId || selected.pending) throw new ClientError('VIEW_BUSY');
|
|
127
|
-
publish({ phase: 'opening' }); selected = { threadId: crypto.randomUUID(), creating: true }; save();
|
|
128
|
-
const thread = await client.createThread({ id: selected.threadId, agentId: 'notebook.assistant', title: 'My notes' }, { signal: lifetime.signal });
|
|
129
|
-
if (disposed) return; dropRun(); state.threadStore?.dispose(); selected = { threadId: thread.id }; save();
|
|
130
|
-
const threadStore = createHeadlessThreadStore({ client, threadId: thread.id, maxEntries: 40 });
|
|
131
|
-
publish({ threadStore, threadId: thread.id, runId: null, message: null, phase: 'ready', errorCode: null }); await latestHistory();
|
|
132
|
-
}),
|
|
133
|
-
dispose: () => {
|
|
134
|
-
if (disposed) return; disposed = true; generation++; lifetime.abort(); detachRun();
|
|
135
|
-
state.runStore?.dispose(); state.approval?.dispose(); state.threadStore?.dispose(); listeners.clear();
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* A quiet notebook: warm paper, forest ink and a narrow reading column. No external font or asset requests. */
|
|
2
|
-
:root { color-scheme: light; color: #183e32; background: #f5f2e9; font-family: 'Trebuchet MS', sans-serif; line-height: 1.6; }
|
|
3
|
-
* { box-sizing: border-box; } body { margin: 0; } main { width: min(100% - 2.5rem, 54rem); margin: clamp(2rem, 8vw, 6rem) auto; }
|
|
4
|
-
h1, h2 { font-family: Georgia, serif; font-weight: 400; line-height: 1.1; } h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); letter-spacing: -.045em; margin: .4em 0; } h2 { font-size: 1.65rem; }
|
|
5
|
-
.eyebrow { font-size: .7rem; letter-spacing: .18em; } header, footer { padding-bottom: 1.5rem; } section, aside, nav { margin-block: 1.5rem; }
|
|
6
|
-
button { font: inherit; padding: .55rem .95rem; margin: .3rem .4rem .3rem 0; border: 1px solid #768c7e; background: #f5f2e9; color: #183e32; cursor: pointer; border-radius: 3px; }
|
|
7
|
-
button[type=submit] { color: #f5f2e9; background: #183e32; } button:disabled { opacity: .55; cursor: default; } :focus-visible { outline: 3px solid #9a542c; outline-offset: 3px; }
|
|
8
|
-
label { display: block; } textarea, input { display: block; font: inherit; width: 100%; padding: .75rem; background: #fcfaf3; color: inherit; border: 1px solid #768c7e; border-radius: 3px; } textarea { min-height: 6rem; resize: vertical; }
|
|
9
|
-
[role=alert] { color: #8c3827; } pre, .message, [role=log] { white-space: pre-wrap; overflow-wrap: anywhere; } pre { max-height: 16rem; overflow: auto; padding: 1rem; border: 1px solid #d6d9cd; }
|
|
10
|
-
footer, .demo-note, small { font-size: .8rem; } li { margin-bottom: .7rem; } aside { border-block: 1px solid #768c7e; padding-block: 1rem; }
|
|
11
|
-
@media (max-width: 480px) { main { width: calc(100% - 1.5rem); } nav button { width: 100%; } }
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createHeadlessThreadsStore } from 'mayura/client/headless';
|
|
2
|
-
import { connectNotebook } from './connect.js';
|
|
3
|
-
/** Framework-neutral subscriptions. Observers read; all commands require an explicit UI action. */
|
|
4
|
-
export function createNotebookView() {
|
|
5
|
-
const listeners = new Set(); let session; let threads; let detach = []; let watched = []; let detachSession; let busy = false; let disposed = false; let generation = 0;
|
|
6
|
-
let state = Object.freeze({ connected: false, busy: false, phase: 'idle', error: null, threadId: null, runId: null, pending: false, message: null, history: [], threads: [], cursor: null, runStatus: null, approval: null });
|
|
7
|
-
const publish = change => { if (disposed) return; state = Object.freeze({ ...state, ...change }); for (const listener of [...listeners]) { try { listener(); } catch { /* Rendering cannot change commands. */ } } };
|
|
8
|
-
function sync() {
|
|
9
|
-
if (disposed || !session) return; const next = session.getSnapshot(); const stores = [next.threadStore, next.runStore, next.approval, threads];
|
|
10
|
-
if (stores.some((store, index) => watched[index] !== store)) { detach.forEach(fn => fn()); watched = stores; detach = stores.filter(Boolean).map(store => store.subscribe(sync)); }
|
|
11
|
-
publish({ connected: true, phase: next.phase, error: next.errorCode, threadId: next.threadId, runId: next.runId, pending: next.hasPending, message: next.message,
|
|
12
|
-
history: next.threadStore?.getSnapshot().entries ?? [], threads: threads.getSnapshot().page?.threads ?? [], cursor: threads.getSnapshot().page?.cursor ?? null,
|
|
13
|
-
runStatus: next.runStore?.getSnapshot().snapshot?.status ?? null, approval: next.approval?.getSnapshot() ?? null });
|
|
14
|
-
}
|
|
15
|
-
const perform = async task => {
|
|
16
|
-
if (disposed || busy) return; busy = true; publish({ busy: true, error: null });
|
|
17
|
-
try { await task(); } catch { publish({ error: 'Action was not confirmed. Inspect or reconnect before repeating it.' }); }
|
|
18
|
-
finally { busy = false; publish({ busy: false }); }
|
|
19
|
-
};
|
|
20
|
-
return Object.freeze({ getSnapshot: () => state, subscribe: listener => { listeners.add(listener); return () => listeners.delete(listener); },
|
|
21
|
-
connect: token => perform(async () => {
|
|
22
|
-
if (session) return; const current = ++generation; const next = await connectNotebook(token);
|
|
23
|
-
if (disposed || current !== generation) { next.session.dispose(); return; }
|
|
24
|
-
session = next.session; threads = createHeadlessThreadsStore({ client: next.client }); detachSession = session.subscribe(sync); sync();
|
|
25
|
-
await Promise.all([session.open(), threads.refresh()]);
|
|
26
|
-
}),
|
|
27
|
-
disconnect() {
|
|
28
|
-
if (disposed || busy) return; generation++; detachSession?.(); detach.forEach(fn => fn()); session?.dispose(); threads?.dispose();
|
|
29
|
-
session = undefined; threads = undefined; detachSession = undefined; detach = []; watched = [];
|
|
30
|
-
publish({ connected: false, busy: false, phase: 'idle', error: null, threadId: null, runId: null, pending: false, message: null, history: [], threads: [], cursor: null, runStatus: null, approval: null });
|
|
31
|
-
},
|
|
32
|
-
send: message => perform(() => session.send(message)),
|
|
33
|
-
retry: () => perform(() => session.retrySubmission()),
|
|
34
|
-
reconnect: () => perform(() => session.reconnect()),
|
|
35
|
-
cancel: () => perform(() => session.cancel()),
|
|
36
|
-
newThread: () => perform(async () => { await session.newThread(); await threads.refresh(); }),
|
|
37
|
-
select: id => perform(() => session.selectThread(id)),
|
|
38
|
-
list: cursor => perform(() => threads.refresh(cursor ? { cursor } : {})),
|
|
39
|
-
history: options => perform(() => session.refreshHistory(options)),
|
|
40
|
-
decide: decision => perform(async () => {
|
|
41
|
-
const controller = session.getSnapshot().approval; const snapshot = controller?.getSnapshot();
|
|
42
|
-
if (!snapshot || snapshot.status !== 'idle' || snapshot.approval.expiresAtMs <= Date.now()
|
|
43
|
-
|| decision === 'approved' && JSON.stringify(snapshot.approval.input).length > 16000) throw new Error('Approval must be refreshed.');
|
|
44
|
-
await controller.submit(decision);
|
|
45
|
-
}),
|
|
46
|
-
dispose() { if (disposed) return; disposed = true; generation++; detachSession?.(); detach.forEach(fn => fn()); session?.dispose(); threads?.dispose(); listeners.clear(); },
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
export const display = value => JSON.stringify(value, null, 2)?.slice(0, 16000) ?? '';
|
|
@@ -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
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
FROM node:24.14.1-bookworm-slim
|
|
2
|
-
WORKDIR /app
|
|
3
|
-
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ && rm -rf /var/lib/apt/lists/*
|
|
4
|
-
COPY package.json ./
|
|
5
|
-
RUN npm install --no-audit --no-fund
|
|
6
|
-
COPY . .
|
|
7
|
-
ENV NEXT_TELEMETRY_DISABLED=1 NUXT_TELEMETRY_DISABLED=1
|
|
8
|
-
RUN npm run build && mkdir -p /app/.data && chown node:node /app/.data
|
|
9
|
-
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000 NITRO_HOST=0.0.0.0 NITRO_PORT=3000
|
|
10
|
-
USER node
|
|
11
|
-
EXPOSE 3000
|
|
12
|
-
CMD ["npm", "start"]
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
web:
|
|
3
|
-
build: .
|
|
4
|
-
ports: ["127.0.0.1:3000:3000"]
|
|
5
|
-
env_file: .env
|
|
6
|
-
environment:
|
|
7
|
-
MAYURA_SQLITE_PATH: /app/.data/notebook.sqlite
|
|
8
|
-
volumes: ["notebook:/app/.data"]
|
|
9
|
-
restart: unless-stopped
|
|
10
|
-
worker:
|
|
11
|
-
build: .
|
|
12
|
-
command: ["npm", "run", "worker"]
|
|
13
|
-
env_file: .env
|
|
14
|
-
environment:
|
|
15
|
-
MAYURA_SQLITE_PATH: /app/.data/notebook.sqlite
|
|
16
|
-
volumes: ["notebook:/app/.data"]
|
|
17
|
-
restart: unless-stopped
|
|
18
|
-
volumes:
|
|
19
|
-
notebook:
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
MAYURA_PUBLIC_ORIGIN=http://localhost:3000
|
|
2
|
-
MAYURA_PROJECT_ID=notebook
|
|
3
|
-
# Explicit token SHA-256, principal and absolute expiry; never a browser-provided project/principal.
|
|
4
|
-
MAYURA_SESSIONS_JSON=[]
|
|
5
|
-
MAYURA_SQLITE_PATH=.data/notebook.sqlite
|
|
6
|
-
# For replicas/serverless, replace SQLite with a shared persistent database:
|
|
7
|
-
# DATABASE_URL=postgresql://...
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { randomBytes, createHash } from 'node:crypto';
|
|
2
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
// Local single-user setup only. Secrets go to owner-readable ignored files, never logs or browser bundles.
|
|
4
|
-
const token = randomBytes(32).toString('hex');
|
|
5
|
-
const sessions = [{ tokenSha256: createHash('sha256').update(token).digest('hex'), principalId: 'local-user', expiresAtMs: Date.now() + 8 * 3600000 }];
|
|
6
|
-
await mkdir('.data', { recursive: true });
|
|
7
|
-
await writeFile('.env', `MAYURA_PUBLIC_ORIGIN=http://localhost:3000\nMAYURA_PROJECT_ID=notebook\nMAYURA_SESSIONS_JSON='${JSON.stringify(sessions)}'\n`, { flag: 'wx', mode: 0o600 });
|
|
8
|
-
await writeFile('.data/login-token', token, { flag: 'wx', mode: 0o600 });
|
|
9
|
-
console.log('Local session created. Open .data/login-token and enter it in the notebook. Restart the server after changing identities.');
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { defineAgent, defineTool, z } from 'mayura';
|
|
2
|
-
import { createAgentServer } from 'mayura/server';
|
|
3
|
-
import { createAggregateRunRecords } from 'mayura/storage-contracts';
|
|
4
|
-
import { identityDirectory, agentId } from './auth.mjs';
|
|
5
|
-
import { workflowServices } from './workflows.mjs';
|
|
6
|
-
|
|
7
|
-
/** All adapters, including edge hosts, receive the same persistent store and host-verified identity directory. */
|
|
8
|
-
export async function createApplication({ store, publicOrigin, projectId, sessions, modelOverride }) {
|
|
9
|
-
const origin = new URL(publicOrigin);
|
|
10
|
-
if (origin.origin !== publicOrigin || !(origin.protocol === 'https:' || origin.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(origin.hostname))) throw new Error('Invalid public origin.');
|
|
11
|
-
const directory = identityDirectory(projectId, sessions);
|
|
12
|
-
await store.initialize(); await store.threads.initialize();
|
|
13
|
-
const workflows = directory.scopes.map(scope => workflowServices(store, scope));
|
|
14
|
-
const save = defineTool({ id: 'notes.save', version: '1', description: 'Save this note and schedule local indexing after your approval.',
|
|
15
|
-
input: z.object({ text: z.string().trim().min(1).max(2000) }).strict(), output: z.object({ saved: z.literal(true), noteId: z.string() }).strict(),
|
|
16
|
-
effects: 'write', capabilities: ['notes:write'], approval: 'required', costMicros: 0, timeoutMs: 5000,
|
|
17
|
-
execute: async ({ text }, context) => {
|
|
18
|
-
context.signal.throwIfAborted(); const scope = context.scope;
|
|
19
|
-
const index = directory.scopes.findIndex(item => item.principalId === scope.principalId && item.projectId === scope.projectId);
|
|
20
|
-
if (index < 0) throw new Error('Scope refused.');
|
|
21
|
-
const noteId = `${context.runId}:${context.callId}`;
|
|
22
|
-
// Effect-local idempotency is still needed: a checkpoint is not an external-effect transaction.
|
|
23
|
-
await store.create({ scope: JSON.stringify([scope.principalId, scope.projectId, 'notes']), id: noteId, idempotencyKey: noteId,
|
|
24
|
-
definitionHash: 'notebook-note-v1', state: { text }, events: [{ type: 'note.saved', data: { text } }] });
|
|
25
|
-
await workflows[index].host.runtime.submit(workflows[index].definition, { idempotencyKey: noteId, input: { noteId } });
|
|
26
|
-
return { saved: true, noteId };
|
|
27
|
-
} });
|
|
28
|
-
// Deterministic fixture: no provider key or paid model request. One approval-required write per submitted turn.
|
|
29
|
-
const model = modelOverride ?? Object.freeze({ id: 'notebook.fixture', maxCostMicros: 0, capabilities: { tools: true, structuredOutput: true, history: true },
|
|
30
|
-
async generate(request) {
|
|
31
|
-
request.signal.throwIfAborted();
|
|
32
|
-
const result = request.messages.findLast(item => item.role === 'tool');
|
|
33
|
-
if (result) return { type: 'final', output: { reply: result.result?.saved === true ? 'Saved after your approval. Indexing is queued.' : 'The note was not saved.' }, usage: { costMicros: 0 } };
|
|
34
|
-
const input = request.messages.find(item => item.role === 'user')?.content;
|
|
35
|
-
return { type: 'tool_calls', calls: [{ id: crypto.randomUUID(), toolId: save.id, input: { text: input.message } }], usage: { costMicros: 0 } };
|
|
36
|
-
} });
|
|
37
|
-
const agent = defineAgent({ id: agentId, version: '1', instructions: 'Propose one note write, then report its approved result.',
|
|
38
|
-
input: z.object({ message: z.string().trim().min(1).max(2000) }).strict(), output: z.object({ reply: z.string() }).strict(), tools: [save], model });
|
|
39
|
-
const server = createAgentServer({ publicOrigin, mounted: true, agents: [{ agent,
|
|
40
|
-
permissions: { allow: [`model:${model.id}`, 'tool:notes.save', 'notes:write', 'effect:write'] },
|
|
41
|
-
limits: { maxCostMicros: 0, maxSteps: 3, maxModelCalls: 2, maxToolCalls: 1, maxDurationMs: 10000 } }],
|
|
42
|
-
authenticate: directory.authenticate, threads: { store }, runRecords: createAggregateRunRecords(store), runExecution: 'request',
|
|
43
|
-
conversationRecovery: { permissions: { allow: ['conversations:recover'] }, pageSize: 25,
|
|
44
|
-
authorize: async ({ scope, agentId: requested, signal }) => !signal.aborted && requested === agentId && directory.scopes.some(item => item.principalId === scope.principalId && item.projectId === scope.projectId) },
|
|
45
|
-
limits: { maxRuns: 128, maxRuntimes: 32, maxRequests: 32, maxStreams: 16, maxBodyBytes: 16384, maxResponseBytes: 1048576,
|
|
46
|
-
requestTimeoutMs: 15000, streamDurationMs: 5000, runRecordPollMs: 100 } });
|
|
47
|
-
let recoveryCursor; let closed = false; let recovering;
|
|
48
|
-
return Object.freeze({ server, store, workflows,
|
|
49
|
-
async fetch(request) {
|
|
50
|
-
const url = new URL(request.url); const prefix = '/api/mayura';
|
|
51
|
-
if (!url.pathname.startsWith(`${prefix}/`)) return new Response('Not found', { status: 404 });
|
|
52
|
-
url.pathname = url.pathname.slice(prefix.length);
|
|
53
|
-
return server.fetch(new Request(url, request));
|
|
54
|
-
},
|
|
55
|
-
async runOnce() {
|
|
56
|
-
if (closed) throw new Error('Application closed.');
|
|
57
|
-
if (recovering) return recovering;
|
|
58
|
-
recovering = (async () => {
|
|
59
|
-
const recovery = await server.recoverConversations({ limit: 25, ...(recoveryCursor ? { after: recoveryCursor } : {}) });
|
|
60
|
-
recoveryCursor = recovery.next ?? undefined;
|
|
61
|
-
const reports = []; for (const item of workflows) reports.push(await item.worker.runOnce({ budgetMs: 1000 }));
|
|
62
|
-
if (recovery.outcomes.some(item => item.status === 'retry') || reports.some(item => item.failures.length)) throw new Error('Background work needs attention.');
|
|
63
|
-
return { recovered: recovery.outcomes.length, scopes: reports.length };
|
|
64
|
-
})();
|
|
65
|
-
try { return await recovering; } finally { recovering = undefined; }
|
|
66
|
-
},
|
|
67
|
-
async close() {
|
|
68
|
-
if (closed) return; closed = true;
|
|
69
|
-
await recovering?.catch(() => undefined); await server.close();
|
|
70
|
-
for (const item of workflows) { await item.worker.drain(); await item.host.close(); }
|
|
71
|
-
await store.close();
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { sha256Hex } from 'mayura/core/host';
|
|
2
|
-
|
|
3
|
-
export const agentId = 'notebook.assistant';
|
|
4
|
-
export const capabilities = Object.freeze(['runs:read', 'runs:submit', 'runs:cancel', 'runs:approve', 'threads:read', 'threads:write']);
|
|
5
|
-
/** Snapshot a bounded host-owned identity directory. Browser claims never set scope or capabilities. */
|
|
6
|
-
export function identityDirectory(projectId, sessions) {
|
|
7
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(projectId) || !Array.isArray(sessions) || !sessions.length || sessions.length > 32) throw new Error('Invalid identity configuration.');
|
|
8
|
-
const seen = new Set();
|
|
9
|
-
const entries = sessions.map(item => {
|
|
10
|
-
if (!item || Object.keys(item).some(key => !['tokenSha256', 'principalId', 'expiresAtMs'].includes(key))
|
|
11
|
-
|| !/^[a-f0-9]{64}$/u.test(item.tokenSha256) || seen.has(item.tokenSha256)
|
|
12
|
-
|| typeof item.principalId !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(item.principalId)
|
|
13
|
-
|| !Number.isSafeInteger(item.expiresAtMs) || item.expiresAtMs < 1) throw new Error('Invalid identity configuration.');
|
|
14
|
-
seen.add(item.tokenSha256);
|
|
15
|
-
return Object.freeze({ ...item, scope: Object.freeze({ principalId: item.principalId, projectId }) });
|
|
16
|
-
});
|
|
17
|
-
const scopes = [...new Map(entries.map(item => [item.principalId, item.scope])).values()];
|
|
18
|
-
return Object.freeze({ scopes: Object.freeze(scopes), authenticate: async ({ token, signal }) => {
|
|
19
|
-
if (signal.aborted || typeof token !== 'string' || !/^[a-f0-9]{64}$/u.test(token)) return null;
|
|
20
|
-
const digest = await sha256Hex(token); if (signal.aborted) return null;
|
|
21
|
-
const entry = entries.find(item => item.tokenSha256 === digest);
|
|
22
|
-
return entry && entry.expiresAtMs > Date.now() ? { scope: entry.scope, agentIds: [agentId], capabilities, expiresAtMs: entry.expiresAtMs } : null;
|
|
23
|
-
} });
|
|
24
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { application } from './node.mjs';
|
|
2
|
-
// A separate bounded worker process; runOnce is also available to a trusted scheduler. No public cron endpoint.
|
|
3
|
-
const app = await application(); let stopping = false; let timer; let active;
|
|
4
|
-
async function cycle() {
|
|
5
|
-
try { await app.runOnce(); } catch { console.error('Notebook background work needs attention.'); }
|
|
6
|
-
finally { if (!stopping) timer = setTimeout(() => { active = cycle(); }, 1000); }
|
|
7
|
-
}
|
|
8
|
-
async function stop() { if (stopping) return; stopping = true; clearTimeout(timer); await active; await app.close(); }
|
|
9
|
-
process.once('SIGINT', () => void stop()); process.once('SIGTERM', () => void stop());
|
|
10
|
-
console.log(JSON.stringify({ event: 'worker-started' }));
|
|
11
|
-
active = cycle();
|