diff --git a/.changeset/fix-1500-missing-declaration-chunks.md b/.changeset/fix-1500-missing-declaration-chunks.md new file mode 100644 index 000000000..79ccfbb3a --- /dev/null +++ b/.changeset/fix-1500-missing-declaration-chunks.md @@ -0,0 +1,5 @@ +--- +"eve": patch +--- + +Fix missing content-hashed declaration chunks in the published `eve` tarball. The chat and twilio vendor configs previously only co-copied `jsx-runtime-.d.ts` (chat) or no hashed chunks at all (twilio), so the upstream `messages-.d.ts` and `types-.d.ts` files were dropped from the published package — degrading ~120 chat exports to `any` and producing TS2307 errors with `skipLibCheck: false`. Extend `discoverExtraFiles` in `_shared.mjs` to fold the hashed siblings into the same declaration-rewrite pass as the named entry files, and add the chunk patterns (`messages-`, `types-`) to the chat and twilio configs. Also fixes a small set of `chat` and `@chat-adapter/twilio` type-surface leaks in eve sources and tests that were silently relying on the previous `any` fallback. Resolves #1500. diff --git a/packages/eve/scripts/vendor-compiled/@chat-adapter/twilio.mjs b/packages/eve/scripts/vendor-compiled/@chat-adapter/twilio.mjs index 39b2fd957..641354449 100644 --- a/packages/eve/scripts/vendor-compiled/@chat-adapter/twilio.mjs +++ b/packages/eve/scripts/vendor-compiled/@chat-adapter/twilio.mjs @@ -35,5 +35,14 @@ export default { rewrites: { chat: { kind: "vendored", compiledPath: "chat" }, }, + discoverExtraFiles: (distEntries) => + // The upstream bundler emits content-hashed sibling declaration + // chunks (`types-.d.ts`) that the entry .d.ts files import by + // relative path. Co-copy them verbatim so the specifier resolves + // inside the published tarball — the miss here produced TS2307 for + // `TwilioWebhookUrl` and `TwilioVerifiedRequest` under + // skipLibCheck:false (see #1500). Mirrors the @chat-adapter/slack + // pattern a few directories over. + distEntries.filter((name) => /^types-[^./]+\.d\.ts$/.test(name)), }), }; diff --git a/packages/eve/scripts/vendor-compiled/_shared.mjs b/packages/eve/scripts/vendor-compiled/_shared.mjs index ec095cd3b..cbdf0863a 100644 --- a/packages/eve/scripts/vendor-compiled/_shared.mjs +++ b/packages/eve/scripts/vendor-compiled/_shared.mjs @@ -120,8 +120,21 @@ export function createDeclarationCopier({ ? files : [{ source: "index.d.ts", output: "index.d.ts" }]; + // discoverExtraFiles names content-hashed sibling chunks (e.g. + // `messages-.d.ts`, `types-.d.ts`) that the upstream + // bundler emits next to the entry .d.ts. They must flow through the + // same rewrite pass as the named `files` — chat's `messages-` + // chunk imports `mdast`, and the published package cannot ship that + // bare specifier (no @types/mdast in scope; see #1500). + const extraFileNames = + typeof discoverExtraFiles === "function" ? discoverExtraFiles(distEntries) : []; + const allFiles = [ + ...declarationFiles, + ...extraFileNames.map((name) => ({ source: name, output: name })), + ]; + const declarations = await Promise.all( - declarationFiles.map(async (file) => ({ + allFiles.map(async (file) => ({ ...file, sourceText: await readFile(join(distDir, file.source), "utf8"), })), @@ -178,16 +191,10 @@ export function createDeclarationCopier({ }), ); - if (typeof discoverExtraFiles === "function") { - const extras = discoverExtraFiles(distEntries); - await Promise.all( - extras.map(async (file) => { - const outputPath = join(destinationRoot, file); - await mkdir(dirname(outputPath), { recursive: true }); - await copyFile(join(distDir, file), outputPath); - }), - ); - } + // NOTE: the previous tail block that re-copied each extra file verbatim + // (via copyFile) is removed — extras are folded into `declarations` + // above so they receive the same rewrite pass. Re-adding it would + // overwrite the rewritten output with the un-rewritten source. }; } diff --git a/packages/eve/scripts/vendor-compiled/chat.mjs b/packages/eve/scripts/vendor-compiled/chat.mjs index affcc5ff8..e4df9bcb6 100644 --- a/packages/eve/scripts/vendor-compiled/chat.mjs +++ b/packages/eve/scripts/vendor-compiled/chat.mjs @@ -38,6 +38,14 @@ export default { }, }, discoverExtraFiles: (distEntries) => - distEntries.filter((name) => /^jsx-runtime-[^./]+\.d\.ts$/.test(name)), + // Co-copy the sibling content-hashed declaration chunks the upstream + // build emits that the entry .d.ts imports by relative path: + // `jsx-runtime-.d.ts` (pre-existing) and `messages-.d.ts` + // (previously missed — its absence with skipLibCheck:false produced + // TS2307 across ~120 chat exports, see #1500). The hash suffix is + // content-derived and drifts on every upstream build. + distEntries.filter((name) => + /^(jsx-runtime|messages)-[^./]+\.d\.ts$/.test(name), + ), }), }; diff --git a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts index 516cd531e..b844ad82c 100644 --- a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts +++ b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts @@ -270,7 +270,7 @@ export function chatSdkChannel( { inputResponses: [response] }, { auth: config.resolveInputAuth ? await config.resolveInputAuth(event) : null, - thread: event.thread, + thread: event.thread as Thread, }, ); }); diff --git a/packages/eve/src/public/channels/photon/inboundContent.test.ts b/packages/eve/src/public/channels/photon/inboundContent.test.ts index c031c075e..9eb68138c 100644 --- a/packages/eve/src/public/channels/photon/inboundContent.test.ts +++ b/packages/eve/src/public/channels/photon/inboundContent.test.ts @@ -6,8 +6,10 @@ import { photonInboundContent } from "#public/channels/photon/inboundContent.js" function message(text: string, attachments: Message["attachments"] = []): Message { return new Message({ attachments, - author: { isBot: false, isMe: false, userId: "user", userName: "user" }, + author: { fullName: "user", isBot: false, isMe: false, userId: "user", userName: "user" }, + formatted: { type: "root", children: [] }, id: "message-id", + metadata: { dateSent: new Date(), edited: false }, raw: {}, text, threadId: "thread-id", diff --git a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts index e52be32b9..3a8d2e9e2 100644 --- a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts +++ b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts @@ -42,8 +42,11 @@ describe("photonIMessageChannel", () => { if (handler === undefined) throw new Error("Expected an inbound direct-message handler."); const thread = { id: "thread-id" }; const message = new Message({ - author: { isBot: false, isMe: false, userId: "user", userName: "user" }, + attachments: [], + author: { fullName: "user", isBot: false, isMe: false, userId: "user", userName: "user" }, + formatted: { type: "root", children: [] }, id: "message-id", + metadata: { dateSent: new Date(), edited: false }, raw: {}, text: "Steer this response", threadId: thread.id, @@ -65,8 +68,11 @@ describe("photonIMessageChannel", () => { if (handler === undefined) throw new Error("Expected an inbound direct-message handler."); const thread = { id: "thread-id" }; const message = new Message({ - author: { isBot: false, isMe: false, userId: "user", userName: "user" }, + attachments: [], + author: { fullName: "user", isBot: false, isMe: false, userId: "user", userName: "user" }, + formatted: { type: "root", children: [] }, id: "message-id", + metadata: { dateSent: new Date(), edited: false }, raw: {}, text: " \n", threadId: thread.id, @@ -87,8 +93,11 @@ describe("photonIMessageChannel", () => { } const thread = { id: "group-thread-id" }; const message = new Message({ - author: { isBot: false, isMe: false, userId: "user", userName: "user" }, + attachments: [], + author: { fullName: "user", isBot: false, isMe: false, userId: "user", userName: "user" }, + formatted: { type: "root", children: [] }, id: "message-id", + metadata: { dateSent: new Date(), edited: false }, raw: {}, text: "Hello group", threadId: thread.id,