@5ss/ai-tools 2.11.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 +112 -0
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/dist/ai-sdk/index.d.ts +15 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +24 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/artifact-D064mHfK.js +44 -0
- package/dist/artifact-D064mHfK.js.map +1 -0
- package/dist/artifacts-O8g-40Pw.js +404 -0
- package/dist/artifacts-O8g-40Pw.js.map +1 -0
- package/dist/aws-json-CecFqzqX.js +23 -0
- package/dist/aws-json-CecFqzqX.js.map +1 -0
- package/dist/aws-service-msttbPrz.js +58 -0
- package/dist/aws-service-msttbPrz.js.map +1 -0
- package/dist/batch-BMM5dXqL.d.ts +22 -0
- package/dist/batch-BMM5dXqL.d.ts.map +1 -0
- package/dist/batch-Co1ujeAW.js +67 -0
- package/dist/batch-Co1ujeAW.js.map +1 -0
- package/dist/bedrock-agentcore-browser-a_qOs-NR.js +182 -0
- package/dist/bedrock-agentcore-browser-a_qOs-NR.js.map +1 -0
- package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js +357 -0
- package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js.map +1 -0
- package/dist/bytes-BxpimpQx.js +45 -0
- package/dist/bytes-BxpimpQx.js.map +1 -0
- package/dist/client-CCKGsTeI.js +743 -0
- package/dist/client-CCKGsTeI.js.map +1 -0
- package/dist/cloudflare/index.d.ts +37 -0
- package/dist/cloudflare/index.d.ts.map +1 -0
- package/dist/cloudflare/index.js +41 -0
- package/dist/cloudflare/index.js.map +1 -0
- package/dist/cloudflare-browser-B6Yolpin.js +428 -0
- package/dist/cloudflare-browser-B6Yolpin.js.map +1 -0
- package/dist/cloudflare-email-Dy0KHeDf.js +197 -0
- package/dist/cloudflare-email-Dy0KHeDf.js.map +1 -0
- package/dist/cloudflare-sandbox-Dp_uNaqW.js +982 -0
- package/dist/cloudflare-sandbox-Dp_uNaqW.js.map +1 -0
- package/dist/content-type-CORxaxcv.js +49 -0
- package/dist/content-type-CORxaxcv.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +204 -0
- package/dist/core/index.js.map +1 -0
- package/dist/define-CvpJ_pNP.js +115 -0
- package/dist/define-CvpJ_pNP.js.map +1 -0
- package/dist/errors-DoSpNHvs.js +20 -0
- package/dist/errors-DoSpNHvs.js.map +1 -0
- package/dist/errors-aKhko9T1.d.ts +18 -0
- package/dist/errors-aKhko9T1.d.ts.map +1 -0
- package/dist/eventbridge-scheduler-Bh6GqZY2.js +349 -0
- package/dist/eventbridge-scheduler-Bh6GqZY2.js.map +1 -0
- package/dist/framework-context-DVIIY8ZO.js +24 -0
- package/dist/framework-context-DVIIY8ZO.js.map +1 -0
- package/dist/gotenberg-NuJjxyln.js +291 -0
- package/dist/gotenberg-NuJjxyln.js.map +1 -0
- package/dist/http/index.d.ts +47 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +3 -0
- package/dist/http-service-DDNCO1s4.js +254 -0
- package/dist/http-service-DDNCO1s4.js.map +1 -0
- package/dist/http-service-T7E5UjP8.d.ts +80 -0
- package/dist/http-service-T7E5UjP8.d.ts.map +1 -0
- package/dist/imessage-BSAFOI8Z.js +154 -0
- package/dist/imessage-BSAFOI8Z.js.map +1 -0
- package/dist/index-BU4gmYO8.d.ts +254 -0
- package/dist/index-BU4gmYO8.d.ts.map +1 -0
- package/dist/index-CCivzmxO.d.ts +188 -0
- package/dist/index-CCivzmxO.d.ts.map +1 -0
- package/dist/index-CLmTrcu5.d.ts +22 -0
- package/dist/index-CLmTrcu5.d.ts.map +1 -0
- package/dist/index-CZX5OeOF.d.ts +235 -0
- package/dist/index-CZX5OeOF.d.ts.map +1 -0
- package/dist/index-CdFmEfZO.d.ts +359 -0
- package/dist/index-CdFmEfZO.d.ts.map +1 -0
- package/dist/index-Cuh6eMWc.d.ts +285 -0
- package/dist/index-Cuh6eMWc.d.ts.map +1 -0
- package/dist/index-DuOGj7vc.d.ts +107 -0
- package/dist/index-DuOGj7vc.d.ts.map +1 -0
- package/dist/index-ccZ1XOHw.d.ts +69 -0
- package/dist/index-ccZ1XOHw.d.ts.map +1 -0
- package/dist/index-n8JTpNf1.d.ts +247 -0
- package/dist/index-n8JTpNf1.d.ts.map +1 -0
- package/dist/index-pwW1OsOx.d.ts +134 -0
- package/dist/index-pwW1OsOx.d.ts.map +1 -0
- package/dist/index-zK1ZwS4m.d.ts +347 -0
- package/dist/index-zK1ZwS4m.d.ts.map +1 -0
- package/dist/limits-hjrO8zUG.js +80 -0
- package/dist/limits-hjrO8zUG.js.map +1 -0
- package/dist/mastra/index.d.ts +14 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +26 -0
- package/dist/mastra/index.js.map +1 -0
- package/dist/mastra-vector-Dhc6XZ8l.js +234 -0
- package/dist/mastra-vector-Dhc6XZ8l.js.map +1 -0
- package/dist/mcp/index.d.ts +80 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +97 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/modules/artifacts/index.d.ts +337 -0
- package/dist/modules/artifacts/index.d.ts.map +1 -0
- package/dist/modules/artifacts/index.js +348 -0
- package/dist/modules/artifacts/index.js.map +1 -0
- package/dist/modules/browser/index.d.ts +516 -0
- package/dist/modules/browser/index.d.ts.map +1 -0
- package/dist/modules/browser/index.js +475 -0
- package/dist/modules/browser/index.js.map +1 -0
- package/dist/modules/calendar/index.d.ts +93 -0
- package/dist/modules/calendar/index.d.ts.map +1 -0
- package/dist/modules/calendar/index.js +131 -0
- package/dist/modules/calendar/index.js.map +1 -0
- package/dist/modules/code-sandbox/index.d.ts +317 -0
- package/dist/modules/code-sandbox/index.d.ts.map +1 -0
- package/dist/modules/code-sandbox/index.js +537 -0
- package/dist/modules/code-sandbox/index.js.map +1 -0
- package/dist/modules/content-type/index.d.ts +22 -0
- package/dist/modules/content-type/index.d.ts.map +1 -0
- package/dist/modules/content-type/index.js +66 -0
- package/dist/modules/content-type/index.js.map +1 -0
- package/dist/modules/crypto/index.d.ts +115 -0
- package/dist/modules/crypto/index.d.ts.map +1 -0
- package/dist/modules/crypto/index.js +139 -0
- package/dist/modules/crypto/index.js.map +1 -0
- package/dist/modules/document/index.d.ts +575 -0
- package/dist/modules/document/index.d.ts.map +1 -0
- package/dist/modules/document/index.js +444 -0
- package/dist/modules/document/index.js.map +1 -0
- package/dist/modules/document-extract/index.d.ts +438 -0
- package/dist/modules/document-extract/index.d.ts.map +1 -0
- package/dist/modules/document-extract/index.js +127 -0
- package/dist/modules/document-extract/index.js.map +1 -0
- package/dist/modules/document-render/index.d.ts +336 -0
- package/dist/modules/document-render/index.d.ts.map +1 -0
- package/dist/modules/document-render/index.js +155 -0
- package/dist/modules/document-render/index.js.map +1 -0
- package/dist/modules/email/index.d.ts +311 -0
- package/dist/modules/email/index.d.ts.map +1 -0
- package/dist/modules/email/index.js +167 -0
- package/dist/modules/email/index.js.map +1 -0
- package/dist/modules/email-message/index.d.ts +95 -0
- package/dist/modules/email-message/index.d.ts.map +1 -0
- package/dist/modules/email-message/index.js +264 -0
- package/dist/modules/email-message/index.js.map +1 -0
- package/dist/modules/file-convert/index.d.ts +273 -0
- package/dist/modules/file-convert/index.d.ts.map +1 -0
- package/dist/modules/file-convert/index.js +103 -0
- package/dist/modules/file-convert/index.js.map +1 -0
- package/dist/modules/files/index.d.ts +452 -0
- package/dist/modules/files/index.d.ts.map +1 -0
- package/dist/modules/files/index.js +733 -0
- package/dist/modules/files/index.js.map +1 -0
- package/dist/modules/image/index.d.ts +342 -0
- package/dist/modules/image/index.d.ts.map +1 -0
- package/dist/modules/image/index.js +281 -0
- package/dist/modules/image/index.js.map +1 -0
- package/dist/modules/messaging/index.d.ts +608 -0
- package/dist/modules/messaging/index.d.ts.map +1 -0
- package/dist/modules/messaging/index.js +1067 -0
- package/dist/modules/messaging/index.js.map +1 -0
- package/dist/modules/pdf/index.d.ts +287 -0
- package/dist/modules/pdf/index.d.ts.map +1 -0
- package/dist/modules/pdf/index.js +259 -0
- package/dist/modules/pdf/index.js.map +1 -0
- package/dist/modules/presentation/index.d.ts +247 -0
- package/dist/modules/presentation/index.d.ts.map +1 -0
- package/dist/modules/presentation/index.js +12657 -0
- package/dist/modules/presentation/index.js.map +1 -0
- package/dist/modules/queue/index.d.ts +129 -0
- package/dist/modules/queue/index.d.ts.map +1 -0
- package/dist/modules/queue/index.js +131 -0
- package/dist/modules/queue/index.js.map +1 -0
- package/dist/modules/rag/index.d.ts +250 -0
- package/dist/modules/rag/index.d.ts.map +1 -0
- package/dist/modules/rag/index.js +366 -0
- package/dist/modules/rag/index.js.map +1 -0
- package/dist/modules/scheduler/index.d.ts +216 -0
- package/dist/modules/scheduler/index.d.ts.map +1 -0
- package/dist/modules/scheduler/index.js +153 -0
- package/dist/modules/scheduler/index.js.map +1 -0
- package/dist/modules/skills/index.d.ts +205 -0
- package/dist/modules/skills/index.d.ts.map +1 -0
- package/dist/modules/skills/index.js +203 -0
- package/dist/modules/skills/index.js.map +1 -0
- package/dist/modules/tasks/index.d.ts +287 -0
- package/dist/modules/tasks/index.d.ts.map +1 -0
- package/dist/modules/tasks/index.js +207 -0
- package/dist/modules/tasks/index.js.map +1 -0
- package/dist/modules/vector-store/index.d.ts +3 -0
- package/dist/modules/vector-store/index.js +3 -0
- package/dist/modules/web-fetch/index.d.ts +99 -0
- package/dist/modules/web-fetch/index.d.ts.map +1 -0
- package/dist/modules/web-fetch/index.js +242 -0
- package/dist/modules/web-fetch/index.js.map +1 -0
- package/dist/object-artifact-store-CMTzCm_G.d.ts +7 -0
- package/dist/object-artifact-store-CMTzCm_G.d.ts.map +1 -0
- package/dist/object-artifact-store-wZ2j9cto.js +28 -0
- package/dist/object-artifact-store-wZ2j9cto.js.map +1 -0
- package/dist/pinecone-umY4t6OF.js +190 -0
- package/dist/pinecone-umY4t6OF.js.map +1 -0
- package/dist/provider-CgDAlg6K.js +34 -0
- package/dist/provider-CgDAlg6K.js.map +1 -0
- package/dist/qdrant-DMp4NhKR.js +253 -0
- package/dist/qdrant-DMp4NhKR.js.map +1 -0
- package/dist/resend-BAC38_dA.js +155 -0
- package/dist/resend-BAC38_dA.js.map +1 -0
- package/dist/s3-CsOaPWMP.js +955 -0
- package/dist/s3-CsOaPWMP.js.map +1 -0
- package/dist/schemas-ChOAhdo9.js +192 -0
- package/dist/schemas-ChOAhdo9.js.map +1 -0
- package/dist/slack-Di5BBNpt.js +1455 -0
- package/dist/slack-Di5BBNpt.js.map +1 -0
- package/dist/sqs-DCwS1i2N.js +225 -0
- package/dist/sqs-DCwS1i2N.js.map +1 -0
- package/dist/supabase-vector-Dpp9mmJR.js +218 -0
- package/dist/supabase-vector-Dpp9mmJR.js.map +1 -0
- package/dist/tanstack/index.d.ts +15 -0
- package/dist/tanstack/index.d.ts.map +1 -0
- package/dist/tanstack/index.js +28 -0
- package/dist/tanstack/index.js.map +1 -0
- package/dist/teams-DYAHNb39.js +835 -0
- package/dist/teams-DYAHNb39.js.map +1 -0
- package/dist/telegram-DDXWzkfL.js +734 -0
- package/dist/telegram-DDXWzkfL.js.map +1 -0
- package/dist/textract-CPLiB22H.js +554 -0
- package/dist/textract-CPLiB22H.js.map +1 -0
- package/dist/transport-B4vn-XiQ.js +157 -0
- package/dist/transport-B4vn-XiQ.js.map +1 -0
- package/dist/transport-i96ACAI_.d.ts +46 -0
- package/dist/transport-i96ACAI_.d.ts.map +1 -0
- package/dist/types-Ccb0DXY9.d.ts +150 -0
- package/dist/types-Ccb0DXY9.d.ts.map +1 -0
- package/dist/unique-EwBH1JPB.js +19 -0
- package/dist/unique-EwBH1JPB.js.map +1 -0
- package/dist/vector-store-C3nEO80e.js +193 -0
- package/dist/vector-store-C3nEO80e.js.map +1 -0
- package/dist/vendors/amazon-sp-api/index.d.ts +526 -0
- package/dist/vendors/amazon-sp-api/index.d.ts.map +1 -0
- package/dist/vendors/amazon-sp-api/index.js +975 -0
- package/dist/vendors/amazon-sp-api/index.js.map +1 -0
- package/dist/vendors/bedrock-agentcore-browser/index.d.ts +2 -0
- package/dist/vendors/bedrock-agentcore-browser/index.js +2 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts +228 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts.map +1 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.js +2 -0
- package/dist/vendors/cloudflare-browser/index.d.ts +2 -0
- package/dist/vendors/cloudflare-browser/index.js +2 -0
- package/dist/vendors/cloudflare-email/index.d.ts +260 -0
- package/dist/vendors/cloudflare-email/index.d.ts.map +1 -0
- package/dist/vendors/cloudflare-email/index.js +3 -0
- package/dist/vendors/cloudflare-sandbox/index.d.ts +565 -0
- package/dist/vendors/cloudflare-sandbox/index.d.ts.map +1 -0
- package/dist/vendors/cloudflare-sandbox/index.js +2 -0
- package/dist/vendors/eventbridge-scheduler/index.d.ts +2 -0
- package/dist/vendors/eventbridge-scheduler/index.js +2 -0
- package/dist/vendors/gotenberg/index.d.ts +306 -0
- package/dist/vendors/gotenberg/index.d.ts.map +1 -0
- package/dist/vendors/gotenberg/index.js +2 -0
- package/dist/vendors/imessage/index.d.ts +420 -0
- package/dist/vendors/imessage/index.d.ts.map +1 -0
- package/dist/vendors/imessage/index.js +4 -0
- package/dist/vendors/katana/index.d.ts +1570 -0
- package/dist/vendors/katana/index.d.ts.map +1 -0
- package/dist/vendors/katana/index.js +1639 -0
- package/dist/vendors/katana/index.js.map +1 -0
- package/dist/vendors/mastra-vector/index.d.ts +120 -0
- package/dist/vendors/mastra-vector/index.d.ts.map +1 -0
- package/dist/vendors/mastra-vector/index.js +3 -0
- package/dist/vendors/pinecone/index.d.ts +75 -0
- package/dist/vendors/pinecone/index.d.ts.map +1 -0
- package/dist/vendors/pinecone/index.js +3 -0
- package/dist/vendors/qdrant/index.d.ts +75 -0
- package/dist/vendors/qdrant/index.d.ts.map +1 -0
- package/dist/vendors/qdrant/index.js +3 -0
- package/dist/vendors/resend/index.d.ts +3 -0
- package/dist/vendors/resend/index.js +3 -0
- package/dist/vendors/s3/index.d.ts +2 -0
- package/dist/vendors/s3/index.js +2 -0
- package/dist/vendors/slack/index.d.ts +576 -0
- package/dist/vendors/slack/index.d.ts.map +1 -0
- package/dist/vendors/slack/index.js +3 -0
- package/dist/vendors/sqs/index.d.ts +2 -0
- package/dist/vendors/sqs/index.js +2 -0
- package/dist/vendors/supabase-vector/index.d.ts +89 -0
- package/dist/vendors/supabase-vector/index.d.ts.map +1 -0
- package/dist/vendors/supabase-vector/index.js +3 -0
- package/dist/vendors/teams/index.d.ts +303 -0
- package/dist/vendors/teams/index.d.ts.map +1 -0
- package/dist/vendors/teams/index.js +3 -0
- package/dist/vendors/telegram/index.d.ts +319 -0
- package/dist/vendors/telegram/index.d.ts.map +1 -0
- package/dist/vendors/telegram/index.js +3 -0
- package/dist/vendors/textract/index.d.ts +2 -0
- package/dist/vendors/textract/index.js +2 -0
- package/dist/vendors/woocommerce/index.d.ts +1700 -0
- package/dist/vendors/woocommerce/index.d.ts.map +1 -0
- package/dist/vendors/woocommerce/index.js +1427 -0
- package/dist/vendors/woocommerce/index.js.map +1 -0
- package/dist/with-auth-CpKqTrGK.js +240 -0
- package/dist/with-auth-CpKqTrGK.js.map +1 -0
- package/logos/LUCIDE-ATTRIBUTION.txt +4 -0
- package/logos/README.md +89 -0
- package/logos/amazon.svg +6 -0
- package/logos/artifacts.svg +9 -0
- package/logos/browser.svg +9 -0
- package/logos/calendar.svg +15 -0
- package/logos/cloudflare-browser.svg +5 -0
- package/logos/cloudflare-email.svg +5 -0
- package/logos/cloudflare.svg +4 -0
- package/logos/code-sandbox.svg +8 -0
- package/logos/content-type.svg +10 -0
- package/logos/crypto.svg +7 -0
- package/logos/document-extract.svg +12 -0
- package/logos/document-render.svg +8 -0
- package/logos/document.svg +10 -0
- package/logos/email-message.svg +8 -0
- package/logos/email.svg +7 -0
- package/logos/file-convert.svg +9 -0
- package/logos/files.svg +6 -0
- package/logos/gotenberg.svg +340 -0
- package/logos/image.svg +8 -0
- package/logos/imessage.svg +7 -0
- package/logos/katana.svg +13 -0
- package/logos/mastra.svg +7 -0
- package/logos/messaging.svg +7 -0
- package/logos/pack-logos.json +48 -0
- package/logos/pdf.svg +10 -0
- package/logos/pinecone.svg +25 -0
- package/logos/presentation.svg +8 -0
- package/logos/qdrant.svg +4 -0
- package/logos/queue.svg +11 -0
- package/logos/rag.svg +18 -0
- package/logos/resend.svg +5 -0
- package/logos/scheduler.svg +7 -0
- package/logos/skills.svg +10 -0
- package/logos/slack.svg +14 -0
- package/logos/supabase.svg +4 -0
- package/logos/tasks.svg +10 -0
- package/logos/teams.svg +6 -0
- package/logos/telegram.svg +10 -0
- package/logos/textract.svg +5 -0
- package/logos/vector-store.svg +8 -0
- package/logos/web-fetch.svg +8 -0
- package/logos/woocommerce.svg +4 -0
- package/package.json +373 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { t as ToolError } from "./errors-DoSpNHvs.js";
|
|
2
|
+
import { n as defineModule, r as defineTool } from "./define-CvpJ_pNP.js";
|
|
3
|
+
import { n as requireAuth } from "./provider-CgDAlg6K.js";
|
|
4
|
+
import { t as artifactRefSchema } from "./artifact-D064mHfK.js";
|
|
5
|
+
import { t as HttpService } from "./http-service-DDNCO1s4.js";
|
|
6
|
+
import { a as toArrayBuffer } from "./bytes-BxpimpQx.js";
|
|
7
|
+
import { m as s3AuthSchema, p as S3Client } from "./s3-CsOaPWMP.js";
|
|
8
|
+
import { n as runBatchItems, t as batchResultSchema } from "./batch-Co1ujeAW.js";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
//#region src/vendors/gotenberg/contracts.ts
|
|
11
|
+
const MAX_HTML_CHARS = 2e6;
|
|
12
|
+
const gotenbergAuthSchema = z.object({
|
|
13
|
+
gotenberg_base_url: z.url().describe("Self-hosted Gotenberg origin, for example http://localhost:3000"),
|
|
14
|
+
gotenberg_api_username: z.string().min(1).optional().describe("Optional basic-auth username"),
|
|
15
|
+
gotenberg_api_password: z.string().min(1).optional().describe("Optional basic-auth password"),
|
|
16
|
+
storage: s3AuthSchema.describe("Object storage for rendered ArtifactRef output")
|
|
17
|
+
});
|
|
18
|
+
const gotenbergViewportSchema = z.object({
|
|
19
|
+
width: z.int().min(1).max(8e3).describe("Viewport width in CSS pixels"),
|
|
20
|
+
height: z.int().min(1).max(8e3).describe("Viewport height in CSS pixels"),
|
|
21
|
+
device_scale_factor: z.number().min(.1).max(4).optional().describe("Device scale factor (default 1)")
|
|
22
|
+
});
|
|
23
|
+
const gotenbergRenderSourceSchema = z.object({
|
|
24
|
+
html: z.string().min(1).max(MAX_HTML_CHARS).optional().describe("HTML document body to render"),
|
|
25
|
+
url: z.url().optional().describe("Absolute http(s) URL to open and render")
|
|
26
|
+
}).refine((v) => Boolean(v.html?.trim() || v.url), { message: "Provide html or url" }).refine((v) => !(v.html && v.url), { message: "Provide only one of html or url" });
|
|
27
|
+
const gotenbergRenderPdfInputSchema = z.object({
|
|
28
|
+
source: gotenbergRenderSourceSchema.describe("HTML string or URL to print"),
|
|
29
|
+
output_key: z.string().min(1).optional().describe("Object key for the PDF. Defaults under renders/"),
|
|
30
|
+
filename: z.string().min(1).optional().describe("Display filename for the result ArtifactRef")
|
|
31
|
+
});
|
|
32
|
+
const gotenbergRenderScreenshotInputSchema = z.object({
|
|
33
|
+
source: gotenbergRenderSourceSchema.describe("HTML string or URL to capture"),
|
|
34
|
+
output_key: z.string().min(1).optional().describe("Object key for the PNG. Defaults under renders/"),
|
|
35
|
+
filename: z.string().min(1).optional().describe("Display filename for the result ArtifactRef"),
|
|
36
|
+
viewport: gotenbergViewportSchema.optional().describe("Optional screenshot viewport")
|
|
37
|
+
});
|
|
38
|
+
const gotenbergRenderOutputSchema = z.object({
|
|
39
|
+
result: artifactRefSchema,
|
|
40
|
+
kind: z.enum(["pdf", "screenshot"])
|
|
41
|
+
});
|
|
42
|
+
/** Office document → PDF via LibreOffice (not HTML print). */
|
|
43
|
+
const gotenbergConvertPathSchema = z.enum(["office-to-pdf"]).describe("Closed conversion path");
|
|
44
|
+
const gotenbergConvertInputSchema = z.object({
|
|
45
|
+
source: artifactRefSchema.describe("Input artifact in object storage (office document)"),
|
|
46
|
+
path: gotenbergConvertPathSchema.default("office-to-pdf").describe("Conversion path (currently office-to-pdf only)"),
|
|
47
|
+
output_key: z.string().min(1).optional().describe("Object key for the PDF result. Defaults to source key with .pdf extension"),
|
|
48
|
+
filename: z.string().min(1).optional().describe("Upload filename when source has none")
|
|
49
|
+
});
|
|
50
|
+
const gotenbergConvertOutputSchema = z.object({
|
|
51
|
+
source: artifactRefSchema,
|
|
52
|
+
result: artifactRefSchema,
|
|
53
|
+
path: gotenbergConvertPathSchema
|
|
54
|
+
});
|
|
55
|
+
const MAX_BATCH_CONVERT = 10;
|
|
56
|
+
const gotenbergConvertBatchInputSchema = z.object({ items: z.array(gotenbergConvertInputSchema).min(1).max(10).describe(`Conversions to run (max 10)`) });
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/vendors/gotenberg/domain.ts
|
|
59
|
+
/**
|
|
60
|
+
* Gotenberg form/path helpers (no HTTP).
|
|
61
|
+
*/
|
|
62
|
+
function appendSource(form, source) {
|
|
63
|
+
if (source.html) {
|
|
64
|
+
const bytes = new TextEncoder().encode(source.html);
|
|
65
|
+
const blob = new Blob([toArrayBuffer(bytes)], { type: "text/html" });
|
|
66
|
+
form.append("files", blob, "index.html");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (source.url) {
|
|
70
|
+
form.append("url", source.url);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
throw new ToolError("Provide html or url", { code: "bad_input" });
|
|
74
|
+
}
|
|
75
|
+
function htmlPath(kind, source) {
|
|
76
|
+
if (source.html) return kind === "pdf" ? "/forms/chromium/convert/html" : "/forms/chromium/screenshot/html";
|
|
77
|
+
return kind === "pdf" ? "/forms/chromium/convert/url" : "/forms/chromium/screenshot/url";
|
|
78
|
+
}
|
|
79
|
+
function defaultRenderKey(kind, outputKey) {
|
|
80
|
+
if (outputKey) return outputKey;
|
|
81
|
+
const stamp = Date.now();
|
|
82
|
+
return kind === "pdf" ? `renders/${stamp}.pdf` : `renders/${stamp}.png`;
|
|
83
|
+
}
|
|
84
|
+
/** LibreOffice route — office suite docs → PDF. */
|
|
85
|
+
const LIBREOFFICE_CONVERT_PATH = "/forms/libreoffice/convert";
|
|
86
|
+
function basenameFromKey(key) {
|
|
87
|
+
const parts = key.replace(/\/+$/, "").split("/");
|
|
88
|
+
const last = parts[parts.length - 1];
|
|
89
|
+
return last && last.length > 0 ? last : "document";
|
|
90
|
+
}
|
|
91
|
+
function officeUploadName(source, filename) {
|
|
92
|
+
if (filename && filename.trim().length > 0) return filename.trim();
|
|
93
|
+
if (source.filename && source.filename.trim().length > 0) return source.filename.trim();
|
|
94
|
+
return basenameFromKey(source.key);
|
|
95
|
+
}
|
|
96
|
+
function officeToPdfResultKey(sourceKey, outputKey) {
|
|
97
|
+
if (outputKey) return outputKey;
|
|
98
|
+
return `${sourceKey.replace(/\.[^./]+$/, "")}.pdf`;
|
|
99
|
+
}
|
|
100
|
+
function guessOfficeMediaType(filename, hint) {
|
|
101
|
+
if (hint && hint.length > 0) return hint;
|
|
102
|
+
const lower = filename.toLowerCase();
|
|
103
|
+
if (lower.endsWith(".docx")) return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
104
|
+
if (lower.endsWith(".doc")) return "application/msword";
|
|
105
|
+
if (lower.endsWith(".pptx")) return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
106
|
+
if (lower.endsWith(".ppt")) return "application/vnd.ms-powerpoint";
|
|
107
|
+
if (lower.endsWith(".xlsx")) return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
108
|
+
if (lower.endsWith(".xls")) return "application/vnd.ms-excel";
|
|
109
|
+
if (lower.endsWith(".odt")) return "application/vnd.oasis.opendocument.text";
|
|
110
|
+
if (lower.endsWith(".odp")) return "application/vnd.oasis.opendocument.presentation";
|
|
111
|
+
if (lower.endsWith(".ods")) return "application/vnd.oasis.opendocument.spreadsheet";
|
|
112
|
+
if (lower.endsWith(".rtf")) return "application/rtf";
|
|
113
|
+
if (lower.endsWith(".csv")) return "text/csv";
|
|
114
|
+
if (lower.endsWith(".txt")) return "text/plain";
|
|
115
|
+
return "application/octet-stream";
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/vendors/gotenberg/client.ts
|
|
119
|
+
/**
|
|
120
|
+
* Gotenberg vendor client.
|
|
121
|
+
* Chromium: HTML/URL → PDF or screenshot.
|
|
122
|
+
* LibreOffice: office documents → PDF (file convert).
|
|
123
|
+
* Host: `new GotenbergClient(auth)`. Agent tools: `fromContext(ctx)`.
|
|
124
|
+
*/
|
|
125
|
+
var GotenbergClient = class GotenbergClient {
|
|
126
|
+
#auth;
|
|
127
|
+
#http;
|
|
128
|
+
#storage;
|
|
129
|
+
constructor(auth, options = {}) {
|
|
130
|
+
const parsed = gotenbergAuthSchema.safeParse(auth);
|
|
131
|
+
if (!parsed.success) throw new ToolError("Invalid Gotenberg auth credentials", {
|
|
132
|
+
code: "bad_auth",
|
|
133
|
+
details: { issues: parsed.error.issues.map((issue) => issue.message) }
|
|
134
|
+
});
|
|
135
|
+
this.#auth = parsed.data;
|
|
136
|
+
const headers = {};
|
|
137
|
+
if (this.#auth.gotenberg_api_username && this.#auth.gotenberg_api_password) headers["Authorization"] = `Basic ${btoa(`${this.#auth.gotenberg_api_username}:${this.#auth.gotenberg_api_password}`)}`;
|
|
138
|
+
this.#http = new HttpService({
|
|
139
|
+
...options,
|
|
140
|
+
baseURL: this.#auth.gotenberg_base_url,
|
|
141
|
+
headers,
|
|
142
|
+
label: "Gotenberg"
|
|
143
|
+
});
|
|
144
|
+
this.#storage = new S3Client(this.#auth.storage, options);
|
|
145
|
+
}
|
|
146
|
+
static fromContext(ctx) {
|
|
147
|
+
const auth = requireAuth(ctx, gotenbergAuthSchema);
|
|
148
|
+
return new GotenbergClient(auth, {
|
|
149
|
+
...ctx.fetch && { fetch: ctx.fetch },
|
|
150
|
+
...ctx.signal && { signal: ctx.signal }
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** Chromium HTML/URL → PDF; store result in object storage. */
|
|
154
|
+
async renderPdf(input) {
|
|
155
|
+
return this.#renderAndStore("pdf", input);
|
|
156
|
+
}
|
|
157
|
+
/** Chromium HTML/URL → PNG screenshot; store result in object storage. */
|
|
158
|
+
async renderScreenshot(input) {
|
|
159
|
+
return this.#renderAndStore("screenshot", input);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* LibreOffice convert: office document in object storage → PDF ArtifactRef.
|
|
163
|
+
* Path: office-to-pdf only (docx/pptx/xlsx/odt/…). Not for HTML layout print.
|
|
164
|
+
*/
|
|
165
|
+
async convert(input) {
|
|
166
|
+
if (input.source.store !== "object") throw new ToolError("Gotenberg convert requires source.store \"object\"", { code: "bad_input" });
|
|
167
|
+
const bytes = await this.#storage.getBytes(input.source.key);
|
|
168
|
+
const filename = officeUploadName(input.source, input.filename);
|
|
169
|
+
const mediaType = guessOfficeMediaType(filename, input.source.media_type);
|
|
170
|
+
const form = new FormData();
|
|
171
|
+
const blob = new Blob([toArrayBuffer(bytes)], { type: mediaType });
|
|
172
|
+
form.append("files", blob, filename);
|
|
173
|
+
const { bytes: outBytes } = await this.#http.bytes("POST", LIBREOFFICE_CONVERT_PATH, {
|
|
174
|
+
label: "Gotenberg libreoffice convert",
|
|
175
|
+
body: form
|
|
176
|
+
});
|
|
177
|
+
const resultKey = officeToPdfResultKey(input.source.key, input.output_key);
|
|
178
|
+
const resultName = filename.replace(/\.[^./]+$/, "") + ".pdf";
|
|
179
|
+
await this.#storage.putBytes(resultKey, outBytes, "application/pdf");
|
|
180
|
+
const result = artifactRefSchema.parse({
|
|
181
|
+
store: "object",
|
|
182
|
+
key: resultKey,
|
|
183
|
+
media_type: "application/pdf",
|
|
184
|
+
filename: resultName,
|
|
185
|
+
byte_length: outBytes.byteLength
|
|
186
|
+
});
|
|
187
|
+
return gotenbergConvertOutputSchema.parse({
|
|
188
|
+
source: input.source,
|
|
189
|
+
result,
|
|
190
|
+
path: "office-to-pdf"
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async convertBatch(input) {
|
|
194
|
+
return runBatchItems(input.items, (item) => this.convert(item));
|
|
195
|
+
}
|
|
196
|
+
async #renderAndStore(kind, input) {
|
|
197
|
+
const form = new FormData();
|
|
198
|
+
appendSource(form, input.source);
|
|
199
|
+
if (kind === "screenshot" && "viewport" in input && input.viewport) {
|
|
200
|
+
form.append("width", String(input.viewport.width));
|
|
201
|
+
form.append("height", String(input.viewport.height));
|
|
202
|
+
if (input.viewport.device_scale_factor !== void 0) form.append("deviceScaleFactor", String(input.viewport.device_scale_factor));
|
|
203
|
+
}
|
|
204
|
+
const path = htmlPath(kind, input.source);
|
|
205
|
+
const { bytes } = await this.#http.bytes("POST", path, {
|
|
206
|
+
label: `Gotenberg ${kind}`,
|
|
207
|
+
body: form
|
|
208
|
+
});
|
|
209
|
+
const mediaType = kind === "pdf" ? "application/pdf" : "image/png";
|
|
210
|
+
const key = defaultRenderKey(kind, input.output_key);
|
|
211
|
+
const filename = input.filename ?? (kind === "pdf" ? "render.pdf" : "render.png");
|
|
212
|
+
await this.#storage.putBytes(key, bytes, mediaType);
|
|
213
|
+
const result = artifactRefSchema.parse({
|
|
214
|
+
store: "object",
|
|
215
|
+
key,
|
|
216
|
+
media_type: mediaType,
|
|
217
|
+
filename,
|
|
218
|
+
byte_length: bytes.byteLength
|
|
219
|
+
});
|
|
220
|
+
return gotenbergRenderOutputSchema.parse({
|
|
221
|
+
result,
|
|
222
|
+
kind
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/vendors/gotenberg/module.ts
|
|
228
|
+
const gotenbergConvertBatchOutputSchema = batchResultSchema(gotenbergConvertOutputSchema);
|
|
229
|
+
const gotenbergRenderPdfTool = defineTool({
|
|
230
|
+
id: "gotenberg-render-pdf",
|
|
231
|
+
name: "gotenbergRenderPdf",
|
|
232
|
+
description: "Render HTML or a URL to a PDF via Chromium. Writes the PDF to object storage and returns an ArtifactRef. Prefer for web layouts; use convert for office documents.",
|
|
233
|
+
inputSchema: gotenbergRenderPdfInputSchema,
|
|
234
|
+
outputSchema: gotenbergRenderOutputSchema,
|
|
235
|
+
sideEffect: "write",
|
|
236
|
+
runtime: "both",
|
|
237
|
+
execute: async (input, ctx) => GotenbergClient.fromContext(ctx).renderPdf(input)
|
|
238
|
+
});
|
|
239
|
+
const gotenbergRenderScreenshotTool = defineTool({
|
|
240
|
+
id: "gotenberg-render-screenshot",
|
|
241
|
+
name: "gotenbergRenderScreenshot",
|
|
242
|
+
description: "Capture a PNG screenshot of HTML or a URL via Chromium. Writes the image to object storage and returns an ArtifactRef.",
|
|
243
|
+
inputSchema: gotenbergRenderScreenshotInputSchema,
|
|
244
|
+
outputSchema: gotenbergRenderOutputSchema,
|
|
245
|
+
sideEffect: "write",
|
|
246
|
+
runtime: "both",
|
|
247
|
+
execute: async (input, ctx) => GotenbergClient.fromContext(ctx).renderScreenshot(input)
|
|
248
|
+
});
|
|
249
|
+
const gotenbergConvertTool = defineTool({
|
|
250
|
+
id: "gotenberg-convert",
|
|
251
|
+
name: "gotenbergConvert",
|
|
252
|
+
description: "Convert an office document ArtifactRef to PDF (path office-to-pdf: docx, pptx, xlsx, odt, …). Not for HTML print layouts. Writes PDF to object storage.",
|
|
253
|
+
inputSchema: gotenbergConvertInputSchema,
|
|
254
|
+
outputSchema: gotenbergConvertOutputSchema,
|
|
255
|
+
sideEffect: "write",
|
|
256
|
+
runtime: "both",
|
|
257
|
+
execute: async (input, ctx) => GotenbergClient.fromContext(ctx).convert(input)
|
|
258
|
+
});
|
|
259
|
+
const gotenbergConvertBatchTool = defineTool({
|
|
260
|
+
id: "gotenberg-convert-batch",
|
|
261
|
+
name: "gotenbergConvertBatch",
|
|
262
|
+
description: "Convert up to 10 office document ArtifactRefs to PDF. Per-item success or error without aborting the batch.",
|
|
263
|
+
inputSchema: gotenbergConvertBatchInputSchema,
|
|
264
|
+
outputSchema: gotenbergConvertBatchOutputSchema,
|
|
265
|
+
sideEffect: "write",
|
|
266
|
+
runtime: "both",
|
|
267
|
+
execute: async (input, ctx) => GotenbergClient.fromContext(ctx).convertBatch(input)
|
|
268
|
+
});
|
|
269
|
+
const gotenbergModule = defineModule({
|
|
270
|
+
id: "gotenberg",
|
|
271
|
+
title: "Gotenberg",
|
|
272
|
+
description: "Gotenberg tools for HTML or URL rendering and office-document-to-PDF conversion. Each successful output is a final ArtifactRef; use the specific render or convert action matching the source format.",
|
|
273
|
+
runtime: "both",
|
|
274
|
+
auth: {
|
|
275
|
+
type: "custom",
|
|
276
|
+
schema: gotenbergAuthSchema
|
|
277
|
+
},
|
|
278
|
+
categories: ["documents", "convert"],
|
|
279
|
+
classification: "standard",
|
|
280
|
+
tags: ["libreoffice", "pdf"],
|
|
281
|
+
tools: [
|
|
282
|
+
gotenbergRenderPdfTool,
|
|
283
|
+
gotenbergRenderScreenshotTool,
|
|
284
|
+
gotenbergConvertTool,
|
|
285
|
+
gotenbergConvertBatchTool
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
//#endregion
|
|
289
|
+
export { gotenbergRenderSourceSchema as _, gotenbergRenderScreenshotTool as a, MAX_HTML_CHARS as c, gotenbergConvertInputSchema as d, gotenbergConvertOutputSchema as f, gotenbergRenderScreenshotInputSchema as g, gotenbergRenderPdfInputSchema as h, gotenbergRenderPdfTool as i, gotenbergAuthSchema as l, gotenbergRenderOutputSchema as m, gotenbergConvertTool as n, GotenbergClient as o, gotenbergConvertPathSchema as p, gotenbergModule as r, MAX_BATCH_CONVERT as s, gotenbergConvertBatchTool as t, gotenbergConvertBatchInputSchema as u, gotenbergViewportSchema as v };
|
|
290
|
+
|
|
291
|
+
//# sourceMappingURL=gotenberg-NuJjxyln.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gotenberg-NuJjxyln.js","names":["#auth","#http","#storage","#renderAndStore"],"sources":["../src/vendors/gotenberg/contracts.ts","../src/vendors/gotenberg/domain.ts","../src/vendors/gotenberg/client.ts","../src/vendors/gotenberg/module.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { artifactRefSchema } from '../../shared/artifact'\nimport { s3AuthSchema } from '../s3'\n\nexport const MAX_HTML_CHARS = 2_000_000\n\nexport const gotenbergAuthSchema = z.object({\n\tgotenberg_base_url: z.url().describe('Self-hosted Gotenberg origin, for example http://localhost:3000'),\n\tgotenberg_api_username: z.string().min(1).optional().describe('Optional basic-auth username'),\n\tgotenberg_api_password: z.string().min(1).optional().describe('Optional basic-auth password'),\n\tstorage: s3AuthSchema.describe('Object storage for rendered ArtifactRef output')\n})\n\nexport type GotenbergAuth = z.infer<typeof gotenbergAuthSchema>\n\nexport const gotenbergViewportSchema = z.object({\n\twidth: z.int().min(1).max(8_000).describe('Viewport width in CSS pixels'),\n\theight: z.int().min(1).max(8_000).describe('Viewport height in CSS pixels'),\n\tdevice_scale_factor: z.number().min(0.1).max(4).optional().describe('Device scale factor (default 1)')\n})\n\nexport const gotenbergRenderSourceSchema = z\n\t.object({\n\t\thtml: z.string().min(1).max(MAX_HTML_CHARS).optional().describe('HTML document body to render'),\n\t\turl: z.url().optional().describe('Absolute http(s) URL to open and render')\n\t})\n\t.refine((v) => Boolean(v.html?.trim() || v.url), {\n\t\tmessage: 'Provide html or url'\n\t})\n\t.refine((v) => !(v.html && v.url), {\n\t\tmessage: 'Provide only one of html or url'\n\t})\n\nexport const gotenbergRenderPdfInputSchema = z.object({\n\tsource: gotenbergRenderSourceSchema.describe('HTML string or URL to print'),\n\toutput_key: z.string().min(1).optional().describe('Object key for the PDF. Defaults under renders/'),\n\tfilename: z.string().min(1).optional().describe('Display filename for the result ArtifactRef')\n})\n\nexport const gotenbergRenderScreenshotInputSchema = z.object({\n\tsource: gotenbergRenderSourceSchema.describe('HTML string or URL to capture'),\n\toutput_key: z.string().min(1).optional().describe('Object key for the PNG. Defaults under renders/'),\n\tfilename: z.string().min(1).optional().describe('Display filename for the result ArtifactRef'),\n\tviewport: gotenbergViewportSchema.optional().describe('Optional screenshot viewport')\n})\n\nexport const gotenbergRenderOutputSchema = z.object({\n\tresult: artifactRefSchema,\n\tkind: z.enum(['pdf', 'screenshot'])\n})\n\n/** Office document → PDF via LibreOffice (not HTML print). */\nexport const gotenbergConvertPathSchema = z.enum(['office-to-pdf']).describe('Closed conversion path')\n\nexport const gotenbergConvertInputSchema = z.object({\n\tsource: artifactRefSchema.describe('Input artifact in object storage (office document)'),\n\tpath: gotenbergConvertPathSchema.default('office-to-pdf').describe('Conversion path (currently office-to-pdf only)'),\n\toutput_key: z\n\t\t.string()\n\t\t.min(1)\n\t\t.optional()\n\t\t.describe('Object key for the PDF result. Defaults to source key with .pdf extension'),\n\tfilename: z.string().min(1).optional().describe('Upload filename when source has none')\n})\n\nexport const gotenbergConvertOutputSchema = z.object({\n\tsource: artifactRefSchema,\n\tresult: artifactRefSchema,\n\tpath: gotenbergConvertPathSchema\n})\n\nexport const MAX_BATCH_CONVERT = 10\n\nexport const gotenbergConvertBatchInputSchema = z.object({\n\titems: z\n\t\t.array(gotenbergConvertInputSchema)\n\t\t.min(1)\n\t\t.max(MAX_BATCH_CONVERT)\n\t\t.describe(`Conversions to run (max ${MAX_BATCH_CONVERT})`)\n})\n\nexport type GotenbergViewport = z.infer<typeof gotenbergViewportSchema>\nexport type GotenbergRenderSource = z.infer<typeof gotenbergRenderSourceSchema>\nexport type GotenbergRenderPdfInput = z.infer<typeof gotenbergRenderPdfInputSchema>\nexport type GotenbergRenderScreenshotInput = z.infer<typeof gotenbergRenderScreenshotInputSchema>\nexport type GotenbergRenderOutput = z.infer<typeof gotenbergRenderOutputSchema>\nexport type GotenbergConvertPath = z.infer<typeof gotenbergConvertPathSchema>\nexport type GotenbergConvertInput = z.infer<typeof gotenbergConvertInputSchema>\nexport type GotenbergConvertOutput = z.infer<typeof gotenbergConvertOutputSchema>\nexport type GotenbergConvertBatchInput = z.infer<typeof gotenbergConvertBatchInputSchema>\n","/**\n * Gotenberg form/path helpers (no HTTP).\n */\n\nimport { ToolError } from '../../core/errors'\nimport type { ArtifactRef } from '../../shared/artifact'\nimport { toArrayBuffer } from '../../shared/bytes'\nimport type { GotenbergRenderSource } from './contracts'\n\nexport function appendSource(form: FormData, source: GotenbergRenderSource): void {\n\tif (source.html) {\n\t\tconst bytes = new TextEncoder().encode(source.html)\n\t\tconst blob = new Blob([toArrayBuffer(bytes)], { type: 'text/html' })\n\t\tform.append('files', blob, 'index.html')\n\t\treturn\n\t}\n\tif (source.url) {\n\t\tform.append('url', source.url)\n\t\treturn\n\t}\n\tthrow new ToolError('Provide html or url', { code: 'bad_input' })\n}\n\nexport function htmlPath(kind: 'pdf' | 'screenshot', source: GotenbergRenderSource): string {\n\tif (source.html) {\n\t\treturn kind === 'pdf' ? '/forms/chromium/convert/html' : '/forms/chromium/screenshot/html'\n\t}\n\treturn kind === 'pdf' ? '/forms/chromium/convert/url' : '/forms/chromium/screenshot/url'\n}\n\nexport function defaultRenderKey(kind: 'pdf' | 'screenshot', outputKey: string | undefined): string {\n\tif (outputKey) return outputKey\n\tconst stamp = Date.now()\n\treturn kind === 'pdf' ? `renders/${stamp}.pdf` : `renders/${stamp}.png`\n}\n\n/** LibreOffice route — office suite docs → PDF. */\nexport const LIBREOFFICE_CONVERT_PATH = '/forms/libreoffice/convert'\n\nexport function basenameFromKey(key: string): string {\n\tconst parts = key.replace(/\\/+$/, '').split('/')\n\tconst last = parts[parts.length - 1]\n\treturn last && last.length > 0 ? last : 'document'\n}\n\nexport function officeUploadName(source: ArtifactRef, filename?: string): string {\n\tif (filename && filename.trim().length > 0) return filename.trim()\n\tif (source.filename && source.filename.trim().length > 0) return source.filename.trim()\n\treturn basenameFromKey(source.key)\n}\n\nexport function officeToPdfResultKey(sourceKey: string, outputKey: string | undefined): string {\n\tif (outputKey) return outputKey\n\tconst base = sourceKey.replace(/\\.[^./]+$/, '')\n\treturn `${base}.pdf`\n}\n\nexport function guessOfficeMediaType(filename: string, hint?: string): string {\n\tif (hint && hint.length > 0) return hint\n\tconst lower = filename.toLowerCase()\n\tif (lower.endsWith('.docx')) return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\n\tif (lower.endsWith('.doc')) return 'application/msword'\n\tif (lower.endsWith('.pptx')) return 'application/vnd.openxmlformats-officedocument.presentationml.presentation'\n\tif (lower.endsWith('.ppt')) return 'application/vnd.ms-powerpoint'\n\tif (lower.endsWith('.xlsx')) return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\n\tif (lower.endsWith('.xls')) return 'application/vnd.ms-excel'\n\tif (lower.endsWith('.odt')) return 'application/vnd.oasis.opendocument.text'\n\tif (lower.endsWith('.odp')) return 'application/vnd.oasis.opendocument.presentation'\n\tif (lower.endsWith('.ods')) return 'application/vnd.oasis.opendocument.spreadsheet'\n\tif (lower.endsWith('.rtf')) return 'application/rtf'\n\tif (lower.endsWith('.csv')) return 'text/csv'\n\tif (lower.endsWith('.txt')) return 'text/plain'\n\treturn 'application/octet-stream'\n}\n","/**\n * Gotenberg vendor client.\n * Chromium: HTML/URL → PDF or screenshot.\n * LibreOffice: office documents → PDF (file convert).\n * Host: `new GotenbergClient(auth)`. Agent tools: `fromContext(ctx)`.\n */\n\nimport { ToolError } from '../../core/errors'\nimport { requireAuth } from '../../core/provider'\nimport type { ToolContext } from '../../core/types'\nimport { artifactRefSchema } from '../../shared/artifact'\nimport { runBatchItems } from '../../shared/batch'\nimport { toArrayBuffer } from '../../shared/bytes'\nimport { HttpService } from '../../transport/http-service'\nimport type { HttpServiceOptions } from '../../transport/http-service'\nimport { S3Client } from '../s3'\nimport type {\n\tGotenbergAuth,\n\tGotenbergConvertBatchInput,\n\tGotenbergConvertInput,\n\tGotenbergConvertOutput,\n\tGotenbergRenderOutput,\n\tGotenbergRenderPdfInput,\n\tGotenbergRenderScreenshotInput\n} from './contracts'\nimport { gotenbergAuthSchema, gotenbergConvertOutputSchema, gotenbergRenderOutputSchema } from './contracts'\nimport {\n\tappendSource,\n\tdefaultRenderKey,\n\tguessOfficeMediaType,\n\thtmlPath,\n\tLIBREOFFICE_CONVERT_PATH,\n\tofficeToPdfResultKey,\n\tofficeUploadName\n} from './domain'\n\nexport type GotenbergClientOptions = Pick<HttpServiceOptions, 'fetch' | 'signal'>\n\nexport class GotenbergClient {\n\treadonly #auth: GotenbergAuth\n\treadonly #http: HttpService\n\treadonly #storage: S3Client\n\n\tconstructor(auth: GotenbergAuth, options: GotenbergClientOptions = {}) {\n\t\tconst parsed = gotenbergAuthSchema.safeParse(auth)\n\t\tif (!parsed.success) {\n\t\t\tthrow new ToolError('Invalid Gotenberg auth credentials', {\n\t\t\t\tcode: 'bad_auth',\n\t\t\t\tdetails: { issues: parsed.error.issues.map((issue) => issue.message) }\n\t\t\t})\n\t\t}\n\t\tthis.#auth = parsed.data\n\t\tconst headers: Record<string, string> = {}\n\t\tif (this.#auth.gotenberg_api_username && this.#auth.gotenberg_api_password) {\n\t\t\tconst token = btoa(`${this.#auth.gotenberg_api_username}:${this.#auth.gotenberg_api_password}`)\n\t\t\theaders['Authorization'] = `Basic ${token}`\n\t\t}\n\t\tthis.#http = new HttpService({\n\t\t\t...options,\n\t\t\tbaseURL: this.#auth.gotenberg_base_url,\n\t\t\theaders,\n\t\t\tlabel: 'Gotenberg'\n\t\t})\n\t\tthis.#storage = new S3Client(this.#auth.storage, options)\n\t}\n\n\tstatic fromContext(ctx: ToolContext): GotenbergClient {\n\t\tconst auth = requireAuth(ctx, gotenbergAuthSchema)\n\t\treturn new GotenbergClient(auth, {\n\t\t\t...(ctx.fetch && { fetch: ctx.fetch }),\n\t\t\t...(ctx.signal && { signal: ctx.signal })\n\t\t})\n\t}\n\n\t/** Chromium HTML/URL → PDF; store result in object storage. */\n\tasync renderPdf(input: GotenbergRenderPdfInput): Promise<GotenbergRenderOutput> {\n\t\treturn this.#renderAndStore('pdf', input)\n\t}\n\n\t/** Chromium HTML/URL → PNG screenshot; store result in object storage. */\n\tasync renderScreenshot(input: GotenbergRenderScreenshotInput): Promise<GotenbergRenderOutput> {\n\t\treturn this.#renderAndStore('screenshot', input)\n\t}\n\n\t/**\n\t * LibreOffice convert: office document in object storage → PDF ArtifactRef.\n\t * Path: office-to-pdf only (docx/pptx/xlsx/odt/…). Not for HTML layout print.\n\t */\n\tasync convert(input: GotenbergConvertInput): Promise<GotenbergConvertOutput> {\n\t\tif (input.source.store !== 'object') {\n\t\t\tthrow new ToolError('Gotenberg convert requires source.store \"object\"', { code: 'bad_input' })\n\t\t}\n\t\t// path is a closed enum (office-to-pdf); future paths branch here.\n\n\t\tconst bytes = await this.#storage.getBytes(input.source.key)\n\t\tconst filename = officeUploadName(input.source, input.filename)\n\t\tconst mediaType = guessOfficeMediaType(filename, input.source.media_type)\n\n\t\tconst form = new FormData()\n\t\tconst blob = new Blob([toArrayBuffer(bytes)], { type: mediaType })\n\t\tform.append('files', blob, filename)\n\n\t\tconst { bytes: outBytes } = await this.#http.bytes('POST', LIBREOFFICE_CONVERT_PATH, {\n\t\t\tlabel: 'Gotenberg libreoffice convert',\n\t\t\tbody: form\n\t\t})\n\n\t\tconst resultKey = officeToPdfResultKey(input.source.key, input.output_key)\n\t\tconst resultName = filename.replace(/\\.[^./]+$/, '') + '.pdf'\n\t\tawait this.#storage.putBytes(resultKey, outBytes, 'application/pdf')\n\n\t\tconst result = artifactRefSchema.parse({\n\t\t\tstore: 'object',\n\t\t\tkey: resultKey,\n\t\t\tmedia_type: 'application/pdf',\n\t\t\tfilename: resultName,\n\t\t\tbyte_length: outBytes.byteLength\n\t\t})\n\n\t\treturn gotenbergConvertOutputSchema.parse({\n\t\t\tsource: input.source,\n\t\t\tresult,\n\t\t\tpath: 'office-to-pdf'\n\t\t})\n\t}\n\n\tasync convertBatch(input: GotenbergConvertBatchInput) {\n\t\treturn runBatchItems(input.items, (item) => this.convert(item))\n\t}\n\n\tasync #renderAndStore(\n\t\tkind: 'pdf' | 'screenshot',\n\t\tinput: GotenbergRenderPdfInput | GotenbergRenderScreenshotInput\n\t): Promise<GotenbergRenderOutput> {\n\t\tconst form = new FormData()\n\t\tappendSource(form, input.source)\n\t\tif (kind === 'screenshot' && 'viewport' in input && input.viewport) {\n\t\t\tform.append('width', String(input.viewport.width))\n\t\t\tform.append('height', String(input.viewport.height))\n\t\t\tif (input.viewport.device_scale_factor !== undefined) {\n\t\t\t\tform.append('deviceScaleFactor', String(input.viewport.device_scale_factor))\n\t\t\t}\n\t\t}\n\n\t\tconst path = htmlPath(kind, input.source)\n\t\tconst { bytes } = await this.#http.bytes('POST', path, {\n\t\t\tlabel: `Gotenberg ${kind}`,\n\t\t\tbody: form\n\t\t})\n\n\t\tconst mediaType = kind === 'pdf' ? 'application/pdf' : 'image/png'\n\t\tconst key = defaultRenderKey(kind, input.output_key)\n\t\tconst filename = input.filename ?? (kind === 'pdf' ? 'render.pdf' : 'render.png')\n\t\tawait this.#storage.putBytes(key, bytes, mediaType)\n\n\t\tconst result = artifactRefSchema.parse({\n\t\t\tstore: 'object',\n\t\t\tkey,\n\t\t\tmedia_type: mediaType,\n\t\t\tfilename,\n\t\t\tbyte_length: bytes.byteLength\n\t\t})\n\t\treturn gotenbergRenderOutputSchema.parse({ result, kind })\n\t}\n}\n","import { defineModule, defineTool } from '../../core/define'\nimport { batchResultSchema } from '../../shared/batch'\nimport { GotenbergClient } from './client'\nimport {\n\tgotenbergAuthSchema,\n\tgotenbergConvertBatchInputSchema,\n\tgotenbergConvertInputSchema,\n\tgotenbergConvertOutputSchema,\n\tgotenbergRenderOutputSchema,\n\tgotenbergRenderPdfInputSchema,\n\tgotenbergRenderScreenshotInputSchema\n} from './contracts'\n\nconst gotenbergConvertBatchOutputSchema = batchResultSchema(gotenbergConvertOutputSchema)\n\nexport const gotenbergRenderPdfTool = defineTool({\n\tid: 'gotenberg-render-pdf',\n\tname: 'gotenbergRenderPdf',\n\tdescription:\n\t\t'Render HTML or a URL to a PDF via Chromium. Writes the PDF to object storage and returns an ArtifactRef. Prefer for web layouts; use convert for office documents.',\n\tinputSchema: gotenbergRenderPdfInputSchema,\n\toutputSchema: gotenbergRenderOutputSchema,\n\tsideEffect: 'write',\n\truntime: 'both',\n\texecute: async (input, ctx) => GotenbergClient.fromContext(ctx).renderPdf(input)\n})\n\nexport const gotenbergRenderScreenshotTool = defineTool({\n\tid: 'gotenberg-render-screenshot',\n\tname: 'gotenbergRenderScreenshot',\n\tdescription:\n\t\t'Capture a PNG screenshot of HTML or a URL via Chromium. Writes the image to object storage and returns an ArtifactRef.',\n\tinputSchema: gotenbergRenderScreenshotInputSchema,\n\toutputSchema: gotenbergRenderOutputSchema,\n\tsideEffect: 'write',\n\truntime: 'both',\n\texecute: async (input, ctx) => GotenbergClient.fromContext(ctx).renderScreenshot(input)\n})\n\nexport const gotenbergConvertTool = defineTool({\n\tid: 'gotenberg-convert',\n\tname: 'gotenbergConvert',\n\tdescription:\n\t\t'Convert an office document ArtifactRef to PDF (path office-to-pdf: docx, pptx, xlsx, odt, …). Not for HTML print layouts. Writes PDF to object storage.',\n\tinputSchema: gotenbergConvertInputSchema,\n\toutputSchema: gotenbergConvertOutputSchema,\n\tsideEffect: 'write',\n\truntime: 'both',\n\texecute: async (input, ctx) => GotenbergClient.fromContext(ctx).convert(input)\n})\n\nexport const gotenbergConvertBatchTool = defineTool({\n\tid: 'gotenberg-convert-batch',\n\tname: 'gotenbergConvertBatch',\n\tdescription:\n\t\t'Convert up to 10 office document ArtifactRefs to PDF. Per-item success or error without aborting the batch.',\n\tinputSchema: gotenbergConvertBatchInputSchema,\n\toutputSchema: gotenbergConvertBatchOutputSchema,\n\tsideEffect: 'write',\n\truntime: 'both',\n\texecute: async (input, ctx) => GotenbergClient.fromContext(ctx).convertBatch(input)\n})\n\nexport const gotenbergModule = defineModule({\n\tid: 'gotenberg',\n\ttitle: 'Gotenberg',\n\tdescription:\n\t\t'Gotenberg tools for HTML or URL rendering and office-document-to-PDF conversion. Each successful output is a final ArtifactRef; use the specific render or convert action matching the source format.',\n\truntime: 'both',\n\tauth: { type: 'custom', schema: gotenbergAuthSchema },\n\tcategories: ['documents', 'convert'],\n\tclassification: 'standard',\n\ttags: ['libreoffice', 'pdf'],\n\ttools: [gotenbergRenderPdfTool, gotenbergRenderScreenshotTool, gotenbergConvertTool, gotenbergConvertBatchTool]\n})\n"],"mappings":";;;;;;;;;;AAKA,MAAa,iBAAiB;AAE9B,MAAa,sBAAsB,EAAE,OAAO;CAC3C,oBAAoB,EAAE,IAAI,CAAC,CAAC,SAAS,iEAAiE;CACtG,wBAAwB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,8BAA8B;CAC5F,wBAAwB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,8BAA8B;CAC5F,SAAS,aAAa,SAAS,gDAAgD;AAChF,CAAC;AAID,MAAa,0BAA0B,EAAE,OAAO;CAC/C,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAK,CAAC,CAAC,SAAS,8BAA8B;CACxE,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAK,CAAC,CAAC,SAAS,+BAA+B;CAC1E,qBAAqB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,iCAAiC;AACtG,CAAC;AAED,MAAa,8BAA8B,EACzC,OAAO;CACP,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC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;CAAyB;AAC/G,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { n as ToolErrorCode } from "../errors-aKhko9T1.js";
|
|
2
|
+
import { a as HttpQueryResult, i as HttpCallOptions, n as HttpBytesOptions, o as HttpService, r as HttpBytesResult, s as HttpServiceOptions, t as HttpBody } from "../http-service-T7E5UjP8.js";
|
|
3
|
+
//#region src/transport/aws-service.d.ts
|
|
4
|
+
type AwsCredentials = {
|
|
5
|
+
accessKeyId: string;
|
|
6
|
+
secretAccessKey: string;
|
|
7
|
+
region: string;
|
|
8
|
+
/** AWS service name for SigV4 (s3, textract, sqs, …). */
|
|
9
|
+
service: string;
|
|
10
|
+
sessionToken?: string;
|
|
11
|
+
};
|
|
12
|
+
type AwsServiceOptions = AwsCredentials & HttpServiceOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Same surface as HttpService (query/bytes/get/post/…).
|
|
15
|
+
* Outbound requests are SigV4-signed; retries off (agent owns retry).
|
|
16
|
+
*/
|
|
17
|
+
declare class AwsService extends HttpService {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(options: AwsServiceOptions);
|
|
20
|
+
/** Query-string presign (does not perform the request). */
|
|
21
|
+
sign(url: string, options?: {
|
|
22
|
+
method?: string;
|
|
23
|
+
signQuery?: boolean;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
method: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/transport/errors.d.ts
|
|
31
|
+
type StatusThrowOptions = {
|
|
32
|
+
allowStatuses?: readonly number[];
|
|
33
|
+
/** When true, non-2xx does not throw. */
|
|
34
|
+
noThrow?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** Map common HTTP status codes to stable ToolError codes. */
|
|
37
|
+
declare function httpErrorCode(status: number): ToolErrorCode;
|
|
38
|
+
declare function throwHttpStatus(operation: string, status: number, retryAfterMs?: number): never;
|
|
39
|
+
/** Parse Retry-After header (seconds or HTTP-date) into milliseconds when possible. */
|
|
40
|
+
declare function retryAfterMsFromHeader(value: string | null): number | undefined;
|
|
41
|
+
/** Default: throw ToolError on non-2xx (404 → not_found). */
|
|
42
|
+
declare function assertHttpStatusOk(label: string, status: number, headers: Headers, options?: StatusThrowOptions): void;
|
|
43
|
+
/** Map ofetch / AbortError / unknown network failures to ToolError. */
|
|
44
|
+
declare function mapTransportNetworkError(error: unknown, label: string): never;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { type HttpBytesOptions as AwsBytesOptions, type HttpBytesOptions, type HttpBytesResult as AwsBytesResult, type HttpBytesResult, type HttpCallOptions as AwsCallOptions, type HttpCallOptions, type AwsCredentials, type HttpQueryResult as AwsQueryResult, type HttpQueryResult, AwsService, type AwsServiceOptions, type HttpBody, HttpService, type HttpServiceOptions, type StatusThrowOptions, assertHttpStatusOk, httpErrorCode, mapTransportNetworkError, retryAfterMsFromHeader, throwHttpStatus };
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/transport/aws-service.ts","../../src/transport/errors.ts"],"mappings":";;;KAWY;EACX;EACA;EACA;;EAEA;EACA;;KAGW,oBAAoB,iBAAiB;;;;;cAapC,mBAAmB;;EAI/B,YAAY,SAAS;;EA4Bf,KACL,aACA;IAAW;IAAiB;MAC1B;IAAU;IAAa;;;;;KC1Df;EACX;;EAEA;;;iBAIe,cAAc,iBAAiB;iBAS/B,gBAAgB,mBAAmB,gBAAgB;;iBAanD,uBAAuB;;iBAavB,mBACf,eACA,gBACA,SAAS,SACT,UAAS;;iBA8BM,yBAAyB,gBAAgB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as retryAfterMsFromHeader, i as mapTransportNetworkError, n as assertHttpStatusOk, o as throwHttpStatus, r as httpErrorCode, t as HttpService } from "../http-service-DDNCO1s4.js";
|
|
2
|
+
import { t as AwsService } from "../aws-service-msttbPrz.js";
|
|
3
|
+
export { AwsService, HttpService, assertHttpStatusOk, httpErrorCode, mapTransportNetworkError, retryAfterMsFromHeader, throwHttpStatus };
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { t as ToolError } from "./errors-DoSpNHvs.js";
|
|
2
|
+
import { isError, isNumber, trimEnd } from "es-toolkit";
|
|
3
|
+
import { FetchError, createFetch } from "ofetch";
|
|
4
|
+
//#region src/transport/errors.ts
|
|
5
|
+
/**
|
|
6
|
+
* HTTP status / network → ToolError for HttpService and AwsService.
|
|
7
|
+
*/
|
|
8
|
+
/** Map common HTTP status codes to stable ToolError codes. */
|
|
9
|
+
function httpErrorCode(status) {
|
|
10
|
+
if (status === 401) return "bad_auth";
|
|
11
|
+
if (status === 403) return "forbidden";
|
|
12
|
+
if (status === 404) return "not_found";
|
|
13
|
+
if (status === 429) return "rate_limited";
|
|
14
|
+
if (status === 413) return "too_large";
|
|
15
|
+
return "upstream";
|
|
16
|
+
}
|
|
17
|
+
function throwHttpStatus(operation, status, retryAfterMs) {
|
|
18
|
+
const code = httpErrorCode(status);
|
|
19
|
+
throw new ToolError(`${operation} failed with HTTP ${status}`, {
|
|
20
|
+
code,
|
|
21
|
+
retryable: status >= 500 || status === 429,
|
|
22
|
+
details: {
|
|
23
|
+
status,
|
|
24
|
+
...retryAfterMs !== void 0 && { retry_after_ms: retryAfterMs }
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Parse Retry-After header (seconds or HTTP-date) into milliseconds when possible. */
|
|
29
|
+
function retryAfterMsFromHeader(value) {
|
|
30
|
+
if (value === null || value.length === 0) return void 0;
|
|
31
|
+
const asSeconds = Number.parseInt(value, 10);
|
|
32
|
+
if (Number.isFinite(asSeconds) && asSeconds >= 0) return asSeconds * 1e3;
|
|
33
|
+
const asDate = Date.parse(value);
|
|
34
|
+
if (Number.isFinite(asDate)) {
|
|
35
|
+
const delta = asDate - Date.now();
|
|
36
|
+
return delta > 0 ? delta : 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Default: throw ToolError on non-2xx (404 → not_found). */
|
|
40
|
+
function assertHttpStatusOk(label, status, headers, options = {}) {
|
|
41
|
+
if (options.noThrow === true) return;
|
|
42
|
+
if (status >= 200 && status < 300) return;
|
|
43
|
+
if (options.allowStatuses && options.allowStatuses.includes(status)) return;
|
|
44
|
+
if (status === 404) throw new ToolError("Not found", {
|
|
45
|
+
code: "not_found",
|
|
46
|
+
details: { status }
|
|
47
|
+
});
|
|
48
|
+
throwHttpStatus(label, status, retryAfterMsFromHeader(headers.get("retry-after")));
|
|
49
|
+
}
|
|
50
|
+
/** True if error or any nested `cause` is an AbortError (ofetch wraps abort in FetchError). */
|
|
51
|
+
function isAbortErrorChain(error) {
|
|
52
|
+
let current = error;
|
|
53
|
+
const seen = /* @__PURE__ */ new Set();
|
|
54
|
+
while (current !== void 0 && current !== null && !seen.has(current)) {
|
|
55
|
+
seen.add(current);
|
|
56
|
+
if (isError(current) && (current.name === "AbortError" || current.name === "TimeoutError")) return true;
|
|
57
|
+
if (isError(current) && "cause" in current) {
|
|
58
|
+
current = current.cause;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/** Map ofetch / AbortError / unknown network failures to ToolError. */
|
|
66
|
+
function mapTransportNetworkError(error, label) {
|
|
67
|
+
if (error instanceof ToolError) throw error;
|
|
68
|
+
if (isAbortErrorChain(error)) throw new ToolError(`${label} request was aborted`, {
|
|
69
|
+
code: "timeout",
|
|
70
|
+
retryable: true,
|
|
71
|
+
cause: error
|
|
72
|
+
});
|
|
73
|
+
if (error instanceof FetchError) {
|
|
74
|
+
const status = error.statusCode ?? error.response?.status;
|
|
75
|
+
if (isNumber(status) && Number.isFinite(status)) throwHttpStatus(label, status, retryAfterMsFromHeader(error.response?.headers.get("retry-after") ?? null));
|
|
76
|
+
throw new ToolError(error.message || `${label} request failed`, {
|
|
77
|
+
code: "upstream",
|
|
78
|
+
retryable: true,
|
|
79
|
+
cause: error
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
throw new ToolError(`${label} request failed`, {
|
|
83
|
+
code: "upstream",
|
|
84
|
+
retryable: true,
|
|
85
|
+
cause: error
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/transport/http-service.ts
|
|
90
|
+
/**
|
|
91
|
+
* Shared HTTP transport (ofetch under the hood).
|
|
92
|
+
* Product clients construct this and call query/bytes/get/post/….
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* HTTP client: query (parsed), bytes, get/post/put/patch/delete/head.
|
|
96
|
+
* Non-2xx → ToolError by default.
|
|
97
|
+
*/
|
|
98
|
+
var HttpService = class {
|
|
99
|
+
#http;
|
|
100
|
+
#defaultLabel;
|
|
101
|
+
#defaultSignal;
|
|
102
|
+
constructor(options = {}) {
|
|
103
|
+
this.#defaultLabel = options.label ?? "HTTP";
|
|
104
|
+
this.#defaultSignal = options.signal;
|
|
105
|
+
this.#http = createOfetch(options);
|
|
106
|
+
}
|
|
107
|
+
/** Shared ofetch.raw + status assert + error map. */
|
|
108
|
+
async #raw(method, path, options, extra) {
|
|
109
|
+
const label = options.label ?? this.#defaultLabel;
|
|
110
|
+
try {
|
|
111
|
+
const res = await this.#http.raw(path, {
|
|
112
|
+
signal: this.#defaultSignal ?? null,
|
|
113
|
+
method,
|
|
114
|
+
...options,
|
|
115
|
+
...extra
|
|
116
|
+
});
|
|
117
|
+
assertHttpStatusOk(label, res.status, res.headers, options);
|
|
118
|
+
return {
|
|
119
|
+
status: res.status,
|
|
120
|
+
ok: res.ok,
|
|
121
|
+
headers: res.headers,
|
|
122
|
+
url: res.url,
|
|
123
|
+
data: res._data
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
mapTransportNetworkError(error, label);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Parsed body (JSON/text). ofetch parses JSON responses by default. */
|
|
130
|
+
async query(method, path, options = {}) {
|
|
131
|
+
return this.#raw(method, path, options);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Binary body. `maxBytes` switches to streaming and cancels before an
|
|
135
|
+
* oversized response is materialized.
|
|
136
|
+
*/
|
|
137
|
+
async bytes(method, path, options = {}) {
|
|
138
|
+
const { maxBytes, ...requestOptions } = options;
|
|
139
|
+
if (maxBytes !== void 0 && (!Number.isSafeInteger(maxBytes) || maxBytes < 0)) throw new ToolError("Response byte limit must be a non-negative safe integer", { code: "bad_input" });
|
|
140
|
+
const res = await this.#raw(method, path, requestOptions, { responseType: maxBytes === void 0 ? "arrayBuffer" : "stream" });
|
|
141
|
+
if (maxBytes === void 0) return {
|
|
142
|
+
...res,
|
|
143
|
+
bytes: new Uint8Array(res.data)
|
|
144
|
+
};
|
|
145
|
+
const label = options.label ?? this.#defaultLabel;
|
|
146
|
+
try {
|
|
147
|
+
const bytes = await readBoundedBytes(res.data, res.headers, maxBytes, label);
|
|
148
|
+
return {
|
|
149
|
+
...res,
|
|
150
|
+
bytes
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
mapTransportNetworkError(error, label);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
get(path, options = {}) {
|
|
157
|
+
return this.query("GET", path, options);
|
|
158
|
+
}
|
|
159
|
+
post(path, body, options = {}) {
|
|
160
|
+
return this.query("POST", path, body === void 0 ? options : {
|
|
161
|
+
...options,
|
|
162
|
+
body
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
put(path, body, options = {}) {
|
|
166
|
+
return this.query("PUT", path, body === void 0 ? options : {
|
|
167
|
+
...options,
|
|
168
|
+
body
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
patch(path, body, options = {}) {
|
|
172
|
+
return this.query("PATCH", path, body === void 0 ? options : {
|
|
173
|
+
...options,
|
|
174
|
+
body
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
delete(path, options = {}) {
|
|
178
|
+
return this.query("DELETE", path, options);
|
|
179
|
+
}
|
|
180
|
+
head(path, options = {}) {
|
|
181
|
+
return this.query("HEAD", path, options);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
function isReadableByteStream(value) {
|
|
185
|
+
return value instanceof ReadableStream;
|
|
186
|
+
}
|
|
187
|
+
function contentLength(headers) {
|
|
188
|
+
const value = headers.get("content-length");
|
|
189
|
+
if (value === null || !/^\d+$/.test(value)) return void 0;
|
|
190
|
+
const parsed = Number(value);
|
|
191
|
+
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
192
|
+
}
|
|
193
|
+
function responseTooLarge(label, maxBytes, observedBytes) {
|
|
194
|
+
throw new ToolError(`${label} response exceeds byte limit`, {
|
|
195
|
+
code: "too_large",
|
|
196
|
+
details: {
|
|
197
|
+
max_bytes: maxBytes,
|
|
198
|
+
content_length: observedBytes
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async function readBoundedBytes(data, headers, maxBytes, label) {
|
|
203
|
+
const declaredLength = contentLength(headers);
|
|
204
|
+
if (declaredLength !== void 0 && declaredLength > maxBytes) {
|
|
205
|
+
if (isReadableByteStream(data)) try {
|
|
206
|
+
await data.cancel();
|
|
207
|
+
} catch {}
|
|
208
|
+
responseTooLarge(label, maxBytes, declaredLength);
|
|
209
|
+
}
|
|
210
|
+
if (data === null || data === void 0) return /* @__PURE__ */ new Uint8Array();
|
|
211
|
+
if (!isReadableByteStream(data)) throw new ToolError(`${label} returned an invalid byte stream`, { code: "upstream" });
|
|
212
|
+
const reader = data.getReader();
|
|
213
|
+
const chunks = [];
|
|
214
|
+
let total = 0;
|
|
215
|
+
try {
|
|
216
|
+
while (true) {
|
|
217
|
+
const chunk = await reader.read();
|
|
218
|
+
if (chunk.done) break;
|
|
219
|
+
if (!(chunk.value instanceof Uint8Array)) throw new ToolError(`${label} returned an invalid byte chunk`, { code: "upstream" });
|
|
220
|
+
total += chunk.value.byteLength;
|
|
221
|
+
if (total > maxBytes) {
|
|
222
|
+
try {
|
|
223
|
+
await reader.cancel();
|
|
224
|
+
} catch {}
|
|
225
|
+
responseTooLarge(label, maxBytes, declaredLength ?? total);
|
|
226
|
+
}
|
|
227
|
+
chunks.push(chunk.value);
|
|
228
|
+
}
|
|
229
|
+
} finally {
|
|
230
|
+
reader.releaseLock();
|
|
231
|
+
}
|
|
232
|
+
const bytes = new Uint8Array(total);
|
|
233
|
+
let offset = 0;
|
|
234
|
+
for (const chunk of chunks) {
|
|
235
|
+
bytes.set(chunk, offset);
|
|
236
|
+
offset += chunk.byteLength;
|
|
237
|
+
}
|
|
238
|
+
return bytes;
|
|
239
|
+
}
|
|
240
|
+
function createOfetch(options) {
|
|
241
|
+
const defaults = {
|
|
242
|
+
...options,
|
|
243
|
+
retry: false,
|
|
244
|
+
ignoreResponseError: true
|
|
245
|
+
};
|
|
246
|
+
if (defaults.baseURL) defaults.baseURL = trimEnd(defaults.baseURL, "/");
|
|
247
|
+
const createOptions = { defaults };
|
|
248
|
+
if (options.fetch) Object.assign(createOptions, { fetch: options.fetch });
|
|
249
|
+
return createFetch(createOptions);
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
export { retryAfterMsFromHeader as a, mapTransportNetworkError as i, assertHttpStatusOk as n, throwHttpStatus as o, httpErrorCode as r, HttpService as t };
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=http-service-DDNCO1s4.js.map
|