@copilotkit/shared 1.72.0 → 1.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/finalize-events.cjs +92 -71
- package/dist/finalize-events.cjs.map +1 -1
- package/dist/finalize-events.d.cts +20 -1
- package/dist/finalize-events.d.cts.map +1 -1
- package/dist/finalize-events.d.mts +20 -1
- package/dist/finalize-events.d.mts.map +1 -1
- package/dist/finalize-events.mjs +92 -72
- package/dist/finalize-events.mjs.map +1 -1
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +218 -72
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/telemetry/events.d.cts +33 -0
- package/dist/telemetry/events.d.cts.map +1 -1
- package/dist/telemetry/events.d.mts +33 -0
- package/dist/telemetry/events.d.mts.map +1 -1
- package/dist/telemetry/index.cjs +3 -0
- package/dist/telemetry/index.d.cts +2 -2
- package/dist/telemetry/index.d.mts +2 -2
- package/dist/telemetry/index.mjs +2 -2
- package/dist/telemetry/model-host.cjs +104 -0
- package/dist/telemetry/model-host.cjs.map +1 -0
- package/dist/telemetry/model-host.d.cts +26 -0
- package/dist/telemetry/model-host.d.cts.map +1 -0
- package/dist/telemetry/model-host.d.mts +26 -0
- package/dist/telemetry/model-host.d.mts.map +1 -0
- package/dist/telemetry/model-host.mjs +102 -0
- package/dist/telemetry/model-host.mjs.map +1 -0
- package/dist/telemetry/sampling.cjs +22 -0
- package/dist/telemetry/sampling.cjs.map +1 -1
- package/dist/telemetry/sampling.d.cts +22 -2
- package/dist/telemetry/sampling.d.cts.map +1 -1
- package/dist/telemetry/sampling.d.mts +22 -2
- package/dist/telemetry/sampling.d.mts.map +1 -1
- package/dist/telemetry/sampling.mjs +20 -1
- package/dist/telemetry/sampling.mjs.map +1 -1
- package/dist/telemetry/telemetry-client.cjs +18 -11
- package/dist/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/telemetry/telemetry-client.d.cts +3 -3
- package/dist/telemetry/telemetry-client.d.cts.map +1 -1
- package/dist/telemetry/telemetry-client.d.mts +3 -3
- package/dist/telemetry/telemetry-client.d.mts.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +19 -12
- package/dist/telemetry/telemetry-client.mjs.map +1 -1
- package/package.json +1 -1
- package/src/finalize-events.test.ts +146 -0
- package/src/finalize-events.ts +124 -124
- package/src/index.ts +9 -1
- package/src/telemetry/events.ts +33 -0
- package/src/telemetry/model-host.test.ts +145 -0
- package/src/telemetry/model-host.ts +155 -0
- package/src/telemetry/sampling.ts +39 -6
- package/src/telemetry/telemetry-blank-license-identity.test.ts +11 -4
- package/src/telemetry/telemetry-client.test.ts +107 -39
- package/src/telemetry/telemetry-client.ts +48 -27
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ModelHostClass } from "./model-host.cjs";
|
|
2
|
+
|
|
1
3
|
//#region src/telemetry/events.d.ts
|
|
2
4
|
type AnalyticsEvents = {
|
|
3
5
|
"oss.runtime.instance_created": RuntimeInstanceCreatedInfo;
|
|
@@ -16,7 +18,28 @@ type AnalyticsEvents = {
|
|
|
16
18
|
hashedLgcKey?: string;
|
|
17
19
|
error?: string;
|
|
18
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* A managed Channel lost its gateway link. Carries only the cause we already
|
|
23
|
+
* compute for the log line — never the Channel name, which is a
|
|
24
|
+
* customer-chosen identifier, and never message content.
|
|
25
|
+
*/
|
|
26
|
+
"oss.runtime.channel_session_dropped": ChannelSessionDroppedInfo; /** A managed Channel's gateway link came back, and how long it was gone. */
|
|
27
|
+
"oss.runtime.channel_session_recovered": {
|
|
28
|
+
downForMs: number;
|
|
29
|
+
};
|
|
19
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Kept identical to the v2 runtime's catalog in
|
|
33
|
+
* `packages/runtime/src/v2/runtime/telemetry/events.ts`. The v1 entrypoint
|
|
34
|
+
* hands its capture scope to the V2 runtime it builds, so that scope has to
|
|
35
|
+
* accept every event the V2 runtime can send, channel events included.
|
|
36
|
+
*/
|
|
37
|
+
interface ChannelSessionDroppedInfo {
|
|
38
|
+
/** Diagnosis of the drop, e.g. `the gateway host answered HTTP 502`. */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** Transport/OS code when the transport named one, e.g. `ECONNRESET`. */
|
|
41
|
+
code?: string;
|
|
42
|
+
}
|
|
20
43
|
interface RuntimeInstanceCreatedInfo {
|
|
21
44
|
actionsAmount: number;
|
|
22
45
|
endpointTypes: string[];
|
|
@@ -28,6 +51,16 @@ interface RuntimeInstanceCreatedInfo {
|
|
|
28
51
|
"cloud.base_url"?: string;
|
|
29
52
|
}
|
|
30
53
|
interface AgentExecutionResponseInfo {
|
|
54
|
+
/**
|
|
55
|
+
* Which vendor the runtime actually sent the completion to, as a closed
|
|
56
|
+
* vocabulary — see `classifyModelHost`. Distinct from `provider` below,
|
|
57
|
+
* which the upstream reports as a model name and which cannot tell Azure,
|
|
58
|
+
* OpenRouter or a local server apart from OpenAI.
|
|
59
|
+
*
|
|
60
|
+
* `unknown` when the developer handed us an already-built model, because
|
|
61
|
+
* the endpoint is unrecoverable from one.
|
|
62
|
+
*/
|
|
63
|
+
llmHostClass?: ModelHostClass;
|
|
31
64
|
provider?: string;
|
|
32
65
|
model?: string;
|
|
33
66
|
langGraphHost?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.cts","names":[],"sources":["../../src/telemetry/events.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.d.cts","names":[],"sources":["../../src/telemetry/events.ts"],"mappings":";;;KAEY,eAAA;EACV,8BAAA,EAAgC,0BAAA;EAChC,qCAAA;IACE,0BAAA;IACA,WAAA;IACA,wBAAA;IACA,sBAAA;IACA,gBAAA;EAAA;EAEF,4CAAA;IAAgD,YAAA;EAAA;EAChD,0CAAA,EAA4C,0BAAA;EAC5C,4CAAA;IACE,YAAA;IACA,KAAA;EAAA;EANA;;;;;EAaF,qCAAA,EAAuC,yBAAA,EARrC;EAUF,uCAAA;IAA2C,SAAA;EAAA;AAAA;;;;AAS7C;;;UAAiB,yBAAA;EAIX;EAFJ,MAAA;EAKyC;EAHzC,IAAA;AAAA;AAAA,UAGe,0BAAA;EACf,aAAA;EACA,aAAA;EACA,YAAA;EACA,eAAA;EACA,YAAA;EACA,wBAAA;EACA,sBAAA;EACA,gBAAA;AAAA;AAAA,UAGe,0BAAA;EAA0B;;;;;;;;;EAUzC,YAAA,GAAe,cAAA;EACf,QAAA;EACA,KAAA;EACA,aAAA;EACA,gBAAA;EACA,YAAA;AAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ModelHostClass } from "./model-host.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/telemetry/events.d.ts
|
|
2
4
|
type AnalyticsEvents = {
|
|
3
5
|
"oss.runtime.instance_created": RuntimeInstanceCreatedInfo;
|
|
@@ -16,7 +18,28 @@ type AnalyticsEvents = {
|
|
|
16
18
|
hashedLgcKey?: string;
|
|
17
19
|
error?: string;
|
|
18
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* A managed Channel lost its gateway link. Carries only the cause we already
|
|
23
|
+
* compute for the log line — never the Channel name, which is a
|
|
24
|
+
* customer-chosen identifier, and never message content.
|
|
25
|
+
*/
|
|
26
|
+
"oss.runtime.channel_session_dropped": ChannelSessionDroppedInfo; /** A managed Channel's gateway link came back, and how long it was gone. */
|
|
27
|
+
"oss.runtime.channel_session_recovered": {
|
|
28
|
+
downForMs: number;
|
|
29
|
+
};
|
|
19
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Kept identical to the v2 runtime's catalog in
|
|
33
|
+
* `packages/runtime/src/v2/runtime/telemetry/events.ts`. The v1 entrypoint
|
|
34
|
+
* hands its capture scope to the V2 runtime it builds, so that scope has to
|
|
35
|
+
* accept every event the V2 runtime can send, channel events included.
|
|
36
|
+
*/
|
|
37
|
+
interface ChannelSessionDroppedInfo {
|
|
38
|
+
/** Diagnosis of the drop, e.g. `the gateway host answered HTTP 502`. */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** Transport/OS code when the transport named one, e.g. `ECONNRESET`. */
|
|
41
|
+
code?: string;
|
|
42
|
+
}
|
|
20
43
|
interface RuntimeInstanceCreatedInfo {
|
|
21
44
|
actionsAmount: number;
|
|
22
45
|
endpointTypes: string[];
|
|
@@ -28,6 +51,16 @@ interface RuntimeInstanceCreatedInfo {
|
|
|
28
51
|
"cloud.base_url"?: string;
|
|
29
52
|
}
|
|
30
53
|
interface AgentExecutionResponseInfo {
|
|
54
|
+
/**
|
|
55
|
+
* Which vendor the runtime actually sent the completion to, as a closed
|
|
56
|
+
* vocabulary — see `classifyModelHost`. Distinct from `provider` below,
|
|
57
|
+
* which the upstream reports as a model name and which cannot tell Azure,
|
|
58
|
+
* OpenRouter or a local server apart from OpenAI.
|
|
59
|
+
*
|
|
60
|
+
* `unknown` when the developer handed us an already-built model, because
|
|
61
|
+
* the endpoint is unrecoverable from one.
|
|
62
|
+
*/
|
|
63
|
+
llmHostClass?: ModelHostClass;
|
|
31
64
|
provider?: string;
|
|
32
65
|
model?: string;
|
|
33
66
|
langGraphHost?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.mts","names":[],"sources":["../../src/telemetry/events.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.d.mts","names":[],"sources":["../../src/telemetry/events.ts"],"mappings":";;;KAEY,eAAA;EACV,8BAAA,EAAgC,0BAAA;EAChC,qCAAA;IACE,0BAAA;IACA,WAAA;IACA,wBAAA;IACA,sBAAA;IACA,gBAAA;EAAA;EAEF,4CAAA;IAAgD,YAAA;EAAA;EAChD,0CAAA,EAA4C,0BAAA;EAC5C,4CAAA;IACE,YAAA;IACA,KAAA;EAAA;EANA;;;;;EAaF,qCAAA,EAAuC,yBAAA,EARrC;EAUF,uCAAA;IAA2C,SAAA;EAAA;AAAA;;;;AAS7C;;;UAAiB,yBAAA;EAIX;EAFJ,MAAA;EAKyC;EAHzC,IAAA;AAAA;AAAA,UAGe,0BAAA;EACf,aAAA;EACA,aAAA;EACA,YAAA;EACA,eAAA;EACA,YAAA;EACA,wBAAA;EACA,sBAAA;EACA,gBAAA;AAAA;AAAA,UAGe,0BAAA;EAA0B;;;;;;;;;EAUzC,YAAA,GAAe,cAAA;EACf,QAAA;EACA,KAAA;EACA,aAAA;EACA,gBAAA;EACA,YAAA;AAAA"}
|
package/dist/telemetry/index.cjs
CHANGED
|
@@ -6,7 +6,10 @@ const require_telemetry_client = require('./telemetry-client.cjs');
|
|
|
6
6
|
|
|
7
7
|
exports.TELEMETRY_EMITTER_V1 = require_sampling.TELEMETRY_EMITTER_V1;
|
|
8
8
|
exports.TELEMETRY_EMITTER_V2 = require_sampling.TELEMETRY_EMITTER_V2;
|
|
9
|
+
exports.TELEMETRY_SURFACE_V1 = require_sampling.TELEMETRY_SURFACE_V1;
|
|
10
|
+
exports.TELEMETRY_SURFACE_V2 = require_sampling.TELEMETRY_SURFACE_V2;
|
|
9
11
|
exports.TelemetryClient = require_telemetry_client.TelemetryClient;
|
|
12
|
+
exports.UNSAMPLED_RATE = require_sampling.UNSAMPLED_RATE;
|
|
10
13
|
exports.computeSamplingMeta = require_sampling.computeSamplingMeta;
|
|
11
14
|
exports.firstNonBlankTelemetryId = require_lambda_client.firstNonBlankTelemetryId;
|
|
12
15
|
exports.isTelemetryDisabled = require_telemetry_disabled.isTelemetryDisabled;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isTelemetryDisabled } from "./telemetry-disabled.cjs";
|
|
2
|
-
import { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryEmitter, TelemetryTransport, computeSamplingMeta } from "./sampling.cjs";
|
|
2
|
+
import { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryEmitter, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.cjs";
|
|
3
3
|
import { LambdaSendOptions, firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense } from "./lambda-client.cjs";
|
|
4
4
|
import { TelemetryCapture, TelemetryClient, TelemetryIdentity } from "./telemetry-client.cjs";
|
|
5
|
-
export { type LambdaSendOptions, SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryCapture, TelemetryClient, TelemetryEmitter, TelemetryIdentity, TelemetryTransport, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
|
5
|
+
export { type LambdaSendOptions, SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryCapture, TelemetryClient, TelemetryEmitter, TelemetryIdentity, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isTelemetryDisabled } from "./telemetry-disabled.mjs";
|
|
2
|
-
import { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryEmitter, TelemetryTransport, computeSamplingMeta } from "./sampling.mjs";
|
|
2
|
+
import { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryEmitter, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.mjs";
|
|
3
3
|
import { LambdaSendOptions, firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense } from "./lambda-client.mjs";
|
|
4
4
|
import { TelemetryCapture, TelemetryClient, TelemetryIdentity } from "./telemetry-client.mjs";
|
|
5
|
-
export { type LambdaSendOptions, SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryCapture, TelemetryClient, TelemetryEmitter, TelemetryIdentity, TelemetryTransport, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
|
5
|
+
export { type LambdaSendOptions, SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryCapture, TelemetryClient, TelemetryEmitter, TelemetryIdentity, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
package/dist/telemetry/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isTelemetryDisabled } from "./telemetry-disabled.mjs";
|
|
2
|
-
import { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, computeSamplingMeta } from "./sampling.mjs";
|
|
2
|
+
import { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, UNSAMPLED_RATE, computeSamplingMeta } from "./sampling.mjs";
|
|
3
3
|
import { firstNonBlankTelemetryId, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense } from "./lambda-client.mjs";
|
|
4
4
|
import { TelemetryClient } from "./telemetry-client.mjs";
|
|
5
5
|
|
|
6
|
-
export { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryClient, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
|
6
|
+
export { TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryClient, UNSAMPLED_RATE, computeSamplingMeta, firstNonBlankTelemetryId, isTelemetryDisabled, lambdaClient, parseAndWarnTelemetryId, parseTelemetryIdFromLicense };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/telemetry/model-host.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every value `classifyModelHost` can return.
|
|
5
|
+
*
|
|
6
|
+
* `other` means a host we observed and did not recognize: a gateway, a proxy,
|
|
7
|
+
* or a vendor we have no rule for. `unknown` means we never saw a host at all,
|
|
8
|
+
* which is the case when a caller hands us an already-built LanguageModel.
|
|
9
|
+
* The two are not interchangeable — one is an unrecognized answer, the other
|
|
10
|
+
* is a missing one, and they need different follow-up.
|
|
11
|
+
*/
|
|
12
|
+
const MODEL_HOST_CLASSES = [
|
|
13
|
+
"openai",
|
|
14
|
+
"azure",
|
|
15
|
+
"openrouter",
|
|
16
|
+
"anthropic",
|
|
17
|
+
"google",
|
|
18
|
+
"vertex",
|
|
19
|
+
"bedrock",
|
|
20
|
+
"groq",
|
|
21
|
+
"unify",
|
|
22
|
+
"minimax",
|
|
23
|
+
"local",
|
|
24
|
+
"other",
|
|
25
|
+
"unknown"
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Host suffixes mapped to their vendor.
|
|
29
|
+
*
|
|
30
|
+
* Matched on label boundaries, never as substrings, so
|
|
31
|
+
* `myresource.openai.azure.com.attacker.test` does not read as Azure.
|
|
32
|
+
*/
|
|
33
|
+
const HOST_SUFFIXES = [
|
|
34
|
+
["openai.azure.com", "azure"],
|
|
35
|
+
["services.ai.azure.com", "azure"],
|
|
36
|
+
["cognitiveservices.azure.com", "azure"],
|
|
37
|
+
["azure-api.net", "azure"],
|
|
38
|
+
["api.openai.com", "openai"],
|
|
39
|
+
["openrouter.ai", "openrouter"],
|
|
40
|
+
["api.anthropic.com", "anthropic"],
|
|
41
|
+
["generativelanguage.googleapis.com", "google"],
|
|
42
|
+
["aiplatform.googleapis.com", "vertex"],
|
|
43
|
+
["api.groq.com", "groq"],
|
|
44
|
+
["api.unify.ai", "unify"],
|
|
45
|
+
["api.minimax.io", "minimax"],
|
|
46
|
+
["api.minimaxi.com", "minimax"]
|
|
47
|
+
];
|
|
48
|
+
/** Suffixes that mean the model runs on the same machine or private network. */
|
|
49
|
+
const LOCAL_SUFFIXES = [
|
|
50
|
+
"localhost",
|
|
51
|
+
"local",
|
|
52
|
+
"internal",
|
|
53
|
+
"docker.internal"
|
|
54
|
+
];
|
|
55
|
+
/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */
|
|
56
|
+
const REGIONAL_HOST_PATTERNS = [[/^[a-z0-9-]+-aiplatform\.googleapis\.com$/, "vertex"], [/^bedrock[a-z0-9.-]*\.[a-z0-9-]+\.amazonaws\.com$/, "bedrock"]];
|
|
57
|
+
/** True when `host` equals `suffix` or sits directly beneath it. */
|
|
58
|
+
function matchesSuffix(host, suffix) {
|
|
59
|
+
return host === suffix || host.endsWith(`.${suffix}`);
|
|
60
|
+
}
|
|
61
|
+
/** True for loopback, unspecified, and RFC 1918 private addresses. */
|
|
62
|
+
function isPrivateAddress(host) {
|
|
63
|
+
if (host === "127.0.0.1" || host === "0.0.0.0" || host === "::1") return true;
|
|
64
|
+
if (/^127\./.test(host)) return true;
|
|
65
|
+
if (/^10\./.test(host) || /^192\.168\./.test(host)) return true;
|
|
66
|
+
const privateClassB = /^172\.(\d{1,3})\./.exec(host);
|
|
67
|
+
if (privateClassB) {
|
|
68
|
+
const secondOctet = Number(privateClassB[1]);
|
|
69
|
+
return secondOctet >= 16 && secondOctet <= 31;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
|
|
75
|
+
*
|
|
76
|
+
* @param baseUrl The endpoint the provider was configured with. Absent when
|
|
77
|
+
* the provider was left on its own default, which is why `providerDefault`
|
|
78
|
+
* exists: "no base URL, provider is openai" means api.openai.com.
|
|
79
|
+
* @param providerDefault What to report when no base URL was supplied. Callers
|
|
80
|
+
* that genuinely cannot observe a host — a pre-built LanguageModel handed in
|
|
81
|
+
* by the developer — leave this alone and get `unknown`.
|
|
82
|
+
*/
|
|
83
|
+
function classifyModelHost(baseUrl, providerDefault = "unknown") {
|
|
84
|
+
const trimmed = baseUrl?.trim();
|
|
85
|
+
if (!trimmed) return providerDefault;
|
|
86
|
+
let host;
|
|
87
|
+
try {
|
|
88
|
+
host = new URL(trimmed).hostname.toLowerCase();
|
|
89
|
+
} catch {
|
|
90
|
+
return "other";
|
|
91
|
+
}
|
|
92
|
+
host = host.replace(/^\[|\]$/g, "");
|
|
93
|
+
if (!host) return "other";
|
|
94
|
+
if (isPrivateAddress(host)) return "local";
|
|
95
|
+
for (const suffix of LOCAL_SUFFIXES) if (matchesSuffix(host, suffix)) return "local";
|
|
96
|
+
for (const [suffix, hostClass] of HOST_SUFFIXES) if (matchesSuffix(host, suffix)) return hostClass;
|
|
97
|
+
for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) if (pattern.test(host)) return hostClass;
|
|
98
|
+
return "other";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.MODEL_HOST_CLASSES = MODEL_HOST_CLASSES;
|
|
103
|
+
exports.classifyModelHost = classifyModelHost;
|
|
104
|
+
//# sourceMappingURL=model-host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-host.cjs","names":[],"sources":["../../src/telemetry/model-host.ts"],"sourcesContent":["// Which endpoint the runtime sends completions to, as a closed vocabulary.\n//\n// The AI SDK's provider label cannot answer this. `createOpenAI` stamps\n// `openai.responses` on every model it builds, whether the base URL points at\n// api.openai.com, Azure, OpenRouter or a laptop running Ollama — and Azure's\n// own migration guide tells customers to use exactly that client. So the\n// provider field reports the wire protocol, and the host reports the vendor.\n//\n// Only the classification travels. A base URL like\n// `myresource.openai.azure.com` carries the customer's Azure resource name,\n// which identifies them, so the raw host must never reach telemetry. That is\n// why this returns a member of a fixed list rather than anything derived from\n// the input.\n\n/**\n * Every value `classifyModelHost` can return.\n *\n * `other` means a host we observed and did not recognize: a gateway, a proxy,\n * or a vendor we have no rule for. `unknown` means we never saw a host at all,\n * which is the case when a caller hands us an already-built LanguageModel.\n * The two are not interchangeable — one is an unrecognized answer, the other\n * is a missing one, and they need different follow-up.\n */\nexport const MODEL_HOST_CLASSES = [\n \"openai\",\n \"azure\",\n \"openrouter\",\n \"anthropic\",\n \"google\",\n \"vertex\",\n \"bedrock\",\n \"groq\",\n \"unify\",\n \"minimax\",\n \"local\",\n \"other\",\n \"unknown\",\n] as const;\n\nexport type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];\n\n/**\n * Host suffixes mapped to their vendor.\n *\n * Matched on label boundaries, never as substrings, so\n * `myresource.openai.azure.com.attacker.test` does not read as Azure.\n */\nconst HOST_SUFFIXES: ReadonlyArray<readonly [string, ModelHostClass]> = [\n // Azure exposes the same models under three host families: the classic\n // Azure OpenAI host, the Foundry Models host, and the general Cognitive\n // Services host. All three are Azure for our purposes.\n [\"openai.azure.com\", \"azure\"],\n [\"services.ai.azure.com\", \"azure\"],\n [\"cognitiveservices.azure.com\", \"azure\"],\n // API Management fronting an Azure OpenAI deployment, a common enterprise\n // pattern. Reported as azure because that is what sits behind it.\n [\"azure-api.net\", \"azure\"],\n\n [\"api.openai.com\", \"openai\"],\n [\"openrouter.ai\", \"openrouter\"],\n [\"api.anthropic.com\", \"anthropic\"],\n [\"generativelanguage.googleapis.com\", \"google\"],\n // Vertex regional hosts are `<region>-aiplatform.googleapis.com`, which is\n // not a suffix of a single label, so both spellings are listed.\n [\"aiplatform.googleapis.com\", \"vertex\"],\n [\"api.groq.com\", \"groq\"],\n [\"api.unify.ai\", \"unify\"],\n [\"api.minimax.io\", \"minimax\"],\n [\"api.minimaxi.com\", \"minimax\"],\n];\n\n/** Suffixes that mean the model runs on the same machine or private network. */\nconst LOCAL_SUFFIXES = [\"localhost\", \"local\", \"internal\", \"docker.internal\"];\n\n/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */\nconst REGIONAL_HOST_PATTERNS: ReadonlyArray<readonly [RegExp, ModelHostClass]> =\n [\n [/^[a-z0-9-]+-aiplatform\\.googleapis\\.com$/, \"vertex\"],\n [/^bedrock[a-z0-9.-]*\\.[a-z0-9-]+\\.amazonaws\\.com$/, \"bedrock\"],\n ];\n\n/** True when `host` equals `suffix` or sits directly beneath it. */\nfunction matchesSuffix(host: string, suffix: string): boolean {\n return host === suffix || host.endsWith(`.${suffix}`);\n}\n\n/** True for loopback, unspecified, and RFC 1918 private addresses. */\nfunction isPrivateAddress(host: string): boolean {\n if (host === \"127.0.0.1\" || host === \"0.0.0.0\" || host === \"::1\") {\n return true;\n }\n // 127.0.0.0/8 is entirely loopback.\n if (/^127\\./.test(host)) return true;\n // 10.0.0.0/8 and 192.168.0.0/16.\n if (/^10\\./.test(host) || /^192\\.168\\./.test(host)) return true;\n // 172.16.0.0/12 is 172.16 through 172.31 only. 172.32 is public, so the\n // second octet is range-checked rather than prefix-matched.\n const privateClassB = /^172\\.(\\d{1,3})\\./.exec(host);\n if (privateClassB) {\n const secondOctet = Number(privateClassB[1]);\n return secondOctet >= 16 && secondOctet <= 31;\n }\n return false;\n}\n\n/**\n * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.\n *\n * @param baseUrl The endpoint the provider was configured with. Absent when\n * the provider was left on its own default, which is why `providerDefault`\n * exists: \"no base URL, provider is openai\" means api.openai.com.\n * @param providerDefault What to report when no base URL was supplied. Callers\n * that genuinely cannot observe a host — a pre-built LanguageModel handed in\n * by the developer — leave this alone and get `unknown`.\n */\nexport function classifyModelHost(\n baseUrl?: string | null,\n providerDefault: ModelHostClass = \"unknown\",\n): ModelHostClass {\n const trimmed = baseUrl?.trim();\n if (!trimmed) {\n return providerDefault;\n }\n\n let host: string;\n try {\n // `hostname` drops the port, the path, the query and any credentials, so\n // nothing but the host can survive into the return value below.\n host = new URL(trimmed).hostname.toLowerCase();\n } catch {\n // We were given something and could not read it. That is a different fact\n // from having been given nothing, so it does not fall back to the default.\n return \"other\";\n }\n\n // IPv6 hostnames arrive bracketed from the URL parser.\n host = host.replace(/^\\[|\\]$/g, \"\");\n\n if (!host) return \"other\";\n\n if (isPrivateAddress(host)) return \"local\";\n for (const suffix of LOCAL_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return \"local\";\n }\n\n for (const [suffix, hostClass] of HOST_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return hostClass;\n }\n\n for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) {\n if (pattern.test(host)) return hostClass;\n }\n\n return \"other\";\n}\n"],"mappings":";;;;;;;;;;;AAuBA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAUD,MAAM,gBAAkE;CAItE,CAAC,oBAAoB,QAAQ;CAC7B,CAAC,yBAAyB,QAAQ;CAClC,CAAC,+BAA+B,QAAQ;CAGxC,CAAC,iBAAiB,QAAQ;CAE1B,CAAC,kBAAkB,SAAS;CAC5B,CAAC,iBAAiB,aAAa;CAC/B,CAAC,qBAAqB,YAAY;CAClC,CAAC,qCAAqC,SAAS;CAG/C,CAAC,6BAA6B,SAAS;CACvC,CAAC,gBAAgB,OAAO;CACxB,CAAC,gBAAgB,QAAQ;CACzB,CAAC,kBAAkB,UAAU;CAC7B,CAAC,oBAAoB,UAAU;CAChC;;AAGD,MAAM,iBAAiB;CAAC;CAAa;CAAS;CAAY;CAAkB;;AAG5E,MAAM,yBACJ,CACE,CAAC,4CAA4C,SAAS,EACtD,CAAC,oDAAoD,UAAU,CAChE;;AAGH,SAAS,cAAc,MAAc,QAAyB;AAC5D,QAAO,SAAS,UAAU,KAAK,SAAS,IAAI,SAAS;;;AAIvD,SAAS,iBAAiB,MAAuB;AAC/C,KAAI,SAAS,eAAe,SAAS,aAAa,SAAS,MACzD,QAAO;AAGT,KAAI,SAAS,KAAK,KAAK,CAAE,QAAO;AAEhC,KAAI,QAAQ,KAAK,KAAK,IAAI,cAAc,KAAK,KAAK,CAAE,QAAO;CAG3D,MAAM,gBAAgB,oBAAoB,KAAK,KAAK;AACpD,KAAI,eAAe;EACjB,MAAM,cAAc,OAAO,cAAc,GAAG;AAC5C,SAAO,eAAe,MAAM,eAAe;;AAE7C,QAAO;;;;;;;;;;;;AAaT,SAAgB,kBACd,SACA,kBAAkC,WAClB;CAChB,MAAM,UAAU,SAAS,MAAM;AAC/B,KAAI,CAAC,QACH,QAAO;CAGT,IAAI;AACJ,KAAI;AAGF,SAAO,IAAI,IAAI,QAAQ,CAAC,SAAS,aAAa;SACxC;AAGN,SAAO;;AAIT,QAAO,KAAK,QAAQ,YAAY,GAAG;AAEnC,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI,iBAAiB,KAAK,CAAE,QAAO;AACnC,MAAK,MAAM,UAAU,eACnB,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,QAAQ,cAAc,cAChC,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,SAAS,cAAc,uBACjC,KAAI,QAAQ,KAAK,KAAK,CAAE,QAAO;AAGjC,QAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/telemetry/model-host.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every value `classifyModelHost` can return.
|
|
4
|
+
*
|
|
5
|
+
* `other` means a host we observed and did not recognize: a gateway, a proxy,
|
|
6
|
+
* or a vendor we have no rule for. `unknown` means we never saw a host at all,
|
|
7
|
+
* which is the case when a caller hands us an already-built LanguageModel.
|
|
8
|
+
* The two are not interchangeable — one is an unrecognized answer, the other
|
|
9
|
+
* is a missing one, and they need different follow-up.
|
|
10
|
+
*/
|
|
11
|
+
declare const MODEL_HOST_CLASSES: readonly ["openai", "azure", "openrouter", "anthropic", "google", "vertex", "bedrock", "groq", "unify", "minimax", "local", "other", "unknown"];
|
|
12
|
+
type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
|
|
15
|
+
*
|
|
16
|
+
* @param baseUrl The endpoint the provider was configured with. Absent when
|
|
17
|
+
* the provider was left on its own default, which is why `providerDefault`
|
|
18
|
+
* exists: "no base URL, provider is openai" means api.openai.com.
|
|
19
|
+
* @param providerDefault What to report when no base URL was supplied. Callers
|
|
20
|
+
* that genuinely cannot observe a host — a pre-built LanguageModel handed in
|
|
21
|
+
* by the developer — leave this alone and get `unknown`.
|
|
22
|
+
*/
|
|
23
|
+
declare function classifyModelHost(baseUrl?: string | null, providerDefault?: ModelHostClass): ModelHostClass;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { MODEL_HOST_CLASSES, ModelHostClass, classifyModelHost };
|
|
26
|
+
//# sourceMappingURL=model-host.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-host.d.cts","names":[],"sources":["../../src/telemetry/model-host.ts"],"mappings":";;AAuBA;;;;;AAgBA;;;cAhBa,kBAAA;AAAA,KAgBD,cAAA,WAAyB,kBAAA;AA4ErC;;;;;;;;;;AAAA,iBAAgB,iBAAA,CACd,OAAA,kBACA,eAAA,GAAiB,cAAA,GAChB,cAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/telemetry/model-host.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every value `classifyModelHost` can return.
|
|
4
|
+
*
|
|
5
|
+
* `other` means a host we observed and did not recognize: a gateway, a proxy,
|
|
6
|
+
* or a vendor we have no rule for. `unknown` means we never saw a host at all,
|
|
7
|
+
* which is the case when a caller hands us an already-built LanguageModel.
|
|
8
|
+
* The two are not interchangeable — one is an unrecognized answer, the other
|
|
9
|
+
* is a missing one, and they need different follow-up.
|
|
10
|
+
*/
|
|
11
|
+
declare const MODEL_HOST_CLASSES: readonly ["openai", "azure", "openrouter", "anthropic", "google", "vertex", "bedrock", "groq", "unify", "minimax", "local", "other", "unknown"];
|
|
12
|
+
type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
|
|
15
|
+
*
|
|
16
|
+
* @param baseUrl The endpoint the provider was configured with. Absent when
|
|
17
|
+
* the provider was left on its own default, which is why `providerDefault`
|
|
18
|
+
* exists: "no base URL, provider is openai" means api.openai.com.
|
|
19
|
+
* @param providerDefault What to report when no base URL was supplied. Callers
|
|
20
|
+
* that genuinely cannot observe a host — a pre-built LanguageModel handed in
|
|
21
|
+
* by the developer — leave this alone and get `unknown`.
|
|
22
|
+
*/
|
|
23
|
+
declare function classifyModelHost(baseUrl?: string | null, providerDefault?: ModelHostClass): ModelHostClass;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { MODEL_HOST_CLASSES, ModelHostClass, classifyModelHost };
|
|
26
|
+
//# sourceMappingURL=model-host.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-host.d.mts","names":[],"sources":["../../src/telemetry/model-host.ts"],"mappings":";;AAuBA;;;;;AAgBA;;;cAhBa,kBAAA;AAAA,KAgBD,cAAA,WAAyB,kBAAA;AA4ErC;;;;;;;;;;AAAA,iBAAgB,iBAAA,CACd,OAAA,kBACA,eAAA,GAAiB,cAAA,GAChB,cAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/telemetry/model-host.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every value `classifyModelHost` can return.
|
|
4
|
+
*
|
|
5
|
+
* `other` means a host we observed and did not recognize: a gateway, a proxy,
|
|
6
|
+
* or a vendor we have no rule for. `unknown` means we never saw a host at all,
|
|
7
|
+
* which is the case when a caller hands us an already-built LanguageModel.
|
|
8
|
+
* The two are not interchangeable — one is an unrecognized answer, the other
|
|
9
|
+
* is a missing one, and they need different follow-up.
|
|
10
|
+
*/
|
|
11
|
+
const MODEL_HOST_CLASSES = [
|
|
12
|
+
"openai",
|
|
13
|
+
"azure",
|
|
14
|
+
"openrouter",
|
|
15
|
+
"anthropic",
|
|
16
|
+
"google",
|
|
17
|
+
"vertex",
|
|
18
|
+
"bedrock",
|
|
19
|
+
"groq",
|
|
20
|
+
"unify",
|
|
21
|
+
"minimax",
|
|
22
|
+
"local",
|
|
23
|
+
"other",
|
|
24
|
+
"unknown"
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Host suffixes mapped to their vendor.
|
|
28
|
+
*
|
|
29
|
+
* Matched on label boundaries, never as substrings, so
|
|
30
|
+
* `myresource.openai.azure.com.attacker.test` does not read as Azure.
|
|
31
|
+
*/
|
|
32
|
+
const HOST_SUFFIXES = [
|
|
33
|
+
["openai.azure.com", "azure"],
|
|
34
|
+
["services.ai.azure.com", "azure"],
|
|
35
|
+
["cognitiveservices.azure.com", "azure"],
|
|
36
|
+
["azure-api.net", "azure"],
|
|
37
|
+
["api.openai.com", "openai"],
|
|
38
|
+
["openrouter.ai", "openrouter"],
|
|
39
|
+
["api.anthropic.com", "anthropic"],
|
|
40
|
+
["generativelanguage.googleapis.com", "google"],
|
|
41
|
+
["aiplatform.googleapis.com", "vertex"],
|
|
42
|
+
["api.groq.com", "groq"],
|
|
43
|
+
["api.unify.ai", "unify"],
|
|
44
|
+
["api.minimax.io", "minimax"],
|
|
45
|
+
["api.minimaxi.com", "minimax"]
|
|
46
|
+
];
|
|
47
|
+
/** Suffixes that mean the model runs on the same machine or private network. */
|
|
48
|
+
const LOCAL_SUFFIXES = [
|
|
49
|
+
"localhost",
|
|
50
|
+
"local",
|
|
51
|
+
"internal",
|
|
52
|
+
"docker.internal"
|
|
53
|
+
];
|
|
54
|
+
/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */
|
|
55
|
+
const REGIONAL_HOST_PATTERNS = [[/^[a-z0-9-]+-aiplatform\.googleapis\.com$/, "vertex"], [/^bedrock[a-z0-9.-]*\.[a-z0-9-]+\.amazonaws\.com$/, "bedrock"]];
|
|
56
|
+
/** True when `host` equals `suffix` or sits directly beneath it. */
|
|
57
|
+
function matchesSuffix(host, suffix) {
|
|
58
|
+
return host === suffix || host.endsWith(`.${suffix}`);
|
|
59
|
+
}
|
|
60
|
+
/** True for loopback, unspecified, and RFC 1918 private addresses. */
|
|
61
|
+
function isPrivateAddress(host) {
|
|
62
|
+
if (host === "127.0.0.1" || host === "0.0.0.0" || host === "::1") return true;
|
|
63
|
+
if (/^127\./.test(host)) return true;
|
|
64
|
+
if (/^10\./.test(host) || /^192\.168\./.test(host)) return true;
|
|
65
|
+
const privateClassB = /^172\.(\d{1,3})\./.exec(host);
|
|
66
|
+
if (privateClassB) {
|
|
67
|
+
const secondOctet = Number(privateClassB[1]);
|
|
68
|
+
return secondOctet >= 16 && secondOctet <= 31;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.
|
|
74
|
+
*
|
|
75
|
+
* @param baseUrl The endpoint the provider was configured with. Absent when
|
|
76
|
+
* the provider was left on its own default, which is why `providerDefault`
|
|
77
|
+
* exists: "no base URL, provider is openai" means api.openai.com.
|
|
78
|
+
* @param providerDefault What to report when no base URL was supplied. Callers
|
|
79
|
+
* that genuinely cannot observe a host — a pre-built LanguageModel handed in
|
|
80
|
+
* by the developer — leave this alone and get `unknown`.
|
|
81
|
+
*/
|
|
82
|
+
function classifyModelHost(baseUrl, providerDefault = "unknown") {
|
|
83
|
+
const trimmed = baseUrl?.trim();
|
|
84
|
+
if (!trimmed) return providerDefault;
|
|
85
|
+
let host;
|
|
86
|
+
try {
|
|
87
|
+
host = new URL(trimmed).hostname.toLowerCase();
|
|
88
|
+
} catch {
|
|
89
|
+
return "other";
|
|
90
|
+
}
|
|
91
|
+
host = host.replace(/^\[|\]$/g, "");
|
|
92
|
+
if (!host) return "other";
|
|
93
|
+
if (isPrivateAddress(host)) return "local";
|
|
94
|
+
for (const suffix of LOCAL_SUFFIXES) if (matchesSuffix(host, suffix)) return "local";
|
|
95
|
+
for (const [suffix, hostClass] of HOST_SUFFIXES) if (matchesSuffix(host, suffix)) return hostClass;
|
|
96
|
+
for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) if (pattern.test(host)) return hostClass;
|
|
97
|
+
return "other";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { MODEL_HOST_CLASSES, classifyModelHost };
|
|
102
|
+
//# sourceMappingURL=model-host.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-host.mjs","names":[],"sources":["../../src/telemetry/model-host.ts"],"sourcesContent":["// Which endpoint the runtime sends completions to, as a closed vocabulary.\n//\n// The AI SDK's provider label cannot answer this. `createOpenAI` stamps\n// `openai.responses` on every model it builds, whether the base URL points at\n// api.openai.com, Azure, OpenRouter or a laptop running Ollama — and Azure's\n// own migration guide tells customers to use exactly that client. So the\n// provider field reports the wire protocol, and the host reports the vendor.\n//\n// Only the classification travels. A base URL like\n// `myresource.openai.azure.com` carries the customer's Azure resource name,\n// which identifies them, so the raw host must never reach telemetry. That is\n// why this returns a member of a fixed list rather than anything derived from\n// the input.\n\n/**\n * Every value `classifyModelHost` can return.\n *\n * `other` means a host we observed and did not recognize: a gateway, a proxy,\n * or a vendor we have no rule for. `unknown` means we never saw a host at all,\n * which is the case when a caller hands us an already-built LanguageModel.\n * The two are not interchangeable — one is an unrecognized answer, the other\n * is a missing one, and they need different follow-up.\n */\nexport const MODEL_HOST_CLASSES = [\n \"openai\",\n \"azure\",\n \"openrouter\",\n \"anthropic\",\n \"google\",\n \"vertex\",\n \"bedrock\",\n \"groq\",\n \"unify\",\n \"minimax\",\n \"local\",\n \"other\",\n \"unknown\",\n] as const;\n\nexport type ModelHostClass = (typeof MODEL_HOST_CLASSES)[number];\n\n/**\n * Host suffixes mapped to their vendor.\n *\n * Matched on label boundaries, never as substrings, so\n * `myresource.openai.azure.com.attacker.test` does not read as Azure.\n */\nconst HOST_SUFFIXES: ReadonlyArray<readonly [string, ModelHostClass]> = [\n // Azure exposes the same models under three host families: the classic\n // Azure OpenAI host, the Foundry Models host, and the general Cognitive\n // Services host. All three are Azure for our purposes.\n [\"openai.azure.com\", \"azure\"],\n [\"services.ai.azure.com\", \"azure\"],\n [\"cognitiveservices.azure.com\", \"azure\"],\n // API Management fronting an Azure OpenAI deployment, a common enterprise\n // pattern. Reported as azure because that is what sits behind it.\n [\"azure-api.net\", \"azure\"],\n\n [\"api.openai.com\", \"openai\"],\n [\"openrouter.ai\", \"openrouter\"],\n [\"api.anthropic.com\", \"anthropic\"],\n [\"generativelanguage.googleapis.com\", \"google\"],\n // Vertex regional hosts are `<region>-aiplatform.googleapis.com`, which is\n // not a suffix of a single label, so both spellings are listed.\n [\"aiplatform.googleapis.com\", \"vertex\"],\n [\"api.groq.com\", \"groq\"],\n [\"api.unify.ai\", \"unify\"],\n [\"api.minimax.io\", \"minimax\"],\n [\"api.minimaxi.com\", \"minimax\"],\n];\n\n/** Suffixes that mean the model runs on the same machine or private network. */\nconst LOCAL_SUFFIXES = [\"localhost\", \"local\", \"internal\", \"docker.internal\"];\n\n/** Matches `<region>-aiplatform.googleapis.com` and the Bedrock regional hosts. */\nconst REGIONAL_HOST_PATTERNS: ReadonlyArray<readonly [RegExp, ModelHostClass]> =\n [\n [/^[a-z0-9-]+-aiplatform\\.googleapis\\.com$/, \"vertex\"],\n [/^bedrock[a-z0-9.-]*\\.[a-z0-9-]+\\.amazonaws\\.com$/, \"bedrock\"],\n ];\n\n/** True when `host` equals `suffix` or sits directly beneath it. */\nfunction matchesSuffix(host: string, suffix: string): boolean {\n return host === suffix || host.endsWith(`.${suffix}`);\n}\n\n/** True for loopback, unspecified, and RFC 1918 private addresses. */\nfunction isPrivateAddress(host: string): boolean {\n if (host === \"127.0.0.1\" || host === \"0.0.0.0\" || host === \"::1\") {\n return true;\n }\n // 127.0.0.0/8 is entirely loopback.\n if (/^127\\./.test(host)) return true;\n // 10.0.0.0/8 and 192.168.0.0/16.\n if (/^10\\./.test(host) || /^192\\.168\\./.test(host)) return true;\n // 172.16.0.0/12 is 172.16 through 172.31 only. 172.32 is public, so the\n // second octet is range-checked rather than prefix-matched.\n const privateClassB = /^172\\.(\\d{1,3})\\./.exec(host);\n if (privateClassB) {\n const secondOctet = Number(privateClassB[1]);\n return secondOctet >= 16 && secondOctet <= 31;\n }\n return false;\n}\n\n/**\n * Reduce a model endpoint to one of {@link MODEL_HOST_CLASSES}.\n *\n * @param baseUrl The endpoint the provider was configured with. Absent when\n * the provider was left on its own default, which is why `providerDefault`\n * exists: \"no base URL, provider is openai\" means api.openai.com.\n * @param providerDefault What to report when no base URL was supplied. Callers\n * that genuinely cannot observe a host — a pre-built LanguageModel handed in\n * by the developer — leave this alone and get `unknown`.\n */\nexport function classifyModelHost(\n baseUrl?: string | null,\n providerDefault: ModelHostClass = \"unknown\",\n): ModelHostClass {\n const trimmed = baseUrl?.trim();\n if (!trimmed) {\n return providerDefault;\n }\n\n let host: string;\n try {\n // `hostname` drops the port, the path, the query and any credentials, so\n // nothing but the host can survive into the return value below.\n host = new URL(trimmed).hostname.toLowerCase();\n } catch {\n // We were given something and could not read it. That is a different fact\n // from having been given nothing, so it does not fall back to the default.\n return \"other\";\n }\n\n // IPv6 hostnames arrive bracketed from the URL parser.\n host = host.replace(/^\\[|\\]$/g, \"\");\n\n if (!host) return \"other\";\n\n if (isPrivateAddress(host)) return \"local\";\n for (const suffix of LOCAL_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return \"local\";\n }\n\n for (const [suffix, hostClass] of HOST_SUFFIXES) {\n if (matchesSuffix(host, suffix)) return hostClass;\n }\n\n for (const [pattern, hostClass] of REGIONAL_HOST_PATTERNS) {\n if (pattern.test(host)) return hostClass;\n }\n\n return \"other\";\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAUD,MAAM,gBAAkE;CAItE,CAAC,oBAAoB,QAAQ;CAC7B,CAAC,yBAAyB,QAAQ;CAClC,CAAC,+BAA+B,QAAQ;CAGxC,CAAC,iBAAiB,QAAQ;CAE1B,CAAC,kBAAkB,SAAS;CAC5B,CAAC,iBAAiB,aAAa;CAC/B,CAAC,qBAAqB,YAAY;CAClC,CAAC,qCAAqC,SAAS;CAG/C,CAAC,6BAA6B,SAAS;CACvC,CAAC,gBAAgB,OAAO;CACxB,CAAC,gBAAgB,QAAQ;CACzB,CAAC,kBAAkB,UAAU;CAC7B,CAAC,oBAAoB,UAAU;CAChC;;AAGD,MAAM,iBAAiB;CAAC;CAAa;CAAS;CAAY;CAAkB;;AAG5E,MAAM,yBACJ,CACE,CAAC,4CAA4C,SAAS,EACtD,CAAC,oDAAoD,UAAU,CAChE;;AAGH,SAAS,cAAc,MAAc,QAAyB;AAC5D,QAAO,SAAS,UAAU,KAAK,SAAS,IAAI,SAAS;;;AAIvD,SAAS,iBAAiB,MAAuB;AAC/C,KAAI,SAAS,eAAe,SAAS,aAAa,SAAS,MACzD,QAAO;AAGT,KAAI,SAAS,KAAK,KAAK,CAAE,QAAO;AAEhC,KAAI,QAAQ,KAAK,KAAK,IAAI,cAAc,KAAK,KAAK,CAAE,QAAO;CAG3D,MAAM,gBAAgB,oBAAoB,KAAK,KAAK;AACpD,KAAI,eAAe;EACjB,MAAM,cAAc,OAAO,cAAc,GAAG;AAC5C,SAAO,eAAe,MAAM,eAAe;;AAE7C,QAAO;;;;;;;;;;;;AAaT,SAAgB,kBACd,SACA,kBAAkC,WAClB;CAChB,MAAM,UAAU,SAAS,MAAM;AAC/B,KAAI,CAAC,QACH,QAAO;CAGT,IAAI;AACJ,KAAI;AAGF,SAAO,IAAI,IAAI,QAAQ,CAAC,SAAS,aAAa;SACxC;AAGN,SAAO;;AAIT,QAAO,KAAK,QAAQ,YAAY,GAAG;AAEnC,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI,iBAAiB,KAAK,CAAE,QAAO;AACnC,MAAK,MAAM,UAAU,eACnB,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,QAAQ,cAAc,cAChC,KAAI,cAAc,MAAM,OAAO,CAAE,QAAO;AAG1C,MAAK,MAAM,CAAC,SAAS,cAAc,uBACjC,KAAI,QAAQ,KAAK,KAAK,CAAE,QAAO;AAGjC,QAAO"}
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/telemetry/sampling.ts
|
|
3
|
+
/** The rate a sink that takes every event is "gated" at. */
|
|
4
|
+
const UNSAMPLED_RATE = 1;
|
|
3
5
|
/** Identifies which client emitted an event. */
|
|
4
6
|
const TELEMETRY_EMITTER_V1 = "v1-shared";
|
|
5
7
|
const TELEMETRY_EMITTER_V2 = "v2-runtime";
|
|
6
8
|
/**
|
|
9
|
+
* Which public API surface the developer built against.
|
|
10
|
+
*
|
|
11
|
+
* Separate from {@link TelemetryEmitter} on purpose. The emitter names a
|
|
12
|
+
* client library, and there are six of them across four languages; the
|
|
13
|
+
* surface answers the question anyone actually asks of this data, which
|
|
14
|
+
* is how much traffic still arrives through the deprecated v1 API. The
|
|
15
|
+
* native runtimes (Go, Python, Ruby, .NET) expose v2 only, so they report
|
|
16
|
+
* `v2` without having a v1 notion of their own.
|
|
17
|
+
*/
|
|
18
|
+
const TELEMETRY_SURFACE_V1 = "v1";
|
|
19
|
+
const TELEMETRY_SURFACE_V2 = "v2";
|
|
20
|
+
/**
|
|
7
21
|
* Compute the sampling block for one captured event.
|
|
8
22
|
*
|
|
9
23
|
* `telemetryId` is the caller's parsed license telemetry_id, or null when
|
|
10
24
|
* anonymous — it decides the branch, and is deliberately not returned:
|
|
11
25
|
* only the non-PII shape below travels on the event.
|
|
26
|
+
*
|
|
27
|
+
* `sampleRate` is the rate of the wire this copy travels on, so an
|
|
28
|
+
* unsampled sink passes {@link UNSAMPLED_RATE}. Call it once per wire:
|
|
29
|
+
* the v1 client sends one capture to two wires gated differently, and a
|
|
30
|
+
* shared block would misweight one of them.
|
|
12
31
|
*/
|
|
13
32
|
function computeSamplingMeta({ telemetryId, sampleRate }) {
|
|
14
33
|
const identified = Boolean(telemetryId);
|
|
@@ -24,5 +43,8 @@ function computeSamplingMeta({ telemetryId, sampleRate }) {
|
|
|
24
43
|
//#endregion
|
|
25
44
|
exports.TELEMETRY_EMITTER_V1 = TELEMETRY_EMITTER_V1;
|
|
26
45
|
exports.TELEMETRY_EMITTER_V2 = TELEMETRY_EMITTER_V2;
|
|
46
|
+
exports.TELEMETRY_SURFACE_V1 = TELEMETRY_SURFACE_V1;
|
|
47
|
+
exports.TELEMETRY_SURFACE_V2 = TELEMETRY_SURFACE_V2;
|
|
48
|
+
exports.UNSAMPLED_RATE = UNSAMPLED_RATE;
|
|
27
49
|
exports.computeSamplingMeta = computeSamplingMeta;
|
|
28
50
|
//# sourceMappingURL=sampling.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampling.cjs","names":[],"sources":["../../src/telemetry/sampling.ts"],"sourcesContent":["// Per-event telemetry metadata shared by both TelemetryClients.\n//\n// Two clients emit `oss.runtime.*`: the v1 client in this package and the\n// v2 client in @copilotkit/runtime.
|
|
1
|
+
{"version":3,"file":"sampling.cjs","names":[],"sources":["../../src/telemetry/sampling.ts"],"sourcesContent":["// Per-event telemetry metadata shared by both TelemetryClients.\n//\n// Two clients emit `oss.runtime.*`: the v1 client in this package and the\n// v2 client in @copilotkit/runtime. Neither samples the lambda sink any\n// more — that sink is ours, so anonymous volume costs us nothing per\n// event and full fidelity beats an extrapolation. One wire is still\n// gated: the Segment copy the v1 client sends, which is billed per event.\n//\n// Every event therefore still carries a sampling block, because the two\n// populations remain distinguishable and a Segment-sourced count still\n// needs sum(sampleWeight) to mean anything. On the lambda wire the block\n// reads sampleRate=1/sampleWeight=1, which is the honest answer rather\n// than a placeholder.\n//\n// The two clients computed this independently and drifted: v2 sampled but\n// stamped nothing, leaving ~24% of runtime volume unweightable from the\n// data alone (OSS-1017). Computing it here is what stops them drifting\n// again.\n\n/** The rate a sink that takes every event is \"gated\" at. */\nexport const UNSAMPLED_RATE = 1;\n\n/** Identifies which client emitted an event. */\nexport const TELEMETRY_EMITTER_V1 = \"v1-shared\";\nexport const TELEMETRY_EMITTER_V2 = \"v2-runtime\";\n\nexport type TelemetryEmitter =\n | typeof TELEMETRY_EMITTER_V1\n | typeof TELEMETRY_EMITTER_V2;\n\n/**\n * Which public API surface the developer built against.\n *\n * Separate from {@link TelemetryEmitter} on purpose. The emitter names a\n * client library, and there are six of them across four languages; the\n * surface answers the question anyone actually asks of this data, which\n * is how much traffic still arrives through the deprecated v1 API. The\n * native runtimes (Go, Python, Ruby, .NET) expose v2 only, so they report\n * `v2` without having a v1 notion of their own.\n */\n// `as const` so the values keep their literal types when they land in a\n// mutable object property, which is how the v1 shim passes the surface\n// into the V2 runtime's options.\nexport const TELEMETRY_SURFACE_V1 = \"v1\" as const;\nexport const TELEMETRY_SURFACE_V2 = \"v2\" as const;\n\nexport type TelemetrySurface =\n | typeof TELEMETRY_SURFACE_V1\n | typeof TELEMETRY_SURFACE_V2;\n\n/**\n * Which wire an event copy travelled on. The v1 client sends each capture\n * to both, so this is what tells the two copies apart downstream\n * (OSS-1019); the v2 client only ever sends to the lambda sink.\n */\nexport type TelemetryTransport = \"segment\" | \"lambda\";\n\nexport interface SamplingMeta {\n /** The rate this event was actually gated at: 1 when unsampled or identified. */\n sampleRate: number;\n sampleRateAdjustmentFactor: number;\n /** Multiply by this to extrapolate the population the event stands for. */\n sampleWeight: number;\n /** Whether the event bypassed the sample gate. */\n telemetry_identified: boolean;\n}\n\n/**\n * Compute the sampling block for one captured event.\n *\n * `telemetryId` is the caller's parsed license telemetry_id, or null when\n * anonymous — it decides the branch, and is deliberately not returned:\n * only the non-PII shape below travels on the event.\n *\n * `sampleRate` is the rate of the wire this copy travels on, so an\n * unsampled sink passes {@link UNSAMPLED_RATE}. Call it once per wire:\n * the v1 client sends one capture to two wires gated differently, and a\n * shared block would misweight one of them.\n */\nexport function computeSamplingMeta({\n telemetryId,\n sampleRate,\n}: {\n telemetryId: string | null;\n sampleRate: number;\n}): SamplingMeta {\n const identified = Boolean(telemetryId);\n // Identified events ship at a 100% effective rate, anonymous ones at\n // sampleRate. Computed per event because a single global weight would\n // overweight identified-customer counts by 1/sampleRate.\n const effectiveSampleRate = identified ? 1 : sampleRate;\n\n return {\n sampleRate: effectiveSampleRate,\n sampleRateAdjustmentFactor: 1 - effectiveSampleRate,\n sampleWeight: 1 / effectiveSampleRate,\n // Stated outright rather than inferred from sampleWeight === 1:\n // under COPILOTKIT_TELEMETRY_SAMPLE_RATE=1 anonymous events also\n // weigh 1, and the two populations stop being distinguishable\n // (OSS-1018).\n telemetry_identified: identified,\n };\n}\n"],"mappings":";;;AAoBA,MAAa,iBAAiB;;AAG9B,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;;;;;;;;;;;AAmBpC,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;;;;;;;;;;;;;AAmCpC,SAAgB,oBAAoB,EAClC,aACA,cAIe;CACf,MAAM,aAAa,QAAQ,YAAY;CAIvC,MAAM,sBAAsB,aAAa,IAAI;AAE7C,QAAO;EACL,YAAY;EACZ,4BAA4B,IAAI;EAChC,cAAc,IAAI;EAKlB,sBAAsB;EACvB"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
//#region src/telemetry/sampling.d.ts
|
|
2
|
+
/** The rate a sink that takes every event is "gated" at. */
|
|
3
|
+
declare const UNSAMPLED_RATE = 1;
|
|
2
4
|
/** Identifies which client emitted an event. */
|
|
3
5
|
declare const TELEMETRY_EMITTER_V1 = "v1-shared";
|
|
4
6
|
declare const TELEMETRY_EMITTER_V2 = "v2-runtime";
|
|
5
7
|
type TelemetryEmitter = typeof TELEMETRY_EMITTER_V1 | typeof TELEMETRY_EMITTER_V2;
|
|
8
|
+
/**
|
|
9
|
+
* Which public API surface the developer built against.
|
|
10
|
+
*
|
|
11
|
+
* Separate from {@link TelemetryEmitter} on purpose. The emitter names a
|
|
12
|
+
* client library, and there are six of them across four languages; the
|
|
13
|
+
* surface answers the question anyone actually asks of this data, which
|
|
14
|
+
* is how much traffic still arrives through the deprecated v1 API. The
|
|
15
|
+
* native runtimes (Go, Python, Ruby, .NET) expose v2 only, so they report
|
|
16
|
+
* `v2` without having a v1 notion of their own.
|
|
17
|
+
*/
|
|
18
|
+
declare const TELEMETRY_SURFACE_V1: "v1";
|
|
19
|
+
declare const TELEMETRY_SURFACE_V2: "v2";
|
|
20
|
+
type TelemetrySurface = typeof TELEMETRY_SURFACE_V1 | typeof TELEMETRY_SURFACE_V2;
|
|
6
21
|
/**
|
|
7
22
|
* Which wire an event copy travelled on. The v1 client sends each capture
|
|
8
23
|
* to both, so this is what tells the two copies apart downstream
|
|
@@ -10,7 +25,7 @@ type TelemetryEmitter = typeof TELEMETRY_EMITTER_V1 | typeof TELEMETRY_EMITTER_V
|
|
|
10
25
|
*/
|
|
11
26
|
type TelemetryTransport = "segment" | "lambda";
|
|
12
27
|
interface SamplingMeta {
|
|
13
|
-
/** The rate this event was actually gated at: 1 when identified. */
|
|
28
|
+
/** The rate this event was actually gated at: 1 when unsampled or identified. */
|
|
14
29
|
sampleRate: number;
|
|
15
30
|
sampleRateAdjustmentFactor: number;
|
|
16
31
|
/** Multiply by this to extrapolate the population the event stands for. */
|
|
@@ -24,6 +39,11 @@ interface SamplingMeta {
|
|
|
24
39
|
* `telemetryId` is the caller's parsed license telemetry_id, or null when
|
|
25
40
|
* anonymous — it decides the branch, and is deliberately not returned:
|
|
26
41
|
* only the non-PII shape below travels on the event.
|
|
42
|
+
*
|
|
43
|
+
* `sampleRate` is the rate of the wire this copy travels on, so an
|
|
44
|
+
* unsampled sink passes {@link UNSAMPLED_RATE}. Call it once per wire:
|
|
45
|
+
* the v1 client sends one capture to two wires gated differently, and a
|
|
46
|
+
* shared block would misweight one of them.
|
|
27
47
|
*/
|
|
28
48
|
declare function computeSamplingMeta({
|
|
29
49
|
telemetryId,
|
|
@@ -33,5 +53,5 @@ declare function computeSamplingMeta({
|
|
|
33
53
|
sampleRate: number;
|
|
34
54
|
}): SamplingMeta;
|
|
35
55
|
//#endregion
|
|
36
|
-
export { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TelemetryEmitter, TelemetryTransport, computeSamplingMeta };
|
|
56
|
+
export { SamplingMeta, TELEMETRY_EMITTER_V1, TELEMETRY_EMITTER_V2, TELEMETRY_SURFACE_V1, TELEMETRY_SURFACE_V2, TelemetryEmitter, TelemetrySurface, TelemetryTransport, UNSAMPLED_RATE, computeSamplingMeta };
|
|
37
57
|
//# sourceMappingURL=sampling.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampling.d.cts","names":[],"sources":["../../src/telemetry/sampling.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sampling.d.cts","names":[],"sources":["../../src/telemetry/sampling.ts"],"mappings":";;cAoBa,cAAA;;cAGA,oBAAA;AAAA,cACA,oBAAA;AAAA,KAED,gBAAA,UACD,oBAAA,UACA,oBAAA;AALX;;;;;AACA;;;;;AADA,cAoBa,oBAAA;AAAA,cACA,oBAAA;AAAA,KAED,gBAAA,UACD,oBAAA,UACA,oBAAA;;;AALX;;;KAYY,kBAAA;AAAA,UAEK,YAAA;EAbJ;EAeX,UAAA;EACA,0BAAA;EAhB+C;EAkB/C,YAAA;EAhBU;EAkBV,oBAAA;AAAA;;;AATF;;;;;AAEA;;;;;iBAsBgB,mBAAA,CAAA;EACd,WAAA;EACA;AAAA;EAEA,WAAA;EACA,UAAA;AAAA,IACE,YAAA"}
|