@jsonstudio/llms 0.6.3685 → 0.6.3686
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/dist/conversion/compat/actions/antigravity-thought-signature-cache.js +2 -22
- package/dist/conversion/compat/actions/deepseek-web-response.js +7 -0
- package/dist/conversion/compat/actions/field-mapping.js +153 -2
- package/dist/conversion/compat/actions/lmstudio-responses-input-stringify.js +104 -3
- package/dist/conversion/hub/node-support.js +1 -1
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +1 -9
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +28 -35
- package/dist/conversion/hub/pipeline/hub-pipeline.js +121 -197
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +4 -4
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -20
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +7 -6
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +41 -69
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +0 -3
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +1 -2
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +0 -2
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +0 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +2 -3
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +5 -18
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +2 -1
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +16 -0
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +52 -27
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +0 -1
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +1 -1
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +5 -9
- package/dist/conversion/hub/process/chat-process-continue-execution.js +3 -0
- package/dist/conversion/hub/process/chat-process-media.d.ts +2 -1
- package/dist/conversion/hub/process/chat-process-media.js +63 -9
- package/dist/conversion/hub/process/chat-process-session-usage.d.ts +6 -24
- package/dist/conversion/hub/process/chat-process-session-usage.js +101 -200
- package/dist/conversion/hub/response/provider-response.js +13 -13
- package/dist/conversion/hub/types/chat-envelope.d.ts +0 -1
- package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +4 -0
- package/dist/conversion/responses/responses-openai-bridge.d.ts +0 -1
- package/dist/conversion/responses/responses-openai-bridge.js +34 -28
- package/dist/conversion/shared/anthropic-message-utils.js +1 -14
- package/dist/conversion/shared/reasoning-normalizer.js +22 -41
- package/dist/conversion/shared/responses-tool-utils.js +2 -3
- package/dist/conversion/shared/tool-governor.js +4 -2
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/router/virtual-router/engine/routing-state/store.js +2 -21
- package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +0 -1
- package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +0 -1
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.d.ts +0 -3
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.js +0 -72
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +1 -1
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +1 -1
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +2 -2
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +96 -80
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +29 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +2 -6
- package/dist/router/virtual-router/engine.js +6 -9
- package/dist/router/virtual-router/routing-instructions/state.js +27 -37
- package/dist/router/virtual-router/routing-instructions/types.d.ts +4 -6
- package/dist/router/virtual-router/token-estimator.js +0 -21
- package/dist/servertool/handlers/stop-message-auto.js +1 -11
- package/dist/tools/apply-patch/execution-capturer.d.ts +1 -1
- package/dist/tools/apply-patch/execution-capturer.js +2 -1
- package/dist/tools/apply-patch/regression-capturer.js +1 -2
- package/dist/tools/tool-registry.js +2 -1
- package/package.json +1 -1
package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js
CHANGED
|
@@ -1,44 +1,61 @@
|
|
|
1
|
-
import { recordStage } from
|
|
2
|
-
import { sanitizeReqInboundFormatEnvelopeWithNative } from
|
|
3
|
-
import { parseReqInboundFormatEnvelopeWithNative } from
|
|
4
|
-
import { normalizeReasoningInAnthropicPayload, normalizeReasoningInChatPayload, normalizeReasoningInGeminiPayload, normalizeReasoningInResponsesPayload } from
|
|
5
|
-
import {
|
|
1
|
+
import { recordStage } from "../../../stages/utils.js";
|
|
2
|
+
import { sanitizeReqInboundFormatEnvelopeWithNative } from "../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js";
|
|
3
|
+
import { parseReqInboundFormatEnvelopeWithNative } from "../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js";
|
|
4
|
+
import { normalizeReasoningInAnthropicPayload, normalizeReasoningInChatPayload, normalizeReasoningInGeminiPayload, normalizeReasoningInResponsesPayload, } from "../../../../../shared/reasoning-normalizer.js";
|
|
5
|
+
import { logHubStageTiming } from "../../../hub-stage-timing.js";
|
|
6
6
|
function resolveProtocolToken(adapterContext) {
|
|
7
|
-
const candidate = typeof adapterContext.providerProtocol ===
|
|
7
|
+
const candidate = typeof adapterContext.providerProtocol === "string" &&
|
|
8
|
+
adapterContext.providerProtocol.trim().length
|
|
8
9
|
? adapterContext.providerProtocol.trim().toLowerCase()
|
|
9
|
-
:
|
|
10
|
-
if (candidate ===
|
|
10
|
+
: "";
|
|
11
|
+
if (candidate === "openai-chat" ||
|
|
12
|
+
candidate === "openai-responses" ||
|
|
13
|
+
candidate === "anthropic-messages" ||
|
|
14
|
+
candidate === "gemini-chat") {
|
|
11
15
|
return candidate;
|
|
12
16
|
}
|
|
13
|
-
return
|
|
17
|
+
return "openai-chat";
|
|
14
18
|
}
|
|
15
19
|
function applyReasoningNormalization(rawRequest, protocol) {
|
|
16
|
-
if (protocol ===
|
|
20
|
+
if (protocol === "openai-responses") {
|
|
17
21
|
normalizeReasoningInResponsesPayload(rawRequest, {
|
|
18
22
|
includeInput: true,
|
|
19
|
-
includeInstructions: true
|
|
23
|
+
includeInstructions: true,
|
|
20
24
|
});
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
|
-
if (protocol ===
|
|
27
|
+
if (protocol === "anthropic-messages") {
|
|
24
28
|
normalizeReasoningInAnthropicPayload(rawRequest);
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
27
|
-
if (protocol ===
|
|
31
|
+
if (protocol === "gemini-chat") {
|
|
28
32
|
normalizeReasoningInGeminiPayload(rawRequest);
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
35
|
normalizeReasoningInChatPayload(rawRequest);
|
|
32
36
|
}
|
|
33
37
|
export async function runReqInboundStage1FormatParse(options) {
|
|
38
|
+
const requestId = options.adapterContext.requestId || "unknown";
|
|
34
39
|
const protocol = resolveProtocolToken(options.adapterContext);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
logHubStageTiming(requestId, "req_inbound.stage1_reasoning_normalize", "start", { protocol });
|
|
41
|
+
const normalizeStart = Date.now();
|
|
42
|
+
applyReasoningNormalization(options.rawRequest, protocol);
|
|
43
|
+
logHubStageTiming(requestId, "req_inbound.stage1_reasoning_normalize", "completed", { elapsedMs: Date.now() - normalizeStart, protocol });
|
|
44
|
+
logHubStageTiming(requestId, "req_inbound.stage1_native_parse", "start");
|
|
45
|
+
const parseStart = Date.now();
|
|
46
|
+
const envelopeRaw = parseReqInboundFormatEnvelopeWithNative({
|
|
38
47
|
rawRequest: options.rawRequest,
|
|
39
|
-
protocol
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
protocol,
|
|
49
|
+
});
|
|
50
|
+
logHubStageTiming(requestId, "req_inbound.stage1_native_parse", "completed", {
|
|
51
|
+
elapsedMs: Date.now() - parseStart,
|
|
52
|
+
});
|
|
53
|
+
logHubStageTiming(requestId, "req_inbound.stage1_sanitize", "start");
|
|
54
|
+
const sanitizeStart = Date.now();
|
|
55
|
+
const envelope = sanitizeReqInboundFormatEnvelopeWithNative(envelopeRaw);
|
|
56
|
+
logHubStageTiming(requestId, "req_inbound.stage1_sanitize", "completed", {
|
|
57
|
+
elapsedMs: Date.now() - sanitizeStart,
|
|
58
|
+
});
|
|
59
|
+
recordStage(options.stageRecorder, "chat_process.req.stage1.format_parse", envelope);
|
|
43
60
|
return envelope;
|
|
44
61
|
}
|
package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { AdapterContext, ChatEnvelope } from
|
|
2
|
-
import type { FormatEnvelope } from
|
|
3
|
-
import { type JsonObject } from
|
|
4
|
-
import type { SemanticMapper, StageRecorder } from
|
|
5
|
-
import type { StandardizedRequest } from
|
|
1
|
+
import type { AdapterContext, ChatEnvelope } from "../../../../types/chat-envelope.js";
|
|
2
|
+
import type { FormatEnvelope } from "../../../../types/format-envelope.js";
|
|
3
|
+
import { type JsonObject } from "../../../../types/json.js";
|
|
4
|
+
import type { SemanticMapper, StageRecorder } from "../../../../format-adapters/index.js";
|
|
5
|
+
import type { StandardizedRequest } from "../../../../types/standardized.js";
|
|
6
6
|
export interface ReqInboundStage2SemanticMapOptions {
|
|
7
7
|
adapterContext: AdapterContext;
|
|
8
8
|
formatEnvelope: FormatEnvelope<JsonObject>;
|
|
9
|
-
semanticMapper: Pick<SemanticMapper,
|
|
9
|
+
semanticMapper: Pick<SemanticMapper, "toChat">;
|
|
10
10
|
/**
|
|
11
11
|
* Mappable cross-protocol semantics (e.g. /v1/responses submit resume) must be
|
|
12
12
|
* lifted into chat semantics before entering chat_process.
|
|
@@ -19,5 +19,6 @@ export interface ReqInboundStage2SemanticMapOptions {
|
|
|
19
19
|
export interface ReqInboundStage2SemanticMapResult {
|
|
20
20
|
chatEnvelope: ChatEnvelope;
|
|
21
21
|
standardizedRequest: StandardizedRequest;
|
|
22
|
+
responsesContext?: JsonObject;
|
|
22
23
|
}
|
|
23
24
|
export declare function runReqInboundStage2SemanticMap(options: ReqInboundStage2SemanticMapOptions): Promise<ReqInboundStage2SemanticMapResult>;
|
package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js
CHANGED
|
@@ -1,59 +1,18 @@
|
|
|
1
|
-
import { isJsonObject, jsonClone } from
|
|
2
|
-
import { applyHubOperationTableInbound } from
|
|
3
|
-
import { recordStage } from
|
|
4
|
-
import { liftReqInboundSemantics } from
|
|
5
|
-
import { validateChatEnvelopeWithNative } from
|
|
6
|
-
import { chatEnvelopeToStandardizedWithNative } from
|
|
7
|
-
import {
|
|
8
|
-
import { logHubStageTiming, measureHubStage } from '../../../hub-stage-timing.js';
|
|
9
|
-
function logNativeResponsesSemanticMapBreakdown(requestId, timings) {
|
|
10
|
-
if (!requestId || !timings) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const stages = [
|
|
14
|
-
['captureContextMs', 'request_stage.req_inbound.semantic_map.native.capture_context'],
|
|
15
|
-
['buildRequestMs', 'request_stage.req_inbound.semantic_map.native.build_request'],
|
|
16
|
-
['mapChatMs', 'request_stage.req_inbound.semantic_map.native.map_chat'],
|
|
17
|
-
['toStandardizedMs', 'request_stage.req_inbound.semantic_map.native.to_standardized']
|
|
18
|
-
];
|
|
19
|
-
for (const [key, stage] of stages) {
|
|
20
|
-
const value = timings[key];
|
|
21
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
22
|
-
logHubStageTiming(requestId, stage, 'completed', { nativeMs: value, elapsedMs: value });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function isResponsesCreateFastPathCandidate(options) {
|
|
27
|
-
if (options.responsesResume) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
const protocol = options.formatEnvelope.protocol?.trim().toLowerCase();
|
|
31
|
-
if (protocol !== 'openai-responses') {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const endpoint = options.adapterContext.entryEndpoint?.trim().toLowerCase();
|
|
35
|
-
return endpoint !== '/v1/responses.submit_tool_outputs';
|
|
36
|
-
}
|
|
1
|
+
import { isJsonObject, jsonClone, } from "../../../../types/json.js";
|
|
2
|
+
import { applyHubOperationTableInbound } from "../../../../operation-table/operation-table-runner.js";
|
|
3
|
+
import { recordStage } from "../../../stages/utils.js";
|
|
4
|
+
import { liftReqInboundSemantics } from "./semantic-lift.js";
|
|
5
|
+
import { validateChatEnvelopeWithNative } from "../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js";
|
|
6
|
+
import { chatEnvelopeToStandardizedWithNative } from "../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js";
|
|
7
|
+
import { logHubStageTiming } from "../../../hub-stage-timing.js";
|
|
37
8
|
export async function runReqInboundStage2SemanticMap(options) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
entryEndpoint: options.adapterContext.entryEndpoint,
|
|
42
|
-
adapterContext: options.adapterContext
|
|
43
|
-
}));
|
|
44
|
-
logNativeResponsesSemanticMapBreakdown(options.adapterContext.requestId, nativeResult.timings);
|
|
45
|
-
const chatEnvelope = nativeResult.chatEnvelope;
|
|
46
|
-
const standardizedRequest = nativeResult.standardizedRequest;
|
|
47
|
-
validateChatEnvelopeWithNative(chatEnvelope, {
|
|
48
|
-
stage: 'req_inbound',
|
|
49
|
-
direction: 'request'
|
|
50
|
-
});
|
|
51
|
-
recordStage(options.stageRecorder, 'chat_process.req.stage2.semantic_map', chatEnvelope);
|
|
52
|
-
return { chatEnvelope, standardizedRequest };
|
|
53
|
-
}
|
|
9
|
+
const requestId = options.adapterContext.requestId || "unknown";
|
|
10
|
+
logHubStageTiming(requestId, "req_inbound.stage2_semantic_mapper_toChat", "start");
|
|
11
|
+
const toChatStart = Date.now();
|
|
54
12
|
const chatEnvelope = await options.semanticMapper.toChat(options.formatEnvelope, options.adapterContext);
|
|
13
|
+
logHubStageTiming(requestId, "req_inbound.stage2_semantic_mapper_toChat", "completed", { elapsedMs: Date.now() - toChatStart });
|
|
55
14
|
const preservedResponsesContext = (() => {
|
|
56
|
-
if (!chatEnvelope.semantics || typeof chatEnvelope.semantics !==
|
|
15
|
+
if (!chatEnvelope.semantics || typeof chatEnvelope.semantics !== "object") {
|
|
57
16
|
return undefined;
|
|
58
17
|
}
|
|
59
18
|
const semantics = chatEnvelope.semantics;
|
|
@@ -68,7 +27,7 @@ export async function runReqInboundStage2SemanticMap(options) {
|
|
|
68
27
|
applyHubOperationTableInbound({
|
|
69
28
|
formatEnvelope: options.formatEnvelope,
|
|
70
29
|
chatEnvelope,
|
|
71
|
-
adapterContext: options.adapterContext
|
|
30
|
+
adapterContext: options.adapterContext,
|
|
72
31
|
});
|
|
73
32
|
// Semantic Gate (request): before entering chat_process, lift any mappable protocol semantics
|
|
74
33
|
// into ChatEnvelope.semantics. Do not persist these in metadata.
|
|
@@ -76,12 +35,14 @@ export async function runReqInboundStage2SemanticMap(options) {
|
|
|
76
35
|
chatEnvelope,
|
|
77
36
|
formatEnvelope: options.formatEnvelope,
|
|
78
37
|
adapterContext: options.adapterContext,
|
|
79
|
-
responsesResume: options.responsesResume
|
|
38
|
+
responsesResume: options.responsesResume,
|
|
80
39
|
});
|
|
81
40
|
if (preservedResponsesContext) {
|
|
82
41
|
const currentSemantics = chatEnvelope.semantics;
|
|
83
|
-
if (!currentSemantics || typeof currentSemantics !==
|
|
84
|
-
chatEnvelope.semantics = {
|
|
42
|
+
if (!currentSemantics || typeof currentSemantics !== "object") {
|
|
43
|
+
chatEnvelope.semantics = {
|
|
44
|
+
responses: { context: jsonClone(preservedResponsesContext) },
|
|
45
|
+
};
|
|
85
46
|
}
|
|
86
47
|
else {
|
|
87
48
|
const semantics = currentSemantics;
|
|
@@ -93,28 +54,31 @@ export async function runReqInboundStage2SemanticMap(options) {
|
|
|
93
54
|
...semantics,
|
|
94
55
|
responses: {
|
|
95
56
|
...responsesNode,
|
|
96
|
-
context: jsonClone(preservedResponsesContext)
|
|
97
|
-
}
|
|
57
|
+
context: jsonClone(preservedResponsesContext),
|
|
58
|
+
},
|
|
98
59
|
};
|
|
99
60
|
}
|
|
100
61
|
}
|
|
101
62
|
}
|
|
102
63
|
validateChatEnvelopeWithNative(chatEnvelope, {
|
|
103
|
-
stage:
|
|
104
|
-
direction:
|
|
64
|
+
stage: "req_inbound",
|
|
65
|
+
direction: "request",
|
|
105
66
|
});
|
|
106
|
-
recordStage(options.stageRecorder,
|
|
67
|
+
recordStage(options.stageRecorder, "chat_process.req.stage2.semantic_map", chatEnvelope);
|
|
68
|
+
logHubStageTiming(requestId, "req_inbound.stage2_to_standardized", "start");
|
|
69
|
+
const stdStart = Date.now();
|
|
107
70
|
const standardizedRequest = chatEnvelopeToStandardizedWithNative({
|
|
108
71
|
chatEnvelope: chatEnvelope,
|
|
109
72
|
adapterContext: options.adapterContext,
|
|
110
73
|
endpoint: options.adapterContext.entryEndpoint,
|
|
111
|
-
requestId: options.adapterContext.requestId
|
|
74
|
+
requestId: options.adapterContext.requestId,
|
|
112
75
|
});
|
|
76
|
+
logHubStageTiming(requestId, "req_inbound.stage2_to_standardized", "completed", { elapsedMs: Date.now() - stdStart });
|
|
113
77
|
// Ensure responses semantics (context) survive into standardized request for VirtualRouter parsing.
|
|
114
|
-
if (chatEnvelope.semantics && typeof chatEnvelope.semantics ===
|
|
78
|
+
if (chatEnvelope.semantics && typeof chatEnvelope.semantics === "object") {
|
|
115
79
|
const envelopeSemantics = chatEnvelope.semantics;
|
|
116
80
|
const existing = standardizedRequest.semantics;
|
|
117
|
-
if (!existing || typeof existing !==
|
|
81
|
+
if (!existing || typeof existing !== "object") {
|
|
118
82
|
standardizedRequest.semantics = jsonClone(envelopeSemantics);
|
|
119
83
|
}
|
|
120
84
|
else {
|
|
@@ -127,15 +91,23 @@ export async function runReqInboundStage2SemanticMap(options) {
|
|
|
127
91
|
: undefined;
|
|
128
92
|
if (envelopeContext) {
|
|
129
93
|
const nextResponses = {
|
|
130
|
-
...(isJsonObject(existingObj.responses)
|
|
131
|
-
|
|
94
|
+
...(isJsonObject(existingObj.responses)
|
|
95
|
+
? existingObj.responses
|
|
96
|
+
: {}),
|
|
97
|
+
context: jsonClone(envelopeContext),
|
|
132
98
|
};
|
|
133
99
|
standardizedRequest.semantics = {
|
|
134
100
|
...existingObj,
|
|
135
|
-
responses: nextResponses
|
|
101
|
+
responses: nextResponses,
|
|
136
102
|
};
|
|
137
103
|
}
|
|
138
104
|
}
|
|
139
105
|
}
|
|
140
|
-
return {
|
|
106
|
+
return {
|
|
107
|
+
chatEnvelope,
|
|
108
|
+
standardizedRequest,
|
|
109
|
+
...(preservedResponsesContext
|
|
110
|
+
? { responsesContext: preservedResponsesContext }
|
|
111
|
+
: {}),
|
|
112
|
+
};
|
|
141
113
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
2
|
-
import type { ChatEnvelope } from '../../../../types/chat-envelope.js';
|
|
3
2
|
import type { StageRecorder } from '../../../../format-adapters/index.js';
|
|
4
3
|
import type { JsonObject } from '../../../../types/json.js';
|
|
5
4
|
export interface ContextCaptureOptions {
|
|
6
5
|
rawRequest: JsonObject;
|
|
7
6
|
adapterContext: AdapterContext;
|
|
8
|
-
chatEnvelope?: ChatEnvelope;
|
|
9
7
|
stageRecorder?: StageRecorder;
|
|
10
8
|
}
|
|
11
9
|
export type ContextCaptureHandler = (options: ContextCaptureOptions) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
|
|
12
10
|
export interface ReqInboundStage3ContextCaptureOptions {
|
|
13
11
|
rawRequest: JsonObject;
|
|
14
12
|
adapterContext: AdapterContext;
|
|
15
|
-
chatEnvelope?: ChatEnvelope;
|
|
16
13
|
captureContext?: ContextCaptureHandler;
|
|
17
14
|
stageRecorder?: StageRecorder;
|
|
18
15
|
}
|
|
@@ -13,8 +13,7 @@ export async function runReqInboundStage3ContextCaptureOrchestration(options) {
|
|
|
13
13
|
try {
|
|
14
14
|
context = await options.captureContext({
|
|
15
15
|
rawRequest: options.rawRequest,
|
|
16
|
-
adapterContext: options.adapterContext
|
|
17
|
-
chatEnvelope: options.chatEnvelope
|
|
16
|
+
adapterContext: options.adapterContext
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
catch {
|
|
@@ -4,7 +4,6 @@ export function createResponsesContextCapture(captureImpl) {
|
|
|
4
4
|
return (options) => runReqInboundStage3ContextCapture({
|
|
5
5
|
rawRequest: options.rawRequest,
|
|
6
6
|
adapterContext: options.adapterContext,
|
|
7
|
-
chatEnvelope: options.chatEnvelope,
|
|
8
7
|
stageRecorder: options.stageRecorder,
|
|
9
8
|
captureContext: captureImpl
|
|
10
9
|
});
|
|
@@ -14,7 +13,6 @@ export function createNoopContextCapture(label) {
|
|
|
14
13
|
return (options) => runReqInboundStage3ContextCapture({
|
|
15
14
|
rawRequest: options.rawRequest,
|
|
16
15
|
adapterContext: options.adapterContext,
|
|
17
|
-
chatEnvelope: options.chatEnvelope,
|
|
18
16
|
stageRecorder: options.stageRecorder,
|
|
19
17
|
captureContext: () => ({ stage: normalizedLabel })
|
|
20
18
|
});
|
package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js
CHANGED
|
@@ -9,7 +9,6 @@ export function runChatContextCapture(options) {
|
|
|
9
9
|
return runReqInboundStage3ContextCapture({
|
|
10
10
|
rawRequest: options.rawRequest,
|
|
11
11
|
adapterContext: options.adapterContext,
|
|
12
|
-
chatEnvelope: options.chatEnvelope,
|
|
13
12
|
stageRecorder: options.stageRecorder,
|
|
14
13
|
captureContext: captureChatContextSnapshot
|
|
15
14
|
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { AdapterContext
|
|
2
|
-
import {
|
|
1
|
+
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
2
|
+
import type { JsonObject } from '../../../../types/json.js';
|
|
3
3
|
import type { ResponsesRequestContext } from '../../../../../responses/responses-openai-bridge.js';
|
|
4
4
|
export interface ResponsesContextCaptureOptions {
|
|
5
5
|
rawRequest: JsonObject;
|
|
6
6
|
adapterContext: AdapterContext;
|
|
7
|
-
chatEnvelope?: ChatEnvelope;
|
|
8
7
|
}
|
|
9
8
|
export declare function captureResponsesContextSnapshot(options: ResponsesContextCaptureOptions): ResponsesRequestContext;
|
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import { isJsonObject } from '../../../../types/json.js';
|
|
2
1
|
import { captureResponsesRequestContext } from '../../../../../shared/responses-conversation-store.js';
|
|
3
2
|
import { captureReqInboundResponsesContextSnapshotWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
4
|
-
function readResponsesContextFromChatEnvelope(chatEnvelope) {
|
|
5
|
-
if (!chatEnvelope?.semantics || typeof chatEnvelope.semantics !== 'object') {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const responsesNode = isJsonObject(chatEnvelope.semantics.responses)
|
|
9
|
-
? chatEnvelope.semantics.responses
|
|
10
|
-
: undefined;
|
|
11
|
-
return responsesNode && isJsonObject(responsesNode.context)
|
|
12
|
-
? responsesNode.context
|
|
13
|
-
: undefined;
|
|
14
|
-
}
|
|
15
3
|
export function captureResponsesContextSnapshot(options) {
|
|
16
|
-
const context =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
4
|
+
const context = captureReqInboundResponsesContextSnapshotWithNative({
|
|
5
|
+
rawRequest: options.rawRequest,
|
|
6
|
+
requestId: options.adapterContext.requestId,
|
|
7
|
+
toolCallIdStyle: options.adapterContext.toolCallIdStyle
|
|
8
|
+
});
|
|
22
9
|
// OpenAI Responses tool loop: store the request context keyed by requestId so that
|
|
23
10
|
// `/v1/responses/:id/submit_tool_outputs` can resume the conversation later.
|
|
24
11
|
//
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { ChatEnvelope } from '../../../../types/chat-envelope.js';
|
|
1
|
+
import type { AdapterContext, ChatEnvelope } from '../../../../types/chat-envelope.js';
|
|
2
|
+
export declare function applyToolCallIdStyleMetadata(chatEnvelope: ChatEnvelope, adapterContext: AdapterContext, snapshot?: Record<string, unknown>): void;
|
|
2
3
|
export declare function applyContextSnapshotToChatEnvelope(chatEnvelope: ChatEnvelope, snapshot: Record<string, unknown>): void;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
import { selectToolCallIdStyleWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js';
|
|
1
2
|
import { applyReqOutboundContextSnapshotWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
|
|
3
|
+
export function applyToolCallIdStyleMetadata(chatEnvelope, adapterContext, snapshot) {
|
|
4
|
+
const metadata = chatEnvelope.metadata || (chatEnvelope.metadata = { context: adapterContext });
|
|
5
|
+
const current = typeof metadata.toolCallIdStyle === 'string'
|
|
6
|
+
? String(metadata.toolCallIdStyle).trim()
|
|
7
|
+
: '';
|
|
8
|
+
const resolved = selectToolCallIdStyleWithNative(adapterContext, snapshot ?? {}, current || undefined);
|
|
9
|
+
if (!resolved) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// Always honor the route-selected AdapterContext toolCallIdStyle when present.
|
|
13
|
+
// This prevents cross-provider leakage (e.g. LM Studio "preserve" contaminating OpenAI "fc").
|
|
14
|
+
if (!current || current !== resolved) {
|
|
15
|
+
metadata.toolCallIdStyle = resolved;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
2
18
|
export function applyContextSnapshotToChatEnvelope(chatEnvelope, snapshot) {
|
|
3
19
|
const hasExistingTools = Array.isArray(chatEnvelope.tools) && chatEnvelope.tools.length > 0;
|
|
4
20
|
const patch = applyReqOutboundContextSnapshotWithNative({
|
package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AdapterContext, ChatEnvelope } from '../../../../types/chat-envelope.js';
|
|
2
2
|
import type { FormatEnvelope } from '../../../../types/format-envelope.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { JsonObject } from '../../../../types/json.js';
|
|
4
4
|
import type { StageRecorder, SemanticMapper } from '../../../../format-adapters/index.js';
|
|
5
5
|
import type { ProcessedRequest, StandardizedRequest } from '../../../../types/standardized.js';
|
|
6
6
|
export interface ReqOutboundStage1SemanticMapOptions {
|
package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js
CHANGED
|
@@ -1,53 +1,78 @@
|
|
|
1
|
-
import { isJsonObject } from '../../../../types/json.js';
|
|
2
1
|
import { applyHubOperationTableOutboundPostMap, applyHubOperationTableOutboundPreMap } from '../../../../operation-table/operation-table-runner.js';
|
|
3
2
|
import { recordStage } from '../../../stages/utils.js';
|
|
4
|
-
import { applyContextSnapshotToChatEnvelope } from './context-merge.js';
|
|
3
|
+
import { applyContextSnapshotToChatEnvelope, applyToolCallIdStyleMetadata } from './context-merge.js';
|
|
5
4
|
import { shouldAttachReqOutboundContextSnapshotWithNative, standardizedToChatEnvelopeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
|
|
6
5
|
import { validateChatEnvelopeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
|
|
7
|
-
import {
|
|
8
|
-
function hasResponsesContextSemantics(chatEnvelope) {
|
|
9
|
-
if (!chatEnvelope?.semantics || typeof chatEnvelope.semantics !== 'object') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const responsesNode = isJsonObject(chatEnvelope.semantics.responses)
|
|
13
|
-
? chatEnvelope.semantics.responses
|
|
14
|
-
: undefined;
|
|
15
|
-
return Boolean(responsesNode && isJsonObject(responsesNode.context));
|
|
16
|
-
}
|
|
6
|
+
import { logHubStageTiming } from '../../../hub-stage-timing.js';
|
|
17
7
|
export async function runReqOutboundStage1SemanticMap(options) {
|
|
18
|
-
const requestId = options.adapterContext.requestId;
|
|
19
|
-
const
|
|
8
|
+
const requestId = options.adapterContext.requestId || 'unknown';
|
|
9
|
+
const forceDetailLog = String(process.env.ROUTECODEX_HUB_STAGE_TIMING_DETAIL || '')
|
|
10
|
+
.trim()
|
|
11
|
+
.toLowerCase() === '1';
|
|
12
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_native_to_chat_envelope', 'start');
|
|
13
|
+
const toChatStart = Date.now();
|
|
14
|
+
const chatEnvelope = standardizedToChatEnvelopeWithNative({
|
|
20
15
|
request: options.request,
|
|
21
16
|
adapterContext: options.adapterContext
|
|
22
|
-
})
|
|
17
|
+
});
|
|
18
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_native_to_chat_envelope', 'completed', {
|
|
19
|
+
elapsedMs: Date.now() - toChatStart,
|
|
20
|
+
forceLog: forceDetailLog
|
|
21
|
+
});
|
|
22
|
+
applyToolCallIdStyleMetadata(chatEnvelope, options.adapterContext, options.contextSnapshot);
|
|
23
23
|
const shouldAttachContextSnapshot = shouldAttachReqOutboundContextSnapshotWithNative(Boolean(options.contextSnapshot), options.contextMetadataKey);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
!shouldSkipResponsesSnapshotMerge &&
|
|
28
|
-
options.contextSnapshot &&
|
|
29
|
-
options.contextMetadataKey) {
|
|
24
|
+
if (shouldAttachContextSnapshot && options.contextSnapshot && options.contextMetadataKey) {
|
|
25
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_context_merge', 'start');
|
|
26
|
+
const contextMergeStart = Date.now();
|
|
30
27
|
const snapshot = options.contextSnapshot;
|
|
31
28
|
if (options.contextMetadataKey !== 'responsesContext') {
|
|
32
29
|
chatEnvelope.metadata[options.contextMetadataKey] = snapshot;
|
|
33
30
|
}
|
|
34
|
-
|
|
31
|
+
applyContextSnapshotToChatEnvelope(chatEnvelope, snapshot);
|
|
32
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_context_merge', 'completed', {
|
|
33
|
+
elapsedMs: Date.now() - contextMergeStart,
|
|
34
|
+
forceLog: forceDetailLog
|
|
35
|
+
});
|
|
35
36
|
}
|
|
37
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_validate_chat_envelope', 'start');
|
|
38
|
+
const validateStart = Date.now();
|
|
36
39
|
validateChatEnvelopeWithNative(chatEnvelope, {
|
|
37
40
|
stage: 'req_outbound',
|
|
38
41
|
direction: 'request'
|
|
39
42
|
});
|
|
40
|
-
|
|
43
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_validate_chat_envelope', 'completed', {
|
|
44
|
+
elapsedMs: Date.now() - validateStart,
|
|
45
|
+
forceLog: forceDetailLog
|
|
46
|
+
});
|
|
47
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_operation_table_pre_map', 'start');
|
|
48
|
+
const preMapStart = Date.now();
|
|
49
|
+
await applyHubOperationTableOutboundPreMap({
|
|
41
50
|
protocol: options.adapterContext.providerProtocol,
|
|
42
51
|
chatEnvelope,
|
|
43
52
|
adapterContext: options.adapterContext
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
});
|
|
54
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_operation_table_pre_map', 'completed', {
|
|
55
|
+
elapsedMs: Date.now() - preMapStart,
|
|
56
|
+
forceLog: forceDetailLog
|
|
57
|
+
});
|
|
58
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_mapper_from_chat', 'start');
|
|
59
|
+
const fromChatStart = Date.now();
|
|
60
|
+
const formatEnvelope = (await options.semanticMapper.fromChat(chatEnvelope, options.adapterContext));
|
|
61
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_mapper_from_chat', 'completed', {
|
|
62
|
+
elapsedMs: Date.now() - fromChatStart,
|
|
63
|
+
forceLog: forceDetailLog
|
|
64
|
+
});
|
|
65
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_operation_table_post_map', 'start');
|
|
66
|
+
const postMapStart = Date.now();
|
|
67
|
+
applyHubOperationTableOutboundPostMap({
|
|
47
68
|
chatEnvelope,
|
|
48
69
|
formatEnvelope,
|
|
49
70
|
adapterContext: options.adapterContext
|
|
50
|
-
})
|
|
71
|
+
});
|
|
72
|
+
logHubStageTiming(requestId, 'req_outbound.stage1_operation_table_post_map', 'completed', {
|
|
73
|
+
elapsedMs: Date.now() - postMapStart,
|
|
74
|
+
forceLog: forceDetailLog
|
|
75
|
+
});
|
|
51
76
|
recordStage(options.stageRecorder, 'chat_process.req.stage6.outbound.semantic_map', chatEnvelope);
|
|
52
77
|
return { chatEnvelope, formatEnvelope };
|
|
53
78
|
}
|
|
@@ -7,7 +7,6 @@ export interface ReqProcessStage1ToolGovernanceOptions {
|
|
|
7
7
|
metadata: Record<string, unknown>;
|
|
8
8
|
entryEndpoint: string;
|
|
9
9
|
requestId: string;
|
|
10
|
-
applyPatchToolMode?: 'schema' | 'freeform';
|
|
11
10
|
stageRecorder?: StageRecorder;
|
|
12
11
|
}
|
|
13
12
|
export interface ReqProcessStage1ToolGovernanceResult {
|
package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js
CHANGED
|
@@ -54,7 +54,7 @@ export async function runReqProcessStage1ToolGovernance(options) {
|
|
|
54
54
|
recordStage(options.stageRecorder, 'chat_process.req.stage4.tool_governance', processedRequest);
|
|
55
55
|
// Best-effort: capture apply_patch execution failures reported by tool role messages.
|
|
56
56
|
// This is for errorsamples collection only and must not affect runtime behavior.
|
|
57
|
-
captureApplyPatchExecutionFailuresFromProcessedRequest(processedRequest
|
|
57
|
+
captureApplyPatchExecutionFailuresFromProcessedRequest(processedRequest);
|
|
58
58
|
return {
|
|
59
59
|
processedRequest,
|
|
60
60
|
nodeResult
|
package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.d.ts
CHANGED
|
@@ -14,4 +14,4 @@ export interface ReqProcessStage2RouteSelectResult {
|
|
|
14
14
|
decision: RoutingDecision;
|
|
15
15
|
diagnostics: RoutingDiagnostics;
|
|
16
16
|
}
|
|
17
|
-
export declare function runReqProcessStage2RouteSelect(options: ReqProcessStage2RouteSelectOptions):
|
|
17
|
+
export declare function runReqProcessStage2RouteSelect(options: ReqProcessStage2RouteSelectOptions): ReqProcessStage2RouteSelectResult;
|
package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { recordStage } from '../../../stages/utils.js';
|
|
2
2
|
import { applyReqProcessRouteSelectionWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js';
|
|
3
3
|
import { cleanRoutingInstructionMarkersWithNative } from '../../../../../../router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js';
|
|
4
|
-
import { measureHubStage } from '../../../hub-stage-timing.js';
|
|
5
4
|
function replaceRecordInPlace(target, source) {
|
|
6
5
|
for (const key of Object.keys(target)) {
|
|
7
6
|
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
@@ -10,20 +9,17 @@ function replaceRecordInPlace(target, source) {
|
|
|
10
9
|
}
|
|
11
10
|
Object.assign(target, source);
|
|
12
11
|
}
|
|
13
|
-
export
|
|
12
|
+
export function runReqProcessStage2RouteSelect(options) {
|
|
14
13
|
const previousModel = typeof options.request.model === 'string' ? options.request.model : undefined;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
: 'unknown';
|
|
18
|
-
const result = await measureHubStage(requestId, 'route_select.engine_route', () => options.routerEngine.route(options.request, options.metadataInput));
|
|
19
|
-
const nativeApplied = await measureHubStage(requestId, 'route_select.native_apply', () => applyReqProcessRouteSelectionWithNative({
|
|
14
|
+
const result = options.routerEngine.route(options.request, options.metadataInput);
|
|
15
|
+
const nativeApplied = applyReqProcessRouteSelectionWithNative({
|
|
20
16
|
request: options.request,
|
|
21
17
|
normalizedMetadata: options.normalizedMetadata,
|
|
22
18
|
target: result.target,
|
|
23
19
|
routeName: result.decision.routeName,
|
|
24
20
|
originalModel: previousModel
|
|
25
|
-
})
|
|
26
|
-
const cleanedRequest =
|
|
21
|
+
});
|
|
22
|
+
const cleanedRequest = cleanRoutingInstructionMarkersWithNative(nativeApplied.request);
|
|
27
23
|
replaceRecordInPlace(options.request, cleanedRequest);
|
|
28
24
|
replaceRecordInPlace(options.normalizedMetadata, nativeApplied.normalizedMetadata);
|
|
29
25
|
recordStage(options.stageRecorder, 'chat_process.req.stage5.route_select', {
|
|
@@ -59,6 +59,9 @@ export function injectContinueExecutionDirectiveIntoUserMessage(request, metadat
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function hasActiveStopMessageStateForContinueExecution(metadata) {
|
|
62
|
+
if (!isClientInjectReady(metadata)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
62
65
|
const persistedState = resolvePersistedStopMessageState(metadata);
|
|
63
66
|
return isStopMessageStateActiveWithNative(persistedState);
|
|
64
67
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { StandardizedMessage } from
|
|
1
|
+
import type { StandardizedMessage } from "../types/standardized.js";
|
|
2
2
|
export declare function stripHistoricalImageAttachments(messages: StandardizedMessage[]): StandardizedMessage[];
|
|
3
3
|
export declare function stripHistoricalVisualToolOutputs(messages: StandardizedMessage[]): StandardizedMessage[];
|
|
4
4
|
export declare function containsImageAttachment(messages: StandardizedMessage[]): boolean;
|
|
5
|
+
export declare function repairIncompleteToolCalls(messages: StandardizedMessage[]): StandardizedMessage[];
|