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,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,57 +0,0 @@
|
|
|
1
|
-
import { createElement as h, useEffect, useState, useSyncExternalStore } from 'react';
|
|
2
|
-
import { useMayuraRun, useMayuraRunApprovalCommand } from 'mayura/client-react';
|
|
3
|
-
import { ThreadHistory as MayuraThreadHistory } from './components/mayura/thread-history';
|
|
4
|
-
import { Approval as MayuraRunApprovalControl } from './components/mayura/approval';
|
|
5
|
-
import { ThreadList } from './components/mayura/thread-list';
|
|
6
|
-
|
|
7
|
-
const ignore = promise => { void promise.catch(() => {}); };
|
|
8
|
-
function ApprovalPanel({ controller, session }) {
|
|
9
|
-
const state = useMayuraRunApprovalCommand(controller); const [nowMs, setNowMs] = useState(Date.now);
|
|
10
|
-
// This is application policy, not a side effect of the reusable approval component.
|
|
11
|
-
useEffect(() => { const timer = setInterval(() => setNowMs(Date.now()), 1_000); return () => clearInterval(timer); }, []);
|
|
12
|
-
return h('aside', { 'aria-label': 'Review note before saving' },
|
|
13
|
-
h('h2', null, 'Review before saving'), h(MayuraRunApprovalControl, { controller, nowMs, subject: 'this note' }),
|
|
14
|
-
['failed', 'conflict'].includes(state.status) ? h('button', { type: 'button', onClick: () => ignore(session.reconnect()) }, 'Refresh approval') : null);
|
|
15
|
-
}
|
|
16
|
-
function ActiveRun({ store, controller, session, canCancel }) {
|
|
17
|
-
const state = useMayuraRun(store);
|
|
18
|
-
return h('section', { 'aria-label': 'Current turn' },
|
|
19
|
-
h('p', { role: 'status' }, `Run ${state.snapshot?.status ?? state.connection}`),
|
|
20
|
-
state.snapshot?.status === 'waiting' && controller ? h(ApprovalPanel, { controller, session }) : null,
|
|
21
|
-
canCancel ? h('button', { type: 'button', onClick: () => ignore(session.cancel()) }, 'Cancel current run') : null);
|
|
22
|
-
}
|
|
23
|
-
/** The app owns transport/session lifecycle; the library's history and approval components remain inert on mount. */
|
|
24
|
-
export function ChatApp({ session, threads }) {
|
|
25
|
-
const state = useSyncExternalStore(session.subscribe, session.getSnapshot, session.getSnapshot);
|
|
26
|
-
const [message, setMessage] = useState(() => session.getSnapshot().runId || session.getSnapshot().hasPending ? '' : 'Remember to send the release notes.');
|
|
27
|
-
const canSend = state.phase === 'ready' && !state.busy && !state.hasPending && !state.runId;
|
|
28
|
-
const send = async event => {
|
|
29
|
-
event.preventDefault(); if (!canSend || !message.trim()) return;
|
|
30
|
-
try { await session.send(message); setMessage(''); } catch { /* Session feedback retains the draft and exact retry key. */ }
|
|
31
|
-
};
|
|
32
|
-
return h('div', { className: 'chat' },
|
|
33
|
-
h('header', null, h('p', { className: 'eyebrow' }, 'MAYURA / NOTEBOOK'), h('h1', null, 'A note, with your approval.'),
|
|
34
|
-
h('p', null, 'Send a message. Review the proposed note write. Approve it, reject it, or cancel the run.'),
|
|
35
|
-
h('p', { className: 'demo-note' }, 'Deterministic demo adapter · no model API key · no external effects')),
|
|
36
|
-
h(ThreadList, { store: threads, onSelect: threadId => { if (canSend) ignore(session.selectThread(threadId)); } }),
|
|
37
|
-
h('nav', { 'aria-label': 'Conversation actions' },
|
|
38
|
-
h('button', { type: 'button', onClick: () => ignore(threads.refresh()) }, 'Refresh conversations'),
|
|
39
|
-
h('button', { type: 'button', disabled: !canSend, onClick: () => ignore(session.newThread()) }, 'New chat'),
|
|
40
|
-
h('button', { type: 'button', disabled: state.busy || ['opening', 'submitting', 'idle'].includes(state.phase), onClick: () => ignore(session.reconnect()) }, 'Reconnect / refresh')),
|
|
41
|
-
state.errorCode ? h('p', { role: 'alert' }, `Chat needs attention (${state.errorCode}). Reconnect to inspect the run; decisions are never retried automatically.`) : null,
|
|
42
|
-
['THREAD_NOT_FOUND', 'RUN_NOT_FOUND'].includes(state.errorCode) ? h('button', { type: 'button', onClick: () => ignore(session.forgetMissing()) }, 'Forget missing chat') : null,
|
|
43
|
-
state.hasPending ? h('section', { 'aria-label': 'Unconfirmed submission' },
|
|
44
|
-
h('p', null, 'This send has not been confirmed. Retry uses the same message and idempotency key.'),
|
|
45
|
-
h('button', { type: 'button', disabled: state.busy || state.phase === 'submitting', onClick: () => ignore(session.retrySubmission()) }, 'Retry last send')) : null,
|
|
46
|
-
state.threadStore ? h(MayuraThreadHistory, { store: state.threadStore,
|
|
47
|
-
onLoadEarlier: page => ignore(session.refreshHistory(page)), onLoadLater: page => ignore(session.refreshHistory(page)) })
|
|
48
|
-
: h('p', { role: 'status' }, 'Opening your conversation…'),
|
|
49
|
-
state.message ? h('section', { 'aria-label': 'Current message' }, h('h2', null, 'You'), h('p', { className: 'message' }, state.message)) : null,
|
|
50
|
-
state.runStore ? h(ActiveRun, { store: state.runStore, controller: state.approval, session, canCancel: Boolean(state.runId) && !state.busy }) : null,
|
|
51
|
-
h('form', { onSubmit: send, 'aria-label': 'Send a message' },
|
|
52
|
-
h('label', { htmlFor: 'chat-message' }, 'Message'),
|
|
53
|
-
h('textarea', { id: 'chat-message', value: message, maxLength: 2_000, rows: 3, disabled: !canSend,
|
|
54
|
-
onChange: event => setMessage(event.target.value), placeholder: 'Write a note to save…' }),
|
|
55
|
-
h('button', { type: 'submit', disabled: !canSend || !message.trim() }, 'Send message')),
|
|
56
|
-
h('footer', null, 'Reload this page while a run is waiting to recover its approval. Notes and approvals use the configured database. Run the background worker to process indexing and recovery.'));
|
|
57
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { createElement as h, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { createHeadlessThreadsStore } from 'mayura/client/headless';
|
|
4
|
-
import { connectNotebook } from './connect.js';
|
|
5
|
-
import { ChatApp } from './ChatApp.jsx';
|
|
6
|
-
|
|
7
|
-
/** Inert on render. Login is explicit; unmount disposes observers, never cancelling remote writes implicitly. */
|
|
8
|
-
export default function Notebook() {
|
|
9
|
-
const [token, setToken] = useState(''); const [active, setActive] = useState(null); const [error, setError] = useState(''); const [busy, setBusy] = useState(false);
|
|
10
|
-
const current = useRef(null); const mounted = useRef(true); const connecting = useRef(false);
|
|
11
|
-
useEffect(() => { mounted.current = true; return () => { mounted.current = false; current.current?.session.dispose(); current.current?.threads.dispose(); }; }, []);
|
|
12
|
-
async function login(event) {
|
|
13
|
-
event.preventDefault(); if (connecting.current) return; connecting.current = true; setBusy(true); setError('');
|
|
14
|
-
try {
|
|
15
|
-
const next = await connectNotebook(token); if (!mounted.current) { next.session.dispose(); return; }
|
|
16
|
-
const threads = createHeadlessThreadsStore({ client: next.client }); current.current = { ...next, threads }; setToken(''); setActive(current.current);
|
|
17
|
-
await Promise.all([next.session.open(), threads.refresh()]);
|
|
18
|
-
} catch { if (mounted.current) setError('Connection needs attention. Check your session or inspect the conversation before retrying.'); }
|
|
19
|
-
finally { connecting.current = false; if (mounted.current) setBusy(false); }
|
|
20
|
-
}
|
|
21
|
-
function logout() { current.current?.session.dispose(); current.current?.threads.dispose(); current.current = null; setActive(null); }
|
|
22
|
-
return h('main', null, active ? h('div', null, h('button', { type: 'button', onClick: logout }, 'Disconnect'), h(ChatApp, { session: active.session, threads: active.threads })) :
|
|
23
|
-
h('section', null, h('p', { className: 'eyebrow' }, 'MAYURA / NOTEBOOK'), h('h1', null, 'Your words. Your decision.'), h('p', null, 'Connect with your private session token. Every note waits for your approval.'),
|
|
24
|
-
h('form', { onSubmit: login }, h('label', null, 'Session token', h('input', { type: 'password', value: token, autoComplete: 'off', maxLength: 64, required: true, onChange: event => setToken(event.target.value) })), h('button', { disabled: busy, type: 'submit' }, busy ? 'Connecting…' : 'Connect'))), error ? h('p', { role: 'alert' }, error) : null);
|
|
25
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createElement, useCallback, useId, useMemo, useRef, useState, type ReactElement } from 'react';
|
|
2
|
-
import type { ClientJson, RemoteThreadEntry } from 'mayura/client';
|
|
3
|
-
import type { HeadlessThreadStore, RunApprovalController, RunApprovalCommandState } from 'mayura/client/headless';
|
|
4
|
-
import { MayuraReactError, useMayuraThread, useMayuraRunApprovalCommand } from 'mayura/client-react';
|
|
5
|
-
|
|
6
|
-
export interface MayuraThreadHistoryProps {
|
|
7
|
-
readonly store: HeadlessThreadStore; readonly label?: string;
|
|
8
|
-
/** Maximum displayed characters per entry (default 8,192, at most 65,536). Truncation is explicit. */
|
|
9
|
-
readonly maxContentChars?: number;
|
|
10
|
-
/** Explicit page intents; route these to store.refresh with the store's configured limit. */
|
|
11
|
-
readonly onLoadEarlier?: (page: { readonly before: number }) => void;
|
|
12
|
-
readonly onLoadLater?: (page: { readonly after: number }) => void;
|
|
13
|
-
}
|
|
14
|
-
export interface MayuraRunApprovalControlProps {
|
|
15
|
-
readonly controller: RunApprovalController;
|
|
16
|
-
/** Caller-owned clock: update this to reflect expiry; the component starts no timer. */
|
|
17
|
-
readonly nowMs: number;
|
|
18
|
-
readonly label?: string;
|
|
19
|
-
/** Optional accessible context when several runs have pending approvals. */
|
|
20
|
-
readonly subject?: string;
|
|
21
|
-
/** Default 8,192, at most 65,536. Approval is unavailable if the input cannot be displayed in full. */
|
|
22
|
-
readonly maxInputChars?: number;
|
|
23
|
-
}
|
|
24
|
-
function invalid(): never { throw new MayuraReactError('INVALID_COMPONENT_PROPS'); }
|
|
25
|
-
function label(value: string | undefined, fallback: string): string {
|
|
26
|
-
const result = value ?? fallback;
|
|
27
|
-
if (typeof result !== 'string' || result.length < 1 || result.length > 128 || result.includes('\0')) return invalid(); return result;
|
|
28
|
-
}
|
|
29
|
-
function bound(value: number | undefined): number {
|
|
30
|
-
const result = value ?? 8_192; if (!Number.isSafeInteger(result) || result < 1 || result > 65_536) return invalid(); return result;
|
|
31
|
-
}
|
|
32
|
-
/** Values remain text, including strings that resemble HTML, Markdown, URLs or tool instructions. */
|
|
33
|
-
function display(value: ClientJson, maximum: number, json = false): { readonly text: string; readonly truncated: boolean } {
|
|
34
|
-
const raw = typeof value === 'string' && !json ? value : JSON.stringify(value, null, 2);
|
|
35
|
-
// Do not split a UTF-16 surrogate pair at the display boundary.
|
|
36
|
-
const end = raw.length > maximum && /[\uD800-\uDBFF]/.test(raw[maximum - 1]!) ? maximum - 1 : maximum;
|
|
37
|
-
return { text: raw.slice(0, end), truncated: raw.length > maximum };
|
|
38
|
-
}
|
|
39
|
-
function entryContent(entry: RemoteThreadEntry): { readonly name: string; readonly content: ClientJson } {
|
|
40
|
-
switch (entry.kind) {
|
|
41
|
-
case 'user': return { name: 'You', content: entry.content };
|
|
42
|
-
case 'assistant': return { name: 'Assistant', content: entry.output };
|
|
43
|
-
case 'tool_calls': return { name: 'Tool calls', content: entry.calls };
|
|
44
|
-
case 'tool_result': return { name: `Tool result: ${entry.toolId}`, content: entry.result };
|
|
45
|
-
case 'approval': return { name: `Approval: ${entry.toolId}`, content: `${entry.decision}${entry.actorId ? ` by ${entry.actorId}` : ''}` };
|
|
46
|
-
case 'run': return { name: 'Run', content: `${entry.status}${entry.errorCode ? ` (${entry.errorCode})` : ''}` };
|
|
47
|
-
case 'summary': return { name: `Summary of entries ${entry.covers.from}–${entry.covers.to}`, content: entry.content };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function historyEntry(entry: RemoteThreadEntry, maximum: number): ReactElement {
|
|
51
|
-
const content = entryContent(entry); const text = display(content.content, maximum);
|
|
52
|
-
const omitted = 'omitted' in entry && entry.omitted === 'too_large';
|
|
53
|
-
const media = 'mediaOmitted' in entry ? entry.mediaOmitted : undefined;
|
|
54
|
-
return createElement('li', { key: entry.sequence, value: entry.sequence, 'data-kind': entry.kind, 'data-turn-id': entry.turnId },
|
|
55
|
-
createElement('p', null, content.name, ' · ', createElement('time', { dateTime: entry.createdAt }, entry.createdAt)),
|
|
56
|
-
omitted ? createElement('p', { 'data-mayura-omitted': true }, 'Content omitted from the saved history because it was too large')
|
|
57
|
-
: createElement('pre', { 'data-mayura-content': true }, text.text),
|
|
58
|
-
!omitted && text.truncated ? createElement('p', { 'data-mayura-truncated': true }, 'Display truncated; the saved entry contains more content') : null,
|
|
59
|
-
'media' in entry && entry.media?.length ? createElement('ul', { 'aria-label': 'Saved media references' }, ...entry.media.map((reference,index) => createElement('li', { key: `${reference.id}-${index}` }, `${reference.name ?? reference.mediaType} · ${reference.id}`))) : null,
|
|
60
|
-
media ? createElement('p', null, `${media} media item${media === 1 ? '' : 's'} omitted from the saved history`) : null);
|
|
61
|
-
}
|
|
62
|
-
/** One bounded history page. Rendering never fetches, paginates, scrolls, starts a run or disposes a shared store. */
|
|
63
|
-
export function MayuraThreadHistory({ store, label: suppliedLabel, maxContentChars, onLoadEarlier, onLoadLater }: MayuraThreadHistoryProps): ReactElement {
|
|
64
|
-
const state = useMayuraThread(store); const accessibleLabel = label(suppliedLabel, 'Thread history'); const maximum = bound(maxContentChars);
|
|
65
|
-
if ((onLoadEarlier !== undefined && typeof onLoadEarlier !== 'function') || (onLoadLater !== undefined && typeof onLoadLater !== 'function')) return invalid();
|
|
66
|
-
const first = state.entries[0]?.sequence; const last = state.entries.at(-1)?.sequence;
|
|
67
|
-
const locked = !['ready', 'failed'].includes(state.status);
|
|
68
|
-
const page = (direction: 'earlier' | 'later'): void => {
|
|
69
|
-
const current = store.getSnapshot(); if (!['ready', 'failed'].includes(current.status)) return;
|
|
70
|
-
const before = current.entries[0]?.sequence; const after = current.entries.at(-1)?.sequence;
|
|
71
|
-
if (direction === 'earlier' && before !== undefined && before > 1) onLoadEarlier?.(Object.freeze({ before }));
|
|
72
|
-
else if (direction === 'later' && after !== undefined && after < (current.thread?.lastSequence ?? 0)) onLoadLater?.(Object.freeze({ after }));
|
|
73
|
-
};
|
|
74
|
-
// Durable recording markers are bookkeeping between chunks, rather than conversation messages.
|
|
75
|
-
const entries = useMemo(() => state.entries.filter(entry => entry.kind !== 'run' || !entry.recording), [state.entries]);
|
|
76
|
-
const renderedEntries = useMemo(() => entries.map(entry => historyEntry(entry, maximum)), [entries, maximum]);
|
|
77
|
-
const feedback = state.status === 'loading' ? 'Loading conversation history' : state.status === 'deleted' ? 'Conversation deleted'
|
|
78
|
-
: state.status === 'disposed' ? 'History view closed' : state.status === 'idle' ? 'History not loaded' : 'Conversation history';
|
|
79
|
-
return createElement('section', { 'aria-label': accessibleLabel, 'aria-busy': state.status === 'loading', 'data-mayura-component': 'thread-history' },
|
|
80
|
-
createElement('p', { role: 'status', 'aria-live': 'polite', 'data-history-status': state.status }, feedback),
|
|
81
|
-
state.errorCode === null ? null : createElement('p', { role: 'alert' }, entries.length ? 'History could not be refreshed. Showing the last loaded page.' : 'History could not be loaded.'),
|
|
82
|
-
entries.length ? createElement('ol', { 'aria-label': 'Conversation entries', start: entries[0]!.sequence }, renderedEntries)
|
|
83
|
-
: createElement('p', { 'data-mayura-empty': true }, state.status === 'ready' ? 'No conversation entries on this page' : 'No conversation entries displayed'),
|
|
84
|
-
onLoadEarlier !== undefined && first !== undefined && first > 1
|
|
85
|
-
? createElement('button', { type: 'button', 'aria-disabled': locked, onClick: () => page('earlier') }, 'Load earlier entries') : null,
|
|
86
|
-
onLoadLater !== undefined && last !== undefined && last < (state.thread?.lastSequence ?? 0)
|
|
87
|
-
? createElement('button', { type: 'button', 'aria-disabled': locked, onClick: () => page('later') }, 'Load later entries') : null);
|
|
88
|
-
}
|
|
89
|
-
interface ApprovalBodyProps {
|
|
90
|
-
readonly controller: RunApprovalController; readonly state: RunApprovalCommandState; readonly nowMs: number;
|
|
91
|
-
readonly accessibleLabel: string; readonly subject: string | undefined; readonly maximum: number;
|
|
92
|
-
}
|
|
93
|
-
/** Keyed to the captured approval, so a new request gets a fresh reason field and local validation state. */
|
|
94
|
-
function ApprovalBody({ controller, state, nowMs, accessibleLabel, subject, maximum }: ApprovalBodyProps): ReactElement {
|
|
95
|
-
const reasonId = useId(); const inputId = useId(); const errorId = useId(); const reason = useRef<HTMLTextAreaElement | null>(null);
|
|
96
|
-
const [invalidReason, setInvalidReason] = useState(false); const approval = state.approval;
|
|
97
|
-
const input = useMemo(() => display(approval.input, maximum, true), [approval.input, maximum]); const expired = nowMs >= approval.expiresAtMs;
|
|
98
|
-
// A failed transport can have applied a decision. Require a fresh inspection instead of presenting a retry button.
|
|
99
|
-
const locked = state.status !== 'idle' || expired;
|
|
100
|
-
const decide = useCallback((decision: 'approved' | 'rejected') => {
|
|
101
|
-
const current = controller.getSnapshot();
|
|
102
|
-
// Recheck synchronously: two click events may arrive before React has painted submitting feedback.
|
|
103
|
-
if (current.status !== 'idle' || current.approval.digest !== approval.digest || current.approval.callId !== approval.callId
|
|
104
|
-
|| nowMs >= current.approval.expiresAtMs || (decision === 'approved' && input.truncated)) return;
|
|
105
|
-
const value = reason.current?.value ?? ''; if (value.length > 1_000) { setInvalidReason(true); return; }
|
|
106
|
-
setInvalidReason(false);
|
|
107
|
-
// The controller publishes errors and accepted decisions; rendering never owns or retries the command.
|
|
108
|
-
void controller.submit(decision, value.length ? { reason: value } : undefined).catch(() => {});
|
|
109
|
-
}, [controller, approval.callId, approval.digest, nowMs, input.truncated]);
|
|
110
|
-
const feedback = state.status === 'submitting' ? 'Submitting decision' : state.status === 'succeeded' ? 'Decision submitted'
|
|
111
|
-
: state.status === 'conflict' ? 'Approval changed or expired; refresh the run before deciding'
|
|
112
|
-
: state.status === 'failed' ? 'Decision outcome unknown; refresh the run before deciding'
|
|
113
|
-
: state.status === 'disposed' ? 'Approval controller closed' : expired ? 'Approval expired; refresh the run' : 'Awaiting your decision';
|
|
114
|
-
const context = subject ?? `${approval.toolId}, call ${approval.callId}`;
|
|
115
|
-
return createElement('section', { 'aria-label': accessibleLabel, 'aria-busy': state.status === 'submitting', 'data-mayura-component': 'run-approval-control' },
|
|
116
|
-
createElement('p', null, `Review ${approval.toolId} (version ${approval.toolVersion})`),
|
|
117
|
-
createElement('p', null, `Call ${approval.callId}`),
|
|
118
|
-
createElement('p', null, 'Expires ', createElement('time', { dateTime: new Date(approval.expiresAtMs).toISOString() }, new Date(approval.expiresAtMs).toISOString())),
|
|
119
|
-
createElement('pre', { id: inputId, 'data-mayura-approval-input': true }, input.text),
|
|
120
|
-
input.truncated ? createElement('p', { 'data-mayura-truncated': true }, 'Input truncated. Review the full input outside this view before approving. You can still reject this request.') : null,
|
|
121
|
-
createElement('label', { htmlFor: reasonId }, 'Reason (optional)'),
|
|
122
|
-
createElement('textarea', { key: 'reason', ref: reason, id: reasonId, maxLength: 1_000, disabled: locked,
|
|
123
|
-
'aria-invalid': invalidReason, 'aria-describedby': invalidReason ? errorId : undefined, onInput: () => setInvalidReason(false) }),
|
|
124
|
-
invalidReason ? createElement('p', { id: errorId, role: 'alert' }, 'Reason must be at most 1,000 characters') : null,
|
|
125
|
-
createElement('p', { role: 'status', 'aria-live': 'polite', 'data-command-status': state.status }, feedback),
|
|
126
|
-
createElement('button', { type: 'button', 'aria-label': `Approve for ${context}`, 'aria-disabled': locked || input.truncated,
|
|
127
|
-
'aria-describedby': inputId, onClick: () => decide('approved') }, 'Approve'),
|
|
128
|
-
createElement('button', { type: 'button', 'aria-label': `Reject for ${context}`, 'aria-disabled': locked,
|
|
129
|
-
'aria-describedby': inputId, onClick: () => decide('rejected') }, 'Reject'));
|
|
130
|
-
}
|
|
131
|
-
/** Review and decide one captured approval. Buttons keep focus while busy; neither mounting nor expiry starts work. */
|
|
132
|
-
export function MayuraRunApprovalControl({ controller, nowMs, label: suppliedLabel, subject, maxInputChars }: MayuraRunApprovalControlProps): ReactElement {
|
|
133
|
-
const state = useMayuraRunApprovalCommand(controller); const accessibleLabel = label(suppliedLabel, 'Run approval');
|
|
134
|
-
if (!Number.isSafeInteger(nowMs) || nowMs < 0 || !Number.isFinite(new Date(state.approval.expiresAtMs).getTime())) return invalid();
|
|
135
|
-
const subjectText = subject === undefined ? undefined : label(subject, 'run');
|
|
136
|
-
return createElement(ApprovalBody, { key: `${state.approval.callId}:${state.approval.digest}`, controller, state, nowMs,
|
|
137
|
-
accessibleLabel, subject: subjectText, maximum: bound(maxInputChars) });
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
import './ui.css';
|
|
141
|
-
/** Source-owned rendering and hook subscriptions; no mount-time network work. */
|
|
142
|
-
export function Approval(props: MayuraRunApprovalControlProps) { return createElement('section',{ className:'mayura-ui' },createElement(MayuraRunApprovalControl,props)); }
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createElement, useCallback, useId, useMemo, useRef, useState, type ReactElement } from 'react';
|
|
2
|
-
import type { ClientJson, RemoteThreadEntry } from 'mayura/client';
|
|
3
|
-
import type { HeadlessThreadStore, RunApprovalController, RunApprovalCommandState } from 'mayura/client/headless';
|
|
4
|
-
import { MayuraReactError, useMayuraThread, useMayuraRunApprovalCommand } from 'mayura/client-react';
|
|
5
|
-
|
|
6
|
-
export interface MayuraThreadHistoryProps {
|
|
7
|
-
readonly store: HeadlessThreadStore; readonly label?: string;
|
|
8
|
-
/** Maximum displayed characters per entry (default 8,192, at most 65,536). Truncation is explicit. */
|
|
9
|
-
readonly maxContentChars?: number;
|
|
10
|
-
/** Explicit page intents; route these to store.refresh with the store's configured limit. */
|
|
11
|
-
readonly onLoadEarlier?: (page: { readonly before: number }) => void;
|
|
12
|
-
readonly onLoadLater?: (page: { readonly after: number }) => void;
|
|
13
|
-
}
|
|
14
|
-
export interface MayuraRunApprovalControlProps {
|
|
15
|
-
readonly controller: RunApprovalController;
|
|
16
|
-
/** Caller-owned clock: update this to reflect expiry; the component starts no timer. */
|
|
17
|
-
readonly nowMs: number;
|
|
18
|
-
readonly label?: string;
|
|
19
|
-
/** Optional accessible context when several runs have pending approvals. */
|
|
20
|
-
readonly subject?: string;
|
|
21
|
-
/** Default 8,192, at most 65,536. Approval is unavailable if the input cannot be displayed in full. */
|
|
22
|
-
readonly maxInputChars?: number;
|
|
23
|
-
}
|
|
24
|
-
function invalid(): never { throw new MayuraReactError('INVALID_COMPONENT_PROPS'); }
|
|
25
|
-
function label(value: string | undefined, fallback: string): string {
|
|
26
|
-
const result = value ?? fallback;
|
|
27
|
-
if (typeof result !== 'string' || result.length < 1 || result.length > 128 || result.includes('\0')) return invalid(); return result;
|
|
28
|
-
}
|
|
29
|
-
function bound(value: number | undefined): number {
|
|
30
|
-
const result = value ?? 8_192; if (!Number.isSafeInteger(result) || result < 1 || result > 65_536) return invalid(); return result;
|
|
31
|
-
}
|
|
32
|
-
/** Values remain text, including strings that resemble HTML, Markdown, URLs or tool instructions. */
|
|
33
|
-
function display(value: ClientJson, maximum: number, json = false): { readonly text: string; readonly truncated: boolean } {
|
|
34
|
-
const raw = typeof value === 'string' && !json ? value : JSON.stringify(value, null, 2);
|
|
35
|
-
// Do not split a UTF-16 surrogate pair at the display boundary.
|
|
36
|
-
const end = raw.length > maximum && /[\uD800-\uDBFF]/.test(raw[maximum - 1]!) ? maximum - 1 : maximum;
|
|
37
|
-
return { text: raw.slice(0, end), truncated: raw.length > maximum };
|
|
38
|
-
}
|
|
39
|
-
function entryContent(entry: RemoteThreadEntry): { readonly name: string; readonly content: ClientJson } {
|
|
40
|
-
switch (entry.kind) {
|
|
41
|
-
case 'user': return { name: 'You', content: entry.content };
|
|
42
|
-
case 'assistant': return { name: 'Assistant', content: entry.output };
|
|
43
|
-
case 'tool_calls': return { name: 'Tool calls', content: entry.calls };
|
|
44
|
-
case 'tool_result': return { name: `Tool result: ${entry.toolId}`, content: entry.result };
|
|
45
|
-
case 'approval': return { name: `Approval: ${entry.toolId}`, content: `${entry.decision}${entry.actorId ? ` by ${entry.actorId}` : ''}` };
|
|
46
|
-
case 'run': return { name: 'Run', content: `${entry.status}${entry.errorCode ? ` (${entry.errorCode})` : ''}` };
|
|
47
|
-
case 'summary': return { name: `Summary of entries ${entry.covers.from}–${entry.covers.to}`, content: entry.content };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function historyEntry(entry: RemoteThreadEntry, maximum: number): ReactElement {
|
|
51
|
-
const content = entryContent(entry); const text = display(content.content, maximum);
|
|
52
|
-
const omitted = 'omitted' in entry && entry.omitted === 'too_large';
|
|
53
|
-
const media = 'mediaOmitted' in entry ? entry.mediaOmitted : undefined;
|
|
54
|
-
return createElement('li', { key: entry.sequence, value: entry.sequence, 'data-kind': entry.kind, 'data-turn-id': entry.turnId },
|
|
55
|
-
createElement('p', null, content.name, ' · ', createElement('time', { dateTime: entry.createdAt }, entry.createdAt)),
|
|
56
|
-
omitted ? createElement('p', { 'data-mayura-omitted': true }, 'Content omitted from the saved history because it was too large')
|
|
57
|
-
: createElement('pre', { 'data-mayura-content': true }, text.text),
|
|
58
|
-
!omitted && text.truncated ? createElement('p', { 'data-mayura-truncated': true }, 'Display truncated; the saved entry contains more content') : null,
|
|
59
|
-
'media' in entry && entry.media?.length ? createElement('ul', { 'aria-label': 'Saved media references' }, ...entry.media.map((reference,index) => createElement('li', { key: `${reference.id}-${index}` }, `${reference.name ?? reference.mediaType} · ${reference.id}`))) : null,
|
|
60
|
-
media ? createElement('p', null, `${media} media item${media === 1 ? '' : 's'} omitted from the saved history`) : null);
|
|
61
|
-
}
|
|
62
|
-
/** One bounded history page. Rendering never fetches, paginates, scrolls, starts a run or disposes a shared store. */
|
|
63
|
-
export function MayuraThreadHistory({ store, label: suppliedLabel, maxContentChars, onLoadEarlier, onLoadLater }: MayuraThreadHistoryProps): ReactElement {
|
|
64
|
-
const state = useMayuraThread(store); const accessibleLabel = label(suppliedLabel, 'Thread history'); const maximum = bound(maxContentChars);
|
|
65
|
-
if ((onLoadEarlier !== undefined && typeof onLoadEarlier !== 'function') || (onLoadLater !== undefined && typeof onLoadLater !== 'function')) return invalid();
|
|
66
|
-
const first = state.entries[0]?.sequence; const last = state.entries.at(-1)?.sequence;
|
|
67
|
-
const locked = !['ready', 'failed'].includes(state.status);
|
|
68
|
-
const page = (direction: 'earlier' | 'later'): void => {
|
|
69
|
-
const current = store.getSnapshot(); if (!['ready', 'failed'].includes(current.status)) return;
|
|
70
|
-
const before = current.entries[0]?.sequence; const after = current.entries.at(-1)?.sequence;
|
|
71
|
-
if (direction === 'earlier' && before !== undefined && before > 1) onLoadEarlier?.(Object.freeze({ before }));
|
|
72
|
-
else if (direction === 'later' && after !== undefined && after < (current.thread?.lastSequence ?? 0)) onLoadLater?.(Object.freeze({ after }));
|
|
73
|
-
};
|
|
74
|
-
// Durable recording markers are bookkeeping between chunks, rather than conversation messages.
|
|
75
|
-
const entries = useMemo(() => state.entries.filter(entry => entry.kind !== 'run' || !entry.recording), [state.entries]);
|
|
76
|
-
const renderedEntries = useMemo(() => entries.map(entry => historyEntry(entry, maximum)), [entries, maximum]);
|
|
77
|
-
const feedback = state.status === 'loading' ? 'Loading conversation history' : state.status === 'deleted' ? 'Conversation deleted'
|
|
78
|
-
: state.status === 'disposed' ? 'History view closed' : state.status === 'idle' ? 'History not loaded' : 'Conversation history';
|
|
79
|
-
return createElement('section', { 'aria-label': accessibleLabel, 'aria-busy': state.status === 'loading', 'data-mayura-component': 'thread-history' },
|
|
80
|
-
createElement('p', { role: 'status', 'aria-live': 'polite', 'data-history-status': state.status }, feedback),
|
|
81
|
-
state.errorCode === null ? null : createElement('p', { role: 'alert' }, entries.length ? 'History could not be refreshed. Showing the last loaded page.' : 'History could not be loaded.'),
|
|
82
|
-
entries.length ? createElement('ol', { 'aria-label': 'Conversation entries', start: entries[0]!.sequence }, renderedEntries)
|
|
83
|
-
: createElement('p', { 'data-mayura-empty': true }, state.status === 'ready' ? 'No conversation entries on this page' : 'No conversation entries displayed'),
|
|
84
|
-
onLoadEarlier !== undefined && first !== undefined && first > 1
|
|
85
|
-
? createElement('button', { type: 'button', 'aria-disabled': locked, onClick: () => page('earlier') }, 'Load earlier entries') : null,
|
|
86
|
-
onLoadLater !== undefined && last !== undefined && last < (state.thread?.lastSequence ?? 0)
|
|
87
|
-
? createElement('button', { type: 'button', 'aria-disabled': locked, onClick: () => page('later') }, 'Load later entries') : null);
|
|
88
|
-
}
|
|
89
|
-
interface ApprovalBodyProps {
|
|
90
|
-
readonly controller: RunApprovalController; readonly state: RunApprovalCommandState; readonly nowMs: number;
|
|
91
|
-
readonly accessibleLabel: string; readonly subject: string | undefined; readonly maximum: number;
|
|
92
|
-
}
|
|
93
|
-
/** Keyed to the captured approval, so a new request gets a fresh reason field and local validation state. */
|
|
94
|
-
function ApprovalBody({ controller, state, nowMs, accessibleLabel, subject, maximum }: ApprovalBodyProps): ReactElement {
|
|
95
|
-
const reasonId = useId(); const inputId = useId(); const errorId = useId(); const reason = useRef<HTMLTextAreaElement | null>(null);
|
|
96
|
-
const [invalidReason, setInvalidReason] = useState(false); const approval = state.approval;
|
|
97
|
-
const input = useMemo(() => display(approval.input, maximum, true), [approval.input, maximum]); const expired = nowMs >= approval.expiresAtMs;
|
|
98
|
-
// A failed transport can have applied a decision. Require a fresh inspection instead of presenting a retry button.
|
|
99
|
-
const locked = state.status !== 'idle' || expired;
|
|
100
|
-
const decide = useCallback((decision: 'approved' | 'rejected') => {
|
|
101
|
-
const current = controller.getSnapshot();
|
|
102
|
-
// Recheck synchronously: two click events may arrive before React has painted submitting feedback.
|
|
103
|
-
if (current.status !== 'idle' || current.approval.digest !== approval.digest || current.approval.callId !== approval.callId
|
|
104
|
-
|| nowMs >= current.approval.expiresAtMs || (decision === 'approved' && input.truncated)) return;
|
|
105
|
-
const value = reason.current?.value ?? ''; if (value.length > 1_000) { setInvalidReason(true); return; }
|
|
106
|
-
setInvalidReason(false);
|
|
107
|
-
// The controller publishes errors and accepted decisions; rendering never owns or retries the command.
|
|
108
|
-
void controller.submit(decision, value.length ? { reason: value } : undefined).catch(() => {});
|
|
109
|
-
}, [controller, approval.callId, approval.digest, nowMs, input.truncated]);
|
|
110
|
-
const feedback = state.status === 'submitting' ? 'Submitting decision' : state.status === 'succeeded' ? 'Decision submitted'
|
|
111
|
-
: state.status === 'conflict' ? 'Approval changed or expired; refresh the run before deciding'
|
|
112
|
-
: state.status === 'failed' ? 'Decision outcome unknown; refresh the run before deciding'
|
|
113
|
-
: state.status === 'disposed' ? 'Approval controller closed' : expired ? 'Approval expired; refresh the run' : 'Awaiting your decision';
|
|
114
|
-
const context = subject ?? `${approval.toolId}, call ${approval.callId}`;
|
|
115
|
-
return createElement('section', { 'aria-label': accessibleLabel, 'aria-busy': state.status === 'submitting', 'data-mayura-component': 'run-approval-control' },
|
|
116
|
-
createElement('p', null, `Review ${approval.toolId} (version ${approval.toolVersion})`),
|
|
117
|
-
createElement('p', null, `Call ${approval.callId}`),
|
|
118
|
-
createElement('p', null, 'Expires ', createElement('time', { dateTime: new Date(approval.expiresAtMs).toISOString() }, new Date(approval.expiresAtMs).toISOString())),
|
|
119
|
-
createElement('pre', { id: inputId, 'data-mayura-approval-input': true }, input.text),
|
|
120
|
-
input.truncated ? createElement('p', { 'data-mayura-truncated': true }, 'Input truncated. Review the full input outside this view before approving. You can still reject this request.') : null,
|
|
121
|
-
createElement('label', { htmlFor: reasonId }, 'Reason (optional)'),
|
|
122
|
-
createElement('textarea', { key: 'reason', ref: reason, id: reasonId, maxLength: 1_000, disabled: locked,
|
|
123
|
-
'aria-invalid': invalidReason, 'aria-describedby': invalidReason ? errorId : undefined, onInput: () => setInvalidReason(false) }),
|
|
124
|
-
invalidReason ? createElement('p', { id: errorId, role: 'alert' }, 'Reason must be at most 1,000 characters') : null,
|
|
125
|
-
createElement('p', { role: 'status', 'aria-live': 'polite', 'data-command-status': state.status }, feedback),
|
|
126
|
-
createElement('button', { type: 'button', 'aria-label': `Approve for ${context}`, 'aria-disabled': locked || input.truncated,
|
|
127
|
-
'aria-describedby': inputId, onClick: () => decide('approved') }, 'Approve'),
|
|
128
|
-
createElement('button', { type: 'button', 'aria-label': `Reject for ${context}`, 'aria-disabled': locked,
|
|
129
|
-
'aria-describedby': inputId, onClick: () => decide('rejected') }, 'Reject'));
|
|
130
|
-
}
|
|
131
|
-
/** Review and decide one captured approval. Buttons keep focus while busy; neither mounting nor expiry starts work. */
|
|
132
|
-
export function MayuraRunApprovalControl({ controller, nowMs, label: suppliedLabel, subject, maxInputChars }: MayuraRunApprovalControlProps): ReactElement {
|
|
133
|
-
const state = useMayuraRunApprovalCommand(controller); const accessibleLabel = label(suppliedLabel, 'Run approval');
|
|
134
|
-
if (!Number.isSafeInteger(nowMs) || nowMs < 0 || !Number.isFinite(new Date(state.approval.expiresAtMs).getTime())) return invalid();
|
|
135
|
-
const subjectText = subject === undefined ? undefined : label(subject, 'run');
|
|
136
|
-
return createElement(ApprovalBody, { key: `${state.approval.callId}:${state.approval.digest}`, controller, state, nowMs,
|
|
137
|
-
accessibleLabel, subject: subjectText, maximum: bound(maxInputChars) });
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
import './ui.css';
|
|
141
|
-
/** Source-owned rendering and hook subscriptions; no mount-time network work. */
|
|
142
|
-
export function ThreadHistory(props: MayuraThreadHistoryProps) { return createElement('section',{ className:'mayura-ui' },createElement(MayuraThreadHistory,props)); }
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useMayuraThreads } from 'mayura/client-react';
|
|
2
|
-
import type { HeadlessThreadsStore } from 'mayura/client/headless';
|
|
3
|
-
import './ui.css';
|
|
4
|
-
/** Select only listed scoped threads; pagination/loading belongs to the host. */
|
|
5
|
-
export function ThreadList({ store, onSelect }: { readonly store: HeadlessThreadsStore; readonly onSelect: (id: string) => void }) {
|
|
6
|
-
const state = useMayuraThreads(store);
|
|
7
|
-
return <nav className="mayura-ui" aria-label="Conversations"><h2>Your conversations</h2><ul>{(state.page?.threads ?? []).map(thread => <li key={thread.id}><button type="button" onClick={() => onSelect(thread.id)}>{thread.title || 'Untitled conversation'}</button></li>)}</ul>
|
|
8
|
-
{(state.page?.threads.length ?? 0) === 0 ? <p>Create a conversation to get started.</p> : null}</nav>;
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
.mayura-ui { --ui-paper: #faf8f1; --ui-ink: #253329; --ui-muted: #526357; --ui-line: #c7cfc1; --ui-accent: #28583b; color: var(--ui-ink); background: var(--ui-paper); font: 1rem/1.6 Georgia, serif; padding: clamp(1rem,3vw,2rem); overflow-wrap: anywhere; }
|
|
2
|
-
.mayura-ui :where(h2,h3,p) { margin: 0 0 .75rem; }
|
|
3
|
-
.mayura-ui :where(button,textarea,input) { font: inherit; color: inherit; }
|
|
4
|
-
.mayura-ui button { border: 1px solid var(--ui-line); padding: .5rem .9rem; background: transparent; cursor: pointer; }
|
|
5
|
-
.mayura-ui button:disabled { opacity: .55; cursor: default; }
|
|
6
|
-
.mayura-ui :focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 4px; }
|
|
7
|
-
.mayura-ui textarea { width: 100%; min-height: 6rem; box-sizing: border-box; background: transparent; border: 1px solid var(--ui-line); padding: .7rem; resize: vertical; }
|
|
8
|
-
.mayura-ui pre { white-space: pre-wrap; max-height: 20rem; overflow: auto; }
|
|
9
|
-
.mayura-ui [role=log] { max-height: 32rem; overflow: auto; }
|
|
10
|
-
.mayura-ui a { color: var(--ui-accent); text-decoration-thickness: .1em; text-underline-offset: .2em; }
|
|
11
|
-
.mayura-ui small { color: var(--ui-muted); }
|
|
12
|
-
.mayura-ui .ui-row { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
|
|
13
|
-
.mayura-ui li { margin-block: .6rem; }
|
|
14
|
-
.mayura-ui [role=alert] { border-block: 1px solid var(--ui-line); padding-block: .5rem; }
|
|
@@ -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%; } }
|