@ricajs/rica 0.0.0-stage → 0.1.0
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/LICENSE +661 -0
- package/README.md +153 -2
- package/admin/assets/CharacterWorkspace-1DS1hQyt.css +1 -0
- package/admin/assets/CharacterWorkspace-wPK725zl.js +2 -0
- package/admin/assets/ConsoleHome-BWG64JGc.js +1 -0
- package/admin/assets/ConsoleHome-Du2ctyD4.css +1 -0
- package/admin/assets/CreateAccount-VB0Hg0Oo.js +1 -0
- package/admin/assets/CreateAccount-YfoCfhgR.css +1 -0
- package/admin/assets/GrowthWorkspace-C10PHKpZ.css +1 -0
- package/admin/assets/GrowthWorkspace-Kds9pNFQ.js +1 -0
- package/admin/assets/KnowledgeWorkspace-BMA6nsqJ.js +1 -0
- package/admin/assets/KnowledgeWorkspace-DhWn2l8R.css +1 -0
- package/admin/assets/MembershipWorkspace-o0Vnc47u.js +1 -0
- package/admin/assets/MetricsWorkspace-B7hX9jVB.js +1 -0
- package/admin/assets/MetricsWorkspace-__TjvlTz.css +1 -0
- package/admin/assets/PlanningWorkspace-C5fInwML.css +1 -0
- package/admin/assets/PlanningWorkspace-Dg1mJGKs.js +1 -0
- package/admin/assets/PluginWorkspace-9j4kXV6x.js +1 -0
- package/admin/assets/PluginWorkspace-OgCPHMeV.css +1 -0
- package/admin/assets/SecuritySettings-C4GyRpMq.js +1 -0
- package/admin/assets/SecuritySettings-DBa2VRXZ.css +1 -0
- package/admin/assets/SystemHealth-KyjDkMwy.css +1 -0
- package/admin/assets/SystemHealth-rJD8Lfj2.js +1 -0
- package/admin/assets/TimeZoneSelect-DjKgHHLQ.js +1 -0
- package/admin/assets/UiBadge-BfJoDO3X.js +1 -0
- package/admin/assets/UiCombobox-CoLq4WY2.js +1 -0
- package/admin/assets/UiDialog-BJTTfzWz.js +3 -0
- package/admin/assets/UiField-B8YKSMrG.js +2 -0
- package/admin/assets/UiSpinner-CsMdV4kc.js +1 -0
- package/admin/assets/console-Bj81RrGj.css +1 -0
- package/admin/assets/console-Da8k64eY.js +1 -0
- package/admin/assets/console-data-BuMSzMgF.js +1 -0
- package/admin/assets/dist-BjB-W5oC.js +57 -0
- package/admin/assets/index-CkMVftFK.js +4 -0
- package/admin/assets/index-DeJZoKJC.css +1 -0
- package/admin/assets/management-Ci5Yl-iD.js +1 -0
- package/admin/assets/plugin-integrations-C9DuWlXS.css +1 -0
- package/admin/assets/plugin-integrations-VFsmCvor.js +1 -0
- package/admin/assets/plugin-status-DvTwmog1.js +1 -0
- package/admin/index.html +25 -0
- package/apps/api/admin-auth-routes.d.ts +8 -0
- package/apps/api/admin-auth-routes.js +280 -0
- package/apps/api/admin-auth.d.ts +41 -0
- package/apps/api/admin-auth.js +74 -0
- package/apps/api/app.d.ts +7 -0
- package/apps/api/app.js +20 -0
- package/apps/api/main.d.ts +1 -0
- package/apps/api/main.js +107 -0
- package/apps/api/management.d.ts +25 -0
- package/apps/api/management.js +952 -0
- package/apps/auto-review.js +17 -0
- package/apps/deployment-plugin-contracts.js +24 -0
- package/apps/deployment-plugins.js +84 -0
- package/apps/plugin-observation.js +83 -0
- package/apps/plugin-releases.js +55 -0
- package/apps/plugin-status-view.js +14 -0
- package/apps/runtime-plugins.js +85 -0
- package/apps/worker/main.d.ts +1 -0
- package/apps/worker/main.js +84 -0
- package/apps/worker/outbox.d.ts +13 -0
- package/apps/worker/outbox.js +201 -0
- package/apps/worker/retention.d.ts +1 -0
- package/apps/worker/retention.js +16 -0
- package/apps/worker/runtime-retention.d.ts +2 -0
- package/apps/worker/runtime-retention.js +5 -0
- package/apps/worker/simulation.d.ts +1 -0
- package/apps/worker/simulation.js +51 -0
- package/bin/rica.js +33 -0
- package/compose.yaml +27 -0
- package/env.example +15 -0
- package/package.json +43 -3
- package/prisma/migrations/20261109000000_init/migration.sql +6544 -0
- package/prisma/migrations/20261109010000_console_simulation/migration.sql +62 -0
- package/prisma/migrations/20261109020000_run_audit/migration.sql +15 -0
- package/prisma/migrations/20261109030000_connector_queue/migration.sql +6 -0
- package/prisma/migrations/20261109040000_console_run_filters/migration.sql +30 -0
- package/prisma/migrations/20261109050000_console_run_timeline/migration.sql +34 -0
- package/prisma/migrations/20261109060000_connector_read_status/migration.sql +58 -0
- package/prisma/migrations/20261109070000_console_knowledge/migration.sql +7 -0
- package/prisma/migrations/20261109080000_platform_account_pool/migration.sql +22 -0
- package/prisma/migrations/20261109090000_identity_writing_prompt/migration.sql +28 -0
- package/prisma/migrations/20261111000000_collaborative_plans/migration.sql +77 -0
- package/prisma/migrations/20261111010000_commitment_details/migration.sql +49 -0
- package/prisma/migrations/20261111020000_simulation_follow_up/migration.sql +91 -0
- package/prisma/migrations/20261111030000_collaborative_ai_follow_up/migration.sql +146 -0
- package/prisma/migrations/20261111040000_console_simulation_transcript/migration.sql +105 -0
- package/prisma/migrations/20261114000000_newbi_runtime_connection/migration.sql +2 -0
- package/prisma/migrations/20261114010000_shared_runtime_database/migration.sql +2 -0
- package/prisma/migrations/20261114020000_newbi_account_credentials/migration.sql +32 -0
- package/prisma/migrations/20261114030000_remove_unlinked_accounts/migration.sql +1 -0
- package/prisma/migrations/20261114040000_newbi_account_profiles/migration.sql +1 -0
- package/prisma/migrations/20261115000000_local_user_management/migration.sql +55 -0
- package/prisma/migrations/20261115010000_administrator_only_membership/migration.sql +15 -0
- package/prisma/migrations/20261115020000_manage_own_passkeys/migration.sql +32 -0
- package/prisma/migrations/20261115030000_change_own_password/migration.sql +30 -0
- package/prisma/migrations/20261115040000_system_administrators/migration.sql +55 -0
- package/prisma/migrations/20261117000000_identity_draft_model_profile/migration.sql +30 -0
- package/prisma/migrations/20261118000000_auto_review/migration.sql +9 -0
- package/prisma/migrations/20261118010000_internal_core_prompt/migration.sql +62 -0
- package/prisma/migrations/20261118020000_hosted_model_usage/migration.sql +42 -0
- package/prisma/migrations/migration_lock.toml +1 -0
- package/prisma/schema.prisma +1019 -0
- package/prisma.config.js +7 -0
- package/scripts/admin-user.js +51 -0
- package/scripts/plugin-release-manifest.js +17 -0
- package/source/.env.example +15 -0
- package/source/LICENSE +661 -0
- package/source/README.en.md +123 -0
- package/source/README.md +154 -0
- package/source/apps/admin/index.html +12 -0
- package/source/apps/admin/src/app/App.vue +197 -0
- package/source/apps/admin/src/app/ConsoleNavigation.vue +56 -0
- package/source/apps/admin/src/app/ReviewDesk.vue +825 -0
- package/source/apps/admin/src/app/appearance.ts +38 -0
- package/source/apps/admin/src/app/console-location.ts +50 -0
- package/source/apps/admin/src/app/plugin-integrations.ts +73 -0
- package/source/apps/admin/src/features/access/AuditWorkspace.vue +139 -0
- package/source/apps/admin/src/features/access/CreateAccount.vue +64 -0
- package/source/apps/admin/src/features/access/MembershipWorkspace.vue +54 -0
- package/source/apps/admin/src/features/access/SecuritySettings.vue +219 -0
- package/source/apps/admin/src/features/characters/CharacterWorkspace.vue +736 -0
- package/source/apps/admin/src/features/health/SystemHealth.vue +162 -0
- package/source/apps/admin/src/features/home/ConsoleHome.vue +220 -0
- package/source/apps/admin/src/features/knowledge/GrowthWorkspace.vue +57 -0
- package/source/apps/admin/src/features/knowledge/IdentityGrowth.vue +276 -0
- package/source/apps/admin/src/features/knowledge/KnowledgeWorkspace.vue +294 -0
- package/source/apps/admin/src/features/knowledge/MemoryGrantWorkspace.vue +199 -0
- package/source/apps/admin/src/features/planning/CollaborativePlans.vue +240 -0
- package/source/apps/admin/src/features/planning/CommitmentWorkspace.vue +327 -0
- package/source/apps/admin/src/features/planning/PlanningWorkspace.vue +155 -0
- package/source/apps/admin/src/features/plugins/PluginWorkspace.vue +268 -0
- package/source/apps/admin/src/features/plugins/plugin-status.ts +32 -0
- package/source/apps/admin/src/features/review/AutoReviewSettings.vue +152 -0
- package/source/apps/admin/src/features/runs/MetricsWorkspace.vue +128 -0
- package/source/apps/admin/src/features/runs/RunOperations.vue +224 -0
- package/source/apps/admin/src/features/runs/SimulationReconciliation.vue +111 -0
- package/source/apps/admin/src/features/runs/SimulationWorkspace.vue +476 -0
- package/source/apps/admin/src/features/runs/simulation-accounts.ts +13 -0
- package/source/apps/admin/src/main.ts +5 -0
- package/source/apps/admin/src/shared/TimeZoneSelect.vue +25 -0
- package/source/apps/admin/src/styles/console-layout.css +53 -0
- package/source/apps/admin/src/styles/console-theme.css +95 -0
- package/source/apps/admin/src/vite-env.d.ts +3 -0
- package/source/apps/admin/uno.config.ts +8 -0
- package/source/apps/admin/vite.config.ts +33 -0
- package/source/apps/api/admin-auth-routes.ts +269 -0
- package/source/apps/api/admin-auth.test.ts +22 -0
- package/source/apps/api/admin-auth.ts +88 -0
- package/source/apps/api/app.test.ts +21 -0
- package/source/apps/api/app.ts +27 -0
- package/source/apps/api/main.ts +105 -0
- package/source/apps/api/management-plugins.test.ts +67 -0
- package/source/apps/api/management.ts +1055 -0
- package/source/apps/api/plugin-releases.test.ts +21 -0
- package/source/apps/auto-review.ts +18 -0
- package/source/apps/deployment-plugin-contracts.ts +29 -0
- package/source/apps/deployment-plugins.ts +87 -0
- package/source/apps/plugin-observation.ts +88 -0
- package/source/apps/plugin-releases.ts +52 -0
- package/source/apps/plugin-status-view.ts +15 -0
- package/source/apps/runtime-plugins.ts +105 -0
- package/source/apps/worker/main.ts +84 -0
- package/source/apps/worker/outbox.ts +201 -0
- package/source/apps/worker/retention.ts +16 -0
- package/source/apps/worker/runtime-retention.ts +7 -0
- package/source/apps/worker/simulation.ts +50 -0
- package/source/bin/rica.js +33 -0
- package/source/compose.yaml +27 -0
- package/source/package.json +77 -0
- package/source/packages/console-shared/console-data.ts +83 -0
- package/source/packages/console-shared/health.ts +2 -0
- package/source/packages/console-shared/package.json +34 -0
- package/source/packages/console-shared/request.ts +13 -0
- package/source/packages/console-shared/ui/UiAlert.vue +10 -0
- package/source/packages/console-shared/ui/UiBadge.vue +7 -0
- package/source/packages/console-shared/ui/UiButton.vue +19 -0
- package/source/packages/console-shared/ui/UiCheckbox.vue +8 -0
- package/source/packages/console-shared/ui/UiCombobox.vue +55 -0
- package/source/packages/console-shared/ui/UiDialog.vue +42 -0
- package/source/packages/console-shared/ui/UiEmpty.vue +7 -0
- package/source/packages/console-shared/ui/UiField.vue +11 -0
- package/source/packages/console-shared/ui/UiSpinner.vue +3 -0
- package/source/packages/console-shared/ui/index.ts +9 -0
- package/source/packages/console-shared/ui/ui.css +113 -0
- package/source/packages/contracts/action-review.ts +45 -0
- package/source/packages/contracts/auto-review.ts +22 -0
- package/source/packages/contracts/commitments.ts +39 -0
- package/source/packages/contracts/deployment-plugins.ts +4 -0
- package/source/packages/contracts/health.ts +4 -0
- package/source/packages/contracts/local-users.ts +8 -0
- package/source/packages/contracts/management.ts +246 -0
- package/source/packages/contracts/memory.ts +15 -0
- package/source/packages/contracts/model-provider.ts +29 -0
- package/source/packages/contracts/package.json +43 -0
- package/source/packages/contracts/plans.ts +22 -0
- package/source/packages/contracts/platform-reader.ts +27 -0
- package/source/packages/contracts/platform-reply-executor.ts +10 -0
- package/source/packages/contracts/plugin-status.ts +67 -0
- package/source/packages/contracts/run-continuity.ts +60 -0
- package/source/packages/contracts/schedules.ts +22 -0
- package/source/packages/contracts/simulation-follow-up.ts +35 -0
- package/source/packages/contracts/simulation-observability.ts +94 -0
- package/source/packages/contracts/simulation-platform.ts +39 -0
- package/source/packages/persistence/action-review.ts +188 -0
- package/source/packages/persistence/auto-review.ts +21 -0
- package/source/packages/persistence/client.ts +17 -0
- package/source/packages/persistence/console-knowledge.ts +78 -0
- package/source/packages/persistence/identity-reflection.ts +13 -0
- package/source/packages/persistence/inbound.ts +118 -0
- package/source/packages/persistence/management-http.ts +54 -0
- package/source/packages/persistence/management.ts +899 -0
- package/source/packages/persistence/memory-snapshot.ts +111 -0
- package/source/packages/persistence/memory.ts +161 -0
- package/source/packages/persistence/package.json +50 -0
- package/source/packages/persistence/plans.ts +132 -0
- package/source/packages/persistence/run-context.ts +113 -0
- package/source/packages/persistence/run-continuity.ts +30 -0
- package/source/packages/persistence/simulated-draft.ts +313 -0
- package/source/packages/persistence/simulation-execution.ts +203 -0
- package/source/packages/persistence/simulation-observability.ts +119 -0
- package/source/packages/persistence/simulation-reconciliation.ts +35 -0
- package/source/packages/persistence/simulation-retention.ts +8 -0
- package/source/packages/persistence/simulation-schedules.ts +87 -0
- package/source/packages/plugin-host/package.json +20 -0
- package/source/packages/plugin-host/plugin-registry.ts +107 -0
- package/source/packages/runtime/config.ts +23 -0
- package/source/packages/runtime/memory-ranking.test.ts +45 -0
- package/source/packages/runtime/memory-ranking.ts +92 -0
- package/source/packages/runtime/package.json +30 -0
- package/source/packages/runtime/plugin-registry.test.ts +75 -0
- package/source/packages/runtime/settings-directory.ts +10 -0
- package/source/packages/runtime/write-settings.ts +20 -0
- package/source/packages/runtime/writing-prompts.ts +8 -0
- package/source/plugins/hosted-models/README.md +52 -0
- package/source/plugins/hosted-models/index.ts +3 -0
- package/source/plugins/hosted-models/package.json +44 -0
- package/source/plugins/hosted-models/providers/catalog.ts +9 -0
- package/source/plugins/hosted-models/providers/client.ts +142 -0
- package/source/plugins/hosted-models/providers/config.ts +40 -0
- package/source/plugins/hosted-models/providers/usage.ts +49 -0
- package/source/plugins/hosted-models/rica/console/ModelSettings.vue +299 -0
- package/source/plugins/hosted-models/rica/console/ModelUsage.vue +243 -0
- package/source/plugins/hosted-models/rica/console/cards.ts +22 -0
- package/source/plugins/hosted-models/rica/console/health.ts +38 -0
- package/source/plugins/hosted-models/rica/console/index.ts +3 -0
- package/source/plugins/hosted-models/rica/console/labels.ts +11 -0
- package/source/plugins/hosted-models/rica/identity.ts +1 -0
- package/source/plugins/hosted-models/rica/management/check.ts +42 -0
- package/source/plugins/hosted-models/rica/management/contracts.ts +54 -0
- package/source/plugins/hosted-models/rica/management/routes.ts +150 -0
- package/source/plugins/hosted-models/rica/management/settings.ts +116 -0
- package/source/plugins/hosted-models/rica/management/usage-contracts.ts +20 -0
- package/source/plugins/hosted-models/rica/model.ts +90 -0
- package/source/plugins/hosted-models/rica/persistence/usage.ts +37 -0
- package/source/plugins/hosted-models/rica/shared.ts +3 -0
- package/source/plugins/hosted-models/tests/model-settings.test.ts +226 -0
- package/source/plugins/hosted-models/tests/providers.test.ts +129 -0
- package/source/plugins/newbi/README.md +63 -0
- package/source/plugins/newbi/agent-api/client.ts +192 -0
- package/source/plugins/newbi/agent-api/connection.ts +15 -0
- package/source/plugins/newbi/index.ts +4 -0
- package/source/plugins/newbi/package.json +42 -0
- package/source/plugins/newbi/rica/console/AccountConnectionForm.vue +25 -0
- package/source/plugins/newbi/rica/console/ConnectorAccountStatus.vue +186 -0
- package/source/plugins/newbi/rica/console/ConnectorReview.vue +393 -0
- package/source/plugins/newbi/rica/console/NewbiAccountLabel.vue +21 -0
- package/source/plugins/newbi/rica/console/NewbiSettings.vue +29 -0
- package/source/plugins/newbi/rica/console/account-integration.ts +104 -0
- package/source/plugins/newbi/rica/console/accounts.ts +13 -0
- package/source/plugins/newbi/rica/console/card.ts +38 -0
- package/source/plugins/newbi/rica/console/health.ts +27 -0
- package/source/plugins/newbi/rica/console/index.ts +5 -0
- package/source/plugins/newbi/rica/console/labels.ts +16 -0
- package/source/plugins/newbi/rica/console/review.ts +27 -0
- package/source/plugins/newbi/rica/deployment/catalog.ts +13 -0
- package/source/plugins/newbi/rica/deployment/settings.ts +57 -0
- package/source/plugins/newbi/rica/integration.md +39 -0
- package/source/plugins/newbi/rica/management/api.md +156 -0
- package/source/plugins/newbi/rica/management/contracts.ts +95 -0
- package/source/plugins/newbi/rica/management/operations.ts +38 -0
- package/source/plugins/newbi/rica/management/routes.ts +286 -0
- package/source/plugins/newbi/rica/persistence/accounts.ts +40 -0
- package/source/plugins/newbi/rica/persistence/database.ts +49 -0
- package/source/plugins/newbi/rica/persistence/events.ts +59 -0
- package/source/plugins/newbi/rica/persistence/execution.ts +73 -0
- package/source/plugins/newbi/rica/persistence/management.ts +256 -0
- package/source/plugins/newbi/rica/persistence/retention.ts +3 -0
- package/source/plugins/newbi/rica/runtime/agent-adapter.ts +34 -0
- package/source/plugins/newbi/rica/runtime/executor.ts +30 -0
- package/source/plugins/newbi/rica/runtime/identity.ts +11 -0
- package/source/plugins/newbi/rica/runtime/reader.ts +48 -0
- package/source/plugins/newbi/rica/shared.ts +6 -0
- package/source/plugins/newbi/tests/management.integration.test.ts +938 -0
- package/source/plugins/newbi/tests/settings.test.ts +112 -0
- package/source/plugins/simulated-model/index.ts +38 -0
- package/source/plugins/simulated-model/package.json +24 -0
- package/source/plugins/simulated-platforms/index.ts +70 -0
- package/source/plugins/simulated-platforms/package.json +24 -0
- package/source/pnpm-lock.yaml +4386 -0
- package/source/pnpm-workspace.yaml +9 -0
- package/source/prisma/migrations/20261109000000_init/migration.sql +6544 -0
- package/source/prisma/migrations/20261109010000_console_simulation/migration.sql +62 -0
- package/source/prisma/migrations/20261109020000_run_audit/migration.sql +15 -0
- package/source/prisma/migrations/20261109030000_connector_queue/migration.sql +6 -0
- package/source/prisma/migrations/20261109040000_console_run_filters/migration.sql +30 -0
- package/source/prisma/migrations/20261109050000_console_run_timeline/migration.sql +34 -0
- package/source/prisma/migrations/20261109060000_connector_read_status/migration.sql +58 -0
- package/source/prisma/migrations/20261109070000_console_knowledge/migration.sql +7 -0
- package/source/prisma/migrations/20261109080000_platform_account_pool/migration.sql +22 -0
- package/source/prisma/migrations/20261109090000_identity_writing_prompt/migration.sql +28 -0
- package/source/prisma/migrations/20261111000000_collaborative_plans/migration.sql +77 -0
- package/source/prisma/migrations/20261111010000_commitment_details/migration.sql +49 -0
- package/source/prisma/migrations/20261111020000_simulation_follow_up/migration.sql +91 -0
- package/source/prisma/migrations/20261111030000_collaborative_ai_follow_up/migration.sql +146 -0
- package/source/prisma/migrations/20261111040000_console_simulation_transcript/migration.sql +105 -0
- package/source/prisma/migrations/20261114000000_newbi_runtime_connection/migration.sql +2 -0
- package/source/prisma/migrations/20261114010000_shared_runtime_database/migration.sql +2 -0
- package/source/prisma/migrations/20261114020000_newbi_account_credentials/migration.sql +32 -0
- package/source/prisma/migrations/20261114030000_remove_unlinked_accounts/migration.sql +1 -0
- package/source/prisma/migrations/20261114040000_newbi_account_profiles/migration.sql +1 -0
- package/source/prisma/migrations/20261115000000_local_user_management/migration.sql +55 -0
- package/source/prisma/migrations/20261115010000_administrator_only_membership/migration.sql +15 -0
- package/source/prisma/migrations/20261115020000_manage_own_passkeys/migration.sql +32 -0
- package/source/prisma/migrations/20261115030000_change_own_password/migration.sql +30 -0
- package/source/prisma/migrations/20261115040000_system_administrators/migration.sql +55 -0
- package/source/prisma/migrations/20261117000000_identity_draft_model_profile/migration.sql +30 -0
- package/source/prisma/migrations/20261118000000_auto_review/migration.sql +9 -0
- package/source/prisma/migrations/20261118010000_internal_core_prompt/migration.sql +62 -0
- package/source/prisma/migrations/20261118020000_hosted_model_usage/migration.sql +42 -0
- package/source/prisma/migrations/migration_lock.toml +1 -0
- package/source/prisma/schema.prisma +1019 -0
- package/source/prisma.config.ts +8 -0
- package/source/scripts/admin-user.ts +47 -0
- package/source/scripts/inbound.integration.test.ts +1515 -0
- package/source/scripts/management.integration.test.ts +3516 -0
- package/source/scripts/outbox-smoke.ts +122 -0
- package/source/scripts/pack-release.mjs +88 -0
- package/source/scripts/plugin-release-manifest.ts +20 -0
- package/source/tsconfig.json +23 -0
- package/source/tsconfig.server.json +12 -0
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi';
|
|
3
|
+
import { bodyLimit } from 'hono/body-limit';
|
|
4
|
+
import { HTTPException } from 'hono/http-exception';
|
|
5
|
+
import { commitmentInput, commitmentQuery, commitmentReceiptQuery, commitmentReceiptView, commitmentUpdate, commitmentView } from '@ricajs/contracts/commitments';
|
|
6
|
+
import { scheduleInput, scheduleUpdate, scheduleView } from '@ricajs/contracts/schedules';
|
|
7
|
+
import { planInput, planStateInput, planView } from '@ricajs/contracts/plans';
|
|
8
|
+
import { listPlans, savePlan, setPlanEnabled } from '@ricajs/persistence/plans';
|
|
9
|
+
import { consoleSimulationInput, simulationRunQuery, simulationRunSummary, dailyMetricsQuery, outboxQuarantineQuery, outboxQuarantineView, runReplayView, simulationBacklogView, simulationDailyMetricsView } from '@ricajs/contracts/simulation-observability';
|
|
10
|
+
import { listSimulationRuns, startConsoleSimulation, readQuarantinedOutbox, readSimulationBacklog, readSimulationDailyMetrics, replaySimulationRun, retryQuarantinedOutbox } from '@ricajs/persistence/simulation-observability';
|
|
11
|
+
import { listConversationOptions, listIdentityBeliefs, listIdentityContacts, listMembers } from '@ricajs/persistence/console-knowledge';
|
|
12
|
+
import * as schema from '@ricajs/contracts/management';
|
|
13
|
+
import { actionDecision, actionView, reconciliationInput, reconciliationView } from '@ricajs/contracts/action-review';
|
|
14
|
+
import { decideReviewAction, listReviewActions } from '@ricajs/persistence/action-review';
|
|
15
|
+
import { autoReviewInput, autoReviewView } from '@ricajs/contracts/auto-review';
|
|
16
|
+
import { readAutoReviewSettings } from '@ricajs/persistence/auto-review';
|
|
17
|
+
import * as management from '@ricajs/persistence/management';
|
|
18
|
+
import { readSimulationReconciliation, resolveSimulationReconciliation } from '@ricajs/persistence/simulation-reconciliation';
|
|
19
|
+
import { pluginStatusView } from '@ricajs/contracts/plugin-status';
|
|
20
|
+
import { readPluginStatus } from '../plugin-observation.js';
|
|
21
|
+
import { localIssuer } from './admin-auth.js';
|
|
22
|
+
import { deploymentChangeOwner, deploymentPluginChange, deploymentPluginsView } from '../deployment-plugin-contracts.js';
|
|
23
|
+
import { DeploymentPluginError } from '../deployment-plugins.js';
|
|
24
|
+
import { body, character, characterParams, error, errors, extensionFields, failure, security, success, version } from '@ricajs/persistence/management-http';
|
|
25
|
+
const identityParams = characterParams.extend({ identityId: schema.resourceId });
|
|
26
|
+
const grantParams = characterParams.extend({ grantId: schema.resourceId });
|
|
27
|
+
const actionParams = characterParams.extend({ actionId: schema.resourceId });
|
|
28
|
+
function runVersion(header) {
|
|
29
|
+
const value = Number(/^"run-v([1-9][0-9]{0,9})"$/.exec(header)?.[1]);
|
|
30
|
+
if (!Number.isInteger(value) || value >= 2_147_483_647) {
|
|
31
|
+
throw new management.ManagementError(422, 'INVALID_VERSION', 'Expected a quoted run version');
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
export function createManagementApp({ db, authenticate, origin, cookie, resolveAdapter, pluginStatus = readPluginStatus, pluginRelease, activeModel = async () => 'simulated', reviewModel = async () => null, modelProfileExists = async () => false, deploymentPlugins, plugins = [] }) {
|
|
36
|
+
async function validateDraftModel(profile, retained) {
|
|
37
|
+
if (profile && profile !== 'simulated' && !await modelProfileExists(profile) && !await retained?.()) {
|
|
38
|
+
throw new management.ManagementError(422, 'MODEL_NOT_CONFIGURED', 'Draft model profile is unavailable');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const app = new OpenAPIHono({
|
|
42
|
+
defaultHook: (result, c) => {
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
const requestId = c.get('requestId');
|
|
45
|
+
if (result.target === 'header' && (c.req.method === 'PUT' || c.req.method === 'DELETE' || /\/(decisions|reconciliation)$/.test(c.req.path))
|
|
46
|
+
&& c.req.header('If-Match') === undefined) {
|
|
47
|
+
return c.json(error(requestId, 'VERSION_REQUIRED', 'If-Match is required'), 428);
|
|
48
|
+
}
|
|
49
|
+
return c.json(error(requestId, 'INVALID_INPUT', 'Request fields are invalid'), 422);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
app.openAPIRegistry.registerComponent('securitySchemes', 'SessionCookie', { type: 'apiKey', in: 'cookie', name: cookie });
|
|
54
|
+
app.use('*', async (c, next) => {
|
|
55
|
+
const requestId = randomUUID();
|
|
56
|
+
c.set('requestId', requestId);
|
|
57
|
+
c.header('X-Request-Id', requestId);
|
|
58
|
+
c.header('Cache-Control', 'no-store');
|
|
59
|
+
if (c.req.method !== 'GET' && c.req.method !== 'HEAD' && c.req.header('Origin') !== origin) {
|
|
60
|
+
return c.json(error(requestId, 'ORIGIN_FORBIDDEN', 'Request origin is invalid'), 403);
|
|
61
|
+
}
|
|
62
|
+
let actor;
|
|
63
|
+
try {
|
|
64
|
+
actor = await authenticate(c.req.raw);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return c.json(error(requestId, 'AUTH_UNAVAILABLE', 'Authentication is temporarily unavailable'), 503);
|
|
68
|
+
}
|
|
69
|
+
if (!actor)
|
|
70
|
+
return c.json(error(requestId, 'UNAUTHENTICATED', 'Authentication required'), 401);
|
|
71
|
+
c.set('actor', actor);
|
|
72
|
+
await next();
|
|
73
|
+
});
|
|
74
|
+
app.use('*', bodyLimit({
|
|
75
|
+
maxSize: 32_768,
|
|
76
|
+
onError: (c) => c.json(error(c.get('requestId'), 'BODY_TOO_LARGE', 'Request body exceeds the size limit'), 413),
|
|
77
|
+
}));
|
|
78
|
+
app.onError((err, c) => {
|
|
79
|
+
const requestId = c.get('requestId');
|
|
80
|
+
if (err instanceof management.ManagementError)
|
|
81
|
+
return c.json(error(requestId, err.code, err.message), err.status);
|
|
82
|
+
if (err instanceof HTTPException && err.status === 400) {
|
|
83
|
+
return c.json(error(requestId, 'INVALID_BODY', 'Malformed request body'), 400);
|
|
84
|
+
}
|
|
85
|
+
if ('code' in err && err.code === 'P2002') {
|
|
86
|
+
return c.json(error(requestId, 'CONFLICT', 'Resource already exists'), 409);
|
|
87
|
+
}
|
|
88
|
+
if ('code' in err && (err.code === 'P2003' || err.code === 'P2004')) {
|
|
89
|
+
return c.json(error(requestId, 'INVALID_INPUT', 'Request violates a resource constraint'), 422);
|
|
90
|
+
}
|
|
91
|
+
console.error(JSON.stringify({ service: 'api', event: 'management_error', requestId }));
|
|
92
|
+
return c.json(error(requestId, 'INTERNAL_ERROR', 'Request could not be completed'), 500);
|
|
93
|
+
});
|
|
94
|
+
const autoReviewPath = `${character}/auto-review`;
|
|
95
|
+
app.openapi(createRoute({
|
|
96
|
+
method: 'get', path: autoReviewPath, security, request: { params: characterParams },
|
|
97
|
+
responses: { ...errors, 200: success(autoReviewView) },
|
|
98
|
+
}), async (c) => {
|
|
99
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
100
|
+
const settings = await db.$transaction(async (tx) => {
|
|
101
|
+
await management.authorize(tx, scope);
|
|
102
|
+
return readAutoReviewSettings(tx, scope.characterId);
|
|
103
|
+
}, { isolationLevel: 'RepeatableRead' });
|
|
104
|
+
const model = await reviewModel().catch(() => null);
|
|
105
|
+
return c.json(autoReviewView.parse({ ...settings, model }), 200);
|
|
106
|
+
});
|
|
107
|
+
app.openapi(createRoute({
|
|
108
|
+
method: 'put', path: autoReviewPath, security,
|
|
109
|
+
request: { params: characterParams, headers: schema.versionHeader, body: body(autoReviewInput) },
|
|
110
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
111
|
+
}), async (c) => {
|
|
112
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
113
|
+
const requestId = c.get('requestId');
|
|
114
|
+
const input = c.req.valid('json');
|
|
115
|
+
const expected = version(c.req.valid('header'));
|
|
116
|
+
const result = await management.executeManagementCommand(db, {
|
|
117
|
+
...scope, requestId, input, operation: 'auto-review.update', targetScope: scope.characterId,
|
|
118
|
+
}, async (tx) => {
|
|
119
|
+
const updated = await tx.character.updateMany({
|
|
120
|
+
where: { id: scope.characterId, autoReviewVersion: expected },
|
|
121
|
+
data: { autoReviewEnabled: input.enabled, autoReviewPrompt: input.prompt, autoReviewVersion: { increment: 1 } },
|
|
122
|
+
});
|
|
123
|
+
if (updated.count !== 1)
|
|
124
|
+
throw new management.ManagementError(412, 'STALE_VERSION', 'Review settings changed');
|
|
125
|
+
return { id: scope.characterId, version: expected + 1 };
|
|
126
|
+
});
|
|
127
|
+
return c.json({ ...result, requestId }, 200);
|
|
128
|
+
});
|
|
129
|
+
const accountHooks = plugins.flatMap(({ account, accountFields }) => {
|
|
130
|
+
if (!account)
|
|
131
|
+
return [];
|
|
132
|
+
const fields = z.object(accountFields ?? {});
|
|
133
|
+
return [{ ...account, async profiles(...args) {
|
|
134
|
+
const project = await account.profiles(...args);
|
|
135
|
+
return (row) => fields.parse(project(row));
|
|
136
|
+
} }];
|
|
137
|
+
});
|
|
138
|
+
if (new Set(plugins.map(({ id }) => id)).size !== plugins.length)
|
|
139
|
+
throw new Error('Duplicate management plugin');
|
|
140
|
+
const platformIds = [...schema.simulationAccountRegistration.shape.platform.options, ...accountHooks.map(({ platform }) => platform)];
|
|
141
|
+
if (new Set(platformIds).size !== platformIds.length)
|
|
142
|
+
throw new Error('Duplicate account platform');
|
|
143
|
+
const registration = z.union([schema.simulationAccountRegistration, ...accountHooks.map(({ registration }) => registration)]);
|
|
144
|
+
const accountFields = extensionFields({ ...schema.accountView.shape, ...schema.accountRegistrationView.shape }, plugins.map((plugin) => plugin.accountFields));
|
|
145
|
+
const workspaceFields = extensionFields(schema.characterWorkspaceView.shape, plugins.map((plugin) => plugin.workspace?.fields));
|
|
146
|
+
const baseStatusView = pluginStatusView.extend({ deployment: deploymentPluginsView.optional() });
|
|
147
|
+
const statusFields = extensionFields(baseStatusView.shape, plugins.map((plugin) => plugin.status?.fields));
|
|
148
|
+
const workspaceView = schema.characterWorkspaceView.extend(workspaceFields);
|
|
149
|
+
const accountView = schema.accountView.extend(accountFields);
|
|
150
|
+
const accountPoolView = schema.pageView(schema.accountRegistrationView.extend(accountFields));
|
|
151
|
+
const statusView = baseStatusView.extend(statusFields);
|
|
152
|
+
app.openapi(createRoute({
|
|
153
|
+
method: 'put', path: '/deployment-plugins', security,
|
|
154
|
+
request: { headers: schema.versionHeader, body: body(deploymentPluginChange) },
|
|
155
|
+
responses: { ...errors, 200: success(deploymentPluginsView) },
|
|
156
|
+
}), async (c) => {
|
|
157
|
+
const actor = c.get('actor');
|
|
158
|
+
if (actor.issuer !== localIssuer || !actor.canCreate)
|
|
159
|
+
management.denyPermission();
|
|
160
|
+
if (!deploymentPlugins)
|
|
161
|
+
throw new management.ManagementError(404, 'PLUGINS_UNAVAILABLE', 'Plugin settings are unavailable');
|
|
162
|
+
const change = c.req.valid('json');
|
|
163
|
+
try {
|
|
164
|
+
const saved = await deploymentPlugins.save(change, version(c.req.valid('header')), activeModel);
|
|
165
|
+
console.info(JSON.stringify({ service: 'api', event: 'deployment_plugin_changed', actorId: actor.id,
|
|
166
|
+
requestId: c.get('requestId'), action: change.action, plugin: deploymentChangeOwner(change), version: saved.version }));
|
|
167
|
+
return c.json(saved, 200);
|
|
168
|
+
}
|
|
169
|
+
catch (cause) {
|
|
170
|
+
if (!(cause instanceof DeploymentPluginError))
|
|
171
|
+
throw cause;
|
|
172
|
+
const status = cause.code === 'VERSION_CONFLICT' ? 412 : 409;
|
|
173
|
+
throw new management.ManagementError(status, cause.code, 'Check plugin state, version and credentials');
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
app.openapi(createRoute({
|
|
177
|
+
method: 'get', path: '/characters', security,
|
|
178
|
+
request: { query: schema.listQuery },
|
|
179
|
+
responses: { ...errors, 200: success(schema.pageView(schema.characterView)) },
|
|
180
|
+
}), async (c) => c.json(await management.listCharacters(db, c.get('actor'), management.parsePage(c.req.valid('query'))), 200));
|
|
181
|
+
app.openapi(createRoute({
|
|
182
|
+
method: 'post', path: '/characters', security,
|
|
183
|
+
request: { headers: schema.idempotencyHeader, body: body(schema.characterInput) },
|
|
184
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
185
|
+
}), async (c) => {
|
|
186
|
+
const actor = c.get('actor');
|
|
187
|
+
if (!actor.canCreate)
|
|
188
|
+
management.denyPermission();
|
|
189
|
+
const input = c.req.valid('json');
|
|
190
|
+
const requestId = c.get('requestId');
|
|
191
|
+
const result = await management.executeManagementCommand(db, {
|
|
192
|
+
actor, operation: 'character.create', targetScope: '/characters', input, requestId,
|
|
193
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
194
|
+
}, (tx) => management.createCharacter(tx, actor, input));
|
|
195
|
+
return c.json({ ...result, requestId }, 201);
|
|
196
|
+
});
|
|
197
|
+
app.openapi(createRoute({
|
|
198
|
+
method: 'get', path: character, security, request: { params: characterParams },
|
|
199
|
+
responses: { ...errors, 200: success(workspaceView) },
|
|
200
|
+
}), async (c) => {
|
|
201
|
+
const result = await management.getCharacter(db, { ...c.req.valid('param'), actor: c.get('actor') });
|
|
202
|
+
c.header('ETag', `"${result.version ?? 0}"`);
|
|
203
|
+
const platforms = schema.accountInput.shape.platform.options;
|
|
204
|
+
const simulationPlatforms = platforms.filter((id) => resolveAdapter(id));
|
|
205
|
+
const fields = await Promise.all(plugins.map(async ({ workspace }) => workspace && z.object(workspace.fields).parse(await workspace.read())));
|
|
206
|
+
return c.json({ ...result, simulationPlatforms, ...Object.assign({}, ...fields) }, 200);
|
|
207
|
+
});
|
|
208
|
+
app.openapi(createRoute({
|
|
209
|
+
method: 'put', path: `${character}/core`, security,
|
|
210
|
+
request: { params: characterParams, headers: schema.versionHeader, body: body(schema.coreInput) },
|
|
211
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
212
|
+
}), async (c) => {
|
|
213
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
214
|
+
const input = c.req.valid('json');
|
|
215
|
+
const expected = version(c.req.valid('header'));
|
|
216
|
+
const requestId = c.get('requestId');
|
|
217
|
+
const result = await management.executeManagementCommand(db, {
|
|
218
|
+
...scope, operation: 'character.core.update', targetScope: scope.characterId, input: { input, expected }, requestId,
|
|
219
|
+
}, (tx) => management.updateCore(tx, scope, expected, input));
|
|
220
|
+
return c.json({ ...result, requestId }, 200);
|
|
221
|
+
});
|
|
222
|
+
app.openapi(createRoute({
|
|
223
|
+
method: 'get', path: `${character}/identities`, security,
|
|
224
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
225
|
+
responses: { ...errors, 200: success(schema.pageView(schema.identityView)) },
|
|
226
|
+
}), async (c) => c.json(await management.listIdentities(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(c.req.valid('query'))), 200));
|
|
227
|
+
app.openapi(createRoute({
|
|
228
|
+
method: 'post', path: `${character}/identities`, security,
|
|
229
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.identityInput) },
|
|
230
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
231
|
+
}), async (c) => {
|
|
232
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
233
|
+
const input = c.req.valid('json');
|
|
234
|
+
const requestId = c.get('requestId');
|
|
235
|
+
const result = await management.executeManagementCommand(db, {
|
|
236
|
+
...scope, operation: 'identity.create', targetScope: scope.characterId, input, requestId,
|
|
237
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
238
|
+
}, async (tx) => {
|
|
239
|
+
await validateDraftModel(input.roleProfile.draftModelProfile);
|
|
240
|
+
return management.createIdentity(tx, scope, input);
|
|
241
|
+
});
|
|
242
|
+
return c.json({ ...result, requestId }, 201);
|
|
243
|
+
});
|
|
244
|
+
app.openapi(createRoute({
|
|
245
|
+
method: 'put', path: `${character}/identities/{identityId}`, security,
|
|
246
|
+
request: { params: identityParams, headers: schema.versionHeader, body: body(schema.identityUpdate) },
|
|
247
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
248
|
+
}), async (c) => {
|
|
249
|
+
const { identityId, characterId } = c.req.valid('param');
|
|
250
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
251
|
+
const input = c.req.valid('json');
|
|
252
|
+
const expected = version(c.req.valid('header'));
|
|
253
|
+
const requestId = c.get('requestId');
|
|
254
|
+
const result = await management.executeManagementCommand(db, {
|
|
255
|
+
...scope, operation: 'identity.update', targetScope: characterId + '/' + identityId, input: { input, expected }, requestId,
|
|
256
|
+
}, async (tx) => {
|
|
257
|
+
await validateDraftModel(input.roleProfile.draftModelProfile, async () => {
|
|
258
|
+
const previous = await tx.identityVersion.findUnique({
|
|
259
|
+
where: { characterId_identityId_version: { characterId, identityId, version: expected } },
|
|
260
|
+
select: { roleProfile: true },
|
|
261
|
+
});
|
|
262
|
+
return schema.identityProfile.safeParse(previous?.roleProfile).data?.draftModelProfile === input.roleProfile.draftModelProfile;
|
|
263
|
+
});
|
|
264
|
+
return management.updateIdentity(tx, scope, identityId, expected, input);
|
|
265
|
+
});
|
|
266
|
+
return c.json({ ...result, requestId }, 200);
|
|
267
|
+
});
|
|
268
|
+
app.openapi(createRoute({
|
|
269
|
+
method: 'get', path: `${character}/plugins`, security,
|
|
270
|
+
request: { params: characterParams },
|
|
271
|
+
responses: { ...errors, 200: success(statusView) },
|
|
272
|
+
}), async (c) => {
|
|
273
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
274
|
+
await db.$transaction((tx) => management.authorize(tx, scope));
|
|
275
|
+
const current = await pluginStatus();
|
|
276
|
+
const fields = Object.assign({}, ...await Promise.all(plugins.map(async ({ status }) => status && z.object(status.fields).parse(await status.read(scope.characterId)))));
|
|
277
|
+
if (!deploymentPlugins)
|
|
278
|
+
return c.json({ ...current, ...fields }, 200);
|
|
279
|
+
const [provider, release] = await Promise.all([
|
|
280
|
+
activeModel(),
|
|
281
|
+
pluginRelease?.(current.services),
|
|
282
|
+
]);
|
|
283
|
+
const deployment = await deploymentPlugins.status(provider);
|
|
284
|
+
return c.json({ ...current, deployment, release, ...fields }, 200);
|
|
285
|
+
});
|
|
286
|
+
app.openapi(createRoute({
|
|
287
|
+
method: 'get', path: `${character}/accounts`, security,
|
|
288
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
289
|
+
responses: { ...errors, 200: success(schema.pageView(accountView)) },
|
|
290
|
+
}), async (c) => c.json(schema.pageView(accountView).parse(await management.listAccounts(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(c.req.valid('query')), accountHooks)), 200));
|
|
291
|
+
app.openapi(createRoute({
|
|
292
|
+
method: 'get', path: `${character}/account-pool`, security,
|
|
293
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
294
|
+
responses: { ...errors, 200: success(accountPoolView) },
|
|
295
|
+
}), async (c) => c.json(accountPoolView.parse(await management.listAccountPool(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(c.req.valid('query')), accountHooks)), 200));
|
|
296
|
+
app.openapi(createRoute({
|
|
297
|
+
method: 'post', path: `${character}/account-pool`, security,
|
|
298
|
+
request: { params: characterParams, headers: schema.idempotencyHeader,
|
|
299
|
+
body: body(registration) },
|
|
300
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
301
|
+
}), async (c) => {
|
|
302
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
303
|
+
const input = c.req.valid('json');
|
|
304
|
+
const requestId = c.get('requestId');
|
|
305
|
+
const result = await management.executeManagementCommand(db, {
|
|
306
|
+
...scope, operation: 'account.register', targetScope: scope.characterId, input, requestId,
|
|
307
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
308
|
+
}, async (tx) => {
|
|
309
|
+
const account = accountHooks.find(({ platform }) => platform === input.platform);
|
|
310
|
+
return account ? account.register(tx, scope, input)
|
|
311
|
+
: management.registerAccount(tx, scope, schema.simulationAccountRegistration.parse(input));
|
|
312
|
+
});
|
|
313
|
+
return c.json({ ...result, requestId }, 201);
|
|
314
|
+
});
|
|
315
|
+
app.openapi(createRoute({
|
|
316
|
+
method: 'delete', path: `${character}/account-pool/{registrationId}`, security,
|
|
317
|
+
request: { params: characterParams.extend({ registrationId: schema.resourceId }), headers: schema.idempotencyHeader },
|
|
318
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
319
|
+
}), async (c) => {
|
|
320
|
+
const { characterId, registrationId } = c.req.valid('param');
|
|
321
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
322
|
+
const requestId = c.get('requestId');
|
|
323
|
+
const result = await management.executeManagementCommand(db, {
|
|
324
|
+
...scope, operation: 'account.remove', targetScope: registrationId, input: { registrationId }, requestId,
|
|
325
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
326
|
+
}, (tx) => management.removeAccountRegistration(tx, scope, registrationId, accountHooks));
|
|
327
|
+
return c.json({ ...result, requestId }, 200);
|
|
328
|
+
});
|
|
329
|
+
app.openapi(createRoute({
|
|
330
|
+
method: 'post', path: `${character}/account-pool/associations`, security,
|
|
331
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.accountBindingInput) },
|
|
332
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
333
|
+
}), async (c) => {
|
|
334
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
335
|
+
const input = c.req.valid('json');
|
|
336
|
+
const requestId = c.get('requestId');
|
|
337
|
+
const result = await management.executeManagementCommand(db, {
|
|
338
|
+
...scope, operation: 'account.associate', targetScope: scope.characterId, input, requestId,
|
|
339
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
340
|
+
}, (tx) => management.associateAccount(tx, scope, input));
|
|
341
|
+
return c.json({ ...result, requestId }, 201);
|
|
342
|
+
});
|
|
343
|
+
app.openapi(createRoute({
|
|
344
|
+
method: 'get', path: `${character}/accounts/{accountId}/automation-eligibility`, security,
|
|
345
|
+
request: { params: characterParams.extend({ accountId: schema.resourceId }) },
|
|
346
|
+
responses: { ...errors, 200: success(schema.automationEligibilityView) },
|
|
347
|
+
}), async (c) => {
|
|
348
|
+
const { characterId, accountId } = c.req.valid('param');
|
|
349
|
+
const view = await management.readAutomationEligibility(db, { characterId, actor: c.get('actor') }, accountId);
|
|
350
|
+
return c.json(schema.automationEligibilityView.parse(view), 200);
|
|
351
|
+
});
|
|
352
|
+
app.openapi(createRoute({
|
|
353
|
+
method: 'post', path: `${character}/accounts`, security,
|
|
354
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.accountInput) },
|
|
355
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
356
|
+
}), async (c) => {
|
|
357
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
358
|
+
const input = c.req.valid('json');
|
|
359
|
+
const requestId = c.get('requestId');
|
|
360
|
+
const result = await management.executeManagementCommand(db, {
|
|
361
|
+
...scope, operation: 'account.create', targetScope: scope.characterId, input, requestId,
|
|
362
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
363
|
+
}, (tx) => management.createAccount(tx, scope, input));
|
|
364
|
+
return c.json({ ...result, requestId }, 201);
|
|
365
|
+
});
|
|
366
|
+
app.openapi(createRoute({
|
|
367
|
+
method: 'post', path: `${character}/controls`, security,
|
|
368
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.controlInput) },
|
|
369
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
370
|
+
}), async (c) => {
|
|
371
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
372
|
+
const input = c.req.valid('json');
|
|
373
|
+
const requestId = c.get('requestId');
|
|
374
|
+
const result = await management.executeManagementCommand(db, {
|
|
375
|
+
...scope, operation: 'control.apply', targetScope: scope.characterId, input, requestId,
|
|
376
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
377
|
+
}, (tx) => management.control(tx, scope, input, accountHooks));
|
|
378
|
+
return c.json({ ...result, requestId }, 200);
|
|
379
|
+
});
|
|
380
|
+
app.openapi(createRoute({
|
|
381
|
+
method: 'get', path: `${character}/memories`, security,
|
|
382
|
+
request: { params: characterParams, query: schema.memoryListQuery },
|
|
383
|
+
responses: { ...errors, 200: success(schema.pageView(schema.memoryView)) },
|
|
384
|
+
}), async (c) => {
|
|
385
|
+
const query = c.req.valid('query');
|
|
386
|
+
return c.json(await management.listMemories(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(query), query), 200);
|
|
387
|
+
});
|
|
388
|
+
const energyParams = characterParams.extend({ utcDay: z.iso.date() });
|
|
389
|
+
app.openapi(createRoute({
|
|
390
|
+
method: 'get', path: `${character}/daily-energy/{utcDay}`, security,
|
|
391
|
+
request: { params: energyParams }, responses: { ...errors, 200: success(schema.dailyEnergyView) },
|
|
392
|
+
}), async (c) => {
|
|
393
|
+
const { characterId, utcDay } = c.req.valid('param');
|
|
394
|
+
return c.json(await management.readDailyEnergy(db, { characterId, actor: c.get('actor') }, utcDay), 200);
|
|
395
|
+
});
|
|
396
|
+
app.openapi(createRoute({
|
|
397
|
+
method: 'post', path: `${character}/daily-energy`, security,
|
|
398
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.dailyEnergyInput) },
|
|
399
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
400
|
+
}), async (c) => {
|
|
401
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
402
|
+
const input = c.req.valid('json');
|
|
403
|
+
const requestId = c.get('requestId');
|
|
404
|
+
const result = await management.executeManagementCommand(db, {
|
|
405
|
+
...scope, operation: 'state.energy.approve', targetScope: scope.characterId, input, requestId,
|
|
406
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
407
|
+
}, (tx) => management.approveDailyEnergy(tx, scope, input));
|
|
408
|
+
return c.json({ ...result, requestId }, 201);
|
|
409
|
+
});
|
|
410
|
+
app.openapi(createRoute({
|
|
411
|
+
method: 'get', path: `${character}/identities/{identityId}/reflections/{utcDay}`, security,
|
|
412
|
+
request: { params: identityParams.extend({ utcDay: z.iso.date() }) },
|
|
413
|
+
responses: { ...errors, 200: success(schema.identityReflectionView) },
|
|
414
|
+
}), async (c) => {
|
|
415
|
+
const { characterId, identityId, utcDay } = c.req.valid('param');
|
|
416
|
+
const view = await management.readIdentityReflection(db, { characterId, actor: c.get('actor') }, identityId, utcDay);
|
|
417
|
+
return c.json(schema.identityReflectionView.parse(view), 200);
|
|
418
|
+
});
|
|
419
|
+
const beliefs = `${character}/identities/{identityId}/beliefs`;
|
|
420
|
+
app.openapi(createRoute({
|
|
421
|
+
method: 'get', path: beliefs, security,
|
|
422
|
+
request: { params: identityParams, query: schema.listQuery },
|
|
423
|
+
responses: { ...errors, 200: success(schema.pageView(schema.beliefSummary)) },
|
|
424
|
+
}), async (c) => {
|
|
425
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
426
|
+
return c.json(await listIdentityBeliefs(db, { characterId, actor: c.get('actor') }, identityId, management.parsePage(c.req.valid('query'))), 200);
|
|
427
|
+
});
|
|
428
|
+
const beliefParams = identityParams.extend({ beliefId: schema.resourceId });
|
|
429
|
+
app.openapi(createRoute({
|
|
430
|
+
method: 'get', path: `${beliefs}/{beliefId}`, security,
|
|
431
|
+
request: { params: beliefParams, query: z.object({ revision: z.string().regex(/^[1-9][0-9]{0,8}$/).optional() }) },
|
|
432
|
+
responses: { ...errors, 200: success(schema.beliefView) },
|
|
433
|
+
}), async (c) => {
|
|
434
|
+
const { characterId, identityId, beliefId } = c.req.valid('param');
|
|
435
|
+
const { revision } = c.req.valid('query');
|
|
436
|
+
const view = schema.beliefView.parse(await management.readBelief(db, { characterId, actor: c.get('actor') }, identityId, beliefId, revision ? Number(revision) : undefined));
|
|
437
|
+
c.header('ETag', '"' + view.version + '"');
|
|
438
|
+
return c.json(view, 200);
|
|
439
|
+
});
|
|
440
|
+
app.openapi(createRoute({
|
|
441
|
+
method: 'post', path: beliefs, security,
|
|
442
|
+
request: { params: identityParams, headers: schema.idempotencyHeader, body: body(schema.beliefInput) },
|
|
443
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
444
|
+
}), async (c) => {
|
|
445
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
446
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
447
|
+
const input = c.req.valid('json');
|
|
448
|
+
const requestId = c.get('requestId');
|
|
449
|
+
const result = await management.executeManagementCommand(db, {
|
|
450
|
+
...scope, operation: 'belief.create', targetScope: characterId + '/' + identityId, input, requestId,
|
|
451
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
452
|
+
}, (tx) => management.writeBelief(tx, scope, identityId, randomUUID(), 0, input));
|
|
453
|
+
return c.json({ ...result, requestId }, 201);
|
|
454
|
+
});
|
|
455
|
+
app.openapi(createRoute({
|
|
456
|
+
method: 'put', path: `${beliefs}/{beliefId}`, security,
|
|
457
|
+
request: { params: beliefParams, headers: schema.versionHeader, body: body(schema.beliefInput) },
|
|
458
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
459
|
+
}), async (c) => {
|
|
460
|
+
const { characterId, identityId, beliefId } = c.req.valid('param');
|
|
461
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
462
|
+
const input = c.req.valid('json');
|
|
463
|
+
const expected = version(c.req.valid('header'));
|
|
464
|
+
const requestId = c.get('requestId');
|
|
465
|
+
const result = await management.executeManagementCommand(db, {
|
|
466
|
+
...scope, operation: 'belief.update', targetScope: characterId + '/' + identityId + '/' + beliefId,
|
|
467
|
+
input: { input, expected }, requestId,
|
|
468
|
+
}, (tx) => management.writeBelief(tx, scope, identityId, beliefId, expected, input));
|
|
469
|
+
return c.json({ ...result, requestId }, 200);
|
|
470
|
+
});
|
|
471
|
+
app.openapi(createRoute({
|
|
472
|
+
method: 'post', path: `${beliefs}/{beliefId}/restore`, security,
|
|
473
|
+
request: { params: beliefParams, headers: schema.versionHeader, body: body(schema.beliefRestoreInput) },
|
|
474
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
475
|
+
}), async (c) => {
|
|
476
|
+
const { characterId, identityId, beliefId } = c.req.valid('param');
|
|
477
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
478
|
+
const input = c.req.valid('json');
|
|
479
|
+
const expected = version(c.req.valid('header'));
|
|
480
|
+
const requestId = c.get('requestId');
|
|
481
|
+
const result = await management.executeManagementCommand(db, {
|
|
482
|
+
...scope, operation: 'belief.restore', targetScope: characterId + '/' + identityId + '/' + beliefId,
|
|
483
|
+
input: { input, expected }, requestId,
|
|
484
|
+
}, (tx) => management.writeBelief(tx, scope, identityId, beliefId, expected, input));
|
|
485
|
+
return c.json({ ...result, requestId }, 200);
|
|
486
|
+
});
|
|
487
|
+
const goals = `${character}/identities/{identityId}/goals`;
|
|
488
|
+
const goalParams = identityParams.extend({ goalId: schema.resourceId });
|
|
489
|
+
const goalQuery = z.object({ revision: z.string().regex(/^[1-9][0-9]{0,8}$/).optional() });
|
|
490
|
+
const goalList = z.array(schema.manualGoalView);
|
|
491
|
+
app.openapi(createRoute({
|
|
492
|
+
method: 'get', path: goals, security, request: { params: identityParams },
|
|
493
|
+
responses: { ...errors, 200: success(goalList) },
|
|
494
|
+
}), async (c) => {
|
|
495
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
496
|
+
return c.json(goalList.parse(await management.readManualGoals(db, { characterId, actor: c.get('actor') }, identityId)), 200);
|
|
497
|
+
});
|
|
498
|
+
app.openapi(createRoute({
|
|
499
|
+
method: 'get', path: `${goals}/{goalId}`, security, request: { params: goalParams, query: goalQuery },
|
|
500
|
+
responses: { ...errors, 200: success(schema.manualGoalView) },
|
|
501
|
+
}), async (c) => {
|
|
502
|
+
const { characterId, identityId, goalId } = c.req.valid('param');
|
|
503
|
+
const revision = c.req.valid('query').revision;
|
|
504
|
+
const view = schema.manualGoalView.parse(await management.readManualGoals(db, { characterId, actor: c.get('actor') }, identityId, goalId, revision ? Number(revision) : undefined));
|
|
505
|
+
c.header('ETag', '"' + view.version + '"');
|
|
506
|
+
return c.json(view, 200);
|
|
507
|
+
});
|
|
508
|
+
app.openapi(createRoute({
|
|
509
|
+
method: 'post', path: goals, security,
|
|
510
|
+
request: { params: identityParams, headers: schema.idempotencyHeader, body: body(schema.manualGoalInput) },
|
|
511
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
512
|
+
}), async (c) => {
|
|
513
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
514
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
515
|
+
const input = c.req.valid('json');
|
|
516
|
+
const requestId = c.get('requestId');
|
|
517
|
+
const result = await management.executeManagementCommand(db, {
|
|
518
|
+
...scope, operation: 'goal.create', targetScope: characterId + '/' + identityId, input, requestId,
|
|
519
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
520
|
+
}, (tx) => management.writeManualGoal(tx, scope, identityId, randomUUID(), 0, input));
|
|
521
|
+
return c.json({ ...result, requestId }, 201);
|
|
522
|
+
});
|
|
523
|
+
app.openapi(createRoute({
|
|
524
|
+
method: 'put', path: `${goals}/{goalId}`, security,
|
|
525
|
+
request: { params: goalParams, headers: schema.versionHeader, body: body(schema.manualGoalInput) },
|
|
526
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
527
|
+
}), async (c) => {
|
|
528
|
+
const { characterId, identityId, goalId } = c.req.valid('param');
|
|
529
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
530
|
+
const input = c.req.valid('json');
|
|
531
|
+
const expected = version(c.req.valid('header'));
|
|
532
|
+
const requestId = c.get('requestId');
|
|
533
|
+
const result = await management.executeManagementCommand(db, {
|
|
534
|
+
...scope, operation: 'goal.update', targetScope: characterId + '/' + identityId + '/' + goalId,
|
|
535
|
+
input: { input, expected }, requestId,
|
|
536
|
+
}, (tx) => management.writeManualGoal(tx, scope, identityId, goalId, expected, input));
|
|
537
|
+
return c.json({ ...result, requestId }, 200);
|
|
538
|
+
});
|
|
539
|
+
app.openapi(createRoute({
|
|
540
|
+
method: 'get', path: `${character}/identities/{identityId}/contacts`, security,
|
|
541
|
+
request: { params: identityParams, query: schema.listQuery },
|
|
542
|
+
responses: { ...errors, 200: success(schema.pageView(schema.contactSummary)) },
|
|
543
|
+
}), async (c) => {
|
|
544
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
545
|
+
return c.json(await listIdentityContacts(db, { characterId, actor: c.get('actor') }, identityId, management.parsePage(c.req.valid('query'))), 200);
|
|
546
|
+
});
|
|
547
|
+
app.openapi(createRoute({
|
|
548
|
+
method: 'get', path: `${character}/identities/{identityId}/conversations`, security,
|
|
549
|
+
request: { params: identityParams, query: schema.conversationListQuery },
|
|
550
|
+
responses: { ...errors, 200: success(schema.pageView(schema.conversationOption)) },
|
|
551
|
+
}), async (c) => {
|
|
552
|
+
const { characterId, identityId } = c.req.valid('param');
|
|
553
|
+
return c.json(await listConversationOptions(db, { characterId, actor: c.get('actor') }, identityId, c.req.valid('query')), 200);
|
|
554
|
+
});
|
|
555
|
+
const contactParams = characterParams.extend({ contactId: schema.resourceId });
|
|
556
|
+
app.openapi(createRoute({
|
|
557
|
+
method: 'get', path: `${character}/contacts/{contactId}/boundary`, security,
|
|
558
|
+
request: { params: contactParams }, responses: { ...errors, 200: success(schema.contactBoundaryView) },
|
|
559
|
+
}), async (c) => {
|
|
560
|
+
const { characterId, contactId } = c.req.valid('param');
|
|
561
|
+
const view = await management.readContactBoundary(db, { characterId, actor: c.get('actor') }, contactId);
|
|
562
|
+
c.header('ETag', '"' + view.version + '"');
|
|
563
|
+
return c.json(view, 200);
|
|
564
|
+
});
|
|
565
|
+
app.openapi(createRoute({
|
|
566
|
+
method: 'put', path: `${character}/contacts/{contactId}/boundary`, security,
|
|
567
|
+
request: { params: contactParams, headers: schema.versionHeader, body: body(schema.contactBoundaryInput) },
|
|
568
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
569
|
+
}), async (c) => {
|
|
570
|
+
const { characterId, contactId } = c.req.valid('param');
|
|
571
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
572
|
+
const expected = version(c.req.valid('header'));
|
|
573
|
+
const input = c.req.valid('json');
|
|
574
|
+
const requestId = c.get('requestId');
|
|
575
|
+
const result = await management.executeManagementCommand(db, {
|
|
576
|
+
...scope, operation: 'contact.boundary', targetScope: characterId + '/' + contactId, input: { input, expected }, requestId,
|
|
577
|
+
}, (tx) => management.changeContactBoundary(tx, scope, contactId, expected, input));
|
|
578
|
+
return c.json({ ...result, requestId }, 200);
|
|
579
|
+
});
|
|
580
|
+
const memoryParams = characterParams.extend({ memoryId: schema.resourceId });
|
|
581
|
+
app.openapi(createRoute({
|
|
582
|
+
method: 'get', path: `${character}/memories/{memoryId}`, security,
|
|
583
|
+
request: { params: memoryParams }, responses: { ...errors, 200: success(schema.memoryDetailView) },
|
|
584
|
+
}), async (c) => {
|
|
585
|
+
const { characterId, memoryId } = c.req.valid('param');
|
|
586
|
+
return c.json(await management.readMemoryDetail(db, { characterId, actor: c.get('actor') }, memoryId), 200);
|
|
587
|
+
});
|
|
588
|
+
app.openapi(createRoute({
|
|
589
|
+
method: 'get', path: `${character}/memories/{memoryId}/provenance`, security,
|
|
590
|
+
request: { params: memoryParams }, responses: { ...errors, 200: success(schema.memoryProvenanceView) },
|
|
591
|
+
}), async (c) => {
|
|
592
|
+
const { characterId, memoryId } = c.req.valid('param');
|
|
593
|
+
const view = await management.readMemoryProvenance(db, { characterId, actor: c.get('actor') }, memoryId);
|
|
594
|
+
c.header('ETag', '"' + view.revision + '"');
|
|
595
|
+
return c.json(view, 200);
|
|
596
|
+
});
|
|
597
|
+
app.openapi(createRoute({
|
|
598
|
+
method: 'put', path: `${character}/memories/{memoryId}/correction`, security,
|
|
599
|
+
request: { params: memoryParams, headers: schema.versionHeader, body: body(schema.memoryCorrectionInput) },
|
|
600
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
601
|
+
}), async (c) => {
|
|
602
|
+
const { characterId, memoryId } = c.req.valid('param');
|
|
603
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
604
|
+
const expected = version(c.req.valid('header'));
|
|
605
|
+
const input = c.req.valid('json');
|
|
606
|
+
const requestId = c.get('requestId');
|
|
607
|
+
const result = await management.executeManagementCommand(db, {
|
|
608
|
+
...scope, operation: 'memory.correct', targetScope: characterId + '/' + memoryId, input: { input, expected }, requestId,
|
|
609
|
+
}, (tx) => management.correctMemory(tx, scope, memoryId, expected, input));
|
|
610
|
+
return c.json({ ...result, requestId }, 200);
|
|
611
|
+
});
|
|
612
|
+
app.openapi(createRoute({
|
|
613
|
+
method: 'get', path: `${character}/memory-grants`, security,
|
|
614
|
+
request: { params: characterParams, query: schema.grantListQuery },
|
|
615
|
+
responses: { ...errors, 200: success(schema.pageView(schema.grantView)) },
|
|
616
|
+
}), async (c) => {
|
|
617
|
+
const query = c.req.valid('query');
|
|
618
|
+
return c.json(await management.listGrants(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(query), query.memoryId), 200);
|
|
619
|
+
});
|
|
620
|
+
app.openapi(createRoute({
|
|
621
|
+
method: 'post', path: `${character}/memory-grants`, security,
|
|
622
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.memoryGrantInput) },
|
|
623
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
624
|
+
}), async (c) => {
|
|
625
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
626
|
+
const input = c.req.valid('json');
|
|
627
|
+
const requestId = c.get('requestId');
|
|
628
|
+
const result = await management.executeManagementCommand(db, {
|
|
629
|
+
...scope, operation: 'memory.grant.create', targetScope: scope.characterId, input, requestId,
|
|
630
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
631
|
+
}, (tx) => management.createGrant(tx, scope, input));
|
|
632
|
+
return c.json({ ...result, requestId }, 201);
|
|
633
|
+
});
|
|
634
|
+
app.openapi(createRoute({
|
|
635
|
+
method: 'post', path: `${character}/memory-grants/{grantId}/revoke`, security,
|
|
636
|
+
request: { params: grantParams, headers: schema.idempotencyHeader, body: body(schema.reasonInput) },
|
|
637
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
638
|
+
}), async (c) => {
|
|
639
|
+
const { characterId, grantId } = c.req.valid('param');
|
|
640
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
641
|
+
const input = c.req.valid('json');
|
|
642
|
+
const requestId = c.get('requestId');
|
|
643
|
+
const result = await management.executeManagementCommand(db, {
|
|
644
|
+
...scope, operation: 'memory.grant.revoke', targetScope: characterId + '/' + grantId, input, requestId,
|
|
645
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
646
|
+
}, (tx) => management.revokeGrant(tx, scope, grantId));
|
|
647
|
+
return c.json({ ...result, requestId }, 200);
|
|
648
|
+
});
|
|
649
|
+
app.openapi(createRoute({
|
|
650
|
+
method: 'get', path: `${character}/audit`, security,
|
|
651
|
+
request: { params: characterParams, query: schema.auditQuery },
|
|
652
|
+
responses: { ...errors, 200: success(schema.pageView(schema.auditView)) },
|
|
653
|
+
}), async (c) => {
|
|
654
|
+
const query = c.req.valid('query');
|
|
655
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
656
|
+
return c.json(await management.listAudit(db, scope, {
|
|
657
|
+
...management.parsePage(query), runId: query.runId, targetId: query.targetId, order: query.order,
|
|
658
|
+
}), 200);
|
|
659
|
+
});
|
|
660
|
+
app.openapi(createRoute({
|
|
661
|
+
method: 'get', path: `${character}/memberships`, security,
|
|
662
|
+
request: { params: characterParams, query: schema.memberListQuery },
|
|
663
|
+
responses: { ...errors, 200: success(schema.memberPage) },
|
|
664
|
+
}), async (c) => c.json(await listMembers(db, { ...c.req.valid('param'), actor: c.get('actor') }, c.req.valid('query')), 200));
|
|
665
|
+
app.openapi(createRoute({
|
|
666
|
+
method: 'post', path: `${character}/memberships`, security,
|
|
667
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(schema.membershipInput) },
|
|
668
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
669
|
+
}), async (c) => {
|
|
670
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
671
|
+
const input = c.req.valid('json');
|
|
672
|
+
const requestId = c.get('requestId');
|
|
673
|
+
const result = await management.executeManagementCommand(db, {
|
|
674
|
+
...scope, operation: 'membership.change',
|
|
675
|
+
targetScope: scope.characterId, input, requestId, key: c.req.valid('header')['idempotency-key'],
|
|
676
|
+
}, async (tx) => {
|
|
677
|
+
if (scope.actor.issuer === localIssuer && input.action === 'GRANT'
|
|
678
|
+
&& !await tx.adminUser.findUnique({ where: { username: input.subject }, select: { id: true } })) {
|
|
679
|
+
throw new management.ManagementError(422, 'UNKNOWN_USER', 'Create the local user before granting access');
|
|
680
|
+
}
|
|
681
|
+
return management.changeMembership(tx, scope, input);
|
|
682
|
+
});
|
|
683
|
+
return c.json({ ...result, requestId }, 200);
|
|
684
|
+
});
|
|
685
|
+
app.openapi(createRoute({
|
|
686
|
+
method: 'get', path: `${character}/actions`, security,
|
|
687
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
688
|
+
responses: { ...errors, 200: success(schema.pageView(actionView)) },
|
|
689
|
+
}), async (c) => {
|
|
690
|
+
const { limit, cursor } = management.parsePage(c.req.valid('query'));
|
|
691
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
692
|
+
return c.json(await listReviewActions(db, scope, resolveAdapter, undefined, limit, cursor), 200);
|
|
693
|
+
});
|
|
694
|
+
app.openapi(createRoute({
|
|
695
|
+
method: 'get', path: `${character}/actions/{actionId}`, security,
|
|
696
|
+
request: { params: actionParams },
|
|
697
|
+
responses: { ...errors, 200: success(actionView) },
|
|
698
|
+
}), async (c) => {
|
|
699
|
+
const { characterId, actionId } = c.req.valid('param');
|
|
700
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
701
|
+
const { items: [proposal] } = await listReviewActions(db, scope, resolveAdapter, actionId);
|
|
702
|
+
c.header('ETag', `"run-v${proposal.version}"`);
|
|
703
|
+
return c.json(proposal, 200);
|
|
704
|
+
});
|
|
705
|
+
app.openapi(createRoute({
|
|
706
|
+
method: 'post', path: `${character}/actions/{actionId}/decisions`, security,
|
|
707
|
+
request: { params: actionParams, headers: schema.idempotencyHeader.merge(schema.versionHeader), body: body(actionDecision) },
|
|
708
|
+
responses: { ...errors, 200: success(schema.commandResponse), 409: failure },
|
|
709
|
+
}), async (c) => {
|
|
710
|
+
const { characterId, actionId } = c.req.valid('param');
|
|
711
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
712
|
+
const input = c.req.valid('json');
|
|
713
|
+
const headers = c.req.valid('header');
|
|
714
|
+
const expected = runVersion(headers['if-match']);
|
|
715
|
+
const requestId = c.get('requestId');
|
|
716
|
+
const result = await management.executeManagementCommand(db, {
|
|
717
|
+
...scope, operation: 'action.review', targetScope: characterId + '/' + actionId,
|
|
718
|
+
input: { input, expected }, requestId, key: headers['idempotency-key'],
|
|
719
|
+
}, (tx) => decideReviewAction(tx, scope, actionId, expected, input, resolveAdapter));
|
|
720
|
+
if (result.status === 'CANCELED' || result.status === 'EXPIRED') {
|
|
721
|
+
return c.json(error(requestId, 'STALE_REVIEW', 'Proposal is no longer eligible for review'), 409);
|
|
722
|
+
}
|
|
723
|
+
return c.json({ ...result, requestId }, 200);
|
|
724
|
+
});
|
|
725
|
+
app.openapi(createRoute({
|
|
726
|
+
method: 'get', path: `${character}/actions/{actionId}/reconciliation`, security,
|
|
727
|
+
request: { params: actionParams },
|
|
728
|
+
responses: { ...errors, 200: success(reconciliationView) },
|
|
729
|
+
}), async (c) => {
|
|
730
|
+
const { characterId, actionId } = c.req.valid('param');
|
|
731
|
+
const result = await readSimulationReconciliation(db, { characterId, actor: c.get('actor') }, actionId);
|
|
732
|
+
c.header('ETag', `"run-v${result.version}"`);
|
|
733
|
+
return c.json(result, 200);
|
|
734
|
+
});
|
|
735
|
+
app.openapi(createRoute({
|
|
736
|
+
method: 'post', path: `${character}/actions/{actionId}/reconciliation`, security,
|
|
737
|
+
request: { params: actionParams, headers: schema.idempotencyHeader.merge(schema.versionHeader), body: body(reconciliationInput) },
|
|
738
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
739
|
+
}), async (c) => {
|
|
740
|
+
const { characterId, actionId } = c.req.valid('param');
|
|
741
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
742
|
+
const headers = c.req.valid('header');
|
|
743
|
+
const expected = runVersion(headers['if-match']);
|
|
744
|
+
const input = c.req.valid('json');
|
|
745
|
+
const requestId = c.get('requestId');
|
|
746
|
+
const result = await management.executeManagementCommand(db, {
|
|
747
|
+
...scope, operation: 'simulation.resolve', targetScope: characterId + '/' + actionId,
|
|
748
|
+
input: { input, expected }, requestId, key: headers['idempotency-key'],
|
|
749
|
+
}, (tx) => resolveSimulationReconciliation(tx, scope, actionId, expected, input));
|
|
750
|
+
return c.json({ ...result, requestId }, 200);
|
|
751
|
+
});
|
|
752
|
+
app.openapi(createRoute({
|
|
753
|
+
method: 'get', path: `${character}/plans`, security,
|
|
754
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
755
|
+
responses: { ...errors, 200: success(schema.pageView(planView)) },
|
|
756
|
+
}), async (c) => c.json(await listPlans(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(c.req.valid('query'))), 200));
|
|
757
|
+
app.openapi(createRoute({
|
|
758
|
+
method: 'post', path: `${character}/plans`, security,
|
|
759
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(planInput) },
|
|
760
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
761
|
+
}), async (c) => {
|
|
762
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
763
|
+
const input = c.req.valid('json');
|
|
764
|
+
const requestId = c.get('requestId');
|
|
765
|
+
const result = await management.executeManagementCommand(db, {
|
|
766
|
+
...scope, operation: 'plan.create', targetScope: scope.characterId, input, requestId,
|
|
767
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
768
|
+
}, (tx) => savePlan(tx, scope, input));
|
|
769
|
+
return c.json({ ...result, requestId }, 201);
|
|
770
|
+
});
|
|
771
|
+
app.openapi(createRoute({
|
|
772
|
+
method: 'put', path: `${character}/plans/{planId}`, security,
|
|
773
|
+
request: { params: characterParams.extend({ planId: schema.resourceId }), headers: schema.versionHeader, body: body(planInput) },
|
|
774
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
775
|
+
}), async (c) => {
|
|
776
|
+
const { characterId, planId } = c.req.valid('param');
|
|
777
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
778
|
+
const input = c.req.valid('json');
|
|
779
|
+
const expected = version(c.req.valid('header'));
|
|
780
|
+
const requestId = c.get('requestId');
|
|
781
|
+
const result = await management.executeManagementCommand(db, {
|
|
782
|
+
...scope, operation: 'plan.update', targetScope: characterId + '/' + planId, input: { input, expected }, requestId,
|
|
783
|
+
}, (tx) => savePlan(tx, scope, input, { id: planId, expected }));
|
|
784
|
+
return c.json({ ...result, requestId }, 200);
|
|
785
|
+
});
|
|
786
|
+
app.openapi(createRoute({
|
|
787
|
+
method: 'put', path: `${character}/plans/{planId}/state`, security,
|
|
788
|
+
request: { params: characterParams.extend({ planId: schema.resourceId }), headers: schema.versionHeader, body: body(planStateInput) },
|
|
789
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
790
|
+
}), async (c) => {
|
|
791
|
+
const { characterId, planId } = c.req.valid('param');
|
|
792
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
793
|
+
const input = c.req.valid('json');
|
|
794
|
+
const expected = version(c.req.valid('header'));
|
|
795
|
+
const requestId = c.get('requestId');
|
|
796
|
+
const result = await management.executeManagementCommand(db, {
|
|
797
|
+
...scope, operation: 'plan.set-state', targetScope: characterId + '/' + planId, input: { input, expected }, requestId,
|
|
798
|
+
}, (tx) => setPlanEnabled(tx, scope, planId, expected, input.enabled));
|
|
799
|
+
return c.json({ ...result, requestId }, 200);
|
|
800
|
+
});
|
|
801
|
+
app.openapi(createRoute({
|
|
802
|
+
method: 'get', path: `${character}/schedules`, security,
|
|
803
|
+
request: { params: characterParams, query: schema.listQuery },
|
|
804
|
+
responses: { ...errors, 200: success(schema.pageView(scheduleView)) },
|
|
805
|
+
}), async (c) => c.json(await management.listSchedules(db, { ...c.req.valid('param'), actor: c.get('actor') }, management.parsePage(c.req.valid('query'))), 200));
|
|
806
|
+
app.openapi(createRoute({
|
|
807
|
+
method: 'post', path: `${character}/schedules`, security,
|
|
808
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(scheduleInput) },
|
|
809
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
810
|
+
}), async (c) => {
|
|
811
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
812
|
+
const input = c.req.valid('json');
|
|
813
|
+
const requestId = c.get('requestId');
|
|
814
|
+
const result = await management.executeManagementCommand(db, {
|
|
815
|
+
...scope, operation: 'schedule.create', targetScope: scope.characterId, input, requestId,
|
|
816
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
817
|
+
}, (tx) => management.createSchedule(tx, scope, input));
|
|
818
|
+
return c.json({ ...result, requestId }, 201);
|
|
819
|
+
});
|
|
820
|
+
app.openapi(createRoute({
|
|
821
|
+
method: 'put', path: `${character}/schedules/{scheduleId}`, security,
|
|
822
|
+
request: {
|
|
823
|
+
params: characterParams.extend({ scheduleId: schema.resourceId }),
|
|
824
|
+
headers: schema.versionHeader, body: body(scheduleUpdate),
|
|
825
|
+
},
|
|
826
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
827
|
+
}), async (c) => {
|
|
828
|
+
const { characterId, scheduleId } = c.req.valid('param');
|
|
829
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
830
|
+
const input = c.req.valid('json');
|
|
831
|
+
const expected = version(c.req.valid('header'));
|
|
832
|
+
const requestId = c.get('requestId');
|
|
833
|
+
const result = await management.executeManagementCommand(db, {
|
|
834
|
+
...scope, operation: 'schedule.update', targetScope: characterId + '/' + scheduleId,
|
|
835
|
+
input: { input, expected }, requestId,
|
|
836
|
+
}, (tx) => management.updateSchedule(tx, scope, scheduleId, expected, input));
|
|
837
|
+
return c.json({ ...result, requestId }, 200);
|
|
838
|
+
});
|
|
839
|
+
app.openapi(createRoute({
|
|
840
|
+
method: 'get', path: `${character}/commitment-receipts`, security,
|
|
841
|
+
request: { params: characterParams, query: commitmentReceiptQuery },
|
|
842
|
+
responses: { ...errors, 200: success(schema.pageView(commitmentReceiptView)) },
|
|
843
|
+
}), async (c) => c.json(await management.listCommitmentReceipts(db, { ...c.req.valid('param'), actor: c.get('actor') }, c.req.valid('query')), 200));
|
|
844
|
+
app.openapi(createRoute({
|
|
845
|
+
method: 'get', path: `${character}/commitments`, security,
|
|
846
|
+
request: { params: characterParams, query: commitmentQuery },
|
|
847
|
+
responses: { ...errors, 200: success(schema.pageView(commitmentView)) },
|
|
848
|
+
}), async (c) => c.json(await management.listCommitments(db, { ...c.req.valid('param'), actor: c.get('actor') }, c.req.valid('query')), 200));
|
|
849
|
+
app.openapi(createRoute({
|
|
850
|
+
method: 'post', path: `${character}/commitments`, security,
|
|
851
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(commitmentInput) },
|
|
852
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
853
|
+
}), async (c) => {
|
|
854
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
855
|
+
const input = c.req.valid('json');
|
|
856
|
+
const requestId = c.get('requestId');
|
|
857
|
+
const result = await management.executeManagementCommand(db, {
|
|
858
|
+
...scope, operation: 'commitment.create', targetScope: scope.characterId, input, requestId,
|
|
859
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
860
|
+
}, (tx) => management.createCommitment(tx, scope, input));
|
|
861
|
+
return c.json({ ...result, requestId }, 201);
|
|
862
|
+
});
|
|
863
|
+
app.openapi(createRoute({
|
|
864
|
+
method: 'put', path: `${character}/commitments/{commitmentId}`, security,
|
|
865
|
+
request: {
|
|
866
|
+
params: characterParams.extend({ commitmentId: schema.resourceId }),
|
|
867
|
+
headers: schema.versionHeader, body: body(commitmentUpdate),
|
|
868
|
+
},
|
|
869
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
870
|
+
}), async (c) => {
|
|
871
|
+
const { characterId, commitmentId } = c.req.valid('param');
|
|
872
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
873
|
+
const input = c.req.valid('json');
|
|
874
|
+
const expected = version(c.req.valid('header'));
|
|
875
|
+
const requestId = c.get('requestId');
|
|
876
|
+
const result = await management.executeManagementCommand(db, {
|
|
877
|
+
...scope, operation: 'commitment.update', targetScope: characterId + '/' + commitmentId,
|
|
878
|
+
input: { input, expected }, requestId,
|
|
879
|
+
}, (tx) => management.updateCommitment(tx, scope, commitmentId, expected, input));
|
|
880
|
+
return c.json({ ...result, requestId }, 200);
|
|
881
|
+
});
|
|
882
|
+
app.openapi(createRoute({
|
|
883
|
+
method: 'get', path: `${character}/runs`, security,
|
|
884
|
+
request: { params: characterParams, query: simulationRunQuery },
|
|
885
|
+
responses: { ...errors, 200: success(schema.pageView(simulationRunSummary)) },
|
|
886
|
+
}), async (c) => {
|
|
887
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
888
|
+
const query = c.req.valid('query');
|
|
889
|
+
return c.json(await listSimulationRuns(db, scope, { ...query, ...management.parsePage(query) }), 200);
|
|
890
|
+
});
|
|
891
|
+
app.openapi(createRoute({
|
|
892
|
+
method: 'post', path: `${character}/runs`, security,
|
|
893
|
+
request: { params: characterParams, headers: schema.idempotencyHeader, body: body(consoleSimulationInput) },
|
|
894
|
+
responses: { ...errors, 201: success(schema.commandResponse) },
|
|
895
|
+
}), async (c) => {
|
|
896
|
+
const scope = { ...c.req.valid('param'), actor: c.get('actor') };
|
|
897
|
+
const input = c.req.valid('json');
|
|
898
|
+
const requestId = c.get('requestId');
|
|
899
|
+
const result = await management.executeManagementCommand(db, {
|
|
900
|
+
...scope, operation: 'simulation.start', targetScope: scope.characterId, input, requestId,
|
|
901
|
+
key: c.req.valid('header')['idempotency-key'],
|
|
902
|
+
}, (tx) => startConsoleSimulation(tx, scope, input, resolveAdapter));
|
|
903
|
+
return c.json({ ...result, requestId }, 201);
|
|
904
|
+
});
|
|
905
|
+
app.openapi(createRoute({
|
|
906
|
+
method: 'get', path: `${character}/runs/{runId}/replay`, security,
|
|
907
|
+
request: { params: characterParams.extend({ runId: schema.resourceId }) },
|
|
908
|
+
responses: { ...errors, 200: success(runReplayView) },
|
|
909
|
+
}), async (c) => {
|
|
910
|
+
const { characterId, runId } = c.req.valid('param');
|
|
911
|
+
return c.json(await replaySimulationRun(db, { characterId, actor: c.get('actor') }, runId), 200);
|
|
912
|
+
});
|
|
913
|
+
app.openapi(createRoute({
|
|
914
|
+
method: 'get', path: `${character}/outbox/quarantined`, security,
|
|
915
|
+
request: { params: characterParams, query: outboxQuarantineQuery },
|
|
916
|
+
responses: { ...errors, 200: success(outboxQuarantineView) },
|
|
917
|
+
}), async (c) => c.json(await readQuarantinedOutbox(db, { ...c.req.valid('param'), actor: c.get('actor') }, c.req.valid('query').after), 200));
|
|
918
|
+
app.openapi(createRoute({
|
|
919
|
+
method: 'post', path: `${character}/outbox/{eventId}/retry`, security,
|
|
920
|
+
request: {
|
|
921
|
+
params: characterParams.extend({ eventId: schema.resourceId }),
|
|
922
|
+
headers: schema.versionHeader, body: body(schema.reasonInput),
|
|
923
|
+
},
|
|
924
|
+
responses: { ...errors, 200: success(schema.commandResponse) },
|
|
925
|
+
}), async (c) => {
|
|
926
|
+
const { characterId, eventId } = c.req.valid('param');
|
|
927
|
+
const scope = { characterId, actor: c.get('actor') };
|
|
928
|
+
const expected = version(c.req.valid('header'));
|
|
929
|
+
const requestId = c.get('requestId');
|
|
930
|
+
const result = await management.executeManagementCommand(db, {
|
|
931
|
+
...scope, operation: 'outbox.retry', targetScope: characterId + '/' + eventId,
|
|
932
|
+
input: { ...c.req.valid('json'), expected }, requestId,
|
|
933
|
+
}, (tx) => retryQuarantinedOutbox(tx, scope, eventId, expected));
|
|
934
|
+
return c.json({ ...result, requestId }, 200);
|
|
935
|
+
});
|
|
936
|
+
app.openapi(createRoute({
|
|
937
|
+
method: 'get', path: `${character}/monitoring/daily`, security,
|
|
938
|
+
request: { params: characterParams, query: dailyMetricsQuery },
|
|
939
|
+
responses: { ...errors, 200: success(simulationDailyMetricsView) },
|
|
940
|
+
}), async (c) => c.json(await readSimulationDailyMetrics(db, { ...c.req.valid('param'), actor: c.get('actor') }, c.req.valid('query')), 200));
|
|
941
|
+
app.openapi(createRoute({
|
|
942
|
+
method: 'get', path: `${character}/monitoring`, security,
|
|
943
|
+
request: { params: characterParams },
|
|
944
|
+
responses: { ...errors, 200: success(simulationBacklogView) },
|
|
945
|
+
}), async (c) => c.json(await readSimulationBacklog(db, { ...c.req.valid('param'), actor: c.get('actor') }), 200));
|
|
946
|
+
for (const plugin of plugins)
|
|
947
|
+
plugin.registerRoutes(app);
|
|
948
|
+
app.doc31('/openapi.json', {
|
|
949
|
+
openapi: '3.1.0', info: { title: 'Rica Management API', version: '1.0.0' }, servers: [{ url: '/v1' }],
|
|
950
|
+
});
|
|
951
|
+
return app;
|
|
952
|
+
}
|