@gethmy/mcp 2.12.0 → 2.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/dist/cli.js +303 -41
- package/dist/index.js +301 -39
- package/dist/lib/api-client.js +21 -0
- package/package.json +1 -1
- package/src/api-client.ts +101 -0
- package/src/server.ts +394 -41
package/src/server.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { basename } from "node:path";
|
|
3
4
|
import { syncFull, syncPull, syncPush } from "@harmony/memory";
|
|
@@ -67,6 +68,99 @@ import { lintTags, normalizeTags } from "./memory-tags.js";
|
|
|
67
68
|
import { onboardNewUser } from "./onboard.js";
|
|
68
69
|
import { stripSkillPreamble } from "./skills.js";
|
|
69
70
|
|
|
71
|
+
// --- Signed-upload handshake (artifacts & card attachments) ---
|
|
72
|
+
// Mirror the edge-fn caps so a too-large `filePath`/`base64Data` fails fast in
|
|
73
|
+
// the client instead of being read fully into memory and round-tripped only to
|
|
74
|
+
// be rejected server-side (closes the #345 "no size pre-check" finding). The
|
|
75
|
+
// finalize endpoint re-enforces these as the real security boundary.
|
|
76
|
+
const MAX_ARTIFACT_SIZE = 2 * 1024 * 1024; // 2 MB — keep in sync with harmony-api
|
|
77
|
+
const MAX_ATTACHMENT_SIZE = 5 * 1024 * 1024; // 5 MB — keep in sync with harmony-api
|
|
78
|
+
|
|
79
|
+
/** Decoded byte length of a base64 string, tolerating a leading `data:` URL
|
|
80
|
+
* prefix (the edge fn strips it; we strip a copy only to measure). */
|
|
81
|
+
function base64ByteLength(base64: string): number {
|
|
82
|
+
const stripped = base64.replace(/^data:[^,]*,/, "");
|
|
83
|
+
return Buffer.from(stripped, "base64").byteLength;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sha256Hex(bytes: Buffer): string {
|
|
87
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Read a local file for a direct-to-storage upload, rejecting empty and
|
|
91
|
+
* over-cap before any network round-trip. `kind` shapes the error copy. */
|
|
92
|
+
async function readFileForUpload(
|
|
93
|
+
filePath: string,
|
|
94
|
+
maxSize: number,
|
|
95
|
+
kind: "attachment" | "artifact",
|
|
96
|
+
): Promise<Buffer> {
|
|
97
|
+
const bytes = await readFile(filePath);
|
|
98
|
+
if (bytes.byteLength === 0) {
|
|
99
|
+
throw new Error(`File is empty: ${filePath}`);
|
|
100
|
+
}
|
|
101
|
+
if (bytes.byteLength > maxSize) {
|
|
102
|
+
const mb = Math.round(maxSize / (1024 * 1024));
|
|
103
|
+
throw new Error(
|
|
104
|
+
`File is ${bytes.byteLength} bytes, over the ${maxSize}-byte (${mb}MB) ${kind} limit.`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return bytes;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Enforce the exactly-one-of-scope rule shared by the artifact upload,
|
|
111
|
+
* upload-url, and finalize tools. */
|
|
112
|
+
function requireExactlyOneScope(scope: {
|
|
113
|
+
cardId?: string;
|
|
114
|
+
planId?: string;
|
|
115
|
+
workspaceId?: string;
|
|
116
|
+
}): void {
|
|
117
|
+
if (
|
|
118
|
+
[scope.cardId, scope.planId, scope.workspaceId].filter(Boolean).length !== 1
|
|
119
|
+
) {
|
|
120
|
+
throw new Error("Provide exactly one of cardId, planId, or workspaceId.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** PUT raw bytes straight to a Supabase signed upload URL (the token rides in
|
|
125
|
+
* the URL query). Used by the stdio internal handshake; the hosted server can't
|
|
126
|
+
* read local disk, so there the agent drives this PUT itself via the two-step
|
|
127
|
+
* tools. */
|
|
128
|
+
const SIGNED_UPLOAD_TIMEOUT_MS = 30_000;
|
|
129
|
+
|
|
130
|
+
async function putToSignedUrl(
|
|
131
|
+
uploadUrl: string,
|
|
132
|
+
bytes: Uint8Array,
|
|
133
|
+
contentType: string,
|
|
134
|
+
): Promise<void> {
|
|
135
|
+
let res: Response;
|
|
136
|
+
try {
|
|
137
|
+
res = await fetch(uploadUrl, {
|
|
138
|
+
method: "PUT",
|
|
139
|
+
headers: { "Content-Type": contentType },
|
|
140
|
+
// Cast around the TS 5.7 lib regression where the now-generic
|
|
141
|
+
// `Uint8Array<ArrayBufferLike>` no longer matches `BodyInit`'s
|
|
142
|
+
// `ArrayBuffer`-pinned `BufferSource`. The bytes are a valid fetch body.
|
|
143
|
+
body: bytes as unknown as BodyInit,
|
|
144
|
+
// Bound the upload so a stalled storage PUT can't hang the call
|
|
145
|
+
// indefinitely (there is no watchdog at this layer).
|
|
146
|
+
signal: AbortSignal.timeout(SIGNED_UPLOAD_TIMEOUT_MS),
|
|
147
|
+
});
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Direct storage upload timed out after ${SIGNED_UPLOAD_TIMEOUT_MS}ms.`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
throw err;
|
|
155
|
+
}
|
|
156
|
+
if (!res.ok) {
|
|
157
|
+
const detail = await res.text().catch(() => "");
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Direct storage upload failed: ${res.status}${detail ? ` — ${detail}` : ""}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
70
164
|
/**
|
|
71
165
|
* Dependencies injected into tool handlers.
|
|
72
166
|
* Allows the same handlers to be used by both stdio and remote (HTTP) transports.
|
|
@@ -665,7 +759,7 @@ export const TOOLS = {
|
|
|
665
759
|
},
|
|
666
760
|
harmony_upload_card_attachment: {
|
|
667
761
|
description:
|
|
668
|
-
"Upload a file attachment to a card (e.g. a pasted screenshot or a document). Provide the file either as `filePath` (a local path the MCP server can read — works in local/stdio mode) or as `base64Data` (raw base64 bytes — works everywhere, including remote mode). Max 5MB. Allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV. Returns the stored attachment with a short-lived signed URL.",
|
|
762
|
+
"Upload a file attachment to a card (e.g. a pasted screenshot or a document). Provide the file either as `filePath` (a local path the MCP server can read — works in local/stdio mode) or as `base64Data` (raw base64 bytes — works everywhere, including remote mode). With `filePath` the server uploads direct-to-storage (no base64 through the model context); `base64Data` is the small-file fallback. Max 5MB. Allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV. Returns the stored attachment with a short-lived signed URL. For large files on the hosted MCP server (where only base64Data works), prefer the two-step harmony_request_card_attachment_upload_url + harmony_finalize_card_attachment handshake, which keeps bytes out of the model context.",
|
|
669
763
|
inputSchema: {
|
|
670
764
|
type: "object",
|
|
671
765
|
properties: {
|
|
@@ -694,6 +788,65 @@ export const TOOLS = {
|
|
|
694
788
|
required: ["cardId"],
|
|
695
789
|
},
|
|
696
790
|
},
|
|
791
|
+
harmony_request_card_attachment_upload_url: {
|
|
792
|
+
description:
|
|
793
|
+
"Step 1 of the agent-driven card-attachment upload — use this for large files or when running against the hosted MCP server (which cannot read your local disk). Mints a one-shot signed Supabase Storage upload URL for a server-chosen path under the card. Provide cardId, fileName (with extension), the byte size, and optionally fileType. Returns { uploadUrl, token, storagePath, fileType }. Next: PUT the raw bytes straight to uploadUrl (e.g. `curl -X PUT --data-binary @file.png '<uploadUrl>'`) — no bytes pass through the model context — then call harmony_finalize_card_attachment with the returned storagePath. Max 5MB; allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV.",
|
|
794
|
+
inputSchema: {
|
|
795
|
+
type: "object",
|
|
796
|
+
properties: {
|
|
797
|
+
cardId: { type: "string", description: "Card UUID" },
|
|
798
|
+
fileName: {
|
|
799
|
+
type: "string",
|
|
800
|
+
description: "File name including extension (e.g. 'screenshot.png').",
|
|
801
|
+
},
|
|
802
|
+
fileType: {
|
|
803
|
+
type: "string",
|
|
804
|
+
description:
|
|
805
|
+
"Optional MIME type (e.g. 'image/png'). Inferred from the file extension when omitted.",
|
|
806
|
+
},
|
|
807
|
+
size: {
|
|
808
|
+
type: "number",
|
|
809
|
+
description: "File size in bytes (rejected early if over 5MB).",
|
|
810
|
+
},
|
|
811
|
+
},
|
|
812
|
+
required: ["cardId", "fileName", "size"],
|
|
813
|
+
},
|
|
814
|
+
},
|
|
815
|
+
harmony_finalize_card_attachment: {
|
|
816
|
+
description:
|
|
817
|
+
"Step 2 of the agent-driven card-attachment upload. After PUTting the bytes to the signed uploadUrl from harmony_request_card_attachment_upload_url, call this with the returned storagePath to validate and register the attachment. The server re-downloads the object and enforces size, an allowlisted content-type (magic-byte sniff, never the declared type), and — when you pass sha256 — an integrity check, deleting the object and failing on any mismatch. Returns the stored attachment with a short-lived signed URL.",
|
|
818
|
+
inputSchema: {
|
|
819
|
+
type: "object",
|
|
820
|
+
properties: {
|
|
821
|
+
cardId: { type: "string", description: "Card UUID" },
|
|
822
|
+
storagePath: {
|
|
823
|
+
type: "string",
|
|
824
|
+
description:
|
|
825
|
+
"The storagePath returned by harmony_request_card_attachment_upload_url.",
|
|
826
|
+
},
|
|
827
|
+
fileName: {
|
|
828
|
+
type: "string",
|
|
829
|
+
description: "File name including extension (e.g. 'screenshot.png').",
|
|
830
|
+
},
|
|
831
|
+
fileType: {
|
|
832
|
+
type: "string",
|
|
833
|
+
description:
|
|
834
|
+
"Optional MIME type; inferred from the extension when omitted.",
|
|
835
|
+
},
|
|
836
|
+
sha256: {
|
|
837
|
+
type: "string",
|
|
838
|
+
description:
|
|
839
|
+
"Optional hex SHA-256 of the uploaded bytes; verified against the stored object.",
|
|
840
|
+
},
|
|
841
|
+
size: {
|
|
842
|
+
type: "number",
|
|
843
|
+
description:
|
|
844
|
+
"Optional byte size (advisory; re-validated server-side).",
|
|
845
|
+
},
|
|
846
|
+
},
|
|
847
|
+
required: ["cardId", "storagePath", "fileName"],
|
|
848
|
+
},
|
|
849
|
+
},
|
|
697
850
|
harmony_classify_card: {
|
|
698
851
|
description:
|
|
699
852
|
"Classify a card with the LLM classifier: sets `intent` (plan/think/implement/review), `complexity_score` (0-10), and `model_tier` (simple/advanced/research), stamps `classified_at`, and applies the canonical type label (feature/bug/idea). Use this right after creating a card (e.g. in the `hmy-new` flow) so it's classified in-flow instead of waiting for it to surface on the web board. Idempotent — safe to re-run. Never touches the user-owned `model_override`.",
|
|
@@ -707,7 +860,7 @@ export const TOOLS = {
|
|
|
707
860
|
},
|
|
708
861
|
harmony_upload_artifact: {
|
|
709
862
|
description:
|
|
710
|
-
"Host a self-contained HTML document (e.g. a visual design draft or diagram) in Harmony and link it to a card, a plan, or a workspace. The file is stored privately and rendered in-app inside a sandboxed cross-origin iframe. Provide exactly one of cardId, planId, or workspaceId. Supply the HTML as `filePath` (a local path the MCP server can read) or `base64Data
|
|
863
|
+
"Host a self-contained HTML document (e.g. a visual design draft or diagram) in Harmony and link it to a card, a plan, or a workspace. The file is stored privately and rendered in-app inside a sandboxed cross-origin iframe. Provide exactly one of cardId, planId, or workspaceId. Supply the HTML as `filePath` (a local path the MCP server can read — uploaded direct-to-storage, no base64 through the model context) or `base64Data` (the small-file fallback). Only text/html, max 2MB. Returns the stored artifact with a short-lived signed URL; call harmony_share_artifact to mint a public link. For large files on the hosted MCP server (where only base64Data works), prefer the two-step harmony_request_artifact_upload_url + harmony_finalize_artifact handshake, which keeps bytes out of the model context.",
|
|
711
864
|
inputSchema: {
|
|
712
865
|
type: "object",
|
|
713
866
|
properties: {
|
|
@@ -736,6 +889,69 @@ export const TOOLS = {
|
|
|
736
889
|
required: [],
|
|
737
890
|
},
|
|
738
891
|
},
|
|
892
|
+
harmony_request_artifact_upload_url: {
|
|
893
|
+
description:
|
|
894
|
+
"Step 1 of the agent-driven artifact upload — use this for large files or when running against the hosted MCP server (which cannot read your local disk), instead of streaming base64 through the model context. Mints a one-shot signed Supabase Storage upload URL for a server-chosen path. Provide exactly one of cardId/planId/workspaceId, optionally a title and the byte size. Returns { uploadUrl, token, storagePath }. Next: PUT the raw HTML bytes straight to uploadUrl (e.g. `curl -X PUT --data-binary @doc.html '<uploadUrl>'`), then call harmony_finalize_artifact with the returned storagePath. Only text/html, max 2MB.",
|
|
895
|
+
inputSchema: {
|
|
896
|
+
type: "object",
|
|
897
|
+
properties: {
|
|
898
|
+
title: {
|
|
899
|
+
type: "string",
|
|
900
|
+
description:
|
|
901
|
+
"Display title (defaults to the file basename at finalize).",
|
|
902
|
+
},
|
|
903
|
+
cardId: { type: "string", description: "Link to this card (UUID)." },
|
|
904
|
+
planId: { type: "string", description: "Link to this plan (UUID)." },
|
|
905
|
+
workspaceId: {
|
|
906
|
+
type: "string",
|
|
907
|
+
description:
|
|
908
|
+
"Attach to this workspace as a standalone artifact (UUID).",
|
|
909
|
+
},
|
|
910
|
+
contentType: {
|
|
911
|
+
type: "string",
|
|
912
|
+
description: "MIME type; only 'text/html' is accepted (the default).",
|
|
913
|
+
},
|
|
914
|
+
size: {
|
|
915
|
+
type: "number",
|
|
916
|
+
description: "File size in bytes (rejected early if over 2MB).",
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
required: [],
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
harmony_finalize_artifact: {
|
|
923
|
+
description:
|
|
924
|
+
"Step 2 of the agent-driven artifact upload. After PUTting the HTML bytes to the signed uploadUrl from harmony_request_artifact_upload_url, call this with the returned storagePath to validate and register the artifact. The server re-downloads the object and enforces size, the text/html content-type (magic-byte sniff), and — when you pass sha256 — an integrity check, deleting the object and failing on any mismatch. Provide the same one of cardId/planId/workspaceId used for the upload URL. Returns the stored artifact with a short-lived signed URL; call harmony_share_artifact to mint a public link.",
|
|
925
|
+
inputSchema: {
|
|
926
|
+
type: "object",
|
|
927
|
+
properties: {
|
|
928
|
+
storagePath: {
|
|
929
|
+
type: "string",
|
|
930
|
+
description:
|
|
931
|
+
"The storagePath returned by harmony_request_artifact_upload_url.",
|
|
932
|
+
},
|
|
933
|
+
title: { type: "string", description: "Display title." },
|
|
934
|
+
cardId: { type: "string", description: "Link to this card (UUID)." },
|
|
935
|
+
planId: { type: "string", description: "Link to this plan (UUID)." },
|
|
936
|
+
workspaceId: {
|
|
937
|
+
type: "string",
|
|
938
|
+
description:
|
|
939
|
+
"Attach to this workspace as a standalone artifact (UUID).",
|
|
940
|
+
},
|
|
941
|
+
sha256: {
|
|
942
|
+
type: "string",
|
|
943
|
+
description:
|
|
944
|
+
"Optional hex SHA-256 of the uploaded bytes; verified against the stored object.",
|
|
945
|
+
},
|
|
946
|
+
size: {
|
|
947
|
+
type: "number",
|
|
948
|
+
description:
|
|
949
|
+
"Optional byte size (advisory; re-validated server-side).",
|
|
950
|
+
},
|
|
951
|
+
},
|
|
952
|
+
required: ["storagePath"],
|
|
953
|
+
},
|
|
954
|
+
},
|
|
739
955
|
harmony_share_artifact: {
|
|
740
956
|
description:
|
|
741
957
|
"Create a public, unauthenticated share link for a hosted artifact. Anyone with the link can view the rendered HTML without a Harmony account. Returns the share token and the full public URL.",
|
|
@@ -2690,7 +2906,7 @@ async function handleToolCall(
|
|
|
2690
2906
|
args.filePath != null ? z.string().parse(args.filePath) : undefined;
|
|
2691
2907
|
const base64Data =
|
|
2692
2908
|
args.base64Data != null ? z.string().parse(args.base64Data) : undefined;
|
|
2693
|
-
|
|
2909
|
+
const fileName =
|
|
2694
2910
|
args.fileName != null ? z.string().parse(args.fileName) : undefined;
|
|
2695
2911
|
const contentType =
|
|
2696
2912
|
args.contentType != null
|
|
@@ -2701,29 +2917,51 @@ async function handleToolCall(
|
|
|
2701
2917
|
throw new Error("Provide either filePath or base64Data, not both.");
|
|
2702
2918
|
}
|
|
2703
2919
|
|
|
2704
|
-
let data: string;
|
|
2705
2920
|
if (filePath) {
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2921
|
+
// Server can read the file → upload direct-to-storage via the handshake
|
|
2922
|
+
// (no base64 through the model context or the edge-fn JSON body).
|
|
2923
|
+
const bytes = await readFileForUpload(
|
|
2924
|
+
filePath,
|
|
2925
|
+
MAX_ATTACHMENT_SIZE,
|
|
2926
|
+
"attachment",
|
|
2927
|
+
);
|
|
2928
|
+
const resolvedName = fileName || basename(filePath);
|
|
2929
|
+
const signed = await client.requestCardAttachmentUploadUrl(cardId, {
|
|
2930
|
+
fileName: resolvedName,
|
|
2931
|
+
fileType: contentType,
|
|
2932
|
+
size: bytes.byteLength,
|
|
2933
|
+
});
|
|
2934
|
+
await putToSignedUrl(
|
|
2935
|
+
signed.uploadUrl,
|
|
2936
|
+
bytes,
|
|
2937
|
+
contentType || signed.fileType || "application/octet-stream",
|
|
2938
|
+
);
|
|
2939
|
+
return await client.finalizeCardAttachment(cardId, {
|
|
2940
|
+
storagePath: signed.storagePath,
|
|
2941
|
+
fileName: resolvedName,
|
|
2942
|
+
fileType: contentType || signed.fileType,
|
|
2943
|
+
sha256: sha256Hex(bytes),
|
|
2944
|
+
size: bytes.byteLength,
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
if (base64Data) {
|
|
2713
2949
|
if (!fileName) {
|
|
2714
2950
|
throw new Error("fileName is required when using base64Data.");
|
|
2715
2951
|
}
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2952
|
+
if (base64ByteLength(base64Data) > MAX_ATTACHMENT_SIZE) {
|
|
2953
|
+
throw new Error(
|
|
2954
|
+
`File is over the 5MB attachment limit. Use the harmony_request_card_attachment_upload_url + harmony_finalize_card_attachment handshake for large files.`,
|
|
2955
|
+
);
|
|
2956
|
+
}
|
|
2957
|
+
return await client.uploadCardAttachment(cardId, {
|
|
2958
|
+
fileName,
|
|
2959
|
+
data: base64Data,
|
|
2960
|
+
fileType: contentType,
|
|
2961
|
+
});
|
|
2719
2962
|
}
|
|
2720
2963
|
|
|
2721
|
-
|
|
2722
|
-
fileName: fileName as string,
|
|
2723
|
-
data,
|
|
2724
|
-
fileType: contentType,
|
|
2725
|
-
});
|
|
2726
|
-
return result;
|
|
2964
|
+
throw new Error("Provide either filePath or base64Data.");
|
|
2727
2965
|
}
|
|
2728
2966
|
|
|
2729
2967
|
case "harmony_upload_artifact": {
|
|
@@ -2737,12 +2975,7 @@ async function handleToolCall(
|
|
|
2737
2975
|
args.workspaceId != null
|
|
2738
2976
|
? z.string().uuid().parse(args.workspaceId)
|
|
2739
2977
|
: undefined;
|
|
2740
|
-
|
|
2741
|
-
if (anchors.length !== 1) {
|
|
2742
|
-
throw new Error(
|
|
2743
|
-
"Provide exactly one of cardId, planId, or workspaceId.",
|
|
2744
|
-
);
|
|
2745
|
-
}
|
|
2978
|
+
requireExactlyOneScope({ cardId, planId, workspaceId });
|
|
2746
2979
|
|
|
2747
2980
|
const filePath =
|
|
2748
2981
|
args.filePath != null ? z.string().parse(args.filePath) : undefined;
|
|
@@ -2752,29 +2985,149 @@ async function handleToolCall(
|
|
|
2752
2985
|
throw new Error("Provide either filePath or base64Data, not both.");
|
|
2753
2986
|
}
|
|
2754
2987
|
|
|
2755
|
-
let data: string;
|
|
2756
|
-
let inferredTitle = title;
|
|
2757
2988
|
if (filePath) {
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2989
|
+
// Server can read the file → upload direct-to-storage via the handshake
|
|
2990
|
+
// (no base64 through the model context or the edge-fn JSON body).
|
|
2991
|
+
const bytes = await readFileForUpload(
|
|
2992
|
+
filePath,
|
|
2993
|
+
MAX_ARTIFACT_SIZE,
|
|
2994
|
+
"artifact",
|
|
2995
|
+
);
|
|
2996
|
+
const resolvedTitle = title || basename(filePath);
|
|
2997
|
+
const signed = await client.requestArtifactUploadUrl({
|
|
2998
|
+
title: resolvedTitle,
|
|
2999
|
+
cardId,
|
|
3000
|
+
planId,
|
|
3001
|
+
workspaceId,
|
|
3002
|
+
contentType: "text/html",
|
|
3003
|
+
size: bytes.byteLength,
|
|
3004
|
+
});
|
|
3005
|
+
await putToSignedUrl(signed.uploadUrl, bytes, "text/html");
|
|
3006
|
+
return await client.finalizeArtifact({
|
|
3007
|
+
storagePath: signed.storagePath,
|
|
3008
|
+
sha256: sha256Hex(bytes),
|
|
3009
|
+
size: bytes.byteLength,
|
|
3010
|
+
title: resolvedTitle,
|
|
3011
|
+
cardId,
|
|
3012
|
+
planId,
|
|
3013
|
+
workspaceId,
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
if (base64Data) {
|
|
3018
|
+
if (base64ByteLength(base64Data) > MAX_ARTIFACT_SIZE) {
|
|
3019
|
+
throw new Error(
|
|
3020
|
+
`Artifact is over the 2MB limit. Use the harmony_request_artifact_upload_url + harmony_finalize_artifact handshake for large files.`,
|
|
3021
|
+
);
|
|
2761
3022
|
}
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
3023
|
+
return await client.uploadArtifact({
|
|
3024
|
+
title,
|
|
3025
|
+
cardId,
|
|
3026
|
+
planId,
|
|
3027
|
+
workspaceId,
|
|
3028
|
+
data: base64Data,
|
|
3029
|
+
});
|
|
2768
3030
|
}
|
|
2769
3031
|
|
|
2770
|
-
|
|
2771
|
-
|
|
3032
|
+
throw new Error("Provide either filePath or base64Data.");
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
case "harmony_request_artifact_upload_url": {
|
|
3036
|
+
const title =
|
|
3037
|
+
args.title != null ? z.string().parse(args.title) : undefined;
|
|
3038
|
+
const cardId =
|
|
3039
|
+
args.cardId != null ? z.string().uuid().parse(args.cardId) : undefined;
|
|
3040
|
+
const planId =
|
|
3041
|
+
args.planId != null ? z.string().uuid().parse(args.planId) : undefined;
|
|
3042
|
+
const workspaceId =
|
|
3043
|
+
args.workspaceId != null
|
|
3044
|
+
? z.string().uuid().parse(args.workspaceId)
|
|
3045
|
+
: undefined;
|
|
3046
|
+
requireExactlyOneScope({ cardId, planId, workspaceId });
|
|
3047
|
+
const contentType =
|
|
3048
|
+
args.contentType != null
|
|
3049
|
+
? z.string().parse(args.contentType)
|
|
3050
|
+
: undefined;
|
|
3051
|
+
const size =
|
|
3052
|
+
args.size != null ? z.number().positive().parse(args.size) : undefined;
|
|
3053
|
+
if (size != null && size > MAX_ARTIFACT_SIZE) {
|
|
3054
|
+
throw new Error(
|
|
3055
|
+
`Declared size ${size} bytes is over the ${MAX_ARTIFACT_SIZE}-byte (2MB) artifact limit.`,
|
|
3056
|
+
);
|
|
3057
|
+
}
|
|
3058
|
+
return await client.requestArtifactUploadUrl({
|
|
3059
|
+
title,
|
|
2772
3060
|
cardId,
|
|
2773
3061
|
planId,
|
|
2774
3062
|
workspaceId,
|
|
2775
|
-
|
|
3063
|
+
contentType,
|
|
3064
|
+
size,
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
case "harmony_finalize_artifact": {
|
|
3069
|
+
const storagePath = z.string().parse(args.storagePath);
|
|
3070
|
+
const title =
|
|
3071
|
+
args.title != null ? z.string().parse(args.title) : undefined;
|
|
3072
|
+
const cardId =
|
|
3073
|
+
args.cardId != null ? z.string().uuid().parse(args.cardId) : undefined;
|
|
3074
|
+
const planId =
|
|
3075
|
+
args.planId != null ? z.string().uuid().parse(args.planId) : undefined;
|
|
3076
|
+
const workspaceId =
|
|
3077
|
+
args.workspaceId != null
|
|
3078
|
+
? z.string().uuid().parse(args.workspaceId)
|
|
3079
|
+
: undefined;
|
|
3080
|
+
requireExactlyOneScope({ cardId, planId, workspaceId });
|
|
3081
|
+
const sha256 =
|
|
3082
|
+
args.sha256 != null ? z.string().parse(args.sha256) : undefined;
|
|
3083
|
+
const size =
|
|
3084
|
+
args.size != null ? z.number().positive().parse(args.size) : undefined;
|
|
3085
|
+
return await client.finalizeArtifact({
|
|
3086
|
+
storagePath,
|
|
3087
|
+
sha256,
|
|
3088
|
+
size,
|
|
3089
|
+
title,
|
|
3090
|
+
cardId,
|
|
3091
|
+
planId,
|
|
3092
|
+
workspaceId,
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
case "harmony_request_card_attachment_upload_url": {
|
|
3097
|
+
const cardId = z.string().uuid().parse(args.cardId);
|
|
3098
|
+
const fileName = z.string().parse(args.fileName);
|
|
3099
|
+
const fileType =
|
|
3100
|
+
args.fileType != null ? z.string().parse(args.fileType) : undefined;
|
|
3101
|
+
const size = z.number().positive().parse(args.size);
|
|
3102
|
+
if (size > MAX_ATTACHMENT_SIZE) {
|
|
3103
|
+
throw new Error(
|
|
3104
|
+
`Declared size ${size} bytes is over the ${MAX_ATTACHMENT_SIZE}-byte (5MB) attachment limit.`,
|
|
3105
|
+
);
|
|
3106
|
+
}
|
|
3107
|
+
return await client.requestCardAttachmentUploadUrl(cardId, {
|
|
3108
|
+
fileName,
|
|
3109
|
+
fileType,
|
|
3110
|
+
size,
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
case "harmony_finalize_card_attachment": {
|
|
3115
|
+
const cardId = z.string().uuid().parse(args.cardId);
|
|
3116
|
+
const storagePath = z.string().parse(args.storagePath);
|
|
3117
|
+
const fileName = z.string().parse(args.fileName);
|
|
3118
|
+
const fileType =
|
|
3119
|
+
args.fileType != null ? z.string().parse(args.fileType) : undefined;
|
|
3120
|
+
const sha256 =
|
|
3121
|
+
args.sha256 != null ? z.string().parse(args.sha256) : undefined;
|
|
3122
|
+
const size =
|
|
3123
|
+
args.size != null ? z.number().positive().parse(args.size) : undefined;
|
|
3124
|
+
return await client.finalizeCardAttachment(cardId, {
|
|
3125
|
+
storagePath,
|
|
3126
|
+
fileName,
|
|
3127
|
+
fileType,
|
|
3128
|
+
sha256,
|
|
3129
|
+
size,
|
|
2776
3130
|
});
|
|
2777
|
-
return result;
|
|
2778
3131
|
}
|
|
2779
3132
|
|
|
2780
3133
|
case "harmony_share_artifact": {
|