@harness-gw/sdk 0.11.0 → 0.13.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/README.md CHANGED
@@ -63,7 +63,7 @@ You need a running harness. Hermes is the primary one; see
63
63
  docker run --rm \
64
64
  -v "$PWD/config.yaml:/run/harness-gw/config.yaml:ro" \
65
65
  -v "$PWD/hermes-token:/run/secrets/hermes-token:ro" \
66
- ghcr.io/almogbaku/harness-gw:0.11.0 \
66
+ ghcr.io/almogbaku/harness-gw:0.13.0 \
67
67
  config check --config /run/harness-gw/config.yaml
68
68
  ```
69
69
 
@@ -73,7 +73,7 @@ You need a running harness. Hermes is the primary one; see
73
73
  docker run --rm -p 127.0.0.1:4100:4100 \
74
74
  -v "$PWD/config.yaml:/run/harness-gw/config.yaml:ro" \
75
75
  -v "$PWD/hermes-token:/run/secrets/hermes-token:ro" \
76
- ghcr.io/almogbaku/harness-gw:0.11.0 \
76
+ ghcr.io/almogbaku/harness-gw:0.13.0 \
77
77
  serve --config /run/harness-gw/config.yaml
78
78
  ```
79
79
 
@@ -116,12 +116,13 @@ await connection.joined(sessionId)
116
116
  await connection.prompt(sessionId, [{ type: "text", text: "Hello" }], {})
117
117
  ```
118
118
 
119
- The package has two entry points:
119
+ The package has three entry points:
120
120
 
121
121
  | Import | What it holds |
122
122
  | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123
123
  | `@harness-gw/sdk` | The ACP connection with reconnect and backoff, the workspace client (Agents, Sessions, read state, activity), approvals, questions, and `HgwRemoteClient` for the HTTP routes |
124
124
  | `@harness-gw/sdk/protocol` | The wire alone: `_hgw/*` method names, the `_meta.hgw` zod schemas and their types, route paths and `HGW_EXTENSION_VERSION`. It loads without the client |
125
+ | `@harness-gw/sdk/node` | Server-only: `mcpAppStableOriginKey` and `artifactFileId`, the ids an MCP server derives as the gateway does. It needs Node's `crypto` |
125
126
 
126
127
  The client checks the gateway's extension version during `initialize`. On a
127
128
  mismatch it fails `initialized` with both versions named and stops instead of
@@ -1151,20 +1151,27 @@ var McpAppFilesSchema2 = z4.strictObject({
1151
1151
  addresses: z4.record(z4.string(), z4.string().startsWith("/").max(8192)),
1152
1152
  expiresAt: z4.iso.datetime().optional()
1153
1153
  });
1154
+ var McpUiDomainSchema2 = z4.string().max(253).regex(new RegExp(`^${HOST}$`, "u"));
1154
1155
  var McpAppViewSchema2 = z4.strictObject({
1155
1156
  html: z4.string().max(5000000),
1156
1157
  csp: McpUiCspSchema2.optional(),
1157
1158
  permissions: McpUiPermissionsSchema2.optional(),
1158
1159
  prefersBorder: z4.boolean().optional(),
1160
+ domain: McpUiDomainSchema2.optional(),
1159
1161
  toolInput: z4.record(z4.string(), z4.unknown()).optional(),
1160
1162
  toolResult: CallToolResultSchema2.optional(),
1161
1163
  files: McpAppFilesSchema2.optional()
1162
1164
  });
1163
1165
  function viewerFileResult2({
1164
1166
  filename,
1165
- mimeType
1167
+ mimeType,
1168
+ fileId
1166
1169
  }) {
1167
- const value = { filename, ...mimeType && { mimeType } };
1170
+ const value = {
1171
+ filename,
1172
+ ...mimeType && { mimeType },
1173
+ ...fileId && { fileId }
1174
+ };
1168
1175
  return {
1169
1176
  content: [
1170
1177
  {
@@ -1186,25 +1193,81 @@ var McpAppResourceReadRequestSchema2 = z4.strictObject({
1186
1193
  uri: z4.string().min(1).max(2048)
1187
1194
  });
1188
1195
  var MCP_APP_SANDBOX_PATH2 = "/mcp-app-sandbox.html";
1189
- var LOOPBACK_SOURCES = (scheme) => ["127.0.0.1", "localhost", "*.localhost"].map((host) => `${scheme}://${host}:*`);
1190
- var MCP_APP_SANDBOX_CSP2 = [
1191
- "default-src 'none'",
1192
- "script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https:",
1193
- "style-src 'self' 'unsafe-inline' https:",
1194
- "img-src 'self' data: https:",
1195
- "font-src 'self' data: https:",
1196
- ["media-src 'self' data: https:", ...LOOPBACK_SOURCES("http")].join(" "),
1197
- [
1198
- "connect-src https: wss:",
1199
- ...LOOPBACK_SOURCES("http"),
1200
- ...LOOPBACK_SOURCES("ws")
1201
- ].join(" "),
1202
- "worker-src 'self' blob: data:",
1203
- "frame-src https:",
1204
- "base-uri https:",
1205
- "object-src 'none'",
1206
- "form-action 'none'",
1207
- "frame-ancestors 'self'"
1208
- ].join("; ");
1196
+ var POLICY_ORIGIN = new RegExp(`^https?://${HOST}${PORT}$`, "u");
1197
+ function isMcpAppPolicyOrigin2(value) {
1198
+ try {
1199
+ return POLICY_ORIGIN.test(value) && new URL(value).origin === value;
1200
+ } catch {
1201
+ return false;
1202
+ }
1203
+ }
1204
+ function ownHosts({
1205
+ frameAncestors,
1206
+ sandboxOrigin
1207
+ }) {
1208
+ const origins = [...frameAncestors, sandboxOrigin];
1209
+ const invalid = origins.find((origin) => !isMcpAppPolicyOrigin2(origin));
1210
+ if (invalid !== undefined)
1211
+ throw new Error(`Not an exact origin a sandbox policy can name: ${invalid}`);
1212
+ if (frameAncestors.includes(sandboxOrigin))
1213
+ throw new Error(`The sandbox origin is one of the host's: ${sandboxOrigin}`);
1214
+ return new Set(origins.map((origin) => new URL(origin).host));
1215
+ }
1216
+ function namesHost(domain, hosts) {
1217
+ try {
1218
+ return hosts.has(new URL(domain).host);
1219
+ } catch {
1220
+ return false;
1221
+ }
1222
+ }
1223
+ var CSP_LISTS = McpUiCspSchema2.keyof().options;
1224
+ function appliedMcpAppCsp2({
1225
+ csp,
1226
+ ...origins
1227
+ }) {
1228
+ const own = ownHosts(origins);
1229
+ const applied = {};
1230
+ for (const list of CSP_LISTS) {
1231
+ const domains = new Set((csp?.[list] ?? []).filter((domain) => isMcpAppCspDomain2(list, domain)).map((domain) => domain.toLowerCase()).filter((domain) => !namesHost(domain, own)));
1232
+ if (domains.size > 0)
1233
+ applied[list] = [...domains];
1234
+ }
1235
+ return Object.keys(applied).length > 0 ? applied : undefined;
1236
+ }
1237
+ function policyFileLocation(value, origins) {
1238
+ try {
1239
+ const url = new URL(value);
1240
+ if (!["http:", "https:"].includes(url.protocol) || !origins.includes(url.origin) || url.pathname.endsWith("/"))
1241
+ return;
1242
+ const path = url.pathname.split("/").map((segment) => encodeURIComponent(decodeURIComponent(segment)).replaceAll("'", "%27")).join("/");
1243
+ return `${url.origin}${path}`;
1244
+ } catch {
1245
+ return;
1246
+ }
1247
+ }
1248
+ var sources = (base, domains = []) => [...base, ...domains].join(" ") || "'none'";
1249
+ function mcpAppSandboxPolicy2({
1250
+ fileLocations = [],
1251
+ ...view
1252
+ }) {
1253
+ const applied = appliedMcpAppCsp2(view) ?? {};
1254
+ const files = fileLocations.flatMap((location) => policyFileLocation(location, view.frameAncestors) ?? []);
1255
+ const resource = applied.resourceDomains ?? [];
1256
+ return [
1257
+ "default-src 'none'",
1258
+ `script-src ${sources(["'self'", "'unsafe-inline'", "'wasm-unsafe-eval'"], resource)}`,
1259
+ `style-src ${sources(["'self'", "'unsafe-inline'"], resource)}`,
1260
+ `img-src ${sources(["'self'", "data:"], resource)}`,
1261
+ `font-src ${sources(["'self'", "data:"], resource)}`,
1262
+ `media-src ${sources(["'self'", "data:"], [...resource, ...files])}`,
1263
+ `connect-src ${sources(applied.connectDomains ?? [], files)}`,
1264
+ "worker-src 'self' blob: data:",
1265
+ `frame-src ${sources([], applied.frameDomains)}`,
1266
+ `base-uri ${sources([], applied.baseUriDomains)}`,
1267
+ "object-src 'none'",
1268
+ "form-action 'none'",
1269
+ `frame-ancestors ${sources([], view.frameAncestors)}`
1270
+ ].join("; ");
1271
+ }
1209
1272
 
1210
- export { SESSION_CATALOG_MAX_WINDOW2, RuntimeAuthStateSchema2, OperationCapabilitySchema2, RuntimeInfoSchema2, AgentAvatarSchema2, AgentCatalogEntrySchema2, AgentCatalogResponseSchema2, AgentUpdateFields2, writesAgentField2, AgentUpdateRequestSchema2, AgentUpdateResponseSchema2, SessionStatusSchema2, SessionPlatformSchema2, SessionSchema2, newestSessionFirst2, SessionCatalogResponseSchema2, StopReason2, ToolKind2, ToolLocationSchema2, DiffOperation2, DiffChangeSchema2, ToolDiffSchema2, SessionMessageErrorStatusSchema2, SessionMessageSchema2, SessionPlanActivityMessageSchema2, SessionCompactionActivityMessageSchema2, SessionChildActivityMessageSchema2, SessionActivityMessageSchema2, SessionHistoryResponseSchema2, SessionCreateRequestSchema2, SessionCreateResponseSchema2, SessionPatchRequestSchema2, TurnStopResponseSchema2, TurnSteerRequestSchema2, TurnSteerResponseSchema2, SlashCommandSchema2, MAX_SLASH_COMMANDS2, INTERACTION_PROTOCOL2, SessionWorkspaceCapabilitiesResponseSchema2, GuestRuntimeCapabilitiesResponseSchema2, SessionModelsResponseSchema2, SessionModelUpdateRequestSchema2, SessionModelUpdateResponseSchema2, SessionContextResponseSchema2, ArtifactDescriptorSchema2, SessionTodosResponseSchema2, SessionActivityResponseSchema2, SessionAttachmentStageRequestSchema2, SessionAttachmentStageResponseSchema2, SessionAudioResponseSchema2, SessionTranscriptionRequestSchema2, SessionTranscriptionResponseSchema2, SessionSpeechRequestSchema2, ErrorResponseSchema2, ACP_PROTOCOL_VERSION2, HGW_API_PREFIX2, HGW_ACP_PATH2, HGW_ACP_AGENTS_PATH2, hgwAcpAgentPath2, HGW_META_KEY2, HGW_EXTENSION_VERSION2, HGW_AUTH_METHOD_INVITE2, HGW_ATTACHMENT_URI_SCHEME2, HGW_ARTIFACT_URI_SCHEME2, HGW_METHODS2, HGW_PERMISSION_KIND_SESSION2, HGW_PLAN_ID2, HGW_JSONRPC_ERRORS2, HGW_MAX_FRAME_BYTES2, IdentifierSchema2, HgwExtensionsSchema2, HgwClientCapabilitiesMetaSchema2, HgwInitializeMetaSchema2, HgwLoginMetaSchema2, HgwSessionNewMetaSchema2, HgwSessionListMetaSchema2, HgwSessionSearchMetaSchema2, HgwSessionSearchResponseSchema2, HgwSessionInfoMetaSchema2, HgwSessionResumeMetaSchema2, HGW_REPLAY_POSITION2, HgwReplayPositionSchema2, HGW_REPLAY_BEFORE2, HgwReplayBeforeSchema2, HgwHistoryCursorSchema2, HgwHistoryPageResponseMetaSchema2, HgwHistoryPageTagSchema2, HgwSessionResumeResponseMetaSchema2, HgwPromptMetaSchema2, HgwSessionUpdateRequestSchema2, HgwSessionPartRequestSchema2, HgwSteerRequestSchema2, HgwSteerResponseSchema2, HgwFocusRequestSchema2, HgwAgentsListResponseSchema2, HgwAgentUpdateRequestSchema2, HgwAgentUpdateResponseSchema2, HgwTurnMetaSchema2, HgwNoticeMetaSchema2, HgwMessageMetaSchema2, HgwCostSchema2, HgwChildSessionMetaSchema2, HgwStateMetaSchema2, HgwChunkMetaSchema2, HgwToolCallMetaSchema2, HgwPlanMetaSchema2, HgwUsageMetaSchema2, HgwAvailableCommandsMetaSchema2, HgwPermissionMetaSchema2, HgwQuestionOptionSchema2, HgwQuestionSchema2, HgwElicitationMetaSchema2, HgwArtifactDescriptorSchema2, formatArtifactUri2, parseArtifactUri2, HgwComposerPrefillNotificationSchema2, HgwErrorNotificationSchema2, HGW_REQUEST_TEXT_MAX2, HgwActivityNotificationSchema2, PushCategorySchema2, categoryOf2, PushLocaleSchema2, PRESENCE_IDLE_MS2, PRESENCE_HEARTBEAT_MS2, PRESENCE_GRACE_MS2, PRESENCE_CLOSED_GRACE_MS2, COALESCE_WINDOW_MS2, PUSH_TEXT_LIMITS2, PushMessageSchema2, PushCategoriesSchema2, PushSubscriptionJsonSchema2, PushInfoSchema2, PushRegistrationSchema2, PushUnregistrationSchema2, CallToolResultSchema2, ReadResourceResultSchema2, McpUiCspSchema2, isMcpAppCspDomain2, McpUiPermissionsSchema2, McpAppFilesSchema2, McpAppViewSchema2, viewerFileResult2, McpAppToolCallRequestSchema2, McpAppResourceReadRequestSchema2, MCP_APP_SANDBOX_PATH2, MCP_APP_SANDBOX_CSP2 };
1273
+ export { SESSION_CATALOG_MAX_WINDOW2, RuntimeAuthStateSchema2, OperationCapabilitySchema2, RuntimeInfoSchema2, AgentAvatarSchema2, AgentCatalogEntrySchema2, AgentCatalogResponseSchema2, AgentUpdateFields2, writesAgentField2, AgentUpdateRequestSchema2, AgentUpdateResponseSchema2, SessionStatusSchema2, SessionPlatformSchema2, SessionSchema2, newestSessionFirst2, SessionCatalogResponseSchema2, StopReason2, ToolKind2, ToolLocationSchema2, DiffOperation2, DiffChangeSchema2, ToolDiffSchema2, SessionMessageErrorStatusSchema2, SessionMessageSchema2, SessionPlanActivityMessageSchema2, SessionCompactionActivityMessageSchema2, SessionChildActivityMessageSchema2, SessionActivityMessageSchema2, SessionHistoryResponseSchema2, SessionCreateRequestSchema2, SessionCreateResponseSchema2, SessionPatchRequestSchema2, TurnStopResponseSchema2, TurnSteerRequestSchema2, TurnSteerResponseSchema2, SlashCommandSchema2, MAX_SLASH_COMMANDS2, INTERACTION_PROTOCOL2, SessionWorkspaceCapabilitiesResponseSchema2, GuestRuntimeCapabilitiesResponseSchema2, SessionModelsResponseSchema2, SessionModelUpdateRequestSchema2, SessionModelUpdateResponseSchema2, SessionContextResponseSchema2, ArtifactDescriptorSchema2, SessionTodosResponseSchema2, SessionActivityResponseSchema2, SessionAttachmentStageRequestSchema2, SessionAttachmentStageResponseSchema2, SessionAudioResponseSchema2, SessionTranscriptionRequestSchema2, SessionTranscriptionResponseSchema2, SessionSpeechRequestSchema2, ErrorResponseSchema2, ACP_PROTOCOL_VERSION2, HGW_API_PREFIX2, HGW_ACP_PATH2, HGW_ACP_AGENTS_PATH2, hgwAcpAgentPath2, HGW_META_KEY2, HGW_EXTENSION_VERSION2, HGW_AUTH_METHOD_INVITE2, HGW_ATTACHMENT_URI_SCHEME2, HGW_ARTIFACT_URI_SCHEME2, HGW_METHODS2, HGW_PERMISSION_KIND_SESSION2, HGW_PLAN_ID2, HGW_JSONRPC_ERRORS2, HGW_MAX_FRAME_BYTES2, IdentifierSchema2, HgwExtensionsSchema2, HgwClientCapabilitiesMetaSchema2, HgwInitializeMetaSchema2, HgwLoginMetaSchema2, HgwSessionNewMetaSchema2, HgwSessionListMetaSchema2, HgwSessionSearchMetaSchema2, HgwSessionSearchResponseSchema2, HgwSessionInfoMetaSchema2, HgwSessionResumeMetaSchema2, HGW_REPLAY_POSITION2, HgwReplayPositionSchema2, HGW_REPLAY_BEFORE2, HgwReplayBeforeSchema2, HgwHistoryCursorSchema2, HgwHistoryPageResponseMetaSchema2, HgwHistoryPageTagSchema2, HgwSessionResumeResponseMetaSchema2, HgwPromptMetaSchema2, HgwSessionUpdateRequestSchema2, HgwSessionPartRequestSchema2, HgwSteerRequestSchema2, HgwSteerResponseSchema2, HgwFocusRequestSchema2, HgwAgentsListResponseSchema2, HgwAgentUpdateRequestSchema2, HgwAgentUpdateResponseSchema2, HgwTurnMetaSchema2, HgwNoticeMetaSchema2, HgwMessageMetaSchema2, HgwCostSchema2, HgwChildSessionMetaSchema2, HgwStateMetaSchema2, HgwChunkMetaSchema2, HgwToolCallMetaSchema2, HgwPlanMetaSchema2, HgwUsageMetaSchema2, HgwAvailableCommandsMetaSchema2, HgwPermissionMetaSchema2, HgwQuestionOptionSchema2, HgwQuestionSchema2, HgwElicitationMetaSchema2, HgwArtifactDescriptorSchema2, formatArtifactUri2, parseArtifactUri2, HgwComposerPrefillNotificationSchema2, HgwErrorNotificationSchema2, HGW_REQUEST_TEXT_MAX2, HgwActivityNotificationSchema2, PushCategorySchema2, categoryOf2, PushLocaleSchema2, PRESENCE_IDLE_MS2, PRESENCE_HEARTBEAT_MS2, PRESENCE_GRACE_MS2, PRESENCE_CLOSED_GRACE_MS2, COALESCE_WINDOW_MS2, PUSH_TEXT_LIMITS2, PushMessageSchema2, PushCategoriesSchema2, PushSubscriptionJsonSchema2, PushInfoSchema2, PushRegistrationSchema2, PushUnregistrationSchema2, CallToolResultSchema2, ReadResourceResultSchema2, McpUiCspSchema2, isMcpAppCspDomain2, McpUiPermissionsSchema2, McpAppFilesSchema2, McpUiDomainSchema2, McpAppViewSchema2, viewerFileResult2, McpAppToolCallRequestSchema2, McpAppResourceReadRequestSchema2, MCP_APP_SANDBOX_PATH2, isMcpAppPolicyOrigin2, appliedMcpAppCsp2, mcpAppSandboxPolicy2 };
@@ -199,6 +199,7 @@ export declare class HgwRemoteClient {
199
199
  clipboardWrite?: Record<string, never> | undefined;
200
200
  } | undefined;
201
201
  prefersBorder?: boolean | undefined;
202
+ domain?: string | undefined;
202
203
  toolInput?: Record<string, unknown> | undefined;
203
204
  toolResult?: {
204
205
  [x: string]: unknown;
@@ -43,6 +43,13 @@ export declare const McpAppFilesSchema: z.ZodObject<{
43
43
  expiresAt: z.ZodOptional<z.ZodISODateTime>;
44
44
  }, z.core.$strict>;
45
45
  export type McpAppFiles = z.infer<typeof McpAppFilesSchema>;
46
+ /**
47
+ * A UI resource's `_meta.ui.domain`: the lowercase host name its view asks to
48
+ * run on, a stable origin of its own. The format is the host's; the gateway
49
+ * passes one on only when its first label is `mcpAppStableOriginKey`
50
+ * (`@harness-gw/sdk/node`) of the URL it dialed the view's server at.
51
+ */
52
+ export declare const McpUiDomainSchema: z.ZodString;
46
53
  /** `GET` an MCP App view: its HTML, sandbox policy, and the call it renders. */
47
54
  export declare const McpAppViewSchema: z.ZodObject<{
48
55
  html: z.ZodString;
@@ -59,6 +66,7 @@ export declare const McpAppViewSchema: z.ZodObject<{
59
66
  clipboardWrite: z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
60
67
  }, z.core.$strip>>;
61
68
  prefersBorder: z.ZodOptional<z.ZodBoolean>;
69
+ domain: z.ZodOptional<z.ZodString>;
62
70
  toolInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
63
71
  toolResult: z.ZodOptional<z.ZodObject<{
64
72
  _meta: z.ZodOptional<z.ZodObject<{
@@ -176,17 +184,19 @@ export declare const McpAppViewSchema: z.ZodObject<{
176
184
  }, z.core.$strict>;
177
185
  export type McpAppView = z.infer<typeof McpAppViewSchema>;
178
186
  /**
179
- * The file a viewer App shows: the display name and type of a published
180
- * Artifact, which its view reads from `toolResult.structuredContent.value`,
181
- * and from the JSON after `Structured fallback:` in the text for a view that
182
- * reads text alone. It is the whole contract any configured viewer reads.
187
+ * The file a viewer App shows: a published Artifact's display name and type,
188
+ * and its `fileId` (`artifactFileId` of its path) when the runtime read it from
189
+ * a path. The view reads it from `toolResult.structuredContent.value`, or from
190
+ * the JSON after `Structured fallback:` in the text when it reads text alone.
191
+ * It is the whole contract any configured viewer reads.
183
192
  */
184
193
  export type ViewerFile = {
185
194
  filename: string;
186
195
  mimeType?: string;
196
+ fileId?: string;
187
197
  };
188
198
  /** A published Artifact's `toolResult`: its `ViewerFile`, as structure and as text. */
189
- export declare function viewerFileResult({ filename, mimeType, }: ViewerFile): CallToolResult;
199
+ export declare function viewerFileResult({ filename, mimeType, fileId, }: ViewerFile): CallToolResult;
190
200
  /** A view's `tools/call`, answered with a `CallToolResult`. */
191
201
  export declare const McpAppToolCallRequestSchema: z.ZodObject<{
192
202
  name: z.ZodString;
@@ -199,13 +209,57 @@ export declare const McpAppResourceReadRequestSchema: z.ZodObject<{
199
209
  }, z.core.$strict>;
200
210
  export type McpAppResourceReadRequest = z.infer<typeof McpAppResourceReadRequestSchema>;
201
211
  /**
202
- * The MCP App sandbox gateway: a static page, served beside the workspace on
203
- * every listener, that holds only the relay creating the App's own frame. It
204
- * is a real document rather than `srcdoc` so it carries this policy instead of
205
- * inheriting the embedding page's, which on the guest surface forbids inline
206
- * scripts. The App frame inherits it too, so it is the widest any view may
207
- * reach — every source `buildMcpAppCsp` can grant — and the view's own policy,
208
- * injected into its document, narrows it to what it declared.
212
+ * The MCP App sandbox page: a static page that holds only the relay creating
213
+ * the App's own frame. A host serves it from a sandbox origin of its own,
214
+ * apart from its pages' origins as the spec requires, and frames it with
215
+ * `allow-scripts allow-same-origin`, so the view runs on that origin with
216
+ * storage of its own. The page is a real document rather than `srcdoc` so it
217
+ * carries the view's own policy, `mcpAppSandboxPolicy`, as its header; the
218
+ * view's `srcdoc` frame inherits it.
209
219
  */
210
220
  export declare const MCP_APP_SANDBOX_PATH = "/mcp-app-sandbox.html";
211
- export declare const MCP_APP_SANDBOX_CSP: string;
221
+ /** What one view's sandbox policy is built from. */
222
+ export type McpAppSandboxPolicyInput = {
223
+ /**
224
+ * The exact origins of the host's own pages, the only ones that may frame
225
+ * the sandbox page.
226
+ */
227
+ frameAncestors: readonly string[];
228
+ /** The exact origin the sandbox page is served from. */
229
+ sandboxOrigin: string;
230
+ /** The view's declared `_meta.ui.csp`. */
231
+ csp?: McpUiCsp | undefined;
232
+ /** The call's absolute file addresses; no pass is written. */
233
+ fileLocations?: readonly string[] | undefined;
234
+ };
235
+ /**
236
+ * Whether a sandbox policy can name `value` as a framing page or as the
237
+ * sandbox: an `http(s)` origin exactly as `URL` writes it, whose host is a name
238
+ * or an IPv4 address. `mcpAppSandboxPolicy` throws for any other, so a host
239
+ * checks its settings with this once, before it serves a view.
240
+ */
241
+ export declare function isMcpAppPolicyOrigin(value: string): boolean;
242
+ /**
243
+ * The domains a view's sandbox policy applies, per `_meta.ui.csp` list, as a
244
+ * host reports them in `hostCapabilities.sandbox.csp`: those
245
+ * `isMcpAppCspDomain` admits, lowercased and once each, without any that names
246
+ * the host and port of a framing page or of the sandbox itself, whatever its
247
+ * scheme. `undefined` when it applies none. Throws as `mcpAppSandboxPolicy`
248
+ * does for the origins.
249
+ */
250
+ export declare function appliedMcpAppCsp({ csp, ...origins }: Omit<McpAppSandboxPolicyInput, "fileLocations">): McpUiCsp | undefined;
251
+ /**
252
+ * One view's sandbox policy, sent as the sandbox page's header: the MCP Apps
253
+ * default policy (spec 2026-01-26), widened only by the domains
254
+ * `appliedMcpAppCsp` keeps and by the call's own file locations, each by its
255
+ * exact path, to read and to play; never allowing plugins or form posts, and
256
+ * framed only by `frameAncestors`. Views may compile WebAssembly, as a
257
+ * document renderer's decoders do.
258
+ *
259
+ * Anyone can ask for a sandbox page with any query, so every value is checked
260
+ * before it is written: an ancestor or a sandbox origin that is no exact
261
+ * origin (`isMcpAppPolicyOrigin`) throws, as does a sandbox origin among the
262
+ * ancestors, and a domain or a file location its rule refuses is dropped. A
263
+ * file location is kept only on a framing page's origin.
264
+ */
265
+ export declare function mcpAppSandboxPolicy({ fileLocations, ...view }: McpAppSandboxPolicyInput): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A URL as the gateway keeps it: its WHATWG serialization with no trailing
3
+ * slash, so `HTTPS://Example.com:443/mcp/` reads as `https://example.com/mcp`.
4
+ * Throws for anything that is no URL.
5
+ */
6
+ export declare function canonicalUrl(url: string | URL): string;
7
+ /**
8
+ * The first label of an MCP App view's stable origin (`_meta.ui.domain`): the
9
+ * first 32 hex digits of a SHA-256 of the MCP server's URL the gateway dials,
10
+ * in its `canonicalUrl` form; for a URL already in that form, such as
11
+ * `https://example.com/mcp`, Claude's published format. A server declares
12
+ * `<key>.<the host's domain>`; the gateway keeps that `domain` only when its
13
+ * first label is this key of the URL it dialed, however either wrote it.
14
+ */
15
+ export declare function mcpAppStableOriginKey(url: string): string;
16
+ /**
17
+ * A file's identity in a viewer's result: the first 16 hex digits of a
18
+ * SHA-256 of its normalized POSIX path. However a file is shown, it carries
19
+ * the same `fileId`, and the result never carries the path.
20
+ */
21
+ export declare function artifactFileId(path: string): string;
@@ -0,0 +1,18 @@
1
+ // protocol/node.ts
2
+ import { createHash } from "node:crypto";
3
+ import { posix } from "node:path";
4
+ var sha256Hex = (value) => createHash("sha256").update(value).digest("hex");
5
+ function canonicalUrl(url) {
6
+ return new URL(url).href.replace(/\/$/u, "");
7
+ }
8
+ function mcpAppStableOriginKey(url) {
9
+ return sha256Hex(canonicalUrl(url)).slice(0, 32);
10
+ }
11
+ function artifactFileId(path) {
12
+ return sha256Hex(posix.normalize(path)).slice(0, 16);
13
+ }
14
+ export {
15
+ artifactFileId,
16
+ canonicalUrl,
17
+ mcpAppStableOriginKey
18
+ };
@@ -139,12 +139,15 @@ import {
139
139
  isMcpAppCspDomain2,
140
140
  McpUiPermissionsSchema2,
141
141
  McpAppFilesSchema2,
142
+ McpUiDomainSchema2,
142
143
  McpAppViewSchema2,
143
144
  viewerFileResult2,
144
145
  McpAppToolCallRequestSchema2,
145
146
  McpAppResourceReadRequestSchema2,
146
147
  MCP_APP_SANDBOX_PATH2,
147
- MCP_APP_SANDBOX_CSP2
148
+ isMcpAppPolicyOrigin2,
149
+ appliedMcpAppCsp2,
150
+ mcpAppSandboxPolicy2
148
151
  } from "../chunks/index.js";
149
152
  // protocol/audio.ts
150
153
  var RECORDING_MIME_TYPES = [
@@ -278,13 +281,13 @@ export {
278
281
  MAX_SPEECH_BYTES,
279
282
  MAX_SPEECH_TEXT_BYTES,
280
283
  MAX_TRANSCRIPT_BYTES,
281
- MCP_APP_SANDBOX_CSP2 as MCP_APP_SANDBOX_CSP,
282
284
  MCP_APP_SANDBOX_PATH2 as MCP_APP_SANDBOX_PATH,
283
285
  McpAppFilesSchema2 as McpAppFilesSchema,
284
286
  McpAppResourceReadRequestSchema2 as McpAppResourceReadRequestSchema,
285
287
  McpAppToolCallRequestSchema2 as McpAppToolCallRequestSchema,
286
288
  McpAppViewSchema2 as McpAppViewSchema,
287
289
  McpUiCspSchema2 as McpUiCspSchema,
290
+ McpUiDomainSchema2 as McpUiDomainSchema,
288
291
  McpUiPermissionsSchema2 as McpUiPermissionsSchema,
289
292
  OperationCapabilitySchema2 as OperationCapabilitySchema,
290
293
  PRESENCE_CLOSED_GRACE_MS2 as PRESENCE_CLOSED_GRACE_MS,
@@ -342,10 +345,13 @@ export {
342
345
  TurnSteerRequestSchema2 as TurnSteerRequestSchema,
343
346
  TurnSteerResponseSchema2 as TurnSteerResponseSchema,
344
347
  TurnStopResponseSchema2 as TurnStopResponseSchema,
348
+ appliedMcpAppCsp2 as appliedMcpAppCsp,
345
349
  categoryOf2 as categoryOf,
346
350
  formatArtifactUri2 as formatArtifactUri,
347
351
  hgwAcpAgentPath2 as hgwAcpAgentPath,
348
352
  isMcpAppCspDomain2 as isMcpAppCspDomain,
353
+ isMcpAppPolicyOrigin2 as isMcpAppPolicyOrigin,
354
+ mcpAppSandboxPolicy2 as mcpAppSandboxPolicy,
349
355
  newestSessionFirst2 as newestSessionFirst,
350
356
  parseArtifactUri2 as parseArtifactUri,
351
357
  parseRecordingMime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harness-gw/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "A gateway that puts Hermes, OpenClaw, and OpenCode behind one ACP WebSocket, and the browser client and protocol SDK for it.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -13,6 +13,10 @@
13
13
  "./protocol": {
14
14
  "types": "./dist/protocol/sdk.d.ts",
15
15
  "import": "./dist/protocol/sdk.js"
16
+ },
17
+ "./node": {
18
+ "types": "./dist/protocol/node.d.ts",
19
+ "import": "./dist/protocol/node.js"
16
20
  }
17
21
  },
18
22
  "files": [
@@ -35,7 +39,7 @@
35
39
  "test:gate": "vitest run --project gate",
36
40
  "test:bun": "bun test ./src/cli.bun-spec.ts ./src/server.bun-spec.ts ./src/shutdown.bun-spec.ts",
37
41
  "test:watch": "vitest --project !gate",
38
- "build": "rm -rf dist && bun build client/index.ts protocol/sdk.ts --root . --outdir dist --splitting --format esm --target browser --packages external --chunk-naming 'chunks/[name].[ext]' && tsc -p tsconfig.build.json && bun scripts/declaration-extensions.mjs dist"
42
+ "build": "rm -rf dist && bun build client/index.ts protocol/sdk.ts --root . --outdir dist --splitting --format esm --target browser --packages external --chunk-naming 'chunks/[name].[ext]' && bun build protocol/node.ts --root . --outdir dist --format esm --target node --packages external && tsc -p tsconfig.build.json && bun scripts/declaration-extensions.mjs dist"
39
43
  },
40
44
  "dependencies": {
41
45
  "cockatiel": "4.0.0",