linkque-cli-v2 1.6.16 → 1.6.17
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/dataTransformWorker.js +175 -89
- package/linkquejs.js +27598 -9407
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/data-transform/dataTransformWorker.js +175 -89
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-ZK7HXMMY.js → chunk-7OYTZGOC.js} +38727 -20374
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-ZQGBHENQ.js → chunk-EJB2EPNQ.js} +70 -3
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-2O5AZ546.js → chunk-RSMGFPPK.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-DNTEEBEH.js → chunk-SICWMO5Y.js} +1 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-JGCLGHFY.js → getMachineId-bsd-NYGVHXGN.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-COHLFNXH.js → getMachineId-darwin-OPTJOAYC.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-XV3Z5FQG.js → getMachineId-linux-5SQRYTUJ.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-FCRKLIZL.js → getMachineId-unsupported-OJE7WPEH.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-A4WRNVV6.js → getMachineId-win-SLTTCNXU.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-OEOTQWE5.js → mistral-conversations-C43A6QIS.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-WGS5CC2J.js → otel-RUUFBBFE.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +1566 -191
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +3 -3
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +3 -3
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +40895 -22423
package/package.json
CHANGED
|
@@ -1743,6 +1743,9 @@ function smartUnwrap(val) {
|
|
|
1743
1743
|
return val && "default" in val && val.default ? val.default && "default" in val.default && val.default.default ? val.default.default : val.default : val;
|
|
1744
1744
|
}
|
|
1745
1745
|
|
|
1746
|
+
// ../linkque-agent-runtime/dist/esm/core/aiFilter.js
|
|
1747
|
+
var DEFAULT_AI_FILTER_PROMPT = "\u6309\u7167\u7528\u6237\u539F\u59CB\u95EE\u9898\uFF0C\u5BF9\u8FD9\u4E9B\u6570\u636E\u8FDB\u884C\u7B5B\u9009\u548C\u6392\u5E8F";
|
|
1748
|
+
|
|
1746
1749
|
// ../linkque-agent-runtime/dist/esm/core/dataTransformWorker.js
|
|
1747
1750
|
void initialize();
|
|
1748
1751
|
async function initialize() {
|
|
@@ -1752,129 +1755,212 @@ async function initialize() {
|
|
|
1752
1755
|
if (input?.type !== "execute")
|
|
1753
1756
|
return;
|
|
1754
1757
|
const startedAt = Date.now();
|
|
1755
|
-
void execute(quickJs, input).then((resultJson) => {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
requestId: input.requestId,
|
|
1768
|
-
ok: false,
|
|
1769
|
-
code: classified.code,
|
|
1770
|
-
message: classified.message
|
|
1771
|
-
});
|
|
1772
|
-
});
|
|
1758
|
+
void execute(quickJs, input).then((resultJson) => import_node_worker_threads.parentPort?.postMessage({
|
|
1759
|
+
type: "result",
|
|
1760
|
+
requestId: input.requestId,
|
|
1761
|
+
ok: true,
|
|
1762
|
+
resultJson,
|
|
1763
|
+
durationMs: Date.now() - startedAt
|
|
1764
|
+
}), (error) => import_node_worker_threads.parentPort?.postMessage({
|
|
1765
|
+
type: "result",
|
|
1766
|
+
requestId: input.requestId,
|
|
1767
|
+
ok: false,
|
|
1768
|
+
...classifyError(error)
|
|
1769
|
+
}));
|
|
1773
1770
|
});
|
|
1774
1771
|
}
|
|
1775
1772
|
async function execute(module2, input) {
|
|
1776
1773
|
const runtime = module2.newRuntime();
|
|
1777
1774
|
runtime.setMemoryLimit(input.limits.memoryBytes);
|
|
1778
1775
|
runtime.setMaxStackSize(input.limits.stackBytes);
|
|
1779
|
-
|
|
1776
|
+
let remaining = input.limits.executionMs;
|
|
1777
|
+
let deadline = 0;
|
|
1780
1778
|
let interrupted = false;
|
|
1781
1779
|
runtime.setInterruptHandler(() => {
|
|
1782
1780
|
interrupted = Date.now() > deadline;
|
|
1783
1781
|
return interrupted;
|
|
1784
1782
|
});
|
|
1785
1783
|
const context = runtime.newContext();
|
|
1784
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1785
|
+
let nextCallId = 1;
|
|
1786
|
+
let wake;
|
|
1787
|
+
const run = (callback) => {
|
|
1788
|
+
const started = Date.now();
|
|
1789
|
+
deadline = started + remaining;
|
|
1790
|
+
if (remaining <= 0)
|
|
1791
|
+
throw new Error("\u6570\u636E\u8F6C\u6362\u8D85\u8FC7\u6267\u884C\u65F6\u95F4\u9650\u5236");
|
|
1792
|
+
try {
|
|
1793
|
+
return callback();
|
|
1794
|
+
} finally {
|
|
1795
|
+
remaining -= Date.now() - started;
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
const read = (handle) => {
|
|
1799
|
+
const value = context.dump(handle);
|
|
1800
|
+
if (typeof value !== "string")
|
|
1801
|
+
throw new TypeError("transform \u7ED3\u679C\u65E0\u6CD5\u5E8F\u5217\u5316");
|
|
1802
|
+
return value;
|
|
1803
|
+
};
|
|
1804
|
+
const onResponse = (message) => {
|
|
1805
|
+
if (message?.type !== "filter-result" || message.requestId !== input.requestId)
|
|
1806
|
+
return;
|
|
1807
|
+
const promise = pending.get(message.callId);
|
|
1808
|
+
if (!promise)
|
|
1809
|
+
return;
|
|
1810
|
+
pending.delete(message.callId);
|
|
1811
|
+
const handle = message.error ? context.newError(message.error) : context.newString(JSON.stringify(message.indices));
|
|
1812
|
+
if (message.error)
|
|
1813
|
+
promise.reject(handle);
|
|
1814
|
+
else
|
|
1815
|
+
promise.resolve(handle);
|
|
1816
|
+
handle.dispose();
|
|
1817
|
+
promise.dispose();
|
|
1818
|
+
wake?.();
|
|
1819
|
+
};
|
|
1820
|
+
import_node_worker_threads.parentPort?.on("message", onResponse);
|
|
1786
1821
|
try {
|
|
1787
1822
|
if (input.mode === "validate") {
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
`);
|
|
1798
|
-
if (validated.error) {
|
|
1799
|
-
const dumped = context.dump(validated.error);
|
|
1800
|
-
validated.error.dispose();
|
|
1801
|
-
throw new Error(readQuickJsError(dumped));
|
|
1802
|
-
}
|
|
1803
|
-
const result2 = context.dump(validated.value);
|
|
1804
|
-
validated.value.dispose();
|
|
1805
|
-
if (typeof result2 !== "string")
|
|
1806
|
-
throw new TypeError("transform \u6E90\u7801\u6821\u9A8C\u5931\u8D25");
|
|
1807
|
-
return result2;
|
|
1823
|
+
const result = run(() => context.evalCode(`'use strict'; (() => { ${input.source}
|
|
1824
|
+
});`, void 0, { compileOnly: true }));
|
|
1825
|
+
if (result.error) {
|
|
1826
|
+
const error = context.dump(result.error);
|
|
1827
|
+
result.error.dispose();
|
|
1828
|
+
throw new Error(readQuickJsError(error));
|
|
1829
|
+
}
|
|
1830
|
+
result.value.dispose();
|
|
1831
|
+
return "{}";
|
|
1808
1832
|
}
|
|
1833
|
+
const host = context.newFunction("__hostFilter", (listHandle, promptHandle, lengthHandle) => {
|
|
1834
|
+
const modelList = JSON.parse(context.getString(listHandle));
|
|
1835
|
+
if (!Array.isArray(modelList) || modelList.length !== context.getNumber(lengthHandle)) {
|
|
1836
|
+
throw new TypeError("\u5E8F\u5217\u5316\u540E\u7684\u6A21\u578B\u6295\u5F71\u5FC5\u987B\u4E0E\u539F\u59CB\u6570\u7EC4\u7B49\u957F");
|
|
1837
|
+
}
|
|
1838
|
+
const prompt = context.getString(promptHandle);
|
|
1839
|
+
const callId = nextCallId++;
|
|
1840
|
+
const promise = context.newPromise();
|
|
1841
|
+
pending.set(callId, promise);
|
|
1842
|
+
import_node_worker_threads.parentPort?.postMessage({
|
|
1843
|
+
type: "filter",
|
|
1844
|
+
requestId: input.requestId,
|
|
1845
|
+
callId,
|
|
1846
|
+
modelList,
|
|
1847
|
+
prompt
|
|
1848
|
+
});
|
|
1849
|
+
return promise.handle;
|
|
1850
|
+
});
|
|
1851
|
+
context.setProp(context.global, "__LINKQUE_FILTER__", host);
|
|
1852
|
+
host.dispose();
|
|
1809
1853
|
const inputHandle = context.newString(input.inputJson);
|
|
1810
1854
|
context.setProp(context.global, "__LINKQUE_INPUT_JSON__", inputHandle);
|
|
1811
1855
|
inputHandle.dispose();
|
|
1812
|
-
const
|
|
1856
|
+
const source = `
|
|
1813
1857
|
'use strict';
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1858
|
+
(() => {
|
|
1859
|
+
const hostFilter = globalThis.__LINKQUE_FILTER__;
|
|
1860
|
+
delete globalThis.__LINKQUE_FILTER__;
|
|
1861
|
+
const input = JSON.parse(globalThis.__LINKQUE_INPUT_JSON__);
|
|
1862
|
+
delete globalThis.__LINKQUE_INPUT_JSON__;
|
|
1863
|
+
const ctx = Object.freeze({ ai: Object.freeze({ filter: async (list, modelList = list, prompt = ${JSON.stringify(DEFAULT_AI_FILTER_PROMPT)}) => {
|
|
1864
|
+
if (!Array.isArray(list) || !Array.isArray(modelList)) throw new TypeError('AI \u7B5B\u9009\u8F93\u5165\u5FC5\u987B\u662F\u6570\u7EC4');
|
|
1865
|
+
if (list.length !== modelList.length) throw new TypeError('\u6A21\u578B\u6295\u5F71\u5FC5\u987B\u4E0E\u539F\u59CB\u6570\u7EC4\u7B49\u957F\u4E14\u987A\u5E8F\u4E00\u81F4');
|
|
1866
|
+
if (typeof prompt !== 'string') throw new TypeError('AI \u7B5B\u9009\u6307\u4EE4\u5FC5\u987B\u662F\u5B57\u7B26\u4E32');
|
|
1867
|
+
const original = list.slice();
|
|
1868
|
+
if (original.length === 0 || ${input.preview === true}) return original;
|
|
1869
|
+
const indices = JSON.parse(await hostFilter(JSON.stringify(modelList), prompt, original.length));
|
|
1870
|
+
return indices.map(index => original[index]);
|
|
1871
|
+
} }) });
|
|
1872
|
+
const transform = (() => { ${input.source}
|
|
1873
|
+
return transform; })();
|
|
1874
|
+
if (typeof transform !== 'function') throw new TypeError('transform \u5FC5\u987B\u662F\u51FD\u6570');
|
|
1875
|
+
const serialize = output => {
|
|
1876
|
+
if (output === undefined || typeof output !== 'object') {
|
|
1877
|
+
throw new TypeError('transform \u5FC5\u987B\u8FD4\u56DE JSON \u5BF9\u8C61\u6216 null');
|
|
1878
|
+
}
|
|
1879
|
+
return JSON.stringify(output);
|
|
1880
|
+
};
|
|
1881
|
+
const output = transform(input, ctx);
|
|
1882
|
+
return output && typeof output.then === 'function'
|
|
1883
|
+
? Promise.resolve(output).then(serialize)
|
|
1884
|
+
: serialize(output);
|
|
1885
|
+
})()
|
|
1886
|
+
`;
|
|
1887
|
+
const evaluated = run(() => context.evalCode(source));
|
|
1831
1888
|
if (evaluated.error) {
|
|
1832
|
-
const
|
|
1889
|
+
const error = context.dump(evaluated.error);
|
|
1833
1890
|
evaluated.error.dispose();
|
|
1834
|
-
|
|
1835
|
-
throw new TransformWorkerError("timeout");
|
|
1836
|
-
throw new Error(readQuickJsError(dumped));
|
|
1891
|
+
throw new Error(readQuickJsError(error));
|
|
1837
1892
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1893
|
+
try {
|
|
1894
|
+
if (context.typeof(evaluated.value) !== "object")
|
|
1895
|
+
return read(evaluated.value);
|
|
1896
|
+
let done = false;
|
|
1897
|
+
const settled = context.resolvePromise(evaluated.value).then((result2) => {
|
|
1898
|
+
done = true;
|
|
1899
|
+
wake?.();
|
|
1900
|
+
return result2;
|
|
1901
|
+
});
|
|
1902
|
+
for (; ; ) {
|
|
1903
|
+
import_node_worker_threads.parentPort?.postMessage({
|
|
1904
|
+
type: "running",
|
|
1905
|
+
requestId: input.requestId
|
|
1906
|
+
});
|
|
1907
|
+
const jobs = run(() => runtime.executePendingJobs());
|
|
1908
|
+
if (jobs.error) {
|
|
1909
|
+
const error = context.dump(jobs.error);
|
|
1910
|
+
jobs.error.dispose();
|
|
1911
|
+
throw new Error(readQuickJsError(error));
|
|
1912
|
+
}
|
|
1913
|
+
await Promise.resolve();
|
|
1914
|
+
if (done)
|
|
1915
|
+
break;
|
|
1916
|
+
if (pending.size === 0)
|
|
1917
|
+
throw new Error("\u5F02\u6B65\u8F6C\u6362\u672A\u5B8C\u6210\u4E14\u6CA1\u6709\u53EF\u7B49\u5F85\u7684\u5BBF\u4E3B\u8BF7\u6C42");
|
|
1918
|
+
import_node_worker_threads.parentPort?.postMessage({
|
|
1919
|
+
type: "waiting",
|
|
1920
|
+
requestId: input.requestId
|
|
1921
|
+
});
|
|
1922
|
+
await new Promise((resolve) => {
|
|
1923
|
+
wake = resolve;
|
|
1924
|
+
});
|
|
1925
|
+
wake = void 0;
|
|
1926
|
+
}
|
|
1927
|
+
const result = await settled;
|
|
1928
|
+
if (result.error) {
|
|
1929
|
+
const error = context.dump(result.error);
|
|
1930
|
+
result.error.dispose();
|
|
1931
|
+
throw new Error(readQuickJsError(error));
|
|
1932
|
+
}
|
|
1933
|
+
try {
|
|
1934
|
+
return read(result.value);
|
|
1935
|
+
} finally {
|
|
1936
|
+
result.value.dispose();
|
|
1937
|
+
}
|
|
1938
|
+
} finally {
|
|
1939
|
+
evaluated.value.dispose();
|
|
1842
1940
|
}
|
|
1843
|
-
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
if (interrupted || remaining <= 0)
|
|
1943
|
+
throw new Error("\u6570\u636E\u8F6C\u6362\u8D85\u8FC7\u6267\u884C\u65F6\u95F4\u9650\u5236", { cause: error });
|
|
1944
|
+
throw error;
|
|
1844
1945
|
} finally {
|
|
1946
|
+
import_node_worker_threads.parentPort?.off("message", onResponse);
|
|
1947
|
+
for (const promise of pending.values())
|
|
1948
|
+
promise.dispose();
|
|
1845
1949
|
context.dispose();
|
|
1846
1950
|
runtime.dispose();
|
|
1847
1951
|
}
|
|
1848
1952
|
}
|
|
1849
|
-
var TransformWorkerError = class extends Error {
|
|
1850
|
-
kind;
|
|
1851
|
-
constructor(kind) {
|
|
1852
|
-
super(kind);
|
|
1853
|
-
this.kind = kind;
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
1953
|
function classifyError(error) {
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
};
|
|
1862
|
-
}
|
|
1863
|
-
const message = sanitizeError(error);
|
|
1864
|
-
if (/out of memory|stack overflow|allocation failed/iu.test(message)) {
|
|
1954
|
+
const message = error instanceof Error ? error.message.slice(0, 500) : "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5931\u8D25";
|
|
1955
|
+
if (/超过执行时间限制/u.test(message))
|
|
1956
|
+
return { code: "CARD_TRANSFORM_TIMEOUT", message };
|
|
1957
|
+
if (/out of memory|stack overflow|allocation failed/iu.test(message))
|
|
1865
1958
|
return {
|
|
1866
1959
|
code: "CARD_TRANSFORM_RESOURCE_EXCEEDED",
|
|
1867
1960
|
message: "\u6570\u636E\u8F6C\u6362\u8D85\u8FC7\u5185\u5B58\u6216\u6808\u9650\u5236"
|
|
1868
1961
|
};
|
|
1869
|
-
}
|
|
1870
1962
|
return { code: "CARD_TRANSFORM_FAILED", message };
|
|
1871
1963
|
}
|
|
1872
1964
|
function readQuickJsError(value) {
|
|
1873
|
-
|
|
1874
|
-
return value.message;
|
|
1875
|
-
}
|
|
1876
|
-
return "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5931\u8D25";
|
|
1877
|
-
}
|
|
1878
|
-
function sanitizeError(error) {
|
|
1879
|
-
return error instanceof Error && error.message.trim() ? error.message.slice(0, 500) : "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5931\u8D25";
|
|
1965
|
+
return value && typeof value === "object" && "message" in value && typeof value.message === "string" ? value.message : "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5931\u8D25";
|
|
1880
1966
|
}
|