@harness-gw/sdk 0.12.0 → 0.14.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.
@@ -128,15 +128,15 @@ export declare function createAcpWorkspaceClient({ connection, rest, agentIdFor,
128
128
  workspaceCapabilities: (sessionId: string) => {
129
129
  workspace: {
130
130
  slashCommands: {
131
+ status: "unavailable";
132
+ reason: string;
133
+ } | {
131
134
  status: "available";
132
135
  scope: "session";
133
136
  commands: {
134
137
  name: string;
135
138
  description?: string | undefined;
136
139
  }[];
137
- } | {
138
- status: "unavailable";
139
- reason: string;
140
140
  };
141
141
  models: {
142
142
  status: "unavailable";
@@ -1,7 +1,7 @@
1
1
  import type { z } from "zod";
2
2
  import { SessionContextResponseSchema, SessionModelsResponseSchema, SessionWorkspaceCapabilitiesResponseSchema } from "../protocol/index.js";
3
3
  import { type PushRegistration } from "../protocol/push.js";
4
- import { type McpAppResourceReadRequest, type McpAppToolCallRequest } from "../protocol/mcp-apps.js";
4
+ import { type McpAppFileReadFailure, type McpAppResourceReadRequest, type McpAppToolCallRequest } from "../protocol/mcp-apps.js";
5
5
  import type { StagedAttachment } from "./workspace.js";
6
6
  export type HgwWorkspaceCapabilities = z.infer<typeof SessionWorkspaceCapabilitiesResponseSchema>;
7
7
  export type HgwModelChoices = z.infer<typeof SessionModelsResponseSchema>;
@@ -24,6 +24,14 @@ export declare class HgwClientError extends Error {
24
24
  /** The gateway's HTTP status, when it answered. */
25
25
  status?: number | undefined);
26
26
  }
27
+ /**
28
+ * A view's read of its own file address failed: `reason` says why, as the
29
+ * gateway answered it.
30
+ */
31
+ export declare class McpAppFileReadError extends HgwClientError {
32
+ readonly reason: McpAppFileReadFailure;
33
+ constructor(reason: McpAppFileReadFailure, ...failure: ConstructorParameters<typeof HgwClientError>);
34
+ }
27
35
  /** The `fetch` the client sends every request with. */
28
36
  export type Fetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
29
37
  export type HgwRemoteClientOptions = {
@@ -199,6 +207,7 @@ export declare class HgwRemoteClient {
199
207
  clipboardWrite?: Record<string, never> | undefined;
200
208
  } | undefined;
201
209
  prefersBorder?: boolean | undefined;
210
+ domain?: string | undefined;
202
211
  toolInput?: Record<string, unknown> | undefined;
203
212
  toolResult?: {
204
213
  [x: string]: unknown;
@@ -395,7 +404,11 @@ export declare class HgwRemoteClient {
395
404
  structuredContent?: unknown;
396
405
  isError?: boolean | undefined;
397
406
  }>;
398
- /** A resource read the App view makes, answered by the gateway's MCP server. */
407
+ /**
408
+ * A resource read the App view makes, answered by the gateway's MCP server:
409
+ * one of its `ui://` resources, or one of the view's own file addresses,
410
+ * whose failure rejects as `McpAppFileReadError`.
411
+ */
399
412
  readMcpAppResource(sessionId: string, subject: McpAppSubject, request: McpAppResourceReadRequest): Promise<{
400
413
  [x: string]: unknown;
401
414
  _meta?: {
@@ -1,4 +1,10 @@
1
1
  import {
2
+ CallToolResultSchema2,
3
+ ReadResourceResultSchema2,
4
+ McpAppFilesSchema2,
5
+ McpAppViewSchema2,
6
+ McpAppToolCallRequestSchema2,
7
+ McpAppResourceReadRequestSchema2,
2
8
  RuntimeInfoSchema2,
3
9
  SessionAttachmentStageRequestSchema2,
4
10
  SessionAttachmentStageResponseSchema2,
@@ -37,13 +43,7 @@ import {
37
43
  HgwErrorNotificationSchema2,
38
44
  HgwActivityNotificationSchema2,
39
45
  PushInfoSchema2,
40
- PushUnregistrationSchema2,
41
- CallToolResultSchema2,
42
- ReadResourceResultSchema2,
43
- McpAppFilesSchema2,
44
- McpAppViewSchema2,
45
- McpAppToolCallRequestSchema2,
46
- McpAppResourceReadRequestSchema2
46
+ PushUnregistrationSchema2
47
47
  } from "../chunks/index.js";
48
48
 
49
49
  // client/connection.ts
@@ -2497,6 +2497,15 @@ class HgwClientError extends Error {
2497
2497
  this.name = "HgwClientError";
2498
2498
  }
2499
2499
  }
2500
+
2501
+ class McpAppFileReadError extends HgwClientError {
2502
+ reason;
2503
+ constructor(reason, ...failure) {
2504
+ super(...failure);
2505
+ this.reason = reason;
2506
+ this.name = "McpAppFileReadError";
2507
+ }
2508
+ }
2500
2509
  async function normalizedError(response) {
2501
2510
  const parsed = ErrorResponseSchema2.safeParse(await response.json().catch(() => {
2502
2511
  return;
@@ -2540,7 +2549,13 @@ class HgwRemoteClient {
2540
2549
  }
2541
2550
  if (!response.ok) {
2542
2551
  const error = await normalizedError(response);
2543
- throw new HgwClientError(response.status === 503 ? "provider-unavailable" : response.status === 404 ? notFound : "gateway-failure", error?.description, error?.code, response.status);
2552
+ const failure = [
2553
+ response.status === 503 ? "provider-unavailable" : response.status === 404 ? notFound : "gateway-failure",
2554
+ error?.description,
2555
+ error?.code,
2556
+ response.status
2557
+ ];
2558
+ throw error?.reason ? new McpAppFileReadError(error.reason, ...failure) : new HgwClientError(...failure);
2544
2559
  }
2545
2560
  let payload;
2546
2561
  try {
@@ -2736,6 +2751,7 @@ export {
2736
2751
  AgentUpdateError,
2737
2752
  HgwClientError,
2738
2753
  HgwRemoteClient,
2754
+ McpAppFileReadError,
2739
2755
  PART_GRACE_MS,
2740
2756
  SILENT_LOGGER,
2741
2757
  acpDebugEnabled,
@@ -1357,6 +1357,12 @@ export declare const ErrorResponseSchema: z.ZodObject<{
1357
1357
  unsupported: "unsupported";
1358
1358
  }>;
1359
1359
  description: z.ZodString;
1360
+ reason: z.ZodOptional<z.ZodEnum<{
1361
+ denied: "denied";
1362
+ tooLarge: "tooLarge";
1363
+ unavailable: "unavailable";
1364
+ unreachable: "unreachable";
1365
+ }>>;
1360
1366
  }, z.core.$strict>;
1361
1367
  }, z.core.$strict>;
1362
1368
  export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
@@ -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,28 +184,67 @@ 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;
193
203
  arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
194
204
  }, z.core.$strict>;
195
205
  export type McpAppToolCallRequest = z.infer<typeof McpAppToolCallRequestSchema>;
196
- /** A view's `resources/read`, answered with a `ReadResourceResult`. */
206
+ /**
207
+ * A view's `resources/read`, answered with a `ReadResourceResult`: one of its
208
+ * server's `ui://` resources, or one of the view's own file addresses, which
209
+ * the gateway forwards to that server to read.
210
+ */
197
211
  export declare const McpAppResourceReadRequestSchema: z.ZodObject<{
198
212
  uri: z.ZodString;
199
213
  }, z.core.$strict>;
200
214
  export type McpAppResourceReadRequest = z.infer<typeof McpAppResourceReadRequestSchema>;
215
+ /**
216
+ * The most file content a view's read of its own file address answers: 64
217
+ * MiB, so a base64 `blob` of at most 4·⌈64 MiB / 3⌉ characters.
218
+ */
219
+ export declare const MAX_MCP_APP_FILE_BYTES: number;
220
+ /**
221
+ * Why a view's read of its own file address failed, as the gateway answers
222
+ * it: the file route refused the pass (`denied`), the file is past
223
+ * `MAX_MCP_APP_FILE_BYTES` (`tooLarge`), the view's server could not reach
224
+ * the file route, or the read found no turn on the listener or outlasted
225
+ * it (`unreachable`), or the gateway could not forward the read
226
+ * (`unavailable`).
227
+ */
228
+ export declare const McpAppFileReadFailureSchema: z.ZodEnum<{
229
+ denied: "denied";
230
+ tooLarge: "tooLarge";
231
+ unavailable: "unavailable";
232
+ unreachable: "unreachable";
233
+ }>;
234
+ export type McpAppFileReadFailure = z.infer<typeof McpAppFileReadFailureSchema>;
235
+ /**
236
+ * The `data` of the JSON-RPC error a view's server answers a failed file read
237
+ * with, so the gateway passes its reason on.
238
+ */
239
+ export declare const McpAppFileReadErrorDataSchema: z.ZodObject<{
240
+ reason: z.ZodEnum<{
241
+ denied: "denied";
242
+ tooLarge: "tooLarge";
243
+ unavailable: "unavailable";
244
+ unreachable: "unreachable";
245
+ }>;
246
+ }, z.core.$strip>;
247
+ export type McpAppFileReadErrorData = z.infer<typeof McpAppFileReadErrorDataSchema>;
201
248
  /**
202
249
  * The MCP App sandbox page: a static page that holds only the relay creating
203
250
  * the App's own frame. A host serves it from a sandbox origin of its own,
@@ -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
+ };
@@ -1,4 +1,22 @@
1
1
  import {
2
+ CallToolResultSchema2,
3
+ ReadResourceResultSchema2,
4
+ McpUiCspSchema2,
5
+ isMcpAppCspDomain2,
6
+ McpUiPermissionsSchema2,
7
+ McpAppFilesSchema2,
8
+ McpUiDomainSchema2,
9
+ McpAppViewSchema2,
10
+ viewerFileResult2,
11
+ McpAppToolCallRequestSchema2,
12
+ McpAppResourceReadRequestSchema2,
13
+ MAX_MCP_APP_FILE_BYTES2,
14
+ McpAppFileReadFailureSchema2,
15
+ McpAppFileReadErrorDataSchema2,
16
+ MCP_APP_SANDBOX_PATH2,
17
+ isMcpAppPolicyOrigin2,
18
+ appliedMcpAppCsp2,
19
+ mcpAppSandboxPolicy2,
2
20
  SESSION_CATALOG_MAX_WINDOW2,
3
21
  RuntimeAuthStateSchema2,
4
22
  OperationCapabilitySchema2,
@@ -132,21 +150,7 @@ import {
132
150
  PushSubscriptionJsonSchema2,
133
151
  PushInfoSchema2,
134
152
  PushRegistrationSchema2,
135
- PushUnregistrationSchema2,
136
- CallToolResultSchema2,
137
- ReadResourceResultSchema2,
138
- McpUiCspSchema2,
139
- isMcpAppCspDomain2,
140
- McpUiPermissionsSchema2,
141
- McpAppFilesSchema2,
142
- McpAppViewSchema2,
143
- viewerFileResult2,
144
- McpAppToolCallRequestSchema2,
145
- McpAppResourceReadRequestSchema2,
146
- MCP_APP_SANDBOX_PATH2,
147
- isMcpAppPolicyOrigin2,
148
- appliedMcpAppCsp2,
149
- mcpAppSandboxPolicy2
153
+ PushUnregistrationSchema2
150
154
  } from "../chunks/index.js";
151
155
  // protocol/audio.ts
152
156
  var RECORDING_MIME_TYPES = [
@@ -275,17 +279,21 @@ export {
275
279
  HgwUsageMetaSchema2 as HgwUsageMetaSchema,
276
280
  INTERACTION_PROTOCOL2 as INTERACTION_PROTOCOL,
277
281
  IdentifierSchema2 as IdentifierSchema,
282
+ MAX_MCP_APP_FILE_BYTES2 as MAX_MCP_APP_FILE_BYTES,
278
283
  MAX_RECORDING_BYTES,
279
284
  MAX_SLASH_COMMANDS2 as MAX_SLASH_COMMANDS,
280
285
  MAX_SPEECH_BYTES,
281
286
  MAX_SPEECH_TEXT_BYTES,
282
287
  MAX_TRANSCRIPT_BYTES,
283
288
  MCP_APP_SANDBOX_PATH2 as MCP_APP_SANDBOX_PATH,
289
+ McpAppFileReadErrorDataSchema2 as McpAppFileReadErrorDataSchema,
290
+ McpAppFileReadFailureSchema2 as McpAppFileReadFailureSchema,
284
291
  McpAppFilesSchema2 as McpAppFilesSchema,
285
292
  McpAppResourceReadRequestSchema2 as McpAppResourceReadRequestSchema,
286
293
  McpAppToolCallRequestSchema2 as McpAppToolCallRequestSchema,
287
294
  McpAppViewSchema2 as McpAppViewSchema,
288
295
  McpUiCspSchema2 as McpUiCspSchema,
296
+ McpUiDomainSchema2 as McpUiDomainSchema,
289
297
  McpUiPermissionsSchema2 as McpUiPermissionsSchema,
290
298
  OperationCapabilitySchema2 as OperationCapabilitySchema,
291
299
  PRESENCE_CLOSED_GRACE_MS2 as PRESENCE_CLOSED_GRACE_MS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harness-gw/sdk",
3
- "version": "0.12.0",
3
+ "version": "0.14.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",