@jini-ai/provider-plugins 0.7.3-next.1 → 0.7.3-next.3
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/CHANGELOG.md +2 -0
- package/catalog.json +25 -20
- package/dist/model-proxy-anthropic/index.d.ts +18 -0
- package/dist/model-proxy-anthropic/index.js +32 -0
- package/dist/model-proxy-azure/index.d.ts +19 -0
- package/dist/model-proxy-azure/index.js +32 -0
- package/dist/model-proxy-google/index.d.ts +18 -0
- package/dist/model-proxy-google/index.js +25 -0
- package/dist/model-proxy-ollama/index.d.ts +8 -0
- package/dist/model-proxy-ollama/index.js +13 -0
- package/dist/model-proxy-openai/index.d.ts +8 -0
- package/dist/model-proxy-openai/index.js +13 -0
- package/dist/observability-opentelemetry/contract.d.ts +2 -0
- package/dist/observability-opentelemetry/otel-port.d.ts +3 -1
- package/dist/observability-opentelemetry/otel-port.js +31 -15
- package/dist/xai/media/index.d.ts +67 -0
- package/dist/xai/media/index.js +132 -0
- package/dist/xai/oauth-port.d.ts +132 -0
- package/dist/xai/oauth-port.js +5 -0
- package/dist/xai/preset.d.ts +22 -0
- package/dist/xai/preset.js +28 -0
- package/dist/xai/routes.d.ts +108 -0
- package/dist/xai/routes.js +658 -0
- package/package.json +68 -27
- package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +3 -3
- package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/package-license.json +1 -1
- package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +2 -2
- package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/README.md +1 -1
- package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +4 -4
- package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/package-license.json +1 -1
- package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +2 -2
- package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/client/provider.js +1 -1
- package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +3 -3
- package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/package-license.json +1 -1
- package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +2 -2
- package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/package-license.json +1 -1
- package/plugins/fixture-provider/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +2 -2
- package/plugins/fixture-provider/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/formspree/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +2 -2
- package/plugins/formspree/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/google-forms/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +2 -2
- package/plugins/google-forms/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/README.md +1 -1
- package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +5 -5
- package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_core/package-license.json +1 -1
- package/plugins/observability-opentelemetry/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +42 -23
- package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/README.md +1 -1
- package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +5 -5
- package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_core/package-license.json +1 -1
- package/plugins/observability-sentry/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +19 -8
- package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/jini.plugin.json +2 -2
- package/plugins/payments-stripe/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/xai/0.7.3-next.3/jini.plugin.json +48 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_core/LICENSE +201 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_core/package-license.json +5 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_protocol/LICENSE +201 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_protocol/package-license.json +5 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_provider-plugins/LICENSE +201 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_provider-plugins/NOTICE +28 -0
- package/plugins/xai/0.7.3-next.3/licenses/_jini-ai_provider-plugins/package-license.json +5 -0
- package/plugins/xai/0.7.3-next.3/licenses/zod/LICENSE +21 -0
- package/plugins/xai/0.7.3-next.3/licenses/zod/package-license.json +5 -0
- package/plugins/xai/0.7.3-next.3/server/index.mjs +1597 -0
- package/plugins/fixture-provider/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- package/plugins/formspree/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- package/plugins/google-forms/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- package/plugins/observability-opentelemetry/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- package/plugins/observability-sentry/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- package/plugins/payments-stripe/0.7.3-next.1/licenses/_jini-ai_provider-plugins/package-license.json +0 -5
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/CHANGELOG.md +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/LICENSE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/NOTICE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/README.md +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse/LICENSE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse/LICENSE-SOURCE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse/SOURCE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse/package-license.json +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse-core/LICENSE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse-core/LICENSE-SOURCE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse-core/SOURCE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/langfuse-core/package-license.json +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/mustache/LICENSE +0 -0
- /package/plugins/ai-trace-langfuse/{0.7.3-next.1 → 0.7.3-next.3}/licenses/mustache/package-license.json +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/CHANGELOG.md +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/LICENSE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/NOTICE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_posthog_core/LICENSE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_posthog_core/package-license.json +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/posthog-js/LICENSE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/posthog-js/package-license.json +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/posthog-node/LICENSE +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/licenses/posthog-node/package-license.json +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/server/consent-adapter.mjs +0 -0
- /package/plugins/analytics-posthog/{0.7.3-next.1 → 0.7.3-next.3}/server/posthog-browser.js +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/client/styles.css +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/echarts/LICENSE +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/echarts/NOTICE +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/echarts/package-license.json +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/tslib/LICENSE.txt +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/tslib/package-license.json +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/zrender/LICENSE +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/zrender/package-license.json +0 -0
- /package/plugins/charts-echarts/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/client/provider.js +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/client/styles.css +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_reduxjs_toolkit/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_reduxjs_toolkit/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/clsx/license +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/clsx/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-array/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-array/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-color/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-color/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-format/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-format/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-interpolate/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-interpolate/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-path/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-path/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-scale/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-scale/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-shape/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-shape/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-time/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-time/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-time-format/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/d3-time-format/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/decimal.js-light/LICENCE.md +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/decimal.js-light/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/es-toolkit/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/es-toolkit/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/eventemitter3/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/eventemitter3/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/immer/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/immer/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/internmap/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/internmap/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-dom/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-dom/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-is/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-is/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-redux/LICENSE.md +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/react-redux/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/recharts/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/recharts/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/redux/LICENSE.md +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/redux/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/redux-thunk/LICENSE.md +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/redux-thunk/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/reselect/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/reselect/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/scheduler/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/scheduler/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/tiny-invariant/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/tiny-invariant/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/use-sync-external-store/LICENSE +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/use-sync-external-store/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/victory-vendor/LICENSE.txt +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/licenses/victory-vendor/package-license.json +0 -0
- /package/plugins/charts-recharts/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
- /package/plugins/fixture-provider/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/fixture-provider/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/fixture-provider/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
- /package/plugins/formspree/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/formspree/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/formspree/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
- /package/plugins/google-forms/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/google-forms/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/google-forms/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/CHANGELOG.md +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/NOTICE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_core/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api-logs/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api-logs/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_context-async-hooks/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_context-async-hooks/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_core/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_core/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_otlp-exporter-base/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_otlp-exporter-base/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_otlp-transformer/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_otlp-transformer/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_resources/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_resources/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-metrics/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-metrics/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace-base/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace-base/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace-node/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_sdk-trace-node/package-license.json +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_semantic-conventions/LICENSE +0 -0
- /package/plugins/observability-opentelemetry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_semantic-conventions/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/CHANGELOG.md +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/NOTICE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_core/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_opentelemetry_api/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_conventions/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_conventions/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_core/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_core/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_node/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_node/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_opentelemetry/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_opentelemetry/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-runtime-injection/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-runtime-injection/LICENSE-SOURCE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-runtime-injection/package-license.json +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-utils/LICENSE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-utils/LICENSE-SOURCE +0 -0
- /package/plugins/observability-sentry/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_sentry_server-utils/package-license.json +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/CHANGELOG.md +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/LICENSE +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/NOTICE +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/README.md +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/LICENSE +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/licenses/_jini-ai_provider-plugins/NOTICE +0 -0
- /package/plugins/payments-stripe/{0.7.3-next.1 → 0.7.3-next.3}/server/index.mjs +0 -0
|
@@ -0,0 +1,1597 @@
|
|
|
1
|
+
import { createRequire as __jiniCreateRequire } from "node:module"; const require = __jiniCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/xai/media/index.ts
|
|
4
|
+
var XAI_MEDIA_PROVIDER_ID = "grok";
|
|
5
|
+
var PROVIDER_ID = XAI_MEDIA_PROVIDER_ID;
|
|
6
|
+
var DEFAULT_BASE_URL = "https://api.x.ai/v1";
|
|
7
|
+
var NO_CREDENTIAL_MESSAGE = "no xAI credential \u2014 configure an API key or set XAI_API_KEY.";
|
|
8
|
+
var TTS_DEFAULT_VOICE_ID = "eve";
|
|
9
|
+
var TTS_DEFAULT_LANGUAGE = "en";
|
|
10
|
+
var baseUrlOf = (credentials) => (credentials.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
11
|
+
function createImageAdapter({ mediaWire }, _optional = {}) {
|
|
12
|
+
return {
|
|
13
|
+
requireCredential: mediaWire.requireApiKey({ message: NO_CREDENTIAL_MESSAGE }),
|
|
14
|
+
buildRequest({ ctx, credentials }) {
|
|
15
|
+
const apiKey = credentials.apiKey;
|
|
16
|
+
const aspectRatio = mediaWire.imageAspectFor({ aspect: ctx.aspect });
|
|
17
|
+
const body = {
|
|
18
|
+
model: ctx.wireModel,
|
|
19
|
+
prompt: ctx.prompt || "A high-quality reference image.",
|
|
20
|
+
n: 1,
|
|
21
|
+
aspect_ratio: aspectRatio,
|
|
22
|
+
response_format: "b64_json"
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
url: mediaWire.imageGenerationUrl({ baseUrl: baseUrlOf(credentials) }),
|
|
26
|
+
init: mediaWire.jsonPostInit({ ctx, body }, { apiKey }),
|
|
27
|
+
meta: { wireModel: ctx.wireModel, aspectRatio }
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
async parseResponse({ resp, ctx, request }) {
|
|
31
|
+
const data = await mediaWire.parseJson({ resp, providerTag: "grok image" });
|
|
32
|
+
const bytes = await mediaWire.imageBytesFromData({ data, providerTag: "grok image", ctx });
|
|
33
|
+
return {
|
|
34
|
+
bytes,
|
|
35
|
+
providerNote: `grok/${request.meta.wireModel} \xB7 ${request.meta.aspectRatio} \xB7 ${bytes.length} bytes`,
|
|
36
|
+
suggestedExt: mediaWire.sniffImageExt({ bytes })
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createSpeechAdapter({ mediaWire }, _optional = {}) {
|
|
42
|
+
return {
|
|
43
|
+
requireCredential: mediaWire.requireApiKey({ message: NO_CREDENTIAL_MESSAGE }),
|
|
44
|
+
buildRequest({ ctx, credentials }) {
|
|
45
|
+
const apiKey = credentials.apiKey;
|
|
46
|
+
const text = ctx.prompt && ctx.prompt.trim() || "This is a test.";
|
|
47
|
+
const voiceId = ctx.voice && ctx.voice.trim() || TTS_DEFAULT_VOICE_ID;
|
|
48
|
+
const language = ctx.language.trim() || TTS_DEFAULT_LANGUAGE;
|
|
49
|
+
return {
|
|
50
|
+
url: `${baseUrlOf(credentials)}/tts`,
|
|
51
|
+
init: mediaWire.jsonPostInit({ ctx, body: { text, voice_id: voiceId, language } }, { apiKey }),
|
|
52
|
+
meta: { wireModel: ctx.wireModel, voiceId, language }
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
parseResponse: mediaWire.createRawBytesParser({
|
|
56
|
+
errorTag: "xai tts",
|
|
57
|
+
zeroBytesMessage: "xai tts response had zero bytes",
|
|
58
|
+
note: ({ bytes, meta }) => `xai/${meta.wireModel} \xB7 voice=${meta.voiceId} \xB7 ${meta.language} \xB7 ${bytes.length} bytes`,
|
|
59
|
+
suggestedExt: ".mp3"
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createXaiMediaContribution({ mediaWire }, _optional = {}) {
|
|
64
|
+
const model = (id, hint, caps) => ({ id, label: id, hint, provider: PROVIDER_ID, caps });
|
|
65
|
+
return {
|
|
66
|
+
provider: { id: PROVIDER_ID, label: "xAI Grok Imagine", hint: "grok-imagine \u2014 image + video with native audio", integrated: true, defaultBaseUrl: DEFAULT_BASE_URL },
|
|
67
|
+
models: [
|
|
68
|
+
{ ...model("grok-imagine-image", "xAI \xB7 2K text-to-image", ["t2i"]), surface: "image" },
|
|
69
|
+
{ ...model("grok-imagine-video", "xAI \xB7 720p t2v + i2v + native audio", ["t2v", "i2v", "audio"]), surface: "video" },
|
|
70
|
+
{ ...model("grok-tts", "xAI \xB7 multilingual \xB7 uses Grok subscription", ["tts"]), surface: "audio", audioKind: "speech" }
|
|
71
|
+
],
|
|
72
|
+
adapters: {
|
|
73
|
+
image: createImageAdapter({ mediaWire }),
|
|
74
|
+
"audio:speech": createSpeechAdapter({ mediaWire })
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ../core/dist/secret-shapes.js
|
|
80
|
+
var PEM_PATTERN_NAME = "PEM private key block";
|
|
81
|
+
var PRIVATE_KEY_BLOCK = /-----BEGIN ([A-Z ]*)PRIVATE KEY-----[\s\S]*?(?:-----END \1PRIVATE KEY-----|$)/;
|
|
82
|
+
var SECRET_SHAPE_PATTERNS = [
|
|
83
|
+
{ name: "Google API key (AIza)", pattern: /(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9_-])/ },
|
|
84
|
+
{ name: "Anthropic API key (sk-ant-)", pattern: /(?<![A-Za-z0-9_-])sk-ant-[A-Za-z0-9_-]{90,}/ },
|
|
85
|
+
{ name: "generic sk- secret key (OpenAI-shaped)", pattern: /(?<![A-Za-z0-9_-])sk-[A-Za-z0-9]{40,}/ },
|
|
86
|
+
{ name: "GitHub personal access token (classic, ghp_)", pattern: /(?<!\w)ghp_\w{36}(?!\w)/ },
|
|
87
|
+
{ name: "GitHub OAuth token (gho_)", pattern: /(?<!\w)gho_\w{36}(?!\w)/ },
|
|
88
|
+
{ name: "GitHub fine-grained PAT", pattern: /(?<!\w)github_pat_\w{80,}/ },
|
|
89
|
+
{ name: "npm access token", pattern: /(?<!\w)npm_\w{36}(?!\w)/ },
|
|
90
|
+
{ name: "Slack token", pattern: /(?<![A-Za-z0-9-])xox[baprs]-[A-Za-z0-9-]{12,}/ },
|
|
91
|
+
{ name: "AWS access key ID", pattern: /(?<![0-9A-Z])AKIA[0-9A-Z]{16}(?![0-9A-Z])/ },
|
|
92
|
+
{ name: "Fastmail app password (fm2_)", pattern: /(?<![A-Za-z0-9+/=])fm2_[A-Za-z0-9+/=]{20,}/ },
|
|
93
|
+
{ name: PEM_PATTERN_NAME, pattern: PRIVATE_KEY_BLOCK }
|
|
94
|
+
];
|
|
95
|
+
var AGENT_FAILURE_TOKEN_SHAPES = [
|
|
96
|
+
/AIza[\w-]+/,
|
|
97
|
+
// Google API key
|
|
98
|
+
/AQ\.[\w.\/-]+/,
|
|
99
|
+
// AI Studio key
|
|
100
|
+
/sk-[\w.-]+/,
|
|
101
|
+
// OpenAI-style secret key
|
|
102
|
+
/gh[pousr]_\w+/,
|
|
103
|
+
// GitHub token
|
|
104
|
+
/github_pat_\w+/,
|
|
105
|
+
// GitHub fine-grained token
|
|
106
|
+
/ya29\.[\w.-]+/,
|
|
107
|
+
// Google OAuth access token
|
|
108
|
+
/eyJ[\w-]+\.[\w-]+(?:\.[\w-]+)?/
|
|
109
|
+
// JWT
|
|
110
|
+
];
|
|
111
|
+
var AGENT_FAILURE_SECRET_SHAPE_RE = new RegExp(`\\b(?:${AGENT_FAILURE_TOKEN_SHAPES.map((shape) => shape.source).join("|")})`, "g");
|
|
112
|
+
|
|
113
|
+
// ../core/dist/redaction-patterns.js
|
|
114
|
+
var IPV4_OCTET = "(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)";
|
|
115
|
+
var PHONE_SEPARATOR = "[\\s.-]?";
|
|
116
|
+
var PHONE_COUNTRY_CODE = /(?:\+?\d{1,3}[\s.-]?)?/;
|
|
117
|
+
var PHONE_AREA_CODE = /(?:\(\d{3}\)|\d{3})/;
|
|
118
|
+
var PATTERNS = [
|
|
119
|
+
// Langfuse public/secret keys (pk-lf- / sk-lf-). Must run before the
|
|
120
|
+
// generic sk- rule so the more specific label wins.
|
|
121
|
+
{ name: "langfuse_key", regex: /\b(?:pk|sk)-lf-[A-Za-z0-9-]{16,}\b/g },
|
|
122
|
+
// Anthropic / OpenAI-style keys: 'sk-' + optional sub-prefix + base64-ish.
|
|
123
|
+
// Both vendors plus a long tail of OpenAI-compatible providers (DeepSeek,
|
|
124
|
+
// MiniMax, Together, etc.) ship keys in this shape, so a single rule
|
|
125
|
+
// covers most "sk-..." secrets a user might paste into a prompt.
|
|
126
|
+
{ name: "sk_key", regex: /\bsk-(?:proj-|live-|test-|ant-)?[A-Za-z0-9_-]{20,}\b/g },
|
|
127
|
+
// GitHub personal / OAuth / server / user-server / refresh tokens.
|
|
128
|
+
{ name: "github_token", regex: /\bgh[opsur]_[A-Za-z0-9]{36,}\b/g },
|
|
129
|
+
// GitHub legacy 40-hex personal access tokens that ship with no prefix
|
|
130
|
+
// are indistinguishable from a sha1 hash, so we don't try to match them
|
|
131
|
+
// here — false positives would be brutal in commit logs / artifact slugs.
|
|
132
|
+
// AWS access key id. The matching secret access key is just 40 base64
|
|
133
|
+
// chars with no fixed shape, so we cannot reliably redact it without
|
|
134
|
+
// huge collateral damage; flagging the access key id at least
|
|
135
|
+
// signals a paste happened.
|
|
136
|
+
{ name: "aws_access_key", regex: /\bAKIA[0-9A-Z]{16}\b/g },
|
|
137
|
+
// Google API keys — legacy AIza… (Maps / AI Studio) and service-account-
|
|
138
|
+
// bound AQ.… keys AI Studio now issues. AQ. must run before the generic
|
|
139
|
+
// sk_ rule would mis-label unrelated tokens.
|
|
140
|
+
{ name: "google_api_key", regex: /\bAQ\.[A-Za-z0-9_-]{20,}\b/g },
|
|
141
|
+
{ name: "google_api_key", regex: /\bAIza[0-9A-Za-z_-]{35}\b/g },
|
|
142
|
+
// Slack tokens.
|
|
143
|
+
{ name: "slack_token", regex: /\bxox[abprs]-[0-9A-Za-z-]{10,}\b/g },
|
|
144
|
+
// Stripe keys.
|
|
145
|
+
{ name: "stripe_key", regex: /\b(?:sk|pk|rk)_(?:live|test)_[0-9a-zA-Z]{16,}\b/g },
|
|
146
|
+
// JSON Web Tokens. The "header.payload.signature" triple is distinctive
|
|
147
|
+
// enough that false positives are rare (the literal "eyJ" prefix is the
|
|
148
|
+
// base64 encoding of '{"' which is how every JOSE header starts).
|
|
149
|
+
{ name: "jwt", regex: /(?<!\w)(?<!(?<!\w)eyJ[A-Za-z0-9_-]*?)eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g },
|
|
150
|
+
// Bearer tokens in HTTP Authorization header copy/paste. We only match
|
|
151
|
+
// the value, not the literal 'Bearer ', so the marker stays readable in
|
|
152
|
+
// the redacted output ("Authorization: Bearer [REDACTED:bearer_token]").
|
|
153
|
+
// The leading lookahead only lets the lookbehind run where a value can start, so a long
|
|
154
|
+
// whitespace run is not rescanned from every position inside it.
|
|
155
|
+
{ name: "bearer_token", regex: /(?=[A-Za-z0-9._~+/-])(?<=\bBearer\s+)[A-Za-z0-9._~+/-]{16,}={0,2}/g },
|
|
156
|
+
// Email addresses. Conservative enough to require a TLD-like trailer. The local part is
|
|
157
|
+
// bounded at the RFC 5321 limit of 64: an unbounded run rescanned the suffix from every word
|
|
158
|
+
// boundary, so `'a.'.repeat(20000)` blocked ~3 s on a large tool response. Matching starts at
|
|
159
|
+
// the `@` and reads the local part in a lookbehind (captured as `local`): starting at every word
|
|
160
|
+
// boundary still cost up to 64 steps per position, ~2.5 s on 10 MiB of `'eyJ-'`.
|
|
161
|
+
// Alphabetic TLDs preserve versioned package paths in error stacks (e.g. pkg@1.2.3).
|
|
162
|
+
{ name: "email", regex: /@(?<=\b(?<local>[\w.+-]{1,64})@)(?:[\w-]+\.)+[A-Za-z]{2,}\b/g },
|
|
163
|
+
// IPv4. Reject all-zero / 255.255.255.255-ish junk shapes by gating on
|
|
164
|
+
// each octet being 0-255.
|
|
165
|
+
{
|
|
166
|
+
name: "ipv4",
|
|
167
|
+
regex: new RegExp(`\\b(?:${IPV4_OCTET}\\.){3}${IPV4_OCTET}\\b`, "g")
|
|
168
|
+
},
|
|
169
|
+
// Phone numbers. Tight US-leaning shape; a global PII detector would
|
|
170
|
+
// need a real lib. We keep this so US-based test prompts ('call me at
|
|
171
|
+
// (415) 555-...') don't ship. Note: no leading \b — '(' isn't a word
|
|
172
|
+
// char, so a starting boundary would refuse to match `(415)`. Reject
|
|
173
|
+
// adjacent word characters or hyphens so digit segments of UUIDs,
|
|
174
|
+
// hashes and identifiers stay readable; separators within phones still match.
|
|
175
|
+
{
|
|
176
|
+
name: "phone",
|
|
177
|
+
regex: new RegExp(`(?<![\\w-])${PHONE_COUNTRY_CODE.source}${PHONE_AREA_CODE.source}${PHONE_SEPARATOR}\\d{3}${PHONE_SEPARATOR}\\d{4}(?![\\w-])`, "g")
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
var CATEGORY = {
|
|
181
|
+
exactSecret: "exact_secret",
|
|
182
|
+
credential: "credential",
|
|
183
|
+
urlCredentials: "url_credentials",
|
|
184
|
+
signedQuery: "signed_query",
|
|
185
|
+
apiKeyHeader: "api_key_header",
|
|
186
|
+
apiKeyQuery: "api_key_query",
|
|
187
|
+
bearerToken: "bearer_token",
|
|
188
|
+
labeledSecret: "labeled_secret",
|
|
189
|
+
urlSecretParam: "url_secret_param",
|
|
190
|
+
opaqueToken: "opaque_token",
|
|
191
|
+
creditCard: "credit_card"
|
|
192
|
+
};
|
|
193
|
+
var GENERATED_CATEGORIES = [...PATTERNS.map(({ name }) => name), ...Object.values(CATEGORY)];
|
|
194
|
+
function escapeRegExp(text) {
|
|
195
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
196
|
+
}
|
|
197
|
+
function markerSource(categories) {
|
|
198
|
+
return `\\[REDACTED:(?:${[...new Set(categories)].map(escapeRegExp).join("|")})\\]`;
|
|
199
|
+
}
|
|
200
|
+
var GENERATED_MARKER = markerSource(GENERATED_CATEGORIES);
|
|
201
|
+
var GENERATED_MARKER_RE = new RegExp(GENERATED_MARKER, "g");
|
|
202
|
+
var CARD_CANDIDATE = /\b(?:\d[ -]?){12,18}\d\b/g;
|
|
203
|
+
var QUOTED_SECRET_VALUE = String.raw`"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'`;
|
|
204
|
+
var API_KEY_HEADER = new RegExp(`(^|[^?&\\w])(["']?)(x-api-key|api-key|x-goog-api-key)\\2(\\s*[:=]\\s*)(${QUOTED_SECRET_VALUE}|[^\\s,;"'#}]+)`, "gi");
|
|
205
|
+
var API_KEY_QUERY = /([?&](?:key|api_key|api-key)=)[^&#\s,;"']+/gi;
|
|
206
|
+
var SECRET_LABELS = "authorization|bearer|api[-_]?key|access[-_]?token|refresh[-_]?token|client[-_]?secret|password|secret|cookie";
|
|
207
|
+
var SERIALIZED_SECRET_LABELS = `${SECRET_LABELS}|x[-_](?:goog[-_])?api[-_]?key|api key|token|set[-_]cookie|private[-_]?key`;
|
|
208
|
+
var EMPTY_QUOTED_ASSIGNMENT_RE = new RegExp(`\\b(?:${SERIALIZED_SECRET_LABELS})\\s*[:=]\\s*$`, "i");
|
|
209
|
+
var LABELED_SECRET_RE = new RegExp(`\\b(${SECRET_LABELS})\\b\\s*[:=]\\s*\\S+`, "gi");
|
|
210
|
+
var OPAQUE_TOKEN_RE = /[A-Za-z0-9_-]{20,}/g;
|
|
211
|
+
var CORRELATION_ID = "ERR-[0-9A-F]{4}(?:-[0-9A-F]{4}){3}";
|
|
212
|
+
var UPPER_SNAKE_DIAGNOSTIC = "[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+";
|
|
213
|
+
var NON_SECRET_TOKEN_RE = new RegExp(`^(?:${CORRELATION_ID}|delegated-tool-calls|${UPPER_SNAKE_DIAGNOSTIC})$`);
|
|
214
|
+
var RUNTIME_SECRET_LABELS = `${SERIALIZED_SECRET_LABELS}|(?<![?&])(?:key)`;
|
|
215
|
+
var MASK_AWARE_LABELED_SECRET_RE = new RegExp(`(?<![\\w-])(["']?)(${RUNTIME_SECRET_LABELS})\\1\\s*[:=]\\s*(?!Bearer\\s+\\S)(?!${GENERATED_MARKER}[;&])((?!&)\\S)`, "gi");
|
|
216
|
+
var CHAINED_LABEL_RE = new RegExp(`(?:${RUNTIME_SECRET_LABELS})\\b["']?\\s*[:=]\\s*(?=\\S)`, "iy");
|
|
217
|
+
var SHORT_BEARER_RE = new RegExp(`Bearer\\s+["']?(?!${GENERATED_MARKER}(?=$|[\\s"',;<>}]))(?=([^\\s"',;<>}]+))`, "gi");
|
|
218
|
+
var BASIC_AUTH_RE = /\bauthorization["']?\s*[:=]\s*["']?(Basic\s+[^\s"',;}]+)/gi;
|
|
219
|
+
var COOKIE_HEADER_RE = /\bcookie\s*:\s*([^\r\n]+)/gi;
|
|
220
|
+
var PROVIDER_API_KEY_QUERY = /([?&]key=)([^&\s"']+)/gi;
|
|
221
|
+
var URL_CREDENTIALS_RE = /\/\/([^/\s?#@]+)@/g;
|
|
222
|
+
var SIGNED_QUERY_RE = /([?&](?:signature|sig|x-amz-signature|x-goog-signature|access_token|refresh_token)=)([^&#\s,;"']+)/gi;
|
|
223
|
+
var URL_SECRET_WORDS = "token|key|secret|signature|sig|code|password|passwd|pwd|auth|authorization|credential";
|
|
224
|
+
var URL_SECRET_PARAM_RE = new RegExp(`[?&#;]([\\w.-]{0,128}?(?:${URL_SECRET_WORDS})s?(?=[._=-])[\\w.-]{0,128})=[^&;\\s"'<>()]+`, "gi");
|
|
225
|
+
var LABELED_URL_PARAM_NAME_RE = new RegExp(`(?:^|[.-])(?:${SECRET_LABELS})$`, "i");
|
|
226
|
+
var MASKED_VALUE_RE = new RegExp(`^["']?${GENERATED_MARKER}["']?$`);
|
|
227
|
+
function isMaskedValue({ value }, _optional = {}) {
|
|
228
|
+
return MASKED_VALUE_RE.test(value);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ../core/dist/redaction-spans.js
|
|
232
|
+
function mergeSpans(spans, { keepAdjacent = false } = {}) {
|
|
233
|
+
const merged = [];
|
|
234
|
+
for (const rank of orderedSpanRanks({ spans })) {
|
|
235
|
+
const span = spans[rank];
|
|
236
|
+
const length = span.end - span.start;
|
|
237
|
+
const last = merged.at(-1);
|
|
238
|
+
if (!last || startsSeparateSpan({ start: span.start, end: last.end, keepAdjacent })) {
|
|
239
|
+
merged.push({ start: span.start, end: span.end, category: span.category, suffix: span.suffix, rank, categoryLength: length });
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (span.end >= last.end)
|
|
243
|
+
last.suffix = span.suffix;
|
|
244
|
+
last.end = Math.max(last.end, span.end);
|
|
245
|
+
if (length > last.categoryLength || length === last.categoryLength && rank < last.rank) {
|
|
246
|
+
Object.assign(last, { category: span.category, rank, categoryLength: length });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return merged;
|
|
250
|
+
}
|
|
251
|
+
function startsSeparateSpan({ start, end, keepAdjacent }, _options = {}) {
|
|
252
|
+
return keepAdjacent ? start >= end : start > end;
|
|
253
|
+
}
|
|
254
|
+
function orderedSpanRanks({ spans }) {
|
|
255
|
+
let ranks = Uint32Array.from(spans, (_span, rank) => rank);
|
|
256
|
+
let scratch = new Uint32Array(ranks.length);
|
|
257
|
+
const offsets = new Uint32Array(256);
|
|
258
|
+
for (let shift = 0; shift < 32; shift += 8) {
|
|
259
|
+
offsets.fill(0);
|
|
260
|
+
for (const rank of ranks) {
|
|
261
|
+
const bucket = spans[rank].start >>> shift & 255;
|
|
262
|
+
offsets[bucket] = (offsets[bucket] ?? 0) + 1;
|
|
263
|
+
}
|
|
264
|
+
let total = 0;
|
|
265
|
+
for (let bucket = 0; bucket < offsets.length; bucket++) {
|
|
266
|
+
const count = offsets[bucket] ?? 0;
|
|
267
|
+
offsets[bucket] = total;
|
|
268
|
+
total += count;
|
|
269
|
+
}
|
|
270
|
+
for (const rank of ranks) {
|
|
271
|
+
const bucket = spans[rank].start >>> shift & 255;
|
|
272
|
+
const position = offsets[bucket] ?? 0;
|
|
273
|
+
scratch[position] = rank;
|
|
274
|
+
offsets[bucket] = position + 1;
|
|
275
|
+
}
|
|
276
|
+
[ranks, scratch] = [scratch, ranks];
|
|
277
|
+
}
|
|
278
|
+
return ranks;
|
|
279
|
+
}
|
|
280
|
+
function collectMatches({ pass: { text, add }, regex, spanOf }, _optional = {}) {
|
|
281
|
+
const flags = regex.flags.includes("g") ? regex.flags : `${regex.flags}g`;
|
|
282
|
+
for (const match of text.matchAll(new RegExp(regex.source, flags))) {
|
|
283
|
+
const span = spanOf(match, match.index ?? 0);
|
|
284
|
+
if (span)
|
|
285
|
+
add(span.start, span.end, span.category);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function trailingValue({ category, group }, _optional = {}) {
|
|
289
|
+
return (match, index) => {
|
|
290
|
+
const value = match[group] ?? "";
|
|
291
|
+
if (isMaskedValue({ value }))
|
|
292
|
+
return void 0;
|
|
293
|
+
const end = index + match[0].length;
|
|
294
|
+
return { start: end - value.length, end, category };
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ../core/dist/redaction-labels.js
|
|
299
|
+
function collectLabeledSecrets({ text, add }, earlier) {
|
|
300
|
+
const covered = coveredLabelFields({ earlier });
|
|
301
|
+
const hints = emptyAssignmentRanges({ text });
|
|
302
|
+
const extentOf = labelValueExtents(text);
|
|
303
|
+
const regex = new RegExp(MASK_AWARE_LABELED_SECRET_RE.source, MASK_AWARE_LABELED_SECRET_RE.flags);
|
|
304
|
+
const chained = new RegExp(CHAINED_LABEL_RE.source, CHAINED_LABEL_RE.flags);
|
|
305
|
+
const urlField = new RegExp(URL_SECRET_PARAM_RE.source, "iy");
|
|
306
|
+
for (let match = regex.exec(text); match; match = regex.exec(text)) {
|
|
307
|
+
if (hints.has(match.index))
|
|
308
|
+
continue;
|
|
309
|
+
urlField.lastIndex = Math.max(0, match.index - 1);
|
|
310
|
+
if (urlField.exec(text)) {
|
|
311
|
+
regex.lastIndex = urlField.lastIndex;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const start = match.index + match[0].length - 1;
|
|
315
|
+
chained.lastIndex = start;
|
|
316
|
+
if (chained.test(text)) {
|
|
317
|
+
regex.lastIndex = start;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const value = extentOf(start);
|
|
321
|
+
if (covered(start, value) || isMaskedValue({ value: text.slice(start, value.end) })) {
|
|
322
|
+
regex.lastIndex = start;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
addLabelValue({ text, add, start, value });
|
|
326
|
+
regex.lastIndex = value.end;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function addLabelValue({ text, add, start, value }) {
|
|
330
|
+
const quoted = value.quoted ? 1 : 0;
|
|
331
|
+
const closed = value.closingQuote === value.end - 1;
|
|
332
|
+
add(start + quoted, value.end - (quoted && closed ? 1 : 0), CATEGORY.labeledSecret, quoted ? closed ? "" : text[start] : void 0);
|
|
333
|
+
}
|
|
334
|
+
function coveredLabelFields({ earlier }) {
|
|
335
|
+
const furthest = /* @__PURE__ */ new Map();
|
|
336
|
+
for (const { start, end } of earlier) {
|
|
337
|
+
furthest.set(start, Math.max(furthest.get(start) ?? end, end));
|
|
338
|
+
}
|
|
339
|
+
return (start, value) => {
|
|
340
|
+
const at = !value.quoted || furthest.has(start) ? start : start + 1;
|
|
341
|
+
return isCoveredField(furthest.get(at), value);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function isCoveredField(reach, { end, closingQuote }) {
|
|
345
|
+
const target = closingQuote === end - 1 ? closingQuote : end;
|
|
346
|
+
return (reach ?? -1) >= target;
|
|
347
|
+
}
|
|
348
|
+
function labelValueExtents(text) {
|
|
349
|
+
const runEnd = forwardFinder(text, /\s|[;&](?=$|[\w.-]+\s*[:=])/);
|
|
350
|
+
const gluedEnd = forwardFinder(text, /[\s;&,}\]]/);
|
|
351
|
+
const lineEnd = forwardFinder(text, /[\r\n]/);
|
|
352
|
+
const closers = /* @__PURE__ */ new Map([['"', unescapedQuoteFinder(text, /"/)], ["'", unescapedQuoteFinder(text, /'/)]]);
|
|
353
|
+
return (start) => {
|
|
354
|
+
const whitespace = runEnd(start);
|
|
355
|
+
const closer = closers.get(text[start] ?? "");
|
|
356
|
+
if (!closer)
|
|
357
|
+
return { end: whitespace, closingQuote: -1, quoted: false };
|
|
358
|
+
const closing = closer(start + 1);
|
|
359
|
+
const line = lineEnd(start);
|
|
360
|
+
return closing < text.length ? { end: quotedValueEnd({ text, closing, gluedEnd: gluedEnd(closing + 1) }), closingQuote: closing, quoted: true } : { end: line, closingQuote: -1, quoted: true };
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function unescapedQuoteFinder(text, quote) {
|
|
364
|
+
const next = forwardFinder(text, quote);
|
|
365
|
+
let found = -1;
|
|
366
|
+
return (from) => {
|
|
367
|
+
if (from > found) {
|
|
368
|
+
found = next(from);
|
|
369
|
+
while (found < text.length && isBackslashEscaped(text, found))
|
|
370
|
+
found = next(found + 1);
|
|
371
|
+
}
|
|
372
|
+
return found;
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function isBackslashEscaped(text, index) {
|
|
376
|
+
let backslashes = 0;
|
|
377
|
+
while (text[index - 1 - backslashes] === "\\")
|
|
378
|
+
backslashes++;
|
|
379
|
+
return backslashes % 2 === 1;
|
|
380
|
+
}
|
|
381
|
+
function forwardFinder(text, pattern) {
|
|
382
|
+
const regex = new RegExp(pattern.source, "g");
|
|
383
|
+
let found = -1;
|
|
384
|
+
return (from) => {
|
|
385
|
+
if (from > found) {
|
|
386
|
+
regex.lastIndex = from;
|
|
387
|
+
found = regex.exec(text)?.index ?? text.length;
|
|
388
|
+
}
|
|
389
|
+
return found;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function emptyAssignmentRanges({ text }, _optional = {}) {
|
|
393
|
+
const starts = /* @__PURE__ */ new Set();
|
|
394
|
+
for (const match of text.matchAll(new RegExp(QUOTED_SECRET_VALUE, "g"))) {
|
|
395
|
+
if (!EMPTY_QUOTED_ASSIGNMENT_RE.test(match[0].slice(1, -1)))
|
|
396
|
+
continue;
|
|
397
|
+
const labels = new RegExp(MASK_AWARE_LABELED_SECRET_RE.source, "gi");
|
|
398
|
+
for (const label of match[0].matchAll(labels))
|
|
399
|
+
starts.add(match.index + label.index);
|
|
400
|
+
}
|
|
401
|
+
return starts;
|
|
402
|
+
}
|
|
403
|
+
function collectEmptyQuotedAssignments(pass) {
|
|
404
|
+
for (const match of pass.text.matchAll(new RegExp(QUOTED_SECRET_VALUE, "g"))) {
|
|
405
|
+
if (EMPTY_QUOTED_ASSIGNMENT_RE.test(match[0].slice(1, -1))) {
|
|
406
|
+
pass.add(match.index + 1, match.index + match[0].length - 1, CATEGORY.labeledSecret);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function quotedValueEnd({ text, closing, gluedEnd }, _options = {}) {
|
|
411
|
+
return /^[.!)]*$/.test(text.slice(closing + 1, gluedEnd)) ? closing + 1 : gluedEnd;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ../core/dist/redaction-exact-secrets.js
|
|
415
|
+
function exactNeedles(secrets, literalOnly = false) {
|
|
416
|
+
const needles = /* @__PURE__ */ new Set();
|
|
417
|
+
for (const secret of secrets) {
|
|
418
|
+
if (typeof secret !== "string" || secret.length === 0)
|
|
419
|
+
continue;
|
|
420
|
+
needles.add(secret);
|
|
421
|
+
if (!literalOnly)
|
|
422
|
+
needles.add(JSON.stringify(secret).slice(1, -1));
|
|
423
|
+
}
|
|
424
|
+
return needles;
|
|
425
|
+
}
|
|
426
|
+
function collectExactSecrets({ text, add, secrets }, options = {}) {
|
|
427
|
+
const needles = exactNeedles(secrets, options.literalOnly);
|
|
428
|
+
if (needles.size === 0)
|
|
429
|
+
return;
|
|
430
|
+
const protectedSyntax = options.literalOnly ? [] : exactSyntaxRanges({ text });
|
|
431
|
+
for (const needle of needles) {
|
|
432
|
+
const insideSyntax = syntaxContainment({ ranges: protectedSyntax });
|
|
433
|
+
let runStart = -1;
|
|
434
|
+
let runEnd = -1;
|
|
435
|
+
forEachOccurrence(text, needle, (at) => {
|
|
436
|
+
if (insideSyntax(at, at + needle.length))
|
|
437
|
+
return;
|
|
438
|
+
if (beginsSecretRun({ at, runEnd, literalOnly: options.literalOnly === true })) {
|
|
439
|
+
add(runStart, runEnd, CATEGORY.exactSecret);
|
|
440
|
+
runStart = at;
|
|
441
|
+
}
|
|
442
|
+
runEnd = at + needle.length;
|
|
443
|
+
});
|
|
444
|
+
add(runStart, runEnd, CATEGORY.exactSecret);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function exactSyntaxRanges({ text }, _options = {}) {
|
|
448
|
+
const ranges = [];
|
|
449
|
+
const add = (start, end) => {
|
|
450
|
+
ranges.push({ start, end, category: "syntax" });
|
|
451
|
+
};
|
|
452
|
+
const pass = { text, add };
|
|
453
|
+
collectMatches({ pass, regex: new RegExp(`${GENERATED_MARKER}|\\[redacted\\]`, "gi"), spanOf: (m, at) => ({ start: at, end: at + m[0].length, category: "syntax" }) });
|
|
454
|
+
collectMatches({ pass, regex: MASK_AWARE_LABELED_SECRET_RE, spanOf: (m, at) => ({ start: at, end: at + m[0].length - 1, category: "syntax" }) });
|
|
455
|
+
collectMatches({ pass, regex: /\bBearer\s+|\bhttps?:\/\/|(?:x-api-key|api-key|x-goog-api-key)\s*[:=]\s*/gi, spanOf: (m, at) => ({ start: at, end: at + m[0].length, category: "syntax" }) });
|
|
456
|
+
collectMatches({ pass, regex: URL_SECRET_PARAM_RE, spanOf: (m, at) => ({ start: at, end: at + m[0].indexOf("=") + 1, category: "syntax" }) });
|
|
457
|
+
return mergeSpans(ranges);
|
|
458
|
+
}
|
|
459
|
+
function syntaxContainment({ ranges }, _options = {}) {
|
|
460
|
+
let cursor = 0;
|
|
461
|
+
return (start, end) => {
|
|
462
|
+
while (cursor < ranges.length && ranges[cursor].end <= start)
|
|
463
|
+
cursor++;
|
|
464
|
+
const range = ranges[cursor];
|
|
465
|
+
return range !== void 0 && range.start <= start && range.end >= end;
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function beginsSecretRun({ at, runEnd, literalOnly }, _options = {}) {
|
|
469
|
+
return literalOnly ? at >= runEnd : at > runEnd;
|
|
470
|
+
}
|
|
471
|
+
function forEachOccurrence(text, needle, visit) {
|
|
472
|
+
const border = borderTable(needle);
|
|
473
|
+
let matched = 0;
|
|
474
|
+
let at = text.indexOf(needle);
|
|
475
|
+
while (at !== -1) {
|
|
476
|
+
const char = text.charCodeAt(at);
|
|
477
|
+
while (matched > 0 && char !== needle.charCodeAt(matched))
|
|
478
|
+
matched = border[matched - 1] ?? 0;
|
|
479
|
+
if (char === needle.charCodeAt(matched))
|
|
480
|
+
matched += 1;
|
|
481
|
+
if (matched === needle.length) {
|
|
482
|
+
visit(at + 1 - needle.length);
|
|
483
|
+
matched = border[matched - 1] ?? 0;
|
|
484
|
+
}
|
|
485
|
+
at = nextSearchOffset({ text, needle, at, matched });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function nextSearchOffset({ text, needle, at, matched }, _options = {}) {
|
|
489
|
+
const next = at + 1;
|
|
490
|
+
if (next >= text.length)
|
|
491
|
+
return -1;
|
|
492
|
+
return matched === 0 ? text.indexOf(needle, next) : next;
|
|
493
|
+
}
|
|
494
|
+
function borderTable(needle) {
|
|
495
|
+
const border = new Int32Array(needle.length);
|
|
496
|
+
let length = 0;
|
|
497
|
+
for (let i = 1; i < needle.length; i += 1) {
|
|
498
|
+
const char = needle.charCodeAt(i);
|
|
499
|
+
while (length > 0 && char !== needle.charCodeAt(length))
|
|
500
|
+
length = border[length - 1] ?? 0;
|
|
501
|
+
if (char === needle.charCodeAt(length))
|
|
502
|
+
length += 1;
|
|
503
|
+
border[i] = length;
|
|
504
|
+
}
|
|
505
|
+
return border;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ../core/dist/redaction-collectors.js
|
|
509
|
+
function isLuhnValid(digits) {
|
|
510
|
+
let sum = 0;
|
|
511
|
+
let alt = false;
|
|
512
|
+
for (let i = digits.length - 1; i >= 0; i -= 1) {
|
|
513
|
+
let d = digits.charCodeAt(i) - 48;
|
|
514
|
+
if (alt) {
|
|
515
|
+
d *= 2;
|
|
516
|
+
if (d > 9)
|
|
517
|
+
d -= 9;
|
|
518
|
+
}
|
|
519
|
+
sum += d;
|
|
520
|
+
alt = !alt;
|
|
521
|
+
}
|
|
522
|
+
return sum % 10 === 0;
|
|
523
|
+
}
|
|
524
|
+
function collectSpans({ text }, options) {
|
|
525
|
+
const spans = [];
|
|
526
|
+
const add = (start, end, category, suffix) => {
|
|
527
|
+
if (end > start || end === start && suffix !== void 0)
|
|
528
|
+
spans.push({ start, end, category, suffix });
|
|
529
|
+
};
|
|
530
|
+
if (options.policy === "exact-only") {
|
|
531
|
+
collectExactSecrets({ text, add, secrets: options.exactSecrets ?? [] }, { literalOnly: true });
|
|
532
|
+
return spans;
|
|
533
|
+
}
|
|
534
|
+
collectExactSecrets({ text, add, secrets: options.exactSecrets ?? [] });
|
|
535
|
+
collectEmptyQuotedAssignments({ text, add });
|
|
536
|
+
collectUrlCredentials({ text, add });
|
|
537
|
+
collectPatterns({ text, add, patterns: credentialPatterns(options.extraPatterns ?? []) });
|
|
538
|
+
collectKeyedCredentials({ text, add });
|
|
539
|
+
collectLabeledSecrets({ text, add }, spans);
|
|
540
|
+
if (options.policy === "aggressive")
|
|
541
|
+
collectOpaqueTokens({ text, add }, new Set(options.diagnosticToolIds));
|
|
542
|
+
if (options.redactPii !== false)
|
|
543
|
+
collectPii({ text, add }, spans);
|
|
544
|
+
return spans;
|
|
545
|
+
}
|
|
546
|
+
var PII_PATTERN_NAMES = ["email", "ipv4", "phone"];
|
|
547
|
+
var NON_PII_PATTERNS = PATTERNS.filter((pattern) => !PII_PATTERN_NAMES.includes(pattern.name));
|
|
548
|
+
var PII_PATTERNS = PATTERNS.filter((pattern) => PII_PATTERN_NAMES.includes(pattern.name));
|
|
549
|
+
function credentialPatterns(extraPatterns) {
|
|
550
|
+
return [
|
|
551
|
+
...NON_PII_PATTERNS,
|
|
552
|
+
...SECRET_SHAPE_PATTERNS.map((shape) => ({ name: CATEGORY.credential, regex: shape.pattern })),
|
|
553
|
+
...extraPatterns
|
|
554
|
+
];
|
|
555
|
+
}
|
|
556
|
+
function collectPatterns({ text, add, patterns }) {
|
|
557
|
+
for (const { name, regex } of patterns) {
|
|
558
|
+
collectMatches({ pass: { text, add }, regex, spanOf: (match, index) => ({ start: index, end: index + match[0].length, category: name }) });
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function collectUrlCredentials(pass) {
|
|
562
|
+
collectMatches({
|
|
563
|
+
pass,
|
|
564
|
+
regex: URL_CREDENTIALS_RE,
|
|
565
|
+
spanOf: (match, index) => {
|
|
566
|
+
const userinfo = match[1] ?? "";
|
|
567
|
+
if (isMaskedValue({ value: userinfo }))
|
|
568
|
+
return void 0;
|
|
569
|
+
const start = index + "//".length;
|
|
570
|
+
return { start, end: start + userinfo.length, category: CATEGORY.urlCredentials };
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
collectMatches({ pass, regex: SIGNED_QUERY_RE, spanOf: trailingValue({ category: CATEGORY.signedQuery, group: 2 }) });
|
|
574
|
+
}
|
|
575
|
+
function collectKeyedCredentials(pass) {
|
|
576
|
+
collectApiKeyHeaders(pass);
|
|
577
|
+
collectMatches({ pass, regex: PROVIDER_API_KEY_QUERY, spanOf: trailingValue({ category: CATEGORY.apiKeyQuery, group: 2 }) });
|
|
578
|
+
collectMatches({
|
|
579
|
+
pass,
|
|
580
|
+
regex: API_KEY_QUERY,
|
|
581
|
+
spanOf: (match, index) => {
|
|
582
|
+
const start = index + (match[1] ?? "").length;
|
|
583
|
+
const end = index + match[0].length;
|
|
584
|
+
return isMaskedValue({ value: match[0].slice(start - index) }) ? void 0 : { start, end, category: CATEGORY.apiKeyQuery };
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
collectMatches({
|
|
588
|
+
pass,
|
|
589
|
+
regex: SHORT_BEARER_RE,
|
|
590
|
+
spanOf: (match, index) => {
|
|
591
|
+
const start = index + match[0].length;
|
|
592
|
+
return { start, end: start + (match[1] ?? "").length, category: CATEGORY.bearerToken };
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
collectMatches({ pass, regex: BASIC_AUTH_RE, spanOf: trailingValue({ category: CATEGORY.labeledSecret, group: 1 }) });
|
|
596
|
+
collectMatches({ pass, regex: COOKIE_HEADER_RE, spanOf: trailingValue({ category: CATEGORY.labeledSecret, group: 1 }) });
|
|
597
|
+
collectUrlSecretParams(pass);
|
|
598
|
+
}
|
|
599
|
+
function collectApiKeyHeaders(pass) {
|
|
600
|
+
const hints = emptyAssignmentRanges({ text: pass.text });
|
|
601
|
+
collectMatches({
|
|
602
|
+
pass,
|
|
603
|
+
regex: API_KEY_HEADER,
|
|
604
|
+
spanOf: (match, index) => {
|
|
605
|
+
const labelStart = index + (match[1] ?? "").length;
|
|
606
|
+
if (hints.has(labelStart))
|
|
607
|
+
return void 0;
|
|
608
|
+
const value = match[5] ?? "";
|
|
609
|
+
if (isMaskedValue({ value }))
|
|
610
|
+
return void 0;
|
|
611
|
+
const end = index + match[0].length;
|
|
612
|
+
const quoted = /^["']/.test(value) ? 1 : 0;
|
|
613
|
+
return { start: end - value.length + quoted, end: end - quoted, category: CATEGORY.apiKeyHeader };
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function collectUrlSecretParams(pass) {
|
|
618
|
+
collectMatches({
|
|
619
|
+
pass,
|
|
620
|
+
regex: URL_SECRET_PARAM_RE,
|
|
621
|
+
spanOf: (match, index) => {
|
|
622
|
+
const separator = match[0].indexOf("=") + 1;
|
|
623
|
+
if (isMaskedValue({ value: match[0].slice(separator) }))
|
|
624
|
+
return void 0;
|
|
625
|
+
const category = LABELED_URL_PARAM_NAME_RE.test(match[1] ?? "") ? CATEGORY.labeledSecret : CATEGORY.urlSecretParam;
|
|
626
|
+
return { start: index + separator, end: index + match[0].length, category };
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
function collectOpaqueTokens({ text, add }, trustedIds) {
|
|
631
|
+
for (const token of text.matchAll(/[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*/g)) {
|
|
632
|
+
if (trustedIds.has(token[0]))
|
|
633
|
+
continue;
|
|
634
|
+
for (const run of token[0].matchAll(OPAQUE_TOKEN_RE)) {
|
|
635
|
+
if (NON_SECRET_TOKEN_RE.test(run[0]))
|
|
636
|
+
continue;
|
|
637
|
+
const start = (token.index ?? 0) + (run.index ?? 0);
|
|
638
|
+
add(start, start + run[0].length, CATEGORY.opaqueToken);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function collectPii(pass, earlier) {
|
|
643
|
+
const userinfoEnds = new Set(earlier.filter(({ category }) => category === CATEGORY.urlCredentials).map(({ end }) => end));
|
|
644
|
+
for (const { name, regex } of PII_PATTERNS) {
|
|
645
|
+
collectMatches({
|
|
646
|
+
pass,
|
|
647
|
+
regex,
|
|
648
|
+
spanOf: (match, index) => name === "email" && userinfoEnds.has(index) ? void 0 : { start: index - (match.groups?.local?.length ?? 0), end: index + match[0].length, category: name }
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
collectMatches({
|
|
652
|
+
pass,
|
|
653
|
+
regex: CARD_CANDIDATE,
|
|
654
|
+
spanOf: (match, index) => isLuhnValid(match[0].replace(/\D/g, "")) ? { start: index, end: index + match[0].length, category: CATEGORY.creditCard } : void 0
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// ../core/dist/redact.js
|
|
659
|
+
function redactSecrets({ input }, options = {}) {
|
|
660
|
+
return redactSecretsWithCounts({ input }, options).redacted;
|
|
661
|
+
}
|
|
662
|
+
function redactSecretsWithCounts({ input }, options = {}) {
|
|
663
|
+
const counts = {};
|
|
664
|
+
if (!input)
|
|
665
|
+
return { redacted: input, counts };
|
|
666
|
+
const spans = mergeSpans(collectSpans({ text: input }, options), { keepAdjacent: options.policy === "exact-only" });
|
|
667
|
+
let redacted = "";
|
|
668
|
+
let cursor = 0;
|
|
669
|
+
for (const { start, end, category, suffix } of spans) {
|
|
670
|
+
counts[category] = (counts[category] ?? 0) + 1;
|
|
671
|
+
redacted += input.slice(cursor, start) + (options.policy === "exact-only" ? options.marker ?? "[REDACTED:exact_secret]" : `[REDACTED:${category}]`) + (suffix ?? "");
|
|
672
|
+
cursor = end;
|
|
673
|
+
}
|
|
674
|
+
return { redacted: redacted + input.slice(cursor), counts };
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// ../core/dist/primitives/trim-chars.js
|
|
678
|
+
function trimCharsEnd({ text, chars }) {
|
|
679
|
+
let end = text.length;
|
|
680
|
+
while (end > 0 && chars.includes(text.charAt(end - 1)))
|
|
681
|
+
end -= 1;
|
|
682
|
+
return text.slice(0, end);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// ../protocol/dist/errors.js
|
|
686
|
+
function createApiError({ code, message }, optionalArgs = {}) {
|
|
687
|
+
return { code, message, ...optionalArgs };
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// ../core/dist/contracts/server/result.js
|
|
691
|
+
var ok = ({ value }, _optional = {}) => ({ ok: true, value });
|
|
692
|
+
var err = ({ error }, _optional = {}) => ({ ok: false, error });
|
|
693
|
+
|
|
694
|
+
// ../core/dist/contracts/server/api-error.js
|
|
695
|
+
var ERROR_STATUS_BY_CODE = {
|
|
696
|
+
BAD_REQUEST: 400,
|
|
697
|
+
UNAUTHORIZED: 401,
|
|
698
|
+
FORBIDDEN: 403,
|
|
699
|
+
NOT_FOUND: 404,
|
|
700
|
+
CONFLICT: 409,
|
|
701
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
702
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
703
|
+
VALIDATION_FAILED: 422,
|
|
704
|
+
RATE_LIMITED: 429,
|
|
705
|
+
INTERNAL_ERROR: 500,
|
|
706
|
+
UPSTREAM_UNAVAILABLE: 502,
|
|
707
|
+
SERVICE_UNAVAILABLE: 503,
|
|
708
|
+
NOT_CONFIGURED: 503,
|
|
709
|
+
INSUFFICIENT_STORAGE: 507,
|
|
710
|
+
TOOL_TOKEN_MISSING: 401,
|
|
711
|
+
TOOL_TOKEN_INVALID: 401,
|
|
712
|
+
TOOL_TOKEN_EXPIRED: 401,
|
|
713
|
+
TOOL_ENDPOINT_DENIED: 403,
|
|
714
|
+
TOOL_OPERATION_DENIED: 403,
|
|
715
|
+
TOOL_NOT_AVAILABLE: 503,
|
|
716
|
+
UNKNOWN_TOOL: 404,
|
|
717
|
+
TOOL_EXECUTION_FAILED: 422,
|
|
718
|
+
REMOTE_TOOL_BRIDGE_NOT_CONFIGURED: 503,
|
|
719
|
+
REMOTE_TOOL_BRIDGE_TOKEN_REQUIRED: 401,
|
|
720
|
+
OAUTH_FLOW_IN_PROGRESS: 409
|
|
721
|
+
};
|
|
722
|
+
function statusForError({ error }, _optional = {}) {
|
|
723
|
+
return ERROR_STATUS_BY_CODE[error.code] ?? 500;
|
|
724
|
+
}
|
|
725
|
+
function validationError({ message }, { issues = [] } = {}) {
|
|
726
|
+
if (issues.length === 0)
|
|
727
|
+
return { code: "BAD_REQUEST", message };
|
|
728
|
+
return { code: "BAD_REQUEST", message, details: { kind: "validation", issues } };
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// ../core/dist/contracts/server/origin.js
|
|
732
|
+
function guardSameOrigin({ req, origin }, _optional = {}) {
|
|
733
|
+
if (origin.originPolicy.isSameOrigin({ req }))
|
|
734
|
+
return ok({ value: void 0 });
|
|
735
|
+
const error = { code: "FORBIDDEN", message: "cross-origin request rejected" };
|
|
736
|
+
return err({ error });
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// ../core/dist/contracts/server/query.js
|
|
740
|
+
var BRACKETED_QUERY_VALUE = Object.freeze({});
|
|
741
|
+
var MAX_QUERY_LIST_INDEX = 20;
|
|
742
|
+
function listIndex(suffix) {
|
|
743
|
+
if (suffix === "[]")
|
|
744
|
+
return 0;
|
|
745
|
+
const digits = /^\[(0|[1-9]\d*)\]$/.exec(suffix)?.[1];
|
|
746
|
+
const index = digits === void 0 ? Number.NaN : Number(digits);
|
|
747
|
+
return index <= MAX_QUERY_LIST_INDEX ? index : void 0;
|
|
748
|
+
}
|
|
749
|
+
function withPlainValue(previous, value) {
|
|
750
|
+
if (previous === void 0)
|
|
751
|
+
return value;
|
|
752
|
+
if (typeof previous === "string")
|
|
753
|
+
return [previous, value];
|
|
754
|
+
if (Array.isArray(previous))
|
|
755
|
+
previous.push(value);
|
|
756
|
+
return previous;
|
|
757
|
+
}
|
|
758
|
+
function withListValue(previous, { index, value }) {
|
|
759
|
+
if (previous !== void 0 && typeof previous !== "string" && !Array.isArray(previous))
|
|
760
|
+
return previous;
|
|
761
|
+
const list = typeof previous === "string" ? [previous] : previous ?? [];
|
|
762
|
+
const slot = typeof previous === "string" ? index + 1 : index;
|
|
763
|
+
if (slot in list)
|
|
764
|
+
list.push(value);
|
|
765
|
+
else
|
|
766
|
+
list[slot] = value;
|
|
767
|
+
return list;
|
|
768
|
+
}
|
|
769
|
+
function addQueryValue({ query, key, value }) {
|
|
770
|
+
const bracket = key.indexOf("[");
|
|
771
|
+
if (bracket <= 0) {
|
|
772
|
+
query.set(key, withPlainValue(query.get(key), value));
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const name = key.slice(0, bracket);
|
|
776
|
+
const index = listIndex(key.slice(bracket));
|
|
777
|
+
query.set(name, index === void 0 ? BRACKETED_QUERY_VALUE : withListValue(query.get(name), { index, value }));
|
|
778
|
+
}
|
|
779
|
+
function readQuery({ request }, _optional = {}) {
|
|
780
|
+
const query = /* @__PURE__ */ new Map();
|
|
781
|
+
for (const [key, value] of new URL(request.url).searchParams)
|
|
782
|
+
addQueryValue({ query, key, value });
|
|
783
|
+
return Object.fromEntries([...query].map(([key, value]) => [key, Array.isArray(value) ? value.filter(() => true) : value]));
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// ../core/dist/contracts/server/request-body.js
|
|
787
|
+
var DEFAULT_JSON_BODY_MAX_BYTES = 100 * 1024;
|
|
788
|
+
function payloadTooLargeError({ maxBytes }, _optional = {}) {
|
|
789
|
+
return { code: "PAYLOAD_TOO_LARGE", message: `The request body is larger than the ${maxBytes} bytes this address accepts. Send less data.` };
|
|
790
|
+
}
|
|
791
|
+
async function readBodyBytes({ request }, { maxBytes = DEFAULT_JSON_BODY_MAX_BYTES } = {}) {
|
|
792
|
+
const encoding = (request.headers.get("content-encoding") ?? "identity").trim().toLowerCase();
|
|
793
|
+
if (encoding !== "identity")
|
|
794
|
+
return err({ error: { code: "UNSUPPORTED_MEDIA_TYPE", message: "This address does not accept compressed request bodies. Send the body uncompressed (no Content-Encoding)." } });
|
|
795
|
+
const declared = Number(request.headers.get("content-length") ?? "0");
|
|
796
|
+
if (declared > maxBytes)
|
|
797
|
+
return err({ error: payloadTooLargeError({ maxBytes }) });
|
|
798
|
+
if (!request.body)
|
|
799
|
+
return ok({ value: new Uint8Array(0) });
|
|
800
|
+
return collectBody({ body: request.body, maxBytes });
|
|
801
|
+
}
|
|
802
|
+
async function collectBody({ body, maxBytes }) {
|
|
803
|
+
const reader = body.getReader();
|
|
804
|
+
const chunks = [];
|
|
805
|
+
let total = 0;
|
|
806
|
+
for (; ; ) {
|
|
807
|
+
const { done, value } = await reader.read();
|
|
808
|
+
if (done)
|
|
809
|
+
break;
|
|
810
|
+
total += value.byteLength;
|
|
811
|
+
if (total > maxBytes) {
|
|
812
|
+
await reader.cancel();
|
|
813
|
+
return err({ error: payloadTooLargeError({ maxBytes }) });
|
|
814
|
+
}
|
|
815
|
+
chunks.push(value);
|
|
816
|
+
}
|
|
817
|
+
const bytes = new Uint8Array(total);
|
|
818
|
+
let offset = 0;
|
|
819
|
+
for (const chunk of chunks) {
|
|
820
|
+
bytes.set(chunk, offset);
|
|
821
|
+
offset += chunk.byteLength;
|
|
822
|
+
}
|
|
823
|
+
return ok({ value: bytes });
|
|
824
|
+
}
|
|
825
|
+
function isJsonContentType(contentType) {
|
|
826
|
+
const mediaType = (contentType ?? "").split(";")[0]?.trim().toLowerCase() ?? "";
|
|
827
|
+
return mediaType === "application/json" || mediaType.endsWith("+json");
|
|
828
|
+
}
|
|
829
|
+
async function readJsonBody({ request }, { maxBytes = DEFAULT_JSON_BODY_MAX_BYTES } = {}) {
|
|
830
|
+
const bytes = await readBodyBytes({ request }, { maxBytes });
|
|
831
|
+
if (!bytes.ok)
|
|
832
|
+
return bytes;
|
|
833
|
+
if (!isJsonContentType(request.headers.get("content-type")))
|
|
834
|
+
return ok({ value: {} });
|
|
835
|
+
const text = new TextDecoder().decode(bytes.value).trim();
|
|
836
|
+
if (text === "")
|
|
837
|
+
return ok({ value: {} });
|
|
838
|
+
const invalid = { code: "BAD_REQUEST", message: "The request body is not valid JSON. Send a JSON object or array." };
|
|
839
|
+
if (!text.startsWith("{") && !text.startsWith("["))
|
|
840
|
+
return err({ error: invalid });
|
|
841
|
+
try {
|
|
842
|
+
return ok({ value: JSON.parse(text) });
|
|
843
|
+
} catch {
|
|
844
|
+
return err({ error: invalid });
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// ../core/dist/contracts/server/client-facing-error.js
|
|
849
|
+
var ClientFacingError = class extends Error {
|
|
850
|
+
apiError;
|
|
851
|
+
constructor({ apiError }, _optional = {}) {
|
|
852
|
+
super(apiError.message);
|
|
853
|
+
this.name = "ClientFacingError";
|
|
854
|
+
this.apiError = apiError;
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
// ../core/dist/errors/reporter.js
|
|
859
|
+
var UNAVAILABLE_ERROR_ID = "ERR-0000-0000-0000-0000";
|
|
860
|
+
function attempt({ read, fallback }) {
|
|
861
|
+
try {
|
|
862
|
+
return read();
|
|
863
|
+
} catch {
|
|
864
|
+
return fallback;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
function isObjectLike(value) {
|
|
868
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
869
|
+
}
|
|
870
|
+
var NOOP_OPERATION_TRACKER = Object.freeze({ run: (fn) => fn(), end: () => {
|
|
871
|
+
} });
|
|
872
|
+
var COMPLETED = Object.freeze({ outcome: "completed", failed: false });
|
|
873
|
+
function observe({ value }) {
|
|
874
|
+
if (value instanceof Promise)
|
|
875
|
+
value.then(void 0, () => void 0);
|
|
876
|
+
}
|
|
877
|
+
function isTracker(value) {
|
|
878
|
+
return isObjectLike(value) && typeof value.run === "function" && typeof value.end === "function";
|
|
879
|
+
}
|
|
880
|
+
function startOperation(required, _optional = {}) {
|
|
881
|
+
const { observability, name, attributes } = required;
|
|
882
|
+
if (observability === void 0)
|
|
883
|
+
return NOOP_OPERATION_TRACKER;
|
|
884
|
+
const started = attempt({ fallback: void 0, read: () => observability.trackOperation({ name, ...attributes === void 0 ? {} : { attributes } }) });
|
|
885
|
+
observe({ value: started });
|
|
886
|
+
return isTracker(started) ? started : NOOP_OPERATION_TRACKER;
|
|
887
|
+
}
|
|
888
|
+
var endedTrackers = /* @__PURE__ */ new WeakSet();
|
|
889
|
+
function endOnce(required, _optional = {}) {
|
|
890
|
+
const { tracker, verdict } = required;
|
|
891
|
+
if (endedTrackers.has(tracker))
|
|
892
|
+
return;
|
|
893
|
+
endedTrackers.add(tracker);
|
|
894
|
+
attempt({ fallback: void 0, read: () => observe({ value: tracker.end(verdict) }) });
|
|
895
|
+
}
|
|
896
|
+
function reporterBreach({ fallback }) {
|
|
897
|
+
return { kind: "incident", status: 500, error: { code: "INTERNAL_ERROR", message: `${fallback.message} ${fallback.action} (error ${UNAVAILABLE_ERROR_ID})`, requestId: UNAVAILABLE_ERROR_ID } };
|
|
898
|
+
}
|
|
899
|
+
function settleThrown(required, optional) {
|
|
900
|
+
const { run, tracker, error } = required;
|
|
901
|
+
const settled = attempt({ fallback: void 0, read: () => run.settle?.(error) });
|
|
902
|
+
if (settled?.outcome === "cancelled")
|
|
903
|
+
return { ok: false, cancelled: true, verdict: settled };
|
|
904
|
+
const { reporter } = run.deps;
|
|
905
|
+
const options = optional.attributes === void 0 && run.attributes !== void 0 ? { ...optional, attributes: run.attributes } : optional;
|
|
906
|
+
const failure = attempt({
|
|
907
|
+
fallback: reporterBreach({ fallback: run.fallback }),
|
|
908
|
+
read: () => reporter.describe({ error, operation: run.operation, scope: run.scope, step: run.step, fallback: run.fallback, tracker }, options)
|
|
909
|
+
});
|
|
910
|
+
const failed = failure.kind === "incident";
|
|
911
|
+
return { ok: false, failure, verdict: { outcome: failed ? "failed" : "refused", failed } };
|
|
912
|
+
}
|
|
913
|
+
function classifyValue(required) {
|
|
914
|
+
const { run, tracker, value } = required;
|
|
915
|
+
if (run.classify === void 0)
|
|
916
|
+
return COMPLETED;
|
|
917
|
+
try {
|
|
918
|
+
return run.classify(value);
|
|
919
|
+
} catch (error) {
|
|
920
|
+
attempt({ fallback: void 0, read: () => run.deps.reporter.record({ error, step: `${run.step} (judge the result)`, operation: run.operation, tracker }) });
|
|
921
|
+
return COMPLETED;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
async function settleWork(required, optional) {
|
|
925
|
+
const { run, tracker } = required;
|
|
926
|
+
let value;
|
|
927
|
+
try {
|
|
928
|
+
value = await tracker.run(run.work);
|
|
929
|
+
} catch (error) {
|
|
930
|
+
return settleThrown({ run, tracker, error }, optional);
|
|
931
|
+
}
|
|
932
|
+
return { ok: true, value, verdict: classifyValue({ run, tracker, value }) };
|
|
933
|
+
}
|
|
934
|
+
async function runOperation(required, optional = {}) {
|
|
935
|
+
const { deps, operation, attributes } = required;
|
|
936
|
+
const tracker = startOperation({ observability: deps.observability, name: operation, attributes });
|
|
937
|
+
const result = await settleWork({ run: required, tracker }, optional);
|
|
938
|
+
endOnce({ tracker, verdict: result.verdict });
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// ../core/dist/contracts/server/failure-copy.js
|
|
943
|
+
var READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
944
|
+
var MESSAGE = "The server could not finish this request.";
|
|
945
|
+
var READ_FALLBACK = { message: MESSAGE, action: "Nothing was changed. Try again; if it keeps failing, report the error ID." };
|
|
946
|
+
var WRITE_FALLBACK = { message: MESSAGE, action: "Check whether your change was saved, then try again. If it keeps failing, report the error ID." };
|
|
947
|
+
function isReadMethod({ method }) {
|
|
948
|
+
return READ_METHODS.has(method.toUpperCase());
|
|
949
|
+
}
|
|
950
|
+
function httpFallbackCopy({ method }, _optional = {}) {
|
|
951
|
+
return isReadMethod({ method }) ? READ_FALLBACK : WRITE_FALLBACK;
|
|
952
|
+
}
|
|
953
|
+
function internalErrorMessage({ method }, _optional = {}) {
|
|
954
|
+
return isReadMethod({ method }) ? `${MESSAGE} Nothing was changed. Try again; if it keeps failing, copy the request ID and report this problem.` : `${MESSAGE} Check whether your change was saved, then copy the request ID and report this problem.`;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// ../core/dist/contracts/server/json-route.js
|
|
958
|
+
function defineJsonRoute(requiredArgs, optionalArgs = {}) {
|
|
959
|
+
return { ...requiredArgs, ...optionalArgs };
|
|
960
|
+
}
|
|
961
|
+
var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([204, 205, 304]);
|
|
962
|
+
function jsonResponse({ status, body }, { headers = {} } = {}) {
|
|
963
|
+
if (NULL_BODY_STATUSES.has(status))
|
|
964
|
+
return new Response(null, { status, headers });
|
|
965
|
+
const text = JSON.stringify(body);
|
|
966
|
+
return new Response(text, { status, headers: { "content-type": "application/json; charset=utf-8", "content-length": String(new TextEncoder().encode(text).byteLength), ...headers } });
|
|
967
|
+
}
|
|
968
|
+
var errorAnswer = ({ error }) => jsonResponse({ status: statusForError({ error }), body: { error } });
|
|
969
|
+
var CLIENT_CLOSED_STATUS = 499;
|
|
970
|
+
var COMPLETED2 = { outcome: "completed", failed: false };
|
|
971
|
+
var REFUSED = { outcome: "refused", failed: false };
|
|
972
|
+
var FAILED = { outcome: "failed", failed: true };
|
|
973
|
+
var CANCELLED = { outcome: "cancelled", failed: false };
|
|
974
|
+
function tag({ response, verdict }) {
|
|
975
|
+
return { response, verdict: { ...verdict, attributes: { ...verdict.attributes, "http.status_code": response.status } } };
|
|
976
|
+
}
|
|
977
|
+
function verdictFor({ apiError }) {
|
|
978
|
+
return apiError.code === "INTERNAL_ERROR" ? FAILED : REFUSED;
|
|
979
|
+
}
|
|
980
|
+
var errorTagged = ({ error }) => tag({ response: errorAnswer({ error }), verdict: verdictFor({ apiError: error }) });
|
|
981
|
+
function jsonRoute({ spec, deps, reportInternalError }, { host } = {}) {
|
|
982
|
+
const answer = answerJsonRoute({ host });
|
|
983
|
+
return {
|
|
984
|
+
method: spec.method.toUpperCase(),
|
|
985
|
+
path: spec.path,
|
|
986
|
+
handler: ({ request, params, locals = {} }) => answer({ spec, deps, reportInternalError, request, params: { ...params }, locals })
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
function answerJsonRoute({ host }) {
|
|
990
|
+
const errors = host?.errors;
|
|
991
|
+
return errors ? (call) => reporterAnswer(call, { host, errors }) : (call) => legacyAnswer(call, { host });
|
|
992
|
+
}
|
|
993
|
+
async function legacyAnswer(call, { host }) {
|
|
994
|
+
try {
|
|
995
|
+
return (await routeAnswerTagged(call, { host })).response;
|
|
996
|
+
} catch (error) {
|
|
997
|
+
return exceptionAnswer({ call, error }, { host });
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
async function reporterAnswer(call, { host, errors }) {
|
|
1001
|
+
const method = call.spec.method.toUpperCase();
|
|
1002
|
+
const run = await runOperation({
|
|
1003
|
+
deps: errors,
|
|
1004
|
+
operation: "http.route",
|
|
1005
|
+
scope: "http",
|
|
1006
|
+
step: `Handle ${method} ${call.spec.path}`,
|
|
1007
|
+
fallback: httpFallbackCopy({ method }),
|
|
1008
|
+
// The registered pattern (`/runs/:id`), never `request.url`: a URL carries ids, query strings and
|
|
1009
|
+
// tokens, which would leak into telemetry and give every request its own unbounded group.
|
|
1010
|
+
attributes: { "http.method": method, "http.route": call.spec.path },
|
|
1011
|
+
work: () => tracedAnswer(call, { host, errors }),
|
|
1012
|
+
classify: (tagged) => tagged.verdict,
|
|
1013
|
+
settle: (error) => disconnectVerdict({ request: call.request, error })
|
|
1014
|
+
}, { audience: "anonymous" });
|
|
1015
|
+
if (run.ok)
|
|
1016
|
+
return run.value.response;
|
|
1017
|
+
if ("cancelled" in run)
|
|
1018
|
+
return new Response(null, { status: CLIENT_CLOSED_STATUS });
|
|
1019
|
+
return failureResponse({ failure: run.failure });
|
|
1020
|
+
}
|
|
1021
|
+
async function tracedAnswer(call, { host, errors }) {
|
|
1022
|
+
try {
|
|
1023
|
+
return await routeAnswerTagged(call, { host });
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
const onError = call.spec.ports?.onError;
|
|
1026
|
+
if (!onError)
|
|
1027
|
+
throw error;
|
|
1028
|
+
return hostPolicyAnswer({ call, error, onError }, { errors });
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
async function hostPolicyAnswer({ call, error, onError }, { errors }) {
|
|
1032
|
+
let response;
|
|
1033
|
+
try {
|
|
1034
|
+
response = await onError({ error, request: call.request });
|
|
1035
|
+
} catch (policyError) {
|
|
1036
|
+
recordPolicyFailure({ reporter: errors.reporter, policyError });
|
|
1037
|
+
throw error;
|
|
1038
|
+
}
|
|
1039
|
+
return tag({ response, verdict: response.status >= 500 ? FAILED : REFUSED });
|
|
1040
|
+
}
|
|
1041
|
+
function recordPolicyFailure({ reporter, policyError }) {
|
|
1042
|
+
try {
|
|
1043
|
+
reporter.record({ error: policyError, step: "Answer with host error policy", operation: "http.route" });
|
|
1044
|
+
} catch {
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
function disconnectVerdict({ request, error }) {
|
|
1048
|
+
const { signal } = request;
|
|
1049
|
+
if (!signal.aborted)
|
|
1050
|
+
return void 0;
|
|
1051
|
+
const abortLike = error === signal.reason || typeof error === "object" && error !== null && error.name === "AbortError";
|
|
1052
|
+
return abortLike ? { ...CANCELLED, attributes: { "http.status_code": CLIENT_CLOSED_STATUS } } : void 0;
|
|
1053
|
+
}
|
|
1054
|
+
function failureResponse({ failure }) {
|
|
1055
|
+
return jsonResponse({ status: failure.status, body: { error: failure.error } });
|
|
1056
|
+
}
|
|
1057
|
+
async function readRawInput({ spec, request, params }) {
|
|
1058
|
+
const query = readQuery({ request });
|
|
1059
|
+
if (request.method === "GET" || request.method === "HEAD")
|
|
1060
|
+
return { ok: true, value: { body: {}, query, params } };
|
|
1061
|
+
const body = await readJsonBody({ request }, spec.maxBodyBytes === void 0 ? {} : { maxBytes: spec.maxBodyBytes });
|
|
1062
|
+
return body.ok ? { ok: true, value: { body: body.value, query, params } } : body;
|
|
1063
|
+
}
|
|
1064
|
+
function sameOriginRefusal({ request, origin }, _optional = {}) {
|
|
1065
|
+
const header = (name) => request.headers.get(name) ?? void 0;
|
|
1066
|
+
const verdict = guardSameOrigin({ req: { headers: { host: header("host"), origin: header("origin"), "sec-fetch-site": header("sec-fetch-site") } }, origin });
|
|
1067
|
+
return verdict.ok ? void 0 : errorAnswer({ error: verdict.error });
|
|
1068
|
+
}
|
|
1069
|
+
function originRefusal({ spec, request }, { host }) {
|
|
1070
|
+
if (!spec.requireSameOrigin)
|
|
1071
|
+
return void 0;
|
|
1072
|
+
if (!host)
|
|
1073
|
+
throw new Error("same-origin adapter context is required");
|
|
1074
|
+
return sameOriginRefusal({ request, origin: host });
|
|
1075
|
+
}
|
|
1076
|
+
function makeAuthorize({ spec, deps, context }) {
|
|
1077
|
+
return async ({ permission, entityType }, scope) => {
|
|
1078
|
+
if (!spec.ports?.authorize)
|
|
1079
|
+
throw new Error("JSON route authorizer is required");
|
|
1080
|
+
const required = { context, deps, permission, ...entityType === void 0 ? {} : { entityType } };
|
|
1081
|
+
await (scope ? spec.ports.authorize(required, scope) : spec.ports.authorize(required));
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
function authenticate({ call, raw }) {
|
|
1085
|
+
const { spec, deps, request, locals } = call;
|
|
1086
|
+
return spec.ports?.authenticate ? spec.ports.authenticate({ raw, request, locals, deps }) : void 0;
|
|
1087
|
+
}
|
|
1088
|
+
async function routeAnswerTagged(call, { host }) {
|
|
1089
|
+
const { spec, deps, request } = call;
|
|
1090
|
+
const raw = await readRawInput(call);
|
|
1091
|
+
if (!raw.ok)
|
|
1092
|
+
return errorTagged({ error: raw.error });
|
|
1093
|
+
if (spec.ports?.workspace)
|
|
1094
|
+
await spec.ports.workspace({ raw: raw.value, deps });
|
|
1095
|
+
const refused = originRefusal(call, { host });
|
|
1096
|
+
if (refused)
|
|
1097
|
+
return tag({ response: refused, verdict: REFUSED });
|
|
1098
|
+
const context = await authenticate({ call, raw: raw.value });
|
|
1099
|
+
const parsed = spec.parse(raw.value);
|
|
1100
|
+
if (!parsed.ok)
|
|
1101
|
+
return errorTagged({ error: parsed.error });
|
|
1102
|
+
const authorize = makeAuthorize({ spec, deps, context });
|
|
1103
|
+
const result = await spec.handle({ input: parsed.value, deps, context, authorize }, { signal: request.signal });
|
|
1104
|
+
return finalAnswer({ spec, result, request });
|
|
1105
|
+
}
|
|
1106
|
+
function finalAnswer({ spec, result, request }) {
|
|
1107
|
+
if (request.signal.aborted)
|
|
1108
|
+
return tag({ response: new Response(null, { status: CLIENT_CLOSED_STATUS }), verdict: CANCELLED });
|
|
1109
|
+
if (!result.ok)
|
|
1110
|
+
return errorTagged({ error: result.error });
|
|
1111
|
+
return tag({ response: jsonResponse({ status: spec.successStatus ?? 200, body: result.value }), verdict: COMPLETED2 });
|
|
1112
|
+
}
|
|
1113
|
+
async function exceptionAnswer({ call, error }, { host }) {
|
|
1114
|
+
const { spec, request } = call;
|
|
1115
|
+
if (spec.ports?.onError)
|
|
1116
|
+
return spec.ports.onError({ error, request });
|
|
1117
|
+
if (error instanceof ClientFacingError)
|
|
1118
|
+
return errorAnswer({ error: error.apiError });
|
|
1119
|
+
const apiError = call.reportInternalError({
|
|
1120
|
+
report: { method: spec.method, path: spec.path, error },
|
|
1121
|
+
logSource: `${spec.method.toUpperCase()} ${spec.path}`,
|
|
1122
|
+
message: internalErrorMessage({ method: spec.method })
|
|
1123
|
+
}, { onInternalError: host?.onInternalError });
|
|
1124
|
+
return errorAnswer({ error: apiError });
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// src/xai/preset.ts
|
|
1128
|
+
var XAI_OAUTH_PROVIDER_ID = "xai";
|
|
1129
|
+
var XAI_OAUTH_REDIRECT_HOST = "127.0.0.1";
|
|
1130
|
+
var XAI_OAUTH_REDIRECT_PORT = 56121;
|
|
1131
|
+
var XAI_OAUTH_REDIRECT_PATH = "/callback";
|
|
1132
|
+
var XAI_OAUTH_PROVIDER_CONFIG = {
|
|
1133
|
+
providerId: XAI_OAUTH_PROVIDER_ID,
|
|
1134
|
+
issuer: "https://auth.x.ai",
|
|
1135
|
+
authorizationEndpoint: "https://auth.x.ai/oauth2/authorize",
|
|
1136
|
+
tokenEndpoint: "https://auth.x.ai/oauth2/token",
|
|
1137
|
+
clientId: "b1a00492-073a-47ea-816f-4c329264a828",
|
|
1138
|
+
scope: "openid profile email offline_access grok-cli:access api:access"
|
|
1139
|
+
};
|
|
1140
|
+
function xaiOAuthRedirectUri() {
|
|
1141
|
+
return `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}${XAI_OAUTH_REDIRECT_PATH}`;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/xai/routes.ts
|
|
1145
|
+
var XAI_FAILURE_MESSAGES = {
|
|
1146
|
+
"oauth-start": "xAI sign-in could not start. Try again; if it keeps failing, copy the request ID and report this problem.",
|
|
1147
|
+
"oauth-complete": "xAI sign-in could not be completed. Try again; if it keeps failing, copy the request ID and report this problem.",
|
|
1148
|
+
"oauth-disconnect": "xAI could not be disconnected. Try again; if it keeps failing, copy the request ID and report this problem.",
|
|
1149
|
+
"auth-status": "The xAI connection status could not be read. Try again; if it keeps failing, copy the request ID and report this problem.",
|
|
1150
|
+
search: "The X search could not be completed. Try again; if it keeps failing, copy the request ID and report this problem."
|
|
1151
|
+
};
|
|
1152
|
+
var DEFAULT_TOKEN_FILE_NAME = "xai-oauth-token.json";
|
|
1153
|
+
var DEFAULT_PENDING_AUTH_TTL_MS = 30 * 60 * 1e3;
|
|
1154
|
+
var DEFAULT_SEARCH_BASE_URL = "https://api.x.ai/v1";
|
|
1155
|
+
var DEFAULT_SEARCH_MODEL = "grok-4.20-reasoning";
|
|
1156
|
+
var DEFAULT_SEARCH_TIMEOUT_MS = 3e4;
|
|
1157
|
+
function reportXaiInternalError({ resolved, source, error }, _optional = {}) {
|
|
1158
|
+
return resolved.reportInternalError({ report: { source, error }, logSource: `xai/${source}`, message: XAI_FAILURE_MESSAGES[source] });
|
|
1159
|
+
}
|
|
1160
|
+
function resolveXaiHttpDeps(deps) {
|
|
1161
|
+
return { ...resolveOAuthFlowDeps(deps), ...resolveStorageAndSearchDeps(deps) };
|
|
1162
|
+
}
|
|
1163
|
+
function resolveOAuthFlowDeps(deps) {
|
|
1164
|
+
return {
|
|
1165
|
+
providerConfig: deps.providerConfig ?? XAI_OAUTH_PROVIDER_CONFIG,
|
|
1166
|
+
callbackHost: deps.callbackHost ?? XAI_OAUTH_REDIRECT_HOST,
|
|
1167
|
+
callbackPort: deps.callbackPort ?? XAI_OAUTH_REDIRECT_PORT,
|
|
1168
|
+
callbackPath: deps.callbackPath ?? XAI_OAUTH_REDIRECT_PATH,
|
|
1169
|
+
pending: deps.pending ?? deps.oauth.createPendingCache({}, { ttlMs: DEFAULT_PENDING_AUTH_TTL_MS }),
|
|
1170
|
+
listenerRef: deps.listenerRef ?? { current: null },
|
|
1171
|
+
oauth: deps.oauth,
|
|
1172
|
+
baseUrlGuard: deps.baseUrlGuard,
|
|
1173
|
+
now: deps.now
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
function resolveStorageAndSearchDeps(deps) {
|
|
1177
|
+
return {
|
|
1178
|
+
dataDir: deps.dataDir ?? process.cwd(),
|
|
1179
|
+
tokenFileName: deps.tokenFileName ?? DEFAULT_TOKEN_FILE_NAME,
|
|
1180
|
+
searchBaseUrl: deps.searchBaseUrl ?? DEFAULT_SEARCH_BASE_URL,
|
|
1181
|
+
searchDefaultModel: deps.searchDefaultModel ?? DEFAULT_SEARCH_MODEL,
|
|
1182
|
+
fetchImpl: deps.fetchImpl ?? fetch,
|
|
1183
|
+
searchTimeoutMs: deps.searchTimeoutMs ?? DEFAULT_SEARCH_TIMEOUT_MS,
|
|
1184
|
+
reportInternalError: deps.reportInternalError
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
function xaiRedirectUri(resolved) {
|
|
1188
|
+
return `http://${resolved.callbackHost}:${resolved.callbackPort}${resolved.callbackPath}`;
|
|
1189
|
+
}
|
|
1190
|
+
var pendingOAuthStates = /* @__PURE__ */ new WeakMap();
|
|
1191
|
+
async function stopListener({ listenerRef, pending }, _optional = {}) {
|
|
1192
|
+
const state = pendingOAuthStates.get(listenerRef);
|
|
1193
|
+
pendingOAuthStates.delete(listenerRef);
|
|
1194
|
+
if (state !== void 0) pending.consume({ state });
|
|
1195
|
+
const current = listenerRef.current;
|
|
1196
|
+
listenerRef.current = null;
|
|
1197
|
+
if (!current) return;
|
|
1198
|
+
try {
|
|
1199
|
+
await current.stop();
|
|
1200
|
+
} catch {
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
var oauthStartQueues = /* @__PURE__ */ new WeakMap();
|
|
1204
|
+
function serializeOauthStart(key, task) {
|
|
1205
|
+
const previous = oauthStartQueues.get(key) ?? Promise.resolve();
|
|
1206
|
+
const next = previous.then(task, task);
|
|
1207
|
+
oauthStartQueues.set(key, next.then(() => void 0, () => void 0));
|
|
1208
|
+
return next;
|
|
1209
|
+
}
|
|
1210
|
+
function toStoredOAuthToken({ tokenResp, nowMs }) {
|
|
1211
|
+
const stored = {
|
|
1212
|
+
accessToken: tokenResp.access_token,
|
|
1213
|
+
tokenType: tokenResp.token_type ?? "Bearer",
|
|
1214
|
+
savedAt: nowMs
|
|
1215
|
+
};
|
|
1216
|
+
if (tokenResp.refresh_token) stored.refreshToken = tokenResp.refresh_token;
|
|
1217
|
+
if (tokenResp.scope) stored.scope = tokenResp.scope;
|
|
1218
|
+
if (typeof tokenResp.expires_in === "number") {
|
|
1219
|
+
stored.expiresAt = nowMs + tokenResp.expires_in * 1e3;
|
|
1220
|
+
}
|
|
1221
|
+
return stored;
|
|
1222
|
+
}
|
|
1223
|
+
async function persistToken(resolved, tokenResp) {
|
|
1224
|
+
const stored = toStoredOAuthToken({ tokenResp, nowMs: resolved.now() });
|
|
1225
|
+
await resolved.oauth.tokens.set({ dataDir: resolved.dataDir, fileName: resolved.tokenFileName, token: stored });
|
|
1226
|
+
}
|
|
1227
|
+
async function handleListenerCallback(resolved, outcome) {
|
|
1228
|
+
resolved.listenerRef.current = null;
|
|
1229
|
+
if (outcome.kind !== "ok") {
|
|
1230
|
+
reportXaiInternalError({ resolved, source: "oauth-start", error: new Error(`xAI OAuth callback failed: ${outcome.error}`) });
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
try {
|
|
1234
|
+
const tokenResp = await resolved.oauth.complete({
|
|
1235
|
+
config: resolved.providerConfig,
|
|
1236
|
+
pending: resolved.pending,
|
|
1237
|
+
state: outcome.state,
|
|
1238
|
+
code: outcome.code
|
|
1239
|
+
}, {
|
|
1240
|
+
fetchImpl: resolved.fetchImpl
|
|
1241
|
+
});
|
|
1242
|
+
await persistToken(resolved, tokenResp);
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
reportXaiInternalError({ resolved, source: "oauth-start", error });
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
function isRecord(value) {
|
|
1248
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1249
|
+
}
|
|
1250
|
+
function nonEmptyString(value) {
|
|
1251
|
+
if (typeof value !== "string") return null;
|
|
1252
|
+
const trimmed = value.trim();
|
|
1253
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
1254
|
+
}
|
|
1255
|
+
function parseOptionalString(body, key) {
|
|
1256
|
+
const value = body[key];
|
|
1257
|
+
if (value === void 0) return ok({ value: void 0 });
|
|
1258
|
+
if (typeof value !== "string") return err({ error: validationError({ message: `${key} must be a string when provided` }) });
|
|
1259
|
+
return ok({ value });
|
|
1260
|
+
}
|
|
1261
|
+
function parseOptionalBoolean(body, key) {
|
|
1262
|
+
const value = body[key];
|
|
1263
|
+
if (value === void 0) return ok({ value: void 0 });
|
|
1264
|
+
if (typeof value !== "boolean") return err({ error: validationError({ message: `${key} must be a boolean when provided` }) });
|
|
1265
|
+
return ok({ value });
|
|
1266
|
+
}
|
|
1267
|
+
function parseOptionalStringArray(body, key) {
|
|
1268
|
+
const value = body[key];
|
|
1269
|
+
if (value === void 0) return ok({ value: void 0 });
|
|
1270
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
|
|
1271
|
+
return err({ error: validationError({ message: `${key} must be an array of strings when provided` }) });
|
|
1272
|
+
}
|
|
1273
|
+
return ok({ value });
|
|
1274
|
+
}
|
|
1275
|
+
var xaiOauthStartRoute = defineJsonRoute({
|
|
1276
|
+
method: "post",
|
|
1277
|
+
path: "/api/xai/oauth/start",
|
|
1278
|
+
parse: () => ok({ value: void 0 }),
|
|
1279
|
+
handle: async ({ input: _input, deps }) => {
|
|
1280
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1281
|
+
return serializeOauthStart(resolved.listenerRef, async () => {
|
|
1282
|
+
if (resolved.listenerRef.current !== null) {
|
|
1283
|
+
return err({
|
|
1284
|
+
error: createApiError({ code: "OAUTH_FLOW_IN_PROGRESS", message: "an xAI OAuth flow is already in progress \u2014 complete it, or cancel it via POST /api/xai/oauth/cancel, before starting a new one" })
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
try {
|
|
1288
|
+
const { authorizeUrl, state } = resolved.oauth.begin({
|
|
1289
|
+
config: resolved.providerConfig,
|
|
1290
|
+
pending: resolved.pending,
|
|
1291
|
+
redirectUri: xaiRedirectUri(resolved)
|
|
1292
|
+
});
|
|
1293
|
+
pendingOAuthStates.set(resolved.listenerRef, state);
|
|
1294
|
+
const listener = await resolved.oauth.startCallbackListener({
|
|
1295
|
+
host: resolved.callbackHost,
|
|
1296
|
+
port: resolved.callbackPort,
|
|
1297
|
+
path: resolved.callbackPath,
|
|
1298
|
+
expectedState: state,
|
|
1299
|
+
onCallback: (outcome) => handleListenerCallback(resolved, outcome)
|
|
1300
|
+
});
|
|
1301
|
+
resolved.listenerRef.current = listener;
|
|
1302
|
+
return ok({
|
|
1303
|
+
value: {
|
|
1304
|
+
authorizeUrl,
|
|
1305
|
+
state,
|
|
1306
|
+
callback: { host: listener.address.host, port: listener.address.port }
|
|
1307
|
+
}
|
|
1308
|
+
});
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
await stopListener(resolved);
|
|
1311
|
+
return err({ error: reportXaiInternalError({ resolved, source: "oauth-start", error }) });
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
}, { requireSameOrigin: true });
|
|
1316
|
+
function parseXaiOauthComplete(input) {
|
|
1317
|
+
if (!isRecord(input.body)) return err({ error: validationError({ message: "body must be a JSON object" }) });
|
|
1318
|
+
const state = nonEmptyString(input.body.state);
|
|
1319
|
+
if (!state) return err({ error: validationError({ message: "state must be a non-empty string" }, { issues: [{ path: "state", message: "required non-empty string" }] }) });
|
|
1320
|
+
const code = nonEmptyString(input.body.code);
|
|
1321
|
+
if (!code) return err({ error: validationError({ message: "code must be a non-empty string" }, { issues: [{ path: "code", message: "required non-empty string" }] }) });
|
|
1322
|
+
return ok({ value: { state, code } });
|
|
1323
|
+
}
|
|
1324
|
+
var xaiOauthCompleteRoute = defineJsonRoute({
|
|
1325
|
+
method: "post",
|
|
1326
|
+
path: "/api/xai/oauth/complete",
|
|
1327
|
+
parse: parseXaiOauthComplete,
|
|
1328
|
+
handle: async ({ input: { state, code }, deps }) => {
|
|
1329
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1330
|
+
try {
|
|
1331
|
+
const tokenResp = await resolved.oauth.complete({
|
|
1332
|
+
config: resolved.providerConfig,
|
|
1333
|
+
pending: resolved.pending,
|
|
1334
|
+
state,
|
|
1335
|
+
code
|
|
1336
|
+
}, {
|
|
1337
|
+
fetchImpl: resolved.fetchImpl
|
|
1338
|
+
});
|
|
1339
|
+
await persistToken(resolved, tokenResp);
|
|
1340
|
+
await stopListener(resolved);
|
|
1341
|
+
return ok({ value: { ok: true } });
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1344
|
+
if (message.startsWith(`${resolved.providerConfig.providerId} OAuth state`)) {
|
|
1345
|
+
return err({ error: validationError({ message }) });
|
|
1346
|
+
}
|
|
1347
|
+
return err({ error: reportXaiInternalError({ resolved, source: "oauth-complete", error }) });
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}, { requireSameOrigin: true });
|
|
1351
|
+
var xaiOauthCancelRoute = defineJsonRoute({
|
|
1352
|
+
method: "post",
|
|
1353
|
+
path: "/api/xai/oauth/cancel",
|
|
1354
|
+
parse: () => ok({ value: void 0 }),
|
|
1355
|
+
handle: async ({ input: _input, deps }) => {
|
|
1356
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1357
|
+
await stopListener(resolved);
|
|
1358
|
+
return ok({ value: { ok: true } });
|
|
1359
|
+
}
|
|
1360
|
+
}, { requireSameOrigin: true });
|
|
1361
|
+
var xaiAuthStatusRoute = defineJsonRoute({
|
|
1362
|
+
method: "get",
|
|
1363
|
+
path: "/api/xai/auth/status",
|
|
1364
|
+
parse: () => ok({ value: void 0 }),
|
|
1365
|
+
handle: async ({ input: _input, deps }) => {
|
|
1366
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1367
|
+
try {
|
|
1368
|
+
const token = await resolved.oauth.tokens.get({ dataDir: resolved.dataDir, fileName: resolved.tokenFileName });
|
|
1369
|
+
const listening = resolved.listenerRef.current !== null;
|
|
1370
|
+
if (!token) return ok({ value: { connected: false, expiresAt: null, scope: null, savedAt: null, listening } });
|
|
1371
|
+
return ok({
|
|
1372
|
+
value: {
|
|
1373
|
+
connected: true,
|
|
1374
|
+
expiresAt: token.expiresAt ?? null,
|
|
1375
|
+
scope: token.scope ?? null,
|
|
1376
|
+
savedAt: token.savedAt,
|
|
1377
|
+
listening
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
return err({ error: reportXaiInternalError({ resolved, source: "auth-status", error }) });
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}, { requireSameOrigin: true });
|
|
1385
|
+
var xaiOauthDisconnectRoute = defineJsonRoute({
|
|
1386
|
+
method: "post",
|
|
1387
|
+
path: "/api/xai/oauth/disconnect",
|
|
1388
|
+
parse: () => ok({ value: void 0 }),
|
|
1389
|
+
handle: async ({ input: _input, deps }) => {
|
|
1390
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1391
|
+
try {
|
|
1392
|
+
await stopListener(resolved);
|
|
1393
|
+
await resolved.oauth.tokens.clear({ dataDir: resolved.dataDir, fileName: resolved.tokenFileName });
|
|
1394
|
+
return ok({ value: { ok: true } });
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
return err({ error: reportXaiInternalError({ resolved, source: "oauth-disconnect", error }) });
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}, { requireSameOrigin: true });
|
|
1400
|
+
function parseXaiSearch(input) {
|
|
1401
|
+
if (!isRecord(input.body)) return err({ error: validationError({ message: "body must be a JSON object" }) });
|
|
1402
|
+
const body = input.body;
|
|
1403
|
+
const query = nonEmptyString(body.query);
|
|
1404
|
+
if (!query) return err({ error: validationError({ message: "query must be a non-empty string" }, { issues: [{ path: "query", message: "required non-empty string" }] }) });
|
|
1405
|
+
const fields = {};
|
|
1406
|
+
for (const [key, parse] of XAI_SEARCH_OPTIONAL_FIELDS) {
|
|
1407
|
+
const parsed = parse(body, key);
|
|
1408
|
+
if (!parsed.ok) return parsed;
|
|
1409
|
+
if (isProvidedSearchValue(parsed.value)) fields[key] = parsed.value;
|
|
1410
|
+
}
|
|
1411
|
+
return ok({ value: { query, ...fields } });
|
|
1412
|
+
}
|
|
1413
|
+
var XAI_SEARCH_OPTIONAL_FIELDS = [
|
|
1414
|
+
["allowedXHandles", parseOptionalStringArray],
|
|
1415
|
+
["excludedXHandles", parseOptionalStringArray],
|
|
1416
|
+
["fromDate", parseOptionalString],
|
|
1417
|
+
["toDate", parseOptionalString],
|
|
1418
|
+
["enableImageUnderstanding", parseOptionalBoolean],
|
|
1419
|
+
["enableVideoUnderstanding", parseOptionalBoolean],
|
|
1420
|
+
["model", parseOptionalString]
|
|
1421
|
+
];
|
|
1422
|
+
function isProvidedSearchValue(value) {
|
|
1423
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
1424
|
+
return value !== void 0 && value !== "";
|
|
1425
|
+
}
|
|
1426
|
+
function outputContentBlocks(data) {
|
|
1427
|
+
const output = data.output;
|
|
1428
|
+
if (!Array.isArray(output)) return [];
|
|
1429
|
+
return output.filter(isRecord).flatMap((item) => Array.isArray(item.content) ? item.content.filter(isRecord) : []);
|
|
1430
|
+
}
|
|
1431
|
+
function extractAnswerText(data) {
|
|
1432
|
+
if (!isRecord(data)) return "";
|
|
1433
|
+
const direct = data.output_text;
|
|
1434
|
+
if (typeof direct === "string" && direct.trim()) return direct;
|
|
1435
|
+
const chunks = outputContentBlocks(data).map((block) => block.text).filter((text) => typeof text === "string" && text.length > 0);
|
|
1436
|
+
return chunks.join("\n").trim();
|
|
1437
|
+
}
|
|
1438
|
+
function urlCitationOf(annotation) {
|
|
1439
|
+
if (!isRecord(annotation) || annotation.type !== "url_citation") return "";
|
|
1440
|
+
return typeof annotation.url === "string" ? annotation.url.trim() : "";
|
|
1441
|
+
}
|
|
1442
|
+
function extractUrlCitations(data) {
|
|
1443
|
+
if (!isRecord(data)) return [];
|
|
1444
|
+
const urls = outputContentBlocks(data).flatMap((block) => Array.isArray(block.annotations) ? block.annotations : []).map(urlCitationOf).filter((url) => url.length > 0);
|
|
1445
|
+
return [...new Set(urls)];
|
|
1446
|
+
}
|
|
1447
|
+
function buildXSearchTool(request) {
|
|
1448
|
+
const xSearchTool = { type: "x_search" };
|
|
1449
|
+
if (request.allowedXHandles?.length) xSearchTool.allowed_x_handles = request.allowedXHandles;
|
|
1450
|
+
if (request.excludedXHandles?.length) xSearchTool.excluded_x_handles = request.excludedXHandles;
|
|
1451
|
+
if (request.fromDate) xSearchTool.from_date = request.fromDate;
|
|
1452
|
+
if (request.toDate) xSearchTool.to_date = request.toDate;
|
|
1453
|
+
if (request.enableImageUnderstanding === true) xSearchTool.enable_image_understanding = true;
|
|
1454
|
+
if (request.enableVideoUnderstanding === true) xSearchTool.enable_video_understanding = true;
|
|
1455
|
+
return xSearchTool;
|
|
1456
|
+
}
|
|
1457
|
+
function xaiCallFailure(guard, prefix, error) {
|
|
1458
|
+
if (guard.signal.aborted) return new Error(guard.timedOutMessage);
|
|
1459
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1460
|
+
return new Error(redactSecrets({ input: `${prefix}: ${message}` }, { exactSecrets: [guard.accessToken] }));
|
|
1461
|
+
}
|
|
1462
|
+
async function postXaiResponses({ fetchImpl, url, requestBody, guard }) {
|
|
1463
|
+
let response;
|
|
1464
|
+
try {
|
|
1465
|
+
response = await fetchImpl(url, {
|
|
1466
|
+
method: "POST",
|
|
1467
|
+
headers: { authorization: `Bearer ${guard.accessToken}`, "content-type": "application/json" },
|
|
1468
|
+
body: JSON.stringify(requestBody),
|
|
1469
|
+
signal: guard.signal
|
|
1470
|
+
});
|
|
1471
|
+
} catch (error) {
|
|
1472
|
+
throw xaiCallFailure(guard, "xAI request failed", error);
|
|
1473
|
+
}
|
|
1474
|
+
if (!response.ok) {
|
|
1475
|
+
const text = await response.text().catch(() => "");
|
|
1476
|
+
throw new Error(redactSecrets({ input: `xAI ${response.status}: ${text.slice(0, 240) || "no body"}` }, { exactSecrets: [guard.accessToken] }));
|
|
1477
|
+
}
|
|
1478
|
+
return response;
|
|
1479
|
+
}
|
|
1480
|
+
async function readXaiJson(response, guard) {
|
|
1481
|
+
try {
|
|
1482
|
+
return await response.json();
|
|
1483
|
+
} catch (error) {
|
|
1484
|
+
throw xaiCallFailure(guard, "xAI response could not be read", error);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
async function callXaiSearch(resolved, accessToken, request) {
|
|
1488
|
+
const baseUrlCheck = resolved.baseUrlGuard.validate({ baseUrl: resolved.searchBaseUrl });
|
|
1489
|
+
if (baseUrlCheck.error) throw new Error(baseUrlCheck.error);
|
|
1490
|
+
const base = trimCharsEnd({ text: resolved.searchBaseUrl, chars: "/" });
|
|
1491
|
+
const model = request.model ?? resolved.searchDefaultModel;
|
|
1492
|
+
const requestBody = {
|
|
1493
|
+
model,
|
|
1494
|
+
input: [{ role: "user", content: request.query }],
|
|
1495
|
+
tools: [buildXSearchTool(request)],
|
|
1496
|
+
store: false
|
|
1497
|
+
};
|
|
1498
|
+
const timeoutController = new AbortController();
|
|
1499
|
+
const timeoutHandle = setTimeout(() => timeoutController.abort(), resolved.searchTimeoutMs);
|
|
1500
|
+
const guard = {
|
|
1501
|
+
signal: timeoutController.signal,
|
|
1502
|
+
timedOutMessage: `xAI request timed out after ${resolved.searchTimeoutMs}ms`,
|
|
1503
|
+
accessToken
|
|
1504
|
+
};
|
|
1505
|
+
try {
|
|
1506
|
+
const response = await postXaiResponses({ fetchImpl: resolved.fetchImpl, url: `${base}/responses`, requestBody, guard });
|
|
1507
|
+
const data = await readXaiJson(response, guard);
|
|
1508
|
+
return { answer: extractAnswerText(data), citations: extractUrlCitations(data), model };
|
|
1509
|
+
} finally {
|
|
1510
|
+
clearTimeout(timeoutHandle);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
var xaiSearchRoute = defineJsonRoute({
|
|
1514
|
+
method: "post",
|
|
1515
|
+
path: "/api/xai/search",
|
|
1516
|
+
parse: parseXaiSearch,
|
|
1517
|
+
handle: async ({ input: request, deps }) => {
|
|
1518
|
+
const resolved = resolveXaiHttpDeps(deps);
|
|
1519
|
+
let credential;
|
|
1520
|
+
try {
|
|
1521
|
+
credential = await resolved.oauth.resolveBearer({ config: resolved.providerConfig, tokenFileName: resolved.tokenFileName, dataDir: resolved.dataDir }, { fetchImpl: resolved.fetchImpl });
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
return err({ error: reportXaiInternalError({ resolved, source: "search", error }) });
|
|
1524
|
+
}
|
|
1525
|
+
if (!credential) {
|
|
1526
|
+
return err({ error: createApiError({ code: "NOT_CONFIGURED", message: "no xAI account connected \u2014 sign in via /api/xai/oauth/start first" }) });
|
|
1527
|
+
}
|
|
1528
|
+
try {
|
|
1529
|
+
const result = await callXaiSearch(resolved, credential.accessToken, request);
|
|
1530
|
+
return ok({ value: result });
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
return err({ error: reportXaiInternalError({ resolved, source: "search", error }) });
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}, { requireSameOrigin: true });
|
|
1536
|
+
function withHostReporter({ deps, host }, _optional = {}) {
|
|
1537
|
+
return Object.create(deps, { reportInternalError: { value: host.reportInternalError, enumerable: true } });
|
|
1538
|
+
}
|
|
1539
|
+
function hostedJsonRoute({ spec, deps, host }, _optional = {}) {
|
|
1540
|
+
const maxBodyBytes = Math.min(spec.maxBodyBytes ?? host.jsonBodyMaxBytes, host.jsonBodyMaxBytes);
|
|
1541
|
+
return jsonRoute({ spec: { ...spec, maxBodyBytes }, deps, reportInternalError: host.reportInternalError }, { host: host.context });
|
|
1542
|
+
}
|
|
1543
|
+
function xaiRoutes({ deps, host }, _optional = {}) {
|
|
1544
|
+
const routeDeps = resolveXaiHttpDeps(withHostReporter({ deps, host }));
|
|
1545
|
+
const json = (spec) => hostedJsonRoute({ spec, deps: routeDeps, host });
|
|
1546
|
+
return [json(xaiOauthStartRoute), json(xaiOauthCompleteRoute), json(xaiOauthCancelRoute), json(xaiAuthStatusRoute), json(xaiOauthDisconnectRoute), json(xaiSearchRoute)];
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
// src/xai/index.ts
|
|
1550
|
+
function createXaiRoutesProvider(_required, _optional = {}) {
|
|
1551
|
+
return { port: { routes: xaiRoutes, providerConfig: XAI_OAUTH_PROVIDER_CONFIG, redirectUri: xaiOAuthRedirectUri }, dispose: (_required2, _optional2 = {}) => {
|
|
1552
|
+
} };
|
|
1553
|
+
}
|
|
1554
|
+
var WIRE_METHODS = [
|
|
1555
|
+
"requireApiKey",
|
|
1556
|
+
"imageAspectFor",
|
|
1557
|
+
"imageGenerationUrl",
|
|
1558
|
+
"jsonPostInit",
|
|
1559
|
+
"parseJson",
|
|
1560
|
+
"imageBytesFromData",
|
|
1561
|
+
"sniffImageExt",
|
|
1562
|
+
"createRawBytesParser"
|
|
1563
|
+
];
|
|
1564
|
+
var XaiMediaConfigError = class extends Error {
|
|
1565
|
+
code = "xai_media_context_missing";
|
|
1566
|
+
details;
|
|
1567
|
+
constructor(required, _optional = {}) {
|
|
1568
|
+
super("The xAI media provider was started without the media helpers it needs, so it cannot generate media. Restart the app; if this keeps happening, copy the details into a bug report.");
|
|
1569
|
+
this.name = "XaiMediaConfigError";
|
|
1570
|
+
this.details = required.details;
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
function readMediaWire({ context }, _optional = {}) {
|
|
1574
|
+
const record = context !== null && typeof context === "object" ? context : {};
|
|
1575
|
+
const wire = record.mediaWire !== null && typeof record.mediaWire === "object" ? record.mediaWire : {};
|
|
1576
|
+
const missing = WIRE_METHODS.filter((name) => typeof wire[name] !== "function");
|
|
1577
|
+
if (missing.length > 0) throw new XaiMediaConfigError({ details: `optional.context.mediaWire is missing: ${missing.join(", ")}` });
|
|
1578
|
+
return wire;
|
|
1579
|
+
}
|
|
1580
|
+
function createXaiMediaProvider(_required, optional = {}) {
|
|
1581
|
+
return { port: createXaiMediaContribution({ mediaWire: readMediaWire({ context: optional.context }) }), dispose: (_required2, _optional = {}) => {
|
|
1582
|
+
} };
|
|
1583
|
+
}
|
|
1584
|
+
var index_default = {
|
|
1585
|
+
definition: {
|
|
1586
|
+
setup(sdk) {
|
|
1587
|
+
sdk.providers.register({ contract: "xai_routes", id: "xai", contractVersion: 1, factory: createXaiRoutesProvider });
|
|
1588
|
+
sdk.providers.register({ contract: "media", id: XAI_MEDIA_PROVIDER_ID, contractVersion: 1, factory: createXaiMediaProvider });
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
export {
|
|
1593
|
+
XaiMediaConfigError,
|
|
1594
|
+
createXaiMediaProvider,
|
|
1595
|
+
createXaiRoutesProvider,
|
|
1596
|
+
index_default as default
|
|
1597
|
+
};
|