workos 0.19.0 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -646
- package/bin/workos.js +44 -0
- package/package.json +18 -99
- package/LICENSE +0 -47
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +0 -1790
- package/dist/bin.js.map +0 -1
- package/dist/cli.config.d.ts +0 -88
- package/dist/cli.config.js +0 -110
- package/dist/cli.config.js.map +0 -1
- package/dist/commands/api/catalog.d.ts +0 -23
- package/dist/commands/api/catalog.js +0 -97
- package/dist/commands/api/catalog.js.map +0 -1
- package/dist/commands/api/format.d.ts +0 -5
- package/dist/commands/api/format.js +0 -46
- package/dist/commands/api/format.js.map +0 -1
- package/dist/commands/api/index.d.ts +0 -15
- package/dist/commands/api/index.js +0 -213
- package/dist/commands/api/index.js.map +0 -1
- package/dist/commands/api/interactive.d.ts +0 -3
- package/dist/commands/api/interactive.js +0 -133
- package/dist/commands/api/interactive.js.map +0 -1
- package/dist/commands/api/request.d.ts +0 -14
- package/dist/commands/api/request.js +0 -38
- package/dist/commands/api/request.js.map +0 -1
- package/dist/commands/api-key-mgmt.d.ts +0 -16
- package/dist/commands/api-key-mgmt.js +0 -96
- package/dist/commands/api-key-mgmt.js.map +0 -1
- package/dist/commands/audit-log.d.ts +0 -26
- package/dist/commands/audit-log.js +0 -155
- package/dist/commands/audit-log.js.map +0 -1
- package/dist/commands/auth-status.d.ts +0 -1
- package/dist/commands/auth-status.js +0 -57
- package/dist/commands/auth-status.js.map +0 -1
- package/dist/commands/claim.d.ts +0 -11
- package/dist/commands/claim.js +0 -143
- package/dist/commands/claim.js.map +0 -1
- package/dist/commands/config.d.ts +0 -3
- package/dist/commands/config.js +0 -54
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/connection.d.ts +0 -13
- package/dist/commands/connection.js +0 -96
- package/dist/commands/connection.js.map +0 -1
- package/dist/commands/debug-sso.d.ts +0 -1
- package/dist/commands/debug-sso.js +0 -78
- package/dist/commands/debug-sso.js.map +0 -1
- package/dist/commands/debug-sync.d.ts +0 -1
- package/dist/commands/debug-sync.js +0 -102
- package/dist/commands/debug-sync.js.map +0 -1
- package/dist/commands/debug.d.ts +0 -28
- package/dist/commands/debug.js +0 -406
- package/dist/commands/debug.js.map +0 -1
- package/dist/commands/dev.d.ts +0 -22
- package/dist/commands/dev.js +0 -145
- package/dist/commands/dev.js.map +0 -1
- package/dist/commands/directory.d.ts +0 -27
- package/dist/commands/directory.js +0 -176
- package/dist/commands/directory.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -12
- package/dist/commands/doctor.js +0 -41
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/emulate.d.ts +0 -7
- package/dist/commands/emulate.js +0 -69
- package/dist/commands/emulate.js.map +0 -1
- package/dist/commands/env.d.ts +0 -19
- package/dist/commands/env.js +0 -303
- package/dist/commands/env.js.map +0 -1
- package/dist/commands/event.d.ts +0 -9
- package/dist/commands/event.js +0 -43
- package/dist/commands/event.js.map +0 -1
- package/dist/commands/feature-flag.d.ts +0 -12
- package/dist/commands/feature-flag.js +0 -96
- package/dist/commands/feature-flag.js.map +0 -1
- package/dist/commands/install-skill.d.ts +0 -85
- package/dist/commands/install-skill.js +0 -332
- package/dist/commands/install-skill.js.map +0 -1
- package/dist/commands/install.d.ts +0 -6
- package/dist/commands/install.js +0 -51
- package/dist/commands/install.js.map +0 -1
- package/dist/commands/invitation.d.ts +0 -19
- package/dist/commands/invitation.js +0 -94
- package/dist/commands/invitation.js.map +0 -1
- package/dist/commands/list-skills.d.ts +0 -4
- package/dist/commands/list-skills.js +0 -52
- package/dist/commands/list-skills.js.map +0 -1
- package/dist/commands/login.d.ts +0 -32
- package/dist/commands/login.js +0 -239
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -17
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -14
- package/dist/commands/mcp.js +0 -99
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/membership.d.ts +0 -20
- package/dist/commands/membership.js +0 -129
- package/dist/commands/membership.js.map +0 -1
- package/dist/commands/migrations.d.ts +0 -2
- package/dist/commands/migrations.js +0 -50
- package/dist/commands/migrations.js.map +0 -1
- package/dist/commands/onboard-user.d.ts +0 -7
- package/dist/commands/onboard-user.js +0 -61
- package/dist/commands/onboard-user.js.map +0 -1
- package/dist/commands/org-domain.d.ts +0 -4
- package/dist/commands/org-domain.js +0 -45
- package/dist/commands/org-domain.js.map +0 -1
- package/dist/commands/organization.d.ts +0 -14
- package/dist/commands/organization.js +0 -103
- package/dist/commands/organization.js.map +0 -1
- package/dist/commands/permission.d.ts +0 -20
- package/dist/commands/permission.js +0 -93
- package/dist/commands/permission.js.map +0 -1
- package/dist/commands/portal.d.ts +0 -7
- package/dist/commands/portal.js +0 -26
- package/dist/commands/portal.js.map +0 -1
- package/dist/commands/role.d.ts +0 -17
- package/dist/commands/role.js +0 -122
- package/dist/commands/role.js.map +0 -1
- package/dist/commands/seed.d.ts +0 -6
- package/dist/commands/seed.js +0 -298
- package/dist/commands/seed.js.map +0 -1
- package/dist/commands/session.d.ts +0 -8
- package/dist/commands/session.js +0 -63
- package/dist/commands/session.js.map +0 -1
- package/dist/commands/setup-org.d.ts +0 -6
- package/dist/commands/setup-org.js +0 -99
- package/dist/commands/setup-org.js.map +0 -1
- package/dist/commands/setup.d.ts +0 -50
- package/dist/commands/setup.js +0 -237
- package/dist/commands/setup.js.map +0 -1
- package/dist/commands/telemetry.d.ts +0 -3
- package/dist/commands/telemetry.js +0 -88
- package/dist/commands/telemetry.js.map +0 -1
- package/dist/commands/uninstall-skill.d.ts +0 -11
- package/dist/commands/uninstall-skill.js +0 -117
- package/dist/commands/uninstall-skill.js.map +0 -1
- package/dist/commands/user.d.ts +0 -19
- package/dist/commands/user.js +0 -92
- package/dist/commands/user.js.map +0 -1
- package/dist/commands/vault-run.d.ts +0 -13
- package/dist/commands/vault-run.js +0 -195
- package/dist/commands/vault-run.js.map +0 -1
- package/dist/commands/vault.d.ts +0 -25
- package/dist/commands/vault.js +0 -153
- package/dist/commands/vault.js.map +0 -1
- package/dist/commands/verify-login.d.ts +0 -25
- package/dist/commands/verify-login.js +0 -158
- package/dist/commands/verify-login.js.map +0 -1
- package/dist/commands/webhook.d.ts +0 -3
- package/dist/commands/webhook.js +0 -92
- package/dist/commands/webhook.js.map +0 -1
- package/dist/craft-pre-release.sh +0 -10
- package/dist/dashboard/components/AnimatedLogo.d.ts +0 -8
- package/dist/dashboard/components/AnimatedLogo.js +0 -16
- package/dist/dashboard/components/AnimatedLogo.js.map +0 -1
- package/dist/dashboard/components/CompletionView.d.ts +0 -13
- package/dist/dashboard/components/CompletionView.js +0 -25
- package/dist/dashboard/components/CompletionView.js.map +0 -1
- package/dist/dashboard/components/ConfirmPrompt.d.ts +0 -9
- package/dist/dashboard/components/ConfirmPrompt.js +0 -25
- package/dist/dashboard/components/ConfirmPrompt.js.map +0 -1
- package/dist/dashboard/components/CredentialsForm.d.ts +0 -10
- package/dist/dashboard/components/CredentialsForm.js +0 -47
- package/dist/dashboard/components/CredentialsForm.js.map +0 -1
- package/dist/dashboard/components/Dashboard.d.ts +0 -3
- package/dist/dashboard/components/Dashboard.js +0 -100
- package/dist/dashboard/components/Dashboard.js.map +0 -1
- package/dist/dashboard/components/DashboardLayout.d.ts +0 -24
- package/dist/dashboard/components/DashboardLayout.js +0 -25
- package/dist/dashboard/components/DashboardLayout.js.map +0 -1
- package/dist/dashboard/components/DiffPanel.d.ts +0 -9
- package/dist/dashboard/components/DiffPanel.js +0 -136
- package/dist/dashboard/components/DiffPanel.js.map +0 -1
- package/dist/dashboard/components/InlinePrompt.d.ts +0 -8
- package/dist/dashboard/components/InlinePrompt.js +0 -19
- package/dist/dashboard/components/InlinePrompt.js.map +0 -1
- package/dist/dashboard/components/OutputPanel.d.ts +0 -10
- package/dist/dashboard/components/OutputPanel.js +0 -100
- package/dist/dashboard/components/OutputPanel.js.map +0 -1
- package/dist/dashboard/components/Panel.d.ts +0 -12
- package/dist/dashboard/components/Panel.js +0 -6
- package/dist/dashboard/components/Panel.js.map +0 -1
- package/dist/dashboard/components/TextInput.d.ts +0 -13
- package/dist/dashboard/components/TextInput.js +0 -57
- package/dist/dashboard/components/TextInput.js.map +0 -1
- package/dist/dashboard/components/WelcomeArt.d.ts +0 -2
- package/dist/dashboard/components/WelcomeArt.js +0 -9
- package/dist/dashboard/components/WelcomeArt.js.map +0 -1
- package/dist/dashboard/hooks/useAnimation.d.ts +0 -7
- package/dist/dashboard/hooks/useAnimation.js +0 -24
- package/dist/dashboard/hooks/useAnimation.js.map +0 -1
- package/dist/dashboard/hooks/useKeyboard.d.ts +0 -8
- package/dist/dashboard/hooks/useKeyboard.js +0 -18
- package/dist/dashboard/hooks/useKeyboard.js.map +0 -1
- package/dist/dashboard/hooks/useTerminalSize.d.ts +0 -8
- package/dist/dashboard/hooks/useTerminalSize.js +0 -23
- package/dist/dashboard/hooks/useTerminalSize.js.map +0 -1
- package/dist/dashboard/index.d.ts +0 -6
- package/dist/dashboard/index.js +0 -36
- package/dist/dashboard/index.js.map +0 -1
- package/dist/dashboard/lib/diff-utils.d.ts +0 -21
- package/dist/dashboard/lib/diff-utils.js +0 -271
- package/dist/dashboard/lib/diff-utils.js.map +0 -1
- package/dist/dashboard/lib/logo-frames.d.ts +0 -20
- package/dist/dashboard/lib/logo-frames.js +0 -109
- package/dist/dashboard/lib/logo-frames.js.map +0 -1
- package/dist/dashboard/lib/welcome-art.d.ts +0 -1
- package/dist/dashboard/lib/welcome-art.js +0 -5
- package/dist/dashboard/lib/welcome-art.js.map +0 -1
- package/dist/dashboard/types.d.ts +0 -5
- package/dist/dashboard/types.js +0 -2
- package/dist/dashboard/types.js.map +0 -1
- package/dist/doctor/agent-prompt.d.ts +0 -10
- package/dist/doctor/agent-prompt.js +0 -190
- package/dist/doctor/agent-prompt.js.map +0 -1
- package/dist/doctor/checks/ai-analysis.d.ts +0 -9
- package/dist/doctor/checks/ai-analysis.js +0 -124
- package/dist/doctor/checks/ai-analysis.js.map +0 -1
- package/dist/doctor/checks/auth-patterns.d.ts +0 -2
- package/dist/doctor/checks/auth-patterns.js +0 -569
- package/dist/doctor/checks/auth-patterns.js.map +0 -1
- package/dist/doctor/checks/connectivity.d.ts +0 -2
- package/dist/doctor/checks/connectivity.js +0 -35
- package/dist/doctor/checks/connectivity.js.map +0 -1
- package/dist/doctor/checks/dashboard.d.ts +0 -3
- package/dist/doctor/checks/dashboard.js +0 -123
- package/dist/doctor/checks/dashboard.js.map +0 -1
- package/dist/doctor/checks/environment.d.ts +0 -2
- package/dist/doctor/checks/environment.js +0 -86
- package/dist/doctor/checks/environment.js.map +0 -1
- package/dist/doctor/checks/framework.d.ts +0 -2
- package/dist/doctor/checks/framework.js +0 -94
- package/dist/doctor/checks/framework.js.map +0 -1
- package/dist/doctor/checks/host-execution.d.ts +0 -2
- package/dist/doctor/checks/host-execution.js +0 -21
- package/dist/doctor/checks/host-execution.js.map +0 -1
- package/dist/doctor/checks/language.d.ts +0 -6
- package/dist/doctor/checks/language.js +0 -104
- package/dist/doctor/checks/language.js.map +0 -1
- package/dist/doctor/checks/mcp.d.ts +0 -15
- package/dist/doctor/checks/mcp.js +0 -34
- package/dist/doctor/checks/mcp.js.map +0 -1
- package/dist/doctor/checks/runtime.d.ts +0 -2
- package/dist/doctor/checks/runtime.js +0 -20
- package/dist/doctor/checks/runtime.js.map +0 -1
- package/dist/doctor/checks/sdk.d.ts +0 -2
- package/dist/doctor/checks/sdk.js +0 -192
- package/dist/doctor/checks/sdk.js.map +0 -1
- package/dist/doctor/checks/skills.d.ts +0 -9
- package/dist/doctor/checks/skills.js +0 -84
- package/dist/doctor/checks/skills.js.map +0 -1
- package/dist/doctor/clipboard.d.ts +0 -1
- package/dist/doctor/clipboard.js +0 -43
- package/dist/doctor/clipboard.js.map +0 -1
- package/dist/doctor/index.d.ts +0 -26
- package/dist/doctor/index.js +0 -182
- package/dist/doctor/index.js.map +0 -1
- package/dist/doctor/issues.d.ts +0 -63
- package/dist/doctor/issues.js +0 -199
- package/dist/doctor/issues.js.map +0 -1
- package/dist/doctor/json-output.d.ts +0 -2
- package/dist/doctor/json-output.js +0 -4
- package/dist/doctor/json-output.js.map +0 -1
- package/dist/doctor/output.d.ts +0 -7
- package/dist/doctor/output.js +0 -289
- package/dist/doctor/output.js.map +0 -1
- package/dist/doctor/types.d.ts +0 -203
- package/dist/doctor/types.js +0 -2
- package/dist/doctor/types.js.map +0 -1
- package/dist/integrations/dotnet/index.d.ts +0 -8
- package/dist/integrations/dotnet/index.js +0 -170
- package/dist/integrations/dotnet/index.js.map +0 -1
- package/dist/integrations/elixir/index.d.ts +0 -8
- package/dist/integrations/elixir/index.js +0 -146
- package/dist/integrations/elixir/index.js.map +0 -1
- package/dist/integrations/go/index.d.ts +0 -11
- package/dist/integrations/go/index.js +0 -212
- package/dist/integrations/go/index.js.map +0 -1
- package/dist/integrations/kotlin/index.d.ts +0 -4
- package/dist/integrations/kotlin/index.js +0 -78
- package/dist/integrations/kotlin/index.js.map +0 -1
- package/dist/integrations/nextjs/index.d.ts +0 -4
- package/dist/integrations/nextjs/index.js +0 -93
- package/dist/integrations/nextjs/index.js.map +0 -1
- package/dist/integrations/nextjs/utils.d.ts +0 -8
- package/dist/integrations/nextjs/utils.js +0 -68
- package/dist/integrations/nextjs/utils.js.map +0 -1
- package/dist/integrations/node/index.d.ts +0 -4
- package/dist/integrations/node/index.js +0 -52
- package/dist/integrations/node/index.js.map +0 -1
- package/dist/integrations/php/index.d.ts +0 -4
- package/dist/integrations/php/index.js +0 -51
- package/dist/integrations/php/index.js.map +0 -1
- package/dist/integrations/php-laravel/index.d.ts +0 -4
- package/dist/integrations/php-laravel/index.js +0 -51
- package/dist/integrations/php-laravel/index.js.map +0 -1
- package/dist/integrations/python/index.d.ts +0 -9
- package/dist/integrations/python/index.js +0 -249
- package/dist/integrations/python/index.js.map +0 -1
- package/dist/integrations/react/index.d.ts +0 -4
- package/dist/integrations/react/index.js +0 -49
- package/dist/integrations/react/index.js.map +0 -1
- package/dist/integrations/react-router/index.d.ts +0 -4
- package/dist/integrations/react-router/index.js +0 -94
- package/dist/integrations/react-router/index.js.map +0 -1
- package/dist/integrations/react-router/utils.d.ts +0 -10
- package/dist/integrations/react-router/utils.js +0 -162
- package/dist/integrations/react-router/utils.js.map +0 -1
- package/dist/integrations/ruby/index.d.ts +0 -8
- package/dist/integrations/ruby/index.js +0 -137
- package/dist/integrations/ruby/index.js.map +0 -1
- package/dist/integrations/sveltekit/index.d.ts +0 -4
- package/dist/integrations/sveltekit/index.js +0 -50
- package/dist/integrations/sveltekit/index.js.map +0 -1
- package/dist/integrations/tanstack-start/index.d.ts +0 -4
- package/dist/integrations/tanstack-start/index.js +0 -51
- package/dist/integrations/tanstack-start/index.js.map +0 -1
- package/dist/integrations/vanilla-js/index.d.ts +0 -4
- package/dist/integrations/vanilla-js/index.js +0 -49
- package/dist/integrations/vanilla-js/index.js.map +0 -1
- package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.d.ts +0 -7
- package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.js +0 -12
- package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.js.map +0 -1
- package/dist/lib/adapters/cli-adapter.d.ts +0 -113
- package/dist/lib/adapters/cli-adapter.js +0 -641
- package/dist/lib/adapters/cli-adapter.js.map +0 -1
- package/dist/lib/adapters/dashboard-adapter.d.ts +0 -34
- package/dist/lib/adapters/dashboard-adapter.js +0 -121
- package/dist/lib/adapters/dashboard-adapter.js.map +0 -1
- package/dist/lib/adapters/headless-adapter.d.ts +0 -80
- package/dist/lib/adapters/headless-adapter.js +0 -347
- package/dist/lib/adapters/headless-adapter.js.map +0 -1
- package/dist/lib/adapters/index.d.ts +0 -4
- package/dist/lib/adapters/index.js +0 -4
- package/dist/lib/adapters/index.js.map +0 -1
- package/dist/lib/adapters/types.d.ts +0 -41
- package/dist/lib/adapters/types.js +0 -2
- package/dist/lib/adapters/types.js.map +0 -1
- package/dist/lib/agent-interface.d.ts +0 -84
- package/dist/lib/agent-interface.js +0 -840
- package/dist/lib/agent-interface.js.map +0 -1
- package/dist/lib/agent-runner.d.ts +0 -9
- package/dist/lib/agent-runner.js +0 -261
- package/dist/lib/agent-runner.js.map +0 -1
- package/dist/lib/ai-content.d.ts +0 -14
- package/dist/lib/ai-content.js +0 -131
- package/dist/lib/ai-content.js.map +0 -1
- package/dist/lib/api-error-handler.d.ts +0 -18
- package/dist/lib/api-error-handler.js +0 -76
- package/dist/lib/api-error-handler.js.map +0 -1
- package/dist/lib/api-key.d.ts +0 -14
- package/dist/lib/api-key.js +0 -37
- package/dist/lib/api-key.js.map +0 -1
- package/dist/lib/api.d.ts +0 -25
- package/dist/lib/api.js +0 -120
- package/dist/lib/api.js.map +0 -1
- package/dist/lib/background-refresh.d.ts +0 -29
- package/dist/lib/background-refresh.js +0 -95
- package/dist/lib/background-refresh.js.map +0 -1
- package/dist/lib/command-aliases.d.ts +0 -8
- package/dist/lib/command-aliases.js +0 -12
- package/dist/lib/command-aliases.js.map +0 -1
- package/dist/lib/completion-data.d.ts +0 -33
- package/dist/lib/completion-data.js +0 -33
- package/dist/lib/completion-data.js.map +0 -1
- package/dist/lib/config-store.d.ts +0 -63
- package/dist/lib/config-store.js +0 -293
- package/dist/lib/config-store.js.map +0 -1
- package/dist/lib/config.d.ts +0 -34
- package/dist/lib/config.js +0 -37
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/constants.d.ts +0 -51
- package/dist/lib/constants.js +0 -50
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/credential-discovery.d.ts +0 -42
- package/dist/lib/credential-discovery.js +0 -100
- package/dist/lib/credential-discovery.js.map +0 -1
- package/dist/lib/credential-proxy.d.ts +0 -45
- package/dist/lib/credential-proxy.js +0 -364
- package/dist/lib/credential-proxy.js.map +0 -1
- package/dist/lib/credential-store.d.ts +0 -32
- package/dist/lib/credential-store.js +0 -236
- package/dist/lib/credential-store.js.map +0 -1
- package/dist/lib/credentials.d.ts +0 -13
- package/dist/lib/credentials.js +0 -34
- package/dist/lib/credentials.js.map +0 -1
- package/dist/lib/dev-command.d.ts +0 -26
- package/dist/lib/dev-command.js +0 -129
- package/dist/lib/dev-command.js.map +0 -1
- package/dist/lib/device-auth.d.ts +0 -48
- package/dist/lib/device-auth.js +0 -176
- package/dist/lib/device-auth.js.map +0 -1
- package/dist/lib/device-id.d.ts +0 -25
- package/dist/lib/device-id.js +0 -102
- package/dist/lib/device-id.js.map +0 -1
- package/dist/lib/ensure-auth.d.ts +0 -12
- package/dist/lib/ensure-auth.js +0 -111
- package/dist/lib/ensure-auth.js.map +0 -1
- package/dist/lib/env-writer.d.ts +0 -25
- package/dist/lib/env-writer.js +0 -90
- package/dist/lib/env-writer.js.map +0 -1
- package/dist/lib/events.d.ts +0 -248
- package/dist/lib/events.js +0 -19
- package/dist/lib/events.js.map +0 -1
- package/dist/lib/framework-config.d.ts +0 -133
- package/dist/lib/framework-config.js +0 -11
- package/dist/lib/framework-config.js.map +0 -1
- package/dist/lib/helper-functions.d.ts +0 -1
- package/dist/lib/helper-functions.js +0 -2
- package/dist/lib/helper-functions.js.map +0 -1
- package/dist/lib/host-probe.d.ts +0 -28
- package/dist/lib/host-probe.js +0 -154
- package/dist/lib/host-probe.js.map +0 -1
- package/dist/lib/installer-core.d.ts +0 -569
- package/dist/lib/installer-core.js +0 -1134
- package/dist/lib/installer-core.js.map +0 -1
- package/dist/lib/installer-core.types.d.ts +0 -162
- package/dist/lib/installer-core.types.js +0 -2
- package/dist/lib/installer-core.types.js.map +0 -1
- package/dist/lib/mcp-clients.d.ts +0 -45
- package/dist/lib/mcp-clients.js +0 -297
- package/dist/lib/mcp-clients.js.map +0 -1
- package/dist/lib/port-detection.d.ts +0 -7
- package/dist/lib/port-detection.js +0 -244
- package/dist/lib/port-detection.js.map +0 -1
- package/dist/lib/post-install.d.ts +0 -8
- package/dist/lib/post-install.js +0 -51
- package/dist/lib/post-install.js.map +0 -1
- package/dist/lib/preferences.d.ts +0 -143
- package/dist/lib/preferences.js +0 -227
- package/dist/lib/preferences.js.map +0 -1
- package/dist/lib/progress-tracker.d.ts +0 -22
- package/dist/lib/progress-tracker.js +0 -47
- package/dist/lib/progress-tracker.js.map +0 -1
- package/dist/lib/registry.d.ts +0 -42
- package/dist/lib/registry.js +0 -96
- package/dist/lib/registry.js.map +0 -1
- package/dist/lib/resolve-install-credentials.d.ts +0 -11
- package/dist/lib/resolve-install-credentials.js +0 -53
- package/dist/lib/resolve-install-credentials.js.map +0 -1
- package/dist/lib/run-with-core.d.ts +0 -7
- package/dist/lib/run-with-core.js +0 -559
- package/dist/lib/run-with-core.js.map +0 -1
- package/dist/lib/safe-tools.d.ts +0 -2
- package/dist/lib/safe-tools.js +0 -212
- package/dist/lib/safe-tools.js.map +0 -1
- package/dist/lib/scaffold/index.d.ts +0 -1
- package/dist/lib/scaffold/index.js +0 -2
- package/dist/lib/scaffold/index.js.map +0 -1
- package/dist/lib/scaffold/scaffold.d.ts +0 -66
- package/dist/lib/scaffold/scaffold.js +0 -156
- package/dist/lib/scaffold/scaffold.js.map +0 -1
- package/dist/lib/settings.d.ts +0 -60
- package/dist/lib/settings.js +0 -31
- package/dist/lib/settings.js.map +0 -1
- package/dist/lib/staging-api.d.ts +0 -22
- package/dist/lib/staging-api.js +0 -74
- package/dist/lib/staging-api.js.map +0 -1
- package/dist/lib/startup-notice-gate.d.ts +0 -21
- package/dist/lib/startup-notice-gate.js +0 -29
- package/dist/lib/startup-notice-gate.js.map +0 -1
- package/dist/lib/telemetry-notice.d.ts +0 -25
- package/dist/lib/telemetry-notice.js +0 -58
- package/dist/lib/telemetry-notice.js.map +0 -1
- package/dist/lib/token-refresh-client.d.ts +0 -23
- package/dist/lib/token-refresh-client.js +0 -89
- package/dist/lib/token-refresh-client.js.map +0 -1
- package/dist/lib/token-refresh.d.ts +0 -12
- package/dist/lib/token-refresh.js +0 -27
- package/dist/lib/token-refresh.js.map +0 -1
- package/dist/lib/unclaimed-env-api.d.ts +0 -42
- package/dist/lib/unclaimed-env-api.js +0 -139
- package/dist/lib/unclaimed-env-api.js.map +0 -1
- package/dist/lib/unclaimed-env-provision.d.ts +0 -24
- package/dist/lib/unclaimed-env-provision.js +0 -80
- package/dist/lib/unclaimed-env-provision.js.map +0 -1
- package/dist/lib/unclaimed-warning.d.ts +0 -15
- package/dist/lib/unclaimed-warning.js +0 -78
- package/dist/lib/unclaimed-warning.js.map +0 -1
- package/dist/lib/validation/build-validator.d.ts +0 -21
- package/dist/lib/validation/build-validator.js +0 -153
- package/dist/lib/validation/build-validator.js.map +0 -1
- package/dist/lib/validation/index.d.ts +0 -4
- package/dist/lib/validation/index.js +0 -4
- package/dist/lib/validation/index.js.map +0 -1
- package/dist/lib/validation/quick-checks.d.ts +0 -19
- package/dist/lib/validation/quick-checks.js +0 -192
- package/dist/lib/validation/quick-checks.js.map +0 -1
- package/dist/lib/validation/security-checks.d.ts +0 -35
- package/dist/lib/validation/security-checks.js +0 -106
- package/dist/lib/validation/security-checks.js.map +0 -1
- package/dist/lib/validation/types.d.ts +0 -56
- package/dist/lib/validation/types.js +0 -2
- package/dist/lib/validation/types.js.map +0 -1
- package/dist/lib/validation/validator.d.ts +0 -13
- package/dist/lib/validation/validator.js +0 -711
- package/dist/lib/validation/validator.js.map +0 -1
- package/dist/lib/version-check.d.ts +0 -6
- package/dist/lib/version-check.js +0 -46
- package/dist/lib/version-check.js.map +0 -1
- package/dist/lib/workos-api.d.ts +0 -30
- package/dist/lib/workos-api.js +0 -69
- package/dist/lib/workos-api.js.map +0 -1
- package/dist/lib/workos-client.d.ts +0 -58
- package/dist/lib/workos-client.js +0 -140
- package/dist/lib/workos-client.js.map +0 -1
- package/dist/lib/workos-management.d.ts +0 -32
- package/dist/lib/workos-management.js +0 -149
- package/dist/lib/workos-management.js.map +0 -1
- package/dist/nextjs/nextjs-installer-agent.d.ts +0 -5
- package/dist/nextjs/nextjs-installer-agent.js +0 -6
- package/dist/nextjs/nextjs-installer-agent.js.map +0 -1
- package/dist/nextjs/utils.d.ts +0 -4
- package/dist/nextjs/utils.js +0 -5
- package/dist/nextjs/utils.js.map +0 -1
- package/dist/react/react-installer-agent.d.ts +0 -4
- package/dist/react/react-installer-agent.js +0 -5
- package/dist/react/react-installer-agent.js.map +0 -1
- package/dist/react-router/react-router-installer-agent.d.ts +0 -4
- package/dist/react-router/react-router-installer-agent.js +0 -5
- package/dist/react-router/react-router-installer-agent.js.map +0 -1
- package/dist/react-router/utils.d.ts +0 -4
- package/dist/react-router/utils.js +0 -5
- package/dist/react-router/utils.js.map +0 -1
- package/dist/run.d.ts +0 -33
- package/dist/run.js +0 -58
- package/dist/run.js.map +0 -1
- package/dist/smoke-test.ts +0 -881
- package/dist/steps/add-or-update-environment-variables.d.ts +0 -10
- package/dist/steps/add-or-update-environment-variables.js +0 -155
- package/dist/steps/add-or-update-environment-variables.js.map +0 -1
- package/dist/steps/index.d.ts +0 -3
- package/dist/steps/index.js +0 -4
- package/dist/steps/index.js.map +0 -1
- package/dist/steps/run-prettier.d.ts +0 -5
- package/dist/steps/run-prettier.js +0 -50
- package/dist/steps/run-prettier.js.map +0 -1
- package/dist/steps/upload-environment-variables/EnvironmentProvider.d.ts +0 -8
- package/dist/steps/upload-environment-variables/EnvironmentProvider.js +0 -7
- package/dist/steps/upload-environment-variables/EnvironmentProvider.js.map +0 -1
- package/dist/steps/upload-environment-variables/index.d.ts +0 -6
- package/dist/steps/upload-environment-variables/index.js +0 -69
- package/dist/steps/upload-environment-variables/index.js.map +0 -1
- package/dist/steps/upload-environment-variables/providers/vercel.d.ts +0 -14
- package/dist/steps/upload-environment-variables/providers/vercel.js +0 -107
- package/dist/steps/upload-environment-variables/providers/vercel.js.map +0 -1
- package/dist/tanstack-start/tanstack-start-installer-agent.d.ts +0 -4
- package/dist/tanstack-start/tanstack-start-installer-agent.js +0 -5
- package/dist/tanstack-start/tanstack-start-installer-agent.js.map +0 -1
- package/dist/telemetry.d.ts +0 -2
- package/dist/telemetry.js +0 -29
- package/dist/telemetry.js.map +0 -1
- package/dist/test/force-insecure-storage.d.ts +0 -1
- package/dist/test/force-insecure-storage.js +0 -9
- package/dist/test/force-insecure-storage.js.map +0 -1
- package/dist/test/setup.d.ts +0 -1
- package/dist/test/setup.js +0 -38
- package/dist/test/setup.js.map +0 -1
- package/dist/utils/analytics.d.ts +0 -66
- package/dist/utils/analytics.js +0 -330
- package/dist/utils/analytics.js.map +0 -1
- package/dist/utils/bash.d.ts +0 -2
- package/dist/utils/bash.js +0 -17
- package/dist/utils/bash.js.map +0 -1
- package/dist/utils/box.d.ts +0 -9
- package/dist/utils/box.js +0 -15
- package/dist/utils/box.js.map +0 -1
- package/dist/utils/cli-exit.d.ts +0 -15
- package/dist/utils/cli-exit.js +0 -11
- package/dist/utils/cli-exit.js.map +0 -1
- package/dist/utils/cli-symbols.d.ts +0 -44
- package/dist/utils/cli-symbols.js +0 -58
- package/dist/utils/cli-symbols.js.map +0 -1
- package/dist/utils/command-invocation.d.ts +0 -10
- package/dist/utils/command-invocation.js +0 -26
- package/dist/utils/command-invocation.js.map +0 -1
- package/dist/utils/command-telemetry.d.ts +0 -17
- package/dist/utils/command-telemetry.js +0 -67
- package/dist/utils/command-telemetry.js.map +0 -1
- package/dist/utils/crash-reporter.d.ts +0 -13
- package/dist/utils/crash-reporter.js +0 -91
- package/dist/utils/crash-reporter.js.map +0 -1
- package/dist/utils/debug.d.ts +0 -9
- package/dist/utils/debug.js +0 -105
- package/dist/utils/debug.js.map +0 -1
- package/dist/utils/env-parser.d.ts +0 -5
- package/dist/utils/env-parser.js +0 -18
- package/dist/utils/env-parser.js.map +0 -1
- package/dist/utils/environment.d.ts +0 -10
- package/dist/utils/environment.js +0 -69
- package/dist/utils/environment.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -3
- package/dist/utils/errors.js +0 -7
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/exec-file.d.ts +0 -15
- package/dist/utils/exec-file.js +0 -39
- package/dist/utils/exec-file.js.map +0 -1
- package/dist/utils/exit-codes.d.ts +0 -31
- package/dist/utils/exit-codes.js +0 -69
- package/dist/utils/exit-codes.js.map +0 -1
- package/dist/utils/git-utils.d.ts +0 -23
- package/dist/utils/git-utils.js +0 -86
- package/dist/utils/git-utils.js.map +0 -1
- package/dist/utils/help-json.d.ts +0 -58
- package/dist/utils/help-json.js +0 -1577
- package/dist/utils/help-json.js.map +0 -1
- package/dist/utils/interaction-mode.d.ts +0 -25
- package/dist/utils/interaction-mode.js +0 -99
- package/dist/utils/interaction-mode.js.map +0 -1
- package/dist/utils/lock-art.d.ts +0 -4
- package/dist/utils/lock-art.js +0 -73
- package/dist/utils/lock-art.js.map +0 -1
- package/dist/utils/logging.d.ts +0 -9
- package/dist/utils/logging.js +0 -36
- package/dist/utils/logging.js.map +0 -1
- package/dist/utils/ndjson.d.ts +0 -16
- package/dist/utils/ndjson.js +0 -18
- package/dist/utils/ndjson.js.map +0 -1
- package/dist/utils/output.d.ts +0 -60
- package/dist/utils/output.js +0 -124
- package/dist/utils/output.js.map +0 -1
- package/dist/utils/package-json.d.ts +0 -26
- package/dist/utils/package-json.js +0 -32
- package/dist/utils/package-json.js.map +0 -1
- package/dist/utils/package-manager.d.ts +0 -21
- package/dist/utils/package-manager.js +0 -166
- package/dist/utils/package-manager.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -5
- package/dist/utils/paths.js +0 -18
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/platform.d.ts +0 -8
- package/dist/utils/platform.js +0 -7
- package/dist/utils/platform.js.map +0 -1
- package/dist/utils/recovery-hints.d.ts +0 -42
- package/dist/utils/recovery-hints.js +0 -92
- package/dist/utils/recovery-hints.js.map +0 -1
- package/dist/utils/redact.d.ts +0 -5
- package/dist/utils/redact.js +0 -29
- package/dist/utils/redact.js.map +0 -1
- package/dist/utils/register-subcommand.d.ts +0 -10
- package/dist/utils/register-subcommand.js +0 -33
- package/dist/utils/register-subcommand.js.map +0 -1
- package/dist/utils/semver.d.ts +0 -10
- package/dist/utils/semver.js +0 -43
- package/dist/utils/semver.js.map +0 -1
- package/dist/utils/string.d.ts +0 -1
- package/dist/utils/string.js +0 -6
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/summary-box.d.ts +0 -25
- package/dist/utils/summary-box.js +0 -211
- package/dist/utils/summary-box.js.map +0 -1
- package/dist/utils/table.d.ts +0 -5
- package/dist/utils/table.js +0 -18
- package/dist/utils/table.js.map +0 -1
- package/dist/utils/telemetry-client.d.ts +0 -43
- package/dist/utils/telemetry-client.js +0 -171
- package/dist/utils/telemetry-client.js.map +0 -1
- package/dist/utils/telemetry-store-forward.d.ts +0 -11
- package/dist/utils/telemetry-store-forward.js +0 -94
- package/dist/utils/telemetry-store-forward.js.map +0 -1
- package/dist/utils/telemetry-types.d.ts +0 -100
- package/dist/utils/telemetry-types.js +0 -6
- package/dist/utils/telemetry-types.js.map +0 -1
- package/dist/utils/types.d.ts +0 -123
- package/dist/utils/types.js +0 -2
- package/dist/utils/types.js.map +0 -1
- package/dist/utils/ui-utils.d.ts +0 -97
- package/dist/utils/ui-utils.js +0 -449
- package/dist/utils/ui-utils.js.map +0 -1
- package/dist/utils/ui.d.ts +0 -148
- package/dist/utils/ui.js +0 -368
- package/dist/utils/ui.js.map +0 -1
- package/dist/utils/urls.d.ts +0 -13
- package/dist/utils/urls.js +0 -14
- package/dist/utils/urls.js.map +0 -1
- package/dist/utils/vendor/is-unicorn-supported.d.ts +0 -1
- package/dist/utils/vendor/is-unicorn-supported.js +0 -21
- package/dist/utils/vendor/is-unicorn-supported.js.map +0 -1
- package/dist/vanilla-js/vanilla-js-installer-agent.d.ts +0 -4
- package/dist/vanilla-js/vanilla-js-installer-agent.js +0 -5
- package/dist/vanilla-js/vanilla-js-installer-agent.js.map +0 -1
|
@@ -1,840 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared agent interface for WorkOS wizards
|
|
3
|
-
* Uses Claude Agent SDK directly with WorkOS MCP server
|
|
4
|
-
*/
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
import { getSkillsDir as getSkillsPackageDir } from '@workos/skills';
|
|
7
|
-
import { debug, logInfo, logWarn, logError, initLogFile, getLogFilePath } from '../utils/debug.js';
|
|
8
|
-
import { analytics } from '../utils/analytics.js';
|
|
9
|
-
import { INSTALLER_INTERACTION_EVENT_NAME } from './constants.js';
|
|
10
|
-
import { LINTING_TOOLS } from './safe-tools.js';
|
|
11
|
-
import { formatWorkOSCommand } from '../utils/command-invocation.js';
|
|
12
|
-
import { getConfig } from './settings.js';
|
|
13
|
-
import { getLlmGatewayUrl } from '../utils/urls.js';
|
|
14
|
-
import { getCredentials, hasCredentials } from './credentials.js';
|
|
15
|
-
import { ensureValidToken } from './token-refresh.js';
|
|
16
|
-
import { startCredentialProxy, startClaimTokenProxy } from './credential-proxy.js';
|
|
17
|
-
import { getActiveEnvironment, isUnclaimedEnvironment } from './config-store.js';
|
|
18
|
-
import { getAuthkitDomain, getCliAuthClientId } from './settings.js';
|
|
19
|
-
// File content cache for computing edit diffs
|
|
20
|
-
const fileContentCache = new Map();
|
|
21
|
-
// Track pending Read operations by tool_use_id
|
|
22
|
-
const pendingReads = new Map();
|
|
23
|
-
// Track tool start times by tool_use_id for telemetry
|
|
24
|
-
const pendingToolCalls = new Map();
|
|
25
|
-
// Module-level variable to track proxy handle for cleanup
|
|
26
|
-
let activeProxyHandle = null;
|
|
27
|
-
// Dynamic import cache for ESM module
|
|
28
|
-
let _sdkModule = null;
|
|
29
|
-
async function getSDKModule() {
|
|
30
|
-
if (!_sdkModule) {
|
|
31
|
-
_sdkModule = await import('@anthropic-ai/claude-agent-sdk');
|
|
32
|
-
}
|
|
33
|
-
return _sdkModule;
|
|
34
|
-
}
|
|
35
|
-
export const AgentSignals = {
|
|
36
|
-
/** Signal emitted when the agent reports progress to the user */
|
|
37
|
-
STATUS: '[STATUS]',
|
|
38
|
-
/** Signal emitted when the agent cannot access the WorkOS MCP server */
|
|
39
|
-
ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',
|
|
40
|
-
/** Signal emitted when the agent cannot access the setup resource */
|
|
41
|
-
ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',
|
|
42
|
-
};
|
|
43
|
-
/** Internal prefix used to tag service-unavailability errors from handleSDKMessage */
|
|
44
|
-
const SERVICE_UNAVAILABLE_PREFIX = '__SERVICE_UNAVAILABLE__';
|
|
45
|
-
/** Internal prefix used to tag rate-limit errors from handleSDKMessage */
|
|
46
|
-
const RATE_LIMITED_PREFIX = '__RATE_LIMITED__';
|
|
47
|
-
/**
|
|
48
|
-
* Error types that can be returned from agent execution.
|
|
49
|
-
* These correspond to the error signals that the agent emits.
|
|
50
|
-
*/
|
|
51
|
-
export var AgentErrorType;
|
|
52
|
-
(function (AgentErrorType) {
|
|
53
|
-
/** Agent could not access the WorkOS MCP server */
|
|
54
|
-
AgentErrorType["MCP_MISSING"] = "INSTALLER_MCP_MISSING";
|
|
55
|
-
/** Agent could not access the setup resource */
|
|
56
|
-
AgentErrorType["RESOURCE_MISSING"] = "INSTALLER_RESOURCE_MISSING";
|
|
57
|
-
/** Agent execution failed (API error, auth error, etc.) */
|
|
58
|
-
AgentErrorType["EXECUTION_ERROR"] = "INSTALLER_EXECUTION_ERROR";
|
|
59
|
-
/** AI service is unavailable (API 500, outage, etc.) */
|
|
60
|
-
AgentErrorType["SERVICE_UNAVAILABLE"] = "INSTALLER_SERVICE_UNAVAILABLE";
|
|
61
|
-
})(AgentErrorType || (AgentErrorType = {}));
|
|
62
|
-
/**
|
|
63
|
-
* Package managers that can be used to run commands.
|
|
64
|
-
* Includes JS and non-JS ecosystem package managers for multi-SDK support.
|
|
65
|
-
*/
|
|
66
|
-
const PACKAGE_MANAGERS = [
|
|
67
|
-
// JavaScript
|
|
68
|
-
'npm',
|
|
69
|
-
'pnpm',
|
|
70
|
-
'yarn',
|
|
71
|
-
'bun',
|
|
72
|
-
'npx',
|
|
73
|
-
'pnpx',
|
|
74
|
-
'bunx',
|
|
75
|
-
// Python
|
|
76
|
-
'pip',
|
|
77
|
-
'pip3',
|
|
78
|
-
'poetry',
|
|
79
|
-
'uv',
|
|
80
|
-
'pipx',
|
|
81
|
-
'python',
|
|
82
|
-
'python3',
|
|
83
|
-
// Ruby
|
|
84
|
-
'gem',
|
|
85
|
-
'bundle',
|
|
86
|
-
'bundler',
|
|
87
|
-
'ruby',
|
|
88
|
-
// PHP
|
|
89
|
-
'composer',
|
|
90
|
-
'php',
|
|
91
|
-
// Go
|
|
92
|
-
'go',
|
|
93
|
-
// .NET
|
|
94
|
-
'dotnet',
|
|
95
|
-
'nuget',
|
|
96
|
-
// Elixir
|
|
97
|
-
'mix',
|
|
98
|
-
'hex',
|
|
99
|
-
'elixir',
|
|
100
|
-
// Kotlin/Java
|
|
101
|
-
'gradle',
|
|
102
|
-
'gradlew',
|
|
103
|
-
'./gradlew',
|
|
104
|
-
'mvn',
|
|
105
|
-
];
|
|
106
|
-
/**
|
|
107
|
-
* Safe scripts/commands that can be run with any package manager.
|
|
108
|
-
* Uses startsWith matching, so 'build' matches 'build', 'build:prod', etc.
|
|
109
|
-
* Note: Linting tools are in LINTING_TOOLS and checked separately.
|
|
110
|
-
*/
|
|
111
|
-
const SAFE_SCRIPTS = [
|
|
112
|
-
// Package installation
|
|
113
|
-
'install',
|
|
114
|
-
'add',
|
|
115
|
-
'ci',
|
|
116
|
-
// Build
|
|
117
|
-
'build',
|
|
118
|
-
// Type checking (various naming conventions)
|
|
119
|
-
'tsc',
|
|
120
|
-
'typecheck',
|
|
121
|
-
'type-check',
|
|
122
|
-
'check-types',
|
|
123
|
-
'types',
|
|
124
|
-
// Linting/formatting script names (actual tools are in LINTING_TOOLS)
|
|
125
|
-
'lint',
|
|
126
|
-
'format',
|
|
127
|
-
// Common cross-language commands
|
|
128
|
-
'check',
|
|
129
|
-
'test',
|
|
130
|
-
'run',
|
|
131
|
-
'serve',
|
|
132
|
-
'dev',
|
|
133
|
-
'start',
|
|
134
|
-
'compile',
|
|
135
|
-
'vet',
|
|
136
|
-
// Python-specific
|
|
137
|
-
'manage.py',
|
|
138
|
-
'pytest',
|
|
139
|
-
// Ruby-specific
|
|
140
|
-
'rspec',
|
|
141
|
-
'rake',
|
|
142
|
-
'routes',
|
|
143
|
-
// PHP-specific
|
|
144
|
-
'artisan',
|
|
145
|
-
'phpunit',
|
|
146
|
-
// Elixir-specific
|
|
147
|
-
'deps.get',
|
|
148
|
-
'credo',
|
|
149
|
-
'dialyzer',
|
|
150
|
-
// .NET-specific
|
|
151
|
-
'restore',
|
|
152
|
-
];
|
|
153
|
-
/**
|
|
154
|
-
* Dangerous shell operators that could allow command injection.
|
|
155
|
-
* Note: We handle `2>&1` and `| tail/head` separately as safe patterns.
|
|
156
|
-
*/
|
|
157
|
-
const DANGEROUS_OPERATORS = /[;`$()]/;
|
|
158
|
-
/**
|
|
159
|
-
* Check if command is an allowed package manager command.
|
|
160
|
-
* Matches: <pkg-manager> [run|exec] <safe-script> [args...]
|
|
161
|
-
*/
|
|
162
|
-
function matchesAllowedPrefix(command) {
|
|
163
|
-
const parts = command.split(/\s+/);
|
|
164
|
-
if (parts.length === 0 || !PACKAGE_MANAGERS.includes(parts[0])) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
// Skip 'run' or 'exec' if present
|
|
168
|
-
let scriptIndex = 1;
|
|
169
|
-
if (parts[scriptIndex] === 'run' || parts[scriptIndex] === 'exec') {
|
|
170
|
-
scriptIndex++;
|
|
171
|
-
}
|
|
172
|
-
// Get the script/command portion (may include args)
|
|
173
|
-
const scriptPart = parts.slice(scriptIndex).join(' ');
|
|
174
|
-
// Check if script starts with any safe script name or linting tool
|
|
175
|
-
return (SAFE_SCRIPTS.some((safe) => scriptPart.startsWith(safe)) ||
|
|
176
|
-
LINTING_TOOLS.some((tool) => scriptPart.startsWith(tool)));
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Permission hook that allows only safe commands.
|
|
180
|
-
* - Package manager install commands
|
|
181
|
-
* - Build/typecheck/lint commands for verification
|
|
182
|
-
* - Piping to tail/head for output limiting is allowed
|
|
183
|
-
* - Stderr redirection (2>&1) is allowed
|
|
184
|
-
*/
|
|
185
|
-
export function installerCanUseTool(toolName, input) {
|
|
186
|
-
// Allow all non-Bash tools
|
|
187
|
-
if (toolName !== 'Bash') {
|
|
188
|
-
return { behavior: 'allow', updatedInput: input };
|
|
189
|
-
}
|
|
190
|
-
const command = (typeof input.command === 'string' ? input.command : '').trim();
|
|
191
|
-
// Block definitely dangerous operators: ; ` $ ( )
|
|
192
|
-
if (DANGEROUS_OPERATORS.test(command)) {
|
|
193
|
-
logWarn(`Denying bash command with dangerous operators: ${command}`);
|
|
194
|
-
debug(`Denying bash command with dangerous operators: ${command}`);
|
|
195
|
-
analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
|
|
196
|
-
action: 'bash command denied',
|
|
197
|
-
reason: 'dangerous operators',
|
|
198
|
-
command,
|
|
199
|
-
});
|
|
200
|
-
return {
|
|
201
|
-
behavior: 'deny',
|
|
202
|
-
message: `Bash command not allowed. Shell operators like ; \` $ ( ) are not permitted.`,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
// Normalize: remove safe stderr redirection (2>&1, 2>&2, etc.)
|
|
206
|
-
const normalized = command.replace(/\s*\d*>&\d+\s*/g, ' ').trim();
|
|
207
|
-
// Check for pipe to tail/head (safe output limiting)
|
|
208
|
-
const pipeMatch = normalized.match(/^(.+?)\s*\|\s*(tail|head)(\s+\S+)*\s*$/);
|
|
209
|
-
if (pipeMatch) {
|
|
210
|
-
const baseCommand = pipeMatch[1].trim();
|
|
211
|
-
// Block if base command has pipes or & (multiple chaining)
|
|
212
|
-
if (/[|&]/.test(baseCommand)) {
|
|
213
|
-
logWarn(`Denying bash command with multiple pipes: ${command}`);
|
|
214
|
-
debug(`Denying bash command with multiple pipes: ${command}`);
|
|
215
|
-
analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
|
|
216
|
-
action: 'bash command denied',
|
|
217
|
-
reason: 'multiple pipes',
|
|
218
|
-
command,
|
|
219
|
-
});
|
|
220
|
-
return {
|
|
221
|
-
behavior: 'deny',
|
|
222
|
-
message: `Bash command not allowed. Only single pipe to tail/head is permitted.`,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
if (matchesAllowedPrefix(baseCommand)) {
|
|
226
|
-
logInfo(`Allowing bash command with output limiter: ${command}`);
|
|
227
|
-
debug(`Allowing bash command with output limiter: ${command}`);
|
|
228
|
-
return { behavior: 'allow', updatedInput: input };
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Block remaining pipes and & (not covered by tail/head case above)
|
|
232
|
-
if (/[|&]/.test(normalized)) {
|
|
233
|
-
logWarn(`Denying bash command with pipe/&: ${command}`);
|
|
234
|
-
debug(`Denying bash command with pipe/&: ${command}`);
|
|
235
|
-
analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
|
|
236
|
-
action: 'bash command denied',
|
|
237
|
-
reason: 'disallowed pipe',
|
|
238
|
-
command,
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
behavior: 'deny',
|
|
242
|
-
message: `Bash command not allowed. Pipes are only permitted with tail/head for output limiting.`,
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
// Check if command starts with any allowed prefix
|
|
246
|
-
if (matchesAllowedPrefix(normalized)) {
|
|
247
|
-
logInfo(`Allowing bash command: ${command}`);
|
|
248
|
-
debug(`Allowing bash command: ${command}`);
|
|
249
|
-
return { behavior: 'allow', updatedInput: input };
|
|
250
|
-
}
|
|
251
|
-
logWarn(`Denying bash command: ${command}`);
|
|
252
|
-
debug(`Denying bash command: ${command}`);
|
|
253
|
-
analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
|
|
254
|
-
action: 'bash command denied',
|
|
255
|
-
reason: 'not in allowlist',
|
|
256
|
-
command,
|
|
257
|
-
});
|
|
258
|
-
return {
|
|
259
|
-
behavior: 'deny',
|
|
260
|
-
message: `Bash command not allowed. Only install, build, typecheck, lint, and formatting commands are permitted.`,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Initialize agent configuration for the LLM gateway
|
|
265
|
-
*/
|
|
266
|
-
export async function initializeAgent(config, options) {
|
|
267
|
-
// Initialize log file for this run
|
|
268
|
-
initLogFile();
|
|
269
|
-
logInfo('Agent initialization starting');
|
|
270
|
-
logInfo('Install directory:', options.installDir);
|
|
271
|
-
// Emit status event for adapters to render
|
|
272
|
-
options.emitter?.emit('status', { message: 'Initializing Claude agent...' });
|
|
273
|
-
try {
|
|
274
|
-
let authMode;
|
|
275
|
-
// Build SDK env without mutating process.env
|
|
276
|
-
const sdkEnv = {
|
|
277
|
-
...process.env,
|
|
278
|
-
// Disable experimental betas (like input_examples) that the LLM gateway doesn't support
|
|
279
|
-
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: 'true',
|
|
280
|
-
// Disable SDK telemetry - our gateway doesn't proxy /api/event_logging/batch
|
|
281
|
-
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 'true',
|
|
282
|
-
};
|
|
283
|
-
// Placeholder bearer token for the Claude Agent SDK. The SDK's CLI
|
|
284
|
-
// subprocess runs a local auth-source check at startup and exits with
|
|
285
|
-
// "Not logged in · Please run /login" if no credentials are present in
|
|
286
|
-
// its environment — even when a proxy is handling auth upstream. Setting
|
|
287
|
-
// this token puts the SDK in custom-backend mode so it skips that check;
|
|
288
|
-
// the credential proxy rewrites the Authorization header with the real
|
|
289
|
-
// WorkOS token before forwarding upstream.
|
|
290
|
-
const PROXY_PLACEHOLDER_TOKEN = 'workos-cli-proxy-placeholder';
|
|
291
|
-
if (options.direct) {
|
|
292
|
-
// Direct mode: use user's Anthropic API key, skip gateway
|
|
293
|
-
if (!process.env.ANTHROPIC_API_KEY) {
|
|
294
|
-
throw new Error('Direct mode requires ANTHROPIC_API_KEY environment variable.\n' +
|
|
295
|
-
'Set it with: export ANTHROPIC_API_KEY=sk-ant-...\n' +
|
|
296
|
-
'Get your key at: https://console.anthropic.com/settings/keys');
|
|
297
|
-
}
|
|
298
|
-
// SDK defaults to api.anthropic.com when no base URL set
|
|
299
|
-
delete sdkEnv.ANTHROPIC_BASE_URL;
|
|
300
|
-
delete sdkEnv.ANTHROPIC_AUTH_TOKEN;
|
|
301
|
-
authMode = 'direct:api.anthropic.com';
|
|
302
|
-
logInfo('Direct mode: using ANTHROPIC_API_KEY, bypassing llm-gateway');
|
|
303
|
-
// Set analytics tag for direct mode
|
|
304
|
-
analytics.setTag('api_mode', 'direct');
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
// Gateway mode (existing behavior)
|
|
308
|
-
const gatewayUrl = getLlmGatewayUrl();
|
|
309
|
-
// Check for unclaimed environment — use claim token auth
|
|
310
|
-
const activeEnv = getActiveEnvironment();
|
|
311
|
-
if (activeEnv && isUnclaimedEnvironment(activeEnv)) {
|
|
312
|
-
activeProxyHandle = await startClaimTokenProxy({
|
|
313
|
-
upstreamUrl: gatewayUrl,
|
|
314
|
-
claimToken: activeEnv.claimToken,
|
|
315
|
-
clientId: activeEnv.clientId,
|
|
316
|
-
});
|
|
317
|
-
sdkEnv.ANTHROPIC_BASE_URL = activeProxyHandle.url;
|
|
318
|
-
// Prevent the user's personal Anthropic key (if any) from being sent
|
|
319
|
-
// to the WorkOS gateway; auth is injected by the claim-token proxy.
|
|
320
|
-
delete sdkEnv.ANTHROPIC_API_KEY;
|
|
321
|
-
sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
|
|
322
|
-
authMode = `claim-token-proxy:${activeProxyHandle.url}→${gatewayUrl}`;
|
|
323
|
-
logInfo(`[agent-interface] Using claim token proxy for unclaimed environment`);
|
|
324
|
-
}
|
|
325
|
-
else if (!options.skipAuth && !options.local) {
|
|
326
|
-
// Check/refresh authentication for production (unless skipping auth)
|
|
327
|
-
if (!hasCredentials()) {
|
|
328
|
-
throw new Error(`Not authenticated. Run \`${formatWorkOSCommand('auth login')}\` to authenticate.`);
|
|
329
|
-
}
|
|
330
|
-
const creds = getCredentials();
|
|
331
|
-
if (!creds) {
|
|
332
|
-
throw new Error(`Not authenticated. Run \`${formatWorkOSCommand('auth login')}\` to authenticate.`);
|
|
333
|
-
}
|
|
334
|
-
// Check if we have refresh token capability and proxy is not disabled
|
|
335
|
-
if (creds.refreshToken && process.env.WORKOS_DISABLE_PROXY !== '1') {
|
|
336
|
-
// Start credential proxy with lazy refresh
|
|
337
|
-
logInfo('[agent-interface] Starting credential proxy with lazy refresh...');
|
|
338
|
-
const appConfig = getConfig();
|
|
339
|
-
activeProxyHandle = await startCredentialProxy({
|
|
340
|
-
upstreamUrl: gatewayUrl,
|
|
341
|
-
refresh: {
|
|
342
|
-
authkitDomain: getAuthkitDomain(),
|
|
343
|
-
clientId: getCliAuthClientId(),
|
|
344
|
-
refreshThresholdMs: appConfig.proxy.refreshThresholdMs,
|
|
345
|
-
onRefreshSuccess: () => {
|
|
346
|
-
options.emitter?.emit('status', { message: 'Session extended' });
|
|
347
|
-
},
|
|
348
|
-
onRefreshExpired: () => {
|
|
349
|
-
logError('[agent-interface] Session expired, refresh token invalid');
|
|
350
|
-
options.emitter?.emit('error', {
|
|
351
|
-
message: `Session expired. Run \`${formatWorkOSCommand('auth login')}\` to re-authenticate.`,
|
|
352
|
-
});
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
// Point SDK at proxy instead of direct gateway
|
|
357
|
-
sdkEnv.ANTHROPIC_BASE_URL = activeProxyHandle.url;
|
|
358
|
-
logInfo(`[agent-interface] Using credential proxy at ${activeProxyHandle.url}`);
|
|
359
|
-
// Prevent the user's personal Anthropic key (if any) from being
|
|
360
|
-
// sent to the WorkOS gateway; the credential proxy rewrites the
|
|
361
|
-
// Authorization header with the real WorkOS token.
|
|
362
|
-
delete sdkEnv.ANTHROPIC_API_KEY;
|
|
363
|
-
sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
|
|
364
|
-
authMode = `proxy:${activeProxyHandle.url}→${gatewayUrl}`;
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// No refresh token OR proxy disabled - fall back to old behavior (5 min limit)
|
|
368
|
-
if (!creds.refreshToken) {
|
|
369
|
-
logWarn('[agent-interface] No refresh token available, session limited to 5 minutes');
|
|
370
|
-
logWarn(`[agent-interface] Run \`${formatWorkOSCommand('auth login')}\` to enable extended sessions`);
|
|
371
|
-
options.emitter?.emit('status', {
|
|
372
|
-
message: `Note: Run \`${formatWorkOSCommand('auth login')}\` to enable extended sessions`,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
logWarn('[agent-interface] Proxy disabled via WORKOS_DISABLE_PROXY');
|
|
377
|
-
}
|
|
378
|
-
const refreshResult = await ensureValidToken();
|
|
379
|
-
if (!refreshResult.success) {
|
|
380
|
-
throw new Error(refreshResult.error || 'Authentication failed');
|
|
381
|
-
}
|
|
382
|
-
sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
|
|
383
|
-
// Prevent the user's personal Anthropic key (if any) from being
|
|
384
|
-
// forwarded to the WorkOS gateway as an x-api-key header alongside
|
|
385
|
-
// the WorkOS access token we set below.
|
|
386
|
-
delete sdkEnv.ANTHROPIC_API_KEY;
|
|
387
|
-
sdkEnv.ANTHROPIC_AUTH_TOKEN = creds.accessToken;
|
|
388
|
-
authMode = options.local ? `local-gateway:${gatewayUrl}` : `workos-gateway:${gatewayUrl}`;
|
|
389
|
-
logInfo('Sending access token to gateway (legacy mode)');
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else if (options.skipAuth) {
|
|
393
|
-
// Skip auth mode - direct to gateway without a real token. The SDK's
|
|
394
|
-
// local auth-source check would otherwise fail with "Not logged in",
|
|
395
|
-
// so seed a placeholder bearer; the gateway is expected to accept
|
|
396
|
-
// unauthenticated requests here and ignore the placeholder value.
|
|
397
|
-
sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
|
|
398
|
-
delete sdkEnv.ANTHROPIC_API_KEY;
|
|
399
|
-
sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
|
|
400
|
-
authMode = `skip-auth:${gatewayUrl}`;
|
|
401
|
-
logInfo('Skipping auth - placeholder bearer sent to gateway');
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
// Local mode without auth - same rationale as skip-auth above.
|
|
405
|
-
sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
|
|
406
|
-
delete sdkEnv.ANTHROPIC_API_KEY;
|
|
407
|
-
sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
|
|
408
|
-
authMode = `local-gateway:${gatewayUrl}`;
|
|
409
|
-
logInfo('Local mode - placeholder bearer sent to gateway');
|
|
410
|
-
}
|
|
411
|
-
logInfo('Configured LLM gateway:', sdkEnv.ANTHROPIC_BASE_URL);
|
|
412
|
-
// Set analytics tag for gateway mode
|
|
413
|
-
analytics.setTag('api_mode', activeProxyHandle ? 'gateway-proxy' : 'gateway');
|
|
414
|
-
}
|
|
415
|
-
// Configure WorkOS MCP docs server for accessing WorkOS documentation
|
|
416
|
-
const agentRunConfig = {
|
|
417
|
-
workingDirectory: config.workingDirectory,
|
|
418
|
-
mcpServers: {
|
|
419
|
-
workos: {
|
|
420
|
-
command: 'npx',
|
|
421
|
-
args: ['-y', '@workos/mcp-docs-server'],
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
model: getConfig().model,
|
|
425
|
-
// Empty on purpose. A tool listed here is auto-approved BEFORE `canUseTool`
|
|
426
|
-
// (installerCanUseTool) runs, which both defeats the Bash safety gate and
|
|
427
|
-
// triggers the SDK's CLAUDE_SDK_CAN_USE_TOOL_SHADOWED warning. Leaving this
|
|
428
|
-
// empty routes every tool call through canUseTool so the gate is
|
|
429
|
-
// authoritative. Tool *availability* comes from the `tools` preset below,
|
|
430
|
-
// not from this list.
|
|
431
|
-
allowedTools: [],
|
|
432
|
-
sdkEnv,
|
|
433
|
-
};
|
|
434
|
-
const configInfo = { workingDirectory: agentRunConfig.workingDirectory, authMode, useMcp: false };
|
|
435
|
-
logInfo('Agent config:', configInfo);
|
|
436
|
-
debug('Agent config:', configInfo);
|
|
437
|
-
// Emit status events for adapters to render
|
|
438
|
-
const currentLogPath = getLogFilePath();
|
|
439
|
-
if (currentLogPath) {
|
|
440
|
-
options.emitter?.emit('status', { message: `Verbose logs: ${currentLogPath}` });
|
|
441
|
-
}
|
|
442
|
-
options.emitter?.emit('status', { message: "Agent initialized. Let's get cooking!" });
|
|
443
|
-
return agentRunConfig;
|
|
444
|
-
}
|
|
445
|
-
catch (error) {
|
|
446
|
-
// Clean up proxy if initialization fails
|
|
447
|
-
if (activeProxyHandle) {
|
|
448
|
-
logInfo('[agent-interface] Cleaning up proxy after init error');
|
|
449
|
-
await activeProxyHandle.stop();
|
|
450
|
-
activeProxyHandle = null;
|
|
451
|
-
}
|
|
452
|
-
logError('Agent initialization error:', error);
|
|
453
|
-
throw error;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Execute an agent with the provided prompt and options
|
|
458
|
-
* Handles the full lifecycle via event emissions - adapters handle UI rendering.
|
|
459
|
-
*
|
|
460
|
-
* @returns An object containing any error detected in the agent's output
|
|
461
|
-
*/
|
|
462
|
-
export async function runAgent(agentConfig, prompt, options, config, emitter, retryConfig, onMessage) {
|
|
463
|
-
const { spinnerMessage = 'Setting up WorkOS AuthKit...' } = config ?? {};
|
|
464
|
-
const { query } = await getSDKModule();
|
|
465
|
-
// Emit progress for adapters to handle (e.g., CLI adapter starts spinner)
|
|
466
|
-
emitter?.emit('agent:progress', { step: 'Starting', detail: 'This may take a few minutes. Grab some coffee!' });
|
|
467
|
-
emitter?.emit('agent:progress', { step: spinnerMessage });
|
|
468
|
-
logInfo('Starting agent run');
|
|
469
|
-
logInfo('Prompt:', prompt);
|
|
470
|
-
const startTime = Date.now();
|
|
471
|
-
const collectedText = [];
|
|
472
|
-
try {
|
|
473
|
-
let retryCount = 0;
|
|
474
|
-
const maxRetries = retryConfig?.maxRetries ?? 0;
|
|
475
|
-
// Turn completion signals — resolveCurrentTurn is called when a 'result'
|
|
476
|
-
// message arrives; the prompt generator awaits currentTurnDone between turns.
|
|
477
|
-
let resolveCurrentTurn;
|
|
478
|
-
let currentTurnDone;
|
|
479
|
-
// Set by the message loop when a fatal SDK error is detected (e.g. service
|
|
480
|
-
// unavailability). The prompt stream checks this before yielding retry
|
|
481
|
-
// prompts so we fail fast instead of burning minutes on hopeless retries.
|
|
482
|
-
let abortRetries = false;
|
|
483
|
-
function resetTurnSignal() {
|
|
484
|
-
currentTurnDone = new Promise((resolve) => {
|
|
485
|
-
resolveCurrentTurn = resolve;
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
resetTurnSignal();
|
|
489
|
-
const createPromptStream = async function* () {
|
|
490
|
-
yield {
|
|
491
|
-
type: 'user',
|
|
492
|
-
session_id: '',
|
|
493
|
-
message: { role: 'user', content: prompt },
|
|
494
|
-
parent_tool_use_id: null,
|
|
495
|
-
};
|
|
496
|
-
if (retryConfig && maxRetries > 0) {
|
|
497
|
-
while (retryCount < maxRetries) {
|
|
498
|
-
await currentTurnDone;
|
|
499
|
-
// Don't send correction prompts when the service itself is down
|
|
500
|
-
if (abortRetries) {
|
|
501
|
-
logInfo('Skipping validation retries due to service error');
|
|
502
|
-
break;
|
|
503
|
-
}
|
|
504
|
-
emitter?.emit('validation:retry:start', { attempt: retryCount + 1 });
|
|
505
|
-
let validationPrompt;
|
|
506
|
-
try {
|
|
507
|
-
validationPrompt = await retryConfig.validateAndFormat(agentConfig.workingDirectory);
|
|
508
|
-
}
|
|
509
|
-
catch (err) {
|
|
510
|
-
// Don't block on validation bugs — treat as passed
|
|
511
|
-
logError('validateAndFormat threw:', err);
|
|
512
|
-
validationPrompt = null;
|
|
513
|
-
}
|
|
514
|
-
emitter?.emit('validation:retry:complete', {
|
|
515
|
-
attempt: retryCount + 1,
|
|
516
|
-
passed: validationPrompt === null,
|
|
517
|
-
});
|
|
518
|
-
if (validationPrompt === null)
|
|
519
|
-
break;
|
|
520
|
-
retryCount++;
|
|
521
|
-
emitter?.emit('agent:retry', { attempt: retryCount, maxRetries });
|
|
522
|
-
resetTurnSignal();
|
|
523
|
-
yield {
|
|
524
|
-
type: 'user',
|
|
525
|
-
session_id: '',
|
|
526
|
-
message: { role: 'user', content: validationPrompt },
|
|
527
|
-
parent_tool_use_id: null,
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
await currentTurnDone;
|
|
532
|
-
};
|
|
533
|
-
// Load plugin from @workos/skills package
|
|
534
|
-
const pluginPath = dirname(getSkillsPackageDir());
|
|
535
|
-
logInfo('Loading plugin from:', pluginPath);
|
|
536
|
-
const response = query({
|
|
537
|
-
prompt: createPromptStream(),
|
|
538
|
-
options: {
|
|
539
|
-
model: agentConfig.model,
|
|
540
|
-
cwd: agentConfig.workingDirectory,
|
|
541
|
-
permissionMode: 'acceptEdits',
|
|
542
|
-
mcpServers: agentConfig.mcpServers,
|
|
543
|
-
env: agentConfig.sdkEnv,
|
|
544
|
-
canUseTool: (toolName, input) => {
|
|
545
|
-
logInfo('canUseTool called:', { toolName, input });
|
|
546
|
-
const result = installerCanUseTool(toolName, input);
|
|
547
|
-
logInfo('canUseTool result:', result);
|
|
548
|
-
return Promise.resolve(result);
|
|
549
|
-
},
|
|
550
|
-
tools: { type: 'preset', preset: 'claude_code' },
|
|
551
|
-
allowedTools: agentConfig.allowedTools,
|
|
552
|
-
plugins: [{ type: 'local', path: pluginPath }],
|
|
553
|
-
// Capture stderr from CLI subprocess for debugging
|
|
554
|
-
stderr: (data) => {
|
|
555
|
-
logInfo('CLI stderr:', data);
|
|
556
|
-
if (options.debug) {
|
|
557
|
-
debug('CLI stderr:', data);
|
|
558
|
-
}
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
});
|
|
562
|
-
// Process the async generator
|
|
563
|
-
let sdkError;
|
|
564
|
-
for await (const message of response) {
|
|
565
|
-
const messageError = handleSDKMessage(message, options, collectedText, emitter);
|
|
566
|
-
if (messageError) {
|
|
567
|
-
sdkError = messageError;
|
|
568
|
-
// Signal the prompt stream to stop yielding retry prompts
|
|
569
|
-
abortRetries = true;
|
|
570
|
-
}
|
|
571
|
-
if (message.type === 'result') {
|
|
572
|
-
resolveCurrentTurn();
|
|
573
|
-
}
|
|
574
|
-
try {
|
|
575
|
-
onMessage?.(message);
|
|
576
|
-
}
|
|
577
|
-
catch {
|
|
578
|
-
/* non-critical */
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
const durationMs = Date.now() - startTime;
|
|
582
|
-
const outputText = collectedText.join('\n');
|
|
583
|
-
// Check for SDK errors first (e.g., API errors, auth failures)
|
|
584
|
-
// Return error type + message - caller decides whether to throw or emit events
|
|
585
|
-
if (sdkError) {
|
|
586
|
-
if (sdkError.startsWith(SERVICE_UNAVAILABLE_PREFIX)) {
|
|
587
|
-
const detail = sdkError.slice(SERVICE_UNAVAILABLE_PREFIX.length);
|
|
588
|
-
logError('AI service unavailable:', detail);
|
|
589
|
-
return {
|
|
590
|
-
error: AgentErrorType.SERVICE_UNAVAILABLE,
|
|
591
|
-
errorMessage: 'The AI service is temporarily unavailable. Please try again in a few minutes.',
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
if (sdkError.startsWith(RATE_LIMITED_PREFIX)) {
|
|
595
|
-
const detail = sdkError.slice(RATE_LIMITED_PREFIX.length);
|
|
596
|
-
logError('AI service rate-limited:', detail);
|
|
597
|
-
return {
|
|
598
|
-
error: AgentErrorType.SERVICE_UNAVAILABLE,
|
|
599
|
-
errorMessage: 'The AI service is currently rate-limited. Please wait a minute and try again.',
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
logError('Agent SDK error:', sdkError);
|
|
603
|
-
return { error: AgentErrorType.EXECUTION_ERROR, errorMessage: sdkError };
|
|
604
|
-
}
|
|
605
|
-
// Check for error markers in the agent's output
|
|
606
|
-
if (outputText.includes(AgentSignals.ERROR_MCP_MISSING)) {
|
|
607
|
-
logError('Agent error: MCP_MISSING');
|
|
608
|
-
return { error: AgentErrorType.MCP_MISSING, errorMessage: 'Could not access WorkOS MCP server' };
|
|
609
|
-
}
|
|
610
|
-
if (outputText.includes(AgentSignals.ERROR_RESOURCE_MISSING)) {
|
|
611
|
-
logError('Agent error: RESOURCE_MISSING');
|
|
612
|
-
return { error: AgentErrorType.RESOURCE_MISSING, errorMessage: 'Could not access setup resource' };
|
|
613
|
-
}
|
|
614
|
-
logInfo(`Agent run completed in ${Math.round(durationMs / 1000)}s (${retryCount} retries)`);
|
|
615
|
-
analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
|
|
616
|
-
action: 'agent integration completed',
|
|
617
|
-
duration_ms: durationMs,
|
|
618
|
-
duration_seconds: Math.round(durationMs / 1000),
|
|
619
|
-
retry_count: retryCount,
|
|
620
|
-
max_retries: maxRetries,
|
|
621
|
-
passed_after_retry: retryCount > 0,
|
|
622
|
-
});
|
|
623
|
-
// Don't emit agent:success here - let the state machine handle lifecycle events
|
|
624
|
-
return { retryCount };
|
|
625
|
-
}
|
|
626
|
-
catch (error) {
|
|
627
|
-
// Don't emit events here - just log and re-throw for state machine to handle
|
|
628
|
-
logError('Agent run failed:', error);
|
|
629
|
-
debug('Full error:', error);
|
|
630
|
-
throw error;
|
|
631
|
-
}
|
|
632
|
-
finally {
|
|
633
|
-
// Always clean up proxy when agent run completes
|
|
634
|
-
if (activeProxyHandle) {
|
|
635
|
-
logInfo('[agent-interface] Stopping credential proxy');
|
|
636
|
-
analytics.capture('installer.proxy', {
|
|
637
|
-
action: 'stop',
|
|
638
|
-
port: activeProxyHandle.port,
|
|
639
|
-
});
|
|
640
|
-
await activeProxyHandle.stop();
|
|
641
|
-
activeProxyHandle = null;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Handle SDK messages and emit events for adapters to render.
|
|
647
|
-
* @returns Error message if this was an error result, undefined otherwise
|
|
648
|
-
*/
|
|
649
|
-
function handleSDKMessage(message, options, collectedText, emitter) {
|
|
650
|
-
logInfo(`SDK Message: ${message.type}`, JSON.stringify(message, null, 2));
|
|
651
|
-
switch (message.type) {
|
|
652
|
-
case 'assistant': {
|
|
653
|
-
// Extract usage data from Anthropic API response for telemetry
|
|
654
|
-
const usage = message.message?.usage;
|
|
655
|
-
if (usage) {
|
|
656
|
-
const inputTokens = usage.input_tokens ?? 0;
|
|
657
|
-
const outputTokens = usage.output_tokens ?? 0;
|
|
658
|
-
const model = message.message?.model ?? 'unknown';
|
|
659
|
-
analytics.llmRequest(model, inputTokens, outputTokens);
|
|
660
|
-
analytics.incrementAgentIterations();
|
|
661
|
-
}
|
|
662
|
-
// Extract text content from assistant messages
|
|
663
|
-
const content = message.message?.content;
|
|
664
|
-
if (Array.isArray(content)) {
|
|
665
|
-
for (const block of content) {
|
|
666
|
-
if (block.type === 'text' && typeof block.text === 'string') {
|
|
667
|
-
collectedText.push(block.text);
|
|
668
|
-
// Emit output event for dashboard
|
|
669
|
-
emitter?.emit('output', { text: block.text });
|
|
670
|
-
// Check for [STATUS] markers and emit progress events
|
|
671
|
-
const statusRegex = new RegExp(`^.*${AgentSignals.STATUS.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*(.+?)$`, 'm');
|
|
672
|
-
const statusMatch = block.text.match(statusRegex);
|
|
673
|
-
if (statusMatch) {
|
|
674
|
-
const statusText = statusMatch[1].trim();
|
|
675
|
-
// Emit progress event - adapters handle spinner updates
|
|
676
|
-
emitter?.emit('agent:progress', { step: statusText });
|
|
677
|
-
emitter?.emit('status', { message: statusText });
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
// Check for tool_use blocks (Write/Edit operations)
|
|
681
|
-
if (block.type === 'tool_use') {
|
|
682
|
-
const toolName = block.name;
|
|
683
|
-
const toolUseId = block.id;
|
|
684
|
-
const input = block.input;
|
|
685
|
-
// Log tool usage for debugging
|
|
686
|
-
logInfo(`Tool use: ${toolName}`);
|
|
687
|
-
// Track tool start time for telemetry
|
|
688
|
-
if (toolUseId) {
|
|
689
|
-
pendingToolCalls.set(toolUseId, { toolName, startTime: Date.now() });
|
|
690
|
-
}
|
|
691
|
-
// Emit file:write event for Write tool
|
|
692
|
-
if (toolName === 'Write' && input) {
|
|
693
|
-
const filePath = input.file_path;
|
|
694
|
-
const fileContent = input.content;
|
|
695
|
-
if (filePath && fileContent) {
|
|
696
|
-
emitter?.emit('file:write', { path: filePath, content: fileContent });
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
// Emit file:edit event for Edit tool
|
|
700
|
-
if (toolName === 'Edit' && input) {
|
|
701
|
-
const filePath = input.file_path;
|
|
702
|
-
const oldString = input.old_string;
|
|
703
|
-
const newString = input.new_string;
|
|
704
|
-
if (filePath && oldString !== undefined && newString !== undefined) {
|
|
705
|
-
// Emit the actual strings being replaced, not reconstructed full file
|
|
706
|
-
emitter?.emit('file:edit', {
|
|
707
|
-
path: filePath,
|
|
708
|
-
oldContent: oldString,
|
|
709
|
-
newContent: newString,
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
// Surface Bash commands (post-permission: this branch only fires for
|
|
714
|
-
// tool calls that were actually allowed, unlike the canUseTool closure).
|
|
715
|
-
if (toolName === 'Bash' && input) {
|
|
716
|
-
const command = input.command;
|
|
717
|
-
if (command) {
|
|
718
|
-
emitter?.emit('agent:tool', { kind: 'command', detail: command });
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
// Track Read operations for caching file content later
|
|
722
|
-
if (toolName === 'Read' && input && block.id) {
|
|
723
|
-
const filePath = input.file_path;
|
|
724
|
-
if (filePath) {
|
|
725
|
-
pendingReads.set(block.id, filePath);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
case 'user': {
|
|
734
|
-
// User messages contain tool results
|
|
735
|
-
const content = message.message?.content;
|
|
736
|
-
if (Array.isArray(content)) {
|
|
737
|
-
for (const block of content) {
|
|
738
|
-
// Tool results contain file content from Read operations
|
|
739
|
-
if (block.type === 'tool_result' && block.tool_use_id) {
|
|
740
|
-
const toolUseId = block.tool_use_id;
|
|
741
|
-
// Emit telemetry for completed tool call
|
|
742
|
-
const pendingTool = pendingToolCalls.get(toolUseId);
|
|
743
|
-
if (pendingTool) {
|
|
744
|
-
const durationMs = Date.now() - pendingTool.startTime;
|
|
745
|
-
// Check if tool result indicates error (is_error field or error in content)
|
|
746
|
-
const isError = block.is_error === true;
|
|
747
|
-
analytics.toolCalled(pendingTool.toolName, durationMs, !isError);
|
|
748
|
-
pendingToolCalls.delete(toolUseId);
|
|
749
|
-
}
|
|
750
|
-
const filePath = pendingReads.get(toolUseId);
|
|
751
|
-
if (filePath) {
|
|
752
|
-
// Extract content from the tool result
|
|
753
|
-
let resultContent = '';
|
|
754
|
-
if (typeof block.content === 'string') {
|
|
755
|
-
resultContent = block.content;
|
|
756
|
-
}
|
|
757
|
-
else if (Array.isArray(block.content)) {
|
|
758
|
-
// Content might be array of text blocks
|
|
759
|
-
for (const item of block.content) {
|
|
760
|
-
if (item.type === 'text' && item.text) {
|
|
761
|
-
resultContent += item.text;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if (resultContent) {
|
|
766
|
-
fileContentCache.set(filePath, resultContent);
|
|
767
|
-
}
|
|
768
|
-
pendingReads.delete(toolUseId);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
case 'result': {
|
|
776
|
-
// The SDK may return subtype 'success' with is_error: true when API
|
|
777
|
-
// retries are exhausted (e.g., persistent 500s). Check is_error first.
|
|
778
|
-
const isResultError = message.is_error === true;
|
|
779
|
-
if (isResultError) {
|
|
780
|
-
const resultText = typeof message.result === 'string' ? message.result : '';
|
|
781
|
-
logError('Agent result marked as error:', resultText);
|
|
782
|
-
// Detect rate limiting (429) — check before 5xx so it gets distinct messaging
|
|
783
|
-
if (/\b429\b/.test(resultText) || /rate.limit/i.test(resultText)) {
|
|
784
|
-
return `${RATE_LIMITED_PREFIX}${resultText}`;
|
|
785
|
-
}
|
|
786
|
-
// Detect service unavailability (API 500, upstream outage)
|
|
787
|
-
if (/\b50[0-9]\b/.test(resultText) || /server_error|internal_error|overloaded/.test(resultText)) {
|
|
788
|
-
return `${SERVICE_UNAVAILABLE_PREFIX}${resultText}`;
|
|
789
|
-
}
|
|
790
|
-
return resultText || 'Agent execution failed';
|
|
791
|
-
}
|
|
792
|
-
if (message.subtype === 'success') {
|
|
793
|
-
logInfo('Agent completed successfully');
|
|
794
|
-
if (typeof message.result === 'string') {
|
|
795
|
-
collectedText.push(message.result);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
else {
|
|
799
|
-
// Error result
|
|
800
|
-
logError('Agent error result:', message.subtype);
|
|
801
|
-
if (message.errors && message.errors.length > 0) {
|
|
802
|
-
for (const err of message.errors) {
|
|
803
|
-
logError('ERROR:', err);
|
|
804
|
-
// Emit error event - adapters handle rendering
|
|
805
|
-
emitter?.emit('error', { message: err });
|
|
806
|
-
}
|
|
807
|
-
// Return the first error message
|
|
808
|
-
return message.errors[0];
|
|
809
|
-
}
|
|
810
|
-
// Return generic error if subtype indicates failure but no errors array
|
|
811
|
-
return `Agent execution failed: ${message.subtype}`;
|
|
812
|
-
}
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
case 'system': {
|
|
816
|
-
if (message.subtype === 'init') {
|
|
817
|
-
logInfo('Agent session initialized', {
|
|
818
|
-
model: message.model,
|
|
819
|
-
tools: message.tools?.length,
|
|
820
|
-
mcpServers: message.mcp_servers,
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
break;
|
|
824
|
-
}
|
|
825
|
-
default:
|
|
826
|
-
// Log other message types for debugging
|
|
827
|
-
if (options.debug) {
|
|
828
|
-
debug(`Unhandled message type: ${message.type}`);
|
|
829
|
-
}
|
|
830
|
-
break;
|
|
831
|
-
}
|
|
832
|
-
return undefined;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Get the active proxy handle (for testing/debugging).
|
|
836
|
-
*/
|
|
837
|
-
export function getActiveProxyHandle() {
|
|
838
|
-
return activeProxyHandle;
|
|
839
|
-
}
|
|
840
|
-
//# sourceMappingURL=agent-interface.js.map
|