@mastra/factory 0.29.0-alpha.4 → 0.29.0-alpha.6
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 +172 -89
- package/dist/boards/board-events.d.ts +89 -9
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +176 -13
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +14 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/busy-card.d.ts +11 -0
- package/dist/boards/busy-card.d.ts.map +1 -0
- package/dist/boards/busy-card.js +15 -0
- package/dist/boards/busy-card.js.map +1 -0
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +18 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/index.d.ts +2 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +3 -2
- package/dist/boards/intake-dry-run.d.ts +109 -0
- package/dist/boards/intake-dry-run.d.ts.map +1 -0
- package/dist/boards/intake-dry-run.js +158 -0
- package/dist/boards/intake-dry-run.js.map +1 -0
- package/dist/boards/intake-lookup.d.ts +32 -0
- package/dist/boards/intake-lookup.d.ts.map +1 -0
- package/dist/boards/intake-lookup.js +12 -0
- package/dist/boards/intake-lookup.js.map +1 -0
- package/dist/boards/intake-order.d.ts +32 -0
- package/dist/boards/intake-order.d.ts.map +1 -0
- package/dist/boards/intake-order.js +60 -0
- package/dist/boards/intake-order.js.map +1 -0
- package/dist/boards/intake-routing.d.ts +246 -35
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +437 -52
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/reroute.d.ts +7 -3
- package/dist/boards/reroute.d.ts.map +1 -1
- package/dist/boards/reroute.js +21 -4
- package/dist/boards/reroute.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -28
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +14 -40
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-routes.d.ts +31 -11
- package/dist/boards/work-routes.d.ts.map +1 -1
- package/dist/boards/work-routes.js +104 -20
- package/dist/boards/work-routes.js.map +1 -1
- package/dist/factory.d.ts +37 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +127 -48
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +9 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +1 -1
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +22 -1
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +23 -5
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/intake-lookup.d.ts +16 -0
- package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/github/intake-lookup.js +76 -0
- package/dist/integrations/github/intake-lookup.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +19 -5
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +21 -6
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/issue-intake.d.ts +15 -0
- package/dist/integrations/github/issue-intake.d.ts.map +1 -0
- package/dist/integrations/github/issue-intake.js +50 -0
- package/dist/integrations/github/issue-intake.js.map +1 -0
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +10 -1
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +14 -2
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +14 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +221 -30
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +30 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +19 -3
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
- package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/gitlab/intake-lookup.js +85 -0
- package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
- package/dist/integrations/gitlab/integration.d.ts +5 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +21 -1
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +20 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +108 -12
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +14 -4
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +12 -2
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +13 -2
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +43 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +82 -7
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
- package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
- package/dist/integrations/platform/connect/session-tools.js +28 -10
- package/dist/integrations/platform/connect/session-tools.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +9 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +6 -6
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +22 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +3 -3
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/integrations/pull-request-head.d.ts +1 -1
- package/dist/integrations/pull-request-head.d.ts.map +1 -1
- package/dist/integrations/pull-request-head.js +5 -0
- package/dist/integrations/pull-request-head.js.map +1 -1
- package/dist/integrations/vanta/rules.js +1 -1
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/integrations/vanta/sync.d.ts +9 -0
- package/dist/integrations/vanta/sync.d.ts.map +1 -1
- package/dist/integrations/vanta/sync.js +10 -1
- package/dist/integrations/vanta/sync.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +13 -6
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +42 -20
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +17 -2
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +247 -77
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +1294 -7
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +603 -20
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/custom-endpoint-url.d.ts +8 -0
- package/dist/routes/custom-endpoint-url.d.ts.map +1 -0
- package/dist/routes/custom-endpoint-url.js +45 -0
- package/dist/routes/custom-endpoint-url.js.map +1 -0
- package/dist/routes/custom-provider-source.d.ts +24 -8
- package/dist/routes/custom-provider-source.d.ts.map +1 -1
- package/dist/routes/custom-provider-source.js +93 -43
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/intake-check.d.ts +92 -0
- package/dist/routes/intake-check.d.ts.map +1 -0
- package/dist/routes/intake-check.js +322 -0
- package/dist/routes/intake-check.js.map +1 -0
- package/dist/routes/intake-routes.d.ts +10 -2
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +292 -11
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/intake.d.ts +6 -0
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +20 -0
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/mastra-gateway.d.ts.map +1 -1
- package/dist/routes/mastra-gateway.js +3 -2
- package/dist/routes/mastra-gateway.js.map +1 -1
- package/dist/routes/project-sessions.d.ts +61 -0
- package/dist/routes/project-sessions.d.ts.map +1 -0
- package/dist/routes/project-sessions.js +135 -0
- package/dist/routes/project-sessions.js.map +1 -0
- package/dist/routes/projects.d.ts +6 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +19 -3
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +10 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +13 -16
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/run-queue.d.ts +6 -6
- package/dist/routes/run-queue.d.ts.map +1 -1
- package/dist/routes/run-queue.js +28 -8
- package/dist/routes/run-queue.js.map +1 -1
- package/dist/routes/session-rows.d.ts +30 -0
- package/dist/routes/session-rows.d.ts.map +1 -0
- package/dist/routes/session-rows.js +94 -0
- package/dist/routes/session-rows.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +4 -5
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +8 -87
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +16 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +41 -30
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.d.ts.map +1 -1
- package/dist/routes/tenant-credentials.js +4 -4
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-item-starters.d.ts +1 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -1
- package/dist/routes/work-item-starters.js +14 -2
- package/dist/routes/work-item-starters.js.map +1 -1
- package/dist/routes/work-items.d.ts +22 -3
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +124 -48
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -1
- package/dist/rules/binding-context.js +51 -5
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatch-errors.js +1 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +39 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +363 -123
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +69 -1
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +151 -5
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/review-source-tool.js +1 -1
- package/dist/rules/rule-group.d.ts +18 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +52 -8
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/run-bearing.d.ts +8 -0
- package/dist/rules/run-bearing.d.ts.map +1 -0
- package/dist/rules/run-bearing.js +11 -0
- package/dist/rules/run-bearing.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +2 -3
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +25 -38
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.js +2 -1
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +16 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +34 -10
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +18 -5
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/update-fold.d.ts +32 -0
- package/dist/rules/update-fold.d.ts.map +1 -0
- package/dist/rules/update-fold.js +60 -0
- package/dist/rules/update-fold.js.map +1 -0
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +54 -6
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +6 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +17 -0
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +2 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/live-sessions.d.ts +6 -1
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +4 -0
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js +2 -3
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/run-audit.d.ts +10 -1
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +9 -1
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +26 -2
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +60 -10
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-row-query.d.ts +25 -0
- package/dist/session/session-row-query.d.ts.map +1 -0
- package/dist/session/session-row-query.js +47 -0
- package/dist/session/session-row-query.js.map +1 -0
- package/dist/session/session-row-status.d.ts +16 -0
- package/dist/session/session-row-status.d.ts.map +1 -0
- package/dist/session/session-row-status.js +14 -0
- package/dist/session/session-row-status.js.map +1 -0
- package/dist/session/session-row-view.d.ts +13 -0
- package/dist/session/session-row-view.d.ts.map +1 -0
- package/dist/session/session-row-view.js +118 -0
- package/dist/session/session-row-view.js.map +1 -0
- package/dist/session/session-rows.d.ts +60 -0
- package/dist/session/session-rows.d.ts.map +1 -0
- package/dist/session/session-rows.js +307 -0
- package/dist/session/session-rows.js.map +1 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +1 -0
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/session-unloader.d.ts +101 -0
- package/dist/session/session-unloader.d.ts.map +1 -0
- package/dist/session/session-unloader.js +278 -0
- package/dist/session/session-unloader.js.map +1 -0
- package/dist/session/source-control-tools.d.ts +14 -7
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +10 -2
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +49 -1
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +118 -15
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/session/work-item-state-processor.d.ts.map +1 -1
- package/dist/session/work-item-state-processor.js +44 -8
- package/dist/session/work-item-state-processor.js.map +1 -1
- package/dist/session-list-changes.d.ts +9 -0
- package/dist/session-list-changes.d.ts.map +1 -0
- package/dist/session-list-changes.js +54 -0
- package/dist/session-list-changes.js.map +1 -0
- package/dist/storage/announced-lists.d.ts +14 -0
- package/dist/storage/announced-lists.d.ts.map +1 -0
- package/dist/storage/announced-lists.js +78 -0
- package/dist/storage/announced-lists.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +3 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +163 -15
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +440 -48
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts +6 -0
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +95 -1
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.d.ts +62 -19
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -1
- package/dist/storage/domains/custom-providers/base.js +131 -100
- package/dist/storage/domains/custom-providers/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +25 -7
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +83 -19
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +19 -10
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +8 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +110 -61
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +8 -5
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +57 -18
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +168 -83
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +3 -2
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +4 -2
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +2 -2
- package/dist/tools/read-tools.d.ts +9 -5
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +61 -54
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts +0 -13
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +128 -341
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +3 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +99 -27
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +4 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +7 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-context-sessions.d.ts +50 -0
- package/dist/work-items/card-context-sessions.d.ts.map +1 -0
- package/dist/work-items/card-context-sessions.js +84 -0
- package/dist/work-items/card-context-sessions.js.map +1 -0
- package/dist/work-items/card-reference.d.ts +21 -0
- package/dist/work-items/card-reference.d.ts.map +1 -0
- package/dist/work-items/card-reference.js +58 -0
- package/dist/work-items/card-reference.js.map +1 -0
- package/dist/work-items/change-requests.d.ts +87 -0
- package/dist/work-items/change-requests.d.ts.map +1 -0
- package/dist/work-items/change-requests.js +134 -0
- package/dist/work-items/change-requests.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +7 -2
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +44 -13
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts.map +1 -1
- package/dist/work-items/list-related-cards.js +1 -1
- package/dist/work-items/list-related-cards.js.map +1 -1
- package/dist/work-items/providers/github.d.ts.map +1 -1
- package/dist/work-items/providers/github.js +1 -0
- package/dist/work-items/providers/github.js.map +1 -1
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +5 -3
- package/factory-skills/factory-self-review/SKILL.md +2 -0
- package/factory-skills/factory-triage/SKILL.md +1 -1
- package/package.json +10 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-endpoint-url.js","names":[],"sources":["../../src/routes/custom-endpoint-url.ts"],"sourcesContent":["import { BlockList, isIP } from 'node:net';\n\nconst LOCAL_ADDRESSES = new BlockList();\nfor (const [address, prefix] of [\n ['0.0.0.0', 8],\n ['10.0.0.0', 8],\n ['100.64.0.0', 10],\n ['127.0.0.0', 8],\n ['169.254.0.0', 16],\n ['172.16.0.0', 12],\n ['192.168.0.0', 16],\n] as const) {\n LOCAL_ADDRESSES.addSubnet(address, prefix, 'ipv4');\n}\nfor (const [address, prefix] of [\n ['::', 128],\n ['::1', 128],\n ['fc00::', 7],\n ['fe80::', 10],\n] as const) {\n LOCAL_ADDRESSES.addSubnet(address, prefix, 'ipv6');\n}\n\nconst LOCAL_HOSTNAME = /(^|\\.)(localhost|local|internal)$/;\n\n/** The platform stamps every deploy with its id; a Factory run anywhere else has none. */\nfunction hostedOnPlatform(): boolean {\n return Boolean(process.env.MASTRA_DEPLOYMENT_ID?.trim());\n}\n\n/**\n * Why a hosted Factory refuses to call `url`, or `undefined` when it may.\n * The server makes these calls, so a hosted one must not be pointed at its own\n * network or the cloud metadata service. Local and self-hosted Factories keep\n * reaching endpoints on their machine or network (Ollama, vLLM).\n */\nexport function customEndpointUrlProblem(url: string): string | undefined {\n if (!hostedOnPlatform()) return undefined;\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return 'Enter a valid URL.';\n }\n if (parsed.protocol !== 'https:')\n return 'Use an HTTPS address: a hosted Factory only calls custom endpoints over HTTPS.';\n const host = parsed.hostname.replace(/^\\[|\\]$/g, '').toLowerCase();\n const family = isIP(host);\n const local = family\n ? LOCAL_ADDRESSES.check(host, family === 6 ? 'ipv6' : 'ipv4')\n : LOCAL_HOSTNAME.test(host.replace(/\\.$/, ''));\n if (local) return 'Use an address reachable over the internet, not a local or private network one.';\n return undefined;\n}\n"],"mappings":";;AAEA,MAAM,kBAAkB,IAAI,UAAU;AACtC,KAAK,MAAM,CAAC,SAAS,WAAW;CAC9B,CAAC,WAAW,CAAC;CACb,CAAC,YAAY,CAAC;CACd,CAAC,cAAc,EAAE;CACjB,CAAC,aAAa,CAAC;CACf,CAAC,eAAe,EAAE;CAClB,CAAC,cAAc,EAAE;CACjB,CAAC,eAAe,EAAE;AACpB,GACE,gBAAgB,UAAU,SAAS,QAAQ,MAAM;AAEnD,KAAK,MAAM,CAAC,SAAS,WAAW;CAC9B,CAAC,MAAM,GAAG;CACV,CAAC,OAAO,GAAG;CACX,CAAC,UAAU,CAAC;CACZ,CAAC,UAAU,EAAE;AACf,GACE,gBAAgB,UAAU,SAAS,QAAQ,MAAM;AAGnD,MAAM,iBAAiB;;AAGvB,SAAS,mBAA4B;CACnC,OAAO,QAAQ,QAAQ,IAAI,sBAAsB,KAAK,CAAC;AACzD;;;;;;;AAQA,SAAgB,yBAAyB,KAAiC;CACxE,IAAI,CAAC,iBAAiB,GAAG,OAAO,KAAA;CAChC,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,GAAG;CACtB,QAAQ;EACN,OAAO;CACT;CACA,IAAI,OAAO,aAAa,UACtB,OAAO;CACT,MAAM,OAAO,OAAO,SAAS,QAAQ,YAAY,EAAE,CAAC,CAAC,YAAY;CACjE,MAAM,SAAS,KAAK,IAAI;CAIxB,IAHc,SACV,gBAAgB,MAAM,MAAM,WAAW,IAAI,SAAS,MAAM,IAC1D,eAAe,KAAK,KAAK,QAAQ,OAAO,EAAE,CAAC,GACpC,OAAO;AAEpB"}
|
|
@@ -5,21 +5,37 @@
|
|
|
5
5
|
* `CustomProvidersSource` synchronously, so this module keeps a small per-org
|
|
6
6
|
* **snapshot** of custom provider rows hydrated from the `custom-providers`
|
|
7
7
|
* domain. Once registered the source is authoritative — the factory never
|
|
8
|
-
* reads `settings.json` custom providers, in either auth mode
|
|
8
|
+
* reads `settings.json` custom providers, in either auth mode.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Whose rows a call sees is decided in one place, {@link customProviderOwner},
|
|
11
|
+
* which the settings routes and model catalogs use too. Calls without an
|
|
12
|
+
* authenticated tenant in tenant mode (the boot-time catalog) resolve to an
|
|
13
|
+
* empty list.
|
|
14
14
|
*
|
|
15
15
|
* Snapshots are primed per request by `createCustomProvidersPrimer` (mounted
|
|
16
16
|
* after the web auth gate) and invalidated on writes via
|
|
17
17
|
* `invalidateCustomProvidersSnapshots` so changes are visible immediately.
|
|
18
18
|
*/
|
|
19
|
+
import type { CredentialScope } from '@mastra/code-sdk/agents/credential-resolver';
|
|
19
20
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
20
21
|
import type { MiddlewareHandler } from 'hono';
|
|
21
|
-
import type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';
|
|
22
|
+
import type { CustomProviderOwner, CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';
|
|
22
23
|
import type { RouteAuth } from './route.js';
|
|
24
|
+
/**
|
|
25
|
+
* Whose custom providers apply to a tenant at a credential scope, or
|
|
26
|
+
* `undefined` to fail closed (tenant mode without identity). Model
|
|
27
|
+
* resolution, the settings routes and the model catalogs all decide through
|
|
28
|
+
* this function, so what a user sees in Settings is what their models use.
|
|
29
|
+
*
|
|
30
|
+
* Scoped exactly like provider credentials: Factory-scoped work uses the
|
|
31
|
+
* organization's list, personal work the account's own, and the two never
|
|
32
|
+
* mix. No-auth mode has one shared list.
|
|
33
|
+
*/
|
|
34
|
+
export declare function customProviderOwner(tenant: {
|
|
35
|
+
orgId?: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
credentialScope?: CredentialScope;
|
|
38
|
+
} | undefined, authEnabled: boolean): CustomProviderOwner | undefined;
|
|
23
39
|
/**
|
|
24
40
|
* Register the DB-backed custom providers source with the SDK. Called by the
|
|
25
41
|
* factory after storage init with the `custom-providers` domain handle; from
|
|
@@ -31,8 +47,8 @@ export declare function registerCustomProvidersSource({ storage, authEnabled, }:
|
|
|
31
47
|
authEnabled: boolean;
|
|
32
48
|
}): void;
|
|
33
49
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
50
|
+
* After a custom provider write, reload the org's snapshot on its next read
|
|
51
|
+
* instead of after the TTL, so the change reaches the next request at once.
|
|
36
52
|
*/
|
|
37
53
|
export declare function invalidateCustomProvidersSnapshots(tenant: {
|
|
38
54
|
orgId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-provider-source.d.ts","sourceRoot":"","sources":["../../src/routes/custom-provider-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"custom-provider-source.d.ts","sourceRoot":"","sources":["../../src/routes/custom-provider-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAGnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAG/G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAA;CAAE,GAAG,SAAS,EACzF,WAAW,EAAE,OAAO,GACnB,mBAAmB,GAAG,SAAS,CAKjC;AAiGD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,OAAO,EACP,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,sBAAsB,CAAC;IAChC,WAAW,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,CASP;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAElF;AAED,8DAA8D;AAC9D,wBAAgB,kCAAkC,IAAI,IAAI,CAIzD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,IAAI,EACJ,OAAO,EACP,WAAW,GACZ,EAAE;IACD,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,sBAAsB,CAAC;IAChC,WAAW,EAAE,OAAO,CAAC;CACtB,GAAG,iBAAiB,CAYpB;AAED;;;;;GAKG;AACH,wBAAsB,qCAAqC,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CASzG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { customEndpointUrlProblem } from "./custom-endpoint-url.js";
|
|
1
2
|
import { tenantOrgId } from "./provider-credentials.js";
|
|
2
3
|
import { resolveTenantFromRequestContext } from "@mastra/code-sdk/agents/credential-resolver";
|
|
3
4
|
import { setCustomProvidersSource } from "@mastra/code-sdk/agents/custom-provider-source";
|
|
@@ -9,12 +10,12 @@ import { setCustomProvidersSource } from "@mastra/code-sdk/agents/custom-provide
|
|
|
9
10
|
* `CustomProvidersSource` synchronously, so this module keeps a small per-org
|
|
10
11
|
* **snapshot** of custom provider rows hydrated from the `custom-providers`
|
|
11
12
|
* domain. Once registered the source is authoritative — the factory never
|
|
12
|
-
* reads `settings.json` custom providers, in either auth mode
|
|
13
|
+
* reads `settings.json` custom providers, in either auth mode.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Whose rows a call sees is decided in one place, {@link customProviderOwner},
|
|
16
|
+
* which the settings routes and model catalogs use too. Calls without an
|
|
17
|
+
* authenticated tenant in tenant mode (the boot-time catalog) resolve to an
|
|
18
|
+
* empty list.
|
|
18
19
|
*
|
|
19
20
|
* Snapshots are primed per request by `createCustomProvidersPrimer` (mounted
|
|
20
21
|
* after the web auth gate) and invalidated on writes via
|
|
@@ -24,41 +25,94 @@ import { setCustomProvidersSource } from "@mastra/code-sdk/agents/custom-provide
|
|
|
24
25
|
const SNAPSHOT_TTL_MS = 15e3;
|
|
25
26
|
/** Cap on cached org snapshots; oldest-inserted evicted beyond this. */
|
|
26
27
|
const MAX_CACHED_ORGS = 1e3;
|
|
27
|
-
/** Sentinel org for no-auth mode
|
|
28
|
+
/** Sentinel org for no-auth mode. */
|
|
28
29
|
const LOCAL_ORG = "local";
|
|
30
|
+
/**
|
|
31
|
+
* Whose custom providers apply to a tenant at a credential scope, or
|
|
32
|
+
* `undefined` to fail closed (tenant mode without identity). Model
|
|
33
|
+
* resolution, the settings routes and the model catalogs all decide through
|
|
34
|
+
* this function, so what a user sees in Settings is what their models use.
|
|
35
|
+
*
|
|
36
|
+
* Scoped exactly like provider credentials: Factory-scoped work uses the
|
|
37
|
+
* organization's list, personal work the account's own, and the two never
|
|
38
|
+
* mix. No-auth mode has one shared list.
|
|
39
|
+
*/
|
|
40
|
+
function customProviderOwner(tenant, authEnabled) {
|
|
41
|
+
if (!authEnabled) return { orgId: LOCAL_ORG };
|
|
42
|
+
if (!tenant) return void 0;
|
|
43
|
+
const orgId = tenantOrgId(tenant);
|
|
44
|
+
return tenant.credentialScope === "factory" ? { orgId } : {
|
|
45
|
+
orgId,
|
|
46
|
+
userId: tenant.userId
|
|
47
|
+
};
|
|
48
|
+
}
|
|
29
49
|
var OrgCustomProvidersSnapshot = class {
|
|
30
50
|
#orgId;
|
|
31
51
|
#storage;
|
|
32
|
-
#
|
|
52
|
+
#organization = [];
|
|
53
|
+
#members = /* @__PURE__ */ new Map();
|
|
33
54
|
#fetchedAt = 0;
|
|
55
|
+
/** Bumped by every write, so a load that started before it can't count as fresh. */
|
|
56
|
+
#generation = 0;
|
|
34
57
|
#hydrating;
|
|
35
58
|
constructor(orgId, storage) {
|
|
36
59
|
this.#orgId = orgId;
|
|
37
60
|
this.#storage = storage;
|
|
38
61
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (now - this.#fetchedAt < SNAPSHOT_TTL_MS) return;
|
|
42
|
-
this.#hydrating ??= this.#hydrate().finally(() => {
|
|
43
|
-
this.#hydrating = void 0;
|
|
44
|
-
});
|
|
45
|
-
await this.#hydrating;
|
|
62
|
+
#isStale() {
|
|
63
|
+
return Date.now() - this.#fetchedAt >= SNAPSHOT_TTL_MS;
|
|
46
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Hydrate the snapshot when stale; coalesces concurrent callers. Loads again
|
|
67
|
+
* if a write lands while a load is in flight, so callers never settle for
|
|
68
|
+
* rows read before that write.
|
|
69
|
+
*/
|
|
70
|
+
async ensureFresh() {
|
|
71
|
+
while (this.#isStale()) {
|
|
72
|
+
this.#hydrating ??= this.#hydrate().finally(() => {
|
|
73
|
+
this.#hydrating = void 0;
|
|
74
|
+
});
|
|
75
|
+
await this.#hydrating;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* After a write: load again on the next read, but keep serving the current
|
|
80
|
+
* rows meanwhile, so runs already using these providers don't lose them.
|
|
81
|
+
*/
|
|
82
|
+
markStale() {
|
|
83
|
+
this.#generation += 1;
|
|
84
|
+
this.#fetchedAt = 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Loads the organization's providers and every member's in one pass: a
|
|
88
|
+
* session can run as its owner while another member's request primed the
|
|
89
|
+
* snapshot, so any owner in the org must be servable without a second query.
|
|
90
|
+
*/
|
|
47
91
|
async #hydrate() {
|
|
92
|
+
const generation = this.#generation;
|
|
48
93
|
await this.#storage.ensureReady();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
94
|
+
const organization = [];
|
|
95
|
+
const members = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const record of await this.#storage.listForOrg(this.#orgId)) {
|
|
97
|
+
if (customEndpointUrlProblem(record.url)) continue;
|
|
98
|
+
const provider = {
|
|
99
|
+
name: record.name,
|
|
100
|
+
url: record.url,
|
|
101
|
+
apiKey: record.apiKey ?? void 0,
|
|
102
|
+
models: record.models
|
|
103
|
+
};
|
|
104
|
+
const owned = record.userId === null ? organization : members.get(record.userId) ?? [];
|
|
105
|
+
owned.push(provider);
|
|
106
|
+
if (record.userId !== null) members.set(record.userId, owned);
|
|
107
|
+
}
|
|
108
|
+
this.#organization = organization;
|
|
109
|
+
this.#members = members;
|
|
110
|
+
if (generation === this.#generation) this.#fetchedAt = Date.now();
|
|
57
111
|
}
|
|
58
112
|
/** Sync by contract; kicks a background re-hydrate when the snapshot is stale. */
|
|
59
|
-
get() {
|
|
60
|
-
if (
|
|
61
|
-
return this.#
|
|
113
|
+
get(owner) {
|
|
114
|
+
if (this.#isStale()) this.ensureFresh().catch(() => {});
|
|
115
|
+
return owner.userId === void 0 ? this.#organization : this.#members.get(owner.userId) ?? [];
|
|
62
116
|
}
|
|
63
117
|
};
|
|
64
118
|
const orgSnapshots = /* @__PURE__ */ new Map();
|
|
@@ -75,11 +129,6 @@ function snapshotFor(orgId, storage) {
|
|
|
75
129
|
}
|
|
76
130
|
return snapshot;
|
|
77
131
|
}
|
|
78
|
-
/** The org a call resolves to, or `undefined` to fail closed (tenant mode without identity). */
|
|
79
|
-
function orgForTenant(tenant, authEnabled) {
|
|
80
|
-
if (!authEnabled) return LOCAL_ORG;
|
|
81
|
-
return tenant ? tenantOrgId(tenant) : void 0;
|
|
82
|
-
}
|
|
83
132
|
/**
|
|
84
133
|
* Register the DB-backed custom providers source with the SDK. Called by the
|
|
85
134
|
* factory after storage init with the `custom-providers` domain handle; from
|
|
@@ -91,18 +140,19 @@ function registerCustomProvidersSource({ storage, authEnabled }) {
|
|
|
91
140
|
storage,
|
|
92
141
|
authEnabled
|
|
93
142
|
};
|
|
143
|
+
orgSnapshots.clear();
|
|
94
144
|
setCustomProvidersSource((tenant) => {
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
return snapshotFor(orgId, storage).get();
|
|
145
|
+
const owner = customProviderOwner(tenant, authEnabled);
|
|
146
|
+
if (!owner) return [];
|
|
147
|
+
return snapshotFor(owner.orgId, storage).get(owner);
|
|
98
148
|
});
|
|
99
149
|
}
|
|
100
150
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
151
|
+
* After a custom provider write, reload the org's snapshot on its next read
|
|
152
|
+
* instead of after the TTL, so the change reaches the next request at once.
|
|
103
153
|
*/
|
|
104
154
|
function invalidateCustomProvidersSnapshots(tenant) {
|
|
105
|
-
orgSnapshots.
|
|
155
|
+
orgSnapshots.get(tenant.orgId)?.markStale();
|
|
106
156
|
}
|
|
107
157
|
/** Test hook: clear registration and cached org snapshots. */
|
|
108
158
|
function resetCustomProvidersSourceForTests() {
|
|
@@ -118,9 +168,9 @@ function resetCustomProvidersSourceForTests() {
|
|
|
118
168
|
*/
|
|
119
169
|
function createCustomProvidersPrimer({ auth, storage, authEnabled }) {
|
|
120
170
|
return async (c, next) => {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
await snapshotFor(orgId, storage).ensureFresh();
|
|
171
|
+
const owner = customProviderOwner(auth.tenant(c), authEnabled);
|
|
172
|
+
if (owner) try {
|
|
173
|
+
await snapshotFor(owner.orgId, storage).ensureFresh();
|
|
124
174
|
} catch {}
|
|
125
175
|
await next();
|
|
126
176
|
};
|
|
@@ -133,12 +183,12 @@ function createCustomProvidersPrimer({ auth, storage, authEnabled }) {
|
|
|
133
183
|
*/
|
|
134
184
|
async function primeCustomProvidersForRequestContext(requestContext) {
|
|
135
185
|
if (!registered) return;
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
186
|
+
const owner = customProviderOwner(resolveTenantFromRequestContext(requestContext), registered.authEnabled);
|
|
187
|
+
if (!owner) return;
|
|
138
188
|
try {
|
|
139
|
-
await snapshotFor(orgId, registered.storage).ensureFresh();
|
|
189
|
+
await snapshotFor(owner.orgId, registered.storage).ensureFresh();
|
|
140
190
|
} catch {}
|
|
141
191
|
}
|
|
142
|
-
export { createCustomProvidersPrimer, invalidateCustomProvidersSnapshots, primeCustomProvidersForRequestContext, registerCustomProvidersSource, resetCustomProvidersSourceForTests };
|
|
192
|
+
export { createCustomProvidersPrimer, customProviderOwner, invalidateCustomProvidersSnapshots, primeCustomProvidersForRequestContext, registerCustomProvidersSource, resetCustomProvidersSourceForTests };
|
|
143
193
|
|
|
144
194
|
//# sourceMappingURL=custom-provider-source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-provider-source.js","names":[],"sources":["../../src/routes/custom-provider-source.ts"],"sourcesContent":["/**\n * DB-backed custom providers source for model resolution (factory mode).\n *\n * The SDK's `resolveModel` and gateway catalog ask the registered\n * `CustomProvidersSource` synchronously, so this module keeps a small per-org\n * **snapshot** of custom provider rows hydrated from the `custom-providers`\n * domain. Once registered the source is authoritative — the factory never\n * reads `settings.json` custom providers, in either auth mode:\n *\n * - tenant mode: rows are scoped per org (`tenantOrgId`); calls without an\n * authenticated tenant (boot-time catalog) resolve to an empty list.\n * - no-auth/local mode: rows live under the sentinel `local` org, matching the\n * custom provider routes.\n *\n * Snapshots are primed per request by `createCustomProvidersPrimer` (mounted\n * after the web auth gate) and invalidated on writes via\n * `invalidateCustomProvidersSnapshots` so changes are visible immediately.\n */\n\nimport { resolveTenantFromRequestContext } from '@mastra/code-sdk/agents/credential-resolver';\nimport { setCustomProvidersSource } from '@mastra/code-sdk/agents/custom-provider-source';\nimport type { MastraCodeCustomProvider } from '@mastra/code-sdk/agents/mastracode-gateway';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { MiddlewareHandler } from 'hono';\n\nimport type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport { tenantOrgId } from './provider-credentials.js';\nimport type { RouteAuth } from './route.js';\n\n/** How long a hydrated snapshot is considered fresh. */\nconst SNAPSHOT_TTL_MS = 15_000;\n\n/** Cap on cached org snapshots; oldest-inserted evicted beyond this. */\nconst MAX_CACHED_ORGS = 1000;\n\n/** Sentinel org for no-auth mode — must match the custom provider routes. */\nconst LOCAL_ORG = 'local';\n\nclass OrgCustomProvidersSnapshot {\n readonly #orgId: string;\n readonly #storage: CustomProvidersStorage;\n #snapshot: MastraCodeCustomProvider[] = [];\n #fetchedAt = 0;\n #hydrating: Promise<void> | undefined;\n\n constructor(orgId: string, storage: CustomProvidersStorage) {\n this.#orgId = orgId;\n this.#storage = storage;\n }\n\n /** Hydrate the snapshot when stale; coalesces concurrent callers. */\n async ensureFresh(now = Date.now()): Promise<void> {\n if (now - this.#fetchedAt < SNAPSHOT_TTL_MS) return;\n this.#hydrating ??= this.#hydrate().finally(() => {\n this.#hydrating = undefined;\n });\n await this.#hydrating;\n }\n\n async #hydrate(): Promise<void> {\n await this.#storage.ensureReady();\n const records = await this.#storage.list({ orgId: this.#orgId });\n this.#snapshot = records.map(record => ({\n name: record.name,\n url: record.url,\n apiKey: record.apiKey ?? undefined,\n models: record.models,\n }));\n this.#fetchedAt = Date.now();\n }\n\n /** Sync by contract; kicks a background re-hydrate when the snapshot is stale. */\n get(): MastraCodeCustomProvider[] {\n if (Date.now() - this.#fetchedAt >= SNAPSHOT_TTL_MS) {\n void this.ensureFresh().catch(() => {});\n }\n return this.#snapshot;\n }\n}\n\nconst orgSnapshots = new Map<string, OrgCustomProvidersSnapshot>();\n\nlet registered: { storage: CustomProvidersStorage; authEnabled: boolean } | undefined;\n\nfunction snapshotFor(orgId: string, storage: CustomProvidersStorage): OrgCustomProvidersSnapshot {\n let snapshot = orgSnapshots.get(orgId);\n if (!snapshot) {\n if (orgSnapshots.size >= MAX_CACHED_ORGS) {\n const oldest = orgSnapshots.keys().next().value;\n if (oldest !== undefined) orgSnapshots.delete(oldest);\n }\n snapshot = new OrgCustomProvidersSnapshot(orgId, storage);\n orgSnapshots.set(orgId, snapshot);\n }\n return snapshot;\n}\n\n/** The org a call resolves to, or `undefined` to fail closed (tenant mode without identity). */\nfunction orgForTenant(\n tenant: { orgId?: string; userId: string } | undefined,\n authEnabled: boolean,\n): string | undefined {\n if (!authEnabled) return LOCAL_ORG;\n return tenant ? tenantOrgId(tenant) : undefined;\n}\n\n/**\n * Register the DB-backed custom providers source with the SDK. Called by the\n * factory after storage init with the `custom-providers` domain handle; from\n * then on model resolution and the gateway catalog never read settings.json\n * custom providers.\n */\nexport function registerCustomProvidersSource({\n storage,\n authEnabled,\n}: {\n storage: CustomProvidersStorage;\n authEnabled: boolean;\n}): void {\n registered = { storage, authEnabled };\n setCustomProvidersSource(tenant => {\n const orgId = orgForTenant(tenant, authEnabled);\n if (!orgId) return [];\n return snapshotFor(orgId, storage).get();\n });\n}\n\n/**\n * Drop the org's cached snapshot after a custom provider write so the change\n * is visible to the next model call immediately instead of after the TTL.\n */\nexport function invalidateCustomProvidersSnapshots(tenant: { orgId: string }): void {\n orgSnapshots.delete(tenant.orgId);\n}\n\n/** Test hook: clear registration and cached org snapshots. */\nexport function resetCustomProvidersSourceForTests(): void {\n setCustomProvidersSource(undefined);\n registered = undefined;\n orgSnapshots.clear();\n}\n\n/**\n * Middleware mounted after the web auth gate: primes the caller's org snapshot\n * so the request's first model call sees their custom providers without an\n * async seam in model resolution. Cheap when fresh (TTL check), best-effort\n * when not — a failed hydrate serves the last snapshot, never blocks a request.\n */\nexport function createCustomProvidersPrimer({\n auth,\n storage,\n authEnabled,\n}: {\n auth: RouteAuth;\n storage: CustomProvidersStorage;\n authEnabled: boolean;\n}): MiddlewareHandler {\n return async (c, next) => {\n const orgId = orgForTenant(auth.tenant(c), authEnabled);\n if (orgId) {\n try {\n await snapshotFor(orgId, storage).ensureFresh();\n } catch {\n // Fail open: model calls serve the last snapshot (or none).\n }\n }\n await next();\n };\n}\n\n/**\n * Prime the org snapshot for a run that has no inbound request (a notification\n * or peer-signal wake), so its first model call can resolve a custom-provider\n * model. Best-effort like the request primer: a failed hydrate serves the last\n * snapshot.\n */\nexport async function primeCustomProvidersForRequestContext(requestContext: RequestContext): Promise<void> {\n if (!registered) return;\n const orgId = orgForTenant(resolveTenantFromRequestContext(requestContext), registered.authEnabled);\n if (!orgId) return;\n try {\n await snapshotFor(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AA2B,OAAO,OAAO;EACxD,aAAa,IAAI,OAAO,QAAQ;CAClC;CACA,OAAO;AACT;;AAGA,SAAS,aACP,QACA,aACoB;CACpB,IAAI,CAAC,aAAa,OAAO;CACzB,OAAO,SAAS,YAAY,MAAM,IAAI,KAAA;AACxC;;;;;;;AAQA,SAAgB,8BAA8B,EAC5C,SACA,eAIO;CACP,aAAa;EAAE;EAAS;CAAY;CACpC,0BAAyB,WAAU;EACjC,MAAM,QAAQ,aAAa,QAAQ,WAAW;EAC9C,IAAI,CAAC,OAAO,OAAO,CAAC;EACpB,OAAO,YAAY,OAAO,OAAO,CAAC,CAAC,IAAI;CACzC,CAAC;AACH;;;;;AAMA,SAAgB,mCAAmC,QAAiC;CAClF,aAAa,OAAO,OAAO,KAAK;AAClC;;AAGA,SAAgB,qCAA2C;CACzD,yBAAyB,KAAA,CAAS;CAClC,aAAa,KAAA;CACb,aAAa,MAAM;AACrB;;;;;;;AAQA,SAAgB,4BAA4B,EAC1C,MACA,SACA,eAKoB;CACpB,OAAO,OAAO,GAAG,SAAS;EACxB,MAAM,QAAQ,aAAa,KAAK,OAAO,CAAC,GAAG,WAAW;EACtD,IAAI,OACF,IAAI;GACF,MAAM,YAAY,OAAO,OAAO,CAAC,CAAC,YAAY;EAChD,QAAQ,CAER;EAEF,MAAM,KAAK;CACb;AACF;;;;;;;AAQA,eAAsB,sCAAsC,gBAA+C;CACzG,IAAI,CAAC,YAAY;CACjB,MAAM,QAAQ,aAAa,gCAAgC,cAAc,GAAG,WAAW,WAAW;CAClG,IAAI,CAAC,OAAO;CACZ,IAAI;EACF,MAAM,YAAY,OAAO,WAAW,OAAO,CAAC,CAAC,YAAY;CAC3D,QAAQ,CAER;AACF"}
|
|
1
|
+
{"version":3,"file":"custom-provider-source.js","names":[],"sources":["../../src/routes/custom-provider-source.ts"],"sourcesContent":["/**\n * DB-backed custom providers source for model resolution (factory mode).\n *\n * The SDK's `resolveModel` and gateway catalog ask the registered\n * `CustomProvidersSource` synchronously, so this module keeps a small per-org\n * **snapshot** of custom provider rows hydrated from the `custom-providers`\n * domain. Once registered the source is authoritative — the factory never\n * reads `settings.json` custom providers, in either auth mode.\n *\n * Whose rows a call sees is decided in one place, {@link customProviderOwner},\n * which the settings routes and model catalogs use too. Calls without an\n * authenticated tenant in tenant mode (the boot-time catalog) resolve to an\n * empty list.\n *\n * Snapshots are primed per request by `createCustomProvidersPrimer` (mounted\n * after the web auth gate) and invalidated on writes via\n * `invalidateCustomProvidersSnapshots` so changes are visible immediately.\n */\n\nimport { resolveTenantFromRequestContext } from '@mastra/code-sdk/agents/credential-resolver';\nimport type { CredentialScope } from '@mastra/code-sdk/agents/credential-resolver';\nimport { setCustomProvidersSource } from '@mastra/code-sdk/agents/custom-provider-source';\nimport type { MastraCodeCustomProvider } from '@mastra/code-sdk/agents/mastracode-gateway';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { MiddlewareHandler } from 'hono';\n\nimport type { CustomProviderOwner, CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport { customEndpointUrlProblem } from './custom-endpoint-url.js';\nimport { tenantOrgId } from './provider-credentials.js';\nimport type { RouteAuth } from './route.js';\n\n/** How long a hydrated snapshot is considered fresh. */\nconst SNAPSHOT_TTL_MS = 15_000;\n\n/** Cap on cached org snapshots; oldest-inserted evicted beyond this. */\nconst MAX_CACHED_ORGS = 1000;\n\n/** Sentinel org for no-auth mode. */\nconst LOCAL_ORG = 'local';\n\n/**\n * Whose custom providers apply to a tenant at a credential scope, or\n * `undefined` to fail closed (tenant mode without identity). Model\n * resolution, the settings routes and the model catalogs all decide through\n * this function, so what a user sees in Settings is what their models use.\n *\n * Scoped exactly like provider credentials: Factory-scoped work uses the\n * organization's list, personal work the account's own, and the two never\n * mix. No-auth mode has one shared list.\n */\nexport function customProviderOwner(\n tenant: { orgId?: string; userId: string; credentialScope?: CredentialScope } | undefined,\n authEnabled: boolean,\n): CustomProviderOwner | undefined {\n if (!authEnabled) return { orgId: LOCAL_ORG };\n if (!tenant) return undefined;\n const orgId = tenantOrgId(tenant);\n return tenant.credentialScope === 'factory' ? { orgId } : { orgId, userId: tenant.userId };\n}\n\nclass OrgCustomProvidersSnapshot {\n readonly #orgId: string;\n readonly #storage: CustomProvidersStorage;\n #organization: MastraCodeCustomProvider[] = [];\n #members = new Map<string, MastraCodeCustomProvider[]>();\n #fetchedAt = 0;\n /** Bumped by every write, so a load that started before it can't count as fresh. */\n #generation = 0;\n #hydrating: Promise<void> | undefined;\n\n constructor(orgId: string, storage: CustomProvidersStorage) {\n this.#orgId = orgId;\n this.#storage = storage;\n }\n\n #isStale(): boolean {\n return Date.now() - this.#fetchedAt >= SNAPSHOT_TTL_MS;\n }\n\n /**\n * Hydrate the snapshot when stale; coalesces concurrent callers. Loads again\n * if a write lands while a load is in flight, so callers never settle for\n * rows read before that write.\n */\n async ensureFresh(): Promise<void> {\n while (this.#isStale()) {\n this.#hydrating ??= this.#hydrate().finally(() => {\n this.#hydrating = undefined;\n });\n await this.#hydrating;\n }\n }\n\n /**\n * After a write: load again on the next read, but keep serving the current\n * rows meanwhile, so runs already using these providers don't lose them.\n */\n markStale(): void {\n this.#generation += 1;\n this.#fetchedAt = 0;\n }\n\n /**\n * Loads the organization's providers and every member's in one pass: a\n * session can run as its owner while another member's request primed the\n * snapshot, so any owner in the org must be servable without a second query.\n */\n async #hydrate(): Promise<void> {\n const generation = this.#generation;\n await this.#storage.ensureReady();\n const organization: MastraCodeCustomProvider[] = [];\n const members = new Map<string, MastraCodeCustomProvider[]>();\n for (const record of await this.#storage.listForOrg(this.#orgId)) {\n if (customEndpointUrlProblem(record.url)) continue;\n const provider: MastraCodeCustomProvider = {\n name: record.name,\n url: record.url,\n apiKey: record.apiKey ?? undefined,\n models: record.models,\n };\n const owned = record.userId === null ? organization : (members.get(record.userId) ?? []);\n owned.push(provider);\n if (record.userId !== null) members.set(record.userId, owned);\n }\n this.#organization = organization;\n this.#members = members;\n if (generation === this.#generation) this.#fetchedAt = Date.now();\n }\n\n /** Sync by contract; kicks a background re-hydrate when the snapshot is stale. */\n get(owner: CustomProviderOwner): MastraCodeCustomProvider[] {\n if (this.#isStale()) {\n void this.ensureFresh().catch(() => {});\n }\n return owner.userId === undefined ? this.#organization : (this.#members.get(owner.userId) ?? []);\n }\n}\n\nconst orgSnapshots = new Map<string, OrgCustomProvidersSnapshot>();\n\nlet registered: { storage: CustomProvidersStorage; authEnabled: boolean } | undefined;\n\nfunction snapshotFor(orgId: string, storage: CustomProvidersStorage): OrgCustomProvidersSnapshot {\n let snapshot = orgSnapshots.get(orgId);\n if (!snapshot) {\n if (orgSnapshots.size >= MAX_CACHED_ORGS) {\n const oldest = orgSnapshots.keys().next().value;\n if (oldest !== undefined) orgSnapshots.delete(oldest);\n }\n snapshot = new OrgCustomProvidersSnapshot(orgId, storage);\n orgSnapshots.set(orgId, snapshot);\n }\n return snapshot;\n}\n\n/**\n * Register the DB-backed custom providers source with the SDK. Called by the\n * factory after storage init with the `custom-providers` domain handle; from\n * then on model resolution and the gateway catalog never read settings.json\n * custom providers.\n */\nexport function registerCustomProvidersSource({\n storage,\n authEnabled,\n}: {\n storage: CustomProvidersStorage;\n authEnabled: boolean;\n}): void {\n registered = { storage, authEnabled };\n // Snapshots read the storage they were created with.\n orgSnapshots.clear();\n setCustomProvidersSource(tenant => {\n const owner = customProviderOwner(tenant, authEnabled);\n if (!owner) return [];\n return snapshotFor(owner.orgId, storage).get(owner);\n });\n}\n\n/**\n * After a custom provider write, reload the org's snapshot on its next read\n * instead of after the TTL, so the change reaches the next request at once.\n */\nexport function invalidateCustomProvidersSnapshots(tenant: { orgId: string }): void {\n orgSnapshots.get(tenant.orgId)?.markStale();\n}\n\n/** Test hook: clear registration and cached org snapshots. */\nexport function resetCustomProvidersSourceForTests(): void {\n setCustomProvidersSource(undefined);\n registered = undefined;\n orgSnapshots.clear();\n}\n\n/**\n * Middleware mounted after the web auth gate: primes the caller's org snapshot\n * so the request's first model call sees their custom providers without an\n * async seam in model resolution. Cheap when fresh (TTL check), best-effort\n * when not — a failed hydrate serves the last snapshot, never blocks a request.\n */\nexport function createCustomProvidersPrimer({\n auth,\n storage,\n authEnabled,\n}: {\n auth: RouteAuth;\n storage: CustomProvidersStorage;\n authEnabled: boolean;\n}): MiddlewareHandler {\n return async (c, next) => {\n const owner = customProviderOwner(auth.tenant(c), authEnabled);\n if (owner) {\n try {\n await snapshotFor(owner.orgId, storage).ensureFresh();\n } catch {\n // Fail open: model calls serve the last snapshot (or none).\n }\n }\n await next();\n };\n}\n\n/**\n * Prime the org snapshot for a run that has no inbound request (a notification\n * or peer-signal wake), so its first model call can resolve a custom-provider\n * model. Best-effort like the request primer: a failed hydrate serves the last\n * snapshot.\n */\nexport async function primeCustomProvidersForRequestContext(requestContext: RequestContext): Promise<void> {\n if (!registered) return;\n const owner = customProviderOwner(resolveTenantFromRequestContext(requestContext), registered.authEnabled);\n if (!owner) return;\n try {\n await snapshotFor(owner.orgId, registered.storage).ensureFresh();\n } catch {\n // Fail open: model calls serve the last snapshot (or none).\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,kBAAkB;;AAGxB,MAAM,kBAAkB;;AAGxB,MAAM,YAAY;;;;;;;;;;;AAYlB,SAAgB,oBACd,QACA,aACiC;CACjC,IAAI,CAAC,aAAa,OAAO,EAAE,OAAO,UAAU;CAC5C,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,MAAM,QAAQ,YAAY,MAAM;CAChC,OAAO,OAAO,oBAAoB,YAAY,EAAE,MAAM,IAAI;EAAE;EAAO,QAAQ,OAAO;CAAO;AAC3F;AAEA,IAAM,6BAAN,MAAiC;CAC/B;CACA;CACA,gBAA4C,CAAC;CAC7C,2BAAW,IAAI,IAAwC;CACvD,aAAa;;CAEb,cAAc;CACd;CAEA,YAAY,OAAe,SAAiC;EAC1D,KAAK,SAAS;EACd,KAAK,WAAW;CAClB;CAEA,WAAoB;EAClB,OAAO,KAAK,IAAI,IAAI,K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and "Where would this go?" tester behind the intake routes. Both decide with
|
|
3
|
+
* the intake order evaluator's own code ({@link traceIntakeOrder}), so they answer what filing
|
|
4
|
+
* does under `intake-order`; a project still on `route-list` files differently, and the responses
|
|
5
|
+
* say which evaluator it runs. Both use saved rules or a draft of them, and write nothing: no
|
|
6
|
+
* decision rows, no cards, no audit events, and no provider writes.
|
|
7
|
+
*/
|
|
8
|
+
import type { z } from 'zod';
|
|
9
|
+
import type { BoardEventFacts } from '../boards/board-events.js';
|
|
10
|
+
import type { IntakeItemLookup } from '../boards/intake-lookup.js';
|
|
11
|
+
import type { BoardRegistry } from '../boards/registry.js';
|
|
12
|
+
import type { StoredBoardScope, StoredBoardsStorage } from '../storage/domains/boards/base.js';
|
|
13
|
+
import type { WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
14
|
+
import type { intakeDryRunBodySchema, intakeTestBodySchema } from './contracts.js';
|
|
15
|
+
type DryRunBody = z.infer<typeof intakeDryRunBodySchema>;
|
|
16
|
+
type TestBody = z.infer<typeof intakeTestBodySchema>;
|
|
17
|
+
/** How many of a card's newest status events the tester replays. */
|
|
18
|
+
export declare const RECENT_CARD_EVENTS = 10;
|
|
19
|
+
/** How many of a card's newest decisions the tester reads to find and fold its recent events. */
|
|
20
|
+
export declare const CARD_HISTORY = 200;
|
|
21
|
+
/** How far back the live counts read the decision log. */
|
|
22
|
+
export declare const INTAKE_FILED_WINDOW_MS: number;
|
|
23
|
+
/** A request the check refuses: an unknown board in a draft, or a URL it can't test. */
|
|
24
|
+
export declare class IntakeCheckRefusal extends Error {
|
|
25
|
+
readonly status: 404 | 422;
|
|
26
|
+
readonly code: string;
|
|
27
|
+
constructor(status: 404 | 422, code: string, message: string);
|
|
28
|
+
}
|
|
29
|
+
export interface IntakeCheckDeps {
|
|
30
|
+
storage: Pick<StoredBoardsStorage, 'listIntakeRoutes' | 'readIntakeOrder' | 'listRecentNotRouted' | 'countPlacedByRoute' | 'getIntakeDecision'>;
|
|
31
|
+
workItems: Pick<WorkItemsStorage, 'listShared' | 'get' | 'listDeferredDecisions' | 'getTransitionResultByIngress'>;
|
|
32
|
+
/** Providers that can read an item by URL; Linear, Jira and incident.io items are picked from recent ones. */
|
|
33
|
+
lookups?: readonly IntakeItemLookup[];
|
|
34
|
+
now?: () => Date;
|
|
35
|
+
}
|
|
36
|
+
/** Whether the request runs anything but the saved rules and order, which needs the right to edit them. */
|
|
37
|
+
export declare function isDraft(body: {
|
|
38
|
+
boards?: unknown;
|
|
39
|
+
order?: unknown;
|
|
40
|
+
}): boolean;
|
|
41
|
+
export declare class IntakeCheck {
|
|
42
|
+
#private;
|
|
43
|
+
private readonly deps;
|
|
44
|
+
constructor(deps: IntakeCheckDeps);
|
|
45
|
+
dryRun(scope: StoredBoardScope, registry: BoardRegistry, body: DryRunBody): Promise<import("../boards/intake-dry-run.js").IntakeDryRunResult>;
|
|
46
|
+
test(scope: StoredBoardScope, registry: BoardRegistry, body: TestBody): Promise<{
|
|
47
|
+
item: {
|
|
48
|
+
title: string;
|
|
49
|
+
url: string | null;
|
|
50
|
+
kind: "card" | "fetched" | "not_routed";
|
|
51
|
+
id: string | null;
|
|
52
|
+
};
|
|
53
|
+
current: {
|
|
54
|
+
boardKey: string;
|
|
55
|
+
phase: string | null;
|
|
56
|
+
routeId: string | null;
|
|
57
|
+
} | null;
|
|
58
|
+
moves: ({
|
|
59
|
+
decisionId: string | null;
|
|
60
|
+
at: string | null;
|
|
61
|
+
event: BoardEventFacts;
|
|
62
|
+
outcome: 'unknown';
|
|
63
|
+
to: null;
|
|
64
|
+
phase: null;
|
|
65
|
+
reason: string;
|
|
66
|
+
rules: never[];
|
|
67
|
+
} | {
|
|
68
|
+
decisionId: string | null;
|
|
69
|
+
at: string | null;
|
|
70
|
+
event: BoardEventFacts;
|
|
71
|
+
outcome: "ignored" | "moves" | "rule_default" | "stays";
|
|
72
|
+
to: {
|
|
73
|
+
boardKey: string;
|
|
74
|
+
phase: string;
|
|
75
|
+
routeId: string;
|
|
76
|
+
} | null;
|
|
77
|
+
phase: string | null;
|
|
78
|
+
reason: string | null;
|
|
79
|
+
rules: import("../boards/intake-routing.js").EventRuleTrace[];
|
|
80
|
+
})[];
|
|
81
|
+
placement: {
|
|
82
|
+
boardKey: string;
|
|
83
|
+
routeId: string;
|
|
84
|
+
phase: string;
|
|
85
|
+
} | null;
|
|
86
|
+
reason: string | null;
|
|
87
|
+
note: string | null;
|
|
88
|
+
boards: import("../boards/intake-routing.js").IntakeBoardTrace[];
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=intake-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intake-check.d.ts","sourceRoot":"","sources":["../../src/routes/intake-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAIjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AASnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAY3D,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EAGpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACzD,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAKrD,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,iGAAiG;AACjG,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,0DAA0D;A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