@grok/agent-sdk 0.5.0 → 0.7.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/AGENTS.md +40 -0
- package/dist/channels/github/forward.d.ts +5 -0
- package/dist/channels/github/forward.d.ts.map +1 -1
- package/dist/channels/github/forward.js +6 -3
- package/dist/channels/slack/api.d.ts +18 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +31 -0
- package/dist/channels/slack/approvals.d.ts +19 -2
- package/dist/channels/slack/approvals.d.ts.map +1 -1
- package/dist/channels/slack/approvals.js +90 -19
- package/dist/channels/slack/attachments.d.ts +7 -2
- package/dist/channels/slack/attachments.d.ts.map +1 -1
- package/dist/channels/slack/attachments.js +318 -156
- package/dist/channels/slack/connect-card.d.ts +16 -0
- package/dist/channels/slack/connect-card.d.ts.map +1 -0
- package/dist/channels/slack/connect-card.js +31 -0
- package/dist/channels/slack/credentials.d.ts +10 -2
- package/dist/channels/slack/credentials.d.ts.map +1 -1
- package/dist/channels/slack/credentials.js +17 -15
- package/dist/channels/slack/defaults.d.ts.map +1 -1
- package/dist/channels/slack/defaults.js +18 -9
- package/dist/channels/slack/dispatch.d.ts +1 -1
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +19 -3
- package/dist/channels/slack/inbound.d.ts +8 -2
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +25 -4
- package/dist/channels/slack/index.d.ts +3 -2
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +3 -2
- package/dist/channels/slack/init.d.ts.map +1 -1
- package/dist/channels/slack/init.js +2 -1
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +2 -15
- package/dist/channels/slack/mentions.d.ts +28 -0
- package/dist/channels/slack/mentions.d.ts.map +1 -0
- package/dist/channels/slack/mentions.js +178 -0
- package/dist/channels/slack/setup.js +1 -1
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +46 -3
- package/dist/channels/slack/stop.d.ts.map +1 -1
- package/dist/channels/slack/stop.js +7 -1
- package/dist/channels/slack/thread-context.d.ts +3 -0
- package/dist/channels/slack/thread-context.d.ts.map +1 -1
- package/dist/channels/slack/thread-context.js +17 -7
- package/dist/channels/slack/tool-approval-events.d.ts.map +1 -1
- package/dist/channels/slack/tool-approval-events.js +55 -2
- package/dist/channels/slack/types.d.ts +2 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/channels/teams/activity.d.ts +33 -0
- package/dist/channels/teams/activity.d.ts.map +1 -0
- package/dist/channels/teams/activity.js +213 -0
- package/dist/channels/teams/auth.d.ts +25 -0
- package/dist/channels/teams/auth.d.ts.map +1 -0
- package/dist/channels/teams/auth.js +55 -0
- package/dist/channels/teams/bot-framework-auth.d.ts +33 -0
- package/dist/channels/teams/bot-framework-auth.d.ts.map +1 -0
- package/dist/channels/teams/bot-framework-auth.js +154 -0
- package/dist/channels/teams/cards.d.ts +23 -0
- package/dist/channels/teams/cards.d.ts.map +1 -0
- package/dist/channels/teams/cards.js +107 -0
- package/dist/channels/teams/connector.d.ts +48 -0
- package/dist/channels/teams/connector.d.ts.map +1 -0
- package/dist/channels/teams/connector.js +159 -0
- package/dist/channels/teams/credentials.d.ts +65 -0
- package/dist/channels/teams/credentials.d.ts.map +1 -0
- package/dist/channels/teams/credentials.js +84 -0
- package/dist/channels/teams/delivery.d.ts +14 -0
- package/dist/channels/teams/delivery.d.ts.map +1 -0
- package/dist/channels/teams/delivery.js +169 -0
- package/dist/channels/teams/dispatch.d.ts +45 -0
- package/dist/channels/teams/dispatch.d.ts.map +1 -0
- package/dist/channels/teams/dispatch.js +402 -0
- package/dist/channels/teams/engagement.d.ts +32 -0
- package/dist/channels/teams/engagement.d.ts.map +1 -0
- package/dist/channels/teams/engagement.js +120 -0
- package/dist/channels/teams/index.d.ts +21 -0
- package/dist/channels/teams/index.d.ts.map +1 -0
- package/dist/channels/teams/index.js +19 -0
- package/dist/channels/teams/marks.d.ts +19 -0
- package/dist/channels/teams/marks.d.ts.map +1 -0
- package/dist/channels/teams/marks.js +96 -0
- package/dist/channels/teams/senders.d.ts +27 -0
- package/dist/channels/teams/senders.d.ts.map +1 -0
- package/dist/channels/teams/senders.js +72 -0
- package/dist/channels/teams/teams-channel.d.ts +43 -0
- package/dist/channels/teams/teams-channel.d.ts.map +1 -0
- package/dist/channels/teams/teams-channel.js +278 -0
- package/dist/channels/teams/text.d.ts +7 -0
- package/dist/channels/teams/text.d.ts.map +1 -0
- package/dist/channels/teams/text.js +63 -0
- package/dist/channels/teams/types.d.ts +306 -0
- package/dist/channels/teams/types.d.ts.map +1 -0
- package/dist/channels/teams/types.js +1 -0
- package/dist/channels.d.ts +31 -0
- package/dist/channels.d.ts.map +1 -1
- package/dist/channels.js +37 -0
- package/dist/connections.d.ts +1 -1
- package/dist/connections.d.ts.map +1 -1
- package/dist/docs/404.html +3 -3
- package/dist/docs/assets/{app.CYdjweqP.js → app.Ch-048af.js} +4 -4
- package/dist/docs/assets/changelog.md.SoN0MK7o.js +1 -0
- package/dist/docs/assets/{changelog.md.BMrJ5WxW.lean.js → changelog.md.SoN0MK7o.lean.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.BdYoBKxY.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.CRATKS9J.js → VPLocalSearchBox.D7BIa9Su.js} +2 -2
- package/dist/docs/assets/chunks/{arc.BxM78ISR.js → arc.BIzu7OVF.js} +1 -1
- package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.Bi6MuKaU.js → architectureDiagram-Q4EWVU46.DNznI0Sn.js} +1 -1
- package/dist/docs/assets/chunks/{baseUniq.L47qqpDG.js → baseUniq.B4y6Y5eG.js} +1 -1
- package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.kHFF2FK5.js → blockDiagram-DXYQGD6D.BudnBsgw.js} +1 -1
- package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.BTW85ll3.js → c4Diagram-AHTNJAMY._bB00GdB.js} +1 -1
- package/dist/docs/assets/chunks/channel.CgxlmuBS.js +1 -0
- package/dist/docs/assets/chunks/{chunk-4BX2VUAB.Bbh3_48g.js → chunk-4BX2VUAB.CRftnUwS.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-4TB4RGXK.WeAmK3fK.js → chunk-4TB4RGXK.CSx1x2Ob.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-55IACEB6.DTdUiVHf.js → chunk-55IACEB6.KkLHAAbH.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-EDXVE4YY.n5XzANDz.js → chunk-EDXVE4YY.DDeKCCtX.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-FMBD7UC4.D51eewCb.js → chunk-FMBD7UC4.DrLlsD9m.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-OYMX7WX6.BrY0U7ZV.js → chunk-OYMX7WX6.DeVYOGcT.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-QZHKN3VN.B0OA4aFV.js → chunk-QZHKN3VN.Cz4_bS6p.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-YZCP3GAM.Djt3Mjft.js → chunk-YZCP3GAM.CwrYtDVo.js} +1 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.DWroREP-.js +1 -0
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.DWroREP-.js +1 -0
- package/dist/docs/assets/chunks/clone.F824-PNx.js +1 -0
- package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.DiMcA6Q8.js → cose-bilkent-S5V4N54A.3d8hflz6.js} +1 -1
- package/dist/docs/assets/chunks/{dagre-KV5264BT.BGqI4vrS.js → dagre-KV5264BT.BVEgjiPg.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-5BDNPKRD.bDqFuMoH.js → diagram-5BDNPKRD.j7dZpUK_.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.Y0sxaXRU.js → diagram-G4DWMVQ6.4flIgIon.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-MMDJMWI5.Bg43b0yi.js → diagram-MMDJMWI5.BlJiFh-S.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-TYMM5635.DCfVasEC.js → diagram-TYMM5635.DHAOHEyM.js} +1 -1
- package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.C72GaD16.js → erDiagram-SMLLAGMA.DkmyG7xK.js} +1 -1
- package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.DxRQj7pP.js → flowDiagram-DWJPFMVM.L_WiaAU6.js} +1 -1
- package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.DiLZy5Q4.js → ganttDiagram-T4ZO3ILL.CT6kOI2a.js} +1 -1
- package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.DL8XkRvh.js → gitGraphDiagram-UUTBAWPF.D8CRlLqh.js} +1 -1
- package/dist/docs/assets/chunks/{graph.3Xub80xJ.js → graph.CdOyJvsX.js} +1 -1
- package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.O3lGaspu.js → infoDiagram-42DDH7IO.DcmXeSos.js} +1 -1
- package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.w-pCiQzn.js → ishikawaDiagram-UXIWVN3A.BBjY4mxr.js} +1 -1
- package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.Cg_oBs9j.js → journeyDiagram-VCZTEJTY.BrXteAB6.js} +1 -1
- package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.BpfMGPwn.js → kanban-definition-6JOO6SKY.OlHsUJVV.js} +1 -1
- package/dist/docs/assets/chunks/{layout.CtwXs__p.js → layout.DDwvoQlY.js} +1 -1
- package/dist/docs/assets/chunks/{linear.NmCskOrP.js → linear.BRXPDWj3.js} +1 -1
- package/dist/docs/assets/chunks/{min.DpQtsLKs.js → min.3YwC0t3o.js} +1 -1
- package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.B-P-aKVp.js → mindmap-definition-QFDTVHPH.mPHnT2lN.js} +1 -1
- package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.BfjjqK7j.js → pieDiagram-DEJITSTG.DEK2--em.js} +1 -1
- package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.BTzHo53F.js → quadrantDiagram-34T5L4WZ.NCdRAOzK.js} +1 -1
- package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.DIT2FIKr.js → requirementDiagram-MS252O5E.DLAocFWZ.js} +1 -1
- package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.NK1wCsgt.js → sankeyDiagram-XADWPNL6.afIOqpyT.js} +1 -1
- package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.D9oElkvo.js → sequenceDiagram-FGHM5R23.DXBjvkkE.js} +1 -1
- package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.IPksnixH.js → stateDiagram-FHFEXIEX.B_SGgvgs.js} +1 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.OKAy5Bz7.js +1 -0
- package/dist/docs/assets/chunks/{theme.CgKu7tr3.js → theme.bNyH5NPA.js} +2 -2
- package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.CuAtJapY.js → timeline-definition-GMOUNBTQ.CE6S1iSb.js} +1 -1
- package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.B87nNW9E.js → vennDiagram-DHZGUBPP.Blk7wb8V.js} +1 -1
- package/dist/docs/assets/chunks/wardley-RL74JXVD.DQqE3WF8.js +162 -0
- package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BELjSq8w.js → wardleyDiagram-NUSXRM2D.MUEQyRnz.js} +1 -1
- package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.5zN5ZGsz.js → xychartDiagram-5P7HB3ND.DnJA2aXp.js} +1 -1
- package/dist/docs/assets/{deployment.md.DJtuDVLh.js → deployment.md.N9S5KC5R.js} +2 -2
- package/dist/docs/assets/{deployment.md.DJtuDVLh.lean.js → deployment.md.N9S5KC5R.lean.js} +1 -1
- package/dist/docs/assets/guides_cloud-agents.md.BdWqmUGb.js +14 -0
- package/dist/docs/assets/{guides_cloud-agents.md.CiXAW6on.lean.js → guides_cloud-agents.md.BdWqmUGb.lean.js} +1 -1
- package/dist/docs/assets/guides_teams.md.7Lz2sbqB.js +50 -0
- package/dist/docs/assets/guides_teams.md.7Lz2sbqB.lean.js +1 -0
- package/dist/docs/assets/{reference_channels.md.CPWOpdsC.js → reference_channels.md.CRvqgU0n.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.DHm6DmYk.js → reference_cli.md.NS6U5a-7.js} +14 -4
- package/dist/docs/assets/{reference_cli.md.DHm6DmYk.lean.js → reference_cli.md.NS6U5a-7.lean.js} +1 -1
- package/dist/docs/assets/{reference_limits.md.CbdtFr4T.js → reference_limits.md.CW9PTdxr.js} +3 -3
- package/dist/docs/assets/{reference_limits.md.CbdtFr4T.lean.js → reference_limits.md.CW9PTdxr.lean.js} +1 -1
- package/dist/docs/assets/{reference_schedules.md.RhQ9ZLo1.js → reference_schedules.md.Dd8_d0WG.js} +3 -3
- package/dist/docs/assets/{reference_sessions.md.NXVQt9mP.js → reference_sessions.md.CoCyQLEz.js} +2 -2
- package/dist/docs/assets/{reference_sessions.md.NXVQt9mP.lean.js → reference_sessions.md.CoCyQLEz.lean.js} +1 -1
- package/dist/docs/assets/{reference_skills.md.DzCPNPkG.js → reference_skills.md.SFRZDC41.js} +4 -4
- package/dist/docs/assets/{reference_skills.md.DzCPNPkG.lean.js → reference_skills.md.SFRZDC41.lean.js} +1 -1
- package/dist/docs/assets/{style.DK0YX1WL.css → style.B7zPxANR.css} +1 -1
- package/dist/docs/assets/troubleshooting.md.CsQTleto.js +3 -0
- package/dist/docs/assets/{troubleshooting.md.DfKKvW1R.lean.js → troubleshooting.md.CsQTleto.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +37 -37
- package/dist/docs/changelog.html +37 -37
- package/dist/docs/changelog.md +51 -0
- package/dist/docs/deployment.html +39 -39
- package/dist/docs/deployment.md +10 -0
- package/dist/docs/evals.html +37 -37
- package/dist/docs/guides/agent-to-agent.html +37 -37
- package/dist/docs/guides/bitbucket.html +37 -37
- package/dist/docs/guides/cloud-agents.html +43 -38
- package/dist/docs/guides/cloud-agents.md +47 -0
- package/dist/docs/guides/convert-automation.html +37 -37
- package/dist/docs/guides/github.html +37 -37
- package/dist/docs/guides/gitlab.html +37 -37
- package/dist/docs/guides/improve.html +37 -37
- package/dist/docs/guides/jev.html +37 -37
- package/dist/docs/guides/mcp-oauth.html +37 -37
- package/dist/docs/guides/migrate.html +37 -37
- package/dist/docs/guides/opentelemetry.html +37 -37
- package/dist/docs/guides/pagerduty.html +37 -37
- package/dist/docs/guides/slack.html +37 -37
- package/dist/docs/guides/teams.html +109 -0
- package/dist/docs/guides/teams.md +384 -0
- package/dist/docs/guides/webhooks.html +37 -37
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +37 -37
- package/dist/docs/index.html +37 -37
- package/dist/docs/llms-full.txt +652 -4
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/quickstart.html +37 -37
- package/dist/docs/reference/access.html +36 -36
- package/dist/docs/reference/agent-config.html +37 -37
- package/dist/docs/reference/artifacts.html +37 -37
- package/dist/docs/reference/channels.html +38 -38
- package/dist/docs/reference/channels.md +1 -0
- package/dist/docs/reference/cli.html +50 -40
- package/dist/docs/reference/cli.md +116 -0
- package/dist/docs/reference/connections.html +37 -37
- package/dist/docs/reference/evals.html +37 -37
- package/dist/docs/reference/extensions.html +37 -37
- package/dist/docs/reference/hooks.html +37 -37
- package/dist/docs/reference/http-api.html +37 -37
- package/dist/docs/reference/instructions.html +37 -37
- package/dist/docs/reference/limits.html +39 -39
- package/dist/docs/reference/limits.md +4 -4
- package/dist/docs/reference/memory.html +37 -37
- package/dist/docs/reference/playground.html +36 -36
- package/dist/docs/reference/project-layout.html +37 -37
- package/dist/docs/reference/schedules.html +40 -40
- package/dist/docs/reference/sessions.html +38 -38
- package/dist/docs/reference/sessions.md +13 -0
- package/dist/docs/reference/skills.html +40 -40
- package/dist/docs/reference/subagents.html +37 -37
- package/dist/docs/reference/tools.html +37 -37
- package/dist/docs/templates/agentic-owners.html +37 -37
- package/dist/docs/templates/reviews.html +37 -37
- package/dist/docs/troubleshooting.html +38 -38
- package/dist/docs/troubleshooting.md +21 -0
- package/dist/evals/run-facts.d.ts.map +1 -1
- package/dist/evals/run-facts.js +4 -0
- package/dist/extensions/cursor-cloud-agents/channels/cursor-cloud-agents.d.ts +12 -0
- package/dist/extensions/cursor-cloud-agents/channels/cursor-cloud-agents.d.ts.map +1 -0
- package/dist/extensions/cursor-cloud-agents/channels/cursor-cloud-agents.js +42 -0
- package/dist/extensions/cursor-cloud-agents/extension.d.ts +10 -7
- package/dist/extensions/cursor-cloud-agents/extension.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/extension.js +3 -2
- package/dist/extensions/cursor-cloud-agents/lib/agent-id.d.ts +5 -0
- package/dist/extensions/cursor-cloud-agents/lib/agent-id.d.ts.map +1 -0
- package/dist/extensions/cursor-cloud-agents/lib/agent-id.js +10 -0
- package/dist/extensions/cursor-cloud-agents/lib/backend.d.ts +57 -3
- package/dist/extensions/cursor-cloud-agents/lib/backend.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/backend.js +150 -35
- package/dist/extensions/cursor-cloud-agents/lib/fleet.d.ts +32 -4
- package/dist/extensions/cursor-cloud-agents/lib/fleet.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/fleet.js +93 -7
- package/dist/extensions/cursor-cloud-agents/lib/launch-agent.d.ts +24 -7
- package/dist/extensions/cursor-cloud-agents/lib/launch-agent.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/launch-agent.js +158 -25
- package/dist/extensions/cursor-cloud-agents/lib/stop-signal.d.ts +18 -0
- package/dist/extensions/cursor-cloud-agents/lib/stop-signal.d.ts.map +1 -0
- package/dist/extensions/cursor-cloud-agents/lib/stop-signal.js +27 -0
- package/dist/extensions/cursor-cloud-agents/lib/transcript.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/transcript.js +2 -3
- package/dist/extensions/cursor-cloud-agents/lib/watch.d.ts +26 -12
- package/dist/extensions/cursor-cloud-agents/lib/watch.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/watch.js +115 -46
- package/dist/extensions/cursor-cloud-agents/reminders/cloud-agent-stop-watch.d.ts +16 -5
- package/dist/extensions/cursor-cloud-agents/reminders/cloud-agent-stop-watch.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/reminders/cloud-agent-stop-watch.js +76 -20
- package/dist/extensions/cursor-cloud-agents/skills/handoff.md +2 -2
- package/dist/extensions/cursor-cloud-agents/tools/get.js +2 -2
- package/dist/extensions/cursor-cloud-agents/tools/launch.js +1 -1
- package/dist/extensions.d.ts.map +1 -1
- package/dist/extensions.js +18 -3
- package/dist/files-backends/agent-store-presigned-url.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/internal/approval-gate.d.ts +6 -1
- package/dist/internal/approval-gate.d.ts.map +1 -1
- package/dist/internal/approval-gate.js +13 -2
- package/dist/internal/authored-loaders.js +1 -1
- package/dist/internal/channel-architecture.d.ts.map +1 -1
- package/dist/internal/channel-architecture.js +3 -1
- package/dist/internal/cli/commands/channels.d.ts +9 -3
- package/dist/internal/cli/commands/channels.d.ts.map +1 -1
- package/dist/internal/cli/commands/channels.js +193 -4
- package/dist/internal/cli/commands/index.d.ts.map +1 -1
- package/dist/internal/cli/commands/index.js +6 -1
- package/dist/internal/cli/commands/serve.d.ts.map +1 -1
- package/dist/internal/cli/commands/serve.js +25 -5
- package/dist/internal/cli/dispatch.d.ts.map +1 -1
- package/dist/internal/cli/dispatch.js +22 -8
- package/dist/internal/cli/flags.d.ts +14 -0
- package/dist/internal/cli/flags.d.ts.map +1 -1
- package/dist/internal/cli/flags.js +14 -0
- package/dist/internal/cli/help.d.ts.map +1 -1
- package/dist/internal/cli/help.js +3 -1
- package/dist/internal/cli-cursor.js +2 -2
- package/dist/internal/cli-deploy.d.ts +1 -0
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +31 -8
- package/dist/internal/cli-mcp.d.ts.map +1 -1
- package/dist/internal/cli-mcp.js +5 -3
- package/dist/internal/cli-teams-doctor.d.ts +39 -0
- package/dist/internal/cli-teams-doctor.d.ts.map +1 -0
- package/dist/internal/cli-teams-doctor.js +508 -0
- package/dist/internal/cli-teams-forward.d.ts +84 -0
- package/dist/internal/cli-teams-forward.d.ts.map +1 -0
- package/dist/internal/cli-teams-forward.js +386 -0
- package/dist/internal/cli-teams-package.d.ts +26 -0
- package/dist/internal/cli-teams-package.d.ts.map +1 -0
- package/dist/internal/cli-teams-package.js +123 -0
- package/dist/internal/cli-teams.d.ts +15 -0
- package/dist/internal/cli-teams.d.ts.map +1 -0
- package/dist/internal/cli-teams.js +253 -0
- package/dist/internal/connect-click.d.ts +12 -0
- package/dist/internal/connect-click.d.ts.map +1 -0
- package/dist/internal/connect-click.js +22 -0
- package/dist/internal/continuation-channel.d.ts +5 -1
- package/dist/internal/continuation-channel.d.ts.map +1 -1
- package/dist/internal/continuation-channel.js +34 -0
- package/dist/internal/continuation-identity.d.ts +7 -4
- package/dist/internal/continuation-identity.d.ts.map +1 -1
- package/dist/internal/continuation-identity.js +66 -1
- package/dist/internal/convert-automation/convert-workflow.js +2 -2
- package/dist/internal/credential-env-names.d.ts +36 -0
- package/dist/internal/credential-env-names.d.ts.map +1 -0
- package/dist/internal/credential-env-names.js +68 -0
- package/dist/internal/cursor/account-mcp.d.ts +67 -9
- package/dist/internal/cursor/account-mcp.d.ts.map +1 -1
- package/dist/internal/cursor/account-mcp.js +206 -25
- package/dist/internal/cursor/backend-client.d.ts +10 -1
- package/dist/internal/cursor/backend-client.d.ts.map +1 -1
- package/dist/internal/cursor/backend-client.js +19 -7
- package/dist/internal/cursor/cloud-agent-identity.d.ts +81 -0
- package/dist/internal/cursor/cloud-agent-identity.d.ts.map +1 -0
- package/dist/internal/cursor/cloud-agent-identity.js +224 -0
- package/dist/internal/cursor/credentials.d.ts.map +1 -1
- package/dist/internal/cursor/credentials.js +3 -1
- package/dist/internal/cursor-account-mcp-auth.d.ts +1 -0
- package/dist/internal/cursor-account-mcp-auth.d.ts.map +1 -1
- package/dist/internal/cursor-account-mcp-auth.js +2 -1
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +34 -2
- package/dist/internal/deploy-manifest.d.ts +51 -3
- package/dist/internal/deploy-manifest.d.ts.map +1 -1
- package/dist/internal/deploy-manifest.js +96 -7
- package/dist/internal/discovery/agent-config.d.ts.map +1 -1
- package/dist/internal/discovery/agent-config.js +6 -1
- package/dist/internal/discovery/connections.d.ts.map +1 -1
- package/dist/internal/discovery/connections.js +53 -0
- package/dist/internal/discovery/extensions.d.ts.map +1 -1
- package/dist/internal/discovery/extensions.js +2 -0
- package/dist/internal/discovery/info.d.ts.map +1 -1
- package/dist/internal/discovery/info.js +4 -0
- package/dist/internal/env-file.d.ts +1 -0
- package/dist/internal/env-file.d.ts.map +1 -1
- package/dist/internal/env-file.js +18 -17
- package/dist/internal/env-prefix.d.ts +11 -0
- package/dist/internal/env-prefix.d.ts.map +1 -0
- package/dist/internal/env-prefix.js +23 -0
- package/dist/internal/event-id-dedupe.d.ts +12 -0
- package/dist/internal/event-id-dedupe.d.ts.map +1 -0
- package/dist/{channels/slack → internal}/event-id-dedupe.js +7 -4
- package/dist/internal/event-mapper.d.ts +7 -2
- package/dist/internal/event-mapper.d.ts.map +1 -1
- package/dist/internal/event-mapper.js +7 -0
- package/dist/internal/expected-delivery-failure.d.ts.map +1 -1
- package/dist/internal/expected-delivery-failure.js +3 -0
- package/dist/internal/extension-namespace.d.ts +9 -0
- package/dist/internal/extension-namespace.d.ts.map +1 -0
- package/dist/internal/extension-namespace.js +14 -0
- package/dist/internal/guid.d.ts +2 -0
- package/dist/internal/guid.d.ts.map +1 -0
- package/dist/internal/guid.js +4 -0
- package/dist/internal/host-kv-cas.d.ts +13 -0
- package/dist/internal/host-kv-cas.d.ts.map +1 -0
- package/dist/internal/host-kv-cas.js +8 -0
- package/dist/internal/host-kv.d.ts +4 -1
- package/dist/internal/host-kv.d.ts.map +1 -1
- package/dist/internal/host-kv.js +15 -2
- package/dist/internal/hosted-catch-protocol.d.ts +5 -0
- package/dist/internal/hosted-catch-protocol.d.ts.map +1 -1
- package/dist/internal/hosted-catch-protocol.js +5 -0
- package/dist/internal/hosted-catch.d.ts +2 -0
- package/dist/internal/hosted-catch.d.ts.map +1 -1
- package/dist/internal/hosted-catch.js +6 -1
- package/dist/internal/hosted-delivery-protocol.d.ts +6 -0
- package/dist/internal/hosted-delivery-protocol.d.ts.map +1 -1
- package/dist/internal/hosted-delivery-protocol.js +71 -1
- package/dist/internal/hosted-delivery.d.ts +5 -2
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +36 -12
- package/dist/internal/hosted-execution-latency.d.ts +3 -0
- package/dist/internal/hosted-execution-latency.d.ts.map +1 -1
- package/dist/internal/hosted-execution-latency.js +11 -0
- package/dist/internal/hosted-session-fixture.js +1 -1
- package/dist/internal/hosting.d.ts +5 -0
- package/dist/internal/hosting.d.ts.map +1 -1
- package/dist/internal/hosting.js +7 -1
- package/dist/internal/install-cursor-skills.d.ts +6 -7
- package/dist/internal/install-cursor-skills.d.ts.map +1 -1
- package/dist/internal/install-cursor-skills.js +15 -9
- package/dist/internal/interview/agent-questions.d.ts +1 -1
- package/dist/internal/interview/agent-questions.d.ts.map +1 -1
- package/dist/internal/interview/agent-questions.js +4 -3
- package/dist/internal/local-control-plane.d.ts.map +1 -1
- package/dist/internal/local-control-plane.js +24 -0
- package/dist/internal/mcp-allowlist-in-use.d.ts +23 -0
- package/dist/internal/mcp-allowlist-in-use.d.ts.map +1 -0
- package/dist/internal/mcp-allowlist-in-use.js +93 -0
- package/dist/internal/mcp-endpoint.d.ts.map +1 -1
- package/dist/internal/mcp-endpoint.js +8 -10
- package/dist/internal/mcp-host.d.ts +19 -1
- package/dist/internal/mcp-host.d.ts.map +1 -1
- package/dist/internal/mcp-host.js +67 -3
- package/dist/internal/mcp-oauth.d.ts.map +1 -1
- package/dist/internal/mcp-oauth.js +5 -7
- package/dist/internal/oidcAudiences.d.ts +22 -0
- package/dist/internal/oidcAudiences.d.ts.map +1 -0
- package/dist/internal/oidcAudiences.js +35 -0
- package/dist/internal/otel/collector.d.ts.map +1 -1
- package/dist/internal/otel/collector.js +2 -0
- package/dist/internal/platform-timers.d.ts +2 -0
- package/dist/internal/platform-timers.d.ts.map +1 -1
- package/dist/internal/platform-timers.js +14 -0
- package/dist/internal/private-file.d.ts +32 -1
- package/dist/internal/private-file.d.ts.map +1 -1
- package/dist/internal/private-file.js +209 -7
- package/dist/internal/redact-values.d.ts +3 -0
- package/dist/internal/redact-values.d.ts.map +1 -0
- package/dist/internal/redact-values.js +19 -0
- package/dist/internal/reminder-control-plane-protocol.d.ts +7 -1
- package/dist/internal/reminder-control-plane-protocol.d.ts.map +1 -1
- package/dist/internal/reminder-followup-error.d.ts +23 -0
- package/dist/internal/reminder-followup-error.d.ts.map +1 -0
- package/dist/internal/reminder-followup-error.js +12 -0
- package/dist/internal/reminder-runner.d.ts +15 -1
- package/dist/internal/reminder-runner.d.ts.map +1 -1
- package/dist/internal/reminder-runner.js +95 -21
- package/dist/internal/resolved-connections.d.ts.map +1 -1
- package/dist/internal/resolved-connections.js +23 -3
- package/dist/internal/run-client.js +2 -1
- package/dist/internal/run-program.d.ts +31 -0
- package/dist/internal/run-program.d.ts.map +1 -0
- package/dist/internal/run-program.js +150 -0
- package/dist/internal/sdk-runner.d.ts +29 -3
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +304 -38
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +53 -8
- package/dist/internal/session-credential.d.ts +14 -0
- package/dist/internal/session-credential.d.ts.map +1 -0
- package/dist/internal/session-credential.js +25 -0
- package/dist/internal/session-engine.d.ts +137 -5
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +606 -92
- package/dist/internal/storage-coordinator.d.ts +3 -1
- package/dist/internal/storage-coordinator.d.ts.map +1 -1
- package/dist/internal/storage-coordinator.js +13 -0
- package/dist/internal/storage-roles.d.ts +9 -1
- package/dist/internal/storage-roles.d.ts.map +1 -1
- package/dist/internal/tcp-address.d.ts +3 -1
- package/dist/internal/tcp-address.d.ts.map +1 -1
- package/dist/internal/tcp-address.js +6 -0
- package/dist/internal/teams-channel-profile.d.ts +41 -0
- package/dist/internal/teams-channel-profile.d.ts.map +1 -0
- package/dist/internal/teams-channel-profile.js +91 -0
- package/dist/internal/teams-devtunnel.d.ts +55 -0
- package/dist/internal/teams-devtunnel.d.ts.map +1 -0
- package/dist/internal/teams-devtunnel.js +205 -0
- package/dist/internal/teams-tunnel-proxy.d.ts +17 -0
- package/dist/internal/teams-tunnel-proxy.d.ts.map +1 -0
- package/dist/internal/teams-tunnel-proxy.js +100 -0
- package/dist/internal/testing/conversation-identity-vectors.d.ts +7 -1
- package/dist/internal/testing/conversation-identity-vectors.d.ts.map +1 -1
- package/dist/internal/testing/conversation-identity-vectors.js +67 -0
- package/dist/internal/testing/hosted-http.d.ts +15 -0
- package/dist/internal/testing/hosted-http.d.ts.map +1 -0
- package/dist/internal/testing/hosted-http.js +86 -0
- package/dist/internal/testing/teams-activity-fixtures.d.ts +28 -0
- package/dist/internal/testing/teams-activity-fixtures.d.ts.map +1 -0
- package/dist/internal/testing/teams-activity-fixtures.js +236 -0
- package/dist/internal/testing/teams-doctor-fixtures.d.ts +76 -0
- package/dist/internal/testing/teams-doctor-fixtures.d.ts.map +1 -0
- package/dist/internal/testing/teams-doctor-fixtures.js +216 -0
- package/dist/internal/tunnel-process.d.ts +29 -0
- package/dist/internal/tunnel-process.d.ts.map +1 -0
- package/dist/internal/tunnel-process.js +105 -0
- package/dist/internal/turn-context.d.ts +28 -0
- package/dist/internal/turn-context.d.ts.map +1 -0
- package/dist/internal/turn-context.js +1 -0
- package/dist/oidc-token.d.ts +127 -0
- package/dist/oidc-token.d.ts.map +1 -0
- package/dist/oidc-token.js +221 -0
- package/dist/playground/assets/index-BaBSZXki.css +1 -0
- package/dist/playground/assets/index-BkAF8YlO.js +62 -0
- package/dist/playground/index.html +2 -2
- package/dist/teams-app-package.d.ts +78 -0
- package/dist/teams-app-package.d.ts.map +1 -0
- package/dist/teams-app-package.js +204 -0
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/types.d.ts +278 -2
- package/dist/types.d.ts.map +1 -1
- package/docs/changelog.md +51 -0
- package/docs/deployment.md +10 -0
- package/docs/guides/cloud-agents.md +47 -0
- package/docs/guides/teams.md +389 -0
- package/docs/reference/channels.md +1 -0
- package/docs/reference/cli.md +116 -0
- package/docs/reference/limits.md +4 -4
- package/docs/reference/sessions.md +13 -0
- package/docs/troubleshooting.md +21 -0
- package/package.json +21 -46
- package/skills/create-agent/SKILL.md +17 -4
- package/skills/debug/SKILL.md +1 -0
- package/skills/deploy/SKILL.md +1 -1
- package/skills/framework-map/SKILL.md +1 -0
- package/skills/setup-teams/SKILL.md +141 -0
- package/templates/agentic-owners/bot/lib/owners/parse.ts +1 -0
- package/dist/channels/slack/event-id-dedupe.d.ts +0 -10
- package/dist/channels/slack/event-id-dedupe.d.ts.map +0 -1
- package/dist/docs/assets/changelog.md.BMrJ5WxW.js +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.dUaE1f8e.js +0 -1
- package/dist/docs/assets/chunks/channel.ljJtQtBi.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.BZ3Uc-XU.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.BZ3Uc-XU.js +0 -1
- package/dist/docs/assets/chunks/clone.BDtbEo69.js +0 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CbhzVsQE.js +0 -1
- package/dist/docs/assets/chunks/wardley-RL74JXVD.BFIVMaoi.js +0 -162
- package/dist/docs/assets/guides_cloud-agents.md.CiXAW6on.js +0 -9
- package/dist/docs/assets/troubleshooting.md.DfKKvW1R.js +0 -3
- package/dist/playground/assets/index-D0-FHg1x.css +0 -1
- package/dist/playground/assets/index-D5SLKUy6.js +0 -62
- /package/dist/docs/assets/{reference_channels.md.CPWOpdsC.lean.js → reference_channels.md.CRvqgU0n.lean.js} +0 -0
- /package/dist/docs/assets/{reference_schedules.md.RhQ9ZLo1.lean.js → reference_schedules.md.Dd8_d0WG.lean.js} +0 -0
|
@@ -34,6 +34,7 @@ import { resolveConnectionEnvTemplates } from "./connection-env.js";
|
|
|
34
34
|
import { applyAgentContinuationDefaults, channelContinuationIdentity, httpContinuationIdentity, } from "./continuation-channel.js";
|
|
35
35
|
import { continuationSource, isOneShotContinuationKey, resolveV2Key, V2EngineError, } from "./continuation-identity.js";
|
|
36
36
|
import { describeError, describeErrorCode } from "./describe-error.js";
|
|
37
|
+
import { parseConnectClickText } from "./connect-click.js";
|
|
37
38
|
import { isDevMode } from "./dev-mode.js";
|
|
38
39
|
import { EventLogStore } from "./event-log.js";
|
|
39
40
|
import { TurnEventMapper } from "./event-mapper.js";
|
|
@@ -53,6 +54,7 @@ import { McpOauthOnDemandHub } from "./mcp-oauth-on-demand.js";
|
|
|
53
54
|
import { shouldStartProcessMemoryTelemetry, startProcessMemoryTelemetry, } from "./process-memory-telemetry.js";
|
|
54
55
|
import { buildSessionContextBlock, SCHEDULE_CHANNEL_PREFIX } from "./prompt-context.js";
|
|
55
56
|
import { assertCloudCanHonorAccountServersFilters } from "./resolved-connections.js";
|
|
57
|
+
import { SessionCredentials, TOOL_SESSION_CREDENTIAL_PARAM } from "./session-credential.js";
|
|
56
58
|
import { sessionExternalLinks } from "./session-links.js";
|
|
57
59
|
import { SessionStore } from "./session-store.js";
|
|
58
60
|
import { MEMORY_DIR_NAME } from "./memory-dir.js";
|
|
@@ -70,6 +72,7 @@ import { estimateCostFromApi, roundCostUsd } from "./estimate-cost.js";
|
|
|
70
72
|
import { TurnGovernor } from "./turn-governor.js";
|
|
71
73
|
import { TurnLeaseStore } from "./turn-lease-store.js";
|
|
72
74
|
import { TurnOutbox } from "./turn-outbox.js";
|
|
75
|
+
import { markHostedTurnStarted } from "./hosted-execution-latency.js";
|
|
73
76
|
import { isCursorManagedV2Hosting, resolveAgentV2Hosting } from "./v2-hosting.js";
|
|
74
77
|
import { buildAgentsMdContent, buildCloudMemorySection, buildCloudSessionWorkspaceSection, buildCloudWorkspaceSection, ensureOwnGitRoot, isNestedInGitRepo, materializeWorkspace, SERVER_TOOLS_MCP_SERVER_NAME, SKILLS_MOUNT_PATH, skillsFileSystem, withIdentityPreamble, } from "./workspace.js";
|
|
75
78
|
import { syncSessionWorkspaceFiles, syncWorkspaceToStore, WorkspaceFileRefusal, wipeSessionWorkspace, } from "./workspace-sync.js";
|
|
@@ -176,7 +179,58 @@ export class AuthInterruptedError extends Error {
|
|
|
176
179
|
}
|
|
177
180
|
/** How long an interactive turn waits for a person to authorize a connection. */
|
|
178
181
|
export const MCP_AUTH_PARK_TIMEOUT_MS = 10 * 60_000;
|
|
182
|
+
function toolDenialText(toolName, reason) {
|
|
183
|
+
switch (reason) {
|
|
184
|
+
case "timeout":
|
|
185
|
+
return `Tool "${toolName}" was not approved in time.`;
|
|
186
|
+
case "interrupt":
|
|
187
|
+
return `Tool "${toolName}" was not run: the turn stopped before anyone approved it.`;
|
|
188
|
+
case undefined:
|
|
189
|
+
return `Tool "${toolName}" was denied by a human approver.`;
|
|
190
|
+
default: {
|
|
191
|
+
const unexpected = reason;
|
|
192
|
+
return unexpected;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Deny a parked call when the turn aborts or the wait reaches `timeoutMs`.
|
|
198
|
+
* Returns a stop function the caller runs when the park ends.
|
|
199
|
+
*/
|
|
200
|
+
function armParkDeadline(signal, timeoutMs, end) {
|
|
201
|
+
const endForAbort = () => {
|
|
202
|
+
end("interrupt");
|
|
203
|
+
};
|
|
204
|
+
if (signal?.aborted === true) {
|
|
205
|
+
endForAbort();
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
signal?.addEventListener("abort", endForAbort, { once: true });
|
|
209
|
+
}
|
|
210
|
+
const timer = setTimeout(() => {
|
|
211
|
+
end("timeout");
|
|
212
|
+
}, timeoutMs);
|
|
213
|
+
timer.unref();
|
|
214
|
+
return () => {
|
|
215
|
+
clearTimeout(timer);
|
|
216
|
+
signal?.removeEventListener("abort", endForAbort);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
179
219
|
const mcpAuthAls = new AsyncLocalStorage();
|
|
220
|
+
/**
|
|
221
|
+
* The queue key for a turn: its user id. A turn with no user is keyed by its
|
|
222
|
+
* chat sender, so two unlinked senders never share a turn; a run with no
|
|
223
|
+
* sender, such as a schedule, is `"none"`.
|
|
224
|
+
*/
|
|
225
|
+
export function userKey(ctx) {
|
|
226
|
+
if (ctx?.user !== undefined) {
|
|
227
|
+
return String(ctx.user.id);
|
|
228
|
+
}
|
|
229
|
+
const source = ctx?.source;
|
|
230
|
+
return source?.kind === "slack" || source?.kind === "teams"
|
|
231
|
+
? `none:${source.kind}:${source.tenantId}/${source.userId}`
|
|
232
|
+
: "none";
|
|
233
|
+
}
|
|
180
234
|
const RELEASED_CONTINUATIONS_CAP = 256;
|
|
181
235
|
/** Marker that we `git init`'d this shared harness so scaffold is ours to write. */
|
|
182
236
|
const OWNED_HARNESS = join(".agent-serve", "owned-harness");
|
|
@@ -223,6 +277,17 @@ function canonicalJson(value) {
|
|
|
223
277
|
}
|
|
224
278
|
return value;
|
|
225
279
|
}
|
|
280
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
281
|
+
/** The SDK exempts only loopback bridges, so a serve bound to another host names none. */
|
|
282
|
+
function isLoopbackHttpUrl(url) {
|
|
283
|
+
try {
|
|
284
|
+
const parsed = new URL(url);
|
|
285
|
+
return parsed.protocol === "http:" && LOOPBACK_HOSTS.has(parsed.hostname);
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
226
291
|
export class SessionEngine {
|
|
227
292
|
constructor(options) {
|
|
228
293
|
/** In-flight lazy restores, deduped per channel + continuation key. */
|
|
@@ -270,10 +335,16 @@ export class SessionEngine {
|
|
|
270
335
|
/** Live turn snapshot so a coalesced Slack wake can repaint on this process. */
|
|
271
336
|
this.liveTurns = new Map();
|
|
272
337
|
/**
|
|
273
|
-
* Per-session coalesce
|
|
274
|
-
*
|
|
338
|
+
* Per-session coalesce queues for `admission: "coalesce"` (Slack), one per
|
|
339
|
+
* {@link userKey} in arrival order. Each drain starts one key's queue as one
|
|
340
|
+
* follow-up turn when the active turn finishes without interrupt.
|
|
275
341
|
*/
|
|
276
342
|
this.coalesceQueues = new Map();
|
|
343
|
+
/**
|
|
344
|
+
* Context of the session's latest turn, held until that turn's drain ends.
|
|
345
|
+
* The wrapper's identity tells a turn's own entry from its successor's.
|
|
346
|
+
*/
|
|
347
|
+
this.turnContexts = new Map();
|
|
277
348
|
/**
|
|
278
349
|
* Sessions whose turn lifecycle is draining coalesced follow-ups. Counts as
|
|
279
350
|
* busy so inbound coalesce admits enqueue instead of racing `clearCoalesced`.
|
|
@@ -288,6 +359,8 @@ export class SessionEngine {
|
|
|
288
359
|
this.oauthHub = new McpOauthOnDemandHub();
|
|
289
360
|
/** Serve-time resolved connections (see {@link setResolvedConnections}). */
|
|
290
361
|
this.resolvedConnections = [];
|
|
362
|
+
/** Prove which session a tool MCP endpoint request comes from. */
|
|
363
|
+
this.toolSessionCredentials = new SessionCredentials();
|
|
291
364
|
/** Sessions whose completed turns all carry usage (no further backfill). */
|
|
292
365
|
this.cloudUsageBackfillDone = new Set();
|
|
293
366
|
/** Deduped in-flight cloud usage backfills, keyed by session id. */
|
|
@@ -385,7 +458,7 @@ export class SessionEngine {
|
|
|
385
458
|
this.mcpHost = new McpHost([
|
|
386
459
|
...options.project.agent.connections,
|
|
387
460
|
...(options.project.agent.hostConnections ?? []),
|
|
388
|
-
].filter((connection) => !isSymbolicConnectionTransport(connection.transport)));
|
|
461
|
+
].filter((connection) => !isSymbolicConnectionTransport(connection.transport)), { log: this.logger });
|
|
389
462
|
const basePlatforms = options.platforms ?? createHostPlatforms();
|
|
390
463
|
const slackBinding = resolveDedicatedSlackHostBinding(options.project.channels);
|
|
391
464
|
this.platforms =
|
|
@@ -430,6 +503,17 @@ export class SessionEngine {
|
|
|
430
503
|
});
|
|
431
504
|
}
|
|
432
505
|
}
|
|
506
|
+
hostMcpBridgeUrlsField() {
|
|
507
|
+
const urls = this.resolvedConnections
|
|
508
|
+
.filter((resolved) => {
|
|
509
|
+
const authored = this.authoredConnection(resolved.name);
|
|
510
|
+
return (authored !== undefined &&
|
|
511
|
+
isCursorAccountTransport(authored.transport) &&
|
|
512
|
+
isLoopbackHttpUrl(resolved.localUrl));
|
|
513
|
+
})
|
|
514
|
+
.map((resolved) => resolved.localUrl);
|
|
515
|
+
return urls.length === 0 ? {} : { hostMcpBridgeUrls: urls };
|
|
516
|
+
}
|
|
433
517
|
authoredConnection(name) {
|
|
434
518
|
return (this.project.agent.connections.find((item) => item.name === name) ??
|
|
435
519
|
this.project.agent.hostConnections?.find((item) => item.name === name));
|
|
@@ -471,6 +555,10 @@ export class SessionEngine {
|
|
|
471
555
|
setCursorAccountAuthProbe(probe) {
|
|
472
556
|
this.probeCursorAccount = probe;
|
|
473
557
|
}
|
|
558
|
+
/** Whether the session's turn user has connected an individual connection. */
|
|
559
|
+
setIndividualConnectedCheck(check) {
|
|
560
|
+
this.individualConnectedCheck = check;
|
|
561
|
+
}
|
|
474
562
|
get oauthCallbackHub() {
|
|
475
563
|
return this.oauthHub;
|
|
476
564
|
}
|
|
@@ -660,7 +748,10 @@ export class SessionEngine {
|
|
|
660
748
|
}
|
|
661
749
|
slackNudgeHostApi() {
|
|
662
750
|
return {
|
|
663
|
-
append: (input) => this.
|
|
751
|
+
append: async (input) => (await this.runsTurnFor(input.continuationKey)) &&
|
|
752
|
+
!this.queuedForAnotherUser(input.sourceTs)
|
|
753
|
+
? this.nudgeStore.append(input)
|
|
754
|
+
: false,
|
|
664
755
|
drainFormatted: (continuationKey) => this.nudgeStore.drainFormatted(continuationKey),
|
|
665
756
|
clear: (continuationKey) => this.nudgeStore.clear(continuationKey),
|
|
666
757
|
hasUndelivered: (continuationKey) => this.nudgeStore.hasUndelivered(continuationKey),
|
|
@@ -756,19 +847,24 @@ export class SessionEngine {
|
|
|
756
847
|
// synchronize). Leave the durable continuation key unchanged.
|
|
757
848
|
let record = existing;
|
|
758
849
|
const enqueueOnly = sendOptions.hostedEnqueueOnly === true;
|
|
850
|
+
const admission = enqueueOnly ? "coalesce" : (sendOptions.admission ?? "preempt");
|
|
851
|
+
// A coalesced message may be queued and later dropped by a stop or a
|
|
852
|
+
// preempt; images on the record would then attach to an unrelated turn.
|
|
853
|
+
const admitImages = admission === "coalesce" ? sendOptions.images : undefined;
|
|
854
|
+
const recordImages = admission === "coalesce" ? undefined : sendOptions.images;
|
|
759
855
|
if (!enqueueOnly) {
|
|
760
856
|
const refreshWorkspace = sendOptions.workspaceDir !== undefined &&
|
|
761
857
|
sendOptions.workspaceDir !== existing.workspaceOverride;
|
|
762
858
|
if (refreshWorkspace ||
|
|
763
859
|
sendOptions.workspaceFiles !== undefined ||
|
|
764
|
-
|
|
860
|
+
recordImages !== undefined) {
|
|
765
861
|
record = await this.updateRecord(existing.sessionId, (current) => ({
|
|
766
862
|
...current,
|
|
767
863
|
workspaceOverride: refreshWorkspace
|
|
768
864
|
? sendOptions.workspaceDir
|
|
769
865
|
: current.workspaceOverride,
|
|
770
866
|
pendingWorkspaceFiles: mergePendingWorkspaceFiles(current.pendingWorkspaceFiles, sendOptions.workspaceFiles),
|
|
771
|
-
pendingImages: mergePendingImages(current.pendingImages,
|
|
867
|
+
pendingImages: mergePendingImages(current.pendingImages, recordImages),
|
|
772
868
|
}));
|
|
773
869
|
}
|
|
774
870
|
// A caller can explicitly return a continuation to the agent's
|
|
@@ -799,12 +895,16 @@ export class SessionEngine {
|
|
|
799
895
|
const since = (await this.logs.get(record.sessionId)).count;
|
|
800
896
|
const coalesced = await this.startTurn(record.sessionId, message, {
|
|
801
897
|
turnMode: sendOptions.turnMode ?? "non-interactive",
|
|
802
|
-
admission
|
|
898
|
+
admission,
|
|
803
899
|
...(sendOptions.coalesceSourceTs === undefined
|
|
804
900
|
? {}
|
|
805
901
|
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
806
902
|
...(enqueueOnly ? { hostedEnqueueOnly: true } : {}),
|
|
807
903
|
deliveryIds: [deliveryId],
|
|
904
|
+
platformDeliveryId: sendOptions.platformDeliveryId,
|
|
905
|
+
images: admitImages,
|
|
906
|
+
turnContext: sendOptions.turnContext,
|
|
907
|
+
turnSessionKey: sendOptions.turnSessionKey,
|
|
808
908
|
});
|
|
809
909
|
if (enqueueOnly && !coalesced) {
|
|
810
910
|
throw new HostedEnqueueNotActiveError(record.sessionId);
|
|
@@ -868,6 +968,9 @@ export class SessionEngine {
|
|
|
868
968
|
? {}
|
|
869
969
|
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
870
970
|
deliveryIds: [deliveryId],
|
|
971
|
+
turnContext: sendOptions.turnContext,
|
|
972
|
+
turnSessionKey: sendOptions.turnSessionKey,
|
|
973
|
+
platformDeliveryId: sendOptions.platformDeliveryId,
|
|
871
974
|
});
|
|
872
975
|
return this.channelSession(record.sessionId, record, deliveryId, true, false, since);
|
|
873
976
|
}
|
|
@@ -999,11 +1102,16 @@ export class SessionEngine {
|
|
|
999
1102
|
state: repaintState,
|
|
1000
1103
|
continuationToken: record.continuationKey,
|
|
1001
1104
|
setContinuationToken: (token) => this.setContinuationToken(sessionId, token),
|
|
1002
|
-
}, {
|
|
1003
|
-
|
|
1105
|
+
}, this.sessionContext({ sessionId, session: live.session, turnId: live.turnId }));
|
|
1106
|
+
}
|
|
1107
|
+
/** The context every channel `events` handler and hook gets for one event. */
|
|
1108
|
+
sessionContext({ sessionId, session, turnId, }) {
|
|
1109
|
+
return {
|
|
1110
|
+
session,
|
|
1004
1111
|
host: this.hostForSession(sessionId),
|
|
1005
|
-
artifacts: this.artifactsApi({ sessionId }),
|
|
1006
|
-
|
|
1112
|
+
artifacts: this.artifactsApi({ sessionId, turnId }),
|
|
1113
|
+
steer: (message, steerOptions) => this.steerRunningTurn(sessionId, turnId, message, steerOptions),
|
|
1114
|
+
};
|
|
1007
1115
|
}
|
|
1008
1116
|
/**
|
|
1009
1117
|
* Admit a turn for `sessionId`.
|
|
@@ -1028,7 +1136,10 @@ export class SessionEngine {
|
|
|
1028
1136
|
if (options.hostedEnqueueOnly === true) {
|
|
1029
1137
|
throw new HostedEnqueueNotActiveError(sessionId);
|
|
1030
1138
|
}
|
|
1031
|
-
await this.outbox.post(sessionId, {
|
|
1139
|
+
await this.outbox.post(sessionId, {
|
|
1140
|
+
message,
|
|
1141
|
+
options: { ...options, admission: "coalesce" },
|
|
1142
|
+
});
|
|
1032
1143
|
return true;
|
|
1033
1144
|
}
|
|
1034
1145
|
return this.admitTurn(sessionId, message, options);
|
|
@@ -1036,6 +1147,19 @@ export class SessionEngine {
|
|
|
1036
1147
|
this.admissionChains.set(sessionId, admitted.catch(() => { }));
|
|
1037
1148
|
return admitted;
|
|
1038
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
* A nudge reaches only a turn running in this process: the carrier runs
|
|
1152
|
+
* inside it. Another server's turn may belong to another user, which this
|
|
1153
|
+
* server cannot see, so its follow-ups arrive through the outbox instead.
|
|
1154
|
+
*/
|
|
1155
|
+
async runsTurnFor(continuationKey) {
|
|
1156
|
+
for (const sessionId of this.turnAborts.keys()) {
|
|
1157
|
+
if ((await this.sessions.get(sessionId))?.continuationKey === continuationKey) {
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1039
1163
|
/** Admit what other servers handed to this turn's holder. Never awaited by the lifecycle. */
|
|
1040
1164
|
drainOutbox(sessionId) {
|
|
1041
1165
|
void this.outbox
|
|
@@ -1048,7 +1172,9 @@ export class SessionEngine {
|
|
|
1048
1172
|
.catch(() => { });
|
|
1049
1173
|
}
|
|
1050
1174
|
enqueueCoalesced(sessionId, item) {
|
|
1051
|
-
const
|
|
1175
|
+
const queues = this.coalesceQueues.get(sessionId) ?? new Map();
|
|
1176
|
+
const key = userKey(item.turnContext);
|
|
1177
|
+
const queue = queues.get(key) ?? [];
|
|
1052
1178
|
const duplicate = item.sourceTs === undefined
|
|
1053
1179
|
? undefined
|
|
1054
1180
|
: queue.find((entry) => entry.sourceTs === item.sourceTs);
|
|
@@ -1061,10 +1187,49 @@ export class SessionEngine {
|
|
|
1061
1187
|
if (item.turnMode === "interactive") {
|
|
1062
1188
|
duplicate.turnMode = "interactive";
|
|
1063
1189
|
}
|
|
1190
|
+
if (duplicate.images === undefined || duplicate.images.length === 0) {
|
|
1191
|
+
duplicate.images = item.images;
|
|
1192
|
+
}
|
|
1064
1193
|
return;
|
|
1065
1194
|
}
|
|
1066
1195
|
queue.push(item);
|
|
1067
|
-
|
|
1196
|
+
queues.set(key, queue);
|
|
1197
|
+
this.coalesceQueues.set(sessionId, queues);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Take the next key's queue: the key of the turn that just finished first,
|
|
1201
|
+
* so its follow-ups the nudge carrier holds settle before another user's
|
|
1202
|
+
* turn runs, then the others in arrival order.
|
|
1203
|
+
*/
|
|
1204
|
+
takeCoalescedQueue(sessionId) {
|
|
1205
|
+
const queues = this.coalesceQueues.get(sessionId);
|
|
1206
|
+
if (queues === undefined) {
|
|
1207
|
+
return undefined;
|
|
1208
|
+
}
|
|
1209
|
+
const finishedKey = userKey(this.turnContextFor(sessionId));
|
|
1210
|
+
const key = queues.has(finishedKey) ? finishedKey : queues.keys().next().value;
|
|
1211
|
+
if (key === undefined) {
|
|
1212
|
+
this.coalesceQueues.delete(sessionId);
|
|
1213
|
+
return undefined;
|
|
1214
|
+
}
|
|
1215
|
+
const queue = queues.get(key);
|
|
1216
|
+
queues.delete(key);
|
|
1217
|
+
if (queues.size === 0) {
|
|
1218
|
+
this.coalesceQueues.delete(sessionId);
|
|
1219
|
+
}
|
|
1220
|
+
return queue;
|
|
1221
|
+
}
|
|
1222
|
+
/** Whether a Slack follow-up waits in another user's queue, so no turn may carry it. */
|
|
1223
|
+
queuedForAnotherUser(sourceTs) {
|
|
1224
|
+
for (const [sessionId, queues] of this.coalesceQueues) {
|
|
1225
|
+
const runningKey = userKey(this.turnContextFor(sessionId));
|
|
1226
|
+
for (const [key, queue] of queues) {
|
|
1227
|
+
if (key !== runningKey && queue.some((item) => item.sourceTs === sourceTs)) {
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return false;
|
|
1068
1233
|
}
|
|
1069
1234
|
clearCoalesced(sessionId) {
|
|
1070
1235
|
this.coalesceQueues.delete(sessionId);
|
|
@@ -1134,15 +1299,16 @@ export class SessionEngine {
|
|
|
1134
1299
|
return parts.join("\n").trimEnd();
|
|
1135
1300
|
}
|
|
1136
1301
|
async drainCoalescedFollowups(sessionId) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1302
|
+
let pending = [];
|
|
1303
|
+
while (pending.length === 0) {
|
|
1304
|
+
const queued = this.takeCoalescedQueue(sessionId);
|
|
1305
|
+
if (queued === undefined) {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
pending = await this.withoutNudgedFollowups(sessionId, queued);
|
|
1309
|
+
if (pending.length === 0) {
|
|
1310
|
+
this.logger(`[session] coalesce drain skipped; all follow-ups already nudged ${sessionId}`);
|
|
1311
|
+
}
|
|
1146
1312
|
}
|
|
1147
1313
|
// These become the next turn's prompt, so settle them in the nudge store
|
|
1148
1314
|
// first: a surviving pending record would be injected by that turn's own
|
|
@@ -1150,6 +1316,7 @@ export class SessionEngine {
|
|
|
1150
1316
|
await this.settleDrainedFollowups(sessionId, pending);
|
|
1151
1317
|
const message = this.formatCoalescedFollowups(pending);
|
|
1152
1318
|
this.logger(`[session] coalesce drain starting follow-up (${pending.length}) ${sessionId}`);
|
|
1319
|
+
const images = pending.flatMap((item) => item.images ?? []);
|
|
1153
1320
|
await this.startTurn(sessionId, message, {
|
|
1154
1321
|
turnMode: pending.some((item) => item.turnMode === "interactive")
|
|
1155
1322
|
? "interactive"
|
|
@@ -1157,8 +1324,33 @@ export class SessionEngine {
|
|
|
1157
1324
|
admission: "preempt",
|
|
1158
1325
|
retainCoalesced: true,
|
|
1159
1326
|
deliveryIds: pending.flatMap((item) => item.deliveryIds),
|
|
1327
|
+
images: images.length > 0 ? images : undefined,
|
|
1328
|
+
turnContext: pending.at(-1)?.turnContext,
|
|
1329
|
+
turnSessionKey: pending.at(-1)?.turnSessionKey,
|
|
1160
1330
|
});
|
|
1161
1331
|
}
|
|
1332
|
+
/**
|
|
1333
|
+
* The public {@link SteerTurn}: steer into the session's running turn, or
|
|
1334
|
+
* report why not. Never admits, enqueues, or creates anything. `turnId`
|
|
1335
|
+
* pins the turn the caller belongs to.
|
|
1336
|
+
*/
|
|
1337
|
+
async steerRunningTurn(sessionId, turnId, message, options = {}) {
|
|
1338
|
+
const deliveryId = resolveDeliveryId(options.deliveryId);
|
|
1339
|
+
const active = this.activeToolContexts.get(sessionId);
|
|
1340
|
+
if (active === undefined || (turnId !== undefined && active.turnId !== turnId)) {
|
|
1341
|
+
return { status: "no_turn" };
|
|
1342
|
+
}
|
|
1343
|
+
if (this.runner.steer === undefined) {
|
|
1344
|
+
return { status: "not_delivered", reason: "unsupported" };
|
|
1345
|
+
}
|
|
1346
|
+
if ((await this.steerIntoRunningTurn(sessionId, message)) !== "complete_delivered") {
|
|
1347
|
+
return { status: "not_delivered", reason: "refused" };
|
|
1348
|
+
}
|
|
1349
|
+
this.logger(`[session] steered own turn ${sessionId}`);
|
|
1350
|
+
active.emit({ type: "message.received", data: { text: message, deliveryIds: [deliveryId] } });
|
|
1351
|
+
active.emit({ type: "nudge.delivered", data: { deliveryId } });
|
|
1352
|
+
return { status: "steered", turnId: active.turnId, deliveryId };
|
|
1353
|
+
}
|
|
1162
1354
|
async steerIntoRunningTurn(sessionId, message) {
|
|
1163
1355
|
if (this.runner.steer === undefined) {
|
|
1164
1356
|
return "revert_to_followup";
|
|
@@ -1173,7 +1365,12 @@ export class SessionEngine {
|
|
|
1173
1365
|
}
|
|
1174
1366
|
async admitTurn(sessionId, message, options) {
|
|
1175
1367
|
const admission = options.admission ?? "preempt";
|
|
1176
|
-
|
|
1368
|
+
const images = options.images !== undefined && options.images.length > 0 ? options.images : undefined;
|
|
1369
|
+
if (admission === "coalesce" &&
|
|
1370
|
+
images === undefined &&
|
|
1371
|
+
steeringEnabled() &&
|
|
1372
|
+
this.isTurnRunning(sessionId) &&
|
|
1373
|
+
userKey(options.turnContext) === userKey(this.turnContextFor(sessionId))) {
|
|
1177
1374
|
const toolCtx = this.activeToolContexts.get(sessionId);
|
|
1178
1375
|
const steerOutcome = await this.steerIntoRunningTurn(sessionId, message);
|
|
1179
1376
|
if (steerOutcome === "complete_delivered") {
|
|
@@ -1202,19 +1399,25 @@ export class SessionEngine {
|
|
|
1202
1399
|
sourceTs: options.sourceTs,
|
|
1203
1400
|
turnMode: options.turnMode,
|
|
1204
1401
|
deliveryIds: [...(options.deliveryIds ?? [])],
|
|
1402
|
+
images,
|
|
1403
|
+
turnContext: options.turnContext,
|
|
1404
|
+
turnSessionKey: options.turnSessionKey,
|
|
1205
1405
|
});
|
|
1206
1406
|
this.logger(`[session] coalesce enqueue ${sessionId}`);
|
|
1207
1407
|
return true;
|
|
1208
1408
|
}
|
|
1209
|
-
// Another server owns this session, so coalesce even a preempt
|
|
1210
|
-
//
|
|
1211
|
-
//
|
|
1212
|
-
//
|
|
1213
|
-
// Enqueue-only cannot claim coalesced here: nothing joined a local turn.
|
|
1409
|
+
// Another server owns this session, so coalesce even a preempt through
|
|
1410
|
+
// its outbox. Not redundant with `acquire` below — this returns before
|
|
1411
|
+
// preempt's `clearCoalesced` drops the queue. Enqueue-only cannot claim
|
|
1412
|
+
// coalesced here: nothing joined a local turn.
|
|
1214
1413
|
if (await this.turnLeases.runningElsewhere(sessionId)) {
|
|
1215
1414
|
if (options.hostedEnqueueOnly === true) {
|
|
1216
1415
|
throw new HostedEnqueueNotActiveError(sessionId);
|
|
1217
1416
|
}
|
|
1417
|
+
await this.outbox.post(sessionId, {
|
|
1418
|
+
message,
|
|
1419
|
+
options: { ...options, admission: "coalesce" },
|
|
1420
|
+
});
|
|
1218
1421
|
this.logger(`[session] coalesce; another server owns ${sessionId}`);
|
|
1219
1422
|
return true;
|
|
1220
1423
|
}
|
|
@@ -1253,6 +1456,7 @@ export class SessionEngine {
|
|
|
1253
1456
|
const record = await this.updateRecord(sessionId, (current) => ({
|
|
1254
1457
|
...current,
|
|
1255
1458
|
turnCount: current.turnCount + 1,
|
|
1459
|
+
pendingImages: mergePendingImages(current.pendingImages, images),
|
|
1256
1460
|
}));
|
|
1257
1461
|
const turnId = `turn_${record.turnCount}`;
|
|
1258
1462
|
const isFirstTurn = record.turnCount === 1;
|
|
@@ -1266,6 +1470,16 @@ export class SessionEngine {
|
|
|
1266
1470
|
const abort = new AbortController();
|
|
1267
1471
|
this.turnAborts.set(sessionId, abort);
|
|
1268
1472
|
this.turnModes.set(sessionId, options.turnMode);
|
|
1473
|
+
const ownContext = { context: options.turnContext, sessionKey: options.turnSessionKey };
|
|
1474
|
+
this.turnContexts.set(sessionId, ownContext);
|
|
1475
|
+
const unlinkedSlackUserId = this.unlinkedSlackSenderNeedingLink(options);
|
|
1476
|
+
if (unlinkedSlackUserId !== undefined) {
|
|
1477
|
+
await this.appendEvent(sessionId, {
|
|
1478
|
+
type: "action.account_link_requested",
|
|
1479
|
+
turnId,
|
|
1480
|
+
data: { slackUserId: unlinkedSlackUserId },
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1269
1483
|
// Lifecycle promise includes post-turn coalesce drain so waiters and
|
|
1270
1484
|
// interrupt settle after follow-ups are admitted (not only executeTurn).
|
|
1271
1485
|
// Assigned before the async body runs so self-identity checks typecheck.
|
|
@@ -1275,7 +1489,7 @@ export class SessionEngine {
|
|
|
1275
1489
|
const poll = setInterval(() => this.drainOutbox(sessionId), 1_000);
|
|
1276
1490
|
poll.unref();
|
|
1277
1491
|
try {
|
|
1278
|
-
outcome = await this.executeTurn(record, turnId, message, isFirstTurn, abort.signal);
|
|
1492
|
+
outcome = await this.executeTurn(record, turnId, message, isFirstTurn, abort.signal, options.platformDeliveryId);
|
|
1279
1493
|
if (outcome.status === "cancelled") {
|
|
1280
1494
|
outcome.cancellationReason = abort.signal.aborted ? "signal" : "runner";
|
|
1281
1495
|
}
|
|
@@ -1316,6 +1530,9 @@ export class SessionEngine {
|
|
|
1316
1530
|
}
|
|
1317
1531
|
}
|
|
1318
1532
|
}
|
|
1533
|
+
if (this.turnContexts.get(sessionId) === ownContext) {
|
|
1534
|
+
this.turnContexts.delete(sessionId);
|
|
1535
|
+
}
|
|
1319
1536
|
// The drain may have nested a successor turn, which took its own
|
|
1320
1537
|
// reference; the lease outlives this release until that one ends too.
|
|
1321
1538
|
await lease.release();
|
|
@@ -1363,7 +1580,7 @@ export class SessionEngine {
|
|
|
1363
1580
|
const hadWork = this.turnAborts.has(sessionId) ||
|
|
1364
1581
|
this.activeTurns.has(sessionId) ||
|
|
1365
1582
|
this.coalesceDrains.has(sessionId) ||
|
|
1366
|
-
(this.coalesceQueues.get(sessionId)?.
|
|
1583
|
+
(this.coalesceQueues.get(sessionId)?.size ?? 0) > 0;
|
|
1367
1584
|
this.clearCoalesced(sessionId);
|
|
1368
1585
|
await this.outbox.clear(sessionId);
|
|
1369
1586
|
const record = await this.sessions.get(sessionId);
|
|
@@ -1556,6 +1773,33 @@ export class SessionEngine {
|
|
|
1556
1773
|
this.sessionRootInflight.delete(options.sessionId);
|
|
1557
1774
|
}
|
|
1558
1775
|
}
|
|
1776
|
+
/**
|
|
1777
|
+
* The discovered skills the session's `skills` tree serves, asked on
|
|
1778
|
+
* every turn: a skill the tree stops serving drops out of the index, and
|
|
1779
|
+
* so does one whose stat throws.
|
|
1780
|
+
*/
|
|
1781
|
+
async mountedSkills(record) {
|
|
1782
|
+
const { skills: mount } = await this.resolveAuthoredFileSystem({
|
|
1783
|
+
sessionId: record.sessionId,
|
|
1784
|
+
continuationKey: record.continuationKey ?? undefined,
|
|
1785
|
+
cache: true,
|
|
1786
|
+
});
|
|
1787
|
+
const served = [];
|
|
1788
|
+
if (mount === undefined) {
|
|
1789
|
+
return served;
|
|
1790
|
+
}
|
|
1791
|
+
for (const skill of this.project.agent.skills) {
|
|
1792
|
+
try {
|
|
1793
|
+
if ((await mount.stat(`/${skill.name}/SKILL.md`)).kind === "file") {
|
|
1794
|
+
served.push(skill);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
catch (error) {
|
|
1798
|
+
this.logger(`[session] skill ${skill.name} left out of the index for ${record.sessionId}: ${describeError(error)}`);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return served;
|
|
1802
|
+
}
|
|
1559
1803
|
baseSkillsFileSystem() {
|
|
1560
1804
|
this.baseSkills ??= skillsFileSystem(this.project.agent.skills).catch((error) => {
|
|
1561
1805
|
this.baseSkills = undefined;
|
|
@@ -1712,6 +1956,7 @@ export class SessionEngine {
|
|
|
1712
1956
|
// warmed without an identity; the per-send flag still has to match
|
|
1713
1957
|
// the turns' requests or the warmed executor is one no turn asks for.
|
|
1714
1958
|
mcpServers: this.buildMcpServers("local"),
|
|
1959
|
+
...this.hostMcpBridgeUrlsField(),
|
|
1715
1960
|
...(this.hasAttachedAuthedConnections() ||
|
|
1716
1961
|
this.project.agent.connections.some((connection) => isCursorAccountTransport(connection.transport))
|
|
1717
1962
|
? { perSendMcpServers: true }
|
|
@@ -1737,7 +1982,7 @@ export class SessionEngine {
|
|
|
1737
1982
|
}
|
|
1738
1983
|
return this.harnessCwd(record);
|
|
1739
1984
|
}
|
|
1740
|
-
async executeTurn(record, turnId, message, isFirstTurn, signal) {
|
|
1985
|
+
async executeTurn(record, turnId, message, isFirstTurn, signal, platformDeliveryId) {
|
|
1741
1986
|
const sessionId = record.sessionId;
|
|
1742
1987
|
const workspaceDir = this.scaffoldDir(record);
|
|
1743
1988
|
const harnessCwd = this.harnessCwd(record);
|
|
@@ -1746,6 +1991,7 @@ export class SessionEngine {
|
|
|
1746
1991
|
channelState: structuredClone(turnChannelState),
|
|
1747
1992
|
channelStateAtTurnStart: structuredClone(turnChannelState),
|
|
1748
1993
|
session: this.sessionInfo(record),
|
|
1994
|
+
turnId,
|
|
1749
1995
|
};
|
|
1750
1996
|
this.liveTurns.set(sessionId, eventContext);
|
|
1751
1997
|
// Hold the open log so tool events append synchronously. Fire-and-forget
|
|
@@ -1785,6 +2031,7 @@ export class SessionEngine {
|
|
|
1785
2031
|
}
|
|
1786
2032
|
else {
|
|
1787
2033
|
emit({ type: "turn.started", data: {} });
|
|
2034
|
+
markHostedTurnStarted();
|
|
1788
2035
|
try {
|
|
1789
2036
|
if (record.workspaceOverride === undefined &&
|
|
1790
2037
|
this.project.agent.local?.workspaceDir !== undefined) {
|
|
@@ -1866,8 +2113,11 @@ export class SessionEngine {
|
|
|
1866
2113
|
await yieldEventLoop();
|
|
1867
2114
|
}
|
|
1868
2115
|
};
|
|
2116
|
+
const settled = runtime === "local" && this.hasIndividualAccountConnections()
|
|
2117
|
+
? await this.settleConnects(sessionId, message, emit)
|
|
2118
|
+
: undefined;
|
|
1869
2119
|
const endBuildRequest = this.startTurnPhase(record, turnId, "build_request");
|
|
1870
|
-
const request = await this.buildTurnRequest(record, turnId, message, isFirstTurn, emit, eventContext, onUpdate, signal, pendingImages);
|
|
2120
|
+
const request = await this.buildTurnRequest(record, turnId, message, isFirstTurn, emit, eventContext, onUpdate, signal, pendingImages, platformDeliveryId);
|
|
1871
2121
|
endBuildRequest();
|
|
1872
2122
|
// Runner start (SDK agent create/resume, MCP connect, model request)
|
|
1873
2123
|
// until the first streamed update.
|
|
@@ -1875,7 +2125,13 @@ export class SessionEngine {
|
|
|
1875
2125
|
this.activeToolContexts.set(sessionId, { record, turnId, emit });
|
|
1876
2126
|
this.stubbedCallIds.set(sessionId, stubbed);
|
|
1877
2127
|
try {
|
|
1878
|
-
|
|
2128
|
+
if (settled === undefined) {
|
|
2129
|
+
outcome = await this.runTurnExecute(record, turnId, () => this.runner.runTurn(request));
|
|
2130
|
+
}
|
|
2131
|
+
else {
|
|
2132
|
+
mapper.handleUpdate({ type: "text-delta", text: settled.skip });
|
|
2133
|
+
outcome = { status: "finished", result: settled.skip };
|
|
2134
|
+
}
|
|
1879
2135
|
}
|
|
1880
2136
|
finally {
|
|
1881
2137
|
endFirstUpdate?.();
|
|
@@ -2131,7 +2387,7 @@ export class SessionEngine {
|
|
|
2131
2387
|
fallbackAfterStream: undefined,
|
|
2132
2388
|
};
|
|
2133
2389
|
}
|
|
2134
|
-
async buildTurnRequest(record, turnId, prompt, isFirstTurn, emit, eventContext, onUpdate, signal, images) {
|
|
2390
|
+
async buildTurnRequest(record, turnId, prompt, isFirstTurn, emit, eventContext, onUpdate, signal, images, platformDeliveryId) {
|
|
2135
2391
|
const agent = this.project.agent;
|
|
2136
2392
|
const instructionsAgent = agentWithInstructionsOverride(agent, record.instructions);
|
|
2137
2393
|
// Per-session cloud attach (channel/tool handoff) forces cloud runtime
|
|
@@ -2263,10 +2519,9 @@ export class SessionEngine {
|
|
|
2263
2519
|
// bodies and indexes the skills mounted in the tree.
|
|
2264
2520
|
const localInstructions = runtime === "local"
|
|
2265
2521
|
? authoredRoot
|
|
2266
|
-
? buildAgentsMdContent(
|
|
2267
|
-
|
|
2268
|
-
skillsIndex: agent.skillsMount !== false
|
|
2269
|
-
})
|
|
2522
|
+
? buildAgentsMdContent(typeof agent.skillsMount === "function"
|
|
2523
|
+
? { ...instructionsAgent, skills: await this.mountedSkills(record) }
|
|
2524
|
+
: instructionsAgent, { includeScripts: true, skillsIndex: agent.skillsMount !== false })
|
|
2270
2525
|
: buildAgentsMdContent(instructionsAgent, {
|
|
2271
2526
|
includeScripts: this.hasBorrowedWorkspace(record),
|
|
2272
2527
|
skillsIndex: workspaceConfined && agent.skills.length > 0,
|
|
@@ -2321,11 +2576,15 @@ export class SessionEngine {
|
|
|
2321
2576
|
: {}),
|
|
2322
2577
|
customTools: runtime === "local" ? await this.buildCustomTools(record, turnId, emit, signal) : {},
|
|
2323
2578
|
mcpServers: this.buildMcpServers(runtime, record.sessionId, await this.evaluateConnectionAuth(record)),
|
|
2579
|
+
...(runtime === "local" ? this.hostMcpBridgeUrlsField() : {}),
|
|
2324
2580
|
...(runtime === "local" &&
|
|
2325
2581
|
(this.hasAttachedAuthedConnections() ||
|
|
2326
2582
|
this.project.agent.connections.some((connection) => isCursorAccountTransport(connection.transport)))
|
|
2327
2583
|
? { perSendMcpServers: true }
|
|
2328
2584
|
: {}),
|
|
2585
|
+
onMcpAuthRequest: runtime === "local" && this.hasIndividualAccountConnections()
|
|
2586
|
+
? (request) => this.answerMcpAuth(record.sessionId, turnId, emit, request)
|
|
2587
|
+
: undefined,
|
|
2329
2588
|
subagents: buildRunnerSubagents(agent),
|
|
2330
2589
|
onUpdate,
|
|
2331
2590
|
signal,
|
|
@@ -2356,13 +2615,28 @@ export class SessionEngine {
|
|
|
2356
2615
|
},
|
|
2357
2616
|
}, eventContext);
|
|
2358
2617
|
},
|
|
2618
|
+
reattachCloudRunId: reattachableCloudRunId(record, platformDeliveryId),
|
|
2619
|
+
platformDeliveryId,
|
|
2620
|
+
onCloudRunStarted: async ({ sdkAgentId, runId }) => {
|
|
2621
|
+
if (platformDeliveryId !== undefined) {
|
|
2622
|
+
await this.updateRecord(record.sessionId, (current) => ({
|
|
2623
|
+
...current,
|
|
2624
|
+
hostedCloudRun: { platformDeliveryId, sdkAgentId, runId },
|
|
2625
|
+
}));
|
|
2626
|
+
}
|
|
2627
|
+
// The cloud run outlives this process. Storage otherwise sees the
|
|
2628
|
+
// bound agent only at turn end, so a host that replaces this one
|
|
2629
|
+
// mid-turn would start a second cloud agent.
|
|
2630
|
+
this.storage?.flushSessionExact(record.sessionId);
|
|
2631
|
+
},
|
|
2359
2632
|
};
|
|
2360
2633
|
}
|
|
2361
2634
|
/**
|
|
2362
2635
|
* Connection names a cloud turn can only reach through the host connection
|
|
2363
2636
|
* bridge on the tool MCP endpoint: filtered account connections without a
|
|
2364
2637
|
* public bridge URL, and host-OAuth connections whose tokens live on this
|
|
2365
|
-
* host.
|
|
2638
|
+
* host. Individual connections never qualify: the endpoint authenticates
|
|
2639
|
+
* the deployment, not the session, so it cannot dial as a session's user.
|
|
2366
2640
|
*/
|
|
2367
2641
|
cloudBridgeableConnectionNames() {
|
|
2368
2642
|
const names = [];
|
|
@@ -2372,7 +2646,9 @@ export class SessionEngine {
|
|
|
2372
2646
|
}
|
|
2373
2647
|
}
|
|
2374
2648
|
for (const resolved of this.resolvedConnections) {
|
|
2375
|
-
if (resolved.accountServersFilter !== undefined &&
|
|
2649
|
+
if (resolved.accountServersFilter !== undefined &&
|
|
2650
|
+
resolved.individualCredentials !== true &&
|
|
2651
|
+
resolved.cloudUrl === undefined) {
|
|
2376
2652
|
names.push(resolved.name);
|
|
2377
2653
|
}
|
|
2378
2654
|
}
|
|
@@ -2400,11 +2676,25 @@ export class SessionEngine {
|
|
|
2400
2676
|
if (connection === undefined || !("url" in connection)) {
|
|
2401
2677
|
return undefined;
|
|
2402
2678
|
}
|
|
2403
|
-
const url =
|
|
2404
|
-
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2679
|
+
const url = this.sessionToolsUrl(connection.url, sessionId);
|
|
2405
2680
|
url.searchParams.set("connection", connectionName);
|
|
2406
2681
|
return { ...connection, url: url.toString() };
|
|
2407
2682
|
}
|
|
2683
|
+
/** The tool MCP endpoint URL bound to `sessionId` and carrying its credential. */
|
|
2684
|
+
sessionToolsUrl(base, sessionId) {
|
|
2685
|
+
const url = new URL(base);
|
|
2686
|
+
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2687
|
+
url.searchParams.set(TOOL_SESSION_CREDENTIAL_PARAM, this.toolSessionCredentials.for(sessionId));
|
|
2688
|
+
return url;
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Whether a tool MCP endpoint request presents the credential of the
|
|
2692
|
+
* session it names. The endpoint's own auth admits the deployment, not a
|
|
2693
|
+
* session, so this is what keeps one session out of another's tools.
|
|
2694
|
+
*/
|
|
2695
|
+
presentsToolSessionCredential(sessionId, presented) {
|
|
2696
|
+
return this.toolSessionCredentials.verifies(sessionId, presented);
|
|
2697
|
+
}
|
|
2408
2698
|
/**
|
|
2409
2699
|
* Authored + resolved MCP servers for a turn. Skips advertised
|
|
2410
2700
|
* connections (those surface as named server tools). On cloud turns,
|
|
@@ -2482,8 +2772,9 @@ export class SessionEngine {
|
|
|
2482
2772
|
const url = runtime === "cloud" ? resolved.cloudUrl : resolved.localUrl;
|
|
2483
2773
|
if (url === undefined) {
|
|
2484
2774
|
// Filtered account connections bridge through the host so the
|
|
2485
|
-
// `servers` filter is honored;
|
|
2486
|
-
// fallback to the account's native connectors on the VM.
|
|
2775
|
+
// `servers` filter is honored; the rest keep their documented
|
|
2776
|
+
// fallback to the account's native connectors on the VM. An
|
|
2777
|
+
// individual one never gets here: the turn refuses it first.
|
|
2487
2778
|
const bridged = bridgeTransport(resolved.name);
|
|
2488
2779
|
if (bridged !== undefined) {
|
|
2489
2780
|
servers[resolved.name] = bridged;
|
|
@@ -2498,7 +2789,7 @@ export class SessionEngine {
|
|
|
2498
2789
|
bound.searchParams.set("agentkitSessionId", sessionId);
|
|
2499
2790
|
servers[resolved.name] = {
|
|
2500
2791
|
url: bound.toString(),
|
|
2501
|
-
headers: resolved.headers,
|
|
2792
|
+
headers: resolved.sessionHeaders?.(sessionId) ?? resolved.headers,
|
|
2502
2793
|
};
|
|
2503
2794
|
continue;
|
|
2504
2795
|
}
|
|
@@ -2516,11 +2807,9 @@ export class SessionEngine {
|
|
|
2516
2807
|
}
|
|
2517
2808
|
const connection = this.currentCloudServerToolsConnection();
|
|
2518
2809
|
if (connection !== undefined && "url" in connection) {
|
|
2519
|
-
const url = new URL(connection.url);
|
|
2520
|
-
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2521
2810
|
servers[SERVER_TOOLS_MCP_SERVER_NAME] = {
|
|
2522
2811
|
...connection,
|
|
2523
|
-
url: url.toString(),
|
|
2812
|
+
url: this.sessionToolsUrl(connection.url, sessionId).toString(),
|
|
2524
2813
|
};
|
|
2525
2814
|
}
|
|
2526
2815
|
}
|
|
@@ -2535,6 +2824,9 @@ export class SessionEngine {
|
|
|
2535
2824
|
hasAttachedAuthedConnections() {
|
|
2536
2825
|
return this.project.agent.connections.some((connection) => connection.auth !== undefined && connection.advertiseTools !== true);
|
|
2537
2826
|
}
|
|
2827
|
+
hasIndividualAccountConnections() {
|
|
2828
|
+
return this.project.agent.connections.some((connection) => connection.credentials === "individual" && isCursorAccountTransport(connection.transport));
|
|
2829
|
+
}
|
|
2538
2830
|
/**
|
|
2539
2831
|
* Evaluate per-session connection auth (`defineConnection({ auth })`)
|
|
2540
2832
|
* for connections that attach to the model this turn. Advertised
|
|
@@ -2735,6 +3027,7 @@ export class SessionEngine {
|
|
|
2735
3027
|
}),
|
|
2736
3028
|
getSession: (channelId, sessionId) => this.getChannelSession(channelId, sessionId),
|
|
2737
3029
|
emit: args.emit,
|
|
3030
|
+
steer: (message, steerOptions) => this.steerRunningTurn(args.record.sessionId, args.turnId, message, steerOptions),
|
|
2738
3031
|
// Built before runInCall binds the turn. Methods read the active
|
|
2739
3032
|
// context when the tool calls them.
|
|
2740
3033
|
telemetry,
|
|
@@ -2783,8 +3076,9 @@ export class SessionEngine {
|
|
|
2783
3076
|
}
|
|
2784
3077
|
const needsGate = await evaluateNeedsApproval(args.tool.definition.needsApproval, validation.value);
|
|
2785
3078
|
if (needsGate) {
|
|
2786
|
-
const { decision, approver } = await this.parkForApproval({
|
|
3079
|
+
const { decision, reason, approver } = await this.parkForApproval({
|
|
2787
3080
|
sessionId: args.record.sessionId,
|
|
3081
|
+
channelId: args.record.channelId,
|
|
2788
3082
|
turnId: args.turnId,
|
|
2789
3083
|
callId: toolCallId,
|
|
2790
3084
|
toolName: args.tool.name,
|
|
@@ -2792,7 +3086,7 @@ export class SessionEngine {
|
|
|
2792
3086
|
emit: args.emit,
|
|
2793
3087
|
});
|
|
2794
3088
|
if (decision === "deny") {
|
|
2795
|
-
return toolErrorResult(
|
|
3089
|
+
return toolErrorResult(toolDenialText(args.tool.name, reason));
|
|
2796
3090
|
}
|
|
2797
3091
|
toolCtx.approvedBy = approver;
|
|
2798
3092
|
}
|
|
@@ -2927,7 +3221,13 @@ export class SessionEngine {
|
|
|
2927
3221
|
},
|
|
2928
3222
|
});
|
|
2929
3223
|
this.logger(`[session] tool ${args.toolName} awaiting approval (${args.callId})`);
|
|
2930
|
-
const
|
|
3224
|
+
const timeoutMs = this.channelsById.get(args.channelId)?.meta?.toolApprovalTimeoutMs;
|
|
3225
|
+
const stopDeadline = timeoutMs === undefined
|
|
3226
|
+
? () => { }
|
|
3227
|
+
: armParkDeadline(this.turnAborts.get(args.sessionId)?.signal, timeoutMs, (reason) => {
|
|
3228
|
+
this.approvals.expire(args.sessionId, args.callId, reason);
|
|
3229
|
+
});
|
|
3230
|
+
const { decision, by, approver, reason } = await resolutionPromise.finally(stopDeadline);
|
|
2931
3231
|
await this.updateRecord(args.sessionId, (current) => ({
|
|
2932
3232
|
...current,
|
|
2933
3233
|
pendingApprovals: (current.pendingApprovals ?? []).filter((item) => item.callId !== args.callId),
|
|
@@ -2938,11 +3238,12 @@ export class SessionEngine {
|
|
|
2938
3238
|
callId: args.callId,
|
|
2939
3239
|
toolName: args.toolName,
|
|
2940
3240
|
decision,
|
|
2941
|
-
|
|
3241
|
+
by,
|
|
3242
|
+
reason,
|
|
2942
3243
|
},
|
|
2943
3244
|
});
|
|
2944
3245
|
this.logger(`[session] tool ${args.toolName} approval ${decision} (${args.callId})`);
|
|
2945
|
-
return { decision, by, approver };
|
|
3246
|
+
return { decision, by, approver, reason };
|
|
2946
3247
|
}
|
|
2947
3248
|
async clearPendingApprovals(sessionId) {
|
|
2948
3249
|
const current = await this.sessions.get(sessionId);
|
|
@@ -3070,6 +3371,10 @@ export class SessionEngine {
|
|
|
3070
3371
|
if (!canPark() && !canRefresh) {
|
|
3071
3372
|
return giveUp();
|
|
3072
3373
|
}
|
|
3374
|
+
if (authored?.credentials === "individual" &&
|
|
3375
|
+
this.turnContextFor(ctx.sessionId)?.user === undefined) {
|
|
3376
|
+
throw new McpReconnectError(authored.name, individualNoUserMessage(authored.name), error);
|
|
3377
|
+
}
|
|
3073
3378
|
const minted = await this.mintAuthUrl(connection, ctx.sessionId);
|
|
3074
3379
|
if (minted === undefined) {
|
|
3075
3380
|
return giveUp();
|
|
@@ -3079,6 +3384,9 @@ export class SessionEngine {
|
|
|
3079
3384
|
await this.mcpHost.dropClient(connection);
|
|
3080
3385
|
return await this.withMcpAuth(connection, run);
|
|
3081
3386
|
}
|
|
3387
|
+
if (authored?.credentials === "individual") {
|
|
3388
|
+
return this.sendPrivateSignIn(ctx, authored, minted.authUrl, error);
|
|
3389
|
+
}
|
|
3082
3390
|
if (minted.state !== "") {
|
|
3083
3391
|
const bind = this.oauthHub.bind(minted.state, ctx.sessionId, ctx.callId);
|
|
3084
3392
|
if (bind === "already_done") {
|
|
@@ -3112,6 +3420,41 @@ export class SessionEngine {
|
|
|
3112
3420
|
await this.mcpHost.dropClient(connection);
|
|
3113
3421
|
return await this.withMcpAuth(connection, run);
|
|
3114
3422
|
}
|
|
3423
|
+
/**
|
|
3424
|
+
* An individual connection signs in only the person who started the turn,
|
|
3425
|
+
* so the link goes to them alone and the turn does not wait for them.
|
|
3426
|
+
*/
|
|
3427
|
+
sendPrivateSignIn(ctx, connection, authUrl, cause) {
|
|
3428
|
+
const source = this.turnContextFor(ctx.sessionId)?.source;
|
|
3429
|
+
const slackUserId = source?.kind === "slack" ? source.userId : undefined;
|
|
3430
|
+
ctx.emit({
|
|
3431
|
+
type: "action.auth_requested",
|
|
3432
|
+
data: {
|
|
3433
|
+
callId: ctx.callId,
|
|
3434
|
+
toolName: ctx.toolName,
|
|
3435
|
+
connection: connection.name,
|
|
3436
|
+
authUrl,
|
|
3437
|
+
privateTo: { slackUserId },
|
|
3438
|
+
},
|
|
3439
|
+
});
|
|
3440
|
+
throw new McpReconnectError(connection.name, privateSignInMessage({
|
|
3441
|
+
connection: connection.name,
|
|
3442
|
+
authUrl,
|
|
3443
|
+
sentToSlack: slackUserId !== undefined,
|
|
3444
|
+
}), cause);
|
|
3445
|
+
}
|
|
3446
|
+
/** The Slack member to tell how to link an account, when this turn has none and needs one. */
|
|
3447
|
+
unlinkedSlackSenderNeedingLink(options) {
|
|
3448
|
+
const turn = options.turnContext;
|
|
3449
|
+
if (options.turnMode !== "interactive" ||
|
|
3450
|
+
turn === undefined ||
|
|
3451
|
+
turn.user !== undefined ||
|
|
3452
|
+
turn.source.kind !== "slack" ||
|
|
3453
|
+
!this.project.agent.connections.some((item) => item.credentials === "individual")) {
|
|
3454
|
+
return undefined;
|
|
3455
|
+
}
|
|
3456
|
+
return turn.source.userId;
|
|
3457
|
+
}
|
|
3115
3458
|
async persistHostedMcpOauth(connection) {
|
|
3116
3459
|
const authored = this.authoredConnection(connection);
|
|
3117
3460
|
if (authored === undefined || !isHostOauthConnectionTransport(authored.transport)) {
|
|
@@ -3129,7 +3472,7 @@ export class SessionEngine {
|
|
|
3129
3472
|
if (probe === undefined) {
|
|
3130
3473
|
return undefined;
|
|
3131
3474
|
}
|
|
3132
|
-
const authUrl = await probe(connection);
|
|
3475
|
+
const authUrl = await probe(connection, sessionId);
|
|
3133
3476
|
if (authUrl === undefined || authUrl === "") {
|
|
3134
3477
|
return undefined;
|
|
3135
3478
|
}
|
|
@@ -3175,34 +3518,11 @@ export class SessionEngine {
|
|
|
3175
3518
|
},
|
|
3176
3519
|
});
|
|
3177
3520
|
this.logger(`[session] tool ${args.toolName} awaiting MCP auth ${args.connection} (${args.callId})`);
|
|
3178
|
-
const
|
|
3521
|
+
const stopDeadline = armParkDeadline(this.turnAborts.get(args.sessionId)?.signal, MCP_AUTH_PARK_TIMEOUT_MS, (reason) => {
|
|
3179
3522
|
void this.oauthHub.abortCall(args.sessionId, args.callId);
|
|
3180
|
-
|
|
3181
|
-
};
|
|
3182
|
-
const
|
|
3183
|
-
const endForAbort = () => {
|
|
3184
|
-
endWait("interrupt");
|
|
3185
|
-
};
|
|
3186
|
-
if (signal?.aborted) {
|
|
3187
|
-
endForAbort();
|
|
3188
|
-
}
|
|
3189
|
-
else {
|
|
3190
|
-
signal?.addEventListener("abort", endForAbort, { once: true });
|
|
3191
|
-
}
|
|
3192
|
-
let timedOut = false;
|
|
3193
|
-
const timer = setTimeout(() => {
|
|
3194
|
-
timedOut = endWait("timeout");
|
|
3195
|
-
}, MCP_AUTH_PARK_TIMEOUT_MS);
|
|
3196
|
-
timer.unref();
|
|
3197
|
-
let decision;
|
|
3198
|
-
let by;
|
|
3199
|
-
try {
|
|
3200
|
-
({ decision, by } = await resolutionPromise);
|
|
3201
|
-
}
|
|
3202
|
-
finally {
|
|
3203
|
-
clearTimeout(timer);
|
|
3204
|
-
signal?.removeEventListener("abort", endForAbort);
|
|
3205
|
-
}
|
|
3523
|
+
this.auths.expire(args.sessionId, args.callId, reason);
|
|
3524
|
+
});
|
|
3525
|
+
const { decision, by, reason } = await resolutionPromise.finally(stopDeadline);
|
|
3206
3526
|
await this.updateRecord(args.sessionId, (current) => ({
|
|
3207
3527
|
...current,
|
|
3208
3528
|
pendingAuths: (current.pendingAuths ?? []).filter((item) => item.callId !== args.callId),
|
|
@@ -3215,24 +3535,158 @@ export class SessionEngine {
|
|
|
3215
3535
|
connection: args.connection,
|
|
3216
3536
|
decision,
|
|
3217
3537
|
by,
|
|
3538
|
+
reason,
|
|
3218
3539
|
},
|
|
3219
3540
|
});
|
|
3220
|
-
const outcome =
|
|
3541
|
+
const outcome = reason === "timeout" ? "timeout" : decision;
|
|
3221
3542
|
this.logger(`[session] tool ${args.toolName} MCP auth ${outcome} (${args.callId})`);
|
|
3222
3543
|
return outcome;
|
|
3223
3544
|
}
|
|
3545
|
+
/** Keeps connects that wait for the person's next turn rather than this one. */
|
|
3224
3546
|
async clearPendingAuths(sessionId) {
|
|
3225
3547
|
await this.oauthHub.abortSession(sessionId);
|
|
3226
3548
|
const current = await this.sessions.get(sessionId);
|
|
3227
3549
|
if (current === undefined ||
|
|
3228
3550
|
current.pendingAuths === undefined ||
|
|
3229
|
-
current.pendingAuths.
|
|
3551
|
+
current.pendingAuths.every((item) => item.awaitsNextTurn === true)) {
|
|
3230
3552
|
return;
|
|
3231
3553
|
}
|
|
3232
3554
|
await this.updateRecord(sessionId, (record) => ({
|
|
3233
3555
|
...record,
|
|
3234
|
-
pendingAuths: [],
|
|
3556
|
+
pendingAuths: (record.pendingAuths ?? []).filter((item) => item.awaitsNextTurn === true),
|
|
3557
|
+
}));
|
|
3558
|
+
}
|
|
3559
|
+
/**
|
|
3560
|
+
* The agent's `mcp_auth` for an individual connection, answered at once:
|
|
3561
|
+
* the person connects from the card and clicks Connected, which starts
|
|
3562
|
+
* their next turn on fresh MCP clients. A repeat request reuses the pending
|
|
3563
|
+
* link. Only an already-connected connection is approved, because the SDK
|
|
3564
|
+
* does not reload a server it approves.
|
|
3565
|
+
*/
|
|
3566
|
+
async answerMcpAuth(sessionId, turnId, emit, request) {
|
|
3567
|
+
const connection = this.authoredConnection(request.serverName);
|
|
3568
|
+
if (connection?.credentials !== "individual" ||
|
|
3569
|
+
!isCursorAccountTransport(connection.transport)) {
|
|
3570
|
+
return undefined;
|
|
3571
|
+
}
|
|
3572
|
+
const turn = this.turnContextFor(sessionId);
|
|
3573
|
+
if (turn?.user === undefined) {
|
|
3574
|
+
return { kind: "rejected", reason: individualNoUserMessage(connection.name) };
|
|
3575
|
+
}
|
|
3576
|
+
const sentToSlack = turn.source.kind === "slack";
|
|
3577
|
+
const userId = turn.user.id;
|
|
3578
|
+
const pending = (await this.sessions.get(sessionId))?.pendingAuths?.find((item) => item.awaitsNextTurn === true &&
|
|
3579
|
+
item.userId === userId &&
|
|
3580
|
+
item.connection === connection.name);
|
|
3581
|
+
if (pending !== undefined) {
|
|
3582
|
+
// A later turn shows the same card again, in case Connected came early.
|
|
3583
|
+
if (pending.turnId !== turnId) {
|
|
3584
|
+
emit({
|
|
3585
|
+
type: "action.auth_requested",
|
|
3586
|
+
data: {
|
|
3587
|
+
callId: pending.callId,
|
|
3588
|
+
toolName: pending.toolName,
|
|
3589
|
+
connection: pending.connection,
|
|
3590
|
+
authUrl: pending.authUrl,
|
|
3591
|
+
privateTo: {
|
|
3592
|
+
slackUserId: turn.source.kind === "slack" ? turn.source.userId : undefined,
|
|
3593
|
+
},
|
|
3594
|
+
},
|
|
3595
|
+
});
|
|
3596
|
+
await this.updateRecord(sessionId, (current) => ({
|
|
3597
|
+
...current,
|
|
3598
|
+
pendingAuths: (current.pendingAuths ?? []).map((item) => item.callId === pending.callId ? { ...item, turnId } : item),
|
|
3599
|
+
}));
|
|
3600
|
+
}
|
|
3601
|
+
return {
|
|
3602
|
+
kind: "rejected",
|
|
3603
|
+
reason: connectThenContinueMessage(connection.name, pending.authUrl, sentToSlack),
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
if ((await this.individualConnectedCheck?.(connection.name, sessionId)) === true) {
|
|
3607
|
+
return { kind: "approved" };
|
|
3608
|
+
}
|
|
3609
|
+
const minted = await this.mintAuthUrl(connection.name, sessionId);
|
|
3610
|
+
if (minted === undefined || !("authUrl" in minted)) {
|
|
3611
|
+
return {
|
|
3612
|
+
kind: "rejected",
|
|
3613
|
+
reason: `${connection.name} could not start a sign-in. Answer without ${connection.name}.`,
|
|
3614
|
+
};
|
|
3615
|
+
}
|
|
3616
|
+
const entry = {
|
|
3617
|
+
callId: request.toolCallId,
|
|
3618
|
+
turnId,
|
|
3619
|
+
toolName: MCP_AUTH_TOOL_NAME,
|
|
3620
|
+
connection: connection.name,
|
|
3621
|
+
authUrl: minted.authUrl,
|
|
3622
|
+
requestedAt: new Date().toISOString(),
|
|
3623
|
+
awaitsNextTurn: true,
|
|
3624
|
+
userId,
|
|
3625
|
+
};
|
|
3626
|
+
await this.updateRecord(sessionId, (current) => ({
|
|
3627
|
+
...current,
|
|
3628
|
+
pendingAuths: [
|
|
3629
|
+
...(current.pendingAuths ?? []).filter((item) => item.callId !== entry.callId),
|
|
3630
|
+
entry,
|
|
3631
|
+
],
|
|
3235
3632
|
}));
|
|
3633
|
+
emit({
|
|
3634
|
+
type: "action.auth_requested",
|
|
3635
|
+
data: {
|
|
3636
|
+
callId: entry.callId,
|
|
3637
|
+
toolName: entry.toolName,
|
|
3638
|
+
connection: entry.connection,
|
|
3639
|
+
authUrl: entry.authUrl,
|
|
3640
|
+
privateTo: { slackUserId: turn.source.kind === "slack" ? turn.source.userId : undefined },
|
|
3641
|
+
},
|
|
3642
|
+
});
|
|
3643
|
+
return {
|
|
3644
|
+
kind: "rejected",
|
|
3645
|
+
reason: connectThenContinueMessage(connection.name, entry.authUrl, sentToSlack),
|
|
3646
|
+
};
|
|
3647
|
+
}
|
|
3648
|
+
/**
|
|
3649
|
+
* Settles pending connects at turn start, each once: Cancel drops one, and
|
|
3650
|
+
* a connect the person finished resolves. A Connected or Cancel click with
|
|
3651
|
+
* nothing pending for its connection does not run the request again.
|
|
3652
|
+
*/
|
|
3653
|
+
async settleConnects(sessionId, message, emit) {
|
|
3654
|
+
const userId = this.turnContextFor(sessionId)?.user?.id;
|
|
3655
|
+
if (userId === undefined) {
|
|
3656
|
+
return undefined;
|
|
3657
|
+
}
|
|
3658
|
+
// A Slack thread can hold several people; each settles only their own connects.
|
|
3659
|
+
const pending = ((await this.sessions.get(sessionId))?.pendingAuths ?? []).filter((item) => item.awaitsNextTurn === true && item.userId === userId);
|
|
3660
|
+
const individual = this.project.agent.connections
|
|
3661
|
+
.filter((connection) => connection.credentials === "individual" && isCursorAccountTransport(connection.transport))
|
|
3662
|
+
.map((connection) => connection.name);
|
|
3663
|
+
const click = parseConnectClickText(message, individual);
|
|
3664
|
+
if (click !== undefined && !pending.some((item) => item.connection === click.connection)) {
|
|
3665
|
+
return { skip: `Nothing is waiting on ${click.connection}.` };
|
|
3666
|
+
}
|
|
3667
|
+
const resolve = async (item, decision) => {
|
|
3668
|
+
await this.removePendingAuth(sessionId, item.callId);
|
|
3669
|
+
emit({
|
|
3670
|
+
type: "action.auth_resolved",
|
|
3671
|
+
data: {
|
|
3672
|
+
callId: item.callId,
|
|
3673
|
+
toolName: item.toolName,
|
|
3674
|
+
connection: item.connection,
|
|
3675
|
+
decision,
|
|
3676
|
+
},
|
|
3677
|
+
});
|
|
3678
|
+
};
|
|
3679
|
+
for (const item of pending) {
|
|
3680
|
+
if (click?.decision === "deny" && click.connection === item.connection) {
|
|
3681
|
+
await resolve(item, "deny");
|
|
3682
|
+
continue;
|
|
3683
|
+
}
|
|
3684
|
+
const connected = await this.individualConnectedCheck?.(item.connection, sessionId).catch(() => false);
|
|
3685
|
+
if (connected === true) {
|
|
3686
|
+
await resolve(item, "approve");
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
return undefined;
|
|
3236
3690
|
}
|
|
3237
3691
|
async listPendingAuths(sessionId) {
|
|
3238
3692
|
const record = await this.sessions.get(sessionId);
|
|
@@ -3260,6 +3714,24 @@ export class SessionEngine {
|
|
|
3260
3714
|
throw new AuthNotFoundError(sessionId, callId);
|
|
3261
3715
|
}
|
|
3262
3716
|
const resolvedBy = approvalResolverLabel(auth);
|
|
3717
|
+
if (pending.awaitsNextTurn === true) {
|
|
3718
|
+
// No turn waits on it. Connected leaves it for the next turn to confirm.
|
|
3719
|
+
if (decision === "deny") {
|
|
3720
|
+
await this.removePendingAuth(sessionId, callId);
|
|
3721
|
+
await this.appendEvent(sessionId, {
|
|
3722
|
+
type: "action.auth_resolved",
|
|
3723
|
+
turnId: pending.turnId,
|
|
3724
|
+
data: {
|
|
3725
|
+
callId,
|
|
3726
|
+
toolName: pending.toolName,
|
|
3727
|
+
connection: pending.connection,
|
|
3728
|
+
decision,
|
|
3729
|
+
by: resolvedBy,
|
|
3730
|
+
},
|
|
3731
|
+
});
|
|
3732
|
+
}
|
|
3733
|
+
return pending;
|
|
3734
|
+
}
|
|
3263
3735
|
if (decision === "deny") {
|
|
3264
3736
|
await this.oauthHub.abortCall(sessionId, callId);
|
|
3265
3737
|
}
|
|
@@ -3851,14 +4323,11 @@ export class SessionEngine {
|
|
|
3851
4323
|
}
|
|
3852
4324
|
async dispatchEventHandlers(sessionId, event, context, record) {
|
|
3853
4325
|
const channelState = context === undefined ? (record.channelState ?? null) : context.channelState;
|
|
3854
|
-
const sessionCtx = {
|
|
4326
|
+
const sessionCtx = this.sessionContext({
|
|
4327
|
+
sessionId: record.sessionId,
|
|
3855
4328
|
session: context?.session ?? this.sessionInfo(record),
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
sessionId: record.sessionId,
|
|
3859
|
-
turnId: event.turnId,
|
|
3860
|
-
}),
|
|
3861
|
-
};
|
|
4329
|
+
turnId: event.turnId,
|
|
4330
|
+
});
|
|
3862
4331
|
const channelEvents = this.channelEventHandlersFor(record.channelId);
|
|
3863
4332
|
if (channelEvents !== undefined) {
|
|
3864
4333
|
const handlers = [
|
|
@@ -4382,6 +4851,14 @@ export class SessionEngine {
|
|
|
4382
4851
|
takeContinuationRelease(continuationKey) {
|
|
4383
4852
|
return this.releasedContinuations.delete(continuationKey);
|
|
4384
4853
|
}
|
|
4854
|
+
/** The running turn's context. A follow-up that joins the turn reads this one. */
|
|
4855
|
+
turnContextFor(sessionId) {
|
|
4856
|
+
return this.turnContexts.get(sessionId)?.context;
|
|
4857
|
+
}
|
|
4858
|
+
/** The mailbox key the running turn's user was signed under; see {@link EngineSendOptions.turnSessionKey}. */
|
|
4859
|
+
turnSessionKeyFor(sessionId) {
|
|
4860
|
+
return this.turnContexts.get(sessionId)?.sessionKey;
|
|
4861
|
+
}
|
|
4385
4862
|
isTurnRunning(sessionId) {
|
|
4386
4863
|
// Include the admit window (pendingTurns) and coalesce drain so busy
|
|
4387
4864
|
// policies do not treat a turn that has finished executeTurn but not yet
|
|
@@ -4699,6 +5176,25 @@ export class SessionEngine {
|
|
|
4699
5176
|
}
|
|
4700
5177
|
}
|
|
4701
5178
|
const DEPLOYED_AGENTS_DASHBOARD_URL = "https://cursor.com/dashboard/deployed-agents";
|
|
5179
|
+
/** What the model reads after an individual connection's sign-in link went to the asker alone. */
|
|
5180
|
+
export function privateSignInMessage(args) {
|
|
5181
|
+
const { connection } = args;
|
|
5182
|
+
const link = args.sentToSlack
|
|
5183
|
+
? " They were sent a private link to connect it. Do not post a link."
|
|
5184
|
+
: ` Give them this link to connect it: ${args.authUrl}`;
|
|
5185
|
+
return `${connection} uses each person's own account, and the person who asked has not connected theirs.${link} Do not wait for them: answer without ${connection}, and tell them to ask again after they connect.`;
|
|
5186
|
+
}
|
|
5187
|
+
const MCP_AUTH_TOOL_NAME = "mcp_auth";
|
|
5188
|
+
/** Told to the model when an individual connection's sign-in card is shown. */
|
|
5189
|
+
export function connectThenContinueMessage(connection, authUrl, sentToSlack) {
|
|
5190
|
+
const where = sentToSlack
|
|
5191
|
+
? "They were sent a private Connect card. Do not post a link."
|
|
5192
|
+
: `They see a Connect card. If they cannot, give them this link: ${authUrl}`;
|
|
5193
|
+
return `${connection} uses each person's own account, and the person who asked has not connected theirs. ${where} Tell them to connect, then click Connected, and stop: their request continues on their next turn. Do not call ${MCP_AUTH_TOOL_NAME} again for ${connection} in this turn.`;
|
|
5194
|
+
}
|
|
5195
|
+
function individualNoUserMessage(connection) {
|
|
5196
|
+
return `${connection} uses each person's own account, and the person who asked has no linked Cursor account. Do not post a link: answer without ${connection}.`;
|
|
5197
|
+
}
|
|
4702
5198
|
function mcpAuthReconnectMessage(connection) {
|
|
4703
5199
|
if (isCursorAccountTransport(connection.transport)) {
|
|
4704
5200
|
return `Reconnect ${connection.name}: the MCP connection needs authorization. Ask the bot owner to reconnect ${connection.name} at ${DEPLOYED_AGENTS_DASHBOARD_URL}`;
|
|
@@ -4778,6 +5274,21 @@ export function withTurnCountClampedToEvents(record, events) {
|
|
|
4778
5274
|
}
|
|
4779
5275
|
return maxTurn > record.turnCount ? { ...record, turnCount: maxTurn } : record;
|
|
4780
5276
|
}
|
|
5277
|
+
/**
|
|
5278
|
+
* The cloud run this hosted delivery already started on the session's bound
|
|
5279
|
+
* agent, when an earlier host recorded one. Another delivery never matches,
|
|
5280
|
+
* so its message is still sent.
|
|
5281
|
+
*/
|
|
5282
|
+
function reattachableCloudRunId(record, platformDeliveryId) {
|
|
5283
|
+
const recorded = record.hostedCloudRun;
|
|
5284
|
+
if (platformDeliveryId === undefined ||
|
|
5285
|
+
recorded === undefined ||
|
|
5286
|
+
recorded.platformDeliveryId !== platformDeliveryId ||
|
|
5287
|
+
recorded.sdkAgentId !== record.sdkAgentId) {
|
|
5288
|
+
return undefined;
|
|
5289
|
+
}
|
|
5290
|
+
return recorded.runId;
|
|
5291
|
+
}
|
|
4781
5292
|
function subagentPrompt(subagent) {
|
|
4782
5293
|
if (subagent.instructions !== undefined && subagent.instructions !== "") {
|
|
4783
5294
|
return subagent.instructions;
|
|
@@ -4862,6 +5373,9 @@ function approvalResolverLabel(auth) {
|
|
|
4862
5373
|
if (auth === null) {
|
|
4863
5374
|
return undefined;
|
|
4864
5375
|
}
|
|
5376
|
+
if (auth.label !== undefined && auth.label !== "") {
|
|
5377
|
+
return auth.label;
|
|
5378
|
+
}
|
|
4865
5379
|
const slackUser = auth.attributes?.user_id;
|
|
4866
5380
|
if (auth.authenticator === "slack" && slackUser !== undefined && slackUser !== "") {
|
|
4867
5381
|
return slackUser;
|