@puku-ai/sdk 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -10
- package/dist/index.d.ts +26 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/vendor/_vendor/partial-json-parser/parser.d.ts +2 -0
- package/dist/vendor/_vendor/partial-json-parser/parser.js +223 -0
- package/dist/vendor/_vendor/partial-json-parser/parser.js.map +1 -0
- package/dist/vendor/api-promise.d.ts +2 -0
- package/dist/vendor/api-promise.js +3 -0
- package/dist/vendor/api-promise.js.map +1 -0
- package/dist/vendor/client.d.ts +399 -0
- package/dist/vendor/client.js +976 -0
- package/dist/vendor/client.js.map +1 -0
- package/dist/vendor/core/api-promise.d.ts +49 -0
- package/dist/vendor/core/api-promise.js +77 -0
- package/dist/vendor/core/api-promise.js.map +1 -0
- package/dist/vendor/core/api.d.ts +10 -0
- package/dist/vendor/core/api.js +2 -0
- package/dist/vendor/core/api.js.map +1 -0
- package/dist/vendor/core/credentials.d.ts +130 -0
- package/dist/vendor/core/credentials.js +274 -0
- package/dist/vendor/core/credentials.js.map +1 -0
- package/dist/vendor/core/error.d.ts +82 -0
- package/dist/vendor/core/error.js +140 -0
- package/dist/vendor/core/error.js.map +1 -0
- package/dist/vendor/core/middleware.d.ts +153 -0
- package/dist/vendor/core/middleware.js +168 -0
- package/dist/vendor/core/middleware.js.map +1 -0
- package/dist/vendor/core/pagination.d.ts +121 -0
- package/dist/vendor/core/pagination.js +207 -0
- package/dist/vendor/core/pagination.js.map +1 -0
- package/dist/vendor/core/resource.d.ts +5 -0
- package/dist/vendor/core/resource.js +8 -0
- package/dist/vendor/core/resource.js.map +1 -0
- package/dist/vendor/core/streaming.d.ts +41 -0
- package/dist/vendor/core/streaming.js +342 -0
- package/dist/vendor/core/streaming.js.map +1 -0
- package/dist/vendor/core/uploads.d.ts +2 -0
- package/dist/vendor/core/uploads.js +2 -0
- package/dist/vendor/core/uploads.js.map +1 -0
- package/dist/vendor/error.d.ts +2 -0
- package/dist/vendor/error.js +3 -0
- package/dist/vendor/error.js.map +1 -0
- package/dist/vendor/helpers/beta/environments.d.ts +22 -0
- package/dist/vendor/helpers/beta/environments.js +23 -0
- package/dist/vendor/helpers/beta/environments.js.map +1 -0
- package/dist/vendor/helpers/beta/json-schema.d.ts +36 -0
- package/dist/vendor/helpers/beta/json-schema.js +53 -0
- package/dist/vendor/helpers/beta/json-schema.js.map +1 -0
- package/dist/vendor/helpers/beta/mcp.d.ts +302 -0
- package/dist/vendor/helpers/beta/mcp.js +406 -0
- package/dist/vendor/helpers/beta/mcp.js.map +1 -0
- package/dist/vendor/helpers/beta/memory.d.ts +10 -0
- package/dist/vendor/helpers/beta/memory.js +15 -0
- package/dist/vendor/helpers/beta/memory.js.map +1 -0
- package/dist/vendor/helpers/beta/standard-schema.d.ts +44 -0
- package/dist/vendor/helpers/beta/standard-schema.js +54 -0
- package/dist/vendor/helpers/beta/standard-schema.js.map +1 -0
- package/dist/vendor/helpers/beta/zod.d.ts +32 -0
- package/dist/vendor/helpers/beta/zod.js +52 -0
- package/dist/vendor/helpers/beta/zod.js.map +1 -0
- package/dist/vendor/helpers/index.d.ts +2 -0
- package/dist/vendor/helpers/index.js +3 -0
- package/dist/vendor/helpers/index.js.map +1 -0
- package/dist/vendor/helpers/json-schema.d.ts +17 -0
- package/dist/vendor/helpers/json-schema.js +34 -0
- package/dist/vendor/helpers/json-schema.js.map +1 -0
- package/dist/vendor/helpers/zod.d.ts +12 -0
- package/dist/vendor/helpers/zod.js +42 -0
- package/dist/vendor/helpers/zod.js.map +1 -0
- package/dist/vendor/index.d.ts +16 -0
- package/dist/vendor/index.js +23 -0
- package/dist/vendor/index.js.map +1 -0
- package/dist/vendor/internal/builtin-types.d.ts +72 -0
- package/dist/vendor/internal/builtin-types.js +3 -0
- package/dist/vendor/internal/builtin-types.js.map +1 -0
- package/dist/vendor/internal/constants.d.ts +4 -0
- package/dist/vendor/internal/constants.js +10 -0
- package/dist/vendor/internal/constants.js.map +1 -0
- package/dist/vendor/internal/decoders/jsonl.d.ts +9 -0
- package/dist/vendor/internal/decoders/jsonl.js +37 -0
- package/dist/vendor/internal/decoders/jsonl.js.map +1 -0
- package/dist/vendor/internal/decoders/line.d.ts +16 -0
- package/dist/vendor/internal/decoders/line.js +105 -0
- package/dist/vendor/internal/decoders/line.js.map +1 -0
- package/dist/vendor/internal/detect-platform.d.ts +14 -0
- package/dist/vendor/internal/detect-platform.js +155 -0
- package/dist/vendor/internal/detect-platform.js.map +1 -0
- package/dist/vendor/internal/errors.d.ts +2 -0
- package/dist/vendor/internal/errors.js +38 -0
- package/dist/vendor/internal/errors.js.map +1 -0
- package/dist/vendor/internal/file-store.d.ts +135 -0
- package/dist/vendor/internal/file-store.js +529 -0
- package/dist/vendor/internal/file-store.js.map +1 -0
- package/dist/vendor/internal/headers.d.ts +28 -0
- package/dist/vendor/internal/headers.js +114 -0
- package/dist/vendor/internal/headers.js.map +1 -0
- package/dist/vendor/internal/message-stream-utils.d.ts +9 -0
- package/dist/vendor/internal/message-stream-utils.js +30 -0
- package/dist/vendor/internal/message-stream-utils.js.map +1 -0
- package/dist/vendor/internal/node.browser.d.ts +8 -0
- package/dist/vendor/internal/node.browser.js +19 -0
- package/dist/vendor/internal/node.browser.js.map +1 -0
- package/dist/vendor/internal/node.d.ts +13 -0
- package/dist/vendor/internal/node.js +14 -0
- package/dist/vendor/internal/node.js.map +1 -0
- package/dist/vendor/internal/parse.d.ts +17 -0
- package/dist/vendor/internal/parse.js +62 -0
- package/dist/vendor/internal/parse.js.map +1 -0
- package/dist/vendor/internal/qs/formats.d.ts +6 -0
- package/dist/vendor/internal/qs/formats.js +9 -0
- package/dist/vendor/internal/qs/formats.js.map +1 -0
- package/dist/vendor/internal/qs/index.d.ts +9 -0
- package/dist/vendor/internal/qs/index.js +10 -0
- package/dist/vendor/internal/qs/index.js.map +1 -0
- package/dist/vendor/internal/qs/stringify.d.ts +2 -0
- package/dist/vendor/internal/qs/stringify.js +274 -0
- package/dist/vendor/internal/qs/stringify.js.map +1 -0
- package/dist/vendor/internal/qs/types.d.ts +56 -0
- package/dist/vendor/internal/qs/types.js +2 -0
- package/dist/vendor/internal/qs/types.js.map +1 -0
- package/dist/vendor/internal/qs/utils.d.ts +14 -0
- package/dist/vendor/internal/qs/utils.js +217 -0
- package/dist/vendor/internal/qs/utils.js.map +1 -0
- package/dist/vendor/internal/request-options.d.ts +126 -0
- package/dist/vendor/internal/request-options.js +27 -0
- package/dist/vendor/internal/request-options.js.map +1 -0
- package/dist/vendor/internal/request-signal.d.ts +3 -0
- package/dist/vendor/internal/request-signal.js +45 -0
- package/dist/vendor/internal/request-signal.js.map +1 -0
- package/dist/vendor/internal/shim-types.d.ts +16 -0
- package/dist/vendor/internal/shim-types.js +3 -0
- package/dist/vendor/internal/shim-types.js.map +1 -0
- package/dist/vendor/internal/shims.d.ts +25 -0
- package/dist/vendor/internal/shims.js +85 -0
- package/dist/vendor/internal/shims.js.map +1 -0
- package/dist/vendor/internal/stainless-helper-header.d.ts +59 -0
- package/dist/vendor/internal/stainless-helper-header.js +83 -0
- package/dist/vendor/internal/stainless-helper-header.js.map +1 -0
- package/dist/vendor/internal/stream-utils.d.ts +7 -0
- package/dist/vendor/internal/stream-utils.js +35 -0
- package/dist/vendor/internal/stream-utils.js.map +1 -0
- package/dist/vendor/internal/to-file.d.ts +44 -0
- package/dist/vendor/internal/to-file.js +93 -0
- package/dist/vendor/internal/to-file.js.map +1 -0
- package/dist/vendor/internal/types.d.ts +62 -0
- package/dist/vendor/internal/types.js +3 -0
- package/dist/vendor/internal/types.js.map +1 -0
- package/dist/vendor/internal/uploads.d.ts +41 -0
- package/dist/vendor/internal/uploads.js +139 -0
- package/dist/vendor/internal/uploads.js.map +1 -0
- package/dist/vendor/internal/utils/abort.d.ts +11 -0
- package/dist/vendor/internal/utils/abort.js +22 -0
- package/dist/vendor/internal/utils/abort.js.map +1 -0
- package/dist/vendor/internal/utils/async-queue.d.ts +30 -0
- package/dist/vendor/internal/utils/async-queue.js +66 -0
- package/dist/vendor/internal/utils/async-queue.js.map +1 -0
- package/dist/vendor/internal/utils/backoff.d.ts +22 -0
- package/dist/vendor/internal/utils/backoff.js +36 -0
- package/dist/vendor/internal/utils/backoff.js.map +1 -0
- package/dist/vendor/internal/utils/base64.d.ts +2 -0
- package/dist/vendor/internal/utils/base64.js +33 -0
- package/dist/vendor/internal/utils/base64.js.map +1 -0
- package/dist/vendor/internal/utils/bytes.d.ts +3 -0
- package/dist/vendor/internal/utils/bytes.js +26 -0
- package/dist/vendor/internal/utils/bytes.js.map +1 -0
- package/dist/vendor/internal/utils/env.d.ts +8 -0
- package/dist/vendor/internal/utils/env.js +18 -0
- package/dist/vendor/internal/utils/env.js.map +1 -0
- package/dist/vendor/internal/utils/log.d.ts +46 -0
- package/dist/vendor/internal/utils/log.js +105 -0
- package/dist/vendor/internal/utils/log.js.map +1 -0
- package/dist/vendor/internal/utils/path.d.ts +14 -0
- package/dist/vendor/internal/utils/path.js +74 -0
- package/dist/vendor/internal/utils/path.js.map +1 -0
- package/dist/vendor/internal/utils/promise.d.ts +10 -0
- package/dist/vendor/internal/utils/promise.js +15 -0
- package/dist/vendor/internal/utils/promise.js.map +1 -0
- package/dist/vendor/internal/utils/query.d.ts +1 -0
- package/dist/vendor/internal/utils/query.js +6 -0
- package/dist/vendor/internal/utils/query.js.map +1 -0
- package/dist/vendor/internal/utils/sleep.d.ts +9 -0
- package/dist/vendor/internal/utils/sleep.js +24 -0
- package/dist/vendor/internal/utils/sleep.js.map +1 -0
- package/dist/vendor/internal/utils/time.d.ts +2 -0
- package/dist/vendor/internal/utils/time.js +5 -0
- package/dist/vendor/internal/utils/time.js.map +1 -0
- package/dist/vendor/internal/utils/uuid.d.ts +4 -0
- package/dist/vendor/internal/utils/uuid.js +15 -0
- package/dist/vendor/internal/utils/uuid.js.map +1 -0
- package/dist/vendor/internal/utils/values.d.ts +24 -0
- package/dist/vendor/internal/utils/values.js +106 -0
- package/dist/vendor/internal/utils/values.js.map +1 -0
- package/dist/vendor/internal/utils.d.ts +7 -0
- package/dist/vendor/internal/utils.js +9 -0
- package/dist/vendor/internal/utils.js.map +1 -0
- package/dist/vendor/lib/BetaMessageStream.d.ts +123 -0
- package/dist/vendor/lib/BetaMessageStream.js +662 -0
- package/dist/vendor/lib/BetaMessageStream.js.map +1 -0
- package/dist/vendor/lib/MessageStream.d.ts +122 -0
- package/dist/vendor/lib/MessageStream.js +609 -0
- package/dist/vendor/lib/MessageStream.js.map +1 -0
- package/dist/vendor/lib/beta-parser.d.ts +36 -0
- package/dist/vendor/lib/beta-parser.js +75 -0
- package/dist/vendor/lib/beta-parser.js.map +1 -0
- package/dist/vendor/lib/credentials/credential-chain.d.ts +38 -0
- package/dist/vendor/lib/credentials/credential-chain.js +208 -0
- package/dist/vendor/lib/credentials/credential-chain.js.map +1 -0
- package/dist/vendor/lib/credentials/identity-token.d.ts +10 -0
- package/dist/vendor/lib/credentials/identity-token.js +35 -0
- package/dist/vendor/lib/credentials/identity-token.js.map +1 -0
- package/dist/vendor/lib/credentials/oidc-federation.d.ts +39 -0
- package/dist/vendor/lib/credentials/oidc-federation.js +79 -0
- package/dist/vendor/lib/credentials/oidc-federation.js.map +1 -0
- package/dist/vendor/lib/credentials/token-cache.d.ts +53 -0
- package/dist/vendor/lib/credentials/token-cache.js +110 -0
- package/dist/vendor/lib/credentials/token-cache.js.map +1 -0
- package/dist/vendor/lib/credentials/types.d.ts +95 -0
- package/dist/vendor/lib/credentials/types.js +226 -0
- package/dist/vendor/lib/credentials/types.js.map +1 -0
- package/dist/vendor/lib/credentials/user-oauth.d.ts +20 -0
- package/dist/vendor/lib/credentials/user-oauth.js +94 -0
- package/dist/vendor/lib/credentials/user-oauth.js.map +1 -0
- package/dist/vendor/lib/credentials.d.ts +3 -0
- package/dist/vendor/lib/credentials.js +3 -0
- package/dist/vendor/lib/credentials.js.map +1 -0
- package/dist/vendor/lib/environments/index.d.ts +3 -0
- package/dist/vendor/lib/environments/index.js +4 -0
- package/dist/vendor/lib/environments/index.js.map +1 -0
- package/dist/vendor/lib/environments/poller.d.ts +94 -0
- package/dist/vendor/lib/environments/poller.js +218 -0
- package/dist/vendor/lib/environments/poller.js.map +1 -0
- package/dist/vendor/lib/environments/worker.d.ts +226 -0
- package/dist/vendor/lib/environments/worker.js +572 -0
- package/dist/vendor/lib/environments/worker.js.map +1 -0
- package/dist/vendor/lib/helper-client.d.ts +30 -0
- package/dist/vendor/lib/helper-client.js +55 -0
- package/dist/vendor/lib/helper-client.js.map +1 -0
- package/dist/vendor/lib/middleware.d.ts +97 -0
- package/dist/vendor/lib/middleware.js +775 -0
- package/dist/vendor/lib/middleware.js.map +1 -0
- package/dist/vendor/lib/parser.d.ts +31 -0
- package/dist/vendor/lib/parser.js +62 -0
- package/dist/vendor/lib/parser.js.map +1 -0
- package/dist/vendor/lib/sessions/accumulate.d.ts +22 -0
- package/dist/vendor/lib/sessions/accumulate.js +42 -0
- package/dist/vendor/lib/sessions/accumulate.js.map +1 -0
- package/dist/vendor/lib/standard-schema.d.ts +130 -0
- package/dist/vendor/lib/standard-schema.js +41 -0
- package/dist/vendor/lib/standard-schema.js.map +1 -0
- package/dist/vendor/lib/tools/BetaRunnableTool.d.ts +48 -0
- package/dist/vendor/lib/tools/BetaRunnableTool.js +26 -0
- package/dist/vendor/lib/tools/BetaRunnableTool.js.map +1 -0
- package/dist/vendor/lib/tools/BetaToolRunner.d.ts +160 -0
- package/dist/vendor/lib/tools/BetaToolRunner.js +497 -0
- package/dist/vendor/lib/tools/BetaToolRunner.js.map +1 -0
- package/dist/vendor/lib/tools/CompactionControl.d.ts +29 -0
- package/dist/vendor/lib/tools/CompactionControl.js +25 -0
- package/dist/vendor/lib/tools/CompactionControl.js.map +1 -0
- package/dist/vendor/lib/tools/SessionToolRunner.d.ts +178 -0
- package/dist/vendor/lib/tools/SessionToolRunner.js +737 -0
- package/dist/vendor/lib/tools/SessionToolRunner.js.map +1 -0
- package/dist/vendor/lib/tools/ToolError.d.ts +32 -0
- package/dist/vendor/lib/tools/ToolError.js +43 -0
- package/dist/vendor/lib/tools/ToolError.js.map +1 -0
- package/dist/vendor/lib/transform-json-schema.d.ts +2 -0
- package/dist/vendor/lib/transform-json-schema.js +111 -0
- package/dist/vendor/lib/transform-json-schema.js.map +1 -0
- package/dist/vendor/pagination.d.ts +2 -0
- package/dist/vendor/pagination.js +3 -0
- package/dist/vendor/pagination.js.map +1 -0
- package/dist/vendor/resource.d.ts +2 -0
- package/dist/vendor/resource.js +3 -0
- package/dist/vendor/resource.js.map +1 -0
- package/dist/vendor/resources/beta/agents/agents.d.ts +1128 -0
- package/dist/vendor/resources/beta/agents/agents.js +123 -0
- package/dist/vendor/resources/beta/agents/agents.js.map +1 -0
- package/dist/vendor/resources/beta/agents/index.d.ts +2 -0
- package/dist/vendor/resources/beta/agents/index.js +4 -0
- package/dist/vendor/resources/beta/agents/index.js.map +1 -0
- package/dist/vendor/resources/beta/agents/versions.d.ts +32 -0
- package/dist/vendor/resources/beta/agents/versions.js +32 -0
- package/dist/vendor/resources/beta/agents/versions.js.map +1 -0
- package/dist/vendor/resources/beta/agents.d.ts +1 -0
- package/dist/vendor/resources/beta/agents.js +3 -0
- package/dist/vendor/resources/beta/agents.js.map +1 -0
- package/dist/vendor/resources/beta/beta.d.ts +131 -0
- package/dist/vendor/resources/beta/beta.js +69 -0
- package/dist/vendor/resources/beta/beta.js.map +1 -0
- package/dist/vendor/resources/beta/deployment-runs.d.ts +305 -0
- package/dist/vendor/resources/beta/deployment-runs.js +51 -0
- package/dist/vendor/resources/beta/deployment-runs.js.map +1 -0
- package/dist/vendor/resources/beta/deployments.d.ts +698 -0
- package/dist/vendor/resources/beta/deployments.js +192 -0
- package/dist/vendor/resources/beta/deployments.js.map +1 -0
- package/dist/vendor/resources/beta/dreams.d.ts +335 -0
- package/dist/vendor/resources/beta/dreams.js +112 -0
- package/dist/vendor/resources/beta/dreams.js.map +1 -0
- package/dist/vendor/resources/beta/environments/environments.d.ts +432 -0
- package/dist/vendor/resources/beta/environments/environments.js +142 -0
- package/dist/vendor/resources/beta/environments/environments.js.map +1 -0
- package/dist/vendor/resources/beta/environments/index.d.ts +2 -0
- package/dist/vendor/resources/beta/environments/index.js +4 -0
- package/dist/vendor/resources/beta/environments/index.js.map +1 -0
- package/dist/vendor/resources/beta/environments/work.d.ts +500 -0
- package/dist/vendor/resources/beta/environments/work.js +251 -0
- package/dist/vendor/resources/beta/environments/work.js.map +1 -0
- package/dist/vendor/resources/beta/environments.d.ts +1 -0
- package/dist/vendor/resources/beta/environments.js +3 -0
- package/dist/vendor/resources/beta/environments.js.map +1 -0
- package/dist/vendor/resources/beta/files.d.ts +190 -0
- package/dist/vendor/resources/beta/files.js +120 -0
- package/dist/vendor/resources/beta/files.js.map +1 -0
- package/dist/vendor/resources/beta/index.d.ts +17 -0
- package/dist/vendor/resources/beta/index.js +19 -0
- package/dist/vendor/resources/beta/index.js.map +1 -0
- package/dist/vendor/resources/beta/memory-stores/index.d.ts +3 -0
- package/dist/vendor/resources/beta/memory-stores/index.js +5 -0
- package/dist/vendor/resources/beta/memory-stores/index.js.map +1 -0
- package/dist/vendor/resources/beta/memory-stores/memories.d.ts +346 -0
- package/dist/vendor/resources/beta/memory-stores/memories.js +126 -0
- package/dist/vendor/resources/beta/memory-stores/memories.js.map +1 -0
- package/dist/vendor/resources/beta/memory-stores/memory-stores.d.ts +230 -0
- package/dist/vendor/resources/beta/memory-stores/memory-stores.js +137 -0
- package/dist/vendor/resources/beta/memory-stores/memory-stores.js.map +1 -0
- package/dist/vendor/resources/beta/memory-stores/memory-versions.d.ts +252 -0
- package/dist/vendor/resources/beta/memory-stores/memory-versions.js +77 -0
- package/dist/vendor/resources/beta/memory-stores/memory-versions.js.map +1 -0
- package/dist/vendor/resources/beta/memory-stores.d.ts +1 -0
- package/dist/vendor/resources/beta/memory-stores.js +3 -0
- package/dist/vendor/resources/beta/memory-stores.js.map +1 -0
- package/dist/vendor/resources/beta/messages/batches.d.ts +685 -0
- package/dist/vendor/resources/beta/messages/batches.js +203 -0
- package/dist/vendor/resources/beta/messages/batches.js.map +1 -0
- package/dist/vendor/resources/beta/messages/index.d.ts +3 -0
- package/dist/vendor/resources/beta/messages/index.js +5 -0
- package/dist/vendor/resources/beta/messages/index.js.map +1 -0
- package/dist/vendor/resources/beta/messages/messages.d.ts +5376 -0
- package/dist/vendor/resources/beta/messages/messages.js +158 -0
- package/dist/vendor/resources/beta/messages/messages.js.map +1 -0
- package/dist/vendor/resources/beta/messages.d.ts +1 -0
- package/dist/vendor/resources/beta/messages.js +3 -0
- package/dist/vendor/resources/beta/messages.js.map +1 -0
- package/dist/vendor/resources/beta/models.d.ts +217 -0
- package/dist/vendor/resources/beta/models.js +56 -0
- package/dist/vendor/resources/beta/models.js.map +1 -0
- package/dist/vendor/resources/beta/organization/api-keys.d.ts +176 -0
- package/dist/vendor/resources/beta/organization/api-keys.js +52 -0
- package/dist/vendor/resources/beta/organization/api-keys.js.map +1 -0
- package/dist/vendor/resources/beta/organization/compliance-settings.d.ts +73 -0
- package/dist/vendor/resources/beta/organization/compliance-settings.js +48 -0
- package/dist/vendor/resources/beta/organization/compliance-settings.js.map +1 -0
- package/dist/vendor/resources/beta/organization/external-keys.d.ts +271 -0
- package/dist/vendor/resources/beta/organization/external-keys.js +115 -0
- package/dist/vendor/resources/beta/organization/external-keys.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/federation.d.ts +13 -0
- package/dist/vendor/resources/beta/organization/federation/federation.js +13 -0
- package/dist/vendor/resources/beta/organization/federation/federation.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/index.d.ts +3 -0
- package/dist/vendor/resources/beta/organization/federation/index.js +5 -0
- package/dist/vendor/resources/beta/organization/federation/index.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/issuers.d.ts +352 -0
- package/dist/vendor/resources/beta/organization/federation/issuers.js +165 -0
- package/dist/vendor/resources/beta/organization/federation/issuers.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/rules/index.d.ts +2 -0
- package/dist/vendor/resources/beta/organization/federation/rules/index.js +4 -0
- package/dist/vendor/resources/beta/organization/federation/rules/index.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/rules/rules.d.ts +467 -0
- package/dist/vendor/resources/beta/organization/federation/rules/rules.js +190 -0
- package/dist/vendor/resources/beta/organization/federation/rules/rules.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/rules/workspaces.d.ts +123 -0
- package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js +110 -0
- package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation/rules.d.ts +1 -0
- package/dist/vendor/resources/beta/organization/federation/rules.js +3 -0
- package/dist/vendor/resources/beta/organization/federation/rules.js.map +1 -0
- package/dist/vendor/resources/beta/organization/federation.d.ts +1 -0
- package/dist/vendor/resources/beta/organization/federation.js +3 -0
- package/dist/vendor/resources/beta/organization/federation.js.map +1 -0
- package/dist/vendor/resources/beta/organization/index.d.ts +10 -0
- package/dist/vendor/resources/beta/organization/index.js +12 -0
- package/dist/vendor/resources/beta/organization/index.js.map +1 -0
- package/dist/vendor/resources/beta/organization/invites.d.ts +161 -0
- package/dist/vendor/resources/beta/organization/invites.js +72 -0
- package/dist/vendor/resources/beta/organization/invites.js.map +1 -0
- package/dist/vendor/resources/beta/organization/organization.d.ts +72 -0
- package/dist/vendor/resources/beta/organization/organization.js +54 -0
- package/dist/vendor/resources/beta/organization/organization.js.map +1 -0
- package/dist/vendor/resources/beta/organization/rate-limits.d.ts +76 -0
- package/dist/vendor/resources/beta/organization/rate-limits.js +27 -0
- package/dist/vendor/resources/beta/organization/rate-limits.js.map +1 -0
- package/dist/vendor/resources/beta/organization/service-accounts/index.d.ts +2 -0
- package/dist/vendor/resources/beta/organization/service-accounts/index.js +4 -0
- package/dist/vendor/resources/beta/organization/service-accounts/index.js.map +1 -0
- package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.d.ts +257 -0
- package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js +166 -0
- package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js.map +1 -0
- package/dist/vendor/resources/beta/organization/service-accounts/workspaces.d.ts +140 -0
- package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js +121 -0
- package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js.map +1 -0
- package/dist/vendor/resources/beta/organization/service-accounts.d.ts +1 -0
- package/dist/vendor/resources/beta/organization/service-accounts.js +3 -0
- package/dist/vendor/resources/beta/organization/service-accounts.js.map +1 -0
- package/dist/vendor/resources/beta/organization/users.d.ts +123 -0
- package/dist/vendor/resources/beta/organization/users.js +63 -0
- package/dist/vendor/resources/beta/organization/users.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces/index.d.ts +4 -0
- package/dist/vendor/resources/beta/organization/workspaces/index.js +6 -0
- package/dist/vendor/resources/beta/organization/workspaces/index.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces/members.d.ts +134 -0
- package/dist/vendor/resources/beta/organization/workspaces/members.js +98 -0
- package/dist/vendor/resources/beta/organization/workspaces/members.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces/rate-limits.d.ts +82 -0
- package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js +30 -0
- package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces/service-accounts.d.ts +209 -0
- package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js +185 -0
- package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces/workspaces.d.ts +302 -0
- package/dist/vendor/resources/beta/organization/workspaces/workspaces.js +104 -0
- package/dist/vendor/resources/beta/organization/workspaces/workspaces.js.map +1 -0
- package/dist/vendor/resources/beta/organization/workspaces.d.ts +1 -0
- package/dist/vendor/resources/beta/organization/workspaces.js +3 -0
- package/dist/vendor/resources/beta/organization/workspaces.js.map +1 -0
- package/dist/vendor/resources/beta/organization.d.ts +1 -0
- package/dist/vendor/resources/beta/organization.js +3 -0
- package/dist/vendor/resources/beta/organization.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/events.d.ts +1513 -0
- package/dist/vendor/resources/beta/sessions/events.js +115 -0
- package/dist/vendor/resources/beta/sessions/events.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/index.d.ts +4 -0
- package/dist/vendor/resources/beta/sessions/index.js +6 -0
- package/dist/vendor/resources/beta/sessions/index.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/resources.d.ts +227 -0
- package/dist/vendor/resources/beta/sessions/resources.js +128 -0
- package/dist/vendor/resources/beta/sessions/resources.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/sessions.d.ts +866 -0
- package/dist/vendor/resources/beta/sessions/sessions.js +150 -0
- package/dist/vendor/resources/beta/sessions/sessions.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/threads/events.d.ts +77 -0
- package/dist/vendor/resources/beta/sessions/threads/events.js +57 -0
- package/dist/vendor/resources/beta/sessions/threads/events.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/threads/index.d.ts +2 -0
- package/dist/vendor/resources/beta/sessions/threads/index.js +4 -0
- package/dist/vendor/resources/beta/sessions/threads/index.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/threads/threads.d.ts +195 -0
- package/dist/vendor/resources/beta/sessions/threads/threads.js +80 -0
- package/dist/vendor/resources/beta/sessions/threads/threads.js.map +1 -0
- package/dist/vendor/resources/beta/sessions/threads.d.ts +1 -0
- package/dist/vendor/resources/beta/sessions/threads.js +3 -0
- package/dist/vendor/resources/beta/sessions/threads.js.map +1 -0
- package/dist/vendor/resources/beta/sessions.d.ts +1 -0
- package/dist/vendor/resources/beta/sessions.js +3 -0
- package/dist/vendor/resources/beta/sessions.js.map +1 -0
- package/dist/vendor/resources/beta/skills/index.d.ts +2 -0
- package/dist/vendor/resources/beta/skills/index.js +4 -0
- package/dist/vendor/resources/beta/skills/index.js.map +1 -0
- package/dist/vendor/resources/beta/skills/skills.d.ts +178 -0
- package/dist/vendor/resources/beta/skills/skills.js +96 -0
- package/dist/vendor/resources/beta/skills/skills.js.map +1 -0
- package/dist/vendor/resources/beta/skills/versions.d.ts +181 -0
- package/dist/vendor/resources/beta/skills/versions.js +125 -0
- package/dist/vendor/resources/beta/skills/versions.js.map +1 -0
- package/dist/vendor/resources/beta/skills.d.ts +1 -0
- package/dist/vendor/resources/beta/skills.js +3 -0
- package/dist/vendor/resources/beta/skills.js.map +1 -0
- package/dist/vendor/resources/beta/tunnels/certificates.d.ts +162 -0
- package/dist/vendor/resources/beta/tunnels/certificates.js +125 -0
- package/dist/vendor/resources/beta/tunnels/certificates.js.map +1 -0
- package/dist/vendor/resources/beta/tunnels/index.d.ts +2 -0
- package/dist/vendor/resources/beta/tunnels/index.js +4 -0
- package/dist/vendor/resources/beta/tunnels/index.js.map +1 -0
- package/dist/vendor/resources/beta/tunnels/tunnels.d.ts +211 -0
- package/dist/vendor/resources/beta/tunnels/tunnels.js +173 -0
- package/dist/vendor/resources/beta/tunnels/tunnels.js.map +1 -0
- package/dist/vendor/resources/beta/tunnels.d.ts +1 -0
- package/dist/vendor/resources/beta/tunnels.js +3 -0
- package/dist/vendor/resources/beta/tunnels.js.map +1 -0
- package/dist/vendor/resources/beta/user-profiles.d.ts +244 -0
- package/dist/vendor/resources/beta/user-profiles.js +114 -0
- package/dist/vendor/resources/beta/user-profiles.js.map +1 -0
- package/dist/vendor/resources/beta/vaults/credentials.d.ts +715 -0
- package/dist/vendor/resources/beta/vaults/credentials.js +173 -0
- package/dist/vendor/resources/beta/vaults/credentials.js.map +1 -0
- package/dist/vendor/resources/beta/vaults/index.d.ts +2 -0
- package/dist/vendor/resources/beta/vaults/index.js +4 -0
- package/dist/vendor/resources/beta/vaults/index.js.map +1 -0
- package/dist/vendor/resources/beta/vaults/vaults.d.ts +191 -0
- package/dist/vendor/resources/beta/vaults/vaults.js +141 -0
- package/dist/vendor/resources/beta/vaults/vaults.js.map +1 -0
- package/dist/vendor/resources/beta/vaults.d.ts +1 -0
- package/dist/vendor/resources/beta/vaults.js +3 -0
- package/dist/vendor/resources/beta/vaults.js.map +1 -0
- package/dist/vendor/resources/beta/webhooks.d.ts +464 -0
- package/dist/vendor/resources/beta/webhooks.js +29 -0
- package/dist/vendor/resources/beta/webhooks.js.map +1 -0
- package/dist/vendor/resources/beta.d.ts +1 -0
- package/dist/vendor/resources/beta.js +3 -0
- package/dist/vendor/resources/beta.js.map +1 -0
- package/dist/vendor/resources/completions.d.ts +172 -0
- package/dist/vendor/resources/completions.js +19 -0
- package/dist/vendor/resources/completions.js.map +1 -0
- package/dist/vendor/resources/files.d.ts +104 -0
- package/dist/vendor/resources/files.js +48 -0
- package/dist/vendor/resources/files.js.map +1 -0
- package/dist/vendor/resources/index.d.ts +7 -0
- package/dist/vendor/resources/index.js +9 -0
- package/dist/vendor/resources/index.js.map +1 -0
- package/dist/vendor/resources/messages/batches.d.ts +312 -0
- package/dist/vendor/resources/messages/batches.js +157 -0
- package/dist/vendor/resources/messages/batches.js.map +1 -0
- package/dist/vendor/resources/messages/index.d.ts +2 -0
- package/dist/vendor/resources/messages/index.js +4 -0
- package/dist/vendor/resources/messages/index.js.map +1 -0
- package/dist/vendor/resources/messages/messages.d.ts +3886 -0
- package/dist/vendor/resources/messages/messages.js +130 -0
- package/dist/vendor/resources/messages/messages.js.map +1 -0
- package/dist/vendor/resources/messages.d.ts +1 -0
- package/dist/vendor/resources/messages.js +3 -0
- package/dist/vendor/resources/messages.js.map +1 -0
- package/dist/vendor/resources/models.d.ts +196 -0
- package/dist/vendor/resources/models.js +41 -0
- package/dist/vendor/resources/models.js.map +1 -0
- package/dist/vendor/resources/shared.d.ts +43 -0
- package/dist/vendor/resources/shared.js +3 -0
- package/dist/vendor/resources/shared.js.map +1 -0
- package/dist/vendor/resources/skills/index.d.ts +2 -0
- package/dist/vendor/resources/skills/index.js +4 -0
- package/dist/vendor/resources/skills/index.js.map +1 -0
- package/dist/vendor/resources/skills/skills.d.ts +128 -0
- package/dist/vendor/resources/skills/skills.js +36 -0
- package/dist/vendor/resources/skills/skills.js.map +1 -0
- package/dist/vendor/resources/skills/versions.d.ts +103 -0
- package/dist/vendor/resources/skills/versions.js +37 -0
- package/dist/vendor/resources/skills/versions.js.map +1 -0
- package/dist/vendor/resources/skills.d.ts +1 -0
- package/dist/vendor/resources/skills.js +3 -0
- package/dist/vendor/resources/skills.js.map +1 -0
- package/dist/vendor/resources/top-level.d.ts +1 -0
- package/dist/vendor/resources/top-level.js +3 -0
- package/dist/vendor/resources/top-level.js.map +1 -0
- package/dist/vendor/resources.d.ts +1 -0
- package/dist/vendor/resources.js +2 -0
- package/dist/vendor/resources.js.map +1 -0
- package/dist/vendor/streaming.d.ts +2 -0
- package/dist/vendor/streaming.js +3 -0
- package/dist/vendor/streaming.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/fs-util.d.ts +74 -0
- package/dist/vendor/tools/agent-toolset/fs-util.js +184 -0
- package/dist/vendor/tools/agent-toolset/fs-util.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/memories.d.ts +172 -0
- package/dist/vendor/tools/agent-toolset/memories.js +910 -0
- package/dist/vendor/tools/agent-toolset/memories.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/node.browser.d.ts +80 -0
- package/dist/vendor/tools/agent-toolset/node.browser.js +129 -0
- package/dist/vendor/tools/agent-toolset/node.browser.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/node.d.ts +191 -0
- package/dist/vendor/tools/agent-toolset/node.js +886 -0
- package/dist/vendor/tools/agent-toolset/node.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/skills.d.ts +73 -0
- package/dist/vendor/tools/agent-toolset/skills.js +320 -0
- package/dist/vendor/tools/agent-toolset/skills.js.map +1 -0
- package/dist/vendor/tools/agent-toolset/sync-interval.d.ts +18 -0
- package/dist/vendor/tools/agent-toolset/sync-interval.js +25 -0
- package/dist/vendor/tools/agent-toolset/sync-interval.js.map +1 -0
- package/dist/vendor/tools/memory/node.browser.d.ts +26 -0
- package/dist/vendor/tools/memory/node.browser.js +44 -0
- package/dist/vendor/tools/memory/node.browser.js.map +1 -0
- package/dist/vendor/tools/memory/node.d.ts +17 -0
- package/dist/vendor/tools/memory/node.js +327 -0
- package/dist/vendor/tools/memory/node.js.map +1 -0
- package/dist/vendor/uploads.d.ts +2 -0
- package/dist/vendor/uploads.js +3 -0
- package/dist/vendor/uploads.js.map +1 -0
- package/dist/vendor/version.d.ts +1 -0
- package/dist/vendor/version.js +2 -0
- package/dist/vendor/version.js.map +1 -0
- package/package.json +7 -14
- package/sdk.cjs +6 -6
- package/sdk.cjs.map +18 -18
- package/sdk.d.ts +10 -10
- package/sdk.mjs +21 -21
- package/sdk.mjs.map +18 -18
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import { PukuError, APIError } from '../../core/error.js';
|
|
2
|
+
import { loggerFor } from '../../internal/utils/log.js';
|
|
3
|
+
import { fromBase64 } from '../../internal/utils/base64.js';
|
|
4
|
+
import { decodeUTF8 } from '../../internal/utils/bytes.js';
|
|
5
|
+
import { readEnv } from '../../internal/utils/env.js';
|
|
6
|
+
import { sleep } from '../../internal/utils/sleep.js';
|
|
7
|
+
import { isFatal4xx, isStatus } from '../../internal/utils/backoff.js';
|
|
8
|
+
import { linkAbort } from '../../internal/utils/abort.js';
|
|
9
|
+
import { isObj } from '../../internal/utils/values.js';
|
|
10
|
+
import { buildHeaders } from '../../internal/headers.js';
|
|
11
|
+
import { SessionToolRunner } from '../tools/SessionToolRunner.js';
|
|
12
|
+
import { WorkPoller } from './poller.js';
|
|
13
|
+
import { copyClientForHelper } from '../helper-client.js';
|
|
14
|
+
import { checkMemorySyncInterval } from '../../tools/agent-toolset/sync-interval.js';
|
|
15
|
+
const HEARTBEAT_DEFAULT_MS = 30_000;
|
|
16
|
+
const HEARTBEAT_TTL_DEFAULT_MS = 90_000;
|
|
17
|
+
const NO_HEARTBEAT_SENTINEL = 'NO_HEARTBEAT';
|
|
18
|
+
/** True when the session has at least one memory store attached. */
|
|
19
|
+
function hasMemoryStore(session) {
|
|
20
|
+
return session.resources.some((r) => r.type === 'memory_store');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extract the per-item sessions token from a work item's `secret` payload.
|
|
24
|
+
*
|
|
25
|
+
* The `secret` the poll response populates is not itself a credential: it is a
|
|
26
|
+
* URL-safe base64 JSON payload matching {@link BetaWorkSecret} — the
|
|
27
|
+
* `sessions_token` (the bearer for this item's work lifecycle and
|
|
28
|
+
* session-level calls) plus fields this worker does not consume. Returns the
|
|
29
|
+
* sessions token, or `null` (meaning: fall back to the environment key) when
|
|
30
|
+
* the payload is missing, doesn't decode, or carries no token. Never log the
|
|
31
|
+
* payload or anything extracted from it.
|
|
32
|
+
*/
|
|
33
|
+
export function sessionsTokenFromSecret(secret) {
|
|
34
|
+
if (!secret)
|
|
35
|
+
return null;
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
// The payload may arrive URL-safe and without base64 padding; normalize
|
|
39
|
+
// both before decoding.
|
|
40
|
+
const normalized = secret.replace(/-/g, '+').replace(/_/g, '/');
|
|
41
|
+
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, '=');
|
|
42
|
+
parsed = JSON.parse(decodeUTF8(fromBase64(padded)));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
48
|
+
return null;
|
|
49
|
+
// The payload is untrusted input, so the token is still checked at runtime
|
|
50
|
+
// rather than trusted to match the schema.
|
|
51
|
+
const token = parsed.sessions_token;
|
|
52
|
+
return typeof token === 'string' && token !== '' ? token : null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The self-hosted environment runner, composed from the control-plane
|
|
56
|
+
* {@link WorkPoller} and the per-session {@link SessionToolRunner}.
|
|
57
|
+
*
|
|
58
|
+
* For each claimed `session` work item it: builds the per-session
|
|
59
|
+
* {@link AgentToolContext}, downloads the session agent's skills
|
|
60
|
+
* (`setupSkills`), then runs a {@link SessionToolRunner} for the session
|
|
61
|
+
* while heartbeating the work-item lease on the same event loop; on exit it
|
|
62
|
+
* force-stops the work item (unless the lease was lost, in which case the item
|
|
63
|
+
* is left to whoever holds it now), cleans up the downloaded skills, and loops
|
|
64
|
+
* to the next one. The lease heartbeat reports `state === "stopping"` / a lost
|
|
65
|
+
* lease back into the run by aborting the session runner.
|
|
66
|
+
*
|
|
67
|
+
* The `environmentKey` is the worker's standing credential. When a claimed
|
|
68
|
+
* work item carries a per-item `secret` (a short-lived payload the poll
|
|
69
|
+
* response may populate), the sessions token extracted from it is preferred
|
|
70
|
+
* over the environment key for that item's heartbeat / force-stop /
|
|
71
|
+
* skill-download / session calls; polling itself always uses the environment
|
|
72
|
+
* key, and items without a usable secret fall back to it entirely.
|
|
73
|
+
*
|
|
74
|
+
* Use {@link EnvironmentWorker.handleItem} if you already hold a claimed work
|
|
75
|
+
* item (e.g. a `worker poll --on-work` script handed one to a fresh process) and
|
|
76
|
+
* just want the per-item flow without the poll loop — with no arguments it reads
|
|
77
|
+
* the `PUKU_*` env vars that command sets.
|
|
78
|
+
*
|
|
79
|
+
* Construct it via `client.beta.environments.work.worker({ ... })` (or
|
|
80
|
+
* `new EnvironmentWorker({ client, ... })` directly).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* // Long-running daemon: poll for work, serve each session, loop.
|
|
85
|
+
* await client.beta.environments.work
|
|
86
|
+
* .worker({ environmentId, environmentKey, workdir: '/workspace' })
|
|
87
|
+
* .run(AbortSignal.timeout(60 * 60_000));
|
|
88
|
+
*
|
|
89
|
+
* // Already-claimed item (e.g. inside `ant worker poll --on-work ...`):
|
|
90
|
+
* await client.beta.environments.work.worker({ workdir: '/workspace' }).handleItem();
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export class EnvironmentWorker {
|
|
94
|
+
client;
|
|
95
|
+
environmentId;
|
|
96
|
+
environmentKey;
|
|
97
|
+
tools;
|
|
98
|
+
workdir;
|
|
99
|
+
/** @deprecated Never set; see {@link EnvironmentWorkerOptions.unrestrictedPaths}. */
|
|
100
|
+
unrestrictedPaths;
|
|
101
|
+
maxFileBytes;
|
|
102
|
+
maxIdleMs;
|
|
103
|
+
memorySyncIntervalMs;
|
|
104
|
+
memorySyncDeletions;
|
|
105
|
+
workerId;
|
|
106
|
+
requestOptions;
|
|
107
|
+
#signal;
|
|
108
|
+
constructor(opts) {
|
|
109
|
+
if (opts.unrestrictedPaths !== undefined) {
|
|
110
|
+
throw new PukuError('The `unrestrictedPaths` option you passed to EnvironmentWorker (or ' +
|
|
111
|
+
'client.beta.environments.work.worker()) is no longer supported. ' +
|
|
112
|
+
"The worker's file tools (read, write, edit, glob, grep) are now always confined to `workdir` " +
|
|
113
|
+
"plus the session's memory folders. Remove `unrestrictedPaths` from your options; to let the " +
|
|
114
|
+
'file tools reach any other directory, add it to `AgentToolContext.allowedRoots` from a ' +
|
|
115
|
+
'`tools` factory.');
|
|
116
|
+
}
|
|
117
|
+
this.client = opts.client;
|
|
118
|
+
this.environmentId = opts.environmentId;
|
|
119
|
+
this.environmentKey = opts.environmentKey;
|
|
120
|
+
this.tools = opts.tools;
|
|
121
|
+
this.workdir = opts.workdir ?? process.cwd();
|
|
122
|
+
this.maxFileBytes = opts.maxFileBytes;
|
|
123
|
+
this.maxIdleMs = opts.maxIdleMs;
|
|
124
|
+
if (opts.memorySyncIntervalMs != null) {
|
|
125
|
+
checkMemorySyncInterval(opts.memorySyncIntervalMs, 'memorySyncIntervalMs');
|
|
126
|
+
}
|
|
127
|
+
this.memorySyncIntervalMs = opts.memorySyncIntervalMs;
|
|
128
|
+
this.memorySyncDeletions = opts.memorySyncDeletions ?? 'enabled';
|
|
129
|
+
this.workerId = opts.workerId;
|
|
130
|
+
this.requestOptions = opts.requestOptions;
|
|
131
|
+
this.#signal = opts.signal;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Poll the environment and service each claimed session until the supplied
|
|
135
|
+
* signal (or the one passed to the constructor) aborts. Throws if
|
|
136
|
+
* `environmentId` / `environmentKey` were not provided to the constructor.
|
|
137
|
+
*/
|
|
138
|
+
async run(signal) {
|
|
139
|
+
const { environmentId, environmentKey } = this;
|
|
140
|
+
if (environmentId === undefined || environmentKey === undefined) {
|
|
141
|
+
throw new PukuError('EnvironmentWorker.run: environmentId and environmentKey are required to poll for work');
|
|
142
|
+
}
|
|
143
|
+
const externalSignal = signal ?? this.#signal;
|
|
144
|
+
const poller = new WorkPoller({
|
|
145
|
+
client: this.client,
|
|
146
|
+
environmentId,
|
|
147
|
+
environmentKey,
|
|
148
|
+
...(this.workerId !== undefined ? { workerId: this.workerId } : {}),
|
|
149
|
+
...(externalSignal ? { signal: externalSignal } : {}),
|
|
150
|
+
...(this.requestOptions !== undefined ? { requestOptions: this.requestOptions } : {}),
|
|
151
|
+
// The per-item handler stops or releases every work item on exit; let it
|
|
152
|
+
// be the single owner of `work.stop` rather than double-posting from the
|
|
153
|
+
// poller.
|
|
154
|
+
autoStop: false,
|
|
155
|
+
});
|
|
156
|
+
for await (const work of poller) {
|
|
157
|
+
try {
|
|
158
|
+
await this.#handleItem(work, environmentKey, poller.signal);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
// One bad item fails that item, not the worker: the handler's teardown
|
|
162
|
+
// already stopped or released it, so the next poll claims the next
|
|
163
|
+
// item. A store directory left behind by a killed worker would
|
|
164
|
+
// otherwise crashloop this process forever.
|
|
165
|
+
if (poller.signal?.aborted)
|
|
166
|
+
throw e;
|
|
167
|
+
loggerFor(this.client).error('work item failed', { work_id: work.id, error: String(e) });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Service a single, already-claimed work item without the poll loop: build the
|
|
173
|
+
* per-session {@link AgentToolContext} (workdir from this worker's options),
|
|
174
|
+
* download the session agent's skills (`setupSkills`), run a
|
|
175
|
+
* {@link SessionToolRunner} for the session while heartbeating the work-item
|
|
176
|
+
* lease, and force-stop the work item on exit (whether the runner finishes
|
|
177
|
+
* normally, throws, or the control plane signals shutdown). The one
|
|
178
|
+
* exception is a lost lease: the item then belongs to the queue or another
|
|
179
|
+
* worker and is left alone.
|
|
180
|
+
*
|
|
181
|
+
* Use this when something else does the claiming — e.g. a `worker poll
|
|
182
|
+
* --on-work` script that hands an already-claimed item to a fresh process. The
|
|
183
|
+
* work id / environment id / session id each fall back to `PUKU_WORK_ID` /
|
|
184
|
+
* `PUKU_ENVIRONMENT_ID` / `PUKU_SESSION_ID` (the env vars that
|
|
185
|
+
* command sets) when not passed; the environment key resolves from this
|
|
186
|
+
* option, then the worker's own `environmentKey`, then
|
|
187
|
+
* `PUKU_ENVIRONMENT_KEY`. With no arguments inside that command it just
|
|
188
|
+
* works. Throws a clear error naming the first of the four required values
|
|
189
|
+
* still missing after resolution. Throws `SessionMemoryError` when the
|
|
190
|
+
* session has memory stores attached but they cannot be mounted — the work
|
|
191
|
+
* item carried no sessions token (unless `memorySyncIntervalMs` turned
|
|
192
|
+
* memory off), or a store failed to download.
|
|
193
|
+
*
|
|
194
|
+
* `workSecret` is the work item's per-item `secret` payload from the poll
|
|
195
|
+
* response, falling back to `PUKU_WORK_SECRET`; unlike the others it is
|
|
196
|
+
* optional — when present, the sessions token extracted from it is preferred
|
|
197
|
+
* as the Bearer credential for this item's heartbeat / force-stop / session
|
|
198
|
+
* calls; when absent (or undecodable) those calls use the environment key.
|
|
199
|
+
*/
|
|
200
|
+
async handleItem(opts) {
|
|
201
|
+
const workId = opts?.workId ?? readEnv('PUKU_WORK_ID');
|
|
202
|
+
const environmentId = opts?.environmentId ?? readEnv('PUKU_ENVIRONMENT_ID');
|
|
203
|
+
const sessionId = opts?.sessionId ?? readEnv('PUKU_SESSION_ID');
|
|
204
|
+
const environmentKey = opts?.environmentKey ?? this.environmentKey ?? readEnv('PUKU_ENVIRONMENT_KEY');
|
|
205
|
+
// `||` rather than `??` so an empty option still falls through to the env
|
|
206
|
+
// var and then to null (matching how `readEnv` treats empty values).
|
|
207
|
+
const workSecret = opts?.workSecret || readEnv('PUKU_WORK_SECRET') || null;
|
|
208
|
+
if (!workId) {
|
|
209
|
+
throw new PukuError('handleItem: workId is required — pass it or set PUKU_WORK_ID');
|
|
210
|
+
}
|
|
211
|
+
if (!environmentId) {
|
|
212
|
+
throw new PukuError('handleItem: environmentId is required — pass it or set PUKU_ENVIRONMENT_ID');
|
|
213
|
+
}
|
|
214
|
+
if (!sessionId) {
|
|
215
|
+
throw new PukuError('handleItem: sessionId is required — pass it or set PUKU_SESSION_ID');
|
|
216
|
+
}
|
|
217
|
+
if (!environmentKey) {
|
|
218
|
+
throw new PukuError('handleItem: environmentKey is required — pass it, construct the worker with it, or set PUKU_ENVIRONMENT_KEY');
|
|
219
|
+
}
|
|
220
|
+
const work = {
|
|
221
|
+
id: workId,
|
|
222
|
+
environment_id: environmentId,
|
|
223
|
+
secret: workSecret,
|
|
224
|
+
data: { type: 'session', id: sessionId },
|
|
225
|
+
};
|
|
226
|
+
await this.#handleItem(work, environmentKey, opts?.signal ?? this.#signal);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The per-item body shared by {@link EnvironmentWorker.run}'s poll loop and
|
|
230
|
+
* {@link EnvironmentWorker.handleItem}: run a {@link SessionToolRunner} for the
|
|
231
|
+
* work item's session while heartbeating its lease, force-stopping on exit
|
|
232
|
+
* unless the lease was lost. Non-session work items are ignored.
|
|
233
|
+
*
|
|
234
|
+
* When the poll response carried a per-item `secret` (a short-lived payload
|
|
235
|
+
* scoped to this work item), the sessions token extracted from it is
|
|
236
|
+
* preferred over `environmentKey` as the Bearer credential for those
|
|
237
|
+
* per-item calls; a missing/undecodable secret falls back to
|
|
238
|
+
* `environmentKey` unchanged.
|
|
239
|
+
*/
|
|
240
|
+
async #handleItem(work, environmentKey, externalSignal) {
|
|
241
|
+
const log = loggerFor(this.client);
|
|
242
|
+
// The per-item credential: the sessions token carried inside the work
|
|
243
|
+
// item's secret payload when the server issued one, otherwise the
|
|
244
|
+
// environment key. Never log this value.
|
|
245
|
+
const sessionsToken = sessionsTokenFromSecret(work.secret);
|
|
246
|
+
if (work.secret && sessionsToken === null) {
|
|
247
|
+
log.warn('work item carried a secret payload but no sessions token could be extracted; ' +
|
|
248
|
+
'falling back to the environment key', { work_id: work.id });
|
|
249
|
+
}
|
|
250
|
+
const itemCredential = sessionsToken ?? environmentKey;
|
|
251
|
+
// Every per-session call — the SessionToolRunner event stream/list/send, the
|
|
252
|
+
// lease heartbeat, the skill download, and the work force-stop —
|
|
253
|
+
// authenticates with the per-item credential. Scope a client to it once and
|
|
254
|
+
// thread that through. `copyClientForHelper` also clears the parent's
|
|
255
|
+
// `apiKey`, so the sub-client emits *only* the bearer credential on the
|
|
256
|
+
// wire (a plain `withOptions({authToken})` would leave `X-Api-Key` set as
|
|
257
|
+
// well).
|
|
258
|
+
const sessionClient = copyClientForHelper(this.client, {
|
|
259
|
+
authToken: itemCredential,
|
|
260
|
+
helper: 'environments-worker',
|
|
261
|
+
});
|
|
262
|
+
// The poller runs with `autoStop: false`, so the per-item handler is the
|
|
263
|
+
// single owner of `work.stop` for every claimed item.
|
|
264
|
+
const sessionId = work.data.id;
|
|
265
|
+
// A per-session controller: aborts when the supplied signal aborts, when the
|
|
266
|
+
// session runner finishes, or when the lease heartbeat says to stop.
|
|
267
|
+
const ctrl = new AbortController();
|
|
268
|
+
const detachExternal = linkAbort(externalSignal, ctrl);
|
|
269
|
+
const lease = new Lease(ctrl);
|
|
270
|
+
// Lazily load the Node-only toolset module — see the import note at the top.
|
|
271
|
+
const agentToolset = await import('../../tools/agent-toolset/node.js');
|
|
272
|
+
// Start the lease heartbeat BEFORE the session fetch and the skill /
|
|
273
|
+
// memory downloads: those can take longer than the lease TTL, and an
|
|
274
|
+
// unheartbeated lease lapsing mid-download would let another worker
|
|
275
|
+
// reclaim the item and serve the same session (split-brain).
|
|
276
|
+
//
|
|
277
|
+
// Each heartbeat reports the lease TTL the server is enforcing; it becomes
|
|
278
|
+
// the runner's tool-result send retry window so a send keeps retrying
|
|
279
|
+
// exactly as long as the lease could still be live. The runner is only
|
|
280
|
+
// built after the downloads, so hold the latest TTL until then.
|
|
281
|
+
let leaseTtlMs;
|
|
282
|
+
let runner;
|
|
283
|
+
const heartbeatPromise = heartbeatLoop(sessionClient, work, lease, log, this.requestOptions, (ttlMs) => {
|
|
284
|
+
leaseTtlMs = ttlMs;
|
|
285
|
+
runner?._setSendRetryWindow(ttlMs);
|
|
286
|
+
}).catch((e) => {
|
|
287
|
+
if (!ctrl.signal.aborted)
|
|
288
|
+
log.error('heartbeat loop failed', { work_id: work.id, error: String(e) });
|
|
289
|
+
ctrl.abort();
|
|
290
|
+
});
|
|
291
|
+
let cleanupSkills = async () => { };
|
|
292
|
+
let stores;
|
|
293
|
+
let cleanEnd = false;
|
|
294
|
+
try {
|
|
295
|
+
if (work.data.type !== 'session') {
|
|
296
|
+
log.debug('skipping non-session work item', { work_id: work.id, type: work.data.type });
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
// One session fetch, shared by the skills download and the memory-store
|
|
300
|
+
// download — two fetches could disagree about the attached resources.
|
|
301
|
+
// A failed fetch fails the work item (the teardown below still stops
|
|
302
|
+
// or releases it).
|
|
303
|
+
const session = await sessionClient.beta.sessions.retrieve(sessionId);
|
|
304
|
+
// Only with the session in hand can we tell one that simply has no
|
|
305
|
+
// memory from one whose memory we cannot mount. Turning memory off
|
|
306
|
+
// with the interval knob is a deliberate opt-out and stays quiet.
|
|
307
|
+
if (sessionsToken === null && this.memorySyncIntervalMs !== null && hasMemoryStore(session)) {
|
|
308
|
+
throw new agentToolset.SessionMemoryError(`cannot mount the session's memories: the work item carried no sessions token ` +
|
|
309
|
+
`(work_id=${work.id}, session_id=${sessionId}); ` +
|
|
310
|
+
'the memory endpoints reject the environment key, so the poller must issue a per-item ' +
|
|
311
|
+
'`secret` carrying `sessions_token`, or set `memorySyncIntervalMs: null` to run without memory');
|
|
312
|
+
}
|
|
313
|
+
const ctx = {
|
|
314
|
+
workdir: this.workdir,
|
|
315
|
+
// The scoped sub-client, not the parent: the skill download
|
|
316
|
+
// `setupSkills` performs for this session rides the same per-item
|
|
317
|
+
// credential as every other per-item call.
|
|
318
|
+
client: sessionClient,
|
|
319
|
+
session,
|
|
320
|
+
...(this.maxFileBytes !== undefined ? { maxFileBytes: this.maxFileBytes } : {}),
|
|
321
|
+
};
|
|
322
|
+
try {
|
|
323
|
+
cleanupSkills = await agentToolset.setupSkills(ctx);
|
|
324
|
+
}
|
|
325
|
+
catch (e) {
|
|
326
|
+
log.warn('skill setup failed', { session_id: sessionId, work_id: work.id, error: String(e) });
|
|
327
|
+
}
|
|
328
|
+
// Memory stores: the memory_stores endpoints accept the per-item sessions
|
|
329
|
+
// token but reject the environment key, so download and sync only run when
|
|
330
|
+
// the item carried a usable secret (and the interval is set).
|
|
331
|
+
// `sessionClient` is already scoped to that token then, so the memory
|
|
332
|
+
// calls ride the same sub-client. A store that cannot be materialised
|
|
333
|
+
// throws `SessionMemoryError` out of `download` and fails the item.
|
|
334
|
+
if (sessionsToken !== null && this.memorySyncIntervalMs !== null) {
|
|
335
|
+
stores = new agentToolset.SessionMemoryStores(sessionClient, {
|
|
336
|
+
workdir: this.workdir,
|
|
337
|
+
...(this.memorySyncIntervalMs !== undefined ? { syncIntervalMs: this.memorySyncIntervalMs } : {}),
|
|
338
|
+
syncDeletions: this.memorySyncDeletions,
|
|
339
|
+
});
|
|
340
|
+
await stores.download(session);
|
|
341
|
+
// A store mounted outside the workdir must stay reachable by the file
|
|
342
|
+
// tools; read-only stores still refuse writes.
|
|
343
|
+
ctx.allowedRoots = stores.roots;
|
|
344
|
+
ctx.readOnlyRoots = stores.readOnlyRoots;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
log.debug('memory stores disabled for this item', { work_id: work.id });
|
|
348
|
+
}
|
|
349
|
+
const tools = typeof this.tools === 'function' ?
|
|
350
|
+
this.tools(ctx)
|
|
351
|
+
: this.tools ?? agentToolset.betaAgentToolset20260401(ctx);
|
|
352
|
+
runner = new SessionToolRunner(sessionId, {
|
|
353
|
+
client: sessionClient,
|
|
354
|
+
tools,
|
|
355
|
+
...(this.maxIdleMs !== undefined ? { maxIdleMs: this.maxIdleMs } : {}),
|
|
356
|
+
...(this.requestOptions !== undefined ? { requestOptions: this.requestOptions } : {}),
|
|
357
|
+
signal: ctrl.signal,
|
|
358
|
+
});
|
|
359
|
+
if (leaseTtlMs !== undefined)
|
|
360
|
+
runner._setSendRetryWindow(leaseTtlMs);
|
|
361
|
+
for await (const _ of runner) {
|
|
362
|
+
// Drive the runner to completion; per-call observability is not part
|
|
363
|
+
// of this composition's surface — use `SessionToolRunner` directly
|
|
364
|
+
// (via `client.beta.sessions.events.toolRunner`) if you want it.
|
|
365
|
+
if (stores)
|
|
366
|
+
await stores.syncIfDue();
|
|
367
|
+
}
|
|
368
|
+
// Only a clean stream end earns the last full sync; it runs in the
|
|
369
|
+
// teardown below.
|
|
370
|
+
cleanEnd = !ctrl.signal.aborted;
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
// The heartbeat keeps the lease alive until this teardown is done.
|
|
374
|
+
try {
|
|
375
|
+
// cleanupSkills first, so its failure cannot skip the memory flush.
|
|
376
|
+
await cleanupSkills().catch((e) => {
|
|
377
|
+
log.warn('skill cleanup failed', { session_id: sessionId, work_id: work.id, error: String(e) });
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
if (stores) {
|
|
382
|
+
const boundMs = agentToolset.MEMORY_FLUSH_TIMEOUT_MS;
|
|
383
|
+
if (cleanEnd) {
|
|
384
|
+
const finishCutOff = await withTimeout(stores.finish(), boundMs);
|
|
385
|
+
if (finishCutOff) {
|
|
386
|
+
log.warn(`final memory sync cut off after ${boundMs}ms; the flush that follows still uploads changed files`, { session_id: sessionId, work_id: work.id });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// Also after finish(): it swallows its own failures, and a
|
|
390
|
+
// clean flush is a no-op.
|
|
391
|
+
const flushBound = new AbortController();
|
|
392
|
+
const flushCutOff = await withTimeout(stores.flushWrites(flushBound.signal), boundMs);
|
|
393
|
+
if (flushCutOff) {
|
|
394
|
+
flushBound.abort();
|
|
395
|
+
log.warn(`memory flush cut off after ${boundMs}ms; changed files it had not uploaded yet are not saved`, { session_id: sessionId, work_id: work.id });
|
|
396
|
+
}
|
|
397
|
+
await stores.dispose().catch((e) => {
|
|
398
|
+
log.warn('memory store cleanup failed', {
|
|
399
|
+
session_id: sessionId,
|
|
400
|
+
work_id: work.id,
|
|
401
|
+
error: String(e),
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
lease.finish('runner_done');
|
|
407
|
+
detachExternal();
|
|
408
|
+
await heartbeatPromise;
|
|
409
|
+
// Stop only an item this worker still holds — after a lost lease it
|
|
410
|
+
// belongs to the queue or another worker.
|
|
411
|
+
if (lease.lost) {
|
|
412
|
+
log.info('lease lost; released without stopping it', { session_id: sessionId, work_id: work.id });
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
await forceStop(sessionClient, work, log, this.requestOptions);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Resolve when `p` settles or `ms` elapses — `true` when `ms` elapsed
|
|
422
|
+
* first. A timed-out `p` keeps running — JS cannot cancel a promise.
|
|
423
|
+
*/
|
|
424
|
+
async function withTimeout(p, ms) {
|
|
425
|
+
let timer;
|
|
426
|
+
try {
|
|
427
|
+
return await Promise.race([
|
|
428
|
+
p.then(() => false, () => false),
|
|
429
|
+
new Promise((resolve) => {
|
|
430
|
+
timer = setTimeout(() => resolve(true), ms);
|
|
431
|
+
}),
|
|
432
|
+
]);
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
if (timer !== undefined)
|
|
436
|
+
clearTimeout(timer);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/** Force-stop a claimed work item, swallowing the 409 that means it's already stopped. */
|
|
440
|
+
async function forceStop(client, work, log, requestOptions) {
|
|
441
|
+
try {
|
|
442
|
+
await client.beta.environments.work.stop(work.id, { environment_id: work.environment_id, force: true },
|
|
443
|
+
// Caller's headers pass through; the helper-tag header is on the scoped
|
|
444
|
+
// sub-client's default_headers via copyClientForHelper, so no per-call
|
|
445
|
+
// re-stamping needed.
|
|
446
|
+
{ ...requestOptions, headers: buildHeaders([requestOptions?.headers]) });
|
|
447
|
+
}
|
|
448
|
+
catch (e) {
|
|
449
|
+
if (!isStatus(e, 409)) {
|
|
450
|
+
log.error('force-stop on exit failed', { work_id: work.id, error: String(e) });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* This worker's view of one work-item lease: the per-item abort signal plus
|
|
456
|
+
* why heartbeating ended. The first recorded reason wins, so a run aborted
|
|
457
|
+
* *because* the lease was lost still reads as lost afterwards; an abort with
|
|
458
|
+
* no recorded reason (the external signal) is not lost.
|
|
459
|
+
*/
|
|
460
|
+
class Lease {
|
|
461
|
+
#ctrl;
|
|
462
|
+
#endReason;
|
|
463
|
+
constructor(ctrl) {
|
|
464
|
+
this.#ctrl = ctrl;
|
|
465
|
+
}
|
|
466
|
+
get signal() {
|
|
467
|
+
return this.#ctrl.signal;
|
|
468
|
+
}
|
|
469
|
+
finish(reason) {
|
|
470
|
+
this.#endReason ??= reason;
|
|
471
|
+
this.#ctrl.abort();
|
|
472
|
+
}
|
|
473
|
+
/** True once the item belongs to the queue or another worker. */
|
|
474
|
+
get lost() {
|
|
475
|
+
return this.#endReason === 'lease_lost' || this.#endReason === 'assumed_lost';
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/** The server's view of the lease carried by a 412 heartbeat response, or empty if absent. */
|
|
479
|
+
function serverLeaseState(e) {
|
|
480
|
+
let node = e instanceof APIError ? e.error : undefined;
|
|
481
|
+
for (const key of ['error', 'details', 'current_state']) {
|
|
482
|
+
if (!isObj(node))
|
|
483
|
+
return {};
|
|
484
|
+
node = node[key];
|
|
485
|
+
}
|
|
486
|
+
return isObj(node) ? node : {};
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Keep the work-item lease alive while a session is being served. Runs until
|
|
490
|
+
* `lease` ends, and ends it itself when the control plane reports the work is
|
|
491
|
+
* `stopping`/`stopped` or no longer extends the lease, when a heartbeat is
|
|
492
|
+
* rejected (a 412 means the lease already belongs to someone else), or when no
|
|
493
|
+
* heartbeat has succeeded for longer than the lease ttl (the lease is assumed
|
|
494
|
+
* lost, so two runners don't end up serving the same work). Each heartbeat
|
|
495
|
+
* call is cut off after the current beat interval so a hung request cannot
|
|
496
|
+
* outlive the lease it is meant to renew.
|
|
497
|
+
*/
|
|
498
|
+
async function heartbeatLoop(client, work, lease, logger, requestOptions,
|
|
499
|
+
/** Called with the server-reported lease TTL after every successful beat. */
|
|
500
|
+
onLeaseTtl) {
|
|
501
|
+
let intervalMs = HEARTBEAT_DEFAULT_MS;
|
|
502
|
+
let ttlMs = HEARTBEAT_TTL_DEFAULT_MS;
|
|
503
|
+
let lastSuccessMs = Date.now();
|
|
504
|
+
let last = NO_HEARTBEAT_SENTINEL;
|
|
505
|
+
const beat = async () => {
|
|
506
|
+
// Not the request `timeout` option: the core client retries timeouts, so
|
|
507
|
+
// it would not bound the call as a whole.
|
|
508
|
+
const beatCtrl = new AbortController();
|
|
509
|
+
const detach = linkAbort(lease.signal, beatCtrl);
|
|
510
|
+
const cutoff = setTimeout(() => beatCtrl.abort(), intervalMs);
|
|
511
|
+
try {
|
|
512
|
+
const resp = await client.beta.environments.work.heartbeat(work.id, { environment_id: work.environment_id, expected_last_heartbeat: last }, { ...requestOptions, headers: buildHeaders([requestOptions?.headers]), signal: beatCtrl.signal });
|
|
513
|
+
lastSuccessMs = Date.now();
|
|
514
|
+
last = resp.last_heartbeat;
|
|
515
|
+
if (resp.ttl_seconds > 0) {
|
|
516
|
+
ttlMs = resp.ttl_seconds * 1000;
|
|
517
|
+
intervalMs = Math.max(1_000, Math.min(ttlMs / 2, HEARTBEAT_DEFAULT_MS));
|
|
518
|
+
onLeaseTtl?.(ttlMs);
|
|
519
|
+
}
|
|
520
|
+
if (resp.state === 'stopping' || resp.state === 'stopped') {
|
|
521
|
+
logger.info('heartbeat signals shutdown', { work_id: work.id, state: resp.state });
|
|
522
|
+
lease.finish('control_plane_stop');
|
|
523
|
+
}
|
|
524
|
+
if (!resp.lease_extended) {
|
|
525
|
+
logger.warn('lease not extended, shutting down', { work_id: work.id });
|
|
526
|
+
lease.finish('control_plane_stop');
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch (e) {
|
|
530
|
+
// An abort throws to unwind the caller (the `heartbeatLoop(...).catch`
|
|
531
|
+
// in `#handleItem`) rather than returning early.
|
|
532
|
+
lease.signal.throwIfAborted();
|
|
533
|
+
if (isStatus(e, 412)) {
|
|
534
|
+
const server = serverLeaseState(e);
|
|
535
|
+
logger.error('lease lost: heartbeat precondition failed', {
|
|
536
|
+
work_id: work.id,
|
|
537
|
+
server_state: server['state'],
|
|
538
|
+
server_ttl_seconds: server['ttl_seconds'],
|
|
539
|
+
server_last_heartbeat: server['last_heartbeat'],
|
|
540
|
+
});
|
|
541
|
+
lease.finish('lease_lost');
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (isFatal4xx(e)) {
|
|
545
|
+
logger.error('permanent heartbeat failure', { work_id: work.id, error: String(e) });
|
|
546
|
+
lease.finish('heartbeat_rejected');
|
|
547
|
+
throw e;
|
|
548
|
+
}
|
|
549
|
+
if (Date.now() - lastSuccessMs > ttlMs) {
|
|
550
|
+
logger.error('lease assumed lost: no successful heartbeat in ttl', {
|
|
551
|
+
work_id: work.id,
|
|
552
|
+
ttl_ms: ttlMs,
|
|
553
|
+
error: String(e),
|
|
554
|
+
});
|
|
555
|
+
lease.finish('assumed_lost');
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
logger.warn('transient heartbeat failure', { work_id: work.id, error: String(e) });
|
|
559
|
+
}
|
|
560
|
+
finally {
|
|
561
|
+
clearTimeout(cutoff);
|
|
562
|
+
detach();
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
await beat();
|
|
566
|
+
while (!lease.signal.aborted) {
|
|
567
|
+
await sleep(intervalMs, lease.signal);
|
|
568
|
+
lease.signal.throwIfAborted();
|
|
569
|
+
await beat();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/vendor/lib/environments/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,YAAY,E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AAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpF,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;gBACnC,MAAM,CAAC,CAAC;YACV,CAAC;YACD,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC;gBACvC,MAAM,CAAC,KAAK,CAAC,oDAAoD,EAAE;oBACjE,OAAO,EAAE,IAAI,CAAC,EAAE;oBAChB,MAAM,EAAE,KAAK;oBACb,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;iBACjB,CAAC,CAAC;gBACH,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC7B,OAAO;YACT,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACrF,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,IAAI,EAAE,CAAC;IACb,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC7B,MAAM,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAC9B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PukuAI } from '../client';
|
|
2
|
+
import { type StainlessHelperHeaderValue } from '../internal/stainless-helper-header';
|
|
3
|
+
/**
|
|
4
|
+
* Return a `withOptions()` clone of `client` set up for use *by* one of the
|
|
5
|
+
* runner helpers: authenticated with `authToken` as Bearer credentials, with
|
|
6
|
+
* the parent's `X-Api-Key` cleared, and tagged with the helper's
|
|
7
|
+
* `x-stainless-helper` value on every outgoing request.
|
|
8
|
+
*
|
|
9
|
+
* The returned sub-client inherits the parent's full configuration
|
|
10
|
+
* (`baseURL`, `timeout`, `maxRetries`, `fetch`, `fetchOptions`, custom
|
|
11
|
+
* `defaultHeaders`, `defaultQuery`). Overrides applied:
|
|
12
|
+
*
|
|
13
|
+
* - `authToken: authToken` — the new credential.
|
|
14
|
+
* - `apiKey: null` — the parent's `X-Api-Key` is cleared. `withOptions`
|
|
15
|
+
* inherits the parent's `apiKey` by default; without this, both
|
|
16
|
+
* `X-Api-Key` *and* `Authorization: Bearer …` would land on the wire.
|
|
17
|
+
* `client.ts` only triggers the env-var fallback when `apiKey === undefined`,
|
|
18
|
+
* so explicit `null` is honored.
|
|
19
|
+
* - `credentials: undefined` — opts the clone out of any inherited
|
|
20
|
+
* credentials/config/profile so the explicit bearer is the unambiguous auth.
|
|
21
|
+
* - `baseURL: client.baseURL` — pins the parent's resolved host (auth override otherwise resets it).
|
|
22
|
+
* - `defaultHeaders` is rebuilt as `parent._authState.extraHeaders ⊕ parent.defaultHeaders ⊕
|
|
23
|
+
* {'x-stainless-helper': helper}`. `withOptions` *replaces* (does not
|
|
24
|
+
* merge) `defaultHeaders`, so we merge here so any custom headers the
|
|
25
|
+
* caller set on the parent client survive on the sub-client.
|
|
26
|
+
*/
|
|
27
|
+
export declare function copyClientForHelper<T extends PukuAI>(client: T, { authToken, helper }: {
|
|
28
|
+
authToken: string;
|
|
29
|
+
helper: StainlessHelperHeaderValue;
|
|
30
|
+
}): T;
|