linkque-cli-v2 1.6.3 → 1.6.4
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/dev/worker.js +16 -3
- package/linkquejs.js +1015 -631
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-GSYNBLMR.js +17 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{azure-openai-responses-HVAVRLTK.js → azure-openai-responses-NPKMM3LF.js} +7 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-ZRFVXCIT.js → chunk-CO4I3RJE.js} +15 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Q2Y6LMNC.js → chunk-J4JCPZDI.js} +5 -7
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-4XAZNSEQ.js → chunk-JMBJJF7P.js} +18 -5
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{anthropic-messages-5DOLTIGP.js → chunk-KDHBKVSL.js} +14 -15
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-MK4MI4S5.js → chunk-UZS5YLV2.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-4VLP3ODV.js → chunk-VBERH5QM.js} +404 -59
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y3G4J3TB.js → chunk-XOLFZ4XS.js} +316 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{dist-ZPLSQEAM.js → dist-TGBYXSBU.js} +27 -42
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-generative-ai-OLT56CSV.js → google-generative-ai-KD7MXONK.js} +8 -10
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-vertex-4DBBJ7SR.js → google-vertex-TREYA472.js} +9 -11
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-OEBGEDLQ.js → mistral-conversations-OEOTQWE5.js} +7 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-codex-responses-3KOC6KHN.js → openai-codex-responses-GEFKSNVN.js} +10 -12
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-completions-HG6OJRL5.js → openai-completions-TAACO6T5.js} +13 -15
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-responses-F6V2PG3Y.js → openai-responses-4DDTXIGI.js} +12 -14
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +181 -60
- 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 +348 -89
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +0 -317
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{pi-messages-DC4DVRAJ.js → pi-messages-7JN3W3BC.js} +4 -4
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
splitDeferredTools
|
|
3
|
-
} from "./chunk-HTG7JBF2.js";
|
|
4
|
-
import {
|
|
5
|
-
buildCopilotDynamicHeaders,
|
|
6
|
-
hasCopilotVisionInput
|
|
7
|
-
} from "./chunk-XMVFOHGJ.js";
|
|
8
1
|
import {
|
|
9
2
|
convertResponsesMessages,
|
|
10
3
|
convertResponsesTools,
|
|
11
4
|
processResponsesStream
|
|
12
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-J4JCPZDI.js";
|
|
13
6
|
import "./chunk-UFVAKOTZ.js";
|
|
14
7
|
import {
|
|
15
8
|
clampOpenAIPromptCacheKey
|
|
@@ -22,22 +15,27 @@ import {
|
|
|
22
15
|
normalizeProviderError
|
|
23
16
|
} from "./chunk-NKEOCGYU.js";
|
|
24
17
|
import {
|
|
25
|
-
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import "./chunk-CT4G24PS.js";
|
|
18
|
+
splitDeferredTools
|
|
19
|
+
} from "./chunk-HTG7JBF2.js";
|
|
28
20
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
buildCopilotDynamicHeaders,
|
|
22
|
+
hasCopilotVisionInput
|
|
23
|
+
} from "./chunk-XMVFOHGJ.js";
|
|
31
24
|
import {
|
|
32
25
|
getProviderEnvValue
|
|
33
26
|
} from "./chunk-B5XRGKYX.js";
|
|
34
27
|
import "./chunk-WJHOHUET.js";
|
|
35
28
|
import {
|
|
29
|
+
buildBaseOptions,
|
|
36
30
|
clampThinkingLevel
|
|
37
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-XOLFZ4XS.js";
|
|
38
32
|
import {
|
|
39
33
|
AssistantMessageEventStream
|
|
40
34
|
} from "./chunk-46SEH6ER.js";
|
|
35
|
+
import "./chunk-CT4G24PS.js";
|
|
36
|
+
import {
|
|
37
|
+
headersToRecord
|
|
38
|
+
} from "./chunk-Y6UTJIT4.js";
|
|
41
39
|
import "./chunk-2ESYSVXG.js";
|
|
42
40
|
|
|
43
41
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import "../../chunk-6MHDOBWO.js";
|
|
2
2
|
import "../../chunk-E2P6TIFG.js";
|
|
3
|
+
import {
|
|
4
|
+
Anthropic,
|
|
5
|
+
stream
|
|
6
|
+
} from "../../chunk-KDHBKVSL.js";
|
|
7
|
+
import "../../chunk-HTG7JBF2.js";
|
|
8
|
+
import "../../chunk-XMVFOHGJ.js";
|
|
3
9
|
import {
|
|
4
10
|
getProviderEnvValue
|
|
5
11
|
} from "../../chunk-B5XRGKYX.js";
|
|
6
12
|
import "../../chunk-WJHOHUET.js";
|
|
7
13
|
import {
|
|
14
|
+
adjustMaxTokensForThinking,
|
|
15
|
+
buildBaseOptions,
|
|
16
|
+
clampMaxTokensToContext,
|
|
8
17
|
createModels,
|
|
9
18
|
createProvider,
|
|
10
19
|
lazyApi,
|
|
11
20
|
lazyStream
|
|
12
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-XOLFZ4XS.js";
|
|
13
22
|
import {
|
|
14
23
|
createAssistantMessageEventStream
|
|
15
24
|
} from "../../chunk-46SEH6ER.js";
|
|
25
|
+
import "../../chunk-CT4G24PS.js";
|
|
26
|
+
import "../../chunk-Y6UTJIT4.js";
|
|
16
27
|
import {
|
|
17
28
|
APPBASE_RUNTIME_CONFIG_DEFAULTS,
|
|
18
29
|
AppbaseRuntimeConfigProvider,
|
|
@@ -35,17 +46,17 @@ import {
|
|
|
35
46
|
readTraceId,
|
|
36
47
|
resolveBodyJSON,
|
|
37
48
|
resolveGatewayAuthContext,
|
|
38
|
-
|
|
49
|
+
resolveLinkqueGatewayRequestAuth,
|
|
39
50
|
resolveRunStorage,
|
|
40
51
|
toAgentRunMessages,
|
|
41
52
|
withIsoTimestamp
|
|
42
|
-
} from "../../chunk-
|
|
53
|
+
} from "../../chunk-CO4I3RJE.js";
|
|
43
54
|
import "../../chunk-IWOFD643.js";
|
|
44
55
|
import "../../chunk-PXCGFBV5.js";
|
|
45
56
|
import "../../chunk-ETG6PNHQ.js";
|
|
46
57
|
import {
|
|
47
58
|
getBakedProtocol
|
|
48
|
-
} from "../../chunk-
|
|
59
|
+
} from "../../chunk-UZS5YLV2.js";
|
|
49
60
|
import {
|
|
50
61
|
ACTIVATE_SKILL_TOOL_NAME,
|
|
51
62
|
CANCEL_CONVERSATION_RUN_OPERATION,
|
|
@@ -129,6 +140,7 @@ import {
|
|
|
129
140
|
createA2UICardPipelineModelInputSchema,
|
|
130
141
|
createActivateSkillTool,
|
|
131
142
|
createCardPresentationToolName,
|
|
143
|
+
createGatewayRunAuthorization,
|
|
132
144
|
createKnowledgeTools,
|
|
133
145
|
createPresentationDescription,
|
|
134
146
|
createPresentationResult,
|
|
@@ -182,7 +194,7 @@ import {
|
|
|
182
194
|
warnLogFailure,
|
|
183
195
|
wrapToolWithHooks,
|
|
184
196
|
writeJsonPointer
|
|
185
|
-
} from "../../chunk-
|
|
197
|
+
} from "../../chunk-VBERH5QM.js";
|
|
186
198
|
import "../../chunk-EAODRPW4.js";
|
|
187
199
|
import "../../chunk-XUFLSZM4.js";
|
|
188
200
|
import "../../chunk-GAYNLDWK.js";
|
|
@@ -8407,10 +8419,10 @@ function projectProviderUsage(usage) {
|
|
|
8407
8419
|
}
|
|
8408
8420
|
|
|
8409
8421
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.lazy.js
|
|
8410
|
-
var anthropicMessagesApi = () => lazyApi(() => import("../../anthropic-messages-
|
|
8422
|
+
var anthropicMessagesApi = () => lazyApi(() => import("../../anthropic-messages-GSYNBLMR.js"));
|
|
8411
8423
|
|
|
8412
8424
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.lazy.js
|
|
8413
|
-
var azureOpenAIResponsesApi = () => lazyApi(() => import("../../azure-openai-responses-
|
|
8425
|
+
var azureOpenAIResponsesApi = () => lazyApi(() => import("../../azure-openai-responses-NPKMM3LF.js"));
|
|
8414
8426
|
|
|
8415
8427
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.js
|
|
8416
8428
|
var __rewriteRelativeImportExtension = function(path, preserveJsx) {
|
|
@@ -8429,25 +8441,25 @@ var bedrockModuleOverride;
|
|
|
8429
8441
|
var bedrockConverseStreamApi = () => lazyApi(async () => bedrockModuleOverride ?? await importNodeOnlyApi("./bedrock-converse-stream.ts"));
|
|
8430
8442
|
|
|
8431
8443
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.lazy.js
|
|
8432
|
-
var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-ai-
|
|
8444
|
+
var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-ai-KD7MXONK.js"));
|
|
8433
8445
|
|
|
8434
8446
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/google-vertex.lazy.js
|
|
8435
|
-
var googleVertexApi = () => lazyApi(() => import("../../google-vertex-
|
|
8447
|
+
var googleVertexApi = () => lazyApi(() => import("../../google-vertex-TREYA472.js"));
|
|
8436
8448
|
|
|
8437
8449
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.js
|
|
8438
|
-
var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-
|
|
8450
|
+
var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-OEOTQWE5.js"));
|
|
8439
8451
|
|
|
8440
8452
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.js
|
|
8441
|
-
var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-
|
|
8453
|
+
var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-GEFKSNVN.js"));
|
|
8442
8454
|
|
|
8443
8455
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/openai-completions.lazy.js
|
|
8444
|
-
var openAICompletionsApi = () => lazyApi(() => import("../../openai-completions-
|
|
8456
|
+
var openAICompletionsApi = () => lazyApi(() => import("../../openai-completions-TAACO6T5.js"));
|
|
8445
8457
|
|
|
8446
8458
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/openai-responses.lazy.js
|
|
8447
|
-
var openAIResponsesApi = () => lazyApi(() => import("../../openai-responses-
|
|
8459
|
+
var openAIResponsesApi = () => lazyApi(() => import("../../openai-responses-4DDTXIGI.js"));
|
|
8448
8460
|
|
|
8449
8461
|
// ../../node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js
|
|
8450
|
-
var piMessagesApi = () => lazyApi(() => import("../../pi-messages-
|
|
8462
|
+
var piMessagesApi = () => lazyApi(() => import("../../pi-messages-7JN3W3BC.js"));
|
|
8451
8463
|
|
|
8452
8464
|
// ../../node_modules/@earendil-works/pi-ai/dist/env-api-keys.js
|
|
8453
8465
|
var __rewriteRelativeImportExtension2 = function(path, preserveJsx) {
|
|
@@ -13546,38 +13558,38 @@ function scheduleChunk(chunk, tokensPerSecond) {
|
|
|
13546
13558
|
const delayMs = estimateTokens(chunk) / tokensPerSecond * 1e3;
|
|
13547
13559
|
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
13548
13560
|
}
|
|
13549
|
-
async function streamWithDeltas(
|
|
13561
|
+
async function streamWithDeltas(stream2, message, minTokenSize, maxTokenSize, tokensPerSecond, signal) {
|
|
13550
13562
|
const partial = { ...message, content: [] };
|
|
13551
13563
|
if (signal?.aborted) {
|
|
13552
13564
|
const aborted = createAbortedMessage(partial);
|
|
13553
|
-
|
|
13554
|
-
|
|
13565
|
+
stream2.push({ type: "error", reason: "aborted", error: aborted });
|
|
13566
|
+
stream2.end(aborted);
|
|
13555
13567
|
return;
|
|
13556
13568
|
}
|
|
13557
|
-
|
|
13569
|
+
stream2.push({ type: "start", partial: { ...partial } });
|
|
13558
13570
|
for (let index2 = 0; index2 < message.content.length; index2++) {
|
|
13559
13571
|
if (signal?.aborted) {
|
|
13560
13572
|
const aborted = createAbortedMessage(partial);
|
|
13561
|
-
|
|
13562
|
-
|
|
13573
|
+
stream2.push({ type: "error", reason: "aborted", error: aborted });
|
|
13574
|
+
stream2.end(aborted);
|
|
13563
13575
|
return;
|
|
13564
13576
|
}
|
|
13565
13577
|
const block = message.content[index2];
|
|
13566
13578
|
if (block.type === "thinking") {
|
|
13567
13579
|
partial.content = [...partial.content, { type: "thinking", thinking: "" }];
|
|
13568
|
-
|
|
13580
|
+
stream2.push({ type: "thinking_start", contentIndex: index2, partial: { ...partial } });
|
|
13569
13581
|
for (const chunk of splitStringByTokenSize(block.thinking, minTokenSize, maxTokenSize)) {
|
|
13570
13582
|
await scheduleChunk(chunk, tokensPerSecond);
|
|
13571
13583
|
if (signal?.aborted) {
|
|
13572
13584
|
const aborted = createAbortedMessage(partial);
|
|
13573
|
-
|
|
13574
|
-
|
|
13585
|
+
stream2.push({ type: "error", reason: "aborted", error: aborted });
|
|
13586
|
+
stream2.end(aborted);
|
|
13575
13587
|
return;
|
|
13576
13588
|
}
|
|
13577
13589
|
partial.content[index2].thinking += chunk;
|
|
13578
|
-
|
|
13590
|
+
stream2.push({ type: "thinking_delta", contentIndex: index2, delta: chunk, partial: { ...partial } });
|
|
13579
13591
|
}
|
|
13580
|
-
|
|
13592
|
+
stream2.push({
|
|
13581
13593
|
type: "thinking_end",
|
|
13582
13594
|
contentIndex: index2,
|
|
13583
13595
|
content: block.thinking,
|
|
@@ -13587,43 +13599,43 @@ async function streamWithDeltas(stream, message, minTokenSize, maxTokenSize, tok
|
|
|
13587
13599
|
}
|
|
13588
13600
|
if (block.type === "text") {
|
|
13589
13601
|
partial.content = [...partial.content, { type: "text", text: "" }];
|
|
13590
|
-
|
|
13602
|
+
stream2.push({ type: "text_start", contentIndex: index2, partial: { ...partial } });
|
|
13591
13603
|
for (const chunk of splitStringByTokenSize(block.text, minTokenSize, maxTokenSize)) {
|
|
13592
13604
|
await scheduleChunk(chunk, tokensPerSecond);
|
|
13593
13605
|
if (signal?.aborted) {
|
|
13594
13606
|
const aborted = createAbortedMessage(partial);
|
|
13595
|
-
|
|
13596
|
-
|
|
13607
|
+
stream2.push({ type: "error", reason: "aborted", error: aborted });
|
|
13608
|
+
stream2.end(aborted);
|
|
13597
13609
|
return;
|
|
13598
13610
|
}
|
|
13599
13611
|
partial.content[index2].text += chunk;
|
|
13600
|
-
|
|
13612
|
+
stream2.push({ type: "text_delta", contentIndex: index2, delta: chunk, partial: { ...partial } });
|
|
13601
13613
|
}
|
|
13602
|
-
|
|
13614
|
+
stream2.push({ type: "text_end", contentIndex: index2, content: block.text, partial: { ...partial } });
|
|
13603
13615
|
continue;
|
|
13604
13616
|
}
|
|
13605
13617
|
partial.content = [...partial.content, { type: "toolCall", id: block.id, name: block.name, arguments: {} }];
|
|
13606
|
-
|
|
13618
|
+
stream2.push({ type: "toolcall_start", contentIndex: index2, partial: { ...partial } });
|
|
13607
13619
|
for (const chunk of splitStringByTokenSize(JSON.stringify(block.arguments), minTokenSize, maxTokenSize)) {
|
|
13608
13620
|
await scheduleChunk(chunk, tokensPerSecond);
|
|
13609
13621
|
if (signal?.aborted) {
|
|
13610
13622
|
const aborted = createAbortedMessage(partial);
|
|
13611
|
-
|
|
13612
|
-
|
|
13623
|
+
stream2.push({ type: "error", reason: "aborted", error: aborted });
|
|
13624
|
+
stream2.end(aborted);
|
|
13613
13625
|
return;
|
|
13614
13626
|
}
|
|
13615
|
-
|
|
13627
|
+
stream2.push({ type: "toolcall_delta", contentIndex: index2, delta: chunk, partial: { ...partial } });
|
|
13616
13628
|
}
|
|
13617
13629
|
partial.content[index2].arguments = block.arguments;
|
|
13618
|
-
|
|
13630
|
+
stream2.push({ type: "toolcall_end", contentIndex: index2, toolCall: block, partial: { ...partial } });
|
|
13619
13631
|
}
|
|
13620
13632
|
if (message.stopReason === "error" || message.stopReason === "aborted") {
|
|
13621
|
-
|
|
13622
|
-
|
|
13633
|
+
stream2.push({ type: "error", reason: message.stopReason, error: message });
|
|
13634
|
+
stream2.end(message);
|
|
13623
13635
|
return;
|
|
13624
13636
|
}
|
|
13625
|
-
|
|
13626
|
-
|
|
13637
|
+
stream2.push({ type: "done", reason: message.stopReason, message });
|
|
13638
|
+
stream2.end(message);
|
|
13627
13639
|
}
|
|
13628
13640
|
function createFauxCore(options) {
|
|
13629
13641
|
const api = options.api ?? randomId(DEFAULT_API);
|
|
@@ -13657,7 +13669,7 @@ function createFauxCore(options) {
|
|
|
13657
13669
|
contextWindow: definition.contextWindow ?? 128e3,
|
|
13658
13670
|
maxTokens: definition.maxTokens ?? 16384
|
|
13659
13671
|
}));
|
|
13660
|
-
const
|
|
13672
|
+
const stream2 = (requestModel, context, streamOptions) => {
|
|
13661
13673
|
const outer = createAssistantMessageEventStream();
|
|
13662
13674
|
const step = pendingResponses.shift();
|
|
13663
13675
|
state2.callCount++;
|
|
@@ -13683,7 +13695,7 @@ function createFauxCore(options) {
|
|
|
13683
13695
|
});
|
|
13684
13696
|
return outer;
|
|
13685
13697
|
};
|
|
13686
|
-
const streamSimple2 = (streamModel, context, streamOptions) =>
|
|
13698
|
+
const streamSimple2 = (streamModel, context, streamOptions) => stream2(streamModel, context, streamOptions);
|
|
13687
13699
|
function getModel(requestedModelId) {
|
|
13688
13700
|
if (!requestedModelId) {
|
|
13689
13701
|
return models[0];
|
|
@@ -13694,7 +13706,7 @@ function createFauxCore(options) {
|
|
|
13694
13706
|
api,
|
|
13695
13707
|
provider,
|
|
13696
13708
|
models,
|
|
13697
|
-
stream,
|
|
13709
|
+
stream: stream2,
|
|
13698
13710
|
streamSimple: streamSimple2,
|
|
13699
13711
|
getModel,
|
|
13700
13712
|
state: state2,
|
|
@@ -38789,12 +38801,12 @@ function builtinModels(options) {
|
|
|
38789
38801
|
|
|
38790
38802
|
// ../../node_modules/@earendil-works/pi-ai/dist/compat.js
|
|
38791
38803
|
var apiProviderRegistry = /* @__PURE__ */ new Map();
|
|
38792
|
-
function wrapStream(api,
|
|
38804
|
+
function wrapStream(api, stream2) {
|
|
38793
38805
|
return (model, context, options) => {
|
|
38794
38806
|
if (model.api !== api) {
|
|
38795
38807
|
throw new Error(`Mismatched api: ${model.api} expected ${api}`);
|
|
38796
38808
|
}
|
|
38797
|
-
return
|
|
38809
|
+
return stream2(model, context, options);
|
|
38798
38810
|
};
|
|
38799
38811
|
}
|
|
38800
38812
|
function wrapStreamSimple(api, streamSimple2) {
|
|
@@ -40225,6 +40237,47 @@ function createTestProvider() {
|
|
|
40225
40237
|
return { providerId: TEST_PROVIDER_ID, core, provider };
|
|
40226
40238
|
}
|
|
40227
40239
|
|
|
40240
|
+
// ../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/transportAnthropicApi.js
|
|
40241
|
+
function createTransportAnthropicApi(modelFetch) {
|
|
40242
|
+
const call = (model, context, options = {}) => {
|
|
40243
|
+
const client = new Anthropic({
|
|
40244
|
+
baseURL: model.baseUrl,
|
|
40245
|
+
apiKey: options.apiKey ?? null,
|
|
40246
|
+
authToken: null,
|
|
40247
|
+
defaultHeaders: { ...model.headers, ...options.headers },
|
|
40248
|
+
fetch: modelFetch,
|
|
40249
|
+
maxRetries: 0
|
|
40250
|
+
});
|
|
40251
|
+
return stream(model, context, {
|
|
40252
|
+
...options,
|
|
40253
|
+
client,
|
|
40254
|
+
maxRetries: 0
|
|
40255
|
+
});
|
|
40256
|
+
};
|
|
40257
|
+
const simple = (model, context, options) => {
|
|
40258
|
+
const base = buildBaseOptions(model, context, options, options?.apiKey);
|
|
40259
|
+
if (!options?.reasoning)
|
|
40260
|
+
return call(model, context, { ...base, thinkingEnabled: false });
|
|
40261
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
40262
|
+
const mapped = model.thinkingLevelMap?.[options.reasoning];
|
|
40263
|
+
const effort = typeof mapped === "string" ? mapped : options.reasoning === "minimal" || options.reasoning === "low" ? "low" : options.reasoning === "medium" ? "medium" : "high";
|
|
40264
|
+
return call(model, context, { ...base, thinkingEnabled: true, effort });
|
|
40265
|
+
}
|
|
40266
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
40267
|
+
const maxTokens = clampMaxTokensToContext(model, context, adjusted.maxTokens);
|
|
40268
|
+
return call(model, context, {
|
|
40269
|
+
...base,
|
|
40270
|
+
thinkingEnabled: true,
|
|
40271
|
+
maxTokens,
|
|
40272
|
+
thinkingBudgetTokens: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024))
|
|
40273
|
+
});
|
|
40274
|
+
};
|
|
40275
|
+
return {
|
|
40276
|
+
stream: (m, c, o) => call(m, c, o),
|
|
40277
|
+
streamSimple: (m, c, o) => simple(m, c, o)
|
|
40278
|
+
};
|
|
40279
|
+
}
|
|
40280
|
+
|
|
40228
40281
|
// ../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/anthropicProvider.js
|
|
40229
40282
|
function createApiKeyAuth(authName, fixedApiKey) {
|
|
40230
40283
|
return {
|
|
@@ -40247,7 +40300,7 @@ function createAnthropicProvider(options) {
|
|
|
40247
40300
|
auth: { apiKey: createApiKeyAuth(authName, fixedApiKey) },
|
|
40248
40301
|
models,
|
|
40249
40302
|
// 复用 pi-ai 内置的 Anthropic Messages 协议实现(含 stream/SSE 逻辑)
|
|
40250
|
-
api: anthropicMessagesApi()
|
|
40303
|
+
api: options.modelFetch ? createTransportAnthropicApi(options.modelFetch) : anthropicMessagesApi()
|
|
40251
40304
|
});
|
|
40252
40305
|
}
|
|
40253
40306
|
function buildAnthropicModel(providerId, baseUrl, descriptor) {
|
|
@@ -40347,13 +40400,14 @@ function createLinkqueModel(modelId, baseUrl = LINKQUE_DEFAULT_BASE_URL) {
|
|
|
40347
40400
|
id: modelId
|
|
40348
40401
|
});
|
|
40349
40402
|
}
|
|
40350
|
-
function createLinkqueProvider(baseUrl = LINKQUE_DEFAULT_BASE_URL) {
|
|
40403
|
+
function createLinkqueProvider(baseUrl = LINKQUE_DEFAULT_BASE_URL, modelFetch) {
|
|
40351
40404
|
return createAnthropicProvider({
|
|
40352
40405
|
providerId: LINKQUE_PROVIDER_ID,
|
|
40353
40406
|
providerName: "Linkque",
|
|
40354
40407
|
baseUrl,
|
|
40355
40408
|
models: LINKQUE_MODELS,
|
|
40356
|
-
authName: "Linkque API key"
|
|
40409
|
+
authName: "Linkque API key",
|
|
40410
|
+
modelFetch
|
|
40357
40411
|
});
|
|
40358
40412
|
}
|
|
40359
40413
|
|
|
@@ -40576,7 +40630,7 @@ var StreamBridge = class {
|
|
|
40576
40630
|
async startSession() {
|
|
40577
40631
|
const models = createModels();
|
|
40578
40632
|
const providerId = providerIdFor(this.auth.provider);
|
|
40579
|
-
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl));
|
|
40633
|
+
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl, this.auth.modelFetch));
|
|
40580
40634
|
models.setProvider(createTestProvider().provider);
|
|
40581
40635
|
let model;
|
|
40582
40636
|
if (this.options.model !== void 0) {
|
|
@@ -40762,7 +40816,7 @@ var PiFollowUpQuestionGenerator = class {
|
|
|
40762
40816
|
}
|
|
40763
40817
|
async generate(input) {
|
|
40764
40818
|
const models = this.modelsFactory();
|
|
40765
|
-
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl));
|
|
40819
|
+
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl, input.auth.modelFetch));
|
|
40766
40820
|
let model = models.getModel(LINKQUE_PROVIDER_ID, FOLLOW_UP_QUESTION_MODEL_ID);
|
|
40767
40821
|
model ??= createLinkqueModel(FOLLOW_UP_QUESTION_MODEL_ID, this.linkqueBaseUrl);
|
|
40768
40822
|
model = {
|
|
@@ -41259,6 +41313,24 @@ var EMPTY_TELEMETRY_RUN_CONTEXT = {
|
|
|
41259
41313
|
userKey: ""
|
|
41260
41314
|
};
|
|
41261
41315
|
|
|
41316
|
+
// ../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js
|
|
41317
|
+
async function authorizeAgentRun(runId, identity, port) {
|
|
41318
|
+
if (typeof runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(runId) || typeof identity?.userId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(identity.userId) || typeof identity.agentId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(identity.agentId)) {
|
|
41319
|
+
throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
|
|
41320
|
+
}
|
|
41321
|
+
const result = await port.authorizeRun({
|
|
41322
|
+
runId,
|
|
41323
|
+
agentId: identity.agentId,
|
|
41324
|
+
appbaseUserId: identity.userId
|
|
41325
|
+
});
|
|
41326
|
+
if (result?.quotaMode === "NORMAL")
|
|
41327
|
+
return { quotaMode: "NORMAL" };
|
|
41328
|
+
if (result?.quotaMode !== "LIMITED" && result?.quotaMode !== "AUTH_ONLY" || typeof result.modelFetch !== "function") {
|
|
41329
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
41330
|
+
}
|
|
41331
|
+
return result;
|
|
41332
|
+
}
|
|
41333
|
+
|
|
41262
41334
|
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
41263
41335
|
var validatePlugins = (plugins) => {
|
|
41264
41336
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -42583,6 +42655,28 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42583
42655
|
}
|
|
42584
42656
|
/** 产出 AgentStreamEvent 流;内核编排「解析上行资源 → 组请求 → agent loop」。 */
|
|
42585
42657
|
async *runAgentLoop(request, auth, options = {}) {
|
|
42658
|
+
if (options.runAuthorization) {
|
|
42659
|
+
try {
|
|
42660
|
+
const grant = await authorizeAgentRun(request.runId, options.runtimeContext, options.runAuthorization);
|
|
42661
|
+
if (grant.quotaMode !== "NORMAL")
|
|
42662
|
+
auth = { ...auth, modelFetch: grant.modelFetch };
|
|
42663
|
+
} catch (error) {
|
|
42664
|
+
const reason = error instanceof Error ? error.message : "";
|
|
42665
|
+
const code = [
|
|
42666
|
+
"SCENARIO_TURN_LIMIT",
|
|
42667
|
+
"SCENARIO_RUNTIME_AUTH_INVALID",
|
|
42668
|
+
"SCENARIO_RUNTIME_REPLAY"
|
|
42669
|
+
].includes(reason) ? reason : "SCENARIO_RUN_UNAVAILABLE";
|
|
42670
|
+
yield {
|
|
42671
|
+
type: "error",
|
|
42672
|
+
error: {
|
|
42673
|
+
code,
|
|
42674
|
+
message: code === "SCENARIO_TURN_LIMIT" ? "\u4F53\u9A8C\u5BF9\u8BDD\u6B21\u6570\u5DF2\u7528\u5B8C" : "\u672C\u8F6E\u5BF9\u8BDD\u672A\u83B7\u51C6\u6267\u884C"
|
|
42675
|
+
}
|
|
42676
|
+
};
|
|
42677
|
+
return;
|
|
42678
|
+
}
|
|
42679
|
+
}
|
|
42586
42680
|
const input = {
|
|
42587
42681
|
runId: request.runId,
|
|
42588
42682
|
agentId: options.runtimeContext?.agentId ?? this.agentId,
|
|
@@ -43358,6 +43452,7 @@ async function waitForObservation(promise, signal) {
|
|
|
43358
43452
|
function createImageTool(image, input, options, rules) {
|
|
43359
43453
|
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
43360
43454
|
const auth = { ...input.auth };
|
|
43455
|
+
const modelFetch = auth.modelFetch ?? fetchImpl;
|
|
43361
43456
|
const cache = /* @__PURE__ */ new Map();
|
|
43362
43457
|
let calls = 0;
|
|
43363
43458
|
return {
|
|
@@ -43397,7 +43492,7 @@ function createImageTool(image, input, options, rules) {
|
|
|
43397
43492
|
const pending = (async () => {
|
|
43398
43493
|
try {
|
|
43399
43494
|
const resolved = await resolveImage(image, fetchImpl, rules, signal);
|
|
43400
|
-
const response = await
|
|
43495
|
+
const response = await modelFetch(`${(options.baseUrl ?? RUNTIME_CONFIG_DEFAULTS.LINKQUE_BASE_URL).replace(/\/+$/, "")}/v1/messages`, {
|
|
43401
43496
|
method: "POST",
|
|
43402
43497
|
signal,
|
|
43403
43498
|
redirect: "error",
|
|
@@ -46376,19 +46471,32 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
46376
46471
|
}
|
|
46377
46472
|
const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
|
|
46378
46473
|
const { linkqueBaseUrl, knowledgeBaseUrl, skillLoaderBaseUrl, webSearchBaseUrl, eventBaseUrl, mcpSignEndpoint, openMcpBaseUrl, telemetryLogsEndpoint, telemetryTracesEndpoint } = resolveLinkqueEndpoints(env, envSelector);
|
|
46474
|
+
let runAuthorization = deps?.runAuthorization;
|
|
46475
|
+
const isScenarioUser = /^lqs_[a-f0-9]{32}$/u.test(historyOwnerId ?? "");
|
|
46476
|
+
if (!runAuthorization && isScenarioUser) {
|
|
46477
|
+
try {
|
|
46478
|
+
if (resolved.mode !== "user-token")
|
|
46479
|
+
throw new Error("scenario user token required");
|
|
46480
|
+
const accessKey = env.LINKQUE_AGENT_ACCESS_KEY?.trim() ?? "";
|
|
46481
|
+
if (!accessKey || !linkqueBaseUrl)
|
|
46482
|
+
throw new Error("invalid config");
|
|
46483
|
+
runAuthorization = createGatewayRunAuthorization({
|
|
46484
|
+
baseUrl: linkqueBaseUrl,
|
|
46485
|
+
token: resolved.modelCredential,
|
|
46486
|
+
accessKey
|
|
46487
|
+
});
|
|
46488
|
+
} catch {
|
|
46489
|
+
return jsonError(503, "SCENARIO_RUN_UNAVAILABLE", "\u573A\u666F\u53EF\u4FE1\u8BA4\u8BC1\u914D\u7F6E\u6682\u4E0D\u53EF\u7528");
|
|
46490
|
+
}
|
|
46491
|
+
}
|
|
46379
46492
|
const mcpConfigResolver = createAppbaseMcpConfigResolver({
|
|
46380
46493
|
agentId: protocol.agentId,
|
|
46381
46494
|
remoteBaseUrl: openMcpBaseUrl,
|
|
46382
46495
|
...mcpSignEndpoint ? { signEndpoint: mcpSignEndpoint } : {}
|
|
46383
46496
|
});
|
|
46384
|
-
const mcpDebugLog = isDebugLogLevel(env) && logCtx?.log ? (line, scope) => {
|
|
46385
|
-
const prefix = scope ? `[${scope}] ` : "";
|
|
46386
|
-
logCtx.log?.(prefix + line);
|
|
46387
|
-
} : void 0;
|
|
46388
46497
|
const rawMcpServerProvider = deps?.mcpServerProvider ?? createAppbaseMcpProvider({
|
|
46389
46498
|
resolveConfig: mcpConfigResolver,
|
|
46390
|
-
getAuthorizationHeader: mcpAuthorizationHeaderProvider
|
|
46391
|
-
...mcpDebugLog ? { debugLog: mcpDebugLog } : {}
|
|
46499
|
+
getAuthorizationHeader: mcpAuthorizationHeaderProvider
|
|
46392
46500
|
});
|
|
46393
46501
|
const mcpServerProvider = rawMcpServerProvider;
|
|
46394
46502
|
const securityAnswerPlugin = deps?.securityAnswerPlugin ?? createSecurityAnswerPlugin(historyStore, logCtx?.log);
|
|
@@ -46420,6 +46528,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
46420
46528
|
...temporaryFrontendAppId !== void 0 && { temporaryFrontendAppId }
|
|
46421
46529
|
}, logCtx);
|
|
46422
46530
|
return {
|
|
46531
|
+
...runAuthorization ? { runAuthorization } : {},
|
|
46423
46532
|
auth: resolved.auth,
|
|
46424
46533
|
// 模型取自 bundler 已 bake-in 的 protocol 默认模型(历史来自 env AGENT_MODEL,已移除)。
|
|
46425
46534
|
model: protocol.agent.model.defaultModel || void 0,
|
|
@@ -46555,12 +46664,12 @@ function preview(value, max = DEBUG_PREVIEW_MAX) {
|
|
|
46555
46664
|
str = str.replace(/\s+/g, " ").trim();
|
|
46556
46665
|
return str.length > max ? `${str.slice(0, max)}\u2026` : str;
|
|
46557
46666
|
}
|
|
46558
|
-
async function* debugLogAgentStream(
|
|
46667
|
+
async function* debugLogAgentStream(stream2, debugLog) {
|
|
46559
46668
|
const start = Date.now();
|
|
46560
46669
|
let firstResponseLogged = false;
|
|
46561
46670
|
const counts = { delta: 0, thinking: 0, tool: 0, card: 0 };
|
|
46562
46671
|
const summary = () => `\u4E8B\u4EF6\u603B\u6570=${counts.delta + counts.thinking + counts.tool + counts.card}(delta=${counts.delta},thinking=${counts.thinking},tool=${counts.tool},card=${counts.card})`;
|
|
46563
|
-
for await (const ev of
|
|
46672
|
+
for await (const ev of stream2) {
|
|
46564
46673
|
switch (ev.type) {
|
|
46565
46674
|
case "delta":
|
|
46566
46675
|
counts.delta += 1;
|
|
@@ -46852,9 +46961,20 @@ async function runAgentToChunksObserved(observation, deps, request, env, logCtx,
|
|
|
46852
46961
|
securityAnswer: false
|
|
46853
46962
|
};
|
|
46854
46963
|
}
|
|
46964
|
+
let modelAuth = deps.auth;
|
|
46855
46965
|
const runOptions = {
|
|
46856
46966
|
telemetryContext: observation.runtimeContext,
|
|
46857
46967
|
eventObservations: observation.events,
|
|
46968
|
+
...deps.runAuthorization ? {
|
|
46969
|
+
runAuthorization: {
|
|
46970
|
+
authorizeRun: async (input) => {
|
|
46971
|
+
const grant = await deps.runAuthorization.authorizeRun(input);
|
|
46972
|
+
if (grant.quotaMode !== "NORMAL")
|
|
46973
|
+
modelAuth = { ...deps.auth, modelFetch: grant.modelFetch };
|
|
46974
|
+
return grant;
|
|
46975
|
+
}
|
|
46976
|
+
}
|
|
46977
|
+
} : {},
|
|
46858
46978
|
requestSource: EModelRequestSource.APPBASE_FUNCTION,
|
|
46859
46979
|
runtimeContext: {
|
|
46860
46980
|
agentId: deps.protocol.agentId,
|
|
@@ -46996,6 +47116,7 @@ async function runAgentToChunksObserved(observation, deps, request, env, logCtx,
|
|
|
46996
47116
|
}
|
|
46997
47117
|
}
|
|
46998
47118
|
return {
|
|
47119
|
+
modelAuth,
|
|
46999
47120
|
response: completionError ? jsonError(500, "run_completion_failed", "\u4F1A\u8BDD\u6536\u5C3E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002") : {
|
|
47000
47121
|
status: 201,
|
|
47001
47122
|
body: { runId: request.runId, threadId: request.threadId }
|
|
@@ -47317,7 +47438,7 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
|
|
|
47317
47438
|
if (!preparedFollowUpContext || await isAnswerBlocked())
|
|
47318
47439
|
return execution.response;
|
|
47319
47440
|
const generationStartedAt = Date.now();
|
|
47320
|
-
const questions = await cfg.runtime.generateFollowUpQuestions(preparedFollowUpContext, cfg.auth, {
|
|
47441
|
+
const questions = await cfg.runtime.generateFollowUpQuestions(preparedFollowUpContext, execution.modelAuth ?? cfg.auth, {
|
|
47321
47442
|
runId: request.runId,
|
|
47322
47443
|
requestSource: EModelRequestSource.APPBASE_FUNCTION,
|
|
47323
47444
|
telemetryContext: cfg.telemetry?.createContext(request.runId),
|
|
@@ -47510,7 +47631,7 @@ async function chat(ctx) {
|
|
|
47510
47631
|
const envSelector = readEnvSelector(ctx.req.headers);
|
|
47511
47632
|
const traceId = readTraceId(ctx.req.headers);
|
|
47512
47633
|
const temporaryFrontendAppId = readTemporaryFrontendAppId(ctx.req.headers);
|
|
47513
|
-
const gatewayAuth = historyOwnerId ?
|
|
47634
|
+
const gatewayAuth = historyOwnerId ? resolveLinkqueGatewayRequestAuth(ctx.req.headers, process.env, logCtx) : void 0;
|
|
47514
47635
|
result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, readMcpPhoneAuthorization(ctx.req.headers)) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
47515
47636
|
} catch (err2) {
|
|
47516
47637
|
logCtx?.error?.(err2);
|
package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js
CHANGED
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
runClientCapability,
|
|
4
4
|
runClientCapabilityCleanup,
|
|
5
5
|
runClientCapabilityResult
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-CO4I3RJE.js";
|
|
7
7
|
import "../../chunk-IWOFD643.js";
|
|
8
8
|
import "../../chunk-PXCGFBV5.js";
|
|
9
9
|
import "../../chunk-ETG6PNHQ.js";
|
|
10
|
-
import "../../chunk-
|
|
10
|
+
import "../../chunk-VBERH5QM.js";
|
|
11
11
|
import "../../chunk-EAODRPW4.js";
|
|
12
12
|
import "../../chunk-XUFLSZM4.js";
|
|
13
13
|
import "../../chunk-GAYNLDWK.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getBakedProtocol,
|
|
3
3
|
setBakedProtocol
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-UZS5YLV2.js";
|
|
5
|
+
import "../chunk-VBERH5QM.js";
|
|
6
6
|
import "../chunk-EAODRPW4.js";
|
|
7
7
|
import "../chunk-XUFLSZM4.js";
|
|
8
8
|
import "../chunk-GAYNLDWK.js";
|