@stigg/agent-sdk-js 0.0.0-stage → 1.0.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.
Files changed (82) hide show
  1. package/README.md +1147 -2
  2. package/dist/bindings/client/core/registry.d.ts +12 -0
  3. package/dist/bindings/client/core/registry.js +22 -0
  4. package/dist/bindings/client/core/types.d.ts +117 -0
  5. package/dist/bindings/client/core/types.js +13 -0
  6. package/dist/bindings/client/core/wrap-client.d.ts +6 -0
  7. package/dist/bindings/client/core/wrap-client.js +258 -0
  8. package/dist/bindings/client/gateways/litellm/litellm-recipe.d.ts +17 -0
  9. package/dist/bindings/client/gateways/litellm/litellm-recipe.js +171 -0
  10. package/dist/bindings/client/gateways/litellm/types.d.ts +30 -0
  11. package/dist/bindings/client/gateways/litellm/types.js +2 -0
  12. package/dist/bindings/client/gateways/openrouter/openrouter-recipe.d.ts +15 -0
  13. package/dist/bindings/client/gateways/openrouter/openrouter-recipe.js +141 -0
  14. package/dist/bindings/client/gateways/openrouter/types.d.ts +29 -0
  15. package/dist/bindings/client/gateways/openrouter/types.js +2 -0
  16. package/dist/bindings/client/providers/anthropic/anthropic-recipe.d.ts +34 -0
  17. package/dist/bindings/client/providers/anthropic/anthropic-recipe.js +91 -0
  18. package/dist/bindings/client/providers/gemini/gemini-recipe.d.ts +54 -0
  19. package/dist/bindings/client/providers/gemini/gemini-recipe.js +243 -0
  20. package/dist/bindings/client/providers/openai/openai-recipe.d.ts +43 -0
  21. package/dist/bindings/client/providers/openai/openai-recipe.js +80 -0
  22. package/dist/bindings/client/providers/typesafe/typesafe-recipe.d.ts +33 -0
  23. package/dist/bindings/client/providers/typesafe/typesafe-recipe.js +73 -0
  24. package/dist/bindings/proxy/headers.d.ts +6 -0
  25. package/dist/bindings/proxy/headers.js +12 -0
  26. package/dist/bindings/proxy/index.d.ts +21 -0
  27. package/dist/bindings/proxy/index.js +18 -0
  28. package/dist/bindings/proxy/types.d.ts +8 -0
  29. package/dist/bindings/proxy/types.js +2 -0
  30. package/dist/bindings/shared/estimate.d.ts +27 -0
  31. package/dist/bindings/shared/estimate.js +38 -0
  32. package/dist/bindings/shared/meter-stream.d.ts +18 -0
  33. package/dist/bindings/shared/meter-stream.js +151 -0
  34. package/dist/bindings/shared/token-usage.d.ts +148 -0
  35. package/dist/bindings/shared/token-usage.js +414 -0
  36. package/dist/bindings/shared/types.d.ts +79 -0
  37. package/dist/bindings/shared/types.js +2 -0
  38. package/dist/bindings/shared/weighted-metrics.d.ts +37 -0
  39. package/dist/bindings/shared/weighted-metrics.js +44 -0
  40. package/dist/config.d.ts +136 -0
  41. package/dist/config.js +97 -0
  42. package/dist/core/context.d.ts +151 -0
  43. package/dist/core/context.js +154 -0
  44. package/dist/core/dimensions.d.ts +22 -0
  45. package/dist/core/dimensions.js +47 -0
  46. package/dist/core/hooks.d.ts +21 -0
  47. package/dist/core/hooks.js +47 -0
  48. package/dist/core/session.d.ts +161 -0
  49. package/dist/core/session.js +403 -0
  50. package/dist/decision-text.d.ts +15 -0
  51. package/dist/decision-text.js +54 -0
  52. package/dist/engine/composite-engine.d.ts +72 -0
  53. package/dist/engine/composite-engine.js +135 -0
  54. package/dist/engine/create-engine.d.ts +16 -0
  55. package/dist/engine/create-engine.js +93 -0
  56. package/dist/engine/decision.d.ts +37 -0
  57. package/dist/engine/decision.js +128 -0
  58. package/dist/engine/engine.d.ts +166 -0
  59. package/dist/engine/engine.js +11 -0
  60. package/dist/engine/node-sdk-engine.d.ts +125 -0
  61. package/dist/engine/node-sdk-engine.js +262 -0
  62. package/dist/engine/report.d.ts +106 -0
  63. package/dist/engine/report.js +185 -0
  64. package/dist/engine/rest-governance-engine.d.ts +47 -0
  65. package/dist/engine/rest-governance-engine.js +220 -0
  66. package/dist/errors.d.ts +78 -0
  67. package/dist/errors.js +151 -0
  68. package/dist/headers.d.ts +27 -0
  69. package/dist/headers.js +63 -0
  70. package/dist/index.d.ts +48 -0
  71. package/dist/index.js +85 -0
  72. package/dist/internal.d.ts +33 -0
  73. package/dist/internal.js +81 -0
  74. package/dist/logger.d.ts +15 -0
  75. package/dist/logger.js +20 -0
  76. package/dist/sdk-identity.d.ts +36 -0
  77. package/dist/sdk-identity.js +43 -0
  78. package/dist/stigg-agent-sdk.d.ts +242 -0
  79. package/dist/stigg-agent-sdk.js +594 -0
  80. package/dist/types.d.ts +531 -0
  81. package/dist/types.js +97 -0
  82. package/package.json +80 -3
package/dist/errors.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGovernanceNotEnabled = exports.isEngineError = exports.GovernanceNotEnabledError = exports.EngineError = exports.AccessDeniedError = void 0;
4
+ exports.isAccessDenied = isAccessDenied;
5
+ exports.isMeterMismatchError = isMeterMismatchError;
6
+ exports.asEngineError = asEngineError;
7
+ exports.isTransportFailure = isTransportFailure;
8
+ exports.asGovernanceError = asGovernanceError;
9
+ exports.looksLikeGovernanceNotEnabled = looksLikeGovernanceNotEnabled;
10
+ const MARKER = Symbol.for('stigg.agent-sdk.error');
11
+ const mark = (err, kind) => {
12
+ Object.defineProperty(err, MARKER, { value: kind, enumerable: false });
13
+ return err;
14
+ };
15
+ const isKind = (err, kind) => typeof err === 'object' && err !== null && err[MARKER] === kind;
16
+ /**
17
+ * Thrown only where there is no return path for a decision - inside a wrapped client method,
18
+ * which must hand back the vendor's own response type or nothing at all. Everywhere else a
19
+ * denial is a returned `GovernanceDecision`.
20
+ */
21
+ class AccessDeniedError extends Error {
22
+ decision;
23
+ constructor(decision) {
24
+ const by = decision.deniedBy ? ` by ${decision.deniedBy}` : '';
25
+ super(`Denied${by}: ${decision.reason ?? 'no budget remaining'}`);
26
+ this.name = 'AccessDeniedError';
27
+ this.decision = decision;
28
+ mark(this, 'denied');
29
+ }
30
+ }
31
+ exports.AccessDeniedError = AccessDeniedError;
32
+ /** Anything the engine could not complete: transport, timeout, 4xx/5xx, bad input. */
33
+ class EngineError extends Error {
34
+ status;
35
+ operation;
36
+ /**
37
+ * What the server had already accepted when this failed.
38
+ *
39
+ * An ingest is up to two calls - the features, then the wallet - so a rejection on the second
40
+ * leaves the first one's spend sitting at Stigg. Reporting that turn as nothing landed would
41
+ * understate a bill the customer is going to see, which is the one direction a meter must not
42
+ * be wrong in.
43
+ */
44
+ reported;
45
+ /**
46
+ * Whether what landed was a replay. Carried with `reported`, because counting those metrics
47
+ * again is the one thing a caller must not do with keys Stigg had already seen - and
48
+ * `undefined` means here what it means everywhere: the event API could not say.
49
+ */
50
+ replayed;
51
+ constructor(operation, message, options) {
52
+ super(`${operation}: ${message}`, options?.cause === undefined ? undefined : { cause: options.cause });
53
+ this.name = 'EngineError';
54
+ this.operation = operation;
55
+ this.status = options?.status;
56
+ this.reported = options?.reported;
57
+ this.replayed = options?.replayed;
58
+ mark(this, 'engine');
59
+ }
60
+ }
61
+ exports.EngineError = EngineError;
62
+ /** Governance is not enabled for this Stigg account. An account state, not a transient failure. */
63
+ class GovernanceNotEnabledError extends Error {
64
+ constructor(detail = 'Governance is not enabled for this account. Contact Stigg to enable it.') {
65
+ super(detail);
66
+ this.name = 'GovernanceNotEnabledError';
67
+ mark(this, 'not-enabled');
68
+ }
69
+ }
70
+ exports.GovernanceNotEnabledError = GovernanceNotEnabledError;
71
+ /** Returns the decision when `err` is a governance denial - the one-liner for a binding catch. */
72
+ function isAccessDenied(err) {
73
+ if (isKind(err, 'denied'))
74
+ return err.decision;
75
+ // Vendor SDKs wrap callback errors, so the denial can arrive one level down.
76
+ const cause = err?.cause;
77
+ if (cause && isKind(cause, 'denied'))
78
+ return cause.decision;
79
+ return undefined;
80
+ }
81
+ const isEngineError = (err) => isKind(err, 'engine');
82
+ exports.isEngineError = isEngineError;
83
+ const isGovernanceNotEnabled = (err) => isKind(err, 'not-enabled');
84
+ exports.isGovernanceNotEnabled = isGovernanceNotEnabled;
85
+ /**
86
+ * True when Stigg refused a usage report because the feature is backed by a raw-events meter.
87
+ * Ingest forks by meter type, and this error is the definitive signal for which fork to take -
88
+ * `meterType` alone does not say (a raw-events feature can report `INCREMENTAL`).
89
+ */
90
+ function isMeterMismatchError(err) {
91
+ const any = err;
92
+ const code = any?.code ?? any?.error?.code ?? '';
93
+ if (code.startsWith('CannotReportUsageForEntitlementWithMeter'))
94
+ return true;
95
+ const message = any?.message ?? '';
96
+ return message.includes('report usage for entitlement with meter') || message.includes('use reportEvent');
97
+ }
98
+ /** Whatever a client threw, as the seam's own error - keeping the status where there was one. */
99
+ function asEngineError(operation, err, partial) {
100
+ const status = err?.status;
101
+ // Re-wrapping must not drop a partial acknowledgement: the run handle wraps again on its way
102
+ // out, and whatever landed is just as true one frame up.
103
+ const landed = partial ?? (err instanceof EngineError ? { reported: err.reported, replayed: err.replayed } : {});
104
+ return new EngineError(operation, err instanceof Error ? err.message : String(err), {
105
+ status,
106
+ cause: err,
107
+ reported: landed.reported,
108
+ replayed: landed.replayed,
109
+ });
110
+ }
111
+ /**
112
+ * True when a failure looks like "this transport is not answering" rather than "Stigg refused".
113
+ *
114
+ * The distinction decides whether another transport is worth trying: a 404 on the GraphQL
115
+ * endpoint or a refused connection says nothing about the request, while a 400 or a 403 says the
116
+ * request itself is wrong and would be wrong on any transport. Deliberately narrow - demoting on
117
+ * a business error would hide a real problem behind a silent re-route.
118
+ */
119
+ function isTransportFailure(err) {
120
+ const any = err;
121
+ if (any?.status && [404, 500, 502, 503, 504].includes(any.status))
122
+ return true;
123
+ const code = any?.cause?.code ?? '';
124
+ if (['ECONNREFUSED', 'ENOTFOUND', 'ETIMEDOUT', 'ECONNRESET', 'EAI_AGAIN'].includes(code))
125
+ return true;
126
+ const message = `${any?.message ?? ''} ${any?.cause?.message ?? ''}`;
127
+ if (/status code (404|5\d\d)/i.test(message))
128
+ return true;
129
+ return /ECONNREFUSED|ENOTFOUND|ETIMEDOUT|ECONNRESET|socket hang up|fetch failed|network error/i.test(message);
130
+ }
131
+ /**
132
+ * The seam's error for an operation that only governance can serve.
133
+ *
134
+ * Entities and assignments exist nowhere else, so a 403 on one of them is the account saying the
135
+ * feature is off - a state the caller can act on - rather than a call that failed. Every other
136
+ * failure is an ordinary engine error.
137
+ */
138
+ function asGovernanceError(operation, err) {
139
+ if (looksLikeGovernanceNotEnabled(err))
140
+ return new GovernanceNotEnabledError();
141
+ return asEngineError(operation, err);
142
+ }
143
+ /** Recognizes the account-state 403 in whatever shape the transport surfaced it. */
144
+ function looksLikeGovernanceNotEnabled(err) {
145
+ if ((0, exports.isGovernanceNotEnabled)(err))
146
+ return true;
147
+ const any = err;
148
+ if (any?.code === 'GovernanceNotEnabled' || any?.error?.code === 'GovernanceNotEnabled')
149
+ return true;
150
+ return any?.status === 403 && (any.message ?? '').includes('Governance is not enabled');
151
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The wire convention for splitting the run lifecycle across a process boundary.
3
+ *
4
+ * A gateway is out-of-process and sees requests, not runs. These headers are what lets the
5
+ * application keep governance in-process while something downstream still ingests against the
6
+ * right entity - so the convention belongs to the core, not to any one binding.
7
+ */
8
+ export declare const GOVERNANCE_HEADERS: {
9
+ readonly customer: "x-stigg-customer-id";
10
+ readonly dimensions: "x-stigg-dimensions";
11
+ readonly run: "x-stigg-run-id";
12
+ };
13
+ /**
14
+ * What `run.headers()` produces - all three, always.
15
+ *
16
+ * Built rather than parsed, so the type says so: an empty map or an unrelated one is not a set of
17
+ * governance headers, and there is no point discovering that at the far end of a request. The
18
+ * receiving side is deliberately looser, because what arrives there is whatever was sent.
19
+ */
20
+ export type GovernanceHeaders = Record<(typeof GOVERNANCE_HEADERS)[keyof typeof GOVERNANCE_HEADERS], string>;
21
+ export type ParsedGovernanceHeaders = {
22
+ customerId: string;
23
+ dimensions: Record<string, string>;
24
+ runId?: string;
25
+ };
26
+ /** The receiving side. Returns undefined when the request carries no attribution to act on. */
27
+ export declare function parseGovernanceHeaders(headers: Record<string, string | string[] | undefined>): ParsedGovernanceHeaders | undefined;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GOVERNANCE_HEADERS = void 0;
4
+ exports.parseGovernanceHeaders = parseGovernanceHeaders;
5
+ /**
6
+ * The wire convention for splitting the run lifecycle across a process boundary.
7
+ *
8
+ * A gateway is out-of-process and sees requests, not runs. These headers are what lets the
9
+ * application keep governance in-process while something downstream still ingests against the
10
+ * right entity - so the convention belongs to the core, not to any one binding.
11
+ */
12
+ exports.GOVERNANCE_HEADERS = {
13
+ customer: 'x-stigg-customer-id',
14
+ dimensions: 'x-stigg-dimensions',
15
+ run: 'x-stigg-run-id',
16
+ };
17
+ /** The receiving side. Returns undefined when the request carries no attribution to act on. */
18
+ function parseGovernanceHeaders(headers) {
19
+ // Node lowercases what it receives, but a map built by hand or converted from `Headers` keeps
20
+ // whatever case the sender used, and losing attribution over it would be silent.
21
+ // What a header is worth, whichever container it arrived in: `'c'` and `['c']` are the same
22
+ // value under this function's own argument type, so comparing the containers would call them a
23
+ // disagreement. A header present but blank is a header that is not set.
24
+ const valueOf = (raw) => {
25
+ const first = Array.isArray(raw) ? raw[0] : raw;
26
+ return first?.trim() ? first.trim() : undefined;
27
+ };
28
+ const lookup = new Map();
29
+ const ambiguous = new Set();
30
+ for (const [key, raw] of Object.entries(headers)) {
31
+ const name = key.toLowerCase();
32
+ const value = valueOf(raw);
33
+ // Two spellings of one header, disagreeing. Folding case makes them the same name, and
34
+ // letting the last one win would attribute the request to whichever the map happened to
35
+ // iterate second - a silently wrong customer reads exactly like a right one.
36
+ if (lookup.has(name) && lookup.get(name) !== value)
37
+ ambiguous.add(name);
38
+ lookup.set(name, value);
39
+ }
40
+ const read = (name) => (ambiguous.has(name) ? undefined : lookup.get(name));
41
+ const customerId = read(exports.GOVERNANCE_HEADERS.customer);
42
+ if (!customerId)
43
+ return undefined;
44
+ let dimensions = {};
45
+ const raw = read(exports.GOVERNANCE_HEADERS.dimensions);
46
+ if (raw) {
47
+ try {
48
+ const parsed = JSON.parse(raw);
49
+ // `JSON.parse` succeeds on `null`, arrays and scalars, none of which are a dimensions map.
50
+ if (isDimensions(parsed))
51
+ dimensions = parsed;
52
+ }
53
+ catch {
54
+ // A malformed header must not cost the request; usage just loses its entity attribution.
55
+ dimensions = {};
56
+ }
57
+ }
58
+ return { customerId, dimensions, runId: read(exports.GOVERNANCE_HEADERS.run) };
59
+ }
60
+ const isDimensions = (value) => typeof value === 'object' &&
61
+ value !== null &&
62
+ !Array.isArray(value) &&
63
+ Object.values(value).every((entry) => typeof entry === 'string');
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Public surface.
3
+ *
4
+ * Importing this file pulls in no vendor package. The recipes below are exported from here, but
5
+ * each one is duck-typed against the shape a vendor returns rather than written against its SDK,
6
+ * so `@anthropic-ai/sdk`, `openai` and the rest stay out of the dependency tree entirely.
7
+ *
8
+ * What is exported here is the vocabulary, the client, and the seams worth extending: a recipe,
9
+ * a metrics mapper, a `GovernanceEngine`. The implementations behind those seams - the concrete
10
+ * engines, decision construction, config resolution, the metric tables - live in
11
+ * `@stigg/agent-sdk-js/internal`, under a weaker compatibility promise.
12
+ */
13
+ export { StiggAgentSDK } from './stigg-agent-sdk';
14
+ export type { AgentType, StiggContext } from './core/context';
15
+ export type { GovernanceSummary, IngestOptions, SessionHooks } from './core/session';
16
+ export { RAW_PREFIX, flattenRaw } from './core/dimensions';
17
+ export type { CacheOptions, ErrorContext, NodeSdkClient, StiggAgentSDKOptions, StiggTarget } from './config';
18
+ export { describeDecision, remedyMessage } from './decision-text';
19
+ export { GOVERNANCE_HEADERS, parseGovernanceHeaders } from './headers';
20
+ export type { GovernanceHeaders, ParsedGovernanceHeaders } from './headers';
21
+ export { consoleLogger, noopLogger } from './logger';
22
+ export type { Logger } from './logger';
23
+ export { EngineError, AccessDeniedError, GovernanceNotEnabledError, isEngineError, isAccessDenied, isGovernanceNotEnabled, looksLikeGovernanceNotEnabled, } from './errors';
24
+ export type { EngineCapabilities, EngineChainNode, EngineCheckParams, EngineCheckResult, EngineReportParams, EngineReportResult, EngineResolution, EntityInput, EventIngest, EntityPlacement, GovernanceEngine, } from './engine/engine';
25
+ export { creditsPerTokens, vendorMetrics, emptyTokenUsage, entitlementId, entitlementKind, entitlementRef, toMeasurement, } from './types';
26
+ export type { AgentOptions, AgentScope, ClientGovernance, CheckErrorAction, ClientOptions, DecisionSource, DeregisterInput, Entitlement, GovernanceDecision, GovernanceRemedy, GovernedClient, IngestContext, IngestMode, IngestResult, Measurement, RegisterInput, GatedSurface, CallContext, TokenUsage, Metrics, MetricsMapper, } from './types';
27
+ export { wrapClient } from './bindings/client/core/wrap-client';
28
+ export { createClientRegistry, hasMethod } from './bindings/client/core/registry';
29
+ export type { ClientRecipe, ClientRegistry, MethodRecipe, MetricsFor, MetricsOf, MeteredResponse, } from './bindings/client/core/types';
30
+ export type { ObservedVendor } from './bindings/shared/token-usage';
31
+ export { anthropicRecipe, estimateFromMaxTokens } from './bindings/client/providers/anthropic/anthropic-recipe';
32
+ export type { AnthropicMetric, AnthropicMetrics } from './bindings/client/providers/anthropic/anthropic-recipe';
33
+ export { openAIRecipe } from './bindings/client/providers/openai/openai-recipe';
34
+ export type { OpenAIMetric, OpenAIMetrics } from './bindings/client/providers/openai/openai-recipe';
35
+ export { geminiRecipe, geminiChatRecipe, estimateFromMaxOutputTokens, } from './bindings/client/providers/gemini/gemini-recipe';
36
+ export type { GeminiMetric, GeminiMetrics } from './bindings/client/providers/gemini/gemini-recipe';
37
+ export { openrouterRecipe } from './bindings/client/gateways/openrouter/openrouter-recipe';
38
+ export type { OpenRouterMetric, OpenRouterMetrics } from './bindings/client/gateways/openrouter/openrouter-recipe';
39
+ export type { OpenRouterRecipeOptions } from './bindings/client/gateways/openrouter/types';
40
+ export { litellmRecipe } from './bindings/client/gateways/litellm/litellm-recipe';
41
+ export type { LiteLLMMetric, LiteLLMMetrics } from './bindings/client/gateways/litellm/litellm-recipe';
42
+ export type { LiteLLMRecipeOptions } from './bindings/client/gateways/litellm/types';
43
+ export { typesafeRecipe, estimateFromState } from './bindings/client/providers/typesafe/typesafe-recipe';
44
+ export type { TypeSafeMetric, TypeSafeMetrics } from './bindings/client/providers/typesafe/typesafe-recipe';
45
+ export { weightedMetrics } from './bindings/shared/weighted-metrics';
46
+ export type { WeightedMetricsOptions } from './bindings/shared/weighted-metrics';
47
+ export type { ProxyIngestInput } from './bindings/proxy';
48
+ export { normalizedMetrics, normalizeUsage } from './bindings/shared/token-usage';
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeUsage = exports.normalizedMetrics = exports.weightedMetrics = exports.estimateFromState = exports.typesafeRecipe = exports.litellmRecipe = exports.openrouterRecipe = exports.estimateFromMaxOutputTokens = exports.geminiChatRecipe = exports.geminiRecipe = exports.openAIRecipe = exports.estimateFromMaxTokens = exports.anthropicRecipe = exports.hasMethod = exports.createClientRegistry = exports.wrapClient = exports.toMeasurement = exports.entitlementRef = exports.entitlementKind = exports.entitlementId = exports.emptyTokenUsage = exports.vendorMetrics = exports.creditsPerTokens = exports.looksLikeGovernanceNotEnabled = exports.isGovernanceNotEnabled = exports.isAccessDenied = exports.isEngineError = exports.GovernanceNotEnabledError = exports.AccessDeniedError = exports.EngineError = exports.noopLogger = exports.consoleLogger = exports.parseGovernanceHeaders = exports.GOVERNANCE_HEADERS = exports.remedyMessage = exports.describeDecision = exports.flattenRaw = exports.RAW_PREFIX = exports.StiggAgentSDK = void 0;
4
+ /**
5
+ * Public surface.
6
+ *
7
+ * Importing this file pulls in no vendor package. The recipes below are exported from here, but
8
+ * each one is duck-typed against the shape a vendor returns rather than written against its SDK,
9
+ * so `@anthropic-ai/sdk`, `openai` and the rest stay out of the dependency tree entirely.
10
+ *
11
+ * What is exported here is the vocabulary, the client, and the seams worth extending: a recipe,
12
+ * a metrics mapper, a `GovernanceEngine`. The implementations behind those seams - the concrete
13
+ * engines, decision construction, config resolution, the metric tables - live in
14
+ * `@stigg/agent-sdk-js/internal`, under a weaker compatibility promise.
15
+ */
16
+ var stigg_agent_sdk_1 = require("./stigg-agent-sdk");
17
+ Object.defineProperty(exports, "StiggAgentSDK", { enumerable: true, get: function () { return stigg_agent_sdk_1.StiggAgentSDK; } });
18
+ // What an event carries off the vendor's own usage object, for anyone building the payload by hand.
19
+ var dimensions_1 = require("./core/dimensions");
20
+ Object.defineProperty(exports, "RAW_PREFIX", { enumerable: true, get: function () { return dimensions_1.RAW_PREFIX; } });
21
+ Object.defineProperty(exports, "flattenRaw", { enumerable: true, get: function () { return dimensions_1.flattenRaw; } });
22
+ var decision_text_1 = require("./decision-text");
23
+ Object.defineProperty(exports, "describeDecision", { enumerable: true, get: function () { return decision_text_1.describeDecision; } });
24
+ Object.defineProperty(exports, "remedyMessage", { enumerable: true, get: function () { return decision_text_1.remedyMessage; } });
25
+ var headers_1 = require("./headers");
26
+ Object.defineProperty(exports, "GOVERNANCE_HEADERS", { enumerable: true, get: function () { return headers_1.GOVERNANCE_HEADERS; } });
27
+ Object.defineProperty(exports, "parseGovernanceHeaders", { enumerable: true, get: function () { return headers_1.parseGovernanceHeaders; } });
28
+ var logger_1 = require("./logger");
29
+ Object.defineProperty(exports, "consoleLogger", { enumerable: true, get: function () { return logger_1.consoleLogger; } });
30
+ Object.defineProperty(exports, "noopLogger", { enumerable: true, get: function () { return logger_1.noopLogger; } });
31
+ var errors_1 = require("./errors");
32
+ Object.defineProperty(exports, "EngineError", { enumerable: true, get: function () { return errors_1.EngineError; } });
33
+ Object.defineProperty(exports, "AccessDeniedError", { enumerable: true, get: function () { return errors_1.AccessDeniedError; } });
34
+ Object.defineProperty(exports, "GovernanceNotEnabledError", { enumerable: true, get: function () { return errors_1.GovernanceNotEnabledError; } });
35
+ Object.defineProperty(exports, "isEngineError", { enumerable: true, get: function () { return errors_1.isEngineError; } });
36
+ Object.defineProperty(exports, "isAccessDenied", { enumerable: true, get: function () { return errors_1.isAccessDenied; } });
37
+ Object.defineProperty(exports, "isGovernanceNotEnabled", { enumerable: true, get: function () { return errors_1.isGovernanceNotEnabled; } });
38
+ Object.defineProperty(exports, "looksLikeGovernanceNotEnabled", { enumerable: true, get: function () { return errors_1.looksLikeGovernanceNotEnabled; } });
39
+ var types_1 = require("./types");
40
+ Object.defineProperty(exports, "creditsPerTokens", { enumerable: true, get: function () { return types_1.creditsPerTokens; } });
41
+ Object.defineProperty(exports, "vendorMetrics", { enumerable: true, get: function () { return types_1.vendorMetrics; } });
42
+ Object.defineProperty(exports, "emptyTokenUsage", { enumerable: true, get: function () { return types_1.emptyTokenUsage; } });
43
+ Object.defineProperty(exports, "entitlementId", { enumerable: true, get: function () { return types_1.entitlementId; } });
44
+ Object.defineProperty(exports, "entitlementKind", { enumerable: true, get: function () { return types_1.entitlementKind; } });
45
+ Object.defineProperty(exports, "entitlementRef", { enumerable: true, get: function () { return types_1.entitlementRef; } });
46
+ Object.defineProperty(exports, "toMeasurement", { enumerable: true, get: function () { return types_1.toMeasurement; } });
47
+ // Bindings: the generic halves only.
48
+ var wrap_client_1 = require("./bindings/client/core/wrap-client");
49
+ Object.defineProperty(exports, "wrapClient", { enumerable: true, get: function () { return wrap_client_1.wrapClient; } });
50
+ var registry_1 = require("./bindings/client/core/registry");
51
+ Object.defineProperty(exports, "createClientRegistry", { enumerable: true, get: function () { return registry_1.createClientRegistry; } });
52
+ Object.defineProperty(exports, "hasMethod", { enumerable: true, get: function () { return registry_1.hasMethod; } });
53
+ var anthropic_recipe_1 = require("./bindings/client/providers/anthropic/anthropic-recipe");
54
+ Object.defineProperty(exports, "anthropicRecipe", { enumerable: true, get: function () { return anthropic_recipe_1.anthropicRecipe; } });
55
+ Object.defineProperty(exports, "estimateFromMaxTokens", { enumerable: true, get: function () { return anthropic_recipe_1.estimateFromMaxTokens; } });
56
+ var openai_recipe_1 = require("./bindings/client/providers/openai/openai-recipe");
57
+ Object.defineProperty(exports, "openAIRecipe", { enumerable: true, get: function () { return openai_recipe_1.openAIRecipe; } });
58
+ // Two recipes for one vendor, because a `GoogleGenAI` client and a `Chat` it created share no
59
+ // method - and a chat holds the *unwrapped* models module privately, so wrapping the client alone
60
+ // would leave every conversation ungoverned. Wrap the chat as well: `stigg.wrap(ai.chats.create(…))`.
61
+ var gemini_recipe_1 = require("./bindings/client/providers/gemini/gemini-recipe");
62
+ Object.defineProperty(exports, "geminiRecipe", { enumerable: true, get: function () { return gemini_recipe_1.geminiRecipe; } });
63
+ Object.defineProperty(exports, "geminiChatRecipe", { enumerable: true, get: function () { return gemini_recipe_1.geminiChatRecipe; } });
64
+ Object.defineProperty(exports, "estimateFromMaxOutputTokens", { enumerable: true, get: function () { return gemini_recipe_1.estimateFromMaxOutputTokens; } });
65
+ // A default: it reports the same token counters as every other vendor, and adds what only a
66
+ // gateway knows - the model that served, the request id, and the `cost` it charged. Billing that
67
+ // cost instead of the tokens is a mapper away, and never inferred from a base URL:
68
+ // `weightedMetrics(openrouterRecipe(), 'credits', { cost: 1 })`.
69
+ var openrouter_recipe_1 = require("./bindings/client/gateways/openrouter/openrouter-recipe");
70
+ Object.defineProperty(exports, "openrouterRecipe", { enumerable: true, get: function () { return openrouter_recipe_1.openrouterRecipe; } });
71
+ // A default too, on the same terms. Its `cost` comes from `x-litellm-response-cost`, which a
72
+ // streamed call cannot carry because headers precede the body - so a run billing cost gets
73
+ // nothing from a stream. Name it at `wrap(client, { recipe })` to give it your proxy's base URL.
74
+ var litellm_recipe_1 = require("./bindings/client/gateways/litellm/litellm-recipe");
75
+ Object.defineProperty(exports, "litellmRecipe", { enumerable: true, get: function () { return litellm_recipe_1.litellmRecipe; } });
76
+ // Built in as well. One method, no stream, and two counters - see the recipe for why a
77
+ // question-answering API has neither a cache counter nor a cost to report.
78
+ var typesafe_recipe_1 = require("./bindings/client/providers/typesafe/typesafe-recipe");
79
+ Object.defineProperty(exports, "typesafeRecipe", { enumerable: true, get: function () { return typesafe_recipe_1.typesafeRecipe; } });
80
+ Object.defineProperty(exports, "estimateFromState", { enumerable: true, get: function () { return typesafe_recipe_1.estimateFromState; } });
81
+ var weighted_metrics_1 = require("./bindings/shared/weighted-metrics");
82
+ Object.defineProperty(exports, "weightedMetrics", { enumerable: true, get: function () { return weighted_metrics_1.weightedMetrics; } });
83
+ var token_usage_1 = require("./bindings/shared/token-usage");
84
+ Object.defineProperty(exports, "normalizedMetrics", { enumerable: true, get: function () { return token_usage_1.normalizedMetrics; } });
85
+ Object.defineProperty(exports, "normalizeUsage", { enumerable: true, get: function () { return token_usage_1.normalizeUsage; } });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Internal surface - `@stigg/agent-sdk-js/internal`.
3
+ *
4
+ * Everything here is an implementation detail: the concrete engines behind the `GovernanceEngine`
5
+ * seam, the pure functions that build a decision, config resolution, and the metric tables the
6
+ * recipes are written against. It is exported because the tests and anyone extending the SDK need
7
+ * to reach it, and reaching into `dist/` by path is worse than a named door.
8
+ *
9
+ * The contract is weaker than `index.ts`: these names can change in a minor release. Anything you
10
+ * can do from the public barrel, do from there instead.
11
+ */
12
+ export { createGovernanceEngine } from './engine/create-engine';
13
+ export type { CreatedEngine, EngineClientOptions } from './engine/create-engine';
14
+ export { CompositeEngine } from './engine/composite-engine';
15
+ export { NodeSdkEngine } from './engine/node-sdk-engine';
16
+ export { RestGovernanceEngine } from './engine/rest-governance-engine';
17
+ export { describeResolution } from './engine/engine';
18
+ export type { EngineOpSource } from './engine/engine';
19
+ export { withDecisionText, policyDecision, remedyFor, toDecision, unenforcedDecision } from './engine/decision';
20
+ export type { DecisionContext } from './engine/decision';
21
+ export { resolveConfig } from './config';
22
+ export type { ResolvedConfig, EngineConfig } from './config';
23
+ export { isTransportFailure, isMeterMismatchError, asEngineError } from './errors';
24
+ export { prefixed } from './logger';
25
+ export { noCustomer, overrideContext, resolveContext, isEnforced } from './core/context';
26
+ export type { ResolvedContext } from './core/context';
27
+ export { GovernanceSession } from './core/session';
28
+ export type { SessionDeps } from './core/session';
29
+ export { ANTHROPIC_METRICS, GEMINI_METRICS, TYPESAFE_METRICS, GATEWAY_METRICS, OPENAI_CHAT_METRICS, OPENAI_METRICS, OPENAI_RESPONSES_METRICS, METRIC_PATHS, metricName, metricNamesMatchPaths, pickMetrics, addMetrics, addTokenUsage, fromFlatTokenUsage, fromGeminiUsage, fromLangChainUsage, fromOpenAIUsage, fromResponsesUsage, observedMeasurement, } from './bindings/shared/token-usage';
30
+ export type { ObservedVendor } from './bindings/shared/token-usage';
31
+ export { DEFAULT_RECIPES } from './stigg-agent-sdk';
32
+ export { meterStream } from './bindings/shared/meter-stream';
33
+ export { eventNameFor } from './bindings/client/core/types';
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Internal surface - `@stigg/agent-sdk-js/internal`.
4
+ *
5
+ * Everything here is an implementation detail: the concrete engines behind the `GovernanceEngine`
6
+ * seam, the pure functions that build a decision, config resolution, and the metric tables the
7
+ * recipes are written against. It is exported because the tests and anyone extending the SDK need
8
+ * to reach it, and reaching into `dist/` by path is worse than a named door.
9
+ *
10
+ * The contract is weaker than `index.ts`: these names can change in a minor release. Anything you
11
+ * can do from the public barrel, do from there instead.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.eventNameFor = exports.meterStream = exports.DEFAULT_RECIPES = exports.observedMeasurement = exports.fromResponsesUsage = exports.fromOpenAIUsage = exports.fromLangChainUsage = exports.fromGeminiUsage = exports.fromFlatTokenUsage = exports.addTokenUsage = exports.addMetrics = exports.pickMetrics = exports.metricNamesMatchPaths = exports.metricName = exports.METRIC_PATHS = exports.OPENAI_RESPONSES_METRICS = exports.OPENAI_METRICS = exports.OPENAI_CHAT_METRICS = exports.GATEWAY_METRICS = exports.TYPESAFE_METRICS = exports.GEMINI_METRICS = exports.ANTHROPIC_METRICS = exports.GovernanceSession = exports.isEnforced = exports.resolveContext = exports.overrideContext = exports.noCustomer = exports.prefixed = exports.asEngineError = exports.isMeterMismatchError = exports.isTransportFailure = exports.resolveConfig = exports.unenforcedDecision = exports.toDecision = exports.remedyFor = exports.policyDecision = exports.withDecisionText = exports.describeResolution = exports.RestGovernanceEngine = exports.NodeSdkEngine = exports.CompositeEngine = exports.createGovernanceEngine = void 0;
15
+ // The engine seam's implementations. The interface itself is public - see `index.ts`.
16
+ var create_engine_1 = require("./engine/create-engine");
17
+ Object.defineProperty(exports, "createGovernanceEngine", { enumerable: true, get: function () { return create_engine_1.createGovernanceEngine; } });
18
+ var composite_engine_1 = require("./engine/composite-engine");
19
+ Object.defineProperty(exports, "CompositeEngine", { enumerable: true, get: function () { return composite_engine_1.CompositeEngine; } });
20
+ var node_sdk_engine_1 = require("./engine/node-sdk-engine");
21
+ Object.defineProperty(exports, "NodeSdkEngine", { enumerable: true, get: function () { return node_sdk_engine_1.NodeSdkEngine; } });
22
+ var rest_governance_engine_1 = require("./engine/rest-governance-engine");
23
+ Object.defineProperty(exports, "RestGovernanceEngine", { enumerable: true, get: function () { return rest_governance_engine_1.RestGovernanceEngine; } });
24
+ var engine_1 = require("./engine/engine");
25
+ Object.defineProperty(exports, "describeResolution", { enumerable: true, get: function () { return engine_1.describeResolution; } });
26
+ // Engine result -> the structured refusal, as pure functions.
27
+ var decision_1 = require("./engine/decision");
28
+ Object.defineProperty(exports, "withDecisionText", { enumerable: true, get: function () { return decision_1.withDecisionText; } });
29
+ Object.defineProperty(exports, "policyDecision", { enumerable: true, get: function () { return decision_1.policyDecision; } });
30
+ Object.defineProperty(exports, "remedyFor", { enumerable: true, get: function () { return decision_1.remedyFor; } });
31
+ Object.defineProperty(exports, "toDecision", { enumerable: true, get: function () { return decision_1.toDecision; } });
32
+ Object.defineProperty(exports, "unenforcedDecision", { enumerable: true, get: function () { return decision_1.unenforcedDecision; } });
33
+ // Config resolution: the target and the options, as the transport actually needs them.
34
+ var config_1 = require("./config");
35
+ Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return config_1.resolveConfig; } });
36
+ // Error predicates that describe transport and enablement, not the caller's contract.
37
+ var errors_1 = require("./errors");
38
+ Object.defineProperty(exports, "isTransportFailure", { enumerable: true, get: function () { return errors_1.isTransportFailure; } });
39
+ Object.defineProperty(exports, "isMeterMismatchError", { enumerable: true, get: function () { return errors_1.isMeterMismatchError; } });
40
+ Object.defineProperty(exports, "asEngineError", { enumerable: true, get: function () { return errors_1.asEngineError; } });
41
+ var logger_1 = require("./logger");
42
+ Object.defineProperty(exports, "prefixed", { enumerable: true, get: function () { return logger_1.prefixed; } });
43
+ // Context resolution: the split that keeps a gated call's own overhead to a property read.
44
+ var context_1 = require("./core/context");
45
+ Object.defineProperty(exports, "noCustomer", { enumerable: true, get: function () { return context_1.noCustomer; } });
46
+ Object.defineProperty(exports, "overrideContext", { enumerable: true, get: function () { return context_1.overrideContext; } });
47
+ Object.defineProperty(exports, "resolveContext", { enumerable: true, get: function () { return context_1.resolveContext; } });
48
+ Object.defineProperty(exports, "isEnforced", { enumerable: true, get: function () { return context_1.isEnforced; } });
49
+ var session_1 = require("./core/session");
50
+ Object.defineProperty(exports, "GovernanceSession", { enumerable: true, get: function () { return session_1.GovernanceSession; } });
51
+ // What each vendor calls its counters, and where they are read from. A recipe is written against
52
+ // these; a consumer reads `recipe.metrics` instead.
53
+ var token_usage_1 = require("./bindings/shared/token-usage");
54
+ Object.defineProperty(exports, "ANTHROPIC_METRICS", { enumerable: true, get: function () { return token_usage_1.ANTHROPIC_METRICS; } });
55
+ Object.defineProperty(exports, "GEMINI_METRICS", { enumerable: true, get: function () { return token_usage_1.GEMINI_METRICS; } });
56
+ Object.defineProperty(exports, "TYPESAFE_METRICS", { enumerable: true, get: function () { return token_usage_1.TYPESAFE_METRICS; } });
57
+ Object.defineProperty(exports, "GATEWAY_METRICS", { enumerable: true, get: function () { return token_usage_1.GATEWAY_METRICS; } });
58
+ Object.defineProperty(exports, "OPENAI_CHAT_METRICS", { enumerable: true, get: function () { return token_usage_1.OPENAI_CHAT_METRICS; } });
59
+ Object.defineProperty(exports, "OPENAI_METRICS", { enumerable: true, get: function () { return token_usage_1.OPENAI_METRICS; } });
60
+ Object.defineProperty(exports, "OPENAI_RESPONSES_METRICS", { enumerable: true, get: function () { return token_usage_1.OPENAI_RESPONSES_METRICS; } });
61
+ Object.defineProperty(exports, "METRIC_PATHS", { enumerable: true, get: function () { return token_usage_1.METRIC_PATHS; } });
62
+ Object.defineProperty(exports, "metricName", { enumerable: true, get: function () { return token_usage_1.metricName; } });
63
+ Object.defineProperty(exports, "metricNamesMatchPaths", { enumerable: true, get: function () { return token_usage_1.metricNamesMatchPaths; } });
64
+ Object.defineProperty(exports, "pickMetrics", { enumerable: true, get: function () { return token_usage_1.pickMetrics; } });
65
+ Object.defineProperty(exports, "addMetrics", { enumerable: true, get: function () { return token_usage_1.addMetrics; } });
66
+ Object.defineProperty(exports, "addTokenUsage", { enumerable: true, get: function () { return token_usage_1.addTokenUsage; } });
67
+ Object.defineProperty(exports, "fromFlatTokenUsage", { enumerable: true, get: function () { return token_usage_1.fromFlatTokenUsage; } });
68
+ Object.defineProperty(exports, "fromGeminiUsage", { enumerable: true, get: function () { return token_usage_1.fromGeminiUsage; } });
69
+ Object.defineProperty(exports, "fromLangChainUsage", { enumerable: true, get: function () { return token_usage_1.fromLangChainUsage; } });
70
+ Object.defineProperty(exports, "fromOpenAIUsage", { enumerable: true, get: function () { return token_usage_1.fromOpenAIUsage; } });
71
+ Object.defineProperty(exports, "fromResponsesUsage", { enumerable: true, get: function () { return token_usage_1.fromResponsesUsage; } });
72
+ Object.defineProperty(exports, "observedMeasurement", { enumerable: true, get: function () { return token_usage_1.observedMeasurement; } });
73
+ // The recipes `wrap` matches against when no recipe is named. Exposed so a caller - the examples'
74
+ // own offline seeding, above all - can enumerate what this package governs without keeping a
75
+ // second copy of the list that silently falls behind each time a vendor is added.
76
+ var stigg_agent_sdk_1 = require("./stigg-agent-sdk");
77
+ Object.defineProperty(exports, "DEFAULT_RECIPES", { enumerable: true, get: function () { return stigg_agent_sdk_1.DEFAULT_RECIPES; } });
78
+ var meter_stream_1 = require("./bindings/shared/meter-stream");
79
+ Object.defineProperty(exports, "meterStream", { enumerable: true, get: function () { return meter_stream_1.meterStream; } });
80
+ var types_1 = require("./bindings/client/core/types");
81
+ Object.defineProperty(exports, "eventNameFor", { enumerable: true, get: function () { return types_1.eventNameFor; } });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The smallest logger the SDK can depend on. Structural, so any console-shaped object - or a
3
+ * pino/winston child - satisfies it without an adapter.
4
+ */
5
+ export interface Logger {
6
+ debug(message: string, ...args: unknown[]): void;
7
+ info(message: string, ...args: unknown[]): void;
8
+ warn(message: string, ...args: unknown[]): void;
9
+ error(message: string, ...args: unknown[]): void;
10
+ }
11
+ /** What `logger: 'none'` resolves to, for a process that wants the SDK silent. */
12
+ export declare const noopLogger: Logger;
13
+ export declare const consoleLogger: Logger;
14
+ /** Prefixes every line, so example output shows which subsystem spoke. */
15
+ export declare const prefixed: (logger: Logger, prefix: string) => Logger;
package/dist/logger.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prefixed = exports.consoleLogger = exports.noopLogger = void 0;
4
+ const noop = () => undefined;
5
+ /** What `logger: 'none'` resolves to, for a process that wants the SDK silent. */
6
+ exports.noopLogger = { debug: noop, info: noop, warn: noop, error: noop };
7
+ exports.consoleLogger = {
8
+ debug: (message, ...args) => console.debug(message, ...args),
9
+ info: (message, ...args) => console.log(message, ...args),
10
+ warn: (message, ...args) => console.warn(message, ...args),
11
+ error: (message, ...args) => console.error(message, ...args),
12
+ };
13
+ /** Prefixes every line, so example output shows which subsystem spoke. */
14
+ const prefixed = (logger, prefix) => ({
15
+ debug: (message, ...args) => logger.debug(`${prefix} ${message}`, ...args),
16
+ info: (message, ...args) => logger.info(`${prefix} ${message}`, ...args),
17
+ warn: (message, ...args) => logger.warn(`${prefix} ${message}`, ...args),
18
+ error: (message, ...args) => logger.error(`${prefix} ${message}`, ...args),
19
+ });
20
+ exports.prefixed = prefixed;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * How a Stigg deployment can tell this SDK's traffic apart from everything else's.
3
+ *
4
+ * There is no analytics pipeline here and this is not one: nothing is emitted, nothing is batched,
5
+ * nothing fires on a schedule. Adoption is read off the requests the SDK was already making, which
6
+ * is the same answer the Node server SDK and the sidecar give - identity rides along on headers,
7
+ * so there is no second network path to fail, no payload to review for what it collects, and
8
+ * nothing to disable.
9
+ *
10
+ * Without this, an agent-sdk install is invisible: its GraphQL half reports as a plain
11
+ * `node-server-sdk` client, and its REST half carries no Stigg identity at all.
12
+ */
13
+ /**
14
+ * This package's own version, read from its manifest rather than restated here - a constant would
15
+ * have to be remembered on every release, and the one release where it is not is the release the
16
+ * numbers quietly stop meaning anything.
17
+ *
18
+ * `dist/sdk-identity.js` and `src/sdk-identity.ts` both sit one directory under the package root,
19
+ * so the same relative path works built and from source.
20
+ */
21
+ export declare const AGENT_SDK_VERSION: string;
22
+ /**
23
+ * Deliberately not `SourceType.AgentSdk`: that enum lives in Stigg's GraphQL schema, the API
24
+ * groups on it, and there is no member for this SDK. Adding one is a server change that has to
25
+ * land first, so the client name is what carries the distinction in the meantime - exactly the
26
+ * trade the sidecar made when it started naming itself.
27
+ */
28
+ export declare const AGENT_SDK_CLIENT_NAME = "agent-sdk-js";
29
+ /**
30
+ * The REST client's equivalent, since it has no client-awareness convention of its own.
31
+ *
32
+ * Named into the `X-SDK-` family the GraphQL transport already sends, so both halves of one
33
+ * agent-sdk process are recognizable the same way. Nothing on the server branches on these; they
34
+ * arrive as trace tags, which is all identity needs to be.
35
+ */
36
+ export declare const AGENT_SDK_REST_HEADERS: Record<string, string>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * How a Stigg deployment can tell this SDK's traffic apart from everything else's.
4
+ *
5
+ * There is no analytics pipeline here and this is not one: nothing is emitted, nothing is batched,
6
+ * nothing fires on a schedule. Adoption is read off the requests the SDK was already making, which
7
+ * is the same answer the Node server SDK and the sidecar give - identity rides along on headers,
8
+ * so there is no second network path to fail, no payload to review for what it collects, and
9
+ * nothing to disable.
10
+ *
11
+ * Without this, an agent-sdk install is invisible: its GraphQL half reports as a plain
12
+ * `node-server-sdk` client, and its REST half carries no Stigg identity at all.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AGENT_SDK_REST_HEADERS = exports.AGENT_SDK_CLIENT_NAME = exports.AGENT_SDK_VERSION = void 0;
16
+ /**
17
+ * This package's own version, read from its manifest rather than restated here - a constant would
18
+ * have to be remembered on every release, and the one release where it is not is the release the
19
+ * numbers quietly stop meaning anything.
20
+ *
21
+ * `dist/sdk-identity.js` and `src/sdk-identity.ts` both sit one directory under the package root,
22
+ * so the same relative path works built and from source.
23
+ */
24
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
25
+ exports.AGENT_SDK_VERSION = require('../package.json').version;
26
+ /**
27
+ * Deliberately not `SourceType.AgentSdk`: that enum lives in Stigg's GraphQL schema, the API
28
+ * groups on it, and there is no member for this SDK. Adding one is a server change that has to
29
+ * land first, so the client name is what carries the distinction in the meantime - exactly the
30
+ * trade the sidecar made when it started naming itself.
31
+ */
32
+ exports.AGENT_SDK_CLIENT_NAME = 'agent-sdk-js';
33
+ /**
34
+ * The REST client's equivalent, since it has no client-awareness convention of its own.
35
+ *
36
+ * Named into the `X-SDK-` family the GraphQL transport already sends, so both halves of one
37
+ * agent-sdk process are recognizable the same way. Nothing on the server branches on these; they
38
+ * arrive as trace tags, which is all identity needs to be.
39
+ */
40
+ exports.AGENT_SDK_REST_HEADERS = {
41
+ 'X-SDK-CLIENT-NAME': exports.AGENT_SDK_CLIENT_NAME,
42
+ 'X-SDK-CLIENT-VERSION': exports.AGENT_SDK_VERSION,
43
+ };