linkque-cli-v2 1.3.5 → 1.3.7
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/linkquejs.js +14 -104
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NBYB7HSY.js → chunk-AACYYAZ6.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-HM7KNEG3.js → chunk-DNTEEBEH.js} +5 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-EAODRPW4.js +518 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-LT6VSAY4.js → chunk-RHMVQTA7.js} +56 -144
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-VVEDZWQ5.js → chunk-ZNU4GVF3.js} +15262 -378
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-H2ZLZRGB.js → getMachineId-bsd-JGCLGHFY.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-HUKYR46U.js → getMachineId-darwin-COHLFNXH.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-M5ZADHBA.js → getMachineId-linux-XV3Z5FQG.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-BM5RZZVM.js → getMachineId-unsupported-FCRKLIZL.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-BQPUF5TW.js → getMachineId-win-A4WRNVV6.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-TQA2MPJJ.js → mistral-conversations-5RZTVEO2.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-RXJWJ2TU.js → otel-WGS5CC2J.js} +250 -267
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +413 -625
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +4 -3
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +4 -3
- package/worker.js +430 -87
|
@@ -22,15 +22,15 @@ import {
|
|
|
22
22
|
createA2UIInfoLog,
|
|
23
23
|
createAppBaseClient,
|
|
24
24
|
createClientCapabilityStore,
|
|
25
|
-
createPaymentActionStore,
|
|
26
|
-
createPaymentInvocation,
|
|
27
25
|
describeRuntimeEnv,
|
|
28
26
|
isDebugLogLevel,
|
|
29
27
|
jsonError,
|
|
28
|
+
mcpPhoneAuthorizationChallenge,
|
|
30
29
|
parseStoredClientCapabilityResult,
|
|
31
30
|
readAppwriteApiKey,
|
|
32
31
|
readAuthenticatedUserId,
|
|
33
32
|
readEnvSelector,
|
|
33
|
+
readMcpPhoneAuthorization,
|
|
34
34
|
readTemporaryFrontendAppId,
|
|
35
35
|
readTraceId,
|
|
36
36
|
resolveBodyJSON,
|
|
@@ -38,13 +38,13 @@ import {
|
|
|
38
38
|
resolveLinkqueGatewayAuth,
|
|
39
39
|
resolveRunStorage,
|
|
40
40
|
toAgentRunMessages
|
|
41
|
-
} from "../../chunk-
|
|
41
|
+
} from "../../chunk-RHMVQTA7.js";
|
|
42
42
|
import "../../chunk-IWOFD643.js";
|
|
43
43
|
import "../../chunk-PXCGFBV5.js";
|
|
44
44
|
import "../../chunk-ETG6PNHQ.js";
|
|
45
45
|
import {
|
|
46
46
|
getBakedProtocol
|
|
47
|
-
} from "../../chunk-
|
|
47
|
+
} from "../../chunk-AACYYAZ6.js";
|
|
48
48
|
import {
|
|
49
49
|
CANCEL_CONVERSATION_RUN_OPERATION,
|
|
50
50
|
CONVERSATION_HISTORY_VERSION,
|
|
@@ -104,6 +104,7 @@ import {
|
|
|
104
104
|
NoopRuntimeTelemetry,
|
|
105
105
|
NoopSkillLoader,
|
|
106
106
|
NoopWebSearchPort,
|
|
107
|
+
OtelRuntimeTelemetry,
|
|
107
108
|
RUNTIME_CONFIG_DEFAULTS,
|
|
108
109
|
RemoteGatewayMcpServerProvider,
|
|
109
110
|
SideEffectRunner,
|
|
@@ -126,6 +127,7 @@ import {
|
|
|
126
127
|
formatHttpLogLine,
|
|
127
128
|
isAgentPresentationToolResult,
|
|
128
129
|
isJsonValue,
|
|
130
|
+
isMcpPhoneAuthorizationError,
|
|
129
131
|
isSafeJsonPointer,
|
|
130
132
|
normalizeFollowUpQuestionStrings,
|
|
131
133
|
normalizeHookResources,
|
|
@@ -144,6 +146,7 @@ import {
|
|
|
144
146
|
readJsonPointer,
|
|
145
147
|
readStructuredContent,
|
|
146
148
|
redactHeaders,
|
|
149
|
+
resolvePhoneAuthorizationDependency,
|
|
147
150
|
resolveWebSearchResource,
|
|
148
151
|
stableToolName,
|
|
149
152
|
startRuntimeObservation,
|
|
@@ -151,10 +154,11 @@ import {
|
|
|
151
154
|
summarizeBody,
|
|
152
155
|
warnLogFailure,
|
|
153
156
|
wrapToolWithHooks
|
|
154
|
-
} from "../../chunk-
|
|
157
|
+
} from "../../chunk-ZNU4GVF3.js";
|
|
155
158
|
import "../../chunk-XUFLSZM4.js";
|
|
159
|
+
import "../../chunk-EAODRPW4.js";
|
|
156
160
|
import "../../chunk-GAYNLDWK.js";
|
|
157
|
-
import "../../chunk-
|
|
161
|
+
import "../../chunk-DNTEEBEH.js";
|
|
158
162
|
import {
|
|
159
163
|
__commonJS,
|
|
160
164
|
__export,
|
|
@@ -444,8 +448,8 @@ var require_directives = __commonJS({
|
|
|
444
448
|
if (parts.length < 2)
|
|
445
449
|
return false;
|
|
446
450
|
}
|
|
447
|
-
const [handle,
|
|
448
|
-
this.tags[handle] =
|
|
451
|
+
const [handle, prefix] = parts;
|
|
452
|
+
this.tags[handle] = prefix;
|
|
449
453
|
return true;
|
|
450
454
|
}
|
|
451
455
|
case "%YAML": {
|
|
@@ -495,10 +499,10 @@ var require_directives = __commonJS({
|
|
|
495
499
|
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
|
|
496
500
|
if (!suffix)
|
|
497
501
|
onError(`The ${source} tag has no suffix`);
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
502
|
+
const prefix = this.tags[handle];
|
|
503
|
+
if (prefix) {
|
|
500
504
|
try {
|
|
501
|
-
return
|
|
505
|
+
return prefix + decodeURIComponent(suffix);
|
|
502
506
|
} catch (error) {
|
|
503
507
|
onError(String(error));
|
|
504
508
|
return null;
|
|
@@ -514,9 +518,9 @@ var require_directives = __commonJS({
|
|
|
514
518
|
* taking into account current tag prefixes and defaults.
|
|
515
519
|
*/
|
|
516
520
|
tagString(tag) {
|
|
517
|
-
for (const [handle,
|
|
518
|
-
if (tag.startsWith(
|
|
519
|
-
return handle + escapeTagName(tag.substring(
|
|
521
|
+
for (const [handle, prefix] of Object.entries(this.tags)) {
|
|
522
|
+
if (tag.startsWith(prefix))
|
|
523
|
+
return handle + escapeTagName(tag.substring(prefix.length));
|
|
520
524
|
}
|
|
521
525
|
return tag[0] === "!" ? tag : `!<${tag}>`;
|
|
522
526
|
}
|
|
@@ -533,11 +537,11 @@ var require_directives = __commonJS({
|
|
|
533
537
|
tagNames = Object.keys(tags);
|
|
534
538
|
} else
|
|
535
539
|
tagNames = [];
|
|
536
|
-
for (const [handle,
|
|
537
|
-
if (handle === "!!" &&
|
|
540
|
+
for (const [handle, prefix] of tagEntries) {
|
|
541
|
+
if (handle === "!!" && prefix === "tag:yaml.org,2002:")
|
|
538
542
|
continue;
|
|
539
|
-
if (!doc || tagNames.some((tn) => tn.startsWith(
|
|
540
|
-
lines.push(`%TAG ${handle} ${
|
|
543
|
+
if (!doc || tagNames.some((tn) => tn.startsWith(prefix)))
|
|
544
|
+
lines.push(`%TAG ${handle} ${prefix}`);
|
|
541
545
|
}
|
|
542
546
|
return lines.join("\n");
|
|
543
547
|
}
|
|
@@ -572,14 +576,14 @@ var require_anchors = __commonJS({
|
|
|
572
576
|
});
|
|
573
577
|
return anchors;
|
|
574
578
|
}
|
|
575
|
-
function findNewAnchor(
|
|
579
|
+
function findNewAnchor(prefix, exclude) {
|
|
576
580
|
for (let i = 1; true; ++i) {
|
|
577
|
-
const name = `${
|
|
581
|
+
const name = `${prefix}${i}`;
|
|
578
582
|
if (!exclude.has(name))
|
|
579
583
|
return name;
|
|
580
584
|
}
|
|
581
585
|
}
|
|
582
|
-
function createNodeAnchors(doc,
|
|
586
|
+
function createNodeAnchors(doc, prefix) {
|
|
583
587
|
const aliasObjects = [];
|
|
584
588
|
const sourceObjects = /* @__PURE__ */ new Map();
|
|
585
589
|
let prevAnchors = null;
|
|
@@ -587,7 +591,7 @@ var require_anchors = __commonJS({
|
|
|
587
591
|
onAnchor: (source) => {
|
|
588
592
|
aliasObjects.push(source);
|
|
589
593
|
prevAnchors ?? (prevAnchors = anchorNames(doc));
|
|
590
|
-
const anchor = findNewAnchor(
|
|
594
|
+
const anchor = findNewAnchor(prefix, prevAnchors);
|
|
591
595
|
prevAnchors.add(anchor);
|
|
592
596
|
return anchor;
|
|
593
597
|
},
|
|
@@ -2578,10 +2582,10 @@ var require_int = __commonJS({
|
|
|
2578
2582
|
var stringifyNumber = require_stringifyNumber();
|
|
2579
2583
|
var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
|
|
2580
2584
|
var intResolve = (str, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix);
|
|
2581
|
-
function intStringify(node, radix,
|
|
2585
|
+
function intStringify(node, radix, prefix) {
|
|
2582
2586
|
const { value } = node;
|
|
2583
2587
|
if (intIdentify(value) && value >= 0)
|
|
2584
|
-
return
|
|
2588
|
+
return prefix + value.toString(radix);
|
|
2585
2589
|
return stringifyNumber.stringifyNumber(node);
|
|
2586
2590
|
}
|
|
2587
2591
|
var intOct = {
|
|
@@ -3043,11 +3047,11 @@ var require_int2 = __commonJS({
|
|
|
3043
3047
|
const n = parseInt(str, radix);
|
|
3044
3048
|
return sign === "-" ? -1 * n : n;
|
|
3045
3049
|
}
|
|
3046
|
-
function intStringify(node, radix,
|
|
3050
|
+
function intStringify(node, radix, prefix) {
|
|
3047
3051
|
const { value } = node;
|
|
3048
3052
|
if (intIdentify(value)) {
|
|
3049
3053
|
const str = value.toString(radix);
|
|
3050
|
-
return value < 0 ? "-" +
|
|
3054
|
+
return value < 0 ? "-" + prefix + str.substr(1) : prefix + str;
|
|
3051
3055
|
}
|
|
3052
3056
|
return stringifyNumber.stringifyNumber(node);
|
|
3053
3057
|
}
|
|
@@ -7666,29 +7670,29 @@ var require_ignore = __commonJS({
|
|
|
7666
7670
|
var UNDERSCORE = "_";
|
|
7667
7671
|
var TRAILING_WILD_CARD_REPLACERS = {
|
|
7668
7672
|
[MODE_IGNORE](_, p1) {
|
|
7669
|
-
const
|
|
7670
|
-
return `${
|
|
7673
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
7674
|
+
return `${prefix}(?=$|\\/$)`;
|
|
7671
7675
|
},
|
|
7672
7676
|
[MODE_CHECK_IGNORE](_, p1) {
|
|
7673
|
-
const
|
|
7674
|
-
return `${
|
|
7677
|
+
const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
|
|
7678
|
+
return `${prefix}(?=$|\\/$)`;
|
|
7675
7679
|
}
|
|
7676
7680
|
};
|
|
7677
|
-
var makeRegexPrefix = (
|
|
7678
|
-
(prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(
|
|
7679
|
-
|
|
7681
|
+
var makeRegexPrefix = (pattern) => REPLACERS.reduce(
|
|
7682
|
+
(prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)),
|
|
7683
|
+
pattern
|
|
7680
7684
|
);
|
|
7681
7685
|
var isString = (subject) => typeof subject === "string";
|
|
7682
|
-
var checkPattern = (
|
|
7683
|
-
var splitPattern = (
|
|
7686
|
+
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
7687
|
+
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
7684
7688
|
var IgnoreRule = class {
|
|
7685
|
-
constructor(
|
|
7686
|
-
this.pattern =
|
|
7689
|
+
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
7690
|
+
this.pattern = pattern;
|
|
7687
7691
|
this.mark = mark;
|
|
7688
7692
|
this.negative = negative;
|
|
7689
7693
|
define(this, "body", body);
|
|
7690
7694
|
define(this, "ignoreCase", ignoreCase);
|
|
7691
|
-
define(this, "regexPrefix",
|
|
7695
|
+
define(this, "regexPrefix", prefix);
|
|
7692
7696
|
}
|
|
7693
7697
|
get regex() {
|
|
7694
7698
|
const key = UNDERSCORE + MODE_IGNORE;
|
|
@@ -7715,11 +7719,11 @@ var require_ignore = __commonJS({
|
|
|
7715
7719
|
}
|
|
7716
7720
|
};
|
|
7717
7721
|
var createRule = ({
|
|
7718
|
-
pattern
|
|
7722
|
+
pattern,
|
|
7719
7723
|
mark
|
|
7720
7724
|
}, ignoreCase) => {
|
|
7721
7725
|
let negative = false;
|
|
7722
|
-
let body =
|
|
7726
|
+
let body = pattern;
|
|
7723
7727
|
if (body.indexOf("!") === 0) {
|
|
7724
7728
|
negative = true;
|
|
7725
7729
|
body = body.substr(1);
|
|
@@ -7727,7 +7731,7 @@ var require_ignore = __commonJS({
|
|
|
7727
7731
|
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
7728
7732
|
const regexPrefix = makeRegexPrefix(body);
|
|
7729
7733
|
return new IgnoreRule(
|
|
7730
|
-
|
|
7734
|
+
pattern,
|
|
7731
7735
|
mark,
|
|
7732
7736
|
body,
|
|
7733
7737
|
ignoreCase,
|
|
@@ -7740,28 +7744,28 @@ var require_ignore = __commonJS({
|
|
|
7740
7744
|
this._ignoreCase = ignoreCase;
|
|
7741
7745
|
this._rules = [];
|
|
7742
7746
|
}
|
|
7743
|
-
_add(
|
|
7744
|
-
if (
|
|
7745
|
-
this._rules = this._rules.concat(
|
|
7747
|
+
_add(pattern) {
|
|
7748
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
7749
|
+
this._rules = this._rules.concat(pattern._rules._rules);
|
|
7746
7750
|
this._added = true;
|
|
7747
7751
|
return;
|
|
7748
7752
|
}
|
|
7749
|
-
if (isString(
|
|
7750
|
-
|
|
7751
|
-
pattern
|
|
7753
|
+
if (isString(pattern)) {
|
|
7754
|
+
pattern = {
|
|
7755
|
+
pattern
|
|
7752
7756
|
};
|
|
7753
7757
|
}
|
|
7754
|
-
if (checkPattern(
|
|
7755
|
-
const rule = createRule(
|
|
7758
|
+
if (checkPattern(pattern.pattern)) {
|
|
7759
|
+
const rule = createRule(pattern, this._ignoreCase);
|
|
7756
7760
|
this._added = true;
|
|
7757
7761
|
this._rules.push(rule);
|
|
7758
7762
|
}
|
|
7759
7763
|
}
|
|
7760
7764
|
// @param {Array<string> | string | Ignore} pattern
|
|
7761
|
-
add(
|
|
7765
|
+
add(pattern) {
|
|
7762
7766
|
this._added = false;
|
|
7763
7767
|
makeArray(
|
|
7764
|
-
isString(
|
|
7768
|
+
isString(pattern) ? splitPattern(pattern) : pattern
|
|
7765
7769
|
).forEach(this._add, this);
|
|
7766
7770
|
return this._added;
|
|
7767
7771
|
}
|
|
@@ -7839,15 +7843,15 @@ var require_ignore = __commonJS({
|
|
|
7839
7843
|
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
7840
7844
|
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
7841
7845
|
}
|
|
7842
|
-
add(
|
|
7843
|
-
if (this._rules.add(
|
|
7846
|
+
add(pattern) {
|
|
7847
|
+
if (this._rules.add(pattern)) {
|
|
7844
7848
|
this._initCache();
|
|
7845
7849
|
}
|
|
7846
7850
|
return this;
|
|
7847
7851
|
}
|
|
7848
7852
|
// legacy
|
|
7849
|
-
addPattern(
|
|
7850
|
-
return this.add(
|
|
7853
|
+
addPattern(pattern) {
|
|
7854
|
+
return this.add(pattern);
|
|
7851
7855
|
}
|
|
7852
7856
|
// @returns {TestResult}
|
|
7853
7857
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
@@ -7942,10 +7946,10 @@ function toolResultOutcome(result) {
|
|
|
7942
7946
|
if (!(result && typeof result === "object")) {
|
|
7943
7947
|
return ETelemetryOutcome.UNKNOWN;
|
|
7944
7948
|
}
|
|
7945
|
-
const
|
|
7946
|
-
if (
|
|
7949
|
+
const record2 = result;
|
|
7950
|
+
if (record2.isError === true || record2.ok === false || record2.success === false)
|
|
7947
7951
|
return ETelemetryOutcome.ERROR;
|
|
7948
|
-
if (
|
|
7952
|
+
if (record2.isError === false || record2.ok === true || record2.success === true || record2.type === "linkque.presentation-tool-result")
|
|
7949
7953
|
return ETelemetryOutcome.SUCCESS;
|
|
7950
7954
|
} catch {
|
|
7951
7955
|
}
|
|
@@ -8265,7 +8269,7 @@ var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-
|
|
|
8265
8269
|
var googleVertexApi = () => lazyApi(() => import("../../google-vertex-RIGAEYLC.js"));
|
|
8266
8270
|
|
|
8267
8271
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.js
|
|
8268
|
-
var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-
|
|
8272
|
+
var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-5RZTVEO2.js"));
|
|
8269
8273
|
|
|
8270
8274
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.js
|
|
8271
8275
|
var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-WLREQPZK.js"));
|
|
@@ -9961,8 +9965,8 @@ function IsString4(value) {
|
|
|
9961
9965
|
}
|
|
9962
9966
|
|
|
9963
9967
|
// ../../node_modules/typebox/build/type/engine/patterns/pattern.mjs
|
|
9964
|
-
function ParsePatternIntoTypes(
|
|
9965
|
-
const parsed = Pattern(
|
|
9968
|
+
function ParsePatternIntoTypes(pattern) {
|
|
9969
|
+
const parsed = Pattern(pattern);
|
|
9966
9970
|
const result = guard_exports.IsEqual(parsed.length, 2) ? parsed[0] : [];
|
|
9967
9971
|
return result;
|
|
9968
9972
|
}
|
|
@@ -9987,8 +9991,8 @@ function IsTemplateLiteralFinite(types) {
|
|
|
9987
9991
|
}
|
|
9988
9992
|
|
|
9989
9993
|
// ../../node_modules/typebox/build/type/engine/template_literal/create.mjs
|
|
9990
|
-
function TemplateLiteralCreate(
|
|
9991
|
-
return memory_exports.Create({ ["~kind"]: "TemplateLiteral" }, { type: "string", pattern
|
|
9994
|
+
function TemplateLiteralCreate(pattern) {
|
|
9995
|
+
return memory_exports.Create({ ["~kind"]: "TemplateLiteral" }, { type: "string", pattern }, {});
|
|
9992
9996
|
}
|
|
9993
9997
|
|
|
9994
9998
|
// ../../node_modules/typebox/build/type/engine/template_literal/decode.mjs
|
|
@@ -10023,13 +10027,13 @@ function DecodeTypes(types) {
|
|
|
10023
10027
|
guard_exports.IsEqual(types.length, 1) && IsLiteral(types[0]) ? types[0] : DecodeTypesAsUnion(types)
|
|
10024
10028
|
);
|
|
10025
10029
|
}
|
|
10026
|
-
function TemplateLiteralDecodeUnsafe(
|
|
10027
|
-
const types = ParsePatternIntoTypes(
|
|
10028
|
-
const result = guard_exports.IsEqual(types.length, 0) ? String2() : IsTemplateLiteralFinite(types) ? DecodeTypes(types) : TemplateLiteralCreate(
|
|
10030
|
+
function TemplateLiteralDecodeUnsafe(pattern) {
|
|
10031
|
+
const types = ParsePatternIntoTypes(pattern);
|
|
10032
|
+
const result = guard_exports.IsEqual(types.length, 0) ? String2() : IsTemplateLiteralFinite(types) ? DecodeTypes(types) : TemplateLiteralCreate(pattern);
|
|
10029
10033
|
return result;
|
|
10030
10034
|
}
|
|
10031
|
-
function TemplateLiteralDecode(
|
|
10032
|
-
const decoded = TemplateLiteralDecodeUnsafe(
|
|
10035
|
+
function TemplateLiteralDecode(pattern) {
|
|
10036
|
+
const decoded = TemplateLiteralDecodeUnsafe(pattern);
|
|
10033
10037
|
const result = IsTemplateLiteral(decoded) ? String2() : decoded;
|
|
10034
10038
|
return result;
|
|
10035
10039
|
}
|
|
@@ -10218,10 +10222,10 @@ function FromStringKey(key, value) {
|
|
|
10218
10222
|
}
|
|
10219
10223
|
|
|
10220
10224
|
// ../../node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs
|
|
10221
|
-
function FromTemplateKey(
|
|
10222
|
-
const types = ParsePatternIntoTypes(
|
|
10225
|
+
function FromTemplateKey(pattern, value) {
|
|
10226
|
+
const types = ParsePatternIntoTypes(pattern);
|
|
10223
10227
|
const finite = IsTemplateLiteralFinite(types);
|
|
10224
|
-
const result = finite ? FromKey(TemplateLiteralDecode(
|
|
10228
|
+
const result = finite ? FromKey(TemplateLiteralDecode(pattern), value) : CreateRecord(pattern, value);
|
|
10225
10229
|
return result;
|
|
10226
10230
|
}
|
|
10227
10231
|
|
|
@@ -10255,8 +10259,8 @@ function CreateObject(types, value) {
|
|
|
10255
10259
|
}
|
|
10256
10260
|
function FromUnionKey(types, value) {
|
|
10257
10261
|
const flattened = Flatten(types);
|
|
10258
|
-
const
|
|
10259
|
-
return IsSchema(
|
|
10262
|
+
const record2 = TryBuildRecord(flattened, value);
|
|
10263
|
+
return IsSchema(record2) ? record2 : CreateObject(flattened, value);
|
|
10260
10264
|
}
|
|
10261
10265
|
|
|
10262
10266
|
// ../../node_modules/typebox/build/type/engine/record/from_key.mjs
|
|
@@ -10293,8 +10297,8 @@ function RecordPattern(type) {
|
|
|
10293
10297
|
return guard_exports.Keys(type.patternProperties)[0];
|
|
10294
10298
|
}
|
|
10295
10299
|
function RecordKey(type) {
|
|
10296
|
-
const
|
|
10297
|
-
const result = guard_exports.IsEqual(
|
|
10300
|
+
const pattern = RecordPattern(type);
|
|
10301
|
+
const result = guard_exports.IsEqual(pattern, StringKey) ? String2() : guard_exports.IsEqual(pattern, IntegerKey) ? Integer() : guard_exports.IsEqual(pattern, NumberKey) ? Number2() : TemplateLiteralDecodeUnsafe(pattern);
|
|
10298
10302
|
return result;
|
|
10299
10303
|
}
|
|
10300
10304
|
function RecordValue(type) {
|
|
@@ -11187,47 +11191,47 @@ function ParseTemplateIntoTypes(template) {
|
|
|
11187
11191
|
function JoinString(input) {
|
|
11188
11192
|
return input.join("|");
|
|
11189
11193
|
}
|
|
11190
|
-
function UnwrapTemplateLiteralPattern(
|
|
11191
|
-
return
|
|
11194
|
+
function UnwrapTemplateLiteralPattern(pattern) {
|
|
11195
|
+
return pattern.slice(1, pattern.length - 1);
|
|
11192
11196
|
}
|
|
11193
|
-
function EncodeLiteral(value, right,
|
|
11194
|
-
return EncodeTypes(right, `${
|
|
11197
|
+
function EncodeLiteral(value, right, pattern) {
|
|
11198
|
+
return EncodeTypes(right, `${pattern}${value}`);
|
|
11195
11199
|
}
|
|
11196
|
-
function EncodeBigInt(right,
|
|
11197
|
-
return EncodeTypes(right, `${
|
|
11200
|
+
function EncodeBigInt(right, pattern) {
|
|
11201
|
+
return EncodeTypes(right, `${pattern}${BigIntPattern}`);
|
|
11198
11202
|
}
|
|
11199
|
-
function EncodeInteger(right,
|
|
11200
|
-
return EncodeTypes(right, `${
|
|
11203
|
+
function EncodeInteger(right, pattern) {
|
|
11204
|
+
return EncodeTypes(right, `${pattern}${IntegerPattern}`);
|
|
11201
11205
|
}
|
|
11202
|
-
function EncodeNumber(right,
|
|
11203
|
-
return EncodeTypes(right, `${
|
|
11206
|
+
function EncodeNumber(right, pattern) {
|
|
11207
|
+
return EncodeTypes(right, `${pattern}${NumberPattern}`);
|
|
11204
11208
|
}
|
|
11205
|
-
function EncodeBoolean(right,
|
|
11206
|
-
return EncodeType(Union([Literal("false"), Literal("true")]), right,
|
|
11209
|
+
function EncodeBoolean(right, pattern) {
|
|
11210
|
+
return EncodeType(Union([Literal("false"), Literal("true")]), right, pattern);
|
|
11207
11211
|
}
|
|
11208
|
-
function EncodeString(right,
|
|
11209
|
-
return EncodeTypes(right, `${
|
|
11212
|
+
function EncodeString(right, pattern) {
|
|
11213
|
+
return EncodeTypes(right, `${pattern}${StringPattern}`);
|
|
11210
11214
|
}
|
|
11211
|
-
function EncodeTemplateLiteral(templatePattern, right,
|
|
11212
|
-
return EncodeTypes(right, `${
|
|
11215
|
+
function EncodeTemplateLiteral(templatePattern, right, pattern) {
|
|
11216
|
+
return EncodeTypes(right, `${pattern}${UnwrapTemplateLiteralPattern(templatePattern)}`);
|
|
11213
11217
|
}
|
|
11214
|
-
function EncodeTemplateLiteralDeferred(types, right,
|
|
11218
|
+
function EncodeTemplateLiteralDeferred(types, right, pattern) {
|
|
11215
11219
|
const templateLiteral = TemplateLiteralAction(types, {});
|
|
11216
|
-
const result = EncodeType(templateLiteral, right,
|
|
11220
|
+
const result = EncodeType(templateLiteral, right, pattern);
|
|
11217
11221
|
return result;
|
|
11218
11222
|
}
|
|
11219
|
-
function EncodeEnum(types, right,
|
|
11223
|
+
function EncodeEnum(types, right, pattern) {
|
|
11220
11224
|
const variants = EnumValuesToVariants(types);
|
|
11221
|
-
return EncodeUnion(variants, right,
|
|
11225
|
+
return EncodeUnion(variants, right, pattern);
|
|
11222
11226
|
}
|
|
11223
|
-
function EncodeUnion(types, right,
|
|
11224
|
-
return guard_exports.TakeLeft(types, (head, tail) => EncodeUnion(tail, right,
|
|
11227
|
+
function EncodeUnion(types, right, pattern, result = []) {
|
|
11228
|
+
return guard_exports.TakeLeft(types, (head, tail) => EncodeUnion(tail, right, pattern, [...result, EncodeType(head, [], "")]), () => EncodeTypes(right, `${pattern}(${JoinString(result)})`));
|
|
11225
11229
|
}
|
|
11226
|
-
function EncodeType(type, right,
|
|
11227
|
-
return IsEnum(type) ? EncodeEnum(type.enum, right,
|
|
11230
|
+
function EncodeType(type, right, pattern) {
|
|
11231
|
+
return IsEnum(type) ? EncodeEnum(type.enum, right, pattern) : IsInteger3(type) ? EncodeInteger(right, pattern) : IsLiteral(type) ? EncodeLiteral(type.const, right, pattern) : IsBigInt3(type) ? EncodeBigInt(right, pattern) : IsBoolean4(type) ? EncodeBoolean(right, pattern) : IsNumber4(type) ? EncodeNumber(right, pattern) : IsString4(type) ? EncodeString(right, pattern) : IsTemplateLiteral(type) ? EncodeTemplateLiteral(type.pattern, right, pattern) : IsTemplateLiteralDeferred(type) ? EncodeTemplateLiteralDeferred(type.parameters[0], right, pattern) : IsUnion(type) ? EncodeUnion(type.anyOf, right, pattern) : NeverPattern;
|
|
11228
11232
|
}
|
|
11229
|
-
function EncodeTypes(types,
|
|
11230
|
-
return guard_exports.TakeLeft(types, (left, right) => EncodeType(left, right,
|
|
11233
|
+
function EncodeTypes(types, pattern) {
|
|
11234
|
+
return guard_exports.TakeLeft(types, (left, right) => EncodeType(left, right, pattern), () => pattern);
|
|
11231
11235
|
}
|
|
11232
11236
|
function EncodePattern(types) {
|
|
11233
11237
|
const encoded = EncodeTypes(types, "");
|
|
@@ -11235,8 +11239,8 @@ function EncodePattern(types) {
|
|
|
11235
11239
|
return result;
|
|
11236
11240
|
}
|
|
11237
11241
|
function TemplateLiteralEncode(types) {
|
|
11238
|
-
const
|
|
11239
|
-
const result = TemplateLiteralCreate(
|
|
11242
|
+
const pattern = EncodePattern(types);
|
|
11243
|
+
const result = TemplateLiteralCreate(pattern);
|
|
11240
11244
|
return result;
|
|
11241
11245
|
}
|
|
11242
11246
|
|
|
@@ -11943,8 +11947,8 @@ function FromLiteral3(mapping, value) {
|
|
|
11943
11947
|
}
|
|
11944
11948
|
|
|
11945
11949
|
// ../../node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs
|
|
11946
|
-
function FromTemplateLiteral(mapping,
|
|
11947
|
-
const decoded = TemplateLiteralDecode(
|
|
11950
|
+
function FromTemplateLiteral(mapping, pattern) {
|
|
11951
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
11948
11952
|
const result = FromType7(mapping, decoded);
|
|
11949
11953
|
return result;
|
|
11950
11954
|
}
|
|
@@ -12296,8 +12300,8 @@ function FromLiteral4(value) {
|
|
|
12296
12300
|
}
|
|
12297
12301
|
|
|
12298
12302
|
// ../../node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs
|
|
12299
|
-
function FromTemplateLiteral2(
|
|
12300
|
-
const decoded = TemplateLiteralDecode(
|
|
12303
|
+
function FromTemplateLiteral2(pattern) {
|
|
12304
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
12301
12305
|
const result = FromType9(decoded);
|
|
12302
12306
|
return result;
|
|
12303
12307
|
}
|
|
@@ -12503,8 +12507,8 @@ function Mapped2(identifier, type, as, property, options = {}) {
|
|
|
12503
12507
|
}
|
|
12504
12508
|
|
|
12505
12509
|
// ../../node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs
|
|
12506
|
-
function FromTemplateLiteral3(
|
|
12507
|
-
const decoded = TemplateLiteralDecode(
|
|
12510
|
+
function FromTemplateLiteral3(pattern) {
|
|
12511
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
12508
12512
|
const result = FromType13(decoded);
|
|
12509
12513
|
return result;
|
|
12510
12514
|
}
|
|
@@ -13236,8 +13240,8 @@ function fauxAssistantMessage(content, options = {}) {
|
|
|
13236
13240
|
function estimateTokens(text2) {
|
|
13237
13241
|
return Math.ceil(text2.length / 4);
|
|
13238
13242
|
}
|
|
13239
|
-
function randomId(
|
|
13240
|
-
return `${
|
|
13243
|
+
function randomId(prefix) {
|
|
13244
|
+
return `${prefix}:${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
13241
13245
|
}
|
|
13242
13246
|
function contentToText(content) {
|
|
13243
13247
|
if (typeof content === "string") {
|
|
@@ -15482,9 +15486,9 @@ function ErrorPattern(stack, context, schemaPath, instancePath, schema, value) {
|
|
|
15482
15486
|
|
|
15483
15487
|
// ../../node_modules/typebox/build/schema/engine/patternProperties.mjs
|
|
15484
15488
|
function BuildPatternProperties(stack, context, schema, value) {
|
|
15485
|
-
return emit_exports.ReduceAnd(guard_exports.Entries(schema.patternProperties).map(([
|
|
15489
|
+
return emit_exports.ReduceAnd(guard_exports.Entries(schema.patternProperties).map(([pattern, schema2]) => {
|
|
15486
15490
|
const [key, prop] = [Unique(), Unique()];
|
|
15487
|
-
const regexp = CreateVariable(new RegExp(
|
|
15491
|
+
const regexp = CreateVariable(new RegExp(pattern, "u"));
|
|
15488
15492
|
const notKey = emit_exports.Not(emit_exports.Call(emit_exports.Member(regexp, "test"), [key]));
|
|
15489
15493
|
const isSchema = BuildSchemaPushStack(stack, context, schema2, prop);
|
|
15490
15494
|
const addKey = context.AddKey(key);
|
|
@@ -15493,17 +15497,17 @@ function BuildPatternProperties(stack, context, schema, value) {
|
|
|
15493
15497
|
}));
|
|
15494
15498
|
}
|
|
15495
15499
|
function CheckPatternProperties(stack, context, schema, value) {
|
|
15496
|
-
return guard_exports.Every(guard_exports.Entries(schema.patternProperties), 0, ([
|
|
15497
|
-
const regexp = new RegExp(
|
|
15500
|
+
return guard_exports.Every(guard_exports.Entries(schema.patternProperties), 0, ([pattern, schema2]) => {
|
|
15501
|
+
const regexp = new RegExp(pattern, "u");
|
|
15498
15502
|
return guard_exports.Every(guard_exports.Entries(value), 0, ([key, prop]) => {
|
|
15499
15503
|
return !regexp.test(key) || CheckSchemaPushStack(stack, context, schema2, prop) && context.AddKey(key);
|
|
15500
15504
|
});
|
|
15501
15505
|
});
|
|
15502
15506
|
}
|
|
15503
15507
|
function ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value) {
|
|
15504
|
-
return guard_exports.EveryAll(guard_exports.Entries(schema.patternProperties), 0, ([
|
|
15505
|
-
const nextSchemaPath = `${schemaPath}/patternProperties/${
|
|
15506
|
-
const regexp = new RegExp(
|
|
15508
|
+
return guard_exports.EveryAll(guard_exports.Entries(schema.patternProperties), 0, ([pattern, schema2]) => {
|
|
15509
|
+
const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
|
|
15510
|
+
const regexp = new RegExp(pattern, "u");
|
|
15507
15511
|
return guard_exports.EveryAll(guard_exports.Entries(value), 0, ([key, value2]) => {
|
|
15508
15512
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
15509
15513
|
const notKey = !regexp.test(key);
|
|
@@ -41230,7 +41234,7 @@ var CardRenderMcpServer = class {
|
|
|
41230
41234
|
description: createPresentationDescription(config),
|
|
41231
41235
|
inputSchema: config.presentationInputSchema,
|
|
41232
41236
|
// execute 委托 callTool,返回 IAgentPresentationToolResult(execute 返回 unknown 兼容)。
|
|
41233
|
-
execute: (args, signal) => this.callTool(name, args, signal)
|
|
41237
|
+
execute: (args, signal, context) => this.callTool(name, args, signal, { context })
|
|
41234
41238
|
});
|
|
41235
41239
|
continue;
|
|
41236
41240
|
}
|
|
@@ -41287,7 +41291,7 @@ var CardRenderMcpServer = class {
|
|
|
41287
41291
|
description: `\u9009\u62E9 ${name} \u540E\u4F7F\u7528\u3002${source.purpose}\u3002\u6839\u636E\u5BF9\u8BDD\u548C\u5DF2\u6709\u6570\u636E\u6E90\u7ED3\u679C\u786E\u5B9A\u6240\u6709 MCP \u53C2\u6570\u3002${CARD_SEQUENCE}`,
|
|
41288
41292
|
inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
|
|
41289
41293
|
outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
|
|
41290
|
-
execute: async (args, signal) => {
|
|
41294
|
+
execute: async (args, signal, context) => {
|
|
41291
41295
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
41292
41296
|
throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
41293
41297
|
const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
|
|
@@ -41297,7 +41301,7 @@ var CardRenderMcpServer = class {
|
|
|
41297
41301
|
if (!handle)
|
|
41298
41302
|
throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
|
|
41299
41303
|
const mcpStartedAt = Date.now();
|
|
41300
|
-
const result = await handle.execute(args, signal);
|
|
41304
|
+
const result = await handle.execute(args, signal, context);
|
|
41301
41305
|
signal?.throwIfAborted();
|
|
41302
41306
|
if (this.closed)
|
|
41303
41307
|
throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
|
|
@@ -41405,22 +41409,22 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41405
41409
|
this.toolByName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
41406
41410
|
return tools;
|
|
41407
41411
|
}
|
|
41408
|
-
async callTool(name, args, signal) {
|
|
41412
|
+
async callTool(name, args, signal, options) {
|
|
41409
41413
|
const resource = this.resources.find((r) => createCardPresentationToolName(r.resourceId) === name);
|
|
41410
41414
|
if (!resource) {
|
|
41411
41415
|
const descriptor = this.toolByName.get(name);
|
|
41412
41416
|
if (!descriptor)
|
|
41413
41417
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
41414
|
-
return descriptor.execute(args, signal);
|
|
41418
|
+
return descriptor.execute(args, signal, options?.context);
|
|
41415
41419
|
}
|
|
41416
41420
|
const config = parseCardConfig(resource);
|
|
41417
41421
|
if (config.schemaVersion === "3" || config.schemaVersion === "4") {
|
|
41418
41422
|
const descriptor = this.toolByName.get(name);
|
|
41419
41423
|
if (!descriptor)
|
|
41420
41424
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
41421
|
-
return descriptor.execute(args, signal);
|
|
41425
|
+
return descriptor.execute(args, signal, options?.context);
|
|
41422
41426
|
}
|
|
41423
|
-
return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal);
|
|
41427
|
+
return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
|
|
41424
41428
|
}
|
|
41425
41429
|
async close() {
|
|
41426
41430
|
this.closed = true;
|
|
@@ -42038,7 +42042,8 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42038
42042
|
debugLog?.("[mcp] no mcp servers configured (no MCP tools will be available)", EDebugLogScope.MCP);
|
|
42039
42043
|
}
|
|
42040
42044
|
const mcpProxy = new McpProxyTool(this.mcpServerProvider, mcpServerSpecs, {
|
|
42041
|
-
debugLog
|
|
42045
|
+
debugLog,
|
|
42046
|
+
...options.mcpCallAuthorizer ? { authorizeCall: options.mcpCallAuthorizer } : {}
|
|
42042
42047
|
});
|
|
42043
42048
|
cleanup.push(() => mcpProxy.closeAll());
|
|
42044
42049
|
const cardServer = new CardRenderMcpServer(this.cardResources, mcpProxy, { ...options.runtimeContext, threadId: request.threadId }, debugLog);
|
|
@@ -42895,9 +42900,9 @@ var AppbaseSkillLoader = class {
|
|
|
42895
42900
|
const raw = raws[i];
|
|
42896
42901
|
if (typeof raw !== "string" || raw.length === 0)
|
|
42897
42902
|
continue;
|
|
42898
|
-
const
|
|
42899
|
-
if (
|
|
42900
|
-
records.push(
|
|
42903
|
+
const record2 = parseSkillFile(raw, resources[i]?.resourceId ?? "skill");
|
|
42904
|
+
if (record2)
|
|
42905
|
+
records.push(record2);
|
|
42901
42906
|
}
|
|
42902
42907
|
return records;
|
|
42903
42908
|
}
|
|
@@ -42957,6 +42962,8 @@ function resolveLinkqueEndpoints(env, envSelector) {
|
|
|
42957
42962
|
const config = new AppbaseRuntimeConfigProvider(env);
|
|
42958
42963
|
const isPre = envSelector === "PRE";
|
|
42959
42964
|
return {
|
|
42965
|
+
telemetryLogsEndpoint: config.get(isPre ? "LINKQUEGW_TELEMETRY_LOGS_ENDPOINT_PRE" : "LINKQUEGW_TELEMETRY_LOGS_ENDPOINT"),
|
|
42966
|
+
telemetryTracesEndpoint: config.get(isPre ? "LINKQUEGW_TELEMETRY_TRACES_ENDPOINT_PRE" : "LINKQUEGW_TELEMETRY_TRACES_ENDPOINT"),
|
|
42960
42967
|
linkqueBaseUrl: config.get(isPre ? "LINKQUE_BASE_URL_PRE" : "LINKQUE_BASE_URL"),
|
|
42961
42968
|
knowledgeBaseUrl: config.get(isPre ? "LINKQUEGW_KNOWLEDGE_BASE_URL_PRE" : "LINKQUEGW_KNOWLEDGE_BASE_URL"),
|
|
42962
42969
|
webSearchBaseUrl: config.get(isPre ? "LINKQUEGW_WEB_SEARCH_BASE_URL_PRE" : "LINKQUEGW_WEB_SEARCH_BASE_URL"),
|
|
@@ -42968,10 +42975,12 @@ function resolveLinkqueEndpoints(env, envSelector) {
|
|
|
42968
42975
|
function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
|
|
42969
42976
|
const log = (...a) => logCtx?.log?.("[runtime-factory]", ...a);
|
|
42970
42977
|
const debugLog = logCtx?.log ? (line, scope) => {
|
|
42971
|
-
const
|
|
42972
|
-
logCtx.log?.(
|
|
42978
|
+
const prefix = scope ? `[${scope}] ` : "";
|
|
42979
|
+
logCtx.log?.(prefix + line);
|
|
42973
42980
|
} : void 0;
|
|
42974
42981
|
const runtimePorts = {};
|
|
42982
|
+
if (ports.telemetry)
|
|
42983
|
+
runtimePorts.telemetry = ports.telemetry;
|
|
42975
42984
|
if (ports.linkqueBaseUrl) {
|
|
42976
42985
|
runtimePorts.linkqueBaseUrl = ports.linkqueBaseUrl;
|
|
42977
42986
|
log("linkqueBaseUrl: ->", ports.linkqueBaseUrl);
|
|
@@ -43301,9 +43310,9 @@ function createSearchSnippet(content, keyword) {
|
|
|
43301
43310
|
const firstMatch = lowerContent.indexOf(lowerKeyword);
|
|
43302
43311
|
const contentStart = firstMatch < 0 ? 0 : Math.max(0, Math.min(firstMatch - 40, normalizedContent.length - SEARCH_SNIPPET_LENGTH));
|
|
43303
43312
|
const rawSnippet = normalizedContent.slice(contentStart, contentStart + SEARCH_SNIPPET_LENGTH);
|
|
43304
|
-
const
|
|
43313
|
+
const prefix = contentStart > 0 ? "\u2026" : "";
|
|
43305
43314
|
const suffix = contentStart + rawSnippet.length < normalizedContent.length ? "\u2026" : "";
|
|
43306
|
-
const snippet = `${
|
|
43315
|
+
const snippet = `${prefix}${rawSnippet}${suffix}`;
|
|
43307
43316
|
const highlightRanges = [];
|
|
43308
43317
|
if (lowerKeyword) {
|
|
43309
43318
|
const lowerSnippet = rawSnippet.toLowerCase();
|
|
@@ -43313,7 +43322,7 @@ function createSearchSnippet(content, keyword) {
|
|
|
43313
43322
|
if (start < 0)
|
|
43314
43323
|
break;
|
|
43315
43324
|
highlightRanges.push({
|
|
43316
|
-
start:
|
|
43325
|
+
start: prefix.length + start,
|
|
43317
43326
|
length: keyword.length
|
|
43318
43327
|
});
|
|
43319
43328
|
from = start + Math.max(1, lowerKeyword.length);
|
|
@@ -44606,7 +44615,7 @@ function readStatusError(status, code, message) {
|
|
|
44606
44615
|
|
|
44607
44616
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/homeData.js
|
|
44608
44617
|
var HOME_DATA_REQUEST_OPERATION = "homeData.request";
|
|
44609
|
-
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId) {
|
|
44618
|
+
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
|
|
44610
44619
|
if (method.toUpperCase() !== "POST") {
|
|
44611
44620
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
44612
44621
|
}
|
|
@@ -44646,7 +44655,8 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
|
|
|
44646
44655
|
request: body,
|
|
44647
44656
|
protocol,
|
|
44648
44657
|
userId,
|
|
44649
|
-
mcpServerProvider: provider
|
|
44658
|
+
mcpServerProvider: provider,
|
|
44659
|
+
phoneAuthorization
|
|
44650
44660
|
});
|
|
44651
44661
|
debugLog?.("response", response.ok ? { ok: true } : { ok: false, errorCode: response.error.code });
|
|
44652
44662
|
return { status: 200, body: response };
|
|
@@ -44742,7 +44752,7 @@ function sanitizeDiagnosticText(value) {
|
|
|
44742
44752
|
|
|
44743
44753
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiAction.js
|
|
44744
44754
|
var A2UI_ACTION_EXECUTE_OPERATION = "a2uiAction.execute";
|
|
44745
|
-
async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
44755
|
+
async function runA2UIAction(method, body, userId, deps = {}, env = process.env, _appwriteApiKey, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
|
|
44746
44756
|
let mcpTraceId;
|
|
44747
44757
|
const debugLog = createA2UIInfoLog(env, logCtx, traceId, () => mcpTraceId);
|
|
44748
44758
|
const diagnostics = new CardActionDiagnostics(debugLog, {}, "handler");
|
|
@@ -44772,10 +44782,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44772
44782
|
if (request.agentId !== protocol.agentId) {
|
|
44773
44783
|
return paymentFailure(403, "AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
44774
44784
|
}
|
|
44775
|
-
const store = deps.paymentActionStore ?? resolveStore(env, appwriteApiKey);
|
|
44776
|
-
if (!store) {
|
|
44777
|
-
return paymentFailure(503, "EXECUTION_FAILED", "\u652F\u4ED8\u52A8\u4F5C\u5B58\u50A8\u672A\u914D\u7F6E", true);
|
|
44778
|
-
}
|
|
44779
44785
|
const provider = deps.mcpServerProvider ?? resolveProvider(protocol, env, envSelector, gatewayAuth, diagnostics.debugLog, (info) => {
|
|
44780
44786
|
mcpTraceId = info.traceId;
|
|
44781
44787
|
diagnostics.write("mcp_trace");
|
|
@@ -44783,34 +44789,9 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44783
44789
|
if (!provider) {
|
|
44784
44790
|
return paymentFailure(503, "MCP_NOT_BOUND", "\u652F\u4ED8 MCP \u8FDE\u63A5\u672A\u914D\u7F6E", true);
|
|
44785
44791
|
}
|
|
44786
|
-
diagnostics.stage = "store_begin";
|
|
44787
|
-
const invocation = createPaymentInvocation(userId, request);
|
|
44788
|
-
diagnostics.context.invocationId = invocation.invocationId;
|
|
44789
|
-
diagnostics.write("store_started");
|
|
44790
|
-
const begin = await store.begin(invocation);
|
|
44791
|
-
diagnostics.context.invocationId = begin.invocation.invocationId;
|
|
44792
|
-
if (begin.kind === "existing") {
|
|
44793
|
-
const current = begin.invocation;
|
|
44794
|
-
diagnostics.write("idempotency_hit", { status: current.status });
|
|
44795
|
-
if (current.tradeNO && current.status === "trade-created") {
|
|
44796
|
-
return {
|
|
44797
|
-
status: 200,
|
|
44798
|
-
body: success(current.invocationId, current.tradeNO)
|
|
44799
|
-
};
|
|
44800
|
-
}
|
|
44801
|
-
if (current.status === "executing") {
|
|
44802
|
-
return paymentFailure(409, "ACTION_IN_PROGRESS", "\u652F\u4ED8\u52A8\u4F5C\u6B63\u5728\u5904\u7406\u4E2D", true);
|
|
44803
|
-
}
|
|
44804
|
-
if (current.status === "uncertain") {
|
|
44805
|
-
return paymentFailure(409, "EXECUTION_UNCERTAIN", "\u521B\u5EFA\u4EA4\u6613\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u91CD\u590D\u652F\u4ED8", false);
|
|
44806
|
-
}
|
|
44807
|
-
return paymentFailure(409, "EXECUTION_FAILED", "\u652F\u4ED8\u52A8\u4F5C\u5DF2\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0\u5361\u7247\u540E\u91CD\u8BD5", false);
|
|
44808
|
-
}
|
|
44809
|
-
diagnostics.write("store_created", { status: begin.invocation.status });
|
|
44810
|
-
const invocationId = begin.invocation.invocationId;
|
|
44811
44792
|
diagnostics.stage = "execute";
|
|
44812
44793
|
const response = await executeCardAction({
|
|
44813
|
-
request
|
|
44794
|
+
request,
|
|
44814
44795
|
protocol,
|
|
44815
44796
|
runtimeContext: {
|
|
44816
44797
|
agentId: protocol.agentId,
|
|
@@ -44818,23 +44799,11 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44818
44799
|
userId
|
|
44819
44800
|
},
|
|
44820
44801
|
mcpServerProvider: provider,
|
|
44821
|
-
debugLog
|
|
44802
|
+
debugLog,
|
|
44803
|
+
phoneAuthorization
|
|
44822
44804
|
});
|
|
44823
|
-
|
|
44824
|
-
if (response.ok) {
|
|
44825
|
-
await store.update(invocationId, {
|
|
44826
|
-
status: "trade-created",
|
|
44827
|
-
tradeNO: response.result.tradeNO
|
|
44828
|
-
});
|
|
44829
|
-
diagnostics.write("store_updated", { status: "trade-created" });
|
|
44805
|
+
if (response.ok)
|
|
44830
44806
|
return { status: 200, body: response };
|
|
44831
|
-
}
|
|
44832
|
-
await store.update(invocationId, {
|
|
44833
|
-
status: response.error.code === "EXECUTION_FAILED" ? "uncertain" : "failed-before-execute"
|
|
44834
|
-
});
|
|
44835
|
-
diagnostics.write("store_updated", {
|
|
44836
|
-
status: response.error.code === "EXECUTION_FAILED" ? "uncertain" : "failed-before-execute"
|
|
44837
|
-
});
|
|
44838
44807
|
return {
|
|
44839
44808
|
status: response.error.code === "EXECUTION_FAILED" ? 502 : 400,
|
|
44840
44809
|
body: response
|
|
@@ -44853,11 +44822,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44853
44822
|
throw error;
|
|
44854
44823
|
}
|
|
44855
44824
|
}
|
|
44856
|
-
function resolveStore(env, appwriteApiKey) {
|
|
44857
|
-
const config = new AppbaseRuntimeConfigProvider(env);
|
|
44858
|
-
const handle = createAppBaseClient(env, void 0, appwriteApiKey);
|
|
44859
|
-
return createPaymentActionStore(handle.databases, config.get("A2UI_ACTION_DATABASE_ID"), config.get("A2UI_ACTION_TABLE_ID"));
|
|
44860
|
-
}
|
|
44861
44825
|
function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTraceId) {
|
|
44862
44826
|
let auth;
|
|
44863
44827
|
try {
|
|
@@ -44877,9 +44841,6 @@ function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTr
|
|
|
44877
44841
|
...debugLog ? { onTraceId } : {}
|
|
44878
44842
|
});
|
|
44879
44843
|
}
|
|
44880
|
-
function success(invocationId, tradeNO) {
|
|
44881
|
-
return { ok: true, invocationId, result: { kind: "payment", tradeNO } };
|
|
44882
|
-
}
|
|
44883
44844
|
function paymentFailure(status, code, message, retryable) {
|
|
44884
44845
|
return { status, body: { ok: false, error: { code, message, retryable } } };
|
|
44885
44846
|
}
|
|
@@ -44887,271 +44848,59 @@ function errorMessage(error, fallback) {
|
|
|
44887
44848
|
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
44888
44849
|
}
|
|
44889
44850
|
|
|
44890
|
-
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/
|
|
44891
|
-
import {
|
|
44892
|
-
|
|
44893
|
-
|
|
44894
|
-
|
|
44895
|
-
|
|
44896
|
-
|
|
44897
|
-
async create(phone) {
|
|
44898
|
-
const record3 = { id: randomUUID5(), phone };
|
|
44899
|
-
records.set(record3.id, record3);
|
|
44900
|
-
return record3;
|
|
44901
|
-
},
|
|
44902
|
-
async get(id) {
|
|
44903
|
-
return records.get(id);
|
|
44904
|
-
},
|
|
44905
|
-
clear() {
|
|
44906
|
-
records.clear();
|
|
44907
|
-
}
|
|
44908
|
-
};
|
|
44909
|
-
}
|
|
44910
|
-
async function referenceUserPhone(info, store) {
|
|
44911
|
-
if (!info.phone)
|
|
44912
|
-
return info;
|
|
44913
|
-
if (!store)
|
|
44914
|
-
throw new Error("PHONE_REFERENCE_UNAVAILABLE");
|
|
44915
|
-
const record3 = await store.create(info.phone);
|
|
44916
|
-
return { ...info, phone: `${prefix}${record3.id}}}` };
|
|
44917
|
-
}
|
|
44918
|
-
function schemaObject(value) {
|
|
44919
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
44920
|
-
}
|
|
44921
|
-
function modelSchema(value) {
|
|
44922
|
-
const schema = schemaObject(value);
|
|
44923
|
-
if (schema.type === "string" && schema["x-linkque-phone-reference"] === true) {
|
|
44924
|
-
return {
|
|
44925
|
-
anyOf: [schema, { type: "string", pattern: pattern.source }],
|
|
44926
|
-
description: "\u53EF\u4EE5\u5B8C\u6574\u4F20\u5165 client_capability \u8FD4\u56DE\u7684\u624B\u673A\u53F7\u5F15\u7528\uFF1B\u4E0D\u8981\u62FC\u63A5\u6216\u5C55\u5F00\u5F15\u7528\u3002"
|
|
44927
|
-
};
|
|
44928
|
-
}
|
|
44929
|
-
return {
|
|
44930
|
-
...schema,
|
|
44931
|
-
...schema.properties ? {
|
|
44932
|
-
properties: Object.fromEntries(Object.entries(schema.properties).map(([key, child]) => [
|
|
44933
|
-
key,
|
|
44934
|
-
modelSchema(child)
|
|
44935
|
-
]))
|
|
44936
|
-
} : {},
|
|
44937
|
-
...schema.items ? { items: modelSchema(schema.items) } : {}
|
|
44938
|
-
};
|
|
44939
|
-
}
|
|
44940
|
-
function collectReferenceIds(value, schema, ids) {
|
|
44941
|
-
if (typeof value === "string" && value.includes(prefix)) {
|
|
44942
|
-
const match = pattern.exec(value);
|
|
44943
|
-
if (!match || schema.type !== "string" || schema["x-linkque-phone-reference"] !== true)
|
|
44944
|
-
throw new Error("PHONE_REFERENCE_ARGUMENT_FORBIDDEN");
|
|
44945
|
-
ids.add(match[1]);
|
|
44946
|
-
return;
|
|
44947
|
-
}
|
|
44948
|
-
if (Array.isArray(value)) {
|
|
44949
|
-
for (const entry of value)
|
|
44950
|
-
collectReferenceIds(entry, schemaObject(schema.items), ids);
|
|
44951
|
-
return;
|
|
44952
|
-
}
|
|
44953
|
-
if (value && typeof value === "object") {
|
|
44954
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
44955
|
-
if (key.includes(prefix))
|
|
44956
|
-
throw new Error("PHONE_REFERENCE_ARGUMENT_FORBIDDEN");
|
|
44957
|
-
collectReferenceIds(entry, schemaObject(schema.properties?.[key]), ids);
|
|
44958
|
-
}
|
|
44959
|
-
}
|
|
44960
|
-
}
|
|
44961
|
-
async function loadReferences(value, schema, store) {
|
|
44962
|
-
const ids = /* @__PURE__ */ new Set();
|
|
44963
|
-
collectReferenceIds(value, schema, ids);
|
|
44964
|
-
const records = await Promise.all([...ids].map((id) => store.get(id)));
|
|
44965
|
-
if (records.some((record3) => !record3))
|
|
44966
|
-
throw new Error("PHONE_REFERENCE_EXPIRED_OR_UNAVAILABLE");
|
|
44967
|
-
return records;
|
|
44968
|
-
}
|
|
44969
|
-
function resolveArguments(value, schema, records) {
|
|
44970
|
-
if (typeof value === "string" && value.includes(prefix)) {
|
|
44971
|
-
const match = pattern.exec(value);
|
|
44972
|
-
if (!match || schema.type !== "string" || schema["x-linkque-phone-reference"] !== true)
|
|
44973
|
-
throw new Error("PHONE_REFERENCE_ARGUMENT_FORBIDDEN");
|
|
44974
|
-
const record3 = records.find((entry) => entry.id === match[1]);
|
|
44975
|
-
if (!record3)
|
|
44976
|
-
throw new Error("PHONE_REFERENCE_EXPIRED_OR_UNAVAILABLE");
|
|
44977
|
-
return record3.phone;
|
|
44978
|
-
}
|
|
44979
|
-
if (Array.isArray(value))
|
|
44980
|
-
return value.map((entry) => resolveArguments(entry, schemaObject(schema.items), records));
|
|
44981
|
-
if (value && typeof value === "object")
|
|
44982
|
-
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
44983
|
-
key,
|
|
44984
|
-
resolveArguments(entry, schemaObject(schema.properties?.[key]), records)
|
|
44985
|
-
]));
|
|
44986
|
-
return value;
|
|
44987
|
-
}
|
|
44988
|
-
function redactPhoneReferences(value, records) {
|
|
44989
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
44990
|
-
let text2 = String(value);
|
|
44991
|
-
for (const record3 of records) {
|
|
44992
|
-
const reference = `${prefix}${record3.id}}}`;
|
|
44993
|
-
text2 = text2.split(record3.phone).join(reference);
|
|
44994
|
-
const digits = record3.phone.replace(/\D/g, "");
|
|
44995
|
-
if (digits.length >= 7)
|
|
44996
|
-
text2 = text2.replace(new RegExp(digits.split("").join("[\\s-]*"), "g"), reference);
|
|
44997
|
-
}
|
|
44998
|
-
return typeof value === "number" && text2 === String(value) ? value : text2;
|
|
44999
|
-
}
|
|
45000
|
-
if (Array.isArray(value))
|
|
45001
|
-
return value.map((entry) => redactPhoneReferences(entry, records));
|
|
45002
|
-
if (value && typeof value === "object")
|
|
45003
|
-
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
45004
|
-
String(redactPhoneReferences(key, records)),
|
|
45005
|
-
redactPhoneReferences(entry, records)
|
|
45006
|
-
]));
|
|
45007
|
-
return value;
|
|
45008
|
-
}
|
|
45009
|
-
function withPhoneReferences(provider, store) {
|
|
45010
|
-
return {
|
|
45011
|
-
async servers(resources) {
|
|
45012
|
-
const servers = await provider.servers(resources);
|
|
45013
|
-
return servers.map((server) => {
|
|
45014
|
-
let schemas;
|
|
45015
|
-
const list = async () => {
|
|
45016
|
-
const tools = await server.listTools();
|
|
45017
|
-
schemas = new Map(tools.map((tool) => [tool.name, schemaObject(tool.inputSchema)]));
|
|
45018
|
-
return tools.map((tool) => ({
|
|
45019
|
-
...tool,
|
|
45020
|
-
inputSchema: modelSchema(tool.inputSchema),
|
|
45021
|
-
execute: (args, signal) => call(tool.name, args, signal)
|
|
45022
|
-
}));
|
|
45023
|
-
};
|
|
45024
|
-
const call = async (name, args, signal) => {
|
|
45025
|
-
if (!schemas)
|
|
45026
|
-
await list();
|
|
45027
|
-
const schema = schemas.get(name) ?? {};
|
|
45028
|
-
const records = await loadReferences(args, schema, store);
|
|
45029
|
-
const resolved = resolveArguments(args, schema, records);
|
|
45030
|
-
try {
|
|
45031
|
-
const result = await server.callTool(name, resolved, signal);
|
|
45032
|
-
return redactPhoneReferences(result, records);
|
|
45033
|
-
} catch {
|
|
45034
|
-
throw new Error("MCP_CALL_FAILED");
|
|
45035
|
-
}
|
|
45036
|
-
};
|
|
45037
|
-
return {
|
|
45038
|
-
resourceId: server.resourceId,
|
|
45039
|
-
serverName: server.serverName,
|
|
45040
|
-
listTools: list,
|
|
45041
|
-
callTool: call,
|
|
45042
|
-
close: server.close?.bind(server)
|
|
45043
|
-
};
|
|
45044
|
-
});
|
|
44851
|
+
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/appbaseTelemetry.js
|
|
44852
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
44853
|
+
function createAppbaseTelemetry(options) {
|
|
44854
|
+
const diagnostic = (code) => {
|
|
44855
|
+
try {
|
|
44856
|
+
options.logCtx?.log?.("[telemetry]", code);
|
|
44857
|
+
} catch {
|
|
45045
44858
|
}
|
|
45046
44859
|
};
|
|
45047
|
-
|
|
45048
|
-
|
|
45049
|
-
|
|
45050
|
-
|
|
45051
|
-
|
|
45052
|
-
|
|
45053
|
-
|
|
45054
|
-
|
|
44860
|
+
let telemetry;
|
|
44861
|
+
try {
|
|
44862
|
+
telemetry = new OtelRuntimeTelemetry({
|
|
44863
|
+
serviceName: "linkque-appbase",
|
|
44864
|
+
serviceVersion: "0.0.0",
|
|
44865
|
+
environment: options.environment,
|
|
44866
|
+
logsEndpoint: options.logsEndpoint,
|
|
44867
|
+
tracesEndpoint: options.tracesEndpoint,
|
|
44868
|
+
diagnostic: ({ code }) => diagnostic(code)
|
|
44869
|
+
});
|
|
44870
|
+
} catch {
|
|
44871
|
+
diagnostic("initialization_failed");
|
|
44872
|
+
telemetry = new NoopRuntimeTelemetry();
|
|
45055
44873
|
}
|
|
45056
|
-
};
|
|
45057
|
-
|
|
45058
|
-
"GRANT_MISSING",
|
|
45059
|
-
"GRANT_EXPIRED",
|
|
45060
|
-
"NETWORK_ERROR",
|
|
45061
|
-
"IDENTITY_MISSING",
|
|
45062
|
-
"IDENTITY_MISMATCH"
|
|
45063
|
-
]);
|
|
45064
|
-
function record2(value) {
|
|
45065
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
45066
|
-
}
|
|
45067
|
-
function createUserInfoMcpExchange(protocol, provider) {
|
|
45068
|
-
const resource = protocol.agent.resources.find((candidate) => candidate.resourceType === EResourceType.CLIENT_CAPABILITY);
|
|
45069
|
-
const binding = resource?.config.userInfo;
|
|
45070
|
-
if (!resource?.config.allowedCapabilities.includes("userInfo") || !binding)
|
|
45071
|
-
return void 0;
|
|
45072
|
-
if (!/^[A-Za-z0-9_-]{1,256}$/.test(binding.serverName) || !binding.mcpResourceId?.trim() || !binding.toolName?.trim())
|
|
45073
|
-
throw new UserInfoMcpError("INVALID_BINDING");
|
|
44874
|
+
const { authorizationHeader, mode } = options.gatewayAuth;
|
|
44875
|
+
const version = createHash3("sha256").update(authorizationHeader).digest("hex");
|
|
45074
44876
|
return {
|
|
45075
|
-
|
|
45076
|
-
|
|
45077
|
-
|
|
45078
|
-
|
|
45079
|
-
|
|
45080
|
-
|
|
45081
|
-
|
|
45082
|
-
|
|
45083
|
-
|
|
45084
|
-
|
|
45085
|
-
|
|
45086
|
-
|
|
45087
|
-
|
|
45088
|
-
|
|
45089
|
-
|
|
45090
|
-
|
|
45091
|
-
|
|
45092
|
-
|
|
45093
|
-
|
|
45094
|
-
|
|
45095
|
-
const aborted = new Promise((_, reject) => {
|
|
45096
|
-
rejectAbort = reject;
|
|
45097
|
-
});
|
|
45098
|
-
const abort = () => {
|
|
45099
|
-
abandoned = true;
|
|
45100
|
-
rejectAbort(new UserInfoMcpError("ABORTED"));
|
|
44877
|
+
telemetry,
|
|
44878
|
+
createContext(requestId) {
|
|
44879
|
+
return {
|
|
44880
|
+
parent: null,
|
|
44881
|
+
authorization: {
|
|
44882
|
+
subject: version,
|
|
44883
|
+
version,
|
|
44884
|
+
mode: mode === "user-token" ? "bearer" : "aak",
|
|
44885
|
+
agentId: options.agentId,
|
|
44886
|
+
environment: options.environment,
|
|
44887
|
+
getHeaders: () => ({
|
|
44888
|
+
authorization: authorizationHeader,
|
|
44889
|
+
"x-linkque-agent-id": options.agentId
|
|
44890
|
+
})
|
|
44891
|
+
},
|
|
44892
|
+
requestId,
|
|
44893
|
+
turnId: "",
|
|
44894
|
+
accountId: "",
|
|
44895
|
+
channel: "appbase",
|
|
44896
|
+
userKey: ""
|
|
45101
44897
|
};
|
|
45102
|
-
|
|
45103
|
-
|
|
45104
|
-
await Promise.allSettled(connected.map((server) => server.close?.()));
|
|
45105
|
-
}, () => {
|
|
45106
|
-
});
|
|
45107
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
45108
|
-
if (signal.aborted)
|
|
45109
|
-
abort();
|
|
45110
|
-
let servers = [];
|
|
44898
|
+
},
|
|
44899
|
+
async shutdown() {
|
|
45111
44900
|
try {
|
|
45112
|
-
|
|
45113
|
-
|
|
45114
|
-
|
|
45115
|
-
const server = servers.find((candidate) => candidate.resourceId === binding.mcpResourceId);
|
|
45116
|
-
if (!server)
|
|
45117
|
-
throw new UserInfoMcpError("EXCHANGE_FAILED");
|
|
45118
|
-
const result = record2(await Promise.race([
|
|
45119
|
-
server.callTool(binding.toolName, {
|
|
45120
|
-
phase: "userinfo",
|
|
45121
|
-
authCode: input.authCode,
|
|
45122
|
-
invocationId: input.invocationId
|
|
45123
|
-
}, signal),
|
|
45124
|
-
aborted
|
|
45125
|
-
]));
|
|
45126
|
-
if (signal.aborted)
|
|
45127
|
-
throw new UserInfoMcpError("ABORTED");
|
|
45128
|
-
let data = record2(result.structuredContent);
|
|
45129
|
-
if (!result.structuredContent && Array.isArray(result.content)) {
|
|
45130
|
-
const texts = result.content.filter((entry) => record2(entry).type === "text");
|
|
45131
|
-
if (texts.length === 1)
|
|
45132
|
-
data = record2(JSON.parse(String(record2(texts[0]).text)));
|
|
45133
|
-
}
|
|
45134
|
-
if (result.isError || data.error) {
|
|
45135
|
-
const code = record2(data.error).code;
|
|
45136
|
-
throw new UserInfoMcpError(typeof code === "string" && safeCodes.has(code) ? code : "EXCHANGE_FAILED");
|
|
45137
|
-
}
|
|
45138
|
-
if (typeof data.appId !== "string" || !/^[0-9]{16}$/.test(data.appId))
|
|
45139
|
-
throw new UserInfoMcpError("IDENTITY_MISMATCH");
|
|
45140
|
-
const output = { appId: data.appId };
|
|
45141
|
-
for (const key of ["open_id", "user_id", "phone"]) {
|
|
45142
|
-
if (typeof data[key] === "string" && data[key].trim())
|
|
45143
|
-
output[key] = data[key];
|
|
45144
|
-
}
|
|
45145
|
-
if (!output.open_id && !output.user_id)
|
|
45146
|
-
throw new UserInfoMcpError("IDENTITY_MISSING");
|
|
45147
|
-
return output;
|
|
45148
|
-
} catch (error) {
|
|
45149
|
-
if (error instanceof UserInfoMcpError)
|
|
45150
|
-
throw error;
|
|
45151
|
-
throw new UserInfoMcpError(signal.aborted ? "ABORTED" : "EXCHANGE_FAILED");
|
|
45152
|
-
} finally {
|
|
45153
|
-
signal.removeEventListener("abort", abort);
|
|
45154
|
-
await Promise.allSettled(servers.map((server) => server.close?.()));
|
|
44901
|
+
await telemetry.shutdown({ timeoutMs: 2e3, authorization: null });
|
|
44902
|
+
} catch {
|
|
44903
|
+
diagnostic("shutdown_failed");
|
|
45155
44904
|
}
|
|
45156
44905
|
}
|
|
45157
44906
|
};
|
|
@@ -45286,7 +45035,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45286
45035
|
let sessionLease = deps?.sessionLease;
|
|
45287
45036
|
let historyStore = deps?.historyStore;
|
|
45288
45037
|
let clientCapabilityStore = deps?.clientCapabilityStore;
|
|
45289
|
-
let paymentActionStore = deps?.paymentActionStore;
|
|
45290
45038
|
let chunkSize = Number(APPBASE_RUNTIME_CONFIG_DEFAULTS.RUN_CHUNK_SIZE);
|
|
45291
45039
|
if (!store) {
|
|
45292
45040
|
let storage;
|
|
@@ -45306,7 +45054,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45306
45054
|
store = createAppBaseStore(handle.databases, storage.databaseId, storage.tableId, historyOwnerId);
|
|
45307
45055
|
const config = new AppbaseRuntimeConfigProvider(env);
|
|
45308
45056
|
clientCapabilityStore ??= createClientCapabilityStore(handle.databases, config.get("CLIENT_CAPABILITY_DATABASE_ID"), config.get("CLIENT_CAPABILITY_TABLE_ID"));
|
|
45309
|
-
paymentActionStore ??= createPaymentActionStore(handle.databases, config.get("A2UI_ACTION_DATABASE_ID"), config.get("A2UI_ACTION_TABLE_ID"));
|
|
45310
45057
|
try {
|
|
45311
45058
|
historyStore ??= createConversationHistoryStore(handle.databases, resolveConversationHistoryStorage(env), historyOwnerId);
|
|
45312
45059
|
} catch (err2) {
|
|
@@ -45324,7 +45071,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45324
45071
|
chunkSize = storage.chunkSize;
|
|
45325
45072
|
}
|
|
45326
45073
|
const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
|
|
45327
|
-
const { linkqueBaseUrl, knowledgeBaseUrl, webSearchBaseUrl, eventBaseUrl, mcpSignEndpoint, openMcpBaseUrl } = resolveLinkqueEndpoints(env, envSelector);
|
|
45074
|
+
const { linkqueBaseUrl, knowledgeBaseUrl, webSearchBaseUrl, eventBaseUrl, mcpSignEndpoint, openMcpBaseUrl, telemetryLogsEndpoint, telemetryTracesEndpoint } = resolveLinkqueEndpoints(env, envSelector);
|
|
45328
45075
|
const mcpConfigResolver = createAppbaseMcpConfigResolver({
|
|
45329
45076
|
agentId: protocol.agentId,
|
|
45330
45077
|
remoteBaseUrl: openMcpBaseUrl,
|
|
@@ -45334,11 +45081,18 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45334
45081
|
resolveConfig: mcpConfigResolver,
|
|
45335
45082
|
getAuthorizationHeader: mcpAuthorizationHeaderProvider
|
|
45336
45083
|
});
|
|
45337
|
-
const
|
|
45338
|
-
const phoneReferenceStore = deps?.phoneReferenceStore ?? (userInfoExchange ? createRunPhoneReferenceStore() : void 0);
|
|
45339
|
-
const mcpServerProvider = phoneReferenceStore ? withPhoneReferences(rawMcpServerProvider, phoneReferenceStore) : rawMcpServerProvider;
|
|
45084
|
+
const mcpServerProvider = rawMcpServerProvider;
|
|
45340
45085
|
const securityAnswerPlugin = deps?.securityAnswerPlugin ?? createSecurityAnswerPlugin(historyStore, logCtx?.log);
|
|
45086
|
+
const telemetry = deps?.runtime ? void 0 : createAppbaseTelemetry({
|
|
45087
|
+
agentId: protocol.agentId,
|
|
45088
|
+
gatewayAuth: resolved,
|
|
45089
|
+
environment: new AppbaseRuntimeConfigProvider(env).get("LINKQUE_TELEMETRY_ENVIRONMENT") ?? (envSelector === "PRE" ? "pre" : "prod"),
|
|
45090
|
+
logsEndpoint: telemetryLogsEndpoint,
|
|
45091
|
+
tracesEndpoint: telemetryTracesEndpoint,
|
|
45092
|
+
logCtx
|
|
45093
|
+
});
|
|
45341
45094
|
const runtime = deps?.runtime ?? createAppBaseRuntime(protocol, env, {
|
|
45095
|
+
telemetry: telemetry?.telemetry,
|
|
45342
45096
|
...appwriteApiKey ? { appBaseApiKey: appwriteApiKey } : {},
|
|
45343
45097
|
mcpServerProvider,
|
|
45344
45098
|
mcpConfigResolver,
|
|
@@ -45361,13 +45115,11 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45361
45115
|
model: protocol.agent.model.defaultModel || void 0,
|
|
45362
45116
|
protocol,
|
|
45363
45117
|
runtime,
|
|
45118
|
+
telemetry,
|
|
45364
45119
|
store,
|
|
45365
45120
|
sessionLease,
|
|
45366
45121
|
historyStore,
|
|
45367
45122
|
clientCapabilityStore,
|
|
45368
|
-
userInfoExchange,
|
|
45369
|
-
phoneReferenceStore,
|
|
45370
|
-
paymentActionStore,
|
|
45371
45123
|
securityAnswerPlugin,
|
|
45372
45124
|
mcpServerProvider,
|
|
45373
45125
|
chunkSize
|
|
@@ -45436,11 +45188,10 @@ async function* debugLogAgentStream(stream, debugLog) {
|
|
|
45436
45188
|
}
|
|
45437
45189
|
|
|
45438
45190
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/clientCapabilityTool.js
|
|
45439
|
-
import { randomUUID as
|
|
45191
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
45440
45192
|
var POLL_INTERVAL_MS = 500;
|
|
45441
|
-
var ROW_TTL_MS = 3 * 6e4;
|
|
45442
45193
|
var LOCATION_WAIT_MS = 2e4;
|
|
45443
|
-
var
|
|
45194
|
+
var ROW_TTL_MS = 3 * 6e4;
|
|
45444
45195
|
var LOCATION_INPUT = Object.freeze({
|
|
45445
45196
|
type: 0,
|
|
45446
45197
|
cacheTimeout: 30,
|
|
@@ -45448,30 +45199,142 @@ var LOCATION_INPUT = Object.freeze({
|
|
|
45448
45199
|
});
|
|
45449
45200
|
function createClientCapabilityTool(input) {
|
|
45450
45201
|
const resource = input.protocol.agent.resources.find((candidate) => candidate.resourceType === EResourceType.CLIENT_CAPABILITY);
|
|
45451
|
-
if (!resource || !input.ownerId || !input.store)
|
|
45202
|
+
if (!resource?.config.allowedCapabilities.includes("location") || !input.request.clientCapabilities?.includes("location") || !input.ownerId || !input.store)
|
|
45203
|
+
return void 0;
|
|
45204
|
+
let pending = false;
|
|
45205
|
+
return {
|
|
45206
|
+
name: "client_capability",
|
|
45207
|
+
modelName: "client_capability",
|
|
45208
|
+
resourceId: resource.resourceId,
|
|
45209
|
+
label: "\u83B7\u53D6\u7528\u6237\u8BBE\u5907\u4FE1\u606F",
|
|
45210
|
+
description: "\u9700\u8981\u7528\u6237\u5F53\u524D\u4F4D\u7F6E\u65F6\u8C03\u7528\u3002",
|
|
45211
|
+
inputSchema: {
|
|
45212
|
+
type: "object",
|
|
45213
|
+
additionalProperties: false,
|
|
45214
|
+
required: ["capability", "reason"],
|
|
45215
|
+
properties: {
|
|
45216
|
+
capability: { const: "location" },
|
|
45217
|
+
reason: { type: "string", minLength: 1, maxLength: 200 }
|
|
45218
|
+
}
|
|
45219
|
+
},
|
|
45220
|
+
async execute(args, signal, context) {
|
|
45221
|
+
if (!context)
|
|
45222
|
+
return failure("CLIENT_CAPABILITY_CONTEXT_MISSING", "\u7AEF\u4FA7\u8C03\u7528\u4E0A\u4E0B\u6587\u4E0D\u53EF\u7528");
|
|
45223
|
+
const reason = readReason(args);
|
|
45224
|
+
if (!reason)
|
|
45225
|
+
return failure("CLIENT_CAPABILITY_INVALID_ARGS", "\u7AEF\u4FA7\u80FD\u529B\u53C2\u6570\u4E0D\u5408\u6CD5");
|
|
45226
|
+
if (pending)
|
|
45227
|
+
return failure("CLIENT_CAPABILITY_BUSY", "\u5DF2\u6709\u5B9A\u4F4D\u8C03\u7528\u6B63\u5728\u7B49\u5F85");
|
|
45228
|
+
pending = true;
|
|
45229
|
+
const invocationId = randomUUID5();
|
|
45230
|
+
const now = Date.now();
|
|
45231
|
+
const acceptUntil = new Date(now + LOCATION_WAIT_MS).toISOString();
|
|
45232
|
+
const event = {
|
|
45233
|
+
version: "1.0",
|
|
45234
|
+
invocationId,
|
|
45235
|
+
runId: input.request.runId,
|
|
45236
|
+
toolCallId: context.toolCallId,
|
|
45237
|
+
capability: "location",
|
|
45238
|
+
reason,
|
|
45239
|
+
input: LOCATION_INPUT,
|
|
45240
|
+
expiresAt: acceptUntil
|
|
45241
|
+
};
|
|
45242
|
+
let created = false;
|
|
45243
|
+
try {
|
|
45244
|
+
await input.store.create({
|
|
45245
|
+
invocationId,
|
|
45246
|
+
ownerId: input.ownerId,
|
|
45247
|
+
agentId: input.protocol.agentId,
|
|
45248
|
+
threadId: input.request.threadId,
|
|
45249
|
+
runId: input.request.runId,
|
|
45250
|
+
toolCallId: context.toolCallId,
|
|
45251
|
+
capability: "location",
|
|
45252
|
+
status: "pending",
|
|
45253
|
+
input: JSON.stringify(LOCATION_INPUT),
|
|
45254
|
+
createdAt: new Date(now).toISOString(),
|
|
45255
|
+
acceptUntil,
|
|
45256
|
+
expiresAt: new Date(now + ROW_TTL_MS).toISOString()
|
|
45257
|
+
});
|
|
45258
|
+
created = true;
|
|
45259
|
+
context.emit({ type: "client_capability_request", value: event });
|
|
45260
|
+
while (Date.now() < Date.parse(acceptUntil)) {
|
|
45261
|
+
if (signal?.aborted)
|
|
45262
|
+
throw abortError();
|
|
45263
|
+
const row = await input.store.get(invocationId);
|
|
45264
|
+
if (row?.status === "succeeded" || row?.status === "failed") {
|
|
45265
|
+
const result = parseStoredClientCapabilityResult(row.result);
|
|
45266
|
+
await input.store.consume(invocationId);
|
|
45267
|
+
return result ?? failure("CLIENT_CAPABILITY_INVALID_RESULT", "\u7AEF\u4FA7\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
|
|
45268
|
+
}
|
|
45269
|
+
await wait(POLL_INTERVAL_MS, signal);
|
|
45270
|
+
}
|
|
45271
|
+
await input.store.expire(invocationId);
|
|
45272
|
+
return failure("CLIENT_CAPABILITY_TIMEOUT", "\u7B49\u5F85\u7AEF\u4FA7\u80FD\u529B\u7ED3\u679C\u8D85\u65F6", true);
|
|
45273
|
+
} finally {
|
|
45274
|
+
if (created && signal?.aborted)
|
|
45275
|
+
await input.store.expire(invocationId);
|
|
45276
|
+
pending = false;
|
|
45277
|
+
}
|
|
45278
|
+
}
|
|
45279
|
+
};
|
|
45280
|
+
}
|
|
45281
|
+
function readReason(value) {
|
|
45282
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
45283
|
+
return void 0;
|
|
45284
|
+
const args = value;
|
|
45285
|
+
if (args.capability !== "location" || typeof args.reason !== "string")
|
|
45452
45286
|
return void 0;
|
|
45453
|
-
const
|
|
45454
|
-
|
|
45287
|
+
const reason = args.reason.trim();
|
|
45288
|
+
return reason && reason.length <= 200 ? reason : void 0;
|
|
45289
|
+
}
|
|
45290
|
+
function failure(code, message, retriable = false) {
|
|
45291
|
+
return { ok: false, error: { code, message, retriable } };
|
|
45292
|
+
}
|
|
45293
|
+
function abortError() {
|
|
45294
|
+
return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
|
|
45295
|
+
}
|
|
45296
|
+
function wait(ms, signal) {
|
|
45297
|
+
return new Promise((resolve, reject) => {
|
|
45298
|
+
const timer = setTimeout(resolve, ms);
|
|
45299
|
+
signal?.addEventListener("abort", () => {
|
|
45300
|
+
clearTimeout(timer);
|
|
45301
|
+
reject(abortError());
|
|
45302
|
+
}, { once: true });
|
|
45303
|
+
});
|
|
45304
|
+
}
|
|
45305
|
+
|
|
45306
|
+
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/mcpPhoneAuthorization.js
|
|
45307
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
45308
|
+
var POLL_INTERVAL_MS2 = 500;
|
|
45309
|
+
var AUTH_WAIT_MS = 95e3;
|
|
45310
|
+
var ROW_TTL_MS2 = 3 * 6e4;
|
|
45311
|
+
var AUTH_CODE_HEADER = "x-alipay-authcode";
|
|
45312
|
+
function createMcpPhoneAuthorizer(input) {
|
|
45313
|
+
const hasDependencies = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL).some((resource) => resource.config.dependencies?.some((dependency) => dependency.name === "phoneAuthorization"));
|
|
45314
|
+
if (!hasDependencies)
|
|
45455
45315
|
return void 0;
|
|
45456
|
-
|
|
45457
|
-
|
|
45458
|
-
|
|
45459
|
-
|
|
45316
|
+
return async ({ resourceIds, toolName, signal, context }) => {
|
|
45317
|
+
const policy = resolvePhoneAuthorizationDependency(input.protocol, resourceIds, toolName);
|
|
45318
|
+
if (!policy)
|
|
45319
|
+
return void 0;
|
|
45460
45320
|
if (signal?.aborted)
|
|
45461
|
-
throw
|
|
45321
|
+
throw abortError2();
|
|
45322
|
+
if (!input.ownerId || !input.store || !context || !input.request.clientCapabilities?.includes("userInfo")) {
|
|
45323
|
+
if (policy.required)
|
|
45324
|
+
throw authError("AUTH_UNAVAILABLE", "\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743");
|
|
45325
|
+
return void 0;
|
|
45326
|
+
}
|
|
45462
45327
|
const invocationId = randomUUID6();
|
|
45463
45328
|
const now = Date.now();
|
|
45464
|
-
const
|
|
45465
|
-
const
|
|
45466
|
-
const
|
|
45467
|
-
const capabilityInput = capability === "location" ? LOCATION_INPUT : { scopes: [...input.userInfoExchange.scopes] };
|
|
45468
|
-
const request = {
|
|
45329
|
+
const acceptUntil = new Date(now + AUTH_WAIT_MS).toISOString();
|
|
45330
|
+
const capabilityInput = { scopes: ["auth_user"] };
|
|
45331
|
+
const event = {
|
|
45469
45332
|
version: "1.0",
|
|
45470
45333
|
invocationId,
|
|
45471
45334
|
runId: input.request.runId,
|
|
45472
45335
|
toolCallId: context.toolCallId,
|
|
45473
|
-
capability,
|
|
45474
|
-
reason
|
|
45336
|
+
capability: "userInfo",
|
|
45337
|
+
reason: `\u8C03\u7528 ${toolName} \u9700\u8981\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743`,
|
|
45475
45338
|
input: capabilityInput,
|
|
45476
45339
|
expiresAt: acceptUntil
|
|
45477
45340
|
};
|
|
@@ -45484,158 +45347,68 @@ function createClientCapabilityTool(input) {
|
|
|
45484
45347
|
threadId: input.request.threadId,
|
|
45485
45348
|
runId: input.request.runId,
|
|
45486
45349
|
toolCallId: context.toolCallId,
|
|
45487
|
-
capability,
|
|
45350
|
+
capability: "userInfo",
|
|
45488
45351
|
status: "pending",
|
|
45489
45352
|
input: JSON.stringify(capabilityInput),
|
|
45490
45353
|
createdAt: new Date(now).toISOString(),
|
|
45491
45354
|
acceptUntil,
|
|
45492
|
-
expiresAt
|
|
45355
|
+
expiresAt: new Date(now + ROW_TTL_MS2).toISOString()
|
|
45493
45356
|
});
|
|
45494
45357
|
created = true;
|
|
45495
|
-
context.emit({ type: "client_capability_request", value:
|
|
45358
|
+
context.emit({ type: "client_capability_request", value: event });
|
|
45496
45359
|
while (Date.now() < Date.parse(acceptUntil)) {
|
|
45497
45360
|
if (signal?.aborted)
|
|
45498
|
-
throw
|
|
45361
|
+
throw abortError2();
|
|
45499
45362
|
const row = await input.store.get(invocationId);
|
|
45500
45363
|
if (row?.status === "succeeded" || row?.status === "failed") {
|
|
45501
45364
|
const result = parseStoredClientCapabilityResult(row.result);
|
|
45502
|
-
if (!result)
|
|
45503
|
-
return failure("CLIENT_CAPABILITY_INVALID_RESULT", "\u7AEF\u4FA7\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
|
|
45504
45365
|
await input.store.consume(invocationId);
|
|
45505
|
-
if (
|
|
45506
|
-
return result;
|
|
45507
|
-
|
|
45508
|
-
|
|
45509
|
-
|
|
45510
|
-
const exchanged = await input.userInfoExchange.exchange({ authCode: result.data.authCode, invocationId }, signal ? AbortSignal.any([signal, AbortSignal.timeout(2e4)]) : AbortSignal.timeout(2e4));
|
|
45511
|
-
return {
|
|
45512
|
-
ok: true,
|
|
45513
|
-
data: await referenceUserPhone(normalizeUserInfo(exchanged), input.phoneReferenceStore)
|
|
45514
|
-
};
|
|
45515
|
-
} catch (error) {
|
|
45516
|
-
if (signal?.aborted)
|
|
45517
|
-
throw abortError();
|
|
45518
|
-
return failure(readUserInfoExchangeErrorCode(error), "\u7528\u6237\u4FE1\u606F\u83B7\u53D6\u5931\u8D25");
|
|
45366
|
+
if (result?.ok && "authCode" in result.data) {
|
|
45367
|
+
return { [AUTH_CODE_HEADER]: result.data.authCode };
|
|
45368
|
+
}
|
|
45369
|
+
if (policy.required) {
|
|
45370
|
+
throw authError(result && !result.ok ? result.error.code : "AUTH_INVALID_RESULT", result && !result.ok ? result.error.message : "\u6388\u6743\u7ED3\u679C\u65E0\u6548");
|
|
45519
45371
|
}
|
|
45372
|
+
return void 0;
|
|
45520
45373
|
}
|
|
45521
|
-
await
|
|
45374
|
+
await wait2(POLL_INTERVAL_MS2, signal);
|
|
45522
45375
|
}
|
|
45523
45376
|
await input.store.expire(invocationId);
|
|
45524
|
-
|
|
45377
|
+
if (policy.required)
|
|
45378
|
+
throw authError("AUTH_TIMEOUT", "\u7B49\u5F85\u624B\u673A\u53F7\u6388\u6743\u8D85\u65F6");
|
|
45379
|
+
return void 0;
|
|
45525
45380
|
} catch (error) {
|
|
45526
|
-
if (created
|
|
45527
|
-
await input.store.expire(invocationId);
|
|
45528
|
-
|
|
45529
|
-
|
|
45530
|
-
|
|
45531
|
-
|
|
45532
|
-
|
|
45533
|
-
|
|
45534
|
-
resourceId: resource.resourceId,
|
|
45535
|
-
label: "\u83B7\u53D6\u7528\u6237\u8BBE\u5907\u4FE1\u606F",
|
|
45536
|
-
description: "\u9700\u8981\u7528\u6237\u4F4D\u7F6E\u3001\u6807\u8BC6\u6216\u624B\u673A\u53F7\u65F6\u8C03\u7528\u3002\u624B\u673A\u53F7\u53EA\u8FD4\u56DE\u672C\u8F6E\u6709\u6548\u7684\u5F15\u7528\uFF0C\u53EF\u539F\u6837\u4F20\u7ED9\u652F\u6301\u624B\u673A\u53F7\u5F15\u7528\u7684 MCP \u53C2\u6570\uFF1B\u5F15\u7528\u5931\u6548\u65F6\u91CD\u65B0\u83B7\u53D6\u3002",
|
|
45537
|
-
inputSchema: {
|
|
45538
|
-
type: "object",
|
|
45539
|
-
additionalProperties: false,
|
|
45540
|
-
required: ["capability", "reason"],
|
|
45541
|
-
properties: {
|
|
45542
|
-
capability: { enum: capabilities },
|
|
45543
|
-
reason: { type: "string", minLength: 1, maxLength: 200 }
|
|
45544
|
-
}
|
|
45545
|
-
},
|
|
45546
|
-
async execute(args, signal, context) {
|
|
45547
|
-
if (!context)
|
|
45548
|
-
return failure("CLIENT_CAPABILITY_CONTEXT_MISSING", "\u7AEF\u4FA7\u8C03\u7528\u4E0A\u4E0B\u6587\u4E0D\u53EF\u7528");
|
|
45549
|
-
const parsed = readArgs(args, capabilities);
|
|
45550
|
-
if (!parsed)
|
|
45551
|
-
return failure("CLIENT_CAPABILITY_INVALID_ARGS", "\u7AEF\u4FA7\u80FD\u529B\u53C2\u6570\u4E0D\u5408\u6CD5");
|
|
45552
|
-
if (parsed.capability === "location") {
|
|
45553
|
-
if (locationPending)
|
|
45554
|
-
return failure("CLIENT_CAPABILITY_BUSY", "\u5DF2\u6709\u5B9A\u4F4D\u8C03\u7528\u6B63\u5728\u7B49\u5F85");
|
|
45555
|
-
locationPending = true;
|
|
45556
|
-
try {
|
|
45557
|
-
return await native("location", parsed.reason, context, signal);
|
|
45558
|
-
} finally {
|
|
45559
|
-
locationPending = false;
|
|
45560
|
-
}
|
|
45561
|
-
}
|
|
45562
|
-
if (declinedUserInfo)
|
|
45563
|
-
return declinedUserInfo;
|
|
45564
|
-
if (userInfoPending)
|
|
45565
|
-
return userInfoPending;
|
|
45566
|
-
userInfoPending = native("userInfo", parsed.reason, context, signal);
|
|
45567
|
-
try {
|
|
45568
|
-
const result = await userInfoPending;
|
|
45569
|
-
if (!result.ok && isExplicitDecline(result.error.code))
|
|
45570
|
-
declinedUserInfo = result;
|
|
45571
|
-
return result;
|
|
45572
|
-
} finally {
|
|
45573
|
-
userInfoPending = void 0;
|
|
45381
|
+
if (created)
|
|
45382
|
+
await input.store.expire(invocationId).catch(() => void 0);
|
|
45383
|
+
if (signal?.aborted || error instanceof Error && error.name === "AbortError")
|
|
45384
|
+
throw error;
|
|
45385
|
+
if (policy.required) {
|
|
45386
|
+
if (error instanceof Error && "code" in error)
|
|
45387
|
+
throw error;
|
|
45388
|
+
throw authError("AUTH_FAILED", "\u624B\u673A\u53F7\u6388\u6743\u8BF7\u6C42\u5931\u8D25");
|
|
45574
45389
|
}
|
|
45390
|
+
return void 0;
|
|
45575
45391
|
}
|
|
45576
45392
|
};
|
|
45577
45393
|
}
|
|
45578
|
-
function
|
|
45579
|
-
|
|
45580
|
-
return void 0;
|
|
45581
|
-
const args = value;
|
|
45582
|
-
if (!capabilities.includes(args.capability) || typeof args.reason !== "string")
|
|
45583
|
-
return void 0;
|
|
45584
|
-
const reason = args.reason.trim();
|
|
45585
|
-
return reason && reason.length <= 200 ? { capability: args.capability, reason } : void 0;
|
|
45394
|
+
function authError(code, message) {
|
|
45395
|
+
return Object.assign(new Error(message), { code });
|
|
45586
45396
|
}
|
|
45587
|
-
function
|
|
45588
|
-
|
|
45589
|
-
throw new Error("USER_INFO_EXCHANGE_FAILED");
|
|
45590
|
-
const data = value;
|
|
45591
|
-
const output = {};
|
|
45592
|
-
for (const key of ["phone", "open_id", "user_id"]) {
|
|
45593
|
-
const normalized = typeof data[key] === "string" ? data[key].trim() : void 0;
|
|
45594
|
-
const maxLength = key === "phone" ? 64 : 512;
|
|
45595
|
-
if (normalized && normalized.length <= maxLength)
|
|
45596
|
-
output[key] = normalized;
|
|
45597
|
-
}
|
|
45598
|
-
if (!output.open_id && !output.user_id)
|
|
45599
|
-
throw new Error("USER_INFO_IDENTITY_MISSING");
|
|
45600
|
-
return output;
|
|
45397
|
+
function abortError2() {
|
|
45398
|
+
return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
|
|
45601
45399
|
}
|
|
45602
|
-
function
|
|
45603
|
-
return [
|
|
45604
|
-
"11",
|
|
45605
|
-
"USER_DENIED",
|
|
45606
|
-
"USER_CANCELLED",
|
|
45607
|
-
"AUTH_DENIED",
|
|
45608
|
-
"AUTH_CANCELLED",
|
|
45609
|
-
"USER_INFO_AUTHORIZATION_DECLINED"
|
|
45610
|
-
].includes(code);
|
|
45611
|
-
}
|
|
45612
|
-
function readUserInfoExchangeErrorCode(error) {
|
|
45613
|
-
const code = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
45614
|
-
return typeof code === "string" && ["GRANT_MISSING", "GRANT_EXPIRED", "NETWORK_ERROR"].includes(code) ? code : "USER_INFO_EXCHANGE_FAILED";
|
|
45615
|
-
}
|
|
45616
|
-
function failure(code, message, retriable = false) {
|
|
45617
|
-
return { ok: false, error: { code, message, retriable } };
|
|
45618
|
-
}
|
|
45619
|
-
function wait(ms, signal) {
|
|
45400
|
+
function wait2(ms, signal) {
|
|
45620
45401
|
return new Promise((resolve, reject) => {
|
|
45621
|
-
|
|
45622
|
-
return reject(abortError());
|
|
45623
|
-
const onAbort = () => {
|
|
45402
|
+
const finish = (settle) => {
|
|
45624
45403
|
clearTimeout(timer);
|
|
45625
|
-
reject(abortError());
|
|
45626
|
-
};
|
|
45627
|
-
const timer = setTimeout(() => {
|
|
45628
45404
|
signal?.removeEventListener("abort", onAbort);
|
|
45629
|
-
|
|
45630
|
-
}
|
|
45405
|
+
settle();
|
|
45406
|
+
};
|
|
45407
|
+
const onAbort = () => finish(() => reject(abortError2()));
|
|
45408
|
+
const timer = setTimeout(() => finish(resolve), ms);
|
|
45631
45409
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
45632
45410
|
});
|
|
45633
45411
|
}
|
|
45634
|
-
function abortError() {
|
|
45635
|
-
const error = new Error("client capability call aborted");
|
|
45636
|
-
error.name = "AbortError";
|
|
45637
|
-
return error;
|
|
45638
|
-
}
|
|
45639
45412
|
|
|
45640
45413
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chatExecution.js
|
|
45641
45414
|
async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId, signal, traceId) {
|
|
@@ -45662,6 +45435,7 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
|
|
|
45662
45435
|
};
|
|
45663
45436
|
}
|
|
45664
45437
|
const runOptions = {
|
|
45438
|
+
telemetryContext: deps.telemetry?.createContext(request.runId),
|
|
45665
45439
|
requestSource: EModelRequestSource.APPBASE_FUNCTION,
|
|
45666
45440
|
runtimeContext: {
|
|
45667
45441
|
agentId: deps.protocol.agentId,
|
|
@@ -45681,12 +45455,18 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
|
|
|
45681
45455
|
protocol: deps.protocol,
|
|
45682
45456
|
request,
|
|
45683
45457
|
ownerId: authenticatedUserId,
|
|
45684
|
-
store: deps.clientCapabilityStore
|
|
45685
|
-
userInfoExchange: deps.userInfoExchange,
|
|
45686
|
-
phoneReferenceStore: deps.phoneReferenceStore
|
|
45458
|
+
store: deps.clientCapabilityStore
|
|
45687
45459
|
});
|
|
45688
45460
|
if (clientCapabilityTool)
|
|
45689
45461
|
runOptions.additionalTools = [clientCapabilityTool];
|
|
45462
|
+
const mcpCallAuthorizer = createMcpPhoneAuthorizer({
|
|
45463
|
+
protocol: deps.protocol,
|
|
45464
|
+
request,
|
|
45465
|
+
ownerId: authenticatedUserId,
|
|
45466
|
+
store: deps.clientCapabilityStore
|
|
45467
|
+
});
|
|
45468
|
+
if (mcpCallAuthorizer)
|
|
45469
|
+
runOptions.mcpCallAuthorizer = mcpCallAuthorizer;
|
|
45690
45470
|
if (signal)
|
|
45691
45471
|
runOptions.signal = signal;
|
|
45692
45472
|
const agentReq = {
|
|
@@ -45746,7 +45526,6 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
|
|
|
45746
45526
|
} catch (err2) {
|
|
45747
45527
|
logError("finalize \u5931\u8D25:", err2);
|
|
45748
45528
|
} finally {
|
|
45749
|
-
deps.phoneReferenceStore?.clear();
|
|
45750
45529
|
}
|
|
45751
45530
|
}
|
|
45752
45531
|
return {
|
|
@@ -45770,7 +45549,7 @@ function shouldFlushConversationEvent(event) {
|
|
|
45770
45549
|
|
|
45771
45550
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiFunctionMcp.js
|
|
45772
45551
|
var A2UI_FUNCTION_MCP_EXECUTE_OPERATION = "a2uiFunctionMcp.execute";
|
|
45773
|
-
async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth) {
|
|
45552
|
+
async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth, phoneAuthorization) {
|
|
45774
45553
|
if (method.toUpperCase() !== "POST") {
|
|
45775
45554
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
45776
45555
|
}
|
|
@@ -45802,9 +45581,12 @@ async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process
|
|
|
45802
45581
|
request,
|
|
45803
45582
|
protocol,
|
|
45804
45583
|
runtimeContext: { threadId: request.threadId, userId },
|
|
45805
|
-
mcpServerProvider: provider
|
|
45584
|
+
mcpServerProvider: provider,
|
|
45585
|
+
phoneAuthorization
|
|
45806
45586
|
});
|
|
45807
|
-
} catch {
|
|
45587
|
+
} catch (error) {
|
|
45588
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
45589
|
+
throw error;
|
|
45808
45590
|
return failure2(502, "EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5");
|
|
45809
45591
|
}
|
|
45810
45592
|
return {
|
|
@@ -45860,17 +45642,6 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
|
|
|
45860
45642
|
const leaseOwnerId = randomUUID7();
|
|
45861
45643
|
let leaseAcquired = false;
|
|
45862
45644
|
let leaseReleased = false;
|
|
45863
|
-
if (cfg.sessionLease && !isPresentationRun) {
|
|
45864
|
-
try {
|
|
45865
|
-
leaseAcquired = await cfg.sessionLease.acquire(request.threadId, leaseOwnerId);
|
|
45866
|
-
} catch (err2) {
|
|
45867
|
-
logError("session \u79DF\u7EA6\u83B7\u53D6\u5931\u8D25:", err2);
|
|
45868
|
-
return jsonError(500, "session_lock_failed", err2 instanceof Error ? err2.message : "\u4F1A\u8BDD\u79DF\u7EA6\u83B7\u53D6\u5931\u8D25");
|
|
45869
|
-
}
|
|
45870
|
-
if (!leaseAcquired) {
|
|
45871
|
-
return jsonError(409, "thread_busy", "\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u6B63\u5728\u8FD0\u884C\u7684\u8BF7\u6C42");
|
|
45872
|
-
}
|
|
45873
|
-
}
|
|
45874
45645
|
const releaseLease = async () => {
|
|
45875
45646
|
if (!leaseAcquired || !cfg.sessionLease)
|
|
45876
45647
|
return true;
|
|
@@ -45886,6 +45657,17 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
|
|
|
45886
45657
|
}
|
|
45887
45658
|
};
|
|
45888
45659
|
try {
|
|
45660
|
+
if (cfg.sessionLease && !isPresentationRun) {
|
|
45661
|
+
try {
|
|
45662
|
+
leaseAcquired = await cfg.sessionLease.acquire(request.threadId, leaseOwnerId);
|
|
45663
|
+
} catch (err2) {
|
|
45664
|
+
logError("session \u79DF\u7EA6\u83B7\u53D6\u5931\u8D25:", err2);
|
|
45665
|
+
return jsonError(500, "session_lock_failed", err2 instanceof Error ? err2.message : "\u4F1A\u8BDD\u79DF\u7EA6\u83B7\u53D6\u5931\u8D25");
|
|
45666
|
+
}
|
|
45667
|
+
if (!leaseAcquired) {
|
|
45668
|
+
return jsonError(409, "thread_busy", "\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u6B63\u5728\u8FD0\u884C\u7684\u8BF7\u6C42");
|
|
45669
|
+
}
|
|
45670
|
+
}
|
|
45889
45671
|
if (cfg.historyStore && !isPresentationRun) {
|
|
45890
45672
|
try {
|
|
45891
45673
|
await cfg.historyStore.beginRun(request, cfg.protocol.agentId);
|
|
@@ -46036,7 +45818,11 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
|
|
|
46036
45818
|
}
|
|
46037
45819
|
return execution.response;
|
|
46038
45820
|
} finally {
|
|
46039
|
-
|
|
45821
|
+
try {
|
|
45822
|
+
await releaseLease();
|
|
45823
|
+
} finally {
|
|
45824
|
+
await cfg.telemetry?.shutdown();
|
|
45825
|
+
}
|
|
46040
45826
|
}
|
|
46041
45827
|
}
|
|
46042
45828
|
function readSearchableUserContent(request) {
|
|
@@ -46093,7 +45879,7 @@ function waitForCancellationPoll(delayMs, signal) {
|
|
|
46093
45879
|
}
|
|
46094
45880
|
});
|
|
46095
45881
|
}
|
|
46096
|
-
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) {
|
|
45882
|
+
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, mcpPhoneAuthorization) {
|
|
46097
45883
|
const operation = readOperation(bodyJSON);
|
|
46098
45884
|
const startedAt = Date.now();
|
|
46099
45885
|
const logGateway = (event, fields = {}, failed = false) => {
|
|
@@ -46125,6 +45911,9 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
|
|
|
46125
45911
|
}, result.status >= 400);
|
|
46126
45912
|
return result;
|
|
46127
45913
|
} catch (error) {
|
|
45914
|
+
const challenge = mcpPhoneAuthorizationChallenge(error);
|
|
45915
|
+
if (challenge)
|
|
45916
|
+
return challenge;
|
|
46128
45917
|
logGateway("dispatch.error", {
|
|
46129
45918
|
errorType: error instanceof Error ? error.name : typeof error,
|
|
46130
45919
|
durationMs: Date.now() - startedAt
|
|
@@ -46153,22 +45942,21 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
|
|
|
46153
45942
|
return observe(() => runHomeData(method, request, historyOwnerId, {
|
|
46154
45943
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46155
45944
|
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46156
|
-
}, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
|
|
45945
|
+
}, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
|
|
46157
45946
|
}
|
|
46158
45947
|
if (operation === A2UI_ACTION_EXECUTE_OPERATION) {
|
|
46159
45948
|
const request = readOperationPayload(bodyJSON);
|
|
46160
45949
|
return observe(() => runA2UIAction(method, request, historyOwnerId, {
|
|
46161
45950
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46162
|
-
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46163
|
-
|
|
46164
|
-
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
|
|
45951
|
+
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
45952
|
+
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
|
|
46165
45953
|
}
|
|
46166
45954
|
if (operation === A2UI_FUNCTION_MCP_EXECUTE_OPERATION) {
|
|
46167
45955
|
const request = readOperationPayload(bodyJSON);
|
|
46168
45956
|
return observe(() => runA2UIFunctionMcp(method, request, historyOwnerId, {
|
|
46169
45957
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46170
45958
|
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46171
|
-
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth));
|
|
45959
|
+
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, mcpPhoneAuthorization));
|
|
46172
45960
|
}
|
|
46173
45961
|
if (operation && HISTORY_OPERATIONS.has(operation)) {
|
|
46174
45962
|
return observe(() => runHistory(method, bodyJSON, env, deps ? { protocol: deps.protocol, store: deps.historyStore } : void 0, logCtx, historyOwnerId, appwriteApiKey));
|
|
@@ -46198,7 +45986,7 @@ async function chat(ctx) {
|
|
|
46198
45986
|
log: ctx.log,
|
|
46199
45987
|
error: ctx.error
|
|
46200
45988
|
}) : void 0;
|
|
46201
|
-
result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
45989
|
+
result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, readMcpPhoneAuthorization(ctx.req.headers)) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
46202
45990
|
} catch (err2) {
|
|
46203
45991
|
ctx.error?.(err2);
|
|
46204
45992
|
result = err2 instanceof LinkqueGatewayAuthError || err2 instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(err2.status, err2.code, err2.message) : {
|