gsd-pi 2.20.0 → 2.22.0
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 +12 -0
- package/dist/cli.js +21 -18
- package/dist/help-text.d.ts +2 -0
- package/dist/help-text.js +47 -0
- package/dist/loader.js +2 -16
- package/dist/mcp-server.d.ts +18 -0
- package/dist/mcp-server.js +53 -0
- package/dist/onboarding.d.ts +0 -6
- package/dist/onboarding.js +0 -28
- package/dist/resources/agents/javascript-pro.md +280 -0
- package/dist/resources/agents/typescript-pro.md +255 -0
- package/dist/resources/extensions/bg-shell/index.ts +14 -2
- package/dist/resources/extensions/bg-shell/utilities.ts +14 -0
- package/dist/resources/extensions/browser-tools/{core.js → core.ts} +329 -190
- package/dist/resources/extensions/gsd/auto-dashboard.ts +2 -1
- package/dist/resources/extensions/gsd/auto-prompts.ts +42 -1
- package/dist/resources/extensions/gsd/auto-worktree.ts +35 -2
- package/dist/resources/extensions/gsd/auto.ts +116 -10
- package/dist/resources/extensions/gsd/claude-import.ts +656 -0
- package/dist/resources/extensions/gsd/collision-diagnostics.ts +332 -0
- package/dist/resources/extensions/gsd/commands.ts +60 -7
- package/dist/resources/extensions/gsd/diff-context.ts +220 -0
- package/dist/resources/extensions/gsd/docs/claude-marketplace-import.md +214 -0
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +2 -1
- package/dist/resources/extensions/gsd/doctor.ts +12 -4
- package/dist/resources/extensions/gsd/file-watcher.ts +97 -0
- package/dist/resources/extensions/gsd/files.ts +1 -1
- package/dist/resources/extensions/gsd/forensics.ts +596 -0
- package/dist/resources/extensions/gsd/git-service.ts +2 -1
- package/dist/resources/extensions/gsd/github-client.ts +235 -0
- package/dist/resources/extensions/gsd/gitignore.ts +1 -0
- package/dist/resources/extensions/gsd/marketplace-discovery.ts +507 -0
- package/dist/resources/extensions/gsd/mcp-server.ts +87 -0
- package/dist/resources/extensions/gsd/namespaced-registry.ts +467 -0
- package/dist/resources/extensions/gsd/namespaced-resolver.ts +307 -0
- package/dist/resources/extensions/gsd/plugin-importer.ts +410 -0
- package/dist/resources/extensions/gsd/preferences.ts +14 -3
- package/dist/resources/extensions/gsd/prompts/execute-task.md +1 -1
- package/dist/resources/extensions/gsd/prompts/forensics.md +71 -0
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/research-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/system.md +12 -3
- package/dist/resources/extensions/gsd/roadmap-slices.ts +1 -1
- package/dist/resources/extensions/gsd/session-forensics.ts +5 -5
- package/dist/resources/extensions/gsd/tests/claude-import-tui.test.ts +351 -0
- package/dist/resources/extensions/gsd/tests/collision-diagnostics.test.ts +705 -0
- package/dist/resources/extensions/gsd/tests/context-compression.test.ts +13 -0
- package/dist/resources/extensions/gsd/tests/diff-context.test.ts +136 -0
- package/dist/resources/extensions/gsd/tests/doctor-git.test.ts +118 -0
- package/dist/resources/extensions/gsd/tests/marketplace-discovery.test.ts +202 -0
- package/dist/resources/extensions/gsd/tests/marketplace-test-fixtures.ts +91 -0
- package/dist/resources/extensions/gsd/tests/namespaced-registry.test.ts +1027 -0
- package/dist/resources/extensions/gsd/tests/namespaced-resolver.test.ts +671 -0
- package/dist/resources/extensions/gsd/tests/none-mode-gates.test.ts +105 -0
- package/dist/resources/extensions/gsd/tests/plugin-importer-live.test.ts +481 -0
- package/dist/resources/extensions/gsd/tests/plugin-importer.test.ts +1383 -0
- package/dist/resources/extensions/gsd/tests/preferences-git.test.ts +21 -2
- package/dist/resources/extensions/gsd/tests/preferences-schema-validation.test.ts +8 -1
- package/dist/resources/extensions/gsd/tests/visualizer-data.test.ts +11 -0
- package/dist/resources/extensions/gsd/tests/worktree-bugfix.test.ts +120 -0
- package/dist/resources/extensions/gsd/token-counter.ts +45 -0
- package/dist/resources/extensions/gsd/visualizer-data.ts +2 -2
- package/dist/resources/extensions/gsd/worktree-manager.ts +29 -1
- package/dist/resources/extensions/gsd/worktree.ts +3 -0
- package/dist/resources/extensions/mcporter/index.ts +90 -7
- package/dist/resources/extensions/search-the-web/native-search.ts +2 -0
- package/dist/resources/extensions/search-the-web/tool-fetch-page.ts +9 -1
- package/dist/resources/extensions/search-the-web/url-utils.ts +35 -1
- package/dist/resources/extensions/shared/terminal.ts +1 -1
- package/dist/resources/extensions/universal-config/discovery.ts +4 -0
- package/dist/resources/extensions/universal-config/format.ts +35 -4
- package/dist/resources/extensions/universal-config/index.ts +5 -3
- package/dist/resources/extensions/universal-config/scanners.ts +65 -2
- package/dist/resources/extensions/universal-config/tests/discovery.test.ts +9 -1
- package/dist/resources/extensions/universal-config/tests/format.test.ts +22 -6
- package/dist/resources/extensions/universal-config/tests/scanners.test.ts +18 -0
- package/dist/resources/extensions/universal-config/types.ts +20 -1
- package/dist/resources/skills/lint/SKILL.md +141 -0
- package/dist/resources/skills/review/SKILL.md +214 -0
- package/dist/resources/skills/test/SKILL.md +201 -0
- package/dist/tool-bootstrap.js +2 -1
- package/dist/wizard.js +2 -0
- package/package.json +12 -7
- package/packages/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/azure-openai-responses.js +12 -1
- package/packages/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.js +12 -1
- package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/LICENSE +201 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/README.md +9 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-cjs/index.js +762 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/build-abort-error.js +19 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/constants.js +1 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +9 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/index.js +3 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +230 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +87 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +32 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +169 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/readable.mock.js +21 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/server.mock.js +88 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js +36 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-request-timeout.js +21 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js +22 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +23 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/stream-collector/collector.js +8 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/stream-collector/index.js +41 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/stream-collector/readable.mock.js +21 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/timing.js +4 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/write-request-body.js +63 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/build-abort-error.d.ts +10 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/constants.d.ts +5 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/get-transformed-headers.d.ts +4 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/index.d.ts +3 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/node-http-handler.d.ts +46 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +24 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-pool.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +63 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/readable.mock.d.ts +13 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/server.mock.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/set-connection-timeout.d.ts +2 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/set-request-timeout.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/set-socket-keep-alive.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/set-socket-timeout.d.ts +2 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/stream-collector/collector.d.ts +5 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/stream-collector/index.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/stream-collector/readable.mock.d.ts +13 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/timing.d.ts +8 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/build-abort-error.d.ts +10 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/constants.d.ts +5 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/get-transformed-headers.d.ts +4 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/index.d.ts +3 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http-handler.d.ts +46 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-connection-manager.d.ts +24 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-connection-pool.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-handler.d.ts +63 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/readable.mock.d.ts +13 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/server.mock.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-connection-timeout.d.ts +2 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-request-timeout.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-keep-alive.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-timeout.d.ts +2 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/collector.d.ts +5 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/index.d.ts +6 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/readable.mock.d.ts +13 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/timing.d.ts +8 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/ts3.4/write-request-body.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-types/write-request-body.d.ts +12 -0
- package/packages/pi-ai/node_modules/@smithy/node-http-handler/package.json +68 -0
- package/packages/pi-ai/package.json +3 -0
- package/packages/pi-ai/pnpm-lock.yaml +2022 -0
- package/packages/pi-ai/src/providers/azure-openai-responses.ts +12 -1
- package/packages/pi-ai/src/providers/openai-responses.ts +12 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +12 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.js +113 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/project-trust.d.ts +4 -0
- package/packages/pi-coding-agent/dist/core/extensions/project-trust.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/project-trust.js +42 -0
- package/packages/pi-coding-agent/dist/core/extensions/project-trust.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resolve-config-value.js +18 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js +114 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +8 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.d.ts +2 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js +23 -9
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.js +67 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.js.map +1 -0
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/pnpm-lock.yaml +454 -0
- package/packages/pi-coding-agent/scripts/copy-assets.cjs +24 -0
- package/packages/pi-coding-agent/src/core/extensions/index.ts +3 -0
- package/packages/pi-coding-agent/src/core/extensions/loader.test.ts +141 -0
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +14 -1
- package/packages/pi-coding-agent/src/core/extensions/project-trust.ts +51 -0
- package/packages/pi-coding-agent/src/core/resolve-config-value.test.ts +132 -0
- package/packages/pi-coding-agent/src/core/resolve-config-value.ts +20 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/login-dialog.ts +7 -2
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage.test.ts +98 -0
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage.ts +24 -9
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +2 -2
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/package.json +3 -1
- package/packages/pi-tui/src/tui.ts +2 -2
- package/src/resources/agents/javascript-pro.md +280 -0
- package/src/resources/agents/typescript-pro.md +255 -0
- package/src/resources/extensions/bg-shell/index.ts +14 -2
- package/src/resources/extensions/bg-shell/utilities.ts +14 -0
- package/src/resources/extensions/browser-tools/{core.js → core.ts} +329 -190
- package/src/resources/extensions/gsd/auto-dashboard.ts +2 -1
- package/src/resources/extensions/gsd/auto-prompts.ts +42 -1
- package/src/resources/extensions/gsd/auto-worktree.ts +35 -2
- package/src/resources/extensions/gsd/auto.ts +116 -10
- package/src/resources/extensions/gsd/claude-import.ts +656 -0
- package/src/resources/extensions/gsd/collision-diagnostics.ts +332 -0
- package/src/resources/extensions/gsd/commands.ts +60 -7
- package/src/resources/extensions/gsd/diff-context.ts +220 -0
- package/src/resources/extensions/gsd/docs/claude-marketplace-import.md +214 -0
- package/src/resources/extensions/gsd/docs/preferences-reference.md +2 -1
- package/src/resources/extensions/gsd/doctor.ts +12 -4
- package/src/resources/extensions/gsd/file-watcher.ts +97 -0
- package/src/resources/extensions/gsd/files.ts +1 -1
- package/src/resources/extensions/gsd/forensics.ts +596 -0
- package/src/resources/extensions/gsd/git-service.ts +2 -1
- package/src/resources/extensions/gsd/github-client.ts +235 -0
- package/src/resources/extensions/gsd/gitignore.ts +1 -0
- package/src/resources/extensions/gsd/marketplace-discovery.ts +507 -0
- package/src/resources/extensions/gsd/mcp-server.ts +87 -0
- package/src/resources/extensions/gsd/namespaced-registry.ts +467 -0
- package/src/resources/extensions/gsd/namespaced-resolver.ts +307 -0
- package/src/resources/extensions/gsd/plugin-importer.ts +410 -0
- package/src/resources/extensions/gsd/preferences.ts +14 -3
- package/src/resources/extensions/gsd/prompts/execute-task.md +1 -1
- package/src/resources/extensions/gsd/prompts/forensics.md +71 -0
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/research-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/system.md +12 -3
- package/src/resources/extensions/gsd/roadmap-slices.ts +1 -1
- package/src/resources/extensions/gsd/session-forensics.ts +5 -5
- package/src/resources/extensions/gsd/tests/claude-import-tui.test.ts +351 -0
- package/src/resources/extensions/gsd/tests/collision-diagnostics.test.ts +705 -0
- package/src/resources/extensions/gsd/tests/context-compression.test.ts +13 -0
- package/src/resources/extensions/gsd/tests/diff-context.test.ts +136 -0
- package/src/resources/extensions/gsd/tests/doctor-git.test.ts +118 -0
- package/src/resources/extensions/gsd/tests/marketplace-discovery.test.ts +202 -0
- package/src/resources/extensions/gsd/tests/marketplace-test-fixtures.ts +91 -0
- package/src/resources/extensions/gsd/tests/namespaced-registry.test.ts +1027 -0
- package/src/resources/extensions/gsd/tests/namespaced-resolver.test.ts +671 -0
- package/src/resources/extensions/gsd/tests/none-mode-gates.test.ts +105 -0
- package/src/resources/extensions/gsd/tests/plugin-importer-live.test.ts +481 -0
- package/src/resources/extensions/gsd/tests/plugin-importer.test.ts +1383 -0
- package/src/resources/extensions/gsd/tests/preferences-git.test.ts +21 -2
- package/src/resources/extensions/gsd/tests/preferences-schema-validation.test.ts +8 -1
- package/src/resources/extensions/gsd/tests/visualizer-data.test.ts +11 -0
- package/src/resources/extensions/gsd/tests/worktree-bugfix.test.ts +120 -0
- package/src/resources/extensions/gsd/token-counter.ts +45 -0
- package/src/resources/extensions/gsd/visualizer-data.ts +2 -2
- package/src/resources/extensions/gsd/worktree-manager.ts +29 -1
- package/src/resources/extensions/gsd/worktree.ts +3 -0
- package/src/resources/extensions/mcporter/index.ts +90 -7
- package/src/resources/extensions/search-the-web/native-search.ts +2 -0
- package/src/resources/extensions/search-the-web/tool-fetch-page.ts +9 -1
- package/src/resources/extensions/search-the-web/url-utils.ts +35 -1
- package/src/resources/extensions/shared/terminal.ts +1 -1
- package/src/resources/extensions/universal-config/discovery.ts +4 -0
- package/src/resources/extensions/universal-config/format.ts +35 -4
- package/src/resources/extensions/universal-config/index.ts +5 -3
- package/src/resources/extensions/universal-config/scanners.ts +65 -2
- package/src/resources/extensions/universal-config/tests/discovery.test.ts +9 -1
- package/src/resources/extensions/universal-config/tests/format.test.ts +22 -6
- package/src/resources/extensions/universal-config/tests/scanners.test.ts +18 -0
- package/src/resources/extensions/universal-config/types.ts +20 -1
- package/src/resources/skills/lint/SKILL.md +141 -0
- package/src/resources/skills/review/SKILL.md +214 -0
- package/src/resources/skills/test/SKILL.md +201 -0
- package/dist/resources/extensions/browser-tools/core.d.ts +0 -205
- package/src/resources/extensions/browser-tools/core.d.ts +0 -205
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function buildAbortError(abortSignal) {
|
|
2
|
+
const reason = abortSignal && typeof abortSignal === "object" && "reason" in abortSignal
|
|
3
|
+
? abortSignal.reason
|
|
4
|
+
: undefined;
|
|
5
|
+
if (reason) {
|
|
6
|
+
if (reason instanceof Error) {
|
|
7
|
+
const abortError = new Error("Request aborted");
|
|
8
|
+
abortError.name = "AbortError";
|
|
9
|
+
abortError.cause = reason;
|
|
10
|
+
return abortError;
|
|
11
|
+
}
|
|
12
|
+
const abortError = new Error(String(reason));
|
|
13
|
+
abortError.name = "AbortError";
|
|
14
|
+
return abortError;
|
|
15
|
+
}
|
|
16
|
+
const abortError = new Error("Request aborted");
|
|
17
|
+
abortError.name = "AbortError";
|
|
18
|
+
return abortError;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
|
package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const getTransformedHeaders = (headers) => {
|
|
2
|
+
const transformedHeaders = {};
|
|
3
|
+
for (const name of Object.keys(headers)) {
|
|
4
|
+
const headerValues = headers[name];
|
|
5
|
+
transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues;
|
|
6
|
+
}
|
|
7
|
+
return transformedHeaders;
|
|
8
|
+
};
|
|
9
|
+
export { getTransformedHeaders };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { HttpResponse } from "@smithy/protocol-http";
|
|
2
|
+
import { buildQueryString } from "@smithy/querystring-builder";
|
|
3
|
+
import { Agent as hsAgent, request as hsRequest } from "node:https";
|
|
4
|
+
import { buildAbortError } from "./build-abort-error";
|
|
5
|
+
import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants";
|
|
6
|
+
import { getTransformedHeaders } from "./get-transformed-headers";
|
|
7
|
+
import { setConnectionTimeout } from "./set-connection-timeout";
|
|
8
|
+
import { setRequestTimeout } from "./set-request-timeout";
|
|
9
|
+
import { setSocketKeepAlive } from "./set-socket-keep-alive";
|
|
10
|
+
import { setSocketTimeout } from "./set-socket-timeout";
|
|
11
|
+
import { timing } from "./timing";
|
|
12
|
+
import { writeRequestBody } from "./write-request-body";
|
|
13
|
+
export const DEFAULT_REQUEST_TIMEOUT = 0;
|
|
14
|
+
let hAgent = undefined;
|
|
15
|
+
let hRequest = undefined;
|
|
16
|
+
export class NodeHttpHandler {
|
|
17
|
+
config;
|
|
18
|
+
configProvider;
|
|
19
|
+
socketWarningTimestamp = 0;
|
|
20
|
+
externalAgent = false;
|
|
21
|
+
metadata = { handlerProtocol: "http/1.1" };
|
|
22
|
+
static create(instanceOrOptions) {
|
|
23
|
+
if (typeof instanceOrOptions?.handle === "function") {
|
|
24
|
+
return instanceOrOptions;
|
|
25
|
+
}
|
|
26
|
+
return new NodeHttpHandler(instanceOrOptions);
|
|
27
|
+
}
|
|
28
|
+
static checkSocketUsage(agent, socketWarningTimestamp, logger = console) {
|
|
29
|
+
const { sockets, requests, maxSockets } = agent;
|
|
30
|
+
if (typeof maxSockets !== "number" || maxSockets === Infinity) {
|
|
31
|
+
return socketWarningTimestamp;
|
|
32
|
+
}
|
|
33
|
+
const interval = 15_000;
|
|
34
|
+
if (Date.now() - interval < socketWarningTimestamp) {
|
|
35
|
+
return socketWarningTimestamp;
|
|
36
|
+
}
|
|
37
|
+
if (sockets && requests) {
|
|
38
|
+
for (const origin in sockets) {
|
|
39
|
+
const socketsInUse = sockets[origin]?.length ?? 0;
|
|
40
|
+
const requestsEnqueued = requests[origin]?.length ?? 0;
|
|
41
|
+
if (socketsInUse >= maxSockets && requestsEnqueued >= 2 * maxSockets) {
|
|
42
|
+
logger?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${socketsInUse} and ${requestsEnqueued} additional requests are enqueued.
|
|
43
|
+
See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
|
|
44
|
+
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`);
|
|
45
|
+
return Date.now();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return socketWarningTimestamp;
|
|
50
|
+
}
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.configProvider = new Promise((resolve, reject) => {
|
|
53
|
+
if (typeof options === "function") {
|
|
54
|
+
options()
|
|
55
|
+
.then((_options) => {
|
|
56
|
+
resolve(this.resolveDefaultConfig(_options));
|
|
57
|
+
})
|
|
58
|
+
.catch(reject);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
resolve(this.resolveDefaultConfig(options));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
destroy() {
|
|
66
|
+
this.config?.httpAgent?.destroy();
|
|
67
|
+
this.config?.httpsAgent?.destroy();
|
|
68
|
+
}
|
|
69
|
+
async handle(request, { abortSignal, requestTimeout } = {}) {
|
|
70
|
+
if (!this.config) {
|
|
71
|
+
this.config = await this.configProvider;
|
|
72
|
+
}
|
|
73
|
+
const config = this.config;
|
|
74
|
+
const isSSL = request.protocol === "https:";
|
|
75
|
+
if (!isSSL && !this.config.httpAgent) {
|
|
76
|
+
this.config.httpAgent = await this.config.httpAgentProvider();
|
|
77
|
+
}
|
|
78
|
+
return new Promise((_resolve, _reject) => {
|
|
79
|
+
let writeRequestBodyPromise = undefined;
|
|
80
|
+
const timeouts = [];
|
|
81
|
+
const resolve = async (arg) => {
|
|
82
|
+
await writeRequestBodyPromise;
|
|
83
|
+
timeouts.forEach(timing.clearTimeout);
|
|
84
|
+
_resolve(arg);
|
|
85
|
+
};
|
|
86
|
+
const reject = async (arg) => {
|
|
87
|
+
await writeRequestBodyPromise;
|
|
88
|
+
timeouts.forEach(timing.clearTimeout);
|
|
89
|
+
_reject(arg);
|
|
90
|
+
};
|
|
91
|
+
if (abortSignal?.aborted) {
|
|
92
|
+
const abortError = buildAbortError(abortSignal);
|
|
93
|
+
reject(abortError);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const headers = request.headers ?? {};
|
|
97
|
+
const expectContinue = (headers.Expect ?? headers.expect) === "100-continue";
|
|
98
|
+
let agent = isSSL ? config.httpsAgent : config.httpAgent;
|
|
99
|
+
if (expectContinue && !this.externalAgent) {
|
|
100
|
+
agent = new (isSSL ? hsAgent : hAgent)({
|
|
101
|
+
keepAlive: false,
|
|
102
|
+
maxSockets: Infinity,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
timeouts.push(timing.setTimeout(() => {
|
|
106
|
+
this.socketWarningTimestamp = NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, config.logger);
|
|
107
|
+
}, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000)));
|
|
108
|
+
const queryString = buildQueryString(request.query || {});
|
|
109
|
+
let auth = undefined;
|
|
110
|
+
if (request.username != null || request.password != null) {
|
|
111
|
+
const username = request.username ?? "";
|
|
112
|
+
const password = request.password ?? "";
|
|
113
|
+
auth = `${username}:${password}`;
|
|
114
|
+
}
|
|
115
|
+
let path = request.path;
|
|
116
|
+
if (queryString) {
|
|
117
|
+
path += `?${queryString}`;
|
|
118
|
+
}
|
|
119
|
+
if (request.fragment) {
|
|
120
|
+
path += `#${request.fragment}`;
|
|
121
|
+
}
|
|
122
|
+
let hostname = request.hostname ?? "";
|
|
123
|
+
if (hostname[0] === "[" && hostname.endsWith("]")) {
|
|
124
|
+
hostname = request.hostname.slice(1, -1);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
hostname = request.hostname;
|
|
128
|
+
}
|
|
129
|
+
const nodeHttpsOptions = {
|
|
130
|
+
headers: request.headers,
|
|
131
|
+
host: hostname,
|
|
132
|
+
method: request.method,
|
|
133
|
+
path,
|
|
134
|
+
port: request.port,
|
|
135
|
+
agent,
|
|
136
|
+
auth,
|
|
137
|
+
};
|
|
138
|
+
const requestFunc = isSSL ? hsRequest : hRequest;
|
|
139
|
+
const req = requestFunc(nodeHttpsOptions, (res) => {
|
|
140
|
+
const httpResponse = new HttpResponse({
|
|
141
|
+
statusCode: res.statusCode || -1,
|
|
142
|
+
reason: res.statusMessage,
|
|
143
|
+
headers: getTransformedHeaders(res.headers),
|
|
144
|
+
body: res,
|
|
145
|
+
});
|
|
146
|
+
resolve({ response: httpResponse });
|
|
147
|
+
});
|
|
148
|
+
req.on("error", (err) => {
|
|
149
|
+
if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) {
|
|
150
|
+
reject(Object.assign(err, { name: "TimeoutError" }));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
reject(err);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (abortSignal) {
|
|
157
|
+
const onAbort = () => {
|
|
158
|
+
req.destroy();
|
|
159
|
+
const abortError = buildAbortError(abortSignal);
|
|
160
|
+
reject(abortError);
|
|
161
|
+
};
|
|
162
|
+
if (typeof abortSignal.addEventListener === "function") {
|
|
163
|
+
const signal = abortSignal;
|
|
164
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
165
|
+
req.once("close", () => signal.removeEventListener("abort", onAbort));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
abortSignal.onabort = onAbort;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const effectiveRequestTimeout = requestTimeout ?? config.requestTimeout;
|
|
172
|
+
timeouts.push(setConnectionTimeout(req, reject, config.connectionTimeout));
|
|
173
|
+
timeouts.push(setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console));
|
|
174
|
+
timeouts.push(setSocketTimeout(req, reject, config.socketTimeout));
|
|
175
|
+
const httpAgent = nodeHttpsOptions.agent;
|
|
176
|
+
if (typeof httpAgent === "object" && "keepAlive" in httpAgent) {
|
|
177
|
+
timeouts.push(setSocketKeepAlive(req, {
|
|
178
|
+
keepAlive: httpAgent.keepAlive,
|
|
179
|
+
keepAliveMsecs: httpAgent.keepAliveMsecs,
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e) => {
|
|
183
|
+
timeouts.forEach(timing.clearTimeout);
|
|
184
|
+
return _reject(e);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
updateHttpClientConfig(key, value) {
|
|
189
|
+
this.config = undefined;
|
|
190
|
+
this.configProvider = this.configProvider.then((config) => {
|
|
191
|
+
return {
|
|
192
|
+
...config,
|
|
193
|
+
[key]: value,
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
httpHandlerConfigs() {
|
|
198
|
+
return this.config ?? {};
|
|
199
|
+
}
|
|
200
|
+
resolveDefaultConfig(options) {
|
|
201
|
+
const { requestTimeout, connectionTimeout, socketTimeout, socketAcquisitionWarningTimeout, httpAgent, httpsAgent, throwOnRequestTimeout, logger, } = options || {};
|
|
202
|
+
const keepAlive = true;
|
|
203
|
+
const maxSockets = 50;
|
|
204
|
+
return {
|
|
205
|
+
connectionTimeout,
|
|
206
|
+
requestTimeout,
|
|
207
|
+
socketTimeout,
|
|
208
|
+
socketAcquisitionWarningTimeout,
|
|
209
|
+
throwOnRequestTimeout,
|
|
210
|
+
httpAgentProvider: async () => {
|
|
211
|
+
const { Agent, request } = await import("node:http");
|
|
212
|
+
hRequest = request;
|
|
213
|
+
hAgent = Agent;
|
|
214
|
+
if (httpAgent instanceof hAgent || typeof httpAgent?.destroy === "function") {
|
|
215
|
+
this.externalAgent = true;
|
|
216
|
+
return httpAgent;
|
|
217
|
+
}
|
|
218
|
+
return new hAgent({ keepAlive, maxSockets, ...httpAgent });
|
|
219
|
+
},
|
|
220
|
+
httpsAgent: (() => {
|
|
221
|
+
if (httpsAgent instanceof hsAgent || typeof httpsAgent?.destroy === "function") {
|
|
222
|
+
this.externalAgent = true;
|
|
223
|
+
return httpsAgent;
|
|
224
|
+
}
|
|
225
|
+
return new hsAgent({ keepAlive, maxSockets, ...httpsAgent });
|
|
226
|
+
})(),
|
|
227
|
+
logger,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import http2 from "node:http2";
|
|
2
|
+
import { NodeHttp2ConnectionPool } from "./node-http2-connection-pool";
|
|
3
|
+
export class NodeHttp2ConnectionManager {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
if (this.config.maxConcurrency && this.config.maxConcurrency <= 0) {
|
|
7
|
+
throw new RangeError("maxConcurrency must be greater than zero.");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
config;
|
|
11
|
+
sessionCache = new Map();
|
|
12
|
+
lease(requestContext, connectionConfiguration) {
|
|
13
|
+
const url = this.getUrlString(requestContext);
|
|
14
|
+
const existingPool = this.sessionCache.get(url);
|
|
15
|
+
if (existingPool) {
|
|
16
|
+
const existingSession = existingPool.poll();
|
|
17
|
+
if (existingSession && !this.config.disableConcurrency) {
|
|
18
|
+
return existingSession;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const session = http2.connect(url);
|
|
22
|
+
if (this.config.maxConcurrency) {
|
|
23
|
+
session.settings({ maxConcurrentStreams: this.config.maxConcurrency }, (err) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
throw new Error("Fail to set maxConcurrentStreams to " +
|
|
26
|
+
this.config.maxConcurrency +
|
|
27
|
+
"when creating new session for " +
|
|
28
|
+
requestContext.destination.toString());
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
session.unref();
|
|
33
|
+
const destroySessionCb = () => {
|
|
34
|
+
session.destroy();
|
|
35
|
+
this.deleteSession(url, session);
|
|
36
|
+
};
|
|
37
|
+
session.on("goaway", destroySessionCb);
|
|
38
|
+
session.on("error", destroySessionCb);
|
|
39
|
+
session.on("frameError", destroySessionCb);
|
|
40
|
+
session.on("close", () => this.deleteSession(url, session));
|
|
41
|
+
if (connectionConfiguration.requestTimeout) {
|
|
42
|
+
session.setTimeout(connectionConfiguration.requestTimeout, destroySessionCb);
|
|
43
|
+
}
|
|
44
|
+
const connectionPool = this.sessionCache.get(url) || new NodeHttp2ConnectionPool();
|
|
45
|
+
connectionPool.offerLast(session);
|
|
46
|
+
this.sessionCache.set(url, connectionPool);
|
|
47
|
+
return session;
|
|
48
|
+
}
|
|
49
|
+
deleteSession(authority, session) {
|
|
50
|
+
const existingConnectionPool = this.sessionCache.get(authority);
|
|
51
|
+
if (!existingConnectionPool) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!existingConnectionPool.contains(session)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
existingConnectionPool.remove(session);
|
|
58
|
+
this.sessionCache.set(authority, existingConnectionPool);
|
|
59
|
+
}
|
|
60
|
+
release(requestContext, session) {
|
|
61
|
+
const cacheKey = this.getUrlString(requestContext);
|
|
62
|
+
this.sessionCache.get(cacheKey)?.offerLast(session);
|
|
63
|
+
}
|
|
64
|
+
destroy() {
|
|
65
|
+
for (const [key, connectionPool] of this.sessionCache) {
|
|
66
|
+
for (const session of connectionPool) {
|
|
67
|
+
if (!session.destroyed) {
|
|
68
|
+
session.destroy();
|
|
69
|
+
}
|
|
70
|
+
connectionPool.remove(session);
|
|
71
|
+
}
|
|
72
|
+
this.sessionCache.delete(key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setMaxConcurrentStreams(maxConcurrentStreams) {
|
|
76
|
+
if (maxConcurrentStreams && maxConcurrentStreams <= 0) {
|
|
77
|
+
throw new RangeError("maxConcurrentStreams must be greater than zero.");
|
|
78
|
+
}
|
|
79
|
+
this.config.maxConcurrency = maxConcurrentStreams;
|
|
80
|
+
}
|
|
81
|
+
setDisableConcurrentStreams(disableConcurrentStreams) {
|
|
82
|
+
this.config.disableConcurrency = disableConcurrentStreams;
|
|
83
|
+
}
|
|
84
|
+
getUrlString(request) {
|
|
85
|
+
return request.destination.toString();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/packages/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class NodeHttp2ConnectionPool {
|
|
2
|
+
sessions = [];
|
|
3
|
+
constructor(sessions) {
|
|
4
|
+
this.sessions = sessions ?? [];
|
|
5
|
+
}
|
|
6
|
+
poll() {
|
|
7
|
+
if (this.sessions.length > 0) {
|
|
8
|
+
return this.sessions.shift();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
offerLast(session) {
|
|
12
|
+
this.sessions.push(session);
|
|
13
|
+
}
|
|
14
|
+
contains(session) {
|
|
15
|
+
return this.sessions.includes(session);
|
|
16
|
+
}
|
|
17
|
+
remove(session) {
|
|
18
|
+
this.sessions = this.sessions.filter((s) => s !== session);
|
|
19
|
+
}
|
|
20
|
+
[Symbol.iterator]() {
|
|
21
|
+
return this.sessions[Symbol.iterator]();
|
|
22
|
+
}
|
|
23
|
+
destroy(connection) {
|
|
24
|
+
for (const session of this.sessions) {
|
|
25
|
+
if (session === connection) {
|
|
26
|
+
if (!session.destroyed) {
|
|
27
|
+
session.destroy();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { HttpResponse } from "@smithy/protocol-http";
|
|
2
|
+
import { buildQueryString } from "@smithy/querystring-builder";
|
|
3
|
+
import { constants } from "node:http2";
|
|
4
|
+
import { buildAbortError } from "./build-abort-error";
|
|
5
|
+
import { getTransformedHeaders } from "./get-transformed-headers";
|
|
6
|
+
import { NodeHttp2ConnectionManager } from "./node-http2-connection-manager";
|
|
7
|
+
import { writeRequestBody } from "./write-request-body";
|
|
8
|
+
export class NodeHttp2Handler {
|
|
9
|
+
config;
|
|
10
|
+
configProvider;
|
|
11
|
+
metadata = { handlerProtocol: "h2" };
|
|
12
|
+
connectionManager = new NodeHttp2ConnectionManager({});
|
|
13
|
+
static create(instanceOrOptions) {
|
|
14
|
+
if (typeof instanceOrOptions?.handle === "function") {
|
|
15
|
+
return instanceOrOptions;
|
|
16
|
+
}
|
|
17
|
+
return new NodeHttp2Handler(instanceOrOptions);
|
|
18
|
+
}
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.configProvider = new Promise((resolve, reject) => {
|
|
21
|
+
if (typeof options === "function") {
|
|
22
|
+
options()
|
|
23
|
+
.then((opts) => {
|
|
24
|
+
resolve(opts || {});
|
|
25
|
+
})
|
|
26
|
+
.catch(reject);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
resolve(options || {});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
this.connectionManager.destroy();
|
|
35
|
+
}
|
|
36
|
+
async handle(request, { abortSignal, requestTimeout } = {}) {
|
|
37
|
+
if (!this.config) {
|
|
38
|
+
this.config = await this.configProvider;
|
|
39
|
+
this.connectionManager.setDisableConcurrentStreams(this.config.disableConcurrentStreams || false);
|
|
40
|
+
if (this.config.maxConcurrentStreams) {
|
|
41
|
+
this.connectionManager.setMaxConcurrentStreams(this.config.maxConcurrentStreams);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config;
|
|
45
|
+
const effectiveRequestTimeout = requestTimeout ?? configRequestTimeout;
|
|
46
|
+
return new Promise((_resolve, _reject) => {
|
|
47
|
+
let fulfilled = false;
|
|
48
|
+
let writeRequestBodyPromise = undefined;
|
|
49
|
+
const resolve = async (arg) => {
|
|
50
|
+
await writeRequestBodyPromise;
|
|
51
|
+
_resolve(arg);
|
|
52
|
+
};
|
|
53
|
+
const reject = async (arg) => {
|
|
54
|
+
await writeRequestBodyPromise;
|
|
55
|
+
_reject(arg);
|
|
56
|
+
};
|
|
57
|
+
if (abortSignal?.aborted) {
|
|
58
|
+
fulfilled = true;
|
|
59
|
+
const abortError = buildAbortError(abortSignal);
|
|
60
|
+
reject(abortError);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { hostname, method, port, protocol, query } = request;
|
|
64
|
+
let auth = "";
|
|
65
|
+
if (request.username != null || request.password != null) {
|
|
66
|
+
const username = request.username ?? "";
|
|
67
|
+
const password = request.password ?? "";
|
|
68
|
+
auth = `${username}:${password}@`;
|
|
69
|
+
}
|
|
70
|
+
const authority = `${protocol}//${auth}${hostname}${port ? `:${port}` : ""}`;
|
|
71
|
+
const requestContext = { destination: new URL(authority) };
|
|
72
|
+
const session = this.connectionManager.lease(requestContext, {
|
|
73
|
+
requestTimeout: this.config?.sessionTimeout,
|
|
74
|
+
disableConcurrentStreams: disableConcurrentStreams || false,
|
|
75
|
+
});
|
|
76
|
+
const rejectWithDestroy = (err) => {
|
|
77
|
+
if (disableConcurrentStreams) {
|
|
78
|
+
this.destroySession(session);
|
|
79
|
+
}
|
|
80
|
+
fulfilled = true;
|
|
81
|
+
reject(err);
|
|
82
|
+
};
|
|
83
|
+
const queryString = buildQueryString(query || {});
|
|
84
|
+
let path = request.path;
|
|
85
|
+
if (queryString) {
|
|
86
|
+
path += `?${queryString}`;
|
|
87
|
+
}
|
|
88
|
+
if (request.fragment) {
|
|
89
|
+
path += `#${request.fragment}`;
|
|
90
|
+
}
|
|
91
|
+
const req = session.request({
|
|
92
|
+
...request.headers,
|
|
93
|
+
[constants.HTTP2_HEADER_PATH]: path,
|
|
94
|
+
[constants.HTTP2_HEADER_METHOD]: method,
|
|
95
|
+
});
|
|
96
|
+
session.ref();
|
|
97
|
+
req.on("response", (headers) => {
|
|
98
|
+
const httpResponse = new HttpResponse({
|
|
99
|
+
statusCode: headers[":status"] || -1,
|
|
100
|
+
headers: getTransformedHeaders(headers),
|
|
101
|
+
body: req,
|
|
102
|
+
});
|
|
103
|
+
fulfilled = true;
|
|
104
|
+
resolve({ response: httpResponse });
|
|
105
|
+
if (disableConcurrentStreams) {
|
|
106
|
+
session.close();
|
|
107
|
+
this.connectionManager.deleteSession(authority, session);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (effectiveRequestTimeout) {
|
|
111
|
+
req.setTimeout(effectiveRequestTimeout, () => {
|
|
112
|
+
req.close();
|
|
113
|
+
const timeoutError = new Error(`Stream timed out because of no activity for ${effectiveRequestTimeout} ms`);
|
|
114
|
+
timeoutError.name = "TimeoutError";
|
|
115
|
+
rejectWithDestroy(timeoutError);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (abortSignal) {
|
|
119
|
+
const onAbort = () => {
|
|
120
|
+
req.close();
|
|
121
|
+
const abortError = buildAbortError(abortSignal);
|
|
122
|
+
rejectWithDestroy(abortError);
|
|
123
|
+
};
|
|
124
|
+
if (typeof abortSignal.addEventListener === "function") {
|
|
125
|
+
const signal = abortSignal;
|
|
126
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
127
|
+
req.once("close", () => signal.removeEventListener("abort", onAbort));
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
abortSignal.onabort = onAbort;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
req.on("frameError", (type, code, id) => {
|
|
134
|
+
rejectWithDestroy(new Error(`Frame type id ${type} in stream id ${id} has failed with code ${code}.`));
|
|
135
|
+
});
|
|
136
|
+
req.on("error", rejectWithDestroy);
|
|
137
|
+
req.on("aborted", () => {
|
|
138
|
+
rejectWithDestroy(new Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${req.rstCode}.`));
|
|
139
|
+
});
|
|
140
|
+
req.on("close", () => {
|
|
141
|
+
session.unref();
|
|
142
|
+
if (disableConcurrentStreams) {
|
|
143
|
+
session.destroy();
|
|
144
|
+
}
|
|
145
|
+
if (!fulfilled) {
|
|
146
|
+
rejectWithDestroy(new Error("Unexpected error: http2 request did not get a response"));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
updateHttpClientConfig(key, value) {
|
|
153
|
+
this.config = undefined;
|
|
154
|
+
this.configProvider = this.configProvider.then((config) => {
|
|
155
|
+
return {
|
|
156
|
+
...config,
|
|
157
|
+
[key]: value,
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
httpHandlerConfigs() {
|
|
162
|
+
return this.config ?? {};
|
|
163
|
+
}
|
|
164
|
+
destroySession(session) {
|
|
165
|
+
if (!session.destroyed) {
|
|
166
|
+
session.destroy();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
export class ReadFromBuffers extends Readable {
|
|
3
|
+
buffersToRead;
|
|
4
|
+
numBuffersRead = 0;
|
|
5
|
+
errorAfter;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.buffersToRead = options.buffers;
|
|
9
|
+
this.errorAfter = typeof options.errorAfter === "number" ? options.errorAfter : -1;
|
|
10
|
+
}
|
|
11
|
+
_read() {
|
|
12
|
+
if (this.errorAfter !== -1 && this.errorAfter === this.numBuffersRead) {
|
|
13
|
+
this.emit("error", new Error("Mock Error"));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (this.numBuffersRead >= this.buffersToRead.length) {
|
|
17
|
+
return this.push(null);
|
|
18
|
+
}
|
|
19
|
+
return this.push(this.buffersToRead[this.numBuffersRead++]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { createServer as createHttpServer } from "node:http";
|
|
3
|
+
import { createServer as createHttp2Server } from "node:http2";
|
|
4
|
+
import { createServer as createHttpsServer } from "node:https";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { timing } from "./timing";
|
|
8
|
+
const fixturesDir = join(__dirname, "..", "fixtures");
|
|
9
|
+
const setResponseHeaders = (response, headers) => {
|
|
10
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
11
|
+
response.setHeader(key, value);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const setResponseBody = (response, body) => {
|
|
15
|
+
if (body instanceof Readable) {
|
|
16
|
+
body.pipe(response);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
response.end(body);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const createResponseFunction = (httpResp) => (request, response) => {
|
|
23
|
+
response.statusCode = httpResp.statusCode;
|
|
24
|
+
if (httpResp.reason) {
|
|
25
|
+
response.statusMessage = httpResp.reason;
|
|
26
|
+
}
|
|
27
|
+
setResponseHeaders(response, httpResp.headers);
|
|
28
|
+
setResponseBody(response, httpResp.body);
|
|
29
|
+
};
|
|
30
|
+
export const createResponseFunctionWithDelay = (httpResp, delay) => (request, response) => {
|
|
31
|
+
response.statusCode = httpResp.statusCode;
|
|
32
|
+
if (httpResp.reason) {
|
|
33
|
+
response.statusMessage = httpResp.reason;
|
|
34
|
+
}
|
|
35
|
+
setResponseHeaders(response, httpResp.headers);
|
|
36
|
+
timing.setTimeout(() => setResponseBody(response, httpResp.body), delay);
|
|
37
|
+
};
|
|
38
|
+
export const createContinueResponseFunction = (httpResp) => (request, response) => {
|
|
39
|
+
response.writeContinue();
|
|
40
|
+
timing.setTimeout(() => {
|
|
41
|
+
createResponseFunction(httpResp)(request, response);
|
|
42
|
+
}, 100);
|
|
43
|
+
};
|
|
44
|
+
export const createMockHttpsServer = () => {
|
|
45
|
+
const server = createHttpsServer({
|
|
46
|
+
key: readFileSync(join(fixturesDir, "test-server-key.pem")),
|
|
47
|
+
cert: readFileSync(join(fixturesDir, "test-server-cert.pem")),
|
|
48
|
+
});
|
|
49
|
+
return server;
|
|
50
|
+
};
|
|
51
|
+
export const createMockHttpServer = () => {
|
|
52
|
+
const server = createHttpServer();
|
|
53
|
+
return server;
|
|
54
|
+
};
|
|
55
|
+
export const createMockHttp2Server = () => {
|
|
56
|
+
const server = createHttp2Server();
|
|
57
|
+
return server;
|
|
58
|
+
};
|
|
59
|
+
export const createMirrorResponseFunction = (httpResp) => (request, response) => {
|
|
60
|
+
const bufs = [];
|
|
61
|
+
request.on("data", (chunk) => {
|
|
62
|
+
bufs.push(chunk);
|
|
63
|
+
});
|
|
64
|
+
request.on("end", () => {
|
|
65
|
+
response.statusCode = httpResp.statusCode;
|
|
66
|
+
setResponseHeaders(response, httpResp.headers);
|
|
67
|
+
setResponseBody(response, Buffer.concat(bufs));
|
|
68
|
+
});
|
|
69
|
+
request.on("error", (err) => {
|
|
70
|
+
response.statusCode = 500;
|
|
71
|
+
setResponseHeaders(response, httpResp.headers);
|
|
72
|
+
setResponseBody(response, err.message);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export const getResponseBody = (response) => {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const bufs = [];
|
|
78
|
+
response.body.on("data", function (d) {
|
|
79
|
+
bufs.push(d);
|
|
80
|
+
});
|
|
81
|
+
response.body.on("end", function () {
|
|
82
|
+
resolve(Buffer.concat(bufs).toString());
|
|
83
|
+
});
|
|
84
|
+
response.body.on("error", (err) => {
|
|
85
|
+
reject(err);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|