@mastra/factory 0.28.0 → 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 +6 -4
- 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/environment/repository-access.d.ts +2 -0
- package/dist/environment/repository-access.d.ts.map +1 -1
- package/dist/environment/repository-access.js +9 -4
- package/dist/environment/repository-access.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +9 -6
- 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.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 +46 -0
- package/dist/integrations/platform/github/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/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 +1 -1
- package/dist/mcp/routes.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +8 -1
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +23 -2
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/contracts.d.ts +205 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +159 -5
- 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/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/surface.d.ts +6 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +72 -9
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-item-selection.d.ts +0 -4
- package/dist/routes/work-item-selection.d.ts.map +1 -1
- package/dist/routes/work-item-selection.js +4 -21
- package/dist/routes/work-item-selection.js.map +1 -1
- package/dist/routes/work-item-starters.d.ts.map +1 -1
- package/dist/routes/work-item-starters.js +4 -21
- package/dist/routes/work-item-starters.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +112 -36
- 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 +5 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +2 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +39 -18
- 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/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.map +1 -1
- package/dist/rules/transition-service.js +3 -2
- 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/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/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/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 +8 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +11 -1
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +15 -4
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +19 -1
- package/dist/storage/domains/work-items/base.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 +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/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/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-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/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/workspace.d.ts.map +1 -1
- package/dist/workspace.js +92 -47
- package/dist/workspace.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -64,6 +64,8 @@ The whole-board listing also returns a `cursor`, and each card carries `changedA
|
|
|
64
64
|
|
|
65
65
|
Two reads answer questions about a project's cards without listing them. `GET /web/factory/projects/:id/work-items/starters` counts the cards on the default board that each new-session starter would act on: cards whose run failed, pull requests with changes requested, pull requests waiting for review (with when the oldest was opened), triaged cards waiting on a person, untriaged cards, bugs with no plan, the label with the most cards not started, and stale pull requests. Failed runs are read from the 50 newest run decisions, as on the cards. `GET /web/factory/projects/:id/work-items/activity?since=<ISO 8601 instant>` returns how many cards the project has, and when cards were created and completed from `since` on; a missing or malformed `since` is a 400. Its answer carries an `ETag`: ask again for the same `since` with `If-None-Match`, and an answer that did not change comes back as a 304 with no body.
|
|
66
66
|
|
|
67
|
+
Two more reads serve a board without sending every card. `GET /web/factory/projects/:id/boards/:boardKey/phases` returns one entry per phase of the board in `phases`, in the board's order: `phase` is its id, `total` counts the cards in it, and `cards` names the first of them as `{ id, version }`. `version` names the card's body: it is another value whenever anything in the body is, including a change that leaves `changedAt` as it was. `limit` sets how many each phase names (50 unless given, 200 at most), `window=<phase>:<count>` (repeatable) names more cards of one phase, and `item=<card id>` asks for one card wherever it lies: the answer names it in `item` as `{ id, version, places }`, where `places` gives each phase the view lists it under and its `position` there (how many cards the phase lists before it), and `cards=true` sends its body. No phase names more cards for it, so the answer is the same size for the oldest card of a phase as for the newest. `places` is empty when the search or filters leave the card out, and `item` is absent when the board does not hold the card. `sort` is `recent` (latest entry into the phase first, the default), `recent-mine` (the cards the signed-in user last moved into the phase first), `created-newest` or `created-oldest`. `q` keeps the cards whose title, key, number or source id contains every word in it; `label`, `source`, `linearProject`, `teammate`, `author`, `assignee`, `reviewer` and `worked` (all repeatable) keep the cards matching every field given. `boardTotal` counts the board's cards whatever the search and filters, `matchingTotal` the cards matching them, a card in two phases once. `related` names the cards related to a named card that no phase names, the first `limit` of each card's, and `relatedTotal` counts them all, and `runningSessionIds` and `parkedSessionIds` cover the named cards. Pass `cards=true` to also receive the body of every named card in `workItems`, each with its `version`; without it, read the cards whose `version` differs from the copy you kept with `GET /web/factory/projects/:id/work-items?workItemId=<id>`, which sends each card with its `version` too. A card in none of the board's phases is counted in the first one. A malformed parameter is a 400 `invalid_phases_query`; a board the project doesn't have is a 404; a `window` for a phase the board doesn't have is ignored. `GET /web/factory/projects/:id/work-items/filter-options` returns what a board can be filtered by, over every card of the project: `labels`, sorted; `people`, each person a source names as author, assignee or requested reviewer, as `{ id, name, source }`; and `actorIds`, the Factory users who filed, moved or started a card. Both answers carry an `ETag`; send it back as `If-None-Match` and an unchanged answer is a 304.
|
|
68
|
+
|
|
67
69
|
#### Migration and dry run
|
|
68
70
|
|
|
69
71
|
Factory keeps the legacy `work_items` table and copies each card into the new tables. Before it starts serving, it copies only open cards. Done and canceled cards are copied in the background afterwards and appear on the board shortly after startup. While that runs, opening a card, or receiving a Linear, Jira, GitHub, GitLab, or incident.io event for it, copies that card on demand, so a reopened issue keeps its original card. Board lists, such as the Done column, fill in as the background copy progresses.
|
|
@@ -620,7 +622,7 @@ Boards and phases take `name` and an optional `description`. A phase lists the p
|
|
|
620
622
|
- `runner` — `{ agentId?, skill?, context?, instructions?, goal? }`. The runner is the only way a phase starts work: when a card enters the phase, from any source and including a card filed straight into it, Factory starts `skill` in the `context` session. `context` names the session the phase runs in (defaults to `work`); phases that share a context share a session. When the agent moves its own card into another phase of its context, that phase's `skill` still starts: its kickoff is queued onto the agent's run. Moving a card back into the phase it is in (a re-entry, such as a re-review after a push) supersedes the run in flight and resumes the skill. `skill` names a built-in Factory skill or one of your app's skills (see [Skills for custom boards](#skills-for-custom-boards)); a phase without one starts nothing. The kickoff names the card only by its URL (or title, quoted as untrusted data when an outside author wrote it); the agent reads everything else from the [`factory-work-item` signal](#the-factory-work-item-signal). `instructions` (up to 1,000 characters) are added to the kickoff. `agentId` defaults to `code-agent`, the only agent Factory runs today.
|
|
621
623
|
- `runner.goal` — `{ objective, maxRuns? }`: the run pursues `objective` (up to 2,000 characters) as a Mastra goal. Factory stores it on the session's thread as the run starts, with the session's model as judge, and after each run the judge decides from the objective text and the latest messages whether the work is done, should continue (Factory starts another run, up to `maxRuns`, 1–50) or is waiting for a person. Waiting leaves the goal active and the card in its phase; the next message a person sends resumes it, and a skill asks people with `ask_user`, which parks the run in Factory's attention view. When `maxRuns` runs out, the goal pauses and the card stays: resume it from the session or move the card. When the card leaves the phase, by anyone, Factory marks the goal done. The judge sees only the objective and the latest messages, so state the done and waiting criteria in the objective. Work's Building pursues the approved plan this way, with up to 20 runs.
|
|
622
624
|
- `autoStart` and `autoStartWhen` — the phase's runs start without a person's approval, for every card or only for cards matching the rule. To start only trusted authors' cards, add `author.trusted equals true` to `autoStartWhen`; by default, [intake routes](#intake-routes) file GitHub and GitLab cards from outside the write-access circle in Work › Intake, where nothing starts on its own.
|
|
623
|
-
- `exitTool` — a tool name, or `{ id, autoApprove, autoApproveWhen }`, that ends the phase. The phase holds the card until that tool succeeds (for `submit_plan`, with an approved plan) in the session that works the card there: until then an agent or board rule asking to move the card on to another working phase is rejected with `approval_required`. Once it has succeeded during the card's current visit to the phase, the agent moves the card itself with `factory_transition_work_item` (the factory-phase signal tells it so and lists `nextPhases`), or a board tool rule for the exit tool (`tools`) moves it; the tool's success never moves the card by itself. A person can move the card at any time. The phase needs at least one next phase. `autoApprove` and `autoApproveWhen` only decide whether the tool approves itself, for every card or only cards matching the rule, or waits for a person; they are the only way plans are approved without a person. Factory sessions already run tools without asking, so for `submit_plan` this means an auto-approved plan is accepted without a person. Work's Planning declares `{ id: 'submit_plan', autoApprove: false }`: every plan waits for a person, who approves `submit_plan` in a signed-in chat (or moves the card), and then `factory-plan` moves the card to Building.
|
|
625
|
+
- `exitTool` — a tool name, or `{ id, autoApprove, autoApproveWhen }`, that ends the phase. The phase holds the card until that tool succeeds (for `submit_plan`, with an approved plan) in the session that works the card there: until then an agent or board rule asking to move the card on to another working phase is rejected with `approval_required`. Once it has succeeded during the card's current visit to the phase, the agent moves the card itself with `factory_transition_work_item` (the factory-phase signal tells it so and lists `nextPhases`), or a board tool rule for the exit tool (`tools`) moves it; the tool's success never moves the card by itself. A person can move the card at any time. The phase needs at least one next phase. `autoApprove` and `autoApproveWhen` only decide whether the tool approves itself, for every card or only cards matching the rule, or waits for a person; they are the only way plans are approved without a person. Factory sessions already run tools without asking, so for `submit_plan` this means an auto-approved plan is accepted without a person. Any other exit tool that pauses for a yes or no is approved the same way, and the sessions following the card are told a run waits on them only when a person has to answer. Work's Planning declares `{ id: 'submit_plan', autoApprove: false }`: every plan waits for a person, who approves `submit_plan` in a signed-in chat (or moves the card), and then `factory-plan` moves the card to Building.
|
|
624
626
|
- `tools` — Factory tools the phase gives the session that works the card in it (the session whose context is the phase's `runner.context`): `factory_record_review_verdict` and `factory_review_source`. Tools follow the card: when it moves to a phase without them, the session loses them on its next turn, and a verdict tool call made after the card moved is refused. Every bound session keeps `factory_transition_work_item`. Work's Review grants both; a self-review phase, on a board that has one, grants only the verdict tool.
|
|
625
627
|
|
|
626
628
|
Rules test a card's facts, read from its work item as the provider reported it:
|
|
@@ -1282,7 +1284,7 @@ Read tools and `factory_message_origin` are available on every turn. The other t
|
|
|
1282
1284
|
|
|
1283
1285
|
`factory_switch_session_model` changes the model of a side, work item or review session you own in the same Factory, without recreating it. It refuses a model this server can't run. A running session switches right away; a stopped one uses the model on its next run.
|
|
1284
1286
|
|
|
1285
|
-
`factory_create_work_item` files the card as the caller where the project's [intake routes](#intake-routes) send it, or in the Work board's first phase when no route matches (a project without Work: its first board's), stores the description that its runs start from, and subscribes the session. Name the `repository` when the Factory links more than one: a run can't start on a card that doesn't say which. `factory_update_work_item` sets it afterwards, like choosing a repository on the card, and also edits the title, the description and the parent item. It can't pre-approve plans: a plan waits for a person unless the board's phase auto-approves it. Both refuse a repository the Factory doesn't link, and a card synced from an issue keeps the issue's repository. Stages, the board and role sessions aren't fields it edits; stages move with `factory_transition_work_item`. Subscriptions are stored per work item and session in the `factory_work_item_subscriptions` collection and are removed with the item, so any number of sessions can follow one item.
|
|
1287
|
+
`factory_create_work_item` files the card as the caller where the project's [intake routes](#intake-routes) send it, or in the Work board's first phase when no route matches (a project without Work: its first board's), stores the description that its runs start from, and subscribes the session. Name the `repository` when the Factory links more than one: a run can't start on a card that doesn't say which. `factory_update_work_item` sets it afterwards, like choosing a repository on the card, and also edits the title, the description and the parent item. It can't pre-approve plans: a plan waits for a person unless the board's phase auto-approves it. Both refuse a repository the Factory doesn't link, and a card synced from an issue keeps the issue's repository. Stages, the board and role sessions aren't fields it edits; stages move with `factory_transition_work_item`. A session that moves a card follows it from then on, so it hears from the run the move starts. Subscriptions are stored per work item and session in the `factory_work_item_subscriptions` collection and are removed with the item, so any number of sessions can follow one item.
|
|
1286
1288
|
|
|
1287
1289
|
#### Messaging between sessions
|
|
1288
1290
|
|
|
@@ -1299,7 +1301,7 @@ How a message is delivered depends on its priority. `urgent` always delivers, ev
|
|
|
1299
1301
|
- **Side session** (no `workItem`): a standalone session with no work item, for a one-off job. It uses the same repository as the session that started it. Factory stores that session on the new session's row (`origin_session_id`, `origin_thread_id`) and copies the parent's visibility. It runs on the model of the session that started it, or on `model` when one is passed. That model has to be one the session's credentials can run; an unknown or unrunnable model is refused before anything is created. When the parent has no model set, the side session keeps the Factory's default worker model.
|
|
1300
1302
|
- **Work-item role** (`workItem` and `role`): starts a role the item's board seats, the same way **Start** does in the Factory UI. The card does not move and no autonomy is armed. The tool refuses when the role already has a session, naming it so the agent can message it instead, and refuses an item linked to several repositories. The caller is subscribed to the item, and the run is recorded as `factory.run.started` with the caller as the person who started it.
|
|
1301
1303
|
|
|
1302
|
-
|
|
1304
|
+
A side session belongs to the caller and runs with the caller's credentials. A work-item role belongs to the caller only in a Factory on the `user` model scope. Where card work runs on the organization's keys (`factory` and `hybrid`), the role's session belongs to the Factory itself, as every phase session there does, whoever started or moved the card: the person is recorded as the one who started it, and their session follows the card so it hears when that run waits on someone and can approve or decline from there. Without an organization model key the start is refused with a message saying to add one. A work-item role keeps the Factory's default worker model. The first message runs with only the session's owner as its user, never the rest of the parent turn's context. The tool needs no approval but, like the other management tools, only appears on turns a signed-in person started.
|
|
1303
1305
|
|
|
1304
1306
|
#### Reports
|
|
1305
1307
|
|
|
@@ -1317,7 +1319,7 @@ Progress reports from one session replace each other while unread. `done`, `fail
|
|
|
1317
1319
|
|
|
1318
1320
|
Every run of a work session or side session ends with exactly one final report, however the run started: the board, a person typing into the session, a wake from another session's message, or a run after a server restart. Each Factory session gets a listener when it is created. A session with an active run binding reports to everyone following its work item, including for the run that moved the item to a finished stage and so ended its own binding; a side session reports to the session that started it; a person's own session reports to nobody. When a run ends, Factory checks each recipient's thread for a final report the agent sent since the run started, and sends one itself to the recipients that lack it: `done` when the run completed, `failed` when it ended in error (quoting the error), and `blocked`, naming the tool, when the run stopped waiting for an answer or for someone to approve a tool call. A reply with a final `status` counts as the final report, and any reply counts for a completed run. A run that completes after the agent reported `blocked` is waiting for an answer, so it gets no `done`; a run someone stopped gets no report. A board run that fails before it ever runs (no session, a configuration the run can't succeed with) reports `failed` once no retry remains. These backstop reports carry a `backstop` attribute.
|
|
1319
1321
|
|
|
1320
|
-
A run that holds a tool call for approval stays open, so the same listener tells those sessions right away: an urgent `approval` notification names the session, the tool, its arguments and the `toolCallId`, once per call. A session that follows the work item, or started the side session, can answer it with `factory_answer_approval`, as the person signed in to it; the answer is audited as `factory.run.approved` or `factory.run.dismissed`. Other people's private sessions can't be answered, and an approval whose run already ended can't be either: the tool says so, and the session can be messaged to try again.
|
|
1322
|
+
A run that holds a tool call for approval stays open, so the same listener tells those sessions right away: an urgent `approval` notification names the session, the tool, its arguments and the `toolCallId`, once per call. A session that follows the work item, or started the side session, can answer it with `factory_answer_approval`, as the person signed in to it; the answer is audited as `factory.run.approved` or `factory.run.dismissed`. A tool that pauses itself for a bare yes or no, such as `submit_plan`, ends the run instead: the `blocked` report then names the session and the `toolCallId` to approve or decline the same way, while a tool that needs a typed answer is answered in its session. Whoever answers, the run carries on as the session's owner. Other people's private sessions can't be answered, and an approval whose run already ended can't be either: the tool says so, and the session can be messaged to try again.
|
|
1321
1323
|
|
|
1322
1324
|
When a followed work item changes stage, subscribers whose session is running get a `low` priority `stage` notice. A stage change never wakes an offline session; it sees the current stage in its state signal instead.
|
|
1323
1325
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';
|
|
2
|
+
import type { Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
3
|
+
import type { BoardRegistry } from './registry.js';
|
|
4
|
+
export type RerouteMove = {
|
|
5
|
+
item: Card;
|
|
6
|
+
fromBoard: string;
|
|
7
|
+
toBoard: string;
|
|
8
|
+
toPhase: string;
|
|
9
|
+
routeId: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Which untouched cards the routes, as they stand, would file on a different board. Each lands at
|
|
13
|
+
* the start of its new board. A card no route places stays where it is.
|
|
14
|
+
*/
|
|
15
|
+
export declare function planReroute(routes: readonly StoredIntakeRouteRecord[], items: readonly Card[], registry: BoardRegistry): RerouteMove[];
|
|
16
|
+
/** How many cards a plan moves from each board to each other board. */
|
|
17
|
+
export declare function summarizeReroute(moves: readonly RerouteMove[]): {
|
|
18
|
+
fromBoard: string;
|
|
19
|
+
toBoard: string;
|
|
20
|
+
count: number;
|
|
21
|
+
}[];
|
|
22
|
+
export declare function applyReroute({ moves, workItems, registry, userId, }: {
|
|
23
|
+
moves: readonly RerouteMove[];
|
|
24
|
+
workItems: Pick<WorkItemsStorage, 'update' | 'supersedeDecisionsForWorkItem'>;
|
|
25
|
+
registry: BoardRegistry;
|
|
26
|
+
userId: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
moved: number;
|
|
29
|
+
skipped: number;
|
|
30
|
+
}>;
|
|
31
|
+
//# sourceMappingURL=reroute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reroute.d.ts","sourceRoot":"","sources":["../../src/boards/reroute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAGpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAY/G;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,uBAAuB,EAAE,EAC1C,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,QAAQ,EAAE,aAAa,GACtB,WAAW,EAAE,CAYf;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,WAAW,EAAE,GAC5B;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CASzD;AAED,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,SAAS,EACT,QAAQ,EACR,MAAM,GACP,EAAE;IACD,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9B,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,+BAA+B,CAAC,CAAC;IAC9E,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB9C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { cardRuleFacts } from "./card-facts.js";
|
|
2
|
+
import { resolveIntakePlacement } from "./intake-routing.js";
|
|
3
|
+
import { effectiveBoard, moveCardToBoard } from "./relocate.js";
|
|
4
|
+
// src/boards/reroute.ts
|
|
5
|
+
/**
|
|
6
|
+
* A card nobody has worked yet: it sits alone in its board's first phase with no session on it.
|
|
7
|
+
* Only such cards follow a change to the intake routes; anything further along stays put.
|
|
8
|
+
*/
|
|
9
|
+
function untouched(item, registry) {
|
|
10
|
+
const board = registry.get(effectiveBoard(item));
|
|
11
|
+
if (!board) return false;
|
|
12
|
+
return item.stages.length === 1 && item.stages[0] === board.initialPhase && Object.keys(item.sessions).length === 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Which untouched cards the routes, as they stand, would file on a different board. Each lands at
|
|
16
|
+
* the start of its new board. A card no route places stays where it is.
|
|
17
|
+
*/
|
|
18
|
+
function planReroute(routes, items, registry) {
|
|
19
|
+
const moves = [];
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
if (!untouched(item, registry)) continue;
|
|
22
|
+
const placement = resolveIntakePlacement(routes, cardRuleFacts(item), registry);
|
|
23
|
+
if (!placement) continue;
|
|
24
|
+
const fromBoard = effectiveBoard(item);
|
|
25
|
+
if (placement.board === fromBoard) continue;
|
|
26
|
+
const target = registry.get(placement.board);
|
|
27
|
+
moves.push({
|
|
28
|
+
item,
|
|
29
|
+
fromBoard,
|
|
30
|
+
toBoard: placement.board,
|
|
31
|
+
toPhase: target.initialPhase,
|
|
32
|
+
routeId: placement.routeId
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return moves;
|
|
36
|
+
}
|
|
37
|
+
/** How many cards a plan moves from each board to each other board. */
|
|
38
|
+
function summarizeReroute(moves) {
|
|
39
|
+
const counts = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const { fromBoard, toBoard } of moves) {
|
|
41
|
+
const key = `${fromBoard}\u0000${toBoard}`;
|
|
42
|
+
const entry = counts.get(key) ?? {
|
|
43
|
+
fromBoard,
|
|
44
|
+
toBoard,
|
|
45
|
+
count: 0
|
|
46
|
+
};
|
|
47
|
+
entry.count += 1;
|
|
48
|
+
counts.set(key, entry);
|
|
49
|
+
}
|
|
50
|
+
return [...counts.values()];
|
|
51
|
+
}
|
|
52
|
+
async function applyReroute({ moves, workItems, registry, userId }) {
|
|
53
|
+
let moved = 0;
|
|
54
|
+
let skipped = 0;
|
|
55
|
+
for (const move of moves) if (await moveCardToBoard({
|
|
56
|
+
workItems,
|
|
57
|
+
boardRegistry: registry,
|
|
58
|
+
userId,
|
|
59
|
+
item: move.item,
|
|
60
|
+
targetBoard: move.toBoard,
|
|
61
|
+
targetStage: move.toPhase
|
|
62
|
+
}) === "moved") moved += 1;
|
|
63
|
+
else skipped += 1;
|
|
64
|
+
return {
|
|
65
|
+
moved,
|
|
66
|
+
skipped
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export { applyReroute, planReroute, summarizeReroute };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=reroute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reroute.js","names":[],"sources":["../../src/boards/reroute.ts"],"sourcesContent":["import type { StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';\nimport type { Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { cardRuleFacts } from './card-facts.js';\nimport { resolveIntakePlacement } from './intake-routing.js';\nimport type { BoardRegistry } from './registry.js';\nimport { effectiveBoard, moveCardToBoard } from './relocate.js';\n\nexport type RerouteMove = { item: Card; fromBoard: string; toBoard: string; toPhase: string; routeId: string };\n\n/**\n * A card nobody has worked yet: it sits alone in its board's first phase with no session on it.\n * Only such cards follow a change to the intake routes; anything further along stays put.\n */\nfunction untouched(item: Card, registry: BoardRegistry): boolean {\n const board = registry.get(effectiveBoard(item));\n if (!board) return false;\n return item.stages.length === 1 && item.stages[0] === board.initialPhase && Object.keys(item.sessions).length === 0;\n}\n\n/**\n * Which untouched cards the routes, as they stand, would file on a different board. Each lands at\n * the start of its new board. A card no route places stays where it is.\n */\nexport function planReroute(\n routes: readonly StoredIntakeRouteRecord[],\n items: readonly Card[],\n registry: BoardRegistry,\n): RerouteMove[] {\n const moves: RerouteMove[] = [];\n for (const item of items) {\n if (!untouched(item, registry)) continue;\n const placement = resolveIntakePlacement(routes, cardRuleFacts(item), registry);\n if (!placement) continue;\n const fromBoard = effectiveBoard(item);\n if (placement.board === fromBoard) continue;\n const target = registry.get(placement.board)!;\n moves.push({ item, fromBoard, toBoard: placement.board, toPhase: target.initialPhase, routeId: placement.routeId });\n }\n return moves;\n}\n\n/** How many cards a plan moves from each board to each other board. */\nexport function summarizeReroute(\n moves: readonly RerouteMove[],\n): { fromBoard: string; toBoard: string; count: number }[] {\n const counts = new Map<string, { fromBoard: string; toBoard: string; count: number }>();\n for (const { fromBoard, toBoard } of moves) {\n const key = `${fromBoard}\\u0000${toBoard}`;\n const entry = counts.get(key) ?? { fromBoard, toBoard, count: 0 };\n entry.count += 1;\n counts.set(key, entry);\n }\n return [...counts.values()];\n}\n\nexport async function applyReroute({\n moves,\n workItems,\n registry,\n userId,\n}: {\n moves: readonly RerouteMove[];\n workItems: Pick<WorkItemsStorage, 'update' | 'supersedeDecisionsForWorkItem'>;\n registry: BoardRegistry;\n userId: string;\n}): Promise<{ moved: number; skipped: number }> {\n let moved = 0;\n let skipped = 0;\n for (const move of moves) {\n const result = await moveCardToBoard({\n workItems,\n boardRegistry: registry,\n userId,\n item: move.item,\n targetBoard: move.toBoard,\n targetStage: move.toPhase,\n });\n if (result === 'moved') moved += 1;\n else skipped += 1;\n }\n return { moved, skipped };\n}\n"],"mappings":";;;;;;;;AAaA,SAAS,UAAU,MAAY,UAAkC;CAC/D,MAAM,QAAQ,SAAS,IAAI,eAAe,IAAI,CAAC;CAC/C,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,KAAK,OAAO,WAAW,KAAK,KAAK,OAAO,OAAO,MAAM,gBAAgB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW;AACpH;;;;;AAMA,SAAgB,YACd,QACA,OACA,UACe;CACf,MAAM,QAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,UAAU,MAAM,QAAQ,GAAG;EAChC,MAAM,YAAY,uBAAuB,QAAQ,cAAc,IAAI,GAAG,QAAQ;EAC9E,IAAI,CAAC,WAAW;EAChB,MAAM,YAAY,eAAe,IAAI;EACrC,IAAI,UAAU,UAAU,WAAW;EACnC,MAAM,SAAS,SAAS,IAAI,UAAU,KAAK;EAC3C,MAAM,KAAK;GAAE;GAAM;GAAW,SAAS,UAAU;GAAO,SAAS,OAAO;GAAc,SAAS,UAAU;EAAQ,CAAC;CACpH;CACA,OAAO;AACT;;AAGA,SAAgB,iBACd,OACyD;CACzD,MAAM,yBAAS,IAAI,IAAmE;CACtF,KAAK,MAAM,EAAE,WAAW,aAAa,OAAO;EAC1C,MAAM,MAAM,GAAG,UAAU,QAAQ;EACjC,MAAM,QAAQ,OAAO,IAAI,GAAG,KAAK;GAAE;GAAW;GAAS,OAAO;EAAE;EAChE,MAAM,SAAS;EACf,OAAO,IAAI,KAAK,KAAK;CACvB;CACA,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC;AAC5B;AAEA,eAAsB,aAAa,EACjC,OACA,WACA,UACA,UAM8C;CAC9C,IAAI,QAAQ;CACZ,IAAI,UAAU;CACd,KAAK,MAAM,QAAQ,OASjB,IAAI,MARiB,gBAAgB;EACnC;EACA,eAAe;EACf;EACA,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,aAAa,KAAK;CACpB,CAAC,MACc,SAAS,SAAS;MAC5B,WAAW;CAElB,OAAO;EAAE;EAAO;CAAQ;AAC1B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { RepositoryAccess, VersionControl } from '../capabilities/version-control.js';
|
|
2
|
+
/** Split repository ids into the groups one token each can name, keeping order and dropping repeats. */
|
|
3
|
+
export declare function groupRepositoryIds(repositoryIds: readonly string[]): string[][];
|
|
2
4
|
/**
|
|
3
5
|
* Access to each of an environment's repositories, minted a group at a time.
|
|
4
6
|
* Asking for one repository asks for its group of up to ten, so a provider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-access.d.ts","sourceRoot":"","sources":["../../src/environment/repository-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAa/G;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,qBAAqB,GAAG,uBAAuB,CAAC,EACrF,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,GAAG,GAAE,MAAM,MAAiB,GAC3B,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"repository-access.d.ts","sourceRoot":"","sources":["../../src/environment/repository-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAa/G,wGAAwG;AACxG,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAK/E;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,qBAAqB,GAAG,uBAAuB,CAAC,EACrF,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,GAAG,GAAE,MAAM,MAAiB,GAC3B,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CA6BrD"}
|
|
@@ -7,6 +7,13 @@ const REPOSITORIES_PER_TOKEN = 10;
|
|
|
7
7
|
* group would add requests exactly when there is no budget for them.
|
|
8
8
|
*/
|
|
9
9
|
const GROUP_RETRY_AFTER_MS = 6e4;
|
|
10
|
+
/** Split repository ids into the groups one token each can name, keeping order and dropping repeats. */
|
|
11
|
+
function groupRepositoryIds(repositoryIds) {
|
|
12
|
+
const ids = [...new Set(repositoryIds)];
|
|
13
|
+
const groups = [];
|
|
14
|
+
for (let i = 0; i < ids.length; i += REPOSITORIES_PER_TOKEN) groups.push(ids.slice(i, i + REPOSITORIES_PER_TOKEN));
|
|
15
|
+
return groups;
|
|
16
|
+
}
|
|
10
17
|
/**
|
|
11
18
|
* Access to each of an environment's repositories, minted a group at a time.
|
|
12
19
|
* Asking for one repository asks for its group of up to ten, so a provider
|
|
@@ -18,9 +25,7 @@ const GROUP_RETRY_AFTER_MS = 6e4;
|
|
|
18
25
|
* repository's own token.
|
|
19
26
|
*/
|
|
20
27
|
function groupedRepositoryAccess(versionControl, orgId, repositoryIds, now = Date.now) {
|
|
21
|
-
const
|
|
22
|
-
const groups = [];
|
|
23
|
-
for (let i = 0; i < ids.length; i += REPOSITORIES_PER_TOKEN) groups.push(ids.slice(i, i + REPOSITORIES_PER_TOKEN));
|
|
28
|
+
const groups = groupRepositoryIds(repositoryIds);
|
|
24
29
|
const skipUntil = /* @__PURE__ */ new Map();
|
|
25
30
|
const pending = /* @__PURE__ */ new Map();
|
|
26
31
|
const groupAccess = (group, getRepositoriesAccess) => {
|
|
@@ -50,6 +55,6 @@ function groupedRepositoryAccess(versionControl, orgId, repositoryIds, now = Dat
|
|
|
50
55
|
});
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
|
-
export { groupedRepositoryAccess };
|
|
58
|
+
export { groupRepositoryIds, groupedRepositoryAccess };
|
|
54
59
|
|
|
55
60
|
//# sourceMappingURL=repository-access.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-access.js","names":[],"sources":["../../src/environment/repository-access.ts"],"sourcesContent":["import type { RepositoriesAccess, RepositoryAccess, VersionControl } from '../capabilities/version-control.js';\n\ntype GetRepositoriesAccess = NonNullable<VersionControl['getRepositoriesAccess']>;\n\n/** The most repositories one Platform GitHub token can name. */\nconst REPOSITORIES_PER_TOKEN = 10;\n/**\n * How long a group the provider refused or failed to mint is skipped. A failed\n * group mint is often a rate limit, so retrying it for every repository in the\n * group would add requests exactly when there is no budget for them.\n */\nconst GROUP_RETRY_AFTER_MS = 60_000;\n\n/**\n * Access to each of an environment's repositories, minted a group at a time.\n * Asking for one repository asks for its group of up to ten, so a provider\n * that can grant a group mints one token for it and serves every repository in\n * it from that token, instead of minting one per repository (eleven\n * repositories: two mints, not eleven). The group token stays with these\n * callers: a plain `getRepositoryAccess` elsewhere still gets a token for its\n * own repository only. A group the provider can't grant falls back to the\n * repository's own token.\n */\nexport function groupedRepositoryAccess(\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>,\n orgId: string,\n repositoryIds: readonly string[],\n now: () => number = Date.now,\n): (repositoryId: string) => Promise<RepositoryAccess> {\n const
|
|
1
|
+
{"version":3,"file":"repository-access.js","names":[],"sources":["../../src/environment/repository-access.ts"],"sourcesContent":["import type { RepositoriesAccess, RepositoryAccess, VersionControl } from '../capabilities/version-control.js';\n\ntype GetRepositoriesAccess = NonNullable<VersionControl['getRepositoriesAccess']>;\n\n/** The most repositories one Platform GitHub token can name. */\nconst REPOSITORIES_PER_TOKEN = 10;\n/**\n * How long a group the provider refused or failed to mint is skipped. A failed\n * group mint is often a rate limit, so retrying it for every repository in the\n * group would add requests exactly when there is no budget for them.\n */\nconst GROUP_RETRY_AFTER_MS = 60_000;\n\n/** Split repository ids into the groups one token each can name, keeping order and dropping repeats. */\nexport function groupRepositoryIds(repositoryIds: readonly string[]): string[][] {\n const ids = [...new Set(repositoryIds)];\n const groups: string[][] = [];\n for (let i = 0; i < ids.length; i += REPOSITORIES_PER_TOKEN) groups.push(ids.slice(i, i + REPOSITORIES_PER_TOKEN));\n return groups;\n}\n\n/**\n * Access to each of an environment's repositories, minted a group at a time.\n * Asking for one repository asks for its group of up to ten, so a provider\n * that can grant a group mints one token for it and serves every repository in\n * it from that token, instead of minting one per repository (eleven\n * repositories: two mints, not eleven). The group token stays with these\n * callers: a plain `getRepositoryAccess` elsewhere still gets a token for its\n * own repository only. A group the provider can't grant falls back to the\n * repository's own token.\n */\nexport function groupedRepositoryAccess(\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>,\n orgId: string,\n repositoryIds: readonly string[],\n now: () => number = Date.now,\n): (repositoryId: string) => Promise<RepositoryAccess> {\n const groups = groupRepositoryIds(repositoryIds);\n const skipUntil = new Map<string[], number>();\n const pending = new Map<string[], Promise<RepositoriesAccess | undefined>>();\n const groupAccess = (group: string[], getRepositoriesAccess: GetRepositoriesAccess) => {\n let request = pending.get(group);\n if (!request) {\n // Best-effort: the repository's own token still works without it.\n request = getRepositoriesAccess({ orgId, repositoryIds: group })\n .catch(() => undefined)\n .then(access => {\n if (!access) skipUntil.set(group, now() + GROUP_RETRY_AFTER_MS);\n return access;\n })\n .finally(() => pending.delete(group));\n pending.set(group, request);\n }\n return request;\n };\n return async repositoryId => {\n const group = groups.find(candidate => candidate.includes(repositoryId));\n const getRepositoriesAccess = versionControl.getRepositoriesAccess?.bind(versionControl);\n if (group && group.length > 1 && getRepositoriesAccess && (skipUntil.get(group) ?? 0) <= now()) {\n // Parallel callers share one group request.\n const own = (await groupAccess(group, getRepositoriesAccess))?.repositories?.[repositoryId];\n if (own) return own;\n }\n return versionControl.getRepositoryAccess({ orgId, repositoryId });\n };\n}\n"],"mappings":";;AAKA,MAAM,yBAAyB;;;;;;AAM/B,MAAM,uBAAuB;;AAG7B,SAAgB,mBAAmB,eAA8C;CAC/E,MAAM,MAAM,CAAC,GAAG,IAAI,IAAI,aAAa,CAAC;CACtC,MAAM,SAAqB,CAAC;CAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,wBAAwB,OAAO,KAAK,IAAI,MAAM,GAAG,IAAI,sBAAsB,CAAC;CACjH,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,wBACd,gBACA,OACA,eACA,MAAoB,KAAK,KAC4B;CACrD,MAAM,SAAS,mBAAmB,aAAa;CAC/C,MAAM,4BAAY,IAAI,IAAsB;CAC5C,MAAM,0BAAU,IAAI,IAAuD;CAC3E,MAAM,eAAe,OAAiB,0BAAiD;EACrF,IAAI,UAAU,QAAQ,IAAI,KAAK;EAC/B,IAAI,CAAC,SAAS;GAEZ,UAAU,sBAAsB;IAAE;IAAO,eAAe;GAAM,CAAC,CAAC,CAC7D,YAAY,KAAA,CAAS,CAAC,CACtB,MAAK,WAAU;IACd,IAAI,CAAC,QAAQ,UAAU,IAAI,OAAO,IAAI,IAAI,oBAAoB;IAC9D,OAAO;GACT,CAAC,CAAC,CACD,cAAc,QAAQ,OAAO,KAAK,CAAC;GACtC,QAAQ,IAAI,OAAO,OAAO;EAC5B;EACA,OAAO;CACT;CACA,OAAO,OAAM,iBAAgB;EAC3B,MAAM,QAAQ,OAAO,MAAK,cAAa,UAAU,SAAS,YAAY,CA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;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAsB9B;IAED,oGAAoG;IAC9F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAsC9B;CACF"}
|
package/dist/factory.js
CHANGED
|
@@ -39,8 +39,8 @@ import { createFactoryTransitionTools } from "./rules/tools.js";
|
|
|
39
39
|
import { FactoryTransitionService } from "./rules/transition-service.js";
|
|
40
40
|
import { assertFactoryConfigVersion } from "./rules/validation.js";
|
|
41
41
|
import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
|
|
42
|
-
import { resolveFactoryToolScope } from "./tools/scope.js";
|
|
43
42
|
import { controllerRunInFlight, createContextSandboxStops, createTerminalSandboxStops } from "./sandbox/context-sandboxes.js";
|
|
43
|
+
import { resolveFactoryToolScope } from "./tools/scope.js";
|
|
44
44
|
import { isValidGitRef } from "./sandbox/git-ref.js";
|
|
45
45
|
import { LocalFactorySandbox } from "./sandbox/local-factory-sandbox.js";
|
|
46
46
|
import { CachedSandboxEnvs } from "./sandbox/sandbox-env-cache.js";
|
|
@@ -1496,11 +1496,14 @@ var MastraFactory = class {
|
|
|
1496
1496
|
threadId: session.thread.getId(),
|
|
1497
1497
|
outcome,
|
|
1498
1498
|
since
|
|
1499
|
-
}), {
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1499
|
+
}), {
|
|
1500
|
+
onApprovalRequested: (request) => notifyApprovalRequested({
|
|
1501
|
+
sessionId: session.identity.getId(),
|
|
1502
|
+
threadId: session.thread.getId(),
|
|
1503
|
+
...request
|
|
1504
|
+
}),
|
|
1505
|
+
answersItself: (toolCallId) => this.#dispatcher?.autoApproves(toolCallId) ?? false
|
|
1506
|
+
});
|
|
1504
1507
|
observeSessionThreadStamp(session);
|
|
1505
1508
|
});
|
|
1506
1509
|
prepared.base.controller.onSessionCreated((session) => hydrateSessionMemorySettings(session, { sourceControl: { sessions: sourceControlSessions } }), { blocking: true });
|