@grok/agent-sdk 0.6.0 → 0.7.1
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/cursor-account.d.ts +1 -0
- package/dist/channels/github/cursor-account.d.ts.map +1 -1
- package/dist/channels/github/cursor-account.js +8 -2
- 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/origin/cursor-account.d.ts +6 -0
- package/dist/channels/origin/cursor-account.d.ts.map +1 -1
- package/dist/channels/origin/cursor-account.js +17 -0
- 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/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.lt-BYgI2.js → app.CpLKJnOA.js} +4 -4
- package/dist/docs/assets/changelog.md.DoOgjnPC.js +1 -0
- package/dist/docs/assets/{changelog.md.DVNB-ApU.lean.js → changelog.md.DoOgjnPC.lean.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.BJ_1eI6D.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.v_dV4U2Q.js → VPLocalSearchBox.Cr1HJ_9k.js} +2 -2
- package/dist/docs/assets/chunks/{arc.5o92kOg5.js → arc.BjpgGAMM.js} +1 -1
- package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.C-oTwnNq.js → architectureDiagram-Q4EWVU46.CKdhNPPk.js} +1 -1
- package/dist/docs/assets/chunks/{baseUniq.zJ-VNOib.js → baseUniq.iovoEQbg.js} +1 -1
- package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.B9ZJZuPd.js → blockDiagram-DXYQGD6D.BYQIeDre.js} +1 -1
- package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.BBMwSIaN.js → c4Diagram-AHTNJAMY.gbWi2q8N.js} +1 -1
- package/dist/docs/assets/chunks/channel.BP0n324b.js +1 -0
- package/dist/docs/assets/chunks/{chunk-4BX2VUAB.D8qAJpDD.js → chunk-4BX2VUAB.1Mem4UG9.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-4TB4RGXK.B8QR5cdE.js → chunk-4TB4RGXK.Dn3H-X_H.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-55IACEB6.BsWxVuew.js → chunk-55IACEB6.BkpSDZwX.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-EDXVE4YY.BeGygY_i.js → chunk-EDXVE4YY.BScqy1zP.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-FMBD7UC4.DdwgH-ZH.js → chunk-FMBD7UC4.Cp394LWf.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-OYMX7WX6.B9zC_ALe.js → chunk-OYMX7WX6.BDv9LhoL.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-QZHKN3VN.BIxJ0rcL.js → chunk-QZHKN3VN.CsgCcrKO.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-YZCP3GAM.qiM_23_f.js → chunk-YZCP3GAM.BKBpIC5O.js} +1 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.BhTtyWMA.js +1 -0
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.BhTtyWMA.js +1 -0
- package/dist/docs/assets/chunks/clone.BVK2rFqj.js +1 -0
- package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.BKB971D5.js → cose-bilkent-S5V4N54A.Bs3ZS9PC.js} +1 -1
- package/dist/docs/assets/chunks/{dagre-KV5264BT.CcILjJgp.js → dagre-KV5264BT.CgWi0tY2.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-5BDNPKRD.DkY9A0nu.js → diagram-5BDNPKRD.rn6qIo9N.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.BbdzmjMt.js → diagram-G4DWMVQ6.ChhW8oww.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-MMDJMWI5.Be0zy1cM.js → diagram-MMDJMWI5.C0wH5KSk.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-TYMM5635.zOiEycLe.js → diagram-TYMM5635.CNEcrwA0.js} +1 -1
- package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DUd_9HMF.js → erDiagram-SMLLAGMA.DCsnKO-7.js} +1 -1
- package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.2KPYoZBO.js → flowDiagram-DWJPFMVM.WCMkfvP0.js} +1 -1
- package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.DqE8_YpP.js → ganttDiagram-T4ZO3ILL.BUb1Sxfr.js} +1 -1
- package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.CO0Tk47h.js → gitGraphDiagram-UUTBAWPF._kORbCzm.js} +1 -1
- package/dist/docs/assets/chunks/{graph.CNe5KbNy.js → graph.PrGRm4KW.js} +1 -1
- package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.BBhJ1X1B.js → infoDiagram-42DDH7IO.BxhCjiQM.js} +1 -1
- package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.KSIw9w3I.js → ishikawaDiagram-UXIWVN3A.5ddTis2y.js} +1 -1
- package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.BN2Y5oUJ.js → journeyDiagram-VCZTEJTY.BUStU27-.js} +1 -1
- package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.2KFuDYn_.js → kanban-definition-6JOO6SKY.CJd1psl3.js} +1 -1
- package/dist/docs/assets/chunks/{layout.Demb_pzL.js → layout.DqvbZSML.js} +1 -1
- package/dist/docs/assets/chunks/{linear.kYKxzbbR.js → linear.DOmz-1UB.js} +1 -1
- package/dist/docs/assets/chunks/{min.DwmCN5dF.js → min.33k2v8dM.js} +1 -1
- package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.CGlz01QG.js → mindmap-definition-QFDTVHPH.iISCqCXC.js} +1 -1
- package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.n3qsq4nA.js → pieDiagram-DEJITSTG.BHvVgzmD.js} +1 -1
- package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CGNJ1GSb.js → quadrantDiagram-34T5L4WZ.CY3w_-Cn.js} +1 -1
- package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.VhAzHDwQ.js → requirementDiagram-MS252O5E.CHXKQS1v.js} +1 -1
- package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.DmHA5pW-.js → sankeyDiagram-XADWPNL6.DTtRoGss.js} +1 -1
- package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23._TC1aKhg.js → sequenceDiagram-FGHM5R23.NnPcQ3eY.js} +1 -1
- package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.B-kLjV3O.js → stateDiagram-FHFEXIEX.D8DFciH7.js} +1 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.ESAwmMws.js +1 -0
- package/dist/docs/assets/chunks/{theme.BaVlHHL-.js → theme.CwkiT-Fo.js} +2 -2
- package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.CresbphV.js → timeline-definition-GMOUNBTQ._wIWkMU6.js} +1 -1
- package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.CegHD8Y4.js → vennDiagram-DHZGUBPP.NLVv7R6r.js} +1 -1
- package/dist/docs/assets/chunks/{wardley-RL74JXVD.DjCmZrUO.js → wardley-RL74JXVD.DbsCXUZp.js} +1 -1
- package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BJ7s1zdZ.js → wardleyDiagram-NUSXRM2D.Dp5uAVDl.js} +1 -1
- package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.IrEXlemI.js → xychartDiagram-5P7HB3ND.eOEBq4rX.js} +1 -1
- package/dist/docs/assets/{deployment.md.DJtuDVLh.js → deployment.md.CIRydNl3.js} +3 -3
- package/dist/docs/assets/{deployment.md.DJtuDVLh.lean.js → deployment.md.CIRydNl3.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/guides_workload-identity.md.DBV6YkXX.js +82 -0
- package/dist/docs/assets/guides_workload-identity.md.DBV6YkXX.lean.js +1 -0
- package/dist/docs/assets/{reference_agent-config.md.Bbqf0lgS.js → reference_agent-config.md.CfM1S6Ac.js} +2 -2
- package/dist/docs/assets/{reference_agent-config.md.Bbqf0lgS.lean.js → reference_agent-config.md.CfM1S6Ac.lean.js} +1 -1
- 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 +43 -0
- package/dist/docs/deployment.html +40 -40
- package/dist/docs/deployment.md +14 -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/guides/workload-identity.html +141 -0
- package/dist/docs/guides/workload-identity.md +227 -0
- 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 +881 -5
- package/dist/docs/llms.txt +2 -0
- package/dist/docs/quickstart.html +37 -37
- package/dist/docs/reference/access.html +36 -36
- package/dist/docs/reference/agent-config.html +39 -39
- package/dist/docs/reference/agent-config.md +1 -1
- 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-ax.d.ts.map +1 -1
- package/dist/internal/cli-ax.js +6 -3
- 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 +19 -1
- 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 +8 -1
- package/dist/internal/cursor-account-mcp-auth.d.ts.map +1 -1
- package/dist/internal/cursor-account-mcp-auth.js +22 -6
- 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/agent.d.ts.map +1 -1
- package/dist/internal/discovery/agent.js +2 -1
- package/dist/internal/discovery/connections.d.ts +5 -0
- package/dist/internal/discovery/connections.d.ts.map +1 -1
- package/dist/internal/discovery/connections.js +71 -1
- 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 +26 -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 +4 -0
- package/dist/internal/hosted-delivery-protocol.d.ts.map +1 -1
- package/dist/internal/hosted-delivery-protocol.js +73 -3
- package/dist/internal/hosted-delivery.d.ts +9 -3
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +14 -3
- 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/ids.d.ts +2 -0
- package/dist/internal/ids.d.ts.map +1 -1
- package/dist/internal/ids.js +5 -0
- 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/schedule-runner.d.ts +1 -0
- package/dist/internal/schedule-runner.d.ts.map +1 -1
- package/dist/internal/schedule-runner.js +10 -1
- package/dist/internal/sdk-runner.d.ts +28 -2
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +298 -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 +140 -6
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +583 -93
- 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/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 +131 -0
- package/dist/oidc-token.d.ts.map +1 -0
- package/dist/oidc-token.js +221 -0
- package/dist/playground/assets/chunk-YOKDWASO-BPO_8GRX.js +115 -0
- package/dist/playground/assets/highlighted-body-KPVGNVTW-CxEV-T_f.js +1 -0
- package/dist/playground/assets/index-CjFJhCtb.js +62 -0
- package/dist/playground/assets/index-vwUVwmk8.css +1 -0
- package/dist/playground/assets/mermaid-HWGCJPDP-eK-fpbFn.js +1 -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 +271 -2
- package/dist/types.d.ts.map +1 -1
- package/docs/changelog.md +43 -0
- package/docs/deployment.md +14 -0
- package/docs/guides/cloud-agents.md +47 -0
- package/docs/guides/teams.md +389 -0
- package/docs/guides/workload-identity.md +232 -0
- package/docs/reference/agent-config.md +1 -1
- 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 +23 -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.DVNB-ApU.js +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DdlR-9Oe.js +0 -1
- package/dist/docs/assets/chunks/channel.CdyTxaXV.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.CeUcN6TW.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.CeUcN6TW.js +0 -1
- package/dist/docs/assets/chunks/clone.DpIwUbur.js +0 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.HtBkUH4J.js +0 -1
- 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-CnFd5R1_.js +0 -62
- package/dist/playground/assets/index-DNzRv6G8.css +0 -1
- /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";
|
|
@@ -177,7 +179,58 @@ export class AuthInterruptedError extends Error {
|
|
|
177
179
|
}
|
|
178
180
|
/** How long an interactive turn waits for a person to authorize a connection. */
|
|
179
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
|
+
}
|
|
180
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
|
+
}
|
|
181
234
|
const RELEASED_CONTINUATIONS_CAP = 256;
|
|
182
235
|
/** Marker that we `git init`'d this shared harness so scaffold is ours to write. */
|
|
183
236
|
const OWNED_HARNESS = join(".agent-serve", "owned-harness");
|
|
@@ -282,10 +335,16 @@ export class SessionEngine {
|
|
|
282
335
|
/** Live turn snapshot so a coalesced Slack wake can repaint on this process. */
|
|
283
336
|
this.liveTurns = new Map();
|
|
284
337
|
/**
|
|
285
|
-
* Per-session coalesce
|
|
286
|
-
*
|
|
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.
|
|
287
341
|
*/
|
|
288
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();
|
|
289
348
|
/**
|
|
290
349
|
* Sessions whose turn lifecycle is draining coalesced follow-ups. Counts as
|
|
291
350
|
* busy so inbound coalesce admits enqueue instead of racing `clearCoalesced`.
|
|
@@ -300,6 +359,8 @@ export class SessionEngine {
|
|
|
300
359
|
this.oauthHub = new McpOauthOnDemandHub();
|
|
301
360
|
/** Serve-time resolved connections (see {@link setResolvedConnections}). */
|
|
302
361
|
this.resolvedConnections = [];
|
|
362
|
+
/** Prove which session a tool MCP endpoint request comes from. */
|
|
363
|
+
this.toolSessionCredentials = new SessionCredentials();
|
|
303
364
|
/** Sessions whose completed turns all carry usage (no further backfill). */
|
|
304
365
|
this.cloudUsageBackfillDone = new Set();
|
|
305
366
|
/** Deduped in-flight cloud usage backfills, keyed by session id. */
|
|
@@ -397,7 +458,7 @@ export class SessionEngine {
|
|
|
397
458
|
this.mcpHost = new McpHost([
|
|
398
459
|
...options.project.agent.connections,
|
|
399
460
|
...(options.project.agent.hostConnections ?? []),
|
|
400
|
-
].filter((connection) => !isSymbolicConnectionTransport(connection.transport)));
|
|
461
|
+
].filter((connection) => !isSymbolicConnectionTransport(connection.transport)), { log: this.logger });
|
|
401
462
|
const basePlatforms = options.platforms ?? createHostPlatforms();
|
|
402
463
|
const slackBinding = resolveDedicatedSlackHostBinding(options.project.channels);
|
|
403
464
|
this.platforms =
|
|
@@ -494,6 +555,10 @@ export class SessionEngine {
|
|
|
494
555
|
setCursorAccountAuthProbe(probe) {
|
|
495
556
|
this.probeCursorAccount = probe;
|
|
496
557
|
}
|
|
558
|
+
/** Whether the session's turn user has connected an individual connection. */
|
|
559
|
+
setIndividualConnectedCheck(check) {
|
|
560
|
+
this.individualConnectedCheck = check;
|
|
561
|
+
}
|
|
497
562
|
get oauthCallbackHub() {
|
|
498
563
|
return this.oauthHub;
|
|
499
564
|
}
|
|
@@ -683,7 +748,10 @@ export class SessionEngine {
|
|
|
683
748
|
}
|
|
684
749
|
slackNudgeHostApi() {
|
|
685
750
|
return {
|
|
686
|
-
append: (input) => this.
|
|
751
|
+
append: async (input) => (await this.runsTurnFor(input.continuationKey)) &&
|
|
752
|
+
!this.queuedForAnotherUser(input.sourceTs)
|
|
753
|
+
? this.nudgeStore.append(input)
|
|
754
|
+
: false,
|
|
687
755
|
drainFormatted: (continuationKey) => this.nudgeStore.drainFormatted(continuationKey),
|
|
688
756
|
clear: (continuationKey) => this.nudgeStore.clear(continuationKey),
|
|
689
757
|
hasUndelivered: (continuationKey) => this.nudgeStore.hasUndelivered(continuationKey),
|
|
@@ -779,19 +847,24 @@ export class SessionEngine {
|
|
|
779
847
|
// synchronize). Leave the durable continuation key unchanged.
|
|
780
848
|
let record = existing;
|
|
781
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;
|
|
782
855
|
if (!enqueueOnly) {
|
|
783
856
|
const refreshWorkspace = sendOptions.workspaceDir !== undefined &&
|
|
784
857
|
sendOptions.workspaceDir !== existing.workspaceOverride;
|
|
785
858
|
if (refreshWorkspace ||
|
|
786
859
|
sendOptions.workspaceFiles !== undefined ||
|
|
787
|
-
|
|
860
|
+
recordImages !== undefined) {
|
|
788
861
|
record = await this.updateRecord(existing.sessionId, (current) => ({
|
|
789
862
|
...current,
|
|
790
863
|
workspaceOverride: refreshWorkspace
|
|
791
864
|
? sendOptions.workspaceDir
|
|
792
865
|
: current.workspaceOverride,
|
|
793
866
|
pendingWorkspaceFiles: mergePendingWorkspaceFiles(current.pendingWorkspaceFiles, sendOptions.workspaceFiles),
|
|
794
|
-
pendingImages: mergePendingImages(current.pendingImages,
|
|
867
|
+
pendingImages: mergePendingImages(current.pendingImages, recordImages),
|
|
795
868
|
}));
|
|
796
869
|
}
|
|
797
870
|
// A caller can explicitly return a continuation to the agent's
|
|
@@ -822,12 +895,16 @@ export class SessionEngine {
|
|
|
822
895
|
const since = (await this.logs.get(record.sessionId)).count;
|
|
823
896
|
const coalesced = await this.startTurn(record.sessionId, message, {
|
|
824
897
|
turnMode: sendOptions.turnMode ?? "non-interactive",
|
|
825
|
-
admission
|
|
898
|
+
admission,
|
|
826
899
|
...(sendOptions.coalesceSourceTs === undefined
|
|
827
900
|
? {}
|
|
828
901
|
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
829
902
|
...(enqueueOnly ? { hostedEnqueueOnly: true } : {}),
|
|
830
903
|
deliveryIds: [deliveryId],
|
|
904
|
+
platformDeliveryId: sendOptions.platformDeliveryId,
|
|
905
|
+
images: admitImages,
|
|
906
|
+
turnContext: sendOptions.turnContext,
|
|
907
|
+
turnSessionKey: sendOptions.turnSessionKey,
|
|
831
908
|
});
|
|
832
909
|
if (enqueueOnly && !coalesced) {
|
|
833
910
|
throw new HostedEnqueueNotActiveError(record.sessionId);
|
|
@@ -891,6 +968,9 @@ export class SessionEngine {
|
|
|
891
968
|
? {}
|
|
892
969
|
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
893
970
|
deliveryIds: [deliveryId],
|
|
971
|
+
turnContext: sendOptions.turnContext,
|
|
972
|
+
turnSessionKey: sendOptions.turnSessionKey,
|
|
973
|
+
platformDeliveryId: sendOptions.platformDeliveryId,
|
|
894
974
|
});
|
|
895
975
|
return this.channelSession(record.sessionId, record, deliveryId, true, false, since);
|
|
896
976
|
}
|
|
@@ -957,7 +1037,7 @@ export class SessionEngine {
|
|
|
957
1037
|
return this.channelSession(sessionId, record, undefined, false);
|
|
958
1038
|
}
|
|
959
1039
|
/** Cross-channel hand-off (schedules and channel route handlers). */
|
|
960
|
-
async receive(channel, input) {
|
|
1040
|
+
async receive(channel, input, options = {}) {
|
|
961
1041
|
const channelId = this.resolveChannelId(channel);
|
|
962
1042
|
const definition = this.channelsById.get(channelId);
|
|
963
1043
|
if (definition?.receive !== undefined) {
|
|
@@ -979,6 +1059,7 @@ export class SessionEngine {
|
|
|
979
1059
|
}
|
|
980
1060
|
return this.send(channelId, input.message, {
|
|
981
1061
|
auth: input.auth,
|
|
1062
|
+
hostedSessionId: options.hostedSessionId,
|
|
982
1063
|
});
|
|
983
1064
|
}
|
|
984
1065
|
/** Fire-and-forget task session (schedules' markdown form). */
|
|
@@ -986,6 +1067,7 @@ export class SessionEngine {
|
|
|
986
1067
|
const session = await this.send(args.channelId, args.prompt, {
|
|
987
1068
|
auth: args.auth,
|
|
988
1069
|
mode: "task",
|
|
1070
|
+
hostedSessionId: args.hostedSessionId,
|
|
989
1071
|
...(args.title === undefined ? {} : { title: args.title }),
|
|
990
1072
|
});
|
|
991
1073
|
return { sessionId: session.id, done: this.waitForCompletion(session.id) };
|
|
@@ -1022,11 +1104,16 @@ export class SessionEngine {
|
|
|
1022
1104
|
state: repaintState,
|
|
1023
1105
|
continuationToken: record.continuationKey,
|
|
1024
1106
|
setContinuationToken: (token) => this.setContinuationToken(sessionId, token),
|
|
1025
|
-
}, {
|
|
1026
|
-
|
|
1107
|
+
}, this.sessionContext({ sessionId, session: live.session, turnId: live.turnId }));
|
|
1108
|
+
}
|
|
1109
|
+
/** The context every channel `events` handler and hook gets for one event. */
|
|
1110
|
+
sessionContext({ sessionId, session, turnId, }) {
|
|
1111
|
+
return {
|
|
1112
|
+
session,
|
|
1027
1113
|
host: this.hostForSession(sessionId),
|
|
1028
|
-
artifacts: this.artifactsApi({ sessionId }),
|
|
1029
|
-
|
|
1114
|
+
artifacts: this.artifactsApi({ sessionId, turnId }),
|
|
1115
|
+
steer: (message, steerOptions) => this.steerRunningTurn(sessionId, turnId, message, steerOptions),
|
|
1116
|
+
};
|
|
1030
1117
|
}
|
|
1031
1118
|
/**
|
|
1032
1119
|
* Admit a turn for `sessionId`.
|
|
@@ -1051,7 +1138,10 @@ export class SessionEngine {
|
|
|
1051
1138
|
if (options.hostedEnqueueOnly === true) {
|
|
1052
1139
|
throw new HostedEnqueueNotActiveError(sessionId);
|
|
1053
1140
|
}
|
|
1054
|
-
await this.outbox.post(sessionId, {
|
|
1141
|
+
await this.outbox.post(sessionId, {
|
|
1142
|
+
message,
|
|
1143
|
+
options: { ...options, admission: "coalesce" },
|
|
1144
|
+
});
|
|
1055
1145
|
return true;
|
|
1056
1146
|
}
|
|
1057
1147
|
return this.admitTurn(sessionId, message, options);
|
|
@@ -1059,6 +1149,19 @@ export class SessionEngine {
|
|
|
1059
1149
|
this.admissionChains.set(sessionId, admitted.catch(() => { }));
|
|
1060
1150
|
return admitted;
|
|
1061
1151
|
}
|
|
1152
|
+
/**
|
|
1153
|
+
* A nudge reaches only a turn running in this process: the carrier runs
|
|
1154
|
+
* inside it. Another server's turn may belong to another user, which this
|
|
1155
|
+
* server cannot see, so its follow-ups arrive through the outbox instead.
|
|
1156
|
+
*/
|
|
1157
|
+
async runsTurnFor(continuationKey) {
|
|
1158
|
+
for (const sessionId of this.turnAborts.keys()) {
|
|
1159
|
+
if ((await this.sessions.get(sessionId))?.continuationKey === continuationKey) {
|
|
1160
|
+
return true;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return false;
|
|
1164
|
+
}
|
|
1062
1165
|
/** Admit what other servers handed to this turn's holder. Never awaited by the lifecycle. */
|
|
1063
1166
|
drainOutbox(sessionId) {
|
|
1064
1167
|
void this.outbox
|
|
@@ -1071,7 +1174,9 @@ export class SessionEngine {
|
|
|
1071
1174
|
.catch(() => { });
|
|
1072
1175
|
}
|
|
1073
1176
|
enqueueCoalesced(sessionId, item) {
|
|
1074
|
-
const
|
|
1177
|
+
const queues = this.coalesceQueues.get(sessionId) ?? new Map();
|
|
1178
|
+
const key = userKey(item.turnContext);
|
|
1179
|
+
const queue = queues.get(key) ?? [];
|
|
1075
1180
|
const duplicate = item.sourceTs === undefined
|
|
1076
1181
|
? undefined
|
|
1077
1182
|
: queue.find((entry) => entry.sourceTs === item.sourceTs);
|
|
@@ -1084,10 +1189,49 @@ export class SessionEngine {
|
|
|
1084
1189
|
if (item.turnMode === "interactive") {
|
|
1085
1190
|
duplicate.turnMode = "interactive";
|
|
1086
1191
|
}
|
|
1192
|
+
if (duplicate.images === undefined || duplicate.images.length === 0) {
|
|
1193
|
+
duplicate.images = item.images;
|
|
1194
|
+
}
|
|
1087
1195
|
return;
|
|
1088
1196
|
}
|
|
1089
1197
|
queue.push(item);
|
|
1090
|
-
|
|
1198
|
+
queues.set(key, queue);
|
|
1199
|
+
this.coalesceQueues.set(sessionId, queues);
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Take the next key's queue: the key of the turn that just finished first,
|
|
1203
|
+
* so its follow-ups the nudge carrier holds settle before another user's
|
|
1204
|
+
* turn runs, then the others in arrival order.
|
|
1205
|
+
*/
|
|
1206
|
+
takeCoalescedQueue(sessionId) {
|
|
1207
|
+
const queues = this.coalesceQueues.get(sessionId);
|
|
1208
|
+
if (queues === undefined) {
|
|
1209
|
+
return undefined;
|
|
1210
|
+
}
|
|
1211
|
+
const finishedKey = userKey(this.turnContextFor(sessionId));
|
|
1212
|
+
const key = queues.has(finishedKey) ? finishedKey : queues.keys().next().value;
|
|
1213
|
+
if (key === undefined) {
|
|
1214
|
+
this.coalesceQueues.delete(sessionId);
|
|
1215
|
+
return undefined;
|
|
1216
|
+
}
|
|
1217
|
+
const queue = queues.get(key);
|
|
1218
|
+
queues.delete(key);
|
|
1219
|
+
if (queues.size === 0) {
|
|
1220
|
+
this.coalesceQueues.delete(sessionId);
|
|
1221
|
+
}
|
|
1222
|
+
return queue;
|
|
1223
|
+
}
|
|
1224
|
+
/** Whether a Slack follow-up waits in another user's queue, so no turn may carry it. */
|
|
1225
|
+
queuedForAnotherUser(sourceTs) {
|
|
1226
|
+
for (const [sessionId, queues] of this.coalesceQueues) {
|
|
1227
|
+
const runningKey = userKey(this.turnContextFor(sessionId));
|
|
1228
|
+
for (const [key, queue] of queues) {
|
|
1229
|
+
if (key !== runningKey && queue.some((item) => item.sourceTs === sourceTs)) {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return false;
|
|
1091
1235
|
}
|
|
1092
1236
|
clearCoalesced(sessionId) {
|
|
1093
1237
|
this.coalesceQueues.delete(sessionId);
|
|
@@ -1157,15 +1301,16 @@ export class SessionEngine {
|
|
|
1157
1301
|
return parts.join("\n").trimEnd();
|
|
1158
1302
|
}
|
|
1159
1303
|
async drainCoalescedFollowups(sessionId) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1304
|
+
let pending = [];
|
|
1305
|
+
while (pending.length === 0) {
|
|
1306
|
+
const queued = this.takeCoalescedQueue(sessionId);
|
|
1307
|
+
if (queued === undefined) {
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
pending = await this.withoutNudgedFollowups(sessionId, queued);
|
|
1311
|
+
if (pending.length === 0) {
|
|
1312
|
+
this.logger(`[session] coalesce drain skipped; all follow-ups already nudged ${sessionId}`);
|
|
1313
|
+
}
|
|
1169
1314
|
}
|
|
1170
1315
|
// These become the next turn's prompt, so settle them in the nudge store
|
|
1171
1316
|
// first: a surviving pending record would be injected by that turn's own
|
|
@@ -1173,6 +1318,7 @@ export class SessionEngine {
|
|
|
1173
1318
|
await this.settleDrainedFollowups(sessionId, pending);
|
|
1174
1319
|
const message = this.formatCoalescedFollowups(pending);
|
|
1175
1320
|
this.logger(`[session] coalesce drain starting follow-up (${pending.length}) ${sessionId}`);
|
|
1321
|
+
const images = pending.flatMap((item) => item.images ?? []);
|
|
1176
1322
|
await this.startTurn(sessionId, message, {
|
|
1177
1323
|
turnMode: pending.some((item) => item.turnMode === "interactive")
|
|
1178
1324
|
? "interactive"
|
|
@@ -1180,8 +1326,33 @@ export class SessionEngine {
|
|
|
1180
1326
|
admission: "preempt",
|
|
1181
1327
|
retainCoalesced: true,
|
|
1182
1328
|
deliveryIds: pending.flatMap((item) => item.deliveryIds),
|
|
1329
|
+
images: images.length > 0 ? images : undefined,
|
|
1330
|
+
turnContext: pending.at(-1)?.turnContext,
|
|
1331
|
+
turnSessionKey: pending.at(-1)?.turnSessionKey,
|
|
1183
1332
|
});
|
|
1184
1333
|
}
|
|
1334
|
+
/**
|
|
1335
|
+
* The public {@link SteerTurn}: steer into the session's running turn, or
|
|
1336
|
+
* report why not. Never admits, enqueues, or creates anything. `turnId`
|
|
1337
|
+
* pins the turn the caller belongs to.
|
|
1338
|
+
*/
|
|
1339
|
+
async steerRunningTurn(sessionId, turnId, message, options = {}) {
|
|
1340
|
+
const deliveryId = resolveDeliveryId(options.deliveryId);
|
|
1341
|
+
const active = this.activeToolContexts.get(sessionId);
|
|
1342
|
+
if (active === undefined || (turnId !== undefined && active.turnId !== turnId)) {
|
|
1343
|
+
return { status: "no_turn" };
|
|
1344
|
+
}
|
|
1345
|
+
if (this.runner.steer === undefined) {
|
|
1346
|
+
return { status: "not_delivered", reason: "unsupported" };
|
|
1347
|
+
}
|
|
1348
|
+
if ((await this.steerIntoRunningTurn(sessionId, message)) !== "complete_delivered") {
|
|
1349
|
+
return { status: "not_delivered", reason: "refused" };
|
|
1350
|
+
}
|
|
1351
|
+
this.logger(`[session] steered own turn ${sessionId}`);
|
|
1352
|
+
active.emit({ type: "message.received", data: { text: message, deliveryIds: [deliveryId] } });
|
|
1353
|
+
active.emit({ type: "nudge.delivered", data: { deliveryId } });
|
|
1354
|
+
return { status: "steered", turnId: active.turnId, deliveryId };
|
|
1355
|
+
}
|
|
1185
1356
|
async steerIntoRunningTurn(sessionId, message) {
|
|
1186
1357
|
if (this.runner.steer === undefined) {
|
|
1187
1358
|
return "revert_to_followup";
|
|
@@ -1196,7 +1367,12 @@ export class SessionEngine {
|
|
|
1196
1367
|
}
|
|
1197
1368
|
async admitTurn(sessionId, message, options) {
|
|
1198
1369
|
const admission = options.admission ?? "preempt";
|
|
1199
|
-
|
|
1370
|
+
const images = options.images !== undefined && options.images.length > 0 ? options.images : undefined;
|
|
1371
|
+
if (admission === "coalesce" &&
|
|
1372
|
+
images === undefined &&
|
|
1373
|
+
steeringEnabled() &&
|
|
1374
|
+
this.isTurnRunning(sessionId) &&
|
|
1375
|
+
userKey(options.turnContext) === userKey(this.turnContextFor(sessionId))) {
|
|
1200
1376
|
const toolCtx = this.activeToolContexts.get(sessionId);
|
|
1201
1377
|
const steerOutcome = await this.steerIntoRunningTurn(sessionId, message);
|
|
1202
1378
|
if (steerOutcome === "complete_delivered") {
|
|
@@ -1225,19 +1401,25 @@ export class SessionEngine {
|
|
|
1225
1401
|
sourceTs: options.sourceTs,
|
|
1226
1402
|
turnMode: options.turnMode,
|
|
1227
1403
|
deliveryIds: [...(options.deliveryIds ?? [])],
|
|
1404
|
+
images,
|
|
1405
|
+
turnContext: options.turnContext,
|
|
1406
|
+
turnSessionKey: options.turnSessionKey,
|
|
1228
1407
|
});
|
|
1229
1408
|
this.logger(`[session] coalesce enqueue ${sessionId}`);
|
|
1230
1409
|
return true;
|
|
1231
1410
|
}
|
|
1232
|
-
// Another server owns this session, so coalesce even a preempt
|
|
1233
|
-
//
|
|
1234
|
-
//
|
|
1235
|
-
//
|
|
1236
|
-
// Enqueue-only cannot claim coalesced here: nothing joined a local turn.
|
|
1411
|
+
// Another server owns this session, so coalesce even a preempt through
|
|
1412
|
+
// its outbox. Not redundant with `acquire` below — this returns before
|
|
1413
|
+
// preempt's `clearCoalesced` drops the queue. Enqueue-only cannot claim
|
|
1414
|
+
// coalesced here: nothing joined a local turn.
|
|
1237
1415
|
if (await this.turnLeases.runningElsewhere(sessionId)) {
|
|
1238
1416
|
if (options.hostedEnqueueOnly === true) {
|
|
1239
1417
|
throw new HostedEnqueueNotActiveError(sessionId);
|
|
1240
1418
|
}
|
|
1419
|
+
await this.outbox.post(sessionId, {
|
|
1420
|
+
message,
|
|
1421
|
+
options: { ...options, admission: "coalesce" },
|
|
1422
|
+
});
|
|
1241
1423
|
this.logger(`[session] coalesce; another server owns ${sessionId}`);
|
|
1242
1424
|
return true;
|
|
1243
1425
|
}
|
|
@@ -1276,6 +1458,7 @@ export class SessionEngine {
|
|
|
1276
1458
|
const record = await this.updateRecord(sessionId, (current) => ({
|
|
1277
1459
|
...current,
|
|
1278
1460
|
turnCount: current.turnCount + 1,
|
|
1461
|
+
pendingImages: mergePendingImages(current.pendingImages, images),
|
|
1279
1462
|
}));
|
|
1280
1463
|
const turnId = `turn_${record.turnCount}`;
|
|
1281
1464
|
const isFirstTurn = record.turnCount === 1;
|
|
@@ -1289,6 +1472,16 @@ export class SessionEngine {
|
|
|
1289
1472
|
const abort = new AbortController();
|
|
1290
1473
|
this.turnAborts.set(sessionId, abort);
|
|
1291
1474
|
this.turnModes.set(sessionId, options.turnMode);
|
|
1475
|
+
const ownContext = { context: options.turnContext, sessionKey: options.turnSessionKey };
|
|
1476
|
+
this.turnContexts.set(sessionId, ownContext);
|
|
1477
|
+
const unlinkedSlackUserId = this.unlinkedSlackSenderNeedingLink(options);
|
|
1478
|
+
if (unlinkedSlackUserId !== undefined) {
|
|
1479
|
+
await this.appendEvent(sessionId, {
|
|
1480
|
+
type: "action.account_link_requested",
|
|
1481
|
+
turnId,
|
|
1482
|
+
data: { slackUserId: unlinkedSlackUserId },
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1292
1485
|
// Lifecycle promise includes post-turn coalesce drain so waiters and
|
|
1293
1486
|
// interrupt settle after follow-ups are admitted (not only executeTurn).
|
|
1294
1487
|
// Assigned before the async body runs so self-identity checks typecheck.
|
|
@@ -1298,7 +1491,7 @@ export class SessionEngine {
|
|
|
1298
1491
|
const poll = setInterval(() => this.drainOutbox(sessionId), 1_000);
|
|
1299
1492
|
poll.unref();
|
|
1300
1493
|
try {
|
|
1301
|
-
outcome = await this.executeTurn(record, turnId, message, isFirstTurn, abort.signal);
|
|
1494
|
+
outcome = await this.executeTurn(record, turnId, message, isFirstTurn, abort.signal, options.platformDeliveryId);
|
|
1302
1495
|
if (outcome.status === "cancelled") {
|
|
1303
1496
|
outcome.cancellationReason = abort.signal.aborted ? "signal" : "runner";
|
|
1304
1497
|
}
|
|
@@ -1339,6 +1532,9 @@ export class SessionEngine {
|
|
|
1339
1532
|
}
|
|
1340
1533
|
}
|
|
1341
1534
|
}
|
|
1535
|
+
if (this.turnContexts.get(sessionId) === ownContext) {
|
|
1536
|
+
this.turnContexts.delete(sessionId);
|
|
1537
|
+
}
|
|
1342
1538
|
// The drain may have nested a successor turn, which took its own
|
|
1343
1539
|
// reference; the lease outlives this release until that one ends too.
|
|
1344
1540
|
await lease.release();
|
|
@@ -1386,7 +1582,7 @@ export class SessionEngine {
|
|
|
1386
1582
|
const hadWork = this.turnAborts.has(sessionId) ||
|
|
1387
1583
|
this.activeTurns.has(sessionId) ||
|
|
1388
1584
|
this.coalesceDrains.has(sessionId) ||
|
|
1389
|
-
(this.coalesceQueues.get(sessionId)?.
|
|
1585
|
+
(this.coalesceQueues.get(sessionId)?.size ?? 0) > 0;
|
|
1390
1586
|
this.clearCoalesced(sessionId);
|
|
1391
1587
|
await this.outbox.clear(sessionId);
|
|
1392
1588
|
const record = await this.sessions.get(sessionId);
|
|
@@ -1579,6 +1775,33 @@ export class SessionEngine {
|
|
|
1579
1775
|
this.sessionRootInflight.delete(options.sessionId);
|
|
1580
1776
|
}
|
|
1581
1777
|
}
|
|
1778
|
+
/**
|
|
1779
|
+
* The discovered skills the session's `skills` tree serves, asked on
|
|
1780
|
+
* every turn: a skill the tree stops serving drops out of the index, and
|
|
1781
|
+
* so does one whose stat throws.
|
|
1782
|
+
*/
|
|
1783
|
+
async mountedSkills(record) {
|
|
1784
|
+
const { skills: mount } = await this.resolveAuthoredFileSystem({
|
|
1785
|
+
sessionId: record.sessionId,
|
|
1786
|
+
continuationKey: record.continuationKey ?? undefined,
|
|
1787
|
+
cache: true,
|
|
1788
|
+
});
|
|
1789
|
+
const served = [];
|
|
1790
|
+
if (mount === undefined) {
|
|
1791
|
+
return served;
|
|
1792
|
+
}
|
|
1793
|
+
for (const skill of this.project.agent.skills) {
|
|
1794
|
+
try {
|
|
1795
|
+
if ((await mount.stat(`/${skill.name}/SKILL.md`)).kind === "file") {
|
|
1796
|
+
served.push(skill);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
catch (error) {
|
|
1800
|
+
this.logger(`[session] skill ${skill.name} left out of the index for ${record.sessionId}: ${describeError(error)}`);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
return served;
|
|
1804
|
+
}
|
|
1582
1805
|
baseSkillsFileSystem() {
|
|
1583
1806
|
this.baseSkills ??= skillsFileSystem(this.project.agent.skills).catch((error) => {
|
|
1584
1807
|
this.baseSkills = undefined;
|
|
@@ -1761,7 +1984,7 @@ export class SessionEngine {
|
|
|
1761
1984
|
}
|
|
1762
1985
|
return this.harnessCwd(record);
|
|
1763
1986
|
}
|
|
1764
|
-
async executeTurn(record, turnId, message, isFirstTurn, signal) {
|
|
1987
|
+
async executeTurn(record, turnId, message, isFirstTurn, signal, platformDeliveryId) {
|
|
1765
1988
|
const sessionId = record.sessionId;
|
|
1766
1989
|
const workspaceDir = this.scaffoldDir(record);
|
|
1767
1990
|
const harnessCwd = this.harnessCwd(record);
|
|
@@ -1770,6 +1993,7 @@ export class SessionEngine {
|
|
|
1770
1993
|
channelState: structuredClone(turnChannelState),
|
|
1771
1994
|
channelStateAtTurnStart: structuredClone(turnChannelState),
|
|
1772
1995
|
session: this.sessionInfo(record),
|
|
1996
|
+
turnId,
|
|
1773
1997
|
};
|
|
1774
1998
|
this.liveTurns.set(sessionId, eventContext);
|
|
1775
1999
|
// Hold the open log so tool events append synchronously. Fire-and-forget
|
|
@@ -1891,8 +2115,11 @@ export class SessionEngine {
|
|
|
1891
2115
|
await yieldEventLoop();
|
|
1892
2116
|
}
|
|
1893
2117
|
};
|
|
2118
|
+
const settled = runtime === "local" && this.hasIndividualAccountConnections()
|
|
2119
|
+
? await this.settleConnects(sessionId, message, emit)
|
|
2120
|
+
: undefined;
|
|
1894
2121
|
const endBuildRequest = this.startTurnPhase(record, turnId, "build_request");
|
|
1895
|
-
const request = await this.buildTurnRequest(record, turnId, message, isFirstTurn, emit, eventContext, onUpdate, signal, pendingImages);
|
|
2122
|
+
const request = await this.buildTurnRequest(record, turnId, message, isFirstTurn, emit, eventContext, onUpdate, signal, pendingImages, platformDeliveryId);
|
|
1896
2123
|
endBuildRequest();
|
|
1897
2124
|
// Runner start (SDK agent create/resume, MCP connect, model request)
|
|
1898
2125
|
// until the first streamed update.
|
|
@@ -1900,7 +2127,13 @@ export class SessionEngine {
|
|
|
1900
2127
|
this.activeToolContexts.set(sessionId, { record, turnId, emit });
|
|
1901
2128
|
this.stubbedCallIds.set(sessionId, stubbed);
|
|
1902
2129
|
try {
|
|
1903
|
-
|
|
2130
|
+
if (settled === undefined) {
|
|
2131
|
+
outcome = await this.runTurnExecute(record, turnId, () => this.runner.runTurn(request));
|
|
2132
|
+
}
|
|
2133
|
+
else {
|
|
2134
|
+
mapper.handleUpdate({ type: "text-delta", text: settled.skip });
|
|
2135
|
+
outcome = { status: "finished", result: settled.skip };
|
|
2136
|
+
}
|
|
1904
2137
|
}
|
|
1905
2138
|
finally {
|
|
1906
2139
|
endFirstUpdate?.();
|
|
@@ -2156,7 +2389,7 @@ export class SessionEngine {
|
|
|
2156
2389
|
fallbackAfterStream: undefined,
|
|
2157
2390
|
};
|
|
2158
2391
|
}
|
|
2159
|
-
async buildTurnRequest(record, turnId, prompt, isFirstTurn, emit, eventContext, onUpdate, signal, images) {
|
|
2392
|
+
async buildTurnRequest(record, turnId, prompt, isFirstTurn, emit, eventContext, onUpdate, signal, images, platformDeliveryId) {
|
|
2160
2393
|
const agent = this.project.agent;
|
|
2161
2394
|
const instructionsAgent = agentWithInstructionsOverride(agent, record.instructions);
|
|
2162
2395
|
// Per-session cloud attach (channel/tool handoff) forces cloud runtime
|
|
@@ -2288,10 +2521,9 @@ export class SessionEngine {
|
|
|
2288
2521
|
// bodies and indexes the skills mounted in the tree.
|
|
2289
2522
|
const localInstructions = runtime === "local"
|
|
2290
2523
|
? authoredRoot
|
|
2291
|
-
? buildAgentsMdContent(
|
|
2292
|
-
|
|
2293
|
-
skillsIndex: agent.skillsMount !== false
|
|
2294
|
-
})
|
|
2524
|
+
? buildAgentsMdContent(typeof agent.skillsMount === "function"
|
|
2525
|
+
? { ...instructionsAgent, skills: await this.mountedSkills(record) }
|
|
2526
|
+
: instructionsAgent, { includeScripts: true, skillsIndex: agent.skillsMount !== false })
|
|
2295
2527
|
: buildAgentsMdContent(instructionsAgent, {
|
|
2296
2528
|
includeScripts: this.hasBorrowedWorkspace(record),
|
|
2297
2529
|
skillsIndex: workspaceConfined && agent.skills.length > 0,
|
|
@@ -2352,6 +2584,9 @@ export class SessionEngine {
|
|
|
2352
2584
|
this.project.agent.connections.some((connection) => isCursorAccountTransport(connection.transport)))
|
|
2353
2585
|
? { perSendMcpServers: true }
|
|
2354
2586
|
: {}),
|
|
2587
|
+
onMcpAuthRequest: runtime === "local" && this.hasIndividualAccountConnections()
|
|
2588
|
+
? (request) => this.answerMcpAuth(record.sessionId, turnId, emit, request)
|
|
2589
|
+
: undefined,
|
|
2355
2590
|
subagents: buildRunnerSubagents(agent),
|
|
2356
2591
|
onUpdate,
|
|
2357
2592
|
signal,
|
|
@@ -2382,13 +2617,28 @@ export class SessionEngine {
|
|
|
2382
2617
|
},
|
|
2383
2618
|
}, eventContext);
|
|
2384
2619
|
},
|
|
2620
|
+
reattachCloudRunId: reattachableCloudRunId(record, platformDeliveryId),
|
|
2621
|
+
platformDeliveryId,
|
|
2622
|
+
onCloudRunStarted: async ({ sdkAgentId, runId }) => {
|
|
2623
|
+
if (platformDeliveryId !== undefined) {
|
|
2624
|
+
await this.updateRecord(record.sessionId, (current) => ({
|
|
2625
|
+
...current,
|
|
2626
|
+
hostedCloudRun: { platformDeliveryId, sdkAgentId, runId },
|
|
2627
|
+
}));
|
|
2628
|
+
}
|
|
2629
|
+
// The cloud run outlives this process. Storage otherwise sees the
|
|
2630
|
+
// bound agent only at turn end, so a host that replaces this one
|
|
2631
|
+
// mid-turn would start a second cloud agent.
|
|
2632
|
+
this.storage?.flushSessionExact(record.sessionId);
|
|
2633
|
+
},
|
|
2385
2634
|
};
|
|
2386
2635
|
}
|
|
2387
2636
|
/**
|
|
2388
2637
|
* Connection names a cloud turn can only reach through the host connection
|
|
2389
2638
|
* bridge on the tool MCP endpoint: filtered account connections without a
|
|
2390
2639
|
* public bridge URL, and host-OAuth connections whose tokens live on this
|
|
2391
|
-
* host.
|
|
2640
|
+
* host. Individual connections never qualify: the endpoint authenticates
|
|
2641
|
+
* the deployment, not the session, so it cannot dial as a session's user.
|
|
2392
2642
|
*/
|
|
2393
2643
|
cloudBridgeableConnectionNames() {
|
|
2394
2644
|
const names = [];
|
|
@@ -2398,7 +2648,9 @@ export class SessionEngine {
|
|
|
2398
2648
|
}
|
|
2399
2649
|
}
|
|
2400
2650
|
for (const resolved of this.resolvedConnections) {
|
|
2401
|
-
if (resolved.accountServersFilter !== undefined &&
|
|
2651
|
+
if (resolved.accountServersFilter !== undefined &&
|
|
2652
|
+
resolved.individualCredentials !== true &&
|
|
2653
|
+
resolved.cloudUrl === undefined) {
|
|
2402
2654
|
names.push(resolved.name);
|
|
2403
2655
|
}
|
|
2404
2656
|
}
|
|
@@ -2426,11 +2678,25 @@ export class SessionEngine {
|
|
|
2426
2678
|
if (connection === undefined || !("url" in connection)) {
|
|
2427
2679
|
return undefined;
|
|
2428
2680
|
}
|
|
2429
|
-
const url =
|
|
2430
|
-
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2681
|
+
const url = this.sessionToolsUrl(connection.url, sessionId);
|
|
2431
2682
|
url.searchParams.set("connection", connectionName);
|
|
2432
2683
|
return { ...connection, url: url.toString() };
|
|
2433
2684
|
}
|
|
2685
|
+
/** The tool MCP endpoint URL bound to `sessionId` and carrying its credential. */
|
|
2686
|
+
sessionToolsUrl(base, sessionId) {
|
|
2687
|
+
const url = new URL(base);
|
|
2688
|
+
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2689
|
+
url.searchParams.set(TOOL_SESSION_CREDENTIAL_PARAM, this.toolSessionCredentials.for(sessionId));
|
|
2690
|
+
return url;
|
|
2691
|
+
}
|
|
2692
|
+
/**
|
|
2693
|
+
* Whether a tool MCP endpoint request presents the credential of the
|
|
2694
|
+
* session it names. The endpoint's own auth admits the deployment, not a
|
|
2695
|
+
* session, so this is what keeps one session out of another's tools.
|
|
2696
|
+
*/
|
|
2697
|
+
presentsToolSessionCredential(sessionId, presented) {
|
|
2698
|
+
return this.toolSessionCredentials.verifies(sessionId, presented);
|
|
2699
|
+
}
|
|
2434
2700
|
/**
|
|
2435
2701
|
* Authored + resolved MCP servers for a turn. Skips advertised
|
|
2436
2702
|
* connections (those surface as named server tools). On cloud turns,
|
|
@@ -2508,8 +2774,9 @@ export class SessionEngine {
|
|
|
2508
2774
|
const url = runtime === "cloud" ? resolved.cloudUrl : resolved.localUrl;
|
|
2509
2775
|
if (url === undefined) {
|
|
2510
2776
|
// Filtered account connections bridge through the host so the
|
|
2511
|
-
// `servers` filter is honored;
|
|
2512
|
-
// fallback to the account's native connectors on the VM.
|
|
2777
|
+
// `servers` filter is honored; the rest keep their documented
|
|
2778
|
+
// fallback to the account's native connectors on the VM. An
|
|
2779
|
+
// individual one never gets here: the turn refuses it first.
|
|
2513
2780
|
const bridged = bridgeTransport(resolved.name);
|
|
2514
2781
|
if (bridged !== undefined) {
|
|
2515
2782
|
servers[resolved.name] = bridged;
|
|
@@ -2524,7 +2791,7 @@ export class SessionEngine {
|
|
|
2524
2791
|
bound.searchParams.set("agentkitSessionId", sessionId);
|
|
2525
2792
|
servers[resolved.name] = {
|
|
2526
2793
|
url: bound.toString(),
|
|
2527
|
-
headers: resolved.headers,
|
|
2794
|
+
headers: resolved.sessionHeaders?.(sessionId) ?? resolved.headers,
|
|
2528
2795
|
};
|
|
2529
2796
|
continue;
|
|
2530
2797
|
}
|
|
@@ -2542,11 +2809,9 @@ export class SessionEngine {
|
|
|
2542
2809
|
}
|
|
2543
2810
|
const connection = this.currentCloudServerToolsConnection();
|
|
2544
2811
|
if (connection !== undefined && "url" in connection) {
|
|
2545
|
-
const url = new URL(connection.url);
|
|
2546
|
-
url.searchParams.set("agentkitSessionId", sessionId);
|
|
2547
2812
|
servers[SERVER_TOOLS_MCP_SERVER_NAME] = {
|
|
2548
2813
|
...connection,
|
|
2549
|
-
url: url.toString(),
|
|
2814
|
+
url: this.sessionToolsUrl(connection.url, sessionId).toString(),
|
|
2550
2815
|
};
|
|
2551
2816
|
}
|
|
2552
2817
|
}
|
|
@@ -2561,6 +2826,9 @@ export class SessionEngine {
|
|
|
2561
2826
|
hasAttachedAuthedConnections() {
|
|
2562
2827
|
return this.project.agent.connections.some((connection) => connection.auth !== undefined && connection.advertiseTools !== true);
|
|
2563
2828
|
}
|
|
2829
|
+
hasIndividualAccountConnections() {
|
|
2830
|
+
return this.project.agent.connections.some((connection) => connection.credentials === "individual" && isCursorAccountTransport(connection.transport));
|
|
2831
|
+
}
|
|
2564
2832
|
/**
|
|
2565
2833
|
* Evaluate per-session connection auth (`defineConnection({ auth })`)
|
|
2566
2834
|
* for connections that attach to the model this turn. Advertised
|
|
@@ -2761,6 +3029,7 @@ export class SessionEngine {
|
|
|
2761
3029
|
}),
|
|
2762
3030
|
getSession: (channelId, sessionId) => this.getChannelSession(channelId, sessionId),
|
|
2763
3031
|
emit: args.emit,
|
|
3032
|
+
steer: (message, steerOptions) => this.steerRunningTurn(args.record.sessionId, args.turnId, message, steerOptions),
|
|
2764
3033
|
// Built before runInCall binds the turn. Methods read the active
|
|
2765
3034
|
// context when the tool calls them.
|
|
2766
3035
|
telemetry,
|
|
@@ -2809,8 +3078,9 @@ export class SessionEngine {
|
|
|
2809
3078
|
}
|
|
2810
3079
|
const needsGate = await evaluateNeedsApproval(args.tool.definition.needsApproval, validation.value);
|
|
2811
3080
|
if (needsGate) {
|
|
2812
|
-
const { decision, approver } = await this.parkForApproval({
|
|
3081
|
+
const { decision, reason, approver } = await this.parkForApproval({
|
|
2813
3082
|
sessionId: args.record.sessionId,
|
|
3083
|
+
channelId: args.record.channelId,
|
|
2814
3084
|
turnId: args.turnId,
|
|
2815
3085
|
callId: toolCallId,
|
|
2816
3086
|
toolName: args.tool.name,
|
|
@@ -2818,7 +3088,7 @@ export class SessionEngine {
|
|
|
2818
3088
|
emit: args.emit,
|
|
2819
3089
|
});
|
|
2820
3090
|
if (decision === "deny") {
|
|
2821
|
-
return toolErrorResult(
|
|
3091
|
+
return toolErrorResult(toolDenialText(args.tool.name, reason));
|
|
2822
3092
|
}
|
|
2823
3093
|
toolCtx.approvedBy = approver;
|
|
2824
3094
|
}
|
|
@@ -2953,7 +3223,13 @@ export class SessionEngine {
|
|
|
2953
3223
|
},
|
|
2954
3224
|
});
|
|
2955
3225
|
this.logger(`[session] tool ${args.toolName} awaiting approval (${args.callId})`);
|
|
2956
|
-
const
|
|
3226
|
+
const timeoutMs = this.channelsById.get(args.channelId)?.meta?.toolApprovalTimeoutMs;
|
|
3227
|
+
const stopDeadline = timeoutMs === undefined
|
|
3228
|
+
? () => { }
|
|
3229
|
+
: armParkDeadline(this.turnAborts.get(args.sessionId)?.signal, timeoutMs, (reason) => {
|
|
3230
|
+
this.approvals.expire(args.sessionId, args.callId, reason);
|
|
3231
|
+
});
|
|
3232
|
+
const { decision, by, approver, reason } = await resolutionPromise.finally(stopDeadline);
|
|
2957
3233
|
await this.updateRecord(args.sessionId, (current) => ({
|
|
2958
3234
|
...current,
|
|
2959
3235
|
pendingApprovals: (current.pendingApprovals ?? []).filter((item) => item.callId !== args.callId),
|
|
@@ -2964,11 +3240,12 @@ export class SessionEngine {
|
|
|
2964
3240
|
callId: args.callId,
|
|
2965
3241
|
toolName: args.toolName,
|
|
2966
3242
|
decision,
|
|
2967
|
-
|
|
3243
|
+
by,
|
|
3244
|
+
reason,
|
|
2968
3245
|
},
|
|
2969
3246
|
});
|
|
2970
3247
|
this.logger(`[session] tool ${args.toolName} approval ${decision} (${args.callId})`);
|
|
2971
|
-
return { decision, by, approver };
|
|
3248
|
+
return { decision, by, approver, reason };
|
|
2972
3249
|
}
|
|
2973
3250
|
async clearPendingApprovals(sessionId) {
|
|
2974
3251
|
const current = await this.sessions.get(sessionId);
|
|
@@ -3096,6 +3373,10 @@ export class SessionEngine {
|
|
|
3096
3373
|
if (!canPark() && !canRefresh) {
|
|
3097
3374
|
return giveUp();
|
|
3098
3375
|
}
|
|
3376
|
+
if (authored?.credentials === "individual" &&
|
|
3377
|
+
this.turnContextFor(ctx.sessionId)?.user === undefined) {
|
|
3378
|
+
throw new McpReconnectError(authored.name, individualNoUserMessage(authored.name), error);
|
|
3379
|
+
}
|
|
3099
3380
|
const minted = await this.mintAuthUrl(connection, ctx.sessionId);
|
|
3100
3381
|
if (minted === undefined) {
|
|
3101
3382
|
return giveUp();
|
|
@@ -3105,6 +3386,9 @@ export class SessionEngine {
|
|
|
3105
3386
|
await this.mcpHost.dropClient(connection);
|
|
3106
3387
|
return await this.withMcpAuth(connection, run);
|
|
3107
3388
|
}
|
|
3389
|
+
if (authored?.credentials === "individual") {
|
|
3390
|
+
return this.sendPrivateSignIn(ctx, authored, minted.authUrl, error);
|
|
3391
|
+
}
|
|
3108
3392
|
if (minted.state !== "") {
|
|
3109
3393
|
const bind = this.oauthHub.bind(minted.state, ctx.sessionId, ctx.callId);
|
|
3110
3394
|
if (bind === "already_done") {
|
|
@@ -3138,6 +3422,41 @@ export class SessionEngine {
|
|
|
3138
3422
|
await this.mcpHost.dropClient(connection);
|
|
3139
3423
|
return await this.withMcpAuth(connection, run);
|
|
3140
3424
|
}
|
|
3425
|
+
/**
|
|
3426
|
+
* An individual connection signs in only the person who started the turn,
|
|
3427
|
+
* so the link goes to them alone and the turn does not wait for them.
|
|
3428
|
+
*/
|
|
3429
|
+
sendPrivateSignIn(ctx, connection, authUrl, cause) {
|
|
3430
|
+
const source = this.turnContextFor(ctx.sessionId)?.source;
|
|
3431
|
+
const slackUserId = source?.kind === "slack" ? source.userId : undefined;
|
|
3432
|
+
ctx.emit({
|
|
3433
|
+
type: "action.auth_requested",
|
|
3434
|
+
data: {
|
|
3435
|
+
callId: ctx.callId,
|
|
3436
|
+
toolName: ctx.toolName,
|
|
3437
|
+
connection: connection.name,
|
|
3438
|
+
authUrl,
|
|
3439
|
+
privateTo: { slackUserId },
|
|
3440
|
+
},
|
|
3441
|
+
});
|
|
3442
|
+
throw new McpReconnectError(connection.name, privateSignInMessage({
|
|
3443
|
+
connection: connection.name,
|
|
3444
|
+
authUrl,
|
|
3445
|
+
sentToSlack: slackUserId !== undefined,
|
|
3446
|
+
}), cause);
|
|
3447
|
+
}
|
|
3448
|
+
/** The Slack member to tell how to link an account, when this turn has none and needs one. */
|
|
3449
|
+
unlinkedSlackSenderNeedingLink(options) {
|
|
3450
|
+
const turn = options.turnContext;
|
|
3451
|
+
if (options.turnMode !== "interactive" ||
|
|
3452
|
+
turn === undefined ||
|
|
3453
|
+
turn.user !== undefined ||
|
|
3454
|
+
turn.source.kind !== "slack" ||
|
|
3455
|
+
!this.project.agent.connections.some((item) => item.credentials === "individual")) {
|
|
3456
|
+
return undefined;
|
|
3457
|
+
}
|
|
3458
|
+
return turn.source.userId;
|
|
3459
|
+
}
|
|
3141
3460
|
async persistHostedMcpOauth(connection) {
|
|
3142
3461
|
const authored = this.authoredConnection(connection);
|
|
3143
3462
|
if (authored === undefined || !isHostOauthConnectionTransport(authored.transport)) {
|
|
@@ -3155,7 +3474,7 @@ export class SessionEngine {
|
|
|
3155
3474
|
if (probe === undefined) {
|
|
3156
3475
|
return undefined;
|
|
3157
3476
|
}
|
|
3158
|
-
const authUrl = await probe(connection);
|
|
3477
|
+
const authUrl = await probe(connection, sessionId);
|
|
3159
3478
|
if (authUrl === undefined || authUrl === "") {
|
|
3160
3479
|
return undefined;
|
|
3161
3480
|
}
|
|
@@ -3201,34 +3520,11 @@ export class SessionEngine {
|
|
|
3201
3520
|
},
|
|
3202
3521
|
});
|
|
3203
3522
|
this.logger(`[session] tool ${args.toolName} awaiting MCP auth ${args.connection} (${args.callId})`);
|
|
3204
|
-
const
|
|
3523
|
+
const stopDeadline = armParkDeadline(this.turnAborts.get(args.sessionId)?.signal, MCP_AUTH_PARK_TIMEOUT_MS, (reason) => {
|
|
3205
3524
|
void this.oauthHub.abortCall(args.sessionId, args.callId);
|
|
3206
|
-
|
|
3207
|
-
};
|
|
3208
|
-
const
|
|
3209
|
-
const endForAbort = () => {
|
|
3210
|
-
endWait("interrupt");
|
|
3211
|
-
};
|
|
3212
|
-
if (signal?.aborted) {
|
|
3213
|
-
endForAbort();
|
|
3214
|
-
}
|
|
3215
|
-
else {
|
|
3216
|
-
signal?.addEventListener("abort", endForAbort, { once: true });
|
|
3217
|
-
}
|
|
3218
|
-
let timedOut = false;
|
|
3219
|
-
const timer = setTimeout(() => {
|
|
3220
|
-
timedOut = endWait("timeout");
|
|
3221
|
-
}, MCP_AUTH_PARK_TIMEOUT_MS);
|
|
3222
|
-
timer.unref();
|
|
3223
|
-
let decision;
|
|
3224
|
-
let by;
|
|
3225
|
-
try {
|
|
3226
|
-
({ decision, by } = await resolutionPromise);
|
|
3227
|
-
}
|
|
3228
|
-
finally {
|
|
3229
|
-
clearTimeout(timer);
|
|
3230
|
-
signal?.removeEventListener("abort", endForAbort);
|
|
3231
|
-
}
|
|
3525
|
+
this.auths.expire(args.sessionId, args.callId, reason);
|
|
3526
|
+
});
|
|
3527
|
+
const { decision, by, reason } = await resolutionPromise.finally(stopDeadline);
|
|
3232
3528
|
await this.updateRecord(args.sessionId, (current) => ({
|
|
3233
3529
|
...current,
|
|
3234
3530
|
pendingAuths: (current.pendingAuths ?? []).filter((item) => item.callId !== args.callId),
|
|
@@ -3241,24 +3537,158 @@ export class SessionEngine {
|
|
|
3241
3537
|
connection: args.connection,
|
|
3242
3538
|
decision,
|
|
3243
3539
|
by,
|
|
3540
|
+
reason,
|
|
3244
3541
|
},
|
|
3245
3542
|
});
|
|
3246
|
-
const outcome =
|
|
3543
|
+
const outcome = reason === "timeout" ? "timeout" : decision;
|
|
3247
3544
|
this.logger(`[session] tool ${args.toolName} MCP auth ${outcome} (${args.callId})`);
|
|
3248
3545
|
return outcome;
|
|
3249
3546
|
}
|
|
3547
|
+
/** Keeps connects that wait for the person's next turn rather than this one. */
|
|
3250
3548
|
async clearPendingAuths(sessionId) {
|
|
3251
3549
|
await this.oauthHub.abortSession(sessionId);
|
|
3252
3550
|
const current = await this.sessions.get(sessionId);
|
|
3253
3551
|
if (current === undefined ||
|
|
3254
3552
|
current.pendingAuths === undefined ||
|
|
3255
|
-
current.pendingAuths.
|
|
3553
|
+
current.pendingAuths.every((item) => item.awaitsNextTurn === true)) {
|
|
3256
3554
|
return;
|
|
3257
3555
|
}
|
|
3258
3556
|
await this.updateRecord(sessionId, (record) => ({
|
|
3259
3557
|
...record,
|
|
3260
|
-
pendingAuths: [],
|
|
3558
|
+
pendingAuths: (record.pendingAuths ?? []).filter((item) => item.awaitsNextTurn === true),
|
|
3559
|
+
}));
|
|
3560
|
+
}
|
|
3561
|
+
/**
|
|
3562
|
+
* The agent's `mcp_auth` for an individual connection, answered at once:
|
|
3563
|
+
* the person connects from the card and clicks Connected, which starts
|
|
3564
|
+
* their next turn on fresh MCP clients. A repeat request reuses the pending
|
|
3565
|
+
* link. Only an already-connected connection is approved, because the SDK
|
|
3566
|
+
* does not reload a server it approves.
|
|
3567
|
+
*/
|
|
3568
|
+
async answerMcpAuth(sessionId, turnId, emit, request) {
|
|
3569
|
+
const connection = this.authoredConnection(request.serverName);
|
|
3570
|
+
if (connection?.credentials !== "individual" ||
|
|
3571
|
+
!isCursorAccountTransport(connection.transport)) {
|
|
3572
|
+
return undefined;
|
|
3573
|
+
}
|
|
3574
|
+
const turn = this.turnContextFor(sessionId);
|
|
3575
|
+
if (turn?.user === undefined) {
|
|
3576
|
+
return { kind: "rejected", reason: individualNoUserMessage(connection.name) };
|
|
3577
|
+
}
|
|
3578
|
+
const sentToSlack = turn.source.kind === "slack";
|
|
3579
|
+
const userId = turn.user.id;
|
|
3580
|
+
const pending = (await this.sessions.get(sessionId))?.pendingAuths?.find((item) => item.awaitsNextTurn === true &&
|
|
3581
|
+
item.userId === userId &&
|
|
3582
|
+
item.connection === connection.name);
|
|
3583
|
+
if (pending !== undefined) {
|
|
3584
|
+
// A later turn shows the same card again, in case Connected came early.
|
|
3585
|
+
if (pending.turnId !== turnId) {
|
|
3586
|
+
emit({
|
|
3587
|
+
type: "action.auth_requested",
|
|
3588
|
+
data: {
|
|
3589
|
+
callId: pending.callId,
|
|
3590
|
+
toolName: pending.toolName,
|
|
3591
|
+
connection: pending.connection,
|
|
3592
|
+
authUrl: pending.authUrl,
|
|
3593
|
+
privateTo: {
|
|
3594
|
+
slackUserId: turn.source.kind === "slack" ? turn.source.userId : undefined,
|
|
3595
|
+
},
|
|
3596
|
+
},
|
|
3597
|
+
});
|
|
3598
|
+
await this.updateRecord(sessionId, (current) => ({
|
|
3599
|
+
...current,
|
|
3600
|
+
pendingAuths: (current.pendingAuths ?? []).map((item) => item.callId === pending.callId ? { ...item, turnId } : item),
|
|
3601
|
+
}));
|
|
3602
|
+
}
|
|
3603
|
+
return {
|
|
3604
|
+
kind: "rejected",
|
|
3605
|
+
reason: connectThenContinueMessage(connection.name, pending.authUrl, sentToSlack),
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
if ((await this.individualConnectedCheck?.(connection.name, sessionId)) === true) {
|
|
3609
|
+
return { kind: "approved" };
|
|
3610
|
+
}
|
|
3611
|
+
const minted = await this.mintAuthUrl(connection.name, sessionId);
|
|
3612
|
+
if (minted === undefined || !("authUrl" in minted)) {
|
|
3613
|
+
return {
|
|
3614
|
+
kind: "rejected",
|
|
3615
|
+
reason: `${connection.name} could not start a sign-in. Answer without ${connection.name}.`,
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
const entry = {
|
|
3619
|
+
callId: request.toolCallId,
|
|
3620
|
+
turnId,
|
|
3621
|
+
toolName: MCP_AUTH_TOOL_NAME,
|
|
3622
|
+
connection: connection.name,
|
|
3623
|
+
authUrl: minted.authUrl,
|
|
3624
|
+
requestedAt: new Date().toISOString(),
|
|
3625
|
+
awaitsNextTurn: true,
|
|
3626
|
+
userId,
|
|
3627
|
+
};
|
|
3628
|
+
await this.updateRecord(sessionId, (current) => ({
|
|
3629
|
+
...current,
|
|
3630
|
+
pendingAuths: [
|
|
3631
|
+
...(current.pendingAuths ?? []).filter((item) => item.callId !== entry.callId),
|
|
3632
|
+
entry,
|
|
3633
|
+
],
|
|
3261
3634
|
}));
|
|
3635
|
+
emit({
|
|
3636
|
+
type: "action.auth_requested",
|
|
3637
|
+
data: {
|
|
3638
|
+
callId: entry.callId,
|
|
3639
|
+
toolName: entry.toolName,
|
|
3640
|
+
connection: entry.connection,
|
|
3641
|
+
authUrl: entry.authUrl,
|
|
3642
|
+
privateTo: { slackUserId: turn.source.kind === "slack" ? turn.source.userId : undefined },
|
|
3643
|
+
},
|
|
3644
|
+
});
|
|
3645
|
+
return {
|
|
3646
|
+
kind: "rejected",
|
|
3647
|
+
reason: connectThenContinueMessage(connection.name, entry.authUrl, sentToSlack),
|
|
3648
|
+
};
|
|
3649
|
+
}
|
|
3650
|
+
/**
|
|
3651
|
+
* Settles pending connects at turn start, each once: Cancel drops one, and
|
|
3652
|
+
* a connect the person finished resolves. A Connected or Cancel click with
|
|
3653
|
+
* nothing pending for its connection does not run the request again.
|
|
3654
|
+
*/
|
|
3655
|
+
async settleConnects(sessionId, message, emit) {
|
|
3656
|
+
const userId = this.turnContextFor(sessionId)?.user?.id;
|
|
3657
|
+
if (userId === undefined) {
|
|
3658
|
+
return undefined;
|
|
3659
|
+
}
|
|
3660
|
+
// A Slack thread can hold several people; each settles only their own connects.
|
|
3661
|
+
const pending = ((await this.sessions.get(sessionId))?.pendingAuths ?? []).filter((item) => item.awaitsNextTurn === true && item.userId === userId);
|
|
3662
|
+
const individual = this.project.agent.connections
|
|
3663
|
+
.filter((connection) => connection.credentials === "individual" && isCursorAccountTransport(connection.transport))
|
|
3664
|
+
.map((connection) => connection.name);
|
|
3665
|
+
const click = parseConnectClickText(message, individual);
|
|
3666
|
+
if (click !== undefined && !pending.some((item) => item.connection === click.connection)) {
|
|
3667
|
+
return { skip: `Nothing is waiting on ${click.connection}.` };
|
|
3668
|
+
}
|
|
3669
|
+
const resolve = async (item, decision) => {
|
|
3670
|
+
await this.removePendingAuth(sessionId, item.callId);
|
|
3671
|
+
emit({
|
|
3672
|
+
type: "action.auth_resolved",
|
|
3673
|
+
data: {
|
|
3674
|
+
callId: item.callId,
|
|
3675
|
+
toolName: item.toolName,
|
|
3676
|
+
connection: item.connection,
|
|
3677
|
+
decision,
|
|
3678
|
+
},
|
|
3679
|
+
});
|
|
3680
|
+
};
|
|
3681
|
+
for (const item of pending) {
|
|
3682
|
+
if (click?.decision === "deny" && click.connection === item.connection) {
|
|
3683
|
+
await resolve(item, "deny");
|
|
3684
|
+
continue;
|
|
3685
|
+
}
|
|
3686
|
+
const connected = await this.individualConnectedCheck?.(item.connection, sessionId).catch(() => false);
|
|
3687
|
+
if (connected === true) {
|
|
3688
|
+
await resolve(item, "approve");
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
return undefined;
|
|
3262
3692
|
}
|
|
3263
3693
|
async listPendingAuths(sessionId) {
|
|
3264
3694
|
const record = await this.sessions.get(sessionId);
|
|
@@ -3286,6 +3716,24 @@ export class SessionEngine {
|
|
|
3286
3716
|
throw new AuthNotFoundError(sessionId, callId);
|
|
3287
3717
|
}
|
|
3288
3718
|
const resolvedBy = approvalResolverLabel(auth);
|
|
3719
|
+
if (pending.awaitsNextTurn === true) {
|
|
3720
|
+
// No turn waits on it. Connected leaves it for the next turn to confirm.
|
|
3721
|
+
if (decision === "deny") {
|
|
3722
|
+
await this.removePendingAuth(sessionId, callId);
|
|
3723
|
+
await this.appendEvent(sessionId, {
|
|
3724
|
+
type: "action.auth_resolved",
|
|
3725
|
+
turnId: pending.turnId,
|
|
3726
|
+
data: {
|
|
3727
|
+
callId,
|
|
3728
|
+
toolName: pending.toolName,
|
|
3729
|
+
connection: pending.connection,
|
|
3730
|
+
decision,
|
|
3731
|
+
by: resolvedBy,
|
|
3732
|
+
},
|
|
3733
|
+
});
|
|
3734
|
+
}
|
|
3735
|
+
return pending;
|
|
3736
|
+
}
|
|
3289
3737
|
if (decision === "deny") {
|
|
3290
3738
|
await this.oauthHub.abortCall(sessionId, callId);
|
|
3291
3739
|
}
|
|
@@ -3877,14 +4325,11 @@ export class SessionEngine {
|
|
|
3877
4325
|
}
|
|
3878
4326
|
async dispatchEventHandlers(sessionId, event, context, record) {
|
|
3879
4327
|
const channelState = context === undefined ? (record.channelState ?? null) : context.channelState;
|
|
3880
|
-
const sessionCtx = {
|
|
4328
|
+
const sessionCtx = this.sessionContext({
|
|
4329
|
+
sessionId: record.sessionId,
|
|
3881
4330
|
session: context?.session ?? this.sessionInfo(record),
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
sessionId: record.sessionId,
|
|
3885
|
-
turnId: event.turnId,
|
|
3886
|
-
}),
|
|
3887
|
-
};
|
|
4331
|
+
turnId: event.turnId,
|
|
4332
|
+
});
|
|
3888
4333
|
const channelEvents = this.channelEventHandlersFor(record.channelId);
|
|
3889
4334
|
if (channelEvents !== undefined) {
|
|
3890
4335
|
const handlers = [
|
|
@@ -4408,6 +4853,14 @@ export class SessionEngine {
|
|
|
4408
4853
|
takeContinuationRelease(continuationKey) {
|
|
4409
4854
|
return this.releasedContinuations.delete(continuationKey);
|
|
4410
4855
|
}
|
|
4856
|
+
/** The running turn's context. A follow-up that joins the turn reads this one. */
|
|
4857
|
+
turnContextFor(sessionId) {
|
|
4858
|
+
return this.turnContexts.get(sessionId)?.context;
|
|
4859
|
+
}
|
|
4860
|
+
/** The mailbox key the running turn's user was signed under; see {@link EngineSendOptions.turnSessionKey}. */
|
|
4861
|
+
turnSessionKeyFor(sessionId) {
|
|
4862
|
+
return this.turnContexts.get(sessionId)?.sessionKey;
|
|
4863
|
+
}
|
|
4411
4864
|
isTurnRunning(sessionId) {
|
|
4412
4865
|
// Include the admit window (pendingTurns) and coalesce drain so busy
|
|
4413
4866
|
// policies do not treat a turn that has finished executeTurn but not yet
|
|
@@ -4725,6 +5178,25 @@ export class SessionEngine {
|
|
|
4725
5178
|
}
|
|
4726
5179
|
}
|
|
4727
5180
|
const DEPLOYED_AGENTS_DASHBOARD_URL = "https://cursor.com/dashboard/deployed-agents";
|
|
5181
|
+
/** What the model reads after an individual connection's sign-in link went to the asker alone. */
|
|
5182
|
+
export function privateSignInMessage(args) {
|
|
5183
|
+
const { connection } = args;
|
|
5184
|
+
const link = args.sentToSlack
|
|
5185
|
+
? " They were sent a private link to connect it. Do not post a link."
|
|
5186
|
+
: ` Give them this link to connect it: ${args.authUrl}`;
|
|
5187
|
+
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.`;
|
|
5188
|
+
}
|
|
5189
|
+
const MCP_AUTH_TOOL_NAME = "mcp_auth";
|
|
5190
|
+
/** Told to the model when an individual connection's sign-in card is shown. */
|
|
5191
|
+
export function connectThenContinueMessage(connection, authUrl, sentToSlack) {
|
|
5192
|
+
const where = sentToSlack
|
|
5193
|
+
? "They were sent a private Connect card. Do not post a link."
|
|
5194
|
+
: `They see a Connect card. If they cannot, give them this link: ${authUrl}`;
|
|
5195
|
+
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.`;
|
|
5196
|
+
}
|
|
5197
|
+
function individualNoUserMessage(connection) {
|
|
5198
|
+
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}.`;
|
|
5199
|
+
}
|
|
4728
5200
|
function mcpAuthReconnectMessage(connection) {
|
|
4729
5201
|
if (isCursorAccountTransport(connection.transport)) {
|
|
4730
5202
|
return `Reconnect ${connection.name}: the MCP connection needs authorization. Ask the bot owner to reconnect ${connection.name} at ${DEPLOYED_AGENTS_DASHBOARD_URL}`;
|
|
@@ -4804,6 +5276,21 @@ export function withTurnCountClampedToEvents(record, events) {
|
|
|
4804
5276
|
}
|
|
4805
5277
|
return maxTurn > record.turnCount ? { ...record, turnCount: maxTurn } : record;
|
|
4806
5278
|
}
|
|
5279
|
+
/**
|
|
5280
|
+
* The cloud run this hosted delivery already started on the session's bound
|
|
5281
|
+
* agent, when an earlier host recorded one. Another delivery never matches,
|
|
5282
|
+
* so its message is still sent.
|
|
5283
|
+
*/
|
|
5284
|
+
function reattachableCloudRunId(record, platformDeliveryId) {
|
|
5285
|
+
const recorded = record.hostedCloudRun;
|
|
5286
|
+
if (platformDeliveryId === undefined ||
|
|
5287
|
+
recorded === undefined ||
|
|
5288
|
+
recorded.platformDeliveryId !== platformDeliveryId ||
|
|
5289
|
+
recorded.sdkAgentId !== record.sdkAgentId) {
|
|
5290
|
+
return undefined;
|
|
5291
|
+
}
|
|
5292
|
+
return recorded.runId;
|
|
5293
|
+
}
|
|
4807
5294
|
function subagentPrompt(subagent) {
|
|
4808
5295
|
if (subagent.instructions !== undefined && subagent.instructions !== "") {
|
|
4809
5296
|
return subagent.instructions;
|
|
@@ -4888,6 +5375,9 @@ function approvalResolverLabel(auth) {
|
|
|
4888
5375
|
if (auth === null) {
|
|
4889
5376
|
return undefined;
|
|
4890
5377
|
}
|
|
5378
|
+
if (auth.label !== undefined && auth.label !== "") {
|
|
5379
|
+
return auth.label;
|
|
5380
|
+
}
|
|
4891
5381
|
const slackUser = auth.attributes?.user_id;
|
|
4892
5382
|
if (auth.authenticator === "slack" && slackUser !== undefined && slackUser !== "") {
|
|
4893
5383
|
return slackUser;
|