@kortix/sdk 0.9.98
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 +313 -0
- package/dist/files/client.d.ts +96 -0
- package/dist/files/client.d.ts.map +1 -0
- package/dist/files/client.js +346 -0
- package/dist/files/client.js.map +1 -0
- package/dist/files/types.d.ts +82 -0
- package/dist/files/types.d.ts.map +1 -0
- package/dist/files/types.js +6 -0
- package/dist/files/types.js.map +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/kortix.d.ts +897 -0
- package/dist/kortix.d.ts.map +1 -0
- package/dist/kortix.js +772 -0
- package/dist/kortix.js.map +1 -0
- package/dist/opencode/client.d.ts +89 -0
- package/dist/opencode/client.d.ts.map +1 -0
- package/dist/opencode/client.js +191 -0
- package/dist/opencode/client.js.map +1 -0
- package/dist/opencode/env.d.ts +13 -0
- package/dist/opencode/env.d.ts.map +1 -0
- package/dist/opencode/env.js +63 -0
- package/dist/opencode/env.js.map +1 -0
- package/dist/opencode/kortix-master.d.ts +487 -0
- package/dist/opencode/kortix-master.d.ts.map +1 -0
- package/dist/opencode/kortix-master.js +313 -0
- package/dist/opencode/kortix-master.js.map +1 -0
- package/dist/opencode/triggers.d.ts +6 -0
- package/dist/opencode/triggers.d.ts.map +1 -0
- package/dist/opencode/triggers.js +34 -0
- package/dist/opencode/triggers.js.map +1 -0
- package/dist/platform/api/errors.d.ts +106 -0
- package/dist/platform/api/errors.d.ts.map +1 -0
- package/dist/platform/api/errors.js +137 -0
- package/dist/platform/api/errors.js.map +1 -0
- package/dist/platform/api-client.d.ts +35 -0
- package/dist/platform/api-client.d.ts.map +1 -0
- package/dist/platform/api-client.js +279 -0
- package/dist/platform/api-client.js.map +1 -0
- package/dist/platform/auth-core.d.ts +60 -0
- package/dist/platform/auth-core.d.ts.map +1 -0
- package/dist/platform/auth-core.js +104 -0
- package/dist/platform/auth-core.js.map +1 -0
- package/dist/platform/auth.d.ts +88 -0
- package/dist/platform/auth.d.ts.map +1 -0
- package/dist/platform/auth.js +161 -0
- package/dist/platform/auth.js.map +1 -0
- package/dist/platform/config-node.d.ts +33 -0
- package/dist/platform/config-node.d.ts.map +1 -0
- package/dist/platform/config-node.js +63 -0
- package/dist/platform/config-node.js.map +1 -0
- package/dist/platform/config.d.ts +77 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +62 -0
- package/dist/platform/config.js.map +1 -0
- package/dist/platform/feature-flags.d.ts +25 -0
- package/dist/platform/feature-flags.d.ts.map +1 -0
- package/dist/platform/feature-flags.js +114 -0
- package/dist/platform/feature-flags.js.map +1 -0
- package/dist/platform/fresh-sessions.d.ts +4 -0
- package/dist/platform/fresh-sessions.d.ts.map +1 -0
- package/dist/platform/fresh-sessions.js +22 -0
- package/dist/platform/fresh-sessions.js.map +1 -0
- package/dist/platform/instance-routes.d.ts +17 -0
- package/dist/platform/instance-routes.d.ts.map +1 -0
- package/dist/platform/instance-routes.js +105 -0
- package/dist/platform/instance-routes.js.map +1 -0
- package/dist/platform/logger.d.ts +20 -0
- package/dist/platform/logger.d.ts.map +1 -0
- package/dist/platform/logger.js +44 -0
- package/dist/platform/logger.js.map +1 -0
- package/dist/platform/opencode-errors.d.ts +20 -0
- package/dist/platform/opencode-errors.d.ts.map +1 -0
- package/dist/platform/opencode-errors.js +71 -0
- package/dist/platform/opencode-errors.js.map +1 -0
- package/dist/platform/platform-client/backups.d.ts +22 -0
- package/dist/platform/platform-client/backups.d.ts.map +1 -0
- package/dist/platform/platform-client/backups.js +16 -0
- package/dist/platform/platform-client/backups.js.map +1 -0
- package/dist/platform/platform-client/index.d.ts +21 -0
- package/dist/platform/platform-client/index.d.ts.map +1 -0
- package/dist/platform/platform-client/index.js +21 -0
- package/dist/platform/platform-client/index.js.map +1 -0
- package/dist/platform/platform-client/instance-admin.d.ts +67 -0
- package/dist/platform/platform-client/instance-admin.d.ts.map +1 -0
- package/dist/platform/platform-client/instance-admin.js +59 -0
- package/dist/platform/platform-client/instance-admin.js.map +1 -0
- package/dist/platform/platform-client/invites.d.ts +35 -0
- package/dist/platform/platform-client/invites.d.ts.map +1 -0
- package/dist/platform/platform-client/invites.js +25 -0
- package/dist/platform/platform-client/invites.js.map +1 -0
- package/dist/platform/platform-client/lifecycle.d.ts +78 -0
- package/dist/platform/platform-client/lifecycle.d.ts.map +1 -0
- package/dist/platform/platform-client/lifecycle.js +151 -0
- package/dist/platform/platform-client/lifecycle.js.map +1 -0
- package/dist/platform/platform-client/members.d.ts +81 -0
- package/dist/platform/platform-client/members.d.ts.map +1 -0
- package/dist/platform/platform-client/members.js +59 -0
- package/dist/platform/platform-client/members.js.map +1 -0
- package/dist/platform/platform-client/shared.d.ts +44 -0
- package/dist/platform/platform-client/shared.d.ts.map +1 -0
- package/dist/platform/platform-client/shared.js +177 -0
- package/dist/platform/platform-client/shared.js.map +1 -0
- package/dist/platform/platform-client/ssh.d.ts +29 -0
- package/dist/platform/platform-client/ssh.d.ts.map +1 -0
- package/dist/platform/platform-client/ssh.js +14 -0
- package/dist/platform/platform-client/ssh.js.map +1 -0
- package/dist/platform/platform-client/types.d.ts +56 -0
- package/dist/platform/platform-client/types.d.ts.map +1 -0
- package/dist/platform/platform-client/types.js +19 -0
- package/dist/platform/platform-client/types.js.map +1 -0
- package/dist/platform/platform-client/updates.d.ts +117 -0
- package/dist/platform/platform-client/updates.d.ts.map +1 -0
- package/dist/platform/platform-client/updates.js +97 -0
- package/dist/platform/platform-client/updates.js.map +1 -0
- package/dist/platform/platform-client/urls.d.ts +18 -0
- package/dist/platform/platform-client/urls.d.ts.map +1 -0
- package/dist/platform/platform-client/urls.js +31 -0
- package/dist/platform/platform-client/urls.js.map +1 -0
- package/dist/platform/projects-client/access.d.ts +273 -0
- package/dist/platform/projects-client/access.d.ts.map +1 -0
- package/dist/platform/projects-client/access.js +89 -0
- package/dist/platform/projects-client/access.js.map +1 -0
- package/dist/platform/projects-client/accounts.d.ts +184 -0
- package/dist/platform/projects-client/accounts.d.ts.map +1 -0
- package/dist/platform/projects-client/accounts.js +78 -0
- package/dist/platform/projects-client/accounts.js.map +1 -0
- package/dist/platform/projects-client/agent-config.d.ts +58 -0
- package/dist/platform/projects-client/agent-config.d.ts.map +1 -0
- package/dist/platform/projects-client/agent-config.js +9 -0
- package/dist/platform/projects-client/agent-config.js.map +1 -0
- package/dist/platform/projects-client/agent-scope.d.ts +12 -0
- package/dist/platform/projects-client/agent-scope.d.ts.map +1 -0
- package/dist/platform/projects-client/agent-scope.js +6 -0
- package/dist/platform/projects-client/agent-scope.js.map +1 -0
- package/dist/platform/projects-client/apps.d.ts +98 -0
- package/dist/platform/projects-client/apps.d.ts.map +1 -0
- package/dist/platform/projects-client/apps.js +29 -0
- package/dist/platform/projects-client/apps.js.map +1 -0
- package/dist/platform/projects-client/audit.d.ts +85 -0
- package/dist/platform/projects-client/audit.d.ts.map +1 -0
- package/dist/platform/projects-client/audit.js +51 -0
- package/dist/platform/projects-client/audit.js.map +1 -0
- package/dist/platform/projects-client/billing.d.ts +336 -0
- package/dist/platform/projects-client/billing.d.ts.map +1 -0
- package/dist/platform/projects-client/billing.js +260 -0
- package/dist/platform/projects-client/billing.js.map +1 -0
- package/dist/platform/projects-client/change-requests.d.ts +119 -0
- package/dist/platform/projects-client/change-requests.d.ts.map +1 -0
- package/dist/platform/projects-client/change-requests.js +56 -0
- package/dist/platform/projects-client/change-requests.js.map +1 -0
- package/dist/platform/projects-client/channels.d.ts +135 -0
- package/dist/platform/projects-client/channels.d.ts.map +1 -0
- package/dist/platform/projects-client/channels.js +103 -0
- package/dist/platform/projects-client/channels.js.map +1 -0
- package/dist/platform/projects-client/connectors.d.ts +148 -0
- package/dist/platform/projects-client/connectors.d.ts.map +1 -0
- package/dist/platform/projects-client/connectors.js +66 -0
- package/dist/platform/projects-client/connectors.js.map +1 -0
- package/dist/platform/projects-client/files.d.ts +37 -0
- package/dist/platform/projects-client/files.d.ts.map +1 -0
- package/dist/platform/projects-client/files.js +58 -0
- package/dist/platform/projects-client/files.js.map +1 -0
- package/dist/platform/projects-client/gateway.d.ts +177 -0
- package/dist/platform/projects-client/gateway.d.ts.map +1 -0
- package/dist/platform/projects-client/gateway.js +59 -0
- package/dist/platform/projects-client/gateway.js.map +1 -0
- package/dist/platform/projects-client/git-history.d.ts +74 -0
- package/dist/platform/projects-client/git-history.d.ts.map +1 -0
- package/dist/platform/projects-client/git-history.js +40 -0
- package/dist/platform/projects-client/git-history.js.map +1 -0
- package/dist/platform/projects-client/github.d.ts +62 -0
- package/dist/platform/projects-client/github.d.ts.map +1 -0
- package/dist/platform/projects-client/github.js +30 -0
- package/dist/platform/projects-client/github.js.map +1 -0
- package/dist/platform/projects-client/index.d.ts +32 -0
- package/dist/platform/projects-client/index.d.ts.map +1 -0
- package/dist/platform/projects-client/index.js +34 -0
- package/dist/platform/projects-client/index.js.map +1 -0
- package/dist/platform/projects-client/marketplace-catalog.d.ts +76 -0
- package/dist/platform/projects-client/marketplace-catalog.d.ts.map +1 -0
- package/dist/platform/projects-client/marketplace-catalog.js +48 -0
- package/dist/platform/projects-client/marketplace-catalog.js.map +1 -0
- package/dist/platform/projects-client/marketplace.d.ts +80 -0
- package/dist/platform/projects-client/marketplace.d.ts.map +1 -0
- package/dist/platform/projects-client/marketplace.js +52 -0
- package/dist/platform/projects-client/marketplace.js.map +1 -0
- package/dist/platform/projects-client/model-defaults.d.ts +36 -0
- package/dist/platform/projects-client/model-defaults.d.ts.map +1 -0
- package/dist/platform/projects-client/model-defaults.js +16 -0
- package/dist/platform/projects-client/model-defaults.js.map +1 -0
- package/dist/platform/projects-client/policies.d.ts +21 -0
- package/dist/platform/projects-client/policies.d.ts.map +1 -0
- package/dist/platform/projects-client/policies.js +10 -0
- package/dist/platform/projects-client/policies.js.map +1 -0
- package/dist/platform/projects-client/projects.d.ts +235 -0
- package/dist/platform/projects-client/projects.d.ts.map +1 -0
- package/dist/platform/projects-client/projects.js +161 -0
- package/dist/platform/projects-client/projects.js.map +1 -0
- package/dist/platform/projects-client/public-session-shares.d.ts +52 -0
- package/dist/platform/projects-client/public-session-shares.d.ts.map +1 -0
- package/dist/platform/projects-client/public-session-shares.js +54 -0
- package/dist/platform/projects-client/public-session-shares.js.map +1 -0
- package/dist/platform/projects-client/review.d.ts +57 -0
- package/dist/platform/projects-client/review.d.ts.map +1 -0
- package/dist/platform/projects-client/review.js +28 -0
- package/dist/platform/projects-client/review.js.map +1 -0
- package/dist/platform/projects-client/sandbox-shares.d.ts +25 -0
- package/dist/platform/projects-client/sandbox-shares.d.ts.map +1 -0
- package/dist/platform/projects-client/sandbox-shares.js +29 -0
- package/dist/platform/projects-client/sandbox-shares.js.map +1 -0
- package/dist/platform/projects-client/sandbox.d.ts +123 -0
- package/dist/platform/projects-client/sandbox.d.ts.map +1 -0
- package/dist/platform/projects-client/sandbox.js +45 -0
- package/dist/platform/projects-client/sandbox.js.map +1 -0
- package/dist/platform/projects-client/secrets.d.ts +122 -0
- package/dist/platform/projects-client/secrets.d.ts.map +1 -0
- package/dist/platform/projects-client/secrets.js +34 -0
- package/dist/platform/projects-client/secrets.js.map +1 -0
- package/dist/platform/projects-client/session-sandbox.d.ts +61 -0
- package/dist/platform/projects-client/session-sandbox.d.ts.map +1 -0
- package/dist/platform/projects-client/session-sandbox.js +82 -0
- package/dist/platform/projects-client/session-sandbox.js.map +1 -0
- package/dist/platform/projects-client/sessions.d.ts +216 -0
- package/dist/platform/projects-client/sessions.d.ts.map +1 -0
- package/dist/platform/projects-client/sessions.js +74 -0
- package/dist/platform/projects-client/sessions.js.map +1 -0
- package/dist/platform/projects-client/setup-links.d.ts +35 -0
- package/dist/platform/projects-client/setup-links.d.ts.map +1 -0
- package/dist/platform/projects-client/setup-links.js +24 -0
- package/dist/platform/projects-client/setup-links.js.map +1 -0
- package/dist/platform/projects-client/shared.d.ts +66 -0
- package/dist/platform/projects-client/shared.d.ts.map +1 -0
- package/dist/platform/projects-client/shared.js +44 -0
- package/dist/platform/projects-client/shared.js.map +1 -0
- package/dist/platform/projects-client/tokens.d.ts +77 -0
- package/dist/platform/projects-client/tokens.d.ts.map +1 -0
- package/dist/platform/projects-client/tokens.js +43 -0
- package/dist/platform/projects-client/tokens.js.map +1 -0
- package/dist/platform/projects-client/transcription.d.ts +5 -0
- package/dist/platform/projects-client/transcription.d.ts.map +1 -0
- package/dist/platform/projects-client/transcription.js +14 -0
- package/dist/platform/projects-client/transcription.js.map +1 -0
- package/dist/platform/projects-client/triggers.d.ts +102 -0
- package/dist/platform/projects-client/triggers.d.ts.map +1 -0
- package/dist/platform/projects-client/triggers.js +27 -0
- package/dist/platform/projects-client/triggers.js.map +1 -0
- package/dist/platform/session-id.d.ts +9 -0
- package/dist/platform/session-id.d.ts.map +1 -0
- package/dist/platform/session-id.js +23 -0
- package/dist/platform/session-id.js.map +1 -0
- package/dist/platform/storage/managed-storage.d.ts +97 -0
- package/dist/platform/storage/managed-storage.d.ts.map +1 -0
- package/dist/platform/storage/managed-storage.js +271 -0
- package/dist/platform/storage/managed-storage.js.map +1 -0
- package/dist/platform/strings.d.ts +12 -0
- package/dist/platform/strings.d.ts.map +1 -0
- package/dist/platform/strings.js +17 -0
- package/dist/platform/strings.js.map +1 -0
- package/dist/platform/ui.d.ts +11 -0
- package/dist/platform/ui.d.ts.map +1 -0
- package/dist/platform/ui.js +22 -0
- package/dist/platform/ui.js.map +1 -0
- package/dist/react/chat/index.d.ts +3 -0
- package/dist/react/chat/index.d.ts.map +1 -0
- package/dist/react/chat/index.js +7 -0
- package/dist/react/chat/index.js.map +1 -0
- package/dist/react/chat/render-parts.d.ts +39 -0
- package/dist/react/chat/render-parts.d.ts.map +1 -0
- package/dist/react/chat/render-parts.js +34 -0
- package/dist/react/chat/render-parts.js.map +1 -0
- package/dist/react/chat/use-chat-turns.d.ts +19 -0
- package/dist/react/chat/use-chat-turns.d.ts.map +1 -0
- package/dist/react/chat/use-chat-turns.js +27 -0
- package/dist/react/chat/use-chat-turns.js.map +1 -0
- package/dist/react/file-keys.d.ts +18 -0
- package/dist/react/file-keys.d.ts.map +1 -0
- package/dist/react/file-keys.js +18 -0
- package/dist/react/file-keys.js.map +1 -0
- package/dist/react/index.d.ts +12 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +49 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/model-flatten.d.ts +33 -0
- package/dist/react/model-flatten.d.ts.map +1 -0
- package/dist/react/model-flatten.js +59 -0
- package/dist/react/model-flatten.js.map +1 -0
- package/dist/react/opencode.d.ts +43 -0
- package/dist/react/opencode.d.ts.map +1 -0
- package/dist/react/opencode.js +100 -0
- package/dist/react/opencode.js.map +1 -0
- package/dist/react/prefetch-session-start.d.ts +10 -0
- package/dist/react/prefetch-session-start.d.ts.map +1 -0
- package/dist/react/prefetch-session-start.js +17 -0
- package/dist/react/prefetch-session-start.js.map +1 -0
- package/dist/react/provider-refresh.d.ts +7 -0
- package/dist/react/provider-refresh.d.ts.map +1 -0
- package/dist/react/provider-refresh.js +28 -0
- package/dist/react/provider-refresh.js.map +1 -0
- package/dist/react/provider-selection.d.ts +31 -0
- package/dist/react/provider-selection.d.ts.map +1 -0
- package/dist/react/provider-selection.js +135 -0
- package/dist/react/provider-selection.js.map +1 -0
- package/dist/react/route-project.d.ts +7 -0
- package/dist/react/route-project.d.ts.map +1 -0
- package/dist/react/route-project.js +19 -0
- package/dist/react/route-project.js.map +1 -0
- package/dist/react/session-start-stash.d.ts +56 -0
- package/dist/react/session-start-stash.d.ts.map +1 -0
- package/dist/react/session-start-stash.js +202 -0
- package/dist/react/session-start-stash.js.map +1 -0
- package/dist/react/use-canonical-opencode-session.d.ts +35 -0
- package/dist/react/use-canonical-opencode-session.d.ts.map +1 -0
- package/dist/react/use-canonical-opencode-session.js +52 -0
- package/dist/react/use-canonical-opencode-session.js.map +1 -0
- package/dist/react/use-change-requests.d.ts +321 -0
- package/dist/react/use-change-requests.d.ts.map +1 -0
- package/dist/react/use-change-requests.js +43 -0
- package/dist/react/use-change-requests.js.map +1 -0
- package/dist/react/use-current-runtime.d.ts +8 -0
- package/dist/react/use-current-runtime.d.ts.map +1 -0
- package/dist/react/use-current-runtime.js +12 -0
- package/dist/react/use-current-runtime.js.map +1 -0
- package/dist/react/use-gateway-catalog-sync.d.ts +2 -0
- package/dist/react/use-gateway-catalog-sync.d.ts.map +1 -0
- package/dist/react/use-gateway-catalog-sync.js +39 -0
- package/dist/react/use-gateway-catalog-sync.js.map +1 -0
- package/dist/react/use-kortix-master.d.ts +384 -0
- package/dist/react/use-kortix-master.d.ts.map +1 -0
- package/dist/react/use-kortix-master.js +958 -0
- package/dist/react/use-kortix-master.js.map +1 -0
- package/dist/react/use-model-store.d.ts +71 -0
- package/dist/react/use-model-store.d.ts.map +1 -0
- package/dist/react/use-model-store.js +411 -0
- package/dist/react/use-model-store.js.map +1 -0
- package/dist/react/use-opencode-config.d.ts +15 -0
- package/dist/react/use-opencode-config.d.ts.map +1 -0
- package/dist/react/use-opencode-config.js +79 -0
- package/dist/react/use-opencode-config.js.map +1 -0
- package/dist/react/use-opencode-events/diagnostics.d.ts +11 -0
- package/dist/react/use-opencode-events/diagnostics.d.ts.map +1 -0
- package/dist/react/use-opencode-events/diagnostics.js +58 -0
- package/dist/react/use-opencode-events/diagnostics.js.map +1 -0
- package/dist/react/use-opencode-events/handle-event.d.ts +20 -0
- package/dist/react/use-opencode-events/handle-event.d.ts.map +1 -0
- package/dist/react/use-opencode-events/handle-event.js +450 -0
- package/dist/react/use-opencode-events/handle-event.js.map +1 -0
- package/dist/react/use-opencode-events/helpers.d.ts +30 -0
- package/dist/react/use-opencode-events/helpers.d.ts.map +1 -0
- package/dist/react/use-opencode-events/helpers.js +93 -0
- package/dist/react/use-opencode-events/helpers.js.map +1 -0
- package/dist/react/use-opencode-events/index.d.ts +25 -0
- package/dist/react/use-opencode-events/index.d.ts.map +1 -0
- package/dist/react/use-opencode-events/index.js +242 -0
- package/dist/react/use-opencode-events/index.js.map +1 -0
- package/dist/react/use-opencode-events/types.d.ts +10 -0
- package/dist/react/use-opencode-events/types.d.ts.map +1 -0
- package/dist/react/use-opencode-events/types.js +2 -0
- package/dist/react/use-opencode-events/types.js.map +1 -0
- package/dist/react/use-opencode-events/use-event-stream-refs.d.ts +22 -0
- package/dist/react/use-opencode-events/use-event-stream-refs.d.ts.map +1 -0
- package/dist/react/use-opencode-events/use-event-stream-refs.js +158 -0
- package/dist/react/use-opencode-events/use-event-stream-refs.js.map +1 -0
- package/dist/react/use-opencode-local.d.ts +139 -0
- package/dist/react/use-opencode-local.d.ts.map +1 -0
- package/dist/react/use-opencode-local.js +484 -0
- package/dist/react/use-opencode-local.js.map +1 -0
- package/dist/react/use-opencode-mcp.d.ts +34 -0
- package/dist/react/use-opencode-mcp.d.ts.map +1 -0
- package/dist/react/use-opencode-mcp.js +190 -0
- package/dist/react/use-opencode-mcp.js.map +1 -0
- package/dist/react/use-opencode-pty.d.ts +30 -0
- package/dist/react/use-opencode-pty.d.ts.map +1 -0
- package/dist/react/use-opencode-pty.js +126 -0
- package/dist/react/use-opencode-pty.js.map +1 -0
- package/dist/react/use-opencode-sessions/agents.d.ts +14 -0
- package/dist/react/use-opencode-sessions/agents.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/agents.js +82 -0
- package/dist/react/use-opencode-sessions/agents.js.map +1 -0
- package/dist/react/use-opencode-sessions/commands.d.ts +8 -0
- package/dist/react/use-opencode-sessions/commands.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/commands.js +46 -0
- package/dist/react/use-opencode-sessions/commands.js.map +1 -0
- package/dist/react/use-opencode-sessions/files.d.ts +2 -0
- package/dist/react/use-opencode-sessions/files.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/files.js +181 -0
- package/dist/react/use-opencode-sessions/files.js.map +1 -0
- package/dist/react/use-opencode-sessions/index.d.ts +15 -0
- package/dist/react/use-opencode-sessions/index.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/index.js +21 -0
- package/dist/react/use-opencode-sessions/index.js.map +1 -0
- package/dist/react/use-opencode-sessions/keys.d.ts +94 -0
- package/dist/react/use-opencode-sessions/keys.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/keys.js +39 -0
- package/dist/react/use-opencode-sessions/keys.js.map +1 -0
- package/dist/react/use-opencode-sessions/mcp.d.ts +3 -0
- package/dist/react/use-opencode-sessions/mcp.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/mcp.js +23 -0
- package/dist/react/use-opencode-sessions/mcp.js.map +1 -0
- package/dist/react/use-opencode-sessions/messages.d.ts +75 -0
- package/dist/react/use-opencode-sessions/messages.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/messages.js +319 -0
- package/dist/react/use-opencode-sessions/messages.js.map +1 -0
- package/dist/react/use-opencode-sessions/parts.d.ts +23 -0
- package/dist/react/use-opencode-sessions/parts.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/parts.js +49 -0
- package/dist/react/use-opencode-sessions/parts.js.map +1 -0
- package/dist/react/use-opencode-sessions/permissions.d.ts +17 -0
- package/dist/react/use-opencode-sessions/permissions.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/permissions.js +66 -0
- package/dist/react/use-opencode-sessions/permissions.js.map +1 -0
- package/dist/react/use-opencode-sessions/projects.d.ts +5 -0
- package/dist/react/use-opencode-sessions/projects.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/projects.js +54 -0
- package/dist/react/use-opencode-sessions/projects.js.map +1 -0
- package/dist/react/use-opencode-sessions/providers.d.ts +10 -0
- package/dist/react/use-opencode-sessions/providers.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/providers.js +98 -0
- package/dist/react/use-opencode-sessions/providers.js.map +1 -0
- package/dist/react/use-opencode-sessions/sessions.d.ts +35 -0
- package/dist/react/use-opencode-sessions/sessions.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/sessions.js +380 -0
- package/dist/react/use-opencode-sessions/sessions.js.map +1 -0
- package/dist/react/use-opencode-sessions/shared.d.ts +43 -0
- package/dist/react/use-opencode-sessions/shared.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/shared.js +109 -0
- package/dist/react/use-opencode-sessions/shared.js.map +1 -0
- package/dist/react/use-opencode-sessions/sharing.d.ts +4 -0
- package/dist/react/use-opencode-sessions/sharing.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/sharing.js +57 -0
- package/dist/react/use-opencode-sessions/sharing.js.map +1 -0
- package/dist/react/use-opencode-sessions/tools.d.ts +5 -0
- package/dist/react/use-opencode-sessions/tools.d.ts.map +1 -0
- package/dist/react/use-opencode-sessions/tools.js +54 -0
- package/dist/react/use-opencode-sessions/tools.js.map +1 -0
- package/dist/react/use-permission-self-heal.d.ts +45 -0
- package/dist/react/use-permission-self-heal.d.ts.map +1 -0
- package/dist/react/use-permission-self-heal.js +144 -0
- package/dist/react/use-permission-self-heal.js.map +1 -0
- package/dist/react/use-project-config.d.ts +11 -0
- package/dist/react/use-project-config.d.ts.map +1 -0
- package/dist/react/use-project-config.js +22 -0
- package/dist/react/use-project-config.js.map +1 -0
- package/dist/react/use-project-models.d.ts +11 -0
- package/dist/react/use-project-models.d.ts.map +1 -0
- package/dist/react/use-project-models.js +25 -0
- package/dist/react/use-project-models.js.map +1 -0
- package/dist/react/use-project-secrets.d.ts +265 -0
- package/dist/react/use-project-secrets.d.ts.map +1 -0
- package/dist/react/use-project-secrets.js +41 -0
- package/dist/react/use-project-secrets.js.map +1 -0
- package/dist/react/use-project-triggers.d.ts +228 -0
- package/dist/react/use-project-triggers.d.ts.map +1 -0
- package/dist/react/use-project-triggers.js +42 -0
- package/dist/react/use-project-triggers.js.map +1 -0
- package/dist/react/use-question-self-heal.d.ts +36 -0
- package/dist/react/use-question-self-heal.d.ts.map +1 -0
- package/dist/react/use-question-self-heal.js +95 -0
- package/dist/react/use-question-self-heal.js.map +1 -0
- package/dist/react/use-runtime-phase.d.ts +9 -0
- package/dist/react/use-runtime-phase.d.ts.map +1 -0
- package/dist/react/use-runtime-phase.js +20 -0
- package/dist/react/use-runtime-phase.js.map +1 -0
- package/dist/react/use-runtime-reconnect.d.ts +90 -0
- package/dist/react/use-runtime-reconnect.d.ts.map +1 -0
- package/dist/react/use-runtime-reconnect.js +234 -0
- package/dist/react/use-runtime-reconnect.js.map +1 -0
- package/dist/react/use-session-picks.d.ts +17 -0
- package/dist/react/use-session-picks.d.ts.map +1 -0
- package/dist/react/use-session-picks.js +36 -0
- package/dist/react/use-session-picks.js.map +1 -0
- package/dist/react/use-session-prefetch.d.ts +18 -0
- package/dist/react/use-session-prefetch.d.ts.map +1 -0
- package/dist/react/use-session-prefetch.js +84 -0
- package/dist/react/use-session-prefetch.js.map +1 -0
- package/dist/react/use-session-send.d.ts +183 -0
- package/dist/react/use-session-send.d.ts.map +1 -0
- package/dist/react/use-session-send.js +287 -0
- package/dist/react/use-session-send.js.map +1 -0
- package/dist/react/use-session-sync.d.ts +24 -0
- package/dist/react/use-session-sync.d.ts.map +1 -0
- package/dist/react/use-session-sync.js +375 -0
- package/dist/react/use-session-sync.js.map +1 -0
- package/dist/react/use-session.d.ts +171 -0
- package/dist/react/use-session.d.ts.map +1 -0
- package/dist/react/use-session.js +396 -0
- package/dist/react/use-session.js.map +1 -0
- package/dist/react/use-visible-agents.d.ts +22 -0
- package/dist/react/use-visible-agents.d.ts.map +1 -0
- package/dist/react/use-visible-agents.js +45 -0
- package/dist/react/use-visible-agents.js.map +1 -0
- package/dist/server.d.ts +55 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +122 -0
- package/dist/server.js.map +1 -0
- package/dist/session/health.d.ts +49 -0
- package/dist/session/health.d.ts.map +1 -0
- package/dist/session/health.js +57 -0
- package/dist/session/health.js.map +1 -0
- package/dist/session/index.d.ts +19 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +19 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/preview.d.ts +24 -0
- package/dist/session/preview.d.ts.map +1 -0
- package/dist/session/preview.js +85 -0
- package/dist/session/preview.js.map +1 -0
- package/dist/session/url.d.ts +160 -0
- package/dist/session/url.d.ts.map +1 -0
- package/dist/session/url.js +522 -0
- package/dist/session/url.js.map +1 -0
- package/dist/state/chat-events.d.ts +141 -0
- package/dist/state/chat-events.d.ts.map +1 -0
- package/dist/state/chat-events.js +135 -0
- package/dist/state/chat-events.js.map +1 -0
- package/dist/state/current-runtime.d.ts +44 -0
- package/dist/state/current-runtime.d.ts.map +1 -0
- package/dist/state/current-runtime.js +44 -0
- package/dist/state/current-runtime.js.map +1 -0
- package/dist/state/diagnostics-store.d.ts +114 -0
- package/dist/state/diagnostics-store.d.ts.map +1 -0
- package/dist/state/diagnostics-store.js +319 -0
- package/dist/state/diagnostics-store.js.map +1 -0
- package/dist/state/event-stream.d.ts +134 -0
- package/dist/state/event-stream.d.ts.map +1 -0
- package/dist/state/event-stream.js +424 -0
- package/dist/state/event-stream.js.map +1 -0
- package/dist/state/idb-sync-cache.d.ts +18 -0
- package/dist/state/idb-sync-cache.d.ts.map +1 -0
- package/dist/state/idb-sync-cache.js +209 -0
- package/dist/state/idb-sync-cache.js.map +1 -0
- package/dist/state/opencode-compaction-store.d.ts +10 -0
- package/dist/state/opencode-compaction-store.d.ts.map +1 -0
- package/dist/state/opencode-compaction-store.js +32 -0
- package/dist/state/opencode-compaction-store.js.map +1 -0
- package/dist/state/opencode-pending-store.d.ts +19 -0
- package/dist/state/opencode-pending-store.d.ts.map +1 -0
- package/dist/state/opencode-pending-store.js +76 -0
- package/dist/state/opencode-pending-store.js.map +1 -0
- package/dist/state/sandbox-connection-store.d.ts +62 -0
- package/dist/state/sandbox-connection-store.d.ts.map +1 -0
- package/dist/state/sandbox-connection-store.js +290 -0
- package/dist/state/sandbox-connection-store.js.map +1 -0
- package/dist/state/server-store/active.d.ts +49 -0
- package/dist/state/server-store/active.d.ts.map +1 -0
- package/dist/state/server-store/active.js +76 -0
- package/dist/state/server-store/active.js.map +1 -0
- package/dist/state/server-store/types.d.ts +12 -0
- package/dist/state/server-store/types.d.ts.map +1 -0
- package/dist/state/server-store/types.js +2 -0
- package/dist/state/server-store/types.js.map +1 -0
- package/dist/state/server-store/url-helpers.d.ts +33 -0
- package/dist/state/server-store/url-helpers.d.ts.map +1 -0
- package/dist/state/server-store/url-helpers.js +55 -0
- package/dist/state/server-store/url-helpers.js.map +1 -0
- package/dist/state/server-store.d.ts +18 -0
- package/dist/state/server-store.d.ts.map +1 -0
- package/dist/state/server-store.js +23 -0
- package/dist/state/server-store.js.map +1 -0
- package/dist/state/session-runtime-registry.d.ts +49 -0
- package/dist/state/session-runtime-registry.d.ts.map +1 -0
- package/dist/state/session-runtime-registry.js +85 -0
- package/dist/state/session-runtime-registry.js.map +1 -0
- package/dist/state/sync-store/ascending-id.d.ts +2 -0
- package/dist/state/sync-store/ascending-id.d.ts.map +1 -0
- package/dist/state/sync-store/ascending-id.js +21 -0
- package/dist/state/sync-store/ascending-id.js.map +1 -0
- package/dist/state/sync-store/binary.d.ts +7 -0
- package/dist/state/sync-store/binary.d.ts.map +1 -0
- package/dist/state/sync-store/binary.js +21 -0
- package/dist/state/sync-store/binary.js.map +1 -0
- package/dist/state/sync-store/stream-cache.d.ts +2 -0
- package/dist/state/sync-store/stream-cache.d.ts.map +1 -0
- package/dist/state/sync-store/stream-cache.js +29 -0
- package/dist/state/sync-store/stream-cache.js.map +1 -0
- package/dist/state/sync-store/types.d.ts +29 -0
- package/dist/state/sync-store/types.d.ts.map +1 -0
- package/dist/state/sync-store/types.js +2 -0
- package/dist/state/sync-store/types.js.map +1 -0
- package/dist/state/sync-store.d.ts +39 -0
- package/dist/state/sync-store.d.ts.map +1 -0
- package/dist/state/sync-store.js +692 -0
- package/dist/state/sync-store.js.map +1 -0
- package/dist/state/tab-store.d.ts +91 -0
- package/dist/state/tab-store.d.ts.map +1 -0
- package/dist/state/tab-store.js +369 -0
- package/dist/state/tab-store.js.map +1 -0
- package/dist/transcript.d.ts +40 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +126 -0
- package/dist/transcript.js.map +1 -0
- package/dist/turns/classify.d.ts +166 -0
- package/dist/turns/classify.d.ts.map +1 -0
- package/dist/turns/classify.js +259 -0
- package/dist/turns/classify.js.map +1 -0
- package/dist/turns/errors.d.ts +11 -0
- package/dist/turns/errors.d.ts.map +1 -0
- package/dist/turns/errors.js +85 -0
- package/dist/turns/errors.js.map +1 -0
- package/dist/turns/index.d.ts +264 -0
- package/dist/turns/index.d.ts.map +1 -0
- package/dist/turns/index.js +1243 -0
- package/dist/turns/index.js.map +1 -0
- package/dist/turns/tool-registry.d.ts +33 -0
- package/dist/turns/tool-registry.d.ts.map +1 -0
- package/dist/turns/tool-registry.js +108 -0
- package/dist/turns/tool-registry.js.map +1 -0
- package/dist/turns/types.d.ts +125 -0
- package/dist/turns/types.d.ts.map +1 -0
- package/dist/turns/types.js +12 -0
- package/dist/turns/types.js.map +1 -0
- package/dist/turns/view-model.d.ts +127 -0
- package/dist/turns/view-model.d.ts.map +1 -0
- package/dist/turns/view-model.js +401 -0
- package/dist/turns/view-model.js.map +1 -0
- package/package.json +155 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ApiError } from './api/errors.js';
|
|
2
|
+
export { ApiError, AuthError, BillingError, RequestTooLargeError, parseBillingError, isBillingError, formatBillingErrorForUI, type ApiErrorFields, type BillingErrorUI, } from './api/errors.js';
|
|
3
|
+
export interface ErrorContext {
|
|
4
|
+
operation?: string;
|
|
5
|
+
resource?: string;
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiClientOptions {
|
|
9
|
+
showErrors?: boolean;
|
|
10
|
+
errorContext?: ErrorContext;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ApiResponse<T = any> {
|
|
14
|
+
data?: T;
|
|
15
|
+
error?: ApiError;
|
|
16
|
+
success: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function setAdminBypass(enabled: boolean): void;
|
|
19
|
+
export declare function isAdminBypassEnabled(): boolean;
|
|
20
|
+
export declare const supabaseClient: {
|
|
21
|
+
execute<T = any>(queryFn: () => Promise<{
|
|
22
|
+
data: T | null;
|
|
23
|
+
error: any;
|
|
24
|
+
}>, errorContext?: ErrorContext): Promise<ApiResponse<T>>;
|
|
25
|
+
};
|
|
26
|
+
export declare const backendApi: {
|
|
27
|
+
get: <T = any>(endpoint: string, options?: Omit<RequestInit & ApiClientOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
28
|
+
post: <T = any>(endpoint: string, data?: any, options?: Omit<RequestInit & ApiClientOptions, "method">) => Promise<ApiResponse<T>>;
|
|
29
|
+
put: <T = any>(endpoint: string, data?: any, options?: Omit<RequestInit & ApiClientOptions, "method">) => Promise<ApiResponse<T>>;
|
|
30
|
+
patch: <T = any>(endpoint: string, data?: any, options?: Omit<RequestInit & ApiClientOptions, "method">) => Promise<ApiResponse<T>>;
|
|
31
|
+
delete: <T = any>(endpoint: string, options?: Omit<RequestInit & ApiClientOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
32
|
+
upload: <T = any>(endpoint: string, formData: FormData, options?: Omit<RequestInit & ApiClientOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
33
|
+
uploadPut: <T = any>(endpoint: string, formData: FormData, options?: Omit<RequestInit & ApiClientOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/platform/api-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAsD,MAAM,cAAc,CAAC;AAQ5F,OAAO,EACL,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,KAA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,CAAC,kBAAkB,MAAM,YAAY,IAAI,CAAC,WAAW,GAAG,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAC;aAG5F,CAAC,kBAAkB,MAAM,YAAY,QAAQ,YAAY,IAAI,CAAC,WAAW,GAAG,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAC;gBAa7G,CAAC,kBAAkB,MAAM,YAAY,QAAQ,YAAY,IAAI,CAAC,WAAW,GAAG,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAC;CAY7H,CAAC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { platformConfig } from './config.js';
|
|
2
|
+
import { getSupabaseAccessTokenWithRetry } from './auth.js';
|
|
3
|
+
import { ApiError, AuthError, parseBillingError, RequestTooLargeError } from './api/errors.js';
|
|
4
|
+
const getApiUrl = () => platformConfig().backendUrl || '';
|
|
5
|
+
// Ported from web's error-handler. User-facing error handling is routed
|
|
6
|
+
// through platformConfig().onError?.() instead of web's handleApiError.
|
|
7
|
+
// The error classes live in ./api/errors — re-exported here so both the
|
|
8
|
+
// root barrel and the `@kortix/sdk/api-client` subpath expose them.
|
|
9
|
+
export { ApiError, AuthError, BillingError, RequestTooLargeError, parseBillingError, isBillingError, formatBillingErrorForUI, } from './api/errors.js';
|
|
10
|
+
// Platform-admin read-only bypass toggle (web only). In-memory, per-tab — never
|
|
11
|
+
// persisted — so it resets on reload and can't linger silently. When on, every
|
|
12
|
+
// request from this client carries `x-kortix-admin-bypass: 1`; the API only
|
|
13
|
+
// honors it for a real platform admin/super_admin on a `read` action (see
|
|
14
|
+
// apps/api/src/projects/lib/access.ts), so this is safe to set unconditionally
|
|
15
|
+
// here rather than threading it through every call site.
|
|
16
|
+
let adminBypassEnabled = false;
|
|
17
|
+
export function setAdminBypass(enabled) {
|
|
18
|
+
adminBypassEnabled = enabled;
|
|
19
|
+
}
|
|
20
|
+
export function isAdminBypassEnabled() {
|
|
21
|
+
return adminBypassEnabled;
|
|
22
|
+
}
|
|
23
|
+
async function makeRequest(url, options = {}) {
|
|
24
|
+
const { showErrors = true, errorContext, timeout = 30000, ...fetchOptions } = options;
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
let timeoutId = null;
|
|
27
|
+
let isAborted = false;
|
|
28
|
+
// Tracks whether *our* timer fired the abort, vs. an external abort
|
|
29
|
+
// (client navigation, tab close, dropped connection). Only the former is a
|
|
30
|
+
// real timeout; the latter must not be surfaced as one.
|
|
31
|
+
let didTimeout = false;
|
|
32
|
+
try {
|
|
33
|
+
timeoutId = setTimeout(() => {
|
|
34
|
+
if (!isAborted && !controller.signal.aborted) {
|
|
35
|
+
isAborted = true;
|
|
36
|
+
didTimeout = true;
|
|
37
|
+
controller.abort();
|
|
38
|
+
}
|
|
39
|
+
}, timeout);
|
|
40
|
+
const token = await getSupabaseAccessTokenWithRetry();
|
|
41
|
+
// Don't set Content-Type for FormData - browser will set it automatically with boundary
|
|
42
|
+
const isFormData = fetchOptions.body instanceof FormData;
|
|
43
|
+
const headers = {};
|
|
44
|
+
if (!isFormData) {
|
|
45
|
+
headers['Content-Type'] = 'application/json';
|
|
46
|
+
}
|
|
47
|
+
// Merge with any headers from fetchOptions
|
|
48
|
+
Object.assign(headers, fetchOptions.headers);
|
|
49
|
+
if (adminBypassEnabled) {
|
|
50
|
+
headers['x-kortix-admin-bypass'] = '1';
|
|
51
|
+
}
|
|
52
|
+
if (token) {
|
|
53
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// No session yet — Supabase hasn't hydrated from cookies.
|
|
57
|
+
// Return a silent failure instead of sending a naked request that will 401.
|
|
58
|
+
// Callers gated by `enabled: !!user` should prevent this path, but this
|
|
59
|
+
// is a safety net for any calls that slip through.
|
|
60
|
+
return {
|
|
61
|
+
error: new AuthError(),
|
|
62
|
+
success: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Note: X-Refresh-Token was removed to reduce header size and prevent HTTP 431 errors.
|
|
66
|
+
// The backend handles token refresh via Supabase directly.
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
...fetchOptions,
|
|
69
|
+
headers,
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
// API auth is bearer-token based. Don't send browser cookies to the
|
|
72
|
+
// same-origin /v1 proxy; large localhost cookie jars can trip HTTP 431
|
|
73
|
+
// before the request reaches the API.
|
|
74
|
+
credentials: fetchOptions.credentials ?? 'omit',
|
|
75
|
+
});
|
|
76
|
+
if (timeoutId) {
|
|
77
|
+
clearTimeout(timeoutId);
|
|
78
|
+
timeoutId = null;
|
|
79
|
+
}
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
82
|
+
let errorData = null;
|
|
83
|
+
try {
|
|
84
|
+
errorData = await response.json();
|
|
85
|
+
if (errorData.message) {
|
|
86
|
+
errorMessage = errorData.message;
|
|
87
|
+
}
|
|
88
|
+
else if (errorData.error && typeof errorData.error === 'string') {
|
|
89
|
+
errorMessage = errorData.error;
|
|
90
|
+
}
|
|
91
|
+
else if (typeof errorData.detail === 'string') {
|
|
92
|
+
// FastAPI returns {"detail": "error message"}
|
|
93
|
+
errorMessage = errorData.detail;
|
|
94
|
+
}
|
|
95
|
+
else if (errorData.detail?.message) {
|
|
96
|
+
errorMessage = errorData.detail.message;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
}
|
|
101
|
+
let error = new ApiError(errorMessage, {
|
|
102
|
+
status: response.status,
|
|
103
|
+
response: response,
|
|
104
|
+
details: errorData || undefined,
|
|
105
|
+
data: errorData,
|
|
106
|
+
detail: errorData?.detail,
|
|
107
|
+
code: errorData?.code || errorData?.error_code || errorData?.detail?.error_code || response.status.toString()
|
|
108
|
+
});
|
|
109
|
+
if (response.status === 402) {
|
|
110
|
+
error = parseBillingError(error);
|
|
111
|
+
}
|
|
112
|
+
// Handle HTTP 431 - Request Header Fields Too Large
|
|
113
|
+
// This typically happens when uploading many files at once
|
|
114
|
+
if (response.status === 431) {
|
|
115
|
+
error = new RequestTooLargeError(431, {
|
|
116
|
+
message: 'Request is too large to process',
|
|
117
|
+
suggestion: 'Try uploading files one at a time, or reduce the number of files attached to your message.',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (showErrors) {
|
|
121
|
+
platformConfig().onError?.(error, errorContext);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
error,
|
|
125
|
+
success: false,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
let data;
|
|
129
|
+
const contentType = response.headers.get('content-type');
|
|
130
|
+
if (contentType?.includes('application/json')) {
|
|
131
|
+
data = await response.json();
|
|
132
|
+
}
|
|
133
|
+
else if (contentType?.includes('text/')) {
|
|
134
|
+
data = await response.text();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
data = await response.blob();
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
data,
|
|
141
|
+
success: true,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
// Always clear timeout on error
|
|
146
|
+
if (timeoutId) {
|
|
147
|
+
clearTimeout(timeoutId);
|
|
148
|
+
timeoutId = null;
|
|
149
|
+
}
|
|
150
|
+
// Check if this is an abort error (timeout or manual abort)
|
|
151
|
+
const isAbortError = error?.name === 'AbortError' ||
|
|
152
|
+
error?.name === 'AbortSignal' ||
|
|
153
|
+
(error instanceof Error && error.message.includes('aborted'));
|
|
154
|
+
// If it was aborted, mark it so we don't try to abort again
|
|
155
|
+
if (isAbortError) {
|
|
156
|
+
isAborted = true;
|
|
157
|
+
}
|
|
158
|
+
let apiError;
|
|
159
|
+
if (isAbortError) {
|
|
160
|
+
// An external abort (Next.js client navigation, tab close, React Query
|
|
161
|
+
// cancelling an in-flight request, a dropped connection) is NOT a
|
|
162
|
+
// timeout — surfacing it as one produced the mysterious, URL-less
|
|
163
|
+
// "Request timeout" toasts/Sentry events. Swallow it silently.
|
|
164
|
+
if (!didTimeout) {
|
|
165
|
+
return {
|
|
166
|
+
error: new ApiError('Request aborted', { name: 'AbortError', code: 'ABORTED' }),
|
|
167
|
+
success: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// Genuine timeout — our timer fired. Attach the endpoint so it's clear
|
|
171
|
+
// *what* timed out (the previous error carried no URL).
|
|
172
|
+
const endpoint = url.replace(getApiUrl(), '') || url;
|
|
173
|
+
apiError = new ApiError(`Request timed out after ${Math.round(timeout / 1000)}s: ${endpoint}`, {
|
|
174
|
+
code: 'TIMEOUT',
|
|
175
|
+
url,
|
|
176
|
+
endpoint,
|
|
177
|
+
timeout,
|
|
178
|
+
});
|
|
179
|
+
// Only show timeout errors if showErrors is true
|
|
180
|
+
// This prevents spam from multiple concurrent timeouts or React Query cancellations
|
|
181
|
+
if (showErrors) {
|
|
182
|
+
platformConfig().onError?.(apiError, errorContext);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (error instanceof Error) {
|
|
186
|
+
apiError = new ApiError(error.message, {
|
|
187
|
+
name: error.name || 'ApiError',
|
|
188
|
+
stack: error.stack,
|
|
189
|
+
});
|
|
190
|
+
if (showErrors) {
|
|
191
|
+
platformConfig().onError?.(apiError, errorContext);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
apiError = new ApiError(String(error));
|
|
196
|
+
if (showErrors) {
|
|
197
|
+
platformConfig().onError?.(apiError, errorContext);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
error: apiError,
|
|
202
|
+
success: false,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export const supabaseClient = {
|
|
207
|
+
async execute(queryFn, errorContext) {
|
|
208
|
+
try {
|
|
209
|
+
const { data, error } = await queryFn();
|
|
210
|
+
if (error) {
|
|
211
|
+
const apiError = new ApiError(error.message || 'Database error', {
|
|
212
|
+
code: error.code,
|
|
213
|
+
details: error,
|
|
214
|
+
});
|
|
215
|
+
platformConfig().onError?.(apiError, errorContext);
|
|
216
|
+
return {
|
|
217
|
+
error: apiError,
|
|
218
|
+
success: false,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
data: data,
|
|
223
|
+
success: true,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
const apiError = error instanceof Error
|
|
228
|
+
? new ApiError(error.message, { name: error.name || 'ApiError', stack: error.stack })
|
|
229
|
+
: new ApiError(String(error));
|
|
230
|
+
platformConfig().onError?.(apiError, errorContext);
|
|
231
|
+
return {
|
|
232
|
+
error: apiError,
|
|
233
|
+
success: false,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
export const backendApi = {
|
|
239
|
+
get: (endpoint, options) => makeRequest(`${getApiUrl()}${endpoint}`, { ...options, method: 'GET' }),
|
|
240
|
+
post: (endpoint, data, options) => makeRequest(`${getApiUrl()}${endpoint}`, {
|
|
241
|
+
...options,
|
|
242
|
+
method: 'POST',
|
|
243
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
244
|
+
}),
|
|
245
|
+
put: (endpoint, data, options) => makeRequest(`${getApiUrl()}${endpoint}`, {
|
|
246
|
+
...options,
|
|
247
|
+
method: 'PUT',
|
|
248
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
249
|
+
}),
|
|
250
|
+
patch: (endpoint, data, options) => makeRequest(`${getApiUrl()}${endpoint}`, {
|
|
251
|
+
...options,
|
|
252
|
+
method: 'PATCH',
|
|
253
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
254
|
+
}),
|
|
255
|
+
delete: (endpoint, options) => makeRequest(`${getApiUrl()}${endpoint}`, { ...options, method: 'DELETE' }),
|
|
256
|
+
upload: (endpoint, formData, options) => {
|
|
257
|
+
const { headers, ...restOptions } = options || {};
|
|
258
|
+
const uploadHeaders = { ...headers };
|
|
259
|
+
delete uploadHeaders['Content-Type'];
|
|
260
|
+
return makeRequest(`${getApiUrl()}${endpoint}`, {
|
|
261
|
+
...restOptions,
|
|
262
|
+
method: 'POST',
|
|
263
|
+
body: formData,
|
|
264
|
+
headers: uploadHeaders,
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
uploadPut: (endpoint, formData, options) => {
|
|
268
|
+
const { headers, ...restOptions } = options || {};
|
|
269
|
+
const uploadHeaders = { ...headers };
|
|
270
|
+
delete uploadHeaders['Content-Type'];
|
|
271
|
+
return makeRequest(`${getApiUrl()}${endpoint}`, {
|
|
272
|
+
...restOptions,
|
|
273
|
+
method: 'PUT',
|
|
274
|
+
body: formData,
|
|
275
|
+
headers: uploadHeaders,
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/platform/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,+BAA+B,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAE5F,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC;AAE1D,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AACxE,oEAAoE;AACpE,OAAO,EACL,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAoBtB,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,0EAA0E;AAC1E,+EAA+E;AAC/E,yDAAyD;AACzD,IAAI,kB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;QAErC,OAAO,WAAW,CAAI,GAAG,SAAS,EAAE,GAAG,QAAQ,EAAE,EAAE;YACjD,GAAG,WAAW;YACd,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,aAAa;SACvB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,EAAE,CAAU,QAAgB,EAAE,QAAkB,EAAE,OAAiE,EAAE,EAAE;QAC9H,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAClD,MAAM,aAAa,GAAG,EAAE,GAAG,OAAiC,EAAE,CAAC;QAC/D,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC;QAErC,OAAO,WAAW,CAAI,GAAG,SAAS,EAAE,GAAG,QAAQ,EAAE,EAAE;YACjD,GAAG,WAAW;YACd,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,aAAa;SACvB,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free building blocks for `auth.ts` — extracted so they can
|
|
3
|
+
* be unit-tested against the REAL implementation regardless of test-file
|
|
4
|
+
* ordering.
|
|
5
|
+
*
|
|
6
|
+
* Why this file exists: several test suites register process-wide
|
|
7
|
+
* `mock.module('../platform/auth', …)` stubs (Bun's `mock.module` replaces a
|
|
8
|
+
* specifier for the remainder of the process, for every importer — see the
|
|
9
|
+
* note in `opencode/client.test.ts`). Any test that wants to exercise the real
|
|
10
|
+
* retry/timeout semantics therefore can't import them from `./auth` — on some
|
|
11
|
+
* Bun versions/orderings it would receive a stub. Nothing mocks THIS module,
|
|
12
|
+
* so `auth-core.test.ts` always tests the genuine article, and `auth.ts` stays
|
|
13
|
+
* a thin delegating shell whose behavior is pinned here.
|
|
14
|
+
*/
|
|
15
|
+
/** Options accepted by the token-retry helpers (`getAuthTokenWithRetry` et al). */
|
|
16
|
+
export interface TokenRetryOptions {
|
|
17
|
+
attempts?: number;
|
|
18
|
+
baseDelayMs?: number;
|
|
19
|
+
invalidateBetweenAttempts?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retry `getToken` up to `attempts` times (default 1 = no retry) until it
|
|
23
|
+
* returns a truthy token, waiting `baseDelayMs` between attempts. When
|
|
24
|
+
* `invalidateBetweenAttempts` is set, `onInvalidate` runs before each retry —
|
|
25
|
+
* a host that layers its own cache on `getToken` wires cache invalidation
|
|
26
|
+
* there. Returns the last (possibly falsy) result after exhausting attempts.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withTokenRetry(getToken: () => Promise<string | null>, options?: TokenRetryOptions, onInvalidate?: () => void): Promise<string | null>;
|
|
29
|
+
export declare const DEFAULT_FETCH_TIMEOUT_MS = 30000;
|
|
30
|
+
/**
|
|
31
|
+
* The one long-lived streaming call reached through the auth fetch injection
|
|
32
|
+
* point — `openEventStream` (`state/event-stream.ts`) drives the opencode
|
|
33
|
+
* client's `global.event(...)` SSE endpoint (`GET {runtimeUrl}/global/event`).
|
|
34
|
+
* It manages its own lifecycle (heartbeat watchdog + explicit abort/reconnect
|
|
35
|
+
* loop) and must stay open far longer than any request timeout.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isStreamingRequest(input: RequestInfo | URL): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Compose the request's own abort signal with a default 30s timeout, so a
|
|
40
|
+
* hung non-streaming call can't wedge a "Kortix as a Backend" server-side
|
|
41
|
+
* handler forever. The SSE event stream is exempted (see
|
|
42
|
+
* `isStreamingRequest`): its caller signal — if any — passes through
|
|
43
|
+
* untouched. Falls back to the caller's bare signal on a runtime without
|
|
44
|
+
* `AbortSignal.any` (older Node/engines) — guarded so a caller-supplied
|
|
45
|
+
* signal is never silently dropped.
|
|
46
|
+
*/
|
|
47
|
+
export declare function withDefaultTimeout(input: RequestInfo | URL, init: RequestInit | undefined, timeoutMs?: number): AbortSignal | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Build a Headers object from request input + init, injecting the auth token
|
|
50
|
+
* as a Bearer Authorization header (unless one is already present).
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildAuthHeaders(input: RequestInfo | URL, init?: RequestInit, token?: string | null): Headers;
|
|
53
|
+
/**
|
|
54
|
+
* The synthetic 401 returned when no token is available — safe for all
|
|
55
|
+
* callers including the OpenCode SDK, which expects fetch() semantics
|
|
56
|
+
* (returns a Response, never throws), and it means the request never goes
|
|
57
|
+
* out on the wire unauthenticated.
|
|
58
|
+
*/
|
|
59
|
+
export declare function syntheticUnauthenticatedResponse(): Response;
|
|
60
|
+
//# sourceMappingURL=auth-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-core.d.ts","sourceRoot":"","sources":["../../src/platform/auth-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACpC;AAMD;;;;;;GAMG;AACH,wBAAsB,cAAc,CACnC,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EACtC,OAAO,CAAC,EAAE,iBAAiB,EAC3B,YAAY,CAAC,EAAE,MAAM,IAAI,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,OAAO,CAGpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,SAAS,GAAE,MAAiC,GAC1C,WAAW,GAAG,SAAS,CAUzB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACnB,OAAO,CAWT;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,IAAI,QAAQ,CAK3D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free building blocks for `auth.ts` — extracted so they can
|
|
3
|
+
* be unit-tested against the REAL implementation regardless of test-file
|
|
4
|
+
* ordering.
|
|
5
|
+
*
|
|
6
|
+
* Why this file exists: several test suites register process-wide
|
|
7
|
+
* `mock.module('../platform/auth', …)` stubs (Bun's `mock.module` replaces a
|
|
8
|
+
* specifier for the remainder of the process, for every importer — see the
|
|
9
|
+
* note in `opencode/client.test.ts`). Any test that wants to exercise the real
|
|
10
|
+
* retry/timeout semantics therefore can't import them from `./auth` — on some
|
|
11
|
+
* Bun versions/orderings it would receive a stub. Nothing mocks THIS module,
|
|
12
|
+
* so `auth-core.test.ts` always tests the genuine article, and `auth.ts` stays
|
|
13
|
+
* a thin delegating shell whose behavior is pinned here.
|
|
14
|
+
*/
|
|
15
|
+
function delay(ms) {
|
|
16
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retry `getToken` up to `attempts` times (default 1 = no retry) until it
|
|
20
|
+
* returns a truthy token, waiting `baseDelayMs` between attempts. When
|
|
21
|
+
* `invalidateBetweenAttempts` is set, `onInvalidate` runs before each retry —
|
|
22
|
+
* a host that layers its own cache on `getToken` wires cache invalidation
|
|
23
|
+
* there. Returns the last (possibly falsy) result after exhausting attempts.
|
|
24
|
+
*/
|
|
25
|
+
export async function withTokenRetry(getToken, options, onInvalidate) {
|
|
26
|
+
const attempts = Math.max(1, options?.attempts ?? 1);
|
|
27
|
+
const baseDelayMs = options?.baseDelayMs ?? 0;
|
|
28
|
+
const invalidateBetweenAttempts = options?.invalidateBetweenAttempts ?? false;
|
|
29
|
+
let token = null;
|
|
30
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
31
|
+
if (attempt > 0) {
|
|
32
|
+
if (invalidateBetweenAttempts)
|
|
33
|
+
onInvalidate?.();
|
|
34
|
+
if (baseDelayMs > 0)
|
|
35
|
+
await delay(baseDelayMs);
|
|
36
|
+
}
|
|
37
|
+
token = await getToken();
|
|
38
|
+
if (token)
|
|
39
|
+
return token;
|
|
40
|
+
}
|
|
41
|
+
return token;
|
|
42
|
+
}
|
|
43
|
+
export const DEFAULT_FETCH_TIMEOUT_MS = 30_000;
|
|
44
|
+
/**
|
|
45
|
+
* The one long-lived streaming call reached through the auth fetch injection
|
|
46
|
+
* point — `openEventStream` (`state/event-stream.ts`) drives the opencode
|
|
47
|
+
* client's `global.event(...)` SSE endpoint (`GET {runtimeUrl}/global/event`).
|
|
48
|
+
* It manages its own lifecycle (heartbeat watchdog + explicit abort/reconnect
|
|
49
|
+
* loop) and must stay open far longer than any request timeout.
|
|
50
|
+
*/
|
|
51
|
+
export function isStreamingRequest(input) {
|
|
52
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
53
|
+
return url.includes('/global/event');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compose the request's own abort signal with a default 30s timeout, so a
|
|
57
|
+
* hung non-streaming call can't wedge a "Kortix as a Backend" server-side
|
|
58
|
+
* handler forever. The SSE event stream is exempted (see
|
|
59
|
+
* `isStreamingRequest`): its caller signal — if any — passes through
|
|
60
|
+
* untouched. Falls back to the caller's bare signal on a runtime without
|
|
61
|
+
* `AbortSignal.any` (older Node/engines) — guarded so a caller-supplied
|
|
62
|
+
* signal is never silently dropped.
|
|
63
|
+
*/
|
|
64
|
+
export function withDefaultTimeout(input, init, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS) {
|
|
65
|
+
const callerSignal = input instanceof Request ? input.signal : init?.signal;
|
|
66
|
+
if (isStreamingRequest(input))
|
|
67
|
+
return callerSignal ?? undefined;
|
|
68
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
69
|
+
if (!callerSignal)
|
|
70
|
+
return timeoutSignal;
|
|
71
|
+
if (typeof AbortSignal.any === 'function') {
|
|
72
|
+
return AbortSignal.any([callerSignal, timeoutSignal]);
|
|
73
|
+
}
|
|
74
|
+
return callerSignal;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a Headers object from request input + init, injecting the auth token
|
|
78
|
+
* as a Bearer Authorization header (unless one is already present).
|
|
79
|
+
*/
|
|
80
|
+
export function buildAuthHeaders(input, init, token) {
|
|
81
|
+
const headers = new Headers(input instanceof Request ? input.headers : undefined);
|
|
82
|
+
if (init?.headers) {
|
|
83
|
+
new Headers(init.headers).forEach((value, key) => {
|
|
84
|
+
headers.set(key, value);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (token && !headers.has('Authorization')) {
|
|
88
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
89
|
+
}
|
|
90
|
+
return headers;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The synthetic 401 returned when no token is available — safe for all
|
|
94
|
+
* callers including the OpenCode SDK, which expects fetch() semantics
|
|
95
|
+
* (returns a Response, never throws), and it means the request never goes
|
|
96
|
+
* out on the wire unauthenticated.
|
|
97
|
+
*/
|
|
98
|
+
export function syntheticUnauthenticatedResponse() {
|
|
99
|
+
return new Response(JSON.stringify({ error: 'Not authenticated' }), {
|
|
100
|
+
status: 401,
|
|
101
|
+
headers: { 'Content-Type': 'application/json' },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=auth-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-core.js","sourceRoot":"","sources":["../../src/platform/auth-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH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;;GAKG;AACH,MAAM,UAAU,gCAAgC;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAAE;QACnE,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAC/C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared auth token helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every function below is a thin delegate to `platformConfig().getToken()` —
|
|
5
|
+
* the SDK holds no token state of its own. Token acquisition (Supabase
|
|
6
|
+
* getSession/refreshSession or any other provider), caching, deduplicating
|
|
7
|
+
* concurrent callers (SSE, health check, session fetch, etc. all racing for a
|
|
8
|
+
* token on page load), and the install/bootstrap seam are entirely the host
|
|
9
|
+
* app's responsibility, implemented inside the `getToken` it passes to
|
|
10
|
+
* `configureKortix`/`createKortix`. A host that wants the old 30s-TTL +
|
|
11
|
+
* inflight-dedup behavior re-implements it in its own `getToken`; the SDK
|
|
12
|
+
* itself does not cache, dedupe, or retry beyond calling `getToken()` again.
|
|
13
|
+
*
|
|
14
|
+
* `getAuthToken()` is the unified getter: returns whatever token the host's
|
|
15
|
+
* `getToken()` resolves. `getSupabaseAccessToken()` is kept as an alias for
|
|
16
|
+
* callers that historically asked for "the Supabase token" specifically —
|
|
17
|
+
* same delegate, same value.
|
|
18
|
+
*
|
|
19
|
+
* `invalidateTokenCache()` / `setCachedAuthToken()` / `setBootstrapAuthToken()`
|
|
20
|
+
* are no-ops here (there is no SDK-side cache to invalidate or seed); they're
|
|
21
|
+
* kept as exported names so existing call sites compile unchanged, and a host
|
|
22
|
+
* that layers its own caching on top of `getToken()` can wire these to that
|
|
23
|
+
* cache if it wants the "invalidate on 401" / "seed before hydration" hooks to
|
|
24
|
+
* do something.
|
|
25
|
+
*/
|
|
26
|
+
import { type TokenRetryOptions } from './auth-core.js';
|
|
27
|
+
/**
|
|
28
|
+
* Get the current auth token. Delegates directly to `platformConfig().getToken()`
|
|
29
|
+
* — any caching/deduplication the host wants happens inside that function.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSupabaseAccessToken(): Promise<string | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Retry variant — actually retries now. Previously accepted `attempts`/
|
|
34
|
+
* `baseDelayMs`/`invalidateBetweenAttempts` and silently ignored all three
|
|
35
|
+
* (always a single `getToken()` call), which quietly broke every caller that
|
|
36
|
+
* depended on retry semantics around a flaky/cold token provider (e.g. right
|
|
37
|
+
* after sign-in, before a host's own session has hydrated — see the retry
|
|
38
|
+
* call in `authenticatedFetch`'s 401 handler below).
|
|
39
|
+
*
|
|
40
|
+
* Retries up to `attempts` times (default 1 = no retry) until `getToken()`
|
|
41
|
+
* returns a truthy token, waiting `baseDelayMs` between attempts (default 0).
|
|
42
|
+
* When `invalidateBetweenAttempts` is set, calls `invalidateTokenCache()`
|
|
43
|
+
* before each retry — a no-op in this file (there's no SDK-side cache), but
|
|
44
|
+
* kept as a real call so a host that layers its own cache on `getToken()` (and
|
|
45
|
+
* wires `invalidateTokenCache`/`setCachedAuthToken` to it, per this file's
|
|
46
|
+
* top-of-file doc comment) gets invalidated between attempts as intended.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getSupabaseAccessTokenWithRetry(options?: TokenRetryOptions): Promise<string | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Invalidate the cached token (e.g. after a 401 response).
|
|
51
|
+
* The next getSupabaseAccessToken() call will fetch fresh.
|
|
52
|
+
*/
|
|
53
|
+
export declare function invalidateTokenCache(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Sync the resolved auth token cache without affecting bootstrap mode.
|
|
56
|
+
*/
|
|
57
|
+
export declare function setCachedAuthToken(token: string | null): void;
|
|
58
|
+
/**
|
|
59
|
+
* Seed auth for setup/install flows that receive a JWT from server actions
|
|
60
|
+
* before the browser Supabase client has established local session state.
|
|
61
|
+
*/
|
|
62
|
+
export declare function setBootstrapAuthToken(token: string | null): void;
|
|
63
|
+
/**
|
|
64
|
+
* Unified auth token getter.
|
|
65
|
+
*
|
|
66
|
+
* Returns the Supabase JWT. All requests go through kortix-api which
|
|
67
|
+
* authenticates via Supabase JWT — no additional sandbox lock/key needed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getAuthToken(): Promise<string | null>;
|
|
70
|
+
export declare function getAuthTokenWithRetry(options?: TokenRetryOptions): Promise<string | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Shared authenticated fetch — injects auth tokens and handles 401 responses.
|
|
73
|
+
*
|
|
74
|
+
* Centralizes the pattern duplicated across opencode-sdk, use-sandbox-connection,
|
|
75
|
+
* and server-selector. All three auth injection points now go through this.
|
|
76
|
+
*
|
|
77
|
+
* Behavior:
|
|
78
|
+
* 1. Gets the current auth token (Supabase JWT)
|
|
79
|
+
* 2. Injects it as Bearer token on the request
|
|
80
|
+
* 3. On 401: invalidates the token cache, gets fresh, retries once
|
|
81
|
+
*
|
|
82
|
+
* Options:
|
|
83
|
+
* - `retryOnAuthError`: if false, skips stale-token retry (default: true)
|
|
84
|
+
*/
|
|
85
|
+
export declare function authenticatedFetch(input: RequestInfo | URL, init?: RequestInit, options?: {
|
|
86
|
+
retryOnAuthError?: boolean;
|
|
87
|
+
}): Promise<Response>;
|
|
88
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/platform/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAKN,KAAK,iBAAiB,EACtB,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAErE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,+BAA+B,CACpD,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAEhE;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3D;AAED,wBAAsB,qBAAqB,CAC1C,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAExB;AAmCD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE;IACR,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,GACA,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
|