@mastra/factory 0.28.0-alpha.9 → 0.29.0-alpha.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/README.md +67 -46
- package/dist/boards/board-writes.d.ts +3 -3
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +24 -20
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/project-boards.d.ts +20 -0
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +35 -11
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/registry.d.ts.map +1 -1
- package/dist/boards/registry.js +0 -3
- package/dist/boards/registry.js.map +1 -1
- package/dist/boards/reroute.d.ts +31 -0
- package/dist/boards/reroute.d.ts.map +1 -0
- package/dist/boards/reroute.js +71 -0
- package/dist/boards/reroute.js.map +1 -0
- package/dist/capabilities/version-control.d.ts +6 -1
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/environment/build-runner.d.ts +13 -2
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +42 -0
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-schedule.js +1 -1
- package/dist/environment/build-schedule.js.map +1 -1
- package/dist/environment/build-workflow.d.ts +6 -4
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +70 -66
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.d.ts +22 -7
- package/dist/environment/build.d.ts.map +1 -1
- package/dist/environment/build.js +73 -15
- package/dist/environment/build.js.map +1 -1
- package/dist/environment/heads.d.ts +1 -1
- package/dist/environment/heads.d.ts.map +1 -1
- package/dist/environment/heads.js +4 -1
- package/dist/environment/heads.js.map +1 -1
- package/dist/environment/repository-access.d.ts +15 -0
- package/dist/environment/repository-access.d.ts.map +1 -0
- package/dist/environment/repository-access.js +60 -0
- package/dist/environment/repository-access.js.map +1 -0
- package/dist/factory.d.ts +5 -2
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +40 -30
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +8 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/default-rules.d.ts +38 -0
- package/dist/integrations/dependabot/default-rules.d.ts.map +1 -0
- package/dist/integrations/dependabot/default-rules.js +63 -0
- package/dist/integrations/dependabot/default-rules.js.map +1 -0
- package/dist/integrations/dependabot/rules.d.ts +42 -0
- package/dist/integrations/dependabot/rules.d.ts.map +1 -0
- package/dist/integrations/dependabot/rules.js +187 -0
- package/dist/integrations/dependabot/rules.js.map +1 -0
- package/dist/integrations/dependabot/sync.d.ts +76 -0
- package/dist/integrations/dependabot/sync.d.ts.map +1 -0
- package/dist/integrations/dependabot/sync.js +111 -0
- package/dist/integrations/dependabot/sync.js.map +1 -0
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +7 -2
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox-release.d.ts +12 -0
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
- package/dist/integrations/github/sandbox-release.js +16 -1
- package/dist/integrations/github/sandbox-release.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +12 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +22 -1
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +4 -0
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +5 -0
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +33 -2
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +19 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +183 -105
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js +5 -1
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/vanta/integration.d.ts +33 -0
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -0
- package/dist/integrations/platform/vanta/integration.js +133 -0
- package/dist/integrations/platform/vanta/integration.js.map +1 -0
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +7 -4
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/vanta/default-rules.d.ts +34 -0
- package/dist/integrations/vanta/default-rules.d.ts.map +1 -0
- package/dist/integrations/vanta/default-rules.js +61 -0
- package/dist/integrations/vanta/default-rules.js.map +1 -0
- package/dist/integrations/vanta/rules.d.ts +40 -0
- package/dist/integrations/vanta/rules.d.ts.map +1 -0
- package/dist/integrations/vanta/rules.js +208 -0
- package/dist/integrations/vanta/rules.js.map +1 -0
- package/dist/integrations/vanta/sync.d.ts +36 -0
- package/dist/integrations/vanta/sync.d.ts.map +1 -0
- package/dist/integrations/vanta/sync.js +73 -0
- package/dist/integrations/vanta/sync.js.map +1 -0
- package/dist/mcp/routes.d.ts.map +1 -1
- package/dist/mcp/routes.js +3 -5
- package/dist/mcp/routes.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +24 -1
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +75 -7
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.d.ts +2 -3
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +307 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +253 -9
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake-routes.d.ts +3 -0
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +44 -0
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/knowledge.d.ts.map +1 -1
- package/dist/routes/knowledge.js +3 -2
- package/dist/routes/knowledge.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +5 -0
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/sandbox-envs.d.ts +2 -0
- package/dist/routes/sandbox-envs.d.ts.map +1 -1
- package/dist/routes/sandbox-envs.js +3 -0
- package/dist/routes/sandbox-envs.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +1 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +109 -3
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/source-control-settings.d.ts +2 -0
- package/dist/routes/source-control-settings.d.ts.map +1 -1
- package/dist/routes/source-control-settings.js +5 -0
- package/dist/routes/source-control-settings.js.map +1 -1
- package/dist/routes/surface.d.ts +8 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +74 -10
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-item-activity.d.ts +11 -0
- package/dist/routes/work-item-activity.d.ts.map +1 -0
- package/dist/routes/work-item-activity.js +25 -0
- package/dist/routes/work-item-activity.js.map +1 -0
- package/dist/routes/work-item-selection.d.ts +14 -0
- package/dist/routes/work-item-selection.d.ts.map +1 -0
- package/dist/routes/work-item-selection.js +44 -0
- package/dist/routes/work-item-selection.js.map +1 -0
- package/dist/routes/work-item-starters.d.ts +29 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -0
- package/dist/routes/work-item-starters.js +152 -0
- package/dist/routes/work-item-starters.js.map +1 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +239 -16
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts +3 -0
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +9 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +4 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +122 -33
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/index.d.ts +2 -2
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -2
- package/dist/rules/processor.d.ts +2 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +18 -4
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +6 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +6 -2
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/transition-service.d.ts +20 -2
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +43 -20
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +71 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +10 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +5 -0
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/context-sandboxes.d.ts +70 -0
- package/dist/sandbox/context-sandboxes.d.ts.map +1 -0
- package/dist/sandbox/context-sandboxes.js +120 -0
- package/dist/sandbox/context-sandboxes.js.map +1 -0
- package/dist/sandbox/session-retirement.d.ts +11 -4
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +39 -13
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/session/factory-session.d.ts +20 -5
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +20 -6
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/live-sessions.d.ts +1 -1
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +12 -2
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/audit/actors.d.ts.map +1 -1
- package/dist/storage/domains/audit/actors.js +1 -1
- package/dist/storage/domains/audit/actors.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +25 -5
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +57 -20
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +1 -1
- package/dist/storage/domains/intake/base.js +2 -2
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +16 -2
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +32 -5
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +60 -8
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +180 -18
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +1 -0
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +32 -8
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts +19 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.js +62 -3
- package/dist/storage/domains/work-items/legacy-review.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +1 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +46 -18
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/tools/annotations.d.ts.map +1 -1
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -1
- package/dist/tools/approval-tools.d.ts +20 -0
- package/dist/tools/approval-tools.d.ts.map +1 -1
- package/dist/tools/approval-tools.js +79 -30
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +29 -0
- package/dist/tools/audit-events-tool.d.ts.map +1 -0
- package/dist/tools/audit-events-tool.js +180 -0
- package/dist/tools/audit-events-tool.js.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +1 -1
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +1 -0
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/read-tools.d.ts +0 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +2 -7
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/reports.d.ts +3 -0
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +3 -3
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/run-watch.d.ts +14 -2
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +24 -4
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +17 -6
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/sessions-state-processor.js +1 -1
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js +1 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +12 -2
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +1 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +2 -0
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/board-check.d.ts +11 -0
- package/dist/work-items/board-check.d.ts.map +1 -0
- package/dist/work-items/board-check.js +20 -0
- package/dist/work-items/board-check.js.map +1 -0
- package/dist/work-items/board-filter-options.d.ts +5 -0
- package/dist/work-items/board-filter-options.d.ts.map +1 -0
- package/dist/work-items/board-filter-options.js +27 -0
- package/dist/work-items/board-filter-options.js.map +1 -0
- package/dist/work-items/board-phases.d.ts +28 -0
- package/dist/work-items/board-phases.d.ts.map +1 -0
- package/dist/work-items/board-phases.js +165 -0
- package/dist/work-items/board-phases.js.map +1 -0
- package/dist/work-items/card-facts.d.ts +24 -0
- package/dist/work-items/card-facts.d.ts.map +1 -0
- package/dist/work-items/card-facts.js +75 -0
- package/dist/work-items/card-facts.js.map +1 -0
- package/dist/work-items/card-labels.d.ts +5 -0
- package/dist/work-items/card-labels.d.ts.map +1 -0
- package/dist/work-items/card-labels.js +13 -0
- package/dist/work-items/card-labels.js.map +1 -0
- package/dist/work-items/card-number.d.ts +10 -0
- package/dist/work-items/card-number.d.ts.map +1 -0
- package/dist/work-items/card-number.js +15 -0
- package/dist/work-items/card-number.js.map +1 -0
- package/dist/work-items/card-people.d.ts +25 -0
- package/dist/work-items/card-people.d.ts.map +1 -0
- package/dist/work-items/card-people.js +100 -0
- package/dist/work-items/card-people.js.map +1 -0
- package/dist/work-items/card-search-text.d.ts +4 -0
- package/dist/work-items/card-search-text.d.ts.map +1 -0
- package/dist/work-items/card-search-text.js +15 -0
- package/dist/work-items/card-search-text.js.map +1 -0
- package/dist/work-items/card-source-filters.d.ts +23 -0
- package/dist/work-items/card-source-filters.d.ts.map +1 -0
- package/dist/work-items/card-source-filters.js +25 -0
- package/dist/work-items/card-source-filters.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +0 -6
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +2 -7
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts +4 -0
- package/dist/work-items/list-related-cards.d.ts.map +1 -0
- package/dist/work-items/list-related-cards.js +24 -0
- package/dist/work-items/list-related-cards.js.map +1 -0
- package/dist/work-items/related-cards.d.ts +21 -0
- package/dist/work-items/related-cards.d.ts.map +1 -0
- package/dist/work-items/related-cards.js +45 -0
- package/dist/work-items/related-cards.js.map +1 -0
- package/dist/work-items/search-words.d.ts +5 -0
- package/dist/work-items/search-words.d.ts.map +1 -0
- package/dist/work-items/search-words.js +12 -0
- package/dist/work-items/search-words.js.map +1 -0
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +6 -2
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts +0 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +140 -78
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-self-review/SKILL.md +1 -1
- package/factory-skills/factory-triage/SKILL.md +4 -4
- package/package.json +17 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-schema.js","names":[],"sources":["../../../../src/storage/domains/work-items/work-item-schema.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\nimport type { FactoryTriageType } from '../../../rules/types.js';\n\nexport type WorkItemProvider =\n | 'github'\n | 'gitlab'\n | 'jira'\n | 'linear'\n | 'slack'\n | 'incidentio'\n | 'factory'\n | (string & {});\n\n/** The work itself; external identities and facts belong to its sources. */\nexport const FACTORY_WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n title: { type: 'text' },\n description: { type: 'text', nullable: true },\n parent_work_item_id: { type: 'text', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n indexes: [{ name: 'factory_work_items_org_project_idx', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** Several external records can describe one work item. Native work has no source. */\nexport const FACTORY_WORK_ITEM_SOURCES_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_sources',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n provider: { type: 'text' },\n integration_id: { type: 'text' },\n source_type: { type: 'text' },\n workspace_id: { type: 'text', nullable: true },\n external_id: { type: 'text' },\n source_key: { type: 'text', nullable: true },\n url: { type: 'text', nullable: true },\n key: { type: 'text', nullable: true },\n state: { type: 'text', nullable: true },\n labels: { type: 'json' },\n author: { type: 'text', nullable: true },\n metadata: { type: 'json', nullable: true },\n /** `origin` for the record the work item was created from, `attached` for one added later. Null (rows written before this column) reads as `origin`. */\n role: { type: 'text', nullable: true },\n revision: { type: 'integer', default: 1 },\n synced_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_work_item_sources_project_provider_external_unique',\n columns: ['org_id', 'factory_project_id', 'provider', 'external_id'],\n },\n ],\n indexes: [\n { name: 'factory_work_item_sources_work_item_idx', columns: ['work_item_id'] },\n { name: 'factory_work_item_sources_source_key_idx', columns: ['source_key'] },\n ],\n};\n\n/** Placement/process state. Its id preserves every legacy card reference. */\nexport const FACTORY_BOARD_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_board_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n triage_type: { type: 'text', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n board: { type: 'text', nullable: true },\n parent_board_item_id: { type: 'text', nullable: true },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n migrated_from_updated_at: { type: 'timestamp', nullable: true },\n migrated_from_hash: { type: 'text', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_items_work_item_unique', columns: ['work_item_id'] }],\n indexes: [\n {\n name: 'factory_board_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'factory_board_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_board_item_id'],\n },\n ],\n};\n\nexport interface WorkItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n title: string;\n description: string | null;\n parent_work_item_id: string | null;\n revision: number;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface WorkItemSourceDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n provider: WorkItemProvider;\n integration_id: string;\n source_type: string;\n workspace_id: string | null;\n external_id: string;\n source_key: string | null;\n url: string | null;\n key: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n role?: WorkItemSourceRole | null;\n revision: number;\n synced_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nexport type WorkItemSourceRole = 'origin' | 'attached';\n\nexport interface WorkItemSourceRow {\n id: string;\n workItemId: string;\n provider: WorkItemProvider;\n integrationId: string;\n sourceType: string;\n workspaceId: string | null;\n externalId: string;\n sourceKey: string | null;\n key: string | null;\n url: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport function primarySource(card: { workItem: { sources: readonly WorkItemSourceRow[] } }): WorkItemSourceRow | null {\n return card.workItem.sources[0] ?? null;\n}\n\nexport interface WorkItemRow {\n sources: WorkItemSourceRow[];\n id: string;\n orgId: string;\n factoryProjectId: string;\n provider: WorkItemProvider;\n externalId: string;\n key: string | null;\n url: string | null;\n title: string;\n state: string | null;\n labels: string[];\n author: string | null;\n parentWorkItemId: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface BoardItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n triage_type: FactoryTriageType | null;\n accepted_at: Date | null;\n autonomy_armed_at: Date | null;\n plans_preapproved_at: Date | null;\n board: string | null;\n parent_board_item_id: string | null;\n stages: string[];\n stage_history: unknown[];\n sessions: Record<string, unknown>;\n metadata: Record<string, unknown> | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_at: Date;\n migrated_from_updated_at: Date | null;\n migrated_from_hash: string | null;\n}\n\n/** Serializes first-copy migration with deletion without locking an entire project's cards. */\nexport const FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n },\n};\n\n/** Deleted card ids prevent the boot migration resurrecting frozen legacy rows. */\nexport const FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA: CollectionSchema = {\n name: 'factory_board_item_tombstones',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n },\n};\n\n/** The pre-split card table. Frozen: only the split migration reads it. */\nexport const WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board: { type: 'text', nullable: true },\n external_source: { type: 'json', nullable: true },\n source_key: { type: 'text', nullable: true },\n // Retained for existing tables; claims no longer govern work-item identity.\n claim_key: { type: 'text', nullable: true },\n parent_work_item_id: { type: 'text', nullable: true },\n title: { type: 'text' },\n description: { type: 'text', nullable: true },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n triage_type: { type: 'text', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n // Retired hands-off plan grant: plans are approved per board (`exitTool`).\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n // Retired comment summaries: kept so replicas still on the old release can write them.\n comment_count: { type: 'integer', default: 0 },\n feed_activity_at: { type: 'timestamp', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'work_items_project_source_key_unique',\n columns: ['factory_project_id', 'source_key'],\n },\n {\n // One live card per claimed external record per org. NULL keys never\n // collide, so unclaimed cards are unaffected.\n name: 'work_items_org_claim_key_unique',\n columns: ['org_id', 'claim_key'],\n },\n ],\n indexes: [\n {\n name: 'work_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'work_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_work_item_id'],\n },\n {\n // The unique index leads with `factory_project_id`, so it cannot serve a\n // lookup by the key alone — which is what a platform message has.\n name: 'work_items_source_key_idx',\n columns: ['source_key'],\n },\n {\n // Finds the newest legacy write without a scan, so a finished split can be confirmed at boot.\n name: 'work_items_updated_at_id_idx',\n columns: ['updated_at', 'id'],\n },\n ],\n};\n\n/** Records the newest legacy row a finished split pass covered; later boots skip unchanged legacy tables. */\nexport const FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_state',\n columns: {\n id: { type: 'text', primaryKey: true },\n legacy_updated_at: { type: 'timestamp', nullable: true },\n legacy_id: { type: 'text', nullable: true },\n completed_at: { type: 'timestamp' },\n },\n};\n"],"mappings":";;AAeA,MAAa,4BAA8C;CACzD,MAA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W,SAAS;EAAE;EACxC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CACb;EACE,MAAM;EACN,SAAS,CAAC,sBAAsB,YAAY;CAC9C,GACA;EAGE,MAAM;EACN,SAAS,CAAC,UAAU,WAAW;CACjC,CACF;CACA,SAAS;EACP;GACE,MAAM;GACN,SAAS;IAAC;IAAU;IAAsB;IAAc;GAAI;EAC9D;EACA;GACE,MAAM;GACN,SAAS;IAAC;IAAU;IAAsB;GAAqB;EACjE;EACA;GAGE,MAAM;GACN,SAAS,CAAC,YAAY;EACxB;EACA;GAEE,MAAM;GACN,SAAS,CAAC,cAAc,IAAI;EAC9B;CACF;AACF;;AAGA,MAAa,uCAAyD;CACpE,MAAM;CACN,SAAS;EACP,IAAI;GAAE,MAAM;GAAQ,YAAY;EAAK;EACrC,mBAAmB;GAAE,MAAM;GAAa,UAAU;EAAK;EACvD,WAAW;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC1C,cAAc,EAAE,MAAM,YAAY;CACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"work-item-schema.js","names":[],"sources":["../../../../src/storage/domains/work-items/work-item-schema.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\nimport type { FactoryTriageType } from '../../../rules/types.js';\n\nexport type WorkItemProvider =\n | 'github'\n | 'gitlab'\n | 'jira'\n | 'linear'\n | 'slack'\n | 'incidentio'\n | 'factory'\n | (string & {});\n\n/** The work itself; external identities and facts belong to its sources. */\nexport const FACTORY_WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n title: { type: 'text' },\n description: { type: 'text', nullable: true },\n parent_work_item_id: { type: 'text', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n indexes: [{ name: 'factory_work_items_org_project_idx', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** Several external records can describe one work item. Native work has no source. */\nexport const FACTORY_WORK_ITEM_SOURCES_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_sources',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n provider: { type: 'text' },\n integration_id: { type: 'text' },\n source_type: { type: 'text' },\n workspace_id: { type: 'text', nullable: true },\n external_id: { type: 'text' },\n source_key: { type: 'text', nullable: true },\n url: { type: 'text', nullable: true },\n key: { type: 'text', nullable: true },\n state: { type: 'text', nullable: true },\n labels: { type: 'json' },\n author: { type: 'text', nullable: true },\n metadata: { type: 'json', nullable: true },\n /** `origin` for the record the work item was created from, `attached` for one added later. Null (rows written before this column) reads as `origin`. */\n role: { type: 'text', nullable: true },\n revision: { type: 'integer', default: 1 },\n synced_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_work_item_sources_project_provider_external_unique',\n columns: ['org_id', 'factory_project_id', 'provider', 'external_id'],\n },\n ],\n indexes: [\n { name: 'factory_work_item_sources_work_item_idx', columns: ['work_item_id'] },\n { name: 'factory_work_item_sources_source_key_idx', columns: ['source_key'] },\n ],\n};\n\n/** Placement/process state. Its id preserves every legacy card reference. */\nexport const FACTORY_BOARD_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_board_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n triage_type: { type: 'text', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n board: { type: 'text', nullable: true },\n parent_board_item_id: { type: 'text', nullable: true },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n migrated_from_updated_at: { type: 'timestamp', nullable: true },\n migrated_from_hash: { type: 'text', nullable: true },\n /** Moves on every change to the card, in any of its tables; board reloads read rows changed since. */\n changed_at: { type: 'timestamp', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_items_work_item_unique', columns: ['work_item_id'] }],\n indexes: [\n {\n name: 'factory_board_items_project_changed_at_idx',\n columns: ['org_id', 'factory_project_id', 'changed_at'],\n },\n {\n name: 'factory_board_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'factory_board_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_board_item_id'],\n },\n ],\n};\n\nexport interface WorkItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n title: string;\n description: string | null;\n parent_work_item_id: string | null;\n revision: number;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface WorkItemSourceDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n provider: WorkItemProvider;\n integration_id: string;\n source_type: string;\n workspace_id: string | null;\n external_id: string;\n source_key: string | null;\n url: string | null;\n key: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n role?: WorkItemSourceRole | null;\n revision: number;\n synced_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nexport type WorkItemSourceRole = 'origin' | 'attached';\n\nexport interface WorkItemSourceRow {\n id: string;\n workItemId: string;\n provider: WorkItemProvider;\n integrationId: string;\n sourceType: string;\n workspaceId: string | null;\n externalId: string;\n sourceKey: string | null;\n key: string | null;\n url: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport function primarySource(card: { workItem: { sources: readonly WorkItemSourceRow[] } }): WorkItemSourceRow | null {\n return card.workItem.sources[0] ?? null;\n}\n\nexport interface WorkItemRow {\n sources: WorkItemSourceRow[];\n id: string;\n orgId: string;\n factoryProjectId: string;\n provider: WorkItemProvider;\n externalId: string;\n key: string | null;\n url: string | null;\n title: string;\n state: string | null;\n labels: string[];\n author: string | null;\n parentWorkItemId: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface BoardItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n triage_type: FactoryTriageType | null;\n accepted_at: Date | null;\n autonomy_armed_at: Date | null;\n plans_preapproved_at: Date | null;\n board: string | null;\n parent_board_item_id: string | null;\n stages: string[];\n stage_history: unknown[];\n sessions: Record<string, unknown>;\n metadata: Record<string, unknown> | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_at: Date;\n migrated_from_updated_at: Date | null;\n migrated_from_hash: string | null;\n changed_at?: Date | null;\n}\n\n/** Serializes first-copy migration with deletion without locking an entire project's cards. */\nexport const FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n },\n};\n\n/** Deleted card ids prevent the boot migration resurrecting frozen legacy rows. */\nexport const FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA: CollectionSchema = {\n name: 'factory_board_item_tombstones',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n deleted_at: { type: 'timestamp', nullable: true },\n },\n indexes: [\n {\n name: 'factory_board_item_tombstones_project_deleted_at_idx',\n columns: ['org_id', 'factory_project_id', 'deleted_at'],\n },\n ],\n};\n\n/** The pre-split card table. Frozen: only the split migration reads it. */\nexport const WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board: { type: 'text', nullable: true },\n external_source: { type: 'json', nullable: true },\n source_key: { type: 'text', nullable: true },\n // Retained for existing tables; claims no longer govern work-item identity.\n claim_key: { type: 'text', nullable: true },\n parent_work_item_id: { type: 'text', nullable: true },\n title: { type: 'text' },\n description: { type: 'text', nullable: true },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n triage_type: { type: 'text', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n // Retired hands-off plan grant: plans are approved per board (`exitTool`).\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n // Retired comment summaries: kept so replicas still on the old release can write them.\n comment_count: { type: 'integer', default: 0 },\n feed_activity_at: { type: 'timestamp', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'work_items_project_source_key_unique',\n columns: ['factory_project_id', 'source_key'],\n },\n {\n // One live card per claimed external record per org. NULL keys never\n // collide, so unclaimed cards are unaffected.\n name: 'work_items_org_claim_key_unique',\n columns: ['org_id', 'claim_key'],\n },\n ],\n indexes: [\n {\n name: 'work_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'work_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_work_item_id'],\n },\n {\n // The unique index leads with `factory_project_id`, so it cannot serve a\n // lookup by the key alone — which is what a platform message has.\n name: 'work_items_source_key_idx',\n columns: ['source_key'],\n },\n {\n // Finds the newest legacy write without a scan, so a finished split can be confirmed at boot.\n name: 'work_items_updated_at_id_idx',\n columns: ['updated_at', 'id'],\n },\n ],\n};\n\n/** Records the newest legacy row a finished split pass covered; later boots skip unchanged legacy tables. */\nexport const FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_state',\n columns: {\n id: { type: 'text', primaryKey: true },\n legacy_updated_at: { type: 'timestamp', nullable: true },\n legacy_id: { type: 'text', nullable: true },\n completed_at: { type: 'timestamp' },\n },\n};\n"],"mappings":";;AAeA,MAAa,4BAA8C;CACzD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,OAAO,EAAE,MAAM,OAAO;EACtB,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,qBAAqB;GAAE,MAAM;GAAQ,UAAU;EAAK;EACpD,UAAU;GAAE,MAAM;GAAW,SAAS;EAAE;EACxC,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,SAAS,CAAC;EAAE,MAAM;EAAsC,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AACrG;;AAGA,MAAa,mCAAqD;CAChE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,cAAc,EAAE,MAAM,OAAO;EAC7B,UAAU,EAAE,MAAM,OAAO;EACzB,gBAAgB,EAAE,MAAM,OAAO;EAC/B,aAAa,EAAE,MAAM,OAAO;EAC5B,cAAc;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC7C,aAAa,EAAE,MAAM,OAAO;EAC5B,YAAY;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC3C,KAAK;GAAE,MAAM;GAAQ,UAAU;EAAK;EACpC,KAAK;GAAE,MAAM;GAAQ,UAAU;EAAK;EACpC,OAAO;GAAE,MAAM;GAAQ,UAAU;EAAK;EACtC,Q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
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/tools/annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAY1D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/tools/annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAY1D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAmBpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.js","names":[],"sources":["../../src/tools/annotations.ts"],"sourcesContent":["import type { ToolAnnotations } from '@mastra/core/tools';\n\nconst read: ToolAnnotations = {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n};\nconst additive: ToolAnnotations = { readOnlyHint: false, destructiveHint: false, openWorldHint: false };\nconst toggle: ToolAnnotations = { ...additive, idempotentHint: true };\nconst changes: ToolAnnotations = { readOnlyHint: false, destructiveHint: true, openWorldHint: false };\n\n/**\n * MCP hints for each Factory tool, so clients like ChatGPT can tell lookups\n * from writes and ask before a tool changes or discards state.\n */\nexport const FACTORY_TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {\n factory_list_work_items: { ...read, title: 'List work items' },\n factory_inspect_work_item: { ...read, title: 'Inspect a work item' },\n factory_list_attention: { ...read, title: 'List items that need attention' },\n factory_create_work_item: { ...additive, title: 'Create a work item' },\n factory_update_work_item: { ...changes, title: 'Update a work item' },\n factory_transition_work_item: { ...changes, title: 'Move a work item to another stage' },\n factory_retry_decision: { ...additive, title: 'Retry a failed decision' },\n factory_dismiss_decision: { ...changes, title: 'Dismiss a decision' },\n factory_resolve_proposal: { ...changes, title: 'Approve or reject a proposal' },\n factory_subscribe_work_item: { ...toggle, title: 'Follow a work item' },\n factory_unsubscribe_work_item: { ...toggle, title: 'Stop following a work item' },\n factory_start_session: { ...additive, openWorldHint: true, title: 'Start an agent session' },\n factory_signal_session: { ...additive, openWorldHint: true, title: 'Message a running session' },\n factory_message_origin: { ...additive, title: 'Reply to the session that started this one' },\n factory_answer_approval: { ...changes, openWorldHint: true, title: 'Answer a session approval request' },\n search: { ...read, title: 'Search work items' },\n fetch: { ...read, title: 'Fetch a work item' },\n};\n"],"mappings":";AAEA,MAAM,OAAwB;CAC5B,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,eAAe;AACjB;AACA,MAAM,WAA4B;CAAE,cAAc;CAAO,iBAAiB;CAAO,eAAe;AAAM;AACtG,MAAM,SAA0B;CAAE,GAAG;CAAU,gBAAgB;AAAK;AACpE,MAAM,UAA2B;CAAE,cAAc;CAAO,iBAAiB;CAAM,eAAe;AAAM;;;;;AAMpG,MAAa,2BAA4D;CACvE,yBAAyB;EAAE,GAAG;EAAM,OAAO;CAAkB;CAC7D,2BAA2B;EAAE,GAAG;EAAM,OAAO;CAAsB;CACnE,wBAAwB;EAAE,GAAG;EAAM,OAAO;CAAiC;CAC3E,0BAA0B;EAAE,GAAG;EAAU,OAAO;CAAqB;CACrE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAAqB;CACpE,8BAA8B;EAAE,GAAG;EAAS,OAAO;CAAoC;CACvF,wBAAwB;EAAE,GAAG;EAAU,OAAO;CAA0B;CACxE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAAqB;CACpE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAA+B;CAC9E,6BAA6B;EAAE,GAAG;EAAQ,OAAO;CAAqB;CACtE,+BAA+B;EAAE,GAAG;EAAQ,OAAO;CAA6B;CAChF,uBAAuB;EAAE,GAAG;EAAU,eAAe;EAAM,OAAO;CAAyB;CAC3F,wBAAwB;EAAE,GAAG;EAAU,eAAe;EAAM,OAAO;CAA4B;CAC/F,wBAAwB;EAAE,GAAG;EAAU,OAAO;CAA6C;CAC3F,yBAAyB;EAAE,GAAG;EAAS,eAAe;EAAM,OAAO;CAAoC;CACvG,QAAQ;EAAE,GAAG;EAAM,OAAO;CAAoB;CAC9C,OAAO;EAAE,GAAG;EAAM,OAAO;CAAoB;AAC/C"}
|
|
1
|
+
{"version":3,"file":"annotations.js","names":[],"sources":["../../src/tools/annotations.ts"],"sourcesContent":["import type { ToolAnnotations } from '@mastra/core/tools';\n\nconst read: ToolAnnotations = {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n};\nconst additive: ToolAnnotations = { readOnlyHint: false, destructiveHint: false, openWorldHint: false };\nconst toggle: ToolAnnotations = { ...additive, idempotentHint: true };\nconst changes: ToolAnnotations = { readOnlyHint: false, destructiveHint: true, openWorldHint: false };\n\n/**\n * MCP hints for each Factory tool, so clients like ChatGPT can tell lookups\n * from writes and ask before a tool changes or discards state.\n */\nexport const FACTORY_TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {\n factory_list_work_items: { ...read, title: 'List work items' },\n factory_inspect_work_item: { ...read, title: 'Inspect a work item' },\n factory_list_attention: { ...read, title: 'List items that need attention' },\n factory_list_audit_events: { ...read, title: 'List audit events' },\n factory_create_work_item: { ...additive, title: 'Create a work item' },\n factory_update_work_item: { ...changes, title: 'Update a work item' },\n factory_transition_work_item: { ...changes, title: 'Move a work item to another stage' },\n factory_retry_decision: { ...additive, title: 'Retry a failed decision' },\n factory_dismiss_decision: { ...changes, title: 'Dismiss a decision' },\n factory_resolve_proposal: { ...changes, title: 'Approve or reject a proposal' },\n factory_subscribe_work_item: { ...toggle, title: 'Follow a work item' },\n factory_unsubscribe_work_item: { ...toggle, title: 'Stop following a work item' },\n factory_start_session: { ...additive, openWorldHint: true, title: 'Start an agent session' },\n factory_signal_session: { ...additive, openWorldHint: true, title: 'Message a running session' },\n factory_message_origin: { ...additive, title: 'Reply to the session that started this one' },\n factory_answer_approval: { ...changes, openWorldHint: true, title: 'Answer a session approval request' },\n search: { ...read, title: 'Search work items' },\n fetch: { ...read, title: 'Fetch a work item' },\n};\n"],"mappings":";AAEA,MAAM,OAAwB;CAC5B,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,eAAe;AACjB;AACA,MAAM,WAA4B;CAAE,cAAc;CAAO,iBAAiB;CAAO,eAAe;AAAM;AACtG,MAAM,SAA0B;CAAE,GAAG;CAAU,gBAAgB;AAAK;AACpE,MAAM,UAA2B;CAAE,cAAc;CAAO,iBAAiB;CAAM,eAAe;AAAM;;;;;AAMpG,MAAa,2BAA4D;CACvE,yBAAyB;EAAE,GAAG;EAAM,OAAO;CAAkB;CAC7D,2BAA2B;EAAE,GAAG;EAAM,OAAO;CAAsB;CACnE,wBAAwB;EAAE,GAAG;EAAM,OAAO;CAAiC;CAC3E,2BAA2B;EAAE,GAAG;EAAM,OAAO;CAAoB;CACjE,0BAA0B;EAAE,GAAG;EAAU,OAAO;CAAqB;CACrE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAAqB;CACpE,8BAA8B;EAAE,GAAG;EAAS,OAAO;CAAoC;CACvF,wBAAwB;EAAE,GAAG;EAAU,OAAO;CAA0B;CACxE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAAqB;CACpE,0BAA0B;EAAE,GAAG;EAAS,OAAO;CAA+B;CAC9E,6BAA6B;EAAE,GAAG;EAAQ,OAAO;CAAqB;CACtE,+BAA+B;EAAE,GAAG;EAAQ,OAAO;CAA6B;CAChF,uBAAuB;EAAE,GAAG;EAAU,eAAe;EAAM,OAAO;CAAyB;CAC3F,wBAAwB;EAAE,GAAG;EAAU,eAAe;EAAM,OAAO;CAA4B;CAC/F,wBAAwB;EAAE,GAAG;EAAU,OAAO;CAA6C;CAC3F,yBAAyB;EAAE,GAAG;EAAS,eAAe;EAAM,OAAO;CAAoC;CACvG,QAAQ;EAAE,GAAG;EAAM,OAAO;CAAoB;CAC9C,OAAO;EAAE,GAAG;EAAM,OAAO;CAAoB;AAC/C"}
|
|
@@ -10,6 +10,26 @@ export interface FactoryApprovalToolDependencies {
|
|
|
10
10
|
auditRecorder: AuditRecorder;
|
|
11
11
|
messaging: () => Promise<FactoryMessaging | null>;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Approve or decline a tool call a live session waits on, for a caller already allowed
|
|
15
|
+
* to. Any tool can wait this way; with no `toolCallId` the session's only waiting call
|
|
16
|
+
* is answered. The answered run carries on as the session's owner whoever answers: a
|
|
17
|
+
* phase session keeps one identity from kickoff to finish, and a resume never runs with
|
|
18
|
+
* no user.
|
|
19
|
+
*/
|
|
20
|
+
export declare function answerParkedCall(deps: Pick<FactoryApprovalToolDependencies, 'messaging'>, input: {
|
|
21
|
+
session: {
|
|
22
|
+
sessionId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
orgId: string;
|
|
25
|
+
};
|
|
26
|
+
toolCallId?: string;
|
|
27
|
+
decision: 'approve' | 'decline';
|
|
28
|
+
declineReason: string;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
toolCallId: string;
|
|
31
|
+
toolName: string;
|
|
32
|
+
}>;
|
|
13
33
|
/** Answers a tool call another session holds for approval. Only a signed-in person's turn may answer. */
|
|
14
34
|
export declare function createFactoryApprovalTools(scope: FactoryToolScope, deps: FactoryApprovalToolDependencies): IntegrationTools;
|
|
15
35
|
//# sourceMappingURL=approval-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-tools.d.ts","sourceRoot":"","sources":["../../src/tools/approval-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approval-tools.d.ts","sourceRoot":"","sources":["../../src/tools/approval-tools.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;IAC7D,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,gCAAgC,GAAG,0BAA0B,CAAC,CAAC;IACjG,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CACnD;AA+CD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,CAAC,+BAA+B,EAAE,WAAW,CAAC,EACxD,KAAK,EAAE;IACL,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;CACvB,GACA,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAyDnD;AAED,yGAAyG;AACzG,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,+BAA+B,GACpC,gBAAgB,CA2ElB"}
|
|
@@ -1,16 +1,86 @@
|
|
|
1
|
+
import { resumesOnDecision } from "./run-watch.js";
|
|
1
2
|
import { requirePerson } from "./scope.js";
|
|
2
3
|
import { RequestContext } from "@mastra/core/request-context";
|
|
3
4
|
import { createTool } from "@mastra/core/tools";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
// src/tools/approval-tools.ts
|
|
7
|
+
const ALREADY_ANSWERED = "That call was already answered: someone else got there first.";
|
|
8
|
+
function waitingApprovals(live) {
|
|
9
|
+
return [...live.approval.list().map(({ toolCallId, toolName }) => ({
|
|
10
|
+
toolCallId,
|
|
11
|
+
toolName,
|
|
12
|
+
channel: "gate"
|
|
13
|
+
})), ...[...live.displayState.get().pendingSuspensions.values()].filter((suspension) => resumesOnDecision(suspension.resumeSchema)).map(({ toolCallId, toolName }) => ({
|
|
14
|
+
toolCallId,
|
|
15
|
+
toolName,
|
|
16
|
+
channel: "resume"
|
|
17
|
+
}))];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Approve or decline a tool call a live session waits on, for a caller already allowed
|
|
21
|
+
* to. Any tool can wait this way; with no `toolCallId` the session's only waiting call
|
|
22
|
+
* is answered. The answered run carries on as the session's owner whoever answers: a
|
|
23
|
+
* phase session keeps one identity from kickoff to finish, and a resume never runs with
|
|
24
|
+
* no user.
|
|
25
|
+
*/
|
|
26
|
+
async function answerParkedCall(deps, input) {
|
|
27
|
+
const { session, decision, declineReason } = input;
|
|
28
|
+
const messaging = await deps.messaging();
|
|
29
|
+
if (!messaging) throw new Error("Answering approvals is not available on this server.");
|
|
30
|
+
const live = await messaging.controller.getSession(session.sessionId);
|
|
31
|
+
const waiting = live ? waitingApprovals(live) : [];
|
|
32
|
+
const matches = input.toolCallId ? waiting.filter((call) => call.toolCallId === input.toolCallId) : waiting;
|
|
33
|
+
const [call] = matches;
|
|
34
|
+
if (!live || !call) throw new Error(input.toolCallId ? "Nothing is waiting on that tool call any more: the run that asked has ended or it was already answered. Message the session with factory_signal_session if it should try again." : "This session is not waiting on an approval. Open it to see what it needs.");
|
|
35
|
+
if (matches.length > 1) throw new Error(`This session waits on ${matches.length} approvals (${matches.map((match) => `${match.toolName}: ${match.toolCallId}`).join(", ")}). Name the toolCallId to answer.`);
|
|
36
|
+
const { toolCallId, toolName } = call;
|
|
37
|
+
const requestContext = new RequestContext();
|
|
38
|
+
requestContext.set("user", {
|
|
39
|
+
workosId: session.userId,
|
|
40
|
+
organizationId: session.orgId
|
|
41
|
+
});
|
|
42
|
+
if (call.channel === "resume") {
|
|
43
|
+
const claim = live.claimToolSuspension(toolCallId);
|
|
44
|
+
if (!claim.accepted) throw new Error(ALREADY_ANSWERED);
|
|
45
|
+
try {
|
|
46
|
+
await live.respondToToolSuspension({
|
|
47
|
+
resumeData: decision === "approve" ? { action: "approved" } : {
|
|
48
|
+
action: "rejected",
|
|
49
|
+
feedback: declineReason
|
|
50
|
+
},
|
|
51
|
+
address: claim.address,
|
|
52
|
+
requestContext
|
|
53
|
+
});
|
|
54
|
+
} finally {
|
|
55
|
+
live.releaseToolResponse(claim.claimKey);
|
|
56
|
+
}
|
|
57
|
+
if (live.suspensions.has(claim.address)) throw new Error(`The answer did not reach ${toolName}: the session could not carry on and still waits on it. Open the session to see why.`);
|
|
58
|
+
return {
|
|
59
|
+
toolCallId,
|
|
60
|
+
toolName
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const result = live.respondToToolApproval({
|
|
64
|
+
decision,
|
|
65
|
+
toolCallId,
|
|
66
|
+
requestContext,
|
|
67
|
+
...decision === "decline" ? { declineContext: { reason: declineReason } } : {}
|
|
68
|
+
});
|
|
69
|
+
if (!result.accepted) throw new Error(result.reason === "not_pending" ? ALREADY_ANSWERED : `The answer was not accepted (${result.reason}).`);
|
|
70
|
+
return {
|
|
71
|
+
toolCallId,
|
|
72
|
+
toolName
|
|
73
|
+
};
|
|
74
|
+
}
|
|
6
75
|
/** Answers a tool call another session holds for approval. Only a signed-in person's turn may answer. */
|
|
7
76
|
function createFactoryApprovalTools(scope, deps) {
|
|
8
77
|
return { factory_answer_approval: createTool({
|
|
9
78
|
id: "factory_answer_approval",
|
|
10
79
|
description: [
|
|
11
|
-
"Approve or decline a tool call a session you follow is waiting on
|
|
80
|
+
"Approve or decline a tool call a session you follow is waiting on.",
|
|
81
|
+
"The decision is recorded as yours; the run carries on as the owner of the session that asked.",
|
|
12
82
|
"A `factory-session` notification of kind `approval` names the session, tool, arguments and toolCallId;",
|
|
13
|
-
"a `blocked` notice for a session parked on
|
|
83
|
+
"a `blocked` notice for a session parked on a tool that waits for approval names the toolCallId to approve or decline.",
|
|
14
84
|
"Answer only what the person in this conversation agreed to; decline with a reason the session will see."
|
|
15
85
|
].join(" "),
|
|
16
86
|
inputSchema: z.object({
|
|
@@ -36,33 +106,12 @@ function createFactoryApprovalTools(scope, deps) {
|
|
|
36
106
|
sessionId: scope.sessionId
|
|
37
107
|
})).some((subscription) => subscription.workItemId === binding.workItemId);
|
|
38
108
|
if (!isOrigin && !follows) throw new Error(`This session doesn't follow session ${sessionId}: follow its work item first, or answer from that session.`);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const requestContext = new RequestContext();
|
|
46
|
-
requestContext.set("user", {
|
|
47
|
-
workosId: scope.userId,
|
|
48
|
-
organizationId: scope.orgId
|
|
49
|
-
});
|
|
50
|
-
await live.respondToToolSuspension({
|
|
51
|
-
resumeData: decision === "approve" ? { action: "approved" } : {
|
|
52
|
-
action: "rejected",
|
|
53
|
-
feedback: reason ?? "Declined by a session following it."
|
|
54
|
-
},
|
|
55
|
-
toolCallId,
|
|
56
|
-
requestContext
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
const result = live.respondToToolApproval({
|
|
60
|
-
decision,
|
|
61
|
-
toolCallId,
|
|
62
|
-
...decision === "decline" ? { declineContext: { reason: reason ?? "Declined by a session following it." } } : {}
|
|
63
|
-
});
|
|
64
|
-
if (!result.accepted) throw new Error(`The answer was not accepted (${result.reason}).`);
|
|
65
|
-
}
|
|
109
|
+
await answerParkedCall(deps, {
|
|
110
|
+
session: row,
|
|
111
|
+
toolCallId,
|
|
112
|
+
decision,
|
|
113
|
+
declineReason: reason ?? "Declined by a session following it."
|
|
114
|
+
});
|
|
66
115
|
deps.auditRecorder.record({
|
|
67
116
|
orgId: scope.orgId,
|
|
68
117
|
actorId: scope.userId,
|
|
@@ -92,6 +141,6 @@ function createFactoryApprovalTools(scope, deps) {
|
|
|
92
141
|
}
|
|
93
142
|
}) };
|
|
94
143
|
}
|
|
95
|
-
export { createFactoryApprovalTools };
|
|
144
|
+
export { answerParkedCall, createFactoryApprovalTools };
|
|
96
145
|
|
|
97
146
|
//# sourceMappingURL=approval-tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-tools.js","names":[],"sources":["../../src/tools/approval-tools.ts"],"sourcesContent":["import { RequestContext } from '@mastra/core/request-context';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport type { IntegrationTools } from '../integrations/base.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport type { FactoryMessaging } from './messaging-tools.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryApprovalToolDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getBySessionId'>;\n workItems: Pick<WorkItemsStorage, 'findActiveRunBindingForSession' | 'listSessionSubscriptions'>;\n auditRecorder: AuditRecorder;\n messaging: () => Promise<FactoryMessaging | null>;\n}\n\n/** The parts of a live session an answer needs: its open approval gates. */\ninterface ApprovalGateSession {\n approval: { isArmed(filter: { toolCallId: string }): boolean };\n respondToToolApproval(input: {\n decision: 'approve' | 'decline';\n toolCallId: string;\n declineContext?: { reason?: string };\n }): { accepted: true } | { accepted: false; reason: string };\n suspensions: { resolve(filter: { toolCallId: string }): { toolName: string } | undefined };\n respondToToolSuspension(input: {\n resumeData: { action: 'approved' | 'rejected'; feedback?: string };\n toolCallId: string;\n requestContext?: RequestContext;\n }): Promise<void>;\n}\n\n/** Answers a tool call another session holds for approval. Only a signed-in person's turn may answer. */\nexport function createFactoryApprovalTools(\n scope: FactoryToolScope,\n deps: FactoryApprovalToolDependencies,\n): IntegrationTools {\n const answer = createTool({\n id: 'factory_answer_approval',\n description: [\n 'Approve or decline a tool call a session you follow is waiting on, as you.',\n 'A `factory-session` notification of kind `approval` names the session, tool, arguments and toolCallId;',\n 'a `blocked` notice for a session parked on submit_plan names the toolCallId of the plan to approve or decline.',\n 'Answer only what the person in this conversation agreed to; decline with a reason the session will see.',\n ].join(' '),\n inputSchema: z\n .object({\n sessionId: z.string().uuid().describe('The session holding the call, from the approval notice.'),\n toolCallId: z.string().trim().min(1).max(200),\n decision: z.enum(['approve', 'decline']),\n reason: z.string().trim().min(1).max(1000).optional().describe('Why, when declining.'),\n })\n .strict(),\n execute: async ({ sessionId, toolCallId, decision, reason }) => {\n requirePerson(scope, 'answer an approval');\n const row = await deps.sessions.getBySessionId(sessionId);\n if (!row || row.orgId !== scope.orgId || row.factoryProjectId !== scope.factoryProjectId) {\n throw new Error(`Session ${sessionId} was not found in this Factory.`);\n }\n if (row.visibility === 'private' && row.userId !== scope.userId) {\n throw new Error(`Session ${sessionId} is private to its owner.`);\n }\n\n // Only the sessions it reports to may answer it: its origin, or followers of its item.\n const binding = await deps.workItems.findActiveRunBindingForSession({\n orgId: scope.orgId,\n factoryProjectId: scope.factoryProjectId,\n sessionId,\n });\n const isOrigin = row.originSessionId === scope.sessionId;\n const follows =\n binding !== null &&\n (\n await deps.workItems.listSessionSubscriptions({\n orgId: scope.orgId,\n factoryProjectId: scope.factoryProjectId,\n sessionId: scope.sessionId,\n })\n ).some(subscription => subscription.workItemId === binding.workItemId);\n if (!isOrigin && !follows) {\n throw new Error(\n `This session doesn't follow session ${sessionId}: follow its work item first, or answer from that session.`,\n );\n }\n\n const messaging = await deps.messaging();\n if (!messaging) throw new Error('Answering approvals is not available on this server.');\n const live = (await messaging.controller.getSession(sessionId)) as ApprovalGateSession | null;\n const parkedPlan = live?.suspensions.resolve({ toolCallId })?.toolName === 'submit_plan';\n if (!live || (!parkedPlan && !live.approval.isArmed({ toolCallId }))) {\n throw new Error(\n 'Nothing is waiting on that tool call any more: the run that asked has ended or it was already answered. ' +\n 'Message the session with factory_signal_session if it should try again.',\n );\n }\n if (parkedPlan) {\n // The resumed run acts for the person answering, so it can resolve their model credentials.\n const requestContext = new RequestContext();\n requestContext.set('user', { workosId: scope.userId, organizationId: scope.orgId });\n await live.respondToToolSuspension({\n resumeData:\n decision === 'approve'\n ? { action: 'approved' }\n : { action: 'rejected', feedback: reason ?? 'Declined by a session following it.' },\n toolCallId,\n requestContext,\n });\n } else {\n const result = live.respondToToolApproval({\n decision,\n toolCallId,\n ...(decision === 'decline'\n ? { declineContext: { reason: reason ?? 'Declined by a session following it.' } }\n : {}),\n });\n if (!result.accepted) throw new Error(`The answer was not accepted (${result.reason}).`);\n }\n\n deps.auditRecorder.record({\n orgId: scope.orgId,\n actorId: scope.userId,\n actorType: 'human',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n action: decision === 'approve' ? 'factory.run.approved' : 'factory.run.dismissed',\n factoryProjectId: scope.factoryProjectId,\n targets: [\n { type: 'session', id: sessionId },\n ...(binding ? [{ type: 'work_item' as const, id: binding.workItemId }] : []),\n ],\n metadata: { toolCallId, sessionId, decision, cause: 'factory_tools' },\n });\n return { answered: decision, sessionId, toolCallId };\n },\n });\n\n return { factory_answer_approval: answer };\n}\n"],"mappings":";;;;;;AAoCA,SAAgB,2BACd,OACA,MACkB;CAmGlB,OAAO,EAAE,yBAlGM,WAAW;EACxB,IAAI;EACJ,aAAa;GACX;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,GAAG;EACV,aAAa,EACV,OAAO;GACN,WAAW,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,yDAAyD;GAC/F,YAAY,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;GAC5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IAAI,MACR,iLAEF;GAEF,IAAI,YAAY;IAEd,MAAM,iBAAiB,IAAI,eAAe;IAC1C,eAAe,IAAI,QAAQ;KAAE,UAAU,MAAM;KAAQ,gBAAgB,MAAM;IAAM,CAAC;IAClF,MAAM,KAAK,wBAAwB;KACjC,YACE,aAAa,YACT,EAAE,QAAQ,WAAW,IACrB;MAAE,QAAQ;MAAY,UAAU,UAAU;KAAsC;KACtF;KACA;IACF,CAAC;GACH,OAAO;IACL,MAAM,SAAS,KAAK,sBAAsB;KACxC;KACA;KACA,GAAI,aAAa,YACb,EAAE,gBAAgB,EAAE,QAAQ,UAAU,sCAAsC,EAAE,IAC9E,CAAC;IACP,CAAC;IACD,IAAI,CAAC,OAAO,UAAU,MAAM,IAAI,MAAM,gCAAgC,OAAO,OAAO,GAAG;GACzF;GAEA,KAAK,cAAc,OAAO;IACxB,OAAO,MAAM;IACb,SAAS,MAAM;IACf,WAAW;IACX,GAAI,MAAM,eAAe,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;IACjE,QAAQ,aAAa,YAAY,yBAAyB;IAC1D,kBAAkB,MAAM;IACxB,SAAS,CACP;KAAE,MAAM;KAAW,IAAI;IAAU,GACjC,GAAI,UAAU,CAAC;KAAE,MAAM;KAAsB,IAAI,QAAQ;IAAW,CAAC,IAAI,CAAC,CAC5E;IACA,UAAU;KAAE;KAAY;KAAW;KAAU,OAAO;IAAgB;GACtE,CAAC;GACD,OAAO;IAAE,UAAU;IAAU;IAAW;GAAW;EACrD;CACF,CAEuC,EAAE;AAC3C"}
|
|
1
|
+
{"version":3,"file":"approval-tools.js","names":[],"sources":["../../src/tools/approval-tools.ts"],"sourcesContent":["import type { SuspensionAddress } from '@mastra/core/agent-controller';\nimport { RequestContext } from '@mastra/core/request-context';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport type { IntegrationTools } from '../integrations/base.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport type { FactoryMessaging } from './messaging-tools.js';\nimport { resumesOnDecision } from './run-watch.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryApprovalToolDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getBySessionId'>;\n workItems: Pick<WorkItemsStorage, 'findActiveRunBindingForSession' | 'listSessionSubscriptions'>;\n auditRecorder: AuditRecorder;\n messaging: () => Promise<FactoryMessaging | null>;\n}\n\n/** The parts of a live session an answer needs: the calls it waits on, and how each is answered. */\ninterface ApprovalGateSession {\n approval: { list(): Array<{ toolCallId: string; toolName: string }> };\n displayState: {\n get(): { pendingSuspensions: Map<string, { toolCallId: string; toolName: string; resumeSchema?: string }> };\n };\n respondToToolApproval(input: {\n decision: 'approve' | 'decline';\n toolCallId: string;\n requestContext?: RequestContext;\n declineContext?: { reason?: string };\n }): { accepted: true } | { accepted: false; reason: string };\n suspensions: { has(address: SuspensionAddress): boolean };\n /** Takes the right to answer a paused call, so two answers cannot both resume it. */\n claimToolSuspension(\n toolCallId: string,\n ): { accepted: true; address: SuspensionAddress; claimKey: string } | { accepted: false; reason: string };\n releaseToolResponse(claimKey: string): void;\n respondToToolSuspension(input: {\n resumeData: { action: 'approved' | 'rejected'; feedback?: string };\n address: SuspensionAddress;\n requestContext?: RequestContext;\n }): Promise<void>;\n}\n\nconst ALREADY_ANSWERED = 'That call was already answered: someone else got there first.';\n\n/** A tool call waiting for a yes or no, and which of the session's two channels answers it. */\ninterface WaitingApproval {\n toolCallId: string;\n toolName: string;\n /** `gate`: the call has not run yet. `resume`: the tool paused itself to ask. */\n channel: 'gate' | 'resume';\n}\n\nfunction waitingApprovals(live: ApprovalGateSession): WaitingApproval[] {\n return [\n ...live.approval.list().map(({ toolCallId, toolName }) => ({ toolCallId, toolName, channel: 'gate' as const })),\n // Keyed by run address, not tool call id: read the id off each entry.\n ...[...live.displayState.get().pendingSuspensions.values()]\n .filter(suspension => resumesOnDecision(suspension.resumeSchema))\n .map(({ toolCallId, toolName }) => ({ toolCallId, toolName, channel: 'resume' as const })),\n ];\n}\n\n/**\n * Approve or decline a tool call a live session waits on, for a caller already allowed\n * to. Any tool can wait this way; with no `toolCallId` the session's only waiting call\n * is answered. The answered run carries on as the session's owner whoever answers: a\n * phase session keeps one identity from kickoff to finish, and a resume never runs with\n * no user.\n */\nexport async function answerParkedCall(\n deps: Pick<FactoryApprovalToolDependencies, 'messaging'>,\n input: {\n session: { sessionId: string; userId: string; orgId: string };\n toolCallId?: string;\n decision: 'approve' | 'decline';\n declineReason: string;\n },\n): Promise<{ toolCallId: string; toolName: string }> {\n const { session, decision, declineReason } = input;\n const messaging = await deps.messaging();\n if (!messaging) throw new Error('Answering approvals is not available on this server.');\n const live = (await messaging.controller.getSession(session.sessionId)) as ApprovalGateSession | null;\n const waiting = live ? waitingApprovals(live) : [];\n const matches = input.toolCallId ? waiting.filter(call => call.toolCallId === input.toolCallId) : waiting;\n const [call] = matches;\n if (!live || !call) {\n throw new Error(\n input.toolCallId\n ? 'Nothing is waiting on that tool call any more: the run that asked has ended or it was already answered. ' +\n 'Message the session with factory_signal_session if it should try again.'\n : 'This session is not waiting on an approval. Open it to see what it needs.',\n );\n }\n if (matches.length > 1) {\n throw new Error(\n `This session waits on ${matches.length} approvals (${matches.map(match => `${match.toolName}: ${match.toolCallId}`).join(', ')}). Name the toolCallId to answer.`,\n );\n }\n const { toolCallId, toolName } = call;\n const requestContext = new RequestContext();\n requestContext.set('user', { workosId: session.userId, organizationId: session.orgId });\n if (call.channel === 'resume') {\n // Claimed before anything is awaited: of two answers arriving together, one resumes the call.\n const claim = live.claimToolSuspension(toolCallId);\n if (!claim.accepted) throw new Error(ALREADY_ANSWERED);\n try {\n await live.respondToToolSuspension({\n resumeData: decision === 'approve' ? { action: 'approved' } : { action: 'rejected', feedback: declineReason },\n address: claim.address,\n requestContext,\n });\n } finally {\n live.releaseToolResponse(claim.claimKey);\n }\n // A resume that fails to start reports its error to the session and leaves the call waiting.\n if (live.suspensions.has(claim.address)) {\n throw new Error(\n `The answer did not reach ${toolName}: the session could not carry on and still waits on it. Open the session to see why.`,\n );\n }\n return { toolCallId, toolName };\n }\n const result = live.respondToToolApproval({\n decision,\n toolCallId,\n requestContext,\n ...(decision === 'decline' ? { declineContext: { reason: declineReason } } : {}),\n });\n if (!result.accepted) {\n throw new Error(\n result.reason === 'not_pending' ? ALREADY_ANSWERED : `The answer was not accepted (${result.reason}).`,\n );\n }\n return { toolCallId, toolName };\n}\n\n/** Answers a tool call another session holds for approval. Only a signed-in person's turn may answer. */\nexport function createFactoryApprovalTools(\n scope: FactoryToolScope,\n deps: FactoryApprovalToolDependencies,\n): IntegrationTools {\n const answer = createTool({\n id: 'factory_answer_approval',\n description: [\n 'Approve or decline a tool call a session you follow is waiting on.',\n 'The decision is recorded as yours; the run carries on as the owner of the session that asked.',\n 'A `factory-session` notification of kind `approval` names the session, tool, arguments and toolCallId;',\n 'a `blocked` notice for a session parked on a tool that waits for approval names the toolCallId to approve or decline.',\n 'Answer only what the person in this conversation agreed to; decline with a reason the session will see.',\n ].join(' '),\n inputSchema: z\n .object({\n sessionId: z.string().uuid().describe('The session holding the call, from the approval notice.'),\n toolCallId: z.string().trim().min(1).max(200),\n decision: z.enum(['approve', 'decline']),\n reason: z.string().trim().min(1).max(1000).optional().describe('Why, when declining.'),\n })\n .strict(),\n execute: async ({ sessionId, toolCallId, decision, reason }) => {\n requirePerson(scope, 'answer an approval');\n const row = await deps.sessions.getBySessionId(sessionId);\n if (!row || row.orgId !== scope.orgId || row.factoryProjectId !== scope.factoryProjectId) {\n throw new Error(`Session ${sessionId} was not found in this Factory.`);\n }\n if (row.visibility === 'private' && row.userId !== scope.userId) {\n throw new Error(`Session ${sessionId} is private to its owner.`);\n }\n\n // Only the sessions it reports to may answer it: its origin, or followers of its item.\n const binding = await deps.workItems.findActiveRunBindingForSession({\n orgId: scope.orgId,\n factoryProjectId: scope.factoryProjectId,\n sessionId,\n });\n const isOrigin = row.originSessionId === scope.sessionId;\n const follows =\n binding !== null &&\n (\n await deps.workItems.listSessionSubscriptions({\n orgId: scope.orgId,\n factoryProjectId: scope.factoryProjectId,\n sessionId: scope.sessionId,\n })\n ).some(subscription => subscription.workItemId === binding.workItemId);\n if (!isOrigin && !follows) {\n throw new Error(\n `This session doesn't follow session ${sessionId}: follow its work item first, or answer from that session.`,\n );\n }\n\n await answerParkedCall(deps, {\n session: row,\n toolCallId,\n decision,\n declineReason: reason ?? 'Declined by a session following it.',\n });\n\n deps.auditRecorder.record({\n orgId: scope.orgId,\n actorId: scope.userId,\n actorType: 'human',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n action: decision === 'approve' ? 'factory.run.approved' : 'factory.run.dismissed',\n factoryProjectId: scope.factoryProjectId,\n targets: [\n { type: 'session', id: sessionId },\n ...(binding ? [{ type: 'work_item' as const, id: binding.workItemId }] : []),\n ],\n metadata: { toolCallId, sessionId, decision, cause: 'factory_tools' },\n });\n return { answered: decision, sessionId, toolCallId };\n },\n });\n\n return { factory_answer_approval: answer };\n}\n"],"mappings":";;;;;;AA8CA,MAAM,mBAAmB;AAUzB,SAAS,iBAAiB,MAA8C;CACtE,OAAO,CACL,GAAG,KAAK,SAAS,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,gBAAgB;EAAE;EAAY;EAAU,SAAS;CAAgB,EAAE,GAE9G,GAAG,CAAC,GAAG,KAAK,aAAa,IAAI,CAAC,CAAC,mBAAmB,OAAO,CAAC,CAAC,CACxD,QAAO,eAAc,kBAAkB,WAAW,YAAY,CAAC,CAAC,CAChE,KAAK,EAAE,YAAY,gBAAgB;EAAE;EAAY;EAAU,SAAS;CAAkB,EAAE,CAC7F;AACF;;;;;;;;AASA,eAAsB,iBACpB,MACA,OAMmD;CACnD,MAAM,EAAE,SAAS,UAAU,kBAAkB;CAC7C,MAAM,YAAY,MAAM,KAAK,UAAU;CACvC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,MAAM;IACxB,WAAW,MAAM;GACnB,CAAC,EAAA,CACD,MAAK,iBAAgB,aAAa,eAAe,QAAQ,UAAU;GACvE,IAAI,CAAC,YAAY,CAAC,SAChB,MAAM,IAAI,MACR,uCAAuC,UAAU,2DACnD;GAGF,MAAM,iBAAiB,MAAM;IAC3B,SAAS;IACT;IACA;IACA,eAAe,UAAU;GAC3B,CAAC;GAED,KAAK,cAAc,OAAO;IACxB,OAAO,MAAM;IACb,SAAS,MAAM;IACf,WAAW;IACX,GAAI,MAAM,eAAe,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;IACjE,QAAQ,aAAa,YAAY,yBAAyB;IAC1D,kBAAkB,MAAM;IACxB,SAAS,CACP;KAAE,MAAM;KAAW,IAAI;IAAU,GACjC,GAAI,UAAU,CAAC;KAAE,MAAM;KAAsB,IAAI,QAAQ;IAAW,CAAC,IAAI,CAAC,CAC5E;IACA,UAAU;KAAE;KAAY;KAAW;KAAU,OAAO;IAAgB;GACtE,CAAC;GACD,OAAO;IAAE,UAAU;IAAU;IAAW;GAAW;EACrD;CACF,CAEuC,EAAE;AAC3C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SourceControlSessionLookup } from '../session/factory-session.js';
|
|
2
|
+
import type { FactoryReadToolDependencies } from './read-tools.js';
|
|
3
|
+
import type { FactoryToolScope } from './scope.js';
|
|
4
|
+
export interface FactoryAuditToolDependencies {
|
|
5
|
+
workItems: FactoryReadToolDependencies['workItems'];
|
|
6
|
+
audit: FactoryReadToolDependencies['audit'];
|
|
7
|
+
messaging?: FactoryReadToolDependencies['messaging'];
|
|
8
|
+
/** Finds the sessions an event names or an agent ran in, to leave out other people's private sessions. */
|
|
9
|
+
sessions?: Pick<SourceControlSessionLookup, 'getBySessionId'>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Who did what in this Factory, from its audit trail. The trail is org-wide and
|
|
13
|
+
* its reads are unscoped by design, so this tool narrows what it hands back:
|
|
14
|
+
* only this Factory's events, never request context (IP, user agent), names but
|
|
15
|
+
* never emails, no metadata beyond what was acted on, and no events from or
|
|
16
|
+
* about another person's private session.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createAuditEventsTool(scope: FactoryToolScope, deps: FactoryAuditToolDependencies): import("@mastra/core/tools").Tool<{
|
|
19
|
+
actor?: string | undefined;
|
|
20
|
+
includeAgentRuns?: boolean | undefined;
|
|
21
|
+
namespace?: "agent" | "board" | "git" | "intake" | "intake_route" | "run" | "sandbox_env" | "session" | "skill" | "work_item" | undefined;
|
|
22
|
+
actions?: ("factory.agent.commit" | "factory.agent.pr_opened" | "factory.agent.push" | "factory.agent.signaled" | "factory.board.created" | "factory.board.deleted" | "factory.board.reset" | "factory.board.updated" | "factory.git.commit" | "factory.git.pr_opened" | "factory.git.push" | "factory.intake.binding_updated" | "factory.intake.config_updated" | "factory.intake.label_route_updated" | "factory.intake_route.created" | "factory.intake_route.deleted" | "factory.intake_route.reordered" | "factory.intake_route.rerouted" | "factory.intake_route.updated" | "factory.run.approved" | "factory.run.dismissed" | "factory.run.ended" | "factory.run.queued" | "factory.run.rejected" | "factory.run.retry" | "factory.run.started" | "factory.sandbox_env.deleted" | "factory.sandbox_env.set" | "factory.sandbox_env.updated" | "factory.session.owner_transferred" | "factory.skill.reverted" | "factory.skill.updated" | "factory.work_item.created" | "factory.work_item.deleted" | "factory.work_item.labels_reconciled" | "factory.work_item.stage_moved" | "factory.work_item.transition_rejected" | "factory.work_item.updated")[] | undefined;
|
|
23
|
+
workItem?: string | undefined;
|
|
24
|
+
since?: string | undefined;
|
|
25
|
+
until?: string | undefined;
|
|
26
|
+
cursor?: string | undefined;
|
|
27
|
+
limit?: number | undefined;
|
|
28
|
+
}, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "factory_list_audit_events", unknown>;
|
|
29
|
+
//# sourceMappingURL=audit-events-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-events-tool.d.ts","sourceRoot":"","sources":["../../src/tools/audit-events-tool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAUhF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AASnD,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC;IACpD,KAAK,EAAE,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC;IACrD,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,IAAI,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;CAC/D;AA4CD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,4BAA4B;;;;;;;;;;kJAmEhG"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { auditActionsInNamespaces, auditNamespaces, isAuditAction } from "../storage/domains/audit/actions.js";
|
|
2
|
+
import { ACTOR_PROFILE_METADATA_KEY, auditCursorAt, decodeAuditAfterCursor, encodeAuditCursor } from "../storage/domains/audit/base.js";
|
|
3
|
+
import { findWorkItem, truncate, workItemNotFound, workItemRefSchema } from "./read-tools.js";
|
|
4
|
+
import { createTool } from "@mastra/core/tools";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/tools/audit-events-tool.ts
|
|
7
|
+
const DEFAULT_LIMIT = 25;
|
|
8
|
+
const PAGE_SIZE = 200;
|
|
9
|
+
/** Pages read per call before handing back a cursor, so a narrow filter can't scan the whole trail at once. */
|
|
10
|
+
const MAX_PAGES = 5;
|
|
11
|
+
const AGENT_ACTOR_PREFIX = "agent:";
|
|
12
|
+
const SESSION_ACTOR_PREFIX = "session:";
|
|
13
|
+
const namespaces = auditNamespaces();
|
|
14
|
+
const inputSchema = z.object({
|
|
15
|
+
actor: z.string().trim().min(1).max(200).optional().describe("\"me\", a user id, or an agent actor id like \"agent:<threadId>\". Only events this actor performed."),
|
|
16
|
+
includeAgentRuns: z.boolean().optional().describe("With a person as `actor`: also include what agents did in runs that person started."),
|
|
17
|
+
namespace: z.enum(namespaces).optional().describe("Only actions in this namespace, e.g. \"work_item\" or \"run\"."),
|
|
18
|
+
actions: z.array(z.string().refine(isAuditAction, { message: "Not a Factory audit action." })).min(1).max(50).optional().describe("Only these exact actions, e.g. [\"factory.work_item.stage_moved\"]."),
|
|
19
|
+
workItem: workItemRefSchema.optional().describe("Only events that acted on this work item (id or \"#123\")."),
|
|
20
|
+
since: z.iso.datetime({ offset: true }).optional().describe("Only events at or after this ISO time."),
|
|
21
|
+
until: z.iso.datetime({ offset: true }).optional().describe("Only events before this ISO time."),
|
|
22
|
+
cursor: z.string().min(1).max(200).optional().describe("`nextCursor` from a previous call, to read older events."),
|
|
23
|
+
limit: z.number().int().min(1).max(50).optional().describe(`Default ${DEFAULT_LIMIT}, max 50.`)
|
|
24
|
+
}).strict();
|
|
25
|
+
/** A display name stamped at record time, or nothing when it is an email (the fallback when a person has no name). */
|
|
26
|
+
function actorName(event) {
|
|
27
|
+
const profile = event.metadata?.[ACTOR_PROFILE_METADATA_KEY];
|
|
28
|
+
const name = typeof profile?.name === "string" ? profile.name.trim() : "";
|
|
29
|
+
return name && !name.includes("@") ? truncate(name, 600) : void 0;
|
|
30
|
+
}
|
|
31
|
+
function startedBy(event) {
|
|
32
|
+
const value = event.metadata?.startedBy;
|
|
33
|
+
return event.actorType === "agent" && typeof value === "string" ? value : void 0;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Who did what in this Factory, from its audit trail. The trail is org-wide and
|
|
37
|
+
* its reads are unscoped by design, so this tool narrows what it hands back:
|
|
38
|
+
* only this Factory's events, never request context (IP, user agent), names but
|
|
39
|
+
* never emails, no metadata beyond what was acted on, and no events from or
|
|
40
|
+
* about another person's private session.
|
|
41
|
+
*/
|
|
42
|
+
function createAuditEventsTool(scope, deps) {
|
|
43
|
+
const project = {
|
|
44
|
+
orgId: scope.orgId,
|
|
45
|
+
factoryProjectId: scope.factoryProjectId
|
|
46
|
+
};
|
|
47
|
+
return createTool({
|
|
48
|
+
id: "factory_list_audit_events",
|
|
49
|
+
description: "List this Factory's audit events, newest first: who did what to which work item, run, branch or setting, and when. Filter by actor (\"me\" or a user id, optionally with the agent runs they started), action namespace or exact actions, work item, and time range. Pass `nextCursor` back as `cursor` for older events. Events from other people's private sessions are left out.",
|
|
50
|
+
inputSchema,
|
|
51
|
+
execute: async (input) => {
|
|
52
|
+
if (input.cursor && !decodeAuditAfterCursor(input.cursor)) throw new Error("That cursor is not one this tool returned.");
|
|
53
|
+
const since = input.since ? new Date(input.since) : void 0;
|
|
54
|
+
const until = input.until ? new Date(input.until) : void 0;
|
|
55
|
+
if (since && until && since >= until) throw new Error("`since` must be before `until`.");
|
|
56
|
+
if (input.includeAgentRuns && (!input.actor || input.actor.startsWith(AGENT_ACTOR_PREFIX))) throw new Error("`includeAgentRuns` needs a person as `actor`.");
|
|
57
|
+
let workItemId;
|
|
58
|
+
if (input.workItem) {
|
|
59
|
+
const item = await findWorkItem(deps.workItems, scope, input.workItem);
|
|
60
|
+
if (!item) throw workItemNotFound(input.workItem);
|
|
61
|
+
workItemId = item.id;
|
|
62
|
+
}
|
|
63
|
+
const namespaceActions = input.namespace ? auditActionsInNamespaces([input.namespace]) : void 0;
|
|
64
|
+
const actions = input.actions && namespaceActions ? input.actions.filter((action) => namespaceActions.includes(action)) : input.actions ?? namespaceActions;
|
|
65
|
+
if (actions && actions.length === 0) return { events: [] };
|
|
66
|
+
const actorId = input.actor === "me" ? scope.userId : input.actor;
|
|
67
|
+
const limit = input.limit ?? DEFAULT_LIMIT;
|
|
68
|
+
const visible = eventVisibility(scope, deps);
|
|
69
|
+
const events = [];
|
|
70
|
+
let before = input.cursor ?? (until ? auditCursorAt(until) : void 0);
|
|
71
|
+
const beforeUntil = (event) => !until || event.occurredAt < until;
|
|
72
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
73
|
+
const result = await deps.audit.list({
|
|
74
|
+
...project,
|
|
75
|
+
...actions ? { actions } : {},
|
|
76
|
+
...actorId && !input.includeAgentRuns ? { actorId } : {},
|
|
77
|
+
...before ? { before } : {},
|
|
78
|
+
limit: PAGE_SIZE
|
|
79
|
+
});
|
|
80
|
+
for (const event of result.events) {
|
|
81
|
+
if (since && event.occurredAt < since) return { events };
|
|
82
|
+
if (!beforeUntil(event)) continue;
|
|
83
|
+
if (actorId && event.actorId !== actorId && startedBy(event) !== actorId) continue;
|
|
84
|
+
if (workItemId && !event.targets.some((target) => target.type === "work_item" && target.id === workItemId)) continue;
|
|
85
|
+
if (!await visible(event)) continue;
|
|
86
|
+
events.push(summarize(event));
|
|
87
|
+
if (events.length === limit) return {
|
|
88
|
+
events,
|
|
89
|
+
nextCursor: encodeAuditCursor(event)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!result.nextCursor) return { events };
|
|
93
|
+
before = result.nextCursor;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
events,
|
|
97
|
+
nextCursor: before
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function summarize(event) {
|
|
103
|
+
const name = actorName(event);
|
|
104
|
+
const runStartedBy = startedBy(event);
|
|
105
|
+
return {
|
|
106
|
+
action: event.action,
|
|
107
|
+
occurredAt: event.occurredAt.toISOString(),
|
|
108
|
+
actor: {
|
|
109
|
+
type: event.actorType,
|
|
110
|
+
id: event.actorId,
|
|
111
|
+
...name ? { name } : {}
|
|
112
|
+
},
|
|
113
|
+
...runStartedBy ? { startedBy: runStartedBy } : {},
|
|
114
|
+
targets: event.targets.slice(0, 10).map((target) => ({
|
|
115
|
+
type: target.type,
|
|
116
|
+
id: truncate(target.id, 600),
|
|
117
|
+
...target.name ? { name: truncate(target.name, 600) } : {}
|
|
118
|
+
}))
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Sessions an event names: its session targets and the session it records it acted in. */
|
|
122
|
+
function sessionRefs(event) {
|
|
123
|
+
const ids = event.targets.filter((target) => target.type === "session").map((target) => target.id);
|
|
124
|
+
const recorded = event.metadata?.sessionId;
|
|
125
|
+
if (typeof recorded === "string") ids.push(recorded);
|
|
126
|
+
return [...new Set(ids)];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Whether the caller may see an event. An event that names a session, or an
|
|
130
|
+
* agent's act (which belongs to the session it ran in), is only visible when
|
|
131
|
+
* every such session is shared or the caller's own. Fails closed when a
|
|
132
|
+
* session can't be found.
|
|
133
|
+
*/
|
|
134
|
+
function eventVisibility(scope, deps) {
|
|
135
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
136
|
+
const threads = /* @__PURE__ */ new Map();
|
|
137
|
+
let runAgents;
|
|
138
|
+
const sessionVisible = (sessionId) => {
|
|
139
|
+
let result = sessions.get(sessionId);
|
|
140
|
+
if (!result) {
|
|
141
|
+
result = (async () => {
|
|
142
|
+
const row = await deps.sessions?.getBySessionId(sessionId);
|
|
143
|
+
if (!row || row.orgId !== scope.orgId || row.factoryProjectId !== scope.factoryProjectId) return false;
|
|
144
|
+
return row.visibility !== "private" || row.userId === scope.userId;
|
|
145
|
+
})().catch(() => false);
|
|
146
|
+
sessions.set(sessionId, result);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
};
|
|
150
|
+
const threadVisible = async (threadId) => {
|
|
151
|
+
runAgents ??= deps.workItems.listRunBindings(scope.orgId, scope.factoryProjectId).then((bindings) => new Set(bindings.flatMap((binding) => [binding.threadId, binding.id])));
|
|
152
|
+
if ((await runAgents).has(threadId)) return true;
|
|
153
|
+
const controller = (await deps.messaging?.())?.controller;
|
|
154
|
+
if (!controller) return false;
|
|
155
|
+
const thread = await controller.queryThreadById({ threadId });
|
|
156
|
+
if (!thread) return false;
|
|
157
|
+
const stamped = thread.metadata?.factorySessionId;
|
|
158
|
+
return sessionVisible(typeof stamped === "string" ? stamped : thread.id);
|
|
159
|
+
};
|
|
160
|
+
const agentVisible = (event) => {
|
|
161
|
+
if (startedBy(event) === scope.userId) return true;
|
|
162
|
+
if (!event.actorId.startsWith(AGENT_ACTOR_PREFIX)) return false;
|
|
163
|
+
const threadId = event.actorId.slice(6);
|
|
164
|
+
let result = threads.get(threadId);
|
|
165
|
+
if (!result) {
|
|
166
|
+
const sessionId = threadId.startsWith(SESSION_ACTOR_PREFIX) ? threadId.slice(8) : void 0;
|
|
167
|
+
result = (sessionId ? sessionVisible(sessionId) : threadVisible(threadId)).catch(() => false);
|
|
168
|
+
threads.set(threadId, result);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
172
|
+
return async (event) => {
|
|
173
|
+
if (event.actorType === "agent" && !await agentVisible(event)) return false;
|
|
174
|
+
for (const sessionId of sessionRefs(event)) if (!await sessionVisible(sessionId)) return false;
|
|
175
|
+
return true;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export { createAuditEventsTool };
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=audit-events-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-events-tool.js","names":[],"sources":["../../src/tools/audit-events-tool.ts"],"sourcesContent":["import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport { auditActionsInNamespaces, auditNamespaces, isAuditAction } from '../storage/domains/audit/actions.js';\nimport type { AuditNamespace } from '../storage/domains/audit/actions.js';\nimport {\n ACTOR_PROFILE_METADATA_KEY,\n auditCursorAt,\n decodeAuditAfterCursor,\n encodeAuditCursor,\n} from '../storage/domains/audit/base.js';\nimport type { AuditEventRow } from '../storage/domains/audit/base.js';\nimport type { FactoryReadToolDependencies } from './read-tools.js';\nimport { MAX_LIST, MAX_TEXT, findWorkItem, truncate, workItemNotFound, workItemRefSchema } from './read-tools.js';\nimport type { FactoryToolScope } from './scope.js';\n\nconst DEFAULT_LIMIT = 25;\nconst PAGE_SIZE = 200;\n/** Pages read per call before handing back a cursor, so a narrow filter can't scan the whole trail at once. */\nconst MAX_PAGES = 5;\nconst AGENT_ACTOR_PREFIX = 'agent:';\nconst SESSION_ACTOR_PREFIX = 'session:';\n\nexport interface FactoryAuditToolDependencies {\n workItems: FactoryReadToolDependencies['workItems'];\n audit: FactoryReadToolDependencies['audit'];\n messaging?: FactoryReadToolDependencies['messaging'];\n /** Finds the sessions an event names or an agent ran in, to leave out other people's private sessions. */\n sessions?: Pick<SourceControlSessionLookup, 'getBySessionId'>;\n}\n\nconst namespaces = auditNamespaces() as [AuditNamespace, ...AuditNamespace[]];\n\nconst inputSchema = z\n .object({\n actor: z\n .string()\n .trim()\n .min(1)\n .max(200)\n .optional()\n .describe('\"me\", a user id, or an agent actor id like \"agent:<threadId>\". Only events this actor performed.'),\n includeAgentRuns: z\n .boolean()\n .optional()\n .describe('With a person as `actor`: also include what agents did in runs that person started.'),\n namespace: z.enum(namespaces).optional().describe('Only actions in this namespace, e.g. \"work_item\" or \"run\".'),\n actions: z\n .array(z.string().refine(isAuditAction, { message: 'Not a Factory audit action.' }))\n .min(1)\n .max(50)\n .optional()\n .describe('Only these exact actions, e.g. [\"factory.work_item.stage_moved\"].'),\n workItem: workItemRefSchema.optional().describe('Only events that acted on this work item (id or \"#123\").'),\n since: z.iso.datetime({ offset: true }).optional().describe('Only events at or after this ISO time.'),\n until: z.iso.datetime({ offset: true }).optional().describe('Only events before this ISO time.'),\n cursor: z.string().min(1).max(200).optional().describe('`nextCursor` from a previous call, to read older events.'),\n limit: z.number().int().min(1).max(MAX_LIST).optional().describe(`Default ${DEFAULT_LIMIT}, max ${MAX_LIST}.`),\n })\n .strict();\n\n/** A display name stamped at record time, or nothing when it is an email (the fallback when a person has no name). */\nfunction actorName(event: AuditEventRow): string | undefined {\n const profile = event.metadata?.[ACTOR_PROFILE_METADATA_KEY] as { name?: unknown } | undefined;\n const name = typeof profile?.name === 'string' ? profile.name.trim() : '';\n return name && !name.includes('@') ? truncate(name, MAX_TEXT) : undefined;\n}\n\nfunction startedBy(event: AuditEventRow): string | undefined {\n const value = event.metadata?.startedBy;\n return event.actorType === 'agent' && typeof value === 'string' ? value : undefined;\n}\n\n/**\n * Who did what in this Factory, from its audit trail. The trail is org-wide and\n * its reads are unscoped by design, so this tool narrows what it hands back:\n * only this Factory's events, never request context (IP, user agent), names but\n * never emails, no metadata beyond what was acted on, and no events from or\n * about another person's private session.\n */\nexport function createAuditEventsTool(scope: FactoryToolScope, deps: FactoryAuditToolDependencies) {\n const project = { orgId: scope.orgId, factoryProjectId: scope.factoryProjectId };\n\n return createTool({\n id: 'factory_list_audit_events',\n description:\n 'List this Factory\\'s audit events, newest first: who did what to which work item, run, branch or setting, and when. Filter by actor (\"me\" or a user id, optionally with the agent runs they started), action namespace or exact actions, work item, and time range. Pass `nextCursor` back as `cursor` for older events. Events from other people\\'s private sessions are left out.',\n inputSchema,\n execute: async input => {\n if (input.cursor && !decodeAuditAfterCursor(input.cursor)) {\n throw new Error('That cursor is not one this tool returned.');\n }\n const since = input.since ? new Date(input.since) : undefined;\n const until = input.until ? new Date(input.until) : undefined;\n if (since && until && since >= until) throw new Error('`since` must be before `until`.');\n if (input.includeAgentRuns && (!input.actor || input.actor.startsWith(AGENT_ACTOR_PREFIX))) {\n throw new Error('`includeAgentRuns` needs a person as `actor`.');\n }\n\n let workItemId: string | undefined;\n if (input.workItem) {\n const item = await findWorkItem(deps.workItems, scope, input.workItem);\n if (!item) throw workItemNotFound(input.workItem);\n workItemId = item.id;\n }\n\n const namespaceActions = input.namespace ? auditActionsInNamespaces([input.namespace]) : undefined;\n const actions =\n input.actions && namespaceActions\n ? input.actions.filter(action => namespaceActions.includes(action))\n : (input.actions ?? namespaceActions);\n if (actions && actions.length === 0) return { events: [] };\n\n const actorId = input.actor === 'me' ? scope.userId : input.actor;\n const limit = input.limit ?? DEFAULT_LIMIT;\n const visible = eventVisibility(scope, deps);\n\n const events: ReturnType<typeof summarize>[] = [];\n let before = input.cursor ?? (until ? auditCursorAt(until) : undefined);\n // `auditCursorAt` sits after every row at that instant; `until` excludes them.\n const beforeUntil = (event: AuditEventRow) => !until || event.occurredAt < until;\n for (let page = 0; page < MAX_PAGES; page++) {\n const result = await deps.audit.list({\n ...project,\n ...(actions ? { actions } : {}),\n ...(actorId && !input.includeAgentRuns ? { actorId } : {}),\n ...(before ? { before } : {}),\n limit: PAGE_SIZE,\n });\n for (const event of result.events) {\n if (since && event.occurredAt < since) return { events };\n if (!beforeUntil(event)) continue;\n if (actorId && event.actorId !== actorId && startedBy(event) !== actorId) continue;\n if (workItemId && !event.targets.some(target => target.type === 'work_item' && target.id === workItemId)) {\n continue;\n }\n if (!(await visible(event))) continue;\n events.push(summarize(event));\n if (events.length === limit) return { events, nextCursor: encodeAuditCursor(event) };\n }\n if (!result.nextCursor) return { events };\n before = result.nextCursor;\n }\n // Scan budget spent: hand back where to pick up, even with fewer events than asked for.\n return { events, nextCursor: before };\n },\n });\n}\n\nfunction summarize(event: AuditEventRow) {\n const name = actorName(event);\n const runStartedBy = startedBy(event);\n return {\n action: event.action,\n occurredAt: event.occurredAt.toISOString(),\n actor: { type: event.actorType, id: event.actorId, ...(name ? { name } : {}) },\n ...(runStartedBy ? { startedBy: runStartedBy } : {}),\n targets: event.targets.slice(0, 10).map(target => ({\n type: target.type,\n id: truncate(target.id, MAX_TEXT),\n ...(target.name ? { name: truncate(target.name, MAX_TEXT) } : {}),\n })),\n };\n}\n\n/** Sessions an event names: its session targets and the session it records it acted in. */\nfunction sessionRefs(event: AuditEventRow): string[] {\n const ids = event.targets.filter(target => target.type === 'session').map(target => target.id);\n const recorded = event.metadata?.sessionId;\n if (typeof recorded === 'string') ids.push(recorded);\n return [...new Set(ids)];\n}\n\n/**\n * Whether the caller may see an event. An event that names a session, or an\n * agent's act (which belongs to the session it ran in), is only visible when\n * every such session is shared or the caller's own. Fails closed when a\n * session can't be found.\n */\nfunction eventVisibility(scope: FactoryToolScope, deps: FactoryAuditToolDependencies) {\n const sessions = new Map<string, Promise<boolean>>();\n const threads = new Map<string, Promise<boolean>>();\n let runAgents: Promise<Set<string>> | undefined;\n\n const sessionVisible = (sessionId: string): Promise<boolean> => {\n let result = sessions.get(sessionId);\n if (!result) {\n result = (async () => {\n const row = await deps.sessions?.getBySessionId(sessionId);\n if (!row || row.orgId !== scope.orgId || row.factoryProjectId !== scope.factoryProjectId) return false;\n return row.visibility !== 'private' || row.userId === scope.userId;\n })().catch(() => false);\n sessions.set(sessionId, result);\n }\n return result;\n };\n\n const threadVisible = async (threadId: string): Promise<boolean> => {\n // Work item runs are on the board for everyone in the Factory. A run's agent is recorded\n // under its thread (commits, pushes, signals) or under its binding (stage moves).\n runAgents ??= deps.workItems\n .listRunBindings(scope.orgId, scope.factoryProjectId)\n .then(bindings => new Set(bindings.flatMap(binding => [binding.threadId, binding.id])));\n if ((await runAgents).has(threadId)) return true;\n\n const controller = (await deps.messaging?.())?.controller;\n if (!controller) return false;\n const thread = await controller.queryThreadById({ threadId });\n if (!thread) return false;\n const stamped = thread.metadata?.factorySessionId;\n return sessionVisible(typeof stamped === 'string' ? stamped : thread.id);\n };\n\n const agentVisible = (event: AuditEventRow): Promise<boolean> | boolean => {\n if (startedBy(event) === scope.userId) return true;\n if (!event.actorId.startsWith(AGENT_ACTOR_PREFIX)) return false;\n const threadId = event.actorId.slice(AGENT_ACTOR_PREFIX.length);\n let result = threads.get(threadId);\n if (!result) {\n // Turns nobody signed in started are recorded as their session's agent: `agent:session:<sessionId>`.\n // Work item runs are created shared, so the session's own visibility decides.\n const sessionId = threadId.startsWith(SESSION_ACTOR_PREFIX)\n ? threadId.slice(SESSION_ACTOR_PREFIX.length)\n : undefined;\n result = (sessionId ? sessionVisible(sessionId) : threadVisible(threadId)).catch(() => false);\n threads.set(threadId, result);\n }\n return result;\n };\n\n return async (event: AuditEventRow): Promise<boolean> => {\n if (event.actorType === 'agent' && !(await agentVisible(event))) return false;\n for (const sessionId of sessionRefs(event)) {\n if (!(await sessionVisible(sessionId))) return false;\n }\n return true;\n };\n}\n"],"mappings":";;;;;;AAiBA,MAAM,gBAAgB;AACtB,MAAM,YAAY;;AAElB,MAAM,YAAY;AAClB,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAU7B,MAAM,aAAa,gBAAgB;AAEnC,MAAM,cAAc,EACjB,OAAO;CACN,OAAO,EACJ,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,SAAS,CAAC,CACV,SAAS,sGAAkG;CAC9G,kBAAkB,EACf,QAAQ,CAAC,CACT,SAAS,CAAC,CACV,SAAS,qFAAqF;CACjG,WAAW,EAAE,KAAK,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,gEAA4D;CAC9G,SAAS,EACN,MAAM,EAAE,OAAO,CAAC,CAAC,OAAO,eAAe,EAAE,SAAS,8BAA8B,CAAC,CAAC,CAAC,CACnF,IAAI,CAAC,CAAC,CACN,IAAI,EAAE,CAAC,CACP,SAAS,CAAC,CACV,SAAS,qEAAmE;CAC/E,UAAU,kBAAkB,SAAS,CAAC,CAAC,SAAS,4DAA0D;CAC1G,OAAO,EAAE,IAAI,SAAS,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,wCAAwC;CACpG,OAAO,EAAE,IAAI,SAAS,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,mCAAmC;CAC/F,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,0DAA0D;CACjH,OAAO,EAAE,OAAO,CAAC,CAAC,I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,MAAM,aAAa,YAAY,KAAK,GACvC,IAAI,CAAE,MAAM,eAAe,SAAS,GAAI,OAAO;EAEjD,OAAO;CACT;AACF"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IntegrationTools } from '../integrations/base.js';
|
|
2
2
|
import type { FactoryApprovalToolDependencies } from './approval-tools.js';
|
|
3
|
+
import type { FactoryAuditToolDependencies } from './audit-events-tool.js';
|
|
3
4
|
import type { FactoryMessagingToolDependencies } from './messaging-tools.js';
|
|
4
5
|
import type { FactoryReadToolDependencies } from './read-tools.js';
|
|
5
6
|
import type { FactoryToolScope } from './scope.js';
|
|
@@ -9,7 +10,7 @@ export { FACTORY_TOOLS_WITHOUT_APPROVAL, applyFactoryToolPermissions } from './p
|
|
|
9
10
|
export { FACTORY_INTERACTIVE_KEY, resolveFactoryToolScope } from './scope.js';
|
|
10
11
|
export type { FactoryToolScope } from './scope.js';
|
|
11
12
|
/** Storage and services the Factory tools act through. */
|
|
12
|
-
export type FactoryToolDependencies = FactoryReadToolDependencies & FactoryWorkItemToolDependencies & FactoryMessagingToolDependencies & FactorySessionToolDependencies & FactoryApprovalToolDependencies;
|
|
13
|
+
export type FactoryToolDependencies = FactoryReadToolDependencies & FactoryAuditToolDependencies & FactoryWorkItemToolDependencies & FactoryMessagingToolDependencies & FactorySessionToolDependencies & FactoryApprovalToolDependencies;
|
|
13
14
|
export interface CreateFactoryToolsOptions {
|
|
14
15
|
scope: FactoryToolScope;
|
|
15
16
|
deps: FactoryToolDependencies;
|