@supportbridge/sdk 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/LICENSE +13 -0
- package/README.md +326 -0
- package/SECURITY.md +26 -0
- package/dist/agent.d.ts +9 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +73 -0
- package/dist/agent.js.map +1 -0
- package/dist/client.d.ts +68 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +254 -0
- package/dist/client.js.map +1 -0
- package/dist/context.d.ts +4 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/control-plane.d.ts +37 -0
- package/dist/control-plane.d.ts.map +1 -0
- package/dist/control-plane.js +43 -0
- package/dist/control-plane.js.map +1 -0
- package/dist/doctor.d.ts +17 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +49 -0
- package/dist/doctor.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +42 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +215 -0
- package/dist/install.js.map +1 -0
- package/dist/mcp-app.d.ts +50 -0
- package/dist/mcp-app.d.ts.map +1 -0
- package/dist/mcp-app.js +44 -0
- package/dist/mcp-app.js.map +1 -0
- package/dist/mcp.d.ts +44 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +117 -0
- package/dist/mcp.js.map +1 -0
- package/dist/offer-app.d.ts +41 -0
- package/dist/offer-app.d.ts.map +1 -0
- package/dist/offer-app.js +21 -0
- package/dist/offer-app.js.map +1 -0
- package/dist/policy-app.d.ts +41 -0
- package/dist/policy-app.d.ts.map +1 -0
- package/dist/policy-app.js +49 -0
- package/dist/policy-app.js.map +1 -0
- package/dist/policy-store.d.ts +79 -0
- package/dist/policy-store.d.ts.map +1 -0
- package/dist/policy-store.js +137 -0
- package/dist/policy-store.js.map +1 -0
- package/dist/policy.d.ts +226 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +420 -0
- package/dist/policy.js.map +1 -0
- package/dist/sanitize.d.ts +9 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +83 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/state.d.ts +31 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +29 -0
- package/dist/state.js.map +1 -0
- package/dist/transport.d.ts +57 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +132 -0
- package/dist/transport.js.map +1 -0
- package/dist/triggers.d.ts +19 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +132 -0
- package/dist/triggers.js.map +1 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/policy-engine.md +47 -0
- package/docs/telemetry-contract.md +29 -0
- package/package.json +53 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
export interface SupportIdentity {
|
|
6
|
+
userId: string;
|
|
7
|
+
workspaceId?: string;
|
|
8
|
+
tenantId?: string;
|
|
9
|
+
traits?: Record<string, JsonPrimitive>;
|
|
10
|
+
}
|
|
11
|
+
export interface TraceContext {
|
|
12
|
+
traceId: string;
|
|
13
|
+
runId?: string;
|
|
14
|
+
parentSpanId?: string;
|
|
15
|
+
identity?: SupportIdentity;
|
|
16
|
+
}
|
|
17
|
+
export type ToolOutcome = "success" | "error" | "timeout" | "empty" | "blocked" | "cancelled";
|
|
18
|
+
export interface TelemetryBase {
|
|
19
|
+
id: string;
|
|
20
|
+
type: "tool_call" | "agent_run" | "model_call" | "support_decision" | "policy_evaluation" | "sdk_diagnostic";
|
|
21
|
+
timestamp: string;
|
|
22
|
+
sdkName: "@supportbridge/sdk";
|
|
23
|
+
sdkVersion: string;
|
|
24
|
+
source: string;
|
|
25
|
+
serviceVersion?: string;
|
|
26
|
+
environment?: string;
|
|
27
|
+
identity?: SupportIdentity;
|
|
28
|
+
traceId?: string;
|
|
29
|
+
runId?: string;
|
|
30
|
+
spanId?: string;
|
|
31
|
+
parentSpanId?: string;
|
|
32
|
+
attributes?: Record<string, JsonValue>;
|
|
33
|
+
}
|
|
34
|
+
export interface ToolCallEvent extends TelemetryBase {
|
|
35
|
+
type: "tool_call";
|
|
36
|
+
toolName: string;
|
|
37
|
+
outcome: ToolOutcome;
|
|
38
|
+
durationMs: number;
|
|
39
|
+
arguments?: JsonValue;
|
|
40
|
+
responseSummary?: JsonValue;
|
|
41
|
+
errorCode?: string;
|
|
42
|
+
errorMessage?: string;
|
|
43
|
+
triggerId?: string;
|
|
44
|
+
requestId?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface AgentRunEvent extends TelemetryBase {
|
|
47
|
+
type: "agent_run";
|
|
48
|
+
agentName: string;
|
|
49
|
+
phase: "started" | "completed";
|
|
50
|
+
outcome?: "success" | "error" | "cancelled";
|
|
51
|
+
durationMs?: number;
|
|
52
|
+
errorCode?: string;
|
|
53
|
+
errorMessage?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ModelCallEvent extends TelemetryBase {
|
|
56
|
+
type: "model_call";
|
|
57
|
+
provider: string;
|
|
58
|
+
model: string;
|
|
59
|
+
outcome: "success" | "error" | "timeout";
|
|
60
|
+
durationMs: number;
|
|
61
|
+
inputTokens?: number;
|
|
62
|
+
outputTokens?: number;
|
|
63
|
+
costUsd?: number;
|
|
64
|
+
prompt?: JsonValue;
|
|
65
|
+
response?: JsonValue;
|
|
66
|
+
errorCode?: string;
|
|
67
|
+
errorMessage?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface SupportDecisionEvent extends TelemetryBase {
|
|
70
|
+
type: "support_decision";
|
|
71
|
+
triggerId: string;
|
|
72
|
+
decision: "offered" | "presented" | "accepted" | "dismissed" | "expired" | "reset";
|
|
73
|
+
reason?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface PolicyEvaluationEvent extends TelemetryBase {
|
|
76
|
+
type: "policy_evaluation";
|
|
77
|
+
policyId: string;
|
|
78
|
+
policyVersion: number;
|
|
79
|
+
eventId: string;
|
|
80
|
+
correlationId: string;
|
|
81
|
+
workspaceId: string;
|
|
82
|
+
matchResult: boolean;
|
|
83
|
+
durationMs: number;
|
|
84
|
+
conditionTrace: JsonValue;
|
|
85
|
+
proposedActions: JsonValue;
|
|
86
|
+
suppressedActions: JsonValue;
|
|
87
|
+
skippedReason?: string;
|
|
88
|
+
missingFields?: string[];
|
|
89
|
+
}
|
|
90
|
+
export interface SdkDiagnosticEvent extends TelemetryBase {
|
|
91
|
+
type: "sdk_diagnostic";
|
|
92
|
+
code: "queue_overflow" | "delivery_failed" | "invalid_identity" | "installation_verified" | "doctor_check";
|
|
93
|
+
message: string;
|
|
94
|
+
droppedEvents?: number;
|
|
95
|
+
capabilities?: Record<string, JsonValue>;
|
|
96
|
+
}
|
|
97
|
+
export interface SupportBrief {
|
|
98
|
+
issue: string;
|
|
99
|
+
errorCode?: string;
|
|
100
|
+
customer?: string;
|
|
101
|
+
recentToolCalls: Array<{
|
|
102
|
+
timestamp: string;
|
|
103
|
+
toolName: string;
|
|
104
|
+
outcome: ToolOutcome;
|
|
105
|
+
arguments?: JsonValue;
|
|
106
|
+
errorCode?: string;
|
|
107
|
+
errorMessage?: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
export type TelemetryEvent = ToolCallEvent | AgentRunEvent | ModelCallEvent | SupportDecisionEvent | PolicyEvaluationEvent | SdkDiagnosticEvent;
|
|
111
|
+
export type TelemetryEventBase = Omit<TelemetryBase, "type">;
|
|
112
|
+
export interface PrivacyOptions {
|
|
113
|
+
captureToolArguments?: boolean;
|
|
114
|
+
captureToolResponses?: boolean;
|
|
115
|
+
captureAgentContent?: boolean;
|
|
116
|
+
sensitiveKeys?: string[];
|
|
117
|
+
maxStringLength?: number;
|
|
118
|
+
maxArrayLength?: number;
|
|
119
|
+
maxObjectKeys?: number;
|
|
120
|
+
maxDepth?: number;
|
|
121
|
+
redactionText?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface ResolvedPrivacyOptions {
|
|
124
|
+
captureToolArguments: boolean;
|
|
125
|
+
captureToolResponses: boolean;
|
|
126
|
+
captureAgentContent: boolean;
|
|
127
|
+
sensitiveKeys: string[];
|
|
128
|
+
maxStringLength: number;
|
|
129
|
+
maxArrayLength: number;
|
|
130
|
+
maxObjectKeys: number;
|
|
131
|
+
maxDepth: number;
|
|
132
|
+
redactionText: string;
|
|
133
|
+
}
|
|
134
|
+
export interface ArgumentTrigger {
|
|
135
|
+
id: string;
|
|
136
|
+
kind: "argument_match";
|
|
137
|
+
toolName: string | RegExp;
|
|
138
|
+
path: string;
|
|
139
|
+
operator: "equals" | "contains" | "matches";
|
|
140
|
+
value: string;
|
|
141
|
+
action: "offer" | "require_acknowledgement" | "block_and_offer";
|
|
142
|
+
oncePer?: "user" | "workspace" | "trace" | "always";
|
|
143
|
+
reason?: string;
|
|
144
|
+
motion?: "support" | "assistance";
|
|
145
|
+
assignedRep?: {
|
|
146
|
+
id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
status: string;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export interface RepeatedFailureTrigger {
|
|
152
|
+
id: string;
|
|
153
|
+
kind: "repeated_failure";
|
|
154
|
+
toolName?: string | RegExp;
|
|
155
|
+
threshold: number;
|
|
156
|
+
windowMs: number;
|
|
157
|
+
sameErrorCode?: boolean;
|
|
158
|
+
action: "offer" | "require_acknowledgement" | "block_and_offer";
|
|
159
|
+
oncePer?: "user" | "workspace" | "trace" | "always";
|
|
160
|
+
reason?: string;
|
|
161
|
+
motion?: "support" | "assistance";
|
|
162
|
+
assignedRep?: {
|
|
163
|
+
id: string;
|
|
164
|
+
name: string;
|
|
165
|
+
status: string;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export type SupportTrigger = ArgumentTrigger | RepeatedFailureTrigger;
|
|
169
|
+
export interface SupportOffer {
|
|
170
|
+
triggerId: string;
|
|
171
|
+
reason: string;
|
|
172
|
+
blocking: boolean;
|
|
173
|
+
requiresAcknowledgement: boolean;
|
|
174
|
+
message: string;
|
|
175
|
+
retryOriginalRequestAfterDecision: boolean;
|
|
176
|
+
motion?: "support" | "assistance";
|
|
177
|
+
assignedRep?: {
|
|
178
|
+
id: string;
|
|
179
|
+
name: string;
|
|
180
|
+
status: string;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export type SupportDecision = "accepted" | "dismissed";
|
|
184
|
+
export interface ToolInvocation<TArguments = unknown> {
|
|
185
|
+
toolName: string;
|
|
186
|
+
arguments: TArguments;
|
|
187
|
+
identity?: SupportIdentity;
|
|
188
|
+
requestId?: string;
|
|
189
|
+
traceId?: string;
|
|
190
|
+
runId?: string;
|
|
191
|
+
parentSpanId?: string;
|
|
192
|
+
attributes?: Record<string, JsonValue>;
|
|
193
|
+
}
|
|
194
|
+
export type InstrumentedToolResult<TResult> = {
|
|
195
|
+
kind: "result";
|
|
196
|
+
value: TResult;
|
|
197
|
+
offer?: SupportOffer;
|
|
198
|
+
} | {
|
|
199
|
+
kind: "support_offer";
|
|
200
|
+
offer: SupportOffer;
|
|
201
|
+
};
|
|
202
|
+
export interface AgentRunOptions {
|
|
203
|
+
agentName: string;
|
|
204
|
+
identity?: SupportIdentity;
|
|
205
|
+
traceId?: string;
|
|
206
|
+
runId?: string;
|
|
207
|
+
attributes?: Record<string, JsonValue>;
|
|
208
|
+
}
|
|
209
|
+
export interface ModelCallOptions {
|
|
210
|
+
provider: string;
|
|
211
|
+
model: string;
|
|
212
|
+
inputTokens?: number;
|
|
213
|
+
outputTokens?: number;
|
|
214
|
+
costUsd?: number;
|
|
215
|
+
prompt?: unknown;
|
|
216
|
+
response?: unknown;
|
|
217
|
+
error?: unknown;
|
|
218
|
+
startedAt?: number;
|
|
219
|
+
attributes?: Record<string, JsonValue>;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEnF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAE9F,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;IAC7G,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM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AE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACxC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Policy engine
|
|
2
|
+
|
|
3
|
+
SupportBridge policies have one executable form: `CanonicalPolicy` schema version `1.0`. Both the natural-language and manual authoring experiences operate on that object. The original prompt is audit context, never executable input.
|
|
4
|
+
|
|
5
|
+
## Safety boundary
|
|
6
|
+
|
|
7
|
+
- Only paths in `PolicyRegistry.fields` can be read.
|
|
8
|
+
- Each field declares its value type and allowed operators.
|
|
9
|
+
- Only actions in `PolicyRegistry.actions` can enter a decision plan.
|
|
10
|
+
- Action parameters are typed and reference parameters can be checked by a `PolicyReferenceResolver`.
|
|
11
|
+
- Unknown paths, operators, events, actions, parameters, unsafe patterns, and cross-workspace references fail validation.
|
|
12
|
+
- Evaluation receives an explicit clock, has bounded condition depth and action counts, and prevents a policy from reprocessing an event it emitted.
|
|
13
|
+
- Simulations call the pure evaluator and never call an action executor.
|
|
14
|
+
|
|
15
|
+
## Authoring pipeline
|
|
16
|
+
|
|
17
|
+
`PolicyNlpProvider` is vendor-neutral. Its `compile` method returns a canonical draft, assumptions, ambiguities, unsupported requests, confidence, and an explanation. `FakePolicyNlpProvider` is deterministic and intended for local development and automated tests. A production LLM provider must use schema-constrained output and still pass the result through `validatePolicy`.
|
|
18
|
+
|
|
19
|
+
The MCP installation registers `open_policy_builder`, `generate_policy_draft`, `validate_policy_draft`, and `simulate_policy_draft`, plus `ui://supportbridge/policy-builder.html`. The embedded app visibly supports “Describe with AI” and “Build manually.” The draft stays in one canonical object while the administrator switches modes.
|
|
20
|
+
|
|
21
|
+
## Evaluation and execution
|
|
22
|
+
|
|
23
|
+
`PolicyEngine.evaluate` sorts by priority, category, then stable policy ID. It returns condition traces, proposed or dry-run-suppressed actions, missing fields, conflicts, and deterministic deduplication keys. It does not perform side effects.
|
|
24
|
+
|
|
25
|
+
Use `executeDecisionPlan` only after authorization. Supply a persistent `IdempotencyStore` in distributed production systems; `MemoryIdempotencyStore` is for local or single-process use.
|
|
26
|
+
|
|
27
|
+
## Governance
|
|
28
|
+
|
|
29
|
+
`MemoryPolicyStore` demonstrates the lifecycle contract:
|
|
30
|
+
|
|
31
|
+
1. Create and update a revision-checked draft.
|
|
32
|
+
2. Validate and request approval.
|
|
33
|
+
3. Require another authorized actor to approve.
|
|
34
|
+
4. Publish an immutable version, initially in dry-run mode by default.
|
|
35
|
+
5. Disable or roll back by appending a new version.
|
|
36
|
+
6. Retain workspace-scoped audit events and version diffs.
|
|
37
|
+
|
|
38
|
+
Production control planes should implement the same contract with durable transactions, tenant authorization, encrypted storage, rate limits, and an append-only audit log.
|
|
39
|
+
|
|
40
|
+
## Production extension points
|
|
41
|
+
|
|
42
|
+
- Add approved domain fields and resolvers through `PolicyRegistry`.
|
|
43
|
+
- Add typed actions and tenant reference kinds through action definitions.
|
|
44
|
+
- Implement `PolicyReferenceResolver` against the active tenant catalog.
|
|
45
|
+
- Implement `PolicyNlpProvider` for the chosen model vendor.
|
|
46
|
+
- Implement durable policy, evaluation-log, action-execution, and idempotency repositories.
|
|
47
|
+
- Send policy evaluation metrics and redacted traces through the existing telemetry transport.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Telemetry contract
|
|
2
|
+
|
|
3
|
+
All events include `eventId`, `type`, `timestamp`, `source`, `environment`, and `sdkVersion`. When available, they also include `traceId`, `spanId`, `parentSpanId`, `runId`, `requestId`, `serviceVersion`, and a sanitized identity.
|
|
4
|
+
|
|
5
|
+
## Tool calls
|
|
6
|
+
|
|
7
|
+
`tool_call` records the tool name, start and end time, duration, outcome, sanitized arguments, a bounded result summary, and normalized error details. Tool events can also include a support offer and the trigger that produced it.
|
|
8
|
+
|
|
9
|
+
## Agent runs
|
|
10
|
+
|
|
11
|
+
`agent_run` records the agent name, timing, status, and optional metadata. Prompt or response content is collected only when `captureAgentContent` is enabled.
|
|
12
|
+
|
|
13
|
+
## Model calls
|
|
14
|
+
|
|
15
|
+
`model_call` records provider, model, timing, status, token counts, and optional error details. Input and output content follow the same explicit opt-in rule as agent content.
|
|
16
|
+
|
|
17
|
+
## Delivery
|
|
18
|
+
|
|
19
|
+
Events are queued in memory and sent in JSON batches:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"events": []
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The HTTP transport sends `content-type: application/json`, `user-agent: supportbridge-sdk/0.1.0`, and, when configured, `authorization: Bearer <apiKey>`. A non-2xx response is retried by the buffered transport up to its configured limit. Delivery failures do not change the vendor tool result.
|
|
28
|
+
|
|
29
|
+
Event types are exported from the package so a backend can validate and persist the same contract without depending on internal implementation files.
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@supportbridge/sdk",
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"description": "Production-oriented MCP tool-call and agent telemetry SDK for SupportBridge",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"supportbridge": "./dist/doctor.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"docs",
|
|
20
|
+
"README.md",
|
|
21
|
+
"SECURITY.md",
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"mcp",
|
|
31
|
+
"telemetry",
|
|
32
|
+
"support",
|
|
33
|
+
"agents",
|
|
34
|
+
"observability"
|
|
35
|
+
],
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@modelcontextprotocol/ext-apps": "^1.7.5",
|
|
39
|
+
"zod": "^3.25.76"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": ">=1.30.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^24.3.0",
|
|
46
|
+
"typescript": "^5.9.2"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.json",
|
|
50
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
51
|
+
"test": "tsc -p tsconfig.test.json && node --test .test-dist/test/*.test.js"
|
|
52
|
+
}
|
|
53
|
+
}
|