@jsonstudio/llms 0.6.1397 → 0.6.1402
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/codecs/gemini-openai-codec.d.ts +1 -3
- package/dist/conversion/codecs/gemini-openai-codec.js +4 -10
- package/dist/conversion/compat/actions/gemini-cli-request.d.ts +2 -0
- package/dist/conversion/compat/actions/gemini-cli-request.js +490 -0
- package/dist/conversion/compat/profiles/chat-gemini-cli.json +27 -0
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +76 -348
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +2 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +95 -3
- package/dist/conversion/hub/pipeline/hub-pipeline.js +1365 -19
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +22 -0
- package/dist/conversion/hub/policy/policy-engine.js +50 -3
- package/dist/conversion/hub/process/chat-process.js +5 -146
- package/dist/conversion/hub/response/provider-response.js +11 -10
- package/dist/conversion/hub/response/response-mappers.d.ts +1 -3
- package/dist/conversion/hub/response/response-mappers.js +2 -20
- package/dist/conversion/hub/tool-surface/tool-surface-engine.js +2 -1
- package/dist/conversion/responses/responses-openai-bridge.js +4 -3
- package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -6
- package/dist/conversion/shared/gemini-tool-utils.js +164 -542
- package/dist/conversion/shared/mcp-injection.js +29 -0
- package/dist/conversion/shared/openai-message-normalize.js +3 -17
- package/dist/filters/special/request-tool-list-filter.js +21 -13
- package/dist/filters/special/tool-filter-hooks.js +60 -3
- package/dist/router/virtual-router/bootstrap.js +8 -6
- package/dist/router/virtual-router/engine-health.d.ts +1 -1
- package/dist/router/virtual-router/engine-health.js +110 -11
- package/dist/router/virtual-router/engine-selection/alias-selection.d.ts +0 -15
- package/dist/router/virtual-router/engine-selection/alias-selection.js +4 -85
- package/dist/router/virtual-router/engine-selection/route-utils.js +6 -12
- package/dist/router/virtual-router/engine-selection/tier-selection-select.js +17 -40
- package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -5
- package/dist/router/virtual-router/engine.js +6 -21
- package/dist/router/virtual-router/types.d.ts +1 -14
- package/dist/servertool/clock/config.d.ts +1 -1
- package/dist/servertool/clock/config.js +5 -9
- package/dist/servertool/engine.js +6 -83
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +1 -2
- package/dist/sse/sse-to-json/builders/response-builder.js +0 -16
- package/package.json +1 -1
- package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.d.ts +0 -10
- package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.js +0 -142
- package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.d.ts +0 -6
- package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.js +0 -79
- package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.d.ts +0 -3
- package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.js +0 -46
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.d.ts +0 -8
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.js +0 -366
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.d.ts +0 -9
- package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.js +0 -390
- package/dist/conversion/hub/pipeline/hub-pipeline/node-results.d.ts +0 -3
- package/dist/conversion/hub/pipeline/hub-pipeline/node-results.js +0 -14
- package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.d.ts +0 -2
- package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.js +0 -144
- package/dist/conversion/hub/pipeline/hub-pipeline/policy.d.ts +0 -4
- package/dist/conversion/hub/pipeline/hub-pipeline/policy.js +0 -32
- package/dist/conversion/hub/pipeline/hub-pipeline/protocol.d.ts +0 -8
- package/dist/conversion/hub/pipeline/hub-pipeline/protocol.js +0 -63
- package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.d.ts +0 -2
- package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.js +0 -43
- package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.d.ts +0 -1
- package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.js +0 -29
- package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.d.ts +0 -2
- package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.js +0 -16
- package/dist/conversion/hub/pipeline/hub-pipeline/types.d.ts +0 -116
- package/dist/conversion/hub/pipeline/hub-pipeline/types.js +0 -1
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_thought_signature_inject/index.d.ts +0 -10
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_thought_signature_inject/index.js +0 -172
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_thought_signature_capture/index.d.ts +0 -10
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_thought_signature_capture/index.js +0 -71
- package/dist/conversion/hub/pipeline/thought-signature/thought-signature-center.d.ts +0 -14
- package/dist/conversion/hub/pipeline/thought-signature/thought-signature-center.js +0 -289
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { jsonClone } from '../../types/json.js';
|
|
2
|
-
import { ensureRuntimeMetadata, readRuntimeMetadata } from '../../../shared/runtime-metadata.js';
|
|
3
|
-
import { computeRequestTokens } from '../../../../router/virtual-router/token-estimator.js';
|
|
4
|
-
import { recordHubPolicyObservation, applyHubProviderOutboundPolicy } from '../../policy/policy-engine.js';
|
|
5
|
-
import { applyProviderOutboundToolSurface } from '../../tool-surface/tool-surface-engine.js';
|
|
6
|
-
import { extractSessionIdentifiersFromMetadata } from '../session-identifiers.js';
|
|
7
|
-
import { runReqProcessStage1ToolGovernance } from '../stages/req_process/req_process_stage1_tool_governance/index.js';
|
|
8
|
-
import { runReqProcessStage2RouteSelect } from '../stages/req_process/req_process_stage2_route_select/index.js';
|
|
9
|
-
import { runReqOutboundStage1SemanticMap } from '../stages/req_outbound/req_outbound_stage1_semantic_map/index.js';
|
|
10
|
-
import { runReqOutboundStage2FormatBuild } from '../stages/req_outbound/req_outbound_stage2_format_build/index.js';
|
|
11
|
-
import { runReqOutboundStage3Compat } from '../stages/req_outbound/req_outbound_stage3_compat/index.js';
|
|
12
|
-
import { buildAdapterContext, maybeCreateStageRecorder, resolveOutboundStreamIntent, applyOutboundStreamPreference } from './adapter-context.js';
|
|
13
|
-
import { assertNoMappableSemanticsInMetadata } from './semantic-gate.js';
|
|
14
|
-
import { convertProcessNodeResult } from './node-results.js';
|
|
15
|
-
import { injectServerToolRuntimeConfig } from './servertool-runtime-config.js';
|
|
16
|
-
function asJsonObject(value) {
|
|
17
|
-
if (!value || typeof value !== 'object') {
|
|
18
|
-
throw new Error('Responses pipeline requires JSON object payload');
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
function readResponsesResumeFromSemantics(request) {
|
|
23
|
-
try {
|
|
24
|
-
const semantics = request?.semantics;
|
|
25
|
-
const node = semantics && typeof semantics === 'object' && !Array.isArray(semantics) ? semantics.responses : undefined;
|
|
26
|
-
const resume = node && typeof node === 'object' && !Array.isArray(node) ? node.resume : undefined;
|
|
27
|
-
return resume && typeof resume === 'object' && !Array.isArray(resume) ? resume : undefined;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function coerceStandardizedRequestFromPayload(payload, normalized) {
|
|
34
|
-
const model = typeof payload.model === 'string' && payload.model.trim().length ? payload.model.trim() : '';
|
|
35
|
-
if (!model) {
|
|
36
|
-
throw new Error('[HubPipeline] outbound stage requires payload.model');
|
|
37
|
-
}
|
|
38
|
-
const messages = Array.isArray(payload.messages) ? payload.messages : null;
|
|
39
|
-
if (!messages) {
|
|
40
|
-
throw new Error('[HubPipeline] outbound stage requires payload.messages[]');
|
|
41
|
-
}
|
|
42
|
-
const tools = Array.isArray(payload.tools) ? payload.tools : undefined;
|
|
43
|
-
const parameters = payload.parameters && typeof payload.parameters === 'object' && !Array.isArray(payload.parameters)
|
|
44
|
-
? payload.parameters
|
|
45
|
-
: {};
|
|
46
|
-
const semanticsFromPayload = payload.semantics && typeof payload.semantics === 'object' && !Array.isArray(payload.semantics)
|
|
47
|
-
? jsonClone(payload.semantics)
|
|
48
|
-
: undefined;
|
|
49
|
-
const metadataFromPayload = payload.metadata && typeof payload.metadata === 'object' && !Array.isArray(payload.metadata)
|
|
50
|
-
? payload.metadata
|
|
51
|
-
: undefined;
|
|
52
|
-
const standardizedRequest = {
|
|
53
|
-
model,
|
|
54
|
-
messages,
|
|
55
|
-
...(tools ? { tools } : {}),
|
|
56
|
-
parameters,
|
|
57
|
-
metadata: {
|
|
58
|
-
originalEndpoint: normalized.entryEndpoint,
|
|
59
|
-
...(metadataFromPayload ? metadataFromPayload : {}),
|
|
60
|
-
requestId: normalized.id,
|
|
61
|
-
stream: normalized.stream,
|
|
62
|
-
processMode: normalized.processMode,
|
|
63
|
-
...(normalized.routeHint ? { routeHint: normalized.routeHint } : {})
|
|
64
|
-
},
|
|
65
|
-
...(semanticsFromPayload ? { semantics: semanticsFromPayload } : {})
|
|
66
|
-
};
|
|
67
|
-
// Ensure followup/chat_process entry can still preserve mappable semantics
|
|
68
|
-
// without injecting them into metadata.
|
|
69
|
-
try {
|
|
70
|
-
const semantics = standardizedRequest.semantics && typeof standardizedRequest.semantics === 'object'
|
|
71
|
-
? standardizedRequest.semantics
|
|
72
|
-
: (standardizedRequest.semantics = {});
|
|
73
|
-
if (!semantics.tools || typeof semantics.tools !== 'object' || Array.isArray(semantics.tools)) {
|
|
74
|
-
semantics.tools = {};
|
|
75
|
-
}
|
|
76
|
-
const toolsNode = semantics.tools;
|
|
77
|
-
if (Array.isArray(payload.tools) && payload.tools.length && toolsNode.clientToolsRaw === undefined) {
|
|
78
|
-
toolsNode.clientToolsRaw = jsonClone(payload.tools);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// best-effort
|
|
83
|
-
}
|
|
84
|
-
const rawPayload = {
|
|
85
|
-
model,
|
|
86
|
-
messages,
|
|
87
|
-
...(tools ? { tools } : {}),
|
|
88
|
-
...(parameters && Object.keys(parameters).length ? { parameters } : {})
|
|
89
|
-
};
|
|
90
|
-
return { standardizedRequest, rawPayload };
|
|
91
|
-
}
|
|
92
|
-
export async function executeChatProcessEntryPipeline(options) {
|
|
93
|
-
const { config, routerEngine, normalized } = options;
|
|
94
|
-
const hooks = options.resolveProtocolHooks(normalized.providerProtocol);
|
|
95
|
-
if (!hooks) {
|
|
96
|
-
throw new Error(`Unsupported provider protocol for hub pipeline: ${normalized.providerProtocol}`);
|
|
97
|
-
}
|
|
98
|
-
const nodeResults = [];
|
|
99
|
-
nodeResults.push({
|
|
100
|
-
id: 'req_inbound',
|
|
101
|
-
success: true,
|
|
102
|
-
metadata: {
|
|
103
|
-
node: 'req_inbound',
|
|
104
|
-
skipped: true,
|
|
105
|
-
reason: 'stage=outbound',
|
|
106
|
-
dataProcessed: {}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
const rawPayloadInput = asJsonObject(normalized.payload);
|
|
110
|
-
const { standardizedRequest: standardizedRequestBase, rawPayload } = coerceStandardizedRequestFromPayload(rawPayloadInput, normalized);
|
|
111
|
-
const metaBase = {
|
|
112
|
-
...(normalized.metadata ?? {})
|
|
113
|
-
};
|
|
114
|
-
injectServerToolRuntimeConfig(config, metaBase);
|
|
115
|
-
normalized.metadata = metaBase;
|
|
116
|
-
const standardizedRequest = standardizedRequestBase;
|
|
117
|
-
try {
|
|
118
|
-
const resumeMeta = metaBase && typeof metaBase.responsesResume === 'object' && metaBase.responsesResume
|
|
119
|
-
? metaBase.responsesResume
|
|
120
|
-
: undefined;
|
|
121
|
-
if (resumeMeta) {
|
|
122
|
-
standardizedRequest.semantics = standardizedRequest.semantics ?? {};
|
|
123
|
-
const semantics = standardizedRequest.semantics;
|
|
124
|
-
if (!semantics.responses || typeof semantics.responses !== 'object' || Array.isArray(semantics.responses)) {
|
|
125
|
-
semantics.responses = {};
|
|
126
|
-
}
|
|
127
|
-
const responsesNode = semantics.responses;
|
|
128
|
-
if (responsesNode.resume === undefined) {
|
|
129
|
-
responsesNode.resume = jsonClone(resumeMeta);
|
|
130
|
-
}
|
|
131
|
-
delete metaBase.responsesResume;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
// best-effort
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
const rt = readRuntimeMetadata(metaBase);
|
|
139
|
-
const mode = String(rt?.applyPatchToolMode || '').trim().toLowerCase();
|
|
140
|
-
if (mode === 'freeform' || mode === 'schema') {
|
|
141
|
-
standardizedRequest.metadata.applyPatchToolMode = mode;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
// ignore
|
|
146
|
-
}
|
|
147
|
-
const adapterContext = buildAdapterContext(normalized);
|
|
148
|
-
const stageRecorder = maybeCreateStageRecorder(adapterContext, normalized.entryEndpoint, {
|
|
149
|
-
disableSnapshots: normalized.disableSnapshots === true
|
|
150
|
-
});
|
|
151
|
-
let processedRequest;
|
|
152
|
-
if (normalized.processMode !== 'passthrough') {
|
|
153
|
-
assertNoMappableSemanticsInMetadata(metaBase, 'chat_process.request.entry');
|
|
154
|
-
const processResult = await runReqProcessStage1ToolGovernance({
|
|
155
|
-
request: standardizedRequest,
|
|
156
|
-
rawPayload,
|
|
157
|
-
metadata: metaBase,
|
|
158
|
-
entryEndpoint: normalized.entryEndpoint,
|
|
159
|
-
requestId: normalized.id,
|
|
160
|
-
stageRecorder
|
|
161
|
-
});
|
|
162
|
-
processedRequest = processResult.processedRequest;
|
|
163
|
-
try {
|
|
164
|
-
const reservation = processedRequest?.metadata?.__clockReservation;
|
|
165
|
-
if (reservation && typeof reservation === 'object') {
|
|
166
|
-
metaBase.__clockReservation = reservation;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
// best-effort
|
|
171
|
-
}
|
|
172
|
-
if (processResult.nodeResult) {
|
|
173
|
-
nodeResults.push(convertProcessNodeResult('chat_process.req.stage4.tool_governance', processResult.nodeResult));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
let workingRequest = processedRequest ?? standardizedRequest;
|
|
177
|
-
try {
|
|
178
|
-
const estimatedTokens = computeRequestTokens(workingRequest, '');
|
|
179
|
-
if (typeof estimatedTokens === 'number' && Number.isFinite(estimatedTokens) && estimatedTokens > 0) {
|
|
180
|
-
normalized.metadata = normalized.metadata || {};
|
|
181
|
-
normalized.metadata.estimatedInputTokens = estimatedTokens;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
// ignore
|
|
186
|
-
}
|
|
187
|
-
const normalizedMeta = normalized.metadata;
|
|
188
|
-
const responsesResume = readResponsesResumeFromSemantics(workingRequest);
|
|
189
|
-
const stdMetadata = workingRequest?.metadata;
|
|
190
|
-
const hasImageAttachment = (stdMetadata?.hasImageAttachment === true || stdMetadata?.hasImageAttachment === 'true') ||
|
|
191
|
-
(normalizedMeta?.hasImageAttachment === true || normalizedMeta?.hasImageAttachment === 'true');
|
|
192
|
-
const serverToolRequired = stdMetadata?.webSearchEnabled === true || stdMetadata?.serverToolRequired === true;
|
|
193
|
-
const sessionIdentifiers = extractSessionIdentifiersFromMetadata(normalized.metadata);
|
|
194
|
-
if (sessionIdentifiers.sessionId && normalized.metadata && typeof normalized.metadata === 'object') {
|
|
195
|
-
normalized.metadata.sessionId = sessionIdentifiers.sessionId;
|
|
196
|
-
}
|
|
197
|
-
if (sessionIdentifiers.conversationId && normalized.metadata && typeof normalized.metadata === 'object') {
|
|
198
|
-
normalized.metadata.conversationId = sessionIdentifiers.conversationId;
|
|
199
|
-
}
|
|
200
|
-
const disableStickyRoutes = readRuntimeMetadata(normalized.metadata)?.disableStickyRoutes === true;
|
|
201
|
-
const shadowCompareForcedProviderKey = normalizedMeta && typeof normalizedMeta.__shadowCompareForcedProviderKey === 'string'
|
|
202
|
-
? String(normalizedMeta.__shadowCompareForcedProviderKey)
|
|
203
|
-
: '';
|
|
204
|
-
const disabledProviderKeyAliases = normalizedMeta && Array.isArray(normalizedMeta.disabledProviderKeyAliases)
|
|
205
|
-
? normalizedMeta.disabledProviderKeyAliases
|
|
206
|
-
: null;
|
|
207
|
-
const metadataInput = {
|
|
208
|
-
requestId: normalized.id,
|
|
209
|
-
entryEndpoint: normalized.entryEndpoint,
|
|
210
|
-
processMode: normalized.processMode,
|
|
211
|
-
stream: normalized.stream,
|
|
212
|
-
direction: normalized.direction,
|
|
213
|
-
providerProtocol: normalized.providerProtocol,
|
|
214
|
-
routeHint: normalized.routeHint,
|
|
215
|
-
stage: normalized.stage,
|
|
216
|
-
responsesResume: responsesResume,
|
|
217
|
-
...(disableStickyRoutes ? { disableStickyRoutes: true } : {}),
|
|
218
|
-
...(serverToolRequired ? { serverToolRequired: true } : {}),
|
|
219
|
-
...(sessionIdentifiers.sessionId ? { sessionId: sessionIdentifiers.sessionId } : {}),
|
|
220
|
-
...(sessionIdentifiers.conversationId ? { conversationId: sessionIdentifiers.conversationId } : {}),
|
|
221
|
-
...(shadowCompareForcedProviderKey.trim().length
|
|
222
|
-
? { __shadowCompareForcedProviderKey: shadowCompareForcedProviderKey.trim() }
|
|
223
|
-
: {}),
|
|
224
|
-
...(disabledProviderKeyAliases && disabledProviderKeyAliases.length
|
|
225
|
-
? { disabledProviderKeyAliases: disabledProviderKeyAliases }
|
|
226
|
-
: {})
|
|
227
|
-
};
|
|
228
|
-
const routing = runReqProcessStage2RouteSelect({
|
|
229
|
-
routerEngine,
|
|
230
|
-
request: workingRequest,
|
|
231
|
-
metadataInput,
|
|
232
|
-
normalizedMetadata: normalized.metadata,
|
|
233
|
-
stageRecorder
|
|
234
|
-
});
|
|
235
|
-
const stopMessageState = routerEngine.getStopMessageState(metadataInput);
|
|
236
|
-
if (stopMessageState && normalized.metadata && typeof normalized.metadata === 'object') {
|
|
237
|
-
const rt = ensureRuntimeMetadata(normalized.metadata);
|
|
238
|
-
rt.stopMessageState = stopMessageState;
|
|
239
|
-
}
|
|
240
|
-
try {
|
|
241
|
-
const routeName = routing.decision?.routeName;
|
|
242
|
-
const providerKey = routing.target?.providerKey;
|
|
243
|
-
const modelId = workingRequest.model;
|
|
244
|
-
const logger = (normalized.metadata && normalized.metadata.logger);
|
|
245
|
-
if (logger && typeof logger.logVirtualRouterHit === 'function' && routeName && providerKey) {
|
|
246
|
-
logger.logVirtualRouterHit(routeName, providerKey, typeof modelId === 'string' ? modelId : undefined);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
catch {
|
|
250
|
-
// ignore
|
|
251
|
-
}
|
|
252
|
-
const outboundStream = resolveOutboundStreamIntent(routing.target?.streaming);
|
|
253
|
-
workingRequest = applyOutboundStreamPreference(workingRequest, outboundStream);
|
|
254
|
-
const outboundAdapterContext = buildAdapterContext(normalized, routing.target);
|
|
255
|
-
if (routing.target?.compatibilityProfile) {
|
|
256
|
-
outboundAdapterContext.compatibilityProfile = routing.target.compatibilityProfile;
|
|
257
|
-
}
|
|
258
|
-
const outboundProtocol = outboundAdapterContext.providerProtocol;
|
|
259
|
-
const protocolSwitch = outboundProtocol !== normalized.providerProtocol;
|
|
260
|
-
const outboundHooks = protocolSwitch ? options.resolveProtocolHooks(outboundProtocol) : hooks;
|
|
261
|
-
if (!outboundHooks) {
|
|
262
|
-
throw new Error(`[HubPipeline] Unsupported provider protocol for hub pipeline: ${outboundProtocol}`);
|
|
263
|
-
}
|
|
264
|
-
const outboundSemanticMapper = protocolSwitch ? outboundHooks.createSemanticMapper() : hooks.createSemanticMapper();
|
|
265
|
-
const outboundFormatAdapter = protocolSwitch ? outboundHooks.createFormatAdapter() : hooks.createFormatAdapter();
|
|
266
|
-
const outboundContextMetadataKey = protocolSwitch ? outboundHooks.contextMetadataKey : hooks.contextMetadataKey;
|
|
267
|
-
const outboundContextSnapshot = undefined;
|
|
268
|
-
const outboundRecorder = maybeCreateStageRecorder(outboundAdapterContext, normalized.entryEndpoint, {
|
|
269
|
-
disableSnapshots: normalized.disableSnapshots === true
|
|
270
|
-
});
|
|
271
|
-
const outboundStart = Date.now();
|
|
272
|
-
const outboundStage1 = await runReqOutboundStage1SemanticMap({
|
|
273
|
-
request: workingRequest,
|
|
274
|
-
adapterContext: outboundAdapterContext,
|
|
275
|
-
semanticMapper: outboundSemanticMapper,
|
|
276
|
-
contextSnapshot: outboundContextSnapshot,
|
|
277
|
-
contextMetadataKey: outboundContextMetadataKey,
|
|
278
|
-
stageRecorder: outboundRecorder
|
|
279
|
-
});
|
|
280
|
-
let formattedPayload = await runReqOutboundStage2FormatBuild({
|
|
281
|
-
formatEnvelope: outboundStage1.formatEnvelope,
|
|
282
|
-
adapterContext: outboundAdapterContext,
|
|
283
|
-
formatAdapter: outboundFormatAdapter,
|
|
284
|
-
stageRecorder: outboundRecorder
|
|
285
|
-
});
|
|
286
|
-
formattedPayload = await runReqOutboundStage3Compat({
|
|
287
|
-
payload: formattedPayload,
|
|
288
|
-
adapterContext: outboundAdapterContext,
|
|
289
|
-
stageRecorder: outboundRecorder
|
|
290
|
-
});
|
|
291
|
-
const effectivePolicy = normalized.policyOverride ?? config.policy;
|
|
292
|
-
recordHubPolicyObservation({
|
|
293
|
-
policy: effectivePolicy,
|
|
294
|
-
providerProtocol: outboundProtocol,
|
|
295
|
-
payload: formattedPayload,
|
|
296
|
-
stageRecorder: outboundRecorder,
|
|
297
|
-
requestId: normalized.id
|
|
298
|
-
});
|
|
299
|
-
let providerPayload = applyHubProviderOutboundPolicy({
|
|
300
|
-
policy: effectivePolicy,
|
|
301
|
-
providerProtocol: outboundProtocol,
|
|
302
|
-
payload: formattedPayload,
|
|
303
|
-
stageRecorder: outboundRecorder,
|
|
304
|
-
requestId: normalized.id
|
|
305
|
-
});
|
|
306
|
-
providerPayload = applyProviderOutboundToolSurface({
|
|
307
|
-
config: config.toolSurface,
|
|
308
|
-
providerProtocol: outboundProtocol,
|
|
309
|
-
payload: providerPayload,
|
|
310
|
-
stageRecorder: outboundRecorder,
|
|
311
|
-
requestId: normalized.id
|
|
312
|
-
});
|
|
313
|
-
recordHubPolicyObservation({
|
|
314
|
-
policy: effectivePolicy,
|
|
315
|
-
providerProtocol: outboundProtocol,
|
|
316
|
-
payload: providerPayload,
|
|
317
|
-
stageRecorder: outboundRecorder,
|
|
318
|
-
requestId: normalized.id
|
|
319
|
-
});
|
|
320
|
-
const outboundEnd = Date.now();
|
|
321
|
-
nodeResults.push({
|
|
322
|
-
id: 'req_outbound',
|
|
323
|
-
success: true,
|
|
324
|
-
metadata: {
|
|
325
|
-
node: 'req_outbound',
|
|
326
|
-
executionTime: outboundEnd - outboundStart,
|
|
327
|
-
startTime: outboundStart,
|
|
328
|
-
endTime: outboundEnd,
|
|
329
|
-
dataProcessed: {
|
|
330
|
-
messages: workingRequest.messages.length,
|
|
331
|
-
tools: workingRequest.tools?.length ?? 0
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
const capturedChatRequest = {
|
|
336
|
-
model: workingRequest.model,
|
|
337
|
-
messages: jsonClone(workingRequest.messages),
|
|
338
|
-
tools: workingRequest.tools ? jsonClone(workingRequest.tools) : workingRequest.tools,
|
|
339
|
-
parameters: workingRequest.parameters
|
|
340
|
-
? jsonClone(workingRequest.parameters)
|
|
341
|
-
: workingRequest.parameters
|
|
342
|
-
};
|
|
343
|
-
const metadata = {
|
|
344
|
-
...normalized.metadata,
|
|
345
|
-
...(hasImageAttachment ? { hasImageAttachment: true } : {}),
|
|
346
|
-
capturedChatRequest,
|
|
347
|
-
entryEndpoint: normalized.entryEndpoint,
|
|
348
|
-
providerProtocol: outboundProtocol,
|
|
349
|
-
stream: normalized.stream,
|
|
350
|
-
processMode: normalized.processMode,
|
|
351
|
-
routeHint: normalized.routeHint,
|
|
352
|
-
target: routing.target,
|
|
353
|
-
...(typeof outboundStream === 'boolean' ? { providerStream: outboundStream } : {})
|
|
354
|
-
};
|
|
355
|
-
return {
|
|
356
|
-
requestId: normalized.id,
|
|
357
|
-
providerPayload,
|
|
358
|
-
standardizedRequest,
|
|
359
|
-
processedRequest,
|
|
360
|
-
routingDecision: routing.decision,
|
|
361
|
-
routingDiagnostics: routing.diagnostics,
|
|
362
|
-
target: routing.target,
|
|
363
|
-
metadata,
|
|
364
|
-
nodeResults
|
|
365
|
-
};
|
|
366
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { VirtualRouterEngine } from '../../../../router/virtual-router/engine.js';
|
|
2
|
-
import type { HubPipelineConfig, HubPipelineResult, NormalizedRequest, ProviderProtocol, RequestStageHooks } from './types.js';
|
|
3
|
-
export declare function executeRequestStagePipeline<TContext = Record<string, unknown>>(options: {
|
|
4
|
-
config: HubPipelineConfig;
|
|
5
|
-
routerEngine: VirtualRouterEngine;
|
|
6
|
-
normalized: NormalizedRequest;
|
|
7
|
-
hooks: RequestStageHooks<TContext>;
|
|
8
|
-
resolveProtocolHooks: (protocol: ProviderProtocol) => RequestStageHooks<Record<string, unknown>> | undefined;
|
|
9
|
-
}): Promise<HubPipelineResult>;
|