@ganju/utils 0.0.6 → 0.0.9

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.
Files changed (46) hide show
  1. package/dist/attachment.d.ts.map +1 -1
  2. package/dist/chunking.d.ts.map +1 -1
  3. package/dist/chunking.js +9 -3
  4. package/dist/coerce.d.ts.map +1 -1
  5. package/dist/coerce.js +4 -1
  6. package/dist/constants.d.ts +27 -3
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +157 -22
  9. package/dist/containmentToken.d.ts +25 -0
  10. package/dist/containmentToken.d.ts.map +1 -0
  11. package/dist/containmentToken.js +81 -0
  12. package/dist/crypto.d.ts.map +1 -1
  13. package/dist/crypto.js +4 -1
  14. package/dist/getEnv.d.ts.map +1 -1
  15. package/dist/index.d.ts +34 -6
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +7 -0
  18. package/dist/llmBaseUrl.d.ts +39 -0
  19. package/dist/llmBaseUrl.d.ts.map +1 -0
  20. package/dist/llmBaseUrl.js +65 -0
  21. package/dist/localizeZodIssue.d.ts.map +1 -1
  22. package/dist/localizeZodIssue.js +6 -0
  23. package/dist/oauth.d.ts.map +1 -1
  24. package/dist/parseHttpError.d.ts.map +1 -1
  25. package/dist/schema.d.ts +2 -2
  26. package/dist/schema.d.ts.map +1 -1
  27. package/dist/schema.js +32 -8
  28. package/dist/sources.d.ts.map +1 -1
  29. package/dist/vendorError.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/attachment.ts +2 -1
  32. package/src/chunking.ts +9 -3
  33. package/src/coerce.ts +4 -1
  34. package/src/constants.ts +178 -22
  35. package/src/containmentToken.ts +146 -0
  36. package/src/crypto.ts +6 -2
  37. package/src/getEnv.ts +1 -4
  38. package/src/index.ts +16 -0
  39. package/src/llmBaseUrl.ts +65 -0
  40. package/src/localizeZodIssue.ts +6 -0
  41. package/src/oauth.ts +1 -3
  42. package/src/parseHttpError.ts +3 -1
  43. package/src/schema.ts +63 -11
  44. package/src/slackSend.ts +10 -10
  45. package/src/sources.ts +7 -2
  46. package/src/vendorError.ts +4 -1
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import type { WhatsappSendRequest, WhatsappSendResponse, WhatsappSendRemoteResou
11
11
  import { JsonSchema } from './jsonSchemaToZodShape';
12
12
  import type { SchemaViolation } from './jsonSchemaToZodShape';
13
13
  import type { CustomCodeTokenPayload } from './customCodeToken';
14
+ import type { ContainmentTokenPayload } from './containmentToken';
14
15
  import type { OAuthProviderConfig } from './oauthProviders';
15
16
  import type { ExposableResource } from './exposedResource';
16
17
  import type { CustomCodeProject, ProjectPathIssue } from './customCodeProject';
@@ -829,8 +830,8 @@ export declare const utils: {
829
830
  "openai-compatible": "openai-compatible";
830
831
  }>;
831
832
  apiKey: import("zod").ZodString;
832
- model: import("zod").ZodString;
833
833
  baseUrl: import("zod").ZodUnion<[import("zod").ZodOptional<import("zod").ZodURL>, import("zod").ZodLiteral<"">]>;
834
+ model: import("zod").ZodString;
834
835
  systemPrompt: import("zod").ZodOptional<import("zod").ZodString>;
835
836
  }, import("zod/v4/core").$strip>;
836
837
  ORGANIZATION_UPDATE_LLM: import("zod").ZodObject<{
@@ -860,8 +861,8 @@ export declare const utils: {
860
861
  "openai-compatible": "openai-compatible";
861
862
  }>>;
862
863
  apiKey: import("zod").ZodOptional<import("zod").ZodString>;
863
- model: import("zod").ZodOptional<import("zod").ZodString>;
864
864
  baseUrl: import("zod").ZodNullable<import("zod").ZodUnion<[import("zod").ZodOptional<import("zod").ZodURL>, import("zod").ZodLiteral<"">]>>;
865
+ model: import("zod").ZodOptional<import("zod").ZodString>;
865
866
  systemPrompt: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodString>>;
866
867
  }, import("zod/v4/core").$strip>;
867
868
  ORGANIZATION_REMOVE_LLM: import("zod").ZodObject<{
@@ -1795,6 +1796,9 @@ export declare const utils: {
1795
1796
  PRICING_INCLUDED_EMBEDDED_GB: number;
1796
1797
  PRICING_MESSAGE_PER_1K_USD: number;
1797
1798
  PRICING_EMBEDDED_PER_GB_USD: number;
1799
+ PRICING_INCLUDED_TOOL_CALLS: number;
1800
+ PRICING_TOOL_CALL_PER_M_USD: number;
1801
+ PRICING_TOOL_CALL_HARD_CAP: number;
1798
1802
  PRICING_CUSTOM_DOMAIN_USD: number;
1799
1803
  PLAN_FEATURE_ORGANIZATION: "organization";
1800
1804
  PLAN_FEATURE_PROJECT: "project";
@@ -1808,10 +1812,17 @@ export declare const utils: {
1808
1812
  PLAN_FEATURE_RAW_STORAGE: "rawStorage";
1809
1813
  PLAN_FEATURE_EMBEDDED_STORAGE: "embeddedStorage";
1810
1814
  PLAN_FEATURE_MESSAGE: "message";
1815
+ PLAN_FEATURE_TOOL_CALL: "toolCall";
1811
1816
  PLAN_LIMIT_ERROR_CODE: string;
1812
- STRIPE_METER_MESSAGES: string;
1813
- STRIPE_METER_SHARED_MESSAGES: string;
1814
- STRIPE_METER_EMBEDDED: string;
1817
+ BILLING_METER_MESSAGES: string;
1818
+ BILLING_METER_SHARED_MESSAGES: string;
1819
+ BILLING_METER_EMBEDDED: string;
1820
+ BILLING_METER_TOOL_CALLS: string;
1821
+ BILLING_METER_UNITS_KEY: string;
1822
+ POLAR_API_BASE: string;
1823
+ POLAR_SANDBOX_API_BASE: string;
1824
+ POLAR_SERVER_SANDBOX: "sandbox";
1825
+ POLAR_SERVER_PRODUCTION: "production";
1815
1826
  CONSENT_DOCUMENT_TERMS: "terms";
1816
1827
  CONSENT_DOCUMENT_PRIVACY: "privacy";
1817
1828
  CONSENT_DOCUMENTS: ("terms" | "privacy")[];
@@ -1830,6 +1841,15 @@ export declare const utils: {
1830
1841
  CRON_HOURLY: string;
1831
1842
  CRON_ERROR_ALERTS: string;
1832
1843
  ALERT_STATE_KEY_ERROR_LOG: string;
1844
+ ALERT_STATE_KEY_TOOL_CALLS: string;
1845
+ ALERT_TOOL_CALL_SURGE: number;
1846
+ ALERT_TOOL_CALL_CAP_FRACTION: number;
1847
+ ALERT_TOOL_CALL_COOLDOWN_HOURS: number;
1848
+ ALERT_TOOL_CALL_MAX_ROWS: number;
1849
+ CONTAINMENT_TOKEN_VERSION: string;
1850
+ CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE: string;
1851
+ CONTAINMENT_TOKEN_TTL_MS: number;
1852
+ CONTAINMENT_PATH: string;
1833
1853
  ALERT_MIN_STATUS: number;
1834
1854
  ALERT_MAX_ROWS: number;
1835
1855
  ALERT_MAX_GROUPS: number;
@@ -2051,6 +2071,9 @@ export declare const utils: {
2051
2071
  model: string;
2052
2072
  label: string;
2053
2073
  }[];
2074
+ LLM_CATALOG_CUSTOM_KEY: string;
2075
+ LLM_BASE_URL_REQUIRED_MESSAGE: string;
2076
+ LLM_BASE_URL_INVALID_MESSAGE: string;
2054
2077
  LLM_SYSTEM_DEFAULT: string;
2055
2078
  MAX_TOOL_LOOPS: number;
2056
2079
  CHANNEL_HISTORY_LIMIT: number;
@@ -2392,6 +2415,8 @@ export declare const utils: {
2392
2415
  customCodePreviewScriptName: (artifactId: string) => string;
2393
2416
  customCodeUploadName: (artifactId: string) => string;
2394
2417
  customCodePreviewUploadName: (artifactId: string) => string;
2418
+ mintContainmentToken: (organizationId: string, secret: string, issuedAt?: number, ttlMs?: number) => Promise<string>;
2419
+ verifyContainmentToken: (token: string, secret: string, now?: number) => Promise<ContainmentTokenPayload | null>;
2395
2420
  oauthProviders: Record<string, OAuthProviderConfig>;
2396
2421
  resolveAttachment: (resource: AttachmentResource, readObject: (key: string) => Promise<ArrayBuffer | null>, verb?: "attach" | "upload") => Promise<ResolveAttachmentResult>;
2397
2422
  isExposedResource: (resource: ExposableResource) => boolean;
@@ -2406,6 +2431,9 @@ export declare const utils: {
2406
2431
  projectPathIssue: (path: string, taken?: Iterable<string>) => ProjectPathIssue | null;
2407
2432
  ipv4InPrivateRange: (host: string) => boolean;
2408
2433
  isBlockedHost: (hostname: string) => boolean;
2434
+ requiresLlmBaseUrl: (provider?: string | null) => boolean;
2435
+ isAllowedLlmBaseUrl: (value: string) => boolean;
2436
+ llmBaseUrlIssue: (provider?: string | null, baseUrl?: string | null) => string | null;
2409
2437
  validateMessageVariables: (messages: Array<{
2410
2438
  role: string;
2411
2439
  content: string;
@@ -2888,5 +2916,5 @@ export declare const utils: {
2888
2916
  PlanLimitError: typeof PlanLimitError;
2889
2917
  isPlanLimitError: (error: unknown) => error is PlanLimitError;
2890
2918
  };
2891
- export type { MintedAccessToken, CustomCodeProject, ProjectPathIssue, CatalogGroup, CatalogTool, CatalogToolDescriptor, ToolGroupKey, ToolKey, CalendarConfigField, JsonSchema, SchemaViolation, MimeAttachment, MimeMessageInput, GmailOperation, GmailSendRequest, GmailSendResponse, OutlookOperation, OutlookSendRequest, OutlookSendResponse, SlackOperation, SlackSendRequest, SlackSendResponse, SlackSendRemoteResourceRequest, TelegramSendRequest, TelegramSendResponse, TelegramSendRemoteResourceRequest, DiscordSendRequest, DiscordSendResponse, DiscordSendRemoteResourceRequest, WhatsappSendRequest, WhatsappSendResponse, WhatsappSendRemoteResourceRequest, EnvSource, Separator, ChunkMetadata, PreparedChunk, ExtractedDocument, ExtractedDocumentMetadata, ExtractedDocumentSource, RateLimitRetryOptions, QueueBatchLike, QueueMessageLike, ProcessQueueBatchHandlers, ChannelNotifier, ToolStatusEvent, BufferedChannelMessage, ChannelBufferEnvelope, ChannelBufferFlush, Source, ResourceUrlContext, SourceButton, RefreshOAuthTokenInput, RefreshedOAuthToken, HttpEndpointToolConfig, McpProxyToolConfig, McpProxyDiscoveredTool, McpProxyDiscoveredResource, McpProxyDiscoveredPrompt, McpProxyDiscovery, CustomCodeToolConfig, CustomCodeToolManifest, CustomCodeManifest, CustomCodeSendFile, CustomCodeCreateResource, CustomCodeTokenPayload, OAuthProviderConfig, AttachmentResource, ResolvedAttachment, ResolveAttachmentResult, ExposableResource, PlanLimitDetails, PlanLimits };
2919
+ export type { MintedAccessToken, CustomCodeProject, ProjectPathIssue, CatalogGroup, CatalogTool, CatalogToolDescriptor, ToolGroupKey, ToolKey, CalendarConfigField, JsonSchema, SchemaViolation, MimeAttachment, MimeMessageInput, GmailOperation, GmailSendRequest, GmailSendResponse, OutlookOperation, OutlookSendRequest, OutlookSendResponse, SlackOperation, SlackSendRequest, SlackSendResponse, SlackSendRemoteResourceRequest, TelegramSendRequest, TelegramSendResponse, TelegramSendRemoteResourceRequest, DiscordSendRequest, DiscordSendResponse, DiscordSendRemoteResourceRequest, WhatsappSendRequest, WhatsappSendResponse, WhatsappSendRemoteResourceRequest, EnvSource, Separator, ChunkMetadata, PreparedChunk, ExtractedDocument, ExtractedDocumentMetadata, ExtractedDocumentSource, RateLimitRetryOptions, QueueBatchLike, QueueMessageLike, ProcessQueueBatchHandlers, ChannelNotifier, ToolStatusEvent, BufferedChannelMessage, ChannelBufferEnvelope, ChannelBufferFlush, Source, ResourceUrlContext, SourceButton, RefreshOAuthTokenInput, RefreshedOAuthToken, HttpEndpointToolConfig, McpProxyToolConfig, McpProxyDiscoveredTool, McpProxyDiscoveredResource, McpProxyDiscoveredPrompt, McpProxyDiscovery, CustomCodeToolConfig, CustomCodeToolManifest, CustomCodeManifest, CustomCodeSendFile, CustomCodeCreateResource, CustomCodeTokenPayload, ContainmentTokenPayload, OAuthProviderConfig, AttachmentResource, ResolvedAttachment, ResolveAttachmentResult, ExposableResource, PlanLimitDetails, PlanLimits };
2892
2920
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAA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,oBAAoB,EACpB,iCAAiC,EACjC,SAAS,EACT,SAAS,EACT,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,EACN,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACX,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAyCvD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,iCAAiC,EAClC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,gBAAgB,EACh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M,EACN,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACX,CAAC"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ const validateMessageVariables_1 = require("./validateMessageVariables");
18
18
  const jsonSchemaToZodShape_1 = require("./jsonSchemaToZodShape");
19
19
  const mcpProxy_1 = require("./mcpProxy");
20
20
  const customCodeToken_1 = require("./customCodeToken");
21
+ const containmentToken_1 = require("./containmentToken");
21
22
  const oauthProviders_1 = require("./oauthProviders");
22
23
  const attachment_1 = require("./attachment");
23
24
  const exposedResource_1 = require("./exposedResource");
@@ -25,6 +26,7 @@ const vendorError_1 = require("./vendorError");
25
26
  const deadline_1 = require("./deadline");
26
27
  const customCodeProject_1 = require("./customCodeProject");
27
28
  const ssrf_1 = require("./ssrf");
29
+ const llmBaseUrl_1 = require("./llmBaseUrl");
28
30
  const formatRelative_1 = require("./formatRelative");
29
31
  const formatRelativeTime_1 = require("./formatRelativeTime");
30
32
  const languageCookieDomain_1 = require("./languageCookieDomain");
@@ -93,6 +95,8 @@ exports.utils = {
93
95
  customCodePreviewScriptName: customCodeToken_1.customCodePreviewScriptName,
94
96
  customCodeUploadName: customCodeToken_1.customCodeUploadName,
95
97
  customCodePreviewUploadName: customCodeToken_1.customCodePreviewUploadName,
98
+ mintContainmentToken: containmentToken_1.mintContainmentToken,
99
+ verifyContainmentToken: containmentToken_1.verifyContainmentToken,
96
100
  oauthProviders: oauthProviders_1.oauthProviders,
97
101
  resolveAttachment: attachment_1.resolveAttachment,
98
102
  isExposedResource: exposedResource_1.isExposedResource,
@@ -107,6 +111,9 @@ exports.utils = {
107
111
  projectPathIssue: customCodeProject_1.projectPathIssue,
108
112
  ipv4InPrivateRange: ssrf_1.ipv4InPrivateRange,
109
113
  isBlockedHost: ssrf_1.isBlockedHost,
114
+ requiresLlmBaseUrl: llmBaseUrl_1.requiresLlmBaseUrl,
115
+ isAllowedLlmBaseUrl: llmBaseUrl_1.isAllowedLlmBaseUrl,
116
+ llmBaseUrlIssue: llmBaseUrl_1.llmBaseUrlIssue,
110
117
  validateMessageVariables: validateMessageVariables_1.validateMessageVariables,
111
118
  formatRelative: formatRelative_1.formatRelative,
112
119
  formatRelativeTime: formatRelativeTime_1.formatRelativeTime,
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The rules an `organization_llm.base_url` has to satisfy, in one place.
3
+ *
4
+ * Two write paths need them and neither can see the whole picture alone: the
5
+ * create schema validates a complete payload, while an update is a partial, so
6
+ * the provider may arrive in the request and the base URL may only exist on the
7
+ * stored row. Keeping the rules here means the two can't drift into disagreeing
8
+ * about what a valid row is — the same reason every other write in this package
9
+ * goes through a shared validator rather than an inline check.
10
+ */
11
+ /**
12
+ * Which providers need a base URL of their own.
13
+ *
14
+ * Every other provider has an endpoint baked into its SDK. `openai-compatible`
15
+ * has none: it is the escape hatch for services that merely speak the OpenAI
16
+ * protocol, so without a base URL the adapter would send the customer's key to
17
+ * `api.openai.com` and fail somewhere far from the form they typed it into.
18
+ */
19
+ export declare const requiresLlmBaseUrl: (provider?: string | null) => boolean;
20
+ /**
21
+ * Whether a base URL is safe to send a request to.
22
+ *
23
+ * This is an outbound fetch target chosen by a customer, on a worker holding
24
+ * their decrypted API key, so it gets the same screening as every other
25
+ * caller-supplied URL: `https` only, because the key travels in a header, and
26
+ * no loopback, private or link-local host. The Workers runtime can't resolve
27
+ * DNS, so — as everywhere else `isBlockedHost` is used — this screens literal
28
+ * hosts and IPs and is not a defense against DNS rebinding.
29
+ */
30
+ export declare const isAllowedLlmBaseUrl: (value: string) => boolean;
31
+ /**
32
+ * Both rules against one provider/base-URL pair: the message to reject with, or
33
+ * `null` when the pair is acceptable. The messages are constants so
34
+ * `localizeZodIssue` can translate them, and both carry a word `matchStatus`
35
+ * recognises — the update path throws this as a plain Error rather than a
36
+ * ZodError, and an unrecognised message there answers 500 where it means 400.
37
+ */
38
+ export declare const llmBaseUrlIssue: (provider?: string | null, baseUrl?: string | null) => string | null;
39
+ //# sourceMappingURL=llmBaseUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmBaseUrl.d.ts","sourceRoot":"","sources":["../src/llmBaseUrl.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,GAAG,IAAI,KAAG,OACP,CAAC;AAExD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,OASnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,WAAW,MAAM,GAAG,IAAI,EACxB,UAAU,MAAM,GAAG,IAAI,KACtB,MAAM,GAAG,IAQX,CAAC"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.llmBaseUrlIssue = exports.isAllowedLlmBaseUrl = exports.requiresLlmBaseUrl = void 0;
4
+ const constants_1 = require("./constants");
5
+ const ssrf_1 = require("./ssrf");
6
+ /**
7
+ * The rules an `organization_llm.base_url` has to satisfy, in one place.
8
+ *
9
+ * Two write paths need them and neither can see the whole picture alone: the
10
+ * create schema validates a complete payload, while an update is a partial, so
11
+ * the provider may arrive in the request and the base URL may only exist on the
12
+ * stored row. Keeping the rules here means the two can't drift into disagreeing
13
+ * about what a valid row is — the same reason every other write in this package
14
+ * goes through a shared validator rather than an inline check.
15
+ */
16
+ /**
17
+ * Which providers need a base URL of their own.
18
+ *
19
+ * Every other provider has an endpoint baked into its SDK. `openai-compatible`
20
+ * has none: it is the escape hatch for services that merely speak the OpenAI
21
+ * protocol, so without a base URL the adapter would send the customer's key to
22
+ * `api.openai.com` and fail somewhere far from the form they typed it into.
23
+ */
24
+ const requiresLlmBaseUrl = (provider) => provider === constants_1.constants.LLM_PROVIDER_OPENAI_COMPATIBLE;
25
+ exports.requiresLlmBaseUrl = requiresLlmBaseUrl;
26
+ /**
27
+ * Whether a base URL is safe to send a request to.
28
+ *
29
+ * This is an outbound fetch target chosen by a customer, on a worker holding
30
+ * their decrypted API key, so it gets the same screening as every other
31
+ * caller-supplied URL: `https` only, because the key travels in a header, and
32
+ * no loopback, private or link-local host. The Workers runtime can't resolve
33
+ * DNS, so — as everywhere else `isBlockedHost` is used — this screens literal
34
+ * hosts and IPs and is not a defense against DNS rebinding.
35
+ */
36
+ const isAllowedLlmBaseUrl = (value) => {
37
+ let parsed;
38
+ try {
39
+ parsed = new URL(value);
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ if (parsed.protocol !== 'https:')
45
+ return false;
46
+ return !(0, ssrf_1.isBlockedHost)(parsed.hostname);
47
+ };
48
+ exports.isAllowedLlmBaseUrl = isAllowedLlmBaseUrl;
49
+ /**
50
+ * Both rules against one provider/base-URL pair: the message to reject with, or
51
+ * `null` when the pair is acceptable. The messages are constants so
52
+ * `localizeZodIssue` can translate them, and both carry a word `matchStatus`
53
+ * recognises — the update path throws this as a plain Error rather than a
54
+ * ZodError, and an unrecognised message there answers 500 where it means 400.
55
+ */
56
+ const llmBaseUrlIssue = (provider, baseUrl) => {
57
+ if ((0, exports.requiresLlmBaseUrl)(provider) && !baseUrl) {
58
+ return constants_1.constants.LLM_BASE_URL_REQUIRED_MESSAGE;
59
+ }
60
+ if (baseUrl && !(0, exports.isAllowedLlmBaseUrl)(baseUrl)) {
61
+ return constants_1.constants.LLM_BASE_URL_INVALID_MESSAGE;
62
+ }
63
+ return null;
64
+ };
65
+ exports.llmBaseUrlIssue = llmBaseUrlIssue;
@@ -1 +1 @@
1
- {"version":3,"file":"localizeZodIssue.d.ts","sourceRoot":"","sources":["../src/localizeZodIssue.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;CACtB;AAkDD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,MAK3D,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,GAC3B,OAAO,YAAY,EACnB,UAAU,MAAM,KACf,MAmBF,CAAC"}
1
+ {"version":3,"file":"localizeZodIssue.d.ts","sourceRoot":"","sources":["../src/localizeZodIssue.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;CACtB;AAwDD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,MAK3D,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,GAC3B,OAAO,YAAY,EACnB,UAAU,MAAM,KACf,MAmBF,CAAC"}
@@ -43,6 +43,12 @@ const CUSTOM_MESSAGES = {
43
43
  },
44
44
  [constants_1.constants.CUSTOM_CODE_RESOURCE_FILE_TOO_LARGE_MESSAGE]: {
45
45
  es: `Los bytes del archivo superan el límite de ${constants_1.constants.CUSTOM_CODE_MAX_RESOURCE_FILE_BYTES / (1024 * 1024)}MB`
46
+ },
47
+ [constants_1.constants.LLM_BASE_URL_REQUIRED_MESSAGE]: {
48
+ es: 'Se requiere una URL base para un modelo compatible con OpenAI'
49
+ },
50
+ [constants_1.constants.LLM_BASE_URL_INVALID_MESSAGE]: {
51
+ es: 'La URL base debe ser una dirección https:// pública'
46
52
  }
47
53
  };
48
54
  // Built once. `esLocale()` allocates its dictionaries on every call, and this
@@ -1 +1 @@
1
- {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM;CAKzB;AAUD,eAAO,MAAM,iBAAiB,GAC5B,OAAO,sBAAsB,KAC5B,OAAO,CAAC,mBAAmB,CAsC7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACxC,QAAQ,MAAM,KACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAKvB,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,KACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAO5B,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,UAAU,OAAO,KAChB,OAGF,CAAC"}
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM;CAKzB;AAUD,eAAO,MAAM,iBAAiB,GAC5B,OAAO,sBAAsB,KAC5B,OAAO,CAAC,mBAAmB,CAsC7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACxC,QAAQ,MAAM,KACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAKvB,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,KACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAO5B,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,UAAU,OAAO,KAAG,OAG7D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseHttpError.d.ts","sourceRoot":"","sources":["../src/parseHttpError.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,MAAM,CAe9E,CAAC"}
1
+ {"version":3,"file":"parseHttpError.d.ts","sourceRoot":"","sources":["../src/parseHttpError.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAChC,UAAU,QAAQ,KACjB,OAAO,CAAC,MAAM,CAehB,CAAC"}
package/dist/schema.d.ts CHANGED
@@ -1215,8 +1215,8 @@ export declare const Schema: {
1215
1215
  "openai-compatible": "openai-compatible";
1216
1216
  }>;
1217
1217
  apiKey: z.ZodString;
1218
- model: z.ZodString;
1219
1218
  baseUrl: z.ZodUnion<[z.ZodOptional<z.ZodURL>, z.ZodLiteral<"">]>;
1219
+ model: z.ZodString;
1220
1220
  systemPrompt: z.ZodOptional<z.ZodString>;
1221
1221
  }, z.core.$strip>;
1222
1222
  ORGANIZATION_UPDATE_LLM: z.ZodObject<{
@@ -1246,8 +1246,8 @@ export declare const Schema: {
1246
1246
  "openai-compatible": "openai-compatible";
1247
1247
  }>>;
1248
1248
  apiKey: z.ZodOptional<z.ZodString>;
1249
- model: z.ZodOptional<z.ZodString>;
1250
1249
  baseUrl: z.ZodNullable<z.ZodUnion<[z.ZodOptional<z.ZodURL>, z.ZodLiteral<"">]>>;
1250
+ model: z.ZodOptional<z.ZodString>;
1251
1251
  systemPrompt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
1252
1252
  }, z.core.$strip>;
1253
1253
  ORGANIZATION_REMOVE_LLM: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA6tBxB,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FrB,CAAC;AAyDN,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCpB,CAAC;AAWH,QAAA,MAAM,kBAAkB;;;;;;;;;;iBA+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@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Schema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("./constants");
6
+ const llmBaseUrl_1 = require("./llmBaseUrl");
6
7
  const slug_1 = require("./slug");
7
8
  const reservedToolName_1 = require("./reservedToolName");
8
9
  const slugifyTitle_1 = require("./slugifyTitle");
@@ -491,29 +492,52 @@ const ORGANIZATION_LIST_LLM = zod_1.z.object({
491
492
  userId: zod_1.z.uuid(),
492
493
  organizationId: zod_1.z.uuid()
493
494
  });
494
- const ORGANIZATION_CREATE_LLM = zod_1.z.object({
495
+ // The two rules live in `llmBaseUrl.ts`, because the update controller applies
496
+ // them again to the merged row — the only place both halves are visible. Here
497
+ // they are just the field validator and the cross-field check.
498
+ const LLM_BASE_URL = zod_1.z
499
+ .url()
500
+ .max(500)
501
+ .refine(llmBaseUrl_1.isAllowedLlmBaseUrl, constants_1.constants.LLM_BASE_URL_INVALID_MESSAGE);
502
+ const BASE_URL_REQUIRED = {
503
+ message: constants_1.constants.LLM_BASE_URL_REQUIRED_MESSAGE,
504
+ path: ['baseUrl']
505
+ };
506
+ const hasBaseUrlWhenRequired = (provider, baseUrl) => !(0, llmBaseUrl_1.requiresLlmBaseUrl)(provider) || !!baseUrl;
507
+ // The base-URL rule is a cross-field check, and zod cannot `.omit()` from a
508
+ // schema that already carries one. So the shape stays a plain object — the
509
+ // `_VIEW` variants below derive from it — and the refinement is applied last,
510
+ // to each schema in turn, which also keeps the two in step.
511
+ const ORGANIZATION_CREATE_LLM_SHAPE = zod_1.z.object({
495
512
  name: zod_1.z.string().min(1).max(200),
496
513
  provider: zod_1.z.enum(constants_1.constants.LLM_PROVIDERS),
497
514
  model: zod_1.z.string().min(1).max(200),
498
- baseUrl: zod_1.z.url().optional().or(zod_1.z.literal('')),
515
+ baseUrl: LLM_BASE_URL.optional().or(zod_1.z.literal('')),
499
516
  apiKey: zod_1.z.string().min(1).max(500),
500
517
  systemPrompt: zod_1.z.string().max(10000).optional(),
501
518
  config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
502
519
  userId: zod_1.z.uuid(),
503
520
  organizationId: zod_1.z.uuid()
504
521
  });
505
- const ORGANIZATION_UPDATE_LLM = zod_1.z.object({
522
+ const ORGANIZATION_CREATE_LLM = ORGANIZATION_CREATE_LLM_SHAPE.refine(v => hasBaseUrlWhenRequired(v.provider, v.baseUrl), BASE_URL_REQUIRED);
523
+ // An update is a partial: an omitted field keeps its stored value, so the
524
+ // base-URL rule can only be checked here when the caller sends the provider and
525
+ // the base URL together. The controller re-checks it against the merged row,
526
+ // which is the only place both halves are known.
527
+ const ORGANIZATION_UPDATE_LLM_SHAPE = zod_1.z.object({
506
528
  llmId: zod_1.z.uuid(),
507
529
  name: zod_1.z.string().min(1).max(200).optional(),
508
530
  provider: zod_1.z.enum(constants_1.constants.LLM_PROVIDERS).optional(),
509
531
  model: zod_1.z.string().min(1).max(200).optional(),
510
- baseUrl: zod_1.z.url().optional().or(zod_1.z.literal('')).nullable(),
532
+ baseUrl: LLM_BASE_URL.optional().or(zod_1.z.literal('')).nullable(),
511
533
  apiKey: zod_1.z.string().min(1).max(500).optional(),
512
534
  systemPrompt: zod_1.z.string().max(10000).optional().nullable(),
513
535
  config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional().nullable(),
514
536
  userId: zod_1.z.uuid(),
515
537
  organizationId: zod_1.z.uuid()
516
538
  });
539
+ const refineUpdateBaseUrl = (schema) => schema.refine(v => v.baseUrl === undefined || hasBaseUrlWhenRequired(v.provider, v.baseUrl), BASE_URL_REQUIRED);
540
+ const ORGANIZATION_UPDATE_LLM = refineUpdateBaseUrl(ORGANIZATION_UPDATE_LLM_SHAPE);
517
541
  const ORGANIZATION_REMOVE_LLM = zod_1.z.object({
518
542
  llmId: zod_1.z.uuid(),
519
543
  userId: zod_1.z.uuid(),
@@ -561,15 +585,15 @@ const ACCESS_TOKEN_CREATE_VIEW = ACCESS_TOKEN_CREATE.omit({
561
585
  organizationId: true,
562
586
  projectId: true
563
587
  });
564
- const ORGANIZATION_CREATE_LLM_VIEW = ORGANIZATION_CREATE_LLM.omit({
588
+ const ORGANIZATION_CREATE_LLM_VIEW = ORGANIZATION_CREATE_LLM_SHAPE.omit({
565
589
  userId: true,
566
590
  organizationId: true
567
- });
568
- const ORGANIZATION_UPDATE_LLM_VIEW = ORGANIZATION_UPDATE_LLM.omit({
591
+ }).refine(v => hasBaseUrlWhenRequired(v.provider, v.baseUrl), BASE_URL_REQUIRED);
592
+ const ORGANIZATION_UPDATE_LLM_VIEW = refineUpdateBaseUrl(ORGANIZATION_UPDATE_LLM_SHAPE.omit({
569
593
  llmId: true,
570
594
  userId: true,
571
595
  organizationId: true
572
- });
596
+ }));
573
597
  // `channel.config` is an open bag, so this stays loose — it only pins down the
574
598
  // keys we actually read, and passes everything else through untouched.
575
599
  // `debounceMs` is how long a burst from one participant is buffered before the
@@ -1 +1 @@
1
- {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAAC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,CAAC,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EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,CAAC,YAAY,CAAC,KAC/B,OAEwD,CAAC;AAE5D,eAAO,MAAM,uBAAuB,GAClC,UAAU;IAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,KAC1D,OAEwB,CAAC;AAE5B,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAGnD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,KAAK,kBAAkB,EACvB,YAAY,MAAM,EAClB,aAAa,MAAM,KAClB,MAGF,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAKD,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EAAE,EACjB,KAAK,kBAAkB,EACvB,UAAU;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,YAAY,EA2Bd,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EAAE,EACjB,KAAK,kBAAkB,KACtB,MAmBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"vendorError.d.ts","sourceRoot":"","sources":["../src/vendorError.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,mBAAmB,GAAI,MAAM,OAAO,EAAE,UAAU,MAAM,KAAG,MASrE,CAAC"}
1
+ {"version":3,"file":"vendorError.d.ts","sourceRoot":"","sources":["../src/vendorError.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,mBAAmB,GAC9B,MAAM,OAAO,EACb,UAAU,MAAM,KACf,MASF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ganju/utils",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "Shared constants, schemas and helpers for Ganju",
5
5
  "license": "Apache-2.0",
6
6
  "author": "MontoyaAndres <andresmontoyafcb@gmail.com>",
package/src/attachment.ts CHANGED
@@ -28,7 +28,8 @@ export interface ResolvedAttachment {
28
28
  }
29
29
 
30
30
  export type ResolveAttachmentResult =
31
- { ok: true; attachment: ResolvedAttachment } | { ok: false; error: string };
31
+ | { ok: true; attachment: ResolvedAttachment }
32
+ | { ok: false; error: string };
32
33
 
33
34
  /**
34
35
  * Resolve one resource's attachment bytes.
package/src/chunking.ts CHANGED
@@ -37,7 +37,9 @@ export const splitRecursive = (
37
37
  }
38
38
  if (current) chunks.push(current);
39
39
  return chunks.flatMap(chunk =>
40
- chunk.length > target ? splitRecursive(chunk, target, separators) : [chunk]
40
+ chunk.length > target
41
+ ? splitRecursive(chunk, target, separators)
42
+ : [chunk]
41
43
  );
42
44
  }
43
45
 
@@ -104,7 +106,9 @@ export const prepareChunks = (
104
106
  if (documents && documents.length > 0) {
105
107
  const out: PreparedChunk[] = [];
106
108
  documents.forEach((doc, docIndex) => {
107
- const body = (doc.pageContent || '').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '').trim();
109
+ const body = (doc.pageContent || '')
110
+ .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
111
+ .trim();
108
112
  if (!body) return;
109
113
  const text = docIndex === 0 && header ? `${header}\n\n${body}` : body;
110
114
  const pieces = chunkText(text, options);
@@ -122,7 +126,9 @@ export const prepareChunks = (
122
126
  return out;
123
127
  }
124
128
 
125
- const body = (fallbackContent || '').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '').trim();
129
+ const body = (fallbackContent || '')
130
+ .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
131
+ .trim();
126
132
  const fullText = [header, body].filter(Boolean).join('\n\n');
127
133
  return chunkText(fullText, options).map(content => ({
128
134
  content,
package/src/coerce.ts CHANGED
@@ -3,7 +3,10 @@ export const toStringArray = (input: unknown): string[] => {
3
3
  return input.map(s => String(s).trim()).filter(Boolean);
4
4
  }
5
5
  if (typeof input === 'string' && input.trim()) {
6
- return input.split(',').map(s => s.trim()).filter(Boolean);
6
+ return input
7
+ .split(',')
8
+ .map(s => s.trim())
9
+ .filter(Boolean);
7
10
  }
8
11
  return [];
9
12
  };