linkque-cli-v2 1.3.5 → 1.3.6
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 +6 -110
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-LT6VSAY4.js → chunk-7SF3H2GM.js} +51 -144
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NBYB7HSY.js → chunk-NHRW2KQW.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-VVEDZWQ5.js → chunk-RHFHCJYP.js} +143 -35
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +330 -621
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/worker.js +183 -63
|
@@ -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-7SF3H2GM.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-NHRW2KQW.js";
|
|
48
48
|
import {
|
|
49
49
|
CANCEL_CONVERSATION_RUN_OPERATION,
|
|
50
50
|
CONVERSATION_HISTORY_VERSION,
|
|
@@ -126,6 +126,7 @@ import {
|
|
|
126
126
|
formatHttpLogLine,
|
|
127
127
|
isAgentPresentationToolResult,
|
|
128
128
|
isJsonValue,
|
|
129
|
+
isMcpPhoneAuthorizationError,
|
|
129
130
|
isSafeJsonPointer,
|
|
130
131
|
normalizeFollowUpQuestionStrings,
|
|
131
132
|
normalizeHookResources,
|
|
@@ -144,6 +145,7 @@ import {
|
|
|
144
145
|
readJsonPointer,
|
|
145
146
|
readStructuredContent,
|
|
146
147
|
redactHeaders,
|
|
148
|
+
resolvePhoneAuthorizationDependency,
|
|
147
149
|
resolveWebSearchResource,
|
|
148
150
|
stableToolName,
|
|
149
151
|
startRuntimeObservation,
|
|
@@ -151,7 +153,7 @@ import {
|
|
|
151
153
|
summarizeBody,
|
|
152
154
|
warnLogFailure,
|
|
153
155
|
wrapToolWithHooks
|
|
154
|
-
} from "../../chunk-
|
|
156
|
+
} from "../../chunk-RHFHCJYP.js";
|
|
155
157
|
import "../../chunk-XUFLSZM4.js";
|
|
156
158
|
import "../../chunk-GAYNLDWK.js";
|
|
157
159
|
import "../../chunk-HM7KNEG3.js";
|
|
@@ -444,8 +446,8 @@ var require_directives = __commonJS({
|
|
|
444
446
|
if (parts.length < 2)
|
|
445
447
|
return false;
|
|
446
448
|
}
|
|
447
|
-
const [handle,
|
|
448
|
-
this.tags[handle] =
|
|
449
|
+
const [handle, prefix] = parts;
|
|
450
|
+
this.tags[handle] = prefix;
|
|
449
451
|
return true;
|
|
450
452
|
}
|
|
451
453
|
case "%YAML": {
|
|
@@ -495,10 +497,10 @@ var require_directives = __commonJS({
|
|
|
495
497
|
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
|
|
496
498
|
if (!suffix)
|
|
497
499
|
onError(`The ${source} tag has no suffix`);
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
+
const prefix = this.tags[handle];
|
|
501
|
+
if (prefix) {
|
|
500
502
|
try {
|
|
501
|
-
return
|
|
503
|
+
return prefix + decodeURIComponent(suffix);
|
|
502
504
|
} catch (error) {
|
|
503
505
|
onError(String(error));
|
|
504
506
|
return null;
|
|
@@ -514,9 +516,9 @@ var require_directives = __commonJS({
|
|
|
514
516
|
* taking into account current tag prefixes and defaults.
|
|
515
517
|
*/
|
|
516
518
|
tagString(tag) {
|
|
517
|
-
for (const [handle,
|
|
518
|
-
if (tag.startsWith(
|
|
519
|
-
return handle + escapeTagName(tag.substring(
|
|
519
|
+
for (const [handle, prefix] of Object.entries(this.tags)) {
|
|
520
|
+
if (tag.startsWith(prefix))
|
|
521
|
+
return handle + escapeTagName(tag.substring(prefix.length));
|
|
520
522
|
}
|
|
521
523
|
return tag[0] === "!" ? tag : `!<${tag}>`;
|
|
522
524
|
}
|
|
@@ -533,11 +535,11 @@ var require_directives = __commonJS({
|
|
|
533
535
|
tagNames = Object.keys(tags);
|
|
534
536
|
} else
|
|
535
537
|
tagNames = [];
|
|
536
|
-
for (const [handle,
|
|
537
|
-
if (handle === "!!" &&
|
|
538
|
+
for (const [handle, prefix] of tagEntries) {
|
|
539
|
+
if (handle === "!!" && prefix === "tag:yaml.org,2002:")
|
|
538
540
|
continue;
|
|
539
|
-
if (!doc || tagNames.some((tn) => tn.startsWith(
|
|
540
|
-
lines.push(`%TAG ${handle} ${
|
|
541
|
+
if (!doc || tagNames.some((tn) => tn.startsWith(prefix)))
|
|
542
|
+
lines.push(`%TAG ${handle} ${prefix}`);
|
|
541
543
|
}
|
|
542
544
|
return lines.join("\n");
|
|
543
545
|
}
|
|
@@ -572,14 +574,14 @@ var require_anchors = __commonJS({
|
|
|
572
574
|
});
|
|
573
575
|
return anchors;
|
|
574
576
|
}
|
|
575
|
-
function findNewAnchor(
|
|
577
|
+
function findNewAnchor(prefix, exclude) {
|
|
576
578
|
for (let i = 1; true; ++i) {
|
|
577
|
-
const name = `${
|
|
579
|
+
const name = `${prefix}${i}`;
|
|
578
580
|
if (!exclude.has(name))
|
|
579
581
|
return name;
|
|
580
582
|
}
|
|
581
583
|
}
|
|
582
|
-
function createNodeAnchors(doc,
|
|
584
|
+
function createNodeAnchors(doc, prefix) {
|
|
583
585
|
const aliasObjects = [];
|
|
584
586
|
const sourceObjects = /* @__PURE__ */ new Map();
|
|
585
587
|
let prevAnchors = null;
|
|
@@ -587,7 +589,7 @@ var require_anchors = __commonJS({
|
|
|
587
589
|
onAnchor: (source) => {
|
|
588
590
|
aliasObjects.push(source);
|
|
589
591
|
prevAnchors ?? (prevAnchors = anchorNames(doc));
|
|
590
|
-
const anchor = findNewAnchor(
|
|
592
|
+
const anchor = findNewAnchor(prefix, prevAnchors);
|
|
591
593
|
prevAnchors.add(anchor);
|
|
592
594
|
return anchor;
|
|
593
595
|
},
|
|
@@ -2578,10 +2580,10 @@ var require_int = __commonJS({
|
|
|
2578
2580
|
var stringifyNumber = require_stringifyNumber();
|
|
2579
2581
|
var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
|
|
2580
2582
|
var intResolve = (str, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix);
|
|
2581
|
-
function intStringify(node, radix,
|
|
2583
|
+
function intStringify(node, radix, prefix) {
|
|
2582
2584
|
const { value } = node;
|
|
2583
2585
|
if (intIdentify(value) && value >= 0)
|
|
2584
|
-
return
|
|
2586
|
+
return prefix + value.toString(radix);
|
|
2585
2587
|
return stringifyNumber.stringifyNumber(node);
|
|
2586
2588
|
}
|
|
2587
2589
|
var intOct = {
|
|
@@ -3043,11 +3045,11 @@ var require_int2 = __commonJS({
|
|
|
3043
3045
|
const n = parseInt(str, radix);
|
|
3044
3046
|
return sign === "-" ? -1 * n : n;
|
|
3045
3047
|
}
|
|
3046
|
-
function intStringify(node, radix,
|
|
3048
|
+
function intStringify(node, radix, prefix) {
|
|
3047
3049
|
const { value } = node;
|
|
3048
3050
|
if (intIdentify(value)) {
|
|
3049
3051
|
const str = value.toString(radix);
|
|
3050
|
-
return value < 0 ? "-" +
|
|
3052
|
+
return value < 0 ? "-" + prefix + str.substr(1) : prefix + str;
|
|
3051
3053
|
}
|
|
3052
3054
|
return stringifyNumber.stringifyNumber(node);
|
|
3053
3055
|
}
|
|
@@ -7666,29 +7668,29 @@ var require_ignore = __commonJS({
|
|
|
7666
7668
|
var UNDERSCORE = "_";
|
|
7667
7669
|
var TRAILING_WILD_CARD_REPLACERS = {
|
|
7668
7670
|
[MODE_IGNORE](_, p1) {
|
|
7669
|
-
const
|
|
7670
|
-
return `${
|
|
7671
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
7672
|
+
return `${prefix}(?=$|\\/$)`;
|
|
7671
7673
|
},
|
|
7672
7674
|
[MODE_CHECK_IGNORE](_, p1) {
|
|
7673
|
-
const
|
|
7674
|
-
return `${
|
|
7675
|
+
const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
|
|
7676
|
+
return `${prefix}(?=$|\\/$)`;
|
|
7675
7677
|
}
|
|
7676
7678
|
};
|
|
7677
|
-
var makeRegexPrefix = (
|
|
7678
|
-
(prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(
|
|
7679
|
-
|
|
7679
|
+
var makeRegexPrefix = (pattern) => REPLACERS.reduce(
|
|
7680
|
+
(prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)),
|
|
7681
|
+
pattern
|
|
7680
7682
|
);
|
|
7681
7683
|
var isString = (subject) => typeof subject === "string";
|
|
7682
|
-
var checkPattern = (
|
|
7683
|
-
var splitPattern = (
|
|
7684
|
+
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
7685
|
+
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
7684
7686
|
var IgnoreRule = class {
|
|
7685
|
-
constructor(
|
|
7686
|
-
this.pattern =
|
|
7687
|
+
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
7688
|
+
this.pattern = pattern;
|
|
7687
7689
|
this.mark = mark;
|
|
7688
7690
|
this.negative = negative;
|
|
7689
7691
|
define(this, "body", body);
|
|
7690
7692
|
define(this, "ignoreCase", ignoreCase);
|
|
7691
|
-
define(this, "regexPrefix",
|
|
7693
|
+
define(this, "regexPrefix", prefix);
|
|
7692
7694
|
}
|
|
7693
7695
|
get regex() {
|
|
7694
7696
|
const key = UNDERSCORE + MODE_IGNORE;
|
|
@@ -7715,11 +7717,11 @@ var require_ignore = __commonJS({
|
|
|
7715
7717
|
}
|
|
7716
7718
|
};
|
|
7717
7719
|
var createRule = ({
|
|
7718
|
-
pattern
|
|
7720
|
+
pattern,
|
|
7719
7721
|
mark
|
|
7720
7722
|
}, ignoreCase) => {
|
|
7721
7723
|
let negative = false;
|
|
7722
|
-
let body =
|
|
7724
|
+
let body = pattern;
|
|
7723
7725
|
if (body.indexOf("!") === 0) {
|
|
7724
7726
|
negative = true;
|
|
7725
7727
|
body = body.substr(1);
|
|
@@ -7727,7 +7729,7 @@ var require_ignore = __commonJS({
|
|
|
7727
7729
|
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
7728
7730
|
const regexPrefix = makeRegexPrefix(body);
|
|
7729
7731
|
return new IgnoreRule(
|
|
7730
|
-
|
|
7732
|
+
pattern,
|
|
7731
7733
|
mark,
|
|
7732
7734
|
body,
|
|
7733
7735
|
ignoreCase,
|
|
@@ -7740,28 +7742,28 @@ var require_ignore = __commonJS({
|
|
|
7740
7742
|
this._ignoreCase = ignoreCase;
|
|
7741
7743
|
this._rules = [];
|
|
7742
7744
|
}
|
|
7743
|
-
_add(
|
|
7744
|
-
if (
|
|
7745
|
-
this._rules = this._rules.concat(
|
|
7745
|
+
_add(pattern) {
|
|
7746
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
7747
|
+
this._rules = this._rules.concat(pattern._rules._rules);
|
|
7746
7748
|
this._added = true;
|
|
7747
7749
|
return;
|
|
7748
7750
|
}
|
|
7749
|
-
if (isString(
|
|
7750
|
-
|
|
7751
|
-
pattern
|
|
7751
|
+
if (isString(pattern)) {
|
|
7752
|
+
pattern = {
|
|
7753
|
+
pattern
|
|
7752
7754
|
};
|
|
7753
7755
|
}
|
|
7754
|
-
if (checkPattern(
|
|
7755
|
-
const rule = createRule(
|
|
7756
|
+
if (checkPattern(pattern.pattern)) {
|
|
7757
|
+
const rule = createRule(pattern, this._ignoreCase);
|
|
7756
7758
|
this._added = true;
|
|
7757
7759
|
this._rules.push(rule);
|
|
7758
7760
|
}
|
|
7759
7761
|
}
|
|
7760
7762
|
// @param {Array<string> | string | Ignore} pattern
|
|
7761
|
-
add(
|
|
7763
|
+
add(pattern) {
|
|
7762
7764
|
this._added = false;
|
|
7763
7765
|
makeArray(
|
|
7764
|
-
isString(
|
|
7766
|
+
isString(pattern) ? splitPattern(pattern) : pattern
|
|
7765
7767
|
).forEach(this._add, this);
|
|
7766
7768
|
return this._added;
|
|
7767
7769
|
}
|
|
@@ -7839,15 +7841,15 @@ var require_ignore = __commonJS({
|
|
|
7839
7841
|
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
7840
7842
|
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
7841
7843
|
}
|
|
7842
|
-
add(
|
|
7843
|
-
if (this._rules.add(
|
|
7844
|
+
add(pattern) {
|
|
7845
|
+
if (this._rules.add(pattern)) {
|
|
7844
7846
|
this._initCache();
|
|
7845
7847
|
}
|
|
7846
7848
|
return this;
|
|
7847
7849
|
}
|
|
7848
7850
|
// legacy
|
|
7849
|
-
addPattern(
|
|
7850
|
-
return this.add(
|
|
7851
|
+
addPattern(pattern) {
|
|
7852
|
+
return this.add(pattern);
|
|
7851
7853
|
}
|
|
7852
7854
|
// @returns {TestResult}
|
|
7853
7855
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
@@ -7942,10 +7944,10 @@ function toolResultOutcome(result) {
|
|
|
7942
7944
|
if (!(result && typeof result === "object")) {
|
|
7943
7945
|
return ETelemetryOutcome.UNKNOWN;
|
|
7944
7946
|
}
|
|
7945
|
-
const
|
|
7946
|
-
if (
|
|
7947
|
+
const record2 = result;
|
|
7948
|
+
if (record2.isError === true || record2.ok === false || record2.success === false)
|
|
7947
7949
|
return ETelemetryOutcome.ERROR;
|
|
7948
|
-
if (
|
|
7950
|
+
if (record2.isError === false || record2.ok === true || record2.success === true || record2.type === "linkque.presentation-tool-result")
|
|
7949
7951
|
return ETelemetryOutcome.SUCCESS;
|
|
7950
7952
|
} catch {
|
|
7951
7953
|
}
|
|
@@ -9961,8 +9963,8 @@ function IsString4(value) {
|
|
|
9961
9963
|
}
|
|
9962
9964
|
|
|
9963
9965
|
// ../../node_modules/typebox/build/type/engine/patterns/pattern.mjs
|
|
9964
|
-
function ParsePatternIntoTypes(
|
|
9965
|
-
const parsed = Pattern(
|
|
9966
|
+
function ParsePatternIntoTypes(pattern) {
|
|
9967
|
+
const parsed = Pattern(pattern);
|
|
9966
9968
|
const result = guard_exports.IsEqual(parsed.length, 2) ? parsed[0] : [];
|
|
9967
9969
|
return result;
|
|
9968
9970
|
}
|
|
@@ -9987,8 +9989,8 @@ function IsTemplateLiteralFinite(types) {
|
|
|
9987
9989
|
}
|
|
9988
9990
|
|
|
9989
9991
|
// ../../node_modules/typebox/build/type/engine/template_literal/create.mjs
|
|
9990
|
-
function TemplateLiteralCreate(
|
|
9991
|
-
return memory_exports.Create({ ["~kind"]: "TemplateLiteral" }, { type: "string", pattern
|
|
9992
|
+
function TemplateLiteralCreate(pattern) {
|
|
9993
|
+
return memory_exports.Create({ ["~kind"]: "TemplateLiteral" }, { type: "string", pattern }, {});
|
|
9992
9994
|
}
|
|
9993
9995
|
|
|
9994
9996
|
// ../../node_modules/typebox/build/type/engine/template_literal/decode.mjs
|
|
@@ -10023,13 +10025,13 @@ function DecodeTypes(types) {
|
|
|
10023
10025
|
guard_exports.IsEqual(types.length, 1) && IsLiteral(types[0]) ? types[0] : DecodeTypesAsUnion(types)
|
|
10024
10026
|
);
|
|
10025
10027
|
}
|
|
10026
|
-
function TemplateLiteralDecodeUnsafe(
|
|
10027
|
-
const types = ParsePatternIntoTypes(
|
|
10028
|
-
const result = guard_exports.IsEqual(types.length, 0) ? String2() : IsTemplateLiteralFinite(types) ? DecodeTypes(types) : TemplateLiteralCreate(
|
|
10028
|
+
function TemplateLiteralDecodeUnsafe(pattern) {
|
|
10029
|
+
const types = ParsePatternIntoTypes(pattern);
|
|
10030
|
+
const result = guard_exports.IsEqual(types.length, 0) ? String2() : IsTemplateLiteralFinite(types) ? DecodeTypes(types) : TemplateLiteralCreate(pattern);
|
|
10029
10031
|
return result;
|
|
10030
10032
|
}
|
|
10031
|
-
function TemplateLiteralDecode(
|
|
10032
|
-
const decoded = TemplateLiteralDecodeUnsafe(
|
|
10033
|
+
function TemplateLiteralDecode(pattern) {
|
|
10034
|
+
const decoded = TemplateLiteralDecodeUnsafe(pattern);
|
|
10033
10035
|
const result = IsTemplateLiteral(decoded) ? String2() : decoded;
|
|
10034
10036
|
return result;
|
|
10035
10037
|
}
|
|
@@ -10218,10 +10220,10 @@ function FromStringKey(key, value) {
|
|
|
10218
10220
|
}
|
|
10219
10221
|
|
|
10220
10222
|
// ../../node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs
|
|
10221
|
-
function FromTemplateKey(
|
|
10222
|
-
const types = ParsePatternIntoTypes(
|
|
10223
|
+
function FromTemplateKey(pattern, value) {
|
|
10224
|
+
const types = ParsePatternIntoTypes(pattern);
|
|
10223
10225
|
const finite = IsTemplateLiteralFinite(types);
|
|
10224
|
-
const result = finite ? FromKey(TemplateLiteralDecode(
|
|
10226
|
+
const result = finite ? FromKey(TemplateLiteralDecode(pattern), value) : CreateRecord(pattern, value);
|
|
10225
10227
|
return result;
|
|
10226
10228
|
}
|
|
10227
10229
|
|
|
@@ -10255,8 +10257,8 @@ function CreateObject(types, value) {
|
|
|
10255
10257
|
}
|
|
10256
10258
|
function FromUnionKey(types, value) {
|
|
10257
10259
|
const flattened = Flatten(types);
|
|
10258
|
-
const
|
|
10259
|
-
return IsSchema(
|
|
10260
|
+
const record2 = TryBuildRecord(flattened, value);
|
|
10261
|
+
return IsSchema(record2) ? record2 : CreateObject(flattened, value);
|
|
10260
10262
|
}
|
|
10261
10263
|
|
|
10262
10264
|
// ../../node_modules/typebox/build/type/engine/record/from_key.mjs
|
|
@@ -10293,8 +10295,8 @@ function RecordPattern(type) {
|
|
|
10293
10295
|
return guard_exports.Keys(type.patternProperties)[0];
|
|
10294
10296
|
}
|
|
10295
10297
|
function RecordKey(type) {
|
|
10296
|
-
const
|
|
10297
|
-
const result = guard_exports.IsEqual(
|
|
10298
|
+
const pattern = RecordPattern(type);
|
|
10299
|
+
const result = guard_exports.IsEqual(pattern, StringKey) ? String2() : guard_exports.IsEqual(pattern, IntegerKey) ? Integer() : guard_exports.IsEqual(pattern, NumberKey) ? Number2() : TemplateLiteralDecodeUnsafe(pattern);
|
|
10298
10300
|
return result;
|
|
10299
10301
|
}
|
|
10300
10302
|
function RecordValue(type) {
|
|
@@ -11187,47 +11189,47 @@ function ParseTemplateIntoTypes(template) {
|
|
|
11187
11189
|
function JoinString(input) {
|
|
11188
11190
|
return input.join("|");
|
|
11189
11191
|
}
|
|
11190
|
-
function UnwrapTemplateLiteralPattern(
|
|
11191
|
-
return
|
|
11192
|
+
function UnwrapTemplateLiteralPattern(pattern) {
|
|
11193
|
+
return pattern.slice(1, pattern.length - 1);
|
|
11192
11194
|
}
|
|
11193
|
-
function EncodeLiteral(value, right,
|
|
11194
|
-
return EncodeTypes(right, `${
|
|
11195
|
+
function EncodeLiteral(value, right, pattern) {
|
|
11196
|
+
return EncodeTypes(right, `${pattern}${value}`);
|
|
11195
11197
|
}
|
|
11196
|
-
function EncodeBigInt(right,
|
|
11197
|
-
return EncodeTypes(right, `${
|
|
11198
|
+
function EncodeBigInt(right, pattern) {
|
|
11199
|
+
return EncodeTypes(right, `${pattern}${BigIntPattern}`);
|
|
11198
11200
|
}
|
|
11199
|
-
function EncodeInteger(right,
|
|
11200
|
-
return EncodeTypes(right, `${
|
|
11201
|
+
function EncodeInteger(right, pattern) {
|
|
11202
|
+
return EncodeTypes(right, `${pattern}${IntegerPattern}`);
|
|
11201
11203
|
}
|
|
11202
|
-
function EncodeNumber(right,
|
|
11203
|
-
return EncodeTypes(right, `${
|
|
11204
|
+
function EncodeNumber(right, pattern) {
|
|
11205
|
+
return EncodeTypes(right, `${pattern}${NumberPattern}`);
|
|
11204
11206
|
}
|
|
11205
|
-
function EncodeBoolean(right,
|
|
11206
|
-
return EncodeType(Union([Literal("false"), Literal("true")]), right,
|
|
11207
|
+
function EncodeBoolean(right, pattern) {
|
|
11208
|
+
return EncodeType(Union([Literal("false"), Literal("true")]), right, pattern);
|
|
11207
11209
|
}
|
|
11208
|
-
function EncodeString(right,
|
|
11209
|
-
return EncodeTypes(right, `${
|
|
11210
|
+
function EncodeString(right, pattern) {
|
|
11211
|
+
return EncodeTypes(right, `${pattern}${StringPattern}`);
|
|
11210
11212
|
}
|
|
11211
|
-
function EncodeTemplateLiteral(templatePattern, right,
|
|
11212
|
-
return EncodeTypes(right, `${
|
|
11213
|
+
function EncodeTemplateLiteral(templatePattern, right, pattern) {
|
|
11214
|
+
return EncodeTypes(right, `${pattern}${UnwrapTemplateLiteralPattern(templatePattern)}`);
|
|
11213
11215
|
}
|
|
11214
|
-
function EncodeTemplateLiteralDeferred(types, right,
|
|
11216
|
+
function EncodeTemplateLiteralDeferred(types, right, pattern) {
|
|
11215
11217
|
const templateLiteral = TemplateLiteralAction(types, {});
|
|
11216
|
-
const result = EncodeType(templateLiteral, right,
|
|
11218
|
+
const result = EncodeType(templateLiteral, right, pattern);
|
|
11217
11219
|
return result;
|
|
11218
11220
|
}
|
|
11219
|
-
function EncodeEnum(types, right,
|
|
11221
|
+
function EncodeEnum(types, right, pattern) {
|
|
11220
11222
|
const variants = EnumValuesToVariants(types);
|
|
11221
|
-
return EncodeUnion(variants, right,
|
|
11223
|
+
return EncodeUnion(variants, right, pattern);
|
|
11222
11224
|
}
|
|
11223
|
-
function EncodeUnion(types, right,
|
|
11224
|
-
return guard_exports.TakeLeft(types, (head, tail) => EncodeUnion(tail, right,
|
|
11225
|
+
function EncodeUnion(types, right, pattern, result = []) {
|
|
11226
|
+
return guard_exports.TakeLeft(types, (head, tail) => EncodeUnion(tail, right, pattern, [...result, EncodeType(head, [], "")]), () => EncodeTypes(right, `${pattern}(${JoinString(result)})`));
|
|
11225
11227
|
}
|
|
11226
|
-
function EncodeType(type, right,
|
|
11227
|
-
return IsEnum(type) ? EncodeEnum(type.enum, right,
|
|
11228
|
+
function EncodeType(type, right, pattern) {
|
|
11229
|
+
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
11230
|
}
|
|
11229
|
-
function EncodeTypes(types,
|
|
11230
|
-
return guard_exports.TakeLeft(types, (left, right) => EncodeType(left, right,
|
|
11231
|
+
function EncodeTypes(types, pattern) {
|
|
11232
|
+
return guard_exports.TakeLeft(types, (left, right) => EncodeType(left, right, pattern), () => pattern);
|
|
11231
11233
|
}
|
|
11232
11234
|
function EncodePattern(types) {
|
|
11233
11235
|
const encoded = EncodeTypes(types, "");
|
|
@@ -11235,8 +11237,8 @@ function EncodePattern(types) {
|
|
|
11235
11237
|
return result;
|
|
11236
11238
|
}
|
|
11237
11239
|
function TemplateLiteralEncode(types) {
|
|
11238
|
-
const
|
|
11239
|
-
const result = TemplateLiteralCreate(
|
|
11240
|
+
const pattern = EncodePattern(types);
|
|
11241
|
+
const result = TemplateLiteralCreate(pattern);
|
|
11240
11242
|
return result;
|
|
11241
11243
|
}
|
|
11242
11244
|
|
|
@@ -11943,8 +11945,8 @@ function FromLiteral3(mapping, value) {
|
|
|
11943
11945
|
}
|
|
11944
11946
|
|
|
11945
11947
|
// ../../node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs
|
|
11946
|
-
function FromTemplateLiteral(mapping,
|
|
11947
|
-
const decoded = TemplateLiteralDecode(
|
|
11948
|
+
function FromTemplateLiteral(mapping, pattern) {
|
|
11949
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
11948
11950
|
const result = FromType7(mapping, decoded);
|
|
11949
11951
|
return result;
|
|
11950
11952
|
}
|
|
@@ -12296,8 +12298,8 @@ function FromLiteral4(value) {
|
|
|
12296
12298
|
}
|
|
12297
12299
|
|
|
12298
12300
|
// ../../node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs
|
|
12299
|
-
function FromTemplateLiteral2(
|
|
12300
|
-
const decoded = TemplateLiteralDecode(
|
|
12301
|
+
function FromTemplateLiteral2(pattern) {
|
|
12302
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
12301
12303
|
const result = FromType9(decoded);
|
|
12302
12304
|
return result;
|
|
12303
12305
|
}
|
|
@@ -12503,8 +12505,8 @@ function Mapped2(identifier, type, as, property, options = {}) {
|
|
|
12503
12505
|
}
|
|
12504
12506
|
|
|
12505
12507
|
// ../../node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs
|
|
12506
|
-
function FromTemplateLiteral3(
|
|
12507
|
-
const decoded = TemplateLiteralDecode(
|
|
12508
|
+
function FromTemplateLiteral3(pattern) {
|
|
12509
|
+
const decoded = TemplateLiteralDecode(pattern);
|
|
12508
12510
|
const result = FromType13(decoded);
|
|
12509
12511
|
return result;
|
|
12510
12512
|
}
|
|
@@ -13236,8 +13238,8 @@ function fauxAssistantMessage(content, options = {}) {
|
|
|
13236
13238
|
function estimateTokens(text2) {
|
|
13237
13239
|
return Math.ceil(text2.length / 4);
|
|
13238
13240
|
}
|
|
13239
|
-
function randomId(
|
|
13240
|
-
return `${
|
|
13241
|
+
function randomId(prefix) {
|
|
13242
|
+
return `${prefix}:${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
13241
13243
|
}
|
|
13242
13244
|
function contentToText(content) {
|
|
13243
13245
|
if (typeof content === "string") {
|
|
@@ -15482,9 +15484,9 @@ function ErrorPattern(stack, context, schemaPath, instancePath, schema, value) {
|
|
|
15482
15484
|
|
|
15483
15485
|
// ../../node_modules/typebox/build/schema/engine/patternProperties.mjs
|
|
15484
15486
|
function BuildPatternProperties(stack, context, schema, value) {
|
|
15485
|
-
return emit_exports.ReduceAnd(guard_exports.Entries(schema.patternProperties).map(([
|
|
15487
|
+
return emit_exports.ReduceAnd(guard_exports.Entries(schema.patternProperties).map(([pattern, schema2]) => {
|
|
15486
15488
|
const [key, prop] = [Unique(), Unique()];
|
|
15487
|
-
const regexp = CreateVariable(new RegExp(
|
|
15489
|
+
const regexp = CreateVariable(new RegExp(pattern, "u"));
|
|
15488
15490
|
const notKey = emit_exports.Not(emit_exports.Call(emit_exports.Member(regexp, "test"), [key]));
|
|
15489
15491
|
const isSchema = BuildSchemaPushStack(stack, context, schema2, prop);
|
|
15490
15492
|
const addKey = context.AddKey(key);
|
|
@@ -15493,17 +15495,17 @@ function BuildPatternProperties(stack, context, schema, value) {
|
|
|
15493
15495
|
}));
|
|
15494
15496
|
}
|
|
15495
15497
|
function CheckPatternProperties(stack, context, schema, value) {
|
|
15496
|
-
return guard_exports.Every(guard_exports.Entries(schema.patternProperties), 0, ([
|
|
15497
|
-
const regexp = new RegExp(
|
|
15498
|
+
return guard_exports.Every(guard_exports.Entries(schema.patternProperties), 0, ([pattern, schema2]) => {
|
|
15499
|
+
const regexp = new RegExp(pattern, "u");
|
|
15498
15500
|
return guard_exports.Every(guard_exports.Entries(value), 0, ([key, prop]) => {
|
|
15499
15501
|
return !regexp.test(key) || CheckSchemaPushStack(stack, context, schema2, prop) && context.AddKey(key);
|
|
15500
15502
|
});
|
|
15501
15503
|
});
|
|
15502
15504
|
}
|
|
15503
15505
|
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(
|
|
15506
|
+
return guard_exports.EveryAll(guard_exports.Entries(schema.patternProperties), 0, ([pattern, schema2]) => {
|
|
15507
|
+
const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
|
|
15508
|
+
const regexp = new RegExp(pattern, "u");
|
|
15507
15509
|
return guard_exports.EveryAll(guard_exports.Entries(value), 0, ([key, value2]) => {
|
|
15508
15510
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
15509
15511
|
const notKey = !regexp.test(key);
|
|
@@ -41230,7 +41232,7 @@ var CardRenderMcpServer = class {
|
|
|
41230
41232
|
description: createPresentationDescription(config),
|
|
41231
41233
|
inputSchema: config.presentationInputSchema,
|
|
41232
41234
|
// execute 委托 callTool,返回 IAgentPresentationToolResult(execute 返回 unknown 兼容)。
|
|
41233
|
-
execute: (args, signal) => this.callTool(name, args, signal)
|
|
41235
|
+
execute: (args, signal, context) => this.callTool(name, args, signal, { context })
|
|
41234
41236
|
});
|
|
41235
41237
|
continue;
|
|
41236
41238
|
}
|
|
@@ -41287,7 +41289,7 @@ var CardRenderMcpServer = class {
|
|
|
41287
41289
|
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
41290
|
inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
|
|
41289
41291
|
outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
|
|
41290
|
-
execute: async (args, signal) => {
|
|
41292
|
+
execute: async (args, signal, context) => {
|
|
41291
41293
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
41292
41294
|
throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
41293
41295
|
const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
|
|
@@ -41297,7 +41299,7 @@ var CardRenderMcpServer = class {
|
|
|
41297
41299
|
if (!handle)
|
|
41298
41300
|
throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
|
|
41299
41301
|
const mcpStartedAt = Date.now();
|
|
41300
|
-
const result = await handle.execute(args, signal);
|
|
41302
|
+
const result = await handle.execute(args, signal, context);
|
|
41301
41303
|
signal?.throwIfAborted();
|
|
41302
41304
|
if (this.closed)
|
|
41303
41305
|
throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
|
|
@@ -41405,22 +41407,22 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41405
41407
|
this.toolByName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
41406
41408
|
return tools;
|
|
41407
41409
|
}
|
|
41408
|
-
async callTool(name, args, signal) {
|
|
41410
|
+
async callTool(name, args, signal, options) {
|
|
41409
41411
|
const resource = this.resources.find((r) => createCardPresentationToolName(r.resourceId) === name);
|
|
41410
41412
|
if (!resource) {
|
|
41411
41413
|
const descriptor = this.toolByName.get(name);
|
|
41412
41414
|
if (!descriptor)
|
|
41413
41415
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
41414
|
-
return descriptor.execute(args, signal);
|
|
41416
|
+
return descriptor.execute(args, signal, options?.context);
|
|
41415
41417
|
}
|
|
41416
41418
|
const config = parseCardConfig(resource);
|
|
41417
41419
|
if (config.schemaVersion === "3" || config.schemaVersion === "4") {
|
|
41418
41420
|
const descriptor = this.toolByName.get(name);
|
|
41419
41421
|
if (!descriptor)
|
|
41420
41422
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
41421
|
-
return descriptor.execute(args, signal);
|
|
41423
|
+
return descriptor.execute(args, signal, options?.context);
|
|
41422
41424
|
}
|
|
41423
|
-
return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal);
|
|
41425
|
+
return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
|
|
41424
41426
|
}
|
|
41425
41427
|
async close() {
|
|
41426
41428
|
this.closed = true;
|
|
@@ -42038,7 +42040,8 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42038
42040
|
debugLog?.("[mcp] no mcp servers configured (no MCP tools will be available)", EDebugLogScope.MCP);
|
|
42039
42041
|
}
|
|
42040
42042
|
const mcpProxy = new McpProxyTool(this.mcpServerProvider, mcpServerSpecs, {
|
|
42041
|
-
debugLog
|
|
42043
|
+
debugLog,
|
|
42044
|
+
...options.mcpCallAuthorizer ? { authorizeCall: options.mcpCallAuthorizer } : {}
|
|
42042
42045
|
});
|
|
42043
42046
|
cleanup.push(() => mcpProxy.closeAll());
|
|
42044
42047
|
const cardServer = new CardRenderMcpServer(this.cardResources, mcpProxy, { ...options.runtimeContext, threadId: request.threadId }, debugLog);
|
|
@@ -42895,9 +42898,9 @@ var AppbaseSkillLoader = class {
|
|
|
42895
42898
|
const raw = raws[i];
|
|
42896
42899
|
if (typeof raw !== "string" || raw.length === 0)
|
|
42897
42900
|
continue;
|
|
42898
|
-
const
|
|
42899
|
-
if (
|
|
42900
|
-
records.push(
|
|
42901
|
+
const record2 = parseSkillFile(raw, resources[i]?.resourceId ?? "skill");
|
|
42902
|
+
if (record2)
|
|
42903
|
+
records.push(record2);
|
|
42901
42904
|
}
|
|
42902
42905
|
return records;
|
|
42903
42906
|
}
|
|
@@ -42968,8 +42971,8 @@ function resolveLinkqueEndpoints(env, envSelector) {
|
|
|
42968
42971
|
function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
|
|
42969
42972
|
const log = (...a) => logCtx?.log?.("[runtime-factory]", ...a);
|
|
42970
42973
|
const debugLog = logCtx?.log ? (line, scope) => {
|
|
42971
|
-
const
|
|
42972
|
-
logCtx.log?.(
|
|
42974
|
+
const prefix = scope ? `[${scope}] ` : "";
|
|
42975
|
+
logCtx.log?.(prefix + line);
|
|
42973
42976
|
} : void 0;
|
|
42974
42977
|
const runtimePorts = {};
|
|
42975
42978
|
if (ports.linkqueBaseUrl) {
|
|
@@ -43301,9 +43304,9 @@ function createSearchSnippet(content, keyword) {
|
|
|
43301
43304
|
const firstMatch = lowerContent.indexOf(lowerKeyword);
|
|
43302
43305
|
const contentStart = firstMatch < 0 ? 0 : Math.max(0, Math.min(firstMatch - 40, normalizedContent.length - SEARCH_SNIPPET_LENGTH));
|
|
43303
43306
|
const rawSnippet = normalizedContent.slice(contentStart, contentStart + SEARCH_SNIPPET_LENGTH);
|
|
43304
|
-
const
|
|
43307
|
+
const prefix = contentStart > 0 ? "\u2026" : "";
|
|
43305
43308
|
const suffix = contentStart + rawSnippet.length < normalizedContent.length ? "\u2026" : "";
|
|
43306
|
-
const snippet = `${
|
|
43309
|
+
const snippet = `${prefix}${rawSnippet}${suffix}`;
|
|
43307
43310
|
const highlightRanges = [];
|
|
43308
43311
|
if (lowerKeyword) {
|
|
43309
43312
|
const lowerSnippet = rawSnippet.toLowerCase();
|
|
@@ -43313,7 +43316,7 @@ function createSearchSnippet(content, keyword) {
|
|
|
43313
43316
|
if (start < 0)
|
|
43314
43317
|
break;
|
|
43315
43318
|
highlightRanges.push({
|
|
43316
|
-
start:
|
|
43319
|
+
start: prefix.length + start,
|
|
43317
43320
|
length: keyword.length
|
|
43318
43321
|
});
|
|
43319
43322
|
from = start + Math.max(1, lowerKeyword.length);
|
|
@@ -44606,7 +44609,7 @@ function readStatusError(status, code, message) {
|
|
|
44606
44609
|
|
|
44607
44610
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/homeData.js
|
|
44608
44611
|
var HOME_DATA_REQUEST_OPERATION = "homeData.request";
|
|
44609
|
-
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId) {
|
|
44612
|
+
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
|
|
44610
44613
|
if (method.toUpperCase() !== "POST") {
|
|
44611
44614
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
44612
44615
|
}
|
|
@@ -44646,7 +44649,8 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
|
|
|
44646
44649
|
request: body,
|
|
44647
44650
|
protocol,
|
|
44648
44651
|
userId,
|
|
44649
|
-
mcpServerProvider: provider
|
|
44652
|
+
mcpServerProvider: provider,
|
|
44653
|
+
phoneAuthorization
|
|
44650
44654
|
});
|
|
44651
44655
|
debugLog?.("response", response.ok ? { ok: true } : { ok: false, errorCode: response.error.code });
|
|
44652
44656
|
return { status: 200, body: response };
|
|
@@ -44742,7 +44746,7 @@ function sanitizeDiagnosticText(value) {
|
|
|
44742
44746
|
|
|
44743
44747
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiAction.js
|
|
44744
44748
|
var A2UI_ACTION_EXECUTE_OPERATION = "a2uiAction.execute";
|
|
44745
|
-
async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
44749
|
+
async function runA2UIAction(method, body, userId, deps = {}, env = process.env, _appwriteApiKey, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
|
|
44746
44750
|
let mcpTraceId;
|
|
44747
44751
|
const debugLog = createA2UIInfoLog(env, logCtx, traceId, () => mcpTraceId);
|
|
44748
44752
|
const diagnostics = new CardActionDiagnostics(debugLog, {}, "handler");
|
|
@@ -44772,10 +44776,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44772
44776
|
if (request.agentId !== protocol.agentId) {
|
|
44773
44777
|
return paymentFailure(403, "AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
44774
44778
|
}
|
|
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
44779
|
const provider = deps.mcpServerProvider ?? resolveProvider(protocol, env, envSelector, gatewayAuth, diagnostics.debugLog, (info) => {
|
|
44780
44780
|
mcpTraceId = info.traceId;
|
|
44781
44781
|
diagnostics.write("mcp_trace");
|
|
@@ -44783,34 +44783,9 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44783
44783
|
if (!provider) {
|
|
44784
44784
|
return paymentFailure(503, "MCP_NOT_BOUND", "\u652F\u4ED8 MCP \u8FDE\u63A5\u672A\u914D\u7F6E", true);
|
|
44785
44785
|
}
|
|
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
44786
|
diagnostics.stage = "execute";
|
|
44812
44787
|
const response = await executeCardAction({
|
|
44813
|
-
request
|
|
44788
|
+
request,
|
|
44814
44789
|
protocol,
|
|
44815
44790
|
runtimeContext: {
|
|
44816
44791
|
agentId: protocol.agentId,
|
|
@@ -44818,23 +44793,11 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44818
44793
|
userId
|
|
44819
44794
|
},
|
|
44820
44795
|
mcpServerProvider: provider,
|
|
44821
|
-
debugLog
|
|
44796
|
+
debugLog,
|
|
44797
|
+
phoneAuthorization
|
|
44822
44798
|
});
|
|
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" });
|
|
44799
|
+
if (response.ok)
|
|
44830
44800
|
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
44801
|
return {
|
|
44839
44802
|
status: response.error.code === "EXECUTION_FAILED" ? 502 : 400,
|
|
44840
44803
|
body: response
|
|
@@ -44853,11 +44816,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
|
|
|
44853
44816
|
throw error;
|
|
44854
44817
|
}
|
|
44855
44818
|
}
|
|
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
44819
|
function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTraceId) {
|
|
44862
44820
|
let auth;
|
|
44863
44821
|
try {
|
|
@@ -44877,9 +44835,6 @@ function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTr
|
|
|
44877
44835
|
...debugLog ? { onTraceId } : {}
|
|
44878
44836
|
});
|
|
44879
44837
|
}
|
|
44880
|
-
function success(invocationId, tradeNO) {
|
|
44881
|
-
return { ok: true, invocationId, result: { kind: "payment", tradeNO } };
|
|
44882
|
-
}
|
|
44883
44838
|
function paymentFailure(status, code, message, retryable) {
|
|
44884
44839
|
return { status, body: { ok: false, error: { code, message, retryable } } };
|
|
44885
44840
|
}
|
|
@@ -44887,276 +44842,6 @@ function errorMessage(error, fallback) {
|
|
|
44887
44842
|
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
44888
44843
|
}
|
|
44889
44844
|
|
|
44890
|
-
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/phoneReference.js
|
|
44891
|
-
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
44892
|
-
var prefix = "{{authorized_user.phone:";
|
|
44893
|
-
var pattern = /^\{\{authorized_user\.phone:([a-f0-9-]{36})\}\}$/;
|
|
44894
|
-
function createRunPhoneReferenceStore() {
|
|
44895
|
-
const records = /* @__PURE__ */ new Map();
|
|
44896
|
-
return {
|
|
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
|
-
});
|
|
45045
|
-
}
|
|
45046
|
-
};
|
|
45047
|
-
}
|
|
45048
|
-
|
|
45049
|
-
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/userInfoMcpExchange.js
|
|
45050
|
-
var UserInfoMcpError = class extends Error {
|
|
45051
|
-
code;
|
|
45052
|
-
constructor(code) {
|
|
45053
|
-
super(code);
|
|
45054
|
-
this.code = code;
|
|
45055
|
-
}
|
|
45056
|
-
};
|
|
45057
|
-
var safeCodes = /* @__PURE__ */ new Set([
|
|
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");
|
|
45074
|
-
return {
|
|
45075
|
-
scopes: ["auth_user"],
|
|
45076
|
-
async exchange(input, signal) {
|
|
45077
|
-
if (signal.aborted)
|
|
45078
|
-
throw new UserInfoMcpError("ABORTED");
|
|
45079
|
-
const connection = provider.servers([
|
|
45080
|
-
{
|
|
45081
|
-
resourceId: binding.mcpResourceId,
|
|
45082
|
-
resourceType: EResourceType.MCP,
|
|
45083
|
-
providerType: EResourceProviderType.ALIPAY_OPEN,
|
|
45084
|
-
config: {
|
|
45085
|
-
agentId: protocol.agentId,
|
|
45086
|
-
description: "\u5546\u5BB6\u7528\u6237\u8BA4\u8BC1",
|
|
45087
|
-
serverName: binding.serverName,
|
|
45088
|
-
argsMappingRules: [],
|
|
45089
|
-
allowedTools: [binding.toolName]
|
|
45090
|
-
}
|
|
45091
|
-
}
|
|
45092
|
-
]);
|
|
45093
|
-
let abandoned = false;
|
|
45094
|
-
let rejectAbort;
|
|
45095
|
-
const aborted = new Promise((_, reject) => {
|
|
45096
|
-
rejectAbort = reject;
|
|
45097
|
-
});
|
|
45098
|
-
const abort = () => {
|
|
45099
|
-
abandoned = true;
|
|
45100
|
-
rejectAbort(new UserInfoMcpError("ABORTED"));
|
|
45101
|
-
};
|
|
45102
|
-
void connection.then(async (connected) => {
|
|
45103
|
-
if (abandoned)
|
|
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 = [];
|
|
45111
|
-
try {
|
|
45112
|
-
servers = await Promise.race([connection, aborted]);
|
|
45113
|
-
if (abandoned)
|
|
45114
|
-
throw new UserInfoMcpError("ABORTED");
|
|
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?.()));
|
|
45155
|
-
}
|
|
45156
|
-
}
|
|
45157
|
-
};
|
|
45158
|
-
}
|
|
45159
|
-
|
|
45160
44845
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/securityAnswerPlugin.js
|
|
45161
44846
|
var SECURITY_ANSWER_HEADER = "x-linkque-guardrails-action";
|
|
45162
44847
|
var SECURITY_ANSWER_ACTION = "SECURITY_ANSWER";
|
|
@@ -45286,7 +44971,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45286
44971
|
let sessionLease = deps?.sessionLease;
|
|
45287
44972
|
let historyStore = deps?.historyStore;
|
|
45288
44973
|
let clientCapabilityStore = deps?.clientCapabilityStore;
|
|
45289
|
-
let paymentActionStore = deps?.paymentActionStore;
|
|
45290
44974
|
let chunkSize = Number(APPBASE_RUNTIME_CONFIG_DEFAULTS.RUN_CHUNK_SIZE);
|
|
45291
44975
|
if (!store) {
|
|
45292
44976
|
let storage;
|
|
@@ -45306,7 +44990,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45306
44990
|
store = createAppBaseStore(handle.databases, storage.databaseId, storage.tableId, historyOwnerId);
|
|
45307
44991
|
const config = new AppbaseRuntimeConfigProvider(env);
|
|
45308
44992
|
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
44993
|
try {
|
|
45311
44994
|
historyStore ??= createConversationHistoryStore(handle.databases, resolveConversationHistoryStorage(env), historyOwnerId);
|
|
45312
44995
|
} catch (err2) {
|
|
@@ -45334,9 +45017,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45334
45017
|
resolveConfig: mcpConfigResolver,
|
|
45335
45018
|
getAuthorizationHeader: mcpAuthorizationHeaderProvider
|
|
45336
45019
|
});
|
|
45337
|
-
const
|
|
45338
|
-
const phoneReferenceStore = deps?.phoneReferenceStore ?? (userInfoExchange ? createRunPhoneReferenceStore() : void 0);
|
|
45339
|
-
const mcpServerProvider = phoneReferenceStore ? withPhoneReferences(rawMcpServerProvider, phoneReferenceStore) : rawMcpServerProvider;
|
|
45020
|
+
const mcpServerProvider = rawMcpServerProvider;
|
|
45340
45021
|
const securityAnswerPlugin = deps?.securityAnswerPlugin ?? createSecurityAnswerPlugin(historyStore, logCtx?.log);
|
|
45341
45022
|
const runtime = deps?.runtime ?? createAppBaseRuntime(protocol, env, {
|
|
45342
45023
|
...appwriteApiKey ? { appBaseApiKey: appwriteApiKey } : {},
|
|
@@ -45365,9 +45046,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
45365
45046
|
sessionLease,
|
|
45366
45047
|
historyStore,
|
|
45367
45048
|
clientCapabilityStore,
|
|
45368
|
-
userInfoExchange,
|
|
45369
|
-
phoneReferenceStore,
|
|
45370
|
-
paymentActionStore,
|
|
45371
45049
|
securityAnswerPlugin,
|
|
45372
45050
|
mcpServerProvider,
|
|
45373
45051
|
chunkSize
|
|
@@ -45436,11 +45114,10 @@ async function* debugLogAgentStream(stream, debugLog) {
|
|
|
45436
45114
|
}
|
|
45437
45115
|
|
|
45438
45116
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/clientCapabilityTool.js
|
|
45439
|
-
import { randomUUID as
|
|
45117
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
45440
45118
|
var POLL_INTERVAL_MS = 500;
|
|
45441
|
-
var ROW_TTL_MS = 3 * 6e4;
|
|
45442
45119
|
var LOCATION_WAIT_MS = 2e4;
|
|
45443
|
-
var
|
|
45120
|
+
var ROW_TTL_MS = 3 * 6e4;
|
|
45444
45121
|
var LOCATION_INPUT = Object.freeze({
|
|
45445
45122
|
type: 0,
|
|
45446
45123
|
cacheTimeout: 30,
|
|
@@ -45448,30 +45125,142 @@ var LOCATION_INPUT = Object.freeze({
|
|
|
45448
45125
|
});
|
|
45449
45126
|
function createClientCapabilityTool(input) {
|
|
45450
45127
|
const resource = input.protocol.agent.resources.find((candidate) => candidate.resourceType === EResourceType.CLIENT_CAPABILITY);
|
|
45451
|
-
if (!resource || !input.ownerId || !input.store)
|
|
45128
|
+
if (!resource?.config.allowedCapabilities.includes("location") || !input.request.clientCapabilities?.includes("location") || !input.ownerId || !input.store)
|
|
45129
|
+
return void 0;
|
|
45130
|
+
let pending = false;
|
|
45131
|
+
return {
|
|
45132
|
+
name: "client_capability",
|
|
45133
|
+
modelName: "client_capability",
|
|
45134
|
+
resourceId: resource.resourceId,
|
|
45135
|
+
label: "\u83B7\u53D6\u7528\u6237\u8BBE\u5907\u4FE1\u606F",
|
|
45136
|
+
description: "\u9700\u8981\u7528\u6237\u5F53\u524D\u4F4D\u7F6E\u65F6\u8C03\u7528\u3002",
|
|
45137
|
+
inputSchema: {
|
|
45138
|
+
type: "object",
|
|
45139
|
+
additionalProperties: false,
|
|
45140
|
+
required: ["capability", "reason"],
|
|
45141
|
+
properties: {
|
|
45142
|
+
capability: { const: "location" },
|
|
45143
|
+
reason: { type: "string", minLength: 1, maxLength: 200 }
|
|
45144
|
+
}
|
|
45145
|
+
},
|
|
45146
|
+
async execute(args, signal, context) {
|
|
45147
|
+
if (!context)
|
|
45148
|
+
return failure("CLIENT_CAPABILITY_CONTEXT_MISSING", "\u7AEF\u4FA7\u8C03\u7528\u4E0A\u4E0B\u6587\u4E0D\u53EF\u7528");
|
|
45149
|
+
const reason = readReason(args);
|
|
45150
|
+
if (!reason)
|
|
45151
|
+
return failure("CLIENT_CAPABILITY_INVALID_ARGS", "\u7AEF\u4FA7\u80FD\u529B\u53C2\u6570\u4E0D\u5408\u6CD5");
|
|
45152
|
+
if (pending)
|
|
45153
|
+
return failure("CLIENT_CAPABILITY_BUSY", "\u5DF2\u6709\u5B9A\u4F4D\u8C03\u7528\u6B63\u5728\u7B49\u5F85");
|
|
45154
|
+
pending = true;
|
|
45155
|
+
const invocationId = randomUUID5();
|
|
45156
|
+
const now = Date.now();
|
|
45157
|
+
const acceptUntil = new Date(now + LOCATION_WAIT_MS).toISOString();
|
|
45158
|
+
const event = {
|
|
45159
|
+
version: "1.0",
|
|
45160
|
+
invocationId,
|
|
45161
|
+
runId: input.request.runId,
|
|
45162
|
+
toolCallId: context.toolCallId,
|
|
45163
|
+
capability: "location",
|
|
45164
|
+
reason,
|
|
45165
|
+
input: LOCATION_INPUT,
|
|
45166
|
+
expiresAt: acceptUntil
|
|
45167
|
+
};
|
|
45168
|
+
let created = false;
|
|
45169
|
+
try {
|
|
45170
|
+
await input.store.create({
|
|
45171
|
+
invocationId,
|
|
45172
|
+
ownerId: input.ownerId,
|
|
45173
|
+
agentId: input.protocol.agentId,
|
|
45174
|
+
threadId: input.request.threadId,
|
|
45175
|
+
runId: input.request.runId,
|
|
45176
|
+
toolCallId: context.toolCallId,
|
|
45177
|
+
capability: "location",
|
|
45178
|
+
status: "pending",
|
|
45179
|
+
input: JSON.stringify(LOCATION_INPUT),
|
|
45180
|
+
createdAt: new Date(now).toISOString(),
|
|
45181
|
+
acceptUntil,
|
|
45182
|
+
expiresAt: new Date(now + ROW_TTL_MS).toISOString()
|
|
45183
|
+
});
|
|
45184
|
+
created = true;
|
|
45185
|
+
context.emit({ type: "client_capability_request", value: event });
|
|
45186
|
+
while (Date.now() < Date.parse(acceptUntil)) {
|
|
45187
|
+
if (signal?.aborted)
|
|
45188
|
+
throw abortError();
|
|
45189
|
+
const row = await input.store.get(invocationId);
|
|
45190
|
+
if (row?.status === "succeeded" || row?.status === "failed") {
|
|
45191
|
+
const result = parseStoredClientCapabilityResult(row.result);
|
|
45192
|
+
await input.store.consume(invocationId);
|
|
45193
|
+
return result ?? failure("CLIENT_CAPABILITY_INVALID_RESULT", "\u7AEF\u4FA7\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
|
|
45194
|
+
}
|
|
45195
|
+
await wait(POLL_INTERVAL_MS, signal);
|
|
45196
|
+
}
|
|
45197
|
+
await input.store.expire(invocationId);
|
|
45198
|
+
return failure("CLIENT_CAPABILITY_TIMEOUT", "\u7B49\u5F85\u7AEF\u4FA7\u80FD\u529B\u7ED3\u679C\u8D85\u65F6", true);
|
|
45199
|
+
} finally {
|
|
45200
|
+
if (created && signal?.aborted)
|
|
45201
|
+
await input.store.expire(invocationId);
|
|
45202
|
+
pending = false;
|
|
45203
|
+
}
|
|
45204
|
+
}
|
|
45205
|
+
};
|
|
45206
|
+
}
|
|
45207
|
+
function readReason(value) {
|
|
45208
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
45452
45209
|
return void 0;
|
|
45453
|
-
const
|
|
45454
|
-
if (
|
|
45210
|
+
const args = value;
|
|
45211
|
+
if (args.capability !== "location" || typeof args.reason !== "string")
|
|
45455
45212
|
return void 0;
|
|
45456
|
-
|
|
45457
|
-
|
|
45458
|
-
|
|
45459
|
-
|
|
45213
|
+
const reason = args.reason.trim();
|
|
45214
|
+
return reason && reason.length <= 200 ? reason : void 0;
|
|
45215
|
+
}
|
|
45216
|
+
function failure(code, message, retriable = false) {
|
|
45217
|
+
return { ok: false, error: { code, message, retriable } };
|
|
45218
|
+
}
|
|
45219
|
+
function abortError() {
|
|
45220
|
+
return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
|
|
45221
|
+
}
|
|
45222
|
+
function wait(ms, signal) {
|
|
45223
|
+
return new Promise((resolve, reject) => {
|
|
45224
|
+
const timer = setTimeout(resolve, ms);
|
|
45225
|
+
signal?.addEventListener("abort", () => {
|
|
45226
|
+
clearTimeout(timer);
|
|
45227
|
+
reject(abortError());
|
|
45228
|
+
}, { once: true });
|
|
45229
|
+
});
|
|
45230
|
+
}
|
|
45231
|
+
|
|
45232
|
+
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/mcpPhoneAuthorization.js
|
|
45233
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
45234
|
+
var POLL_INTERVAL_MS2 = 500;
|
|
45235
|
+
var AUTH_WAIT_MS = 95e3;
|
|
45236
|
+
var ROW_TTL_MS2 = 3 * 6e4;
|
|
45237
|
+
var AUTH_CODE_HEADER = "x-alipay-authcode";
|
|
45238
|
+
function createMcpPhoneAuthorizer(input) {
|
|
45239
|
+
const hasDependencies = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL).some((resource) => resource.config.dependencies?.some((dependency) => dependency.name === "phoneAuthorization"));
|
|
45240
|
+
if (!hasDependencies)
|
|
45241
|
+
return void 0;
|
|
45242
|
+
return async ({ resourceIds, toolName, signal, context }) => {
|
|
45243
|
+
const policy = resolvePhoneAuthorizationDependency(input.protocol, resourceIds, toolName);
|
|
45244
|
+
if (!policy)
|
|
45245
|
+
return void 0;
|
|
45460
45246
|
if (signal?.aborted)
|
|
45461
|
-
throw
|
|
45247
|
+
throw abortError2();
|
|
45248
|
+
if (!input.ownerId || !input.store || !context || !input.request.clientCapabilities?.includes("userInfo")) {
|
|
45249
|
+
if (policy.required)
|
|
45250
|
+
throw authError("AUTH_UNAVAILABLE", "\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743");
|
|
45251
|
+
return void 0;
|
|
45252
|
+
}
|
|
45462
45253
|
const invocationId = randomUUID6();
|
|
45463
45254
|
const now = Date.now();
|
|
45464
|
-
const
|
|
45465
|
-
const
|
|
45466
|
-
const
|
|
45467
|
-
const capabilityInput = capability === "location" ? LOCATION_INPUT : { scopes: [...input.userInfoExchange.scopes] };
|
|
45468
|
-
const request = {
|
|
45255
|
+
const acceptUntil = new Date(now + AUTH_WAIT_MS).toISOString();
|
|
45256
|
+
const capabilityInput = { scopes: ["auth_user"] };
|
|
45257
|
+
const event = {
|
|
45469
45258
|
version: "1.0",
|
|
45470
45259
|
invocationId,
|
|
45471
45260
|
runId: input.request.runId,
|
|
45472
45261
|
toolCallId: context.toolCallId,
|
|
45473
|
-
capability,
|
|
45474
|
-
reason
|
|
45262
|
+
capability: "userInfo",
|
|
45263
|
+
reason: `\u8C03\u7528 ${toolName} \u9700\u8981\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743`,
|
|
45475
45264
|
input: capabilityInput,
|
|
45476
45265
|
expiresAt: acceptUntil
|
|
45477
45266
|
};
|
|
@@ -45484,158 +45273,68 @@ function createClientCapabilityTool(input) {
|
|
|
45484
45273
|
threadId: input.request.threadId,
|
|
45485
45274
|
runId: input.request.runId,
|
|
45486
45275
|
toolCallId: context.toolCallId,
|
|
45487
|
-
capability,
|
|
45276
|
+
capability: "userInfo",
|
|
45488
45277
|
status: "pending",
|
|
45489
45278
|
input: JSON.stringify(capabilityInput),
|
|
45490
45279
|
createdAt: new Date(now).toISOString(),
|
|
45491
45280
|
acceptUntil,
|
|
45492
|
-
expiresAt
|
|
45281
|
+
expiresAt: new Date(now + ROW_TTL_MS2).toISOString()
|
|
45493
45282
|
});
|
|
45494
45283
|
created = true;
|
|
45495
|
-
context.emit({ type: "client_capability_request", value:
|
|
45284
|
+
context.emit({ type: "client_capability_request", value: event });
|
|
45496
45285
|
while (Date.now() < Date.parse(acceptUntil)) {
|
|
45497
45286
|
if (signal?.aborted)
|
|
45498
|
-
throw
|
|
45287
|
+
throw abortError2();
|
|
45499
45288
|
const row = await input.store.get(invocationId);
|
|
45500
45289
|
if (row?.status === "succeeded" || row?.status === "failed") {
|
|
45501
45290
|
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
45291
|
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");
|
|
45292
|
+
if (result?.ok && "authCode" in result.data) {
|
|
45293
|
+
return { [AUTH_CODE_HEADER]: result.data.authCode };
|
|
45294
|
+
}
|
|
45295
|
+
if (policy.required) {
|
|
45296
|
+
throw authError(result && !result.ok ? result.error.code : "AUTH_INVALID_RESULT", result && !result.ok ? result.error.message : "\u6388\u6743\u7ED3\u679C\u65E0\u6548");
|
|
45519
45297
|
}
|
|
45298
|
+
return void 0;
|
|
45520
45299
|
}
|
|
45521
|
-
await
|
|
45300
|
+
await wait2(POLL_INTERVAL_MS2, signal);
|
|
45522
45301
|
}
|
|
45523
45302
|
await input.store.expire(invocationId);
|
|
45524
|
-
|
|
45303
|
+
if (policy.required)
|
|
45304
|
+
throw authError("AUTH_TIMEOUT", "\u7B49\u5F85\u624B\u673A\u53F7\u6388\u6743\u8D85\u65F6");
|
|
45305
|
+
return void 0;
|
|
45525
45306
|
} 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;
|
|
45307
|
+
if (created)
|
|
45308
|
+
await input.store.expire(invocationId).catch(() => void 0);
|
|
45309
|
+
if (signal?.aborted || error instanceof Error && error.name === "AbortError")
|
|
45310
|
+
throw error;
|
|
45311
|
+
if (policy.required) {
|
|
45312
|
+
if (error instanceof Error && "code" in error)
|
|
45313
|
+
throw error;
|
|
45314
|
+
throw authError("AUTH_FAILED", "\u624B\u673A\u53F7\u6388\u6743\u8BF7\u6C42\u5931\u8D25");
|
|
45574
45315
|
}
|
|
45316
|
+
return void 0;
|
|
45575
45317
|
}
|
|
45576
45318
|
};
|
|
45577
45319
|
}
|
|
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;
|
|
45586
|
-
}
|
|
45587
|
-
function normalizeUserInfo(value) {
|
|
45588
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
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;
|
|
45320
|
+
function authError(code, message) {
|
|
45321
|
+
return Object.assign(new Error(message), { code });
|
|
45601
45322
|
}
|
|
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 } };
|
|
45323
|
+
function abortError2() {
|
|
45324
|
+
return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
|
|
45618
45325
|
}
|
|
45619
|
-
function
|
|
45326
|
+
function wait2(ms, signal) {
|
|
45620
45327
|
return new Promise((resolve, reject) => {
|
|
45621
|
-
|
|
45622
|
-
return reject(abortError());
|
|
45623
|
-
const onAbort = () => {
|
|
45328
|
+
const finish = (settle) => {
|
|
45624
45329
|
clearTimeout(timer);
|
|
45625
|
-
reject(abortError());
|
|
45626
|
-
};
|
|
45627
|
-
const timer = setTimeout(() => {
|
|
45628
45330
|
signal?.removeEventListener("abort", onAbort);
|
|
45629
|
-
|
|
45630
|
-
}
|
|
45331
|
+
settle();
|
|
45332
|
+
};
|
|
45333
|
+
const onAbort = () => finish(() => reject(abortError2()));
|
|
45334
|
+
const timer = setTimeout(() => finish(resolve), ms);
|
|
45631
45335
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
45632
45336
|
});
|
|
45633
45337
|
}
|
|
45634
|
-
function abortError() {
|
|
45635
|
-
const error = new Error("client capability call aborted");
|
|
45636
|
-
error.name = "AbortError";
|
|
45637
|
-
return error;
|
|
45638
|
-
}
|
|
45639
45338
|
|
|
45640
45339
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chatExecution.js
|
|
45641
45340
|
async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId, signal, traceId) {
|
|
@@ -45681,12 +45380,18 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
|
|
|
45681
45380
|
protocol: deps.protocol,
|
|
45682
45381
|
request,
|
|
45683
45382
|
ownerId: authenticatedUserId,
|
|
45684
|
-
store: deps.clientCapabilityStore
|
|
45685
|
-
userInfoExchange: deps.userInfoExchange,
|
|
45686
|
-
phoneReferenceStore: deps.phoneReferenceStore
|
|
45383
|
+
store: deps.clientCapabilityStore
|
|
45687
45384
|
});
|
|
45688
45385
|
if (clientCapabilityTool)
|
|
45689
45386
|
runOptions.additionalTools = [clientCapabilityTool];
|
|
45387
|
+
const mcpCallAuthorizer = createMcpPhoneAuthorizer({
|
|
45388
|
+
protocol: deps.protocol,
|
|
45389
|
+
request,
|
|
45390
|
+
ownerId: authenticatedUserId,
|
|
45391
|
+
store: deps.clientCapabilityStore
|
|
45392
|
+
});
|
|
45393
|
+
if (mcpCallAuthorizer)
|
|
45394
|
+
runOptions.mcpCallAuthorizer = mcpCallAuthorizer;
|
|
45690
45395
|
if (signal)
|
|
45691
45396
|
runOptions.signal = signal;
|
|
45692
45397
|
const agentReq = {
|
|
@@ -45746,7 +45451,6 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
|
|
|
45746
45451
|
} catch (err2) {
|
|
45747
45452
|
logError("finalize \u5931\u8D25:", err2);
|
|
45748
45453
|
} finally {
|
|
45749
|
-
deps.phoneReferenceStore?.clear();
|
|
45750
45454
|
}
|
|
45751
45455
|
}
|
|
45752
45456
|
return {
|
|
@@ -45770,7 +45474,7 @@ function shouldFlushConversationEvent(event) {
|
|
|
45770
45474
|
|
|
45771
45475
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiFunctionMcp.js
|
|
45772
45476
|
var A2UI_FUNCTION_MCP_EXECUTE_OPERATION = "a2uiFunctionMcp.execute";
|
|
45773
|
-
async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth) {
|
|
45477
|
+
async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth, phoneAuthorization) {
|
|
45774
45478
|
if (method.toUpperCase() !== "POST") {
|
|
45775
45479
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
45776
45480
|
}
|
|
@@ -45802,9 +45506,12 @@ async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process
|
|
|
45802
45506
|
request,
|
|
45803
45507
|
protocol,
|
|
45804
45508
|
runtimeContext: { threadId: request.threadId, userId },
|
|
45805
|
-
mcpServerProvider: provider
|
|
45509
|
+
mcpServerProvider: provider,
|
|
45510
|
+
phoneAuthorization
|
|
45806
45511
|
});
|
|
45807
|
-
} catch {
|
|
45512
|
+
} catch (error) {
|
|
45513
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
45514
|
+
throw error;
|
|
45808
45515
|
return failure2(502, "EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5");
|
|
45809
45516
|
}
|
|
45810
45517
|
return {
|
|
@@ -46093,7 +45800,7 @@ function waitForCancellationPoll(delayMs, signal) {
|
|
|
46093
45800
|
}
|
|
46094
45801
|
});
|
|
46095
45802
|
}
|
|
46096
|
-
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) {
|
|
45803
|
+
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, mcpPhoneAuthorization) {
|
|
46097
45804
|
const operation = readOperation(bodyJSON);
|
|
46098
45805
|
const startedAt = Date.now();
|
|
46099
45806
|
const logGateway = (event, fields = {}, failed = false) => {
|
|
@@ -46125,6 +45832,9 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
|
|
|
46125
45832
|
}, result.status >= 400);
|
|
46126
45833
|
return result;
|
|
46127
45834
|
} catch (error) {
|
|
45835
|
+
const challenge = mcpPhoneAuthorizationChallenge(error);
|
|
45836
|
+
if (challenge)
|
|
45837
|
+
return challenge;
|
|
46128
45838
|
logGateway("dispatch.error", {
|
|
46129
45839
|
errorType: error instanceof Error ? error.name : typeof error,
|
|
46130
45840
|
durationMs: Date.now() - startedAt
|
|
@@ -46153,22 +45863,21 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
|
|
|
46153
45863
|
return observe(() => runHomeData(method, request, historyOwnerId, {
|
|
46154
45864
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46155
45865
|
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46156
|
-
}, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
|
|
45866
|
+
}, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
|
|
46157
45867
|
}
|
|
46158
45868
|
if (operation === A2UI_ACTION_EXECUTE_OPERATION) {
|
|
46159
45869
|
const request = readOperationPayload(bodyJSON);
|
|
46160
45870
|
return observe(() => runA2UIAction(method, request, historyOwnerId, {
|
|
46161
45871
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46162
|
-
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46163
|
-
|
|
46164
|
-
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
|
|
45872
|
+
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
45873
|
+
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
|
|
46165
45874
|
}
|
|
46166
45875
|
if (operation === A2UI_FUNCTION_MCP_EXECUTE_OPERATION) {
|
|
46167
45876
|
const request = readOperationPayload(bodyJSON);
|
|
46168
45877
|
return observe(() => runA2UIFunctionMcp(method, request, historyOwnerId, {
|
|
46169
45878
|
...deps?.protocol ? { protocol: deps.protocol } : {},
|
|
46170
45879
|
...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
|
|
46171
|
-
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth));
|
|
45880
|
+
}, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, mcpPhoneAuthorization));
|
|
46172
45881
|
}
|
|
46173
45882
|
if (operation && HISTORY_OPERATIONS.has(operation)) {
|
|
46174
45883
|
return observe(() => runHistory(method, bodyJSON, env, deps ? { protocol: deps.protocol, store: deps.historyStore } : void 0, logCtx, historyOwnerId, appwriteApiKey));
|
|
@@ -46198,7 +45907,7 @@ async function chat(ctx) {
|
|
|
46198
45907
|
log: ctx.log,
|
|
46199
45908
|
error: ctx.error
|
|
46200
45909
|
}) : 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");
|
|
45910
|
+
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
45911
|
} catch (err2) {
|
|
46203
45912
|
ctx.error?.(err2);
|
|
46204
45913
|
result = err2 instanceof LinkqueGatewayAuthError || err2 instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(err2.status, err2.code, err2.message) : {
|