@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69

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 (226) hide show
  1. package/bootstrap.json +9 -1
  2. package/dist/admin/admin.module.js +2 -0
  3. package/dist/admin/health.service.d.ts +11 -4
  4. package/dist/admin/health.service.js +33 -17
  5. package/dist/background/poll.job.js +2 -2
  6. package/dist/background/tasks.service.d.ts +5 -5
  7. package/dist/background/tasks.service.js +9 -8
  8. package/dist/catalog/credential-key.d.ts +10 -0
  9. package/dist/catalog/credential-key.js +28 -0
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.js +1 -19
  12. package/dist/catalog/requests.service.js +1 -1
  13. package/dist/config/schema.d.ts +1 -1
  14. package/dist/config/schema.js +9 -9
  15. package/dist/conversations/conversations.controller.d.ts +8 -3
  16. package/dist/conversations/conversations.controller.js +8 -3
  17. package/dist/conversations/conversations.service.d.ts +33 -15
  18. package/dist/conversations/conversations.service.js +60 -10
  19. package/dist/conversations/events.d.ts +21 -41
  20. package/dist/conversations/events.js +57 -31
  21. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  22. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  23. package/dist/ctx/create-ctx.d.ts +20 -1
  24. package/dist/ctx/create-ctx.js +77 -6
  25. package/dist/ctx/device-provider-check.d.ts +6 -2
  26. package/dist/ctx/device-provider-check.js +17 -2
  27. package/dist/db/kernel-schema.d.ts +10 -48
  28. package/dist/devices/access.d.ts +3 -4
  29. package/dist/devices/access.js +3 -4
  30. package/dist/devices/conversation-devices.d.ts +1 -3
  31. package/dist/devices/conversation-devices.js +2 -7
  32. package/dist/devices/device-projects.service.js +24 -29
  33. package/dist/devices/device-provider-selection.d.ts +5 -6
  34. package/dist/devices/device-provider-selection.js +8 -9
  35. package/dist/devices/devices.controller.d.ts +8 -21
  36. package/dist/devices/devices.controller.js +9 -34
  37. package/dist/devices/devices.module.js +6 -4
  38. package/dist/devices/devices.schemas.d.ts +1 -5
  39. package/dist/devices/devices.schemas.js +1 -5
  40. package/dist/devices/devices.service.d.ts +84 -147
  41. package/dist/devices/devices.service.js +134 -229
  42. package/dist/devices/dto.d.ts +5 -32
  43. package/dist/devices/dto.js +5 -37
  44. package/dist/devices/errors.d.ts +6 -5
  45. package/dist/devices/errors.js +7 -8
  46. package/dist/devices/project-rules.d.ts +9 -11
  47. package/dist/devices/project-rules.js +7 -7
  48. package/dist/devices/working-root.d.ts +3 -6
  49. package/dist/devices/working-root.js +3 -8
  50. package/dist/dial-in/access.d.ts +23 -0
  51. package/dist/dial-in/access.js +64 -0
  52. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  53. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  54. package/dist/dial-in/auth.module.d.ts +7 -0
  55. package/dist/dial-in/auth.module.js +27 -0
  56. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  57. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  58. package/dist/dial-in/dial-in.module.d.ts +9 -0
  59. package/dist/dial-in/dial-in.module.js +37 -0
  60. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  61. package/dist/{local-devices → dial-in}/dto.js +14 -2
  62. package/dist/dial-in/envelope.d.ts +95 -0
  63. package/dist/dial-in/envelope.js +89 -0
  64. package/dist/dial-in/gateway.d.ts +214 -0
  65. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  66. package/dist/dial-in/handlers.d.ts +47 -0
  67. package/dist/dial-in/handlers.js +84 -0
  68. package/dist/dial-in/machines.d.ts +155 -0
  69. package/dist/dial-in/machines.js +383 -0
  70. package/dist/dial-in/relay.d.ts +135 -0
  71. package/dist/dial-in/relay.js +444 -0
  72. package/dist/dial-in/relay.module.d.ts +7 -0
  73. package/dist/dial-in/relay.module.js +24 -0
  74. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  75. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  76. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  77. package/dist/{local-devices → dial-in}/targets.js +3 -48
  78. package/dist/errors.d.ts +8 -27
  79. package/dist/errors.js +8 -27
  80. package/dist/extensions/bootstrap.d.ts +5 -0
  81. package/dist/extensions/bootstrap.js +10 -1
  82. package/dist/extensions/extensions.module.js +6 -0
  83. package/dist/extensions/host.d.ts +6 -0
  84. package/dist/extensions/host.js +12 -2
  85. package/dist/extensions/permission-set.d.ts +15 -1
  86. package/dist/extensions/permission-set.js +11 -1
  87. package/dist/extensions/permission-view.d.ts +1 -1
  88. package/dist/extensions/permission-view.js +4 -1
  89. package/dist/http/api.module.js +4 -4
  90. package/dist/http/gateway-routes.d.ts +1 -1
  91. package/dist/http/gateway-routes.js +1 -1
  92. package/dist/http/meta.controller.js +1 -1
  93. package/dist/identity/settings.d.ts +1 -1
  94. package/dist/identity/settings.js +6 -8
  95. package/dist/infra/config/kernel-config.service.js +2 -2
  96. package/dist/infra/outbox/registry.d.ts +0 -14
  97. package/dist/infra/outbox/registry.js +0 -15
  98. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  99. package/dist/infra/throttler/named-throttlers.js +1 -1
  100. package/dist/kernel.module.js +0 -3
  101. package/dist/orgs/settings.service.js +5 -10
  102. package/dist/overrides.d.ts +0 -4
  103. package/dist/overrides.js +0 -2
  104. package/dist/platform/exclusions.js +5 -5
  105. package/dist/platform/ops/admin.ops.js +1 -1
  106. package/dist/platform/ops/conversations.ops.js +5 -2
  107. package/dist/platform/ops/devices.ops.js +11 -24
  108. package/dist/platform/ops/inbox.ops.js +1 -1
  109. package/dist/roles/gateway-role.d.ts +3 -3
  110. package/dist/roles/gateway-role.js +4 -4
  111. package/dist/roles/gateway.module.d.ts +1 -1
  112. package/dist/roles/gateway.module.js +5 -5
  113. package/dist/runtime/context/device-paths.d.ts +4 -1
  114. package/dist/runtime/context/permission-profile.js +5 -5
  115. package/dist/runtime/maintenance.d.ts +2 -5
  116. package/dist/runtime/maintenance.js +9 -19
  117. package/dist/runtime/project/knowledge.js +4 -5
  118. package/dist/runtime/project/knowledge.service.js +2 -1
  119. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  120. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  121. package/dist/sandbox/device-reports.d.ts +74 -14
  122. package/dist/sandbox/device-reports.js +190 -33
  123. package/dist/sandbox/device-reports.module.d.ts +7 -0
  124. package/dist/sandbox/device-reports.module.js +25 -0
  125. package/dist/sandbox/device-sandbox.d.ts +39 -41
  126. package/dist/sandbox/device-sandbox.js +44 -83
  127. package/dist/sandbox/kernel-read.d.ts +2 -2
  128. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  129. package/dist/sandbox/legacy-retirement.js +34 -186
  130. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  131. package/dist/sandbox/legacy-retirement.module.js +2 -2
  132. package/dist/sandbox/managed-device-context.d.ts +16 -4
  133. package/dist/sandbox/managed-device-context.js +25 -8
  134. package/dist/sandbox/managed-device-context.module.js +4 -0
  135. package/dist/sandbox/modes.d.ts +3 -12
  136. package/dist/sandbox/modes.js +2 -14
  137. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  138. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  139. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  140. package/dist/sandbox/operation-authority.d.ts +6 -20
  141. package/dist/sandbox/operation-authority.js +43 -104
  142. package/dist/sandbox/operation-authority.module.js +1 -1
  143. package/dist/sandbox/operation-intents.d.ts +4 -1
  144. package/dist/sandbox/operation-intents.js +11 -2
  145. package/dist/sandbox/operation-reconcile.job.js +2 -4
  146. package/dist/sandbox/permission-availability.d.ts +6 -7
  147. package/dist/sandbox/permission-availability.js +7 -10
  148. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  149. package/dist/sandbox/permission-call-grants.js +1 -7
  150. package/dist/sandbox/permission-call-types.d.ts +4 -4
  151. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  152. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  153. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  154. package/dist/sandbox/permission-config-publication.js +29 -21
  155. package/dist/sandbox/permission-context-types.d.ts +17 -10
  156. package/dist/sandbox/permission-facts.d.ts +98 -95
  157. package/dist/sandbox/permission-facts.js +160 -314
  158. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  159. package/dist/sandbox/permission-instance-writes.js +44 -121
  160. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  161. package/dist/sandbox/permission-runtime-reports.js +105 -122
  162. package/dist/sandbox/providers.d.ts +26 -38
  163. package/dist/sandbox/providers.js +36 -18
  164. package/dist/sandbox/request-not-sent.d.ts +2 -13
  165. package/dist/sandbox/request-not-sent.js +2 -13
  166. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  167. package/dist/sandbox/review/permission-candidate.js +38 -48
  168. package/dist/sandbox/sandbox.module.js +7 -3
  169. package/dist/sandbox/sandbox.service.d.ts +49 -59
  170. package/dist/sandbox/sandbox.service.js +139 -259
  171. package/dist/schedules/fire.d.ts +15 -6
  172. package/dist/schedules/fire.js +27 -13
  173. package/dist/schedules/grant-rules.js +1 -1
  174. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  175. package/dist/schedules/scheduled-tasks.service.js +1 -4
  176. package/dist/schedules/schedules.module.js +5 -3
  177. package/dist/skills/invoke.d.ts +1 -1
  178. package/dist/skills/invoke.js +2 -3
  179. package/dist/tools/approvals.service.d.ts +8 -5
  180. package/dist/tools/approvals.service.js +5 -5
  181. package/dist/tools/builtins/sandbox/bash.js +1 -2
  182. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  183. package/dist/tools/builtins/sandbox/common.js +37 -38
  184. package/dist/tools/connectors.controller.d.ts +2 -0
  185. package/dist/tools/connectors.schemas.d.ts +2 -0
  186. package/dist/tools/credentials.d.ts +2 -0
  187. package/dist/tools/network-asks.d.ts +19 -22
  188. package/dist/tools/network-asks.js +15 -21
  189. package/dist/tools/oauth/authorization-params.d.ts +7 -0
  190. package/dist/tools/oauth/authorization-params.js +19 -0
  191. package/dist/tools/oauth/flow.js +7 -0
  192. package/dist/tools/oauth/tokens.js +2 -1
  193. package/dist/tools/pipeline.d.ts +6 -7
  194. package/dist/tools/pipeline.js +17 -21
  195. package/dist/tools/tools.module.js +3 -7
  196. package/package.json +3 -4
  197. package/src/migrations/0177_dial_in_contract.sql +32 -0
  198. package/dist/local-devices/device-auth.module.d.ts +0 -7
  199. package/dist/local-devices/device-auth.module.js +0 -25
  200. package/dist/local-devices/device-policy.service.d.ts +0 -213
  201. package/dist/local-devices/device-policy.service.js +0 -605
  202. package/dist/local-devices/instance-bindings.d.ts +0 -82
  203. package/dist/local-devices/instance-bindings.js +0 -307
  204. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  205. package/dist/local-devices/local-device-provider.d.ts +0 -122
  206. package/dist/local-devices/local-device-provider.js +0 -326
  207. package/dist/local-devices/local-devices.module.d.ts +0 -31
  208. package/dist/local-devices/local-devices.module.js +0 -100
  209. package/dist/local-devices/machines.d.ts +0 -211
  210. package/dist/local-devices/machines.js +0 -766
  211. package/dist/local-devices/owner-report.d.ts +0 -81
  212. package/dist/local-devices/owner-report.js +0 -150
  213. package/dist/local-devices/owner-reports.d.ts +0 -48
  214. package/dist/local-devices/owner-reports.js +0 -208
  215. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  216. package/dist/local-devices/policy-op-jobs.js +0 -12
  217. package/dist/local-devices/policy-summary.d.ts +0 -102
  218. package/dist/local-devices/policy-summary.js +0 -155
  219. package/dist/local-devices/relay.d.ts +0 -166
  220. package/dist/local-devices/relay.js +0 -559
  221. package/dist/tools/device-op-resolver.d.ts +0 -34
  222. package/dist/tools/device-op-resolver.js +0 -120
  223. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  224. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  225. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  226. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -1,9 +1,8 @@
1
- import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
1
+ import { DEFAULT_SANDBOX_ROOTS, isDeviceOfflineError, isDeviceRequestNotSent, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
+ import { DeviceProtocolError } from "@capybara-hq/plugin-sdk/device-protocol";
2
3
  import { ANONYMOUS_NO_DEVICE, NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
4
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
5
  import { ApiError } from "../../../errors.js";
5
- import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
6
- import { isDeviceRequestNotSent } from "../../../local-devices/relay.js";
7
6
  import { devicePathsChange } from "../../../runtime/context/device-paths.js";
8
7
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../sandbox/attachments-path.js";
9
8
  import { SandboxPathBusyError } from "../../../sandbox/leases.js";
@@ -52,7 +51,12 @@ const ENV_NOT_FOUND_TEXT = "This conversation's device was deleted or its owner
52
51
  const ENV_FORBIDDEN_TEXT = "This conversation's owner may no longer use its device; ask the user to start a new conversation on a device they can use.";
53
52
  /** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
54
53
  export const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
55
- const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page, then retry.";
54
+ /**
55
+ * The device's files are gone at its provider (`device.files_lost`): the devices page resets them
56
+ * where the provider offers that; otherwise the device is set up again where its provider keeps
57
+ * its files (a dial-in device: its machine signs in to it again).
58
+ */
59
+ export const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page, or, where its provider offers no reset, to set the device up again (for a device served by a machine: sign that machine in to it again), then retry.";
56
60
  /**
57
61
  * A provider call that never connected (refused, unknown host, unreachable network): the request
58
62
  * did not reach the provider, so the call did nothing in the sandbox.
@@ -60,12 +64,11 @@ const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset
60
64
  export const SANDBOX_UNREACHABLE_TEXT = "The sandbox provider can't be reached (the connection failed), so this call did nothing in the sandbox; retrying won't help until a super admin checks the sandbox extension's configuration (Admin console → Extensions). Continue without the sandbox, or ask the person to have a super admin check it.";
61
65
  /** A provider connection that broke during the call: the provider may have acted before it broke. */
62
66
  export const SANDBOX_CONNECTION_DROPPED_TEXT = "The connection to the sandbox provider broke during this call, so it may or may not have taken effect; check the sandbox state before retrying. If it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's configuration (Admin console → Extensions).";
63
- const DEVICE_FILES_LOST_TEXT = "This device's directory is gone from the device's machine. Ask the person to run capybara-device logout, then capybara-device login into this device, on that machine, then retry.";
64
- const FILES_GONE_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page (for a local device: to run capybara-device logout, then capybara-device login, on it), then retry.";
65
- const DEVICE_OFFLINE_TEXT = "The device's machine is offline. Ask the person to start capybara-device on it, or to start a new conversation on another device.";
66
- const DEVICE_OUTDATED_TEXT = "The device's machine runs an outdated capybara-device. Ask the person to update it on that machine and start it again.";
67
- const DEVICE_REVOKED_TEXT = "The device's machine was disconnected. Ask the person to run capybara-device logout, then capybara-device login on it, or to start a new conversation on another device.";
68
- const deviceProtocolText = (detail) => `The device's machine sent an answer the platform cannot read (${detail}). Ask the person to update capybara-device on that machine, then retry.`;
67
+ /** A dial-in device whose machine is not connected (`device.offline`, the SDK's offline error). */
68
+ export const DEVICE_OFFLINE_TEXT = "The machine serving this device is offline. Ask the person to connect it again, or to start a new conversation on another device.";
69
+ const DEVICE_OUTDATED_TEXT = "The machine serving this device runs an outdated device program. Ask the person to update it on that machine and connect it again.";
70
+ const DEVICE_REVOKED_TEXT = "The machine serving this device was disconnected. Ask the person to sign that machine in to this device again, or to start a new conversation on another device.";
71
+ const deviceProtocolText = (detail) => `The machine serving this device sent an answer the platform cannot read (${detail}). Ask the person to update the device program on that machine, then retry.`;
69
72
  /**
70
73
  * A cloud provider refused the device's open public network (`sandbox.open_network_refused`): the
71
74
  * fixed text, never the provider's own message (it may name its settings).
@@ -288,24 +291,18 @@ export const PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands outside
288
291
  /**
289
292
  * The device does not allow running outside the sandbox (`device.outside_sandbox_not_allowed`).
290
293
  */
291
- export const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner to allow it on that machine with `capybara-device ceiling set --outside-sandbox on`.";
294
+ export const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner whether its provider can allow it.";
292
295
  /**
293
296
  * The legacy retirement gate's refusals (`RetirementPendingError`, permission runtime cutover
294
297
  * 8.5): the device's earlier instance may still run background work an earlier version started.
295
298
  * Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
296
299
  */
297
300
  export const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device.";
298
- export const RETIREMENT_RESTART_TOOL_TEXT = "Background work started by an earlier version may still be running on this device's computer, so nothing ran. Ask the user to restart that computer to finish the upgrade, then retry; or continue without the device.";
299
301
  export const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device.";
300
- export const RETIREMENT_REPLACE_TOOL_TEXT = "Background work started by an earlier version may still be running on this device's computer, which cannot prove a restart, so nothing ran. Ask the device's owner to delete the device and connect the computer again as a new device, or ask the user to start a new conversation on another device.";
301
302
  /** The model-facing text of a retirement refusal's code (`device.unavailable` for any other). */
302
303
  function retirementToolText(code) {
303
- if (code === "device.restart_required")
304
- return RETIREMENT_RESTART_TOOL_TEXT;
305
304
  if (code === "device.recreate_required")
306
305
  return RETIREMENT_RECREATE_TOOL_TEXT;
307
- if (code === "device.replace_required")
308
- return RETIREMENT_REPLACE_TOOL_TEXT;
309
306
  return RETIREMENT_PENDING_TOOL_TEXT;
310
307
  }
311
308
  /**
@@ -320,9 +317,9 @@ export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside
320
317
  /** A staged request the machine never got: it reconnected before the request was sent. */
321
318
  export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
322
319
  /** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
323
- export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update capybara-device (or a super admin to update the device's sandbox plugin), or continue without the device.";
320
+ export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
324
321
  /** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
325
- export const WORK_UNSETTLED_TOOL_TEXT = "Earlier work on this device has not settled yet, so nothing ran. Retry in a moment; if it keeps happening, ask the device's owner to stop the device's background tasks or restart capybara-device on that machine.";
322
+ export const WORK_UNSETTLED_TOOL_TEXT = "Earlier work on this device has not settled yet, so nothing ran. Retry in a moment; if it keeps happening, ask the device's owner to stop the device's background tasks or restart its device program.";
326
323
  export { PermissionAdmissionUnavailable };
327
324
  /**
328
325
  * Admission's refusal on a device without permission-scoped operations
@@ -331,7 +328,7 @@ export { PermissionAdmissionUnavailable };
331
328
  export function admissionUnavailableText(cause) {
332
329
  if (cause.kind === "provider-outdated")
333
330
  return `This device's sandbox plugin (${cause.plugin} ${cause.version}) cannot run device tools under a permission profile, so nothing ran. A super admin updates the plugin on the Plugins page; until then, continue without the device, or ask the user to start a new conversation on another device.`;
334
- return "This device's runtime cannot enforce its sandbox, so nothing ran. Ask the device's owner to update capybara-device on that machine (for a cloud device, a super admin updates its sandbox plugin), or continue without the device.";
331
+ return "This device's runtime cannot enforce its sandbox, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
335
332
  }
336
333
  /**
337
334
  * A device refused an operation scope as invalid (`SandboxScopeValidationError`): the kernel only
@@ -340,10 +337,10 @@ export function admissionUnavailableText(cause) {
340
337
  */
341
338
  export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
342
339
  /**
343
- * A device request whose machine came back as a new run of capybara-device before answering
340
+ * A device request whose machine came back as a new run of its device program before answering
344
341
  * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
345
342
  */
346
- export const DEVICE_PROGRAM_RESTARTED_TOOL_TEXT = "The capybara-device program restarted on the device's machine while this operation was in progress, so its result is lost and whether it ran, or how far, is unknown. Check the device's state (for example with Read, Glob or TaskList), then run it again if it is still needed; do not repeat an operation that must not run twice.";
343
+ export const DEVICE_PROGRAM_RESTARTED_TOOL_TEXT = "The device program restarted on the machine serving this device while this operation was in progress, so its result is lost and whether it ran, or how far, is unknown. Check the device's state (for example with Read, Glob or TaskList), then run it again if it is still needed; do not repeat an operation that must not run twice.";
347
344
  /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
348
345
  export const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run this operation: its outcome could not be confirmed. Check the device's state (for example with Read, Glob or TaskList) before retrying, and do not repeat an operation that must not run twice.";
349
346
  /**
@@ -354,7 +351,6 @@ export const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run thi
354
351
  * `ToolError`).
355
352
  */
356
353
  const RECONCILE_REQUIRED_TEXT = "This device's sandbox limits must be established again before it runs anything, so nothing ran. Ask the person to reset the device's files on the devices page, then retry, or to start a new conversation on another device.";
357
- const INSTANCE_BINDING_TEXT = "The device's machine has not confirmed its current instance, so nothing ran. Ask the person to restart capybara-device on that machine (updating it if it is outdated), then retry, or to start a new conversation on another device.";
358
354
  /** The provider connection failure behind an unknown outcome, with the raw error to log. */
359
355
  function unreachableCause(cause) {
360
356
  if (cause instanceof SandboxProviderUnreachableError)
@@ -390,6 +386,9 @@ export function mapSandboxError(e, log) {
390
386
  log?.warn("sandbox operation outcome unknown", { err: e });
391
387
  return new ToolError(OUTCOME_UNKNOWN_TOOL_TEXT, { kind: "unavailable" });
392
388
  }
389
+ // a dial-in provider's machine is not connected (the SDK's error, from any provider)
390
+ if (isDeviceOfflineError(e))
391
+ return new ToolError(DEVICE_OFFLINE_TEXT);
393
392
  // kernel-typed, before the scope refusal it extends: nothing was sent, a retry is safe
394
393
  if (isDeviceRequestNotSent(e))
395
394
  return new ToolError(DEVICE_REQUEST_NOT_SENT_TOOL_TEXT, { kind: "unavailable" });
@@ -453,9 +452,6 @@ export function mapSandboxError(e, log) {
453
452
  return new ToolError(ENV_FORBIDDEN_TEXT);
454
453
  if (e.code === "device.unavailable")
455
454
  return new ToolError(ENV_UNAVAILABLE_TEXT);
456
- if (e.code === "device.files_lost" && detail?.source === "local") {
457
- return new ToolError(DEVICE_FILES_LOST_TEXT);
458
- }
459
455
  if (e.code === "device.files_lost")
460
456
  return new ToolError(ENV_FILES_LOST_TEXT);
461
457
  if (e.code === "device.offline")
@@ -479,13 +475,9 @@ export function mapSandboxError(e, log) {
479
475
  }
480
476
  // an operation outside withSandbox's own mapping (it records lost files itself)
481
477
  if (isFileSystemGoneError(e))
482
- return new ToolError(FILES_GONE_TEXT);
478
+ return new ToolError(ENV_FILES_LOST_TEXT);
483
479
  if (e instanceof DeviceProtocolError)
484
480
  return new ToolError(deviceProtocolText(e.message));
485
- if (e instanceof InstanceBindingError) {
486
- log?.warn("device instance binding failed", { err: e });
487
- return new ToolError(INSTANCE_BINDING_TEXT, { kind: "unavailable" });
488
- }
489
481
  if (e instanceof SandboxLockLostError)
490
482
  return new ToolError(LOCK_LOST_TEXT);
491
483
  if (e instanceof SandboxPathBusyError)
@@ -556,9 +548,8 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
556
548
  // the working facts (workspace, home, project snapshot) are read as the review reads them
557
549
  // a call the review covered runs in the working root it was reviewed against: never read again
558
550
  const reviewed = ctx.reviewedWorkingRoot;
559
- const [level, reach, working] = await Promise.all([
551
+ const [level, working] = await Promise.all([
560
552
  deps.devices.modeLevel?.(ctx.orgId, deviceId) ?? null,
561
- deps.devices.projectReach?.(ctx.orgId, deviceId),
562
553
  reviewed !== undefined
563
554
  ? null
564
555
  : (deps.devices.workingFacts?.(ctx.orgId, sandboxConversationOf(ctx), ctx.conversationId, deviceId) ?? null),
@@ -576,9 +567,17 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
576
567
  beforeUser: async (staging, info, sig) => {
577
568
  // the held instance's device paths, recorded before any preparation or user callback
578
569
  if (managed) {
579
- // no installed binding to describe the held instance: unavailable, not stale
570
+ // no installed evidence to describe the held instance: unavailable, not stale
571
+ // (a device or machine that is gone for good says so instead)
580
572
  if (!info.contextEvidence)
581
- throw new ManagedDeviceContextUnavailable();
573
+ throw ((ctx.runId !== undefined &&
574
+ (await managed.goneFor?.({
575
+ orgId: ctx.orgId,
576
+ conversationId: ctx.conversationId,
577
+ runId: ctx.runId,
578
+ accountId: ctx.accountId,
579
+ }, deviceId))) ||
580
+ new ManagedDeviceContextUnavailable());
582
581
  // B-18: the review judged the call against a root (the workspace included);
583
582
  // held evidence of another root is stale, refused before anything is recorded
584
583
  // or run
@@ -620,7 +619,7 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
620
619
  // which a reviewed call's root equals (checked before the callback, B-18)
621
620
  workingRoot: (managed ? info.contextEvidence?.workingRoot : undefined) ??
622
621
  reviewed ??
623
- sessionWorkingRoot(working, mode, info.roots.workspace, reach),
622
+ sessionWorkingRoot(working, info.roots.workspace),
624
623
  p,
625
624
  signal,
626
625
  };
@@ -689,10 +688,10 @@ async function recordDevicePaths(deps, ctx, roots, level) {
689
688
  * workspace (`workspace`), where the call really runs. Every session built outside `inSandbox` (a
690
689
  * person's project skill invocation) takes its working root from here too.
691
690
  */
692
- export function sessionWorkingRoot(working, mode, workspace, reach) {
691
+ export function sessionWorkingRoot(working, workspace) {
693
692
  if (working === null)
694
693
  return workspace;
695
- const root = workingRootOf(working.project, { mode, reach, ...working });
694
+ const root = workingRootOf(working.project, working);
696
695
  return root === working.workspace ? workspace : root;
697
696
  }
698
697
  /**
@@ -63,6 +63,7 @@ declare const CreateBody: z.ZodObject<{
63
63
  client_secret_post: "client_secret_post";
64
64
  }>>;
65
65
  tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
66
+ authorizationParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
66
67
  }, z.core.$strict>, z.ZodObject<{
67
68
  type: z.ZodLiteral<"oauth_client">;
68
69
  ownership: z.ZodLiteral<"org">;
@@ -133,6 +134,7 @@ declare const PreviewBody: z.ZodObject<{
133
134
  client_secret_post: "client_secret_post";
134
135
  }>>;
135
136
  tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
137
+ authorizationParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
136
138
  }, z.core.$strict>, z.ZodObject<{
137
139
  type: z.ZodLiteral<"oauth_client">;
138
140
  ownership: z.ZodLiteral<"org">;
@@ -83,6 +83,7 @@ export declare const ConnectorCreateSchema: z.ZodObject<{
83
83
  client_secret_post: "client_secret_post";
84
84
  }>>;
85
85
  tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ authorizationParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
86
87
  }, z.core.$strict>, z.ZodObject<{
87
88
  type: z.ZodLiteral<"oauth_client">;
88
89
  ownership: z.ZodLiteral<"org">;
@@ -157,6 +158,7 @@ export declare const ConnectorPreviewSchema: z.ZodObject<{
157
158
  client_secret_post: "client_secret_post";
158
159
  }>>;
159
160
  tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
161
+ authorizationParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
160
162
  }, z.core.$strict>, z.ZodObject<{
161
163
  type: z.ZodLiteral<"oauth_client">;
162
164
  ownership: z.ZodLiteral<"org">;
@@ -44,6 +44,8 @@ export type OAuthAuth = {
44
44
  tokenAuthMethod?: "client_secret_basic" | "client_secret_post" | undefined;
45
45
  /** More `token_type` values accepted as bearer tokens (besides Bearer and `user`). */
46
46
  tokenTypes?: string[] | undefined;
47
+ /** Extra query parameters of the authorize request only (never the token endpoint). */
48
+ authorizationParams?: Record<string, string> | undefined;
47
49
  } | {
48
50
  type: "oauth_client";
49
51
  ownership: "org";
@@ -1,5 +1,5 @@
1
- import { type DeviceFeature, type DeviceLocalPolicySummary, type NetworkBlockedHost } from "@capybara-hq/plugin-sdk";
2
- import type { NetworkRunState } from "../local-devices/network-grants.js";
1
+ import { type NetworkBlockedHost } from "@capybara-hq/plugin-sdk";
2
+ import type { NetworkRunState } from "../sandbox/network-grants.js";
3
3
  import { type UnattendedRun } from "../schedules/unattended.js";
4
4
  import { type ApprovalRecord } from "./approvals.service.js";
5
5
  /**
@@ -15,7 +15,10 @@ export declare const NETWORK_ASK_KEPT_MAX_BYTES: number;
15
15
  export declare const NETWORK_ASK_CLIPPED_NOTE = "[Output clipped to its first 16 KB while waiting for network access.]";
16
16
  /** The idempotency key of a call's `network_blocked` event. */
17
17
  export declare const networkBlockedIdemKey: (runId: string, callId: string) => string;
18
- /** Asked, allowed this time (a run grant, the only offer under device protocol 4). */
18
+ /**
19
+ * Asked, allowed this time (a run grant, the only offer: an ask never adds a host to the device's
20
+ * own network list, only its owner's network setting does).
21
+ */
19
22
  export declare const allowedOnceNote: (hosts: readonly string[]) => string;
20
23
  /** Asked and declined (also the unchecked hosts of a partial decision, and a host refused earlier in the run). */
21
24
  export declare const deniedNote: (hosts: readonly string[], reason?: string | null) => string;
@@ -29,12 +32,6 @@ export declare const cancelledNote: () => string;
29
32
  export declare const otherAskPendingNote: (hosts: readonly string[]) => string;
30
33
  /** Not asked: the run made {@link MAX_NETWORK_ASKS_PER_RUN} asks already (spec §6.8). */
31
34
  export declare const tooManyNote: (hosts: readonly string[]) => string;
32
- /**
33
- * Not asked: the device cannot take network changes from the deployment (Docker mode, or a program
34
- * too old to take them), so a run grant would not reach it; only its owner can
35
- * allow the host locally.
36
- */
37
- export declare const localOnlyNote: (hosts: readonly string[]) => string;
38
35
  /** The org layer (spec §6.6): only an org admin can lift it. */
39
36
  export declare const orgLayerNote: (hosts: readonly string[]) => string;
40
37
  /** An org-layer host beyond the platform's ceiling (org egress ceiling spec §D2): only a super admin. */
@@ -65,20 +62,20 @@ export declare function addressEscalationHint(escalation: "available" | "escalat
65
62
  */
66
63
  export declare const unavailableHostNote: (host: string, why: string) => string;
67
64
  /**
68
- * An unattended run (spec §8.1): the task approves the host, yet the device refused it: the device
69
- * takes no network grants from the deployment (Docker mode, or a program too old for them).
70
- * Not asked, not a missing grant: only the device's owner can allow it locally.
65
+ * An unattended run (spec §8.1): the task approves the host, yet the device refused it: its
66
+ * provider did not apply the task's network grant. Not asked, not a missing grant: the device's
67
+ * owner adds the host to the device's network list on its page.
71
68
  */
72
69
  export declare const taskGrantIgnoredNote: (hosts: readonly string[]) => string;
73
70
  /** An unattended run in `fail` mode (spec §8.3): no ask, the creator can add a task grant. */
74
71
  export declare const unattendedNetworkNote: (hosts: readonly string[]) => string;
75
72
  /** What the pipeline knows when a command reported refused hosts. */
76
73
  export interface NetworkPlanContext {
77
- /** The device's active machine: its features and local policy summary (null: none connected). */
78
- device: {
79
- features: readonly DeviceFeature[];
80
- policy: DeviceLocalPolicySummary | null;
81
- } | null;
74
+ /**
75
+ * The device's provider enforces a sandbox allowlist (its permission support): only then is a
76
+ * device-layer host asked about (absent: never).
77
+ */
78
+ allowlist?: boolean;
82
79
  /** The scheduled task run the run serves (null / undefined: attended). */
83
80
  unattended: UnattendedRun | null | undefined;
84
81
  /**
@@ -106,7 +103,7 @@ export interface NetworkPlanContext {
106
103
  export interface NetworkPlan {
107
104
  /**
108
105
  * The device-layer hosts to ask the device owner about (empty: no ask). The ask offers a run
109
- * grant only: the deployment never adds a host to a local device.
106
+ * grant only; the owner adds a host to the device's own list on its page.
110
107
  */
111
108
  ask: {
112
109
  host: string;
@@ -127,10 +124,10 @@ export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]
127
124
  * an `address` host under the open network on a device that allows running outside the sandbox
128
125
  * gets the escalation hint; an `org` host whose grant is unavailable names who adds it;
129
126
  * `unknown`: nothing (the device's trailer explains);
130
- * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: beyond a local owner's
131
- * allowlist, or the org's or platform's allowlist ceiling): a note naming who adds it, never an
132
- * ask;
133
- * - `device` layer on a program without `policyOpId`: nothing (no ask, the trailer explains);
127
+ * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: a provider without
128
+ * per-operation hosts, or beyond the org's or platform's allowlist ceiling): a note naming who
129
+ * adds it, never an ask;
130
+ * - `device` layer on a provider that enforces no allowlist: nothing (no ask);
134
131
  * - approved by the scheduled task the run serves (`run.taskGranted`) yet refused: a note that
135
132
  * the device ignores the task's grants (never asked, never a missing grant);
136
133
  * - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
@@ -1,4 +1,4 @@
1
- import { validateAllowHost, } from "@capybara-hq/plugin-sdk";
1
+ import { validateAllowHost } from "@capybara-hq/plugin-sdk";
2
2
  import { NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS } from "../conversations/events.js";
3
3
  import { ESCALATION_UNATTENDED_WHY } from "../sandbox/review/permission-candidate.js";
4
4
  import { networkGrantKey, unattendedFails, unattendedRules, } from "../schedules/unattended.js";
@@ -21,7 +21,10 @@ const one = (hosts) => hosts.length === 1;
21
21
  const pron = (hosts) => (one(hosts) ? "it" : "them");
22
22
  /** "x was blocked by this device's network policy." (the lead of every device-layer note). */
23
23
  const blockedLead = (hosts) => `[network] ${list(hosts)} ${one(hosts) ? "was" : "were"} blocked by this device's network policy.`;
24
- /** Asked, allowed this time (a run grant, the only offer under device protocol 4). */
24
+ /**
25
+ * Asked, allowed this time (a run grant, the only offer: an ask never adds a host to the device's
26
+ * own network list, only its owner's network setting does).
27
+ */
25
28
  export const allowedOnceNote = (hosts) => `${blockedLead(hosts)} The user allowed ${pron(hosts)} for the rest of this task. Run the command again.`;
26
29
  /** Asked and declined (also the unchecked hosts of a partial decision, and a host refused earlier in the run). */
27
30
  export const deniedNote = (hosts, reason) => `${blockedLead(hosts)} The user declined access to ${list(hosts)}. Do not try to reach ${pron(hosts)} another way; continue without ${pron(hosts)} or ask the user.` +
@@ -36,14 +39,6 @@ export const cancelledNote = () => NETWORK_ASK_CANCELLED_NOTE;
36
39
  export const otherAskPendingNote = (hosts) => `${blockedLead(hosts).slice(0, -1)}; another network request is waiting for the user.`;
37
40
  /** Not asked: the run made {@link MAX_NETWORK_ASKS_PER_RUN} asks already (spec §6.8). */
38
41
  export const tooManyNote = (hosts) => `${blockedLead(hosts)} Too many network requests in this task; ask the user to allow the domains on the device page.`;
39
- /** The local command that allows each host (one `policy add` per host). */
40
- const localAdd = (hosts) => hosts.map((h) => `capybara-device policy add allowedDomains ${h}`).join(" and ");
41
- /**
42
- * Not asked: the device cannot take network changes from the deployment (Docker mode, or a program
43
- * too old to take them), so a run grant would not reach it; only its owner can
44
- * allow the host locally.
45
- */
46
- export const localOnlyNote = (hosts) => `${blockedLead(hosts).slice(0, -1)}, and this device does not accept network changes from the conversation. The device owner can allow ${pron(hosts)} locally: ${localAdd(hosts)}. Continue without ${pron(hosts)} or tell the user.`;
47
42
  /** The org layer (spec §6.6): only an org admin can lift it. */
48
43
  export const orgLayerNote = (hosts) => one(hosts)
49
44
  ? `[network] ${list(hosts)} is not in the organization's network allowlist. Only an organization admin can add it; the user can ask an admin from the conversation. Continue without it or tell the user.`
@@ -84,11 +79,11 @@ export function addressEscalationHint(escalation, networkMode) {
84
79
  */
85
80
  export const unavailableHostNote = (host, why) => `[network] ${host} was blocked by this device's network policy and cannot be allowed from this conversation: ${why}. Continue without it or tell the user.`;
86
81
  /**
87
- * An unattended run (spec §8.1): the task approves the host, yet the device refused it: the device
88
- * takes no network grants from the deployment (Docker mode, or a program too old for them).
89
- * Not asked, not a missing grant: only the device's owner can allow it locally.
82
+ * An unattended run (spec §8.1): the task approves the host, yet the device refused it: its
83
+ * provider did not apply the task's network grant. Not asked, not a missing grant: the device's
84
+ * owner adds the host to the device's network list on its page.
90
85
  */
91
- export const taskGrantIgnoredNote = (hosts) => `${blockedLead(hosts)} The scheduled task approves ${pron(hosts)}, but this device does not accept the task's network grants. The device owner can allow ${pron(hosts)} locally: ${localAdd(hosts)}. Continue without ${pron(hosts)}.`;
86
+ export const taskGrantIgnoredNote = (hosts) => `${blockedLead(hosts)} The scheduled task approves ${pron(hosts)}, but this device did not apply the task's network grant. The device owner can add ${pron(hosts)} to the device's network list on its page. Continue without ${pron(hosts)}.`;
92
87
  /** An unattended run in `fail` mode (spec §8.3): no ask, the creator can add a task grant. */
93
88
  export const unattendedNetworkNote = (hosts) => `[network] ${list(hosts)} ${one(hosts) ? "is" : "are"} blocked on this device and this scheduled run cannot ask for network access. The task's owner can add ${pron(hosts)} to the task's approved domains. Continue without ${pron(hosts)}.`;
94
89
  /** Hosts in first-seen order, deduplicated, lower-cased, trailing dot dropped. */
@@ -118,10 +113,10 @@ export function blockedEventHosts(blocked) {
118
113
  * an `address` host under the open network on a device that allows running outside the sandbox
119
114
  * gets the escalation hint; an `org` host whose grant is unavailable names who adds it;
120
115
  * `unknown`: nothing (the device's trailer explains);
121
- * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: beyond a local owner's
122
- * allowlist, or the org's or platform's allowlist ceiling): a note naming who adds it, never an
123
- * ask;
124
- * - `device` layer on a program without `policyOpId`: nothing (no ask, the trailer explains);
116
+ * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: a provider without
117
+ * per-operation hosts, or beyond the org's or platform's allowlist ceiling): a note naming who
118
+ * adds it, never an ask;
119
+ * - `device` layer on a provider that enforces no allowlist: nothing (no ask);
125
120
  * - approved by the scheduled task the run serves (`run.taskGranted`) yet refused: a note that
126
121
  * the device ignores the task's grants (never asked, never a missing grant);
127
122
  * - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
@@ -139,9 +134,8 @@ export function planNetworkAsk(blocked, run, ctx) {
139
134
  const candidates = [];
140
135
  const missingGrants = [];
141
136
  const unavailable = [];
142
- // a machine that reports blocked hosts and logs its ops under ids (Docker mode has no report)
143
- const canAsk = ctx.device?.features.includes("networkReport") === true &&
144
- ctx.device.features.includes("policyOpId");
137
+ // only a provider that enforces an allowlist blocks a host at the device layer
138
+ const canAsk = ctx.allowlist === true;
145
139
  for (const b of hostsOf(blocked)) {
146
140
  if (b.layer === "address")
147
141
  address.push(b.host);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Appends a connector's `authorizationParams` to an authorize URL that already carries the
3
+ * kernel's own parameters. The schema refuses reserved names on write; this checks again so a row
4
+ * written by older code or by hand can never override a kernel name. Returns the names it skipped
5
+ * (reserved, or not a string value) for the caller to log; values are never returned.
6
+ */
7
+ export declare function appendAuthorizationParams(url: URL, params: Readonly<Record<string, string>> | undefined): string[];
@@ -0,0 +1,19 @@
1
+ import { OAUTH_RESERVED_AUTHORIZATION_PARAMS } from "@capybara-hq/plugin-sdk";
2
+ const RESERVED = new Set(OAUTH_RESERVED_AUTHORIZATION_PARAMS);
3
+ /**
4
+ * Appends a connector's `authorizationParams` to an authorize URL that already carries the
5
+ * kernel's own parameters. The schema refuses reserved names on write; this checks again so a row
6
+ * written by older code or by hand can never override a kernel name. Returns the names it skipped
7
+ * (reserved, or not a string value) for the caller to log; values are never returned.
8
+ */
9
+ export function appendAuthorizationParams(url, params) {
10
+ const skipped = [];
11
+ for (const [name, value] of Object.entries(params ?? {})) {
12
+ if (RESERVED.has(name.toLowerCase()) || typeof value !== "string") {
13
+ skipped.push(name);
14
+ continue;
15
+ }
16
+ url.searchParams.set(name, value);
17
+ }
18
+ return skipped;
19
+ }
@@ -19,6 +19,7 @@ import { KERNEL_LOGGER, REDIS } from "../../infra/tokens.js";
19
19
  import { OrgLock } from "../../orgs/org-lock.js";
20
20
  import { ConnectorsService } from "../connectors.service.js";
21
21
  import { Credentials } from "../credentials.js";
22
+ import { appendAuthorizationParams } from "./authorization-params.js";
22
23
  import { oauthHttpOptions } from "./discovery.js";
23
24
  import { callbackUrl, DEFAULT_RETURN_PATH, OAUTH_STATE_TTL_SECONDS, publicUrlRequired, } from "./flow-paths.js";
24
25
  import { tokenRequest } from "./tokens.js";
@@ -126,6 +127,12 @@ let OAuthFlow = class OAuthFlow {
126
127
  url.searchParams.set("scope", client.scopes.join(" "));
127
128
  if (client.resource)
128
129
  url.searchParams.set("resource", client.resource);
130
+ // The connector's extra parameters (authorize request only), after the kernel's own
131
+ const auth = app.auth;
132
+ const skipped = appendAuthorizationParams(url, auth.authorizationParams);
133
+ if (skipped.length > 0) {
134
+ this.log.warn("oauth authorization parameters skipped", { orgId, connectorId, skipped });
135
+ }
129
136
  return { authorizationUrl: url.toString() };
130
137
  }
131
138
  /** 回跳地址:`http.publicUrl` + 站内路径 + 结果参数(未配置 publicUrl 时为相对地址)。 */
@@ -317,7 +317,8 @@ export class OAuthTokens {
317
317
  this.log.warn("oauth token request rejected", { connectorId, error: e.error });
318
318
  throw new OAuthUnavailable(`Could not obtain an access token: the authorization server rejected the request (${e.error}). Ask an administrator to check the app.`);
319
319
  }
320
- if (e instanceof OAuthUnavailable)
320
+ // invalidate() inside the try ends in a reconnect (or unavailable): never "request failed"
321
+ if (e instanceof OAuthUnavailable || e instanceof OAuthReconnectRequired)
321
322
  throw e;
322
323
  // URL 校验失败等(配置问题):按不可用处理,不删凭据
323
324
  this.log.warn("oauth token request failed", { connectorId, err: e });
@@ -9,8 +9,6 @@ import { ExtensionHost } from "../extensions/host.js";
9
9
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
10
10
  import { KernelDb } from "../infra/database/kernel-db.js";
11
11
  import { TransactionHost } from "../infra/database/transaction-host.js";
12
- import { DevicePolicyService } from "../local-devices/device-policy.service.js";
13
- import { type NetworkRunState } from "../local-devices/network-grants.js";
14
12
  import type { KernelLogger } from "../log.js";
15
13
  import type { OrgRole } from "../orgs/roles.js";
16
14
  import { type ConversationKindForHooks, type HookRunner } from "../runtime/hook-calls.js";
@@ -18,6 +16,7 @@ import { type SubagentParent, type WaitingFor } from "../runtime/loop.js";
18
16
  import type { DispatchArgs, DispatchOutcome } from "../runtime/subagents/dispatch.js";
19
17
  import { SubagentMessages } from "../runtime/subagents/messages.js";
20
18
  import { SubagentsService } from "../runtime/subagents/subagents.service.js";
19
+ import { type NetworkRunState } from "../sandbox/network-grants.js";
21
20
  import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
22
21
  import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
23
22
  import { PermissionAutoGrants } from "../sandbox/permission-auto-grants.js";
@@ -275,16 +274,16 @@ interface PipelineDeps {
275
274
  readonly devices: Pick<ConversationDevices, "reviewFacts"> | undefined;
276
275
  /**
277
276
  * What a command's refused network hosts need (network ask-to-allow spec §6.2): the run tree's
278
- * network asks and the device's features and policy summary. Without them (hand-built test
279
- * pipelines) a report only writes `network_blocked`.
277
+ * network asks and the device's sandbox (its per-call host ceiling, and whether its provider
278
+ * enforces an allowlist). Without them (hand-built test pipelines) a report only writes
279
+ * `network_blocked`.
280
280
  */
281
281
  readonly network: {
282
282
  /** `deviceId` scopes the run tree's asks to the device (ignored by an older provider). */
283
283
  grants: {
284
284
  runState(runId: string, deviceId?: string): Promise<NetworkRunState>;
285
285
  };
286
- devices: Pick<DevicePolicyService, "summary">;
287
- /** The device's per-call host ceiling (absent: every device-layer host is asked about). */
286
+ /** The device's sandbox (absent: no device-layer host is asked about). */
288
287
  sandbox?: Pick<SandboxService, "hostRefusal">;
289
288
  } | undefined;
290
289
  }
@@ -407,7 +406,7 @@ export declare class ToolPipeline {
407
406
  /** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
408
407
  host: Pick<ExtensionHost, "hooks" | "current"> | undefined, drift: Pick<ToolDrift, "onToolsChanged"> | undefined, effective: Pick<EffectiveConfigs, "get">, switches: Pick<OrgToolSwitches, "isToolOff">, txHost: TransactionHost, hooks?: ToolPipelineHooks, networkGrants?: {
409
408
  runState(runId: string, deviceId?: string): Promise<NetworkRunState>;
410
- }, devicePolicy?: Pick<DevicePolicyService, "summary">,
409
+ },
411
410
  /** The command review (auto mode spec §5.4); absent in hand-built pipelines. */
412
411
  review?: CommandReview,
413
412
  /** The reviewed call's device facts; absent in hand-built pipelines. */