agent-relay 2.0.23 → 2.0.25

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.
Files changed (168) hide show
  1. package/dist/src/cli/index.js +160 -17
  2. package/package.json +18 -52
  3. package/packages/api-types/package.json +1 -1
  4. package/packages/bridge/package.json +8 -8
  5. package/packages/cli-tester/package.json +1 -1
  6. package/packages/config/package.json +2 -2
  7. package/packages/continuity/package.json +1 -1
  8. package/packages/daemon/package.json +12 -12
  9. package/packages/hooks/package.json +4 -4
  10. package/packages/mcp/package.json +2 -2
  11. package/packages/memory/package.json +2 -2
  12. package/packages/policy/package.json +2 -2
  13. package/packages/protocol/package.json +1 -1
  14. package/packages/resiliency/package.json +1 -1
  15. package/packages/sdk/package.json +2 -2
  16. package/packages/spawner/package.json +1 -1
  17. package/packages/state/package.json +1 -1
  18. package/packages/storage/package.json +2 -2
  19. package/packages/telemetry/package.json +1 -1
  20. package/packages/trajectory/package.json +2 -2
  21. package/packages/user-directory/package.json +2 -2
  22. package/packages/utils/package.json +1 -1
  23. package/packages/wrapper/package.json +6 -6
  24. package/deploy/init-db.sql +0 -5
  25. package/deploy/scripts/setup-fly-workspaces.sh +0 -69
  26. package/deploy/scripts/setup-railway.sh +0 -75
  27. package/dist/src/cloud/index.d.ts +0 -8
  28. package/dist/src/cloud/index.js +0 -8
  29. package/packages/cloud/dist/api/admin.d.ts +0 -8
  30. package/packages/cloud/dist/api/admin.js +0 -225
  31. package/packages/cloud/dist/api/auth.d.ts +0 -20
  32. package/packages/cloud/dist/api/auth.js +0 -138
  33. package/packages/cloud/dist/api/billing.d.ts +0 -7
  34. package/packages/cloud/dist/api/billing.js +0 -564
  35. package/packages/cloud/dist/api/cli-pty-runner.d.ts +0 -53
  36. package/packages/cloud/dist/api/cli-pty-runner.js +0 -175
  37. package/packages/cloud/dist/api/codex-auth-helper.d.ts +0 -21
  38. package/packages/cloud/dist/api/codex-auth-helper.js +0 -327
  39. package/packages/cloud/dist/api/consensus.d.ts +0 -13
  40. package/packages/cloud/dist/api/consensus.js +0 -261
  41. package/packages/cloud/dist/api/coordinators.d.ts +0 -8
  42. package/packages/cloud/dist/api/coordinators.js +0 -750
  43. package/packages/cloud/dist/api/daemons.d.ts +0 -12
  44. package/packages/cloud/dist/api/daemons.js +0 -535
  45. package/packages/cloud/dist/api/email-auth.d.ts +0 -11
  46. package/packages/cloud/dist/api/email-auth.js +0 -347
  47. package/packages/cloud/dist/api/generic-webhooks.d.ts +0 -8
  48. package/packages/cloud/dist/api/generic-webhooks.js +0 -129
  49. package/packages/cloud/dist/api/git.d.ts +0 -8
  50. package/packages/cloud/dist/api/git.js +0 -269
  51. package/packages/cloud/dist/api/github-app.d.ts +0 -11
  52. package/packages/cloud/dist/api/github-app.js +0 -223
  53. package/packages/cloud/dist/api/middleware/planLimits.d.ts +0 -43
  54. package/packages/cloud/dist/api/middleware/planLimits.js +0 -202
  55. package/packages/cloud/dist/api/monitoring.d.ts +0 -11
  56. package/packages/cloud/dist/api/monitoring.js +0 -578
  57. package/packages/cloud/dist/api/nango-auth.d.ts +0 -9
  58. package/packages/cloud/dist/api/nango-auth.js +0 -741
  59. package/packages/cloud/dist/api/onboarding.d.ts +0 -15
  60. package/packages/cloud/dist/api/onboarding.js +0 -679
  61. package/packages/cloud/dist/api/policy.d.ts +0 -8
  62. package/packages/cloud/dist/api/policy.js +0 -229
  63. package/packages/cloud/dist/api/provider-env.d.ts +0 -26
  64. package/packages/cloud/dist/api/provider-env.js +0 -141
  65. package/packages/cloud/dist/api/providers.d.ts +0 -7
  66. package/packages/cloud/dist/api/providers.js +0 -574
  67. package/packages/cloud/dist/api/repos.d.ts +0 -8
  68. package/packages/cloud/dist/api/repos.js +0 -577
  69. package/packages/cloud/dist/api/sessions.d.ts +0 -11
  70. package/packages/cloud/dist/api/sessions.js +0 -302
  71. package/packages/cloud/dist/api/teams.d.ts +0 -7
  72. package/packages/cloud/dist/api/teams.js +0 -281
  73. package/packages/cloud/dist/api/test-helpers.d.ts +0 -10
  74. package/packages/cloud/dist/api/test-helpers.js +0 -745
  75. package/packages/cloud/dist/api/usage.d.ts +0 -7
  76. package/packages/cloud/dist/api/usage.js +0 -111
  77. package/packages/cloud/dist/api/webhooks.d.ts +0 -8
  78. package/packages/cloud/dist/api/webhooks.js +0 -645
  79. package/packages/cloud/dist/api/workspaces.d.ts +0 -25
  80. package/packages/cloud/dist/api/workspaces.js +0 -1799
  81. package/packages/cloud/dist/billing/index.d.ts +0 -9
  82. package/packages/cloud/dist/billing/index.js +0 -9
  83. package/packages/cloud/dist/billing/plans.d.ts +0 -39
  84. package/packages/cloud/dist/billing/plans.js +0 -245
  85. package/packages/cloud/dist/billing/service.d.ts +0 -80
  86. package/packages/cloud/dist/billing/service.js +0 -388
  87. package/packages/cloud/dist/billing/types.d.ts +0 -141
  88. package/packages/cloud/dist/billing/types.js +0 -7
  89. package/packages/cloud/dist/config.d.ts +0 -5
  90. package/packages/cloud/dist/config.js +0 -5
  91. package/packages/cloud/dist/db/bulk-ingest.d.ts +0 -89
  92. package/packages/cloud/dist/db/bulk-ingest.js +0 -268
  93. package/packages/cloud/dist/db/drizzle.d.ts +0 -290
  94. package/packages/cloud/dist/db/drizzle.js +0 -1422
  95. package/packages/cloud/dist/db/index.d.ts +0 -56
  96. package/packages/cloud/dist/db/index.js +0 -70
  97. package/packages/cloud/dist/db/schema.d.ts +0 -5117
  98. package/packages/cloud/dist/db/schema.js +0 -656
  99. package/packages/cloud/dist/index.d.ts +0 -11
  100. package/packages/cloud/dist/index.js +0 -38
  101. package/packages/cloud/dist/provisioner/index.d.ts +0 -207
  102. package/packages/cloud/dist/provisioner/index.js +0 -2118
  103. package/packages/cloud/dist/server.d.ts +0 -17
  104. package/packages/cloud/dist/server.js +0 -2055
  105. package/packages/cloud/dist/services/auto-scaler.d.ts +0 -152
  106. package/packages/cloud/dist/services/auto-scaler.js +0 -439
  107. package/packages/cloud/dist/services/capacity-manager.d.ts +0 -148
  108. package/packages/cloud/dist/services/capacity-manager.js +0 -449
  109. package/packages/cloud/dist/services/ci-agent-spawner.d.ts +0 -49
  110. package/packages/cloud/dist/services/ci-agent-spawner.js +0 -373
  111. package/packages/cloud/dist/services/cloud-message-bus.d.ts +0 -28
  112. package/packages/cloud/dist/services/cloud-message-bus.js +0 -19
  113. package/packages/cloud/dist/services/compute-enforcement.d.ts +0 -57
  114. package/packages/cloud/dist/services/compute-enforcement.js +0 -175
  115. package/packages/cloud/dist/services/coordinator.d.ts +0 -62
  116. package/packages/cloud/dist/services/coordinator.js +0 -389
  117. package/packages/cloud/dist/services/index.d.ts +0 -17
  118. package/packages/cloud/dist/services/index.js +0 -25
  119. package/packages/cloud/dist/services/intro-expiration.d.ts +0 -60
  120. package/packages/cloud/dist/services/intro-expiration.js +0 -252
  121. package/packages/cloud/dist/services/mention-handler.d.ts +0 -65
  122. package/packages/cloud/dist/services/mention-handler.js +0 -405
  123. package/packages/cloud/dist/services/nango.d.ts +0 -219
  124. package/packages/cloud/dist/services/nango.js +0 -424
  125. package/packages/cloud/dist/services/persistence.d.ts +0 -131
  126. package/packages/cloud/dist/services/persistence.js +0 -200
  127. package/packages/cloud/dist/services/planLimits.d.ts +0 -147
  128. package/packages/cloud/dist/services/planLimits.js +0 -335
  129. package/packages/cloud/dist/services/presence-registry.d.ts +0 -56
  130. package/packages/cloud/dist/services/presence-registry.js +0 -91
  131. package/packages/cloud/dist/services/scaling-orchestrator.d.ts +0 -159
  132. package/packages/cloud/dist/services/scaling-orchestrator.js +0 -502
  133. package/packages/cloud/dist/services/scaling-policy.d.ts +0 -121
  134. package/packages/cloud/dist/services/scaling-policy.js +0 -415
  135. package/packages/cloud/dist/services/ssh-security.d.ts +0 -31
  136. package/packages/cloud/dist/services/ssh-security.js +0 -63
  137. package/packages/cloud/dist/services/workspace-keepalive.d.ts +0 -76
  138. package/packages/cloud/dist/services/workspace-keepalive.js +0 -234
  139. package/packages/cloud/dist/shims/consensus.d.ts +0 -23
  140. package/packages/cloud/dist/shims/consensus.js +0 -5
  141. package/packages/cloud/dist/webhooks/index.d.ts +0 -24
  142. package/packages/cloud/dist/webhooks/index.js +0 -29
  143. package/packages/cloud/dist/webhooks/parsers/github.d.ts +0 -8
  144. package/packages/cloud/dist/webhooks/parsers/github.js +0 -234
  145. package/packages/cloud/dist/webhooks/parsers/index.d.ts +0 -23
  146. package/packages/cloud/dist/webhooks/parsers/index.js +0 -30
  147. package/packages/cloud/dist/webhooks/parsers/linear.d.ts +0 -9
  148. package/packages/cloud/dist/webhooks/parsers/linear.js +0 -258
  149. package/packages/cloud/dist/webhooks/parsers/slack.d.ts +0 -9
  150. package/packages/cloud/dist/webhooks/parsers/slack.js +0 -214
  151. package/packages/cloud/dist/webhooks/responders/github.d.ts +0 -8
  152. package/packages/cloud/dist/webhooks/responders/github.js +0 -73
  153. package/packages/cloud/dist/webhooks/responders/index.d.ts +0 -23
  154. package/packages/cloud/dist/webhooks/responders/index.js +0 -30
  155. package/packages/cloud/dist/webhooks/responders/linear.d.ts +0 -9
  156. package/packages/cloud/dist/webhooks/responders/linear.js +0 -149
  157. package/packages/cloud/dist/webhooks/responders/slack.d.ts +0 -20
  158. package/packages/cloud/dist/webhooks/responders/slack.js +0 -178
  159. package/packages/cloud/dist/webhooks/router.d.ts +0 -25
  160. package/packages/cloud/dist/webhooks/router.js +0 -504
  161. package/packages/cloud/dist/webhooks/rules-engine.d.ts +0 -24
  162. package/packages/cloud/dist/webhooks/rules-engine.js +0 -287
  163. package/packages/cloud/dist/webhooks/types.d.ts +0 -186
  164. package/packages/cloud/dist/webhooks/types.js +0 -8
  165. package/packages/cloud/package.json +0 -60
  166. package/scripts/run-migrations.js +0 -43
  167. package/scripts/setup-stripe-products.ts +0 -312
  168. package/scripts/verify-schema.js +0 -134
@@ -1,229 +0,0 @@
1
- /**
2
- * Agent Policy API Routes
3
- *
4
- * Provides endpoints for managing workspace-level agent policies.
5
- * These policies serve as fallbacks when repos don't have .claude/policies/ files.
6
- */
7
- import { Router } from 'express';
8
- import { db } from '../db/index.js';
9
- export const policyRouter = Router();
10
- /**
11
- * GET /api/policy/:workspaceId
12
- * Get the agent policy for a workspace
13
- */
14
- policyRouter.get('/:workspaceId', async (req, res) => {
15
- const workspaceId = req.params.workspaceId;
16
- const userId = req.userId;
17
- if (!userId) {
18
- return res.status(401).json({ error: 'Unauthorized' });
19
- }
20
- try {
21
- const workspace = await db.workspaces.findById(workspaceId);
22
- if (!workspace) {
23
- return res.status(404).json({ error: 'Workspace not found' });
24
- }
25
- // Check user has access to this workspace
26
- if (workspace.userId !== userId) {
27
- const members = await db.workspaceMembers.findByWorkspaceId(workspaceId);
28
- const member = members.find(m => m.userId === userId);
29
- if (!member) {
30
- return res.status(403).json({ error: 'Access denied' });
31
- }
32
- }
33
- // Return the policy (or default if not set)
34
- const policy = workspace.config?.agentPolicy ?? getDefaultPolicy();
35
- res.json({
36
- workspaceId,
37
- policy,
38
- source: workspace.config?.agentPolicy ? 'workspace' : 'default',
39
- });
40
- }
41
- catch (error) {
42
- console.error('[policy] Error getting policy:', error);
43
- res.status(500).json({ error: 'Failed to get policy' });
44
- }
45
- });
46
- /**
47
- * PUT /api/policy/:workspaceId
48
- * Update the agent policy for a workspace
49
- */
50
- policyRouter.put('/:workspaceId', async (req, res) => {
51
- const workspaceId = req.params.workspaceId;
52
- const userId = req.userId;
53
- const policy = req.body.policy;
54
- if (!userId) {
55
- return res.status(401).json({ error: 'Unauthorized' });
56
- }
57
- if (!policy || typeof policy !== 'object') {
58
- return res.status(400).json({ error: 'Policy object is required' });
59
- }
60
- try {
61
- const workspace = await db.workspaces.findById(workspaceId);
62
- if (!workspace) {
63
- return res.status(404).json({ error: 'Workspace not found' });
64
- }
65
- // Only owner can update policy
66
- if (workspace.userId !== userId) {
67
- const members = await db.workspaceMembers.findByWorkspaceId(workspaceId);
68
- const member = members.find(m => m.userId === userId);
69
- if (!member || !['owner', 'admin'].includes(member.role)) {
70
- return res.status(403).json({ error: 'Only owners and admins can update policy' });
71
- }
72
- }
73
- // Validate policy structure
74
- const validationError = validatePolicy(policy);
75
- if (validationError) {
76
- return res.status(400).json({ error: validationError });
77
- }
78
- // Update workspace config with new policy
79
- const newConfig = {
80
- ...workspace.config,
81
- agentPolicy: policy,
82
- };
83
- await db.workspaces.updateConfig(workspaceId, newConfig);
84
- res.json({
85
- success: true,
86
- workspaceId,
87
- policy,
88
- });
89
- }
90
- catch (error) {
91
- console.error('[policy] Error updating policy:', error);
92
- res.status(500).json({ error: 'Failed to update policy' });
93
- }
94
- });
95
- /**
96
- * DELETE /api/policy/:workspaceId
97
- * Reset workspace policy to defaults
98
- */
99
- policyRouter.delete('/:workspaceId', async (req, res) => {
100
- const workspaceId = req.params.workspaceId;
101
- const userId = req.userId;
102
- if (!userId) {
103
- return res.status(401).json({ error: 'Unauthorized' });
104
- }
105
- try {
106
- const workspace = await db.workspaces.findById(workspaceId);
107
- if (!workspace) {
108
- return res.status(404).json({ error: 'Workspace not found' });
109
- }
110
- // Only owner can reset policy
111
- if (workspace.userId !== userId) {
112
- const members = await db.workspaceMembers.findByWorkspaceId(workspaceId);
113
- const member = members.find(m => m.userId === userId);
114
- if (!member || member.role !== 'owner') {
115
- return res.status(403).json({ error: 'Only owners can reset policy' });
116
- }
117
- }
118
- // Remove policy from config
119
- const { agentPolicy: _agentPolicy, ...restConfig } = workspace.config ?? {};
120
- await db.workspaces.updateConfig(workspaceId, restConfig);
121
- res.json({
122
- success: true,
123
- workspaceId,
124
- policy: getDefaultPolicy(),
125
- source: 'default',
126
- });
127
- }
128
- catch (error) {
129
- console.error('[policy] Error resetting policy:', error);
130
- res.status(500).json({ error: 'Failed to reset policy' });
131
- }
132
- });
133
- /**
134
- * GET /api/policy/:workspaceId/internal
135
- * Internal endpoint for workspace containers to fetch policy
136
- * Uses workspace token authentication (not user auth)
137
- */
138
- policyRouter.get('/:workspaceId/internal', async (req, res) => {
139
- const workspaceId = req.params.workspaceId;
140
- // This endpoint should be called with the workspace token
141
- // The git.ts file has the token verification logic we can reuse
142
- // For now, we'll trust the workspace ID from container requests
143
- try {
144
- const workspace = await db.workspaces.findById(workspaceId);
145
- if (!workspace) {
146
- return res.status(404).json({ error: 'Workspace not found' });
147
- }
148
- const policy = workspace.config?.agentPolicy ?? getDefaultPolicy();
149
- res.json({
150
- defaultPolicy: policy.defaultPolicy,
151
- agents: policy.agents ?? [],
152
- settings: policy.settings ?? {
153
- requireExplicitAgents: false,
154
- auditEnabled: true,
155
- maxTotalAgents: 50,
156
- },
157
- });
158
- }
159
- catch (error) {
160
- console.error('[policy] Error getting internal policy:', error);
161
- res.status(500).json({ error: 'Failed to get policy' });
162
- }
163
- });
164
- /**
165
- * Get default policy
166
- */
167
- function getDefaultPolicy() {
168
- return {
169
- defaultPolicy: {
170
- name: '*',
171
- allowedTools: undefined, // All tools allowed
172
- canSpawn: undefined, // Can spawn any
173
- canMessage: undefined, // Can message any
174
- maxSpawns: 10,
175
- rateLimit: 60,
176
- canBeSpawned: true,
177
- },
178
- agents: [],
179
- settings: {
180
- requireExplicitAgents: false,
181
- auditEnabled: true,
182
- maxTotalAgents: 50,
183
- },
184
- };
185
- }
186
- /**
187
- * Validate policy structure
188
- */
189
- function validatePolicy(policy) {
190
- // Validate defaultPolicy
191
- if (policy.defaultPolicy && typeof policy.defaultPolicy !== 'object') {
192
- return 'defaultPolicy must be an object';
193
- }
194
- // Validate agents array
195
- if (policy.agents) {
196
- if (!Array.isArray(policy.agents)) {
197
- return 'agents must be an array';
198
- }
199
- for (let i = 0; i < policy.agents.length; i++) {
200
- const agent = policy.agents[i];
201
- if (!agent.name || typeof agent.name !== 'string') {
202
- return `agents[${i}].name is required and must be a string`;
203
- }
204
- // Validate arrays
205
- if (agent.allowedTools && !Array.isArray(agent.allowedTools)) {
206
- return `agents[${i}].allowedTools must be an array`;
207
- }
208
- if (agent.canSpawn && !Array.isArray(agent.canSpawn)) {
209
- return `agents[${i}].canSpawn must be an array`;
210
- }
211
- if (agent.canMessage && !Array.isArray(agent.canMessage)) {
212
- return `agents[${i}].canMessage must be an array`;
213
- }
214
- // Validate numbers
215
- if (agent.maxSpawns !== undefined && typeof agent.maxSpawns !== 'number') {
216
- return `agents[${i}].maxSpawns must be a number`;
217
- }
218
- if (agent.rateLimit !== undefined && typeof agent.rateLimit !== 'number') {
219
- return `agents[${i}].rateLimit must be a number`;
220
- }
221
- }
222
- }
223
- // Validate settings
224
- if (policy.settings && typeof policy.settings !== 'object') {
225
- return 'settings must be an object';
226
- }
227
- return null;
228
- }
229
- //# sourceMappingURL=policy.js.map
@@ -1,26 +0,0 @@
1
- /**
2
- * Set provider API key as environment variable on workspace(s)
3
- * and write credential files for providers that need them.
4
- *
5
- * @param userId - User ID
6
- * @param provider - Provider name (e.g., 'google', 'gemini')
7
- * @param apiKey - API key to set
8
- * @param workspaceId - Optional: specific workspace to update. If not provided, updates all user workspaces (legacy behavior)
9
- */
10
- export declare function setProviderApiKeyEnv(userId: string, provider: string, apiKey: string, workspaceId?: string): Promise<{
11
- updated: number;
12
- skipped: number;
13
- }>;
14
- /**
15
- * Clear provider credentials from workspace(s).
16
- * Deletes credential files and unsets environment variables.
17
- *
18
- * @param userId - User ID
19
- * @param provider - Provider name (e.g., 'google', 'anthropic', 'codex')
20
- * @param workspaceId - Workspace to clear credentials from
21
- */
22
- export declare function clearProviderCredentials(userId: string, provider: string, workspaceId: string): Promise<{
23
- cleared: boolean;
24
- error?: string;
25
- }>;
26
- //# sourceMappingURL=provider-env.d.ts.map
@@ -1,141 +0,0 @@
1
- import { db } from '../db/index.js';
2
- import { getProvisioner } from '../provisioner/index.js';
3
- const PROVIDER_ENV_VARS = {
4
- google: 'GEMINI_API_KEY',
5
- gemini: 'GEMINI_API_KEY',
6
- };
7
- /**
8
- * All providers that may have credential files on the workspace.
9
- * This includes CLI-based providers that store auth locally.
10
- */
11
- const ALL_CREDENTIAL_PROVIDERS = [
12
- 'anthropic', 'claude',
13
- 'codex', 'openai',
14
- 'google', 'gemini',
15
- 'opencode',
16
- 'droid', 'factory',
17
- 'cursor',
18
- ];
19
- /**
20
- * Providers that need credential files written to the workspace filesystem.
21
- * These providers have CLIs that read from files rather than just env vars.
22
- */
23
- const PROVIDERS_NEEDING_CREDENTIAL_FILES = ['google', 'gemini'];
24
- /**
25
- * Set provider API key as environment variable on workspace(s)
26
- * and write credential files for providers that need them.
27
- *
28
- * @param userId - User ID
29
- * @param provider - Provider name (e.g., 'google', 'gemini')
30
- * @param apiKey - API key to set
31
- * @param workspaceId - Optional: specific workspace to update. If not provided, updates all user workspaces (legacy behavior)
32
- */
33
- export async function setProviderApiKeyEnv(userId, provider, apiKey, workspaceId) {
34
- const envVarName = PROVIDER_ENV_VARS[provider];
35
- const needsCredentialFile = PROVIDERS_NEEDING_CREDENTIAL_FILES.includes(provider);
36
- // If no env var and no credential file needed, nothing to do
37
- if (!envVarName && !needsCredentialFile) {
38
- return { updated: 0, skipped: 0 };
39
- }
40
- // If workspaceId is provided, only update that workspace
41
- // Otherwise, update all user workspaces (legacy behavior)
42
- let workspaces;
43
- if (workspaceId) {
44
- const workspace = await db.workspaces.findById(workspaceId);
45
- workspaces = workspace ? [workspace] : [];
46
- }
47
- else {
48
- workspaces = await db.workspaces.findByUserId(userId);
49
- }
50
- if (workspaces.length === 0) {
51
- return { updated: 0, skipped: 0 };
52
- }
53
- const provisioner = getProvisioner();
54
- const results = await Promise.all(workspaces.map(async (workspace) => {
55
- if (!workspace.computeId) {
56
- return 'skipped';
57
- }
58
- // Set environment variable if applicable
59
- if (envVarName) {
60
- await provisioner.setWorkspaceEnvVars(workspace, { [envVarName]: apiKey });
61
- }
62
- // Write credential file to workspace for providers that need it
63
- if (needsCredentialFile && workspace.publicUrl) {
64
- try {
65
- const response = await fetch(`${workspace.publicUrl}/api/credentials/apikey`, {
66
- method: 'POST',
67
- headers: { 'Content-Type': 'application/json' },
68
- body: JSON.stringify({ userId, provider, apiKey }),
69
- });
70
- if (!response.ok) {
71
- console.warn(`[provider-env] Failed to write credential file for ${provider} on workspace ${workspace.id}: ${response.status}`);
72
- }
73
- else {
74
- console.log(`[provider-env] Wrote ${provider} credential file for user ${userId} on workspace ${workspace.id}`);
75
- }
76
- }
77
- catch (err) {
78
- console.warn(`[provider-env] Error writing credential file for ${provider} on workspace ${workspace.id}:`, err);
79
- // Don't fail the whole operation if credential file write fails
80
- }
81
- }
82
- return 'updated';
83
- }));
84
- const updated = results.filter((result) => result === 'updated').length;
85
- return { updated, skipped: results.length - updated };
86
- }
87
- /**
88
- * Clear provider credentials from workspace(s).
89
- * Deletes credential files and unsets environment variables.
90
- *
91
- * @param userId - User ID
92
- * @param provider - Provider name (e.g., 'google', 'anthropic', 'codex')
93
- * @param workspaceId - Workspace to clear credentials from
94
- */
95
- export async function clearProviderCredentials(userId, provider, workspaceId) {
96
- const envVarName = PROVIDER_ENV_VARS[provider];
97
- const needsCredentialFileClear = ALL_CREDENTIAL_PROVIDERS.includes(provider);
98
- // Get the workspace
99
- const workspace = await db.workspaces.findById(workspaceId);
100
- if (!workspace) {
101
- return { cleared: false, error: 'Workspace not found' };
102
- }
103
- if (!workspace.publicUrl) {
104
- // Workspace not running, credentials will be gone when it restarts anyway
105
- return { cleared: true };
106
- }
107
- // Clear environment variable if applicable
108
- if (envVarName && workspace.computeId) {
109
- const provisioner = getProvisioner();
110
- try {
111
- // Set to empty string to clear
112
- await provisioner.setWorkspaceEnvVars(workspace, { [envVarName]: '' });
113
- }
114
- catch (err) {
115
- console.warn(`[provider-env] Failed to clear env var ${envVarName} on workspace ${workspace.id}:`, err);
116
- }
117
- }
118
- // Delete credential files from workspace
119
- if (needsCredentialFileClear) {
120
- try {
121
- const response = await fetch(`${workspace.publicUrl}/api/credentials/apikey`, {
122
- method: 'DELETE',
123
- headers: { 'Content-Type': 'application/json' },
124
- body: JSON.stringify({ userId, provider }),
125
- });
126
- if (!response.ok) {
127
- const data = await response.json().catch(() => ({}));
128
- console.warn(`[provider-env] Failed to delete credential files for ${provider} on workspace ${workspace.id}: ${response.status}`, data);
129
- return { cleared: false, error: 'Failed to delete credential files on workspace' };
130
- }
131
- const data = await response.json();
132
- console.log(`[provider-env] Deleted ${provider} credentials for user ${userId} on workspace ${workspace.id}:`, data.deletedPaths);
133
- }
134
- catch (err) {
135
- console.warn(`[provider-env] Error deleting credential files for ${provider} on workspace ${workspace.id}:`, err);
136
- return { cleared: false, error: 'Error connecting to workspace' };
137
- }
138
- }
139
- return { cleared: true };
140
- }
141
- //# sourceMappingURL=provider-env.js.map
@@ -1,7 +0,0 @@
1
- /**
2
- * Providers API Routes
3
- *
4
- * Handles device flow authentication for AI providers (Claude, Codex, etc.)
5
- */
6
- export declare const providersRouter: import("express-serve-static-core").Router;
7
- //# sourceMappingURL=providers.d.ts.map