@cursor/bdk 0.2.1 → 0.2.3
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 +1 -1
- package/README.md +1 -6
- package/dist/artifacts.d.ts +5 -2
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +5 -2
- package/dist/bin/agent-serve.js +23 -7
- package/dist/channels/github/auth.d.ts.map +1 -1
- package/dist/channels/github/auth.js +36 -5
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +3 -2
- package/dist/channels/slack/types.d.ts +6 -1
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/connections.d.ts +1 -1
- package/dist/connections.js +1 -1
- package/dist/docs/404.html +2 -2
- package/dist/docs/assets/{app.JVQvbRO-.js → app.BOIHhrKi.js} +4 -4
- package/dist/docs/assets/chunks/@localSearchIndexroot.D5L-b34G.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.BkhY63uW.js → VPLocalSearchBox.D49zVZqM.js} +1 -1
- package/dist/docs/assets/chunks/{arc.Cc1unYd3.js → arc.hmjb-sc4.js} +1 -1
- package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.CAY_TPVz.js → architectureDiagram-Q4EWVU46.CxEI1KqM.js} +1 -1
- package/dist/docs/assets/chunks/{baseUniq.my2VD3Xm.js → baseUniq.DHHvBWoV.js} +1 -1
- package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.CQXAOmqd.js → blockDiagram-DXYQGD6D.DnXW-3bu.js} +1 -1
- package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.D0AsQFSX.js → c4Diagram-AHTNJAMY.e-47O2jM.js} +1 -1
- package/dist/docs/assets/chunks/channel.BbOGaJQP.js +1 -0
- package/dist/docs/assets/chunks/{chunk-4BX2VUAB.DZjhgNls.js → chunk-4BX2VUAB.3ry4pYXB.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-4TB4RGXK.qdcp_qbo.js → chunk-4TB4RGXK.DGIZFRx6.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-55IACEB6.BHXoZhJ-.js → chunk-55IACEB6.DKBnqg9U.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-EDXVE4YY.Cds_Vwj3.js → chunk-EDXVE4YY.BIU8Ue5k.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-FMBD7UC4.CSl0HknT.js → chunk-FMBD7UC4.DP-TFhjI.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-OYMX7WX6.DJMvAt5N.js → chunk-OYMX7WX6.Ux0OYj5v.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-QZHKN3VN.BYQzBK9D.js → chunk-QZHKN3VN.BzHMwYox.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-YZCP3GAM.BAvw7N4o.js → chunk-YZCP3GAM.D4OGAsSP.js} +1 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.Db58HCb1.js +1 -0
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.Db58HCb1.js +1 -0
- package/dist/docs/assets/chunks/clone.Co4MBflG.js +1 -0
- package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.Buf3seya.js → cose-bilkent-S5V4N54A.Jq_7BUNx.js} +1 -1
- package/dist/docs/assets/chunks/{dagre-KV5264BT.DMGGa3uA.js → dagre-KV5264BT.Di-skR2x.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-5BDNPKRD.DDjnwRmY.js → diagram-5BDNPKRD.DeREHIdH.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.RwyrIr8Q.js → diagram-G4DWMVQ6.C7Kcqxro.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-MMDJMWI5.DRvQV16Z.js → diagram-MMDJMWI5.BK3eohyo.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-TYMM5635.Dw8W9BTk.js → diagram-TYMM5635.C6TyymXT.js} +1 -1
- package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DQT1Hnwf.js → erDiagram-SMLLAGMA.DYGG-gGx.js} +1 -1
- package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.6_Aky-ut.js → flowDiagram-DWJPFMVM.C9nBcSV4.js} +1 -1
- package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.DHIwqnqN.js → ganttDiagram-T4ZO3ILL.wAg_ymsp.js} +1 -1
- package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.CGd_eJbn.js → gitGraphDiagram-UUTBAWPF.B87j9Oeg.js} +1 -1
- package/dist/docs/assets/chunks/{graph.ChMEylkh.js → graph.CuFMj31w.js} +1 -1
- package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.Cd4gMyAz.js → infoDiagram-42DDH7IO.P_mLGumP.js} +1 -1
- package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.D1uw7MXq.js → ishikawaDiagram-UXIWVN3A.DyuL_MsT.js} +1 -1
- package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.AWLXtelc.js → journeyDiagram-VCZTEJTY.CtP09IoJ.js} +1 -1
- package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.CagPhAn5.js → kanban-definition-6JOO6SKY.BoeSYPZo.js} +1 -1
- package/dist/docs/assets/chunks/{layout.ClTBBkE_.js → layout.B0lMMtNo.js} +1 -1
- package/dist/docs/assets/chunks/{linear.SwS2rOLA.js → linear.HxRBiAFX.js} +1 -1
- package/dist/docs/assets/chunks/{min.By_x-Btb.js → min.BGlFFHwS.js} +1 -1
- package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.By_RAMaP.js → mindmap-definition-QFDTVHPH.JyLBD9M8.js} +1 -1
- package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.DfAl9sy4.js → pieDiagram-DEJITSTG.DnSmNZF8.js} +1 -1
- package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CNuqFRBj.js → quadrantDiagram-34T5L4WZ.CUCnbfCa.js} +1 -1
- package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.DJ5CmTCl.js → requirementDiagram-MS252O5E.py0IVUn5.js} +1 -1
- package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.D-T_AKJj.js → sankeyDiagram-XADWPNL6.Bkc-HWYp.js} +1 -1
- package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.BRn9WcrR.js → sequenceDiagram-FGHM5R23.Dqn8Mlv2.js} +1 -1
- package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.F12urmm7.js → stateDiagram-FHFEXIEX.JikkoQUU.js} +1 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CMsKhrW0.js +1 -0
- package/dist/docs/assets/chunks/{theme.zK3OJa_C.js → theme.b6HQ6zG_.js} +2 -2
- package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.B7GiQBeC.js → timeline-definition-GMOUNBTQ.BvpSXiBj.js} +1 -1
- package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.D0niwuY_.js → vennDiagram-DHZGUBPP.CU7MVnZx.js} +1 -1
- package/dist/docs/assets/chunks/{wardley-RL74JXVD.1zhHNRsx.js → wardley-RL74JXVD.BKwC4ctG.js} +1 -1
- package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.DKaqpT7K.js → wardleyDiagram-NUSXRM2D.BfaF6Uhe.js} +1 -1
- package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.e8BPicch.js → xychartDiagram-5P7HB3ND.Bg5dcpj4.js} +1 -1
- package/dist/docs/assets/{deployment.md.nGo1yIsa.js → deployment.md.BJ8i7Q6p.js} +5 -8
- package/dist/docs/assets/{deployment.md.nGo1yIsa.lean.js → deployment.md.BJ8i7Q6p.lean.js} +1 -1
- package/dist/docs/assets/{guides_github.md.C2_DSWlE.js → guides_github.md.Bq9kQU9B.js} +9 -3
- package/dist/docs/assets/{guides_github.md.C2_DSWlE.lean.js → guides_github.md.Bq9kQU9B.lean.js} +1 -1
- package/dist/docs/assets/{guides_slack.md.ZbHQETOT.js → guides_slack.md.diqqXTTm.js} +2 -2
- package/dist/docs/assets/{guides_slack.md.ZbHQETOT.lean.js → guides_slack.md.diqqXTTm.lean.js} +1 -1
- package/dist/docs/assets/{quickstart.md.wG4shE1f.js → quickstart.md.CHpHPBUN.js} +5 -3
- package/dist/docs/assets/{quickstart.md.wG4shE1f.lean.js → quickstart.md.CHpHPBUN.lean.js} +1 -1
- package/dist/docs/assets/{reference_artifacts.md.IFFC5Zln.js → reference_artifacts.md.CQfKq8F2.js} +1 -1
- package/dist/docs/assets/reference_cli.md.DgeLTO18.js +91 -0
- package/dist/docs/assets/reference_cli.md.DgeLTO18.lean.js +1 -0
- package/dist/docs/assets/{reference_connections.md._XpKiOaF.js → reference_connections.md.COq--gAm.js} +7 -3
- package/dist/docs/assets/{reference_connections.md._XpKiOaF.lean.js → reference_connections.md.COq--gAm.lean.js} +1 -1
- package/dist/docs/assets/{reference_evals.md.DqNyHMA6.js → reference_evals.md.CJm3uCUm.js} +4 -4
- package/dist/docs/assets/{reference_evals.md.DqNyHMA6.lean.js → reference_evals.md.CJm3uCUm.lean.js} +1 -1
- package/dist/docs/assets/{reference_hooks.md.Dg3dEugd.js → reference_hooks.md.DbthhtIR.js} +1 -1
- package/dist/docs/assets/{reference_sessions.md.BtpTjZmh.js → reference_sessions.md.DeRUItHD.js} +1 -1
- package/dist/docs/assets/troubleshooting.md.Cw5PKa3t.js +1 -0
- package/dist/docs/assets/{troubleshooting.md.BzZSu1Gz.lean.js → troubleshooting.md.Cw5PKa3t.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +35 -35
- package/dist/docs/deployment.html +40 -43
- package/dist/docs/deployment.md +45 -15
- package/dist/docs/evals.html +35 -35
- package/dist/docs/guides/agent-to-agent.html +35 -35
- package/dist/docs/guides/bitbucket.html +35 -35
- package/dist/docs/guides/cloud-agents.html +35 -35
- package/dist/docs/guides/convert-automation.html +35 -35
- package/dist/docs/guides/github.html +43 -37
- package/dist/docs/guides/github.md +34 -0
- package/dist/docs/guides/gitlab.html +35 -35
- package/dist/docs/guides/grokbot-agents.html +35 -35
- package/dist/docs/guides/hooks.html +35 -35
- package/dist/docs/guides/improve.html +35 -35
- package/dist/docs/guides/jev.html +35 -35
- package/dist/docs/guides/mcp-oauth.html +35 -35
- package/dist/docs/guides/opentelemetry.html +35 -35
- package/dist/docs/guides/slack.html +37 -37
- package/dist/docs/guides/slack.md +5 -0
- package/dist/docs/guides/webhooks.html +35 -35
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +35 -35
- package/dist/docs/index.html +35 -35
- package/dist/docs/llms-full.txt +205 -97
- package/dist/docs/quickstart.html +40 -38
- package/dist/docs/quickstart.md +7 -1
- package/dist/docs/reference/agent-config.html +35 -35
- package/dist/docs/reference/artifacts.html +37 -37
- package/dist/docs/reference/artifacts.md +1 -1
- package/dist/docs/reference/channels.html +35 -35
- package/dist/docs/reference/cli.html +55 -61
- package/dist/docs/reference/cli.md +65 -63
- package/dist/docs/reference/connections.html +42 -38
- package/dist/docs/reference/connections.md +28 -2
- package/dist/docs/reference/evals.html +39 -39
- package/dist/docs/reference/evals.md +6 -7
- package/dist/docs/reference/extensions.html +35 -35
- package/dist/docs/reference/hooks.html +37 -37
- package/dist/docs/reference/hooks.md +3 -2
- package/dist/docs/reference/http-api.html +35 -35
- package/dist/docs/reference/instructions.html +35 -35
- package/dist/docs/reference/playground.html +35 -35
- package/dist/docs/reference/project-layout.html +35 -35
- package/dist/docs/reference/prompt.html +35 -35
- package/dist/docs/reference/schedules.html +35 -35
- package/dist/docs/reference/sessions.html +36 -36
- package/dist/docs/reference/sessions.md +4 -3
- package/dist/docs/reference/skills.html +35 -35
- package/dist/docs/reference/subagents.html +35 -35
- package/dist/docs/reference/tools.html +35 -35
- package/dist/docs/templates/agentic-owners.html +35 -35
- package/dist/docs/templates/security-reviewer.html +35 -35
- package/dist/docs/templates/thermo-quality-review.html +35 -35
- package/dist/docs/templates/thermo-review.html +35 -35
- package/dist/docs/templates/triage.html +35 -35
- package/dist/docs/troubleshooting.html +36 -36
- package/dist/docs/troubleshooting.md +7 -3
- package/dist/extensions/cursor-cloud-agents/extension.d.ts +16 -4
- package/dist/extensions/cursor-cloud-agents/extension.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/extension.js +7 -3
- package/dist/extensions/cursor-cloud-agents/lib/channels.d.ts +3 -0
- package/dist/extensions/cursor-cloud-agents/lib/channels.d.ts.map +1 -0
- package/dist/extensions/cursor-cloud-agents/lib/channels.js +7 -0
- package/dist/extensions/cursor-cloud-agents/lib/repos.d.ts +4 -2
- package/dist/extensions/cursor-cloud-agents/lib/repos.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/lib/repos.js +21 -12
- package/dist/extensions/cursor-cloud-agents/tools/cancel.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/tools/cancel.js +2 -0
- package/dist/extensions/cursor-cloud-agents/tools/launch.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/tools/launch.js +3 -1
- package/dist/extensions/cursor-cloud-agents/tools/reply.d.ts.map +1 -1
- package/dist/extensions/cursor-cloud-agents/tools/reply.js +2 -0
- package/dist/extensions/cursor-grokbot-agents/extension.d.ts +77 -0
- package/dist/extensions/cursor-grokbot-agents/extension.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/extension.js +63 -0
- package/dist/extensions/cursor-grokbot-agents/lib/agents.d.ts +11 -0
- package/dist/extensions/cursor-grokbot-agents/lib/agents.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/agents.js +31 -0
- package/dist/extensions/cursor-grokbot-agents/lib/backend.d.ts +56 -0
- package/dist/extensions/cursor-grokbot-agents/lib/backend.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/backend.js +158 -0
- package/dist/extensions/cursor-grokbot-agents/lib/contacts.d.ts +28 -0
- package/dist/extensions/cursor-grokbot-agents/lib/contacts.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/contacts.js +59 -0
- package/dist/extensions/cursor-grokbot-agents/lib/conversation.d.ts +53 -0
- package/dist/extensions/cursor-grokbot-agents/lib/conversation.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/conversation.js +206 -0
- package/dist/extensions/cursor-grokbot-agents/lib/inputs.d.ts +4 -0
- package/dist/extensions/cursor-grokbot-agents/lib/inputs.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/inputs.js +15 -0
- package/dist/extensions/cursor-grokbot-agents/lib/lock.d.ts +12 -0
- package/dist/extensions/cursor-grokbot-agents/lib/lock.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/lib/lock.js +25 -0
- package/dist/extensions/cursor-grokbot-agents/skills/consult.md +40 -0
- package/dist/extensions/cursor-grokbot-agents/tools/ask.d.ts +4 -0
- package/dist/extensions/cursor-grokbot-agents/tools/ask.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/tools/ask.js +37 -0
- package/dist/extensions/cursor-grokbot-agents/tools/check.d.ts +4 -0
- package/dist/extensions/cursor-grokbot-agents/tools/check.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/tools/check.js +32 -0
- package/dist/extensions/cursor-grokbot-agents/tools/interrupt.d.ts +4 -0
- package/dist/extensions/cursor-grokbot-agents/tools/interrupt.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/tools/interrupt.js +24 -0
- package/dist/extensions/cursor-grokbot-agents/tools/list.d.ts +4 -0
- package/dist/extensions/cursor-grokbot-agents/tools/list.d.ts.map +1 -0
- package/dist/extensions/cursor-grokbot-agents/tools/list.js +34 -0
- package/dist/files-backends/cursor-hosted.js +4 -4
- package/dist/internal/artifacts-store.d.ts +12 -2
- package/dist/internal/artifacts-store.d.ts.map +1 -1
- package/dist/internal/artifacts-store.js +8 -4
- package/dist/internal/cli-ax.d.ts +1 -0
- package/dist/internal/cli-ax.d.ts.map +1 -1
- package/dist/internal/cli-ax.js +43 -10
- package/dist/internal/cli-deploy.d.ts +5 -1
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +22 -4
- package/dist/internal/cli-mcp-oauth.d.ts.map +1 -1
- package/dist/internal/cli-mcp-oauth.js +2 -1
- package/dist/internal/cli-skills.d.ts +1 -1
- package/dist/internal/cli-skills.d.ts.map +1 -1
- package/dist/internal/cli-skills.js +5 -5
- package/dist/internal/connection-env.d.ts +31 -0
- package/dist/internal/connection-env.d.ts.map +1 -0
- package/dist/internal/connection-env.js +84 -0
- package/dist/internal/cursor/backend-client.js +5 -0
- package/dist/internal/deploy-client.d.ts +30 -6
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +45 -9
- package/dist/internal/discovery/connections.d.ts.map +1 -1
- package/dist/internal/discovery/connections.js +11 -0
- package/dist/internal/event-mapper.d.ts +46 -4
- package/dist/internal/event-mapper.d.ts.map +1 -1
- package/dist/internal/event-mapper.js +316 -25
- package/dist/internal/hosted-delivery-protocol.d.ts +36 -11
- package/dist/internal/hosted-delivery-protocol.d.ts.map +1 -1
- package/dist/internal/hosted-delivery-protocol.js +31 -8
- package/dist/internal/hosted-delivery.d.ts +2 -2
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +229 -49
- package/dist/internal/hosting.d.ts +2 -2
- package/dist/internal/hosting.d.ts.map +1 -1
- package/dist/internal/hosting.js +9 -3
- package/dist/internal/install-cursor-skills.d.ts +20 -24
- package/dist/internal/install-cursor-skills.d.ts.map +1 -1
- package/dist/internal/install-cursor-skills.js +50 -48
- package/dist/internal/legacy-command-guard.d.ts +2 -0
- package/dist/internal/legacy-command-guard.d.ts.map +1 -1
- package/dist/internal/legacy-command-guard.js +10 -1
- package/dist/internal/mcp-host.d.ts +6 -0
- package/dist/internal/mcp-host.d.ts.map +1 -1
- package/dist/internal/mcp-host.js +35 -16
- package/dist/internal/sdk-runner.d.ts +2 -0
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +10 -0
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +11 -1
- package/dist/internal/session-engine.d.ts +1 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +33 -8
- package/dist/playground/assets/index-6BbTPnaT.css +1 -0
- package/dist/playground/assets/{index-FFdUqTt_.js → index-CI7FAmOP.js} +43 -43
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +50 -4
- package/dist/types.d.ts.map +1 -1
- package/docs/deployment.md +45 -15
- package/docs/guides/github.md +34 -0
- package/docs/guides/slack.md +5 -0
- package/docs/quickstart.md +7 -1
- package/docs/reference/artifacts.md +1 -1
- package/docs/reference/cli.md +65 -63
- package/docs/reference/connections.md +28 -2
- package/docs/reference/evals.md +6 -7
- package/docs/reference/hooks.md +3 -2
- package/docs/reference/sessions.md +4 -3
- package/docs/troubleshooting.md +7 -3
- package/package.json +2 -4
- package/scripts/install-cursor-skills.mjs +1 -1
- package/skills/create-agent/SKILL.md +1 -1
- package/skills/debug/SKILL.md +1 -1
- package/skills/deploy/SKILL.md +1 -1
- package/skills/evals/SKILL.md +1 -1
- package/skills/framework-map/SKILL.md +1 -1
- package/skills/github/SKILL.md +1 -1
- package/skills/hillclimb/SKILL.md +1 -1
- package/skills/mcp-auth/SKILL.md +1 -1
- package/skills/otel/SKILL.md +1 -1
- package/skills/setup-slack/SKILL.md +1 -1
- package/src/artifacts.ts +5 -2
- package/src/bin/agent-serve.ts +27 -6
- package/src/channels/github/auth.ts +44 -5
- package/src/channels/slack/manifest.ts +2 -1
- package/src/channels/slack/types.ts +6 -1
- package/src/connections.ts +1 -1
- package/src/extensions/cursor-cloud-agents/extension.ts +23 -6
- package/src/extensions/cursor-cloud-agents/lib/channels.ts +11 -0
- package/src/extensions/cursor-cloud-agents/lib/repos.ts +19 -7
- package/src/extensions/cursor-cloud-agents/tools/cancel.ts +2 -0
- package/src/extensions/cursor-cloud-agents/tools/launch.ts +3 -1
- package/src/extensions/cursor-cloud-agents/tools/reply.ts +2 -0
- package/src/extensions/cursor-grokbot-agents/extension.ts +132 -0
- package/src/extensions/cursor-grokbot-agents/lib/agents.ts +42 -0
- package/src/extensions/cursor-grokbot-agents/lib/backend.ts +208 -0
- package/src/extensions/cursor-grokbot-agents/lib/contacts.ts +74 -0
- package/src/extensions/cursor-grokbot-agents/lib/conversation.ts +260 -0
- package/src/extensions/cursor-grokbot-agents/lib/inputs.ts +21 -0
- package/src/extensions/cursor-grokbot-agents/lib/lock.ts +26 -0
- package/src/extensions/cursor-grokbot-agents/skills/consult.md +40 -0
- package/src/extensions/cursor-grokbot-agents/tools/ask.ts +32 -0
- package/src/extensions/cursor-grokbot-agents/tools/check.ts +25 -0
- package/src/extensions/cursor-grokbot-agents/tools/interrupt.ts +17 -0
- package/src/extensions/cursor-grokbot-agents/tools/list.ts +26 -0
- package/src/files-backends/cursor-hosted.ts +4 -4
- package/src/internal/artifacts-store.ts +14 -3
- package/src/internal/cli-ax.ts +52 -7
- package/src/internal/cli-deploy.ts +39 -6
- package/src/internal/cli-mcp-oauth.ts +2 -1
- package/src/internal/cli-skills.ts +4 -5
- package/src/internal/connection-env.ts +106 -0
- package/src/internal/cursor/backend-client.ts +6 -0
- package/src/internal/deploy-client.ts +79 -9
- package/src/internal/discovery/connections.ts +11 -0
- package/src/internal/event-mapper.ts +367 -36
- package/src/internal/hosted-delivery-protocol.ts +57 -20
- package/src/internal/hosted-delivery.ts +487 -229
- package/src/internal/hosting.ts +10 -3
- package/src/internal/install-cursor-skills.ts +56 -53
- package/src/internal/legacy-command-guard.ts +13 -1
- package/src/internal/mcp-host.ts +45 -17
- package/src/internal/sdk-runner.ts +11 -0
- package/src/internal/server.ts +13 -1
- package/src/internal/session-engine.ts +33 -13
- package/src/types.ts +56 -5
- package/templates/agents-md/bot/lib/collect.ts +1 -4
- package/templates/code-wiki/bot/channels/github.ts +2 -2
- package/templates/demo/bot/channels/github.ts +5 -1
- package/templates/pr-autofixer/bot/lib/start-drive.ts +4 -4
- package/templates/triage/bot/lib/types.ts +6 -6
- package/dist/docs/assets/chunks/@localSearchIndexroot.Caw9W1pM.js +0 -1
- package/dist/docs/assets/chunks/channel.Sapo9HJZ.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.NPiy3Hz7.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.NPiy3Hz7.js +0 -1
- package/dist/docs/assets/chunks/clone.zl2qolPE.js +0 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2._auCa3fR.js +0 -1
- package/dist/docs/assets/reference_cli.md.BK2QUH67.js +0 -97
- package/dist/docs/assets/reference_cli.md.BK2QUH67.lean.js +0 -1
- package/dist/docs/assets/troubleshooting.md.BzZSu1Gz.js +0 -1
- package/dist/playground/assets/index-BMV_IcEE.css +0 -1
- /package/dist/docs/assets/{reference_artifacts.md.IFFC5Zln.lean.js → reference_artifacts.md.CQfKq8F2.lean.js} +0 -0
- /package/dist/docs/assets/{reference_hooks.md.Dg3dEugd.lean.js → reference_hooks.md.DbthhtIR.lean.js} +0 -0
- /package/dist/docs/assets/{reference_sessions.md.BtpTjZmh.lean.js → reference_sessions.md.DeRUItHD.lean.js} +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/v0/grokbot` session API as the tools use it: the same four routes
|
|
3
|
+
* the grokbot runtime drives, on the external API host (`api.cursor.com`;
|
|
4
|
+
* they 404 on api2), under the host's Cursor API key. A session is a hosted
|
|
5
|
+
* Grok Bot agent of the key's account, get-or-created by name; messages go
|
|
6
|
+
* into its one conversation, and the transcript is read back as entries
|
|
7
|
+
* after a cursor, with the turn's status alongside.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import {
|
|
13
|
+
cursorExternalApiUrl,
|
|
14
|
+
resolveApiKeySync,
|
|
15
|
+
SIGN_IN_HINT,
|
|
16
|
+
} from "../../../internal/cursor/credentials.js";
|
|
17
|
+
import extension from "../extension.js";
|
|
18
|
+
|
|
19
|
+
const REQUEST_TIMEOUT_MS = 60_000;
|
|
20
|
+
|
|
21
|
+
export class GrokBotApiError extends Error {
|
|
22
|
+
constructor(
|
|
23
|
+
message: string,
|
|
24
|
+
readonly status?: number,
|
|
25
|
+
) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "GrokBotApiError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Type aliases, not interfaces: these flow into tool results.
|
|
32
|
+
export type GrokBotSession = {
|
|
33
|
+
/** The hosted agent's durable id; every other route addresses it. */
|
|
34
|
+
sessionId: string;
|
|
35
|
+
/** The name as the backend stores it (trimmed). */
|
|
36
|
+
name: string;
|
|
37
|
+
createdAtMs: number;
|
|
38
|
+
/** Transcript tail: reading after it skips the conversation's history. */
|
|
39
|
+
latestUpdatedSeq: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type GrokBotEntry = {
|
|
43
|
+
seq: string;
|
|
44
|
+
updatedSeq: string;
|
|
45
|
+
kind: string;
|
|
46
|
+
role?: string;
|
|
47
|
+
text?: string;
|
|
48
|
+
createdAtMs: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type GrokBotTurnStatus = {
|
|
52
|
+
idle: boolean;
|
|
53
|
+
inFlight: boolean;
|
|
54
|
+
queued: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type GrokBotEntriesPage = {
|
|
58
|
+
entries: GrokBotEntry[];
|
|
59
|
+
latestUpdatedSeq: string;
|
|
60
|
+
turn: GrokBotTurnStatus;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const sessionSchema = z.object({
|
|
64
|
+
id: z.string(),
|
|
65
|
+
name: z.string(),
|
|
66
|
+
createdAtMs: z.number(),
|
|
67
|
+
latestUpdatedSeq: z.string(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const sendSchema = z.object({
|
|
71
|
+
messageId: z.string(),
|
|
72
|
+
delivery: z.string(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const entriesSchema: z.ZodType<GrokBotEntriesPage> = z.object({
|
|
76
|
+
entries: z.array(
|
|
77
|
+
z.object({
|
|
78
|
+
seq: z.string(),
|
|
79
|
+
updatedSeq: z.string(),
|
|
80
|
+
kind: z.string(),
|
|
81
|
+
role: z.string().optional(),
|
|
82
|
+
text: z.string().optional(),
|
|
83
|
+
createdAtMs: z.number(),
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
latestUpdatedSeq: z.string(),
|
|
87
|
+
turn: z.object({
|
|
88
|
+
idle: z.boolean(),
|
|
89
|
+
inFlight: z.boolean(),
|
|
90
|
+
queued: z.number(),
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export class GrokBotAgentsBackend {
|
|
95
|
+
constructor(
|
|
96
|
+
private readonly apiKey: () => string,
|
|
97
|
+
private readonly fetchImpl: typeof fetch = fetch,
|
|
98
|
+
) {}
|
|
99
|
+
|
|
100
|
+
/** `POST /v0/grokbot/sessions`: the account's agent of that name, created when missing. */
|
|
101
|
+
async session(name: string): Promise<GrokBotSession> {
|
|
102
|
+
// No `instructions`: the agent is somebody's, configured in the app, and
|
|
103
|
+
// an omitted field never touches its stored profile.
|
|
104
|
+
const parsed = sessionSchema.parse(
|
|
105
|
+
await this.request("POST", "/v0/grokbot/sessions", { name }),
|
|
106
|
+
);
|
|
107
|
+
return {
|
|
108
|
+
sessionId: parsed.id,
|
|
109
|
+
name: parsed.name,
|
|
110
|
+
createdAtMs: parsed.createdAtMs,
|
|
111
|
+
latestUpdatedSeq: parsed.latestUpdatedSeq,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Deliver one user message to the agent's conversation. */
|
|
116
|
+
async send(sessionId: string, text: string): Promise<void> {
|
|
117
|
+
const { delivery } = sendSchema.parse(
|
|
118
|
+
await this.request("POST", `/v0/grokbot/sessions/${sessionId}/messages`, {
|
|
119
|
+
text,
|
|
120
|
+
messageId: randomUUID(),
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
if (delivery !== "accepted_temporal" && delivery !== "duplicate") {
|
|
124
|
+
throw new GrokBotApiError(
|
|
125
|
+
`The Grok Bot agent's harness did not accept the message (delivery: ${delivery}).`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Transcript entries after `afterUpdatedSeq`, oldest first, with the turn's status. */
|
|
131
|
+
async entries(sessionId: string, afterUpdatedSeq: string): Promise<GrokBotEntriesPage> {
|
|
132
|
+
return entriesSchema.parse(
|
|
133
|
+
await this.request(
|
|
134
|
+
"GET",
|
|
135
|
+
`/v0/grokbot/sessions/${sessionId}/entries?afterUpdatedSeq=${encodeURIComponent(afterUpdatedSeq)}`,
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async interrupt(sessionId: string, reason: string): Promise<void> {
|
|
141
|
+
await this.request("POST", `/v0/grokbot/sessions/${sessionId}/interrupt`, {
|
|
142
|
+
reason,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private async request(method: "GET" | "POST", path: string, body?: unknown): Promise<unknown> {
|
|
147
|
+
const headers: Record<string, string> = {
|
|
148
|
+
authorization: `Bearer ${this.apiKey()}`,
|
|
149
|
+
"x-cursor-client-type": "agent-serve",
|
|
150
|
+
"x-request-id": randomUUID(),
|
|
151
|
+
};
|
|
152
|
+
if (body !== undefined) {
|
|
153
|
+
headers["content-type"] = "application/json";
|
|
154
|
+
}
|
|
155
|
+
let response: Response;
|
|
156
|
+
try {
|
|
157
|
+
response = await this.fetchImpl(`${cursorExternalApiUrl()}${path}`, {
|
|
158
|
+
method,
|
|
159
|
+
headers,
|
|
160
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
161
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw new GrokBotApiError(
|
|
165
|
+
`Grok Bot API ${method} ${path} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
const text = await response.text();
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new GrokBotApiError(
|
|
171
|
+
`Grok Bot API ${method} ${path} failed (${response.status}): ${apiErrorMessage(text)}`,
|
|
172
|
+
response.status,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return JSON.parse(text) as unknown;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let backend: GrokBotAgentsBackend | undefined;
|
|
180
|
+
|
|
181
|
+
/** The process-wide backend for this mount, built on first use. */
|
|
182
|
+
export function grokBotAgentsBackend(): GrokBotAgentsBackend {
|
|
183
|
+
backend ??= new GrokBotAgentsBackend(apiKey);
|
|
184
|
+
return backend;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function apiKey(): string {
|
|
188
|
+
// Read per call: the host can sign in after the mount.
|
|
189
|
+
const key = resolveApiKeySync({ apiKey: extension.config.apiKey });
|
|
190
|
+
if (key === undefined) {
|
|
191
|
+
throw new Error(`Grok Bot agents need a Cursor API key. ${SIGN_IN_HINT}`);
|
|
192
|
+
}
|
|
193
|
+
return key.apiKey;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The route's `{ error }` envelope when it is one, the raw body otherwise. */
|
|
197
|
+
function apiErrorMessage(text: string): string {
|
|
198
|
+
try {
|
|
199
|
+
const parsed = JSON.parse(text) as { error?: unknown; message?: unknown };
|
|
200
|
+
const message = parsed.error ?? parsed.message;
|
|
201
|
+
if (typeof message === "string" && message !== "") {
|
|
202
|
+
return message;
|
|
203
|
+
}
|
|
204
|
+
} catch {
|
|
205
|
+
// Not JSON; fall through to the raw body.
|
|
206
|
+
}
|
|
207
|
+
return text.slice(0, 300);
|
|
208
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who has talked to which Grok Bot agent, and how far into its transcript
|
|
3
|
+
* they have read. The tools authenticate with the serve host's one Cursor
|
|
4
|
+
* API key, so every agent is that account's; what the host keeps per
|
|
5
|
+
* principal is the read cursor, so `check` returns what the agent said
|
|
6
|
+
* since that caller last read, and a lookup by name for `check` and
|
|
7
|
+
* `interrupt`, which never create an agent the caller has not spoken to.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import type { ToolContext } from "../../../types.js";
|
|
12
|
+
import { KeyedLock } from "./lock.js";
|
|
13
|
+
|
|
14
|
+
const PREFIX = "grokbot-agents";
|
|
15
|
+
|
|
16
|
+
// Type alias, not an interface: contacts flow into tool results.
|
|
17
|
+
export type Contact = {
|
|
18
|
+
/** The agent's name as the backend stores it. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The hosted agent's `/v0/grokbot` session id. */
|
|
21
|
+
sessionId: string;
|
|
22
|
+
/** Newest transcript `updatedSeq` this principal has read. */
|
|
23
|
+
cursor: string;
|
|
24
|
+
firstContactAt: string;
|
|
25
|
+
lastContactAt: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const contactsSchema: z.ZodType<Contact[]> = z.array(
|
|
29
|
+
z.object({
|
|
30
|
+
name: z.string(),
|
|
31
|
+
sessionId: z.string(),
|
|
32
|
+
cursor: z.string(),
|
|
33
|
+
firstContactAt: z.string(),
|
|
34
|
+
lastContactAt: z.string(),
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const locks = new KeyedLock();
|
|
39
|
+
|
|
40
|
+
/** Unauthenticated sessions (local dev, direct calls) share one principal. */
|
|
41
|
+
export function principalOf(ctx: ToolContext): string {
|
|
42
|
+
const auth = ctx.session.auth;
|
|
43
|
+
return auth === null ? "anonymous" : `${auth.principalType}:${auth.principalId}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The caller's contacts, most recently spoken to first. */
|
|
47
|
+
export async function listContacts(ctx: ToolContext): Promise<Contact[]> {
|
|
48
|
+
const contacts = contactsSchema.safeParse(await ctx.host.kv.get(contactsKey(principalOf(ctx))));
|
|
49
|
+
return contacts.success ? contacts.data : [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The contact of that name, exact spelling first, then case-insensitively. */
|
|
53
|
+
export function findContact(contacts: Contact[], name: string): Contact | undefined {
|
|
54
|
+
const wanted = name.trim();
|
|
55
|
+
return (
|
|
56
|
+
contacts.find(contact => contact.name === wanted) ??
|
|
57
|
+
contacts.find(contact => contact.name.toLowerCase() === wanted.toLowerCase())
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Insert or replace the caller's record of one agent, newest first. */
|
|
62
|
+
export async function saveContact(ctx: ToolContext, contact: Contact): Promise<void> {
|
|
63
|
+
const key = contactsKey(principalOf(ctx));
|
|
64
|
+
await locks.run(key, async () => {
|
|
65
|
+
const others = (await listContacts(ctx)).filter(
|
|
66
|
+
existing => existing.sessionId !== contact.sessionId,
|
|
67
|
+
);
|
|
68
|
+
await ctx.host.kv.put(key, [contact, ...others]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function contactsKey(principal: string): string {
|
|
73
|
+
return `${PREFIX}/principals/${encodeURIComponent(principal)}`;
|
|
74
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One exchange with a hosted Grok Bot agent, the way the grokbot runtime
|
|
3
|
+
* drives a turn: send a user message, then read the transcript until the
|
|
4
|
+
* agent's turn settles. Only `send-message` entries (what the agent delivers
|
|
5
|
+
* through SendToUser) are the reply; its internal work never appears in the
|
|
6
|
+
* transcript. Waits are bounded, so a long turn comes back as `running` and
|
|
7
|
+
* `check` picks it up from the caller's cursor.
|
|
8
|
+
*
|
|
9
|
+
* Sends and reads on one hosted agent are chained within this process, and
|
|
10
|
+
* a send waits for an in-flight turn to settle first, so a reply always
|
|
11
|
+
* attributes to the message that prompted it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ToolContext } from "../../../types.js";
|
|
15
|
+
import extension from "../extension.js";
|
|
16
|
+
import { resolveAgentName } from "./agents.js";
|
|
17
|
+
import {
|
|
18
|
+
type GrokBotAgentsBackend,
|
|
19
|
+
type GrokBotTurnStatus,
|
|
20
|
+
grokBotAgentsBackend,
|
|
21
|
+
} from "./backend.js";
|
|
22
|
+
import { type Contact, findContact, listContacts, saveContact } from "./contacts.js";
|
|
23
|
+
import { KeyedLock } from "./lock.js";
|
|
24
|
+
|
|
25
|
+
export const DEFAULT_WAIT_SECONDS = 120;
|
|
26
|
+
export const MAX_WAIT_SECONDS = 600;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Idle polls required before a turn counts as settled when the workflow
|
|
30
|
+
* never reported busy: covers the window between an accepted send and the
|
|
31
|
+
* workflow picking the signal up, which a `check` right after a short `ask`
|
|
32
|
+
* can still be inside.
|
|
33
|
+
*/
|
|
34
|
+
const MIN_IDLE_POLLS_WITHOUT_BUSY = 4;
|
|
35
|
+
/**
|
|
36
|
+
* A session whose row is this young, and whose transcript is still empty,
|
|
37
|
+
* was created by the call that fetched it; the allowance covers clock skew
|
|
38
|
+
* between this host and the backend.
|
|
39
|
+
*/
|
|
40
|
+
const CREATED_WINDOW_MS = 60_000;
|
|
41
|
+
/** The transcript tail of an agent nobody has spoken to. */
|
|
42
|
+
const EMPTY_TRANSCRIPT_TAIL = "-1";
|
|
43
|
+
|
|
44
|
+
export type ReplyStatus = "finished" | "running";
|
|
45
|
+
|
|
46
|
+
// Type aliases, not interfaces: these are tool results.
|
|
47
|
+
export type AskResult = {
|
|
48
|
+
agent: string;
|
|
49
|
+
sessionId: string;
|
|
50
|
+
status: ReplyStatus;
|
|
51
|
+
/** What the agent sent back, in order; absent when it sent nothing (yet). */
|
|
52
|
+
reply?: string;
|
|
53
|
+
/** Replies to earlier messages that this caller had not read yet. */
|
|
54
|
+
earlierReplies?: string[];
|
|
55
|
+
/** The account had no agent of that name; this call created an empty one. */
|
|
56
|
+
created?: true;
|
|
57
|
+
note?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type CheckResult = {
|
|
61
|
+
agent: string;
|
|
62
|
+
sessionId: string;
|
|
63
|
+
status: ReplyStatus;
|
|
64
|
+
reply?: string;
|
|
65
|
+
note?: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type InterruptResult = {
|
|
69
|
+
agent: string;
|
|
70
|
+
sessionId: string;
|
|
71
|
+
interrupted: true;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
type Replies = {
|
|
75
|
+
status: ReplyStatus;
|
|
76
|
+
deliveries: string[];
|
|
77
|
+
/** Newest `updatedSeq` consumed. */
|
|
78
|
+
cursor: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const agentLocks = new KeyedLock();
|
|
82
|
+
|
|
83
|
+
export async function ask(
|
|
84
|
+
ctx: ToolContext,
|
|
85
|
+
input: { agent?: string; message: string; waitSeconds: number },
|
|
86
|
+
): Promise<AskResult> {
|
|
87
|
+
const name = resolveAgentName(input.agent, extension.config.agents);
|
|
88
|
+
const backend = grokBotAgentsBackend();
|
|
89
|
+
const startedAt = Date.now();
|
|
90
|
+
const session = await backend.session(name);
|
|
91
|
+
return agentLocks.run(session.sessionId, async () => {
|
|
92
|
+
const contact = (await listContacts(ctx)).find(
|
|
93
|
+
candidate => candidate.sessionId === session.sessionId,
|
|
94
|
+
);
|
|
95
|
+
const created =
|
|
96
|
+
contact === undefined &&
|
|
97
|
+
session.latestUpdatedSeq === EMPTY_TRANSCRIPT_TAIL &&
|
|
98
|
+
session.createdAtMs >= startedAt - CREATED_WINDOW_MS;
|
|
99
|
+
const deadline = Date.now() + input.waitSeconds * 1000;
|
|
100
|
+
// A turn already in flight, from an earlier message or from the person
|
|
101
|
+
// in the app, must settle first; otherwise its deliveries would read as
|
|
102
|
+
// the reply to this message. Nothing is persisted on the way out, so
|
|
103
|
+
// `check` still returns whatever landed meanwhile.
|
|
104
|
+
const before = await collectReplies(backend, session.sessionId, {
|
|
105
|
+
cursor: contact?.cursor ?? session.latestUpdatedSeq,
|
|
106
|
+
deadline,
|
|
107
|
+
confirmIdle: false,
|
|
108
|
+
});
|
|
109
|
+
if (before.status === "running") {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`"${session.name}" is still working on an earlier message; nothing was sent. Call check to read that reply, wait, or interrupt it.`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
await backend.send(session.sessionId, input.message);
|
|
115
|
+
const replies = await collectReplies(backend, session.sessionId, {
|
|
116
|
+
cursor: before.cursor,
|
|
117
|
+
deadline,
|
|
118
|
+
confirmIdle: true,
|
|
119
|
+
});
|
|
120
|
+
const now = ctx.now().toISOString();
|
|
121
|
+
await saveContact(ctx, {
|
|
122
|
+
name: session.name,
|
|
123
|
+
sessionId: session.sessionId,
|
|
124
|
+
cursor: replies.cursor,
|
|
125
|
+
firstContactAt: contact?.firstContactAt ?? now,
|
|
126
|
+
lastContactAt: now,
|
|
127
|
+
});
|
|
128
|
+
const notes = [
|
|
129
|
+
created
|
|
130
|
+
? `No Grok Bot agent named "${session.name}" existed on this account, so an empty one was created. Check the name if that is unexpected.`
|
|
131
|
+
: undefined,
|
|
132
|
+
runningNote(session.name, replies.status),
|
|
133
|
+
].filter(note => note !== undefined);
|
|
134
|
+
return {
|
|
135
|
+
agent: session.name,
|
|
136
|
+
sessionId: session.sessionId,
|
|
137
|
+
status: replies.status,
|
|
138
|
+
reply: joinReplies(replies.deliveries),
|
|
139
|
+
earlierReplies: before.deliveries.length === 0 ? undefined : before.deliveries,
|
|
140
|
+
created: created ? true : undefined,
|
|
141
|
+
note: notes.length === 0 ? undefined : notes.join(" "),
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function check(
|
|
147
|
+
ctx: ToolContext,
|
|
148
|
+
input: { agent?: string; waitSeconds: number },
|
|
149
|
+
): Promise<CheckResult> {
|
|
150
|
+
const contact = await knownContact(ctx, input.agent);
|
|
151
|
+
const backend = grokBotAgentsBackend();
|
|
152
|
+
return agentLocks.run(contact.sessionId, async () => {
|
|
153
|
+
// Re-read under the lock: a parallel call may have moved the cursor.
|
|
154
|
+
const current =
|
|
155
|
+
(await listContacts(ctx)).find(candidate => candidate.sessionId === contact.sessionId) ??
|
|
156
|
+
contact;
|
|
157
|
+
const replies = await collectReplies(backend, current.sessionId, {
|
|
158
|
+
cursor: current.cursor,
|
|
159
|
+
deadline: Date.now() + input.waitSeconds * 1000,
|
|
160
|
+
confirmIdle: true,
|
|
161
|
+
});
|
|
162
|
+
await saveContact(ctx, { ...current, cursor: replies.cursor });
|
|
163
|
+
return {
|
|
164
|
+
agent: current.name,
|
|
165
|
+
sessionId: current.sessionId,
|
|
166
|
+
status: replies.status,
|
|
167
|
+
reply: joinReplies(replies.deliveries),
|
|
168
|
+
note: runningNote(current.name, replies.status),
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function interrupt(
|
|
174
|
+
ctx: ToolContext,
|
|
175
|
+
input: { agent?: string },
|
|
176
|
+
): Promise<InterruptResult> {
|
|
177
|
+
const contact = await knownContact(ctx, input.agent);
|
|
178
|
+
await grokBotAgentsBackend().interrupt(contact.sessionId, "Interrupted from the Agent SDK.");
|
|
179
|
+
return {
|
|
180
|
+
agent: contact.name,
|
|
181
|
+
sessionId: contact.sessionId,
|
|
182
|
+
interrupted: true,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The caller's record of the named agent. Only `ask` resolves a name on the
|
|
188
|
+
* backend, because that creates an agent when none matches; the other tools
|
|
189
|
+
* reach agents the caller has already spoken to.
|
|
190
|
+
*/
|
|
191
|
+
async function knownContact(ctx: ToolContext, requested: string | undefined): Promise<Contact> {
|
|
192
|
+
const name = resolveAgentName(requested, extension.config.agents);
|
|
193
|
+
const contact = findContact(await listContacts(ctx), name);
|
|
194
|
+
if (contact === undefined) {
|
|
195
|
+
throw new Error(`You have not asked "${name}" anything yet; call ask first.`);
|
|
196
|
+
}
|
|
197
|
+
return contact;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Read the transcript after `cursor` until the agent's turn settles or the
|
|
202
|
+
* deadline passes. Only an empty page can settle the turn, so a backlog
|
|
203
|
+
* drains page by page first. With `confirmIdle`, an idle report may predate
|
|
204
|
+
* the workflow picking a message up, so settling takes
|
|
205
|
+
* {@link MIN_IDLE_POLLS_WITHOUT_BUSY} idle polls unless the turn was seen
|
|
206
|
+
* busy; without it, the first idle report settles.
|
|
207
|
+
*/
|
|
208
|
+
async function collectReplies(
|
|
209
|
+
backend: GrokBotAgentsBackend,
|
|
210
|
+
sessionId: string,
|
|
211
|
+
options: { cursor: string; deadline: number; confirmIdle: boolean },
|
|
212
|
+
): Promise<Replies> {
|
|
213
|
+
const deliveries: string[] = [];
|
|
214
|
+
let cursor = options.cursor;
|
|
215
|
+
let sawBusy = false;
|
|
216
|
+
let idlePolls = 0;
|
|
217
|
+
while (true) {
|
|
218
|
+
const page = await backend.entries(sessionId, cursor);
|
|
219
|
+
cursor = page.latestUpdatedSeq;
|
|
220
|
+
for (const entry of page.entries) {
|
|
221
|
+
if (entry.kind === "send-message" && entry.text !== undefined) {
|
|
222
|
+
deliveries.push(entry.text);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const busy = isBusy(page.turn);
|
|
226
|
+
if (busy) {
|
|
227
|
+
sawBusy = true;
|
|
228
|
+
}
|
|
229
|
+
if (page.entries.length === 0 && !busy && page.turn.idle) {
|
|
230
|
+
idlePolls += 1;
|
|
231
|
+
if (sawBusy || !options.confirmIdle || idlePolls >= MIN_IDLE_POLLS_WITHOUT_BUSY) {
|
|
232
|
+
return { status: "finished", deliveries, cursor };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (Date.now() >= options.deadline) {
|
|
236
|
+
return { status: "running", deliveries, cursor };
|
|
237
|
+
}
|
|
238
|
+
await sleep(extension.config.pollIntervalMs);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function isBusy(turn: GrokBotTurnStatus): boolean {
|
|
243
|
+
return turn.inFlight || turn.queued > 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function joinReplies(deliveries: string[]): string | undefined {
|
|
247
|
+
return deliveries.length === 0 ? undefined : deliveries.join("\n\n");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function runningNote(name: string, status: ReplyStatus): string | undefined {
|
|
251
|
+
return status === "running"
|
|
252
|
+
? `"${name}" is still replying. Call check with the same agent to keep waiting; a reply so far, if any, is above.`
|
|
253
|
+
: undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function sleep(ms: number): Promise<void> {
|
|
257
|
+
return new Promise(resolve => {
|
|
258
|
+
setTimeout(resolve, ms);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AGENT_NAME_MAX_LENGTH } from "../extension.js";
|
|
3
|
+
import { DEFAULT_WAIT_SECONDS, MAX_WAIT_SECONDS } from "./conversation.js";
|
|
4
|
+
|
|
5
|
+
export const agentName: z.ZodOptional<z.ZodString> = z
|
|
6
|
+
.string()
|
|
7
|
+
.max(AGENT_NAME_MAX_LENGTH)
|
|
8
|
+
.optional()
|
|
9
|
+
.describe(
|
|
10
|
+
"The Grok Bot agent's name, as shown in the Grok Bot app. With agents configured, one of those; optional when exactly one is configured.",
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const waitSeconds: z.ZodDefault<z.ZodNumber> = z
|
|
14
|
+
.number()
|
|
15
|
+
.int()
|
|
16
|
+
.min(0)
|
|
17
|
+
.max(MAX_WAIT_SECONDS)
|
|
18
|
+
.default(DEFAULT_WAIT_SECONDS)
|
|
19
|
+
.describe(
|
|
20
|
+
`How long to wait for the reply before returning status "running" (default ${DEFAULT_WAIT_SECONDS}, max ${MAX_WAIT_SECONDS}). 0 returns after one look.`,
|
|
21
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-key chaining of async work. `host.kv` has no compare-and-swap, and a
|
|
3
|
+
* model that talks to two agents in one turn calls these tools in parallel,
|
|
4
|
+
* so read-modify-writes of one principal's records queue up here. The same
|
|
5
|
+
* chain keeps one hosted agent's sends and reads from interleaving within
|
|
6
|
+
* this process, so a reply attributes to the message that prompted it.
|
|
7
|
+
*/
|
|
8
|
+
export class KeyedLock {
|
|
9
|
+
private readonly chains = new Map<string, Promise<void>>();
|
|
10
|
+
|
|
11
|
+
run<T>(key: string, task: () => Promise<T>): Promise<T> {
|
|
12
|
+
const previous = this.chains.get(key) ?? Promise.resolve();
|
|
13
|
+
const run = previous.then(task, task);
|
|
14
|
+
const settled = run.then(
|
|
15
|
+
() => undefined,
|
|
16
|
+
() => undefined,
|
|
17
|
+
);
|
|
18
|
+
this.chains.set(key, settled);
|
|
19
|
+
void settled.then(() => {
|
|
20
|
+
if (this.chains.get(key) === settled) {
|
|
21
|
+
this.chains.delete(key);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return run;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Talk to your Grok Bot agents: when to bring one in, how to write a message it can act on alone, and how to wait for, read, and interrupt its reply."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Consulting a Grok Bot agent
|
|
6
|
+
|
|
7
|
+
Bring a Grok Bot agent in when the person set one up for the job: a specialist with its own instructions, memory, and tools, such as one that decides whether an outdoor plan survives a forecast or one that keeps a household's calendar. Answer questions you can answer yourself.
|
|
8
|
+
|
|
9
|
+
The tools below are this extension's; they appear under its mount namespace, as `<namespace>__ask` and so on. Every agent is addressed by its `agent` name, as it appears in the Grok Bot app. When exactly one agent is configured, `agent` can be omitted.
|
|
10
|
+
|
|
11
|
+
## Write for a stranger
|
|
12
|
+
|
|
13
|
+
Your message lands in the person's own conversation with that agent, the same one they see in the app. The agent does not see this conversation, your tools, or your earlier results. Say who is asking and why, paste the facts it needs rather than referring to them, and say what you want back and in what shape. One complete message beats a back-and-forth.
|
|
14
|
+
|
|
15
|
+
## Ask
|
|
16
|
+
|
|
17
|
+
Call `ask` with the `agent` and the `message`. It sends the message and waits up to `wait_seconds` for the agent's turn to finish. The result carries `status`, the `reply` (everything the agent sent back during that turn, in order), and `sessionId`.
|
|
18
|
+
|
|
19
|
+
- `status: "finished"`: the turn is over; `reply` is the whole answer. No `reply` means the agent finished without sending anything.
|
|
20
|
+
- `status: "running"`: the agent is still working. Call `check` with the same `agent` to keep waiting; whatever it had sent so far is already in `reply`.
|
|
21
|
+
|
|
22
|
+
If `earlierReplies` is present, the agent had answered earlier messages that nobody read yet; pass them on when they matter, and do not mistake them for the reply to this message.
|
|
23
|
+
|
|
24
|
+
If `created` is true, no agent of that name existed on the account and an empty one was created. Tell the person and check the spelling before asking it anything else.
|
|
25
|
+
|
|
26
|
+
If `ask` fails because an agent of that name already exists in the Grok Bot app, nothing was created and nothing was sent. Tell the person. Do not invent a different name to get around it.
|
|
27
|
+
|
|
28
|
+
If `ask` refuses because the agent is still working on an earlier message, nothing was sent. If you have already asked that agent, call `check` to read the reply, then ask again; use `interrupt` when the earlier work should stop. On first contact, `check` and `interrupt` cannot address the agent yet, so tell the person it is busy, wait for the existing turn to finish in the Grok Bot app, and retry `ask`.
|
|
29
|
+
|
|
30
|
+
## Wait for a long reply
|
|
31
|
+
|
|
32
|
+
Call `check` with the `agent`. It returns what the agent has sent since you last read, and `status: "running"` while the turn is still going. Pass `wait_seconds: 0` for a single look. Check when you need the answer, not in a tight loop; a long task can take minutes.
|
|
33
|
+
|
|
34
|
+
## Interrupt
|
|
35
|
+
|
|
36
|
+
Call `interrupt` with the `agent` to stop its current turn. The agent keeps its conversation, so a later `ask` continues from there.
|
|
37
|
+
|
|
38
|
+
## Which agents
|
|
39
|
+
|
|
40
|
+
`list` returns the agents configured for you, with what each is for, and the ones you have already asked. Names outside the configured set are refused; with no set configured, any name works, and an unknown name creates an agent.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineTool } from "../../../tools.js";
|
|
3
|
+
import type { ToolDefinition } from "../../../types.js";
|
|
4
|
+
import extension from "../extension.js";
|
|
5
|
+
import { ask as askAgent } from "../lib/conversation.js";
|
|
6
|
+
import { agentName, waitSeconds } from "../lib/inputs.js";
|
|
7
|
+
|
|
8
|
+
const ask: ToolDefinition = defineTool({
|
|
9
|
+
description:
|
|
10
|
+
'Send a message to one of your Grok Bot agents and wait for its reply. The message lands in your own conversation with that agent, which does not see this one, so include everything it needs. Long turns return status "running": call check to keep waiting.',
|
|
11
|
+
effect: "write",
|
|
12
|
+
needsApproval: () => extension.config.needsApproval,
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
agent: agentName,
|
|
15
|
+
message: z
|
|
16
|
+
.string()
|
|
17
|
+
.min(1)
|
|
18
|
+
.describe(
|
|
19
|
+
"What to tell or ask the agent. Self-contained: who is asking, the facts it needs, and what you want back.",
|
|
20
|
+
),
|
|
21
|
+
wait_seconds: waitSeconds,
|
|
22
|
+
}),
|
|
23
|
+
async execute(input, ctx) {
|
|
24
|
+
return askAgent(ctx, {
|
|
25
|
+
agent: input.agent,
|
|
26
|
+
message: input.message,
|
|
27
|
+
waitSeconds: input.wait_seconds,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export default ask;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineTool } from "../../../tools.js";
|
|
3
|
+
import type { ToolDefinition } from "../../../types.js";
|
|
4
|
+
import { check as checkAgent } from "../lib/conversation.js";
|
|
5
|
+
import { agentName, waitSeconds } from "../lib/inputs.js";
|
|
6
|
+
|
|
7
|
+
const check: ToolDefinition = defineTool({
|
|
8
|
+
description:
|
|
9
|
+
'Wait for, or poll, the reply of a Grok Bot agent you asked: everything it has sent since you last read, and whether it is still working. Returns status "running" to keep waiting; pass wait_seconds 0 for a single look.',
|
|
10
|
+
// Reading advances the caller's cursor, which their other sessions read
|
|
11
|
+
// back, so a dry run answers this instead of running it.
|
|
12
|
+
effect: "write",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
agent: agentName,
|
|
15
|
+
wait_seconds: waitSeconds,
|
|
16
|
+
}),
|
|
17
|
+
async execute(input, ctx) {
|
|
18
|
+
return checkAgent(ctx, {
|
|
19
|
+
agent: input.agent,
|
|
20
|
+
waitSeconds: input.wait_seconds,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export default check;
|