@boxrouter/sdk 0.0.1-alpha.0 → 0.12.190
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/NOTICE +29 -5
- package/README.md +497 -24
- package/dist/addresses.d.ts +5 -0
- package/dist/addresses.js +10 -0
- package/dist/api-error.d.ts +62 -0
- package/dist/api-error.js +264 -0
- package/dist/boxrouter.d.ts +68 -0
- package/dist/boxrouter.js +291 -0
- package/dist/browser-session/index.d.ts +17 -0
- package/dist/browser-session/index.js +48 -0
- package/dist/browser-session/operations.gen.d.ts +272 -0
- package/dist/browser-session/operations.gen.js +58 -0
- package/dist/browser-session/responseContracts/api_keys.d.ts +2 -0
- package/dist/browser-session/responseContracts/api_keys.js +10 -0
- package/dist/browser-session/responseContracts/credits.d.ts +2 -0
- package/dist/browser-session/responseContracts/credits.js +8 -0
- package/dist/browser-session/responseContracts/github.d.ts +2 -0
- package/dist/browser-session/responseContracts/github.js +11 -0
- package/dist/browser-session/responseContracts/identity.d.ts +2 -0
- package/dist/browser-session/responseContracts/identity.js +30 -0
- package/dist/browser-session/responseContracts/organizations.d.ts +2 -0
- package/dist/browser-session/responseContracts/organizations.js +17 -0
- package/dist/browser-session/responseContracts/privacy.d.ts +2 -0
- package/dist/browser-session/responseContracts/privacy.js +7 -0
- package/dist/browser-session/responseContracts.gen.d.ts +3 -0
- package/dist/browser-session/responseContracts.gen.js +10 -0
- package/dist/browser-session/responseValidators/api_keys-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/api_keys-diagnostics.d.cts +4 -0
- package/dist/browser-session/responseValidators/api_keys.cjs +2 -0
- package/dist/browser-session/responseValidators/api_keys.d.cts +4 -0
- package/dist/browser-session/responseValidators/credits-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/credits-diagnostics.d.cts +3 -0
- package/dist/browser-session/responseValidators/credits.cjs +2 -0
- package/dist/browser-session/responseValidators/credits.d.cts +3 -0
- package/dist/browser-session/responseValidators/github-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/github-diagnostics.d.cts +3 -0
- package/dist/browser-session/responseValidators/github.cjs +2 -0
- package/dist/browser-session/responseValidators/github.d.cts +3 -0
- package/dist/browser-session/responseValidators/identity-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/identity-diagnostics.d.cts +23 -0
- package/dist/browser-session/responseValidators/identity.cjs +2 -0
- package/dist/browser-session/responseValidators/identity.d.cts +23 -0
- package/dist/browser-session/responseValidators/organizations-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/organizations-diagnostics.d.cts +15 -0
- package/dist/browser-session/responseValidators/organizations.cjs +2 -0
- package/dist/browser-session/responseValidators/organizations.d.cts +15 -0
- package/dist/browser-session/responseValidators/privacy-diagnostics.cjs +1 -0
- package/dist/browser-session/responseValidators/privacy-diagnostics.d.cts +2 -0
- package/dist/browser-session/responseValidators/privacy.cjs +2 -0
- package/dist/browser-session/responseValidators/privacy.d.cts +2 -0
- package/dist/client/client.gen.d.ts +1 -1
- package/dist/client/client.gen.js +46 -94
- package/dist/client/index.d.ts +10 -10
- package/dist/client/index.js +16 -5
- package/dist/client/types.gen.d.ts +6 -6
- package/dist/client/types.gen.js +2 -1
- package/dist/client/utils.gen.d.ts +2 -2
- package/dist/client/utils.gen.js +31 -20
- package/dist/client.gen.d.ts +2 -2
- package/dist/client.gen.js +5 -2
- package/dist/command-check.gen.d.ts +14 -0
- package/dist/command-check.gen.js +23 -0
- package/dist/command-input.gen.d.ts +6 -0
- package/dist/command-input.gen.js +45 -0
- package/dist/core/auth.gen.js +5 -1
- package/dist/core/binaryStream.d.ts +8 -0
- package/dist/core/binaryStream.js +76 -0
- package/dist/core/bodySerializer.gen.d.ts +1 -1
- package/dist/core/bodySerializer.gen.js +8 -5
- package/dist/core/commandValidators.cjs +1 -0
- package/dist/core/commandValidators.d.cts +14 -0
- package/dist/core/eventValidation.d.ts +17 -0
- package/dist/core/eventValidation.js +56 -0
- package/dist/core/eventValidators.cjs +1 -0
- package/dist/core/eventValidators.d.cts +2 -0
- package/dist/core/json.d.ts +3 -0
- package/dist/core/json.js +33 -0
- package/dist/core/params.gen.js +4 -1
- package/dist/core/pathSerializer.gen.js +20 -11
- package/dist/core/queryKeySerializer.gen.js +12 -6
- package/dist/core/responseContracts/actions.d.ts +2 -0
- package/dist/core/responseContracts/actions.js +30 -0
- package/dist/core/responseContracts/agents.d.ts +2 -0
- package/dist/core/responseContracts/agents.js +7 -0
- package/dist/core/responseContracts/artifacts.d.ts +2 -0
- package/dist/core/responseContracts/artifacts.js +8 -0
- package/dist/core/responseContracts/commands.d.ts +2 -0
- package/dist/core/responseContracts/commands.js +6 -0
- package/dist/core/responseContracts/credits.d.ts +2 -0
- package/dist/core/responseContracts/credits.js +27 -0
- package/dist/core/responseContracts/files.d.ts +2 -0
- package/dist/core/responseContracts/files.js +15 -0
- package/dist/core/responseContracts/github.d.ts +2 -0
- package/dist/core/responseContracts/github.js +8 -0
- package/dist/core/responseContracts/images.d.ts +2 -0
- package/dist/core/responseContracts/images.js +8 -0
- package/dist/core/responseContracts/launchRuns.d.ts +2 -0
- package/dist/core/responseContracts/launchRuns.js +10 -0
- package/dist/core/responseContracts/launches.d.ts +2 -0
- package/dist/core/responseContracts/launches.js +10 -0
- package/dist/core/responseContracts/operations.d.ts +2 -0
- package/dist/core/responseContracts/operations.js +7 -0
- package/dist/core/responseContracts/previews.d.ts +2 -0
- package/dist/core/responseContracts/previews.js +8 -0
- package/dist/core/responseContracts/pricing.d.ts +2 -0
- package/dist/core/responseContracts/pricing.js +6 -0
- package/dist/core/responseContracts/processes.d.ts +2 -0
- package/dist/core/responseContracts/processes.js +11 -0
- package/dist/core/responseContracts/provider_accounts.d.ts +2 -0
- package/dist/core/responseContracts/provider_accounts.js +13 -0
- package/dist/core/responseContracts/providers.d.ts +2 -0
- package/dist/core/responseContracts/providers.js +6 -0
- package/dist/core/responseContracts/routing.d.ts +2 -0
- package/dist/core/responseContracts/routing.js +8 -0
- package/dist/core/responseContracts/sandboxes.d.ts +2 -0
- package/dist/core/responseContracts/sandboxes.js +15 -0
- package/dist/core/responseContracts/secrets.d.ts +2 -0
- package/dist/core/responseContracts/secrets.js +8 -0
- package/dist/core/responseContracts/spend_limits.d.ts +2 -0
- package/dist/core/responseContracts/spend_limits.js +8 -0
- package/dist/core/responseContracts/terminals.d.ts +2 -0
- package/dist/core/responseContracts/terminals.js +11 -0
- package/dist/core/responseContracts/usage.d.ts +2 -0
- package/dist/core/responseContracts/usage.js +7 -0
- package/dist/core/responseContracts/volumes.d.ts +2 -0
- package/dist/core/responseContracts/volumes.js +19 -0
- package/dist/core/responseContracts.gen.d.ts +3 -0
- package/dist/core/responseContracts.gen.js +27 -0
- package/dist/core/responseModes.d.ts +19 -0
- package/dist/core/responseModes.js +13 -0
- package/dist/core/responseValidation.d.ts +44 -0
- package/dist/core/responseValidation.js +174 -0
- package/dist/core/responseValidators/actions-diagnostics.cjs +4 -0
- package/dist/core/responseValidators/actions-diagnostics.d.cts +24 -0
- package/dist/core/responseValidators/actions.cjs +2 -0
- package/dist/core/responseValidators/actions.d.cts +24 -0
- package/dist/core/responseValidators/agents-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/agents-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/agents.cjs +2 -0
- package/dist/core/responseValidators/agents.d.cts +2 -0
- package/dist/core/responseValidators/artifacts-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/artifacts-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/artifacts.cjs +2 -0
- package/dist/core/responseValidators/artifacts.d.cts +2 -0
- package/dist/core/responseValidators/commands-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/commands-diagnostics.d.cts +1 -0
- package/dist/core/responseValidators/commands.cjs +2 -0
- package/dist/core/responseValidators/commands.d.cts +1 -0
- package/dist/core/responseValidators/compact.cjs +122 -0
- package/dist/core/responseValidators/credits-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/credits-diagnostics.d.cts +21 -0
- package/dist/core/responseValidators/credits.cjs +2 -0
- package/dist/core/responseValidators/credits.d.cts +21 -0
- package/dist/core/responseValidators/files-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/files-diagnostics.d.cts +5 -0
- package/dist/core/responseValidators/files.cjs +2 -0
- package/dist/core/responseValidators/files.d.cts +5 -0
- package/dist/core/responseValidators/github-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/github-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/github.cjs +2 -0
- package/dist/core/responseValidators/github.d.cts +2 -0
- package/dist/core/responseValidators/images-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/images-diagnostics.d.cts +3 -0
- package/dist/core/responseValidators/images.cjs +2 -0
- package/dist/core/responseValidators/images.d.cts +3 -0
- package/dist/core/responseValidators/launchRuns-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/launchRuns-diagnostics.d.cts +5 -0
- package/dist/core/responseValidators/launchRuns.cjs +2 -0
- package/dist/core/responseValidators/launchRuns.d.cts +5 -0
- package/dist/core/responseValidators/launches-diagnostics.cjs +10 -0
- package/dist/core/responseValidators/launches-diagnostics.d.cts +5 -0
- package/dist/core/responseValidators/launches.cjs +2 -0
- package/dist/core/responseValidators/launches.d.cts +5 -0
- package/dist/core/responseValidators/operations-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/operations-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/operations.cjs +2 -0
- package/dist/core/responseValidators/operations.d.cts +2 -0
- package/dist/core/responseValidators/previews-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/previews-diagnostics.d.cts +3 -0
- package/dist/core/responseValidators/previews.cjs +2 -0
- package/dist/core/responseValidators/previews.d.cts +3 -0
- package/dist/core/responseValidators/pricing-diagnostics.cjs +7 -0
- package/dist/core/responseValidators/pricing-diagnostics.d.cts +1 -0
- package/dist/core/responseValidators/pricing.cjs +2 -0
- package/dist/core/responseValidators/pricing.d.cts +1 -0
- package/dist/core/responseValidators/processes-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/processes-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/processes.cjs +2 -0
- package/dist/core/responseValidators/processes.d.cts +2 -0
- package/dist/core/responseValidators/provider_accounts-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/provider_accounts-diagnostics.d.cts +8 -0
- package/dist/core/responseValidators/provider_accounts.cjs +2 -0
- package/dist/core/responseValidators/provider_accounts.d.cts +8 -0
- package/dist/core/responseValidators/providers-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/providers-diagnostics.d.cts +1 -0
- package/dist/core/responseValidators/providers.cjs +2 -0
- package/dist/core/responseValidators/providers.d.cts +1 -0
- package/dist/core/responseValidators/routing-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/routing-diagnostics.d.cts +3 -0
- package/dist/core/responseValidators/routing.cjs +2 -0
- package/dist/core/responseValidators/routing.d.cts +3 -0
- package/dist/core/responseValidators/sandboxes-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/sandboxes-diagnostics.d.cts +10 -0
- package/dist/core/responseValidators/sandboxes.cjs +2 -0
- package/dist/core/responseValidators/sandboxes.d.cts +10 -0
- package/dist/core/responseValidators/secrets-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/secrets-diagnostics.d.cts +1 -0
- package/dist/core/responseValidators/secrets.cjs +2 -0
- package/dist/core/responseValidators/secrets.d.cts +1 -0
- package/dist/core/responseValidators/spend_limits-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/spend_limits-diagnostics.d.cts +3 -0
- package/dist/core/responseValidators/spend_limits.cjs +2 -0
- package/dist/core/responseValidators/spend_limits.d.cts +3 -0
- package/dist/core/responseValidators/terminals-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/terminals-diagnostics.d.cts +2 -0
- package/dist/core/responseValidators/terminals.cjs +2 -0
- package/dist/core/responseValidators/terminals.d.cts +2 -0
- package/dist/core/responseValidators/usage-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/usage-diagnostics.d.cts +1 -0
- package/dist/core/responseValidators/usage.cjs +2 -0
- package/dist/core/responseValidators/usage.d.cts +1 -0
- package/dist/core/responseValidators/volumes-diagnostics.cjs +1 -0
- package/dist/core/responseValidators/volumes-diagnostics.d.cts +10 -0
- package/dist/core/responseValidators/volumes.cjs +2 -0
- package/dist/core/responseValidators/volumes.d.cts +10 -0
- package/dist/core/serverSentEvents.gen.d.ts +21 -62
- package/dist/core/serverSentEvents.gen.js +297 -116
- package/dist/core/streamErrors.d.ts +32 -0
- package/dist/core/streamErrors.js +51 -0
- package/dist/core/types.gen.d.ts +2 -2
- package/dist/core/types.gen.js +2 -1
- package/dist/core/utils.gen.d.ts +1 -1
- package/dist/core/utils.gen.js +16 -10
- package/dist/creation.gen.d.ts +21 -0
- package/dist/creation.gen.js +35 -0
- package/dist/data-origin.d.ts +25 -0
- package/dist/data-origin.js +57 -0
- package/dist/error-codes.gen.d.ts +2 -0
- package/dist/error-codes.gen.js +2 -0
- package/dist/idempotency.gen.d.ts +1 -0
- package/dist/idempotency.gen.js +60 -0
- package/dist/images.d.ts +74 -0
- package/dist/images.js +88 -0
- package/dist/index.d.ts +22 -2
- package/dist/index.js +79 -1
- package/dist/launch-input.gen.d.ts +9 -0
- package/dist/launch-input.gen.js +83 -0
- package/dist/launch.d.ts +28 -0
- package/dist/launch.js +222 -0
- package/dist/namespace-actions.d.mts +307 -0
- package/dist/namespace-actions.mjs +595 -0
- package/dist/namespace-agents.d.mts +33 -0
- package/dist/namespace-agents.mjs +40 -0
- package/dist/namespace-artifacts.d.mts +46 -0
- package/dist/namespace-artifacts.mjs +69 -0
- package/dist/namespace-base.d.mts +7 -0
- package/dist/namespace-base.mjs +7 -0
- package/dist/namespace-commands.d.mts +57 -0
- package/dist/namespace-commands.mjs +57 -0
- package/dist/namespace-credits.d.mts +213 -0
- package/dist/namespace-credits.mjs +476 -0
- package/dist/namespace-files.d.mts +203 -0
- package/dist/namespace-files.mjs +334 -0
- package/dist/namespace-github.d.mts +50 -0
- package/dist/namespace-github.mjs +68 -0
- package/dist/namespace-images.d.mts +52 -0
- package/dist/namespace-images.mjs +78 -0
- package/dist/namespace-launch_runs.d.mts +89 -0
- package/dist/namespace-launch_runs.mjs +133 -0
- package/dist/namespace-launches.d.mts +89 -0
- package/dist/namespace-launches.mjs +133 -0
- package/dist/namespace-operations.d.mts +45 -0
- package/dist/namespace-operations.mjs +52 -0
- package/dist/namespace-previews.d.mts +79 -0
- package/dist/namespace-previews.mjs +101 -0
- package/dist/namespace-pricing.d.mts +31 -0
- package/dist/namespace-pricing.mjs +22 -0
- package/dist/namespace-processes.d.mts +125 -0
- package/dist/namespace-processes.mjs +184 -0
- package/dist/namespace-provider_accounts.d.mts +156 -0
- package/dist/namespace-provider_accounts.mjs +241 -0
- package/dist/namespace-providers.d.mts +28 -0
- package/dist/namespace-providers.mjs +24 -0
- package/dist/namespace-routing.d.mts +64 -0
- package/dist/namespace-routing.mjs +86 -0
- package/dist/namespace-sandboxes.d.mts +287 -0
- package/dist/namespace-sandboxes.mjs +402 -0
- package/dist/namespace-secrets.d.mts +46 -0
- package/dist/namespace-secrets.mjs +68 -0
- package/dist/namespace-spend_limits.d.mts +48 -0
- package/dist/namespace-spend_limits.mjs +70 -0
- package/dist/namespace-terminals.d.mts +112 -0
- package/dist/namespace-terminals.mjs +177 -0
- package/dist/namespace-usage.d.mts +46 -0
- package/dist/namespace-usage.mjs +53 -0
- package/dist/namespace-volumes.d.mts +110 -0
- package/dist/namespace-volumes.mjs +269 -0
- package/dist/operations.d.ts +14 -0
- package/dist/operations.js +31 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +63 -0
- package/dist/routing-choices.gen.d.ts +132 -0
- package/dist/routing-choices.gen.js +136 -0
- package/dist/routing.d.ts +23 -0
- package/dist/routing.js +38 -0
- package/dist/sandbox-handle.gen.d.ts +8 -0
- package/dist/sandbox-handle.gen.js +14 -0
- package/dist/sandboxes.d.ts +213 -0
- package/dist/sandboxes.js +507 -0
- package/dist/sdk.gen.d.ts +2016 -12
- package/dist/sdk.gen.js +3862 -16
- package/dist/server-timing.d.ts +19 -0
- package/dist/server-timing.gen.d.ts +265 -0
- package/dist/server-timing.gen.js +254 -0
- package/dist/server-timing.js +421 -0
- package/dist/spend-limits.d.ts +17 -0
- package/dist/spend-limits.js +26 -0
- package/dist/telemetry.d.ts +51 -0
- package/dist/telemetry.gen.d.ts +1 -0
- package/dist/telemetry.gen.js +5 -0
- package/dist/telemetry.js +438 -0
- package/dist/terminal.d.ts +61 -0
- package/dist/terminal.js +266 -0
- package/dist/transfer.d.ts +75 -0
- package/dist/transfer.js +389 -0
- package/dist/types.gen.d.ts +14936 -110
- package/dist/types.gen.js +2 -1
- package/dist/user-agent.d.ts +2 -0
- package/dist/user-agent.js +18 -0
- package/dist/version.gen.d.ts +1 -0
- package/dist/version.gen.js +5 -0
- package/dist/volumes.d.ts +33 -0
- package/dist/volumes.js +221 -0
- package/dist/waits.d.ts +31 -0
- package/dist/waits.js +42 -0
- package/dist/workflow-policy.gen.d.ts +41 -0
- package/dist/workflow-policy.gen.js +45 -0
- package/package.json +124 -14
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require("./compact.cjs")({"roots":{"validate0":{"$":0},"validate1":{"$":1},"validate2":{"$":1},"validate3":{"$":7},"validate4":{"$":8},"validate5":{"$":8},"validate6":{"$":12},"validate7":{"$":16},"validate8":{"$":17},"validate9":{"$":18}},"definitions":[{"type":"object","required":["data","next_cursor"],"properties":{"data":{"type":"array","items":{"$":1}},"next_cursor":{"type":["string","null"]},"stored_bytes":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"live_volume_policy":{"$":6},"allowance_bytes":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"gib_hours_this_month":{"minimum":0,"allOf":[{"anyOf":[{"type":"number"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}}}},{"type":"object","required":["id","name","state","labels","created_at","updated_at","last_used_at","head_checkpoint","checkpoint_count","stored_bytes","limits","attachments"],"properties":{"id":{"$":2},"name":{"$":3},"state":{"type":"string"},"labels":{"type":"object","additionalProperties":{"type":"string"}},"observed_volume_bytes":{"minimum":0,"allOf":[{"anyOf":[{"type":["integer","null"]},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_used_at":{"type":["string","null"],"format":"date-time"},"head_checkpoint":{"minimum":1,"allOf":[{"anyOf":[{"type":["integer","null"]},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}},"checkpoint_count":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"stored_bytes":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"limits":{"$":4},"attachments":{"type":"array","items":{"$":5}}}},{"type":"string","pattern":"^vol_[0-9a-f]{32}$"},{"type":"string","minLength":1,"maxLength":63,"pattern":"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$"},{"type":"object","required":["max_checkpoints"],"properties":{"max_checkpoints":{"minimum":1,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}}}},{"type":"object","required":["sandbox_id","access","attached_at","restored_checkpoint"],"properties":{"sandbox_id":{"type":"string"},"access":{"type":"string","enum":["write","read","shared","branch"]},"attached_at":{"type":["string","null"],"format":"date-time"},"restored_checkpoint":{"minimum":1,"allOf":[{"anyOf":[{"type":["integer","null"]},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}}}},{"type":"object","required":["enabled","soft_quota_bytes"],"properties":{"enabled":{"type":"boolean"},"soft_quota_bytes":{"minimum":1,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}}}},{"type":"object","required":["data","next_cursor"],"properties":{"data":{"type":"array","items":{"$":8}},"next_cursor":{"type":["string","null"]}}},{"type":"object","required":["volume_id","checkpoint","state","created_at","reason","saved_on","image","arch","user","path","observed_volume_bytes","duration_ms","message"],"properties":{"volume_id":{"$":2},"checkpoint":{"minimum":1,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}},"state":{"type":"string"},"created_at":{"type":"string","format":"date-time"},"reason":{"type":"string"},"saved_on":{"$":9},"image":{"$":10},"arch":{"type":"string","enum":["amd64","arm64"]},"user":{"$":11},"path":{"type":"string","pattern":"^/[^\\u0000]*$"},"observed_volume_bytes":{"minimum":0,"allOf":[{"anyOf":[{"type":["integer","null"]},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"duration_ms":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"message":{"type":["string","null"],"maxLength":500}}},{"type":"object","required":["sandbox_id","provider","class","region"],"properties":{"sandbox_id":{"type":"string"},"provider":{"type":"string"},"class":{"type":["string","null"]},"region":{"type":["string","null"]}}},{"type":"object","required":["value","digest"],"properties":{"value":{"type":"string"},"digest":{"type":["string","null"]}}},{"type":"object","required":["name","uid"],"properties":{"name":{"type":"string"},"uid":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}}}},{"type":"object","required":["id","volume_id","path","size","part_size","parts","expires_at"],"properties":{"id":{"$":13},"volume_id":{"$":2},"path":{"$":14},"size":{"minimum":0,"maximum":5497558138880,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0,"maximum":5497558138880}},"part_size":{"minimum":1,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1}},"parts":{"type":"array","minItems":1,"maxItems":10000,"items":{"$":15}},"expires_at":{"type":"string","format":"date-time"}}},{"type":"string","pattern":"^vup_[0-9a-f]{32}$"},{"type":"string","minLength":1,"maxLength":1024,"pattern":"^(?!/)(?!.*//)(?!\\.{1,2}(?:/|$))(?!.*\\/\\.{1,2}(?:/|$))(?!.*\\u0000).+$"},{"type":"object","required":["number","size","url"],"properties":{"number":{"minimum":1,"maximum":10000,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":1,"maximum":10000}},"size":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"url":{"type":"string","format":"uri"}}},{"type":"object","required":["path","size"],"properties":{"path":{"$":14},"size":{"minimum":0,"maximum":5497558138880,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0,"maximum":5497558138880}}}},{"type":"object","required":["url","path","size","expires_at"],"properties":{"url":{"type":"string","format":"uri"},"path":{"$":14},"size":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"expires_at":{"type":"string","format":"date-time"}}},{"type":"object","required":["data","next_cursor"],"properties":{"data":{"type":"array","items":{"$":19}},"next_cursor":{"type":["string","null"]}}},{"type":"object","required":["path","size","modified_at"],"properties":{"path":{"$":14},"size":{"minimum":0,"allOf":[{"anyOf":[{"type":"integer"},{"x-boxrouter-bigint":true}]}],"x-boxrouter-bigint-range":{"minimum":0}},"modified_at":{"type":"string","format":"date-time"}}}]});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const validate0: (value: unknown) => boolean;
|
|
2
|
+
export declare const validate1: (value: unknown) => boolean;
|
|
3
|
+
export declare const validate2: (value: unknown) => boolean;
|
|
4
|
+
export declare const validate3: (value: unknown) => boolean;
|
|
5
|
+
export declare const validate4: (value: unknown) => boolean;
|
|
6
|
+
export declare const validate5: (value: unknown) => boolean;
|
|
7
|
+
export declare const validate6: (value: unknown) => boolean;
|
|
8
|
+
export declare const validate7: (value: unknown) => boolean;
|
|
9
|
+
export declare const validate8: (value: unknown) => boolean;
|
|
10
|
+
export declare const validate9: (value: unknown) => boolean;
|
|
@@ -1,71 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StreamHTTPError } from './streamErrors';
|
|
2
|
+
import type { Config } from './types.gen';
|
|
3
|
+
type EventValue<T> = T extends Record<string, unknown> ? T[keyof T] : T;
|
|
4
|
+
export interface StreamEvent<TData = unknown> {
|
|
5
|
+
data: TData;
|
|
6
|
+
event?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
2
9
|
export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
3
|
-
/**
|
|
4
|
-
* Fetch API implementation. You can use this option to provide a custom
|
|
5
|
-
* fetch instance.
|
|
6
|
-
*
|
|
7
|
-
* @default globalThis.fetch
|
|
8
|
-
*/
|
|
9
10
|
fetch?: typeof fetch;
|
|
10
|
-
/**
|
|
11
|
-
* Implementing clients can call request interceptors inside this hook.
|
|
12
|
-
*/
|
|
13
11
|
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
14
|
-
/**
|
|
15
|
-
* Callback invoked when a network or parsing error occurs during streaming.
|
|
16
|
-
*
|
|
17
|
-
* This option applies only if the endpoint returns a stream of events.
|
|
18
|
-
*
|
|
19
|
-
* @param error The error that occurred.
|
|
20
|
-
*/
|
|
21
12
|
onSseError?: (error: unknown) => void;
|
|
22
|
-
|
|
23
|
-
* Callback invoked when an event is streamed from the server.
|
|
24
|
-
*
|
|
25
|
-
* This option applies only if the endpoint returns a stream of events.
|
|
26
|
-
*
|
|
27
|
-
* @param event Event streamed from the server.
|
|
28
|
-
* @returns Nothing (void).
|
|
29
|
-
*/
|
|
30
|
-
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
13
|
+
onSseEvent?: (event: TData) => void;
|
|
31
14
|
serializedBody?: RequestInit['body'];
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
39
|
-
sseDefaultRetryDelay?: number;
|
|
40
|
-
/**
|
|
41
|
-
* Maximum number of retry attempts before giving up.
|
|
42
|
-
*/
|
|
43
|
-
sseMaxRetryAttempts?: number;
|
|
44
|
-
/**
|
|
45
|
-
* Maximum retry delay in milliseconds.
|
|
46
|
-
*
|
|
47
|
-
* Applies only when exponential backoff is used.
|
|
48
|
-
*
|
|
49
|
-
* This option applies only if the endpoint returns a stream of events.
|
|
50
|
-
*
|
|
51
|
-
* @default 30000
|
|
52
|
-
*/
|
|
53
|
-
sseMaxRetryDelay?: number;
|
|
54
|
-
/**
|
|
55
|
-
* Optional sleep function for retry backoff.
|
|
56
|
-
*
|
|
57
|
-
* Defaults to using `setTimeout`.
|
|
58
|
-
*/
|
|
59
|
-
sseSleepFn?: (ms: number) => Promise<void>;
|
|
15
|
+
/** Maximum SSE block bytes after CR/CRLF normalization, including fields and delimiters. */
|
|
16
|
+
sseMaxBufferSize?: number;
|
|
17
|
+
/** @internal Generated operation completion check, before successful EOF. */
|
|
18
|
+
validateStreamEnd?: () => void;
|
|
19
|
+
/** @internal Canonical generated path, before parameter substitution. */
|
|
20
|
+
telemetryPath?: string;
|
|
60
21
|
url: string;
|
|
61
22
|
};
|
|
62
|
-
export interface StreamEvent<TData = unknown> {
|
|
63
|
-
data: TData;
|
|
64
|
-
event?: string;
|
|
65
|
-
id?: string;
|
|
66
|
-
retry?: number;
|
|
67
|
-
}
|
|
68
23
|
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
69
|
-
stream: AsyncGenerator<
|
|
24
|
+
stream: AsyncGenerator<EventValue<TData>, TReturn, TNext>;
|
|
25
|
+
/** Interrupt pending reads and close this HTTP stream, without cancelling remote work. */
|
|
26
|
+
close: () => void;
|
|
70
27
|
};
|
|
71
|
-
export
|
|
28
|
+
export { StreamHTTPError };
|
|
29
|
+
/** One request, incremental SSE envelopes, no reconnect or mutation replay. */
|
|
30
|
+
export declare function createSseClient<TData = unknown>({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, fetch: fetchImplementation, serializedBody, sseMaxBufferSize, validateStreamEnd, telemetryPath, url, signal, ...options }: ServerSentEventsOptions): ServerSentEventsResult<TData>;
|
|
@@ -1,132 +1,313 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamHTTPError = void 0;
|
|
4
|
+
exports.createSseClient = createSseClient;
|
|
5
|
+
const eventsource_parser_1 = require("eventsource-parser");
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const json_1 = require("./json");
|
|
8
|
+
const api_error_1 = require("../api-error");
|
|
9
|
+
const streamErrors_1 = require("./streamErrors");
|
|
10
|
+
Object.defineProperty(exports, "StreamHTTPError", { enumerable: true, get: function () { return streamErrors_1.StreamHTTPError; } });
|
|
11
|
+
const telemetry_1 = require("../telemetry");
|
|
12
|
+
const workflow_policy_gen_1 = require("../workflow-policy.gen");
|
|
13
|
+
function monotonicMilliseconds() {
|
|
14
|
+
try {
|
|
15
|
+
const performance = globalThis.performance;
|
|
16
|
+
const value = performance?.now?.call(performance);
|
|
17
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Bound raw bytes before text decoding or the library can buffer a partial event. */
|
|
24
|
+
function boundedInput(limit) {
|
|
25
|
+
let size = 0;
|
|
26
|
+
let lineBytes = 0;
|
|
27
|
+
let skipLf = false;
|
|
28
|
+
return new TransformStream({
|
|
29
|
+
transform(chunk, controller) {
|
|
30
|
+
for (const byte of chunk) {
|
|
31
|
+
if (byte === 10 && skipLf) {
|
|
32
|
+
skipLf = false;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (++size > limit)
|
|
36
|
+
throw Object.assign(new RangeError(`SSE block exceeds ${limit} normalized bytes`), { type: 'max-buffer-size-exceeded' });
|
|
37
|
+
if (byte === 10 || byte === 13) {
|
|
38
|
+
if (lineBytes === 0)
|
|
39
|
+
size = 0;
|
|
40
|
+
lineBytes = 0;
|
|
41
|
+
skipLf = byte === 13;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
skipLf = false;
|
|
45
|
+
lineBytes++;
|
|
46
|
+
}
|
|
18
47
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
controller.enqueue(chunk);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function eventParser(maxBufferSize) {
|
|
53
|
+
let parser;
|
|
54
|
+
let lastId;
|
|
55
|
+
return new TransformStream({
|
|
56
|
+
start(controller) {
|
|
57
|
+
parser = (0, eventsource_parser_1.createParser)({
|
|
58
|
+
maxBufferSize,
|
|
59
|
+
onId(id) { lastId = id; },
|
|
60
|
+
onEvent(event) {
|
|
61
|
+
// Snapshot the cursor before later blocks in this chunk can update it.
|
|
62
|
+
controller.enqueue({ ...event, id: lastId });
|
|
63
|
+
},
|
|
64
|
+
onError(error) {
|
|
65
|
+
if (error.type === 'max-buffer-size-exceeded')
|
|
66
|
+
controller.error(error);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
transform(chunk) { parser.feed(chunk); },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async function httpError(request, response, signal) {
|
|
74
|
+
const reader = response.body?.getReader();
|
|
75
|
+
const abort = () => { void reader?.cancel(signal.reason).catch(() => { }); };
|
|
76
|
+
const buffer = new Uint8Array(workflow_policy_gen_1.MAX_ERROR_BYTES);
|
|
77
|
+
let length = 0;
|
|
78
|
+
let truncated = false;
|
|
79
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
80
|
+
try {
|
|
81
|
+
if (signal.aborted)
|
|
82
|
+
abort();
|
|
83
|
+
signal.throwIfAborted();
|
|
84
|
+
if (reader) {
|
|
85
|
+
while (true) {
|
|
86
|
+
const { done, value } = await reader.read();
|
|
87
|
+
signal.throwIfAborted();
|
|
88
|
+
if (done)
|
|
89
|
+
break;
|
|
90
|
+
const remaining = workflow_policy_gen_1.MAX_ERROR_BYTES - length;
|
|
91
|
+
buffer.set(value.subarray(0, remaining), length);
|
|
92
|
+
length += Math.min(value.byteLength, remaining);
|
|
93
|
+
if (value.byteLength > remaining) {
|
|
94
|
+
truncated = true;
|
|
95
|
+
break;
|
|
30
96
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
signal.removeEventListener('abort', abort);
|
|
102
|
+
if (reader) {
|
|
103
|
+
await reader.cancel().catch(() => { });
|
|
104
|
+
reader.releaseLock();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Fetch supplies decoded bytes. Keep upstream headers for diagnostics; their
|
|
108
|
+
// Content-Length describes the original response, not the bounded body copy.
|
|
109
|
+
const captured = new Response(length ? buffer.slice(0, length) : null, {
|
|
110
|
+
status: response.status, statusText: response.statusText, headers: response.headers,
|
|
111
|
+
});
|
|
112
|
+
let payload;
|
|
113
|
+
try {
|
|
114
|
+
payload = (0, json_1.parseJson)(new TextDecoder().decode(buffer.subarray(0, length)));
|
|
115
|
+
}
|
|
116
|
+
catch { /* Malformed diagnostics do not replace the HTTP failure. */ }
|
|
117
|
+
return new streamErrors_1.StreamHTTPError(request, captured, truncated, payload);
|
|
118
|
+
}
|
|
119
|
+
/** One request, incremental SSE envelopes, no reconnect or mutation replay. */
|
|
120
|
+
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, fetch: fetchImplementation = globalThis.fetch, serializedBody, sseMaxBufferSize = workflow_policy_gen_1.DEFAULT_EVENT_BYTES, validateStreamEnd, telemetryPath, url, signal, ...options }) {
|
|
121
|
+
const controller = new AbortController();
|
|
122
|
+
const parent = api_1.context.active();
|
|
123
|
+
async function* receive() {
|
|
124
|
+
let reader;
|
|
125
|
+
let pipes = [];
|
|
126
|
+
let response;
|
|
127
|
+
let request;
|
|
128
|
+
const telemetry = new telemetry_1.RequestTrace(options.method, telemetryPath, parent);
|
|
129
|
+
let completed = false;
|
|
130
|
+
let failed = false;
|
|
131
|
+
let events = 0;
|
|
132
|
+
let eventProcessingChecked = false;
|
|
133
|
+
let eventProcessingRecording = false;
|
|
134
|
+
let eventProcessingMeasured = true;
|
|
135
|
+
let eventProcessingMilliseconds = 0;
|
|
136
|
+
let firstEventReadyStarted;
|
|
137
|
+
let firstEventReadyMeasured = true;
|
|
138
|
+
let firstEventReadyMilliseconds;
|
|
139
|
+
const abort = () => controller.abort(signal?.reason);
|
|
140
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
141
|
+
try {
|
|
142
|
+
if (signal?.aborted)
|
|
143
|
+
abort();
|
|
144
|
+
controller.signal.throwIfAborted();
|
|
145
|
+
if (!Number.isSafeInteger(sseMaxBufferSize) || sseMaxBufferSize < 1) {
|
|
146
|
+
throw new RangeError('sseMaxBufferSize must be a positive safe integer');
|
|
147
|
+
}
|
|
148
|
+
const headers = new Headers(options.headers);
|
|
149
|
+
if (!headers.has('Accept'))
|
|
150
|
+
headers.set('Accept', 'text/event-stream');
|
|
151
|
+
const init = {
|
|
152
|
+
redirect: 'error', ...options, headers, body: serializedBody, signal: controller.signal,
|
|
153
|
+
};
|
|
154
|
+
request = onRequest ? await onRequest(url, init) : new Request(url, init);
|
|
155
|
+
controller.signal.throwIfAborted();
|
|
156
|
+
telemetry.inject(request.headers);
|
|
157
|
+
const sentRequest = request;
|
|
158
|
+
response = await telemetry.fetchResponse(() => api_1.context.with(telemetry.context, () => fetchImplementation(sentRequest)));
|
|
159
|
+
telemetry.response(response);
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
throw await httpError(request, response, controller.signal);
|
|
162
|
+
}
|
|
163
|
+
if (response.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase() !== 'text/event-stream') {
|
|
164
|
+
throw new streamErrors_1.StreamParseError('Expected text/event-stream response');
|
|
165
|
+
}
|
|
166
|
+
if (!response.body)
|
|
167
|
+
throw new streamErrors_1.StreamParseError('Missing event stream body');
|
|
168
|
+
telemetry.finishObserverOutcome('success');
|
|
169
|
+
telemetry.startStreamLifetime();
|
|
170
|
+
const bounded = boundedInput(sseMaxBufferSize);
|
|
171
|
+
const decoder = new TextDecoderStream('utf-8', { fatal: true });
|
|
172
|
+
const parser = eventParser(sseMaxBufferSize);
|
|
173
|
+
if (!eventProcessingChecked) {
|
|
174
|
+
eventProcessingChecked = true;
|
|
50
175
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
176
|
+
eventProcessingRecording = telemetry.span.isRecording();
|
|
177
|
+
}
|
|
178
|
+
catch { /* Optional timing observation. */ }
|
|
179
|
+
}
|
|
180
|
+
if (eventProcessingRecording) {
|
|
181
|
+
firstEventReadyStarted = monotonicMilliseconds();
|
|
182
|
+
if (firstEventReadyStarted === undefined)
|
|
183
|
+
firstEventReadyMeasured = false;
|
|
184
|
+
}
|
|
185
|
+
pipes = [
|
|
186
|
+
response.body.pipeTo(bounded.writable, { signal: controller.signal }),
|
|
187
|
+
bounded.readable.pipeTo(decoder.writable, { signal: controller.signal }),
|
|
188
|
+
decoder.readable.pipeTo(parser.writable, { signal: controller.signal }),
|
|
189
|
+
].map(pipe => pipe.catch(() => { })); // Reader errors retain the original failure.
|
|
190
|
+
reader = parser.readable.getReader();
|
|
191
|
+
while (true) {
|
|
192
|
+
const { done, value } = await reader.read();
|
|
193
|
+
controller.signal.throwIfAborted();
|
|
194
|
+
if (done) {
|
|
195
|
+
validateStreamEnd?.();
|
|
196
|
+
completed = true;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const processingStarted = eventProcessingRecording ? monotonicMilliseconds() : undefined;
|
|
200
|
+
if (eventProcessingRecording && processingStarted === undefined)
|
|
201
|
+
eventProcessingMeasured = false;
|
|
202
|
+
let skip = false;
|
|
203
|
+
let event;
|
|
204
|
+
try {
|
|
205
|
+
event = {
|
|
206
|
+
data: (0, json_1.parseJson)(value.data),
|
|
207
|
+
...(value.event === undefined ? {} : { event: value.event }),
|
|
208
|
+
...(value.id === undefined ? {} : { id: value.id }),
|
|
209
|
+
};
|
|
210
|
+
if (responseValidator) {
|
|
211
|
+
try {
|
|
212
|
+
await responseValidator(event);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error instanceof streamErrors_1.UnknownEventKind)
|
|
216
|
+
skip = true;
|
|
217
|
+
else
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (!skip) {
|
|
222
|
+
if (responseTransformer)
|
|
223
|
+
event = await responseTransformer(event);
|
|
224
|
+
if (firstEventReadyStarted !== undefined && firstEventReadyMeasured && firstEventReadyMilliseconds === undefined) {
|
|
225
|
+
const ready = monotonicMilliseconds();
|
|
226
|
+
if (ready === undefined || ready < firstEventReadyStarted ||
|
|
227
|
+
(processingStarted !== undefined && ready < processingStarted)) {
|
|
228
|
+
firstEventReadyMeasured = false;
|
|
99
229
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (dataLines.length) {
|
|
107
|
-
yield data;
|
|
230
|
+
else {
|
|
231
|
+
const elapsed = ready - firstEventReadyStarted;
|
|
232
|
+
if (Number.isFinite(elapsed))
|
|
233
|
+
firstEventReadyMilliseconds = elapsed;
|
|
234
|
+
else
|
|
235
|
+
firstEventReadyMeasured = false;
|
|
108
236
|
}
|
|
109
237
|
}
|
|
238
|
+
onSseEvent?.(event);
|
|
239
|
+
events++;
|
|
110
240
|
}
|
|
111
241
|
}
|
|
112
242
|
finally {
|
|
113
|
-
|
|
114
|
-
|
|
243
|
+
if (eventProcessingRecording) {
|
|
244
|
+
const processingFinished = monotonicMilliseconds();
|
|
245
|
+
if (processingStarted === undefined || processingFinished === undefined || processingFinished < processingStarted) {
|
|
246
|
+
eventProcessingMeasured = false;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
eventProcessingMilliseconds += processingFinished - processingStarted;
|
|
250
|
+
if (!Number.isFinite(eventProcessingMilliseconds))
|
|
251
|
+
eventProcessingMeasured = false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
115
254
|
}
|
|
116
|
-
|
|
255
|
+
if (skip)
|
|
256
|
+
continue;
|
|
257
|
+
yield event;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
failed = !controller.signal.aborted || (0, telemetry_1.isTimeoutError)(controller.signal.reason);
|
|
262
|
+
if (failed)
|
|
263
|
+
telemetry.error(error);
|
|
264
|
+
try {
|
|
265
|
+
const outcome = telemetry.responseOutcome(error);
|
|
266
|
+
telemetry.finishRequestPreparationOutcome(outcome);
|
|
267
|
+
telemetry.finishObserverOutcome(outcome);
|
|
117
268
|
}
|
|
118
|
-
catch
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
269
|
+
catch { /* Preserve the caller's original failure. */ }
|
|
270
|
+
// Observation hooks cannot turn a failed stream into successful iteration.
|
|
271
|
+
const failure = (0, api_error_1.requestFailure)(error, request, response);
|
|
272
|
+
try {
|
|
273
|
+
onSseError?.(failure);
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
throw failure;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
signal?.removeEventListener('abort', abort);
|
|
281
|
+
if (reader) {
|
|
282
|
+
await reader.cancel().catch(() => { });
|
|
283
|
+
reader.releaseLock();
|
|
284
|
+
await Promise.all(pipes);
|
|
285
|
+
}
|
|
286
|
+
else if (response?.ok) {
|
|
287
|
+
await response.body?.cancel().catch(() => { });
|
|
288
|
+
}
|
|
289
|
+
// Failed HTTP bodies are closed; only a bounded diagnostic copy is retained.
|
|
290
|
+
telemetry.span.setAttribute('boxrouter.stream.events', events);
|
|
291
|
+
telemetry.span.setAttribute('boxrouter.stream.end', completed ? 'completed' : failed ? 'error' : 'cancelled');
|
|
292
|
+
// Sum only local decode/validation/transform/callback intervals. Reader and caller waits stay out.
|
|
293
|
+
if (eventProcessingRecording && eventProcessingMeasured) {
|
|
294
|
+
try {
|
|
295
|
+
telemetry.span.setAttribute('boxrouter.stream.event_processing_ms', eventProcessingMilliseconds);
|
|
296
|
+
}
|
|
297
|
+
catch { /* Preserve the stream result. */ }
|
|
298
|
+
}
|
|
299
|
+
if (eventProcessingRecording && firstEventReadyMeasured && firstEventReadyMilliseconds !== undefined) {
|
|
300
|
+
try {
|
|
301
|
+
telemetry.span.setAttribute('boxrouter.stream.first_event_ready_ms', firstEventReadyMilliseconds);
|
|
123
302
|
}
|
|
124
|
-
|
|
125
|
-
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
126
|
-
await sleep(backoff);
|
|
303
|
+
catch { /* Preserve the stream result. */ }
|
|
127
304
|
}
|
|
305
|
+
telemetry.finishStreamLifetime(completed ? 'success' : failed ? 'stream_error' : 'stream_cancelled');
|
|
306
|
+
telemetry.span.end();
|
|
128
307
|
}
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
stream: receive(),
|
|
311
|
+
close: () => controller.abort(new DOMException('Stream closed', 'AbortError')),
|
|
129
312
|
};
|
|
130
|
-
const stream = createStream();
|
|
131
|
-
return { stream };
|
|
132
313
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { APIError } from '../api-error';
|
|
2
|
+
export declare class StreamValidationError extends TypeError {
|
|
3
|
+
readonly schema: string;
|
|
4
|
+
readonly issues: ReadonlyArray<{
|
|
5
|
+
instancePath: string;
|
|
6
|
+
keyword: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
}>;
|
|
9
|
+
constructor(schema: string, issues: ReadonlyArray<{
|
|
10
|
+
instancePath: string;
|
|
11
|
+
keyword: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
}>);
|
|
14
|
+
}
|
|
15
|
+
/** An event of a kind this client does not know; the stream skips it. Never thrown to callers. */
|
|
16
|
+
export declare class UnknownEventKind extends Error {
|
|
17
|
+
readonly kind: string;
|
|
18
|
+
constructor(kind: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class IncompleteStream extends Error {
|
|
21
|
+
constructor();
|
|
22
|
+
}
|
|
23
|
+
/** A successful HTTP response that cannot be consumed as the requested stream. */
|
|
24
|
+
export declare class StreamParseError extends TypeError {
|
|
25
|
+
readonly code = "parse_error";
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class StreamHTTPError extends APIError {
|
|
29
|
+
readonly bodyTruncated: boolean;
|
|
30
|
+
readonly request: Request;
|
|
31
|
+
constructor(request: Request, response: Response, bodyTruncated?: boolean, payload?: unknown);
|
|
32
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamHTTPError = exports.StreamParseError = exports.IncompleteStream = exports.UnknownEventKind = exports.StreamValidationError = void 0;
|
|
4
|
+
const api_error_1 = require("../api-error");
|
|
5
|
+
// One definition for every generated surface, so callers catch the same classes.
|
|
6
|
+
class StreamValidationError extends TypeError {
|
|
7
|
+
schema;
|
|
8
|
+
issues;
|
|
9
|
+
constructor(schema, issues) {
|
|
10
|
+
super(`Event does not match ${schema}`);
|
|
11
|
+
this.schema = schema;
|
|
12
|
+
this.issues = issues;
|
|
13
|
+
this.name = 'StreamValidationError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.StreamValidationError = StreamValidationError;
|
|
17
|
+
/** An event of a kind this client does not know; the stream skips it. Never thrown to callers. */
|
|
18
|
+
class UnknownEventKind extends Error {
|
|
19
|
+
kind;
|
|
20
|
+
constructor(kind) {
|
|
21
|
+
super(`Skipped an event of unknown kind ${JSON.stringify(kind)}`);
|
|
22
|
+
this.kind = kind;
|
|
23
|
+
this.name = 'UnknownEventKind';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.UnknownEventKind = UnknownEventKind;
|
|
27
|
+
class IncompleteStream extends Error {
|
|
28
|
+
constructor() {
|
|
29
|
+
super('Stream ended before a terminal event');
|
|
30
|
+
this.name = 'IncompleteStream';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.IncompleteStream = IncompleteStream;
|
|
34
|
+
/** A successful HTTP response that cannot be consumed as the requested stream. */
|
|
35
|
+
class StreamParseError extends TypeError {
|
|
36
|
+
code = 'parse_error';
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'StreamParseError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.StreamParseError = StreamParseError;
|
|
43
|
+
class StreamHTTPError extends api_error_1.APIError {
|
|
44
|
+
bodyTruncated;
|
|
45
|
+
constructor(request, response, bodyTruncated = false, payload) {
|
|
46
|
+
super(payload, response, request, 'Stream request failed.');
|
|
47
|
+
this.bodyTruncated = bodyTruncated;
|
|
48
|
+
this.name = 'StreamHTTPError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.StreamHTTPError = StreamHTTPError;
|