@jeffreycao/copilot-api 1.13.1 → 1.13.3
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/README.md +12 -31
- package/README.zh-CN.md +12 -31
- package/dist/auth-CtydxYcd.js +2 -0
- package/dist/{auth-BDHOrS4c.js → auth-HSvAnhak.js} +24 -22
- package/dist/auth-HSvAnhak.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{server-s_0_JChu.js → server-BXCLiIHf.js} +93 -185
- package/dist/server-BXCLiIHf.js.map +1 -0
- package/dist/{start-DxOR_R2Y.js → start-DHjCOvZC.js} +4 -4
- package/dist/{start-DxOR_R2Y.js.map → start-DHjCOvZC.js.map} +1 -1
- package/dist/{token-DigcCxDR.js → token-Bi8n0f86.js} +4 -4
- package/dist/{token-DigcCxDR.js.map → token-Bi8n0f86.js.map} +1 -1
- package/package.json +1 -1
- package/dist/auth-BDHOrS4c.js.map +0 -1
- package/dist/auth-BjDQCtUW.js +0 -2
- package/dist/server-s_0_JChu.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as setModelMappings, a as getExtraPromptForModel, c as getModelResponsesApiCompactThreshold$1, d as getReasoningEffortForModel, f as getSmallModel, g as isResponsesApiWebSocketEnabled, h as isResponsesApiWebSearchEnabled, i as getConfig, l as getProviderConfig, m as isResponsesApiContextManagementEnabled, n as getAnthropicApiKey, o as getMessageApiWebSearchModel, p as isMessagesApiEnabled, r as getClaudeTokenMultiplier, s as getModelMappings, u as getRawProviderConfig, v as listEnabledProviders, w as PATHS, x as resolveMappedModel } from "./config-DODTXsGz.js";
|
|
2
|
-
import { B as forwardError, C as prepareInteractionHeaders, D as compactMessageSections, E as compactAutoContinuePromptStarts, F as resolveTraceId$1, I as createPooledWebSocketStream, L as createWebSocketUrl, M as forwardCodexResponses, N as generateTraceId, P as requestContext, R as state, S as prepareForCompact, _ as getCopilotUsage, b as copilotHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as sleep, h as parseUserIdMetadata, k as compactSystemPromptStarts, m as isNullish, p as getUUID, r as setupCodexToken, w as prepareMessageProxyHeaders, x as copilotWebSocketHeaders, y as copilotBaseUrl, z as HTTPError } from "./token-
|
|
2
|
+
import { B as forwardError, C as prepareInteractionHeaders, D as compactMessageSections, E as compactAutoContinuePromptStarts, F as resolveTraceId$1, I as createPooledWebSocketStream, L as createWebSocketUrl, M as forwardCodexResponses, N as generateTraceId, P as requestContext, R as state, S as prepareForCompact, _ as getCopilotUsage, b as copilotHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as sleep, h as parseUserIdMetadata, k as compactSystemPromptStarts, m as isNullish, p as getUUID, r as setupCodexToken, w as prepareMessageProxyHeaders, x as copilotWebSocketHeaders, y as copilotBaseUrl, z as HTTPError } from "./token-Bi8n0f86.js";
|
|
3
3
|
import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, d as shouldEnableResponsesToolSearch, i as isBridgeToolSearchName, l as resolveBridgeToolSearchName, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as selectDeferredToolsByNames } from "./tool-search-OX6iPJ9D.js";
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -3313,8 +3313,8 @@ const createResponsesWebSocketStreamChunk = (data) => {
|
|
|
3313
3313
|
parsed.message = parsed.error.message;
|
|
3314
3314
|
}
|
|
3315
3315
|
return {
|
|
3316
|
-
data: JSON.stringify(parsed),
|
|
3317
3316
|
event: typeof parsed.type === "string" ? parsed.type : void 0,
|
|
3317
|
+
data: JSON.stringify(parsed),
|
|
3318
3318
|
id: typeof parsed.id === "string" ? parsed.id : void 0
|
|
3319
3319
|
};
|
|
3320
3320
|
} catch {
|
|
@@ -3339,8 +3339,8 @@ const createResponsesErrorServerSentEventChunk = (message) => {
|
|
|
3339
3339
|
type: "error"
|
|
3340
3340
|
};
|
|
3341
3341
|
return {
|
|
3342
|
-
|
|
3343
|
-
|
|
3342
|
+
event: errorEvent.type,
|
|
3343
|
+
data: JSON.stringify(errorEvent)
|
|
3344
3344
|
};
|
|
3345
3345
|
};
|
|
3346
3346
|
const getErrorMessage = (error) => {
|
|
@@ -4401,52 +4401,6 @@ const stringifyToolSearchArguments = (argumentsValue) => {
|
|
|
4401
4401
|
return;
|
|
4402
4402
|
}
|
|
4403
4403
|
};
|
|
4404
|
-
//#endregion
|
|
4405
|
-
//#region src/lib/subagent.ts
|
|
4406
|
-
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
4407
|
-
//#endregion
|
|
4408
|
-
//#region src/routes/messages/subagent-marker.ts
|
|
4409
|
-
const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
4410
|
-
const firstUserMessage = payload.messages.find((msg) => msg.role === "user" && Array.isArray(msg.content));
|
|
4411
|
-
if (!firstUserMessage || !Array.isArray(firstUserMessage.content)) return null;
|
|
4412
|
-
for (const block of firstUserMessage.content) {
|
|
4413
|
-
if (block.type !== "text") continue;
|
|
4414
|
-
const marker = parseSubagentMarkerFromSystemReminder(block.text);
|
|
4415
|
-
if (marker) return marker;
|
|
4416
|
-
}
|
|
4417
|
-
return null;
|
|
4418
|
-
};
|
|
4419
|
-
const parseSubagentMarkerFromSystemReminder = (text) => {
|
|
4420
|
-
const startTag = "<system-reminder>";
|
|
4421
|
-
const endTag = "</system-reminder>";
|
|
4422
|
-
let searchFrom = 0;
|
|
4423
|
-
while (true) {
|
|
4424
|
-
const reminderStart = text.indexOf(startTag, searchFrom);
|
|
4425
|
-
if (reminderStart === -1) break;
|
|
4426
|
-
const contentStart = reminderStart + 17;
|
|
4427
|
-
const reminderEnd = text.indexOf(endTag, contentStart);
|
|
4428
|
-
if (reminderEnd === -1) break;
|
|
4429
|
-
const reminderContent = text.slice(contentStart, reminderEnd);
|
|
4430
|
-
const markerIndex = reminderContent.indexOf(subagentMarkerPrefix);
|
|
4431
|
-
if (markerIndex === -1) {
|
|
4432
|
-
searchFrom = reminderEnd + 18;
|
|
4433
|
-
continue;
|
|
4434
|
-
}
|
|
4435
|
-
const markerJson = reminderContent.slice(markerIndex + 19).trim();
|
|
4436
|
-
try {
|
|
4437
|
-
const parsed = JSON.parse(markerJson);
|
|
4438
|
-
if (!parsed.session_id || !parsed.agent_id || !parsed.agent_type) {
|
|
4439
|
-
searchFrom = reminderEnd + 18;
|
|
4440
|
-
continue;
|
|
4441
|
-
}
|
|
4442
|
-
return parsed;
|
|
4443
|
-
} catch {
|
|
4444
|
-
searchFrom = reminderEnd + 18;
|
|
4445
|
-
continue;
|
|
4446
|
-
}
|
|
4447
|
-
}
|
|
4448
|
-
return null;
|
|
4449
|
-
};
|
|
4450
4404
|
const DEFAULT_RESPONSES_COMPACT_THRESHOLD_RATIO = .9;
|
|
4451
4405
|
const responsesUtilsDependencies = {
|
|
4452
4406
|
getModelResponsesApiCompactThreshold: getModelResponsesApiCompactThreshold$1,
|
|
@@ -4761,6 +4715,10 @@ const prepareWebSearchResponsesPayload = (payload, options = {}) => {
|
|
|
4761
4715
|
}, options.subagentAgentId);
|
|
4762
4716
|
responsesPayload.tools = [buildResponsesWebSearchTool(config)];
|
|
4763
4717
|
responsesPayload.tool_choice = void 0;
|
|
4718
|
+
responsesPayload.reasoning = {
|
|
4719
|
+
effort: "medium",
|
|
4720
|
+
summary: "auto"
|
|
4721
|
+
};
|
|
4764
4722
|
return responsesPayload;
|
|
4765
4723
|
};
|
|
4766
4724
|
const reconstructWebSearchResponse = (payload, result, options) => {
|
|
@@ -4783,21 +4741,21 @@ const reconstructWebSearchResponse = (payload, result, options) => {
|
|
|
4783
4741
|
}
|
|
4784
4742
|
};
|
|
4785
4743
|
};
|
|
4786
|
-
const collectWebSearchResponsesStreamResult = async ({ errorMessagePrefix = "Web search responses stream", parseEvent =
|
|
4744
|
+
const collectWebSearchResponsesStreamResult = async ({ errorMessagePrefix = "Web search responses stream", parseEvent = parseResponsesStreamEvent$1, upstreamResponse, logger }) => {
|
|
4787
4745
|
const state = createWebSearchResponsesStreamCollection();
|
|
4788
4746
|
for await (const chunk of upstreamResponse) {
|
|
4789
|
-
debugJson(logger, "Received web search responses stream chunk:", chunk
|
|
4747
|
+
debugJson(logger, "Received web search responses stream chunk:", chunk);
|
|
4790
4748
|
if (chunk.event === "ping") continue;
|
|
4791
4749
|
if (!chunk.data || chunk.data === "[DONE]") continue;
|
|
4792
4750
|
const parsed = parseEvent(chunk.data);
|
|
4793
4751
|
if (!parsed) continue;
|
|
4794
|
-
collectWebSearchResponsesStreamEvent(parsed, state);
|
|
4795
4752
|
if (parsed.type === "error") throw new Error(getStreamErrorMessage(parsed) ?? `${errorMessagePrefix} failed`);
|
|
4796
|
-
|
|
4753
|
+
const result = collectResponsesStreamEvent(parsed, state);
|
|
4754
|
+
if (result) return result;
|
|
4797
4755
|
}
|
|
4798
4756
|
throw new Error(`${errorMessagePrefix} ended without a terminal event`);
|
|
4799
4757
|
};
|
|
4800
|
-
const
|
|
4758
|
+
const parseResponsesStreamEvent$1 = (data) => {
|
|
4801
4759
|
try {
|
|
4802
4760
|
return JSON.parse(data);
|
|
4803
4761
|
} catch {
|
|
@@ -4807,127 +4765,29 @@ const parseWebSearchResponsesStreamEvent = (data) => {
|
|
|
4807
4765
|
const isWebSearchResponsesStream = (value) => {
|
|
4808
4766
|
return Boolean(value) && typeof value[Symbol.asyncIterator] === "function";
|
|
4809
4767
|
};
|
|
4810
|
-
const
|
|
4811
|
-
const
|
|
4812
|
-
outputItemsByIndex: /* @__PURE__ */ new Map(),
|
|
4813
|
-
textPartsByKey: /* @__PURE__ */ new Map()
|
|
4814
|
-
});
|
|
4815
|
-
const collectWebSearchResponsesStreamEvent = (event, state) => {
|
|
4768
|
+
const createWebSearchResponsesStreamCollection = () => ({ outputItemsByIndex: /* @__PURE__ */ new Map() });
|
|
4769
|
+
const collectResponsesStreamEvent = (event, state) => {
|
|
4816
4770
|
switch (event.type) {
|
|
4817
|
-
case "response.created":
|
|
4818
|
-
state.createdResponse = getResponsesResult(event.response);
|
|
4819
|
-
break;
|
|
4820
4771
|
case "response.completed":
|
|
4821
4772
|
case "response.failed":
|
|
4822
|
-
case "response.incomplete":
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
const item = getRecord(event.item);
|
|
4832
|
-
if (outputIndex !== void 0 && item) state.outputItemsByIndex.set(outputIndex, item);
|
|
4833
|
-
break;
|
|
4834
|
-
}
|
|
4835
|
-
case "response.output_text.delta": {
|
|
4836
|
-
const part = getOrCreateOutputTextPart(event, state);
|
|
4837
|
-
const delta = getString(event.delta);
|
|
4838
|
-
if (part && delta) part.text += delta;
|
|
4839
|
-
break;
|
|
4840
|
-
}
|
|
4841
|
-
case "response.output_text.done": {
|
|
4842
|
-
const part = getOrCreateOutputTextPart(event, state);
|
|
4843
|
-
const text = getString(event.text);
|
|
4844
|
-
if (part && text !== void 0) part.text = text;
|
|
4845
|
-
break;
|
|
4846
|
-
}
|
|
4847
|
-
case "response.output_text.annotation.added": {
|
|
4848
|
-
const part = getOrCreateOutputTextPart(event, state);
|
|
4849
|
-
const annotation = event.annotation;
|
|
4850
|
-
if (part && annotation !== void 0) part.annotations.push(annotation);
|
|
4851
|
-
break;
|
|
4773
|
+
case "response.incomplete": {
|
|
4774
|
+
event.response.copilot_usage ??= event.copilot_usage;
|
|
4775
|
+
const response = event.response;
|
|
4776
|
+
if (!response) throw new Error("Web search responses stream ended without a response");
|
|
4777
|
+
const output = [...state.outputItemsByIndex.entries()].sort(([leftIndex], [rightIndex]) => leftIndex - rightIndex).map(([, item]) => item);
|
|
4778
|
+
return {
|
|
4779
|
+
...response,
|
|
4780
|
+
output: output.length > 0 ? output : response.output
|
|
4781
|
+
};
|
|
4852
4782
|
}
|
|
4853
|
-
case "response.
|
|
4854
|
-
|
|
4783
|
+
case "response.output_item.done":
|
|
4784
|
+
state.outputItemsByIndex.set(event.output_index, event.item);
|
|
4855
4785
|
break;
|
|
4856
4786
|
}
|
|
4857
4787
|
};
|
|
4858
|
-
const buildWebSearchResponsesStreamResult = (state) => {
|
|
4859
|
-
const response = state.terminalResponse ?? state.createdResponse;
|
|
4860
|
-
if (!response) throw new Error("Web search responses stream ended without a response");
|
|
4861
|
-
const output = buildCollectedWebSearchOutput(state);
|
|
4862
|
-
return {
|
|
4863
|
-
...response,
|
|
4864
|
-
output: output.length > 0 ? output : response.output
|
|
4865
|
-
};
|
|
4866
|
-
};
|
|
4867
|
-
const buildCollectedWebSearchOutput = (state) => [...state.outputItemsByIndex.entries()].sort(([leftIndex], [rightIndex]) => leftIndex - rightIndex).map(([outputIndex, item]) => mergeOutputItemWithCollectedText(outputIndex, item, state));
|
|
4868
|
-
const mergeOutputItemWithCollectedText = (outputIndex, item, state) => {
|
|
4869
|
-
if (item.type !== "message") return item;
|
|
4870
|
-
const collectedParts = getCollectedTextParts(outputIndex, state);
|
|
4871
|
-
if (collectedParts.length === 0) return item;
|
|
4872
|
-
const content = getArray(item.content);
|
|
4873
|
-
for (const part of collectedParts) {
|
|
4874
|
-
const existingPart = getRecord(content[part.contentIndex]);
|
|
4875
|
-
content[part.contentIndex] = {
|
|
4876
|
-
...existingPart,
|
|
4877
|
-
type: "output_text",
|
|
4878
|
-
text: part.text,
|
|
4879
|
-
annotations: mergeAnnotations(existingPart?.annotations, part.annotations)
|
|
4880
|
-
};
|
|
4881
|
-
}
|
|
4882
|
-
return {
|
|
4883
|
-
...item,
|
|
4884
|
-
content
|
|
4885
|
-
};
|
|
4886
|
-
};
|
|
4887
|
-
const collectDoneContentPart = (event, state) => {
|
|
4888
|
-
const partRecord = getRecord(getRecord(event)?.part);
|
|
4889
|
-
if (partRecord?.type !== "output_text") return;
|
|
4890
|
-
const part = getOrCreateOutputTextPart(event, state);
|
|
4891
|
-
if (!part) return;
|
|
4892
|
-
const text = getString(partRecord.text);
|
|
4893
|
-
if (text !== void 0) part.text = text;
|
|
4894
|
-
const annotations = getArray(partRecord.annotations);
|
|
4895
|
-
if (annotations.length > 0) part.annotations.push(...annotations);
|
|
4896
|
-
};
|
|
4897
|
-
const getOrCreateOutputTextPart = (event, state) => {
|
|
4898
|
-
const eventRecord = getRecord(event);
|
|
4899
|
-
const outputIndex = getNumber(eventRecord?.output_index);
|
|
4900
|
-
const contentIndex = getNumber(eventRecord?.content_index);
|
|
4901
|
-
if (outputIndex === void 0 || contentIndex === void 0) return;
|
|
4902
|
-
const key = `${outputIndex}:${contentIndex}`;
|
|
4903
|
-
let part = state.textPartsByKey.get(key);
|
|
4904
|
-
if (!part) {
|
|
4905
|
-
part = {
|
|
4906
|
-
annotations: [],
|
|
4907
|
-
contentIndex,
|
|
4908
|
-
itemId: getString(eventRecord?.item_id),
|
|
4909
|
-
outputIndex,
|
|
4910
|
-
text: ""
|
|
4911
|
-
};
|
|
4912
|
-
state.textPartsByKey.set(key, part);
|
|
4913
|
-
}
|
|
4914
|
-
return part;
|
|
4915
|
-
};
|
|
4916
|
-
const getCollectedTextParts = (outputIndex, state) => [...state.textPartsByKey.values()].filter((part) => part.outputIndex === outputIndex).sort((left, right) => left.contentIndex - right.contentIndex || (left.itemId ?? "").localeCompare(right.itemId ?? ""));
|
|
4917
|
-
const mergeAnnotations = (existingAnnotations, collectedAnnotations) => {
|
|
4918
|
-
const annotations = getArray(existingAnnotations);
|
|
4919
|
-
annotations.push(...collectedAnnotations);
|
|
4920
|
-
return annotations;
|
|
4921
|
-
};
|
|
4922
|
-
const getResponsesResult = (value) => getRecord(value);
|
|
4923
|
-
const getRecord = (value) => value && typeof value === "object" ? value : void 0;
|
|
4924
|
-
const getArray = (value) => Array.isArray(value) ? Array.from(value) : [];
|
|
4925
4788
|
const getStreamErrorMessage = (event) => {
|
|
4926
|
-
|
|
4927
|
-
return getString(getRecord(eventRecord?.error)?.message) ?? getString(eventRecord?.message);
|
|
4789
|
+
return event.error?.message ?? event.message ?? void 0;
|
|
4928
4790
|
};
|
|
4929
|
-
const getNumber = (value) => typeof value === "number" ? value : void 0;
|
|
4930
|
-
const getString = (value) => typeof value === "string" ? value : void 0;
|
|
4931
4791
|
const createUsageRecorder = (payload, sessionId, webSearchModel) => webSearchFlowDependencies.createUsageRecorder(payload, sessionId, webSearchModel);
|
|
4932
4792
|
/**
|
|
4933
4793
|
* Entry point for web-search detection and routing on /v1/messages.
|
|
@@ -4950,17 +4810,15 @@ const tryHandleWebSearch = async (c, payload, options) => {
|
|
|
4950
4810
|
return await options.forwardToProvider(c, payload, route.alias.provider);
|
|
4951
4811
|
}
|
|
4952
4812
|
if (route.kind === "responses") {
|
|
4953
|
-
const subagentMarker = parseSubagentMarkerFromFirstUser(payload);
|
|
4954
4813
|
let sessionId = getRootSessionId(payload, c);
|
|
4955
4814
|
const requestId = generateRequestIdFromPayload(payload, sessionId);
|
|
4956
4815
|
if (!sessionId) sessionId = getUUID(requestId);
|
|
4957
|
-
const compactType = getCompactType(payload);
|
|
4958
4816
|
return await handleWebSearchViaResponses(c, payload, {
|
|
4959
|
-
subagentMarker,
|
|
4817
|
+
subagentMarker: null,
|
|
4960
4818
|
webSearchModel: route.model,
|
|
4961
4819
|
requestId,
|
|
4962
4820
|
sessionId,
|
|
4963
|
-
compactType,
|
|
4821
|
+
compactType: 0,
|
|
4964
4822
|
logger: options.logger
|
|
4965
4823
|
});
|
|
4966
4824
|
}
|
|
@@ -5007,10 +4865,14 @@ const handleWebSearchViaResponses = async (c, payload, options) => {
|
|
|
5007
4865
|
});
|
|
5008
4866
|
if (!wantsStream) return c.json(response);
|
|
5009
4867
|
return streamSSE(c, async (stream) => {
|
|
5010
|
-
for (const event of buildSyntheticStreamEvents(response))
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
4868
|
+
for (const event of buildSyntheticStreamEvents(response)) {
|
|
4869
|
+
const data = JSON.stringify(event);
|
|
4870
|
+
logger.debug(`Web search stream event`, data);
|
|
4871
|
+
await stream.writeSSE({
|
|
4872
|
+
event: event.type,
|
|
4873
|
+
data
|
|
4874
|
+
});
|
|
4875
|
+
}
|
|
5014
4876
|
});
|
|
5015
4877
|
};
|
|
5016
4878
|
const blockToStreamEvents = (block, index) => {
|
|
@@ -5262,11 +5124,7 @@ async function handleProviderMessagesForProvider(c, options) {
|
|
|
5262
5124
|
}
|
|
5263
5125
|
const handleOpenAIResponsesProviderWebSearchMessages = async (c, options) => {
|
|
5264
5126
|
const { modelConfig, payload, provider, providerConfig } = options;
|
|
5265
|
-
const selectedModel = providerConfig.name === "codex" ? getModels().data.find((model) => model.id === payload.model) : void 0;
|
|
5266
5127
|
const responsesPayload = prepareWebSearchResponsesPayload(payload);
|
|
5267
|
-
responsesPayload.stream = true;
|
|
5268
|
-
applyResponsesApiContextManagement(responsesPayload, selectedModel?.capabilities.limits.max_prompt_tokens);
|
|
5269
|
-
compactInputByLatestCompaction(responsesPayload);
|
|
5270
5128
|
debugJson(logger$6, "provider.messages.responses.web_search.request", {
|
|
5271
5129
|
payload: responsesPayload,
|
|
5272
5130
|
provider
|
|
@@ -5694,13 +5552,17 @@ const respondWebSearchProviderMessagesJson = (c, options) => {
|
|
|
5694
5552
|
const { body, modelConfig, payload, pricingCurrency, provider } = options;
|
|
5695
5553
|
createProviderMessagesUsageRecorder(payload, provider, modelConfig, pricingCurrency)(normalizeResponsesUsage(body.usage));
|
|
5696
5554
|
const { extract, response } = reconstructWebSearchResponse(payload, body, { requestId: body.id || `${provider}:${payload.model}` });
|
|
5697
|
-
logger$6
|
|
5555
|
+
debugJson(logger$6, `Web search via responses: ${extract.queries.length} quer(y/ies), ${extract.sources.length} source(s)`, body);
|
|
5698
5556
|
if (!payload.stream) return c.json(response);
|
|
5699
5557
|
return streamSSE(c, async (stream) => {
|
|
5700
|
-
for (const event of buildSyntheticStreamEvents(response))
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5558
|
+
for (const event of buildSyntheticStreamEvents(response)) {
|
|
5559
|
+
const data = JSON.stringify(event);
|
|
5560
|
+
logger$6.debug(`Web search stream event`, data);
|
|
5561
|
+
await stream.writeSSE({
|
|
5562
|
+
event: event.type,
|
|
5563
|
+
data
|
|
5564
|
+
});
|
|
5565
|
+
}
|
|
5704
5566
|
});
|
|
5705
5567
|
};
|
|
5706
5568
|
const createProviderMessagesUsageRecorder = (payload, provider, modelConfig, pricingCurrency) => createProviderTokenUsageRecorder({
|
|
@@ -5998,6 +5860,52 @@ const parseAnthropicStreamEvent = (data) => {
|
|
|
5998
5860
|
}
|
|
5999
5861
|
};
|
|
6000
5862
|
//#endregion
|
|
5863
|
+
//#region src/lib/subagent.ts
|
|
5864
|
+
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
5865
|
+
//#endregion
|
|
5866
|
+
//#region src/routes/messages/subagent-marker.ts
|
|
5867
|
+
const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
5868
|
+
const firstUserMessage = payload.messages.find((msg) => msg.role === "user" && Array.isArray(msg.content));
|
|
5869
|
+
if (!firstUserMessage || !Array.isArray(firstUserMessage.content)) return null;
|
|
5870
|
+
for (const block of firstUserMessage.content) {
|
|
5871
|
+
if (block.type !== "text") continue;
|
|
5872
|
+
const marker = parseSubagentMarkerFromSystemReminder(block.text);
|
|
5873
|
+
if (marker) return marker;
|
|
5874
|
+
}
|
|
5875
|
+
return null;
|
|
5876
|
+
};
|
|
5877
|
+
const parseSubagentMarkerFromSystemReminder = (text) => {
|
|
5878
|
+
const startTag = "<system-reminder>";
|
|
5879
|
+
const endTag = "</system-reminder>";
|
|
5880
|
+
let searchFrom = 0;
|
|
5881
|
+
while (true) {
|
|
5882
|
+
const reminderStart = text.indexOf(startTag, searchFrom);
|
|
5883
|
+
if (reminderStart === -1) break;
|
|
5884
|
+
const contentStart = reminderStart + 17;
|
|
5885
|
+
const reminderEnd = text.indexOf(endTag, contentStart);
|
|
5886
|
+
if (reminderEnd === -1) break;
|
|
5887
|
+
const reminderContent = text.slice(contentStart, reminderEnd);
|
|
5888
|
+
const markerIndex = reminderContent.indexOf(subagentMarkerPrefix);
|
|
5889
|
+
if (markerIndex === -1) {
|
|
5890
|
+
searchFrom = reminderEnd + 18;
|
|
5891
|
+
continue;
|
|
5892
|
+
}
|
|
5893
|
+
const markerJson = reminderContent.slice(markerIndex + 19).trim();
|
|
5894
|
+
try {
|
|
5895
|
+
const parsed = JSON.parse(markerJson);
|
|
5896
|
+
if (!parsed.session_id || !parsed.agent_id || !parsed.agent_type) {
|
|
5897
|
+
searchFrom = reminderEnd + 18;
|
|
5898
|
+
continue;
|
|
5899
|
+
}
|
|
5900
|
+
return parsed;
|
|
5901
|
+
} catch {
|
|
5902
|
+
searchFrom = reminderEnd + 18;
|
|
5903
|
+
continue;
|
|
5904
|
+
}
|
|
5905
|
+
}
|
|
5906
|
+
return null;
|
|
5907
|
+
};
|
|
5908
|
+
//#endregion
|
|
6001
5909
|
//#region src/routes/messages/handler.ts
|
|
6002
5910
|
const logger$5 = createHandlerLogger("messages-handler");
|
|
6003
5911
|
const messagesFlowHandlers = {
|
|
@@ -6678,4 +6586,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
6678
6586
|
//#endregion
|
|
6679
6587
|
export { server };
|
|
6680
6588
|
|
|
6681
|
-
//# sourceMappingURL=server-
|
|
6589
|
+
//# sourceMappingURL=server-BXCLiIHf.js.map
|