@n8n/ai-utilities 0.16.0 → 0.16.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.
@@ -0,0 +1,5 @@
1
+ export interface FollowRedirectsOptions {
2
+ onBeforeHop?: (url: string) => void | Promise<void>;
3
+ maxRedirects?: number;
4
+ }
5
+ export declare function fetchFollowingRedirects(fetcher: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>, url: string | URL, init?: RequestInit, options?: FollowRedirectsOptions): Promise<Response>;
@@ -0,0 +1,51 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "n8n-workflow"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fetchFollowingRedirects = fetchFollowingRedirects;
13
+ const n8n_workflow_1 = require("n8n-workflow");
14
+ const DEFAULT_MAX_REDIRECTS = 20;
15
+ async function fetchFollowingRedirects(fetcher, url, init, options) {
16
+ const maxRedirects = options?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
17
+ let currentInput = url;
18
+ let currentInit = { ...init };
19
+ let hops = 0;
20
+ while (true) {
21
+ const currentUrlString = currentInput instanceof URL ? currentInput.href : currentInput;
22
+ if (options?.onBeforeHop) {
23
+ await options.onBeforeHop(currentUrlString);
24
+ }
25
+ const response = await fetcher(currentInput, {
26
+ ...currentInit,
27
+ redirect: 'manual',
28
+ });
29
+ if (response.status < 300 || response.status >= 400) {
30
+ return response;
31
+ }
32
+ const location = response.headers.get('location');
33
+ if (!location) {
34
+ return response;
35
+ }
36
+ hops += 1;
37
+ if (hops > maxRedirects) {
38
+ throw new n8n_workflow_1.ApplicationError(`Too many redirects (max ${maxRedirects})`);
39
+ }
40
+ await response.body?.cancel().catch(() => { });
41
+ currentInput = new URL(location, currentUrlString);
42
+ const method = (currentInit.method ?? 'GET').toUpperCase();
43
+ const isUnsafe = method !== 'GET' && method !== 'HEAD';
44
+ if (response.status === 303 ||
45
+ ((response.status === 301 || response.status === 302) && isUnsafe)) {
46
+ currentInit = { ...currentInit, method: 'GET', body: undefined };
47
+ }
48
+ }
49
+ }
50
+ });
51
+ //# sourceMappingURL=follow-redirects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow-redirects.js","sourceRoot":"","sources":["../../../src/utils/follow-redirects.ts"],"names":[],"mappings":";;;;;;;;;;;IAcA,0DAiDC;IA/DD,+CAAgD;IAEhD,MAAM,qBAAqB,GAAG,EAAE,CAAC;IAY1B,KAAK,UAAU,uBAAuB,CAC5C,OAA4E,EAC5E,GAAiB,EACjB,IAAkB,EAClB,OAAgC;QAEhC,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,qBAAqB,CAAC;QACpE,IAAI,YAAY,GAAiB,GAAG,CAAC;QACrC,IAAI,WAAW,GAAgB,EAAE,GAAG,IAAI,EAAE,CAAC;QAC3C,IAAI,IAAI,GAAG,CAAC,CAAC;QAEb,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,gBAAgB,GAAG,YAAY,YAAY,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC;YACxF,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;gBAC1B,MAAM,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;YAC7C,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,YAAY,EAAE;gBAC5C,GAAG,WAAW;gBACd,QAAQ,EAAE,QAAQ;aAClB,CAAC,CAAC;YAEH,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBACrD,OAAO,QAAQ,CAAC;YACjB,CAAC;YAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,OAAO,QAAQ,CAAC;YACjB,CAAC;YAED,IAAI,IAAI,CAAC,CAAC;YACV,IAAI,IAAI,GAAG,YAAY,EAAE,CAAC;gBACzB,MAAM,IAAI,+BAAgB,CAAC,2BAA2B,YAAY,GAAG,CAAC,CAAC;YACxE,CAAC;YAED,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAE9C,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,CAAC,WAAW,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,CAAC;YACvD,IACC,QAAQ,CAAC,MAAM,KAAK,GAAG;gBACvB,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,QAAQ,CAAC,EACjE,CAAC;gBACF,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;YAClE,CAAC;QACF,CAAC;IACF,CAAC"}
@@ -13,6 +13,7 @@ export { estimateTokensFromStringList, estimateTokensByCharCount, estimateTextSp
13
13
  export { encodingForModel, getEncoding } from './utils/tokenizer/tiktoken';
14
14
  export { makeN8nLlmFailedAttemptHandler } from './utils/failed-attempt-handler/n8nLlmFailedAttemptHandler';
15
15
  export { getProxyAgent, getNodeProxyAgent, proxyFetch, type AgentTimeoutOptions, } from './utils/http-proxy-agent';
16
+ export { fetchFollowingRedirects, type FollowRedirectsOptions, } from './utils/follow-redirects';
16
17
  export { getConnectionHintNoticeField, metadataFilterField, getBatchingOptionFields, getTemplateNoticeField, } from './utils/shared-fields';
17
18
  export { createToolFromNode, createZodSchemaFromArgs, extractFromAIParameters, } from './utils/fromai-tool-factory';
18
19
  export { createVectorStoreNode } from './utils/vector-store/createVectorStoreNode/createVectorStoreNode';
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBaseChatMessageHistory = exports.isBaseChatMemory = exports.fromLcContent = exports.toLcContent = exports.toLcMessage = exports.fromLcMessage = exports.getParametersJsonSchema = exports.processDocument = exports.processDocuments = exports.MemoryVectorStoreManager = exports.createVectorStoreNode = exports.extractFromAIParameters = exports.createZodSchemaFromArgs = exports.createToolFromNode = exports.getTemplateNoticeField = exports.getBatchingOptionFields = exports.metadataFilterField = exports.getConnectionHintNoticeField = exports.proxyFetch = exports.getNodeProxyAgent = exports.getProxyAgent = exports.makeN8nLlmFailedAttemptHandler = exports.getEncoding = exports.encodingForModel = exports.estimateTextSplitsByTokens = exports.estimateTokensByCharCount = exports.estimateTokensFromStringList = exports.parseStrReplacements = exports.findDivergenceContext = exports.formatTextWithLineNumbers = exports.BatchReplacementError = exports.FileNotFoundError = exports.FileExistsError = exports.InvalidPathError = exports.InvalidViewRangeError = exports.InvalidLineNumberError = exports.MultipleMatchesError = exports.NoMatchFoundError = exports.TextEditorDocument = exports.N8nLlmTracing = exports.N8nJsonLoader = exports.N8nBinaryLoader = exports.hasLongSequentialRepeat = exports.getMetadataFiltersValues = exports.validateEmbedDocumentsInput = exports.validateEmbedQueryInput = exports.parseSSEStream = exports.logAiEvent = exports.logWrapper = exports.AI_NODE_SDK_VERSION = void 0;
4
- exports.supplyModel = exports.supplyMemory = exports.WindowedChatMemory = exports.BaseChatMemory = exports.BaseChatHistory = exports.BaseChatModel = exports.LangchainChatModelAdapter = exports.isToolsInstance = exports.isChatInstance = void 0;
3
+ exports.isBaseChatMemory = exports.fromLcContent = exports.toLcContent = exports.toLcMessage = exports.fromLcMessage = exports.getParametersJsonSchema = exports.processDocument = exports.processDocuments = exports.MemoryVectorStoreManager = exports.createVectorStoreNode = exports.extractFromAIParameters = exports.createZodSchemaFromArgs = exports.createToolFromNode = exports.getTemplateNoticeField = exports.getBatchingOptionFields = exports.metadataFilterField = exports.getConnectionHintNoticeField = exports.fetchFollowingRedirects = exports.proxyFetch = exports.getNodeProxyAgent = exports.getProxyAgent = exports.makeN8nLlmFailedAttemptHandler = exports.getEncoding = exports.encodingForModel = exports.estimateTextSplitsByTokens = exports.estimateTokensByCharCount = exports.estimateTokensFromStringList = exports.parseStrReplacements = exports.findDivergenceContext = exports.formatTextWithLineNumbers = exports.BatchReplacementError = exports.FileNotFoundError = exports.FileExistsError = exports.InvalidPathError = exports.InvalidViewRangeError = exports.InvalidLineNumberError = exports.MultipleMatchesError = exports.NoMatchFoundError = exports.TextEditorDocument = exports.N8nLlmTracing = exports.N8nJsonLoader = exports.N8nBinaryLoader = exports.hasLongSequentialRepeat = exports.getMetadataFiltersValues = exports.validateEmbedDocumentsInput = exports.validateEmbedQueryInput = exports.parseSSEStream = exports.logAiEvent = exports.logWrapper = exports.AI_NODE_SDK_VERSION = void 0;
4
+ exports.supplyModel = exports.supplyMemory = exports.WindowedChatMemory = exports.BaseChatMemory = exports.BaseChatHistory = exports.BaseChatModel = exports.LangchainChatModelAdapter = exports.isToolsInstance = exports.isChatInstance = exports.isBaseChatMessageHistory = void 0;
5
5
  var ai_node_sdk_version_1 = require("./ai-node-sdk-version");
6
6
  Object.defineProperty(exports, "AI_NODE_SDK_VERSION", { enumerable: true, get: function () { return ai_node_sdk_version_1.AI_NODE_SDK_VERSION; } });
7
7
  var log_wrapper_1 = require("./utils/log-wrapper");
@@ -48,6 +48,8 @@ var http_proxy_agent_1 = require("./utils/http-proxy-agent");
48
48
  Object.defineProperty(exports, "getProxyAgent", { enumerable: true, get: function () { return http_proxy_agent_1.getProxyAgent; } });
49
49
  Object.defineProperty(exports, "getNodeProxyAgent", { enumerable: true, get: function () { return http_proxy_agent_1.getNodeProxyAgent; } });
50
50
  Object.defineProperty(exports, "proxyFetch", { enumerable: true, get: function () { return http_proxy_agent_1.proxyFetch; } });
51
+ var follow_redirects_1 = require("./utils/follow-redirects");
52
+ Object.defineProperty(exports, "fetchFollowingRedirects", { enumerable: true, get: function () { return follow_redirects_1.fetchFollowingRedirects; } });
51
53
  var shared_fields_1 = require("./utils/shared-fields");
52
54
  Object.defineProperty(exports, "getConnectionHintNoticeField", { enumerable: true, get: function () { return shared_fields_1.getConnectionHintNoticeField; } });
53
55
  Object.defineProperty(exports, "metadataFilterField", { enumerable: true, get: function () { return shared_fields_1.metadataFilterField; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AACA,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAG5B,mDAAiD;AAAxC,yGAAA,UAAU,OAAA;AACnB,qDAAkD;AAAzC,0GAAA,UAAU,OAAA;AACnB,mCAA6C;AAApC,qGAAA,cAAc,OAAA;AACvB,mFAG6C;AAF5C,sIAAA,uBAAuB,OAAA;AACvB,0IAAA,2BAA2B,OAAA;AAE5B,2CAAoF;AAA3E,mHAAA,wBAAwB,OAAA;AAAE,kHAAA,uBAAuB,OAAA;AAC1D,+DAA4D;AAAnD,oHAAA,eAAe,OAAA;AACxB,2DAAwD;AAA/C,gHAAA,aAAa,OAAA;AACtB,2DAAwD;AAA/C,gHAAA,aAAa,OAAA;AACtB,mDAa6B;AAZ5B,iHAAA,kBAAkB,OAAA;AAClB,gHAAA,iBAAiB,OAAA;AACjB,mHAAA,oBAAoB,OAAA;AACpB,qHAAA,sBAAsB,OAAA;AACtB,oHAAA,qBAAqB,OAAA;AACrB,+GAAA,gBAAgB,OAAA;AAChB,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AACjB,oHAAA,qBAAqB,OAAA;AACrB,wHAA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