@copilotkit/shared 2.0.0-rc.20 → 2.0.0-rc.22
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/dist/attachments/types.d.cts +1 -3
- package/dist/attachments/types.d.cts.map +1 -1
- package/dist/attachments/types.d.mts +1 -3
- package/dist/attachments/types.d.mts.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.umd.js +26 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/inspector-visibility.cjs +25 -3
- package/dist/utils/inspector-visibility.cjs.map +1 -1
- package/dist/utils/inspector-visibility.d.cts +26 -3
- package/dist/utils/inspector-visibility.d.cts.map +1 -1
- package/dist/utils/inspector-visibility.d.mts +26 -3
- package/dist/utils/inspector-visibility.d.mts.map +1 -1
- package/dist/utils/inspector-visibility.mjs +25 -4
- package/dist/utils/inspector-visibility.mjs.map +1 -1
- package/package.json +1 -1
- package/src/attachments/types.ts +1 -3
- package/src/utils/inspector-visibility.test.ts +26 -0
- package/src/utils/inspector-visibility.ts +35 -3
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/dist/utils/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, Copi
|
|
|
3
3
|
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.cjs";
|
|
4
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.cjs";
|
|
5
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.cjs";
|
|
6
|
-
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.cjs";
|
|
6
|
+
import { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.cjs";
|
|
7
7
|
import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.cjs";
|
|
8
8
|
import { randomId, randomUUID } from "./random-id.cjs";
|
|
9
9
|
import { processEnv } from "./process-env.cjs";
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, Copi
|
|
|
3
3
|
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
4
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
5
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
6
|
-
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.mjs";
|
|
6
|
+
import { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.mjs";
|
|
7
7
|
import { A2UIRuntimeInfo, AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeEntitlementResponse, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode, SingleRouteRuntimeInfo, ThreadEndpointRuntimeInfo } from "./types.mjs";
|
|
8
8
|
import { randomId, randomUUID } from "./random-id.mjs";
|
|
9
9
|
import { processEnv } from "./process-env.mjs";
|
package/dist/utils/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, Copi
|
|
|
3
3
|
import { actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
4
4
|
import { parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
5
5
|
import { parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
6
|
-
import { shouldEnableInspector } from "./inspector-visibility.mjs";
|
|
6
|
+
import { shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS } from "./inspector-visibility.mjs";
|
|
7
7
|
import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "./types.mjs";
|
|
8
8
|
import { randomId, randomUUID } from "./random-id.mjs";
|
|
9
9
|
import { processEnv } from "./process-env.mjs";
|
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/utils/inspector-visibility.ts
|
|
3
3
|
/**
|
|
4
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
5
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
6
|
+
*
|
|
7
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
8
|
+
*/
|
|
9
|
+
const ɵINSPECTOR_LOOPBACK_HOSTS = Object.freeze([
|
|
10
|
+
"localhost",
|
|
11
|
+
"127.0.0.1",
|
|
12
|
+
"[::1]"
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
4
15
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
5
|
-
* but an explicit `true` never overrides a production or server environment
|
|
16
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
17
|
+
* or a page served from a non-loopback host.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* shouldEnableInspector({
|
|
21
|
+
* enableInspector,
|
|
22
|
+
* isBrowser: true,
|
|
23
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
24
|
+
* hostname: window.location.hostname,
|
|
25
|
+
* });
|
|
6
26
|
*/
|
|
7
|
-
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment }) {
|
|
8
|
-
|
|
27
|
+
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment, hostname }) {
|
|
28
|
+
const isAllowedHost = hostname === void 0 || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
29
|
+
return isBrowser && isDevelopment && enableInspector !== false && isAllowedHost;
|
|
9
30
|
}
|
|
10
31
|
|
|
11
32
|
//#endregion
|
|
12
33
|
exports.shouldEnableInspector = shouldEnableInspector;
|
|
34
|
+
exports.ɵINSPECTOR_LOOPBACK_HOSTS = ɵINSPECTOR_LOOPBACK_HOSTS;
|
|
13
35
|
//# sourceMappingURL=inspector-visibility.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.cjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"inspector-visibility.cjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["/**\n * Hosts the Inspector runs on. The Inspector reads agent state, messages and\n * request headers, so it only mounts on a page served from this machine.\n *\n * @internal Framework adapters use this list. Applications must not depend on it.\n */\nexport const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[] = Object.freeze([\n \"localhost\",\n \"127.0.0.1\",\n \"[::1]\",\n]);\n\nexport interface InspectorVisibilityOptions {\n enableInspector?: boolean;\n isBrowser: boolean;\n isDevelopment: boolean;\n /**\n * The page's `location.hostname`. When set, the Inspector is enabled only on\n * a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development\n * build served on a LAN or tunnel address does not expose it.\n */\n hostname?: string;\n}\n\n/**\n * The Inspector is a development-only browser tool. Consumers may disable it,\n * but an explicit `true` never overrides a production or server environment,\n * or a page served from a non-loopback host.\n *\n * @example\n * shouldEnableInspector({\n * enableInspector,\n * isBrowser: true,\n * isDevelopment: process.env.NODE_ENV === \"development\",\n * hostname: window.location.hostname,\n * });\n */\nexport function shouldEnableInspector({\n enableInspector,\n isBrowser,\n isDevelopment,\n hostname,\n}: InspectorVisibilityOptions) {\n const isAllowedHost =\n hostname === undefined || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);\n return (\n isBrowser && isDevelopment && enableInspector !== false && isAllowedHost\n );\n}\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA+C,OAAO,OAAO;CACxE;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;;AA2BF,SAAgB,sBAAsB,EACpC,iBACA,WACA,eACA,YAC6B;CAC7B,MAAM,gBACJ,aAAa,UAAa,0BAA0B,SAAS,SAAS;AACxE,QACE,aAAa,iBAAiB,oBAAoB,SAAS"}
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
declare const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[];
|
|
2
9
|
interface InspectorVisibilityOptions {
|
|
3
10
|
enableInspector?: boolean;
|
|
4
11
|
isBrowser: boolean;
|
|
5
12
|
isDevelopment: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The page's `location.hostname`. When set, the Inspector is enabled only on
|
|
15
|
+
* a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development
|
|
16
|
+
* build served on a LAN or tunnel address does not expose it.
|
|
17
|
+
*/
|
|
18
|
+
hostname?: string;
|
|
6
19
|
}
|
|
7
20
|
/**
|
|
8
21
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
9
|
-
* but an explicit `true` never overrides a production or server environment
|
|
22
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
23
|
+
* or a page served from a non-loopback host.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* shouldEnableInspector({
|
|
27
|
+
* enableInspector,
|
|
28
|
+
* isBrowser: true,
|
|
29
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
30
|
+
* hostname: window.location.hostname,
|
|
31
|
+
* });
|
|
10
32
|
*/
|
|
11
33
|
declare function shouldEnableInspector({
|
|
12
34
|
enableInspector,
|
|
13
35
|
isBrowser,
|
|
14
|
-
isDevelopment
|
|
36
|
+
isDevelopment,
|
|
37
|
+
hostname
|
|
15
38
|
}: InspectorVisibilityOptions): boolean;
|
|
16
39
|
//#endregion
|
|
17
|
-
export { InspectorVisibilityOptions, shouldEnableInspector };
|
|
40
|
+
export { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
18
41
|
//# sourceMappingURL=inspector-visibility.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.d.cts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"inspector-visibility.d.cts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";;AAMA;;;;;cAAa,yBAAA;AAAA,UAMI,0BAAA;EACf,eAAA;EACA,SAAA;EACA,aAAA;EADA;;;;;EAOA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,qBAAA,CAAA;EACd,eAAA;EACA,SAAA;EACA,aAAA;EACA;AAAA,GACC,0BAAA"}
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
declare const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[];
|
|
2
9
|
interface InspectorVisibilityOptions {
|
|
3
10
|
enableInspector?: boolean;
|
|
4
11
|
isBrowser: boolean;
|
|
5
12
|
isDevelopment: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The page's `location.hostname`. When set, the Inspector is enabled only on
|
|
15
|
+
* a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development
|
|
16
|
+
* build served on a LAN or tunnel address does not expose it.
|
|
17
|
+
*/
|
|
18
|
+
hostname?: string;
|
|
6
19
|
}
|
|
7
20
|
/**
|
|
8
21
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
9
|
-
* but an explicit `true` never overrides a production or server environment
|
|
22
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
23
|
+
* or a page served from a non-loopback host.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* shouldEnableInspector({
|
|
27
|
+
* enableInspector,
|
|
28
|
+
* isBrowser: true,
|
|
29
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
30
|
+
* hostname: window.location.hostname,
|
|
31
|
+
* });
|
|
10
32
|
*/
|
|
11
33
|
declare function shouldEnableInspector({
|
|
12
34
|
enableInspector,
|
|
13
35
|
isBrowser,
|
|
14
|
-
isDevelopment
|
|
36
|
+
isDevelopment,
|
|
37
|
+
hostname
|
|
15
38
|
}: InspectorVisibilityOptions): boolean;
|
|
16
39
|
//#endregion
|
|
17
|
-
export { InspectorVisibilityOptions, shouldEnableInspector };
|
|
40
|
+
export { InspectorVisibilityOptions, shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
18
41
|
//# sourceMappingURL=inspector-visibility.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.d.mts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"inspector-visibility.d.mts","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"mappings":";;AAMA;;;;;cAAa,yBAAA;AAAA,UAMI,0BAAA;EACf,eAAA;EACA,SAAA;EACA,aAAA;EADA;;;;;EAOA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,qBAAA,CAAA;EACd,eAAA;EACA,SAAA;EACA,aAAA;EACA;AAAA,GACC,0BAAA"}
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
//#region src/utils/inspector-visibility.ts
|
|
2
2
|
/**
|
|
3
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
4
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
5
|
+
*
|
|
6
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
7
|
+
*/
|
|
8
|
+
const ɵINSPECTOR_LOOPBACK_HOSTS = Object.freeze([
|
|
9
|
+
"localhost",
|
|
10
|
+
"127.0.0.1",
|
|
11
|
+
"[::1]"
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
3
14
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
4
|
-
* but an explicit `true` never overrides a production or server environment
|
|
15
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
16
|
+
* or a page served from a non-loopback host.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* shouldEnableInspector({
|
|
20
|
+
* enableInspector,
|
|
21
|
+
* isBrowser: true,
|
|
22
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
23
|
+
* hostname: window.location.hostname,
|
|
24
|
+
* });
|
|
5
25
|
*/
|
|
6
|
-
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment }) {
|
|
7
|
-
|
|
26
|
+
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment, hostname }) {
|
|
27
|
+
const isAllowedHost = hostname === void 0 || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
28
|
+
return isBrowser && isDevelopment && enableInspector !== false && isAllowedHost;
|
|
8
29
|
}
|
|
9
30
|
|
|
10
31
|
//#endregion
|
|
11
|
-
export { shouldEnableInspector };
|
|
32
|
+
export { shouldEnableInspector, ɵINSPECTOR_LOOPBACK_HOSTS };
|
|
12
33
|
//# sourceMappingURL=inspector-visibility.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-visibility.mjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"inspector-visibility.mjs","names":[],"sources":["../../src/utils/inspector-visibility.ts"],"sourcesContent":["/**\n * Hosts the Inspector runs on. The Inspector reads agent state, messages and\n * request headers, so it only mounts on a page served from this machine.\n *\n * @internal Framework adapters use this list. Applications must not depend on it.\n */\nexport const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[] = Object.freeze([\n \"localhost\",\n \"127.0.0.1\",\n \"[::1]\",\n]);\n\nexport interface InspectorVisibilityOptions {\n enableInspector?: boolean;\n isBrowser: boolean;\n isDevelopment: boolean;\n /**\n * The page's `location.hostname`. When set, the Inspector is enabled only on\n * a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development\n * build served on a LAN or tunnel address does not expose it.\n */\n hostname?: string;\n}\n\n/**\n * The Inspector is a development-only browser tool. Consumers may disable it,\n * but an explicit `true` never overrides a production or server environment,\n * or a page served from a non-loopback host.\n *\n * @example\n * shouldEnableInspector({\n * enableInspector,\n * isBrowser: true,\n * isDevelopment: process.env.NODE_ENV === \"development\",\n * hostname: window.location.hostname,\n * });\n */\nexport function shouldEnableInspector({\n enableInspector,\n isBrowser,\n isDevelopment,\n hostname,\n}: InspectorVisibilityOptions) {\n const isAllowedHost =\n hostname === undefined || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);\n return (\n isBrowser && isDevelopment && enableInspector !== false && isAllowedHost\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAa,4BAA+C,OAAO,OAAO;CACxE;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;;AA2BF,SAAgB,sBAAsB,EACpC,iBACA,WACA,eACA,YAC6B;CAC7B,MAAM,gBACJ,aAAa,UAAa,0BAA0B,SAAS,SAAS;AACxE,QACE,aAAa,iBAAiB,oBAAoB,SAAS"}
|
package/package.json
CHANGED
package/src/attachments/types.ts
CHANGED
|
@@ -49,9 +49,7 @@ export interface AttachmentsConfig {
|
|
|
49
49
|
* called concurrently unless you raise this. Files past the limit wait for a
|
|
50
50
|
* free slot; `Infinity` lifts it. The limit covers everything in flight, so
|
|
51
51
|
* two selections dropped or pasted at once share the slots rather than each
|
|
52
|
-
* taking the full number.
|
|
53
|
-
* Honored by the React `useAttachments` hook — the Vue and Angular bindings
|
|
54
|
-
* still upload serially.
|
|
52
|
+
* taking the full number. React, Vue and Angular all honor it.
|
|
55
53
|
*/
|
|
56
54
|
maxConcurrentUploads?: number;
|
|
57
55
|
/** Custom upload handler. Return an InputContentSource with optional metadata. */
|
|
@@ -41,3 +41,29 @@ describe("shouldEnableInspector", () => {
|
|
|
41
41
|
).toBe(false);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe("shouldEnableInspector hostname rule", () => {
|
|
46
|
+
const developmentBrowser = { isBrowser: true, isDevelopment: true };
|
|
47
|
+
|
|
48
|
+
it.each(["localhost", "127.0.0.1", "[::1]"])(
|
|
49
|
+
"shows on the loopback host %s",
|
|
50
|
+
(hostname) => {
|
|
51
|
+
expect(shouldEnableInspector({ ...developmentBrowser, hostname })).toBe(
|
|
52
|
+
true,
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
it.each(["192.168.1.20", "dev.example.com", "my-tunnel.ngrok.app"])(
|
|
58
|
+
"hides on the remote host %s, even when explicitly enabled",
|
|
59
|
+
(hostname) => {
|
|
60
|
+
expect(
|
|
61
|
+
shouldEnableInspector({
|
|
62
|
+
...developmentBrowser,
|
|
63
|
+
enableInspector: true,
|
|
64
|
+
hostname,
|
|
65
|
+
}),
|
|
66
|
+
).toBe(false);
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
});
|
|
@@ -1,17 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
3
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
4
|
+
*
|
|
5
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
6
|
+
*/
|
|
7
|
+
export const ɵINSPECTOR_LOOPBACK_HOSTS: readonly string[] = Object.freeze([
|
|
8
|
+
"localhost",
|
|
9
|
+
"127.0.0.1",
|
|
10
|
+
"[::1]",
|
|
11
|
+
]);
|
|
12
|
+
|
|
1
13
|
export interface InspectorVisibilityOptions {
|
|
2
14
|
enableInspector?: boolean;
|
|
3
15
|
isBrowser: boolean;
|
|
4
16
|
isDevelopment: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The page's `location.hostname`. When set, the Inspector is enabled only on
|
|
19
|
+
* a loopback host (see {@link ɵINSPECTOR_LOOPBACK_HOSTS}), so a development
|
|
20
|
+
* build served on a LAN or tunnel address does not expose it.
|
|
21
|
+
*/
|
|
22
|
+
hostname?: string;
|
|
5
23
|
}
|
|
6
24
|
|
|
7
25
|
/**
|
|
8
26
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
9
|
-
* but an explicit `true` never overrides a production or server environment
|
|
27
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
28
|
+
* or a page served from a non-loopback host.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* shouldEnableInspector({
|
|
32
|
+
* enableInspector,
|
|
33
|
+
* isBrowser: true,
|
|
34
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
35
|
+
* hostname: window.location.hostname,
|
|
36
|
+
* });
|
|
10
37
|
*/
|
|
11
38
|
export function shouldEnableInspector({
|
|
12
39
|
enableInspector,
|
|
13
40
|
isBrowser,
|
|
14
41
|
isDevelopment,
|
|
15
|
-
|
|
16
|
-
|
|
42
|
+
hostname,
|
|
43
|
+
}: InspectorVisibilityOptions) {
|
|
44
|
+
const isAllowedHost =
|
|
45
|
+
hostname === undefined || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
46
|
+
return (
|
|
47
|
+
isBrowser && isDevelopment && enableInspector !== false && isAllowedHost
|
|
48
|
+
);
|
|
17
49
|
}
|